+ *errorstream << "Variable name not followed immediately by its value at " << filename << ":" << linenumber << endl;
+ error = true;
+ return "";
+ }
+ else if (!c)
+ {
+ *errorstream << "Value without a variable (line starts with '=') at " << filename << ":" << linenumber << endl;
+ error = true;
+ return "";
+ }
+ else if (buffer[c-1] == '\xA0')
+ {
+ *errorstream << "Variable name not followed immediately by its value at " << filename << ":" << linenumber << endl;
+ error = true;
+ return "";
+ }
+ }
+ }
+ // no quotes, and no equals. something freaky.
+ if ((!number_of_quotes) || (!number_of_equals) && (strlen(buffer)>2) && (buffer[0]=='<'))
+ {
+ *errorstream << "Malformed tag at " << filename << ":" << linenumber << endl;
+ error = true;
+ return "";
+ }
+ // odd number of quotes. thats just wrong.
+ if ((number_of_quotes % 2) != 0)
+ {
+ *errorstream << "Missing \" at " << filename << ":" << linenumber << endl;
+ error = true;
+ return "";
+ }
+ if (number_of_equals < (number_of_quotes/2))
+ {
+ *errorstream << "Missing '=' at " << filename << ":" << linenumber << endl;
+ }
+ if (number_of_equals > (number_of_quotes/2))
+ {
+ *errorstream << "Too many '=' at " << filename << ":" << linenumber << endl;
+ }
+
+ std::string parsedata = buffer;
+ // turn multispace into single space
+ while (parsedata.find("\xA0\xA0") != std::string::npos)
+ {
+ parsedata.erase(parsedata.find("\xA0\xA0"),1);
+ }
+
+ // turn our hardspace back into softspace
+ for (int d = 0; d < parsedata.length(); d++)
+ {
+ if (parsedata[d] == '\xA0')
+ parsedata[d] = ' ';
+ }
+
+ // and we're done, the line is fine!
+ return parsedata;
+}
+
+bool LoadConf(const char* filename, std::stringstream *target, std::stringstream* errorstream)
+{
+ target->str("");
+ errorstream->str("");
+ long linenumber = 1;
+ // first, check that the file exists before we try to do anything with it
+ if (!FileExists(filename))
+ {
+ *errorstream << "File " << filename << " not found." << endl;
+ return false;
+ }
+ // Fix the chmod of the file to restrict it to the current user and group
+ chmod(filename,0600);
+ // now open it
+ FILE* conf = fopen(filename,"r");
+ char buffer[MAXBUF];
+ if (conf)
+ {
+ while (!feof(conf))
+ {
+ if (fgets(buffer, MAXBUF, conf))
+ {
+ if ((!feof(conf)) && (buffer) && (strlen(buffer)))