popt
1.16
|
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_POPT 00010 #define H_POPT 00011 00012 #include <stdio.h> /* for FILE * */ 00013 00014 #define POPT_OPTION_DEPTH 10 00015 00020 #define POPT_ARG_NONE 0U 00021 #define POPT_ARG_STRING 1U 00022 #define POPT_ARG_INT 2U 00023 #define POPT_ARG_LONG 3U 00024 #define POPT_ARG_INCLUDE_TABLE 4U 00025 #define POPT_ARG_CALLBACK 5U 00029 #define POPT_ARG_INTL_DOMAIN 6U 00033 #define POPT_ARG_VAL 7U 00034 #define POPT_ARG_FLOAT 8U 00035 #define POPT_ARG_DOUBLE 9U 00036 #define POPT_ARG_LONGLONG 10U 00038 #define POPT_ARG_MAINCALL 16U+11U 00039 #define POPT_ARG_ARGV 12U 00040 #define POPT_ARG_SHORT 13U 00041 #define POPT_ARG_BITSET 16U+14U 00043 #define POPT_ARG_MASK 0x000000FFU 00044 #define POPT_GROUP_MASK 0x0000FF00U 00045 00052 #define POPT_ARGFLAG_ONEDASH 0x80000000U 00053 #define POPT_ARGFLAG_DOC_HIDDEN 0x40000000U 00054 #define POPT_ARGFLAG_STRIP 0x20000000U 00055 #define POPT_ARGFLAG_OPTIONAL 0x10000000U 00057 #define POPT_ARGFLAG_OR 0x08000000U 00058 #define POPT_ARGFLAG_NOR 0x09000000U 00059 #define POPT_ARGFLAG_AND 0x04000000U 00060 #define POPT_ARGFLAG_NAND 0x05000000U 00061 #define POPT_ARGFLAG_XOR 0x02000000U 00062 #define POPT_ARGFLAG_NOT 0x01000000U 00063 #define POPT_ARGFLAG_LOGICALOPS \ 00064 (POPT_ARGFLAG_OR|POPT_ARGFLAG_AND|POPT_ARGFLAG_XOR) 00065 00066 #define POPT_BIT_SET (POPT_ARG_VAL|POPT_ARGFLAG_OR) 00067 00068 #define POPT_BIT_CLR (POPT_ARG_VAL|POPT_ARGFLAG_NAND) 00069 00071 #define POPT_ARGFLAG_SHOW_DEFAULT 0x00800000U 00072 #define POPT_ARGFLAG_RANDOM 0x00400000U 00073 #define POPT_ARGFLAG_TOGGLE 0x00200000U 00076 00077 00081 #define POPT_CBFLAG_PRE 0x80000000U 00082 #define POPT_CBFLAG_POST 0x40000000U 00083 #define POPT_CBFLAG_INC_DATA 0x20000000U 00085 #define POPT_CBFLAG_SKIPOPTION 0x10000000U 00086 #define POPT_CBFLAG_CONTINUE 0x08000000U 00088 00089 00093 #define POPT_ERROR_NOARG -10 00094 #define POPT_ERROR_BADOPT -11 00095 #define POPT_ERROR_OPTSTOODEEP -13 00096 #define POPT_ERROR_BADQUOTE -15 00097 #define POPT_ERROR_ERRNO -16 00098 #define POPT_ERROR_BADNUMBER -17 00099 #define POPT_ERROR_OVERFLOW -18 00100 #define POPT_ERROR_BADOPERATION -19 00101 #define POPT_ERROR_NULLARG -20 00102 #define POPT_ERROR_MALLOC -21 00103 #define POPT_ERROR_NOCONTEXT -22 00104 #define POPT_ERROR_BADCONFIG -23 00107 00108 00112 #define POPT_BADOPTION_NOALIAS (1U << 0) 00114 00115 00119 #define POPT_CONTEXT_NO_EXEC (1U << 0) 00120 #define POPT_CONTEXT_KEEP_FIRST (1U << 1) 00121 #define POPT_CONTEXT_POSIXMEHARDER (1U << 2) 00122 #define POPT_CONTEXT_ARG_OPTS (1U << 4) 00124 00125 00127 struct poptOption { 00128 /*@observer@*/ /*@null@*/ 00129 const char * longName; 00130 char shortName; 00131 unsigned int argInfo; 00132 /*@shared@*/ /*@null@*/ 00133 void * arg; 00134 int val; 00135 /*@observer@*/ /*@null@*/ 00136 const char * descrip; 00137 /*@observer@*/ /*@null@*/ 00138 const char * argDescrip; 00139 }; 00140 00144 struct poptAlias { 00145 /*@owned@*/ /*@null@*/ 00146 const char * longName; 00147 char shortName; 00148 int argc; 00149 /*@owned@*/ 00150 const char ** argv; 00151 }; 00152 00156 /*@-exporttype@*/ 00157 typedef struct poptItem_s { 00158 struct poptOption option; 00159 int argc; 00160 /*@owned@*/ 00161 const char ** argv; 00162 } * poptItem; 00163 /*@=exporttype@*/ 00164 00169 00173 /*@-exportvar@*/ 00174 /*@unchecked@*/ /*@observer@*/ 00175 extern struct poptOption poptAliasOptions[]; 00176 /*@=exportvar@*/ 00177 #define POPT_AUTOALIAS { NULL, '\0', POPT_ARG_INCLUDE_TABLE, poptAliasOptions, \ 00178 0, "Options implemented via popt alias/exec:", NULL }, 00179 00183 /*@-exportvar@*/ 00184 /*@unchecked@*/ /*@observer@*/ 00185 extern struct poptOption poptHelpOptions[]; 00186 /*@=exportvar@*/ 00187 00188 /*@-exportvar@*/ 00189 /*@unchecked@*/ /*@observer@*/ 00190 extern struct poptOption * poptHelpOptionsI18N; 00191 /*@=exportvar@*/ 00192 00193 #define POPT_AUTOHELP { NULL, '\0', POPT_ARG_INCLUDE_TABLE, poptHelpOptions, \ 00194 0, "Help options:", NULL }, 00195 00196 #define POPT_TABLEEND { NULL, '\0', 0, NULL, 0, NULL, NULL } 00197 00201 /*@-exporttype@*/ 00202 typedef /*@abstract@*/ struct poptContext_s * poptContext; 00203 /*@=exporttype@*/ 00204 00207 #ifndef __cplusplus 00208 /*@-exporttype -typeuse@*/ 00209 typedef struct poptOption * poptOption; 00210 /*@=exporttype =typeuse@*/ 00211 #endif 00212 00215 /*@-exportconst@*/ 00216 enum poptCallbackReason { 00217 POPT_CALLBACK_REASON_PRE = 0, 00218 POPT_CALLBACK_REASON_POST = 1, 00219 POPT_CALLBACK_REASON_OPTION = 2 00220 }; 00221 /*@=exportconst@*/ 00222 00223 #ifdef __cplusplus 00224 extern "C" { 00225 #endif 00226 /*@-type@*/ 00227 00236 typedef void (*poptCallbackType) (poptContext con, 00237 enum poptCallbackReason reason, 00238 /*@null@*/ const struct poptOption * opt, 00239 /*@null@*/ const char * arg, 00240 /*@null@*/ const void * data) 00241 /*@globals internalState @*/ 00242 /*@modifies internalState @*/; 00243 00249 /*@null@*/ 00250 poptContext poptFreeContext( /*@only@*/ /*@null@*/ poptContext con) 00251 /*@modifies con @*/; 00252 00262 /*@only@*/ /*@null@*/ 00263 poptContext poptGetContext( 00264 /*@dependent@*/ /*@keep@*/ const char * name, 00265 int argc, /*@dependent@*/ /*@keep@*/ const char ** argv, 00266 /*@dependent@*/ /*@keep@*/ const struct poptOption * options, 00267 unsigned int flags) 00268 /*@globals internalState @*/ 00269 /*@modifies internalState @*/; 00270 00276 /*@null@*/ 00277 poptContext poptFini( /*@only@*/ /*@null@*/ poptContext con) 00278 /*@modifies con @*/; 00279 00289 /*@only@*/ /*@null@*/ /*@unused@*/ 00290 poptContext poptInit(int argc, /*@dependent@*/ /*@keep@*/ const char ** argv, 00291 /*@dependent@*/ /*@keep@*/ const struct poptOption * options, 00292 /*@null@*/ const char * configPaths) 00293 /*@globals fileSystem, internalState @*/ 00294 /*@modifies fileSystem, internalState @*/; 00295 00300 /*@unused@*/ 00301 void poptResetContext(/*@null@*/poptContext con) 00302 /*@modifies con @*/; 00303 00309 int poptGetNextOpt(/*@null@*/poptContext con) 00310 /*@globals fileSystem, internalState @*/ 00311 /*@modifies con, fileSystem, internalState @*/; 00312 00318 /*@observer@*/ /*@null@*/ /*@unused@*/ 00319 char * poptGetOptArg(/*@null@*/poptContext con) 00320 /*@modifies con @*/; 00321 00327 /*@observer@*/ /*@null@*/ /*@unused@*/ 00328 const char * poptGetArg(/*@null@*/poptContext con) 00329 /*@modifies con @*/; 00330 00336 /*@observer@*/ /*@null@*/ /*@unused@*/ 00337 const char * poptPeekArg(/*@null@*/poptContext con) 00338 /*@*/; 00339 00345 /*@observer@*/ /*@null@*/ 00346 const char ** poptGetArgs(/*@null@*/poptContext con) 00347 /*@modifies con @*/; 00348 00355 /*@observer@*/ 00356 const char * poptBadOption(/*@null@*/poptContext con, unsigned int flags) 00357 /*@*/; 00358 00365 /*@unused@*/ 00366 int poptStuffArgs(poptContext con, /*@keep@*/ const char ** argv) 00367 /*@modifies con @*/; 00368 00378 /*@unused@*/ 00379 int poptAddAlias(poptContext con, struct poptAlias alias, int flags) 00380 /*@modifies con @*/; 00381 00389 int poptAddItem(poptContext con, poptItem newItem, int flags) 00390 /*@modifies con @*/; 00391 00397 int poptSaneFile(const char * fn) 00398 /*@globals errno, internalState @*/ 00399 /*@modifies errno, internalState @*/; 00400 00409 int poptReadFile(const char * fn, /*@null@*/ /*@out@*/ char ** bp, 00410 /*@null@*/ /*@out@*/ size_t * nbp, int flags) 00411 /*@globals errno, fileSystem, internalState @*/ 00412 /*@modifies *bp, *nbp, errno, fileSystem, internalState @*/; 00413 #define POPT_READFILE_TRIMNEWLINES 1 00414 00421 int poptReadConfigFile(poptContext con, const char * fn) 00422 /*@globals errno, fileSystem, internalState @*/ 00423 /*@modifies con->execs, con->numExecs, 00424 errno, fileSystem, internalState @*/; 00425 00435 int poptReadConfigFiles(poptContext con, /*@null@*/ const char * paths) 00436 /*@globals errno, fileSystem, internalState @*/ 00437 /*@modifies con->execs, con->numExecs, 00438 errno, fileSystem, internalState @*/; 00439 00446 /*@unused@*/ 00447 int poptReadDefaultConfig(poptContext con, /*@unused@*/ int useEnv) 00448 /*@globals fileSystem, internalState @*/ 00449 /*@modifies con->execs, con->numExecs, 00450 fileSystem, internalState @*/; 00451 00463 int poptDupArgv(int argc, /*@null@*/ const char **argv, 00464 /*@null@*/ /*@out@*/ int * argcPtr, 00465 /*@null@*/ /*@out@*/ const char *** argvPtr) 00466 /*@modifies *argcPtr, *argvPtr @*/; 00467 00479 int poptParseArgvString(const char * s, 00480 /*@out@*/ int * argcPtr, /*@out@*/ const char *** argvPtr) 00481 /*@modifies *argcPtr, *argvPtr @*/; 00482 00529 /*@-fcnuse@*/ 00530 int poptConfigFileToString(FILE *fp, /*@out@*/ char ** argstrp, int flags) 00531 /*@globals fileSystem @*/ 00532 /*@modifies *fp, *argstrp, fileSystem @*/; 00533 /*@=fcnuse@*/ 00534 00540 /*@observer@*/ 00541 const char * poptStrerror(const int error) 00542 /*@*/; 00543 00550 /*@unused@*/ 00551 void poptSetExecPath(poptContext con, const char * path, int allowAbsolute) 00552 /*@modifies con @*/; 00553 00560 void poptPrintHelp(poptContext con, FILE * fp, /*@unused@*/ int flags) 00561 /*@globals fileSystem @*/ 00562 /*@modifies fp, fileSystem @*/; 00563 00570 void poptPrintUsage(poptContext con, FILE * fp, /*@unused@*/ int flags) 00571 /*@globals fileSystem @*/ 00572 /*@modifies fp, fileSystem @*/; 00573 00579 /*@-fcnuse@*/ 00580 void poptSetOtherOptionHelp(poptContext con, const char * text) 00581 /*@modifies con @*/; 00582 /*@=fcnuse@*/ 00583 00589 /*@-fcnuse@*/ 00590 /*@observer@*/ 00591 const char * poptGetInvocationName(poptContext con) 00592 /*@*/; 00593 /*@=fcnuse@*/ 00594 00602 /*@-fcnuse@*/ 00603 int poptStrippedArgv(poptContext con, int argc, char ** argv) 00604 /*@modifies *argv @*/; 00605 /*@=fcnuse@*/ 00606 00614 /*@unused@*/ 00615 int poptSaveString(/*@null@*/ const char *** argvp, unsigned int argInfo, 00616 /*@null@*/const char * val) 00617 /*@modifies *argvp @*/; 00618 00627 /*@-incondefs@*/ 00628 /*@unused@*/ 00629 int poptSaveLongLong(/*@null@*/ long long * arg, unsigned int argInfo, 00630 long long aLongLong) 00631 /*@globals internalState @*/ 00632 /*@modifies *arg, internalState @*/ 00633 /*@requires maxSet(arg) >= 0 /\ maxRead(arg) == 0 @*/; 00634 /*@=incondefs@*/ 00635 00644 /*@-incondefs@*/ 00645 /*@unused@*/ 00646 int poptSaveLong(/*@null@*/ long * arg, unsigned int argInfo, long aLong) 00647 /*@globals internalState @*/ 00648 /*@modifies *arg, internalState @*/ 00649 /*@requires maxSet(arg) >= 0 /\ maxRead(arg) == 0 @*/; 00650 /*@=incondefs@*/ 00651 00660 /*@-incondefs@*/ 00661 /*@unused@*/ 00662 int poptSaveShort(/*@null@*/ short * arg, unsigned int argInfo, long aLong) 00663 /*@globals internalState @*/ 00664 /*@modifies *arg, internalState @*/ 00665 /*@requires maxSet(arg) >= 0 /\ maxRead(arg) == 0 @*/; 00666 /*@=incondefs@*/ 00667 00676 /*@-incondefs@*/ 00677 /*@unused@*/ 00678 int poptSaveInt(/*@null@*/ int * arg, unsigned int argInfo, long aLong) 00679 /*@globals internalState @*/ 00680 /*@modifies *arg, internalState @*/ 00681 /*@requires maxSet(arg) >= 0 /\ maxRead(arg) == 0 @*/; 00682 /*@=incondefs@*/ 00683 00684 /* The bit set typedef. */ 00685 /*@-exporttype@*/ 00686 typedef struct poptBits_s { 00687 unsigned int bits[1]; 00688 } * poptBits; 00689 /*@=exporttype@*/ 00690 00691 #define _POPT_BITS_N 1024U /* estimated population */ 00692 #define _POPT_BITS_M ((3U * _POPT_BITS_N) / 2U) 00693 #define _POPT_BITS_K 16U /* no. of linear hash combinations */ 00694 00695 /*@-exportlocal -exportvar -globuse @*/ 00696 /*@unchecked@*/ 00697 extern unsigned int _poptBitsN; 00698 /*@unchecked@*/ 00699 extern unsigned int _poptBitsM; 00700 /*@unchecked@*/ 00701 extern unsigned int _poptBitsK; 00702 /*@=exportlocal =exportvar =globuse @*/ 00703 00704 /*@-exportlocal@*/ 00705 int poptBitsAdd(/*@null@*/poptBits bits, /*@null@*/const char * s) 00706 /*@modifies bits @*/; 00707 /*@=exportlocal@*/ 00708 int poptBitsChk(/*@null@*/poptBits bits, /*@null@*/const char * s) 00709 /*@*/; 00710 int poptBitsClr(/*@null@*/poptBits bits) 00711 /*@modifies bits @*/; 00712 /*@-exportlocal@*/ 00713 int poptBitsDel(/*@null@*/poptBits bits, /*@null@*/const char * s) 00714 /*@modifies bits @*/; 00715 /*@-fcnuse@*/ 00716 int poptBitsIntersect(/*@null@*/ poptBits * ap, /*@null@*/ const poptBits b) 00717 /*@modifies *ap @*/; 00718 int poptBitsUnion(/*@null@*/ poptBits * ap, /*@null@*/ const poptBits b) 00719 /*@modifies *ap @*/; 00720 int poptBitsArgs(/*@null@*/ poptContext con, /*@null@*/ poptBits * ap) 00721 /*@modifies con, *ap @*/; 00722 /*@=fcnuse@*/ 00723 /*@=exportlocal@*/ 00724 00732 /*@-incondefs@*/ 00733 /*@unused@*/ 00734 int poptSaveBits(/*@null@*/ poptBits * bitsp, unsigned int argInfo, 00735 /*@null@*/ const char * s) 00736 /*@globals _poptBitsN, _poptBitsM, _poptBitsK, internalState @*/ 00737 /*@modifies *bitsp, _poptBitsN, _poptBitsM, _poptBitsK, internalState @*/; 00738 /*@=incondefs@*/ 00739 00740 /*@=type@*/ 00741 00742 #ifdef __cplusplus 00743 } 00744 #endif 00745 00746 #endif