aboutsummaryrefslogtreecommitdiff
path: root/miscutils
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2008-07-20 17:41:30 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2008-07-20 17:41:30 +0000
commit09aaf78ad51d95866972a926cb43bafa0c4a5c5e (patch)
treec3f3b02de67e1d10e1d1aea360f687a8e06c0d9c /miscutils
parentadc772a5f2b5b74f398aaa59c36739fee4ee7a85 (diff)
downloadbusybox-w32-09aaf78ad51d95866972a926cb43bafa0c4a5c5e.tar.gz
busybox-w32-09aaf78ad51d95866972a926cb43bafa0c4a5c5e.tar.bz2
busybox-w32-09aaf78ad51d95866972a926cb43bafa0c4a5c5e.zip
mn: use libbb for config parsing (by Vladimir)
function old new delta man_main 757 713 -44
Diffstat (limited to 'miscutils')
-rw-r--r--miscutils/man.c39
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)
75int man_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 75int man_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
76int man_main(int argc UNUSED_PARAM, char **argv) 76int man_main(int argc UNUSED_PARAM, char **argv)
77{ 77{
78 FILE *cf; 78 parser_t *parser;
79 const char *pager; 79 const char *pager;
80 char **man_path_list; 80 char **man_path_list;
81 char *sec_list; 81 char *sec_list;
82 char *cur_path, *cur_sect; 82 char *cur_path, *cur_sect;
83 char *line, *value;
84 int count_mp, cur_mp; 83 int count_mp, cur_mp;
85 int opt, not_found; 84 int opt, not_found;
86 85
@@ -103,30 +102,24 @@ int man_main(int argc UNUSED_PARAM, char **argv)
103 } 102 }
104 103
105 /* Parse man.conf */ 104 /* Parse man.conf */
106 cf = fopen_or_warn("/etc/man.conf", "r"); 105 parser = config_open("/etc/man.conf");
107 if (cf) { 106 if (parser) {
108 /* go through man configuration file and search relevant paths, sections */ 107 /* go through man configuration file and search relevant paths, sections */
109 while ((line = xmalloc_fgetline(cf)) != NULL) { 108 char *token[2];
110 trim(line); /* remove whitespace at the beginning/end */ 109 while (config_read(parser, token, 2, 2, "# \t", PARSE_LAST_IS_GREEDY)) {
111 if (isspace(line[7])) { 110 if (strcmp("MANPATH", token[0]) == 0) {
112 line[7] = '\0'; 111 man_path_list = xrealloc_vector(man_path_list, 4, count_mp);
113 value = skip_whitespace(&line[8]); 112 man_path_list[count_mp] = xstrdup(token[1]);
114 *skip_non_whitespace(value) = '\0'; 113 count_mp++;
115 if (strcmp("MANPATH", line) == 0) { 114 /* man_path_list is NULL terminated */
116 man_path_list[count_mp] = xstrdup(value); 115 man_path_list[count_mp] = NULL;
117 count_mp++; 116 }
118 /* man_path_list is NULL terminated */ 117 if (strcmp("MANSECT", token[0]) == 0) {
119 man_path_list[count_mp] = NULL; 118 free(sec_list);
120 man_path_list = xrealloc_vector(man_path_list, 4, count_mp); 119 sec_list = xstrdup(token[1]);
121 }
122 if (strcmp("MANSECT", line) == 0) {
123 free(sec_list);
124 sec_list = xstrdup(value);
125 }
126 } 120 }
127 free(line);
128 } 121 }
129 fclose(cf); 122 config_close(parser);
130 } 123 }
131 124
132// TODO: my man3/getpwuid.3.gz contains just one line: 125// TODO: my man3/getpwuid.3.gz contains just one line: