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 */
6 * \brief Header: a module for parsing command line options
16 #include <stdio.h> /* for FILE * */
18 #define POPT_OPTION_DEPTH 10
20 #define POPT_ARG_NONE 0
21 #define POPT_ARG_STRING 1
22 #define POPT_ARG_INT 2
23 #define POPT_ARG_LONG 3
24 #define POPT_ARG_INCLUDE_TABLE 4 /* arg points to table */
25 #define POPT_ARG_CALLBACK 5 /* table-wide callback... must be
26 set first in table; arg points
27 to callback, descrip points to
28 callback data to pass */
29 #define POPT_ARG_INTL_DOMAIN 6 /* set the translation domain
30 for this table and any
31 included tables; arg points
32 to the domain string */
33 #define POPT_ARG_VAL 7 /* arg should take value val */
34 #define POPT_ARG_MASK 0x0000FFFF
35 #define POPT_ARGFLAG_ONEDASH 0x80000000 /* allow -longoption */
36 #define POPT_ARGFLAG_DOC_HIDDEN 0x40000000 /* don't show in help/usage */
37 #define POPT_CBFLAG_PRE 0x80000000 /* call the callback before parse */
38 #define POPT_CBFLAG_POST 0x40000000 /* call the callback after parse */
39 #define POPT_CBFLAG_INC_DATA 0x20000000 /* use data from the include line,
42 #define POPT_ERROR_NOARG -10
43 #define POPT_ERROR_BADOPT -11
44 #define POPT_ERROR_OPTSTOODEEP -13
45 #define POPT_ERROR_BADQUOTE -15 /* only from poptParseArgString() */
46 #define POPT_ERROR_ERRNO -16 /* only from poptParseArgString() */
47 #define POPT_ERROR_BADNUMBER -17
48 #define POPT_ERROR_OVERFLOW -18
50 /* poptBadOption() flags */
51 #define POPT_BADOPTION_NOALIAS (1 << 0) /* don't go into an alias */
53 /* poptGetContext() flags */
54 #define POPT_CONTEXT_NO_EXEC (1 << 0) /* ignore exec expansions */
55 #define POPT_CONTEXT_KEEP_FIRST (1 << 1) /* pay attention to argv[0] */
56 #define POPT_CONTEXT_POSIXMEHARDER (1 << 2) /* options can't follow args */
60 enum poptCallbackReason
{ POPT_CALLBACK_REASON_PRE
,
61 POPT_CALLBACK_REASON_POST
,
62 POPT_CALLBACK_REASON_OPTION
};
63 typedef struct poptContext_s
* poptContext
;
65 typedef void (*poptCallbackType
)(poptContext con
,
66 enum poptCallbackReason reason
,
67 const struct poptOption
* opt
,
68 const char * arg
, void * data
);
72 void (*f1
)(poptContext
, enum poptCallbackReason
, struct poptOption
*,
73 const char *, void *);
78 const char * longName
; /* may be NULL */
79 char shortName
; /* may be '\0' */
81 popt_arg_t arg
; /* depends on argInfo */
82 int val
; /* 0 means don't return, just update flag */
83 char * descrip
; /* description for autohelp -- may be NULL */
84 const char * argDescrip
; /* argument description for autohelp */
88 char * longName
; /* may be NULL */
89 char shortName
; /* may be '\0' */
91 char ** argv
; /* must be free()able */
95 typedef struct poptOption
* poptOption
;
99 poptContext
poptGetContext(const char * name
, int argc
, char ** argv
,
100 const struct poptOption
* options
, int flags
);
101 void poptResetContext(poptContext con
);
103 /* returns 'val' element, -1 on last item, POPT_ERROR_* on error */
104 int poptGetNextOpt(poptContext con
);
105 /* returns NULL if no argument is available */
106 char * poptGetOptArg(poptContext con
);
107 /* returns NULL if no more options are available */
108 char * poptGetArg(poptContext con
);
109 char * poptPeekArg(poptContext con
);
110 char ** poptGetArgs(poptContext con
);
111 /* returns the option which caused the most recent error */
112 char * poptBadOption(poptContext con
, int flags
);
113 void poptFreeContext(poptContext con
);
114 int poptStuffArgs(poptContext con
, char ** argv
);
115 int poptAddAlias(poptContext con
, struct poptAlias alias
, int flags
);
116 int poptReadConfigFile(poptContext con
, const char * fn
);
117 /* like above, but reads /etc/popt and $HOME/.popt along with environment
119 int poptReadDefaultConfig(poptContext con
, int useEnv
);
120 /* argv should be freed -- this allows ', ", and \ quoting, but ' is treated
121 the same as " and both may include \ quotes */
122 int poptParseArgvString(const char * s
, int * argcPtr
, char *** argvPtr
);
123 const char * poptStrerror(const int error
);
124 void poptSetExecPath(poptContext con
, const char * path
, int allowAbsolute
);
125 int poptPrintHelp(poptContext con
, FILE * f
, int flags
);
126 void poptPrintUsage(poptContext con
, FILE * f
, int flags
);
127 void poptSetOtherOptionHelp(poptContext con
, const char * text
);
128 const char * poptGetInvocationName(poptContext con
);