mirror of
https://github.com/moparisthebest/pacman
synced 2025-01-10 21:38:19 -05:00
conf.c: pass _parse_directive as a callback
This will allow passing arbitrary key/value handlers. Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com> Signed-off-by: Allan McRae <allan@archlinux.org>
This commit is contained in:
parent
26da037fd5
commit
ab84249a58
@ -841,8 +841,9 @@ cleanup:
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int _parse_directive(const char *file, int linenum, const char *name,
|
static int _parse_directive(const char *file, int linenum, const char *name,
|
||||||
char *key, char *value, struct section_t *section)
|
char *key, char *value, void *data)
|
||||||
{
|
{
|
||||||
|
struct section_t *section = data;
|
||||||
if(!key && !value) {
|
if(!key && !value) {
|
||||||
int ret = finish_section(section);
|
int ret = finish_section(section);
|
||||||
pm_printf(ALPM_LOG_DEBUG, "config: new section '%s'\n", name);
|
pm_printf(ALPM_LOG_DEBUG, "config: new section '%s'\n", name);
|
||||||
@ -872,6 +873,9 @@ static int _parse_directive(const char *file, int linenum, const char *name,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
typedef int (ini_parser_fn)(const char *file, int line, const char *section,
|
||||||
|
char *key, char *value, void *data);
|
||||||
|
|
||||||
/** The "real" parseconfig. Each "Include" directive will recall this method so
|
/** The "real" parseconfig. Each "Include" directive will recall this method so
|
||||||
* recursion and stack depth are limited to 10 levels. The publicly visible
|
* recursion and stack depth are limited to 10 levels. The publicly visible
|
||||||
* parseconfig calls this with a NULL section argument so we can recall from
|
* parseconfig calls this with a NULL section argument so we can recall from
|
||||||
@ -881,7 +885,7 @@ static int _parse_directive(const char *file, int linenum, const char *name,
|
|||||||
* @param depth the current recursion depth
|
* @param depth the current recursion depth
|
||||||
* @return 0 on success, 1 on failure
|
* @return 0 on success, 1 on failure
|
||||||
*/
|
*/
|
||||||
static int _parseconfig(const char *file, struct section_t *section,
|
static int _parseconfig(const char *file, ini_parser_fn cb, void *data,
|
||||||
char **section_name, int depth)
|
char **section_name, int depth)
|
||||||
{
|
{
|
||||||
FILE *fp = NULL;
|
FILE *fp = NULL;
|
||||||
@ -936,7 +940,7 @@ static int _parseconfig(const char *file, struct section_t *section,
|
|||||||
name = strdup(line + 1);
|
name = strdup(line + 1);
|
||||||
name[line_len - 2] = '\0';
|
name[line_len - 2] = '\0';
|
||||||
|
|
||||||
ret = _parse_directive(file, linenum, name, NULL, NULL, section);
|
ret = cb(file, linenum, name, NULL, NULL, data);
|
||||||
free(*section_name);
|
free(*section_name);
|
||||||
*section_name = name;
|
*section_name = name;
|
||||||
|
|
||||||
@ -994,7 +998,7 @@ static int _parseconfig(const char *file, struct section_t *section,
|
|||||||
for(gindex = 0; gindex < globbuf.gl_pathc; gindex++) {
|
for(gindex = 0; gindex < globbuf.gl_pathc; gindex++) {
|
||||||
pm_printf(ALPM_LOG_DEBUG, "config file %s, line %d: including %s\n",
|
pm_printf(ALPM_LOG_DEBUG, "config file %s, line %d: including %s\n",
|
||||||
file, linenum, globbuf.gl_pathv[gindex]);
|
file, linenum, globbuf.gl_pathv[gindex]);
|
||||||
_parseconfig(globbuf.gl_pathv[gindex], section,
|
_parseconfig(globbuf.gl_pathv[gindex], cb, data,
|
||||||
section_name, depth + 1);
|
section_name, depth + 1);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -1002,13 +1006,13 @@ static int _parseconfig(const char *file, struct section_t *section,
|
|||||||
globfree(&globbuf);
|
globfree(&globbuf);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if((ret = _parse_directive(file, linenum, *section_name, key, value, section)) != 0) {
|
if((ret = cb(file, linenum, *section_name, key, value, data)) != 0) {
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(depth == 0) {
|
if(depth == 0) {
|
||||||
ret = _parse_directive(NULL, 0, NULL, NULL, NULL, section);
|
ret = cb(NULL, 0, NULL, NULL, NULL, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
@ -1041,7 +1045,7 @@ int parseconfig(const char *file)
|
|||||||
/* call the real parseconfig function with a null section & db argument */
|
/* call the real parseconfig function with a null section & db argument */
|
||||||
pm_printf(ALPM_LOG_DEBUG, "parseconfig: options pass\n");
|
pm_printf(ALPM_LOG_DEBUG, "parseconfig: options pass\n");
|
||||||
section.parse_options = 1;
|
section.parse_options = 1;
|
||||||
if((ret = _parseconfig(file, §ion, §ion_name, 0))) {
|
if((ret = _parseconfig(file, _parse_directive, §ion, §ion_name, 0))) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
if((ret = setup_libalpm())) {
|
if((ret = setup_libalpm())) {
|
||||||
@ -1050,7 +1054,7 @@ int parseconfig(const char *file)
|
|||||||
/* second pass, repo section parsing */
|
/* second pass, repo section parsing */
|
||||||
pm_printf(ALPM_LOG_DEBUG, "parseconfig: repo pass\n");
|
pm_printf(ALPM_LOG_DEBUG, "parseconfig: repo pass\n");
|
||||||
section.parse_options = 0;
|
section.parse_options = 0;
|
||||||
return _parseconfig(file, §ion, §ion_name, 0);
|
return _parseconfig(file, _parse_directive, §ion, §ion_name, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* vim: set ts=2 sw=2 noet: */
|
/* vim: set ts=2 sw=2 noet: */
|
||||||
|
Loading…
Reference in New Issue
Block a user