const char *TrackSpecParser::GetNextAttrib(const char *pAttrib) { if((mParsePtr != mLineBuffer) || (mLineNumber == 0)) { if(!ReadNewLine()) { return NULL; } } while(strchr(mLineBuffer, '=') == NULL) { if(mLineBuffer[0] == '[') { return NULL; } if(!ReadNewLine()) { return NULL; } } // Copy the answer in the return buffer sscanf(mLineBuffer, " %29[^ =]", mReturnBuffer); mParsePtr = strchr(mLineBuffer, '=') + 1; // Verify that the word can be accepted by the user const char *lReturnValue = mReturnBuffer; if(pAttrib != NULL) { if(_stricmp(pAttrib, mReturnBuffer)) { lReturnValue = GetNextAttrib(pAttrib); // Warning, this code can easily lead to a stack overflow } } return lReturnValue; }
const char *TrackSpecParser::InternalGetNextClass() { if(mParsePtr != mLineBuffer) { if(!ReadNewLine()) { return NULL; } } while(mLineBuffer[0] != '[') { if(!ReadNewLine()) { return NULL; } } // Copy the word in the buffer back // Replace "]" because they can not include them in a set for scanf char *lBracketPtr = strchr(mLineBuffer, ']'); if(lBracketPtr != NULL) { *lBracketPtr = '|'; } sscanf(mLineBuffer + 1, " %29[^|]", mReturnBuffer); mParsePtr++; return mReturnBuffer; }
/** * Read the next meaningful line from the input stream into the buffer. * @return @c true if successful, * @c false if the end of the stream has been reached. */ bool TrackSpecParser::ReadNewLine() { if (in.eof()) return false; std::string ris; mParsePtr = mLineBuffer; mLineBuffer[0] = 0; std::getline(in, ris); ASSERT(ris.length() < sizeof(mLineBuffer)); strncat(mLineBuffer, ris.c_str(), sizeof(mLineBuffer) - 1); mLineBuffer[sizeof(mLineBuffer) - 1] = 0; mLineNumber++; char *lPtr = mLineBuffer; bool lJustBlank = true; bool lAfterEqual = false; while(*lPtr != 0) { switch (*lPtr) { // Remove comments and ending CR/LF. case ';': case '#': case 10: case 13: *lPtr = 0; break; case '=': lAfterEqual = true; // Convert to uppercase. default: if(lJustBlank && !isspace(*lPtr)) { lJustBlank = false; } if(!lAfterEqual) { *lPtr = (char) toupper(*lPtr); } } if(*lPtr != 0) { lPtr++; } } // Make sure the line is not empty. if(lJustBlank) { return ReadNewLine(); } else { return true; } }
void TrackSpecParser::Reset() { in.clear(); in.seekg(0, std::ios::beg); mLineBuffer[0] = 0; mParsePtr = mLineBuffer; mLineNumber = 0; ReadNewLine(); }
bool TrackSpecParser::GetNextLine() { if(!ReadNewLine()) { return false; } if(mLineBuffer[0] == '[') { return false; } else { return true; } }
CStrAny Parse::ReadLine(CStrAny &s) { CStrAny sLine = ReadToNewLine(s); sLine >>= ReadNewLine(s); return sLine; }