mirror of
https://github.com/moparisthebest/pacman
synced 2024-12-23 00:08:50 -05:00
ini.c: move error output into conf.c
Move the remaining output into conf.c by notifying the callback of read errors. Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com>
This commit is contained in:
parent
ea96b56722
commit
3b20561748
@ -964,7 +964,11 @@ static int _parse_directive(const char *file, int linenum, const char *name,
|
|||||||
char *key, char *value, void *data)
|
char *key, char *value, void *data)
|
||||||
{
|
{
|
||||||
struct section_t *section = data;
|
struct section_t *section = data;
|
||||||
if(!key && !value) {
|
if(!name && !key && !value) {
|
||||||
|
pm_printf(ALPM_LOG_ERROR, _("config file %s could not be read: %s\n"),
|
||||||
|
file, strerror(errno));
|
||||||
|
return 1;
|
||||||
|
} else if(!key && !value) {
|
||||||
section->name = name;
|
section->name = name;
|
||||||
pm_printf(ALPM_LOG_DEBUG, "config: new section '%s'\n", name);
|
pm_printf(ALPM_LOG_DEBUG, "config: new section '%s'\n", name);
|
||||||
if(strcmp(name, "options") == 0) {
|
if(strcmp(name, "options") == 0) {
|
||||||
@ -1007,9 +1011,11 @@ int parseconfig(const char *file)
|
|||||||
int ret;
|
int ret;
|
||||||
struct section_t section;
|
struct section_t section;
|
||||||
memset(§ion, 0, sizeof(struct section_t));
|
memset(§ion, 0, sizeof(struct section_t));
|
||||||
|
pm_printf(ALPM_LOG_DEBUG, "config: attempting to read file %s\n", file);
|
||||||
if((ret = parse_ini(file, _parse_directive, §ion))) {
|
if((ret = parse_ini(file, _parse_directive, §ion))) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
pm_printf(ALPM_LOG_DEBUG, "config: finished parsing %s\n", file);
|
||||||
if((ret = setup_libalpm())) {
|
if((ret = setup_libalpm())) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -33,12 +33,15 @@
|
|||||||
* @param cb callback for key/value pairs
|
* @param cb callback for key/value pairs
|
||||||
* @param data caller defined data to be passed to the callback
|
* @param data caller defined data to be passed to the callback
|
||||||
*
|
*
|
||||||
* @return 0 on success, 1 on parsing errors, the callback return value
|
* @return the callback return value
|
||||||
* otherwise
|
|
||||||
*
|
*
|
||||||
* @note The callback will be called at the beginning of each section with an
|
* @note The callback will be called at the beginning of each section with an
|
||||||
* empty key and value and for each key/value pair.
|
* empty key and value and for each key/value pair.
|
||||||
*
|
*
|
||||||
|
* @note If the parser encounters an error the callback will be called with
|
||||||
|
* section, key, and value set to NULL and errno set by fopen, fgets, or
|
||||||
|
* strdup.
|
||||||
|
*
|
||||||
* @note The @a key and @a value passed to @ cb will be overwritten between
|
* @note The @a key and @a value passed to @ cb will be overwritten between
|
||||||
* calls. The section name will remain valid until after @a cb is called to
|
* calls. The section name will remain valid until after @a cb is called to
|
||||||
* begin a new section.
|
* begin a new section.
|
||||||
@ -52,13 +55,9 @@ int parse_ini(const char *file, ini_parser_fn cb, void *data)
|
|||||||
int linenum = 0;
|
int linenum = 0;
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
|
||||||
pm_printf(ALPM_LOG_DEBUG, "config: attempting to read file %s\n", file);
|
|
||||||
fp = fopen(file, "r");
|
fp = fopen(file, "r");
|
||||||
if(fp == NULL) {
|
if(fp == NULL) {
|
||||||
pm_printf(ALPM_LOG_ERROR, _("config file %s could not be read: %s\n"),
|
return cb(file, 0, NULL, NULL, NULL, data);
|
||||||
file, strerror(errno));
|
|
||||||
ret = 1;
|
|
||||||
goto cleanup;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
while(safe_fgets(line, PATH_MAX, fp)) {
|
while(safe_fgets(line, PATH_MAX, fp)) {
|
||||||
@ -109,11 +108,8 @@ int parse_ini(const char *file, ini_parser_fn cb, void *data)
|
|||||||
}
|
}
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
if(fp) {
|
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
}
|
|
||||||
free(section_name);
|
free(section_name);
|
||||||
pm_printf(ALPM_LOG_DEBUG, "config: finished parsing %s\n", file);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user