From 7c5076198f213707f9b136bef9ec076982349d64 Mon Sep 17 00:00:00 2001 From: Silvan Calarco Date: Sun, 6 Oct 2013 20:26:34 +0200 Subject: [PATCH] Better management of firstconfigtag and configtag global variables --- src/distromatic.c | 6 +++++- src/functions.c | 28 +++++++++++++--------------- src/include/distromatic.h | 2 -- src/include/functions.h | 2 +- 4 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/distromatic.c b/src/distromatic.c index 5789836..be4224f 100644 --- a/src/distromatic.c +++ b/src/distromatic.c @@ -112,6 +112,8 @@ PROGRAMNAME " version " PROGRAMVERSION, (char *)0 }; +static struct configTag *firstconfigtag = NULL, *configtag = NULL; + unsigned int quietmode = 0; unsigned int genheader_mode = GENHEADER_BASE + GENHEADER_REQUIREMENTS; unsigned int mode = 0; @@ -1070,12 +1072,14 @@ main(int argc, char *argv[]) strcpy(configfile, DEFAULT_CONFIGFILE); } - if (read_configuration(configfile, repository_tag)) { + firstconfigtag = read_configuration(configfile); + if (!firstconfigtag) { fprintf(stderr, "Fatal error while parsing config file %s; aborting.\n",configfile); exit(1); } + configtag = findRepositoryByTag(repository_tag); if (!configtag) { fprintf(stderr, "Fatal error: configuration missing for given tag\n"); diff --git a/src/functions.c b/src/functions.c index d88984f..28b74f6 100644 --- a/src/functions.c +++ b/src/functions.c @@ -74,6 +74,8 @@ #include "changelog.h" static int debug_log = 0; +static struct configDefaults configdefaults; +static struct configTag *firstconfigtag = NULL; struct configTag* findRepositoryByTag(const char *tag) { @@ -84,7 +86,7 @@ struct configTag* findRepositoryByTag(const char *tag) if (ct) return ct; else return NULL; } -int read_configuration(const char *confFile, const char *tag) +struct configTag* read_configuration(const char *confFile) { FILE *fin; @@ -97,7 +99,7 @@ int read_configuration(const char *confFile, const char *tag) struct Packager *currmaintainer; if ((fin = fopen(confFile, "r")) == NULL) { - return 1; + return NULL; } unsigned int configsection = 0; @@ -134,7 +136,7 @@ int read_configuration(const char *confFile, const char *tag) newconfigtag = malloc(sizeof(struct configTag)); if (!newconfigtag) { fprintf(stderr, "The system is out of memory\n"); - return 1; + return NULL; } newconfigtag->tag = @@ -164,10 +166,6 @@ int read_configuration(const char *confFile, const char *tag) newconfigtag->html_dir = (char *) strdup(buf); } - if ((!tag) || (!strcmp(newconfigtag->tag, tag))) { - configtag = newconfigtag; - } - if (!currconfigtag) { firstconfigtag = newconfigtag; } else { @@ -218,13 +216,13 @@ int read_configuration(const char *confFile, const char *tag) if (vartok) { fprintf(stderr, "Error: exceeding number of archs defined; maximum is %d.",ARCHS_MAX); - return 1; + return NULL; } else { currconfigtag->arch[i] = NULL; } } else { fprintf(stderr, "Undefined token: %s\n", vartok); - return 1; + return NULL; } } else if (configsection == CONF_DEFAULTS_SECTION) { /* we are in the default section */ @@ -259,13 +257,13 @@ int read_configuration(const char *confFile, const char *tag) if (vartok) { fprintf(stderr, "Error: exceeding number of archs defined; maximum is %d.",ARCHS_MAX); - return 1; + return NULL; } } else { fprintf(stderr, "Invalid token for `defaults' tag: %s\n", vartok); - return 1; + return NULL; } } else if (configsection == CONF_MAINTAINERS_SECTION) { @@ -275,7 +273,7 @@ int read_configuration(const char *confFile, const char *tag) if (!currmaintainer) { fprintf(stderr, "Error: cannot create maintainers; aborting."); - return 1; + return NULL; } currmaintainer->role |= PACKAGER_ROLE_MAINTAINER; @@ -294,7 +292,7 @@ int read_configuration(const char *confFile, const char *tag) if (vartok) { fprintf(stderr, "Error: exceeding number of aliases defined for maintainer %s.",currmaintainer->name); - return 1; + return NULL; } } } @@ -306,7 +304,7 @@ int read_configuration(const char *confFile, const char *tag) fprintf(stderr, "REPOSITORY_DIR not given for tag %s\n", currconfigtag->tag); - return 1; + return NULL; } if (!currconfigtag->repository_source_dir) { @@ -332,7 +330,7 @@ int read_configuration(const char *confFile, const char *tag) fclose(fin); - return 0; + return firstconfigtag; } char ** diff --git a/src/include/distromatic.h b/src/include/distromatic.h index 3f3720d..5de62e1 100644 --- a/src/include/distromatic.h +++ b/src/include/distromatic.h @@ -19,7 +19,6 @@ struct configDefaults { char *url_dir; char *arch[ARCHS_MAX]; }; -static struct configDefaults configdefaults; struct configTag { struct configDefaults *configdefaults; @@ -41,6 +40,5 @@ struct configTag { struct headerStats stats; struct configTag *next; }; -static struct configTag *firstconfigtag = NULL, *configtag = NULL; #endif diff --git a/src/include/functions.h b/src/include/functions.h index 17d9abe..82e327d 100644 --- a/src/include/functions.h +++ b/src/include/functions.h @@ -20,7 +20,7 @@ typedef char sizeString[SSSIZE]; #define LOG_DEBUG 4 #define LOG_MARK 8 -int read_configuration(const char *confFile, const char *tag); +struct configTag* read_configuration(const char *confFile); struct configTag* findRepositoryByTag(const char *tag); char **dupnargv(char **argv, int count);