man: handle many MANPAGER directives so that they do not override
but accumulate. By Ivana Varekova <varekova AT redhat.com> function old new delta man_main 567 684 +117
This commit is contained in:
parent
e96dcb4dcf
commit
50d068cb76
@ -69,9 +69,11 @@ int man_main(int argc ATTRIBUTE_UNUSED, char **argv)
|
|||||||
{
|
{
|
||||||
FILE *cf;
|
FILE *cf;
|
||||||
const char *pager;
|
const char *pager;
|
||||||
char *man_path, *sec_list;
|
char **man_path_list;
|
||||||
|
char *sec_list;
|
||||||
char *cur_path, *cur_sect;
|
char *cur_path, *cur_sect;
|
||||||
char *line, *value;
|
char *line, *value;
|
||||||
|
int count_mp, alloc_mp, cur_mp;
|
||||||
int opt;
|
int opt;
|
||||||
|
|
||||||
opt_complementary = "-1"; /* at least one argument */
|
opt_complementary = "-1"; /* at least one argument */
|
||||||
@ -79,7 +81,12 @@ int man_main(int argc ATTRIBUTE_UNUSED, char **argv)
|
|||||||
argv += optind;
|
argv += optind;
|
||||||
|
|
||||||
sec_list = xstrdup("1:2:3:4:5:6:7:8:9");
|
sec_list = xstrdup("1:2:3:4:5:6:7:8:9");
|
||||||
man_path = xstrdup(getenv("MANPATH"));
|
alloc_mp = 10;
|
||||||
|
man_path_list = xmalloc(10 * sizeof(man_path_list[0]));
|
||||||
|
count_mp = 0;
|
||||||
|
man_path_list[0] = xstrdup(getenv("MANPATH"));
|
||||||
|
if (man_path_list[0])
|
||||||
|
count_mp++;
|
||||||
pager = getenv("MANPAGER");
|
pager = getenv("MANPAGER");
|
||||||
if (!pager) {
|
if (!pager) {
|
||||||
pager = getenv("PAGER");
|
pager = getenv("PAGER");
|
||||||
@ -98,8 +105,13 @@ int man_main(int argc ATTRIBUTE_UNUSED, char **argv)
|
|||||||
value = skip_whitespace(&line[8]);
|
value = skip_whitespace(&line[8]);
|
||||||
*skip_non_whitespace(value) = '\0';
|
*skip_non_whitespace(value) = '\0';
|
||||||
if (strcmp("MANPATH", line) == 0) {
|
if (strcmp("MANPATH", line) == 0) {
|
||||||
free(man_path);
|
man_path_list[count_mp] = xstrdup(value);
|
||||||
man_path = xstrdup(value);
|
count_mp++;
|
||||||
|
if (alloc_mp == count_mp) {
|
||||||
|
alloc_mp += 10;
|
||||||
|
man_path_list = xrealloc(man_path_list, alloc_mp * sizeof(man_path_list[0]));
|
||||||
|
}
|
||||||
|
/* thus man_path_list is always NULL terminated */
|
||||||
}
|
}
|
||||||
if (strcmp("MANSECT", line) == 0) {
|
if (strcmp("MANSECT", line) == 0) {
|
||||||
free(sec_list);
|
free(sec_list);
|
||||||
@ -112,37 +124,35 @@ int man_main(int argc ATTRIBUTE_UNUSED, char **argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
do { /* for each argv[] */
|
do { /* for each argv[] */
|
||||||
cur_path = man_path;
|
cur_mp = 0;
|
||||||
do { /* for each MANPATH item */
|
while ((cur_path = man_path_list[cur_mp++]) != NULL) {
|
||||||
char *next_path = strchrnul(cur_path, ':');
|
/* for each MANPATH */
|
||||||
int path_len = next_path - cur_path;
|
do { /* for each MANPATH item */
|
||||||
|
char *next_path = strchrnul(cur_path, ':');
|
||||||
|
int path_len = next_path - cur_path;
|
||||||
|
cur_sect = sec_list;
|
||||||
|
do { /* for each section */
|
||||||
|
char *next_sect = strchrnul(cur_sect, ':');
|
||||||
|
int sect_len = next_sect - cur_sect;
|
||||||
|
|
||||||
cur_sect = sec_list;
|
char *man_filename = xasprintf("%.*s/man%.*s/%s.%.*s" ".bz2",
|
||||||
do { /* for each section */
|
path_len, cur_path,
|
||||||
char *next_sect = strchrnul(cur_sect, ':');
|
sect_len, cur_sect,
|
||||||
int sect_len = next_sect - cur_sect;
|
*argv,
|
||||||
|
sect_len, cur_sect);
|
||||||
char *man_filename = xasprintf("%.*s/man%.*s/%s.%.*s" ".bz2",
|
int found = show_manpage(pager, man_filename);
|
||||||
path_len, cur_path,
|
free(man_filename);
|
||||||
sect_len, cur_sect,
|
if (found && !(opt & OPT_a))
|
||||||
*argv,
|
|
||||||
sect_len, cur_sect);
|
|
||||||
if (show_manpage(pager, man_filename)) {
|
|
||||||
if (!(opt & OPT_a)) {
|
|
||||||
goto next_arg;
|
goto next_arg;
|
||||||
}
|
cur_sect = next_sect;
|
||||||
}
|
while (*cur_sect == ':')
|
||||||
free(man_filename);
|
cur_sect++;
|
||||||
|
} while (*cur_sect);
|
||||||
cur_sect = next_sect;
|
cur_path = next_path;
|
||||||
while (*cur_sect == ':')
|
while (*cur_path == ':')
|
||||||
cur_sect++;
|
cur_path++;
|
||||||
} while (*cur_sect);
|
} while (*cur_path);
|
||||||
|
}
|
||||||
cur_path = next_path;
|
|
||||||
while (*cur_path == ':')
|
|
||||||
cur_path++;
|
|
||||||
} while (*cur_path);
|
|
||||||
next_arg:
|
next_arg:
|
||||||
argv++;
|
argv++;
|
||||||
} while (*argv);
|
} while (*argv);
|
||||||
|
Loading…
Reference in New Issue
Block a user