2 * globbing_test.c: test program for file-finding functions
4 * Copyright (C) 1995 Graeme W. Wilford. (Wilf.)
5 * Copyright (C) 2001, 2002, 2003, 2006, 2007, 2008 Colin Watson.
7 * This file is part of man-db.
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.
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.
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
26 #endif /* HAVE_CONFIG_H */
35 #define _(String) gettext (String)
36 #define N_(String) gettext_noop (String)
38 #include "manconfig.h"
44 man_sandbox *sandbox; /* unused, but needed by libman */
46 extern const char *extension;
47 static int match_case = 0;
48 static int regex_opt = 0;
49 static int wildcard = 0;
50 static char **remaining_args;
52 const char *argp_program_version = "globbing " PACKAGE_VERSION;
53 const char *argp_program_bug_address = PACKAGE_BUGREPORT;
54 error_t argp_err_exit_status = FAIL;
56 static const char args_doc[] = N_("PATH SECTION NAME");
58 static struct argp_option options[] = {
59 { "debug", 'd', 0, 0, N_("emit debugging messages") },
60 { "extension", 'e', N_("EXTENSION"), 0, N_("limit search to extension type EXTENSION") },
61 { "ignore-case", 'i', 0, 0, N_("look for pages case-insensitively (default)") },
62 { "match-case", 'I', 0, 0, N_("look for pages case-sensitively") },
63 { "regex", 'r', 0, 0, N_("interpret page name as a regex") },
64 { "wildcard", 'w', 0, 0, N_("the page name contains wildcards") },
65 { 0, 'h', 0, OPTION_HIDDEN, 0 }, /* compatibility for --help */
69 static error_t parse_opt (int key, char *arg, struct argp_state *state)
91 argp_state_help (state, state->out_stream,
95 if (state->argc - state->next != 3)
97 remaining_args = state->argv + state->next;
100 return ARGP_ERR_UNKNOWN;
103 static struct argp argp = { options, parse_opt, args_doc };
105 int main (int argc, char **argv)
109 set_program_name (argv[0]);
114 if (argp_parse (&argp, argc, argv, 0, 0, 0))
117 for (i = 0; i <= 1; i++) {
120 files = look_for_file (remaining_args[0], remaining_args[1],
121 remaining_args[2], i,
122 (match_case ? LFF_MATCHCASE : 0) |
123 (regex_opt ? LFF_REGEX : 0) |
124 (wildcard ? LFF_WILDCARD : 0));
127 printf ("%s\n", *files++);