*/
-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;
return 1;
}
- /* "2>&1" added so that nroff errors are shown in pager too.
+ /* "2>&1" is added so that nroff errors are shown in pager too.
* Otherwise it may show just empty screen */
- cmd = xasprintf("%s '%s' | gtbl | nroff -Tlatin1 -mandoc 2>&1 | %s",
+ cmd = xasprintf(cat ? "%s '%s' | %s"
+ : "%s '%s' | gtbl | nroff -Tlatin1 -mandoc 2>&1 | %s",
unpacker, man_filename, pager);
system(cmd);
free(cmd);
}
/* 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;
do { /* for each section */
char *next_sect = strchrnul(cur_sect, ':');
int sect_len = next_sect - cur_sect;
-
- char *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);
+ 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) {
+ 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);
+ free(man_filename);
+ }
+ found |= found_here;
+
if (found && !(opt & OPT_a))
goto next_arg;
cur_sect = next_sect;