summaryrefslogtreecommitdiff
path: root/miscutils/man.c
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2008-07-05 08:38:41 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2008-07-05 08:38:41 +0000
commitfec8b42317dfe5a1471a9cfa9dc9ecf6ddf95e3f (patch)
tree6dd53b44a5b906d8ba7b0a4044dc99b3ad07916b /miscutils/man.c
parent4cbffc0f349557e13565753df6f1cd240dd2973c (diff)
downloadbusybox-w32-fec8b42317dfe5a1471a9cfa9dc9ecf6ddf95e3f.tar.gz
busybox-w32-fec8b42317dfe5a1471a9cfa9dc9ecf6ddf95e3f.tar.bz2
busybox-w32-fec8b42317dfe5a1471a9cfa9dc9ecf6ddf95e3f.zip
man: code shrink
function old new delta man_main 725 765 +40 show_manpage 112 - -112 ------------------------------------------------------------------------------ (add/remove: 0/1 grow/shrink: 1/0 up/down: 40/-112) Total: -72 bytes
Diffstat (limited to 'miscutils/man.c')
-rw-r--r--miscutils/man.c38
1 files changed, 18 insertions, 20 deletions
diff --git a/miscutils/man.c b/miscutils/man.c
index 20172f6b2..509ae96bd 100644
--- a/miscutils/man.c
+++ b/miscutils/man.c
@@ -23,6 +23,10 @@ echo ".pl \n(nlu+10"
23 23
24*/ 24*/
25 25
26/* Trick gcc to reuse "cat" string. */
27#define STR_catNULmanNUL "cat\0man"
28#define STR_cat "cat\0man"
29
26static int run_pipe(const char *unpacker, const char *pager, char *man_filename, int cat) 30static int run_pipe(const char *unpacker, const char *pager, char *man_filename, int cat)
27{ 31{
28 char *cmd; 32 char *cmd;
@@ -61,7 +65,7 @@ static int show_manpage(const char *pager, char *man_filename, int cat)
61 return 1; 65 return 1;
62 66
63 man_filename[len - 3] = '\0'; /* ".gz" -> "" */ 67 man_filename[len - 3] = '\0'; /* ".gz" -> "" */
64 if (run_pipe("cat", pager, man_filename, cat)) 68 if (run_pipe(STR_cat, pager, man_filename, cat))
65 return 1; 69 return 1;
66 70
67 return 0; 71 return 0;
@@ -147,28 +151,22 @@ int man_main(int argc ATTRIBUTE_UNUSED, char **argv)
147 char *next_sect = strchrnul(cur_sect, ':'); 151 char *next_sect = strchrnul(cur_sect, ':');
148 int sect_len = next_sect - cur_sect; 152 int sect_len = next_sect - cur_sect;
149 char *man_filename; 153 char *man_filename;
150 int found_here; 154 int cat0man1 = 0;
151 155
152 /* Search for cat page first */ 156 /* Search for cat, then man page */
153 man_filename = xasprintf("%.*s/%s%.*s/%s.%.*s" ".bz2", 157 while (cat0man1 < 2) {
154 path_len, cur_path, 158 int found_here;
155 "cat",
156 sect_len, cur_sect,
157 *argv,
158 sect_len, cur_sect);
159 found_here = show_manpage(pager, man_filename, 1);
160 free(man_filename);
161 if (!found_here) {
162 man_filename = xasprintf("%.*s/%s%.*s/%s.%.*s" ".bz2", 159 man_filename = xasprintf("%.*s/%s%.*s/%s.%.*s" ".bz2",
163 path_len, cur_path, 160 path_len, cur_path,
164 "man", 161 STR_catNULmanNUL + cat0man1 * 4,
165 sect_len, cur_sect, 162 sect_len, cur_sect,
166 *argv, 163 *argv,
167 sect_len, cur_sect); 164 sect_len, cur_sect);
168 found_here = show_manpage(pager, man_filename, 0); 165 found_here = show_manpage(pager, man_filename, cat0man1);
166 found |= found_here;
167 cat0man1 += found_here + 1;
169 free(man_filename); 168 free(man_filename);
170 } 169 }
171 found |= found_here;
172 170
173 if (found && !(opt & OPT_a)) 171 if (found && !(opt & OPT_a))
174 goto next_arg; 172 goto next_arg;