popt.h 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744
  1. /** \file popt/popt.h
  2. * \ingroup popt
  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_POPT
  8. #define H_POPT
  9. #include <stdio.h> /* for FILE * */
  10. #define POPT_OPTION_DEPTH 10
  11. /** \ingroup popt
  12. * \name Arg type identifiers
  13. */
  14. /*@{*/
  15. #define POPT_ARG_NONE 0U /*!< no arg */
  16. #define POPT_ARG_STRING 1U /*!< arg will be saved as string */
  17. #define POPT_ARG_INT 2U /*!< arg ==> int */
  18. #define POPT_ARG_LONG 3U /*!< arg ==> long */
  19. #define POPT_ARG_INCLUDE_TABLE 4U /*!< arg points to table */
  20. #define POPT_ARG_CALLBACK 5U /*!< table-wide callback... must be
  21. set first in table; arg points
  22. to callback, descrip points to
  23. callback data to pass */
  24. #define POPT_ARG_INTL_DOMAIN 6U /*!< set the translation domain
  25. for this table and any
  26. included tables; arg points
  27. to the domain string */
  28. #define POPT_ARG_VAL 7U /*!< arg should take value val */
  29. #define POPT_ARG_FLOAT 8U /*!< arg ==> float */
  30. #define POPT_ARG_DOUBLE 9U /*!< arg ==> double */
  31. #define POPT_ARG_LONGLONG 10U /*!< arg ==> long long */
  32. #define POPT_ARG_MAINCALL 16U+11U /*!< EXPERIMENTAL: return (*arg) (argc, argv) */
  33. #define POPT_ARG_ARGV 12U /*!< dupe'd arg appended to realloc'd argv array. */
  34. #define POPT_ARG_SHORT 13U /*!< arg ==> short */
  35. #define POPT_ARG_BITSET 16U+14U /*!< arg ==> bit set */
  36. #define POPT_ARG_MASK 0x000000FFU
  37. #define POPT_GROUP_MASK 0x0000FF00U
  38. /*@}*/
  39. /** \ingroup popt
  40. * \name Arg modifiers
  41. */
  42. /*@{*/
  43. #define POPT_ARGFLAG_ONEDASH 0x80000000U /*!< allow -longoption */
  44. #define POPT_ARGFLAG_DOC_HIDDEN 0x40000000U /*!< don't show in help/usage */
  45. #define POPT_ARGFLAG_STRIP 0x20000000U /*!< strip this arg from argv(only applies to long args) */
  46. #define POPT_ARGFLAG_OPTIONAL 0x10000000U /*!< arg may be missing */
  47. #define POPT_ARGFLAG_OR 0x08000000U /*!< arg will be or'ed */
  48. #define POPT_ARGFLAG_NOR 0x09000000U /*!< arg will be nor'ed */
  49. #define POPT_ARGFLAG_AND 0x04000000U /*!< arg will be and'ed */
  50. #define POPT_ARGFLAG_NAND 0x05000000U /*!< arg will be nand'ed */
  51. #define POPT_ARGFLAG_XOR 0x02000000U /*!< arg will be xor'ed */
  52. #define POPT_ARGFLAG_NOT 0x01000000U /*!< arg will be negated */
  53. #define POPT_ARGFLAG_LOGICALOPS \
  54. (POPT_ARGFLAG_OR|POPT_ARGFLAG_AND|POPT_ARGFLAG_XOR)
  55. #define POPT_BIT_SET (POPT_ARG_VAL|POPT_ARGFLAG_OR)
  56. /*!< set arg bit(s) */
  57. #define POPT_BIT_CLR (POPT_ARG_VAL|POPT_ARGFLAG_NAND)
  58. /*!< clear arg bit(s) */
  59. #define POPT_ARGFLAG_SHOW_DEFAULT 0x00800000U /*!< show default value in --help */
  60. #define POPT_ARGFLAG_RANDOM 0x00400000U /*!< random value in [1,arg] */
  61. #define POPT_ARGFLAG_TOGGLE 0x00200000U /*!< permit --[no]opt prefix toggle */
  62. /*@}*/
  63. /** \ingroup popt
  64. * \name Callback modifiers
  65. */
  66. /*@{*/
  67. #define POPT_CBFLAG_PRE 0x80000000U /*!< call the callback before parse */
  68. #define POPT_CBFLAG_POST 0x40000000U /*!< call the callback after parse */
  69. #define POPT_CBFLAG_INC_DATA 0x20000000U /*!< use data from the include line,
  70. not the subtable */
  71. #define POPT_CBFLAG_SKIPOPTION 0x10000000U /*!< don't callback with option */
  72. #define POPT_CBFLAG_CONTINUE 0x08000000U /*!< continue callbacks with option */
  73. /*@}*/
  74. /** \ingroup popt
  75. * \name Error return values
  76. */
  77. /*@{*/
  78. #define POPT_ERROR_NOARG -10 /*!< missing argument */
  79. #define POPT_ERROR_BADOPT -11 /*!< unknown option */
  80. #define POPT_ERROR_OPTSTOODEEP -13 /*!< aliases nested too deeply */
  81. #define POPT_ERROR_BADQUOTE -15 /*!< error in paramter quoting */
  82. #define POPT_ERROR_ERRNO -16 /*!< errno set, use strerror(errno) */
  83. #define POPT_ERROR_BADNUMBER -17 /*!< invalid numeric value */
  84. #define POPT_ERROR_OVERFLOW -18 /*!< number too large or too small */
  85. #define POPT_ERROR_BADOPERATION -19 /*!< mutually exclusive logical operations requested */
  86. #define POPT_ERROR_NULLARG -20 /*!< opt->arg should not be NULL */
  87. #define POPT_ERROR_MALLOC -21 /*!< memory allocation failed */
  88. #define POPT_ERROR_BADCONFIG -22 /*!< config file failed sanity test */
  89. /*@}*/
  90. /** \ingroup popt
  91. * \name poptBadOption() flags
  92. */
  93. /*@{*/
  94. #define POPT_BADOPTION_NOALIAS (1U << 0) /*!< don't go into an alias */
  95. /*@}*/
  96. /** \ingroup popt
  97. * \name poptGetContext() flags
  98. */
  99. /*@{*/
  100. #define POPT_CONTEXT_NO_EXEC (1U << 0) /*!< ignore exec expansions */
  101. #define POPT_CONTEXT_KEEP_FIRST (1U << 1) /*!< pay attention to argv[0] */
  102. #define POPT_CONTEXT_POSIXMEHARDER (1U << 2) /*!< options can't follow args */
  103. #define POPT_CONTEXT_ARG_OPTS (1U << 4) /*!< return args as options with value 0 */
  104. /*@}*/
  105. /** \ingroup popt
  106. */
  107. struct poptOption {
  108. /*@observer@*/ /*@null@*/
  109. const char * longName; /*!< may be NULL */
  110. char shortName; /*!< may be NUL */
  111. unsigned int argInfo;
  112. /*@shared@*/ /*@null@*/
  113. void * arg; /*!< depends on argInfo */
  114. int val; /*!< 0 means don't return, just update flag */
  115. /*@observer@*/ /*@null@*/
  116. const char * descrip; /*!< description for autohelp -- may be NULL */
  117. /*@observer@*/ /*@null@*/
  118. const char * argDescrip; /*!< argument description for autohelp */
  119. };
  120. /** \ingroup popt
  121. * A popt alias argument for poptAddAlias().
  122. */
  123. struct poptAlias {
  124. /*@owned@*/ /*@null@*/
  125. const char * longName; /*!< may be NULL */
  126. char shortName; /*!< may be NUL */
  127. int argc;
  128. /*@owned@*/
  129. const char ** argv; /*!< must be free()able */
  130. };
  131. /** \ingroup popt
  132. * A popt alias or exec argument for poptAddItem().
  133. */
  134. /*@-exporttype@*/
  135. typedef struct poptItem_s {
  136. struct poptOption option; /*!< alias/exec name(s) and description. */
  137. int argc; /*!< (alias) no. of args. */
  138. /*@owned@*/
  139. const char ** argv; /*!< (alias) args, must be free()able. */
  140. } * poptItem;
  141. /*@=exporttype@*/
  142. /** \ingroup popt
  143. * \name Auto-generated help/usage
  144. */
  145. /*@{*/
  146. /**
  147. * Empty table marker to enable displaying popt alias/exec options.
  148. */
  149. /*@-exportvar@*/
  150. /*@unchecked@*/ /*@observer@*/
  151. extern struct poptOption poptAliasOptions[];
  152. /*@=exportvar@*/
  153. #define POPT_AUTOALIAS { NULL, '\0', POPT_ARG_INCLUDE_TABLE, poptAliasOptions, \
  154. 0, "Options implemented via popt alias/exec:", NULL },
  155. /**
  156. * Auto help table options.
  157. */
  158. /*@-exportvar@*/
  159. /*@unchecked@*/ /*@observer@*/
  160. extern struct poptOption poptHelpOptions[];
  161. /*@=exportvar@*/
  162. /*@-exportvar@*/
  163. /*@unchecked@*/ /*@observer@*/
  164. extern struct poptOption * poptHelpOptionsI18N;
  165. /*@=exportvar@*/
  166. #define POPT_AUTOHELP { NULL, '\0', POPT_ARG_INCLUDE_TABLE, poptHelpOptions, \
  167. 0, "Help options:", NULL },
  168. #define POPT_TABLEEND { NULL, '\0', 0, NULL, 0, NULL, NULL }
  169. /*@}*/
  170. /** \ingroup popt
  171. */
  172. /*@-exporttype@*/
  173. typedef /*@abstract@*/ struct poptContext_s * poptContext;
  174. /*@=exporttype@*/
  175. /** \ingroup popt
  176. */
  177. #ifndef __cplusplus
  178. /*@-exporttype -typeuse@*/
  179. typedef struct poptOption * poptOption;
  180. /*@=exporttype =typeuse@*/
  181. #endif
  182. /** \ingroup popt
  183. */
  184. /*@-exportconst@*/
  185. enum poptCallbackReason {
  186. POPT_CALLBACK_REASON_PRE = 0,
  187. POPT_CALLBACK_REASON_POST = 1,
  188. POPT_CALLBACK_REASON_OPTION = 2
  189. };
  190. /*@=exportconst@*/
  191. #ifdef __cplusplus
  192. extern "C" {
  193. #endif
  194. /*@-type@*/
  195. /** \ingroup popt
  196. * Table callback prototype.
  197. * @param con context
  198. * @param reason reason for callback
  199. * @param opt option that triggered callback
  200. * @param arg @todo Document.
  201. * @param data @todo Document.
  202. */
  203. typedef void (*poptCallbackType) (poptContext con,
  204. enum poptCallbackReason reason,
  205. /*@null@*/ const struct poptOption * opt,
  206. /*@null@*/ const char * arg,
  207. /*@null@*/ const void * data)
  208. /*@globals internalState @*/
  209. /*@modifies internalState @*/;
  210. /** \ingroup popt
  211. * Destroy context.
  212. * @param con context
  213. * @return NULL always
  214. */
  215. /*@null@*/
  216. poptContext poptFreeContext( /*@only@*/ /*@null@*/ poptContext con)
  217. /*@modifies con @*/;
  218. /** \ingroup popt
  219. * Initialize popt context.
  220. * @param name context name (usually argv[0] program name)
  221. * @param argc no. of arguments
  222. * @param argv argument array
  223. * @param options address of popt option table
  224. * @param flags or'd POPT_CONTEXT_* bits
  225. * @return initialized popt context
  226. */
  227. /*@only@*/ /*@null@*/
  228. poptContext poptGetContext(
  229. /*@dependent@*/ /*@keep@*/ const char * name,
  230. int argc, /*@dependent@*/ /*@keep@*/ const char ** argv,
  231. /*@dependent@*/ /*@keep@*/ const struct poptOption * options,
  232. unsigned int flags)
  233. /*@globals internalState @*/
  234. /*@modifies internalState @*/;
  235. /** \ingroup popt
  236. * Destroy context (alternative implementation).
  237. * @param con context
  238. * @return NULL always
  239. */
  240. /*@null@*/
  241. poptContext poptFini( /*@only@*/ /*@null@*/ poptContext con)
  242. /*@modifies con @*/;
  243. /** \ingroup popt
  244. * Initialize popt context (alternative implementation).
  245. * This routine does poptGetContext() and then poptReadConfigFiles().
  246. * @param argc no. of arguments
  247. * @param argv argument array
  248. * @param options address of popt option table
  249. * @param configPaths colon separated file path(s) to read.
  250. * @return initialized popt context (NULL on error).
  251. */
  252. /*@only@*/ /*@null@*/ /*@unused@*/
  253. poptContext poptInit(int argc, /*@dependent@*/ /*@keep@*/ const char ** argv,
  254. /*@dependent@*/ /*@keep@*/ const struct poptOption * options,
  255. /*@null@*/ const char * configPaths)
  256. /*@globals fileSystem, internalState @*/
  257. /*@modifies fileSystem, internalState @*/;
  258. /** \ingroup popt
  259. * Reinitialize popt context.
  260. * @param con context
  261. */
  262. /*@unused@*/
  263. void poptResetContext(/*@null@*/poptContext con)
  264. /*@modifies con @*/;
  265. /** \ingroup popt
  266. * Return value of next option found.
  267. * @param con context
  268. * @return next option val, -1 on last item, POPT_ERROR_* on error
  269. */
  270. int poptGetNextOpt(/*@null@*/poptContext con)
  271. /*@globals fileSystem, internalState @*/
  272. /*@modifies con, fileSystem, internalState @*/;
  273. /** \ingroup popt
  274. * Return next option argument (if any).
  275. * @param con context
  276. * @return option argument, NULL if no argument is available
  277. */
  278. /*@observer@*/ /*@null@*/ /*@unused@*/
  279. char * poptGetOptArg(/*@null@*/poptContext con)
  280. /*@modifies con @*/;
  281. /** \ingroup popt
  282. * Return next argument.
  283. * @param con context
  284. * @return next argument, NULL if no argument is available
  285. */
  286. /*@observer@*/ /*@null@*/ /*@unused@*/
  287. const char * poptGetArg(/*@null@*/poptContext con)
  288. /*@modifies con @*/;
  289. /** \ingroup popt
  290. * Peek at current argument.
  291. * @param con context
  292. * @return current argument, NULL if no argument is available
  293. */
  294. /*@observer@*/ /*@null@*/ /*@unused@*/
  295. const char * poptPeekArg(/*@null@*/poptContext con)
  296. /*@*/;
  297. /** \ingroup popt
  298. * Return remaining arguments.
  299. * @param con context
  300. * @return argument array, NULL terminated
  301. */
  302. /*@observer@*/ /*@null@*/
  303. const char ** poptGetArgs(/*@null@*/poptContext con)
  304. /*@modifies con @*/;
  305. /** \ingroup popt
  306. * Return the option which caused the most recent error.
  307. * @param con context
  308. * @param flags
  309. * @return offending option
  310. */
  311. /*@observer@*/
  312. const char * poptBadOption(/*@null@*/poptContext con, unsigned int flags)
  313. /*@*/;
  314. /** \ingroup popt
  315. * Add arguments to context.
  316. * @param con context
  317. * @param argv argument array, NULL terminated
  318. * @return 0 on success, POPT_ERROR_OPTSTOODEEP on failure
  319. */
  320. /*@unused@*/
  321. int poptStuffArgs(poptContext con, /*@keep@*/ const char ** argv)
  322. /*@modifies con @*/;
  323. /** \ingroup popt
  324. * Add alias to context.
  325. * @todo Pass alias by reference, not value.
  326. * @deprecated Use poptAddItem instead.
  327. * @param con context
  328. * @param alias alias to add
  329. * @param flags (unused)
  330. * @return 0 on success
  331. */
  332. /*@unused@*/
  333. int poptAddAlias(poptContext con, struct poptAlias alias, int flags)
  334. /*@modifies con @*/;
  335. /** \ingroup popt
  336. * Add alias/exec item to context.
  337. * @param con context
  338. * @param newItem alias/exec item to add
  339. * @param flags 0 for alias, 1 for exec
  340. * @return 0 on success
  341. */
  342. int poptAddItem(poptContext con, poptItem newItem, int flags)
  343. /*@modifies con @*/;
  344. /** \ingroup popt
  345. * Perform sanity checks on a file path.
  346. * @param fn file name
  347. * @return 0 on OK, 1 on NOTOK.
  348. */
  349. int poptSaneFile(const char * fn)
  350. /*@globals errno, internalState @*/
  351. /*@modifies errno, internalState @*/;
  352. /**
  353. * Read a file into a buffer.
  354. * @param fn file name
  355. * @retval *bp buffer (malloc'd) (or NULL)
  356. * @retval *nbp no. of bytes in buffer (including final NUL) (or NULL)
  357. * @param flags 1 to trim escaped newlines
  358. * return 0 on success
  359. */
  360. int poptReadFile(const char * fn, /*@null@*/ /*@out@*/ char ** bp,
  361. /*@null@*/ /*@out@*/ size_t * nbp, int flags)
  362. /*@globals errno, fileSystem, internalState @*/
  363. /*@modifies *bp, *nbp, errno, fileSystem, internalState @*/;
  364. #define POPT_READFILE_TRIMNEWLINES 1
  365. /** \ingroup popt
  366. * Read configuration file.
  367. * @param con context
  368. * @param fn file name to read
  369. * @return 0 on success, POPT_ERROR_ERRNO on failure
  370. */
  371. int poptReadConfigFile(poptContext con, const char * fn)
  372. /*@globals errno, fileSystem, internalState @*/
  373. /*@modifies con->execs, con->numExecs,
  374. errno, fileSystem, internalState @*/;
  375. /** \ingroup popt
  376. * Read configuration file(s).
  377. * Colon separated files to read, looping over poptReadConfigFile().
  378. * Note that an '@' character preceeding a path in the list will
  379. * also perform additional sanity checks on the file before reading.
  380. * @param con context
  381. * @param paths colon separated file name(s) to read
  382. * @return 0 on success, POPT_ERROR_BADCONFIG on failure
  383. */
  384. int poptReadConfigFiles(poptContext con, /*@null@*/ const char * paths)
  385. /*@globals errno, fileSystem, internalState @*/
  386. /*@modifies con->execs, con->numExecs,
  387. errno, fileSystem, internalState @*/;
  388. /** \ingroup popt
  389. * Read default configuration from /etc/popt and $HOME/.popt.
  390. * @param con context
  391. * @param useEnv (unused)
  392. * @return 0 on success, POPT_ERROR_ERRNO on failure
  393. */
  394. /*@unused@*/
  395. int poptReadDefaultConfig(poptContext con, /*@unused@*/ int useEnv)
  396. /*@globals fileSystem, internalState @*/
  397. /*@modifies con->execs, con->numExecs,
  398. fileSystem, internalState @*/;
  399. /** \ingroup popt
  400. * Duplicate an argument array.
  401. * @note: The argument array is malloc'd as a single area, so only argv must
  402. * be free'd.
  403. *
  404. * @param argc no. of arguments
  405. * @param argv argument array
  406. * @retval argcPtr address of returned no. of arguments
  407. * @retval argvPtr address of returned argument array
  408. * @return 0 on success, POPT_ERROR_NOARG on failure
  409. */
  410. int poptDupArgv(int argc, /*@null@*/ const char **argv,
  411. /*@null@*/ /*@out@*/ int * argcPtr,
  412. /*@null@*/ /*@out@*/ const char *** argvPtr)
  413. /*@modifies *argcPtr, *argvPtr @*/;
  414. /** \ingroup popt
  415. * Parse a string into an argument array.
  416. * The parse allows ', ", and \ quoting, but ' is treated the same as " and
  417. * both may include \ quotes.
  418. * @note: The argument array is malloc'd as a single area, so only argv must
  419. * be free'd.
  420. *
  421. * @param s string to parse
  422. * @retval argcPtr address of returned no. of arguments
  423. * @retval argvPtr address of returned argument array
  424. */
  425. int poptParseArgvString(const char * s,
  426. /*@out@*/ int * argcPtr, /*@out@*/ const char *** argvPtr)
  427. /*@modifies *argcPtr, *argvPtr @*/;
  428. /** \ingroup popt
  429. * Parses an input configuration file and returns an string that is a
  430. * command line. For use with popt. You must free the return value when done.
  431. *
  432. * Given the file:
  433. \verbatim
  434. # this line is ignored
  435. # this one too
  436. aaa
  437. bbb
  438. ccc
  439. bla=bla
  440. this_is = fdsafdas
  441. bad_line=
  442. reall bad line
  443. reall bad line = again
  444. 5555= 55555
  445. test = with lots of spaces
  446. \endverbatim
  447. *
  448. * The result is:
  449. \verbatim
  450. --aaa --bbb --ccc --bla="bla" --this_is="fdsafdas" --5555="55555" --test="with lots of spaces"
  451. \endverbatim
  452. *
  453. * Passing this to poptParseArgvString() yields an argv of:
  454. \verbatim
  455. '--aaa'
  456. '--bbb'
  457. '--ccc'
  458. '--bla=bla'
  459. '--this_is=fdsafdas'
  460. '--5555=55555'
  461. '--test=with lots of spaces'
  462. \endverbatim
  463. *
  464. * @bug NULL is returned if file line is too long.
  465. * @bug Silently ignores invalid lines.
  466. *
  467. * @param fp file handle to read
  468. * @param *argstrp return string of options (malloc'd)
  469. * @param flags unused
  470. * @return 0 on success
  471. * @see poptParseArgvString
  472. */
  473. /*@-fcnuse@*/
  474. int poptConfigFileToString(FILE *fp, /*@out@*/ char ** argstrp, int flags)
  475. /*@globals fileSystem @*/
  476. /*@modifies *fp, *argstrp, fileSystem @*/;
  477. /*@=fcnuse@*/
  478. /** \ingroup popt
  479. * Return formatted error string for popt failure.
  480. * @param error popt error
  481. * @return error string
  482. */
  483. /*@observer@*/
  484. const char * poptStrerror(const int error)
  485. /*@*/;
  486. /** \ingroup popt
  487. * Limit search for executables.
  488. * @param con context
  489. * @param path single path to search for executables
  490. * @param allowAbsolute absolute paths only?
  491. */
  492. /*@unused@*/
  493. void poptSetExecPath(poptContext con, const char * path, int allowAbsolute)
  494. /*@modifies con @*/;
  495. /** \ingroup popt
  496. * Print detailed description of options.
  497. * @param con context
  498. * @param fp ouput file handle
  499. * @param flags (unused)
  500. */
  501. void poptPrintHelp(poptContext con, FILE * fp, /*@unused@*/ int flags)
  502. /*@globals fileSystem @*/
  503. /*@modifies fp, fileSystem @*/;
  504. /** \ingroup popt
  505. * Print terse description of options.
  506. * @param con context
  507. * @param fp ouput file handle
  508. * @param flags (unused)
  509. */
  510. void poptPrintUsage(poptContext con, FILE * fp, /*@unused@*/ int flags)
  511. /*@globals fileSystem @*/
  512. /*@modifies fp, fileSystem @*/;
  513. /** \ingroup popt
  514. * Provide text to replace default "[OPTION...]" in help/usage output.
  515. * @param con context
  516. * @param text replacement text
  517. */
  518. /*@-fcnuse@*/
  519. void poptSetOtherOptionHelp(poptContext con, const char * text)
  520. /*@modifies con @*/;
  521. /*@=fcnuse@*/
  522. /** \ingroup popt
  523. * Return argv[0] from context.
  524. * @param con context
  525. * @return argv[0]
  526. */
  527. /*@-fcnuse@*/
  528. /*@observer@*/
  529. const char * poptGetInvocationName(poptContext con)
  530. /*@*/;
  531. /*@=fcnuse@*/
  532. /** \ingroup popt
  533. * Shuffle argv pointers to remove stripped args, returns new argc.
  534. * @param con context
  535. * @param argc no. of args
  536. * @param argv arg vector
  537. * @return new argc
  538. */
  539. /*@-fcnuse@*/
  540. int poptStrippedArgv(poptContext con, int argc, char ** argv)
  541. /*@modifies *argv @*/;
  542. /*@=fcnuse@*/
  543. /**
  544. * Add a string to an argv array.
  545. * @retval *argvp argv array
  546. * @param argInfo (unused)
  547. * @param val string arg to add (using strdup)
  548. * @return 0 on success, POPT_ERROR_NULLARG/POPT_ERROR_BADOPERATION
  549. */
  550. /*@unused@*/
  551. int poptSaveString(/*@null@*/ const char *** argvp, unsigned int argInfo,
  552. /*@null@*/const char * val)
  553. /*@modifies *argvp @*/;
  554. /**
  555. * Save a long long, performing logical operation with value.
  556. * @warning Alignment check may be too strict on certain platorms.
  557. * @param arg integer pointer, aligned on int boundary.
  558. * @param argInfo logical operation (see POPT_ARGFLAG_*)
  559. * @param aLongLong value to use
  560. * @return 0 on success, POPT_ERROR_NULLARG/POPT_ERROR_BADOPERATION
  561. */
  562. /*@-incondefs@*/
  563. /*@unused@*/
  564. int poptSaveLongLong(/*@null@*/ long long * arg, unsigned int argInfo,
  565. long long aLongLong)
  566. /*@globals internalState @*/
  567. /*@modifies *arg, internalState @*/
  568. /*@requires maxSet(arg) >= 0 /\ maxRead(arg) == 0 @*/;
  569. /*@=incondefs@*/
  570. /**
  571. * Save a long, performing logical operation with value.
  572. * @warning Alignment check may be too strict on certain platorms.
  573. * @param arg integer pointer, aligned on int boundary.
  574. * @param argInfo logical operation (see POPT_ARGFLAG_*)
  575. * @param aLong value to use
  576. * @return 0 on success, POPT_ERROR_NULLARG/POPT_ERROR_BADOPERATION
  577. */
  578. /*@-incondefs@*/
  579. /*@unused@*/
  580. int poptSaveLong(/*@null@*/ long * arg, unsigned int argInfo, long aLong)
  581. /*@globals internalState @*/
  582. /*@modifies *arg, internalState @*/
  583. /*@requires maxSet(arg) >= 0 /\ maxRead(arg) == 0 @*/;
  584. /*@=incondefs@*/
  585. /**
  586. * Save a short integer, performing logical operation with value.
  587. * @warning Alignment check may be too strict on certain platorms.
  588. * @param arg short pointer, aligned on short boundary.
  589. * @param argInfo logical operation (see POPT_ARGFLAG_*)
  590. * @param aLong value to use
  591. * @return 0 on success, POPT_ERROR_NULLARG/POPT_ERROR_BADOPERATION
  592. */
  593. /*@-incondefs@*/
  594. /*@unused@*/
  595. int poptSaveShort(/*@null@*/ short * arg, unsigned int argInfo, long aLong)
  596. /*@globals internalState @*/
  597. /*@modifies *arg, internalState @*/
  598. /*@requires maxSet(arg) >= 0 /\ maxRead(arg) == 0 @*/;
  599. /*@=incondefs@*/
  600. /**
  601. * Save an integer, performing logical operation with value.
  602. * @warning Alignment check may be too strict on certain platorms.
  603. * @param arg integer pointer, aligned on int boundary.
  604. * @param argInfo logical operation (see POPT_ARGFLAG_*)
  605. * @param aLong value to use
  606. * @return 0 on success, POPT_ERROR_NULLARG/POPT_ERROR_BADOPERATION
  607. */
  608. /*@-incondefs@*/
  609. /*@unused@*/
  610. int poptSaveInt(/*@null@*/ int * arg, unsigned int argInfo, long aLong)
  611. /*@globals internalState @*/
  612. /*@modifies *arg, internalState @*/
  613. /*@requires maxSet(arg) >= 0 /\ maxRead(arg) == 0 @*/;
  614. /*@=incondefs@*/
  615. /* The bit set typedef. */
  616. /*@-exporttype@*/
  617. typedef struct poptBits_s {
  618. unsigned int bits[1];
  619. } * poptBits;
  620. /*@=exporttype@*/
  621. #define _POPT_BITS_N 1024U /* estimated population */
  622. #define _POPT_BITS_M ((3U * _POPT_BITS_N) / 2U)
  623. #define _POPT_BITS_K 16U /* no. of linear hash combinations */
  624. /*@-exportlocal -exportvar -globuse @*/
  625. /*@unchecked@*/
  626. extern unsigned int _poptBitsN;
  627. /*@unchecked@*/
  628. extern unsigned int _poptBitsM;
  629. /*@unchecked@*/
  630. extern unsigned int _poptBitsK;
  631. /*@=exportlocal =exportvar =globuse @*/
  632. /*@-exportlocal@*/
  633. int poptBitsAdd(/*@null@*/poptBits bits, /*@null@*/const char * s)
  634. /*@modifies bits @*/;
  635. /*@=exportlocal@*/
  636. int poptBitsChk(/*@null@*/poptBits bits, /*@null@*/const char * s)
  637. /*@*/;
  638. int poptBitsClr(/*@null@*/poptBits bits)
  639. /*@modifies bits @*/;
  640. /*@-exportlocal@*/
  641. int poptBitsDel(/*@null@*/poptBits bits, /*@null@*/const char * s)
  642. /*@modifies bits @*/;
  643. /*@-fcnuse@*/
  644. int poptBitsIntersect(/*@null@*/ poptBits * ap, /*@null@*/ const poptBits b)
  645. /*@modifies *ap @*/;
  646. int poptBitsUnion(/*@null@*/ poptBits * ap, /*@null@*/ const poptBits b)
  647. /*@modifies *ap @*/;
  648. int poptBitsArgs(/*@null@*/ poptContext con, /*@null@*/ poptBits * ap)
  649. /*@modifies con, *ap @*/;
  650. /*@=fcnuse@*/
  651. /*@=exportlocal@*/
  652. /**
  653. * Save a string into a bit set (experimental).
  654. * @retval *bits bit set (lazily malloc'd if NULL)
  655. * @param argInfo logical operation (see POPT_ARGFLAG_*)
  656. * @param s string to add to bit set
  657. * @return 0 on success, POPT_ERROR_NULLARG/POPT_ERROR_BADOPERATION
  658. */
  659. /*@-incondefs@*/
  660. /*@unused@*/
  661. int poptSaveBits(/*@null@*/ poptBits * bitsp, unsigned int argInfo,
  662. /*@null@*/ const char * s)
  663. /*@globals _poptBitsN, _poptBitsM, _poptBitsK, internalState @*/
  664. /*@modifies *bitsp, _poptBitsN, _poptBitsM, _poptBitsK, internalState @*/;
  665. /*@=incondefs@*/
  666. /*@=type@*/
  667. #ifdef __cplusplus
  668. }
  669. #endif
  670. #endif