popt  1.16
popt.h
Go to the documentation of this file.
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_BADCONFIG    -22     
00105 
00106 
00110 #define POPT_BADOPTION_NOALIAS  (1U << 0)  
00112 
00113 
00117 #define POPT_CONTEXT_NO_EXEC    (1U << 0)  
00118 #define POPT_CONTEXT_KEEP_FIRST (1U << 1)  
00119 #define POPT_CONTEXT_POSIXMEHARDER (1U << 2) 
00120 #define POPT_CONTEXT_ARG_OPTS   (1U << 4) 
00122 
00123 
00125 struct poptOption {
00126 /*@observer@*/ /*@null@*/
00127     const char * longName;      
00128     char shortName;             
00129     unsigned int argInfo;
00130 /*@shared@*/ /*@null@*/
00131     void * arg;                 
00132     int val;                    
00133 /*@observer@*/ /*@null@*/
00134     const char * descrip;       
00135 /*@observer@*/ /*@null@*/
00136     const char * argDescrip;    
00137 };
00138 
00142 struct poptAlias {
00143 /*@owned@*/ /*@null@*/
00144     const char * longName;      
00145     char shortName;             
00146     int argc;
00147 /*@owned@*/
00148     const char ** argv;         
00149 };
00150 
00154 /*@-exporttype@*/
00155 typedef struct poptItem_s {
00156     struct poptOption option;   
00157     int argc;                   
00158 /*@owned@*/
00159     const char ** argv;         
00160 } * poptItem;
00161 /*@=exporttype@*/
00162 
00167 
00171 /*@-exportvar@*/
00172 /*@unchecked@*/ /*@observer@*/
00173 extern struct poptOption poptAliasOptions[];
00174 /*@=exportvar@*/
00175 #define POPT_AUTOALIAS { NULL, '\0', POPT_ARG_INCLUDE_TABLE, poptAliasOptions, \
00176                         0, "Options implemented via popt alias/exec:", NULL },
00177 
00181 /*@-exportvar@*/
00182 /*@unchecked@*/ /*@observer@*/
00183 extern struct poptOption poptHelpOptions[];
00184 /*@=exportvar@*/
00185 
00186 /*@-exportvar@*/
00187 /*@unchecked@*/ /*@observer@*/
00188 extern struct poptOption * poptHelpOptionsI18N;
00189 /*@=exportvar@*/
00190 
00191 #define POPT_AUTOHELP { NULL, '\0', POPT_ARG_INCLUDE_TABLE, poptHelpOptions, \
00192                         0, "Help options:", NULL },
00193 
00194 #define POPT_TABLEEND { NULL, '\0', 0, NULL, 0, NULL, NULL }
00195 
00199 /*@-exporttype@*/
00200 typedef /*@abstract@*/ struct poptContext_s * poptContext;
00201 /*@=exporttype@*/
00202 
00205 #ifndef __cplusplus
00206 /*@-exporttype -typeuse@*/
00207 typedef struct poptOption * poptOption;
00208 /*@=exporttype =typeuse@*/
00209 #endif
00210 
00213 /*@-exportconst@*/
00214 enum poptCallbackReason {
00215     POPT_CALLBACK_REASON_PRE    = 0, 
00216     POPT_CALLBACK_REASON_POST   = 1,
00217     POPT_CALLBACK_REASON_OPTION = 2
00218 };
00219 /*@=exportconst@*/
00220 
00221 #ifdef __cplusplus
00222 extern "C" {
00223 #endif
00224 /*@-type@*/
00225 
00234 typedef void (*poptCallbackType) (poptContext con, 
00235                 enum poptCallbackReason reason,
00236                 /*@null@*/ const struct poptOption * opt,
00237                 /*@null@*/ const char * arg,
00238                 /*@null@*/ const void * data)
00239         /*@globals internalState @*/
00240         /*@modifies internalState @*/;
00241 
00247 /*@null@*/
00248 poptContext poptFreeContext( /*@only@*/ /*@null@*/ poptContext con)
00249         /*@modifies con @*/;
00250 
00260 /*@only@*/ /*@null@*/
00261 poptContext poptGetContext(
00262                 /*@dependent@*/ /*@keep@*/ const char * name,
00263                 int argc, /*@dependent@*/ /*@keep@*/ const char ** argv,
00264                 /*@dependent@*/ /*@keep@*/ const struct poptOption * options,
00265                 unsigned int flags)
00266         /*@globals internalState @*/
00267         /*@modifies internalState @*/;
00268 
00274 /*@null@*/
00275 poptContext poptFini( /*@only@*/ /*@null@*/ poptContext con)
00276         /*@modifies con @*/;
00277 
00287 /*@only@*/ /*@null@*/ /*@unused@*/
00288 poptContext poptInit(int argc, /*@dependent@*/ /*@keep@*/ const char ** argv,
00289                 /*@dependent@*/ /*@keep@*/ const struct poptOption * options,
00290                 /*@null@*/ const char * configPaths)
00291         /*@globals fileSystem, internalState @*/
00292         /*@modifies fileSystem, internalState @*/;
00293 
00298 /*@unused@*/
00299 void poptResetContext(/*@null@*/poptContext con)
00300         /*@modifies con @*/;
00301 
00307 int poptGetNextOpt(/*@null@*/poptContext con)
00308         /*@globals fileSystem, internalState @*/
00309         /*@modifies con, fileSystem, internalState @*/;
00310 
00316 /*@observer@*/ /*@null@*/ /*@unused@*/
00317 char * poptGetOptArg(/*@null@*/poptContext con)
00318         /*@modifies con @*/;
00319 
00325 /*@observer@*/ /*@null@*/ /*@unused@*/
00326 const char * poptGetArg(/*@null@*/poptContext con)
00327         /*@modifies con @*/;
00328 
00334 /*@observer@*/ /*@null@*/ /*@unused@*/
00335 const char * poptPeekArg(/*@null@*/poptContext con)
00336         /*@*/;
00337 
00343 /*@observer@*/ /*@null@*/
00344 const char ** poptGetArgs(/*@null@*/poptContext con)
00345         /*@modifies con @*/;
00346 
00353 /*@observer@*/
00354 const char * poptBadOption(/*@null@*/poptContext con, unsigned int flags)
00355         /*@*/;
00356 
00363 /*@unused@*/
00364 int poptStuffArgs(poptContext con, /*@keep@*/ const char ** argv)
00365         /*@modifies con @*/;
00366 
00376 /*@unused@*/
00377 int poptAddAlias(poptContext con, struct poptAlias alias, int flags)
00378         /*@modifies con @*/;
00379 
00387 int poptAddItem(poptContext con, poptItem newItem, int flags)
00388         /*@modifies con @*/;
00389 
00395 int poptSaneFile(const char * fn)
00396         /*@globals errno, internalState @*/
00397         /*@modifies errno, internalState @*/;
00398 
00407 int poptReadFile(const char * fn, /*@null@*/ /*@out@*/ char ** bp,
00408                 /*@null@*/ /*@out@*/ size_t * nbp, int flags)
00409         /*@globals errno, fileSystem, internalState @*/
00410         /*@modifies *bp, *nbp, errno, fileSystem, internalState @*/;
00411 #define POPT_READFILE_TRIMNEWLINES      1
00412 
00419 int poptReadConfigFile(poptContext con, const char * fn)
00420         /*@globals errno, fileSystem, internalState @*/
00421         /*@modifies con->execs, con->numExecs,
00422                 errno, fileSystem, internalState @*/;
00423 
00433 int poptReadConfigFiles(poptContext con, /*@null@*/ const char * paths)
00434         /*@globals errno, fileSystem, internalState @*/
00435         /*@modifies con->execs, con->numExecs,
00436                 errno, fileSystem, internalState @*/;
00437 
00444 /*@unused@*/
00445 int poptReadDefaultConfig(poptContext con, /*@unused@*/ int useEnv)
00446         /*@globals fileSystem, internalState @*/
00447         /*@modifies con->execs, con->numExecs,
00448                 fileSystem, internalState @*/;
00449 
00461 int poptDupArgv(int argc, /*@null@*/ const char **argv,
00462                 /*@null@*/ /*@out@*/ int * argcPtr,
00463                 /*@null@*/ /*@out@*/ const char *** argvPtr)
00464         /*@modifies *argcPtr, *argvPtr @*/;
00465 
00477 int poptParseArgvString(const char * s,
00478                 /*@out@*/ int * argcPtr, /*@out@*/ const char *** argvPtr)
00479         /*@modifies *argcPtr, *argvPtr @*/;
00480 
00527 /*@-fcnuse@*/
00528 int poptConfigFileToString(FILE *fp, /*@out@*/ char ** argstrp, int flags)
00529         /*@globals fileSystem @*/
00530         /*@modifies *fp, *argstrp, fileSystem @*/;
00531 /*@=fcnuse@*/
00532 
00538 /*@observer@*/
00539 const char * poptStrerror(const int error)
00540         /*@*/;
00541 
00548 /*@unused@*/
00549 void poptSetExecPath(poptContext con, const char * path, int allowAbsolute)
00550         /*@modifies con @*/;
00551 
00558 void poptPrintHelp(poptContext con, FILE * fp, /*@unused@*/ int flags)
00559         /*@globals fileSystem @*/
00560         /*@modifies fp, fileSystem @*/;
00561 
00568 void poptPrintUsage(poptContext con, FILE * fp, /*@unused@*/ int flags)
00569         /*@globals fileSystem @*/
00570         /*@modifies fp, fileSystem @*/;
00571 
00577 /*@-fcnuse@*/
00578 void poptSetOtherOptionHelp(poptContext con, const char * text)
00579         /*@modifies con @*/;
00580 /*@=fcnuse@*/
00581 
00587 /*@-fcnuse@*/
00588 /*@observer@*/
00589 const char * poptGetInvocationName(poptContext con)
00590         /*@*/;
00591 /*@=fcnuse@*/
00592 
00600 /*@-fcnuse@*/
00601 int poptStrippedArgv(poptContext con, int argc, char ** argv)
00602         /*@modifies *argv @*/;
00603 /*@=fcnuse@*/
00604 
00612 /*@unused@*/
00613 int poptSaveString(/*@null@*/ const char *** argvp, unsigned int argInfo,
00614                 /*@null@*/const char * val)
00615         /*@modifies *argvp @*/;
00616 
00625 /*@-incondefs@*/
00626 /*@unused@*/
00627 int poptSaveLongLong(/*@null@*/ long long * arg, unsigned int argInfo,
00628                 long long aLongLong)
00629         /*@globals internalState @*/
00630         /*@modifies *arg, internalState @*/
00631         /*@requires maxSet(arg) >= 0 /\ maxRead(arg) == 0 @*/;
00632 /*@=incondefs@*/
00633 
00642 /*@-incondefs@*/
00643 /*@unused@*/
00644 int poptSaveLong(/*@null@*/ long * arg, unsigned int argInfo, long aLong)
00645         /*@globals internalState @*/
00646         /*@modifies *arg, internalState @*/
00647         /*@requires maxSet(arg) >= 0 /\ maxRead(arg) == 0 @*/;
00648 /*@=incondefs@*/
00649 
00658 /*@-incondefs@*/
00659 /*@unused@*/
00660 int poptSaveShort(/*@null@*/ short * arg, unsigned int argInfo, long aLong)
00661         /*@globals internalState @*/
00662         /*@modifies *arg, internalState @*/
00663         /*@requires maxSet(arg) >= 0 /\ maxRead(arg) == 0 @*/;
00664 /*@=incondefs@*/
00665 
00674 /*@-incondefs@*/
00675 /*@unused@*/
00676 int poptSaveInt(/*@null@*/ int * arg, unsigned int argInfo, long aLong)
00677         /*@globals internalState @*/
00678         /*@modifies *arg, internalState @*/
00679         /*@requires maxSet(arg) >= 0 /\ maxRead(arg) == 0 @*/;
00680 /*@=incondefs@*/
00681 
00682 /* The bit set typedef. */
00683 /*@-exporttype@*/
00684 typedef struct poptBits_s {
00685     unsigned int bits[1];
00686 } * poptBits;
00687 /*@=exporttype@*/
00688 
00689 #define _POPT_BITS_N    1024U    /* estimated population */
00690 #define _POPT_BITS_M    ((3U * _POPT_BITS_N) / 2U)
00691 #define _POPT_BITS_K    16U      /* no. of linear hash combinations */
00692 
00693 /*@-exportlocal -exportvar -globuse @*/
00694 /*@unchecked@*/
00695 extern unsigned int _poptBitsN;
00696 /*@unchecked@*/
00697 extern  unsigned int _poptBitsM;
00698 /*@unchecked@*/
00699 extern  unsigned int _poptBitsK;
00700 /*@=exportlocal =exportvar =globuse @*/
00701 
00702 /*@-exportlocal@*/
00703 int poptBitsAdd(/*@null@*/poptBits bits, /*@null@*/const char * s)
00704         /*@modifies bits @*/;
00705 /*@=exportlocal@*/
00706 int poptBitsChk(/*@null@*/poptBits bits, /*@null@*/const char * s)
00707         /*@*/;
00708 int poptBitsClr(/*@null@*/poptBits bits)
00709         /*@modifies bits @*/;
00710 /*@-exportlocal@*/
00711 int poptBitsDel(/*@null@*/poptBits bits, /*@null@*/const char * s)
00712         /*@modifies bits @*/;
00713 /*@-fcnuse@*/
00714 int poptBitsIntersect(/*@null@*/ poptBits * ap, /*@null@*/ const poptBits b)
00715         /*@modifies *ap @*/;
00716 int poptBitsUnion(/*@null@*/ poptBits * ap, /*@null@*/ const poptBits b)
00717         /*@modifies *ap @*/;
00718 int poptBitsArgs(/*@null@*/ poptContext con, /*@null@*/ poptBits * ap)
00719         /*@modifies con, *ap @*/;
00720 /*@=fcnuse@*/
00721 /*@=exportlocal@*/
00722 
00730 /*@-incondefs@*/
00731 /*@unused@*/
00732 int poptSaveBits(/*@null@*/ poptBits * bitsp, unsigned int argInfo,
00733                 /*@null@*/ const char * s)
00734         /*@globals _poptBitsN, _poptBitsM, _poptBitsK, internalState @*/
00735         /*@modifies *bitsp, _poptBitsN, _poptBitsM, _poptBitsK, internalState @*/;
00736 /*@=incondefs@*/
00737 
00738 /*@=type@*/
00739 
00740 #ifdef  __cplusplus
00741 }
00742 #endif
00743 
00744 #endif

Generated for popt by  doxygen 1.7.6.1