PointListPtr PointList::FromDelStr (const KKStr& _s) { PointListPtr result = new PointList (true); KKStr s (_s); s.TrimLeft (); while (s.Len () > 0) { char nextCh = s.FirstChar (); char endPairChar = 0; if (nextCh == '[') endPairChar = ']'; else if (nextCh == '(') endPairChar = ')'; else { // Not Bracketed. endPairChar = 0; kkint16 row = (kkint16)s.ExtractTokenInt (",\t\n\t"); kkint16 col = (kkint16)s.ExtractTokenInt (",\t\n\t"); result->PushOnBack (new Point (row, col)); } if (endPairChar != 0) { KKStr pairStr = ""; auto idx = s.Find (endPairChar); if (idx) { pairStr = s.SubStrSeg (0, idx); s = s.SubStrPart (idx + 1); } else { pairStr = s; s = ""; } kkint16 row = (kkint16)pairStr.ExtractTokenInt (","); kkint16 col = (kkint16)pairStr.ExtractTokenInt (","); result->PushOnBack (new Point (row, col)); nextCh = s.FirstChar (); if ((nextCh == ',') || (nextCh == '\n') || (nextCh == '\r') || (nextCh == '\t')) s.ChopFirstChar (); } s.TrimLeft (); } return result; } /* FromDelStr */
XmlTag::XmlTag (istream& i) { tagType = tagNULL; if (i.peek () == '<') i.get (); KKStr tagStr (100); ReadWholeTag (i, tagStr); if (tagStr.FirstChar () == '/') { tagStr.ChopFirstChar (); tagType = tagEnd; } if (tagStr.EndsWith ("/>")) { tagType = tagEmpty; tagStr.ChopLastChar (); tagStr.ChopLastChar (); } else if (tagStr.LastChar () != '>') { tagType = tagStart; } else { if (tagType == tagNULL) tagType = tagStart; tagStr.ChopLastChar (); } name.TrimLeft (); name.TrimRight (); name = tagStr.ExtractToken2 (" \n\r\t"); KKStr attributeName (20); KKStr attributeValue (20); while (!tagStr.Empty ()) { ExtractAttribute (tagStr, attributeName, attributeValue); if (!attributeName.Empty ()) attributes.push_back (XmlAttribute (attributeName, attributeValue)); } }
void Configuration::LoadFile (RunLog& log) { log.Level (10) << "Configuration::LoadFile: " << fileName << endl; kkint32 lastLineNum = 0; if (fileName == "") { log.Level (-1) << endl << "Configuration::LoadFile ***ERROR*** File-Name is blank" << endl << endl; FormatGood (false); return; } FILE* inFile = osFOPEN (fileName.Str (), "r"); if (!inFile) { log.Level (-1) << endl << "Configuration::LoadFile ***ERROR*** Opening File: " << fileName << endl << endl; FormatGood (false); return; } char buff[10240]; kkint32 lineCount = 0; curSectionName = ""; ConfSectionPtr curSection = NULL; while (fgets (buff, sizeof (buff), inFile)) { lastLineNum++; KKStr line (buff); line.TrimRight (); line.TrimLeft (); StripOutAnyComments (line); log.Level (70) << line << endl; StripOutAnyComments (line); if (line.Empty ()) { // If we have a blank line, we do nothing. } else if (line.FirstChar () == '[') { // Looks like definition of new section. if (line.LastChar () == ']') { curSectionName = line.SubStrPart (1, line.Len () - 2); curSectionName.TrimLeft (); curSectionName.TrimRight (); curSectionName.Upper (); curSection = new ConfSection (curSectionName, lastLineNum); sections->AddConfSection (curSection); log.Level (30) << "LoadFile SectionName[" << curSectionName << "]." << endl; } else { log.Level (-1) << endl << "Configuration::LoadFile ***ERROR*** LineNumber[" << lastLineNum << "] Improper Section Name[" << line << "]." << endl << endl; formatGood = false; } } else { if (!curSection) { log.Level (-1) << endl << "Configuration::LoadFile ***ERROR*** Format Error LineNumber[" << lastLineNum << "]" << endl << " No Section Defined." << endl << endl; formatGood = false; curSectionName = "GLOBAL"; curSection = new ConfSection (curSectionName, lastLineNum); sections->AddConfSection (curSection); } kkint32 equalIdx = line.LocateCharacter ('='); if (equalIdx < 0) { // We have a improperly formated line. log.Level (-1) << endl << "Configuration::LoadFile ***ERROR*** LineNumber[" << lastLineNum << "] Improperly Formated Line[" << line << "]." << endl; formatGood = false; } else { KKStr settingName (line.SubStrPart (0, equalIdx - 1)); settingName.TrimLeft (); settingName.TrimRight (); settingName.Upper (); KKStr settingValue (line.SubStrPart (equalIdx + 1)); settingValue.TrimLeft (); settingValue.TrimRight (); log.Level (30) << "LoadFile SectionName[" << curSectionName << "], " << "Setting[" << settingName << "], Value[" << settingValue << "]." << endl; curSection->AddSetting (settingName, settingValue, lastLineNum); } lineCount++; } } fclose (inFile); } /* LoadFile */