1 /* (C) 1998 Red Hat Software, Inc. -- Licensing details are in the COPYING
2 file accompanying popt source distributions, available from
3 ftp://ftp.redhat.com/pub/code/popt */
8 #include <stdio.h> /* for FILE * */
10 #define POPT_OPTION_DEPTH 10
12 #define POPT_ARG_NONE 0
13 #define POPT_ARG_STRING 1
14 #define POPT_ARG_INT 2
15 #define POPT_ARG_LONG 3
16 #define POPT_ARG_INCLUDE_TABLE 4 /* arg points to table */
17 #define POPT_ARG_CALLBACK 5 /* table-wide callback... must be
18 set first in table; arg points
19 to callback, descrip points to
20 callback data to pass */
21 #define POPT_ARG_MASK 0x0000FFFF
22 #define POPT_ARGFLAG_ONEDASH 0x80000000 /* allow -longoption */
23 #define POPT_ARGFLAG_DOC_HIDDEN 0x40000000 /* don't show in help/usage */
24 #define POPT_CBFLAG_PRE 0x80000000 /* call the callback before parse */
25 #define POPT_CBFLAG_POST 0x40000000 /* call the callback after parse */
26 #define POPT_CBFLAG_INC_DATA 0x20000000 /* use data from the include line,
29 #define POPT_ERROR_NOARG -10
30 #define POPT_ERROR_BADOPT -11
31 #define POPT_ERROR_OPTSTOODEEP -13
32 #define POPT_ERROR_BADQUOTE -15 /* only from poptParseArgString() */
33 #define POPT_ERROR_ERRNO -16 /* only from poptParseArgString() */
34 #define POPT_ERROR_BADNUMBER -17
35 #define POPT_ERROR_OVERFLOW -18
37 /* poptBadOption() flags */
38 #define POPT_BADOPTION_NOALIAS (1 << 0) /* don't go into an alias */
40 /* poptGetContext() flags */
41 #define POPT_CONTEXT_NO_EXEC (1 << 0) /* ignore exec expansions */
42 #define POPT_CONTEXT_KEEP_FIRST (1 << 1) /* pay attention to argv[0] */
43 #define POPT_CONTEXT_POSIXMEHARDER (1 << 2) /* options can't follow args */
46 const char * longName; /* may be NULL */
47 char shortName; /* may be '\0' */
49 void * arg; /* depends on argInfo */
50 int val; /* 0 means don't return, just update flag */
51 char * descrip; /* description for autohelp -- may be NULL */
52 char * argDescrip; /* argument description for autohelp */
56 char * longName; /* may be NULL */
57 char shortName; /* may be '\0' */
59 char ** argv; /* must be free()able */
62 extern struct poptOption poptHelpOptions[];
63 #define POPT_AUTOHELP { NULL, '\0', POPT_ARG_INCLUDE_TABLE, poptHelpOptions, \
64 0, "Help options", NULL },
66 typedef struct poptContext_s * poptContext;
68 typedef struct poptOption * poptOption;
71 enum poptCallbackReason { POPT_CALLBACK_REASON_PRE,
72 POPT_CALLBACK_REASON_POST,
73 POPT_CALLBACK_REASON_OPTION };
74 typedef void (*poptCallbackType)(poptContext con,
75 enum poptCallbackReason reason,
76 const struct poptOption * opt,
77 const char * arg, void * data);
79 poptContext poptGetContext(char * name, int argc, char ** argv,
80 const struct poptOption * options, int flags);
81 void poptResetContext(poptContext con);
83 /* returns 'val' element, -1 on last item, POPT_ERROR_* on error */
84 int poptGetNextOpt(poptContext con);
85 /* returns NULL if no argument is available */
86 char * poptGetOptArg(poptContext con);
87 /* returns NULL if no more options are available */
88 char * poptGetArg(poptContext con);
89 char * poptPeekArg(poptContext con);
90 char ** poptGetArgs(poptContext con);
91 /* returns the option which caused the most recent error */
92 char * poptBadOption(poptContext con, int flags);
93 void poptFreeContext(poptContext con);
94 int poptStuffArgs(poptContext con, char ** argv);
95 int poptAddAlias(poptContext con, struct poptAlias alias, int flags);
96 int poptReadConfigFile(poptContext con, char * fn);
97 /* like above, but reads /etc/popt and $HOME/.popt along with environment
99 int poptReadDefaultConfig(poptContext con, int useEnv);
100 /* argv should be freed -- this allows ', ", and \ quoting, but ' is treated
101 the same as " and both may include \ quotes */
102 int poptParseArgvString(char * s, int * argcPtr, char *** argvPtr);
103 const char * poptStrerror(const int error);
104 void poptSetExecPath(poptContext con, const char * path, int allowAbsolute);
105 void poptPrintHelp(poptContext con, FILE * f, int flags);
106 void poptPrintUsage(poptContext con, FILE * f, int flags);
107 void poptSetOtherOptionHelp(poptContext con, const char * text);
108 const char * poptGetInvocationName(poptContext con);