Commit | Line | Data |
---|---|---|
cc248aae WD |
1 | /** \ingroup popt |
2 | * \file popt/poptint.h | |
3 | */ | |
4 | ||
5 | /* (C) 1998-2000 Red Hat, Inc. -- Licensing details are in the COPYING | |
b348deae | 6 | file accompanying popt source distributions, available from |
cc248aae | 7 | ftp://ftp.rpm.org/pub/rpm/dist. */ |
b348deae MP |
8 | |
9 | #ifndef H_POPTINT | |
10 | #define H_POPTINT | |
11 | ||
cc248aae WD |
12 | /** |
13 | * Wrapper to free(3), hides const compilation noise, permit NULL, return NULL. | |
14 | * @param p memory to free | |
15 | * @retval NULL always | |
16 | */ | |
17 | /*@unused@*/ static inline /*@null@*/ void * | |
18 | _free(/*@only@*/ /*@null@*/ const void * p) | |
19 | /*@modifies p @*/ | |
20 | { | |
21 | if (p != NULL) free((void *)p); | |
22 | return NULL; | |
23 | } | |
24 | ||
a8facdc0 WD |
25 | static inline int |
26 | isSpace(const char *ptr) | |
27 | { | |
28 | return isspace(*(unsigned char *)ptr); | |
29 | } | |
30 | ||
b348deae | 31 | /* Bit mask macros. */ |
bc93ee84 | 32 | /*@-exporttype -redef @*/ |
b348deae | 33 | typedef unsigned int __pbm_bits; |
bc93ee84 | 34 | /*@=exporttype =redef @*/ |
b348deae MP |
35 | #define __PBM_NBITS (8 * sizeof (__pbm_bits)) |
36 | #define __PBM_IX(d) ((d) / __PBM_NBITS) | |
cc248aae | 37 | #define __PBM_MASK(d) ((__pbm_bits) 1 << (((unsigned)(d)) % __PBM_NBITS)) |
bc93ee84 | 38 | /*@-exporttype -redef @*/ |
b348deae MP |
39 | typedef struct { |
40 | __pbm_bits bits[1]; | |
41 | } pbm_set; | |
bc93ee84 | 42 | /*@=exporttype =redef @*/ |
b348deae MP |
43 | #define __PBM_BITS(set) ((set)->bits) |
44 | ||
45 | #define PBM_ALLOC(d) calloc(__PBM_IX (d) + 1, sizeof(__pbm_bits)) | |
cc248aae | 46 | #define PBM_FREE(s) _free(s); |
b348deae MP |
47 | #define PBM_SET(d, s) (__PBM_BITS (s)[__PBM_IX (d)] |= __PBM_MASK (d)) |
48 | #define PBM_CLR(d, s) (__PBM_BITS (s)[__PBM_IX (d)] &= ~__PBM_MASK (d)) | |
49 | #define PBM_ISSET(d, s) ((__PBM_BITS (s)[__PBM_IX (d)] & __PBM_MASK (d)) != 0) | |
50 | ||
51 | struct optionStackEntry { | |
52 | int argc; | |
bc93ee84 WD |
53 | /*@only@*/ /*@null@*/ |
54 | const char ** argv; | |
55 | /*@only@*/ /*@null@*/ | |
56 | pbm_set * argb; | |
b348deae | 57 | int next; |
bc93ee84 WD |
58 | /*@only@*/ /*@null@*/ |
59 | const char * nextArg; | |
60 | /*@observer@*/ /*@null@*/ | |
61 | const char * nextCharArg; | |
62 | /*@dependent@*/ /*@null@*/ | |
63 | poptItem currAlias; | |
b348deae MP |
64 | int stuffed; |
65 | }; | |
66 | ||
b348deae MP |
67 | struct poptContext_s { |
68 | struct optionStackEntry optionStack[POPT_OPTION_DEPTH]; | |
bc93ee84 WD |
69 | /*@dependent@*/ |
70 | struct optionStackEntry * os; | |
71 | /*@owned@*/ /*@null@*/ | |
72 | const char ** leftovers; | |
b348deae MP |
73 | int numLeftovers; |
74 | int nextLeftover; | |
bc93ee84 WD |
75 | /*@keep@*/ |
76 | const struct poptOption * options; | |
b348deae | 77 | int restLeftover; |
bc93ee84 WD |
78 | /*@only@*/ /*@null@*/ |
79 | const char * appName; | |
80 | /*@only@*/ /*@null@*/ | |
81 | poptItem aliases; | |
b348deae MP |
82 | int numAliases; |
83 | int flags; | |
bc93ee84 WD |
84 | /*@owned@*/ /*@null@*/ |
85 | poptItem execs; | |
b348deae | 86 | int numExecs; |
bc93ee84 WD |
87 | /*@only@*/ /*@null@*/ |
88 | const char ** finalArgv; | |
b348deae MP |
89 | int finalArgvCount; |
90 | int finalArgvAlloced; | |
bc93ee84 WD |
91 | /*@dependent@*/ /*@null@*/ |
92 | poptItem doExec; | |
93 | /*@only@*/ | |
94 | const char * execPath; | |
b348deae | 95 | int execAbsolute; |
bc93ee84 WD |
96 | /*@only@*/ /*@relnull@*/ |
97 | const char * otherHelp; | |
98 | /*@null@*/ | |
99 | pbm_set * arg_strip; | |
b348deae MP |
100 | }; |
101 | ||
b348deae MP |
102 | #ifdef HAVE_LIBINTL_H |
103 | #include <libintl.h> | |
104 | #endif | |
105 | ||
106 | #if defined(HAVE_GETTEXT) && !defined(__LCLINT__) | |
107 | #define _(foo) gettext(foo) | |
108 | #else | |
cc248aae | 109 | #define _(foo) foo |
b348deae MP |
110 | #endif |
111 | ||
bc93ee84 | 112 | #if defined(HAVE_DCGETTEXT) && !defined(__LCLINT__) |
b348deae MP |
113 | #define D_(dom, str) dgettext(dom, str) |
114 | #define POPT_(foo) D_("popt", foo) | |
115 | #else | |
cc248aae WD |
116 | #define D_(dom, str) str |
117 | #define POPT_(foo) foo | |
b348deae MP |
118 | #endif |
119 | ||
cc248aae | 120 | #define N_(foo) foo |
b348deae MP |
121 | |
122 | #endif |