379 |
FILE *fp_info; |
FILE *fp_info; |
380 |
char *line = NULL; |
char *line = NULL; |
381 |
unsigned int ln; /* Input file line counter. */ |
unsigned int ln; /* Input file line counter. */ |
382 |
size_t line_allocated = 0; |
char *buf = NULL; |
383 |
|
size_t buf_allocated = 0; |
384 |
size_t len; |
size_t len; |
385 |
char *p; |
char *p; |
386 |
struct config *retval; |
struct config *retval; |
387 |
|
/* PROCESSING Whether config keys are currently being processed for |
388 |
|
* this root. |
389 |
|
* PROCESSED Whether any keys have been processed for this root. |
390 |
|
* This is initialized to true so that any initial keys |
391 |
|
* may be processed as global defaults. |
392 |
|
*/ |
393 |
|
bool processing = true; |
394 |
|
bool processed = true; |
395 |
|
|
396 |
TRACE (TRACE_FUNCTION, "parse_config (%s)", cvsroot); |
TRACE (TRACE_FUNCTION, "parse_config (%s)", cvsroot); |
397 |
|
|
444 |
} |
} |
445 |
|
|
446 |
ln = 0; /* Have not read any lines yet. */ |
ln = 0; /* Have not read any lines yet. */ |
447 |
while (getline (&line, &line_allocated, fp_info) >= 0) |
while (getline (&buf, &buf_allocated, fp_info) >= 0) |
448 |
{ |
{ |
449 |
ln++; /* Keep track of input file line number for error messages. */ |
ln++; /* Keep track of input file line number for error messages. */ |
450 |
|
|
451 |
|
line = buf; |
452 |
|
|
453 |
|
/* Skip leading white space. */ |
454 |
|
while (isspace (*line)) line++; |
455 |
|
|
456 |
/* Skip comments. */ |
/* Skip comments. */ |
457 |
if (line[0] == '#') |
if (line[0] == '#') |
458 |
continue; |
continue; |
459 |
|
|
460 |
/* At least for the moment we don't skip whitespace at the start |
/* Is there any kind of written standard for the syntax of this |
|
of the line. Too picky? Maybe. But being insufficiently |
|
|
picky leads to all sorts of confusion, and it is a lot easier |
|
|
to start out picky and relax it than the other way around. |
|
|
|
|
|
Is there any kind of written standard for the syntax of this |
|
461 |
sort of config file? Anywhere in POSIX for example (I guess |
sort of config file? Anywhere in POSIX for example (I guess |
462 |
makefiles are sort of close)? Red Hat Linux has a bunch of |
makefiles are sort of close)? Red Hat Linux has a bunch of |
463 |
these too (with some GUI tools which edit them)... |
these too (with some GUI tools which edit them)... |
473 |
|
|
474 |
len = strlen (line) - 1; |
len = strlen (line) - 1; |
475 |
if (line[len] == '\n') |
if (line[len] == '\n') |
476 |
line[len] = '\0'; |
line[len--] = '\0'; |
477 |
|
|
478 |
/* Skip blank lines. */ |
/* Skip blank lines. */ |
479 |
if (line[0] == '\0') |
if (line[0] == '\0') |
481 |
|
|
482 |
TRACE (TRACE_DATA, "parse_info() examining line: `%s'", line); |
TRACE (TRACE_DATA, "parse_info() examining line: `%s'", line); |
483 |
|
|
484 |
|
/* Check for a root specification. */ |
485 |
|
if (line[0] == '[' && line[len] == ']') |
486 |
|
{ |
487 |
|
cvsroot_t *tmproot; |
488 |
|
|
489 |
|
line++[len] = '\0'; |
490 |
|
tmproot = parse_cvsroot (line); |
491 |
|
|
492 |
|
/* Ignoring method. */ |
493 |
|
if (!tmproot |
494 |
|
/* FIXME: Check isThisHost (tmproot->hostname). */ |
495 |
|
|| (tmproot->method != local_method |
496 |
|
&& (!tmproot->hostname || !isThisHost (tmproot->hostname))) |
497 |
|
|| !isSamePath (tmproot->directory, cvsroot)) |
498 |
|
{ |
499 |
|
if (processed) processing = false; |
500 |
|
} |
501 |
|
else |
502 |
|
{ |
503 |
|
TRACE (TRACE_FLOW, "Matched root section`%s'", line); |
504 |
|
processing = true; |
505 |
|
processed = false; |
506 |
|
} |
507 |
|
|
508 |
|
continue; |
509 |
|
} |
510 |
|
|
511 |
|
/* There is data on this line. */ |
512 |
|
|
513 |
|
/* Even if the data is bad or ignored, consider data processed for |
514 |
|
* this root. |
515 |
|
*/ |
516 |
|
processed = true; |
517 |
|
|
518 |
|
if (!processing) |
519 |
|
/* ...but it is for a different root. */ |
520 |
|
continue; |
521 |
|
|
522 |
/* The first '=' separates keyword from value. */ |
/* The first '=' separates keyword from value. */ |
523 |
p = strchr (line, '='); |
p = strchr (line, '='); |
524 |
if (!p) |
if (!p) |
706 |
if (fclose (fp_info) < 0) |
if (fclose (fp_info) < 0) |
707 |
error (0, errno, "cannot close %s", infopath); |
error (0, errno, "cannot close %s", infopath); |
708 |
if (freeinfopath) free (freeinfopath); |
if (freeinfopath) free (freeinfopath); |
709 |
if (line) free (line); |
if (buf) free (buf); |
710 |
|
|
711 |
return retval; |
return retval; |
712 |
} |
} |