BusyBox 1.11.0 man patch for "cat"
Denys Vlasenko
vda.linux at googlemail.com
Sat Jul 5 09:25:37 UTC 2008
On Saturday 05 July 2008 11:02, Jason Curl wrote:
> I've checked your fix Denys and it also works (I don't get segfaults
> anymore). I've taken the code from my second patch, checked it against
> the latest snapshot and found I can reduce the size of man a bit more by
> removing the two instances of the format string when generating the man
> filename. I think the code is much more cryptic, but it's a small piece.
+ int mode = 0;
- /* Search for cat page first */
- man_filename = xasprintf("%.*s/%s%.*s/%s.%.*s" ".bz2",
Interesting patch format.
char *man_filename;
- int found_here;
+ int mode = 0;
- /* 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) {
+ /* We search first for a cat page, then for a man page */
+ while (mode < 2) {
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,
+ mode?"man":"cat",
+ sect_len, cur_sect,
+ *argv,
+ sect_len, cur_sect);
+ found = show_manpage(pager, man_filename, 1-mode);
free(man_filename);
+ mode += found + 1;
}
- found |= found_here;
if (found && !(opt & OPT_a))
goto next_arg;
"found |= found_here;" was there for a reason:
If no man page is found, we need to report that.
With "man -a", we are getting false negative (found == 0) -
man thinks that page is not found, whereas it's "page is not found
_in last man directory_".
But overall idea is good and I incorporated it in man.c now.
Thanks.
--
vda
More information about the busybox
mailing list