/* Takes a string path and collapses it to find the absolute path without "." or ".." */ node *collapseFilePath(char *path) { int isQuoted = quotedString(path); if(isQuoted == -1) { printf("Error: File Path string not closed\n"); return NULL; } node *currentNode = NULL; char *checkedStr = NULL; if(!isQuoted) { currentNode = getCurrentPath(); checkedStr = parseString(path); if(checkedStr == NULL) { freePathReverse(currentNode); return NULL; } char *temp = (char *) malloc(strlen(checkedStr) + 8); if(temp == NULL) { printf("ERROR: No memory left to append uni to file path\n"); freePathReverse(currentNode); return NULL; } strncpy(temp, checkedStr, strlen(checkedStr) + 1); strncat(temp, ".jg3538", 8); currentNode = insertNode(currentNode, temp); free(temp); }else { if(path[1] != '/') { currentNode = getCurrentPath(); } path = removeQuotes(path); char temp[strlen(path)+1]; strncpy(temp, path, strlen(path)+1); char *base = basename(temp); if(strncmp(base, "..", 3) == 0 && strlen(base) == 2) { path = (char *) realloc(path, strlen(path) + 9); if(path == NULL) { printf("ERROR: No memory left to append uni to file path\n"); freePathReverse(currentNode); return NULL; } strncat(path, "/.jg3538", 8); }else { path = (char *) realloc(path, strlen(path) + 8); if(path == NULL) { printf("ERROR: No memory left to append uni to file path\n"); freePathReverse(currentNode); return NULL; } strncat(path, ".jg3538", 8); } char *token = strtok(path, "/"); while(token != NULL) { checkedStr = parseQuotedString(token); if(checkedStr == NULL) { freePathReverse(currentNode); free(path); return NULL; } currentNode = insertNode(currentNode, checkedStr); free(checkedStr); token = strtok(NULL, "/"); } free(path); } while(currentNode->prev != NULL) { currentNode = currentNode->prev; } return currentNode; }
static inline int parseSQString(YYSTYPE *lvalp, yyscan_t scanner) { return parseString(lvalp, scanner, '\'', SingleQString); }
int main( int argc, char *argv[] ) { QCoreApplication app( argc, argv ); // --interpolation-method=NearestNeighbor|Bilinear QString outputDirectory; int outputTileLevel = -1; int threadCount = QThread::idealThreadCount(); int clusterSize = 0; // cluster size 0 makes no sense bool onlySimulate = false; QVector<ReadOnlyMapDefinition> mapSources; // input: type, tile-level, base-dir|file // --input,type=NasaWW,tile-level=8,base-directory=<dir>,interpolation-method=Bilinear // --input,type=Image,file=<file> enum { HelpOption = 1, InputOption, OutputDirectoryOption, OutputTileLevelOption, JobsOption, ClusterSizeOption, SimulateOption }; static struct option long_options[] = { {"help", no_argument, NULL, HelpOption }, {"input", required_argument, NULL, InputOption }, {"output-directory", required_argument, NULL, OutputDirectoryOption }, {"output-tile-level", required_argument, NULL, OutputTileLevelOption }, {"jobs", required_argument, NULL, JobsOption }, {"cluster-size", required_argument, NULL, ClusterSizeOption }, {"simulate", no_argument, NULL, SimulateOption }, {0, 0, 0, 0 } }; while ( true ) { int option_index = 0; int const opt = getopt_long( argc, argv, "", long_options, &option_index ); if ( opt == -1 ) break; switch ( opt ) { case HelpOption: printUsage(); exit( EXIT_SUCCESS ); case InputOption: mapSources.push_back( parseInput( optarg )); break; case OutputDirectoryOption: outputDirectory = parseString( optarg ); break; case OutputTileLevelOption: outputTileLevel = parseInt( optarg ); break; case JobsOption: threadCount = parseInt( optarg ); break; case ClusterSizeOption: clusterSize = parseInt( optarg ); break; case SimulateOption: onlySimulate = true; break; case '?': break; } } qDebug() << "\noutput directory:" << outputDirectory << "\noutput tile level:" << outputTileLevel << "\ncluster size:" << clusterSize << "\nthreads:" << threadCount << "\ninputs:" << mapSources; if (onlySimulate) exit( EXIT_SUCCESS ); NasaWorldWindToOpenStreetMapConverter converter; converter.setMapSources( mapSources ); converter.setOsmBaseDirectory( QDir( outputDirectory )); converter.setOsmTileLevel( outputTileLevel ); converter.setOsmTileClusterEdgeLengthTiles( clusterSize ); converter.setThreadCount( threadCount ); QObject::connect( &converter, SIGNAL(finished()), &app, SLOT(quit())); QVector<QPair<Thread*, OsmTileClusterRenderer*> > renderThreads = converter.start(); app.exec(); QVector<QPair<Thread*, OsmTileClusterRenderer*> >::iterator pos = renderThreads.begin(); QVector<QPair<Thread*, OsmTileClusterRenderer*> >::iterator const end = renderThreads.end(); for (; pos != end; ++pos ) { (*pos).first->stop(); (*pos).first->wait(); delete (*pos).second; } return EXIT_SUCCESS; }
QDropboxJson& QDropboxJson::operator=(QDropboxJson& other) { /*!< \todo use toString() */ parseString(other.strContent()); return *this; }
static void readTokenFull (tokenInfo *const token, boolean include_newlines, vString *const repr) { int c; int i; boolean newline_encountered = FALSE; /* if we've got a token held back, emit it */ if (NextToken) { copyToken (token, NextToken, FALSE); deleteToken (NextToken); NextToken = NULL; return; } token->type = TOKEN_UNDEFINED; token->keyword = KEYWORD_NONE; vStringClear (token->string); getNextChar: i = 0; do { c = getcFromInputFile (); if (include_newlines && (c == '\r' || c == '\n')) newline_encountered = TRUE; i++; } while (c == '\t' || c == ' ' || c == '\r' || c == '\n'); token->lineNumber = getInputLineNumber (); token->filePosition = getInputFilePosition (); if (repr) { if (i > 1) vStringPut (repr, ' '); vStringPut (repr, c); } switch (c) { case EOF: token->type = TOKEN_EOF; break; case '(': token->type = TOKEN_OPEN_PAREN; break; case ')': token->type = TOKEN_CLOSE_PAREN; break; case ';': token->type = TOKEN_SEMICOLON; break; case ',': token->type = TOKEN_COMMA; break; case '.': token->type = TOKEN_PERIOD; break; case ':': token->type = TOKEN_COLON; break; case '{': token->type = TOKEN_OPEN_CURLY; break; case '}': token->type = TOKEN_CLOSE_CURLY; break; case '=': token->type = TOKEN_EQUAL_SIGN; break; case '[': token->type = TOKEN_OPEN_SQUARE; break; case ']': token->type = TOKEN_CLOSE_SQUARE; break; case '+': case '-': { int d = getcFromInputFile (); if (d == c) /* ++ or -- */ token->type = TOKEN_POSTFIX_OPERATOR; else { ungetcToInputFile (d); token->type = TOKEN_BINARY_OPERATOR; } break; } case '*': case '%': case '?': case '>': case '<': case '^': case '|': case '&': token->type = TOKEN_BINARY_OPERATOR; break; case '\'': case '"': token->type = TOKEN_STRING; parseString (token->string, c); token->lineNumber = getInputLineNumber (); token->filePosition = getInputFilePosition (); if (repr) { vStringCat (repr, token->string); vStringPut (repr, c); } break; case '`': token->type = TOKEN_TEMPLATE_STRING; parseTemplateString (token->string); token->lineNumber = getInputLineNumber (); token->filePosition = getInputFilePosition (); if (repr) { vStringCat (repr, token->string); vStringPut (repr, c); } break; case '\\': c = getcFromInputFile (); if (c != '\\' && c != '"' && !isspace (c)) ungetcToInputFile (c); token->type = TOKEN_CHARACTER; token->lineNumber = getInputLineNumber (); token->filePosition = getInputFilePosition (); break; case '/': { int d = getcFromInputFile (); if ( (d != '*') && /* is this the start of a comment? */ (d != '/') ) /* is a one line comment? */ { ungetcToInputFile (d); switch (LastTokenType) { case TOKEN_CHARACTER: case TOKEN_IDENTIFIER: case TOKEN_STRING: case TOKEN_TEMPLATE_STRING: case TOKEN_CLOSE_CURLY: case TOKEN_CLOSE_PAREN: case TOKEN_CLOSE_SQUARE: token->type = TOKEN_BINARY_OPERATOR; break; default: token->type = TOKEN_REGEXP; parseRegExp (); token->lineNumber = getInputLineNumber (); token->filePosition = getInputFilePosition (); break; } } else { if (repr) /* remove the / we added */ repr->buffer[--repr->length] = 0; if (d == '*') { do { skipToCharacterInInputFile ('*'); c = getcFromInputFile (); if (c == '/') break; else ungetcToInputFile (c); } while (c != EOF && c != '\0'); goto getNextChar; } else if (d == '/') /* is this the start of a comment? */ { skipToCharacterInInputFile ('\n'); /* if we care about newlines, put it back so it is seen */ if (include_newlines) ungetcToInputFile ('\n'); goto getNextChar; } } break; } case '#': /* skip shebang in case of e.g. Node.js scripts */ if (token->lineNumber > 1) token->type = TOKEN_UNDEFINED; else if ((c = getcFromInputFile ()) != '!') { ungetcToInputFile (c); token->type = TOKEN_UNDEFINED; } else { skipToCharacterInInputFile ('\n'); goto getNextChar; } break; default: if (! isIdentChar (c)) token->type = TOKEN_UNDEFINED; else { parseIdentifier (token->string, c); token->lineNumber = getInputLineNumber (); token->filePosition = getInputFilePosition (); token->keyword = analyzeToken (token->string, Lang_js); if (isKeyword (token, KEYWORD_NONE)) token->type = TOKEN_IDENTIFIER; else token->type = TOKEN_KEYWORD; if (repr && vStringLength (token->string) > 1) vStringCatS (repr, vStringValue (token->string) + 1); } break; } if (include_newlines && newline_encountered) { /* This isn't strictly correct per the standard, but following the * real rules means understanding all statements, and that's not * what the parser currently does. What we do here is a guess, by * avoiding inserting semicolons that would make the statement on * the left or right obviously invalid. Hopefully this should not * have false negatives (e.g. should not miss insertion of a semicolon) * but might have false positives (e.g. it will wrongfully emit a * semicolon sometimes, i.e. for the newline in "foo\n(bar)"). * This should however be mostly harmless as we only deal with * newlines in specific situations where we know a false positive * wouldn't hurt too bad. */ /* these already end a statement, so no need to duplicate it */ #define IS_STMT_SEPARATOR(t) ((t) == TOKEN_SEMICOLON || \ (t) == TOKEN_EOF || \ (t) == TOKEN_COMMA || \ (t) == TOKEN_CLOSE_CURLY || \ (t) == TOKEN_OPEN_CURLY) /* these cannot be the start or end of a statement */ #define IS_BINARY_OPERATOR(t) ((t) == TOKEN_EQUAL_SIGN || \ (t) == TOKEN_COLON || \ (t) == TOKEN_PERIOD || \ (t) == TOKEN_BINARY_OPERATOR) if (! IS_STMT_SEPARATOR(LastTokenType) && ! IS_STMT_SEPARATOR(token->type) && ! IS_BINARY_OPERATOR(LastTokenType) && ! IS_BINARY_OPERATOR(token->type) && /* these cannot be followed by a semicolon */ ! (LastTokenType == TOKEN_OPEN_PAREN || LastTokenType == TOKEN_OPEN_SQUARE)) { /* hold the token... */ Assert (NextToken == NULL); NextToken = newToken (); copyToken (NextToken, token, FALSE); /* ...and emit a semicolon instead */ token->type = TOKEN_SEMICOLON; token->keyword = KEYWORD_NONE; vStringClear (token->string); if (repr) vStringPut (token->string, '\n'); } #undef IS_STMT_SEPARATOR #undef IS_BINARY_OPERATOR } LastTokenType = token->type; }
void Editor::autoCalc() { if( !d->autoCalcEnabled ) return; QString str = Evaluator::autoFix( text() ); if( str.isEmpty() ) return; // too short? do not bother... Tokens tokens = Evaluator::scan( str ); if( tokens.count() < 2 ) return; // If we're using set for a function don't try. QRegExp setFn("\\s*set.*\\(.*="); if( str.find(setFn) != -1 ) return; // strip off assignment operator, e.g. "x=1+2" becomes "1+2" only // the reason is that we want only to evaluate (on the fly) the expression, // not to update (put the result in) the variable if( tokens.count() > 2 && tokens[0].isIdentifier() && tokens[1].asOperator() == Token::Equal ) { Tokens::const_iterator it = tokens.begin(); ++it; ++it; // Skip first two tokens. // Reconstruct string to evaluate using the tokens. str = ""; while(it != tokens.end()) { str += (*it).text(); str += ' '; ++it; } } Abakus::number_t result = parseString(str.latin1()); if( Result::lastResult()->type() == Result::Value ) { QString ss = i18n("Result: <b>%2</b>", result.toString()); d->autoCalcLabel->setText( ss ); d->autoCalcLabel->adjustSize(); // reposition nicely QPoint pos = mapToGlobal( QPoint( 0, 0 ) ); pos.setY( pos.y() - d->autoCalcLabel->height() - 1 ); d->autoCalcLabel->move( pos ); d->autoCalcLabel->show(); d->autoCalcLabel->raise(); // do not show it forever QTimer::singleShot( 5000, d->autoCalcLabel, SLOT( hide()) ); } else { // invalid expression d->autoCalcLabel->hide(); } }
QDropboxJson::QDropboxJson(QString strJson, QObject *parent) : QObject(parent) { _init(); parseString(strJson); }
/** * Parses a string which may either be enclosed by " or ', unescapes * entities in the string as specified for JavaScript. * * @param reader is a reference to the CharReader instance which is * the source for the character data. The reader will be positioned after * the terminating quote character. * @param logger is the logger instance that should be used to log error * messages and warnings. */ static std::pair<bool, std::string> parseString(CharReader &reader, Logger &logger) { return parseString(reader, logger, nullptr); }
std::unique_ptr<SEXPR> PARSER::Parse( const std::string& aString ) { std::string::const_iterator it = aString.begin(); return parseString( aString, it ); }
/* mainFunction method {{{ */ int mainFunction(ConfigMap &config) { if(config.find("general::equation")==config.end()) { cerr << "[E] No problem defined!" << endl; return -1; } cerr << "[I] Initializing problem...\n"; Expression *eqn=parseString(config["general::equation"]); Expression *pot=parseString(config["general::potential"]); cerr << "[I] Equation: " << eqn << endl; cerr << "[I] Potential: " << pot << endl; VarDef params; cerr << "[I] Getting parameters:\n"; for(ConfigMap::iterator it=config.begin();it!=config.end();it++) { if((it->first).find("parameters::")!=string::npos) { string name=(it->first).substr(12); params[name]=parseString(it->second); cerr << "[I]\t" << name << "=" << it->second << "\n"; } } cerr.flush(); eqn=eqn->simplify(params); pot=pot->simplify(params); GPE *gpe=0; if(pot->find("X")) { if(pot->find("Y")) { if(pot->find("Z")) { if(eqn->find("LZ")) gpe=new GPE3DROT(config,eqn,pot); else gpe=new GPE3D(config,eqn,pot); } else { if(eqn->find("LZ")) gpe=new GPE2DROT(config,eqn,pot); else gpe=new GPE2D(config,eqn,pot); } } else gpe=new GPE1D(config,eqn,pot); } else if(eqn->find("R")) gpe=new Polar1D(config,eqn,pot); if(gpe==0) { cerr << "[E] Unknown problem type!" << std::endl; return -1; } gpe->initialize(pot); if(config["in"].size()>0) { gpe->load(config["in"]); } string out="psi1.dat"; if(config["out"].size()>0) { out=config["out"]; } string log=""; if(config.find("log")!=config.end()) { log="log.txt"; if(config["log"].size()>0) { log=config["log"]; } } if(config.find("imprint")!=config.end()) { int l=getConfig(config,string("imprint"),1); std::cerr << "[I] Imprinting a l=" << l << " circulation" << endl; gpe->imprint(l); } if(config.find("groundstate")!=config.end()) { double dt=getConfig(config,string("general::dt"),1e-3); double tol=getConfig(config,string("general::tol"),1e-12); double dttol=getConfig(config,string("general::dttol"),0.999); gpe->findGroundState(dt,tol,dttol,log); gpe->save(out); } if(config.find("spectrum")!=config.end()) { range<int> def={0,0,1}; range<int> m=getConfig(config,string("spectrum"),def); for(int i=m.min;i<=m.max;i+=m.incr) gpe->spectrum(log,i); } if(config.find("evolve")!=config.end()) { range<double> def={0.,1.,1e-3}; range<double> t=getConfig(config,string("evolve"),def); gpe->evolve(t.min,t.incr,t.max,out); } if(config.find("plot")!=config.end()) { int n=5; //getConfig(config,string("plot"),0); gpe->plot(n,config["plot"]); } if(config.find("measure")!=config.end()) { std::cout << gpe->measure() << std::endl; } return 0; };
/** * Parses a string which may either be enclosed by " or ', unescapes * entities in the string as specified for JavaScript. * * @param reader is a reference to the CharReader instance which is * the source for the character data. The reader will be positioned after * the terminating quote character or at the terminating delimiting * character. * @param logger is the logger instance that should be used to log error * messages and warnings. * @param delims is a set of delimiters after which parsing has to * be stopped (the delimiters may occur inside the actual string, but not * outside). */ static std::pair<bool, std::string> parseString( CharReader &reader, Logger &logger, const std::unordered_set<char> &delims) { return parseString(reader, logger, &delims); }
int parseConfigFile( char *filename ) { FILE *fp; char line[MAX_LINE+1], *cur; int parse, i; /* Initialize the operating configuration structures */ bzero( &feed, sizeof(feed) ); bzero( monitors, sizeof(monitors) ); /* Open the filename defined by the caller */ fp = fopen(filename, "r"); if (fp == NULL) return -1; /* Walk through each line of the file until the end */ while( !feof(fp) ) { /* Get a line from the file */ fgets( line, MAX_LINE, fp ); /* If we've reached the end, break */ if (feof(fp)) break; /* If the line is a comment or blank, continue to get the next line */ if (line[0] == '#') continue; else if (line[0] == 0x0a) continue; /* Check the configuration file markers, when one is found, change the * parsing state accordingly. */ if (!strncmp(line, "[monitor]", 9)) { parse = MONITOR_PARSE; } else if (!strncmp(line, "[feeds]", 7)) { parse = FEEDS_PARSE; } else if (!strncmp(line, "[groups]", 8)) { parse = GROUPS_PARSE; } else { if (parse == MONITOR_PARSE) { /* For monitor parsing, we're looking or URLS. These must be * preceded by the 'http://' protocol specification. We parse * the URL and then the subsequent strings separately. */ if (!strncmp(line, "http://", 7)) { cur = parseURLorGroup( line, monitors[curMonitor].url ); parseString( cur, monitors[curMonitor].urlName ); monitors[curMonitor].active = 1; curMonitor++; } else return -1; } else if (parse == FEEDS_PARSE) { /* For feeds parsing, we're looking for an NNTP server URL */ if (!strncmp(line, "nntp://", 7)) { cur = parseURLorGroup( line, feed.url ); } else return -1; } else if (parse == GROUPS_PARSE) { /* For groups parsing, we're looking for a URL and then a set of * search strings. */ cur = parseURLorGroup( line, feed.groups[curGroup].groupName ); i = 0; while (*cur) { cur = parseString( cur, feed.groups[curGroup].searchString[i] ); if (strlen(feed.groups[curGroup].searchString[i])) i++; if (i == MAX_SEARCH_STRINGS) break; } feed.groups[curGroup].numSearchStrings = i; feed.groups[curGroup].active = 1; curGroup++; } } } /* Now that we've read the configuration file, read the group status file * to preload the last message read (for any groups that are in both the * configuration file and group status file). */ readGroupStatus(); #if 1 { int i, j; for (i = 0 ; i < curMonitor ; i++) { printf("Monitor %s [%s]\n", monitors[i].url, monitors[i].urlName); } printf("feed %s\n", feed.url); for (i = 0 ; i < curGroup ; i++) { if (feed.groups[i].active) { printf("group %s", feed.groups[i].groupName); printf(" -- search strings : "); for (j = 0 ; j < MAX_SEARCH_STRINGS ; j++) { if (strlen(feed.groups[i].searchString[j])) printf("%s ", feed.groups[i].searchString[j]); } printf("\n"); } } } #endif return 0; }
bool parseString(const std::string& input, TYPE* output) { return parseString(input.c_str(), output); }
static void parseParamaterBlock(char** strPtr, drawtextstate_t* state, int* numBreaks) { (*strPtr)++; while(*(*strPtr) && *(*strPtr) != '}') { (*strPtr) = M_SkipWhite((*strPtr)); // What do we have here? if(!strnicmp((*strPtr), "flash", 5)) { (*strPtr) += 5; state->typeIn = true; } else if(!strnicmp((*strPtr), "noflash", 7)) { (*strPtr) += 7; state->typeIn = false; } else if(!strnicmp((*strPtr), "case", 4)) { (*strPtr) += 4; state->caseScale = true; } else if(!strnicmp((*strPtr), "nocase", 6)) { (*strPtr) += 6; state->caseScale = false; } else if(!strnicmp((*strPtr), "ups", 3)) { (*strPtr) += 3; state->caseMod[1].scale = parseFloat(&(*strPtr)); } else if(!strnicmp((*strPtr), "upo", 3)) { (*strPtr) += 3; state->caseMod[1].offset = parseFloat(&(*strPtr)); } else if(!strnicmp((*strPtr), "los", 3)) { (*strPtr) += 3; state->caseMod[0].scale = parseFloat(&(*strPtr)); } else if(!strnicmp((*strPtr), "loo", 3)) { (*strPtr) += 3; state->caseMod[0].offset = parseFloat(&(*strPtr)); } else if(!strnicmp((*strPtr), "break", 5)) { (*strPtr) += 5; ++(*numBreaks); } else if(!strnicmp((*strPtr), "r", 1)) { (*strPtr)++; state->rgba[CR] = parseFloat(&(*strPtr)); } else if(!strnicmp((*strPtr), "g", 1)) { (*strPtr)++; state->rgba[CG] = parseFloat(&(*strPtr)); } else if(!strnicmp((*strPtr), "b", 1)) { (*strPtr)++; state->rgba[CB] = parseFloat(&(*strPtr)); } else if(!strnicmp((*strPtr), "a", 1)) { (*strPtr)++; state->rgba[CA] = parseFloat(&(*strPtr)); } else if(!strnicmp((*strPtr), "x", 1)) { (*strPtr)++; state->offX = parseFloat(&(*strPtr)); } else if(!strnicmp((*strPtr), "y", 1)) { (*strPtr)++; state->offY = parseFloat(&(*strPtr)); } else if(!strnicmp((*strPtr), "scalex", 6)) { (*strPtr) += 6; state->scaleX = parseFloat(&(*strPtr)); } else if(!strnicmp((*strPtr), "scaley", 6)) { (*strPtr) += 6; state->scaleY = parseFloat(&(*strPtr)); } else if(!strnicmp((*strPtr), "scale", 5)) { (*strPtr) += 5; state->scaleX = state->scaleY = parseFloat(&(*strPtr)); } else if(!strnicmp((*strPtr), "angle", 5)) { (*strPtr) += 5; state->angle = parseFloat(&(*strPtr)); } else if(!strnicmp((*strPtr), "glitter", 7)) { (*strPtr) += 7; state->glitterStrength = parseFloat(&(*strPtr)); } else if(!strnicmp((*strPtr), "shadow", 6)) { (*strPtr) += 6; state->shadowStrength = parseFloat(&(*strPtr)); } else if(!strnicmp((*strPtr), "tracking", 8)) { (*strPtr) += 8; state->tracking = parseFloat(&(*strPtr)); } else { // Perhaps a font name? fontid_t fontId; if(!strnicmp((*strPtr), "font", 4)) { char buf[80]; (*strPtr) += 4; if(parseString(&(*strPtr), buf, 80)) { Uri* uri = Uri_NewWithPath2(buf, RC_NULL); fontId = Fonts_ResolveUri2(uri, true/*quiet please*/); Uri_Delete(uri); if(fontId != NOFONTID) { state->fontNum = fontId; continue; } } Con_Message("Warning:parseParamaterBlock: Unknown font '%s'.", (*strPtr)); continue; } // Unknown, skip it. if(*(*strPtr) != '}') (*strPtr)++; } } // Skip over the closing brace. if(*(*strPtr)) (*strPtr)++; }
ParserGridDistribution( const std::string s ) { parseString( s ); }
std::unique_ptr<SEXPR> PARSER::parseString( const std::string& aString, std::string::const_iterator& it ) { for( ; it != aString.end(); ++it ) { if( *it == '\n' ) m_lineNumber++; if( whitespaceCharacters.find(*it) != std::string::npos ) continue; if( *it == '(' ) { std::advance( it, 1 ); auto list = std::make_unique<SEXPR_LIST>( m_lineNumber ); while( it != aString.end() && *it != ')' ) { //there may be newlines in between atoms of a list, so detect these here if( *it == '\n' ) m_lineNumber++; if( whitespaceCharacters.find(*it) != std::string::npos ) { std::advance( it, 1 ); continue; } std::unique_ptr<SEXPR> item = parseString( aString, it ); list->AddChild( item.release() ); } if( it != aString.end() ) std::advance( it, 1 ); return list; } else if( *it == ')' ) { return NULL; } else if( *it == '"' ) { size_t startPos = std::distance(aString.begin(), it) + 1; size_t closingPos = startPos > 0 ? startPos - 1 : startPos; // find the closing quote character, be sure it is not escaped do { closingPos = aString.find_first_of( '"', closingPos + 1 ); } while( closingPos != std::string::npos && ( closingPos > 0 && aString[closingPos - 1] == '\\' ) ); if( closingPos != std::string::npos ) { auto str = std::make_unique<SEXPR_STRING>( aString.substr( startPos, closingPos - startPos ), m_lineNumber ); std::advance( it, closingPos - startPos + 2 ); return str; } else { throw PARSE_EXCEPTION("missing closing quote"); } } else { size_t startPos = std::distance( aString.begin(), it ); size_t closingPos = aString.find_first_of( whitespaceCharacters + "()", startPos ); std::string tmp = aString.substr( startPos, closingPos - startPos ); if( closingPos != std::string::npos ) { if( tmp.find_first_not_of( "0123456789." ) == std::string::npos || ( tmp.size() > 1 && tmp[0] == '-' && tmp.find_first_not_of( "0123456789.", 1 ) == std::string::npos ) ) { std::unique_ptr<SEXPR> res; if( tmp.find( '.' ) != std::string::npos ) { res = std::make_unique<SEXPR_DOUBLE>( strtod( tmp.c_str(), nullptr ), m_lineNumber ); //floating point type } else { res = std::make_unique<SEXPR_INTEGER>( strtoll( tmp.c_str(), nullptr, 0 ), m_lineNumber ); } std::advance( it, closingPos - startPos ); return res; } else { auto str = std::make_unique<SEXPR_SYMBOL>( tmp, m_lineNumber ); std::advance( it, closingPos - startPos ); return str; } } else { throw PARSE_EXCEPTION( "format error" ); } } } return nullptr; }
static void readToken (tokenInfo *const token) { int c; token->type = TOKEN_UNDEFINED; token->keyword = KEYWORD_NONE; vStringClear (token->string); getNextChar: do { c = fileGetc (); } while (c == '\t' || c == ' ' || c == '\n'); token->lineNumber = getSourceLineNumber (); token->filePosition = getInputFilePosition (); switch (c) { case EOF: longjmp (Exception, (int)ExceptionEOF); break; case '(': token->type = TOKEN_OPEN_PAREN; break; case ')': token->type = TOKEN_CLOSE_PAREN; break; case ';': token->type = TOKEN_SEMICOLON; break; case ',': token->type = TOKEN_COMMA; break; case '.': token->type = TOKEN_PERIOD; break; case ':': token->type = TOKEN_COLON; break; case '{': token->type = TOKEN_OPEN_CURLY; break; case '}': token->type = TOKEN_CLOSE_CURLY; break; case '=': token->type = TOKEN_EQUAL_SIGN; break; case '[': token->type = TOKEN_OPEN_SQUARE; break; case ']': token->type = TOKEN_CLOSE_SQUARE; break; case '\'': case '"': token->type = TOKEN_STRING; parseString (token->string, c); token->lineNumber = getSourceLineNumber (); token->filePosition = getInputFilePosition (); break; case '\\': c = fileGetc (); if (c != '\\' && c != '"' && !isspace (c)) fileUngetc (c); token->type = TOKEN_CHARACTER; token->lineNumber = getSourceLineNumber (); token->filePosition = getInputFilePosition (); break; case '/': { int d = fileGetc (); if ( (d != '*') && /* is this the start of a comment? */ (d != '/') ) /* is a one line comment? */ { fileUngetc (d); switch (LastTokenType) { case TOKEN_CHARACTER: case TOKEN_KEYWORD: case TOKEN_IDENTIFIER: case TOKEN_STRING: case TOKEN_CLOSE_CURLY: case TOKEN_CLOSE_PAREN: case TOKEN_CLOSE_SQUARE: token->type = TOKEN_FORWARD_SLASH; break; default: token->type = TOKEN_REGEXP; parseRegExp (); token->lineNumber = getSourceLineNumber (); token->filePosition = getInputFilePosition (); break; } } else { if (d == '*') { do { fileSkipToCharacter ('*'); c = fileGetc (); if (c == '/') break; else fileUngetc (c); } while (c != EOF && c != '\0'); goto getNextChar; } else if (d == '/') /* is this the start of a comment? */ { fileSkipToCharacter ('\n'); goto getNextChar; } } break; } default: if (! isIdentChar (c)) token->type = TOKEN_UNDEFINED; else { parseIdentifier (token->string, c); token->lineNumber = getSourceLineNumber (); token->filePosition = getInputFilePosition (); token->keyword = analyzeToken (token->string, Lang_js); if (isKeyword (token, KEYWORD_NONE)) token->type = TOKEN_IDENTIFIER; else token->type = TOKEN_KEYWORD; } break; } LastTokenType = token->type; }
void parseVariant(proto_tree *tree, tvbuff_t *tvb, gint *pOffset, const char *szFieldName) { proto_item *ti = proto_tree_add_text(tree, tvb, *pOffset, -1, "%s: Variant", szFieldName); proto_tree *subtree = proto_item_add_subtree(ti, ett_opcua_variant); gint iOffset = *pOffset; guint8 EncodingMask; gint32 ArrayDimensions = 0; EncodingMask = tvb_get_guint8(tvb, iOffset); proto_tree_add_item(subtree, hf_opcua_variant_encodingmask, tvb, iOffset, 1, ENC_LITTLE_ENDIAN); iOffset++; if (EncodingMask & VARIANT_ARRAYMASK) { /* type is encoded in bits 0-5 */ switch(EncodingMask & 0x3f) { case OpcUaType_Null: break; case OpcUaType_Boolean: parseArraySimple(subtree, tvb, &iOffset, hf_opcua_Boolean, parseBoolean); break; case OpcUaType_SByte: parseArraySimple(subtree, tvb, &iOffset, hf_opcua_SByte, parseSByte); break; case OpcUaType_Byte: parseArraySimple(subtree, tvb, &iOffset, hf_opcua_Byte, parseByte); break; case OpcUaType_Int16: parseArraySimple(subtree, tvb, &iOffset, hf_opcua_Int16, parseInt16); break; case OpcUaType_UInt16: parseArraySimple(subtree, tvb, &iOffset, hf_opcua_UInt16, parseUInt16); break; case OpcUaType_Int32: parseArraySimple(subtree, tvb, &iOffset, hf_opcua_Int32, parseInt32); break; case OpcUaType_UInt32: parseArraySimple(subtree, tvb, &iOffset, hf_opcua_UInt32, parseUInt32); break; case OpcUaType_Int64: parseArraySimple(subtree, tvb, &iOffset, hf_opcua_Int64, parseInt64); break; case OpcUaType_UInt64: parseArraySimple(subtree, tvb, &iOffset, hf_opcua_UInt64, parseUInt64); break; case OpcUaType_Float: parseArraySimple(subtree, tvb, &iOffset, hf_opcua_Float, parseFloat); break; case OpcUaType_Double: parseArraySimple(subtree, tvb, &iOffset, hf_opcua_Double, parseDouble); break; case OpcUaType_String: parseArraySimple(subtree, tvb, &iOffset, hf_opcua_String, parseString); break; case OpcUaType_DateTime: parseArraySimple(subtree, tvb, &iOffset, hf_opcua_DateTime, parseDateTime); break; case OpcUaType_Guid: parseArraySimple(subtree, tvb, &iOffset, hf_opcua_Guid, parseGuid); break; case OpcUaType_ByteString: parseArraySimple(subtree, tvb, &iOffset, hf_opcua_ByteString, parseByteString); break; case OpcUaType_XmlElement: parseArraySimple(subtree, tvb, &iOffset, hf_opcua_XmlElement, parseXmlElement); break; case OpcUaType_NodeId: parseArrayComplex(subtree, tvb, &iOffset, "NodeId", parseNodeId); break; case OpcUaType_ExpandedNodeId: parseArrayComplex(subtree, tvb, &iOffset, "ExpandedNodeId", parseExpandedNodeId); break; case OpcUaType_StatusCode: parseArraySimple(subtree, tvb, &iOffset, hf_opcua_StatusCode, parseStatusCode); break; case OpcUaType_DiagnosticInfo: parseArrayComplex(subtree, tvb, &iOffset, "DiagnosticInfo", parseDiagnosticInfo); break; case OpcUaType_QualifiedName: parseArrayComplex(subtree, tvb, &iOffset, "QualifiedName", parseQualifiedName); break; case OpcUaType_LocalizedText: parseArrayComplex(subtree, tvb, &iOffset, "LocalizedText", parseLocalizedText); break; case OpcUaType_ExtensionObject: parseArrayComplex(subtree, tvb, &iOffset, "ExtensionObject", parseExtensionObject); break; case OpcUaType_DataValue: parseArrayComplex(subtree, tvb, &iOffset, "DataValue", parseDataValue); break; case OpcUaType_Variant: parseArrayComplex(subtree, tvb, &iOffset, "Variant", parseVariant); break; } if (EncodingMask & VARIANT_ARRAYDIMENSIONS) { proto_item *ti_2 = proto_tree_add_text(subtree, tvb, iOffset, -1, "ArrayDimensions"); proto_tree *subtree_2 = proto_item_add_subtree(ti_2, ett_opcua_array); int i; /* read array length */ ArrayDimensions = tvb_get_letohl(tvb, iOffset); proto_tree_add_item(subtree_2, hf_opcua_ArraySize, tvb, iOffset, 4, ENC_LITTLE_ENDIAN); if (ArrayDimensions > MAX_ARRAY_LEN) { proto_item *pi; pi = proto_tree_add_text(subtree_2, tvb, iOffset, 4, "ArrayDimensions length %d too large to process", ArrayDimensions); PROTO_ITEM_SET_GENERATED(pi); return; } iOffset += 4; for (i=0; i<ArrayDimensions; i++) { parseInt32(subtree_2, tvb, &iOffset, hf_opcua_Int32); } proto_item_set_end(ti_2, tvb, iOffset); } } else { /* type is encoded in bits 0-5 */ switch(EncodingMask & 0x3f) { case OpcUaType_Null: break; case OpcUaType_Boolean: parseBoolean(subtree, tvb, &iOffset, hf_opcua_Boolean); break; case OpcUaType_SByte: parseSByte(subtree, tvb, &iOffset, hf_opcua_SByte); break; case OpcUaType_Byte: parseByte(subtree, tvb, &iOffset, hf_opcua_Byte); break; case OpcUaType_Int16: parseInt16(subtree, tvb, &iOffset, hf_opcua_Int16); break; case OpcUaType_UInt16: parseUInt16(subtree, tvb, &iOffset, hf_opcua_UInt16); break; case OpcUaType_Int32: parseInt32(subtree, tvb, &iOffset, hf_opcua_Int32); break; case OpcUaType_UInt32: parseUInt32(subtree, tvb, &iOffset, hf_opcua_UInt32); break; case OpcUaType_Int64: parseInt64(subtree, tvb, &iOffset, hf_opcua_Int64); break; case OpcUaType_UInt64: parseUInt64(subtree, tvb, &iOffset, hf_opcua_UInt64); break; case OpcUaType_Float: parseFloat(subtree, tvb, &iOffset, hf_opcua_Float); break; case OpcUaType_Double: parseDouble(subtree, tvb, &iOffset, hf_opcua_Double); break; case OpcUaType_String: parseString(subtree, tvb, &iOffset, hf_opcua_String); break; case OpcUaType_DateTime: parseDateTime(subtree, tvb, &iOffset, hf_opcua_DateTime); break; case OpcUaType_Guid: parseGuid(subtree, tvb, &iOffset, hf_opcua_Guid); break; case OpcUaType_ByteString: parseByteString(subtree, tvb, &iOffset, hf_opcua_ByteString); break; case OpcUaType_XmlElement: parseXmlElement(subtree, tvb, &iOffset, hf_opcua_XmlElement); break; case OpcUaType_NodeId: parseNodeId(subtree, tvb, &iOffset, "Value"); break; case OpcUaType_ExpandedNodeId: parseExpandedNodeId(subtree, tvb, &iOffset, "Value"); break; case OpcUaType_StatusCode: parseStatusCode(subtree, tvb, &iOffset, hf_opcua_StatusCode); break; case OpcUaType_DiagnosticInfo: parseDiagnosticInfo(subtree, tvb, &iOffset, "Value"); break; case OpcUaType_QualifiedName: parseQualifiedName(subtree, tvb, &iOffset, "Value"); break; case OpcUaType_LocalizedText: parseLocalizedText(subtree, tvb, &iOffset, "Value"); break; case OpcUaType_ExtensionObject: parseExtensionObject(subtree, tvb, &iOffset, "Value"); break; case OpcUaType_DataValue: parseDataValue(subtree, tvb, &iOffset, "Value"); break; case OpcUaType_Variant: parseVariant(subtree, tvb, &iOffset, "Value"); break; } } proto_item_set_end(ti, tvb, iOffset); *pOffset = iOffset; }
static void readTokenFull (tokenInfo *const token, boolean include_newlines, vString *const repr) { int c; int i; token->type = TOKEN_UNDEFINED; token->keyword = KEYWORD_NONE; vStringClear (token->string); getNextChar: i = 0; do { c = fileGetc (); i++; } while (c == '\t' || c == ' ' || ((c == '\r' || c == '\n') && ! include_newlines)); token->lineNumber = getSourceLineNumber (); token->filePosition = getInputFilePosition (); if (repr) { if (i > 1) vStringPut (repr, ' '); vStringPut (repr, c); } switch (c) { case EOF: token->type = TOKEN_EOF; break; case '(': token->type = TOKEN_OPEN_PAREN; break; case ')': token->type = TOKEN_CLOSE_PAREN; break; case ';': token->type = TOKEN_SEMICOLON; break; case ',': token->type = TOKEN_COMMA; break; case '.': token->type = TOKEN_PERIOD; break; case ':': token->type = TOKEN_COLON; break; case '{': token->type = TOKEN_OPEN_CURLY; break; case '}': token->type = TOKEN_CLOSE_CURLY; break; case '=': token->type = TOKEN_EQUAL_SIGN; break; case '[': token->type = TOKEN_OPEN_SQUARE; break; case ']': token->type = TOKEN_CLOSE_SQUARE; break; case '+': case '-': { int d = fileGetc (); if (d == c) /* ++ or -- */ token->type = TOKEN_POSTFIX_OPERATOR; else { fileUngetc (d); token->type = TOKEN_BINARY_OPERATOR; } break; } case '*': case '%': case '?': case '>': case '<': case '^': case '|': case '&': token->type = TOKEN_BINARY_OPERATOR; break; case '\r': case '\n': /* This isn't strictly correct per the standard, but following the * real rules means understanding all statements, and that's not * what the parser currently does. What we do here is a guess, by * avoiding inserting semicolons that would make the statement on * the left invalid. Hopefully this should not have false negatives * (e.g. should not miss insertion of a semicolon) but might have * false positives (e.g. it will wrongfully emit a semicolon for the * newline in "foo\n+bar"). * This should however be mostly harmless as we only deal with * newlines in specific situations where we know a false positive * wouldn't hurt too bad. */ switch (LastTokenType) { /* these cannot be the end of a statement, so hold the newline */ case TOKEN_EQUAL_SIGN: case TOKEN_COLON: case TOKEN_PERIOD: case TOKEN_FORWARD_SLASH: case TOKEN_BINARY_OPERATOR: /* and these already end one, no need to duplicate it */ case TOKEN_SEMICOLON: case TOKEN_COMMA: case TOKEN_CLOSE_CURLY: case TOKEN_OPEN_CURLY: include_newlines = FALSE; /* no need to recheck */ goto getNextChar; break; default: token->type = TOKEN_SEMICOLON; } break; case '\'': case '"': token->type = TOKEN_STRING; parseString (token->string, c); token->lineNumber = getSourceLineNumber (); token->filePosition = getInputFilePosition (); if (repr) { vStringCat (repr, token->string); vStringPut (repr, c); } break; case '\\': c = fileGetc (); if (c != '\\' && c != '"' && !isspace (c)) fileUngetc (c); token->type = TOKEN_CHARACTER; token->lineNumber = getSourceLineNumber (); token->filePosition = getInputFilePosition (); break; case '/': { int d = fileGetc (); if ( (d != '*') && /* is this the start of a comment? */ (d != '/') ) /* is a one line comment? */ { fileUngetc (d); switch (LastTokenType) { case TOKEN_CHARACTER: case TOKEN_IDENTIFIER: case TOKEN_STRING: case TOKEN_CLOSE_CURLY: case TOKEN_CLOSE_PAREN: case TOKEN_CLOSE_SQUARE: token->type = TOKEN_FORWARD_SLASH; break; default: token->type = TOKEN_REGEXP; parseRegExp (); token->lineNumber = getSourceLineNumber (); token->filePosition = getInputFilePosition (); break; } } else { if (repr) /* remove the / we added */ repr->buffer[--repr->length] = 0; if (d == '*') { do { skipToCharacter ('*'); c = fileGetc (); if (c == '/') break; else fileUngetc (c); } while (c != EOF && c != '\0'); goto getNextChar; } else if (d == '/') /* is this the start of a comment? */ { skipToCharacter ('\n'); /* if we care about newlines, put it back so it is seen */ if (include_newlines) fileUngetc ('\n'); goto getNextChar; } } break; } case '#': /* skip shebang in case of e.g. Node.js scripts */ if (token->lineNumber > 1) token->type = TOKEN_UNDEFINED; else if ((c = fileGetc ()) != '!') { fileUngetc (c); token->type = TOKEN_UNDEFINED; } else { skipToCharacter ('\n'); goto getNextChar; } break; default: if (! isIdentChar (c)) token->type = TOKEN_UNDEFINED; else { parseIdentifier (token->string, c); token->lineNumber = getSourceLineNumber (); token->filePosition = getInputFilePosition (); token->keyword = analyzeToken (token->string); if (isKeyword (token, KEYWORD_NONE)) token->type = TOKEN_IDENTIFIER; else token->type = TOKEN_KEYWORD; if (repr && vStringLength (token->string) > 1) vStringCatS (repr, vStringValue (token->string) + 1); } break; } LastTokenType = token->type; }
static void parseMeshInfo( MeshModel *root,float curr_time ){ _log( "OBJECT_NODE_TAG" ); enterChunk(); string name,inst; Vector pivot; Animation anim; unsigned short id=65535,parent=65535,flags1,flags2; Box box( (Vector()),(Vector()) ); Vector box_centre; while( int chunk_id=nextChunk() ){ switch( chunk_id ){ case 0xb030: //NODE_ID in.sgetn( (char*)&id,2 ); _log( "NODE_ID: "+itoa(id) ); break; case 0xb010: //NODE_HDR name=parseString(); in.sgetn( (char*)&flags1,2 ); in.sgetn( (char*)&flags2,2 ); in.sgetn( (char*)&parent,2 ); _log( "NODE_HDR: name="+name+" parent="+itoa(parent) ); break; case 0xb011: //INSTANCE NAME inst=parseString(); _log( "INSTANCE_NAME: "+inst ); break; case 0xb013: //PIVOT in.sgetn( (char*)&pivot,12 ); if( conv ) pivot=conv_tform * pivot; _log( "PIVOT: "+ftoa(pivot.x)+","+ftoa(pivot.y)+","+ftoa(pivot.z) ); break; case 0xb014: //BOUNDBOX in.sgetn( (char*)&box.a,12 ); in.sgetn( (char*)&box.b,12 ); box_centre=box.centre(); if( conv ) box_centre=conv_tform * box_centre; _log( "BOUNDBOX: min="+ftoa(box.a.x)+","+ftoa(box.a.y)+","+ftoa(box.a.z)+" max="+ftoa(box.b.x)+","+ftoa(box.b.y)+","+ftoa(box.b.z) ); break; case 0xb020: //POS_TRACK_TAG case 0xb021: //ROT_TRACK_TAG case 0xb022: //SCALE_TRACK_TAG if( !collapse ) parseAnimKeys( &anim,chunk_id ); break; } } leaveChunk(); MeshModel *p=root; if( parent!=65535 ){ map<int,MeshModel*>::const_iterator it=id_map.find( parent ); if( it==id_map.end() ) return; p=it->second; } MeshModel *mesh=0; if( name=="$$$DUMMY" ){ mesh=d_new MeshModel(); mesh->setName( inst ); mesh->setParent( p ); }else{ map<string,MeshModel*>::const_iterator it=name_map.find( name ); if( it==name_map.end() ) return; mesh=it->second; name_map.erase( name ); if( pivot!=Vector() ){ mesh->transform( -pivot ); } Transform t= mesh->getWorldTform(); mesh->setParent( p ); mesh->setWorldTform( t ); } mesh->setAnimation( anim ); if( id!=65535 ) id_map[id]=mesh; }
QDropboxJson::QDropboxJson(const QDropboxJson &other) : QObject(other.parent()) { _init(); parseString(other.strContent()); }
void ParseUnsupportedBumpModifier(const char *&token, std::stringstream &err) { if ((0 == strncmp(token, "-mm", 3)) && isSpace(token[3])) { token += 4; (void)parseFloat(token); // base_value (void)parseFloat(token); // gain_value err << "Ignoring bump map modifier \"-mm\"" << std::endl; } else if ((0 == strncmp(token, "-blendu", 7)) && isSpace(token[7])) { token += 8; (void)parseString(token); err << "Ignoring bump map modifier \"-blendu\"" << std::endl; } else if ((0 == strncmp(token, "-blendv", 7)) && isSpace(token[7])) { token += 8; (void)parseString(token); err << "Ignoring bump map modifier \"-blendv\"" << std::endl; } else if ((0 == strncmp(token, "-boost", 6)) && isSpace(token[6])) { token += 7; (void)parseFloat(token); err << "Ignoring bump map modifier \"-boost\"" << std::endl; } else if ((0 == strncmp(token, "-texres", 7)) && isSpace(token[7])) { token += 8; (void)parseFloat(token); err << "Ignoring bump map modifier \"-texres\"" << std::endl; } else if ((0 == strncmp(token, "-clamp", 6)) && isSpace(token[6])) { token += 7; (void)parseString(token); err << "Ignoring bump map modifier \"-clamp\"" << std::endl; } else if ((0 == strncmp(token, "-imfchan", 8)) && isSpace(token[8])) { token += 9; (void)parseString(token); err << "Ignoring bump map modifier \"-imfchan\"" << std::endl; } else if ((0 == strncmp(token, "-type", 5)) && isSpace(token[5])) { token += 6; (void)parseString(token); err << "Ignoring bump map modifier \"-type\"" << std::endl; } else if ((0 == strncmp(token, "-o", 2)) && isSpace(token[2])) { token += 3; (void)parseFloat(token); // x if (IsFloat(token)) { (void)parseFloat(token); // y if (IsFloat(token)) { (void)parseFloat(token); // z } } err << "Ignoring bump map modifier \"-o\"" << std::endl; } else if ((0 == strncmp(token, "-s", 2)) && isSpace(token[2])) { token += 3; (void)parseFloat(token); // x if (IsFloat(token)) { (void)parseFloat(token); // y if (IsFloat(token)) { (void)parseFloat(token); // z } } err << "Ignoring bump map modifier \"-s\"" << std::endl; } else if ((0 == strncmp(token, "-t", 2)) && isSpace(token[2])) { token += 3; (void)parseFloat(token); // x if (IsFloat(token)) { (void)parseFloat(token); // y if (IsFloat(token)) { (void)parseFloat(token); // z } } err << "Ignoring bump map modifier \"-t\"" << std::endl; } else err << "Unexpected modifier \"" << token << "\" for bump map" << std::endl; }
com::typesafe::config::Config* com::typesafe::config::ConfigFactory::parseString(::java::lang::String* s) { clinit(); return parseString(s, ConfigParseOptions::defaults()); }
// Returns TRUE for "ok to continue parsing fields". UBool PreparsedUCD::parseProperty(UniProps &props, const char *field, UnicodeSet &newValues, UErrorCode &errorCode) { CharString pBuffer; const char *p=field; const char *v=strchr(p, '='); int binaryValue; if(*p=='-') { if(v!=NULL) { fprintf(stderr, "error in preparsed UCD: mix of binary-property-no and " "enum-property syntax '%s' on line %ld\n", field, (long)lineNumber); errorCode=U_PARSE_ERROR; return FALSE; } binaryValue=0; ++p; } else if(v==NULL) { binaryValue=1; } else { binaryValue=-1; // Copy out the property name rather than modifying the field (writing a NUL). pBuffer.append(p, (int32_t)(v-p), errorCode); p=pBuffer.data(); ++v; } int32_t prop=pnames->getPropertyEnum(p); if(prop<0) { for(int32_t i=0;; ++i) { if(i==UPRV_LENGTHOF(ppucdProperties)) { // Ignore unknown property names. return TRUE; } if(0==uprv_stricmp(p, ppucdProperties[i].name)) { prop=ppucdProperties[i].prop; U_ASSERT(prop>=0); break; } } } if(prop<UCHAR_BINARY_LIMIT) { if(binaryValue>=0) { props.binProps[prop]=(UBool)binaryValue; } else { // No binary value for a binary property. fprintf(stderr, "error in preparsed UCD: enum-property syntax '%s' " "for binary property on line %ld\n", field, (long)lineNumber); errorCode=U_PARSE_ERROR; } } else if(binaryValue>=0) { // Binary value for a non-binary property. fprintf(stderr, "error in preparsed UCD: binary-property syntax '%s' " "for non-binary property on line %ld\n", field, (long)lineNumber); errorCode=U_PARSE_ERROR; } else if (prop < UCHAR_INT_START) { fprintf(stderr, "error in preparsed UCD: prop value is invalid: '%d' for line %ld\n", prop, (long)lineNumber); errorCode=U_PARSE_ERROR; } else if(prop<UCHAR_INT_LIMIT) { int32_t value=pnames->getPropertyValueEnum(prop, v); if(value==UCHAR_INVALID_CODE && prop==UCHAR_CANONICAL_COMBINING_CLASS) { // TODO: Make getPropertyValueEnum(UCHAR_CANONICAL_COMBINING_CLASS, v) work. char *end; unsigned long ccc=uprv_strtoul(v, &end, 10); if(v<end && *end==0 && ccc<=254) { value=(int32_t)ccc; } } if(value==UCHAR_INVALID_CODE) { fprintf(stderr, "error in preparsed UCD: '%s' is not a valid value on line %ld\n", field, (long)lineNumber); errorCode=U_PARSE_ERROR; } else { props.intProps[prop-UCHAR_INT_START]=value; } } else if(*v=='<') { // Do not parse default values like <code point>, just set null values. switch(prop) { case UCHAR_BIDI_MIRRORING_GLYPH: props.bmg=U_SENTINEL; break; case UCHAR_BIDI_PAIRED_BRACKET: props.bpb=U_SENTINEL; break; case UCHAR_SIMPLE_CASE_FOLDING: props.scf=U_SENTINEL; break; case UCHAR_SIMPLE_LOWERCASE_MAPPING: props.slc=U_SENTINEL; break; case UCHAR_SIMPLE_TITLECASE_MAPPING: props.stc=U_SENTINEL; break; case UCHAR_SIMPLE_UPPERCASE_MAPPING: props.suc=U_SENTINEL; break; case UCHAR_CASE_FOLDING: props.cf.remove(); break; case UCHAR_LOWERCASE_MAPPING: props.lc.remove(); break; case UCHAR_TITLECASE_MAPPING: props.tc.remove(); break; case UCHAR_UPPERCASE_MAPPING: props.uc.remove(); break; case UCHAR_SCRIPT_EXTENSIONS: props.scx.clear(); break; default: fprintf(stderr, "error in preparsed UCD: '%s' is not a valid default value on line %ld\n", field, (long)lineNumber); errorCode=U_PARSE_ERROR; } } else { char c; switch(prop) { case UCHAR_NUMERIC_VALUE: props.numericValue=v; c=*v; if('0'<=c && c<='9' && v[1]==0) { props.digitValue=c-'0'; } else { props.digitValue=-1; } break; case UCHAR_NAME: props.name=v; break; case UCHAR_AGE: u_versionFromString(props.age, v); // Writes 0.0.0.0 if v is not numeric. break; case UCHAR_BIDI_MIRRORING_GLYPH: props.bmg=parseCodePoint(v, errorCode); break; case UCHAR_BIDI_PAIRED_BRACKET: props.bpb=parseCodePoint(v, errorCode); break; case UCHAR_SIMPLE_CASE_FOLDING: props.scf=parseCodePoint(v, errorCode); break; case UCHAR_SIMPLE_LOWERCASE_MAPPING: props.slc=parseCodePoint(v, errorCode); break; case UCHAR_SIMPLE_TITLECASE_MAPPING: props.stc=parseCodePoint(v, errorCode); break; case UCHAR_SIMPLE_UPPERCASE_MAPPING: props.suc=parseCodePoint(v, errorCode); break; case UCHAR_CASE_FOLDING: parseString(v, props.cf, errorCode); break; case UCHAR_LOWERCASE_MAPPING: parseString(v, props.lc, errorCode); break; case UCHAR_TITLECASE_MAPPING: parseString(v, props.tc, errorCode); break; case UCHAR_UPPERCASE_MAPPING: parseString(v, props.uc, errorCode); break; case PPUCD_NAME_ALIAS: props.nameAlias=v; break; case PPUCD_CONDITIONAL_CASE_MAPPINGS: case PPUCD_TURKIC_CASE_FOLDING: // No need to parse their values: They are hardcoded in the runtime library. break; case UCHAR_SCRIPT_EXTENSIONS: parseScriptExtensions(v, props.scx, errorCode); break; default: // Ignore unhandled properties. return TRUE; } } if(U_SUCCESS(errorCode)) { newValues.add((UChar32)prop); return TRUE; } else { return FALSE; } }
static inline int parseDQString(YYSTYPE *lvalp, yyscan_t scanner) { return parseString(lvalp, scanner, '"', DoubleQString); }
std::string ObjLoader::LoadObj(shapes_t& shapes, const char* filename, const char* mtl_basepath) { shapes.reset(); std::stringstream err; std::istringstream ifs(FileUtils::getInstance()->getStringFromFile(filename)); std::map<vertex_index, ssize_t> vertexCache; //std::ifstream ifs(filename); if (!ifs) { err << "Cannot open file [" << filename << "]" << std::endl; return err.str(); } std::vector<float> v; std::vector<float> vn; std::vector<float> vt; std::vector<std::vector<vertex_index> > faceGroup; std::string name; // material std::map<std::string, material_t> material_map; material_t material; int maxchars = 8192; // Alloc enough size. std::vector<char> buf(maxchars); // Alloc enough size. while (ifs.peek() != -1) { ifs.getline(&buf[0], maxchars); std::string linebuf(&buf[0]); // Trim newline '\r\n' or '\r' if (linebuf.size() > 0) { if (linebuf[linebuf.size()-1] == '\n') linebuf.erase(linebuf.size()-1); } if (linebuf.size() > 0) { if (linebuf[linebuf.size()-1] == '\n') linebuf.erase(linebuf.size()-1); } // Skip if empty line. if (linebuf.empty()) { continue; } // Skip leading space. const char* token = linebuf.c_str(); token += strspn(token, " \t"); assert(token); if (token[0] == '\0') continue; // empty line if (token[0] == '#') continue; // comment line // vertex if (token[0] == 'v' && isSpace((token[1]))) { token += 2; float x, y, z; parseFloat3(x, y, z, token); v.push_back(x); v.push_back(y); v.push_back(z); continue; } // normal if (token[0] == 'v' && token[1] == 'n' && isSpace((token[2]))) { token += 3; float x, y, z; parseFloat3(x, y, z, token); vn.push_back(x); vn.push_back(y); vn.push_back(z); continue; } // texcoord if (token[0] == 'v' && token[1] == 't' && isSpace((token[2]))) { token += 3; float x, y; parseFloat2(x, y, token); vt.push_back(x); vt.push_back(y); continue; } // face if (token[0] == 'f' && isSpace((token[1]))) { token += 2; token += strspn(token, " \t"); std::vector<vertex_index> face; while (!isNewLine(token[0])) { // fix warning, cast to int, i think int is enough vertex_index vi = parseTriple(token, (int)v.size() / 3, (int)vn.size() / 3, (int)vt.size() / 2); face.push_back(vi); auto n = strspn(token, " \t\r"); token += n; } faceGroup.push_back(face); continue; } // use mtl if ((0 == strncmp(token, "usemtl", 6)) && isSpace((token[6]))) { exportFaceGroupToShape(vertexCache, shapes, v, vn, vt, faceGroup, material, name); faceGroup.clear(); char namebuf[4096]; token += 7; sscanf(token, "%s", namebuf); if (material_map.find(namebuf) != material_map.end()) { material = material_map[namebuf]; } else { // { error!! material not found } InitMaterial(material); } continue; } // load mtl if ((0 == strncmp(token, "mtllib", 6)) && isSpace((token[6]))) { char namebuf[4096]; token += 7; sscanf(token, "%s", namebuf); std::string err_mtl = LoadMtl(material_map, namebuf, mtl_basepath); if (!err_mtl.empty()) { faceGroup.clear(); // for safety //return err_mtl; } continue; } // group name if (token[0] == 'g' && isSpace((token[1]))) { // flush previous face group. shape_t shape; exportFaceGroupToShape(vertexCache, shapes, v, vn, vt, faceGroup, material, name); faceGroup.clear(); std::vector<std::string> names; while (!isNewLine(token[0])) { std::string str = parseString(token); names.push_back(str); token += strspn(token, " \t\r"); // skip tag } assert(names.size() > 0); // names[0] must be 'g', so skipt 0th element. if (names.size() > 1) { name = names[1]; } else { name = ""; } continue; } // object name if (token[0] == 'o' && isSpace((token[1]))) { // flush previous face group. shape_t shape; exportFaceGroupToShape(vertexCache, shapes, v, vn, vt, faceGroup, material, name); faceGroup.clear(); // @todo { multiple object name? } char namebuf[4096]; token += 2; sscanf(token, "%s", namebuf); name = std::string(namebuf); continue; } // Ignore unknown command. } shape_t shape; exportFaceGroupToShape(vertexCache, shapes, v, vn, vt, faceGroup, material, name); faceGroup.clear(); // for safety return err.str(); }
static int yylex(YYSTYPE *lvalp, yyscan_t scanner) { const size_t len = scanner->insize; const unsigned char *in = (const unsigned char*)scanner->in; unsigned char lookahead; enum char_class cClass; scanner->yytext = NULL; scanner->yylen = 0; if(scanner->pos == scanner->lastpos) { if(scanner->last_state == scanner->state) { cli_dbgmsg(MODULE "infloop detected, skipping character\n"); scanner->pos++; } /* its not necesarely an infloop if it changed * state, and it shouldn't infloop between states */ } scanner->lastpos = scanner->pos; scanner->last_state = scanner->state; while(scanner->pos < scanner->insize) { switch(scanner->state) { case Initial: textbuf_clean(&scanner->buf); cClass = ctype[in[scanner->pos++]]; switch(cClass) { case Whitespace: /* eat whitespace */ continue; case Slash: if(scanner->pos < len) { lookahead = in[scanner->pos]; switch(lookahead) { case '*': scanner->state = MultilineComment; scanner->pos++; continue; case '/': scanner->state = SinglelineComment; scanner->pos++; continue; } } --scanner->pos; return parseOperator(lvalp, scanner); case Operator: --scanner->pos; return parseOperator(lvalp, scanner); case DQuote: return parseDQString(lvalp, scanner); case SQuote: return parseSQString(lvalp, scanner); case Digit: --scanner->pos; return parseNumber(lvalp, scanner); case IdStart: --scanner->pos; return parseId(lvalp,scanner); CASE_SPECIAL_CHAR(BracketOpen, "["); CASE_SPECIAL_CHAR(BracketClose, "]"); CASE_SPECIAL_CHAR(Comma, ","); CASE_SPECIAL_CHAR(CurlyOpen, "{"); CASE_SPECIAL_CHAR(CurlyClose, "}"); CASE_SPECIAL_CHAR(ParOpen, "("); CASE_SPECIAL_CHAR(ParClose, ")"); CASE_SPECIAL_CHAR(Dot, "."); CASE_SPECIAL_CHAR(SemiColon, ";"); case Nop: continue; } break; case DoubleQString: return parseString(lvalp, scanner, '"', DoubleQString); case SingleQString: return parseString(lvalp, scanner, '\'', SingleQString); case Identifier: return parseId(lvalp, scanner); case MultilineComment: while(scanner->pos+1 < scanner->insize) { if(in[scanner->pos] == '*' && in[scanner->pos+1] == '/') { scanner->state = Initial; scanner->pos++; break; } scanner->pos++; } scanner->pos++; break; case Number: return parseNumber(lvalp, scanner); case SinglelineComment: while(scanner->pos < scanner->insize) { /* htmlnorm converts \n to space, so * stop on space too */ if(in[scanner->pos] == '\n' || in[scanner->pos] == ' ') break; scanner->pos++; } scanner->state = Initial; break; default: assert(0 && "Not reached"); } } return 0; }
WineDllOverrides::WineDllOverrides(const char * dllOverridesStr) : d(new WineDllOverridesData) { parseString(dllOverridesStr); }
ReadOnlyMapDefinition parseInput( char * subopts ) { if ( !subopts ) qFatal("Missing argument for '--input'"); enum { TypeOption = 0, BaseDirectoryOption, FileOption, TileLevelOption, InterpolationOption, CacheSizeOption, TheEnd }; char optionType[] = "type"; char optionBaseDirectory[] = "base-directory"; char optionFile[] = "file"; char optionTileLevel[] = "tile-level"; char optionInterpolationMethod[] = "interpolation-method"; char optionCacheSize[] = "cache-size"; char * const input_opts[] = { optionType, optionBaseDirectory, optionFile, optionTileLevel, optionInterpolationMethod, optionCacheSize, NULL }; ReadOnlyMapDefinition mapDefinition; char * value; while ( *subopts != '\0' ) { switch ( getsubopt( &subopts, input_opts, &value )) { case TypeOption: mapDefinition.setMapType( parseType( value )); break; case BaseDirectoryOption: mapDefinition.setBaseDirectory( parseString( value )); break; case FileOption: mapDefinition.setFileName( parseString( value )); break; case TileLevelOption: mapDefinition.setTileLevel( parseInt( value )); break; case InterpolationOption: mapDefinition.setInterpolationMethod( parseInterpolationMethod( value )); break; case CacheSizeOption: mapDefinition.setCacheSizeBytes( parseInt( value )); break; default: qFatal("Unrecognized input suboption."); } } return mapDefinition; }
static void readToken (tokenInfo * const token) { int c; token->type = TOKEN_NONE; token->keyword = KEYWORD_NONE; vStringClear (token->string); getNextChar: do { c = getcFromInputFile (); token->lineNumber = getInputLineNumber (); token->filePosition = getInputFilePosition (); } while (c == '\t' || c == ' ' || c == '\n'); switch (c) { case EOF: token->type = TOKEN_EOF; break; case '(': token->type = TOKEN_OPEN_PAREN; break; case ')': token->type = TOKEN_CLOSE_PAREN; break; case ';': token->type = TOKEN_SEMICOLON; break; case '.': token->type = TOKEN_PERIOD; break; case ',': token->type = TOKEN_COMMA; break; case '\'': /* only single char are inside simple quotes */ break; /* or it is for attributes so we don't care */ case '"': token->type = TOKEN_STRING; parseString (token->string, c); token->lineNumber = getInputLineNumber (); token->filePosition = getInputFilePosition (); break; case '-': c = getcFromInputFile (); if (c == '-') /* start of a comment */ { skipToCharacterInInputFile ('\n'); goto getNextChar; } else { if (!isspace (c)) ungetcToInputFile (c); token->type = TOKEN_OPERATOR; } break; default: if (!isIdentChar1 (c)) token->type = TOKEN_NONE; else { parseIdentifier (token->string, c); token->lineNumber = getInputLineNumber (); token->filePosition = getInputFilePosition (); token->keyword = lookupCaseKeyword (vStringValue (token->string), Lang_vhdl); if (isKeyword (token, KEYWORD_NONE)) token->type = TOKEN_IDENTIFIER; else token->type = TOKEN_KEYWORD; } break; } }