aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2014-11-27 00:40:08 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2014-11-27 00:40:08 +0100
commitee41094b809452fdd23d25c1879a96acfcddde08 (patch)
treee9307b6a7856b097d4b7067a6e61504fe8e02ffc
parent04c14176023c65550fd46c2e44a1aa04d426d69a (diff)
downloadbusybox-w32-ee41094b809452fdd23d25c1879a96acfcddde08.tar.gz
busybox-w32-ee41094b809452fdd23d25c1879a96acfcddde08.tar.bz2
busybox-w32-ee41094b809452fdd23d25c1879a96acfcddde08.zip
man: accept a list of dirs in $MANPATH
function old new delta add_MANPATH - 143 +143 man_main 852 731 -121 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 0/1 up/down: 143/-121) Total: 22 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--miscutils/man.c86
1 files changed, 49 insertions, 37 deletions
diff --git a/miscutils/man.c b/miscutils/man.c
index 5c1fa2c9d..ccb57a93f 100644
--- a/miscutils/man.c
+++ b/miscutils/man.c
@@ -147,15 +147,49 @@ static int show_manpage(const char *pager, char *man_filename, int man, int leve
147 return run_pipe(pager, man_filename, man, level); 147 return run_pipe(pager, man_filename, man, level);
148} 148}
149 149
150static char **add_MANPATH(char **man_path_list, int *count_mp, char *path)
151{
152 if (path) while (*path) {
153 char *next_path;
154 char **path_element;
155
156 next_path = strchr(path, ':');
157 if (next_path) {
158 *next_path = '\0';
159 if (next_path++ == path) /* "::"? */
160 goto next;
161 }
162 /* Do we already have path? */
163 path_element = man_path_list;
164 if (path_element) while (*path_element) {
165 if (strcmp(*path_element, path) == 0)
166 goto skip;
167 path_element++;
168 }
169 man_path_list = xrealloc_vector(man_path_list, 4, *count_mp);
170 man_path_list[*count_mp] = xstrdup(path);
171 (*count_mp)++;
172 /* man_path_list is NULL terminated */
173 /* man_path_list[*count_mp] = NULL; - xrealloc_vector did it */
174 skip:
175 if (!next_path)
176 break;
177 next:
178 path = next_path;
179 }
180 return man_path_list;
181}
182
150int man_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 183int man_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
151int man_main(int argc UNUSED_PARAM, char **argv) 184int man_main(int argc UNUSED_PARAM, char **argv)
152{ 185{
153 parser_t *parser; 186 parser_t *parser;
154 const char *pager = ENABLE_LESS ? "less" : "more"; 187 const char *pager = ENABLE_LESS ? "less" : "more";
155 char **man_path_list;
156 char *sec_list; 188 char *sec_list;
157 char *cur_path, *cur_sect; 189 char *cur_path, *cur_sect;
158 int count_mp, cur_mp; 190 char **man_path_list;
191 int count_mp;
192 int cur_mp;
159 int opt, not_found; 193 int opt, not_found;
160 char *token[2]; 194 char *token[2];
161 195
@@ -164,14 +198,20 @@ int man_main(int argc UNUSED_PARAM, char **argv)
164 argv += optind; 198 argv += optind;
165 199
166 sec_list = xstrdup("0p:1:1p:2:3:3p:4:5:6:7:8:9"); 200 sec_list = xstrdup("0p:1:1p:2:3:3p:4:5:6:7:8:9");
167 /* Last valid man_path_list[] is [0x10] */ 201
168 count_mp = 0; 202 count_mp = 0;
169 man_path_list = xzalloc(0x11 * sizeof(man_path_list[0])); 203 man_path_list = add_MANPATH(NULL, &count_mp,
170 man_path_list[0] = getenv("MANPATH"); 204 getenv("MANDATORY_MANPATH"+10) /* "MANPATH" */
171 if (!man_path_list[0]) /* default, may be overridden by /etc/man.conf */ 205 );
206 if (!man_path_list) {
207 /* default, may be overridden by /etc/man.conf */
208 man_path_list = xzalloc(2 * sizeof(man_path_list[0]));
172 man_path_list[0] = (char*)"/usr/man"; 209 man_path_list[0] = (char*)"/usr/man";
173 else 210 /* count_mp stays 0.
174 count_mp++; 211 * Thus, man.conf will overwrite man_path_list[0]
212 * if a path is defined there.
213 */
214 }
175 215
176 /* Parse man.conf[ig] or man_db.conf */ 216 /* Parse man.conf[ig] or man_db.conf */
177 /* man version 1.6f uses man.config */ 217 /* man version 1.6f uses man.config */
@@ -193,35 +233,7 @@ int man_main(int argc UNUSED_PARAM, char **argv)
193 if (strcmp("MANDATORY_MANPATH"+10, token[0]) == 0 /* "MANPATH"? */ 233 if (strcmp("MANDATORY_MANPATH"+10, token[0]) == 0 /* "MANPATH"? */
194 || strcmp("MANDATORY_MANPATH", token[0]) == 0 234 || strcmp("MANDATORY_MANPATH", token[0]) == 0
195 ) { 235 ) {
196 char *path = token[1]; 236 man_path_list = add_MANPATH(man_path_list, &count_mp, token[1]);
197 while (*path) {
198 char *next_path;
199 char **path_element;
200
201 next_path = strchr(path, ':');
202 if (next_path) {
203 *next_path = '\0';
204 if (next_path++ == path) /* "::"? */
205 goto next;
206 }
207 /* Do we already have path? */
208 path_element = man_path_list;
209 while (*path_element) {
210 if (strcmp(*path_element, path) == 0)
211 goto skip;
212 path_element++;
213 }
214 man_path_list = xrealloc_vector(man_path_list, 4, count_mp);
215 man_path_list[count_mp] = xstrdup(path);
216 count_mp++;
217 /* man_path_list is NULL terminated */
218 /*man_path_list[count_mp] = NULL; - xrealloc_vector did it */
219 skip:
220 if (!next_path)
221 break;
222 next:
223 path = next_path;
224 }
225 } 237 }
226 if (strcmp("MANSECT", token[0]) == 0) { 238 if (strcmp("MANSECT", token[0]) == 0) {
227 free(sec_list); 239 free(sec_list);