// -*- mode: cpp; mode: fold -*-
// Description /*{{{*/
-// $Id: configuration.cc,v 1.8 1998/10/22 04:56:45 jgg Exp $
+// $Id: configuration.cc,v 1.12 1999/01/27 02:48:52 jgg Exp $
/* ######################################################################
Configuration Class
#endif
#include <apt-pkg/configuration.h>
#include <apt-pkg/error.h>
-#include <strutl.h>
+#include <apt-pkg/strutl.h>
#include <stdio.h>
#include <fstream.h>
int Res = 1;
Item *I = Head->Child;
Item **Last = &Head->Child;
- for (; I != 0; Last = &I->Next, I = I->Next)
- if ((Res = stringcasecmp(I->Tag.begin(),I->Tag.end(),S,S + Len)) == 0)
- break;
+ // Empty strings match nothing. They are used for lists.
+ if (Len != 0)
+ {
+ for (; I != 0; Last = &I->Next, I = I->Next)
+ if ((Res = stringcasecmp(I->Tag.begin(),I->Tag.end(),S,S + Len)) == 0)
+ break;
+ }
+ else
+ for (; I != 0; Last = &I->Next, I = I->Next);
+
if (Res == 0)
return I;
if (Create == false)
const char *End = Start + strlen(Name);
const char *TagEnd = Name;
Item *Itm = Root;
- for (; End - TagEnd > 2; TagEnd++)
+ for (; End - TagEnd >= 2; TagEnd++)
{
if (TagEnd[0] == ':' && TagEnd[1] == ':')
{
}
}
+ // This must be a trailing ::, we create unique items in a list
+ if (End - Start == 0)
+ {
+ if (Create == false)
+ return 0;
+ }
+
Itm = Lookup(Itm,Start,End - Start,Create);
return Itm;
}
return true;
}
/*}}}*/
+// Configuration::Dump - Dump the config /*{{{*/
+// ---------------------------------------------------------------------
+/* Dump the entire configuration space */
+void Configuration::Dump()
+{
+ /* Write out all of the configuration directives by walking the
+ configuration tree */
+ const Configuration::Item *Top = _config->Tree(0);
+ for (; Top != 0;)
+ {
+ clog << Top->FullTag() << " \"" << Top->Value << "\";" << endl;
+
+ if (Top->Child != 0)
+ {
+ Top = Top->Child;
+ continue;
+ }
+
+ while (Top != 0 && Top->Next == 0)
+ Top = Top->Parent;
+ if (Top != 0)
+ Top = Top->Next;
+ }
+}
+ /*}}}*/
// Configuration::Item::FullTag - Return the fully scoped tag /*{{{*/
// ---------------------------------------------------------------------
}
// Discard single line comments
+ bool InQuote = false;
for (char *I = Buffer; *I != 0; I++)
{
+ if (*I == '"')
+ InQuote = !InQuote;
+ if (InQuote == true)
+ continue;
+
if (*I == '/' && I[1] == '/')
{
*I = 0;
// Look for multi line comments
for (char *I = Buffer; *I != 0; I++)
{
+ if (*I == '"')
+ InQuote = !InQuote;
+ if (InQuote == true)
+ continue;
+
if (*I == '/' && I[1] == '*')
{
InComment = true;
continue;
// Parse off the tag
- string::size_type Pos = LineBuffer.find(' ');
- if (Pos == string::npos)
- {
- if (TermChar == '{')
- Pos = LineBuffer.length();
- else
- return _error->Error("Syntax error %s:%u: Tag with no value",FName.c_str(),CurLine);
- }
+ string Tag;
+ const char *Pos = LineBuffer.c_str();
+ if (ParseQuoteWord(Pos,Tag) == false)
+ return _error->Error("Syntax error %s:%u: Malformed Tag",FName.c_str(),CurLine);
- string Tag = string(LineBuffer,0,Pos);
-
// Go down a level
if (TermChar == '{')
{
Tag = string();
}
- // We dont have a value to set
- if (Pos == LineBuffer.length())
+ // Parse off the word
+ string Word;
+ if (ParseCWord(Pos,Word) == false)
{
- LineBuffer = string();
- continue;
+ if (TermChar != '{')
+ {
+ Word = Tag;
+ Tag = "";
+ }
}
- // Parse off the word
- string Word;
- if (ParseCWord(LineBuffer.c_str()+Pos,Word) == false)
- return _error->Error("Syntax error %s:%u: Malformed value",FName.c_str(),CurLine);
-
// Generate the item name
string Item;
if (ParentTag.empty() == true)
Item = Tag;
else
{
- if (Tag.empty() == true)
- Item = ParentTag;
- else
+ if (TermChar != '{' || Tag.empty() == false)
Item = ParentTag + "::" + Tag;
+ else
+ Item = ParentTag;
}
// Set the item in the configuration class