diff options
author | Andrew Gregory <andrew.gregory.8@gmail.com> | 2014-04-26 12:32:58 -0400 |
---|---|---|
committer | Allan McRae <allan@archlinux.org> | 2015-01-21 14:27:46 +1000 |
commit | 4ccafc484d43710d66d2622210cf33461b1b1c49 (patch) | |
tree | b33eb36bfe264dae6223621000062cf41641bc91 /src | |
parent | 09cfe2a4c061a4b2c08d93c1d99f60c8879f5cf2 (diff) |
ini.c: remove unnecessary helper function
Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/pacman/ini.c | 50 |
1 files changed, 16 insertions, 34 deletions
diff --git a/src/pacman/ini.c b/src/pacman/ini.c index 048c3d9b..f4f606b2 100644 --- a/src/pacman/ini.c +++ b/src/pacman/ini.c @@ -27,20 +27,27 @@ #include "util.h" /** - * @brief INI parser backend. + * @brief Parse a pacman-style INI config file. * * @param file path to the config file * @param cb callback for key/value pairs * @param data caller defined data to be passed to the callback - * @param section_name the name of the current section - * @param line buffer to read into, must be at least PATH_MAX long * * @return 0 on success, 1 on parsing errors, the callback return value * otherwise + * + * @note The callback will be called at the beginning of each section with an + * empty key and value and for each key/value pair. + * + * @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 + * begin a new section. + * + * @note Parsing will immediately stop if the callback returns non-zero. */ -static int _parse_ini(const char *file, ini_parser_fn cb, void *data, - char **section_name, char *line) +int parse_ini(const char *file, ini_parser_fn cb, void *data) { + char line[PATH_MAX], *section_name = NULL; FILE *fp = NULL; int linenum = 0; int ret = 0; @@ -85,8 +92,8 @@ static int _parse_ini(const char *file, ini_parser_fn cb, void *data, name[line_len - 2] = '\0'; ret = cb(file, linenum, name, NULL, NULL, data); - free(*section_name); - *section_name = name; + free(section_name); + section_name = name; /* we're at a new section; perform any post-actions for the prior */ if(ret) { @@ -109,7 +116,7 @@ static int _parse_ini(const char *file, ini_parser_fn cb, void *data, ret = 1; goto cleanup; } - if((ret = cb(file, linenum, *section_name, key, value, data)) != 0) { + if((ret = cb(file, linenum, section_name, key, value, data)) != 0) { goto cleanup; } } @@ -118,34 +125,9 @@ cleanup: if(fp) { fclose(fp); } - free(*section_name); + free(section_name); pm_printf(ALPM_LOG_DEBUG, "config: finished parsing %s\n", file); return ret; } -/** - * @brief Parse a pacman-style INI config file. - * - * @param file path to the config file - * @param cb callback for key/value pairs - * @param data caller defined data to be passed to the callback - * - * @return 0 on success, 1 on parsing errors, the callback return value - * otherwise - * - * @note The callback will be called at the beginning of each section with an - * empty key and value and for each key/value pair. - * - * @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 - * begin a new section. - * - * @note Parsing will immediately stop if the callback returns non-zero. - */ -int parse_ini(const char *file, ini_parser_fn cb, void *data) -{ - char *section_name = NULL, line[PATH_MAX]; - return _parse_ini(file, cb, data, §ion_name, line); -} - /* vim: set noet: */ |