diff options
| author | Denis Vlasenko <vda.linux@googlemail.com> | 2008-04-19 03:42:47 +0000 |
|---|---|---|
| committer | Denis Vlasenko <vda.linux@googlemail.com> | 2008-04-19 03:42:47 +0000 |
| commit | 50d068cb76baa7d37b948d021d3b16e2798ed7cf (patch) | |
| tree | 61c248628dbc469cf62e459e1d544958c4a887fb /miscutils | |
| parent | e96dcb4dcffc8ade4c4f812ab2ed63287faaec83 (diff) | |
| download | busybox-w32-50d068cb76baa7d37b948d021d3b16e2798ed7cf.tar.gz busybox-w32-50d068cb76baa7d37b948d021d3b16e2798ed7cf.tar.bz2 busybox-w32-50d068cb76baa7d37b948d021d3b16e2798ed7cf.zip | |
man: handle many MANPAGER directives so that they do not override
but accumulate. By Ivana Varekova <varekova AT redhat.com>
function old new delta
man_main 567 684 +117
Diffstat (limited to 'miscutils')
| -rw-r--r-- | miscutils/man.c | 78 |
1 files changed, 44 insertions, 34 deletions
diff --git a/miscutils/man.c b/miscutils/man.c index ed31b66c7..bf13ab527 100644 --- a/miscutils/man.c +++ b/miscutils/man.c | |||
| @@ -69,9 +69,11 @@ int man_main(int argc ATTRIBUTE_UNUSED, char **argv) | |||
| 69 | { | 69 | { |
| 70 | FILE *cf; | 70 | FILE *cf; |
| 71 | const char *pager; | 71 | const char *pager; |
| 72 | char *man_path, *sec_list; | 72 | char **man_path_list; |
| 73 | char *sec_list; | ||
| 73 | char *cur_path, *cur_sect; | 74 | char *cur_path, *cur_sect; |
| 74 | char *line, *value; | 75 | char *line, *value; |
| 76 | int count_mp, alloc_mp, cur_mp; | ||
| 75 | int opt; | 77 | int opt; |
| 76 | 78 | ||
| 77 | opt_complementary = "-1"; /* at least one argument */ | 79 | opt_complementary = "-1"; /* at least one argument */ |
| @@ -79,7 +81,12 @@ int man_main(int argc ATTRIBUTE_UNUSED, char **argv) | |||
| 79 | argv += optind; | 81 | argv += optind; |
| 80 | 82 | ||
| 81 | sec_list = xstrdup("1:2:3:4:5:6:7:8:9"); | 83 | sec_list = xstrdup("1:2:3:4:5:6:7:8:9"); |
| 82 | man_path = xstrdup(getenv("MANPATH")); | 84 | alloc_mp = 10; |
| 85 | man_path_list = xmalloc(10 * sizeof(man_path_list[0])); | ||
| 86 | count_mp = 0; | ||
| 87 | man_path_list[0] = xstrdup(getenv("MANPATH")); | ||
| 88 | if (man_path_list[0]) | ||
| 89 | count_mp++; | ||
| 83 | pager = getenv("MANPAGER"); | 90 | pager = getenv("MANPAGER"); |
| 84 | if (!pager) { | 91 | if (!pager) { |
| 85 | pager = getenv("PAGER"); | 92 | pager = getenv("PAGER"); |
| @@ -98,8 +105,13 @@ int man_main(int argc ATTRIBUTE_UNUSED, char **argv) | |||
| 98 | value = skip_whitespace(&line[8]); | 105 | value = skip_whitespace(&line[8]); |
| 99 | *skip_non_whitespace(value) = '\0'; | 106 | *skip_non_whitespace(value) = '\0'; |
| 100 | if (strcmp("MANPATH", line) == 0) { | 107 | if (strcmp("MANPATH", line) == 0) { |
| 101 | free(man_path); | 108 | man_path_list[count_mp] = xstrdup(value); |
| 102 | man_path = xstrdup(value); | 109 | count_mp++; |
| 110 | if (alloc_mp == count_mp) { | ||
| 111 | alloc_mp += 10; | ||
| 112 | man_path_list = xrealloc(man_path_list, alloc_mp * sizeof(man_path_list[0])); | ||
| 113 | } | ||
| 114 | /* thus man_path_list is always NULL terminated */ | ||
| 103 | } | 115 | } |
| 104 | if (strcmp("MANSECT", line) == 0) { | 116 | if (strcmp("MANSECT", line) == 0) { |
| 105 | free(sec_list); | 117 | free(sec_list); |
| @@ -112,37 +124,35 @@ int man_main(int argc ATTRIBUTE_UNUSED, char **argv) | |||
| 112 | } | 124 | } |
| 113 | 125 | ||
| 114 | do { /* for each argv[] */ | 126 | do { /* for each argv[] */ |
| 115 | cur_path = man_path; | 127 | cur_mp = 0; |
| 116 | do { /* for each MANPATH item */ | 128 | while ((cur_path = man_path_list[cur_mp++]) != NULL) { |
| 117 | char *next_path = strchrnul(cur_path, ':'); | 129 | /* for each MANPATH */ |
| 118 | int path_len = next_path - cur_path; | 130 | do { /* for each MANPATH item */ |
| 119 | 131 | char *next_path = strchrnul(cur_path, ':'); | |
| 120 | cur_sect = sec_list; | 132 | int path_len = next_path - cur_path; |
| 121 | do { /* for each section */ | 133 | cur_sect = sec_list; |
| 122 | char *next_sect = strchrnul(cur_sect, ':'); | 134 | do { /* for each section */ |
| 123 | int sect_len = next_sect - cur_sect; | 135 | char *next_sect = strchrnul(cur_sect, ':'); |
| 124 | 136 | int sect_len = next_sect - cur_sect; | |
| 125 | char *man_filename = xasprintf("%.*s/man%.*s/%s.%.*s" ".bz2", | 137 | |
| 126 | path_len, cur_path, | 138 | char *man_filename = xasprintf("%.*s/man%.*s/%s.%.*s" ".bz2", |
| 127 | sect_len, cur_sect, | 139 | path_len, cur_path, |
| 128 | *argv, | 140 | sect_len, cur_sect, |
| 129 | sect_len, cur_sect); | 141 | *argv, |
| 130 | if (show_manpage(pager, man_filename)) { | 142 | sect_len, cur_sect); |
| 131 | if (!(opt & OPT_a)) { | 143 | int found = show_manpage(pager, man_filename); |
| 144 | free(man_filename); | ||
| 145 | if (found && !(opt & OPT_a)) | ||
| 132 | goto next_arg; | 146 | goto next_arg; |
| 133 | } | 147 | cur_sect = next_sect; |
| 134 | } | 148 | while (*cur_sect == ':') |
| 135 | free(man_filename); | 149 | cur_sect++; |
| 136 | 150 | } while (*cur_sect); | |
| 137 | cur_sect = next_sect; | 151 | cur_path = next_path; |
| 138 | while (*cur_sect == ':') | 152 | while (*cur_path == ':') |
| 139 | cur_sect++; | 153 | cur_path++; |
| 140 | } while (*cur_sect); | 154 | } while (*cur_path); |
| 141 | 155 | } | |
| 142 | cur_path = next_path; | ||
| 143 | while (*cur_path == ':') | ||
| 144 | cur_path++; | ||
| 145 | } while (*cur_path); | ||
| 146 | next_arg: | 156 | next_arg: |
| 147 | argv++; | 157 | argv++; |
| 148 | } while (*argv); | 158 | } while (*argv); |
