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 static inline void *
_free(const void * p)20 _free(const void * p)
21 {
22 if (p != NULL) free((void *)p);
23 return NULL;
24 }
25
26 /* Bit mask macros. */
27 typedef unsigned int __pbm_bits;
28 #define __PBM_NBITS (8 * sizeof (__pbm_bits))
29 #define __PBM_IX(d) ((d) / __PBM_NBITS)
30 #define __PBM_MASK(d) ((__pbm_bits) 1 << (((unsigned)(d)) % __PBM_NBITS))
31 typedef struct {
32 __pbm_bits bits[1];
33 } pbm_set;
34 #define __PBM_BITS(set) ((set)->bits)
35
36 #define PBM_ALLOC(d) calloc(__PBM_IX (d) + 1, sizeof(__pbm_bits))
37 #define PBM_FREE(s) _free(s);
38 #define PBM_SET(d, s) (__PBM_BITS (s)[__PBM_IX (d)] |= __PBM_MASK (d))
39 #define PBM_CLR(d, s) (__PBM_BITS (s)[__PBM_IX (d)] &= ~__PBM_MASK (d))
40 #define PBM_ISSET(d, s) ((__PBM_BITS (s)[__PBM_IX (d)] & __PBM_MASK (d)) != 0)
41
42 extern void poptJlu32lpair(const void *key, size_t size,
43 uint32_t *pc, uint32_t *pb);
44
45 /** \ingroup popt
46 * Typedef's for string and array of strings.
47 */
48 typedef const char * poptString;
49 typedef poptString * poptArgv;
50
51 /** \ingroup popt
52 * A union to simplify opt->arg access without casting.
53 */
54 typedef union poptArg_u {
55 void * ptr;
56 int * intp;
57 short * shortp;
58 long * longp;
59 long long * longlongp;
60 float * floatp;
61 double * doublep;
62 const char ** argv;
63 poptCallbackType cb;
64 poptOption opt;
65 } poptArg;
66
67 extern unsigned int _poptArgMask;
68 extern unsigned int _poptGroupMask;
69
70 #define poptArgType(_opt) ((_opt)->argInfo & _poptArgMask)
71 #define poptGroup(_opt) ((_opt)->argInfo & _poptGroupMask)
72
73 #define F_ISSET(_opt, _FLAG) ((_opt)->argInfo & POPT_ARGFLAG_##_FLAG)
74 #define LF_ISSET(_FLAG) (argInfo & POPT_ARGFLAG_##_FLAG)
75 #define CBF_ISSET(_opt, _FLAG) ((_opt)->argInfo & POPT_CBFLAG_##_FLAG)
76
77 /* XXX sick hack to preserve pretense of a popt-1.x ABI. */
78 #define poptSubstituteHelpI18N(opt) \
79 { if ((opt) == poptHelpOptions) (opt) = poptHelpOptionsI18N; }
80
81 struct optionStackEntry {
82 int argc;
83 poptArgv argv;
84 pbm_set * argb;
85 int next;
86 char * nextArg;
87 const char * nextCharArg;
88 poptItem currAlias;
89 int stuffed;
90 };
91
92 struct poptContext_s {
93 struct optionStackEntry optionStack[POPT_OPTION_DEPTH];
94 struct optionStackEntry * os;
95 poptArgv leftovers;
96 int numLeftovers;
97 int nextLeftover;
98 const struct poptOption * options;
99 int restLeftover;
100 const char * appName;
101 poptItem aliases;
102 int numAliases;
103 unsigned int flags;
104 poptItem execs;
105 int numExecs;
106 char * execFail;
107 poptArgv finalArgv;
108 int finalArgvCount;
109 int finalArgvAlloced;
110 int (*maincall) (int argc, const char **argv);
111 poptItem doExec;
112 const char * execPath;
113 int execAbsolute;
114 const char * otherHelp;
115 pbm_set * arg_strip;
116 };
117
118 #if defined(POPT_fprintf)
119 #define POPT_dgettext dgettext
120 #else
121 #ifdef HAVE_ICONV
122 #include <iconv.h>
123 #endif
124
125 #if defined(HAVE_DCGETTEXT)
126 char *POPT_dgettext(const char * dom, const char * str);
127 #endif
128
129 int POPT_fprintf (FILE* stream, const char *format, ...);
130 #endif /* !defined(POPT_fprintf) */
131
132 const char *POPT_prev_char (const char *str);
133 const char *POPT_next_char (const char *str);
134
135 #endif
136
137 #if defined(ENABLE_NLS) && defined(HAVE_LIBINTL_H)
138 #include <libintl.h>
139 #endif
140
141 #if defined(ENABLE_NLS) && defined(HAVE_GETTEXT)
142 #define _(foo) gettext(foo)
143 #else
144 #define _(foo) foo
145 #endif
146
147 #if defined(ENABLE_NLS) && defined(HAVE_DCGETTEXT)
148 #define D_(dom, str) POPT_dgettext(dom, str)
149 #define POPT_(foo) D_("popt", foo)
150 #else
151 #define D_(dom, str) str
152 #define POPT_(foo) foo
153 #endif
154
155 #define N_(foo) foo
156
157