#include "argp.h"
#include "dirname.h"
#include "minmax.h"
+#include "progname.h"
#include "regex.h"
#include "stat-time.h"
#include "utimens.h"
char *lang;
/* external formatter programs, one for use without -t, and one with -t */
-#define NFMT_PROG "./mandb_nfmt"
-#define TFMT_PROG "./mandb_tfmt"
+#define NFMT_PROG "mandb_nfmt"
+#define TFMT_PROG "mandb_tfmt"
#undef ALT_EXT_FORMAT /* allow external formatters located in cat hierarchy */
static int global_manpath = -1; /* global or user manual page hierarchy? */
/* globals */
int quiet = 1;
-char *program_name;
char *database = NULL;
extern const char *extension; /* for globbing.c */
extern char *user_config_file; /* defined in manp.c */
/* allocate space for the program name */
*argc = 0;
argv = XNMALLOC (*argc + 3, char *);
- argv[(*argc)++] = program_name;
+ argv[(*argc)++] = base_name (program_name);
/* for each [ \t]+ delimited string, allocate an array space and fill
it in. An escaped space is treated specially */
char **result_encoding)
{
const char *roff_opt;
- char *fmt_prog;
+ char *fmt_prog = NULL;
pipeline *p = pipeline_new ();
pipecmd *cmd;
char *page_encoding = NULL;
if (!roff_opt)
roff_opt = "";
-#ifdef ALT_EXT_FORMAT
- /* Check both external formatter locations */
if (dir && !recode) {
+#ifdef ALT_EXT_FORMAT
char *catpath = get_catpath
(dir, global_manpath ? SYSTEM_CAT : USER_CAT);
- /* If we have an alternate catpath */
+ /* If we have an alternate catpath, look for an external
+ * formatter there.
+ */
if (catpath) {
fmt_prog = appendstr (catpath, "/",
troff ? TFMT_PROG : NFMT_PROG,
NULL);
- if (access (fmt_prog, X_OK)) {
+ if (!CAN_ACCESS (fmt_prog, X_OK)) {
free (fmt_prog);
- fmt_prog = xstrdup (troff ? TFMT_PROG :
- NFMT_PROG);
- if (access (fmt_prog, X_OK)) {
- free (fmt_prog);
- fmt_prog = NULL;
- }
+ fmt_prog = NULL;
}
- /* If we don't */
- } else {
+ }
#endif /* ALT_EXT_FORMAT */
- fmt_prog = xstrdup (troff ? TFMT_PROG : NFMT_PROG);
- if (access (fmt_prog, X_OK)) {
+ /* If the page is in a proper manual page hierarchy (as
+ * opposed to being read using --local-file or similar),
+ * look for an external formatter there.
+ */
+ if (!fmt_prog) {
+ fmt_prog = appendstr (NULL, dir, "/",
+ troff ? TFMT_PROG : NFMT_PROG,
+ NULL);
+ if (!CAN_ACCESS (fmt_prog, X_OK)) {
free (fmt_prog);
fmt_prog = NULL;
}
-
-#ifdef ALT_EXT_FORMAT
}
- } else
- fmt_prog = NULL;
-#endif /* ALT_EXT_FORMAT */
-
+ }
+
if (fmt_prog)
debug ("External formatter %s\n", fmt_prog);
if (*man_file == '\0')
found = 1;
else
- found = !access (man_file, R_OK);
+ found = CAN_ACCESS (man_file, R_OK);
if (found) {
int status;
if (prompt && do_prompt (title)) {
if (format == 1 && *man_file == '\0')
found = 1;
else
- found = !access (format ? man_file : cat_file, R_OK);
+ found = CAN_ACCESS
+ (format ? man_file : cat_file, R_OK);
debug ("format: %d, save_cat: %d, found: %d\n",
format, save_cat, found);
cat_file = find_cat_file (candp->path, filename, man_file);
found = display (candp->path, man_file, cat_file, title, NULL);
- if (cat_file)
- free (cat_file);
+ free (cat_file);
free (lang);
lang = NULL;
}
cat_file = find_cat_file (candp->path, file, man_file);
found += display (candp->path, man_file, cat_file,
title, in->filter);
- if (cat_file)
- free (cat_file);
+ free (cat_file);
free (lang);
lang = NULL;
free (file);
return found; /* zero */
}
} else {
- if (catpath)
- free (catpath);
+ free (catpath);
free (title);
return found; /* zero */
}
sections[i] = NULL;
return sections;
} else {
- if (sections)
- free (sections);
+ free (sections);
return config_sections;
}
}
char **argv_env;
const char *tmp;
- program_name = base_name (argv[0]);
+ set_program_name (argv[0]);
check_standard_fds ();
exit (OK);
} else {
free (internal_locale);
- free (program_name);
gripe_no_name (NULL);
}
}
++first_arg;
}
free (internal_locale);
- free (program_name);
exit (exit_status);
}
free (database);
free_pathlist (manpathlist);
free (internal_locale);
- free (program_name);
exit (exit_status);
}