1 /*
2 * manpath.c: display either the manpath or catpath
3 *
4 * Copyright (C) 1994, 1995 Graeme W. Wilford. (Wilf.)
5 * Copyright (C) 2001, 2002 Colin Watson.
6 *
7 * This file is part of man-db.
8 *
9 * man-db is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * man-db is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with man-db; if not, write to the Free Software Foundation,
21 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 *
23 * Thu Nov 17 08:29:39 GMT 1994 Wilf. (G.Wilford@ee.surrey.ac.uk)
24 */
25
26 #ifdef HAVE_CONFIG_H
27 #include "config.h"
28 #endif /* HAVE_CONFIG_H */
29
30 #include <stdbool.h>
31 #include <string.h>
32 #include <stdlib.h>
33 #include <stdio.h>
34 #include <errno.h>
35 #include <unistd.h>
36 #include <limits.h>
37
38 #include "argp.h"
39 #include "error.h"
40 #include "progname.h"
41
42 #include "gettext.h"
43 #define _(String) gettext (String)
44 #define N_(String) gettext_noop (String)
45
46 #include "manconfig.h"
47
48 #include "debug.h"
49 #include "util.h"
50
51 #include "manp.h"
52
53 int quiet = 0;
54
55 static bool cat = false;
56 static bool global = false;
57 static const char *alt_system = "";
58 extern char *user_config_file;
59
60 const char *argp_program_version = "manpath " PACKAGE_VERSION;
61 const char *argp_program_bug_address = PACKAGE_BUGREPORT;
62 error_t argp_err_exit_status = FAIL;
63
64 static struct argp_option options[] = {
65 OPT ("catpath", 'c', 0, N_("show relative catpaths")),
66 OPT ("global", 'g', 0, N_("show the entire global manpath")),
67 OPT ("debug", 'd', 0, N_("emit debugging messages")),
68 OPT ("quiet", 'q', 0, N_("produce fewer warnings")),
69 OPT ("config-file", 'C', N_("FILE"),
70 N_("use this user configuration file")),
71 OPT ("systems", 'm', N_("SYSTEM"),
72 N_("use manual pages from other systems")),
73 OPT_HELP_COMPAT,
74 { 0 }
75 };
76
77 static error_t parse_opt (int key, char *arg, struct argp_state *state)
78 {
79 switch (key) {
80 case 'c':
81 cat = true;
82 return 0;
83 case 'g':
84 global = true;
85 quiet = 1;
86 return 0;
87 case 'd':
88 debug_level = true;
89 return 0;
90 case 'q':
91 quiet = 1;
92 return 0;
93 case 'C':
94 user_config_file = arg;
95 return 0;
96 case 'm':
97 alt_system = arg;
98 return 0;
99 case 'h':
100 argp_state_help (state, state->out_stream,
101 ARGP_HELP_STD_HELP);
102 break;
103 }
104 return ARGP_ERR_UNKNOWN;
105 }
106
107 static struct argp argp = { options, parse_opt };
108
109 /*
110 * Examine user's PATH and print a reasonable MANPATH.
111 */
112 int main (int argc, char *argv[])
113 {
114 char *path_string;
115
116 set_program_name (argv[0]);
117
118 init_debug ();
119 init_locale ();
120
121 if (argp_parse (&argp, argc, argv, 0, 0, 0))
122 exit (FAIL);
123
124 path_string = get_manpath (alt_system);
125
126 if (global) {
127 path_string = get_mandb_manpath ();
128 if (!path_string)
129 error (FAIL, 0,
130 _("warning: no global manpaths set in "
131 "config file %s"),
132 CONFIG_FILE);
133 }
134 if (cat)
135 path_string = cat_manpath (path_string);
136
137 printf ("%s\n", path_string);
138 exit (OK);
139 }