diff options
Diffstat (limited to 'contrib/cvs/src/parseinfo.c')
-rw-r--r-- | contrib/cvs/src/parseinfo.c | 60 |
1 files changed, 35 insertions, 25 deletions
diff --git a/contrib/cvs/src/parseinfo.c b/contrib/cvs/src/parseinfo.c index 9771692..27f7d79 100644 --- a/contrib/cvs/src/parseinfo.c +++ b/contrib/cvs/src/parseinfo.c @@ -14,15 +14,16 @@ extern char *logHistory; /* * Parse the INFOFILE file for the specified REPOSITORY. Invoke CALLPROC for - * the first line in the file that matches the REPOSITORY, or if ALL != 0, any lines - * matching "ALL", or if no lines match, the last line matching "DEFAULT". + * the first line in the file that matches the REPOSITORY, or if ALL != 0, any + * lines matching "ALL", or if no lines match, the last line matching + * "DEFAULT". * * Return 0 for success, -1 if there was not an INFOFILE, and >0 for failure. */ int Parse_Info (infofile, repository, callproc, all) - char *infofile; - char *repository; + const char *infofile; + const char *repository; CALLPROC callproc; int all; { @@ -32,9 +33,11 @@ Parse_Info (infofile, repository, callproc, all) char *line = NULL; size_t line_allocated = 0; char *default_value = NULL; - char *expanded_value= NULL; + int default_line = 0; + char *expanded_value; int callback_done, line_number; - char *cp, *exp, *value, *srepos, bad; + char *cp, *exp, *value; + const char *srepos; const char *regex_err; if (current_parsed_root == NULL) @@ -114,10 +117,6 @@ Parse_Info (infofile, repository, callproc, all) if ((cp = strrchr (value, '\n')) != NULL) *cp = '\0'; - if (expanded_value != NULL) - free (expanded_value); - expanded_value = expand_path (value, infofile, line_number); - /* * At this point, exp points to the regular expression, and value * points to the value to call the callback routine with. Evaluate @@ -128,12 +127,14 @@ Parse_Info (infofile, repository, callproc, all) /* save the default value so we have it later if we need it */ if (strcmp (exp, "DEFAULT") == 0) { - /* Is it OK to silently ignore all but the last DEFAULT - expression? */ - if (default_value != NULL && default_value != &bad) + if (default_value != NULL) + { + error (0, 0, "Multiple `DEFAULT' lines (%d and %d) in %s file", + default_line, line_number, infofile); free (default_value); - default_value = (expanded_value != NULL ? - xstrdup (expanded_value) : &bad); + } + default_value = xstrdup(value); + default_line = line_number; continue; } @@ -147,8 +148,12 @@ Parse_Info (infofile, repository, callproc, all) if (!all) error(0, 0, "Keyword `ALL' is ignored at line %d in %s file", line_number, infofile); - else if (expanded_value != NULL) + else if ((expanded_value = expand_path (value, infofile, + line_number)) != NULL) + { err += callproc (repository, expanded_value); + free (expanded_value); + } else err++; continue; @@ -169,8 +174,11 @@ Parse_Info (infofile, repository, callproc, all) continue; /* no match */ /* it did, so do the callback and note that we did one */ - if (expanded_value != NULL) + if ((expanded_value = expand_path (value, infofile, line_number)) != NULL) + { err += callproc (repository, expanded_value); + free (expanded_value); + } else err++; callback_done = 1; @@ -183,17 +191,18 @@ Parse_Info (infofile, repository, callproc, all) /* if we fell through and didn't callback at all, do the default */ if (callback_done == 0 && default_value != NULL) { - if (default_value != &bad) - err += callproc (repository, default_value); + if ((expanded_value = expand_path (default_value, infofile, default_line)) != NULL) + { + err += callproc (repository, expanded_value); + free (expanded_value); + } else err++; } /* free up space if necessary */ - if (default_value != NULL && default_value != &bad) + if (default_value != NULL) free (default_value); - if (expanded_value != NULL) - free (expanded_value); free (infopath); if (line != NULL) free (line); @@ -209,8 +218,9 @@ Parse_Info (infofile, repository, callproc, all) KEYWORD=VALUE. There is currently no way to have a multi-line VALUE (would be nice if there was, probably). - CVSROOT is the $CVSROOT directory (current_parsed_root->directory might not be - set yet). + CVSROOT is the $CVSROOT directory + (current_parsed_root->directory might not be set yet, so this + function takes the cvsroot as a function argument). Returns 0 for success, negative value for failure. Call error(0, ...) on errors in addition to the return value. */ @@ -285,7 +295,7 @@ parse_config (cvsroot) for making sure the syntax is consistent. Any good examples to follow there (Apache?)? */ - /* Strip the training newline. There will be one unless we + /* Strip the trailing newline. There will be one unless we read a partial line without a newline, and then got end of file (or error?). */ |