@@ -378,38 +378,46 @@ void ArgvMap::preParse(int &argc, char **argv, const string &arg)
378
378
}
379
379
}
380
380
381
- bool ArgvMap::parseLine (ifstream& f, const string& arg, string& line, bool lax) {
381
+ bool ArgvMap::parseFile (const char *fname, const string& arg, bool lax) {
382
+ string line;
382
383
string pline;
383
384
string::size_type pos;
384
385
385
- if (!getline (f, pline)) return false ;
386
- trim_right (pline);
387
- if (pline[pline.size ()-1 ]==' \\ ' ) {
388
- line+=pline.substr (0 ,pline.length ()-1 );
389
- return true ;
390
- }
391
- else
392
- line+=pline;
393
-
394
- // strip everything after a #
395
- if ((pos=line.find (" #" ))!=string::npos) {
396
- // make sure it's either first char or has whitespace before
397
- // fixes issue #354
398
- if (pos == 0 || std::isspace (line[pos-1 ]))
399
- line=line.substr (0 ,pos);
400
- }
386
+ ifstream f (fname);
387
+ if (!f)
388
+ return false ;
401
389
402
- // strip trailing spaces
403
- trim_right (line);
390
+ while (getline (f,pline)) {
391
+ trim_right (pline);
392
+
393
+ if (pline[pline.size ()-1 ]==' \\ ' ) {
394
+ line+=pline.substr (0 ,pline.length ()-1 );
395
+ continue ;
396
+ }
397
+ else
398
+ line+=pline;
399
+
400
+ // strip everything after a #
401
+ if ((pos=line.find (" #" ))!=string::npos) {
402
+ // make sure it's either first char or has whitespace before
403
+ // fixes issue #354
404
+ if (pos == 0 || std::isspace (line[pos-1 ]))
405
+ line=line.substr (0 ,pos);
406
+ }
407
+
408
+ // strip trailing spaces
409
+ trim_right (line);
404
410
405
- // strip leading spaces
406
- if ((pos=line.find_first_not_of (" \t\r\n " ))!=string::npos)
407
- line=line.substr (pos);
411
+ // strip leading spaces
412
+ if ((pos=line.find_first_not_of (" \t\r\n " ))!=string::npos)
413
+ line=line.substr (pos);
408
414
409
- // gpgsql-basic-query=sdfsdfs dfsdfsdf sdfsdfsfd
415
+ // gpgsql-basic-query=sdfsdfs dfsdfsdf sdfsdfsfd
416
+
417
+ parseOne ( string (" --" ) + line, arg, lax );
418
+ line=" " ;
419
+ }
410
420
411
- parseOne ( string (" --" ) + line, arg, lax );
412
- line=" " ;
413
421
return true ;
414
422
}
415
423
@@ -418,15 +426,7 @@ bool ArgvMap::preParseFile(const char *fname, const string &arg, const string& t
418
426
{
419
427
params[arg]=theDefault;
420
428
421
- ifstream f (fname);
422
- if (!f)
423
- return false ;
424
-
425
- string line;
426
-
427
- while (parseLine (f, arg, line, false ));
428
-
429
- return true ;
429
+ return parseFile (fname, arg, false );
430
430
}
431
431
432
432
bool ArgvMap::file (const char *fname, bool lax)
@@ -436,17 +436,13 @@ bool ArgvMap::file(const char *fname, bool lax)
436
436
437
437
bool ArgvMap::file (const char *fname, bool lax, bool included)
438
438
{
439
- ifstream f (fname);
440
- if (!f) {
441
- return false ;
442
- }
443
-
444
439
if (!parmIsset (" include-dir" )) // inject include-dir
445
440
set (" include-dir" ," Directory to include configuration files from" );
446
441
447
- string line;
448
-
449
- while (parseLine (f, " " , line, lax));
442
+ if (!parseFile (fname, " " , lax)) {
443
+ L << Logger::Warning << " Unable to open " << fname << std::endl;
444
+ return false ;
445
+ }
450
446
451
447
// handle include here (avoid re-include)
452
448
if (!included && !params[" include-dir" ].empty ()) {
0 commit comments