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 */ |
---|
4 | |
---|
5 | #ifndef H_POPT |
---|
6 | #define H_POPT |
---|
7 | |
---|
8 | #ifdef __cplusplus |
---|
9 | extern "C" { |
---|
10 | #endif |
---|
11 | |
---|
12 | #include <stdio.h> /* for FILE * */ |
---|
13 | |
---|
14 | #define POPT_OPTION_DEPTH 10 |
---|
15 | |
---|
16 | #define POPT_ARG_NONE 0 |
---|
17 | #define POPT_ARG_STRING 1 |
---|
18 | #define POPT_ARG_INT 2 |
---|
19 | #define POPT_ARG_LONG 3 |
---|
20 | #define POPT_ARG_INCLUDE_TABLE 4 /* arg points to table */ |
---|
21 | #define POPT_ARG_CALLBACK 5 /* table-wide callback... must be |
---|
22 | set first in table; arg points |
---|
23 | to callback, descrip points to |
---|
24 | callback data to pass */ |
---|
25 | #define POPT_ARG_INTL_DOMAIN 6 /* set the translation domain |
---|
26 | for this table and any |
---|
27 | included tables; arg points |
---|
28 | to the domain string */ |
---|
29 | #define POPT_ARG_VAL 7 /* arg should take value val */ |
---|
30 | #define POPT_ARG_FLOAT 8 /* arg should be converted to float */ |
---|
31 | #define POPT_ARG_DOUBLE 9 /* arg should be converted to double */ |
---|
32 | |
---|
33 | #define POPT_ARG_MASK 0x0000FFFF |
---|
34 | #define POPT_ARGFLAG_ONEDASH 0x80000000 /* allow -longoption */ |
---|
35 | #define POPT_ARGFLAG_DOC_HIDDEN 0x40000000 /* don't show in help/usage */ |
---|
36 | #define POPT_ARGFLAG_STRIP 0x20000000 /* strip this arg from argv (only applies to long args) */ |
---|
37 | |
---|
38 | #define POPT_ARGFLAG_OR 0x08000000 /* arg will be or'ed */ |
---|
39 | #define POPT_ARGFLAG_NOR 0x09000000 /* arg will be nor'ed */ |
---|
40 | #define POPT_ARGFLAG_AND 0x04000000 /* arg will be and'ed */ |
---|
41 | #define POPT_ARGFLAG_NAND 0x05000000 /* arg will be nand'ed */ |
---|
42 | #define POPT_ARGFLAG_XOR 0x02000000 /* arg will be xor'ed */ |
---|
43 | #define POPT_ARGFLAG_NOT 0x01000000 /* arg will be negated */ |
---|
44 | #define POPT_ARGFLAG_LOGICALOPS \ |
---|
45 | (POPT_ARGFLAG_OR|POPT_ARGFLAG_AND|POPT_ARGFLAG_XOR) |
---|
46 | |
---|
47 | #define POPT_CBFLAG_PRE 0x80000000 /* call the callback before parse */ |
---|
48 | #define POPT_CBFLAG_POST 0x40000000 /* call the callback after parse */ |
---|
49 | #define POPT_CBFLAG_INC_DATA 0x20000000 /* use data from the include line, |
---|
50 | not the subtable */ |
---|
51 | #define POPT_CBFLAG_SKIPOPTION 0x10000000 /* don't callback with option */ |
---|
52 | #define POPT_CBFLAG_CONTINUE 0x08000000 /* continue callbacks with option */ |
---|
53 | |
---|
54 | #define POPT_ERROR_NOARG -10 |
---|
55 | #define POPT_ERROR_BADOPT -11 |
---|
56 | #define POPT_ERROR_OPTSTOODEEP -13 |
---|
57 | #define POPT_ERROR_BADQUOTE -15 /* only from poptParseArgString() */ |
---|
58 | #define POPT_ERROR_ERRNO -16 /* only from poptParseArgString() */ |
---|
59 | #define POPT_ERROR_BADNUMBER -17 |
---|
60 | #define POPT_ERROR_OVERFLOW -18 |
---|
61 | #define POPT_ERROR_BADOPERATION -19 |
---|
62 | |
---|
63 | /* poptBadOption() flags */ |
---|
64 | #define POPT_BADOPTION_NOALIAS (1 << 0) /* don't go into an alias */ |
---|
65 | |
---|
66 | /* poptGetContext() flags */ |
---|
67 | #define POPT_CONTEXT_NO_EXEC (1 << 0) /* ignore exec expansions */ |
---|
68 | #define POPT_CONTEXT_KEEP_FIRST (1 << 1) /* pay attention to argv[0] */ |
---|
69 | #define POPT_CONTEXT_POSIXMEHARDER (1 << 2) /* options can't follow args */ |
---|
70 | |
---|
71 | struct poptOption { |
---|
72 | /*@observer@*/ /*@null@*/ const char * longName; /* may be NULL */ |
---|
73 | char shortName; /* may be '\0' */ |
---|
74 | int argInfo; |
---|
75 | /*@shared@*/ /*@null@*/ void * arg; /* depends on argInfo */ |
---|
76 | int val; /* 0 means don't return, just update flag */ |
---|
77 | /*@shared@*/ /*@null@*/ const char * descrip; /* description for autohelp -- may be NULL */ |
---|
78 | /*@shared@*/ /*@null@*/ const char * argDescrip; /* argument description for autohelp */ |
---|
79 | }; |
---|
80 | |
---|
81 | struct poptAlias { |
---|
82 | /*@owned@*/ /*@null@*/ const char * longName; /* may be NULL */ |
---|
83 | char shortName; /* may be '\0' */ |
---|
84 | int argc; |
---|
85 | /*@owned@*/ const char ** argv; /* must be free()able */ |
---|
86 | }; |
---|
87 | |
---|
88 | extern struct poptOption poptHelpOptions[]; |
---|
89 | #define POPT_AUTOHELP { NULL, '\0', POPT_ARG_INCLUDE_TABLE, poptHelpOptions, \ |
---|
90 | 0, "Help options", NULL }, |
---|
91 | |
---|
92 | typedef struct poptContext_s * poptContext; |
---|
93 | #ifndef __cplusplus |
---|
94 | typedef struct poptOption * poptOption; |
---|
95 | #endif |
---|
96 | |
---|
97 | enum poptCallbackReason { POPT_CALLBACK_REASON_PRE, |
---|
98 | POPT_CALLBACK_REASON_POST, |
---|
99 | POPT_CALLBACK_REASON_OPTION }; |
---|
100 | typedef void (*poptCallbackType)(poptContext con, |
---|
101 | enum poptCallbackReason reason, |
---|
102 | const struct poptOption * opt, |
---|
103 | const char * arg, const void * data); |
---|
104 | |
---|
105 | /*@only@*/ poptContext poptGetContext(/*@keep@*/ const char * name, |
---|
106 | int argc, /*@keep@*/ const char ** argv, |
---|
107 | /*@keep@*/ const struct poptOption * options, int flags); |
---|
108 | void poptResetContext(poptContext con); |
---|
109 | |
---|
110 | /* returns 'val' element, -1 on last item, POPT_ERROR_* on error */ |
---|
111 | int poptGetNextOpt(poptContext con); |
---|
112 | /* returns NULL if no argument is available */ |
---|
113 | /*@observer@*/ /*@null@*/ const char * poptGetOptArg(poptContext con); |
---|
114 | /* returns NULL if no more options are available */ |
---|
115 | /*@observer@*/ /*@null@*/ const char * poptGetArg(poptContext con); |
---|
116 | /*@observer@*/ /*@null@*/ const char * poptPeekArg(poptContext con); |
---|
117 | /*@observer@*/ /*@null@*/ const char ** poptGetArgs(poptContext con); |
---|
118 | /* returns the option which caused the most recent error */ |
---|
119 | /*@observer@*/ const char * poptBadOption(poptContext con, int flags); |
---|
120 | void poptFreeContext( /*@only@*/ poptContext con); |
---|
121 | int poptStuffArgs(poptContext con, /*@keep@*/ const char ** argv); |
---|
122 | int poptAddAlias(poptContext con, struct poptAlias alias, int flags); |
---|
123 | int poptReadConfigFile(poptContext con, const char * fn); |
---|
124 | /* like above, but reads /etc/popt and $HOME/.popt along with environment |
---|
125 | vars */ |
---|
126 | int poptReadDefaultConfig(poptContext con, int useEnv); |
---|
127 | /* argv should be freed -- this allows ', ", and \ quoting, but ' is treated |
---|
128 | the same as " and both may include \ quotes */ |
---|
129 | int poptDupArgv(int argc, const char **argv, |
---|
130 | /*@out@*/ int * argcPtr, /*@out@*/ const char *** argvPtr); |
---|
131 | int poptParseArgvString(const char * s, |
---|
132 | /*@out@*/ int * argcPtr, /*@out@*/ const char *** argvPtr); |
---|
133 | /*@observer@*/ const char *const poptStrerror(const int error); |
---|
134 | void poptSetExecPath(poptContext con, const char * path, int allowAbsolute); |
---|
135 | void poptPrintHelp(poptContext con, FILE * f, int flags); |
---|
136 | void poptPrintUsage(poptContext con, FILE * f, int flags); |
---|
137 | void poptSetOtherOptionHelp(poptContext con, const char * text); |
---|
138 | /*@observer@*/ const char * poptGetInvocationName(poptContext con); |
---|
139 | /* shuffles argv pointers to remove stripped args, returns new argc */ |
---|
140 | int poptStrippedArgv(poptContext con, int argc, char **argv); |
---|
141 | |
---|
142 | #ifdef __cplusplus |
---|
143 | } |
---|
144 | #endif |
---|
145 | |
---|
146 | #endif |
---|