diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2019-03-30 17:27:09 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2019-03-30 17:27:09 +0100 |
commit | 0f5a7f35206668f79c18415eaa4a1fd15750dc74 (patch) | |
tree | 17a1f9dfdb16ad2d6327fe11d9fc1fb42945415e | |
parent | 3193cb56d60e73db8bbadf46947a229b321d6c79 (diff) | |
download | busybox-w32-0f5a7f35206668f79c18415eaa4a1fd15750dc74.tar.gz busybox-w32-0f5a7f35206668f79c18415eaa4a1fd15750dc74.tar.bz2 busybox-w32-0f5a7f35206668f79c18415eaa4a1fd15750dc74.zip |
man: add "/usr/share/man" as another default MANPATH, fix col override
function old new delta
static.mpl - 12 +12
packed_usage 33307 33316 +9
man_main 857 851 -6
add_MANPATH 148 138 -10
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 1/2 up/down: 21/-16) Total: 5 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | miscutils/man.c | 33 |
1 files changed, 13 insertions, 20 deletions
diff --git a/miscutils/man.c b/miscutils/man.c index 9884325b7..61086612a 100644 --- a/miscutils/man.c +++ b/miscutils/man.c | |||
@@ -13,9 +13,9 @@ | |||
13 | //kbuild:lib-$(CONFIG_MAN) += man.o | 13 | //kbuild:lib-$(CONFIG_MAN) += man.o |
14 | 14 | ||
15 | //usage:#define man_trivial_usage | 15 | //usage:#define man_trivial_usage |
16 | //usage: "[-aw] [MANPAGE]..." | 16 | //usage: "[-aw] MANPAGE..." |
17 | //usage:#define man_full_usage "\n\n" | 17 | //usage:#define man_full_usage "\n\n" |
18 | //usage: "Format and display manual page\n" | 18 | //usage: "Display manual page\n" |
19 | //usage: "\n -a Display all pages" | 19 | //usage: "\n -a Display all pages" |
20 | //usage: "\n -w Show page locations" | 20 | //usage: "\n -w Show page locations" |
21 | //usage: "\n" | 21 | //usage: "\n" |
@@ -210,9 +210,6 @@ static char **add_MANPATH(char **man_path_list, int *count_mp, char *path) | |||
210 | path_element = man_path_list; | 210 | path_element = man_path_list; |
211 | if (path_element) while (*path_element) { | 211 | if (path_element) while (*path_element) { |
212 | if (strcmp(*path_element, path) == 0) { | 212 | if (strcmp(*path_element, path) == 0) { |
213 | /* Have path but haven't counted it, must be default */ | ||
214 | if (*count_mp == 0) | ||
215 | break; | ||
216 | goto skip; | 213 | goto skip; |
217 | } | 214 | } |
218 | path_element++; | 215 | path_element++; |
@@ -248,10 +245,8 @@ int man_main(int argc UNUSED_PARAM, char **argv) | |||
248 | { | 245 | { |
249 | parser_t *parser; | 246 | parser_t *parser; |
250 | char *sec_list; | 247 | char *sec_list; |
251 | char *cur_path, *cur_sect; | ||
252 | char **man_path_list; | 248 | char **man_path_list; |
253 | int count_mp; | 249 | int count_mp; |
254 | int cur_mp; | ||
255 | int opt, not_found; | 250 | int opt, not_found; |
256 | char *token[2]; | 251 | char *token[2]; |
257 | 252 | ||
@@ -266,16 +261,6 @@ int man_main(int argc UNUSED_PARAM, char **argv) | |||
266 | man_path_list = add_MANPATH(NULL, &count_mp, | 261 | man_path_list = add_MANPATH(NULL, &count_mp, |
267 | getenv("MANDATORY_MANPATH"+10) /* "MANPATH" */ | 262 | getenv("MANDATORY_MANPATH"+10) /* "MANPATH" */ |
268 | ); | 263 | ); |
269 | if (!man_path_list) { | ||
270 | /* default, may be overridden by /etc/man.conf */ | ||
271 | man_path_list = xzalloc(2 * sizeof(man_path_list[0])); | ||
272 | man_path_list[0] = (char*)"/usr/man"; | ||
273 | /* count_mp stays 0. | ||
274 | * Thus, man.conf will overwrite man_path_list[0] | ||
275 | * if a path is defined there. | ||
276 | */ | ||
277 | } | ||
278 | |||
279 | /* Parse man.conf[ig] or man_db.conf */ | 264 | /* Parse man.conf[ig] or man_db.conf */ |
280 | /* man version 1.6f uses man.config */ | 265 | /* man version 1.6f uses man.config */ |
281 | /* man-db implementation of man uses man_db.conf */ | 266 | /* man-db implementation of man uses man_db.conf */ |
@@ -289,7 +274,7 @@ int man_main(int argc UNUSED_PARAM, char **argv) | |||
289 | if (!token[1]) | 274 | if (!token[1]) |
290 | continue; | 275 | continue; |
291 | if (strcmp("DEFINE", token[0]) == 0) { | 276 | if (strcmp("DEFINE", token[0]) == 0) { |
292 | G.col = if_redefined(G.tbl , "col", token[1]); | 277 | G.col = if_redefined(G.col , "col", token[1]); |
293 | G.tbl = if_redefined(G.tbl , "tbl", token[1]); | 278 | G.tbl = if_redefined(G.tbl , "tbl", token[1]); |
294 | G.nroff = if_redefined(G.nroff, "nroff", token[1]); | 279 | G.nroff = if_redefined(G.nroff, "nroff", token[1]); |
295 | G.pager = if_redefined(G.pager, "pager", token[1]); | 280 | G.pager = if_redefined(G.pager, "pager", token[1]); |
@@ -306,6 +291,12 @@ int man_main(int argc UNUSED_PARAM, char **argv) | |||
306 | } | 291 | } |
307 | config_close(parser); | 292 | config_close(parser); |
308 | 293 | ||
294 | if (!man_path_list) { | ||
295 | static const char *const mpl[] = { "/usr/man", "/usr/share/man", NULL }; | ||
296 | man_path_list = (char**)mpl; | ||
297 | /*count_mp = 2; - not used below anyway */ | ||
298 | } | ||
299 | |||
309 | { | 300 | { |
310 | /* environment overrides setting from man.config */ | 301 | /* environment overrides setting from man.config */ |
311 | char *env_pager = getenv("MANPAGER"); | 302 | char *env_pager = getenv("MANPAGER"); |
@@ -322,16 +313,18 @@ int man_main(int argc UNUSED_PARAM, char **argv) | |||
322 | 313 | ||
323 | not_found = 0; | 314 | not_found = 0; |
324 | do { /* for each argv[] */ | 315 | do { /* for each argv[] */ |
316 | const char *cur_path; | ||
317 | int cur_mp; | ||
325 | int found = 0; | 318 | int found = 0; |
326 | cur_mp = 0; | ||
327 | 319 | ||
328 | if (strchr(*argv, '/')) { | 320 | if (strchr(*argv, '/')) { |
329 | found = show_manpage(*argv, /*man:*/ 1, 0); | 321 | found = show_manpage(*argv, /*man:*/ 1, 0); |
330 | goto check_found; | 322 | goto check_found; |
331 | } | 323 | } |
324 | cur_mp = 0; | ||
332 | while ((cur_path = man_path_list[cur_mp++]) != NULL) { | 325 | while ((cur_path = man_path_list[cur_mp++]) != NULL) { |
333 | /* for each MANPATH */ | 326 | /* for each MANPATH */ |
334 | cur_sect = sec_list; | 327 | const char *cur_sect = sec_list; |
335 | do { /* for each section */ | 328 | do { /* for each section */ |
336 | char *next_sect = strchrnul(cur_sect, ':'); | 329 | char *next_sect = strchrnul(cur_sect, ':'); |
337 | int sect_len = next_sect - cur_sect; | 330 | int sect_len = next_sect - cur_sect; |