1 /* PSPP - a program for statistical analysis.
2 Copyright (C) 2009 Free Software Foundation, Inc.
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
17 #ifndef LIBPSPP_ARGV_PARSER_H
18 #define LIBPSPP_ARGV_PARSER_H 1
20 /* Simple, modular command-line argument parser.
22 glibc has two option parsers, but neither one of them feels
25 - getopt_long is simple, but not modular, in that there is
26 no easy way to make it accept multiple collections of
27 options supported by different modules.
29 - argp is more sophisticated and more complete, and hence
30 more complex. It still lacks one important feature for
31 modularity: there is no straightforward way for option
32 groups that are implemented independently to have separate
35 The parser implemented in this file is meant to be simple and
36 modular. It is based internally on getopt_long. */
44 const char *long_name; /* Long option name, NULL if none. */
45 int short_name; /* Short option character, 0 if none. */
46 int has_arg; /* no_argument, required_argument, or
48 int id; /* Value passed to callback. */
51 struct argv_parser *argv_parser_create (void);
52 void argv_parser_destroy (struct argv_parser *);
54 void argv_parser_add_options (struct argv_parser *,
55 const struct argv_option *options, size_t n,
56 void (*cb) (int id, void *aux), void *aux);
57 bool argv_parser_run (struct argv_parser *, int argc, char **argv);
59 #endif /* libpspp/argv-parser.h */