2 * zsoelim_main.c: eliminate .so includes within *roff source
4 * Copyright (C) 1994, 1995 Graeme W. Wilford. (Wilf.)
5 * Copyright (C) 1997 Fabrizio Polacco.
6 * Copyright (C) 2001, 2002, 2003, 2004, 2006, 2007, 2008, 2009, 2010
9 * This file is part of man-db.
11 * man-db is free software; you can redistribute it and/or modify it
12 * under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * man-db is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with man-db; if not, write to the Free Software Foundation,
23 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
28 #endif /* HAVE_CONFIG_H */
34 #include "xvasprintf.h"
38 #define _(String) gettext (String)
39 #define N_(String) gettext_noop (String)
41 #include "manconfig.h"
46 #include "decompress.h"
55 static char *manpathlist[MAXDIRS];
60 const char *argp_program_version = "zsoelim " PACKAGE_VERSION;
61 const char *argp_program_bug_address = PACKAGE_BUGREPORT;
62 error_t argp_err_exit_status = FAIL;
64 static const char args_doc[] = N_("FILE...");
66 static struct argp_option options[] = {
67 { "debug", 'd', 0, 0, N_("emit debugging messages") },
68 { "compatible", 'C', 0, 0, N_("compatibility switch (ignored)"), 1 },
69 { 0, 'h', 0, OPTION_HIDDEN, 0 }, /* compatibility for --help */
73 static error_t parse_opt (int key, char *arg ATTRIBUTE_UNUSED,
74 struct argp_state *state)
81 return 0; /* compatibility with GNU soelim */
83 argp_state_help (state, state->out_stream,
86 case ARGP_KEY_NO_ARGS:
88 files = xmalloc (sizeof *files);
89 files[0] = xstrdup ("-");
93 files = state->argv + state->next;
94 num_files = state->argc - state->next;
97 return ARGP_ERR_UNKNOWN;
100 static struct argp argp = { options, parse_opt, args_doc };
102 int main (int argc, char *argv[])
104 char *multiple_locale = NULL, *internal_locale, *all_locales;
108 set_program_name (argv[0]);
111 pipeline_install_post_fork (pop_all_cleanups);
112 sandbox = sandbox_init ();
115 internal_locale = setlocale (LC_MESSAGES, NULL);
116 /* Use LANGUAGE only when LC_MESSAGES locale category is
117 * neither "C" nor "POSIX". */
118 if (internal_locale && strcmp (internal_locale, "C") &&
119 strcmp (internal_locale, "POSIX"))
120 multiple_locale = getenv ("LANGUAGE");
121 internal_locale = xstrdup (internal_locale ? internal_locale : "C");
123 if (argp_parse (&argp, argc, argv, 0, 0, 0))
126 if (multiple_locale && *multiple_locale) {
127 if (internal_locale && *internal_locale)
128 all_locales = xasprintf ("%s:%s",
132 all_locales = xstrdup (multiple_locale);
134 if (internal_locale && *internal_locale)
135 all_locales = xstrdup (internal_locale);
140 manp = add_nls_manpaths (get_manpath (NULL), all_locales);
143 create_pathlist (manp, manpathlist);
145 /* parse files in command line order */
146 for (i = 0; i < num_files; ++i) {
147 if (zsoelim_open_file (files[i], manpathlist, NULL))
149 zsoelim_parse_file (manpathlist, NULL);
152 free_pathlist (manpathlist);
154 free (internal_locale);