if (Itm == 0 || Itm->Value.empty() == true)
{
if (Default == 0)
- return "";
+ return rootDir;
else
- return Default;
+ return rootDir + Default;
}
string val = Itm->Value;
return Res;
}
/*}}}*/
+// Configuration::FindVector - Find a vector of values /*{{{*/
+// ---------------------------------------------------------------------
+/* Returns a vector of config values under the given item */
+vector<string> Configuration::FindVector(const char *Name) const
+{
+ vector<string> Vec;
+ const Item *Top = Lookup(Name);
+ if (Top == NULL)
+ return Vec;
+
+ Item *I = Top->Child;
+ while(I != NULL)
+ {
+ Vec.push_back(I->Value);
+ I = I->Next;
+ }
+ return Vec;
+}
+ /*}}}*/
// Configuration::FindI - Find an integer value /*{{{*/
// ---------------------------------------------------------------------
/* */
std::string Input;
// The input line with comments stripped.
std::string Fragment;
+
+ // Grab the next line of F and place it in Input.
do
{
char *Buffer = new char[1024];
F.getline(Buffer,sizeof(Buffer) / 2);
Input += Buffer;
+ delete[] Buffer;
}
while (F.fail() && !F.eof());
+ // Expand tabs in the input line and remove leading and trailing
+ // whitespace.
{
- // Allocate enough space to expand an entire line of tabs
- // below.
const int BufferSize = Input.size() * 8 + 1;
char *Buffer = new char[BufferSize];
try
}
CurLine++;
+ // Now strip comments; if the whole line is contained in a
+ // comment, skip this line.
+
// The first meaningful character in the current fragment; will
// be adjusted below as we remove bytes from the front.
std::string::const_iterator Start = Input.begin();
InQuote = !InQuote;
if (InQuote == true)
continue;
-
- if (*I == '/' && I + 1 != End && I[1] == '/')
- {
+
+ if ((*I == '/' && I + 1 != End && I[1] == '/') ||
+ (*I == '#' && strcmp(string(I,I+6).c_str(),"#clear") != 0 &&
+ strcmp(string(I,I+8).c_str(),"#include") != 0))
+ {
End = I;
break;
}
if (Fragment.empty())
continue;
- // We now have a valid line fragment. Walk down it and
- // interpret it.
+ // The line has actual content; interpret what it means.
InQuote = false;
Start = Fragment.begin();
End = Fragment.end();
for (std::string::const_iterator I = Start;
I != End; ++I)
{
- if(Start > End)
- {
- _error->Error("Why is Start > End?");
- }
-
if (*I == '"')
InQuote = !InQuote;
if (InQuote == false && (*I == '{' || *I == ';' || *I == '}'))
{
// Put the last fragment into the buffer
- std::string::const_iterator FirstNonWhitespace = Start;
- std::string::const_iterator LastNonWhitespace = I;
- for (; FirstNonWhitespace != I && isspace(*FirstNonWhitespace) != 0; FirstNonWhitespace++)
+ std::string::const_iterator NonWhitespaceStart = Start;
+ std::string::const_iterator NonWhitespaceStop = I;
+ for (; NonWhitespaceStart != I && isspace(*NonWhitespaceStart) != 0; NonWhitespaceStart++)
;
- for (; LastNonWhitespace != FirstNonWhitespace && isspace(LastNonWhitespace[-1]) != 0; LastNonWhitespace--)
+ for (; NonWhitespaceStop != NonWhitespaceStart && isspace(NonWhitespaceStop[-1]) != 0; NonWhitespaceStop--)
;
- if (LineBuffer.empty() == false && LastNonWhitespace - FirstNonWhitespace != 0)
+ if (LineBuffer.empty() == false && NonWhitespaceStop - NonWhitespaceStart != 0)
LineBuffer += ' ';
- LineBuffer += string(FirstNonWhitespace, LastNonWhitespace);
+ LineBuffer += string(NonWhitespaceStart, NonWhitespaceStop);
// Drop this from the input string, saving the character
// that terminated the construct we just closed. (i.e., a