2 Copyright (c) 1998 Red Hat Software
4 Permission is hereby granted, free of charge, to any person obtaining a copy
5 of this software and associated documentation files (the "Software"), to deal
6 in the Software without restriction, including without limitation the rights
7 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 copies of the Software, and to permit persons to whom the Software is
9 furnished to do so, subject to the following conditions:
11 The above copyright notice and this permission notice shall be included in
12 all copies or substantial portions of the Software.
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
18 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 Except as contained in this notice, the name of the X Consortium shall not be
22 used in advertising or otherwise to promote the sale, use or other dealings
23 in this Software without prior written authorization from the X Consortium.
29 #include <stdio.h> /* for FILE * */
31 #define POPT_OPTION_DEPTH 10
33 #define POPT_ARG_NONE 0
34 #define POPT_ARG_STRING 1
35 #define POPT_ARG_INT 2
36 #define POPT_ARG_LONG 3
37 #define POPT_ARG_INCLUDE_TABLE 4 /* arg points to table */
38 #define POPT_ARG_CALLBACK 5 /* table-wide callback... must be
39 set first in table; arg points
40 to callback, descrip points to
41 callback data to pass */
42 #define POPT_ARG_MASK 0x0000FFFF
43 #define POPT_ARGFLAG_ONEDASH 0x80000000 /* allow -longoption */
44 #define POPT_ARGFLAG_DOC_HIDDEN 0x40000000 /* don't show in help/usage */
45 #define POPT_CBFLAG_PRE 0x80000000 /* call the callback before parse */
46 #define POPT_CBFLAG_POST 0x40000000 /* call the callback after parse */
47 #define POPT_CBFLAG_INC_DATA 0x20000000 /* use data from the include line,
50 #define POPT_ERROR_NOARG -10
51 #define POPT_ERROR_BADOPT -11
52 #define POPT_ERROR_OPTSTOODEEP -13
53 #define POPT_ERROR_BADQUOTE -15 /* only from poptParseArgString() */
54 #define POPT_ERROR_ERRNO -16 /* only from poptParseArgString() */
55 #define POPT_ERROR_BADNUMBER -17
56 #define POPT_ERROR_OVERFLOW -18
58 /* poptBadOption() flags */
59 #define POPT_BADOPTION_NOALIAS (1 << 0) /* don't go into an alias */
61 /* poptGetContext() flags */
62 #define POPT_CONTEXT_NO_EXEC (1 << 0) /* ignore exec expansions */
63 #define POPT_CONTEXT_KEEP_FIRST (1 << 1) /* pay attention to argv[0] */
64 #define POPT_CONTEXT_POSIXMEHARDER (1 << 2) /* options can't follow args */
67 const char * longName; /* may be NULL */
68 char shortName; /* may be '\0' */
70 void * arg; /* depends on argInfo */
71 int val; /* 0 means don't return, just update flag */
72 char * descrip; /* description for autohelp -- may be NULL */
73 char * argDescrip; /* argument description for autohelp */
77 char * longName; /* may be NULL */
78 char shortName; /* may be '\0' */
80 char ** argv; /* must be free()able */
83 extern struct poptOption poptHelpOptions[];
84 #define POPT_AUTOHELP { NULL, '\0', POPT_ARG_INCLUDE_TABLE, poptHelpOptions, \
85 0, "Help options", NULL },
87 typedef struct poptContext_s * poptContext;
89 typedef struct poptOption * poptOption;
92 enum poptCallbackReason { POPT_CALLBACK_REASON_PRE,
93 POPT_CALLBACK_REASON_POST,
94 POPT_CALLBACK_REASON_OPTION };
95 typedef void (*poptCallbackType)(poptContext con,
96 enum poptCallbackReason reason,
97 const struct poptOption * opt,
98 const char * arg, void * data);
100 poptContext poptGetContext(char * name, int argc, char ** argv,
101 const struct poptOption * options, int flags);
102 void poptResetContext(poptContext con);
104 /* returns 'val' element, -1 on last item, POPT_ERROR_* on error */
105 int poptGetNextOpt(poptContext con);
106 /* returns NULL if no argument is available */
107 char * poptGetOptArg(poptContext con);
108 /* returns NULL if no more options are available */
109 char * poptGetArg(poptContext con);
110 char * poptPeekArg(poptContext con);
111 char ** poptGetArgs(poptContext con);
112 /* returns the option which caused the most recent error */
113 char * poptBadOption(poptContext con, int flags);
114 void poptFreeContext(poptContext con);
115 int poptStuffArgs(poptContext con, char ** argv);
116 int poptAddAlias(poptContext con, struct poptAlias alias, int flags);
117 int poptReadConfigFile(poptContext con, char * fn);
118 /* like above, but reads /etc/popt and $HOME/.popt along with environment
120 int poptReadDefaultConfig(poptContext con, int useEnv);
121 /* argv should be freed -- this allows ', ", and \ quoting, but ' is treated
122 the same as " and both may include \ quotes */
123 int poptParseArgvString(char * s, int * argcPtr, char *** argvPtr);
124 const char * poptStrerror(const int error);
125 void poptSetExecPath(poptContext con, const char * path, int allowAbsolute);
126 void poptPrintHelp(poptContext con, FILE * f, int flags);
127 void poptPrintUsage(poptContext con, FILE * f, int flags);
128 void poptSetOtherOptionHelp(poptContext con, const char * text);
129 const char * poptGetInvocationName(poptContext con);