/** reads the next token from the input file into the token buffer; returns whether a token was read */ static SCIP_Bool getNextToken( BLKINPUT* blkinput /**< BLK reading data */ ) { SCIP_Bool hasdot; BLKEXPTYPE exptype; char* buf; int tokenlen; assert(blkinput != NULL); assert(blkinput->linepos < BLK_MAX_LINELEN); /* check the token stack */ if( blkinput->npushedtokens > 0 ) { swapPointers(&blkinput->token, &blkinput->pushedtokens[blkinput->npushedtokens-1]); blkinput->npushedtokens--; SCIPdebugMessage("(line %d) read token again: '%s'\n", blkinput->linenumber, blkinput->token); return TRUE; } /* skip delimiters */ buf = blkinput->linebuf; while( isDelimChar(buf[blkinput->linepos]) ) { if( buf[blkinput->linepos] == '\0' ) { if( !getNextLine(blkinput) ) { blkinput->section = BLK_END; SCIPdebugMessage("(line %d) end of file\n", blkinput->linenumber); return FALSE; } assert(blkinput->linepos == 0); } else blkinput->linepos++; } assert(blkinput->linepos < BLK_MAX_LINELEN); assert(!isDelimChar(buf[blkinput->linepos])); /* check if the token is a value */ hasdot = FALSE; exptype = BLK_EXP_NONE; if( isValueChar(buf[blkinput->linepos], buf[blkinput->linepos+1], TRUE, &hasdot, &exptype) ) /*lint !e679*/ { /* read value token */ tokenlen = 0; do { assert(tokenlen < BLK_MAX_LINELEN); assert(!isDelimChar(buf[blkinput->linepos])); blkinput->token[tokenlen] = buf[blkinput->linepos]; ++tokenlen; ++(blkinput->linepos); assert(blkinput->linepos < BLK_MAX_LINELEN); } while( isValueChar(buf[blkinput->linepos], buf[blkinput->linepos+1], FALSE, &hasdot, &exptype) ); /*lint !e679*/ } else { /* read non-value token */ tokenlen = 0; do { assert(tokenlen < BLK_MAX_LINELEN); blkinput->token[tokenlen] = buf[blkinput->linepos]; tokenlen++; blkinput->linepos++; if( tokenlen == 1 && isTokenChar(blkinput->token[0]) ) break; } while( !isDelimChar(buf[blkinput->linepos]) && !isTokenChar(buf[blkinput->linepos]) ); /* if the token is an equation sense '<', '>', or '=', skip a following '=' * if the token is an equality token '=' and the next character is a '<' or '>', replace the token by the inequality sense */ if( tokenlen >= 1 && (blkinput->token[tokenlen-1] == '<' || blkinput->token[tokenlen-1] == '>' || blkinput->token[tokenlen-1] == '=') && buf[blkinput->linepos] == '=' ) { blkinput->linepos++; } else if( blkinput->token[tokenlen-1] == '=' && (buf[blkinput->linepos] == '<' || buf[blkinput->linepos] == '>') ) { blkinput->token[tokenlen-1] = buf[blkinput->linepos]; blkinput->linepos++; } } assert(tokenlen < BLK_MAX_LINELEN); blkinput->token[tokenlen] = '\0'; SCIPdebugMessage("(line %d) read token: '%s'\n", blkinput->linenumber, blkinput->token); return TRUE; }
/** reads the next token from the input file into the token buffer; returns whether a token was read */ static SCIP_Bool getNextToken( SCIP* scip, /**< SCIP data structure */ LPINPUT* lpinput /**< LP reading data */ ) { SCIP_Bool hasdot; LPEXPTYPE exptype; char* buf; int tokenlen; assert(lpinput != NULL); assert(lpinput->linepos < LP_MAX_LINELEN); /* check the token stack */ if( lpinput->npushedtokens > 0 ) { swapPointers(&lpinput->token, &lpinput->pushedtokens[lpinput->npushedtokens-1]); lpinput->npushedtokens--; SCIPdebugMessage("(line %d) read token again: '%s'\n", lpinput->linenumber, lpinput->token); return TRUE; } /* skip delimiters */ buf = lpinput->linebuf; while( isDelimChar(buf[lpinput->linepos]) ) { if( buf[lpinput->linepos] == '\0' ) { if( !getNextLine(scip, lpinput) ) { lpinput->section = LP_END; SCIPdebugMessage("(line %d) end of file\n", lpinput->linenumber); return FALSE; } assert(lpinput->linepos == 0); } else lpinput->linepos++; } assert(lpinput->linepos < LP_MAX_LINELEN); assert(!isDelimChar(buf[lpinput->linepos])); /* check if the token is a value */ hasdot = FALSE; exptype = LP_EXP_NONE; if( isValueChar(buf[lpinput->linepos], buf[lpinput->linepos+1], TRUE, &hasdot, &exptype) ) { /* read value token */ tokenlen = 0; do { assert(tokenlen < LP_MAX_LINELEN); assert(!isDelimChar(buf[lpinput->linepos])); lpinput->token[tokenlen] = buf[lpinput->linepos]; tokenlen++; lpinput->linepos++; } while( isValueChar(buf[lpinput->linepos], buf[lpinput->linepos+1], FALSE, &hasdot, &exptype) ); } else { /* read non-value token */ tokenlen = 0; do { assert(tokenlen < LP_MAX_LINELEN); lpinput->token[tokenlen] = buf[lpinput->linepos]; tokenlen++; lpinput->linepos++; if( tokenlen == 1 && isTokenChar(lpinput->token[0]) ) break; } while( !isDelimChar(buf[lpinput->linepos]) && !isTokenChar(buf[lpinput->linepos]) ); /* if the token is a power sign '^', skip a following '2' * if the token is an equation sense '<', '>', or '=', skip a following '=' * if the token is an equality token '=' and the next character is a '<' or '>', replace the token by the inequality sense */ if( tokenlen >= 1 && lpinput->token[tokenlen-1] == '^' && buf[lpinput->linepos] == '2' ) { lpinput->linepos++; } if( tokenlen >= 1 && (lpinput->token[tokenlen-1] == '<' || lpinput->token[tokenlen-1] == '>' || lpinput->token[tokenlen-1] == '=') && buf[lpinput->linepos] == '=' ) { lpinput->linepos++; } else if( lpinput->token[tokenlen-1] == '=' && (buf[lpinput->linepos] == '<' || buf[lpinput->linepos] == '>') ) { lpinput->token[tokenlen-1] = buf[lpinput->linepos]; lpinput->linepos++; } } assert(tokenlen < LP_MAX_LINELEN); lpinput->token[tokenlen] = '\0'; SCIPdebugMessage("(line %d) read token: '%s'\n", lpinput->linenumber, lpinput->token); return TRUE; }