Changeset 3417
- Timestamp:
- 2002-09-10T17:09:10+12:00 (22 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gsdl/lib/cfgread.cpp
r3010 r3417 25 25 26 26 #include "cfgread.h" 27 #include <ctype.h> // for isspace() 27 28 28 29 int write_ini_line (ofstream &fileout, const text_t &key, const text_t value) { … … 90 91 // ignore status - assume it is "finished" as buffer is big enough 91 92 write(fileout, buffer, num_chars); 92 delete buffer;93 delete[] buffer; 93 94 first = false; 94 95 here ++; … … 101 102 // returns 0 on success, -1 on failure 102 103 int read_cfg_line (ifstream &filein, text_tarray &values) { 103 // outconvertclass text_t2ascii; 104 // we split up the line into tokens, pushing each token into the 105 // values array. Quoted phrases are a single token. A "\" at the end 106 // of a line continues onto the next line. 104 107 105 108 values.erase(values.begin(), values.end()); … … 108 111 109 112 text_t curvalue; 110 char c, quote; 113 char c; 114 filein.get(c); 111 115 112 bool linecontinues = true; 113 filein.get(c); 114 while (!filein.eof() && linecontinues) { 115 // eat up all return characters 116 while (!filein.eof() && (c=='\n' || c=='\r')) { filein.get(c); } 116 // skip white space 117 while (!filein.eof() && isspace(c)) { filein.get(c); } 117 118 118 119 // ignore comments 119 if (c == '#') { 120 while (!filein.eof() && c!='\n' && c!='\r') { filein.get(c); } 120 while (c == '#') { 121 while (!filein.eof() && c!='\n' && c!='\r') { filein.get(c); } 122 // skip white space... 123 while (!filein.eof() && isspace(c)) { filein.get(c); } 124 } 125 126 // deal with all the records on this line (possibly multi-line) 127 while (!filein.eof()) { 128 if (c=='\n' || c=='\r') { // shouldn't happen? 129 break; 121 130 } 122 131 123 // deal with all the records on this line 124 while (!filein.eof() && c!='\n' && c!='\r') { 125 // ignore white space 126 while (!filein.eof() && (c==' ' || c=='\t')) { filein.get(c); } 127 128 // get the next record 129 if (c!='\n' && c!='\r') { 130 curvalue.clear(); 131 quote = 0; 132 133 // see if this is a quoted record 134 if (c=='\'' || c=='\"') { 135 quote = c; 136 filein.get(c); 137 } 138 139 // get the value 140 while (!filein.eof() && c!='\n' && c!='\r') { 141 if (quote != 0 && c == quote) { // end of quote 142 filein.get(c); 143 break; 144 } else if (quote == 0 && (c == ' ' || c == '\t')) { 145 break; // space seperator 146 } 147 curvalue.push_back(c); 148 filein.get(c); 149 } 150 151 // see if the record continues on the next line 152 if ((c=='\n' || c=='\r') && curvalue=="\\") { 153 linecontinues = true; 154 } else { 155 // cerr << text_t2ascii << "\"" << curvalue << "\" "; 156 157 values.push_back(curvalue); 158 curvalue.clear(); 159 linecontinues = false; 160 } 132 // get the next token 133 curvalue.clear(); 134 135 // see if this is a quoted phrase 136 if (c=='\'' || c=='\"') { // starts with a quote 137 char quote, old_c; 138 quote = c; 139 old_c = c; 140 filein.get(c); 141 while (!filein.eof() && (c != quote || old_c == '\\') ) { 142 curvalue.push_back(c); 143 old_c = c; 144 filein.get(c); 145 } 146 // get the character after the closing quote... 147 filein.get(c); 148 } else { // it's not a quoted phrase 149 // get the token 150 while (!filein.eof() && !isspace(c)) { 151 curvalue.push_back(c); 152 filein.get(c); 161 153 } 162 154 } 163 } 155 // we now have a token or a phrase 156 157 // see if we've reached the end of the line 158 if (c == '\n' || c == '\r') { 159 if (curvalue != "\\") { // the line DOESN'T continue. End of line. 160 values.push_back(curvalue); 161 break; 162 } 163 } else { // no new line seen 164 values.push_back(curvalue); 165 } 164 166 165 // cerr << "\n"; 167 curvalue.clear(); 168 169 // the record continues on the next line 170 // remove whitespace before next token 171 while (!filein.eof() && isspace(c)) filein.get(c); 172 173 } // while(1) 174 166 175 167 176 return 0;
Note:
See TracChangeset
for help on using the changeset viewer.