mn: use libbb for config parsing (by Vladimir)
function old new delta man_main 757 713 -44
This commit is contained in:
parent
adc772a5f2
commit
09aaf78ad5
@ -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, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||||
int man_main(int argc UNUSED_PARAM, char **argv)
|
int man_main(int argc UNUSED_PARAM, char **argv)
|
||||||
{
|
{
|
||||||
FILE *cf;
|
parser_t *parser;
|
||||||
const char *pager;
|
const char *pager;
|
||||||
char **man_path_list;
|
char **man_path_list;
|
||||||
char *sec_list;
|
char *sec_list;
|
||||||
char *cur_path, *cur_sect;
|
char *cur_path, *cur_sect;
|
||||||
char *line, *value;
|
|
||||||
int count_mp, cur_mp;
|
int count_mp, cur_mp;
|
||||||
int opt, not_found;
|
int opt, not_found;
|
||||||
|
|
||||||
@ -103,30 +102,24 @@ int man_main(int argc UNUSED_PARAM, char **argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Parse man.conf */
|
/* Parse man.conf */
|
||||||
cf = fopen_or_warn("/etc/man.conf", "r");
|
parser = config_open("/etc/man.conf");
|
||||||
if (cf) {
|
if (parser) {
|
||||||
/* go through man configuration file and search relevant paths, sections */
|
/* go through man configuration file and search relevant paths, sections */
|
||||||
while ((line = xmalloc_fgetline(cf)) != NULL) {
|
char *token[2];
|
||||||
trim(line); /* remove whitespace at the beginning/end */
|
while (config_read(parser, token, 2, 2, "# \t", PARSE_LAST_IS_GREEDY)) {
|
||||||
if (isspace(line[7])) {
|
if (strcmp("MANPATH", token[0]) == 0) {
|
||||||
line[7] = '\0';
|
man_path_list = xrealloc_vector(man_path_list, 4, count_mp);
|
||||||
value = skip_whitespace(&line[8]);
|
man_path_list[count_mp] = xstrdup(token[1]);
|
||||||
*skip_non_whitespace(value) = '\0';
|
count_mp++;
|
||||||
if (strcmp("MANPATH", line) == 0) {
|
/* man_path_list is NULL terminated */
|
||||||
man_path_list[count_mp] = xstrdup(value);
|
man_path_list[count_mp] = NULL;
|
||||||
count_mp++;
|
}
|
||||||
/* man_path_list is NULL terminated */
|
if (strcmp("MANSECT", token[0]) == 0) {
|
||||||
man_path_list[count_mp] = NULL;
|
free(sec_list);
|
||||||
man_path_list = xrealloc_vector(man_path_list, 4, count_mp);
|
sec_list = xstrdup(token[1]);
|
||||||
}
|
|
||||||
if (strcmp("MANSECT", line) == 0) {
|
|
||||||
free(sec_list);
|
|
||||||
sec_list = xstrdup(value);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
free(line);
|
|
||||||
}
|
}
|
||||||
fclose(cf);
|
config_close(parser);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: my man3/getpwuid.3.gz contains just one line:
|
// TODO: my man3/getpwuid.3.gz contains just one line:
|
||||||
|
Loading…
Reference in New Issue
Block a user