BusyBox 1.11.0 man patch for "cat"

Bernhard Fischer rep.dot.nop at gmail.com
Fri Jul 4 14:36:04 UTC 2008


On Fri, Jul 04, 2008 at 09:55:48AM +0200, Jason Curl wrote:
>Hello,
>
>I'd like to welcome comments on my first bb patch (it's the first I've needed to do since I've started using 1.0.0). I like the new "man" applet, but it needs nroff and gtbl. Unfortunately, I didn't prepare the c++ compiler and the gnu tools won't compile. No worry though, I've updated busybox to support "cat" pages also. This requires less space than installing all the GNU tools.
>
>The diff is applied, generated with "diff -au source modified".
>
>So, I have
>/share/man/cat1
>/share/man/man1
>
>It searches first in the "cat" pages and if it isn't found, then searches in the "man" pages. I'm sure there could be some optimisations made....
>
>Thanks,
>Jason.
>
>Jetzt komfortabel bei Arcor-Digital TV einsteigen: Mehr Happy Ends, mehr Herzschmerz, mehr Fernsehen! Erleben Sie 50 digitale TV Programme und optional 60 Pay TV Sender, einen elektronischen Programmführer mit Movie Star Bewertungen von TV Movie. Außerdem, aktuelle Filmhits und spannende Dokus in der Arcor-Videothek. Infos unter www.arcor.de/tv
>--- busybox-1.11.0/miscutils/man.c	2008-06-25 14:51:35.000000000 +0200
>+++ busybox-1.11.0_manpatch/miscutils/man.c	2008-07-04 09:47:58.000000000 +0200
>@@ -23,7 +23,7 @@
> 
> */
> 
>-static int run_pipe(const char *unpacker, const char *pager, char *man_filename)
>+static int run_pipe(const char *unpacker, const char *pager, char *man_filename, int cat)
> {
> 	char *cmd;
> 
>@@ -35,30 +35,34 @@
> 		return 1;
> 	}
> 
>-	cmd = xasprintf("%s '%s' | gtbl | nroff -Tlatin1 -mandoc | %s",
>-			unpacker, man_filename, pager);
>+        if (!cat) {
>+            cmd = xasprintf("%s '%s' | gtbl | nroff -Tlatin1 -mandoc | %s",
>+                            unpacker, man_filename, pager);
>+        } else {
>+            cmd = xasprintf("%s '%s' | %s", unpacker, man_filename, pager);
>+        }

the parameter cat should probably be a smalluint (or bool).
Perhaps try something like (pseudo-code):
static const char const man_converter[]=
	"| gtbl | nroff -Tlatin1 -mandoc | %s";
cmd = xasprintf("%s '%s' | %s",
unp,man_f,cat?man_converter:man_converter+32);

> 	system(cmd);
> 	free(cmd);
> 	return 1;
> }
> 
> /* man_filename is of the form "/dir/dir/dir/name.s.bz2" */
>-static int show_manpage(const char *pager, char *man_filename)
>+static int show_manpage(const char *pager, char *man_filename, int cat)
> {
> 	int len;
> 
>-	if (run_pipe("bunzip2 -c", pager, man_filename))
>+	if (run_pipe("bunzip2 -c", pager, man_filename, cat))
> 		return 1;
> 
> 	len = strlen(man_filename) - 1;
> 
> 	man_filename[len] = '\0'; /* ".bz2" -> ".gz" */
> 	man_filename[len - 2] = 'g';
>-	if (run_pipe("gunzip -c", pager, man_filename))
>+	if (run_pipe("gunzip -c", pager, man_filename, cat))
> 		return 1;
> 
> 	man_filename[len - 3] = '\0'; /* ".gz" -> "" */
>-	if (run_pipe("cat", pager, man_filename))
>+	if (run_pipe("cat", pager, man_filename, cat))
> 		return 1;
> 
> 	return 0;
>@@ -134,14 +138,27 @@
> 				do { /* for each section */
> 					char *next_sect = strchrnul(cur_sect, ':');
> 					int sect_len = next_sect - cur_sect;
>+                                        char *man_filename;
>+                                        int found;
> 
>-					char *man_filename = xasprintf("%.*s/man%.*s/%s.%.*s" ".bz2",
>-								path_len, cur_path,
>-								sect_len, cur_sect,
>-								*argv,
>-								sect_len, cur_sect);
>-					int found = show_manpage(pager, man_filename);
>+                                        /* Search for CAT page first */
>+					man_filename = xasprintf("%.*s/cat%.*s/%s.%.*s" ".bz2",

It could be smaller to pass "cat" and "man" in here, since we could use
the same fmt-string for both then.

And you really need to fix the indentation :)

Please resend (and include figures for size(1) with and without your
patch, eventually ./scripts/bloat-o-meter output too).

TIA
>+                                                                 path_len, cur_path,
>+                                                                 sect_len, cur_sect,
>+                                                                 *argv,
>+                                                                 sect_len, cur_sect);
>+                                        found = show_manpage(pager, man_filename, 1);
> 					free(man_filename);
>+
>+                                        if (!found) {
>+                                            man_filename = xasprintf("%.*s/man%.*s/%s.%.*s" ".bz2",
>+                                                                     path_len, cur_path,
>+                                                                     sect_len, cur_sect,
>+                                                                     *argv,
>+                                                                     sect_len, cur_sect);
>+                                            found = show_manpage(pager, man_filename, 0);
>+                                            free(man_filename);
>+                                        }
> 					if (found && !(opt & OPT_a))
> 						goto next_arg;
> 					cur_sect = next_sect;

>_______________________________________________
>busybox mailing list
>busybox at busybox.net
>http://busybox.net/cgi-bin/mailman/listinfo/busybox



More information about the busybox mailing list