Changeset 522
- Timestamp:
- Dec 25, 2007, 1:51:27 AM (15 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/bin/svndigest.cc
r519 r522 79 79 } 80 80 catch (std::runtime_error e) { 81 std::cerr << e.what() << std::endl; 81 std::cerr << "svndigest: invalid config file\n" 82 << e.what() << std::endl; 82 83 exit(-1); 83 84 } -
trunk/lib/Configuration.cc
r521 r522 148 148 continue; 149 149 } 150 getline(ss, tmp, '='); 151 std::string lhs = trim(tmp); 152 getline(ss, tmp); 153 std::string rhs = trim(tmp); 150 std::string lhs; 151 getline(ss, lhs, '='); 152 lhs = trim(lhs); 153 std::string rhs; 154 getline(ss, rhs); 155 rhs = trim(rhs); 154 156 if (rhs.empty()){ 155 std::stringstream mess; 156 mess << "svndigest: invalid config file: " 157 << "line: `" << line << "' is invalid."; 158 throw std::runtime_error(mess.str()); 157 throw Config_error(line, "expected format: <lhs> = <rhs>"); 159 158 } 160 159 if (section == "copyright-alias"){ … … 163 162 if (iter!=copyright_alias_.end() && iter->first==lhs){ 164 163 std::stringstream mess; 165 mess << "svndigest: invalid config file: " 166 << "in copright-alias section " << lhs << " defined twice."; 167 throw std::runtime_error(mess.str()); 164 mess << "in copright-alias section " << lhs << " defined twice."; 165 throw Config_error(line, mess.str()); 168 166 } 169 167 … … 176 174 else { 177 175 std::stringstream mess; 178 mess << "svndigest: invalid config file: " 179 << "in trac section" << lhs + " is invalid option."; 180 throw std::runtime_error(mess.str()); 176 mess << "in trac section" << lhs + " is invalid option."; 177 throw Config_error(line, mess.str()); 181 178 } 182 179 } … … 188 185 missing_copyright_warning_ = true; 189 186 else { 190 std::stringstream mess; 191 mess << "svndigest: invalid config file: " 192 << "line: `" << line << "' is invalid."; 193 throw std::runtime_error(mess.str()); 187 throw Config_error(line, ""); 194 188 } 195 189 } … … 203 197 if (codon(lhs)) { 204 198 std::stringstream mess; 205 mess << "svndigest: invalid config file\n" 206 << "line: `" << line << "' is invalid.\n" 207 << "clashes with previous given file name pattern: "; 199 mess << "clashes with previous given file name pattern: "; 208 200 // find previous file-name-pattern 209 201 for (String2Codons::const_iterator i(string2codons_.begin()); … … 215 207 } 216 208 } 217 throw std::runtime_error(mess.str());209 throw Config_error(line, mess.str()); 218 210 } 219 211 std::stringstream ss(rhs); … … 221 213 while (getline(ss, start, ':')) { 222 214 start = trim(start); 223 start = start.substr(1, start.size()-2);224 215 std::string end; 225 216 getline(ss, end, ';'); 226 217 end = trim(end); 227 end = end.substr(1, end.size()-2); 228 if (!start.empty() && !end.empty()) { 229 replace(start, "\\n", "\n"); 230 replace(end, "\\n", "\n"); 231 add_codon(lhs, start, end); 218 if (start.empty() && end.empty()) 219 continue; 220 try { 221 if (start.empty() || start=="\"\"") { 222 throw std::runtime_error("start-code is empty"); 223 } 224 else if (start.size()<3) { 225 std::stringstream mess; 226 mess << "start-code `" << start << "' is invalid"; 227 throw std::runtime_error(mess.str()); 228 } 229 start = trim(start, '"'); 230 if (end.empty() || end=="\"\"") { 231 throw std::runtime_error("end-code is empty"); 232 } 233 else if (end.size()<3) { 234 std::stringstream mess; 235 mess << "end-code `" << end << "' is invalid"; 236 throw std::runtime_error(mess.str()); 237 } 238 end = trim(end, '"'); 232 239 } 233 else if (!start.empty() || !end.empty()) { 234 std::cout << start << "\n" << end << std::endl; 235 std::stringstream mess; 236 mess << "svndigest: invalid config file\n" 237 << "line: `" << line << "' is invalid.\n"; 238 throw std::runtime_error(mess.str()); 240 catch (std::runtime_error& e){ 241 throw Config_error(line, e.what()); 239 242 } 243 replace(start, "\\n", "\n"); 244 replace(end, "\\n", "\n"); 245 add_codon(lhs, start, end); 240 246 } 241 247 } … … 249 255 if (const std::pair<std::string, std::string>* entry=dictionary(lhs)) { 250 256 std::stringstream mess; 251 mess << "svndigest: invalid config file\n" 252 << "line: `" << line << "' is invalid.\n" 253 << "clashes with previous given file name pattern: " 257 mess << "clashes with previous given file name pattern: " 254 258 << "`" << entry->first << "'"; 255 throw std::runtime_error(mess.str());259 throw Config_error(line, mess.str()); 256 260 } 257 261 lhs = trim(lhs); … … 260 264 dictionary_.push_back(std::make_pair(lhs, rhs)); 261 265 else if (!lhs.empty() || !rhs.empty()) { 262 std::stringstream mess; 263 mess << "svndigest: invalid config file\n" 264 << "line: `" << line << "' is invalid.\n"; 265 throw std::runtime_error(mess.str()); 266 throw Config_error(line, ""); 266 267 } 267 268 } … … 337 338 return std::string("\\n") + str.substr(1); 338 339 return str; 340 } 341 342 343 std::string trim(std::string str, char c) 344 { 345 if (str.size()<2 || str[0]!=c || str[str.size()-1]!=c){ 346 std::stringstream mess; 347 mess << "expected `" << str << "' to be surrounded by `" << c << "'"; 348 throw std::runtime_error(mess.str()); 349 } 350 return str.substr(1, str.size()-2); 339 351 } 340 352 … … 489 501 } 490 502 503 504 Config_error::Config_error(const std::string& line,const std::string& message) 505 : std::runtime_error(std::string("line: `") + line + 506 std::string("' is invalid.\n") + message) 507 {} 491 508 492 509 }} // end of namespace svndigest and namespace theplu -
trunk/lib/Configuration.h
r519 r522 29 29 #include <iostream> 30 30 #include <map> 31 #include <stdexcept> 31 32 #include <string> 32 33 #include <utility> … … 141 142 std::string trans_beg_code(std::string); 142 143 144 /** 145 Trim \a c from beginning and end of string \a str; 146 147 \return resulting string 148 149 \throw if first or last character of \a str is NOT character \a c 150 */ 151 std::string trim(std::string str, char c); 152 153 /** 154 \brief Class for errors when reading config file. 155 */ 156 class Config_error : public std::runtime_error 157 { 158 public: 159 Config_error(const std::string& line, const std::string& message); 160 }; 161 143 162 }} // end of namespace svndigest and namespace theplu 144 163
Note: See TracChangeset
for help on using the changeset viewer.