Correct checking for getopt_long()
[public/netxms.git] / include / netxms_getopt.h
1 /* Declarations for getopt.
2 Copyright (C) 1989, 1990, 1991, 1992, 1993 Free Software Foundation, Inc.
3
4 This program is free software; you can redistribute it and/or modify it
5 under the terms of the GNU General Public License as published by the
6 Free Software Foundation; either version 2, or (at your option) any
7 later version.
8
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.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
17
18 #ifndef _GETOPT_H
19 #define _GETOPT_H 1
20
21 #ifdef _WIN32
22 #ifdef LIBNETXMS_EXPORTS
23 #define GETOPT_EXPORTABLE __declspec(dllexport)
24 #else
25 #define GETOPT_EXPORTABLE __declspec(dllimport)
26 #endif
27 #else /* _WIN32 */
28 #define GETOPT_EXPORTABLE
29 #endif
30
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34
35 /* For communication from `getopt' to the caller.
36 When `getopt' finds an option that takes an argument,
37 the argument value is returned here.
38 Also, when `ordering' is RETURN_IN_ORDER,
39 each non-option ARGV-element is returned here. */
40
41 extern GETOPT_EXPORTABLE char *optarg;
42
43 /* Index in ARGV of the next element to be scanned.
44 This is used for communication to and from the caller
45 and for communication between successive calls to `getopt'.
46
47 On entry to `getopt', zero means this is the first call; initialize.
48
49 When `getopt' returns EOF, this is the index of the first of the
50 non-option elements that the caller should itself scan.
51
52 Otherwise, `optind' communicates from one call to the next
53 how much of ARGV has been scanned so far. */
54
55 extern GETOPT_EXPORTABLE int optind;
56
57 /* Callers store zero here to inhibit the error message `getopt' prints
58 for unrecognized options. */
59
60 extern GETOPT_EXPORTABLE int opterr;
61
62 /* Set to an option character which was unrecognized. */
63
64 extern GETOPT_EXPORTABLE int optopt;
65
66 /* Describe the long-named options requested by the application.
67 The LONG_OPTIONS argument to getopt_long or getopt_long_only is a vector
68 of `struct option' terminated by an element containing a name which is
69 zero.
70
71 The field `has_arg' is:
72 no_argument (or 0) if the option does not take an argument,
73 required_argument (or 1) if the option requires an argument,
74 optional_argument (or 2) if the option takes an optional argument.
75
76 If the field `flag' is not NULL, it points to a variable that is set
77 to the value given in the field `val' when the option is found, but
78 left unchanged if the option is not found.
79
80 To have a long-named option do something other than set an `int' to
81 a compiled-in constant, such as set a value from `optarg', set the
82 option's `flag' field to zero and its `val' field to a nonzero
83 value (the equivalent single-letter option character, if there is
84 one). For long options that have a zero `flag' field, `getopt'
85 returns the contents of the `val' field. */
86
87 struct option
88 {
89 #if __STDC__
90 const char *name;
91 #else
92 char *name;
93 #endif
94 /* has_arg can't be an enum because some compilers complain about
95 type mismatches in all the code that assumes it is an int. */
96 int has_arg;
97 int *flag;
98 int val;
99 };
100
101 /* Names for the values of the `has_arg' field of `struct option'. */
102
103 #define no_argument 0
104 #define required_argument 1
105 #define optional_argument 2
106
107 extern int GETOPT_EXPORTABLE getopt (int argc, char *const *argv, const char *shortopts);
108 extern int GETOPT_EXPORTABLE getopt_long (int argc, char *const *argv, const char *shortopts,
109 const struct option *longopts, int *longind);
110 extern int GETOPT_EXPORTABLE getopt_long_only (int argc, char *const *argv,
111 const char *shortopts,
112 const struct option *longopts, int *longind);
113
114 /* Internal only. Users should not call this directly. */
115 extern int _getopt_internal (int argc, char *const *argv,
116 const char *shortopts,
117 const struct option *longopts, int *longind,
118 int long_only);
119
120 #ifdef __cplusplus
121 }
122 #endif
123
124 #endif /* _GETOPT_H */