diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2008-07-20 21:41:30 +0400 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2008-07-20 21:41:30 +0400 |
commit | 09aaf78ad51d95866972a926cb43bafa0c4a5c5e (patch) | |
tree | c3f3b02de67e1d10e1d1aea360f687a8e06c0d9c /miscutils/man.c | |
parent | adc772a5f2b5b74f398aaa59c36739fee4ee7a85 (diff) |
mn: use libbb for config parsing (by Vladimir)
function old new delta
man_main 757 713 -44
Diffstat (limited to 'miscutils/man.c')
-rw-r--r-- | miscutils/man.c | 39 |
1 files changed, 16 insertions, 23 deletions
diff --git a/miscutils/man.c b/miscutils/man.c index b1bb1530a..75af3d775 100644 --- a/miscutils/man.c +++ b/miscutils/man.c @@ -75,12 +75,11 @@ static int show_manpage(const char *pager, char *man_filename, int man) int man_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; int man_main(int argc UNUSED_PARAM, char **argv) { - FILE *cf; + parser_t *parser; const char *pager; char **man_path_list; char *sec_list; char *cur_path, *cur_sect; - char *line, *value; int count_mp, cur_mp; int opt, not_found; @@ -103,30 +102,24 @@ int man_main(int argc UNUSED_PARAM, char **argv) } /* Parse man.conf */ - cf = fopen_or_warn("/etc/man.conf", "r"); - if (cf) { + parser = config_open("/etc/man.conf"); + if (parser) { /* go through man configuration file and search relevant paths, sections */ - while ((line = xmalloc_fgetline(cf)) != NULL) { - trim(line); /* remove whitespace at the beginning/end */ - if (isspace(line[7])) { - line[7] = '\0'; - value = skip_whitespace(&line[8]); - *skip_non_whitespace(value) = '\0'; - if (strcmp("MANPATH", line) == 0) { - man_path_list[count_mp] = xstrdup(value); - count_mp++; - /* man_path_list is NULL terminated */ - man_path_list[count_mp] = NULL; - man_path_list = xrealloc_vector(man_path_list, 4, count_mp); - } - if (strcmp("MANSECT", line) == 0) { - free(sec_list); - sec_list = xstrdup(value); - } + char *token[2]; + while (config_read(parser, token, 2, 2, "# \t", PARSE_LAST_IS_GREEDY)) { + if (strcmp("MANPATH", token[0]) == 0) { + man_path_list = xrealloc_vector(man_path_list, 4, count_mp); + man_path_list[count_mp] = xstrdup(token[1]); + count_mp++; + /* man_path_list is NULL terminated */ + man_path_list[count_mp] = NULL; + } + if (strcmp("MANSECT", token[0]) == 0) { + free(sec_list); + sec_list = xstrdup(token[1]); } - free(line); } - fclose(cf); + config_close(parser); } // TODO: my man3/getpwuid.3.gz contains just one line: |