summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Vlasenko2008-07-05 08:38:41 +0000
committerDenis Vlasenko2008-07-05 08:38:41 +0000
commitfec8b42317dfe5a1471a9cfa9dc9ecf6ddf95e3f (patch)
tree6dd53b44a5b906d8ba7b0a4044dc99b3ad07916b
parent4cbffc0f349557e13565753df6f1cd240dd2973c (diff)
downloadbusybox-fec8b42317dfe5a1471a9cfa9dc9ecf6ddf95e3f.zip
busybox-fec8b42317dfe5a1471a9cfa9dc9ecf6ddf95e3f.tar.gz
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
-rw-r--r--miscutils/man.c38
1 files changed, 18 insertions, 20 deletions
diff --git a/miscutils/man.c b/miscutils/man.c
index 20172f6..509ae96 100644
--- a/miscutils/man.c
+++ b/miscutils/man.c
@@ -23,6 +23,10 @@ echo ".pl \n(nlu+10"
*/
+/* Trick gcc to reuse "cat" string. */
+#define STR_catNULmanNUL "cat\0man"
+#define STR_cat "cat\0man"
+
static int run_pipe(const char *unpacker, const char *pager, char *man_filename, int cat)
{
char *cmd;
@@ -61,7 +65,7 @@ static int show_manpage(const char *pager, char *man_filename, int cat)
return 1;
man_filename[len - 3] = '\0'; /* ".gz" -> "" */
- if (run_pipe("cat", pager, man_filename, cat))
+ if (run_pipe(STR_cat, pager, man_filename, cat))
return 1;
return 0;
@@ -147,28 +151,22 @@ int man_main(int argc ATTRIBUTE_UNUSED, char **argv)
char *next_sect = strchrnul(cur_sect, ':');
int sect_len = next_sect - cur_sect;
char *man_filename;
- int found_here;
-
- /* Search for cat page first */
- man_filename = xasprintf("%.*s/%s%.*s/%s.%.*s" ".bz2",
- path_len, cur_path,
- "cat",
- sect_len, cur_sect,
- *argv,
- sect_len, cur_sect);
- found_here = show_manpage(pager, man_filename, 1);
- free(man_filename);
- if (!found_here) {
+ int cat0man1 = 0;
+
+ /* Search for cat, then man page */
+ while (cat0man1 < 2) {
+ int found_here;
man_filename = xasprintf("%.*s/%s%.*s/%s.%.*s" ".bz2",
- path_len, cur_path,
- "man",
- sect_len, cur_sect,
- *argv,
- sect_len, cur_sect);
- found_here = show_manpage(pager, man_filename, 0);
+ path_len, cur_path,
+ STR_catNULmanNUL + cat0man1 * 4,
+ sect_len, cur_sect,
+ *argv,
+ sect_len, cur_sect);
+ found_here = show_manpage(pager, man_filename, cat0man1);
+ found |= found_here;
+ cat0man1 += found_here + 1;
free(man_filename);
}
- found |= found_here;
if (found && !(opt & OPT_a))
goto next_arg;