-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added -d postfix to libs. Adjust int casting. #10
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,8 @@ | |
// accompanying file LICENSE_1_0.txt or copy at | ||
// http://www.boost.org/LICENSE_1_0.txt) | ||
// | ||
// Note: does all pointer-math in DWORD, assumes no overflows. | ||
|
||
#define BOOST_NOWIDE_SOURCE | ||
#include <boost/nowide/iostream.hpp> | ||
#include <boost/nowide/convert.hpp> | ||
|
@@ -43,8 +45,8 @@ namespace details { | |
{ | ||
if(!handle_) | ||
return -1; | ||
int n = pptr() - pbase(); | ||
int r = 0; | ||
DWORD n = static_cast<DWORD>(pptr() - pbase()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. instead DWORD, pointers math should be calculated with |
||
DWORD r = 0; | ||
|
||
if(n > 0 && (r=write(pbase(),n)) < 0) | ||
return -1; | ||
|
@@ -59,29 +61,29 @@ namespace details { | |
} | ||
private: | ||
|
||
int write(char const *p,int n) | ||
DWORD write(char const *p, DWORD n) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that |
||
{ | ||
namespace uf = boost::locale::utf; | ||
char const *b = p; | ||
char const *e = p+n; | ||
DWORD size=0; | ||
if(!isatty_) { | ||
if(!WriteFile(handle_,p,n,&size,0) || static_cast<int>(size) != n) | ||
if(!WriteFile(handle_,p,n,&size,0) || size != n) | ||
return -1; | ||
return n; | ||
} | ||
if(n > buffer_size) | ||
return -1; | ||
wchar_t *out = wbuffer_; | ||
uf::code_point c; | ||
size_t decoded = 0; | ||
DWORD decoded = 0; | ||
while(p < e && (c = uf::utf_traits<char>::decode(p,e))!=uf::illegal && c!=uf::incomplete) { | ||
out = uf::utf_traits<wchar_t>::encode(c,out); | ||
decoded = p-b; | ||
decoded = static_cast<DWORD>(p-b); | ||
} | ||
if(c==uf::illegal) | ||
return -1; | ||
if(!WriteConsoleW(handle_,wbuffer_,out - wbuffer_,&size,0)) | ||
if(!WriteConsoleW(handle_,wbuffer_, static_cast<DWORD>(out - wbuffer_),&size,0)) | ||
return -1; | ||
return decoded; | ||
} | ||
|
@@ -167,19 +169,19 @@ namespace details { | |
return read_bytes; | ||
} | ||
DWORD read_wchars = 0; | ||
size_t n = wbuffer_size - wsize_; | ||
if(!ReadConsoleW(handle_,wbuffer_,n,&read_wchars,0)) | ||
DWORD n = wbuffer_size - wsize_; | ||
if(!ReadConsoleW(handle_,wbuffer_, n, &read_wchars,0)) | ||
return 0; | ||
wsize_ += read_wchars; | ||
char *out = buffer_; | ||
wchar_t *b = wbuffer_; | ||
wchar_t *e = b + wsize_; | ||
wchar_t *p = b; | ||
uf::code_point c; | ||
wsize_ = e-p; | ||
wsize_ = static_cast<DWORD>(e-p); | ||
while(p < e && (c = uf::utf_traits<wchar_t>::decode(p,e))!=uf::illegal && c!=uf::incomplete) { | ||
out = uf::utf_traits<char>::encode(c,out); | ||
wsize_ = e-p; | ||
wsize_ = static_cast<DWORD>(e-p); | ||
} | ||
|
||
if(c==uf::illegal) | ||
|
@@ -193,13 +195,13 @@ namespace details { | |
return out - buffer_; | ||
} | ||
|
||
static const size_t buffer_size = 1024 * 3; | ||
static const size_t wbuffer_size = 1024; | ||
static const DWORD buffer_size = 1024 * 3; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. size_t was better for 64-bit portability |
||
static const DWORD wbuffer_size = 1024; | ||
char buffer_[buffer_size]; | ||
wchar_t wbuffer_[buffer_size]; // for null | ||
HANDLE handle_; | ||
bool isatty_; | ||
int wsize_; | ||
DWORD wsize_; | ||
std::vector<char> pback_buffer_; | ||
}; | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
according to https://msdn.microsoft.com/en-us/library/windows/desktop/ms683188(v=vs.85).aspx, cast should be written as
static_cast<DWORD>