#include "cvs.h"
#include "getline.h"
#include <assert.h>
int
Parse_Info (infofile, repository, callproc, all)
char *infofile;
char *repository;
CALLPROC callproc;
int all;
{
int err = 0;
FILE *fp_info;
char *infopath;
char *line = NULL;
size_t line_allocated = 0;
char *default_value = NULL;
char *expanded_value= NULL;
int callback_done, line_number;
char *cp, *exp, *value, *srepos;
const char *regex_err;
if (CVSroot_original == NULL)
{
error (0, 0, "CVSROOT variable not set");
return (1);
}
infopath = xmalloc (strlen (CVSroot_directory)
+ strlen (infofile)
+ sizeof (CVSROOTADM)
+ 10);
(void) sprintf (infopath, "%s/%s/%s", CVSroot_directory,
CVSROOTADM, infofile);
fp_info = CVS_FOPEN (infopath, "r");
if (fp_info == NULL)
{
if (!existence_error (errno))
error (0, errno, "cannot open %s", infopath);
free (infopath);
return 0;
}
srepos = Short_Repository (repository);
if (trace)
(void) fprintf (stderr, " -> ParseInfo(%s, %s, %s)\n",
infopath, srepos, all ? "ALL" : "not ALL");
callback_done = line_number = 0;
while (getline (&line, &line_allocated, fp_info) >= 0)
{
line_number++;
if (line[0] == '#')
continue;
for (cp = line; *cp && isspace (*cp); cp++)
;
if (*cp == '\0')
continue;
for (exp = cp; *cp && !isspace (*cp); cp++)
;
if (*cp != '\0')
*cp++ = '\0';
while (*cp && isspace (*cp))
cp++;
if (*cp == '\0')
{
error (0, 0, "syntax error at line %d file %s; ignored",
line_number, infofile);
continue;
}
value = cp;
if ((cp = strrchr (value, '\n')) != NULL)
*cp = '\0';
if (expanded_value != NULL)
free (expanded_value);
expanded_value = expand_path (value, infofile, line_number);
if (!expanded_value)
{
continue;
}
if (strcmp (exp, "DEFAULT") == 0)
{
if (default_value != NULL)
free (default_value);
default_value = xstrdup (expanded_value);
continue;
}
if (strcmp (exp, "ALL") == 0)
{
if (all)
err += callproc (repository, expanded_value);
else
error(0, 0, "Keyword `ALL' is ignored at line %d in %s file",
line_number, infofile);
continue;
}
if (callback_done)
continue;
if ((regex_err = re_comp (exp)) != NULL)
{
error (0, 0, "bad regular expression at line %d file %s: %s",
line_number, infofile, regex_err);
continue;
}
if (re_exec (srepos) == 0)
continue;
err += callproc (repository, expanded_value);
callback_done = 1;
}
if (ferror (fp_info))
error (0, errno, "cannot read %s", infopath);
if (fclose (fp_info) < 0)
error (0, errno, "cannot close %s", infopath);
if (callback_done == 0 && default_value != NULL)
err += callproc (repository, default_value);
if (default_value != NULL)
free (default_value);
if (expanded_value != NULL)
free (expanded_value);
free (infopath);
if (line != NULL)
free (line);
return (err);
}
int
parse_config (cvsroot)
char *cvsroot;
{
char *infopath;
FILE *fp_info;
char *line = NULL;
size_t line_allocated = 0;
size_t len;
char *p;
static int parsed = 0;
if (parsed)
return 0;
parsed = 1;
infopath = malloc (strlen (cvsroot)
+ sizeof (CVSROOTADM_CONFIG)
+ sizeof (CVSROOTADM)
+ 10);
if (infopath == NULL)
{
error (0, 0, "out of memory; cannot allocate infopath");
goto error_return;
}
strcpy (infopath, cvsroot);
strcat (infopath, "/");
strcat (infopath, CVSROOTADM);
strcat (infopath, "/");
strcat (infopath, CVSROOTADM_CONFIG);
fp_info = CVS_FOPEN (infopath, "r");
if (fp_info == NULL)
{
if (!existence_error (errno))
{
error (0, errno, "cannot open %s", infopath);
}
free (infopath);
return 0;
}
while (getline (&line, &line_allocated, fp_info) >= 0)
{
if (line[0] == '#')
continue;
len = strlen (line) - 1;
if (line[len] == '\n')
line[len] = '\0';
if (line[0] == '\0')
continue;
p = strchr (line, '=');
if (p == NULL)
{
error (0, 0, "syntax error in %s: line '%s' is missing '='",
infopath, line);
goto error_return;
}
*p++ = '\0';
if (strcmp (line, "RCSBIN") == 0)
{
;
}
else if (strcmp (line, "SystemAuth") == 0)
{
if (strcmp (p, "no") == 0)
#ifdef AUTH_SERVER_SUPPORT
system_auth = 0;
#else
;
#endif
else if (strcmp (p, "yes") == 0)
#ifdef AUTH_SERVER_SUPPORT
system_auth = 1;
#else
;
#endif
else
{
error (0, 0, "unrecognized value '%s' for SystemAuth", p);
goto error_return;
}
}
else if (strcmp (line, "PreservePermissions") == 0)
{
if (strcmp (p, "no") == 0)
preserve_perms = 0;
else if (strcmp (p, "yes") == 0)
{
#ifdef PRESERVE_PERMISSIONS_SUPPORT
preserve_perms = 1;
#else
error (0, 0, "\
warning: this CVS does not support PreservePermissions");
#endif
}
else
{
error (0, 0, "unrecognized value '%s' for PreservePermissions",
p);
goto error_return;
}
}
else if (strcmp (line, "TopLevelAdmin") == 0)
{
if (strcmp (p, "no") == 0)
top_level_admin = 0;
else if (strcmp (p, "yes") == 0)
top_level_admin = 1;
else
{
error (0, 0, "unrecognized value '%s' for TopLevelAdmin", p);
goto error_return;
}
}
else
{
error (0, 0, "%s: unrecognized keyword '%s'",
infopath, line);
goto error_return;
}
}
if (ferror (fp_info))
{
error (0, errno, "cannot read %s", infopath);
goto error_return;
}
if (fclose (fp_info) < 0)
{
error (0, errno, "cannot close %s", infopath);
goto error_return;
}
free (infopath);
if (line != NULL)
free (line);
return 0;
error_return:
if (infopath != NULL)
free (infopath);
if (line != NULL)
free (line);
return -1;
}