popt  1.16
popt.h
Go to the documentation of this file.
1 
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_POPT
10 #define H_POPT
11 
12 #include <stdio.h> /* for FILE * */
13 
14 #define POPT_OPTION_DEPTH 10
15 
20 #define POPT_ARG_NONE 0U
21 #define POPT_ARG_STRING 1U
22 #define POPT_ARG_INT 2U
23 #define POPT_ARG_LONG 3U
24 #define POPT_ARG_INCLUDE_TABLE 4U
25 #define POPT_ARG_CALLBACK 5U
29 #define POPT_ARG_INTL_DOMAIN 6U
33 #define POPT_ARG_VAL 7U
34 #define POPT_ARG_FLOAT 8U
35 #define POPT_ARG_DOUBLE 9U
36 #define POPT_ARG_LONGLONG 10U
38 #define POPT_ARG_MAINCALL 16U+11U
39 #define POPT_ARG_ARGV 12U
40 #define POPT_ARG_SHORT 13U
41 #define POPT_ARG_BITSET 16U+14U
43 #define POPT_ARG_MASK 0x000000FFU
44 #define POPT_GROUP_MASK 0x0000FF00U
45 
52 #define POPT_ARGFLAG_ONEDASH 0x80000000U
53 #define POPT_ARGFLAG_DOC_HIDDEN 0x40000000U
54 #define POPT_ARGFLAG_STRIP 0x20000000U
55 #define POPT_ARGFLAG_OPTIONAL 0x10000000U
57 #define POPT_ARGFLAG_OR 0x08000000U
58 #define POPT_ARGFLAG_NOR 0x09000000U
59 #define POPT_ARGFLAG_AND 0x04000000U
60 #define POPT_ARGFLAG_NAND 0x05000000U
61 #define POPT_ARGFLAG_XOR 0x02000000U
62 #define POPT_ARGFLAG_NOT 0x01000000U
63 #define POPT_ARGFLAG_LOGICALOPS \
64  (POPT_ARGFLAG_OR|POPT_ARGFLAG_AND|POPT_ARGFLAG_XOR)
65 
66 #define POPT_BIT_SET (POPT_ARG_VAL|POPT_ARGFLAG_OR)
67 
68 #define POPT_BIT_CLR (POPT_ARG_VAL|POPT_ARGFLAG_NAND)
69 
71 #define POPT_ARGFLAG_SHOW_DEFAULT 0x00800000U
72 #define POPT_ARGFLAG_RANDOM 0x00400000U
73 #define POPT_ARGFLAG_TOGGLE 0x00200000U
76 
77 
81 #define POPT_CBFLAG_PRE 0x80000000U
82 #define POPT_CBFLAG_POST 0x40000000U
83 #define POPT_CBFLAG_INC_DATA 0x20000000U
85 #define POPT_CBFLAG_SKIPOPTION 0x10000000U
86 #define POPT_CBFLAG_CONTINUE 0x08000000U
88 
89 
93 #define POPT_ERROR_NOARG -10
94 #define POPT_ERROR_BADOPT -11
95 #define POPT_ERROR_OPTSTOODEEP -13
96 #define POPT_ERROR_BADQUOTE -15
97 #define POPT_ERROR_ERRNO -16
98 #define POPT_ERROR_BADNUMBER -17
99 #define POPT_ERROR_OVERFLOW -18
100 #define POPT_ERROR_BADOPERATION -19
101 #define POPT_ERROR_NULLARG -20
102 #define POPT_ERROR_MALLOC -21
103 #define POPT_ERROR_BADCONFIG -22
110 #define POPT_BADOPTION_NOALIAS (1U << 0)
112 
113 
117 #define POPT_CONTEXT_NO_EXEC (1U << 0)
118 #define POPT_CONTEXT_KEEP_FIRST (1U << 1)
119 #define POPT_CONTEXT_POSIXMEHARDER (1U << 2)
120 #define POPT_CONTEXT_ARG_OPTS (1U << 4)
122 
123 
125 struct poptOption {
126 /*@observer@*/ /*@null@*/
127  const char * longName;
128  char shortName;
129  unsigned int argInfo;
130 /*@shared@*/ /*@null@*/
131  void * arg;
132  int val;
133 /*@observer@*/ /*@null@*/
134  const char * descrip;
135 /*@observer@*/ /*@null@*/
136  const char * argDescrip;
137 };
142 struct poptAlias {
143 /*@owned@*/ /*@null@*/
144  const char * longName;
145  char shortName;
146  int argc;
147 /*@owned@*/
148  const char ** argv;
149 };
150 
154 /*@-exporttype@*/
155 typedef struct poptItem_s {
156  struct poptOption option;
157  int argc;
158 /*@owned@*/
159  const char ** argv;
160 } * poptItem;
161 /*@=exporttype@*/
167 
171 /*@-exportvar@*/
172 /*@unchecked@*/ /*@observer@*/
173 extern struct poptOption poptAliasOptions[];
174 /*@=exportvar@*/
175 #define POPT_AUTOALIAS { NULL, '\0', POPT_ARG_INCLUDE_TABLE, poptAliasOptions, \
176  0, "Options implemented via popt alias/exec:", NULL },
177 
181 /*@-exportvar@*/
182 /*@unchecked@*/ /*@observer@*/
183 extern struct poptOption poptHelpOptions[];
184 /*@=exportvar@*/
185 
186 /*@-exportvar@*/
187 /*@unchecked@*/ /*@observer@*/
188 extern struct poptOption * poptHelpOptionsI18N;
189 /*@=exportvar@*/
190 
191 #define POPT_AUTOHELP { NULL, '\0', POPT_ARG_INCLUDE_TABLE, poptHelpOptions, \
192  0, "Help options:", NULL },
193 
194 #define POPT_TABLEEND { NULL, '\0', 0, NULL, 0, NULL, NULL }
195 
199 /*@-exporttype@*/
200 typedef /*@abstract@*/ struct poptContext_s * poptContext;
201 /*@=exporttype@*/
202 
205 #ifndef __cplusplus
206 /*@-exporttype -typeuse@*/
207 typedef struct poptOption * poptOption;
208 /*@=exporttype =typeuse@*/
209 #endif
210 
213 /*@-exportconst@*/
218 };
219 /*@=exportconst@*/
220 
221 #ifdef __cplusplus
222 extern "C" {
223 #endif
224 /*@-type@*/
225 
234 typedef void (*poptCallbackType) (poptContext con,
235  enum poptCallbackReason reason,
236  /*@null@*/ const struct poptOption * opt,
237  /*@null@*/ const char * arg,
238  /*@null@*/ const void * data)
239  /*@globals internalState @*/
240  /*@modifies internalState @*/;
247 /*@null@*/
248 poptContext poptFreeContext( /*@only@*/ /*@null@*/ poptContext con)
249  /*@modifies con @*/;
250 
260 /*@only@*/ /*@null@*/
261 poptContext poptGetContext(
262  /*@dependent@*/ /*@keep@*/ const char * name,
263  int argc, /*@dependent@*/ /*@keep@*/ const char ** argv,
264  /*@dependent@*/ /*@keep@*/ const struct poptOption * options,
265  unsigned int flags)
266  /*@globals internalState @*/
267  /*@modifies internalState @*/;
268 
274 /*@null@*/
275 poptContext poptFini( /*@only@*/ /*@null@*/ poptContext con)
276  /*@modifies con @*/;
277 
287 /*@only@*/ /*@null@*/ /*@unused@*/
288 poptContext poptInit(int argc, /*@dependent@*/ /*@keep@*/ const char ** argv,
289  /*@dependent@*/ /*@keep@*/ const struct poptOption * options,
290  /*@null@*/ const char * configPaths)
291  /*@globals fileSystem, internalState @*/
292  /*@modifies fileSystem, internalState @*/;
293 
298 /*@unused@*/
299 void poptResetContext(/*@null@*/poptContext con)
300  /*@modifies con @*/;
301 
307 int poptGetNextOpt(/*@null@*/poptContext con)
308  /*@globals fileSystem, internalState @*/
309  /*@modifies con, fileSystem, internalState @*/;
310 
316 /*@observer@*/ /*@null@*/ /*@unused@*/
317 char * poptGetOptArg(/*@null@*/poptContext con)
318  /*@modifies con @*/;
319 
325 /*@observer@*/ /*@null@*/ /*@unused@*/
326 const char * poptGetArg(/*@null@*/poptContext con)
327  /*@modifies con @*/;
328 
334 /*@observer@*/ /*@null@*/ /*@unused@*/
335 const char * poptPeekArg(/*@null@*/poptContext con)
336  /*@*/;
337 
343 /*@observer@*/ /*@null@*/
344 const char ** poptGetArgs(/*@null@*/poptContext con)
345  /*@modifies con @*/;
346 
353 /*@observer@*/
354 const char * poptBadOption(/*@null@*/poptContext con, unsigned int flags)
355  /*@*/;
356 
363 /*@unused@*/
364 int poptStuffArgs(poptContext con, /*@keep@*/ const char ** argv)
365  /*@modifies con @*/;
366 
376 /*@unused@*/
377 int poptAddAlias(poptContext con, struct poptAlias alias, int flags)
378  /*@modifies con @*/;
379 
387 int poptAddItem(poptContext con, poptItem newItem, int flags)
388  /*@modifies con @*/;
389 
395 int poptSaneFile(const char * fn)
396  /*@globals errno, internalState @*/
397  /*@modifies errno, internalState @*/;
398 
407 int poptReadFile(const char * fn, /*@null@*/ /*@out@*/ char ** bp,
408  /*@null@*/ /*@out@*/ size_t * nbp, int flags)
409  /*@globals errno, fileSystem, internalState @*/
410  /*@modifies *bp, *nbp, errno, fileSystem, internalState @*/;
411 #define POPT_READFILE_TRIMNEWLINES 1
412 
419 int poptReadConfigFile(poptContext con, const char * fn)
420  /*@globals errno, fileSystem, internalState @*/
421  /*@modifies con->execs, con->numExecs,
422  errno, fileSystem, internalState @*/;
423 
433 int poptReadConfigFiles(poptContext con, /*@null@*/ const char * paths)
434  /*@globals errno, fileSystem, internalState @*/
435  /*@modifies con->execs, con->numExecs,
436  errno, fileSystem, internalState @*/;
437 
444 /*@unused@*/
445 int poptReadDefaultConfig(poptContext con, /*@unused@*/ int useEnv)
446  /*@globals fileSystem, internalState @*/
447  /*@modifies con->execs, con->numExecs,
448  fileSystem, internalState @*/;
449 
461 int poptDupArgv(int argc, /*@null@*/ const char **argv,
462  /*@null@*/ /*@out@*/ int * argcPtr,
463  /*@null@*/ /*@out@*/ const char *** argvPtr)
464  /*@modifies *argcPtr, *argvPtr @*/;
465 
477 int poptParseArgvString(const char * s,
478  /*@out@*/ int * argcPtr, /*@out@*/ const char *** argvPtr)
479  /*@modifies *argcPtr, *argvPtr @*/;
480 
527 /*@-fcnuse@*/
528 int poptConfigFileToString(FILE *fp, /*@out@*/ char ** argstrp, int flags)
529  /*@globals fileSystem @*/
530  /*@modifies *fp, *argstrp, fileSystem @*/;
531 /*@=fcnuse@*/
532 
538 /*@observer@*/
539 const char * poptStrerror(const int error)
540  /*@*/;
541 
548 /*@unused@*/
549 void poptSetExecPath(poptContext con, const char * path, int allowAbsolute)
550  /*@modifies con @*/;
551 
558 void poptPrintHelp(poptContext con, FILE * fp, /*@unused@*/ int flags)
559  /*@globals fileSystem @*/
560  /*@modifies fp, fileSystem @*/;
561 
568 void poptPrintUsage(poptContext con, FILE * fp, /*@unused@*/ int flags)
569  /*@globals fileSystem @*/
570  /*@modifies fp, fileSystem @*/;
571 
577 /*@-fcnuse@*/
578 void poptSetOtherOptionHelp(poptContext con, const char * text)
579  /*@modifies con @*/;
580 /*@=fcnuse@*/
581 
587 /*@-fcnuse@*/
588 /*@observer@*/
589 const char * poptGetInvocationName(poptContext con)
590  /*@*/;
591 /*@=fcnuse@*/
592 
600 /*@-fcnuse@*/
601 int poptStrippedArgv(poptContext con, int argc, char ** argv)
602  /*@modifies *argv @*/;
603 /*@=fcnuse@*/
604 
612 /*@unused@*/
613 int poptSaveString(/*@null@*/ const char *** argvp, unsigned int argInfo,
614  /*@null@*/const char * val)
615  /*@modifies *argvp @*/;
616 
625 /*@-incondefs@*/
626 /*@unused@*/
627 int poptSaveLongLong(/*@null@*/ long long * arg, unsigned int argInfo,
628  long long aLongLong)
629  /*@globals internalState @*/
630  /*@modifies *arg, internalState @*/
631  /*@requires maxSet(arg) >= 0 /\ maxRead(arg) == 0 @*/;
632 /*@=incondefs@*/
633 
642 /*@-incondefs@*/
643 /*@unused@*/
644 int poptSaveLong(/*@null@*/ long * arg, unsigned int argInfo, long aLong)
645  /*@globals internalState @*/
646  /*@modifies *arg, internalState @*/
647  /*@requires maxSet(arg) >= 0 /\ maxRead(arg) == 0 @*/;
648 /*@=incondefs@*/
649 
658 /*@-incondefs@*/
659 /*@unused@*/
660 int poptSaveShort(/*@null@*/ short * arg, unsigned int argInfo, long aLong)
661  /*@globals internalState @*/
662  /*@modifies *arg, internalState @*/
663  /*@requires maxSet(arg) >= 0 /\ maxRead(arg) == 0 @*/;
664 /*@=incondefs@*/
665 
674 /*@-incondefs@*/
675 /*@unused@*/
676 int poptSaveInt(/*@null@*/ int * arg, unsigned int argInfo, long aLong)
677  /*@globals internalState @*/
678  /*@modifies *arg, internalState @*/
679  /*@requires maxSet(arg) >= 0 /\ maxRead(arg) == 0 @*/;
680 /*@=incondefs@*/
681 
682 /* The bit set typedef. */
683 /*@-exporttype@*/
684 typedef struct poptBits_s {
685  unsigned int bits[1];
686 } * poptBits;
687 /*@=exporttype@*/
688 
689 #define _POPT_BITS_N 1024U /* estimated population */
690 #define _POPT_BITS_M ((3U * _POPT_BITS_N) / 2U)
691 #define _POPT_BITS_K 16U /* no. of linear hash combinations */
693 /*@-exportlocal -exportvar -globuse @*/
694 /*@unchecked@*/
695 extern unsigned int _poptBitsN;
696 /*@unchecked@*/
697 extern unsigned int _poptBitsM;
698 /*@unchecked@*/
699 extern unsigned int _poptBitsK;
700 /*@=exportlocal =exportvar =globuse @*/
701 
702 /*@-exportlocal@*/
703 int poptBitsAdd(/*@null@*/poptBits bits, /*@null@*/const char * s)
704  /*@modifies bits @*/;
705 /*@=exportlocal@*/
706 int poptBitsChk(/*@null@*/poptBits bits, /*@null@*/const char * s)
707  /*@*/;
708 int poptBitsClr(/*@null@*/poptBits bits)
709  /*@modifies bits @*/;
710 /*@-exportlocal@*/
711 int poptBitsDel(/*@null@*/poptBits bits, /*@null@*/const char * s)
712  /*@modifies bits @*/;
713 /*@-fcnuse@*/
714 int poptBitsIntersect(/*@null@*/ poptBits * ap, /*@null@*/ const poptBits b)
715  /*@modifies *ap @*/;
716 int poptBitsUnion(/*@null@*/ poptBits * ap, /*@null@*/ const poptBits b)
717  /*@modifies *ap @*/;
718 int poptBitsArgs(/*@null@*/ poptContext con, /*@null@*/ poptBits * ap)
719  /*@modifies con, *ap @*/;
720 /*@=fcnuse@*/
721 /*@=exportlocal@*/
722 
730 /*@-incondefs@*/
731 /*@unused@*/
732 int poptSaveBits(/*@null@*/ poptBits * bitsp, unsigned int argInfo,
733  /*@null@*/ const char * s)
734  /*@globals _poptBitsN, _poptBitsM, _poptBitsK, internalState @*/
735  /*@modifies *bitsp, _poptBitsN, _poptBitsM, _poptBitsK, internalState @*/;
736 /*@=incondefs@*/
737 
738 /*@=type@*/
739 
740 #ifdef __cplusplus
741 }
742 #endif
743 
744 #endif
const char * poptStrerror(const int error)
Return formatted error string for popt failure.
Definition: popt.c:1707
int poptParseArgvString(const char *s, int *argcPtr, const char ***argvPtr)
Parse a string into an argument array.
Definition: poptparse.c:54
char * poptGetOptArg(poptContext con)
Return next option argument (if any).
Definition: popt.c:1553
struct poptContext_s * poptContext
Definition: popt.h:207
unsigned int _poptBitsK
Definition: popt.c:760
A popt alias argument for poptAddAlias().
Definition: popt.h:149
int poptBitsAdd(poptBits bits, const char *s)
Definition: popt.c:785
void poptPrintUsage(poptContext con, FILE *fp, int flags)
Print terse description of options.
Definition: popthelp.c:884
int poptReadConfigFile(poptContext con, const char *fn)
Read configuration file.
Definition: poptconfig.c:392
int poptReadDefaultConfig(poptContext con, int useEnv)
Read default configuration from /etc/popt and $HOME/.popt.
Definition: poptconfig.c:499
int poptSaveShort(short *arg, unsigned int argInfo, long aLong)
Save a short integer, performing logical operation with value.
Definition: popt.c:1089
int poptGetNextOpt(poptContext con)
Return value of next option found.
Definition: popt.c:1299
struct poptItem_s * poptItem
A popt alias or exec argument for poptAddItem().
int poptSaneFile(const char *fn)
Perform sanity checks on a file path.
Definition: poptconfig.c:141
struct poptBits_s * poptBits
int poptBitsClr(poptBits bits)
Definition: popt.c:827
int poptSaveLongLong(long long *arg, unsigned int argInfo, long long aLongLong)
Save a long long, performing logical operation with value.
Definition: popt.c:978
A popt alias or exec argument for poptAddItem().
Definition: popt.h:162
poptCallbackReason
Definition: popt.h:221
const char * poptGetArg(poptContext con)
Return next argument.
Definition: popt.c:1563
const char * argDescrip
Definition: popt.h:143
unsigned int argInfo
Definition: popt.h:136
int poptStuffArgs(poptContext con, const char **argv)
Add arguments to context.
Definition: popt.c:1737
poptContext poptInit(int argc, const char **argv, const struct poptOption *options, const char *configPaths)
Initialize popt context (alternative implementation).
Definition: poptconfig.c:565
void poptSetOtherOptionHelp(poptContext con, const char *text)
Provide text to replace default "[OPTION...]" in help/usage output.
Definition: popthelp.c:921
const char ** poptGetArgs(poptContext con)
Return remaining arguments.
Definition: popt.c:1579
void * arg
Definition: popt.h:138
int poptConfigFileToString(FILE *fp, char **argstrp, int flags)
Parses an input configuration file and returns an string that is a command line.
Definition: poptparse.c:131
unsigned int _poptBitsN
Definition: popt.c:756
int poptBitsChk(poptBits bits, const char *s)
Definition: popt.c:804
int poptStrippedArgv(poptContext con, int argc, char **argv)
Shuffle argv pointers to remove stripped args, returns new argc.
Definition: popt.c:1765
int poptAddItem(poptContext con, poptItem newItem, int flags)
Add alias/exec item to context.
Definition: popt.c:1654
int poptBitsUnion(poptBits *ap, const poptBits b)
Definition: popt.c:877
int poptSaveLong(long *arg, unsigned int argInfo, long aLong)
Save a long, performing logical operation with value.
Definition: popt.c:1023
int poptSaveString(const char ***argvp, unsigned int argInfo, const char *val)
Add a string to an argv array.
Definition: popt.c:953
int poptDupArgv(int argc, const char **argv, int *argcPtr, const char ***argvPtr)
Duplicate an argument array.
Definition: poptparse.c:13
int poptBitsDel(poptBits bits, const char *s)
Definition: popt.c:838
poptContext poptFreeContext(poptContext con)
Destroy context.
Definition: popt.c:1613
void poptPrintHelp(poptContext con, FILE *fp, int flags)
Print detailed description of options.
Definition: popthelp.c:663
struct poptOption * poptHelpOptionsI18N
Definition: popthelp.c:97
char shortName
Definition: popt.h:135
void poptResetContext(poptContext con)
Reinitialize popt context.
Definition: popt.c:221
void(* poptCallbackType)(poptContext con, enum poptCallbackReason reason, const struct poptOption *opt, const char *arg, const void *data)
Table callback prototype.
Definition: popt.h:241
const char * longName
Definition: popt.h:134
int poptBitsArgs(poptContext con, poptBits *ap)
Definition: popt.c:897
int val
Definition: popt.h:139
const char * poptPeekArg(poptContext con)
Peek at current argument.
Definition: popt.c:1571
const char * poptBadOption(poptContext con, unsigned int flags)
Return the option which caused the most recent error.
Definition: popt.c:1697
poptContext poptGetContext(const char *name, int argc, const char **argv, const struct poptOption *options, unsigned int flags)
Initialize popt context.
Definition: popt.c:168
void poptSetExecPath(poptContext con, const char *path, int allowAbsolute)
Limit search for executables.
Definition: popt.c:66
unsigned int _poptBitsM
Definition: popt.c:758
const char * poptGetInvocationName(poptContext con)
Return argv[0] from context.
Definition: popt.c:1760
struct poptOption * poptOption
Definition: popt.h:214
int poptBitsIntersect(poptBits *ap, const poptBits b)
Definition: popt.c:857
int poptSaveInt(int *arg, unsigned int argInfo, long aLong)
Save an integer, performing logical operation with value.
Definition: popt.c:1056
poptContext poptFini(poptContext con)
Destroy context (alternative implementation).
Definition: poptconfig.c:559
struct poptOption poptHelpOptions[]
Auto help table options.
Definition: popthelp.c:73
int poptReadConfigFiles(poptContext con, const char *paths)
Read configuration file(s).
Definition: poptconfig.c:445
struct poptOption poptAliasOptions[]
Empty table marker to enable displaying popt alias/exec options.
Definition: popthelp.c:64
const char * descrip
Definition: popt.h:141
int poptSaveBits(poptBits *bitsp, unsigned int argInfo, const char *s)
Save a string into a bit set (experimental).
Definition: popt.c:918
int poptAddAlias(poptContext con, struct poptAlias alias, int flags)
Add alias to context.
Definition: popt.c:1636
int poptReadFile(const char *fn, char **bp, size_t *nbp, int flags)
Read a file into a buffer.
Definition: poptconfig.c:159

Generated for popt by  doxygen 1.8.13