861 |
|
|
862 |
int main (int argc, char *argv[]) |
int main (int argc, char *argv[]) |
863 |
{ |
{ |
864 |
int argc_env, status = 0, exit_status = OK; |
int argc_env, exit_status = OK; |
865 |
char **argv_env; |
char **argv_env; |
866 |
const char *tmp; |
const char *tmp; |
867 |
char *multiple_locale = NULL; |
char *multiple_locale = NULL; |
1073 |
#endif /* MAN_DB_UPDATES */ |
#endif /* MAN_DB_UPDATES */ |
1074 |
|
|
1075 |
while (optind < argc) { |
while (optind < argc) { |
1076 |
|
int status = OK; |
1077 |
|
int found = 0; |
1078 |
static int maybe_section = 0; |
static int maybe_section = 0; |
1079 |
const char *nextarg = argv[optind++]; |
const char *nextarg = argv[optind++]; |
1080 |
|
|
1104 |
|
|
1105 |
/* this is where we actually start looking for the man page */ |
/* this is where we actually start looking for the man page */ |
1106 |
skip = 0; |
skip = 0; |
1107 |
status = man (nextarg); |
status = man (nextarg, &found); |
1108 |
|
|
1109 |
/* clean out the cache of database lookups for each man page */ |
/* clean out the cache of database lookups for each man page */ |
1110 |
hash_free (db_hash); |
hash_free (db_hash); |
1111 |
db_hash = NULL; |
db_hash = NULL; |
1112 |
|
|
1113 |
if (section && maybe_section) { |
if (section && maybe_section) { |
1114 |
if (!status && !catman) { |
if (status != OK && !catman) { |
1115 |
/* Maybe the section wasn't a section after |
/* Maybe the section wasn't a section after |
1116 |
* all? e.g. 'man 9wm fvwm'. |
* all? e.g. 'man 9wm fvwm'. |
1117 |
*/ |
*/ |
1121 |
"name\n", section); |
"name\n", section); |
1122 |
tmp = section; |
tmp = section; |
1123 |
section = NULL; |
section = NULL; |
1124 |
status = man (tmp); |
status = man (tmp, &found); |
1125 |
hash_free (db_hash); |
hash_free (db_hash); |
1126 |
db_hash = NULL; |
db_hash = NULL; |
1127 |
/* ... but don't gripe about it if it doesn't |
/* ... but don't gripe about it if it doesn't |
1128 |
* work! |
* work! |
1129 |
*/ |
*/ |
1130 |
if (status) { |
if (status == OK) { |
1131 |
/* It was a name after all, so arrange |
/* It was a name after all, so arrange |
1132 |
* to try the next page again with a |
* to try the next page again with a |
1133 |
* null section. |
* null section. |
1140 |
} |
} |
1141 |
} |
} |
1142 |
|
|
1143 |
if (!status && !catman) { |
if (status != OK && !catman) { |
1144 |
if (!skip) { |
if (!skip) { |
1145 |
if (strchr (nextarg, '/')) |
exit_status = status; |
|
exit_status = local_man_loop (nextarg); |
|
|
else |
|
|
exit_status = NOT_FOUND; |
|
1146 |
if (exit_status == NOT_FOUND) { |
if (exit_status == NOT_FOUND) { |
1147 |
if (!section && maybe_section && |
if (!section && maybe_section && |
1148 |
isdigit (nextarg[0])) |
isdigit (nextarg[0])) |
1153 |
} |
} |
1154 |
} else { |
} else { |
1155 |
if (debug) |
if (debug) |
1156 |
fprintf(stderr, |
fprintf (stderr, |
1157 |
"\nFound %d man pages\n", status); |
"\nFound %d man pages\n", found); |
1158 |
if (catman) { |
if (catman) { |
1159 |
printf ("%s", nextarg); |
printf ("%s", nextarg); |
1160 |
if (section) |
if (section) |
3324 |
* being used, only look for the man page source file. |
* being used, only look for the man page source file. |
3325 |
* |
* |
3326 |
*/ |
*/ |
3327 |
static int man (const char *name) |
static int man (const char *name, int *found) |
3328 |
{ |
{ |
3329 |
struct candidate *candidates = NULL; |
struct candidate *candidates = NULL; |
|
int found = 0; |
|
3330 |
|
|
3331 |
|
*found = 0; |
3332 |
fflush (stdout); |
fflush (stdout); |
3333 |
|
|
3334 |
|
if (strchr (name, '/')) { |
3335 |
|
int status = local_man_loop (name); |
3336 |
|
if (status == OK) |
3337 |
|
*found = 1; |
3338 |
|
return status; |
3339 |
|
} |
3340 |
|
|
3341 |
if (section) { |
if (section) { |
3342 |
char **mp; |
char **mp; |
3343 |
|
|
3344 |
for (mp = manpathlist; *mp; mp++) |
for (mp = manpathlist; *mp; mp++) |
3345 |
found += locate_page (*mp, section, name, &candidates); |
*found += locate_page (*mp, section, name, &candidates); |
3346 |
} else { |
} else { |
3347 |
char **sp; |
char **sp; |
3348 |
|
|
3350 |
char **mp; |
char **mp; |
3351 |
|
|
3352 |
for (mp = manpathlist; *mp; mp++) |
for (mp = manpathlist; *mp; mp++) |
3353 |
found += locate_page (*mp, *sp, name, |
*found += locate_page (*mp, *sp, name, |
3354 |
&candidates); |
&candidates); |
3355 |
} |
} |
3356 |
} |
} |
3357 |
|
|
3358 |
if (found) |
if (*found) |
3359 |
found = display_pages (candidates); |
*found = display_pages (candidates); |
3360 |
|
|
3361 |
return found; |
return *found ? OK : NOT_FOUND; |
3362 |
} |
} |
3363 |
|
|
3364 |
|
|