Fix some usage of std::istream unformatted input in hwpfilter/source/hwpeq.cxx
(Though some deficiencies remain, e.g. when values are assumed to be valid characters and not eof().) Change-Id: Ia5ec681a68086e9843206a6b44a44f8ec3800b88
This commit is contained in:
@@ -41,14 +41,21 @@ using namespace std;
|
|||||||
# define ENDL "\n"
|
# define ENDL "\n"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define WS " \t\r\n\v\f"
|
|
||||||
|
|
||||||
#define EQ_CASE 0x01 // case sensitive cmd
|
#define EQ_CASE 0x01 // case sensitive cmd
|
||||||
#define EQ_ENV 0x02 // equiv to latex environment
|
#define EQ_ENV 0x02 // equiv to latex environment
|
||||||
#define EQ_ATOP 0x04 // must revert order
|
#define EQ_ATOP 0x04 // must revert order
|
||||||
|
|
||||||
#define IS_WS(ch) (strchr(WS, ch))
|
static bool IS_WS(std::istream::int_type ch) {
|
||||||
#define IS_BINARY(ch) (strchr("+-<=>", ch))
|
return ch != std::istream::traits_type::eof()
|
||||||
|
&& rtl::isAsciiWhiteSpace(
|
||||||
|
static_cast<unsigned char>(
|
||||||
|
std::istream::traits_type::to_char_type(ch)));
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool IS_BINARY(std::istream::int_type ch) {
|
||||||
|
return ch != std::istream::traits_type::eof()
|
||||||
|
&& strchr("+-<=>", std::istream::traits_type::to_char_type(ch));
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
#define STRICMP stricmp
|
#define STRICMP stricmp
|
||||||
@@ -479,7 +486,7 @@ void push_token(MzString &white, MzString &token, istream *strm)
|
|||||||
* alphabet string, sigle character */
|
* alphabet string, sigle character */
|
||||||
static int next_token(MzString &white, MzString &token, istream *strm)
|
static int next_token(MzString &white, MzString &token, istream *strm)
|
||||||
{
|
{
|
||||||
int ch = 0;
|
std::istream::int_type ch = 0;
|
||||||
|
|
||||||
if( stk->state(strm) ) {
|
if( stk->state(strm) ) {
|
||||||
white = stk->white;
|
white = stk->white;
|
||||||
@@ -500,7 +507,9 @@ static int next_token(MzString &white, MzString &token, istream *strm)
|
|||||||
while( IS_WS(ch = strm->get()) );
|
while( IS_WS(ch = strm->get()) );
|
||||||
}
|
}
|
||||||
|
|
||||||
if( ch == '\\' || ch & 0x80 || isalpha(ch) ) {
|
if( ch == '\\' || ch & 0x80
|
||||||
|
|| (ch != std::istream::traits_type::eof() && rtl::isAsciiAlpha(ch)) )
|
||||||
|
{
|
||||||
if( ch == '\\' ) {
|
if( ch == '\\' ) {
|
||||||
token << (char) ch;
|
token << (char) ch;
|
||||||
ch = strm->get();
|
ch = strm->get();
|
||||||
@@ -509,8 +518,8 @@ static int next_token(MzString &white, MzString &token, istream *strm)
|
|||||||
token << (char) ch;
|
token << (char) ch;
|
||||||
ch = strm->get();
|
ch = strm->get();
|
||||||
} while( ch != std::istream::traits_type::eof()
|
} while( ch != std::istream::traits_type::eof()
|
||||||
&& (ch & 0x80 || isalpha(ch)) ) ;
|
&& (ch & 0x80 || rtl::isAsciiAlpha(ch)) ) ;
|
||||||
strm->putback(sal::static_int_cast<char>(ch));
|
strm->putback(static_cast<char>(ch));
|
||||||
/* special treatment of sub, sub, over, atop
|
/* special treatment of sub, sub, over, atop
|
||||||
The reason for this is that affect next_state().
|
The reason for this is that affect next_state().
|
||||||
*/
|
*/
|
||||||
@@ -531,12 +540,14 @@ static int next_token(MzString &white, MzString &token, istream *strm)
|
|||||||
else if( IS_BINARY(ch) ) {
|
else if( IS_BINARY(ch) ) {
|
||||||
do token << (char) ch;
|
do token << (char) ch;
|
||||||
while( IS_BINARY(ch = strm->get()) );
|
while( IS_BINARY(ch = strm->get()) );
|
||||||
strm->putback(sal::static_int_cast<char>(ch));
|
strm->putback(static_cast<char>(ch));
|
||||||
}
|
}
|
||||||
else if( isdigit(ch) ) {
|
else if( ch != std::istream::traits_type::eof() && rtl::isAsciiDigit(ch) ) {
|
||||||
do token << (char) ch;
|
do {
|
||||||
while( isdigit(ch = strm->get()) );
|
token << (char) ch;
|
||||||
strm->putback(sal::static_int_cast<char>(ch));
|
ch = strm->get();
|
||||||
|
} while( ch != std::istream::traits_type::eof() && rtl::isAsciiDigit(ch) );
|
||||||
|
strm->putback(static_cast<char>(ch));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
token << (char) ch;
|
token << (char) ch;
|
||||||
@@ -544,20 +555,20 @@ static int next_token(MzString &white, MzString &token, istream *strm)
|
|||||||
return token.length();
|
return token.length();
|
||||||
}
|
}
|
||||||
|
|
||||||
static int read_white_space(MzString& outs, istream *strm)
|
static std::istream::int_type read_white_space(MzString& outs, istream *strm)
|
||||||
{
|
{
|
||||||
int result;
|
std::istream::int_type result;
|
||||||
|
|
||||||
if( stk->state(strm) ) {
|
if( stk->state(strm) ) {
|
||||||
outs << stk->white;
|
outs << stk->white;
|
||||||
stk->white = nullptr;
|
stk->white = nullptr;
|
||||||
result = stk->token[0];
|
result = std::istream::traits_type::to_int_type(stk->token[0]);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
int ch;
|
std::istream::int_type ch;
|
||||||
while( IS_WS(ch = strm->get()) )
|
while( IS_WS(ch = strm->get()) )
|
||||||
outs << (char )ch;
|
outs << (char )ch;
|
||||||
strm->putback(sal::static_int_cast<char>(ch));
|
strm->putback(static_cast<char>(ch));
|
||||||
result = ch;
|
result = ch;
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
@@ -619,7 +630,7 @@ static int eq_word(MzString& outs, istream *strm, int status)
|
|||||||
if( nullptr != (eq = lookup_eqn(keyword)) ) {
|
if( nullptr != (eq = lookup_eqn(keyword)) ) {
|
||||||
int nargs = eq->nargs;
|
int nargs = eq->nargs;
|
||||||
while( nargs-- ) {
|
while( nargs-- ) {
|
||||||
const int ch = read_white_space(state, strm);
|
const std::istream::int_type ch = read_white_space(state, strm);
|
||||||
if( ch != '{' ) state << '{';
|
if( ch != '{' ) state << '{';
|
||||||
eq_word(state, strm, script_status);
|
eq_word(state, strm, script_status);
|
||||||
if( ch != '{' ) state << '}';
|
if( ch != '{' ) state << '}';
|
||||||
@@ -678,7 +689,8 @@ static char eq2ltxconv(MzString& sstr, istream *strm, const char *sentinel)
|
|||||||
{
|
{
|
||||||
MzString white, token;
|
MzString white, token;
|
||||||
char key[256];
|
char key[256];
|
||||||
int ch, result;
|
std::istream::int_type ch;
|
||||||
|
int result;
|
||||||
|
|
||||||
while( 0 != (result = next_token(white, token, strm)) ) {
|
while( 0 != (result = next_token(white, token, strm)) ) {
|
||||||
if( sentinel && (result == 1) && strchr(sentinel, token[0]) )
|
if( sentinel && (result == 1) && strchr(sentinel, token[0]) )
|
||||||
|
Reference in New Issue
Block a user