diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2008-11-16 04:05:13 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2008-11-16 04:05:13 +0000 |
commit | e88bd2d9318417d01e141e598c3870def0eddfcc (patch) | |
tree | 06afd0c5b9fec38fbed14873ea659392ca6f9e47 /miscutils | |
parent | 2479cd4a5d50044e9d8e791a6ac17d528761a0a6 (diff) | |
download | busybox-w32-e88bd2d9318417d01e141e598c3870def0eddfcc.tar.gz busybox-w32-e88bd2d9318417d01e141e598c3870def0eddfcc.tar.bz2 busybox-w32-e88bd2d9318417d01e141e598c3870def0eddfcc.zip |
man: better check for duplicated MANPATH. Also -10 bytes.
Diffstat (limited to 'miscutils')
-rw-r--r-- | miscutils/man.c | 103 |
1 files changed, 56 insertions, 47 deletions
diff --git a/miscutils/man.c b/miscutils/man.c index 24551c0e0..672ddb1c8 100644 --- a/miscutils/man.c +++ b/miscutils/man.c | |||
@@ -188,24 +188,40 @@ int man_main(int argc UNUSED_PARAM, char **argv) | |||
188 | if (!token[1]) | 188 | if (!token[1]) |
189 | continue; | 189 | continue; |
190 | if (strcmp("MANPATH", token[0]) == 0) { | 190 | if (strcmp("MANPATH", token[0]) == 0) { |
191 | /* Do we already have it? */ | 191 | char *path = token[1]; |
192 | char **path_element = man_path_list; | 192 | while (*path) { |
193 | while (*path_element) { | 193 | char *next_path; |
194 | if (strcmp(*path_element, token[1]) == 0) | 194 | char **path_element; |
195 | goto skip; | 195 | |
196 | path_element++; | 196 | next_path = strchr(path, ':'); |
197 | if (next_path) { | ||
198 | *next_path = '\0'; | ||
199 | if (next_path++ == path) /* "::"? */ | ||
200 | goto next; | ||
201 | } | ||
202 | /* Do we already have path? */ | ||
203 | path_element = man_path_list; | ||
204 | while (*path_element) { | ||
205 | if (strcmp(*path_element, path) == 0) | ||
206 | goto skip; | ||
207 | path_element++; | ||
208 | } | ||
209 | man_path_list = xrealloc_vector(man_path_list, 4, count_mp); | ||
210 | man_path_list[count_mp] = xstrdup(path); | ||
211 | count_mp++; | ||
212 | /* man_path_list is NULL terminated */ | ||
213 | /*man_path_list[count_mp] = NULL; - xrealloc_vector did it */ | ||
214 | skip: | ||
215 | if (!next_path) | ||
216 | break; | ||
217 | next: | ||
218 | path = next_path; | ||
197 | } | 219 | } |
198 | man_path_list = xrealloc_vector(man_path_list, 4, count_mp); | ||
199 | man_path_list[count_mp] = xstrdup(token[1]); | ||
200 | count_mp++; | ||
201 | /* man_path_list is NULL terminated */ | ||
202 | /*man_path_list[count_mp] = NULL; - xrealloc_vector did it */ | ||
203 | } | 220 | } |
204 | if (strcmp("MANSECT", token[0]) == 0) { | 221 | if (strcmp("MANSECT", token[0]) == 0) { |
205 | free(sec_list); | 222 | free(sec_list); |
206 | sec_list = xstrdup(token[1]); | 223 | sec_list = xstrdup(token[1]); |
207 | } | 224 | } |
208 | skip: ; | ||
209 | } | 225 | } |
210 | config_close(parser); | 226 | config_close(parser); |
211 | 227 | ||
@@ -220,41 +236,34 @@ int man_main(int argc UNUSED_PARAM, char **argv) | |||
220 | } | 236 | } |
221 | while ((cur_path = man_path_list[cur_mp++]) != NULL) { | 237 | while ((cur_path = man_path_list[cur_mp++]) != NULL) { |
222 | /* for each MANPATH */ | 238 | /* for each MANPATH */ |
223 | do { /* for each MANPATH item */ | 239 | cur_sect = sec_list; |
224 | char *next_path = strchrnul(cur_path, ':'); | 240 | do { /* for each section */ |
225 | int path_len = next_path - cur_path; | 241 | char *next_sect = strchrnul(cur_sect, ':'); |
226 | cur_sect = sec_list; | 242 | int sect_len = next_sect - cur_sect; |
227 | do { /* for each section */ | 243 | char *man_filename; |
228 | char *next_sect = strchrnul(cur_sect, ':'); | 244 | int cat0man1 = 0; |
229 | int sect_len = next_sect - cur_sect; | 245 | |
230 | char *man_filename; | 246 | /* Search for cat, then man page */ |
231 | int cat0man1 = 0; | 247 | while (cat0man1 < 2) { |
232 | 248 | int found_here; | |
233 | /* Search for cat, then man page */ | 249 | man_filename = xasprintf("%s/%s%.*s/%s.%.*s" Z_SUFFIX, |
234 | while (cat0man1 < 2) { | 250 | cur_path, |
235 | int found_here; | 251 | "cat\0man" + (cat0man1 * 4), |
236 | man_filename = xasprintf("%.*s/%s%.*s/%s.%.*s" Z_SUFFIX, | 252 | sect_len, cur_sect, |
237 | path_len, cur_path, | 253 | *argv, |
238 | "cat\0man" + (cat0man1 * 4), | 254 | sect_len, cur_sect); |
239 | sect_len, cur_sect, | 255 | found_here = show_manpage(pager, man_filename, cat0man1, 0); |
240 | *argv, | 256 | found |= found_here; |
241 | sect_len, cur_sect); | 257 | cat0man1 += found_here + 1; |
242 | found_here = show_manpage(pager, man_filename, cat0man1, 0); | 258 | free(man_filename); |
243 | found |= found_here; | 259 | } |
244 | cat0man1 += found_here + 1; | 260 | |
245 | free(man_filename); | 261 | if (found && !(opt & OPT_a)) |
246 | } | 262 | goto next_arg; |
247 | 263 | cur_sect = next_sect; | |
248 | if (found && !(opt & OPT_a)) | 264 | while (*cur_sect == ':') |
249 | goto next_arg; | 265 | cur_sect++; |
250 | cur_sect = next_sect; | 266 | } while (*cur_sect); |
251 | while (*cur_sect == ':') | ||
252 | cur_sect++; | ||
253 | } while (*cur_sect); | ||
254 | cur_path = next_path; | ||
255 | while (*cur_path == ':') | ||
256 | cur_path++; | ||
257 | } while (*cur_path); | ||
258 | } | 267 | } |
259 | check_found: | 268 | check_found: |
260 | if (!found) { | 269 | if (!found) { |