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
9extern "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_MASK		0x0000FFFF
31#define POPT_ARGFLAG_ONEDASH	0x80000000  /* allow -longoption */
32#define POPT_ARGFLAG_DOC_HIDDEN 0x40000000  /* don't show in help/usage */
33#define POPT_ARGFLAG_STRIP	0x20000000  /* strip this arg from argv (only applies to long args) */
34#define POPT_CBFLAG_PRE		0x80000000  /* call the callback before parse */
35#define POPT_CBFLAG_POST	0x40000000  /* call the callback after parse */
36#define POPT_CBFLAG_INC_DATA	0x20000000  /* use data from the include line,
37					       not the subtable */
38
39#define POPT_ERROR_NOARG	-10
40#define POPT_ERROR_BADOPT	-11
41#define POPT_ERROR_OPTSTOODEEP	-13
42#define POPT_ERROR_BADQUOTE	-15	/* only from poptParseArgString() */
43#define POPT_ERROR_ERRNO	-16	/* only from poptParseArgString() */
44#define POPT_ERROR_BADNUMBER	-17
45#define POPT_ERROR_OVERFLOW	-18
46
47/* poptBadOption() flags */
48#define POPT_BADOPTION_NOALIAS  (1 << 0)  /* don't go into an alias */
49
50/* poptGetContext() flags */
51#define POPT_CONTEXT_NO_EXEC	(1 << 0)  /* ignore exec expansions */
52#define POPT_CONTEXT_KEEP_FIRST	(1 << 1)  /* pay attention to argv[0] */
53#define POPT_CONTEXT_POSIXMEHARDER (1 << 2) /* options can't follow args */
54
55struct poptOption {
56    /*@observer@*/ /*@null@*/ const char * longName;	/* may be NULL */
57    char shortName;		/* may be '\0' */
58    int argInfo;
59    /*@shared@*/ /*@null@*/ void * arg;		/* depends on argInfo */
60    int val;			/* 0 means don't return, just update flag */
61    /*@shared@*/ /*@null@*/ const char * descrip;	/* description for autohelp -- may be NULL */
62    /*@shared@*/ /*@null@*/ const char * argDescrip;	/* argument description for autohelp */
63};
64
65struct poptAlias {
66    /*@owned@*/ /*@null@*/ const char * longName;	/* may be NULL */
67    char shortName;		/* may be '\0' */
68    int argc;
69    /*@owned@*/ const char ** argv;		/* must be free()able */
70};
71
72extern struct poptOption poptHelpOptions[];
73#define POPT_AUTOHELP { NULL, '\0', POPT_ARG_INCLUDE_TABLE, poptHelpOptions, \
74			0, "Help options", NULL },
75
76typedef struct poptContext_s * poptContext;
77#ifndef __cplusplus
78typedef struct poptOption * poptOption;
79#endif
80
81enum poptCallbackReason { POPT_CALLBACK_REASON_PRE,
82			  POPT_CALLBACK_REASON_POST,
83			  POPT_CALLBACK_REASON_OPTION };
84typedef void (*poptCallbackType)(poptContext con,
85				 enum poptCallbackReason reason,
86			         const struct poptOption * opt,
87				 const char * arg, const void * data);
88
89/*@only@*/ poptContext poptGetContext(/*@keep@*/ const char * name,
90		int argc, /*@keep@*/ const char ** argv,
91		/*@keep@*/ const struct poptOption * options, int flags);
92void poptResetContext(poptContext con);
93
94/* returns 'val' element, -1 on last item, POPT_ERROR_* on error */
95int poptGetNextOpt(poptContext con);
96/* returns NULL if no argument is available */
97/*@observer@*/ /*@null@*/ const char * poptGetOptArg(poptContext con);
98/* returns NULL if no more options are available */
99/*@observer@*/ /*@null@*/ const char * poptGetArg(poptContext con);
100/*@observer@*/ /*@null@*/ const char * poptPeekArg(poptContext con);
101/*@observer@*/ /*@null@*/ const char ** poptGetArgs(poptContext con);
102/* returns the option which caused the most recent error */
103/*@observer@*/ const char * poptBadOption(poptContext con, int flags);
104void poptFreeContext( /*@only@*/ poptContext con);
105int poptStuffArgs(poptContext con, /*@keep@*/ const char ** argv);
106int poptAddAlias(poptContext con, struct poptAlias alias, int flags);
107int poptReadConfigFile(poptContext con, const char * fn);
108/* like above, but reads /etc/popt and $HOME/.popt along with environment
109   vars */
110int poptReadDefaultConfig(poptContext con, int useEnv);
111/* argv should be freed -- this allows ', ", and \ quoting, but ' is treated
112   the same as " and both may include \ quotes */
113int poptDupArgv(int argc, const char **argv,
114		/*@out@*/ int * argcPtr, /*@out@*/ const char *** argvPtr);
115int poptParseArgvString(const char * s,
116		/*@out@*/ int * argcPtr, /*@out@*/ const char *** argvPtr);
117/*@observer@*/ const char *poptStrerror(const int error);
118void poptSetExecPath(poptContext con, const char * path, int allowAbsolute);
119void poptPrintHelp(poptContext con, FILE * f, int flags);
120void poptPrintUsage(poptContext con, FILE * f, int flags);
121void poptSetOtherOptionHelp(poptContext con, const char * text);
122/*@observer@*/ const char * poptGetInvocationName(poptContext con);
123/* shuffles argv pointers to remove stripped args, returns new argc */
124int poptStrippedArgv(poptContext con, int argc, char **argv);
125
126#ifdef  __cplusplus
127}
128#endif
129
130#endif
131