Check in built-in copy of libpopt in preparation for switching
[rsync/rsync.git] / popt-1.2 / popt.h
CommitLineData
62402cb1
MP
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#include <stdio.h> /* for FILE * */
9
10#define POPT_OPTION_DEPTH 10
11
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,
27 not the subtable */
28
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
36
37/* poptBadOption() flags */
38#define POPT_BADOPTION_NOALIAS (1 << 0) /* don't go into an alias */
39
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 */
44
45struct poptOption {
46 const char * longName; /* may be NULL */
47 char shortName; /* may be '\0' */
48 int argInfo;
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 */
53};
54
55struct poptAlias {
56 char * longName; /* may be NULL */
57 char shortName; /* may be '\0' */
58 int argc;
59 char ** argv; /* must be free()able */
60};
61
62extern struct poptOption poptHelpOptions[];
63#define POPT_AUTOHELP { NULL, '\0', POPT_ARG_INCLUDE_TABLE, poptHelpOptions, \
64 0, "Help options", NULL },
65
66typedef struct poptContext_s * poptContext;
67#ifndef __cplusplus
68typedef struct poptOption * poptOption;
69#endif
70
71enum poptCallbackReason { POPT_CALLBACK_REASON_PRE,
72 POPT_CALLBACK_REASON_POST,
73 POPT_CALLBACK_REASON_OPTION };
74typedef void (*poptCallbackType)(poptContext con,
75 enum poptCallbackReason reason,
76 const struct poptOption * opt,
77 const char * arg, void * data);
78
79poptContext poptGetContext(char * name, int argc, char ** argv,
80 const struct poptOption * options, int flags);
81void poptResetContext(poptContext con);
82
83/* returns 'val' element, -1 on last item, POPT_ERROR_* on error */
84int poptGetNextOpt(poptContext con);
85/* returns NULL if no argument is available */
86char * poptGetOptArg(poptContext con);
87/* returns NULL if no more options are available */
88char * poptGetArg(poptContext con);
89char * poptPeekArg(poptContext con);
90char ** poptGetArgs(poptContext con);
91/* returns the option which caused the most recent error */
92char * poptBadOption(poptContext con, int flags);
93void poptFreeContext(poptContext con);
94int poptStuffArgs(poptContext con, char ** argv);
95int poptAddAlias(poptContext con, struct poptAlias alias, int flags);
96int poptReadConfigFile(poptContext con, char * fn);
97/* like above, but reads /etc/popt and $HOME/.popt along with environment
98 vars */
99int 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 */
102int poptParseArgvString(char * s, int * argcPtr, char *** argvPtr);
103const char * poptStrerror(const int error);
104void poptSetExecPath(poptContext con, const char * path, int allowAbsolute);
105void poptPrintHelp(poptContext con, FILE * f, int flags);
106void poptPrintUsage(poptContext con, FILE * f, int flags);
107void poptSetOtherOptionHelp(poptContext con, const char * text);
108const char * poptGetInvocationName(poptContext con);
109
110#endif