X-Git-Url: https://git.saurik.com/apt.git/blobdiff_plain/3f807f6c39dd6056fca04264ae896990a83c7244..29bc4c1c75d3d1ca4e6133a7685980483c34f58d:/apt-pkg/contrib/configuration.cc diff --git a/apt-pkg/contrib/configuration.cc b/apt-pkg/contrib/configuration.cc index 3140be446..48a5f0bff 100644 --- a/apt-pkg/contrib/configuration.cc +++ b/apt-pkg/contrib/configuration.cc @@ -182,9 +182,9 @@ string Configuration::FindFile(const char *Name,const char *Default) const if (Itm == 0 || Itm->Value.empty() == true) { if (Default == 0) - return ""; + return rootDir; else - return Default; + return rootDir + Default; } string val = Itm->Value; @@ -511,6 +511,8 @@ bool ReadConfigFile(Configuration &Conf,const string &FName,bool AsSectional, 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]; @@ -519,12 +521,13 @@ bool ReadConfigFile(Configuration &Conf,const string &FName,bool AsSectional, 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 @@ -544,6 +547,9 @@ bool ReadConfigFile(Configuration &Conf,const string &FName,bool AsSectional, } 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(); @@ -577,7 +583,7 @@ bool ReadConfigFile(Configuration &Conf,const string &FName,bool AsSectional, if (InQuote == true) continue; - if (*I == '/' && I + 1 != End && I[1] == '/') + if ((*I == '/' && I + 1 != End && I[1] == '/') || *I == '#') { End = I; break; @@ -623,34 +629,28 @@ bool ReadConfigFile(Configuration &Conf,const string &FName,bool AsSectional, 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