bool Config::ParseFile(const wchar_t * wsPath) { JSONSTREAM *stream = json_new_stream(jsonNodeComplete, jsonNodeError, this); FILE *f = NULL; char buffer[256]; memset(buffer, 0, sizeof(buffer)); int iResult = _wfopen_s(&f, wsPath, L"rt"); if (iResult == 0 && f != NULL) { while (buffer != NULL && !feof(f)) { fgets(buffer, sizeof(buffer), f); RemoveComments(buffer); json_stream_push(stream, buffer); } fclose(f); } // TODO: file not found json_delete_stream(stream); if (m_wsUrl != std::wstring()) { m_bLoadSuccess = true; return true; } return false; }
bool ConfigParser::ParseLine(string line, RawTokenArray &rawTokens) { //Remove comments RemoveComments(line); //Loop while there is still tokens to be parsed do { string rawToken; bool isQuoteToken =false; //Get a token if(!GetRawToken(line,rawToken,isQuoteToken)) { return false; } //Add if a valid quoted token or a regular token of some length if(rawToken.length() > 0 || isQuoteToken) { //Add the raw token to the array rawTokens.push_back(RawToken(rawToken,isQuoteToken)); } } while (line.length() > 0); return true; }
CFileReader::CFileReader(std::string filename){ m_Filename = filename; std::string line; m_NumberOfLines = 0; std::ifstream file(filename.c_str()); if(file.is_open()){ m_bFileExists = true; while(!file.eof()){ getline (file, line); //line = RemoveSpaces(line); line = RemoveComments(line); if(line.size() != 0){ m_NumberOfLines++; m_Lines.push_back(line); } } file.close(); } else m_bFileExists = false; }
SymFile::SymFile(std::string filename) : m_filename(filename) { FILE *fp = std::fopen(filename.c_str(), "rb"); if (fp == NULL) FATAL_ERROR("Failed to open \"%s\" for reading.\n", filename.c_str()); std::fseek(fp, 0, SEEK_END); m_size = std::ftell(fp); if (m_size < 0) FATAL_ERROR("File size of \"%s\" is less than zero.\n", filename.c_str()); m_buffer = new char[m_size + 1]; std::rewind(fp); if (std::fread(m_buffer, m_size, 1, fp) != 1) FATAL_ERROR("Failed to read \"%s\".\n", filename.c_str()); m_buffer[m_size] = 0; std::fclose(fp); m_pos = 0; m_lineNum = 1; m_lineStart = 0; RemoveComments(); }
ribi::QtCreatorProFile::QtCreatorProFile(const std::string& filename) : m_config{}, m_defines{}, m_forms{}, m_headers{}, m_includepath{}, m_libs{}, m_other_files{}, m_pri_files{}, m_pro_filename{filename}, m_qmake_cxxflags{}, m_qt{}, m_resources{}, m_target{}, m_template{}, m_sources{} { #ifndef NDEBUG Test(); #endif #ifndef NDEBUG if (!ribi::fileio::IsRegularFile(filename)) { TRACE(filename); TRACE("BREAK"); } #endif assert(ribi::fileio::IsRegularFile(filename)); std::vector<std::string> v = ribi::fileio::FileToVector(filename); RemoveComments(v); DoReplacements(v); std::stringstream data; std::copy(std::begin(v),std::end(v),std::ostream_iterator<std::string>(data," ")); TRACE(data.str()); Parse(data); }
int Parse(FILE *asmFile, Instruction **instructions, SymbolTable **symbolTables) { char buf[128]; // buffer for each line char *temp = NULL; // temp for the each instruction char *symbol = NULL; // symbol address for C command int count=0; // count of instructions int i; // array index Instruction *currentInstruction = NULL; while(!feof(asmFile)) { // hasMoreCommands if(fgets(buf,128,asmFile)!=NULL) { // advance // remove the comments and white space on each line temp = TrimWhitespace(RemoveComments(buf)); // if *temp is 0, it must be a space line if(*temp != 0) { if(*temp == '(') { // Label symbol = temp + 1; symbol[strcspn(symbol,")")] = '\0'; AddEntry(symbol, count, symbolTables); // Add Label to Symbol Table continue; } currentInstruction = *instructions+count; memset(currentInstruction, 0, sizeof(Instruction)); if(*temp == '@') { // A Command or L COMMAND strcpy(currentInstruction->symbol, temp+1); if(IsDecimalOnly(currentInstruction->symbol)) { currentInstruction->commandType = A_COMMAND; } else { currentInstruction->commandType = L_COMMAND; } } else { // C Command dest=comp;jump currentInstruction->commandType = C_COMMAND; symbol = strchr(temp, '='); // check if '=' is existed if(symbol != 0) { // if '=' is existed, copy L value to dest, change temp to be the remainder strncpy(currentInstruction->dest, temp, strcspn(temp,"=")); temp = symbol+1; } else { // else, dest is empty strcpy(currentInstruction->dest, ""); } symbol = strchr(temp, ';'); // check if ';' is existed if(symbol != 0) { // if ';' is existed, copy L value to comp, R value to jump strncpy(currentInstruction->comp, temp, strcspn(temp,";")); strcpy(currentInstruction->jump, symbol+1); } else { // since ';' is not existed, there is no jump op, and the remainder is comp op only strcpy(currentInstruction->comp, temp); strcpy(currentInstruction->jump, ""); } } count++; } } } // Add variables to symbol table for( i = 0; i < count; i++ ){ currentInstruction = *instructions + i; if( currentInstruction->commandType == L_COMMAND ){ AddEntry(currentInstruction->symbol, VARIABLE, symbolTables); } } return count; }
void PPFile::Parse(Stream& in) { LTIMING("PPFile::Parse"); for(int i = 0; i < ppmacro.GetCount(); i++) sAllMacros.Unlink(ppmacro[i]); ppmacro.Clear(); item.Clear(); includes.Clear(); bool was_using = false; bool was_namespace = false; int level = 0; bool incomment = false; Vector<int> namespace_block; bool next_segment = true; Index<int> local_segments; keywords.Clear(); int linei = 0; Md5Stream md5; while(!in.IsEof()) { String l = in.GetLine(); while(*l.Last() == '\\' && !in.IsEof()) { l.Trim(l.GetLength() - 1); l.Cat(in.GetLine()); } RemoveComments(l, incomment); try { CParser p(l); if(p.Char('#')) { if(p.Id("define")) { if(next_segment) { PPItem& m = item.Add(); m.type = PP_DEFINES; m.segment_id = ++sPPserial; next_segment = false; local_segments.Add(sPPserial); } CppMacro def; String id = def.Define(p.GetPtr()); if(id.GetCount()) { PPMacro m; m.segment_id = sPPserial; m.line = linei; m.macro = def; ppmacro.Add(sAllMacros.Put(id, m)); md5.Put("#", 1); md5.Put(id); md5.Put(0); md5.Put(m.macro.md5, 16); } } else if(p.Id("undef")) { if(p.IsId()) { String id = p.ReadId(); md5.Put("#", 1); md5.Put(id); md5.Put(1); int segmenti = -1; PPMacro *um = FindPPMacro(id, local_segments, segmenti); if(um && segmenti) { // heuristic: only local undefs are allowed PPItem& m = item.Add(); m.type = PP_DEFINES; m.segment_id = ++sPPserial; um->undef_segment_id = m.segment_id; next_segment = true; local_segments.Add(sPPserial); if(id.GetCount()) { PPMacro m; m.segment_id = sPPserial; m.line = linei; m.macro.SetUndef(); ppmacro.Add(sAllMacros.Put(id, m)); } } } } else if(p.Id("include")) { PPItem& m = item.Add(); next_segment = true; m.type = PP_INCLUDE; m.text = TrimBoth(p.GetPtr()); if(IsNull(m.text)) item.Drop(); else includes.FindAdd(m.text); md5.Put('@'); md5.Put(m.text); } } else { while(!p.IsEof()) { if(was_namespace) { int type = was_using ? PP_USING : PP_NAMESPACE; String id; while(p.Char2(':', ':')) id = "::"; if(p.IsId()) { id << p.ReadId(); while(p.Char2(':', ':') && p.IsId()) id << "::" << p.ReadId(); if(!was_using) namespace_block.Add(level); if(!was_using || level == 0) { PPItem& m = item.Add(); next_segment = true; m.type = type; m.text = id; } md5.Put('$'); md5.Put(type); md5.Put(id); } was_namespace = was_using = false; } else if(p.Id("using")) was_using = true; else if(p.Id("namespace")) was_namespace = true; else { was_using = was_namespace = false; if(p.IsId()) { static const VectorMap<String, String>& namespace_macro = GetNamespaceMacros(); static const Index<String>& namespace_end_macro = GetNamespaceEndMacros(); String id = p.ReadId(); int q = namespace_macro.Find(id); if(q > 0) { PPItem& m = item.Add(); next_segment = true; m.type = PP_NAMESPACE; m.text = namespace_macro[q]; namespace_block.Add(level); level++; md5.Put('%'); md5.Put(id); } else { q = namespace_end_macro.Find(id); if(q >= 0) { level--; CheckEndNamespace(namespace_block, level, md5); } } keywords.Add(id); } else if(p.Char('}')) { if(level > 0) { level--; CheckEndNamespace(namespace_block, level, md5); } } else if(p.Char('{')) level++; else p.SkipTerm(); } } } } catch(...) {} linei++; } md5sum = md5.FinishString(); Sort(keywords); Vector<int> remove; int i = 0; while(i < keywords.GetCount()) { // Remove identical items int ii = i; i++; while(i < keywords.GetCount() && keywords[ii] == keywords[i]) remove.Add(i++); } keywords.Remove(remove); }
/*--------------------------------------------------------------------------*/ int SendScilabJobs(char **jobs, int numberjobs) { #define BUFFERSECURITYSIZE 64 int retcode = -10; if (jobs) { int i = 0; int nbcharsjobs = 0; char *bufCommands = NULL; char **LOCALJOBS = NULL; int jobsloop = 0; LOCALJOBS = (char **)MALLOC(sizeof(char *) * numberjobs); if (LOCALJOBS) { for (i = 0; i < numberjobs; i++) { if (jobs[i]) { nbcharsjobs = nbcharsjobs + (int)strlen(jobs[i]); LOCALJOBS[i] = (char *)MALLOC(sizeof(char) * (strlen(jobs[i]) + BUFFERSECURITYSIZE)); if (LOCALJOBS[i]) { strcpy(LOCALJOBS[i], jobs[i]); } else { CleanBuffers(bufCommands, LOCALJOBS, numberjobs); fprintf(stderr, "Error: SendScilabJobs (1) 'LOCALJOBS[%d] MALLOC'.\n", i); return retcode; } } else { fprintf(stderr, "Error: SendScilabJobs (2) 'jobs[%d] == NULL'.\n", i); return retcode; } } bufCommands = (char *)MALLOC(sizeof(char) * (nbcharsjobs + numberjobs + BUFFERSECURITYSIZE)); if (bufCommands) { strcpy(bufCommands, ""); for (jobsloop = 0; jobsloop < numberjobs; jobsloop++) { if (jobs[jobsloop]) { char *currentline = NULL; BOOL AddSemiColon; if (jobsloop == 0) { AddSemiColon = FALSE; } else { AddSemiColon = TRUE; } DOTDOTLOOP: currentline = LOCALJOBS[jobsloop]; RemoveCharsFromEOL(currentline, '\n'); RemoveComments(currentline); RemoveCharsFromEOL(currentline, ' '); if (RemoveCharsFromEOL(currentline, '.')) { RemoveCharsFromEOL(currentline, ' '); strcat(bufCommands, currentline); jobsloop++; AddSemiColon = FALSE; goto DOTDOTLOOP; } else { if (!AddSemiColon) { strcat(currentline, ";"); } else { strcat(bufCommands, ";"); } strcat(bufCommands, currentline); } } } retcode = SendScilabJob(bufCommands); CleanBuffers(bufCommands, LOCALJOBS, numberjobs); } else { CleanBuffers(bufCommands, LOCALJOBS, numberjobs); fprintf(stderr, "Error: SendScilabJobs (3) 'bufCommands MALLOC'.\n"); return retcode; } } else { CleanBuffers(bufCommands, LOCALJOBS, numberjobs); fprintf(stderr, "Error: SendScilabJobs (4) 'LOCALJOBS == NULL'.\n"); return retcode; } } else { fprintf(stderr, "Error: SendScilabJobs (5) 'jobs == NULL'.\n"); retcode = -10; } return retcode; }
//*************************************************** int Logic::AddIncludes() { TStringList IncludeStrings,IncludeLines; int CurInputLine,CurIncludeLine; string filename; int err=0; string::size_type pos1,pos2; int CurLine; char *ptr; IncludeFilenames = TStringList(); IncludeStrings = TStringList(); EditLines = TStringList(); IncludeLines = TStringList(); CurLine = 0; for(CurInputLine = 0;CurInputLine<InputLines.num;CurInputLine++){ EditLines.add(InputLines.at(CurInputLine)); CurLine = EditLines.num -1; RealLineNum[CurLine] = CurInputLine; LineFile[CurLine] = 0; #ifdef _WIN32 if(_strnicmp(InputLines.at(CurInputLine).c_str(),"#include",8)) { #else if(strncasecmp(InputLines.at(CurInputLine).c_str(),"#include",8)){ #endif continue; } string str = InputLines.at(CurInputLine).substr(8); if(str.length()<4){ ShowError(CurLine,"Missing include filename !"); err=1; continue; } if(str[0] != ' '){ ShowError(CurLine,"' ' expected after #include."); err=1; continue; } pos1 = str.find_first_of("\"",1); pos2 = str.find_first_of("\"",pos1+1); if(pos1 == string::npos || pos2 == string::npos){ ShowError(CurLine,"Include filenames need quote marks around them."); err=1; continue; } filename = str.substr(pos1+1,pos2-pos1-1); if(filename.find_first_of("/")!=string::npos){ ShowError(CurLine,"Only files in the src directory can be included."); err=1; continue; } sprintf(tmp,"%s/src/%s",game->dir.c_str(),filename.c_str()); FILE *fptr = fopen(tmp,"rb"); if(fptr==NULL){ sprintf(tmp,"Can't open include file: %s/src/%s",game->dir.c_str(),filename.c_str()); ShowError(CurLine,tmp); err=1; continue; } IncludeLines.lfree(); while(fgets(tmp,MAX_TMP,fptr)!=NULL){ if((ptr=strchr(tmp,0x0a)))*ptr=0; if((ptr=strchr(tmp,0x0d)))*ptr=0; IncludeLines.add(tmp); } fclose(fptr); if(IncludeLines.num==0)continue; IncludeFilenames.add(filename); RemoveComments(IncludeLines); EditLines.replace(CurLine,empty_tmp); for(CurIncludeLine=0;CurIncludeLine<IncludeLines.num;CurIncludeLine++){ EditLines.add(IncludeLines.at(CurIncludeLine)); CurLine=EditLines.num-1; RealLineNum[CurLine] = CurIncludeLine; LineFile[CurLine] = IncludeFilenames.num; } } IncludeLines.lfree(); InputLines.lfree(); return err; } //*************************************************** int Logic::ReadDefines() { int err=0,i; string::size_type pos1,pos2; string ThisDefineName,ThisDefineValue; int CurLine; NumDefines = 0; for(CurLine = 0;CurLine<EditLines.num;CurLine++){ #ifdef _WIN32 if(_strnicmp(EditLines.at(CurLine).c_str(),"#define",7)){ #else if(strncasecmp(EditLines.at(CurLine).c_str(),"#define",7)){ #endif continue; } string str = EditLines.at(CurLine).substr(7); toLower(&str); if(str.length()<4){ ShowError(CurLine,"Missing define name !"); err=1; continue; } if(str[0] != ' '){ ShowError(CurLine,"' ' expected after #define."); err=1; continue; } if(NumDefines >= MaxDefines){ ShowError(CurLine,"Too many defines (max " + IntToStr(MaxDefines) + ")"); err=1; continue; } pos1 = str.find_first_not_of(" ",1); pos2 = str.find_first_of(" ",pos1); if(pos1 == string::npos||pos2 == string::npos){ ShowError(CurLine,"Missing define name !"); err=1; continue; } ThisDefineName = str.substr(pos1,pos2-1); if(ThisDefineName.find_first_not_of("qwertyuiopasdfghjklzxcvbnm1234567890._") != string::npos){ ShowError(CurLine,"Define name can contain only characters from [a-z],'.' and '_'."); err=1; continue; } for(i=0;i<NumDefines;i++){ if(ThisDefineName == DefineNames[i]){ ShowError(CurLine,ThisDefineName + " already defined !"); err=1; break; } } if(err)continue; for(i=0;i<=NumAGICommands;i++){ if(ThisDefineName == AGICommand[i].Name){ ShowError(CurLine,"Define name can not be a command name."); err=1; break; } } if(err)continue; for(i=1;i<=NumTestCommands;i++){ if(ThisDefineName == TestCommand[i].Name){ ShowError(CurLine,"Define name can not be a command name."); err=1; break; } } if(err)continue; if(ThisDefineName == "if" || ThisDefineName == "else" || ThisDefineName == "goto"){ ShowError(CurLine,"Invalid define name (" + ThisDefineName + ")"); err=1; continue; } pos1 = str.find_first_not_of(" ",pos2+1); if(pos1 == string::npos){ ShowError(CurLine,"Missing define value !"); err=1; continue; } if(str[pos1] == '"'){ ThisDefineValue = "\"" + ReadString(&pos1,str) + "\""; if(ErrorOccured)continue; if(str.find_first_not_of(" ",pos1) != string::npos){ ShowError(CurLine,"Nothing allowed on line after define value."); err=1; continue; } } else{ pos2 = str.find_first_of(" ",pos1+1); if(pos2 == string::npos){ ThisDefineValue = str.substr(pos1); } else{ ThisDefineValue = str.substr(pos1,pos2-pos1); if(str.find_first_not_of(" ",pos2) != string::npos){ ShowError(CurLine,"Nothing allowed on line after define value."); err=1; continue; } } if(ThisDefineValue.find_first_not_of("qwertyuiopasdfghjklzxcvbnm1234567890._") != string::npos){ ShowError(CurLine,"Non-string define value can contain only characters from [a-z],'.' and '_'."); err=1; continue; } } DefineNames[NumDefines]=ThisDefineName; DefineValues[NumDefines]=ThisDefineValue; DefineNameLength[NumDefines] = ThisDefineName.length(); NumDefines++; EditLines.replace(CurLine,empty_tmp); } return err; } //*************************************************** int Logic::ReadPredefinedMessages() { int err=0,i; string::size_type pos1; int MessageNum; for(i=0;i<MaxMessages;i++){ Messages[i]=""; MessageExists[i]=false; } for(CurLine = 0;CurLine<EditLines.num;CurLine++){ #ifdef _WIN32 if(_strnicmp(EditLines.at(CurLine).c_str(),"#message",8)){ #else if(strncasecmp(EditLines.at(CurLine).c_str(),"#message",8)){ #endif continue; } string str = EditLines.at(CurLine).substr(8); if(str[0] != ' '){ ShowError(CurLine,"' ' expected after #message."); err=1; continue; } MessageNum = atoi(str.c_str()); if(MessageNum==0){ ShowError(CurLine,"Invalid message number (must be 1-255)."); err=1; continue; } pos1 = str.find_first_of("\""); if(pos1 == string::npos){ ShowError(CurLine,"\" required at start of string."); err=1; continue; } Messages[MessageNum]=ReadString(&pos1,str); if(ErrorOccured)continue; if(Messages[MessageNum].find_first_not_of(" ",pos1) != string::npos){ sprintf(tmp,"Nothing allowed on line after message. "); ShowError(CurLine,tmp); err=1; continue; } MessageExists[MessageNum] =true; EditLines.replace(CurLine,empty_tmp); } return err; } //*************************************************** int Logic::ReadLabels() { int err=0,i; string::size_type pos1,pos2; string LabelName; int CurLine; NumLabels = 0; for(CurLine = 0;CurLine<EditLines.num;CurLine++){ string str = EditLines.at(CurLine); toLower(&str); pos1 = str.find_first_not_of(" "); if(pos1 == string::npos)continue; pos2 = str.find_first_not_of("qwertyuiopasdfghjklzxcvbnm1234567890._",pos1); if(pos2 == string::npos)continue; if((pos1 == pos2) || (str[pos2]!=':'))continue; LabelName = str.substr(pos1,pos2-pos1); for(i=1;i<=NumLabels;i++){ if(LabelName == Labels[i].Name){ ShowError(CurLine,"Label "+LabelName+" already defined."); err=1;break; } } if(err)continue; if(NumLabels > MaxLabels){ ShowError(CurLine,"Too many labels (max "+IntToStr(MaxLabels)+")"); err=1;continue; } if(LabelName == "if" || LabelName == "else" || LabelName == "goto"){ ShowError(CurLine,"Invalid label name ("+LabelName+")"); err=1;continue; } for(i=0;i<NumDefines;i++){ if((LabelName == DefineNames[i]) || (LabelName+":" == DefineNames[i])){ ShowError(CurLine,"Can't have a label with the same name a a define."); err=1;break; } } if(err)continue; NumLabels++; Labels[NumLabels].Name = LabelName; Labels[NumLabels].Loc = 0; } return err; }
bool CConfigData::LoadConfigFile(std::string configFilename){ CLog *pLog = CLog::Instance(); //function variables std::string line; int equalCount = 0; std::ifstream file(configFilename.c_str()); //open file for reading if(file.is_open()){ //read one line at a time pLog->Log("Reading config file"); while(!file.eof()){ getline (file, line); line = RemoveSpaces(line); line = RemoveComments(line); equalCount = CountEqualSigns(line); if(line.size() != 0 && equalCount == 1){ m_lines.push_back(line); equalCount = 0; pLog->Log("Config line", line); } } file.close(); } //file doesn't exist else return false; //break string into key and value std::string key; std::string value; size_t equalPos = 0; bool bFound; pLog->Log("***************************************"); pLog->Log("Configuration File Data (key = value)"); pLog->Log("***************************************"); for(size_t i = 0; i < m_lines.size(); ++i){ equalPos = m_lines[i].find("="); if(equalPos > 0){ key = m_lines[i].substr(0, equalPos); value = m_lines[i].substr(equalPos + 1); //load all config variables with values bFound = false; if(key == "ScreenLeft"){ ScreenLeft = atoi(value.c_str()); bFound = true; } else if(key == "ScreenTop"){ ScreenTop = atoi(value.c_str()); bFound = true; } else if(key == "ScreenWidth"){ ScreenWidth = atoi(value.c_str()); bFound = true; } else if(key == "ScreenHeight"){ ScreenHeight = atoi(value.c_str()); bFound = true; } else if(key == "FullScreen"){ if(atoi(value.c_str()) == 1) FullScreen = true; else FullScreen = false; bFound = true; } else if(key == "DisplayDebugInfo"){ if(atoi(value.c_str()) == 0) DisplayDebugInfo = false; else if(atoi(value.c_str()) == 1) DisplayDebugInfo = true; bFound = true; } else if(key == "LogDebugInfo"){ if(atoi(value.c_str()) == 0) LogDebugInfo = false; else if(atoi(value.c_str()) == 1) LogDebugInfo = true; bFound = true; } else if(key == "PlaySounds"){ if(atoi(value.c_str()) == 0) PlaySounds = false; else if(atoi(value.c_str()) == 1) PlaySounds = true; bFound = true; } else if(key == "PlayMusic"){ if(atoi(value.c_str()) == 0) PlayMusic = false; else if(atoi(value.c_str()) == 1) PlayMusic = true; bFound = true; } else if(key == "FrameworkAssetFile"){ FrameworkAssetFile = value; bFound = true; } else if(key == "GamePlayAssetFile"){ GamePlayAssetFile = value; bFound = true; } else if(key == "SoundAssetFile"){ SoundAssetFile = value; bFound = true; } else if(key == "ObjectsFile"){ ObjectsFile = value; bFound = true; } else if(key == "EffectsFile"){ EffectsFile = value; bFound = true; } else if(key == "EffectsFileI"){ EffectsFileI = value; bFound = true; } else if(key == "CreditsFile"){ CreditsFile = value; bFound = true; } else if(key == "TilesFile"){ TilesFile = value; bFound = true; } else if(key == "ProgramName"){ ProgramName = value; bFound = true; } else if(key == "ProgramVersion"){ ProgramVersion = value; bFound = true; } else if(key == "RootPath"){ RootPath = value; bFound = true; } /* else if(key == "Level1"){ Level1 = value; bFound = true; } else if(key == "Level2"){ Level2 = value; bFound = true; } else if(key == "Level3"){ Level3 = value; bFound = true; } else if(key == "Level4"){ Level4 = value; bFound = true; } else if(key == "Level5"){ Level5 = value; bFound = true; } else if(key == "Level6"){ Level6 = value; bFound = true; } else if(key == "Level7"){ Level7 = value; bFound = true; } else if(key == "Level8"){ Level8 = value; bFound = true; } else if(key == "Level9"){ Level9 = value; bFound = true; } else if(key == "Level10"){ Level10 = value; bFound = true; } */ if(bFound == false) pLog->Log("No match for config file key", key); } } }
static void ReadOBJ(const char *filename) { FILE *fp = fopen(filename, "r"); if (fp == NULL) sreFatalError("Could not open file %s.", filename); for (;;) { char *str = GetWords(fp); if (str == NULL) // End of file. break; RemoveComments(); if (nu_words == 0) continue; int command = - 1; if (strcmp(words[0], "v") == 0) command = 0; else if (strcmp(words[0], "vn") == 0) command = 1; else if (strcmp(words[0], "vt") == 0) command = 2; else if (strcmp(words[0], "f") == 0) command = 3; if (command < 0) // First word not recognized. continue; if (command <= 2) { // Get up to four coordinates. float coord[4]; int n = GetCoordinates(1, coord); if (command == 0) AddVertexAttribute(SRE_ATTRIBUTE_POSITION, coord, n); else if (command == 1) AddVertexAttribute(SRE_ATTRIBUTE_NORMAL, coord, n); else AddVertexAttribute(SRE_ATTRIBUTE_TEXCOORDS, coord, n); } else { // Face defition. BeginFace(4, SRE_POSITION_MASK | SRE_NORMAL_MASK | SRE_TEXCOORDS_MASK); for (int word_index = 1; word_index < nu_words; word_index++) { int vertex_index[3]; DecodeOBJFaceIndices(words[word_index], vertex_index); for (int k = 0; k < 3; k++) { // Special value INT_MAX means not used; AddFace expects - 1 // for unused attributes. if (vertex_index[k] == INT_MAX) vertex_index[k] = - 1; else { if (vertex_index[k] > 0) // Regular index; counting starts at 1 in OBJ files. vertex_index[k]--; else if (vertex_index[k] < 0) // Negative numer is relative index. vertex_index[k] += nu_attribute_vertices[OBJ_attributes[k]]; else ModelFileReadError("Vertex index of 0 not allowed in OBJ file"); } } AddFaceVertex(OBJ_attributes, vertex_index); } EndFace(); } } fclose(fp); }