BusyBox 1.11.0 man patch for "cat"
Jason Curl
jcurlnews at arcor.de
Fri Jul 4 14:00:22 PDT 2008
Hello BB,
New patch attached. There was a bug that I reported in a previous email
that's also included in this patch (a one-liner so I didn't bother
generating a patch for that only).
Cheers,
Jason.
Bernhard Fischer wrote:
> 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.
>>
>> --- 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);
>
I've changed it to a smalluint and removed some of the spacing due to
format strings.
>
>> 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.
>
Now in a loop.
> And you really need to fix the indentation :)
>
I hope I caught all of them.
> Please resend (and include figures for size(1) with and without your
> patch, eventually ./scripts/bloat-o-meter output too).
>
I didn't have luck with the bloat-o-meter. It gave me weird results with
differences where nothing was changed. So I'll have to look into it
further....
> TIA
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: mancat.patch
Type: text/x-diff
Size: 2463 bytes
Desc: not available
Url : http://busybox.net/lists/busybox/attachments/20080704/cfa4d5f3/attachment.patch
More information about the busybox
mailing list