poptint.h 5.5 KB

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