options.h 44 KB

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