• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /** \ingroup popt
2  * \file popt/poptint.h
3  */
4 
5 /* (C) 1998-2000 Red Hat, Inc. -- Licensing details are in the COPYING
6    file accompanying popt source distributions, available from
7    ftp://ftp.rpm.org/pub/rpm/dist. */
8 
9 #ifndef H_POPTINT
10 #define H_POPTINT
11 
12 #include <stdint.h>
13 
14 /**
15  * Wrapper to free(3), hides const compilation noise, permit NULL, return NULL.
16  * @param p		memory to free
17  * @retval		NULL always
18  */
19 /*@unused@*/ static inline /*@null@*/ void *
_free(const void * p)20 _free(/*@only@*/ /*@null@*/ const void * p)
21 	/*@modifies p @*/
22 {
23     if (p != NULL)	free((void *)p);
24     return NULL;
25 }
26 
27 /* Bit mask macros. */
28 /*@-exporttype -redef @*/
29 typedef	unsigned int __pbm_bits;
30 /*@=exporttype =redef @*/
31 #define	__PBM_NBITS		(8 * sizeof (__pbm_bits))
32 #define	__PBM_IX(d)		((d) / __PBM_NBITS)
33 #define __PBM_MASK(d)		((__pbm_bits) 1 << (((unsigned)(d)) % __PBM_NBITS))
34 /*@-exporttype -redef @*/
35 typedef struct {
36     __pbm_bits bits[1];
37 } pbm_set;
38 /*@=exporttype =redef @*/
39 #define	__PBM_BITS(set)	((set)->bits)
40 
41 #define	PBM_ALLOC(d)	calloc(__PBM_IX (d) + 1, sizeof(__pbm_bits))
42 #define	PBM_FREE(s)	_free(s);
43 #define PBM_SET(d, s)   (__PBM_BITS (s)[__PBM_IX (d)] |= __PBM_MASK (d))
44 #define PBM_CLR(d, s)   (__PBM_BITS (s)[__PBM_IX (d)] &= ~__PBM_MASK (d))
45 #define PBM_ISSET(d, s) ((__PBM_BITS (s)[__PBM_IX (d)] & __PBM_MASK (d)) != 0)
46 
47 extern void poptJlu32lpair(/*@null@*/ const void *key, size_t size,
48                 uint32_t *pc, uint32_t *pb)
49         /*@modifies *pc, *pb@*/;
50 
51 /** \ingroup popt
52  * Typedef's for string and array of strings.
53  */
54 /*@-exporttype@*/
55 typedef const char * poptString;
56 typedef poptString * poptArgv;
57 /*@=exporttype@*/
58 
59 /** \ingroup popt
60  * A union to simplify opt->arg access without casting.
61  */
62 /*@-exporttype -fielduse@*/
63 typedef union poptArg_u {
64 /*@shared@*/
65     void * ptr;
66     int * intp;
67     short * shortp;
68     long * longp;
69     long long * longlongp;
70     float * floatp;
71     double * doublep;
72     const char ** argv;
73     poptCallbackType cb;
74 /*@shared@*/
75     poptOption opt;
76 } poptArg;
77 /*@=exporttype =fielduse@*/
78 
79 /*@-exportvar@*/
80 /*@unchecked@*/
81 extern unsigned int _poptArgMask;
82 /*@unchecked@*/
83 extern unsigned int _poptGroupMask;
84 /*@=exportvar@*/
85 
86 #define	poptArgType(_opt)	((_opt)->argInfo & _poptArgMask)
87 #define	poptGroup(_opt)		((_opt)->argInfo & _poptGroupMask)
88 
89 #define	F_ISSET(_opt, _FLAG)	((_opt)->argInfo & POPT_ARGFLAG_##_FLAG)
90 #define	LF_ISSET(_FLAG)		(argInfo & POPT_ARGFLAG_##_FLAG)
91 #define	CBF_ISSET(_opt, _FLAG)	((_opt)->argInfo & POPT_CBFLAG_##_FLAG)
92 
93 /* XXX sick hack to preserve pretense of a popt-1.x ABI. */
94 #define	poptSubstituteHelpI18N(opt) \
95   { /*@-observertrans@*/ \
96     if ((opt) == poptHelpOptions) (opt) = poptHelpOptionsI18N; \
97     /*@=observertrans@*/ }
98 
99 struct optionStackEntry {
100     int argc;
101 /*@only@*/ /*@null@*/
102     poptArgv argv;
103 /*@only@*/ /*@null@*/
104     pbm_set * argb;
105     int next;
106 /*@only@*/ /*@null@*/
107     char * nextArg;
108 /*@observer@*/ /*@null@*/
109     const char * nextCharArg;
110 /*@dependent@*/ /*@null@*/
111     poptItem currAlias;
112     int stuffed;
113 };
114 
115 struct poptContext_s {
116     struct optionStackEntry optionStack[POPT_OPTION_DEPTH];
117 /*@dependent@*/
118     struct optionStackEntry * os;
119 /*@owned@*/ /*@null@*/
120     poptArgv leftovers;
121     int numLeftovers;
122     int nextLeftover;
123 /*@keep@*/
124     const struct poptOption * options;
125     int restLeftover;
126 /*@only@*/ /*@null@*/
127     const char * appName;
128 /*@only@*/ /*@null@*/
129     poptItem aliases;
130     int numAliases;
131     unsigned int flags;
132 /*@owned@*/ /*@null@*/
133     poptItem execs;
134     int numExecs;
135 /*@only@*/ /*@null@*/
136     poptArgv finalArgv;
137     int finalArgvCount;
138     int finalArgvAlloced;
139 /*@null@*/
140     int (*maincall) (int argc, const char **argv);
141 /*@dependent@*/ /*@null@*/
142     poptItem doExec;
143 /*@only@*/ /*@null@*/
144     const char * execPath;
145     int execAbsolute;
146 /*@only@*/ /*@relnull@*/
147     const char * otherHelp;
148 /*@null@*/
149     pbm_set * arg_strip;
150 };
151 
152 #if defined(POPT_fprintf)
153 #define	POPT_dgettext	dgettext
154 #else
155 #ifdef HAVE_ICONV
156 #include <iconv.h>
157 #if defined(__LCLINT__)
158 /*@-declundef -incondefs @*/
159 extern /*@only@*/ iconv_t iconv_open(const char *__tocode, const char *__fromcode)
160 	/*@*/;
161 
162 extern size_t iconv(iconv_t __cd, /*@null@*/ char ** __inbuf,
163 		    /*@null@*/ /*@out@*/ size_t * __inbytesleft,
164 		    /*@null@*/ /*@out@*/ char ** __outbuf,
165 		    /*@null@*/ /*@out@*/ size_t * __outbytesleft)
166 	/*@modifies __cd,
167 		*__inbuf, *__inbytesleft, *__outbuf, *__outbytesleft @*/;
168 
169 extern int iconv_close(/*@only@*/ iconv_t __cd)
170 	/*@modifies __cd @*/;
171 /*@=declundef =incondefs @*/
172 #endif
173 #endif
174 
175 #ifdef HAVE_LANGINFO_H
176 #include <langinfo.h>
177 #if defined(__LCLINT__)
178 /*@-declundef -incondefs @*/
179 extern char *nl_langinfo (nl_item __item)
180 	/*@*/;
181 /*@=declundef =incondefs @*/
182 #endif
183 #endif
184 
185 #if defined(HAVE_DCGETTEXT) && !defined(__LCLINT__)
186 char *POPT_dgettext(const char * dom, const char * str)
187 	/*@*/;
188 #endif
189 
190 int   POPT_fprintf (FILE* stream, const char *format, ...)
191 	/*@globals fileSystem @*/
192 	/*@modifies stream, fileSystem @*/;
193 #endif	/* !defined(POPT_fprintf) */
194 
195 const char *POPT_prev_char (/*@returned@*/ const char *str)
196 	/*@*/;
197 
198 const char *POPT_next_char (/*@returned@*/ const char *str)
199 	/*@*/;
200 
201 #endif
202 
203 #if defined(ENABLE_NLS) && defined(HAVE_LIBINTL_H)
204 #include <libintl.h>
205 #endif
206 
207 #if defined(ENABLE_NLS) && defined(HAVE_GETTEXT) && !defined(__LCLINT__)
208 #define _(foo) gettext(foo)
209 #else
210 #define _(foo) foo
211 #endif
212 
213 #if defined(ENABLE_NLS) && defined(HAVE_DCGETTEXT) && !defined(__LCLINT__)
214 #define D_(dom, str) POPT_dgettext(dom, str)
215 #define POPT_(foo) D_("popt", foo)
216 #else
217 #define D_(dom, str) str
218 #define POPT_(foo) foo
219 #endif
220 
221 #define N_(foo) foo
222 
223