options.h 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263
  1. /* -*- buffer-read-only: t -*- vi: set ro:
  2. *
  3. * DO NOT EDIT THIS FILE (options.h)
  4. *
  5. * It has been AutoGen-ed
  6. * From the definitions funcs.def
  7. * and the template file options_h
  8. *
  9. * This file defines all the global structures and special values
  10. * used in the automated option processing library.
  11. *
  12. * Automated Options Copyright (C) 1992-2018 by Bruce Korb
  13. *
  14. * This file is part of AutoOpts, a companion to AutoGen.
  15. * AutoOpts is free software.
  16. * AutoOpts is Copyright (C) 1992-2018 by Bruce Korb - all rights reserved
  17. *
  18. * AutoOpts is available under any one of two licenses. The license
  19. * in use must be one of these two and the choice is under the control
  20. * of the user of the license.
  21. *
  22. * The GNU Lesser General Public License, version 3 or later
  23. * See the files "COPYING.lgplv3" and "COPYING.gplv3"
  24. *
  25. * The Modified Berkeley Software Distribution License
  26. * See the file "COPYING.mbsd"
  27. *
  28. * These files have the following sha256 sums:
  29. *
  30. * 8584710e9b04216a394078dc156b781d0b47e1729104d666658aecef8ee32e95 COPYING.gplv3
  31. * 4379e7444a0e2ce2b12dd6f5a52a27a4d02d39d247901d3285c88cf0d37f477b COPYING.lgplv3
  32. * 13aa749a5b0a454917a944ed8fffc530b784f5ead522b1aacaf4ec8aa55a6239 COPYING.mbsd
  33. */
  34. #ifndef AUTOOPTS_OPTIONS_H_GUARD
  35. #define AUTOOPTS_OPTIONS_H_GUARD 1
  36. /** \file options.h
  37. *
  38. * @addtogroup autoopts
  39. * @{
  40. */
  41. #include <sys/types.h>
  42. #include <stdio.h>
  43. #ifndef COMPAT_H_GUARD
  44. /*
  45. * This is needed for test compilations where the "compat.h"
  46. * header is not usually available.
  47. */
  48. # if defined(HAVE_STDINT_H)
  49. # include <stdint.h>
  50. # elif defined(HAVE_INTTYPES_H)
  51. # include <inttypes.h>
  52. # endif /* HAVE_STDINT/INTTYPES_H */
  53. # if defined(HAVE_LIMITS_H)
  54. # include <limits.h>
  55. # elif defined(HAVE_SYS_LIMITS_H)
  56. # include <sys/limits.h>
  57. # endif /* HAVE_LIMITS/SYS_LIMITS_H */
  58. # if defined(HAVE_SYSEXITS_H)
  59. # include <sysexits.h>
  60. # endif /* HAVE_SYSEXITS_H */
  61. # if defined(HAVE_STDBOOL_H)
  62. # include <stdbool.h>
  63. # elif ! defined(bool)
  64. typedef enum { false = 0, true = 1 } _Bool;
  65. # define bool _Bool
  66. /* The other macros must be usable in preprocessor directives. */
  67. # define false 0
  68. # define true 1
  69. # endif /* HAVE_SYSEXITS_H */
  70. #endif /* COMPAT_H_GUARD */
  71. // END-CONFIGURED-HEADERS
  72. /**
  73. * Defined to abnormal value of EX_USAGE. Used to indicate that paged usage
  74. * was requested. It is used to distinguish a --usage from a --help request.
  75. * --usage is abbreviated and --help gives as much help as possible.
  76. */
  77. #define AO_EXIT_REQ_USAGE 10064
  78. #undef VOIDP
  79. /**
  80. * Coerce a value into a void pointer with no const or volatile attributes.
  81. * Somewhere along the line, the above set of includes need to set up
  82. * the "uintptr_t" type.
  83. */
  84. #define VOIDP(_a) ((void *)(uintptr_t)(_a))
  85. /**
  86. * PUBLIC DEFINES
  87. *
  88. * The following defines may be used in applications that need to test the
  89. * state of an option. To test against these masks and values, a pointer
  90. * to an option descriptor must be obtained. There are two ways:
  91. *
  92. * 1. inside an option processing procedure, it is the second argument,
  93. * conventionally "tOptDesc * pOD".
  94. *
  95. * 2. Outside of an option procedure (or to reference a different option
  96. * descriptor), use either "&DESC( opt_name )" or "&pfx_DESC( opt_name )".
  97. *
  98. * See the relevant generated header file to determine which and what
  99. * values for "opt_name" are available.
  100. * @group version
  101. * @{
  102. */
  103. /// autoopts structure version
  104. #define OPTIONS_STRUCT_VERSION 172033
  105. /// autoopts structure version string
  106. #define OPTIONS_VERSION_STRING "42:1:17"
  107. /// minimum version the autoopts library supports
  108. #define OPTIONS_MINIMUM_VERSION 102400
  109. /// minimum version the autoopts library supports as a string
  110. #define OPTIONS_MIN_VER_STRING "25:0:0"
  111. /// the display version of the autoopts library, as a string
  112. #define OPTIONS_DOTTED_VERSION "42.1"
  113. /// convert a version/release number pair to an integer value
  114. #define OPTIONS_VER_TO_NUM(_v, _r) (((_v) * 4096) + (_r))
  115. /// @}
  116. /**
  117. * Option argument types. This must fit in the OPTST_ARG_TYPE_MASK
  118. * field of the fOptState field of an option descriptor (tOptDesc).
  119. * It will be a problem to extend beyond 4 bits.
  120. */
  121. typedef enum {
  122. OPARG_TYPE_NONE = 0, ///< does not take an argument
  123. OPARG_TYPE_STRING = 1, ///< default type/ vanilla string
  124. OPARG_TYPE_ENUMERATION = 2, ///< opt arg is an enum (keyword list)
  125. OPARG_TYPE_BOOLEAN = 3, ///< opt arg is boolean-valued
  126. OPARG_TYPE_MEMBERSHIP = 4, ///< opt arg sets set membership bits
  127. OPARG_TYPE_NUMERIC = 5, ///< opt arg is a long int
  128. OPARG_TYPE_HIERARCHY = 6, ///< option arg is hierarchical value
  129. OPARG_TYPE_FILE = 7, ///< option arg names a file
  130. OPARG_TYPE_TIME = 8, ///< opt arg is a time duration
  131. OPARG_TYPE_FLOAT = 9, ///< opt arg is a floating point num
  132. OPARG_TYPE_DOUBLE = 10, ///< opt arg is a double prec. float
  133. OPARG_TYPE_LONG_DOUBLE = 11, ///< opt arg is a long double prec.
  134. OPARG_TYPE_LONG_LONG = 12, ///< opt arg is a long long int
  135. OPARG_TYPE_STATIC = 13 ///<
  136. } teOptArgType;
  137. /**
  138. * value descriptor for sub options
  139. */
  140. typedef struct optionValue {
  141. teOptArgType valType; ///< which argument type
  142. char * pzName; ///< name of the sub-option
  143. union {
  144. char strVal[1]; ///< OPARG_TYPE_STRING
  145. unsigned int enumVal; ///< OPARG_TYPE_ENUMERATION
  146. unsigned int boolVal; ///< OPARG_TYPE_BOOLEAN
  147. unsigned long setVal; ///< OPARG_TYPE_MEMBERSHIP
  148. long longVal; ///< OPARG_TYPE_NUMERIC
  149. void * nestVal; ///< OPARG_TYPE_HIERARCHY
  150. } v;
  151. } tOptionValue;
  152. /**
  153. * file argument state and handling.
  154. */
  155. typedef enum {
  156. FTYPE_MODE_MAY_EXIST = 0x00, ///< may or may not exist
  157. FTYPE_MODE_MUST_EXIST = 0x01, ///< must pre-exist
  158. FTYPE_MODE_MUST_NOT_EXIST = 0x02, ///< must *not* pre-exist
  159. FTYPE_MODE_EXIST_MASK = 0x03, ///< mask for these bits
  160. FTYPE_MODE_NO_OPEN = 0x00, ///< leave file closed
  161. FTYPE_MODE_OPEN_FD = 0x10, ///< call open(2)
  162. FTYPE_MODE_FOPEN_FP = 0x20, ///< call fopen(3)
  163. FTYPE_MODE_OPEN_MASK = 0x30 ///< open/fopen/not open
  164. } teOptFileType;
  165. /**
  166. * the open flag bits or the mode string, depending on the open type.
  167. */
  168. typedef union {
  169. int file_flags; ///< open(2) flag bits
  170. char const * file_mode; ///< fopen(3) mode string
  171. } tuFileMode;
  172. /// initial number of option argument holders to allocate
  173. #define MIN_ARG_ALLOC_CT 6
  174. /// amount by which to increment the argument holder allocation.
  175. #define INCR_ARG_ALLOC_CT 8
  176. /**
  177. * an argument list. When an option appears multiple times and
  178. * the values get "stacked". \a apzArgs holds 8 pointers initially
  179. * and is incremented by \a INCR_ARG_ALLOC_CT as needed.
  180. */
  181. typedef struct {
  182. int useCt; ///< elements in use
  183. /// allocated elements, mininum \a MIN_ARG_ALLOC_CT
  184. /// steps by \a INCR_ARG_ALLOC_CT
  185. int allocCt;
  186. char const * apzArgs[MIN_ARG_ALLOC_CT]; ///< element array
  187. } tArgList;
  188. /**
  189. * Bits in the fOptState option descriptor field.
  190. * @{
  191. */
  192. /** integral type for holding opt_state masks */
  193. typedef uint32_t opt_state_mask_t;
  194. #define OPTST_ARG_TYPE_SHIFT 12
  195. /** bits defined for opt_state_mask_t */
  196. /** Set via the "SET_OPT()" macro */
  197. #define OPTST_SET 0x0000001U
  198. /** Set via an RC/INI file */
  199. #define OPTST_PRESET 0x0000002U
  200. /** Set via a command line option */
  201. #define OPTST_DEFINED 0x0000004U
  202. /** Reset via command line option */
  203. #define OPTST_RESET 0x0000008U
  204. /** selected by equiv'ed option */
  205. #define OPTST_EQUIVALENCE 0x0000010U
  206. /** option is in disabled state */
  207. #define OPTST_DISABLED 0x0000020U
  208. /** pzOptArg was allocated */
  209. #define OPTST_ALLOC_ARG 0x0000040U
  210. /** option cannot be preset */
  211. #define OPTST_NO_INIT 0x0000100U
  212. /** opt value (flag) is any digit */
  213. #define OPTST_NUMBER_OPT 0x0000200U
  214. /** opt uses optionStackArg proc */
  215. #define OPTST_STACKED 0x0000400U
  216. /** option defaults to enabled */
  217. #define OPTST_INITENABLED 0x0000800U
  218. /** bit 1 of arg type enum */
  219. #define OPTST_ARG_TYPE_1 0x0001000U
  220. /** bit 2 of arg type enum */
  221. #define OPTST_ARG_TYPE_2 0x0002000U
  222. /** bit 3 of arg type enum */
  223. #define OPTST_ARG_TYPE_3 0x0004000U
  224. /** bit 4 of arg type enum */
  225. #define OPTST_ARG_TYPE_4 0x0008000U
  226. /** the option arg not required */
  227. #define OPTST_ARG_OPTIONAL 0x0010000U
  228. /** process opt on first pass */
  229. #define OPTST_IMM 0x0020000U
  230. /** process disablement immed. */
  231. #define OPTST_DISABLE_IMM 0x0040000U
  232. /** compiled out of program */
  233. #define OPTST_OMITTED 0x0080000U
  234. /** must be set or pre-set */
  235. #define OPTST_MUST_SET 0x0100000U
  236. /** opt is for doc only */
  237. #define OPTST_DOCUMENT 0x0200000U
  238. /** process opt twice - imm + reg */
  239. #define OPTST_TWICE 0x0400000U
  240. /** process disabled option twice */
  241. #define OPTST_DISABLE_TWICE 0x0800000U
  242. /** scaled integer value */
  243. #define OPTST_SCALED_NUM 0x1000000U
  244. /** disable from cmd line */
  245. #define OPTST_NO_COMMAND 0x2000000U
  246. /** support is being removed */
  247. #define OPTST_DEPRECATED 0x4000000U
  248. /** alias for other option */
  249. #define OPTST_ALIAS 0x8000000U
  250. /** bits in SET mask:
  251. * set preset reset defined */
  252. #define OPTST_SET_MASK 0x000000FU
  253. /** bits in MUTABLE mask:
  254. * set preset reset defined equivalence disabled
  255. * alloc_arg */
  256. #define OPTST_MUTABLE_MASK 0x000007FU
  257. /** bits omitted from PERSISTENT mask:
  258. * mutable_mask */
  259. #define OPTST_PERSISTENT_MASK 0xFFFFF00U
  260. /** bits in SELECTED mask:
  261. * set defined */
  262. #define OPTST_SELECTED_MASK 0x0000005U
  263. /** bits in ARG_TYPE mask:
  264. * arg_type_1 arg_type_2 arg_type_3 arg_type_4 */
  265. #define OPTST_ARG_TYPE_MASK 0x000F000U
  266. /** bits in NO_USAGE mask:
  267. * omitted no_command deprecated */
  268. #define OPTST_NO_USAGE_MASK 0x6080000U
  269. /** bits in IMMUTABLE mask:
  270. * document omitted */
  271. #define OPTST_IMMUTABLE_MASK 0x0280000U
  272. /** bits in DO_NOT_SAVE mask:
  273. * document omitted no_init */
  274. #define OPTST_DO_NOT_SAVE_MASK 0x0280100U
  275. /** bits in NO_OUTPUT mask:
  276. * document omitted alias */
  277. #define OPTST_NO_OUTPUT_MASK 0x8280000U
  278. /** all bits in opt_state_mask_t masks */
  279. #define OPTST_MASK_ALL 0xFFFFF7FU
  280. /** no bits in opt_state_mask_t */
  281. #define OPTST_INIT 0x0000000U
  282. /** @} */
  283. #ifdef NO_OPTIONAL_OPT_ARGS
  284. # undef OPTST_ARG_OPTIONAL
  285. # define OPTST_ARG_OPTIONAL 0
  286. #endif
  287. #define VENDOR_OPTION_VALUE 'W'
  288. #define SELECTED_OPT(_od) ((_od)->fOptState & OPTST_SELECTED_MASK)
  289. #define UNUSED_OPT( _od) (((_od)->fOptState & OPTST_SET_MASK) == 0)
  290. #define DISABLED_OPT(_od) ((_od)->fOptState & OPTST_DISABLED)
  291. #define OPTION_STATE(_od) ((_od)->fOptState)
  292. #define OPTST_SET_ARGTYPE(_n) ((_n) << OPTST_ARG_TYPE_SHIFT)
  293. #define OPTST_GET_ARGTYPE(_f) \
  294. (((_f)&OPTST_ARG_TYPE_MASK) >> OPTST_ARG_TYPE_SHIFT)
  295. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  296. *
  297. * PRIVATE INTERFACES
  298. *
  299. * The following values are used in the generated code to communicate
  300. * with the option library procedures. They are not for public use
  301. * and may be subject to change.
  302. */
  303. /**
  304. * Define the processing state flags
  305. * @{
  306. */
  307. /** integral type for holding proc_state masks */
  308. typedef uint32_t proc_state_mask_t;
  309. /** bits defined for proc_state_mask_t */
  310. /** Process long style options */
  311. #define OPTPROC_LONGOPT 0x000001U
  312. /** Process short style "flags" */
  313. #define OPTPROC_SHORTOPT 0x000002U
  314. /** Stop on argument errors */
  315. #define OPTPROC_ERRSTOP 0x000004U
  316. /** Current option is disabled */
  317. #define OPTPROC_DISABLEDOPT 0x000008U
  318. /** no options are required */
  319. #define OPTPROC_NO_REQ_OPT 0x000010U
  320. /** there is a number option */
  321. #define OPTPROC_NUM_OPT 0x000020U
  322. /** have inits been done? */
  323. #define OPTPROC_INITDONE 0x000040U
  324. /** any negation options? */
  325. #define OPTPROC_NEGATIONS 0x000080U
  326. /** check environment? */
  327. #define OPTPROC_ENVIRON 0x000100U
  328. /** Disallow remaining arguments */
  329. #define OPTPROC_NO_ARGS 0x000200U
  330. /** Require args after options */
  331. #define OPTPROC_ARGS_REQ 0x000400U
  332. /** reorder operands after opts */
  333. #define OPTPROC_REORDER 0x000800U
  334. /** emit usage in GNU style */
  335. #define OPTPROC_GNUUSAGE 0x001000U
  336. /** Translate strings in tOptions */
  337. #define OPTPROC_TRANSLATE 0x002000U
  338. /** no usage on usage error */
  339. #define OPTPROC_MISUSE 0x004000U
  340. /** immediate options active */
  341. #define OPTPROC_IMMEDIATE 0x008000U
  342. /** suppress for config only */
  343. #define OPTPROC_NXLAT_OPT_CFG 0x010000U
  344. /** suppress xlation always */
  345. #define OPTPROC_NXLAT_OPT 0x020000U
  346. /** vendor options active */
  347. #define OPTPROC_VENDOR_OPT 0x040000U
  348. /** opt processing in preset state */
  349. #define OPTPROC_PRESETTING 0x080000U
  350. /** Ignore pzFullUsage, compute usage text */
  351. #define OPTPROC_COMPUTE 0x100000U
  352. /** Program outputs digested option state for shell scripts. Usage text
  353. * always written to stderr */
  354. #define OPTPROC_SHELL_OUTPUT 0x200000U
  355. /** bits in NO_XLAT mask:
  356. * nxlat_opt_cfg nxlat_opt */
  357. #define OPTPROC_NO_XLAT_MASK 0x030000U
  358. /** all bits in proc_state_mask_t masks */
  359. #define OPTPROC_MASK_ALL 0x3FFFFFU
  360. /** no bits in proc_state_mask_t */
  361. #define OPTPROC_NONE 0x000000U
  362. /** @} */
  363. #define STMTS(s) do { s; } while (false)
  364. /**
  365. * Abbreviation for const memory character.
  366. */
  367. #define tCC char const
  368. /**
  369. * Magical values for the program's option pointer
  370. * @{
  371. */
  372. typedef enum {
  373. OP_VAL_EMIT_USAGE = 1, ///< request for usage
  374. OP_VAL_EMIT_SHELL = 2, ///< emit value for Bourne shell evaluation
  375. OP_VAL_RETURN_VALNAME = 3, ///< return the value as a string
  376. OP_VAL_EMIT_LIMIT = 15 ///< limit for magic values
  377. } opt_proc_vals_t;
  378. /// \a OPT_VAL_EMIT_USAGE cast as a pointer
  379. #define OPTPROC_EMIT_USAGE ((tOptions *)OP_VAL_EMIT_USAGE)
  380. /// \a OPT_VAL_EMIT_SHELL cast as a pointer
  381. #define OPTPROC_EMIT_SHELL ((tOptions *)OP_VAL_EMIT_SHELL)
  382. /// \a OPT_VAL_RETURN_VALNAME cast as a pointer
  383. #define OPTPROC_RETURN_VALNAME ((tOptions *)OP_VAL_RETURN_VALNAME)
  384. /// \a OPT_VAL_EMIT_LIMIT cast as a pointer
  385. #define OPTPROC_EMIT_LIMIT ((tOptions *)OP_VAL_EMIT_LIMIT)
  386. /** @} */
  387. /** group option processing procedure types
  388. * @{
  389. */
  390. /** forward declaration for tOptDesc */
  391. typedef struct opt_desc tOptDesc;
  392. /** forward declaration for tOptiond */
  393. typedef struct options tOptions;
  394. /**
  395. * The option procedures do the special processing for each
  396. * option flag that needs it.
  397. */
  398. typedef void (tOptProc)(tOptions * pOpts, tOptDesc * pOptDesc);
  399. /**
  400. * a pointer to an option processing procedure
  401. */
  402. typedef tOptProc * tpOptProc;
  403. /**
  404. * The usage procedure will never return. It calls "exit(2)"
  405. * with the "exitCode" argument passed to it.
  406. */
  407. // coverity[+kill]
  408. typedef void (tUsageProc)(tOptions * pOpts, int exitCode);
  409. /**
  410. * a pointer to a procedure that prints usage and exits.
  411. */
  412. typedef tUsageProc * tpUsageProc;
  413. /** @} */
  414. /**
  415. * Special definitions. "NOLIMIT" is the 'max' value to use when
  416. * a flag may appear multiple times without limit. "NO_EQUIVALENT"
  417. * is an illegal value for 'optIndex' (option description index).
  418. * @{
  419. */
  420. #define NOLIMIT USHRT_MAX ///< no occurrance count limit
  421. #define OPTION_LIMIT SHRT_MAX ///< maximum number of option types
  422. /// option index to indicate no equivalance or alias
  423. #define NO_EQUIVALENT (OPTION_LIMIT+1)
  424. /** @} */
  425. /**
  426. * Option argument value. Which is valid is determined by:
  427. * (fOptState & OPTST_ARG_TYPE_MASK) >> OPTST_ARG_TYPE_SHIFT
  428. * which will yield one of the teOptArgType values.
  429. */
  430. typedef union {
  431. char const * argString; ///< as a string
  432. uintptr_t argEnum; ///< as an enumeration value
  433. uintptr_t argIntptr; ///< as an integer big enough to hold pointer
  434. long argInt; ///< as a long integer
  435. unsigned long argUint; ///< as an unsigned long ingeger
  436. unsigned int argBool; ///< as a boolean value
  437. FILE * argFp; ///< as a FILE * pointer
  438. int argFd; ///< as a file descriptor (int)
  439. } opt_arg_union_t;
  440. /// Compatibility define: \a pzLastArg is now \a optArg.argString
  441. #define pzLastArg optArg.argString
  442. /// The old amorphous argument bucket is now the opt_arg_union_t union.
  443. #define optArgBucket_t opt_arg_union_t
  444. /**
  445. * Enumeration of AutoOpts defined options. The enumeration is used in
  446. * marking each option that is defined by AutoOpts so libopts can find
  447. * the correct descriptor. This renders \a option_spec_idx_t redundant.
  448. */
  449. typedef enum {
  450. AOUSE_USER_DEFINED = 0, ///< user specified option
  451. AOUSE_RESET_OPTION, ///< reset option state option
  452. AOUSE_VERSION, ///< request version
  453. AOUSE_HELP, ///< request usage help
  454. AOUSE_MORE_HELP, ///< request paged usage
  455. AOUSE_USAGE, ///< request short usage
  456. AOUSE_SAVE_OPTS, ///< save option state
  457. AOUSE_LOAD_OPTS, ///< load options from file
  458. AOUSE_VENDOR_OPT ///< specify a vendor option
  459. } opt_usage_t;
  460. /**
  461. * Descriptor structure for each option.
  462. * Only the fields marked "PUBLIC" are for public use.
  463. */
  464. struct opt_desc {
  465. /// Public, the index of this descriptor
  466. uint16_t const optIndex;
  467. /// Public, the flag character (value)
  468. uint16_t const optValue;
  469. /// Public, the index of the option used to activate option
  470. uint16_t optActualIndex;
  471. /// Public, the flag character of the activating option
  472. uint16_t optActualValue;
  473. /// Public, the index of the equivalenced-to option.
  474. /// This is NO_EQUIVALENT unless activated.
  475. uint16_t const optEquivIndex;
  476. /// Private, the minimum occurrance count
  477. uint16_t const optMinCt;
  478. /// Private, the maximum occurrance count (NOLIMIT, if unlimited)
  479. uint16_t const optMaxCt;
  480. /// Public, the actual occurrance count
  481. uint16_t optOccCt;
  482. /// Public, the option processing state
  483. opt_state_mask_t fOptState;
  484. /// Private, how the option is used (opt_usage_t)
  485. uint32_t optUsage;
  486. /// Public, The current option argument value
  487. opt_arg_union_t optArg;
  488. /// Public, data that is actually private to the code that handles
  489. /// this particular option. It is public IFF you have your own
  490. /// handling function.
  491. void * optCookie;
  492. /// Private, a list of options that must be specified when this option
  493. /// has been specified
  494. int const * const pOptMust;
  495. /// Private, a list of options that cannot be specified when this option
  496. /// has been specified
  497. int const * const pOptCant;
  498. /// Private, the function to call for handling this option
  499. tpOptProc const pOptProc;
  500. /// Private, usage information about this option
  501. char const * const pzText;
  502. /// Public, the UPPER CASE, shell variable name syntax name of the option
  503. char const * const pz_NAME;
  504. /// the unmodified name of the option
  505. char const * const pz_Name;
  506. /// the option name to use to disable the option. Long options names
  507. /// must be active.
  508. char const * const pz_DisableName;
  509. /// the special prefix that makes the normal option name become the
  510. /// disablement name.
  511. char const * const pz_DisablePfx;
  512. };
  513. /**
  514. * Some options need special processing, so we store their
  515. * indexes in a known place.
  516. */
  517. typedef struct {
  518. uint16_t const more_help; ///< passes help text through pager
  519. uint16_t const save_opts; ///< stores option state to a file
  520. uint16_t const number_option; ///< the option "name" is an integer
  521. /// all arguments are options, this is the default option that must
  522. /// take an argument. That argument is the unrecognized option.
  523. uint16_t const default_opt;
  524. } option_spec_idx_t;
  525. /**
  526. * The procedure generated for translating option text
  527. */
  528. typedef void (tOptionXlateProc)(void);
  529. /**
  530. * Everything marked "PUBLIC" is also marked "const". Public access is not
  531. * a license to modify. Other fields are used and modified by the library.
  532. * They are also subject to change without any notice.
  533. * Do not even look at these outside of libopts.
  534. */
  535. struct options {
  536. int const structVersion; ///< The version of this struct
  537. unsigned int origArgCt; ///< program argument count
  538. char ** origArgVect; ///< program argument vector
  539. proc_state_mask_t fOptSet; ///< option proc. state flags
  540. unsigned int curOptIdx; ///< current option index
  541. char * pzCurOpt; ///< current option text
  542. /// Public, the full path of the program
  543. char const * const pzProgPath;
  544. /// Public, the name of the executable, without any path
  545. char const * const pzProgName;
  546. /// Public, the upper-cased, shell variable syntax-ed program name
  547. char const * const pzPROGNAME;
  548. /// the name of the "rc file" (configuration file)
  549. char const * const pzRcName;
  550. /// the copyright text
  551. char const * const pzCopyright;
  552. /// the full copyright notice
  553. char const * const pzCopyNotice;
  554. /// a string with the program name, project name and version
  555. char const * const pzFullVersion;
  556. /// a list of pointers to directories to search for the config file
  557. char const * const * const papzHomeList;
  558. /// the title line for usage
  559. char const * const pzUsageTitle;
  560. /// some added explanation for what this program is trying to do
  561. char const * const pzExplain;
  562. /// a detailed explanation of the program's purpose, for use when
  563. /// full help has been requested
  564. char const * const pzDetail;
  565. /// The public array of option descriptors
  566. tOptDesc * const pOptDesc;
  567. /// the email address for reporting bugs
  568. char const * const pzBugAddr;
  569. /// Reserved for future use
  570. void * pExtensions;
  571. /// A copy of the option state when optionSaveState was called.
  572. void * pSavedState;
  573. /// The procedure to call to print usage text
  574. /* __attribute__((__noreturn__)) */
  575. // coverity[+kill]
  576. tpUsageProc pUsageProc;
  577. /// The procedure to call to translate translatable option messages
  578. tOptionXlateProc * pTransProc;
  579. /// Special option indexes.
  580. option_spec_idx_t specOptIdx;
  581. /// the total number of options for the program
  582. int const optCt;
  583. /// The number of "presettable" options, though some may be marked
  584. /// "no-preset". Includes all user specified options, plus a few
  585. /// that are specified by AutoOpts.
  586. int const presetOptCt;
  587. /// user specified full usage text
  588. char const * pzFullUsage;
  589. /// user specifed short usage (usage error triggered) message
  590. char const * pzShortUsage;
  591. /// The option argument settings active when optionSaveState was called
  592. opt_arg_union_t const * const originalOptArgArray;
  593. /// any saved cookie value
  594. void * const * const originalOptArgCookie;
  595. /// the package data directory (e.g. global configuration files)
  596. char const * const pzPkgDataDir;
  597. /// email address of the project packager
  598. char const * const pzPackager;
  599. };
  600. /*
  601. * Versions where in various fields first appear:
  602. * ($AO_CURRENT * 4096 + $AO_REVISION, but $AO_REVISION must be zero)
  603. */
  604. /**
  605. * The version that first stored the original argument vector
  606. */
  607. #define originalOptArgArray_STRUCT_VERSION 0x20000 /* AO_CURRENT = 32 */
  608. #define HAS_originalOptArgArray(_opt) \
  609. ((_opt)->structVersion >= originalOptArgArray_STRUCT_VERSION)
  610. /**
  611. * The version that first stored the package data directory
  612. */
  613. #define pzPkgDataDir_STRUCT_VERSION 0x22000 /* AO_CURRENT = 34 */
  614. #define HAS_pzPkgDataDir(_opt) \
  615. ((_opt)->structVersion >= pzPkgDataDir_STRUCT_VERSION)
  616. /**
  617. * The version that first stored the option usage in each option descriptor
  618. */
  619. #define opt_usage_t_STRUCT_VERSION 0x26000 /* AO_CURRENT = 38 */
  620. #define HAS_opt_usage_t(_opt) \
  621. ((_opt)->structVersion >= opt_usage_t_STRUCT_VERSION)
  622. /**
  623. * "token list" structure returned by "string_tokenize()"
  624. */
  625. typedef struct {
  626. unsigned long tkn_ct; ///< number of tokens found
  627. unsigned char * tkn_list[1]; ///< array of pointers to tokens
  628. } token_list_t;
  629. /*
  630. * Hide the interface - it pollutes a POSIX claim, but leave it for
  631. * anyone #include-ing this header
  632. */
  633. #define strneqvcmp option_strneqvcmp
  634. #define streqvcmp option_streqvcmp
  635. #define streqvmap option_streqvmap
  636. #define strequate option_strequate
  637. #define strtransform option_strtransform
  638. /**
  639. * Everything needed to be known about an mmap-ed file.
  640. *
  641. * This is an output only structure used by text_mmap and text_munmap.
  642. * Clients must not alter the contents and must provide it to both
  643. * the text_mmap and text_munmap procedures. BE ADVISED: if you are
  644. * mapping the file with PROT_WRITE the NUL byte at the end MIGHT NOT
  645. * BE WRITABLE. In any event, that byte is not be written back
  646. * to the source file. ALSO: if "txt_data" is valid and "txt_errno"
  647. * is not zero, then there *may* not be a terminating NUL.
  648. */
  649. typedef struct {
  650. void * txt_data; ///< text file data
  651. size_t txt_size; ///< actual file size
  652. size_t txt_full_size; ///< mmaped mem size
  653. int txt_fd; ///< file descriptor
  654. int txt_zero_fd; ///< fd for /dev/zero
  655. int txt_errno; ///< warning code
  656. int txt_prot; ///< "prot" flags
  657. int txt_flags; ///< mapping type
  658. } tmap_info_t;
  659. /**
  660. * mmap result wrapper that yields "true" when mmap has failed.
  661. */
  662. #define TEXT_MMAP_FAILED_ADDR(a) (VOIDP(a) == VOIDP(MAP_FAILED))
  663. #ifdef __cplusplus
  664. #define CPLUSPLUS_OPENER extern "C" {
  665. CPLUSPLUS_OPENER
  666. #define CPLUSPLUS_CLOSER }
  667. #else
  668. #define CPLUSPLUS_CLOSER
  669. #endif
  670. /**
  671. * The following routines may be coded into AutoOpts client code:
  672. */
  673. /**
  674. * ao_string_tokenize - tokenize an input string
  675. *
  676. * This function will convert one input string into a list of strings.
  677. * The list of strings is derived by separating the input based on
  678. * white space separation. However, if the input contains either single
  679. * or double quote characters, then the text after that character up to
  680. * a matching quote will become the string in the list.
  681. *
  682. * The returned pointer should be deallocated with @code{free(3C)} when
  683. * are done using the data. The data are placed in a single block of
  684. * allocated memory. Do not deallocate individual token/strings.
  685. *
  686. * The structure pointed to will contain at least these two fields:
  687. * @table @samp
  688. * @item tkn_ct
  689. * The number of tokens found in the input string.
  690. * @item tok_list
  691. * An array of @code{tkn_ct + 1} pointers to substring tokens, with
  692. * the last pointer set to NULL.
  693. * @end table
  694. *
  695. * There are two types of quoted strings: single quoted (@code{'}) and
  696. * double quoted (@code{"}). Singly quoted strings are fairly raw in that
  697. * escape characters (@code{\\}) are simply another character, except when
  698. * preceding the following characters:
  699. * @example
  700. * @code{\\} double backslashes reduce to one
  701. * @code{'} incorporates the single quote into the string
  702. * @code{\n} suppresses both the backslash and newline character
  703. * @end example
  704. *
  705. * Double quote strings are formed according to the rules of string
  706. * constants in ANSI-C programs.
  707. *
  708. * @param string string to be tokenized
  709. *
  710. * @return token_list_t * - pointer to a structure that lists each token
  711. */
  712. extern token_list_t * ao_string_tokenize(char const *);
  713. /**
  714. * configFileLoad - parse a configuration file
  715. *
  716. * This routine will load a named configuration file and parse the
  717. * text as a hierarchically valued option. The option descriptor
  718. * created from an option definition file is not used via this interface.
  719. * The returned value is "named" with the input file name and is of
  720. * type "@code{OPARG_TYPE_HIERARCHY}". It may be used in calls to
  721. * @code{optionGetValue()}, @code{optionNextValue()} and
  722. * @code{optionUnloadNested()}.
  723. *
  724. * @param fname the file to load
  725. *
  726. * @return const tOptionValue * - An allocated, compound value structure
  727. */
  728. extern const tOptionValue * configFileLoad(char const *);
  729. /**
  730. * optionFileLoad - Load the locatable config files, in order
  731. *
  732. * This function looks in all the specified directories for a configuration
  733. * file ("rc" file or "ini" file) and processes any found twice. The first
  734. * time through, they are processed in reverse order (last file first). At
  735. * that time, only "immediate action" configurables are processed. For
  736. * example, if the last named file specifies not processing any more
  737. * configuration files, then no more configuration files will be processed.
  738. * Such an option in the @strong{first} named directory will have no effect.
  739. *
  740. * Once the immediate action configurables have been handled, then the
  741. * directories are handled in normal, forward order. In that way, later
  742. * config files can override the settings of earlier config files.
  743. *
  744. * See the AutoOpts documentation for a thorough discussion of the
  745. * config file format.
  746. *
  747. * Configuration files not found or not decipherable are simply ignored.
  748. *
  749. * @param opts program options descriptor
  750. * @param prog program name
  751. *
  752. * @return int - 0 -> SUCCESS, -1 -> FAILURE
  753. */
  754. extern int optionFileLoad(tOptions *, char const *);
  755. /**
  756. * optionFindNextValue - find a hierarcicaly valued option instance
  757. *
  758. * This routine will find the next entry in a nested value option or
  759. * configurable. It will search through the list and return the next entry
  760. * that matches the criteria.
  761. *
  762. * @param odesc an option with a nested arg type
  763. * @param pPrevVal the last entry
  764. * @param name name of value to find
  765. * @param value the matching value
  766. *
  767. * @return const tOptionValue * - a compound value structure
  768. */
  769. extern const tOptionValue * optionFindNextValue(const tOptDesc *, const tOptionValue *, char const *, char const *);
  770. /**
  771. * optionFindValue - find a hierarcicaly valued option instance
  772. *
  773. * This routine will find an entry in a nested value option or configurable.
  774. * It will search through the list and return a matching entry.
  775. *
  776. * @param odesc an option with a nested arg type
  777. * @param name name of value to find
  778. * @param val the matching value
  779. *
  780. * @return const tOptionValue * - a compound value structure
  781. */
  782. extern const tOptionValue * optionFindValue(const tOptDesc *, char const *, char const *);
  783. /**
  784. * optionFree - free allocated option processing memory
  785. *
  786. * AutoOpts sometimes allocates memory and puts pointers to it in the
  787. * option state structures. This routine deallocates all such memory.
  788. *
  789. * @param pOpts program options descriptor
  790. */
  791. extern void optionFree(tOptions *);
  792. /**
  793. * optionGetValue - get a specific value from a hierarcical list
  794. *
  795. * This routine will find an entry in a nested value option or configurable.
  796. * If "valueName" is NULL, then the first entry is returned. Otherwise,
  797. * the first entry with a name that exactly matches the argument will be
  798. * returned. If there is no matching value, NULL is returned and errno is
  799. * set to ENOENT. If the provided option value is not a hierarchical value,
  800. * NULL is also returned and errno is set to EINVAL.
  801. *
  802. * @param pOptValue a hierarchcal value
  803. * @param valueName name of value to get
  804. *
  805. * @return const tOptionValue * - a compound value structure
  806. */
  807. extern const tOptionValue * optionGetValue(const tOptionValue *, char const *);
  808. /**
  809. * optionLoadLine - process a string for an option name and value
  810. *
  811. * This is a client program callable routine for setting options from, for
  812. * example, the contents of a file that they read in. Only one option may
  813. * appear in the text. It will be treated as a normal (non-preset) option.
  814. *
  815. * When passed a pointer to the option struct and a string, it will find
  816. * the option named by the first token on the string and set the option
  817. * argument to the remainder of the string. The caller must NUL terminate
  818. * the string. The caller need not skip over any introductory hyphens.
  819. * Any embedded new lines will be included in the option
  820. * argument. If the input looks like one or more quoted strings, then the
  821. * input will be "cooked". The "cooking" is identical to the string
  822. * formation used in AutoGen definition files (@pxref{basic expression}),
  823. * except that you may not use backquotes.
  824. *
  825. * @param opts program options descriptor
  826. * @param line NUL-terminated text
  827. */
  828. extern void optionLoadLine(tOptions *, char const *);
  829. /**
  830. * optionMemberList - Get the list of members of a bit mask set
  831. *
  832. * This converts the OPT_VALUE_name mask value to a allocated string.
  833. * It is the caller's responsibility to free the string.
  834. *
  835. * @param od the set membership option description
  836. *
  837. * @return char * - the names of the set bits
  838. */
  839. extern char * optionMemberList(tOptDesc *);
  840. /**
  841. * optionNextValue - get the next value from a hierarchical list
  842. *
  843. * This routine will return the next entry after the entry passed in. At the
  844. * end of the list, NULL will be returned. If the entry is not found on the
  845. * list, NULL will be returned and "@var{errno}" will be set to EINVAL.
  846. * The "@var{pOldValue}" must have been gotten from a prior call to this
  847. * routine or to "@code{opitonGetValue()}".
  848. *
  849. * @param pOptValue a hierarchcal list value
  850. * @param pOldValue a value from this list
  851. *
  852. * @return const tOptionValue * - a compound value structure
  853. */
  854. extern const tOptionValue * optionNextValue(const tOptionValue *, const tOptionValue *);
  855. /**
  856. * optionOnlyUsage - Print usage text for just the options
  857. *
  858. * This routine will print only the usage for each option.
  859. * This function may be used when the emitted usage must incorporate
  860. * information not available to AutoOpts.
  861. *
  862. * @param pOpts program options descriptor
  863. * @param ex_code exit code for calling exit(3)
  864. */
  865. extern void optionOnlyUsage(tOptions *, int);
  866. /**
  867. * optionPrintVersion - Print the program version
  868. *
  869. * This routine will print the version to stdout.
  870. *
  871. * @param opts program options descriptor
  872. * @param od the descriptor for this arg
  873. */
  874. extern void optionPrintVersion(tOptions *, tOptDesc *);
  875. /**
  876. * optionPrintVersionAndReturn - Print the program version
  877. *
  878. * This routine will print the version to stdout and return
  879. * instead of exiting. Please see the source for the
  880. * @code{print_ver} funtion for details on selecting how
  881. * verbose to be after this function returns.
  882. *
  883. * @param opts program options descriptor
  884. * @param od the descriptor for this arg
  885. */
  886. extern void optionPrintVersionAndReturn(tOptions *, tOptDesc *);
  887. /**
  888. * optionProcess - this is the main option processing routine
  889. *
  890. * This is the main entry point for processing options. It is intended
  891. * that this procedure be called once at the beginning of the execution of
  892. * a program. Depending on options selected earlier, it is sometimes
  893. * necessary to stop and restart option processing, or to select completely
  894. * different sets of options. This can be done easily, but you generally
  895. * do not want to do this.
  896. *
  897. * The number of arguments processed always includes the program name.
  898. * If one of the arguments is "--", then it is counted and the processing
  899. * stops. If an error was encountered and errors are to be tolerated, then
  900. * the returned value is the index of the argument causing the error.
  901. * A hyphen by itself ("-") will also cause processing to stop and will
  902. * @emph{not} be counted among the processed arguments. A hyphen by itself
  903. * is treated as an operand. Encountering an operand stops option
  904. * processing.
  905. *
  906. * @param opts program options descriptor
  907. * @param a_ct program arg count
  908. * @param a_v program arg vector
  909. *
  910. * @return int - the count of the arguments processed
  911. */
  912. extern int optionProcess(tOptions *, int, char **);
  913. /**
  914. * optionRestore - restore option state from memory copy
  915. *
  916. * Copy back the option state from saved memory.
  917. * The allocated memory is left intact, so this routine can be
  918. * called repeatedly without having to call optionSaveState again.
  919. * If you are restoring a state that was saved before the first call
  920. * to optionProcess(3AO), then you may change the contents of the
  921. * argc/argv parameters to optionProcess.
  922. *
  923. * @param pOpts program options descriptor
  924. */
  925. extern void optionRestore(tOptions *);
  926. /**
  927. * optionSaveFile - saves the option state to a file
  928. *
  929. * This routine will save the state of option processing to a file. The name
  930. * of that file can be specified with the argument to the @code{--save-opts}
  931. * option, or by appending the @code{rcfile} attribute to the last
  932. * @code{homerc} attribute. If no @code{rcfile} attribute was specified, it
  933. * will default to @code{.@i{programname}rc}. If you wish to specify another
  934. * file, you should invoke the @code{SET_OPT_SAVE_OPTS(@i{filename})} macro.
  935. *
  936. * The recommend usage is as follows:
  937. * @example
  938. * optionProcess(&progOptions, argc, argv);
  939. * if (i_want_a_non_standard_place_for_this)
  940. * SET_OPT_SAVE_OPTS("myfilename");
  941. * optionSaveFile(&progOptions);
  942. * @end example
  943. *
  944. * @param opts program options descriptor
  945. */
  946. extern void optionSaveFile(tOptions *);
  947. /**
  948. * optionSaveState - saves the option state to memory
  949. *
  950. * This routine will allocate enough memory to save the current option
  951. * processing state. If this routine has been called before, that memory
  952. * will be reused. You may only save one copy of the option state. This
  953. * routine may be called before optionProcess(3AO). If you do call it
  954. * before the first call to optionProcess, then you may also change the
  955. * contents of argc/argv after you call optionRestore(3AO)
  956. *
  957. * In fact, more strongly put: it is safest to only use this function
  958. * before having processed any options. In particular, the saving and
  959. * restoring of stacked string arguments and hierarchical values is
  960. * disabled. The values are not saved.
  961. *
  962. * @param pOpts program options descriptor
  963. */
  964. extern void optionSaveState(tOptions *);
  965. /**
  966. * optionUnloadNested - Deallocate the memory for a nested value
  967. *
  968. * A nested value needs to be deallocated. The pointer passed in should
  969. * have been gotten from a call to @code{configFileLoad()} (See
  970. * @pxref{libopts-configFileLoad}).
  971. *
  972. * @param pOptVal the hierarchical value
  973. */
  974. extern void optionUnloadNested(tOptionValue const *);
  975. /**
  976. * optionVersion - return the compiled AutoOpts version number
  977. *
  978. * Returns the full version string compiled into the library.
  979. * The returned string cannot be modified.
  980. *
  981. * @return char const * - the version string in constant memory
  982. */
  983. extern char const * optionVersion(void);
  984. /**
  985. * strequate - map a list of characters to the same value
  986. *
  987. * Each character in the input string get mapped to the first character
  988. * in the string.
  989. * This function name is mapped to option_strequate so as to not conflict
  990. * with the POSIX name space.
  991. *
  992. * @param ch_list characters to equivalence
  993. */
  994. extern void strequate(char const *);
  995. /**
  996. * streqvcmp - compare two strings with an equivalence mapping
  997. *
  998. * Using a character mapping, two strings are compared for "equivalence".
  999. * Each input character is mapped to a comparison character and the
  1000. * mapped-to characters are compared for the two NUL terminated input strings.
  1001. * This function name is mapped to option_streqvcmp so as to not conflict
  1002. * with the POSIX name space.
  1003. *
  1004. * @param str1 first string
  1005. * @param str2 second string
  1006. *
  1007. * @return int - the difference between two differing characters
  1008. */
  1009. extern int streqvcmp(char const *, char const *);
  1010. /**
  1011. * streqvmap - Set the character mappings for the streqv functions
  1012. *
  1013. * Set the character mapping. If the count (@code{ct}) is set to zero, then
  1014. * the map is cleared by setting all entries in the map to their index
  1015. * value. Otherwise, the "@code{From}" character is mapped to the "@code{To}"
  1016. * character. If @code{ct} is greater than 1, then @code{From} and @code{To}
  1017. * are incremented and the process repeated until @code{ct} entries have been
  1018. * set. For example,
  1019. * @example
  1020. * streqvmap('a', 'A', 26);
  1021. * @end example
  1022. * @noindent
  1023. * will alter the mapping so that all English lower case letters
  1024. * will map to upper case.
  1025. *
  1026. * This function name is mapped to option_streqvmap so as to not conflict
  1027. * with the POSIX name space.
  1028. *
  1029. * @param from Input character
  1030. * @param to Mapped-to character
  1031. * @param ct compare length
  1032. */
  1033. extern void streqvmap(char, char, int);
  1034. /**
  1035. * strneqvcmp - compare two strings with an equivalence mapping
  1036. *
  1037. * Using a character mapping, two strings are compared for "equivalence".
  1038. * Each input character is mapped to a comparison character and the
  1039. * mapped-to characters are compared for the two NUL terminated input strings.
  1040. * The comparison is limited to @code{ct} bytes.
  1041. * This function name is mapped to option_strneqvcmp so as to not conflict
  1042. * with the POSIX name space.
  1043. *
  1044. * @param str1 first string
  1045. * @param str2 second string
  1046. * @param ct compare length
  1047. *
  1048. * @return int - the difference between two differing characters
  1049. */
  1050. extern int strneqvcmp(char const *, char const *, int);
  1051. /**
  1052. * strtransform - convert a string into its mapped-to value
  1053. *
  1054. * Each character in the input string is mapped and the mapped-to
  1055. * character is put into the output.
  1056. * This function name is mapped to option_strtransform so as to not conflict
  1057. * with the POSIX name space.
  1058. *
  1059. * The source and destination may be the same.
  1060. *
  1061. * @param dest output string
  1062. * @param src input string
  1063. */
  1064. extern void strtransform(char *, char const *);
  1065. /* AutoOpts PRIVATE FUNCTIONS: */
  1066. tOptProc optionStackArg, optionUnstackArg, optionBooleanVal, optionNumericVal;
  1067. extern char * ao_string_cook(char *, int *);
  1068. extern unsigned int ao_string_cook_escape_char(char const *, char *, unsigned int);
  1069. extern void genshelloptUsage(tOptions *, int);
  1070. extern int optionAlias(tOptions *, tOptDesc *, unsigned int);
  1071. extern void optionBooleanVal(tOptions *, tOptDesc *);
  1072. extern uintptr_t optionEnumerationVal(tOptions *, tOptDesc *, char const * const *, unsigned int);
  1073. extern void optionFileCheck(tOptions *, tOptDesc *, teOptFileType, tuFileMode);
  1074. extern char const * optionKeywordName(tOptDesc *, unsigned int);
  1075. extern void optionLoadOpt(tOptions *, tOptDesc *);
  1076. extern bool optionMakePath(char *, int, char const *, char const *);
  1077. extern void optionNestedVal(tOptions *, tOptDesc *);
  1078. extern void optionNumericVal(tOptions *, tOptDesc *);
  1079. extern void optionPagedUsage(tOptions *, tOptDesc *);
  1080. extern void optionParseShell(tOptions *);
  1081. extern void optionPrintParagraphs(char const *, bool, FILE *);
  1082. extern void optionPutShell(tOptions *);
  1083. extern char const * optionQuoteString(char const *, char const *);
  1084. extern void optionResetOpt(tOptions *, tOptDesc *);
  1085. extern void optionSetMembers(tOptions *, tOptDesc *, char const * const *, unsigned int);
  1086. extern void optionShowRange(tOptions *, tOptDesc *, void *, int);
  1087. extern void optionStackArg(tOptions *, tOptDesc *);
  1088. extern void optionTimeDate(tOptions *, tOptDesc *);
  1089. extern void optionTimeVal(tOptions *, tOptDesc *);
  1090. extern void optionUnstackArg(tOptions *, tOptDesc *);
  1091. extern void optionUsage(tOptions *, int);
  1092. extern void optionVendorOption(tOptions *, tOptDesc *);
  1093. extern void optionVersionStderr(tOptions *, tOptDesc *);
  1094. extern void * text_mmap(char const *, int, int, tmap_info_t *);
  1095. extern int text_munmap(tmap_info_t *);
  1096. CPLUSPLUS_CLOSER
  1097. #endif /* AUTOOPTS_OPTIONS_H_GUARD */
  1098. /** @}
  1099. *
  1100. * Local Variables:
  1101. * c-file-style: "stroustrup"
  1102. * indent-tabs-mode: nil
  1103. * End:
  1104. * options.h ends here */