Fix coding style
[survex.git] / src / cmdline.h
blob8845a97b2089bec003aca4c240649e1d50dabf43
1 /* cmdline.h
2 * Wrapper for GNU getopt which deals with standard options
3 * Copyright (C) 1998-2001,2003,2011 Olly Betts
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 #ifndef CMDLINE_H
21 # define CMDLINE_H
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
27 /* Duplicate these from getopt.h to avoid problems
28 * with trying to compile getopt.h with C++ on MacOS X */
29 #ifndef no_argument
30 /* These values are definitely correct since getopt.h says 0, 1, 2 work */
31 # define no_argument 0
32 # define required_argument 1
33 # define optional_argument 2
35 /* FIXME: struct definition needs to match getopt.h */
36 struct option {
37 const char *name;
38 /* has_arg can't be an enum because some compilers complain about
39 * type mismatches in all the code that assumes it is an int. */
40 int has_arg;
41 int *flag;
42 int val;
45 extern char *optarg;
46 extern int optind;
47 extern int opterr;
48 extern int optopt;
49 #endif
51 struct help_msg {
52 int opt;
53 int msg_no;
54 const char * arg;
57 /* give -1 for max_args_ if there's no limit */
58 void cmdline_init(int argc_, char *const *argv_, const char *shortopts_,
59 const struct option *longopts_, int *longind_,
60 const struct help_msg *help_,
61 int min_args_, int max_args_);
62 /* if args not 0, use instead of auto-generated FILE args */
63 /* if extra not 0, display as extra blurb at end */
64 /* if arg not NULL, extra must be a printf format with one %s */
65 void cmdline_set_syntax_message(int msg_args, int msg_extra, const char * arg);
66 int cmdline_getopt(void);
67 void cmdline_help(void);
68 void cmdline_version(void);
69 void cmdline_syntax(void);
70 void cmdline_too_few_args(void);
71 void cmdline_too_many_args(void);
72 int cmdline_int_arg(void);
73 double cmdline_double_arg(void);
75 #define HLP_ENCODELONG(N) (-(N + 1))
76 #define HLP_DECODELONG(N) (-(N + 1))
77 #define HLP_ISLONG(N) ((N) <= 0)
78 #define HLP_HELP 30000
79 #define HLP_VERSION 30001
81 #ifdef __cplusplus
83 #endif
85 #endif