]> err.no Git - pkg-config/blob - popt.h
Print out \r\n on windows, not just \n
[pkg-config] / popt.h
1 /*
2 Copyright (c) 1998  Red Hat Software
3  
4 Permission is hereby granted, free of charge, to any person obtaining a copy
5 of this software and associated documentation files (the "Software"), to deal
6 in the Software without restriction, including without limitation the rights
7 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 copies of the Software, and to permit persons to whom the Software is
9 furnished to do so, subject to the following conditions:
10  
11 The above copyright notice and this permission notice shall be included in
12 all copies or substantial portions of the Software.
13  
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
17 X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
18 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20  
21 Except as contained in this notice, the name of the X Consortium shall not be
22 used in advertising or otherwise to promote the sale, use or other dealings
23 in this Software without prior written authorization from the X Consortium.
24 */
25
26 #ifndef H_POPT
27 #define H_POPT
28
29 #include <stdio.h>                      /* for FILE * */
30
31 #define POPT_OPTION_DEPTH       10
32
33 #define POPT_ARG_NONE           0
34 #define POPT_ARG_STRING         1
35 #define POPT_ARG_INT            2
36 #define POPT_ARG_LONG           3
37 #define POPT_ARG_INCLUDE_TABLE  4       /* arg points to table */
38 #define POPT_ARG_CALLBACK       5       /* table-wide callback... must be
39                                            set first in table; arg points 
40                                            to callback, descrip points to 
41                                            callback data to pass */
42 #define POPT_ARG_MASK           0x0000FFFF
43 #define POPT_ARGFLAG_ONEDASH    0x80000000  /* allow -longoption */
44 #define POPT_ARGFLAG_DOC_HIDDEN 0x40000000  /* don't show in help/usage */
45 #define POPT_CBFLAG_PRE         0x80000000  /* call the callback before parse */
46 #define POPT_CBFLAG_POST        0x40000000  /* call the callback after parse */
47 #define POPT_CBFLAG_INC_DATA    0x20000000  /* use data from the include line,
48                                                not the subtable */
49
50 #define POPT_ERROR_NOARG        -10
51 #define POPT_ERROR_BADOPT       -11
52 #define POPT_ERROR_OPTSTOODEEP  -13
53 #define POPT_ERROR_BADQUOTE     -15     /* only from poptParseArgString() */
54 #define POPT_ERROR_ERRNO        -16     /* only from poptParseArgString() */
55 #define POPT_ERROR_BADNUMBER    -17
56 #define POPT_ERROR_OVERFLOW     -18
57
58 /* poptBadOption() flags */
59 #define POPT_BADOPTION_NOALIAS  (1 << 0)  /* don't go into an alias */
60
61 /* poptGetContext() flags */
62 #define POPT_CONTEXT_NO_EXEC    (1 << 0)  /* ignore exec expansions */
63 #define POPT_CONTEXT_KEEP_FIRST (1 << 1)  /* pay attention to argv[0] */
64 #define POPT_CONTEXT_POSIXMEHARDER (1 << 2) /* options can't follow args */
65
66 struct poptOption {
67     const char * longName;      /* may be NULL */
68     char shortName;             /* may be '\0' */
69     int argInfo;
70     void * arg;                 /* depends on argInfo */
71     int val;                    /* 0 means don't return, just update flag */
72     char * descrip;             /* description for autohelp -- may be NULL */
73     char * argDescrip;          /* argument description for autohelp */
74 };
75
76 struct poptAlias {
77     char * longName;            /* may be NULL */
78     char shortName;             /* may be '\0' */
79     int argc;
80     char ** argv;               /* must be free()able */
81 };
82
83 extern struct poptOption poptHelpOptions[];
84 #define POPT_AUTOHELP { NULL, '\0', POPT_ARG_INCLUDE_TABLE, poptHelpOptions, \
85                         0, "Help options", NULL },
86
87 typedef struct poptContext_s * poptContext;
88 #ifndef __cplusplus
89 typedef struct poptOption * poptOption;
90 #endif
91
92 enum poptCallbackReason { POPT_CALLBACK_REASON_PRE, 
93                           POPT_CALLBACK_REASON_POST,
94                           POPT_CALLBACK_REASON_OPTION };
95 typedef void (*poptCallbackType)(poptContext con, 
96                                  enum poptCallbackReason reason,
97                                  const struct poptOption * opt,
98                                  const char * arg, void * data);
99
100 poptContext poptGetContext(char * name, int argc, char ** argv, 
101                            const struct poptOption * options, int flags);
102 void poptResetContext(poptContext con);
103
104 /* returns 'val' element, -1 on last item, POPT_ERROR_* on error */
105 int poptGetNextOpt(poptContext con);
106 /* returns NULL if no argument is available */
107 char * poptGetOptArg(poptContext con);
108 /* returns NULL if no more options are available */
109 char * poptGetArg(poptContext con);
110 char * poptPeekArg(poptContext con);
111 char ** poptGetArgs(poptContext con);
112 /* returns the option which caused the most recent error */
113 char * poptBadOption(poptContext con, int flags);
114 void poptFreeContext(poptContext con);
115 int poptStuffArgs(poptContext con, char ** argv);
116 int poptAddAlias(poptContext con, struct poptAlias alias, int flags);
117 int poptReadConfigFile(poptContext con, char * fn);
118 /* like above, but reads /etc/popt and $HOME/.popt along with environment 
119    vars */
120 int poptReadDefaultConfig(poptContext con, int useEnv);
121 /* argv should be freed -- this allows ', ", and \ quoting, but ' is treated
122    the same as " and both may include \ quotes */
123 int poptParseArgvString(char * s, int * argcPtr, char *** argvPtr);
124 const char * poptStrerror(const int error);
125 void poptSetExecPath(poptContext con, const char * path, int allowAbsolute);
126 void poptPrintHelp(poptContext con, FILE * f, int flags);
127 void poptPrintUsage(poptContext con, FILE * f, int flags);
128 void poptSetOtherOptionHelp(poptContext con, const char * text);
129 const char * poptGetInvocationName(poptContext con);
130
131 #endif