popt
1.14
|
00001 00005 /* (C) 1998-2000 Red Hat, Inc. -- Licensing details are in the COPYING 00006 file accompanying popt source distributions, available from 00007 ftp://ftp.rpm.org/pub/rpm/dist. */ 00008 00009 #ifndef H_POPTINT 00010 #define H_POPTINT 00011 00012 /* Drop the malloc'ing fprintf to fix ALT#16017 */ 00013 #define POPT_fprintf fprintf 00014 00020 /*@unused@*/ static inline /*@null@*/ void * 00021 _free(/*@only@*/ /*@null@*/ const void * p) 00022 /*@modifies p @*/ 00023 { 00024 if (p != NULL) free((void *)p); 00025 return NULL; 00026 } 00027 00028 /* Bit mask macros. */ 00029 /*@-exporttype -redef @*/ 00030 typedef unsigned int __pbm_bits; 00031 /*@=exporttype =redef @*/ 00032 #define __PBM_NBITS (8 * sizeof (__pbm_bits)) 00033 #define __PBM_IX(d) ((d) / __PBM_NBITS) 00034 #define __PBM_MASK(d) ((__pbm_bits) 1 << (((unsigned)(d)) % __PBM_NBITS)) 00035 /*@-exporttype -redef @*/ 00036 typedef struct { 00037 __pbm_bits bits[1]; 00038 } pbm_set; 00039 /*@=exporttype =redef @*/ 00040 #define __PBM_BITS(set) ((set)->bits) 00041 00042 #define PBM_ALLOC(d) calloc(__PBM_IX (d) + 1, sizeof(__pbm_bits)) 00043 #define PBM_FREE(s) _free(s); 00044 #define PBM_SET(d, s) (__PBM_BITS (s)[__PBM_IX (d)] |= __PBM_MASK (d)) 00045 #define PBM_CLR(d, s) (__PBM_BITS (s)[__PBM_IX (d)] &= ~__PBM_MASK (d)) 00046 #define PBM_ISSET(d, s) ((__PBM_BITS (s)[__PBM_IX (d)] & __PBM_MASK (d)) != 0) 00047 00051 /*@-exporttype@*/ 00052 typedef const char * poptString; 00053 typedef poptString * poptArgv; 00054 /*@=exporttype@*/ 00055 00059 /*@-exporttype -fielduse@*/ 00060 typedef union poptArg_u { 00061 /*@shared@*/ 00062 void * ptr; 00063 int * intp; 00064 long * longp; 00065 long long * longlongp; 00066 float * floatp; 00067 double * doublep; 00068 const char ** argv; 00069 poptCallbackType cb; 00070 /*@shared@*/ 00071 poptOption opt; 00072 } poptArg; 00073 /*@=exporttype =fielduse@*/ 00074 00075 #define poptArgType(_opt) ((_opt)->argInfo & POPT_ARG_MASK) 00076 #define F_ISSET(_opt, _FLAG) ((_opt)->argInfo & POPT_ARGFLAG_##_FLAG) 00077 #define LF_ISSET(_FLAG) (argInfo & POPT_ARGFLAG_##_FLAG) 00078 #define CBF_ISSET(_opt, _FLAG) ((_opt)->argInfo & POPT_CBFLAG_##_FLAG) 00079 00080 /* XXX sick hack to preserve pretense of a popt-1.x ABI. */ 00081 #define poptSubstituteHelpI18N(opt) \ 00082 { /*@-observertrans@*/ \ 00083 if ((opt) == poptHelpOptions) (opt) = poptHelpOptionsI18N; \ 00084 /*@=observertrans@*/ } 00085 00086 struct optionStackEntry { 00087 int argc; 00088 /*@only@*/ /*@null@*/ 00089 poptArgv argv; 00090 /*@only@*/ /*@null@*/ 00091 pbm_set * argb; 00092 int next; 00093 /*@only@*/ /*@null@*/ 00094 char * nextArg; 00095 /*@observer@*/ /*@null@*/ 00096 const char * nextCharArg; 00097 /*@dependent@*/ /*@null@*/ 00098 poptItem currAlias; 00099 int stuffed; 00100 }; 00101 00102 struct poptContext_s { 00103 struct optionStackEntry optionStack[POPT_OPTION_DEPTH]; 00104 /*@dependent@*/ 00105 struct optionStackEntry * os; 00106 /*@owned@*/ /*@null@*/ 00107 poptArgv leftovers; 00108 int numLeftovers; 00109 int nextLeftover; 00110 /*@keep@*/ 00111 const struct poptOption * options; 00112 int restLeftover; 00113 /*@only@*/ /*@null@*/ 00114 const char * appName; 00115 /*@only@*/ /*@null@*/ 00116 poptItem aliases; 00117 int numAliases; 00118 unsigned int flags; 00119 /*@owned@*/ /*@null@*/ 00120 poptItem execs; 00121 int numExecs; 00122 /*@only@*/ /*@null@*/ 00123 poptArgv finalArgv; 00124 int finalArgvCount; 00125 int finalArgvAlloced; 00126 /*@null@*/ 00127 int (*maincall) (int argc, const char **argv); 00128 /*@dependent@*/ /*@null@*/ 00129 poptItem doExec; 00130 /*@only@*/ /*@null@*/ 00131 const char * execPath; 00132 int execAbsolute; 00133 /*@only@*/ /*@relnull@*/ 00134 const char * otherHelp; 00135 /*@null@*/ 00136 pbm_set * arg_strip; 00137 }; 00138 00139 #if defined(POPT_fprintf) 00140 #define POPT_dgettext dgettext 00141 #else 00142 #ifdef HAVE_ICONV 00143 #include <iconv.h> 00144 #if defined(__LCLINT__) 00145 /*@-declundef -incondefs @*/ 00146 extern /*@only@*/ iconv_t iconv_open(const char *__tocode, const char *__fromcode) 00147 /*@*/; 00148 00149 extern size_t iconv(iconv_t __cd, /*@null@*/ char ** __inbuf, 00150 /*@out@*/ size_t * __inbytesleft, 00151 /*@out@*/ char ** __outbuf, 00152 /*@out@*/ size_t * __outbytesleft) 00153 /*@modifies __cd, 00154 *__inbuf, *__inbytesleft, *__outbuf, *__outbytesleft @*/; 00155 00156 extern int iconv_close(/*@only@*/ iconv_t __cd) 00157 /*@modifies __cd @*/; 00158 /*@=declundef =incondefs @*/ 00159 #endif 00160 #endif 00161 00162 #ifdef HAVE_LANGINFO_H 00163 #include <langinfo.h> 00164 #if defined(__LCLINT__) 00165 /*@-declundef -incondefs @*/ 00166 extern char *nl_langinfo (nl_item __item) 00167 /*@*/; 00168 /*@=declundef =incondefs @*/ 00169 #endif 00170 #endif 00171 00172 #if defined(HAVE_DCGETTEXT) && !defined(__LCLINT__) 00173 char *POPT_dgettext(const char * dom, const char * str) 00174 /*@*/; 00175 #endif 00176 00177 int POPT_fprintf (FILE* stream, const char *format, ...) 00178 /*@globals fileSystem @*/ 00179 /*@modifies stream, fileSystem @*/; 00180 #endif /* !defined(POPT_fprintf) */ 00181 00182 const char *POPT_prev_char (/*@returned@*/ const char *str) 00183 /*@*/; 00184 00185 const char *POPT_next_char (/*@returned@*/ const char *str) 00186 /*@*/; 00187 00188 #endif 00189 00190 #ifdef HAVE_LIBINTL_H 00191 #include <libintl.h> 00192 #endif 00193 00194 #if defined(HAVE_GETTEXT) && !defined(__LCLINT__) 00195 #define _(foo) gettext(foo) 00196 #else 00197 #define _(foo) foo 00198 #endif 00199 00200 #if defined(HAVE_DCGETTEXT) && !defined(__LCLINT__) 00201 #define D_(dom, str) POPT_dgettext(dom, str) 00202 #define POPT_(foo) D_("popt", foo) 00203 #else 00204 #define D_(dom, str) str 00205 #define POPT_(foo) foo 00206 #endif 00207 00208 #define N_(foo) foo 00209