| 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 |
/** |
| 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 |
|
| 25 |
static inline int |
| 26 |
isSpace(const char *ptr) |
| 27 |
{ |
| 28 |
return isspace(*(unsigned char *)ptr); |
| 29 |
} |
| 30 |
|
| 31 |
/* Bit mask macros. */ |
| 32 |
/*@-exporttype -redef @*/ |
| 33 |
typedef unsigned int __pbm_bits; |
| 34 |
/*@=exporttype =redef @*/ |
| 35 |
#define __PBM_NBITS (8 * sizeof (__pbm_bits)) |
| 36 |
#define __PBM_IX(d) ((d) / __PBM_NBITS) |
| 37 |
#define __PBM_MASK(d) ((__pbm_bits) 1 << (((unsigned)(d)) % __PBM_NBITS)) |
| 38 |
/*@-exporttype -redef @*/ |
| 39 |
typedef struct { |
| 40 |
__pbm_bits bits[1]; |
| 41 |
} pbm_set; |
| 42 |
/*@=exporttype =redef @*/ |
| 43 |
#define __PBM_BITS(set) ((set)->bits) |
| 44 |
|
| 45 |
#define PBM_ALLOC(d) calloc(__PBM_IX (d) + 1, sizeof(__pbm_bits)) |
| 46 |
#define PBM_FREE(s) _free(s); |
| 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; |
| 53 |
/*@only@*/ /*@null@*/ |
| 54 |
const char ** argv; |
| 55 |
/*@only@*/ /*@null@*/ |
| 56 |
pbm_set * argb; |
| 57 |
int next; |
| 58 |
/*@only@*/ /*@null@*/ |
| 59 |
const char * nextArg; |
| 60 |
/*@observer@*/ /*@null@*/ |
| 61 |
const char * nextCharArg; |
| 62 |
/*@dependent@*/ /*@null@*/ |
| 63 |
poptItem currAlias; |
| 64 |
int stuffed; |
| 65 |
}; |
| 66 |
|
| 67 |
struct poptContext_s { |
| 68 |
struct optionStackEntry optionStack[POPT_OPTION_DEPTH]; |
| 69 |
/*@dependent@*/ |
| 70 |
struct optionStackEntry * os; |
| 71 |
/*@owned@*/ /*@null@*/ |
| 72 |
const char ** leftovers; |
| 73 |
int numLeftovers; |
| 74 |
int nextLeftover; |
| 75 |
/*@keep@*/ |
| 76 |
const struct poptOption * options; |
| 77 |
int restLeftover; |
| 78 |
/*@only@*/ /*@null@*/ |
| 79 |
const char * appName; |
| 80 |
/*@only@*/ /*@null@*/ |
| 81 |
poptItem aliases; |
| 82 |
int numAliases; |
| 83 |
int flags; |
| 84 |
/*@owned@*/ /*@null@*/ |
| 85 |
poptItem execs; |
| 86 |
int numExecs; |
| 87 |
/*@only@*/ /*@null@*/ |
| 88 |
const char ** finalArgv; |
| 89 |
int finalArgvCount; |
| 90 |
int finalArgvAlloced; |
| 91 |
/*@dependent@*/ /*@null@*/ |
| 92 |
poptItem doExec; |
| 93 |
/*@only@*/ |
| 94 |
const char * execPath; |
| 95 |
int execAbsolute; |
| 96 |
/*@only@*/ /*@relnull@*/ |
| 97 |
const char * otherHelp; |
| 98 |
/*@null@*/ |
| 99 |
pbm_set * arg_strip; |
| 100 |
}; |
| 101 |
|
| 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 |
| 109 |
#define _(foo) foo |
| 110 |
#endif |
| 111 |
|
| 112 |
#if defined(HAVE_DCGETTEXT) && !defined(__LCLINT__) |
| 113 |
#define D_(dom, str) dgettext(dom, str) |
| 114 |
#define POPT_(foo) D_("popt", foo) |
| 115 |
#else |
| 116 |
#define D_(dom, str) str |
| 117 |
#define POPT_(foo) foo |
| 118 |
#endif |
| 119 |
|
| 120 |
#define N_(foo) foo |
| 121 |
|
| 122 |
#endif |