xref: /freebsd/contrib/ntp/sntp/libopts/genshell.h (revision a466cc55373fc3cf86837f09da729535b57e69a1)
1ea906c41SOllivier Robert /*   -*- buffer-read-only: t -*- vi: set ro:
2ea906c41SOllivier Robert  *
3ea906c41SOllivier Robert  *  DO NOT EDIT THIS FILE   (genshell.h)
4ea906c41SOllivier Robert  *
52b15cb3dSCy Schubert  *  It has been AutoGen-ed
6ea906c41SOllivier Robert  *  From the definitions    genshell.def
7ea906c41SOllivier Robert  *  and the template file   options
8ea906c41SOllivier Robert  *
9*a466cc55SCy Schubert  * Generated from AutoOpts 42:1:17 templates.
10ea906c41SOllivier Robert  *
112b15cb3dSCy Schubert  *  AutoOpts is a copyrighted work.  This header file is not encumbered
122b15cb3dSCy Schubert  *  by AutoOpts licensing, but is provided under the licensing terms chosen
132b15cb3dSCy Schubert  *  by the genshellopt author or copyright holder.  AutoOpts is
142b15cb3dSCy Schubert  *  licensed under the terms of the LGPL.  The redistributable library
152b15cb3dSCy Schubert  *  (``libopts'') is licensed under the terms of either the LGPL or, at the
162b15cb3dSCy Schubert  *  users discretion, the BSD license.  See the AutoOpts and/or libopts sources
172b15cb3dSCy Schubert  *  for details.
18ea906c41SOllivier Robert  *
192b15cb3dSCy Schubert  * The genshellopt program is copyrighted and licensed
202b15cb3dSCy Schubert  * under the following terms:
21ea906c41SOllivier Robert  *
22*a466cc55SCy Schubert  *  Copyright (C) 1999-2018 Bruce Korb, all rights reserved.
232b15cb3dSCy Schubert  *  This is free software. It is licensed for use, modification and
242b15cb3dSCy Schubert  *  redistribution under the terms of the GNU Lesser General Public License,
252b15cb3dSCy Schubert  *  version 2 or later <http://www.gnu.org/licenses/old-licenses/lgpl-2.0.html>
26ea906c41SOllivier Robert  *
272b15cb3dSCy Schubert  *  The genshellopt library is free software; you can redistribute it and/or
282b15cb3dSCy Schubert  *  modify it under the terms of the GNU Library General Public License as
292b15cb3dSCy Schubert  *  published by the Free Software Foundation; either version 2 of the
302b15cb3dSCy Schubert  *  License, or (at your option) any later version.
312b15cb3dSCy Schubert  *
322b15cb3dSCy Schubert  *  This library is distributed in the hope that it will be useful, but
332b15cb3dSCy Schubert  *  WITHOUT ANY WARRANTY; without even the implied warranty of
34ea906c41SOllivier Robert  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
352b15cb3dSCy Schubert  *  Library General Public License for more details.
36ea906c41SOllivier Robert  *
372b15cb3dSCy Schubert  *  You should have received a copy of the GNU Library General Public
382b15cb3dSCy Schubert  *  License along with this library; if not, see
392b15cb3dSCy Schubert  *  <http://www.gnu.org/licenses/old-licenses/lgpl-2.0.html>
40ea906c41SOllivier Robert  */
412b15cb3dSCy Schubert /**
42ea906c41SOllivier Robert  *  This file contains the programmatic interface to the Automated
43ea906c41SOllivier Robert  *  Options generated for the genshellopt program.
44ea906c41SOllivier Robert  *  These macros are documented in the AutoGen info file in the
45ea906c41SOllivier Robert  *  "AutoOpts" chapter.  Please refer to that doc for usage help.
46ea906c41SOllivier Robert  */
47ea906c41SOllivier Robert #ifndef AUTOOPTS_GENSHELL_H_GUARD
482b15cb3dSCy Schubert #define AUTOOPTS_GENSHELL_H_GUARD 1
49ea906c41SOllivier Robert #include <autoopts/options.h>
50*a466cc55SCy Schubert #include <stdarg.h>
51*a466cc55SCy Schubert #include <stdnoreturn.h>
52ea906c41SOllivier Robert 
532b15cb3dSCy Schubert /**
54ea906c41SOllivier Robert  *  Ensure that the library used for compiling this generated header is at
55ea906c41SOllivier Robert  *  least as new as the version current when the header template was released
56ea906c41SOllivier Robert  *  (not counting patch version increments).  Also ensure that the oldest
57ea906c41SOllivier Robert  *  tolerable version is at least as old as what was current when the header
58ea906c41SOllivier Robert  *  template was released.
59ea906c41SOllivier Robert  */
60*a466cc55SCy Schubert #define AO_TEMPLATE_VERSION 172033
61ea906c41SOllivier Robert #if (AO_TEMPLATE_VERSION < OPTIONS_MINIMUM_VERSION) \
62ea906c41SOllivier Robert  || (AO_TEMPLATE_VERSION > OPTIONS_STRUCT_VERSION)
63ea906c41SOllivier Robert # error option template version mismatches autoopts/options.h header
64ea906c41SOllivier Robert   Choke Me.
65ea906c41SOllivier Robert #endif
66ea906c41SOllivier Robert 
67*a466cc55SCy Schubert #if GCC_VERSION > 40400
68*a466cc55SCy Schubert #define NOT_REACHED __builtin_unreachable();
69*a466cc55SCy Schubert #else
70*a466cc55SCy Schubert #define NOT_REACHED
71*a466cc55SCy Schubert #endif
72*a466cc55SCy Schubert 
732b15cb3dSCy Schubert /**
742b15cb3dSCy Schubert  *  Enumeration of each option type for genshellopt
75ea906c41SOllivier Robert  */
76ea906c41SOllivier Robert typedef enum {
772b15cb3dSCy Schubert     INDEX_GENSHELL_OPT_SCRIPT      =  0,
782b15cb3dSCy Schubert     INDEX_GENSHELL_OPT_SHELL       =  1,
792b15cb3dSCy Schubert     INDEX_GENSHELL_OPT_VERSION     =  2,
802b15cb3dSCy Schubert     INDEX_GENSHELL_OPT_HELP        =  3,
812b15cb3dSCy Schubert     INDEX_GENSHELL_OPT_MORE_HELP   =  4
822b15cb3dSCy Schubert } teGenshell_OptIndex;
832b15cb3dSCy Schubert /** count of all options for genshellopt */
842b15cb3dSCy Schubert #define GENSHELL_OPTION_CT    5
852b15cb3dSCy Schubert /** genshellopt version */
86ea906c41SOllivier Robert #define GENSHELLOPT_VERSION       "1"
872b15cb3dSCy Schubert /** Full genshellopt version text */
882b15cb3dSCy Schubert #define GENSHELLOPT_FULL_VERSION  "genshellopt 1"
89ea906c41SOllivier Robert 
902b15cb3dSCy Schubert /**
91ea906c41SOllivier Robert  *  Interface defines for all options.  Replace "n" with the UPPER_CASED
922b15cb3dSCy Schubert  *  option name (as in the teGenshell_OptIndex enumeration above).
932b15cb3dSCy Schubert  *  e.g. HAVE_GENSHELL_OPT(SCRIPT)
94ea906c41SOllivier Robert  */
952b15cb3dSCy Schubert #define GENSHELL_DESC(n) (genshelloptOptions.pOptDesc[INDEX_GENSHELL_OPT_## n])
962b15cb3dSCy Schubert /** 'true' if an option has been specified in any way */
972b15cb3dSCy Schubert #define     HAVE_GENSHELL_OPT(n) (! UNUSED_OPT(& GENSHELL_DESC(n)))
982b15cb3dSCy Schubert /** The string argument to an option. The argument type must be \"string\". */
992b15cb3dSCy Schubert #define      GENSHELL_OPT_ARG(n) (GENSHELL_DESC(n).optArg.argString)
1002b15cb3dSCy Schubert /** Mask the option state revealing how an option was specified.
1012b15cb3dSCy Schubert  *  It will be one and only one of \a OPTST_SET, \a OPTST_PRESET,
1022b15cb3dSCy Schubert  * \a OPTST_DEFINED, \a OPTST_RESET or zero.
1032b15cb3dSCy Schubert  */
1042b15cb3dSCy Schubert #define    STATE_GENSHELL_OPT(n) (GENSHELL_DESC(n).fOptState & OPTST_SET_MASK)
1052b15cb3dSCy Schubert /** Count of option's occurrances *on the command line*. */
1062b15cb3dSCy Schubert #define    COUNT_GENSHELL_OPT(n) (GENSHELL_DESC(n).optOccCt)
1072b15cb3dSCy Schubert /** mask of \a OPTST_SET and \a OPTST_DEFINED. */
1082b15cb3dSCy Schubert #define    ISSEL_GENSHELL_OPT(n) (SELECTED_OPT(&GENSHELL_DESC(n)))
1092b15cb3dSCy Schubert /** 'true' if \a HAVE_OPT would yield 'false'. */
1102b15cb3dSCy Schubert #define ISUNUSED_GENSHELL_OPT(n) (UNUSED_OPT(& GENSHELL_DESC(n)))
1112b15cb3dSCy Schubert /** 'true' if OPTST_DISABLED bit not set. */
1122b15cb3dSCy Schubert #define  ENABLED_GENSHELL_OPT(n) (! DISABLED_OPT(& GENSHELL_DESC(n)))
1132b15cb3dSCy Schubert /** number of stacked option arguments.
1142b15cb3dSCy Schubert  *  Valid only for stacked option arguments. */
1152b15cb3dSCy Schubert #define  STACKCT_GENSHELL_OPT(n) (((tArgList*)(GENSHELL_DESC(n).optCookie))->useCt)
1162b15cb3dSCy Schubert /** stacked argument vector.
1172b15cb3dSCy Schubert  *  Valid only for stacked option arguments. */
1182b15cb3dSCy Schubert #define STACKLST_GENSHELL_OPT(n) (((tArgList*)(GENSHELL_DESC(n).optCookie))->apzArgs)
1192b15cb3dSCy Schubert /** Reset an option. */
1202b15cb3dSCy Schubert #define    CLEAR_GENSHELL_OPT(n) STMTS( \
1212b15cb3dSCy Schubert                 GENSHELL_DESC(n).fOptState &= OPTST_PERSISTENT_MASK;   \
1222b15cb3dSCy Schubert                 if ((GENSHELL_DESC(n).fOptState & OPTST_INITENABLED) == 0) \
1232b15cb3dSCy Schubert                     GENSHELL_DESC(n).fOptState |= OPTST_DISABLED; \
1242b15cb3dSCy Schubert                 GENSHELL_DESC(n).optCookie = NULL )
1252b15cb3dSCy Schubert /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1262b15cb3dSCy Schubert /**
1272b15cb3dSCy Schubert  *  Enumeration of genshellopt exit codes
1282b15cb3dSCy Schubert  */
1292b15cb3dSCy Schubert typedef enum {
1302b15cb3dSCy Schubert     GENSHELLOPT_EXIT_SUCCESS         = 0,
1312b15cb3dSCy Schubert     GENSHELLOPT_EXIT_FAILURE         = 1,
1322b15cb3dSCy Schubert     GENSHELLOPT_EXIT_USAGE_ERROR     = 64,
1332b15cb3dSCy Schubert     GENSHELLOPT_EXIT_LIBOPTS_FAILURE = 70
1342b15cb3dSCy Schubert }   genshellopt_exit_code_t;
1352b15cb3dSCy Schubert /**
136ea906c41SOllivier Robert  *  Interface defines for specific options.
1372b15cb3dSCy Schubert  * @{
138ea906c41SOllivier Robert  */
1392b15cb3dSCy Schubert #define VALUE_GENSHELL_OPT_SCRIPT 'o'
1402b15cb3dSCy Schubert #define VALUE_GENSHELL_OPT_SHELL 's'
1412b15cb3dSCy Schubert /** option flag (value) for help-value option */
1422b15cb3dSCy Schubert #define VALUE_GENSHELL_OPT_HELP '?'
1432b15cb3dSCy Schubert /** option flag (value) for more-help-value option */
1442b15cb3dSCy Schubert #define VALUE_GENSHELL_OPT_MORE_HELP '!'
1452b15cb3dSCy Schubert /** option flag (value) for version-value option */
1462b15cb3dSCy Schubert #define VALUE_GENSHELL_OPT_VERSION 'v'
147ea906c41SOllivier Robert /*
148ea906c41SOllivier Robert  *  Interface defines not associated with particular options
149ea906c41SOllivier Robert  */
1502b15cb3dSCy Schubert #define ERRSKIP_GENSHELL_OPTERR  STMTS(genshelloptOptions.fOptSet &= ~OPTPROC_ERRSTOP)
1512b15cb3dSCy Schubert #define ERRSTOP_GENSHELL_OPTERR  STMTS(genshelloptOptions.fOptSet |= OPTPROC_ERRSTOP)
1522b15cb3dSCy Schubert #define RESTART_GENSHELL_OPT(n)  STMTS( \
153ea906c41SOllivier Robert                 genshelloptOptions.curOptIdx = (n); \
154ea906c41SOllivier Robert                 genshelloptOptions.pzCurOpt  = NULL )
1552b15cb3dSCy Schubert #define START_GENSHELL_OPT       RESTART_GENSHELL_OPT(1)
1562b15cb3dSCy Schubert #define GENSHELL_USAGE(c)        (*genshelloptOptions.pUsageProc)(&genshelloptOptions, c)
1572b15cb3dSCy Schubert 
1582b15cb3dSCy Schubert #ifdef  __cplusplus
1592b15cb3dSCy Schubert extern "C" {
1602b15cb3dSCy Schubert #endif
161*a466cc55SCy Schubert /*
162*a466cc55SCy Schubert  *  global exported definitions
163*a466cc55SCy Schubert  */
164*a466cc55SCy Schubert #define ch_t  unsigned char
165*a466cc55SCy Schubert #define cc_t  const unsigned char
166*a466cc55SCy Schubert #define cch_t char const
1672b15cb3dSCy Schubert 
168ea906c41SOllivier Robert 
169ea906c41SOllivier Robert /* * * * * *
170ea906c41SOllivier Robert  *
171ea906c41SOllivier Robert  *  Declare the genshellopt option descriptor.
172ea906c41SOllivier Robert  */
173ea906c41SOllivier Robert extern tOptions genshelloptOptions;
174ea906c41SOllivier Robert 
1752b15cb3dSCy Schubert #if defined(ENABLE_NLS)
176ea906c41SOllivier Robert # ifndef _
177ea906c41SOllivier Robert #   include <stdio.h>
1782b15cb3dSCy Schubert #   ifndef HAVE_GETTEXT
1792b15cb3dSCy Schubert       extern char * gettext(char const *);
1802b15cb3dSCy Schubert #   else
1812b15cb3dSCy Schubert #     include <libintl.h>
1822b15cb3dSCy Schubert #   endif
1832b15cb3dSCy Schubert 
1842b15cb3dSCy Schubert # ifndef ATTRIBUTE_FORMAT_ARG
1852b15cb3dSCy Schubert #   define ATTRIBUTE_FORMAT_ARG(_a)
1862b15cb3dSCy Schubert # endif
1872b15cb3dSCy Schubert 
1882b15cb3dSCy Schubert static inline char* aoGetsText(char const* pz) ATTRIBUTE_FORMAT_ARG(1);
aoGetsText(char const * pz)189ea906c41SOllivier Robert static inline char* aoGetsText(char const* pz) {
190ea906c41SOllivier Robert     if (pz == NULL) return NULL;
191ea906c41SOllivier Robert     return (char*)gettext(pz);
192ea906c41SOllivier Robert }
193ea906c41SOllivier Robert #   define _(s)  aoGetsText(s)
1942b15cb3dSCy Schubert # endif /* _() */
1952b15cb3dSCy Schubert 
1962b15cb3dSCy Schubert # define OPT_NO_XLAT_CFG_NAMES  STMTS(genshelloptOptions.fOptSet |= \
1972b15cb3dSCy Schubert                                     OPTPROC_NXLAT_OPT_CFG;)
1982b15cb3dSCy Schubert # define OPT_NO_XLAT_OPT_NAMES  STMTS(genshelloptOptions.fOptSet |= \
1992b15cb3dSCy Schubert                                     OPTPROC_NXLAT_OPT|OPTPROC_NXLAT_OPT_CFG;)
2002b15cb3dSCy Schubert 
2012b15cb3dSCy Schubert # define OPT_XLAT_CFG_NAMES     STMTS(genshelloptOptions.fOptSet &= \
2022b15cb3dSCy Schubert                                   ~(OPTPROC_NXLAT_OPT|OPTPROC_NXLAT_OPT_CFG);)
2032b15cb3dSCy Schubert # define OPT_XLAT_OPT_NAMES     STMTS(genshelloptOptions.fOptSet &= \
2042b15cb3dSCy Schubert                                   ~OPTPROC_NXLAT_OPT;)
2052b15cb3dSCy Schubert 
206ea906c41SOllivier Robert #else   /* ENABLE_NLS */
2072b15cb3dSCy Schubert # define OPT_NO_XLAT_CFG_NAMES
2082b15cb3dSCy Schubert # define OPT_NO_XLAT_OPT_NAMES
2092b15cb3dSCy Schubert 
2102b15cb3dSCy Schubert # define OPT_XLAT_CFG_NAMES
2112b15cb3dSCy Schubert # define OPT_XLAT_OPT_NAMES
2122b15cb3dSCy Schubert 
2132b15cb3dSCy Schubert # ifndef _
2142b15cb3dSCy Schubert #   define _(_s)  _s
215ea906c41SOllivier Robert # endif
2162b15cb3dSCy Schubert #endif  /* ENABLE_NLS */
217ea906c41SOllivier Robert 
218*a466cc55SCy Schubert 
219ea906c41SOllivier Robert #ifdef  __cplusplus
220ea906c41SOllivier Robert }
221ea906c41SOllivier Robert #endif
222ea906c41SOllivier Robert #endif /* AUTOOPTS_GENSHELL_H_GUARD */
2232b15cb3dSCy Schubert 
224ea906c41SOllivier Robert /* genshell.h ends here */
225