ini.c: remove unnecessary helper function
Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com>
This commit is contained in:
parent
09cfe2a4c0
commit
4ccafc484d
1 changed files with 16 additions and 34 deletions
|
@ -27,20 +27,27 @@
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief INI parser backend.
|
* @brief Parse a pacman-style INI config file.
|
||||||
*
|
*
|
||||||
* @param file path to the config file
|
* @param file path to the config file
|
||||||
* @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
|
||||||
* @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
|
* @return 0 on success, 1 on parsing errors, the callback return value
|
||||||
* otherwise
|
* 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,
|
int parse_ini(const char *file, ini_parser_fn cb, void *data)
|
||||||
char **section_name, char *line)
|
|
||||||
{
|
{
|
||||||
|
char line[PATH_MAX], *section_name = NULL;
|
||||||
FILE *fp = NULL;
|
FILE *fp = NULL;
|
||||||
int linenum = 0;
|
int linenum = 0;
|
||||||
int ret = 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';
|
name[line_len - 2] = '\0';
|
||||||
|
|
||||||
ret = cb(file, linenum, name, NULL, NULL, data);
|
ret = cb(file, linenum, name, NULL, NULL, data);
|
||||||
free(*section_name);
|
free(section_name);
|
||||||
*section_name = name;
|
section_name = name;
|
||||||
|
|
||||||
/* we're at a new section; perform any post-actions for the prior */
|
/* we're at a new section; perform any post-actions for the prior */
|
||||||
if(ret) {
|
if(ret) {
|
||||||
|
@ -109,7 +116,7 @@ static int _parse_ini(const char *file, ini_parser_fn cb, void *data,
|
||||||
ret = 1;
|
ret = 1;
|
||||||
goto cleanup;
|
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;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -118,34 +125,9 @@ cleanup:
|
||||||
if(fp) {
|
if(fp) {
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
}
|
}
|
||||||
free(*section_name);
|
free(section_name);
|
||||||
pm_printf(ALPM_LOG_DEBUG, "config: finished parsing %s\n", file);
|
pm_printf(ALPM_LOG_DEBUG, "config: finished parsing %s\n", file);
|
||||||
return ret;
|
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: */
|
/* vim: set noet: */
|
||||||
|
|
Loading…
Add table
Reference in a new issue