xref: /netbsd-src/external/bsd/ntp/dist/sntp/libopts/genshell.h (revision eabc0478de71e4e011a5b4e0392741e01d491794)
1*eabc0478Schristos /*	$NetBSD: genshell.h,v 1.6 2024/08/18 20:47:24 christos Exp $	*/
2abb0f93cSkardel 
3abb0f93cSkardel /*   -*- buffer-read-only: t -*- vi: set ro:
4abb0f93cSkardel  *
5abb0f93cSkardel  *  DO NOT EDIT THIS FILE   (genshell.h)
6abb0f93cSkardel  *
7b8ecfcfeSchristos  *  It has been AutoGen-ed
8abb0f93cSkardel  *  From the definitions    genshell.def
9abb0f93cSkardel  *  and the template file   options
10abb0f93cSkardel  *
11*eabc0478Schristos  * Generated from AutoOpts 42:1:17 templates.
12f003fb54Skardel  *
13f003fb54Skardel  *  AutoOpts is a copyrighted work.  This header file is not encumbered
14f003fb54Skardel  *  by AutoOpts licensing, but is provided under the licensing terms chosen
15f003fb54Skardel  *  by the genshellopt author or copyright holder.  AutoOpts is
16f003fb54Skardel  *  licensed under the terms of the LGPL.  The redistributable library
17f003fb54Skardel  *  (``libopts'') is licensed under the terms of either the LGPL or, at the
18f003fb54Skardel  *  users discretion, the BSD license.  See the AutoOpts and/or libopts sources
19f003fb54Skardel  *  for details.
20abb0f93cSkardel  *
218585484eSchristos  * The genshellopt program is copyrighted and licensed
228585484eSchristos  * under the following terms:
23abb0f93cSkardel  *
24*eabc0478Schristos  *  Copyright (C) 1999-2018 Bruce Korb, all rights reserved.
258585484eSchristos  *  This is free software. It is licensed for use, modification and
268585484eSchristos  *  redistribution under the terms of the GNU Lesser General Public License,
278585484eSchristos  *  version 2 or later <http://www.gnu.org/licenses/old-licenses/lgpl-2.0.html>
28abb0f93cSkardel  *
298585484eSchristos  *  The genshellopt library is free software; you can redistribute it and/or
308585484eSchristos  *  modify it under the terms of the GNU Library General Public License as
318585484eSchristos  *  published by the Free Software Foundation; either version 2 of the
328585484eSchristos  *  License, or (at your option) any later version.
33abb0f93cSkardel  *
348585484eSchristos  *  This library is distributed in the hope that it will be useful, but
35abb0f93cSkardel  *  WITHOUT ANY WARRANTY; without even the implied warranty of
368585484eSchristos  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
378585484eSchristos  *  Library General Public License for more details.
38abb0f93cSkardel  *
398585484eSchristos  *  You should have received a copy of the GNU Library General Public
408585484eSchristos  *  License along with this library; if not, see
418585484eSchristos  *  <http://www.gnu.org/licenses/old-licenses/lgpl-2.0.html>
42abb0f93cSkardel  */
438585484eSchristos /**
44abb0f93cSkardel  *  This file contains the programmatic interface to the Automated
45abb0f93cSkardel  *  Options generated for the genshellopt program.
46abb0f93cSkardel  *  These macros are documented in the AutoGen info file in the
47abb0f93cSkardel  *  "AutoOpts" chapter.  Please refer to that doc for usage help.
48abb0f93cSkardel  */
49abb0f93cSkardel #ifndef AUTOOPTS_GENSHELL_H_GUARD
50abb0f93cSkardel #define AUTOOPTS_GENSHELL_H_GUARD 1
51abb0f93cSkardel #include <autoopts/options.h>
52*eabc0478Schristos #include <stdarg.h>
53*eabc0478Schristos #include <stdnoreturn.h>
54abb0f93cSkardel 
558585484eSchristos /**
56abb0f93cSkardel  *  Ensure that the library used for compiling this generated header is at
57abb0f93cSkardel  *  least as new as the version current when the header template was released
58abb0f93cSkardel  *  (not counting patch version increments).  Also ensure that the oldest
59abb0f93cSkardel  *  tolerable version is at least as old as what was current when the header
60abb0f93cSkardel  *  template was released.
61abb0f93cSkardel  */
62*eabc0478Schristos #define AO_TEMPLATE_VERSION 172033
63abb0f93cSkardel #if (AO_TEMPLATE_VERSION < OPTIONS_MINIMUM_VERSION) \
64abb0f93cSkardel  || (AO_TEMPLATE_VERSION > OPTIONS_STRUCT_VERSION)
65abb0f93cSkardel # error option template version mismatches autoopts/options.h header
66abb0f93cSkardel   Choke Me.
67abb0f93cSkardel #endif
68abb0f93cSkardel 
69*eabc0478Schristos #if GCC_VERSION > 40400
70*eabc0478Schristos #define NOT_REACHED __builtin_unreachable();
71*eabc0478Schristos #else
72*eabc0478Schristos #define NOT_REACHED
73*eabc0478Schristos #endif
74*eabc0478Schristos 
758585484eSchristos /**
768585484eSchristos  *  Enumeration of each option type for genshellopt
77abb0f93cSkardel  */
78abb0f93cSkardel typedef enum {
79f003fb54Skardel     INDEX_GENSHELL_OPT_SCRIPT      =  0,
80f003fb54Skardel     INDEX_GENSHELL_OPT_SHELL       =  1,
81f003fb54Skardel     INDEX_GENSHELL_OPT_VERSION     =  2,
82f003fb54Skardel     INDEX_GENSHELL_OPT_HELP        =  3,
83f003fb54Skardel     INDEX_GENSHELL_OPT_MORE_HELP   =  4
84f003fb54Skardel } teGenshell_OptIndex;
858585484eSchristos /** count of all options for genshellopt */
86f003fb54Skardel #define GENSHELL_OPTION_CT    5
878585484eSchristos /** genshellopt version */
88abb0f93cSkardel #define GENSHELLOPT_VERSION       "1"
898585484eSchristos /** Full genshellopt version text */
90f003fb54Skardel #define GENSHELLOPT_FULL_VERSION  "genshellopt 1"
91abb0f93cSkardel 
928585484eSchristos /**
93abb0f93cSkardel  *  Interface defines for all options.  Replace "n" with the UPPER_CASED
94f003fb54Skardel  *  option name (as in the teGenshell_OptIndex enumeration above).
95f003fb54Skardel  *  e.g. HAVE_GENSHELL_OPT(SCRIPT)
96abb0f93cSkardel  */
97f003fb54Skardel #define GENSHELL_DESC(n) (genshelloptOptions.pOptDesc[INDEX_GENSHELL_OPT_## n])
988585484eSchristos /** 'true' if an option has been specified in any way */
99f003fb54Skardel #define     HAVE_GENSHELL_OPT(n) (! UNUSED_OPT(& GENSHELL_DESC(n)))
1008585484eSchristos /** The string argument to an option. The argument type must be \"string\". */
101f003fb54Skardel #define      GENSHELL_OPT_ARG(n) (GENSHELL_DESC(n).optArg.argString)
1028585484eSchristos /** Mask the option state revealing how an option was specified.
1038585484eSchristos  *  It will be one and only one of \a OPTST_SET, \a OPTST_PRESET,
1048585484eSchristos  * \a OPTST_DEFINED, \a OPTST_RESET or zero.
1058585484eSchristos  */
106f003fb54Skardel #define    STATE_GENSHELL_OPT(n) (GENSHELL_DESC(n).fOptState & OPTST_SET_MASK)
1078585484eSchristos /** Count of option's occurrances *on the command line*. */
108f003fb54Skardel #define    COUNT_GENSHELL_OPT(n) (GENSHELL_DESC(n).optOccCt)
1098585484eSchristos /** mask of \a OPTST_SET and \a OPTST_DEFINED. */
110f003fb54Skardel #define    ISSEL_GENSHELL_OPT(n) (SELECTED_OPT(&GENSHELL_DESC(n)))
1118585484eSchristos /** 'true' if \a HAVE_OPT would yield 'false'. */
112f003fb54Skardel #define ISUNUSED_GENSHELL_OPT(n) (UNUSED_OPT(& GENSHELL_DESC(n)))
1138585484eSchristos /** 'true' if OPTST_DISABLED bit not set. */
114f003fb54Skardel #define  ENABLED_GENSHELL_OPT(n) (! DISABLED_OPT(& GENSHELL_DESC(n)))
1158585484eSchristos /** number of stacked option arguments.
1168585484eSchristos  *  Valid only for stacked option arguments. */
117f003fb54Skardel #define  STACKCT_GENSHELL_OPT(n) (((tArgList*)(GENSHELL_DESC(n).optCookie))->useCt)
1188585484eSchristos /** stacked argument vector.
1198585484eSchristos  *  Valid only for stacked option arguments. */
120f003fb54Skardel #define STACKLST_GENSHELL_OPT(n) (((tArgList*)(GENSHELL_DESC(n).optCookie))->apzArgs)
1218585484eSchristos /** Reset an option. */
122f003fb54Skardel #define    CLEAR_GENSHELL_OPT(n) STMTS( \
123f003fb54Skardel                 GENSHELL_DESC(n).fOptState &= OPTST_PERSISTENT_MASK;   \
124f003fb54Skardel                 if ((GENSHELL_DESC(n).fOptState & OPTST_INITENABLED) == 0) \
125f003fb54Skardel                     GENSHELL_DESC(n).fOptState |= OPTST_DISABLED; \
126f003fb54Skardel                 GENSHELL_DESC(n).optCookie = NULL )
1278585484eSchristos /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1288585484eSchristos /**
129f003fb54Skardel  *  Enumeration of genshellopt exit codes
130f003fb54Skardel  */
131f003fb54Skardel typedef enum {
132f003fb54Skardel     GENSHELLOPT_EXIT_SUCCESS         = 0,
1338585484eSchristos     GENSHELLOPT_EXIT_FAILURE         = 1,
1348585484eSchristos     GENSHELLOPT_EXIT_USAGE_ERROR     = 64,
1358585484eSchristos     GENSHELLOPT_EXIT_LIBOPTS_FAILURE = 70
136f003fb54Skardel }   genshellopt_exit_code_t;
1378585484eSchristos /**
138abb0f93cSkardel  *  Interface defines for specific options.
1398585484eSchristos  * @{
140abb0f93cSkardel  */
141f003fb54Skardel #define VALUE_GENSHELL_OPT_SCRIPT 'o'
142f003fb54Skardel #define VALUE_GENSHELL_OPT_SHELL 's'
143b8ecfcfeSchristos /** option flag (value) for help-value option */
144f003fb54Skardel #define VALUE_GENSHELL_OPT_HELP '?'
145b8ecfcfeSchristos /** option flag (value) for more-help-value option */
146f003fb54Skardel #define VALUE_GENSHELL_OPT_MORE_HELP '!'
147b8ecfcfeSchristos /** option flag (value) for version-value option */
148f003fb54Skardel #define VALUE_GENSHELL_OPT_VERSION 'v'
149abb0f93cSkardel /*
150abb0f93cSkardel  *  Interface defines not associated with particular options
151abb0f93cSkardel  */
152f003fb54Skardel #define ERRSKIP_GENSHELL_OPTERR  STMTS(genshelloptOptions.fOptSet &= ~OPTPROC_ERRSTOP)
153f003fb54Skardel #define ERRSTOP_GENSHELL_OPTERR  STMTS(genshelloptOptions.fOptSet |= OPTPROC_ERRSTOP)
154f003fb54Skardel #define RESTART_GENSHELL_OPT(n)  STMTS( \
155abb0f93cSkardel                 genshelloptOptions.curOptIdx = (n); \
156abb0f93cSkardel                 genshelloptOptions.pzCurOpt  = NULL )
157f003fb54Skardel #define START_GENSHELL_OPT       RESTART_GENSHELL_OPT(1)
158f003fb54Skardel #define GENSHELL_USAGE(c)        (*genshelloptOptions.pUsageProc)(&genshelloptOptions, c)
159f003fb54Skardel 
160f003fb54Skardel #ifdef  __cplusplus
161f003fb54Skardel extern "C" {
162f003fb54Skardel #endif
163*eabc0478Schristos /*
164*eabc0478Schristos  *  global exported definitions
165*eabc0478Schristos  */
166*eabc0478Schristos #define ch_t  unsigned char
167*eabc0478Schristos #define cc_t  const unsigned char
168*eabc0478Schristos #define cch_t char const
169abb0f93cSkardel 
1708585484eSchristos 
171abb0f93cSkardel /* * * * * *
172abb0f93cSkardel  *
173abb0f93cSkardel  *  Declare the genshellopt option descriptor.
174abb0f93cSkardel  */
175abb0f93cSkardel extern tOptions genshelloptOptions;
176abb0f93cSkardel 
177abb0f93cSkardel #if defined(ENABLE_NLS)
178abb0f93cSkardel # ifndef _
179abb0f93cSkardel #   include <stdio.h>
1808585484eSchristos #   ifndef HAVE_GETTEXT
1818585484eSchristos       extern char * gettext(char const *);
1828585484eSchristos #   else
1838585484eSchristos #     include <libintl.h>
1848585484eSchristos #   endif
1858585484eSchristos 
186b8ecfcfeSchristos # ifndef ATTRIBUTE_FORMAT_ARG
187b8ecfcfeSchristos #   define ATTRIBUTE_FORMAT_ARG(_a)
188b8ecfcfeSchristos # endif
189b8ecfcfeSchristos 
190b8ecfcfeSchristos static inline char* aoGetsText(char const* pz) ATTRIBUTE_FORMAT_ARG(1);
191abb0f93cSkardel static inline char* aoGetsText(char const* pz) {
192abb0f93cSkardel     if (pz == NULL) return NULL;
193abb0f93cSkardel     return (char*)gettext(pz);
194abb0f93cSkardel }
195abb0f93cSkardel #   define _(s)  aoGetsText(s)
196abb0f93cSkardel # endif /* _() */
197abb0f93cSkardel 
198abb0f93cSkardel # define OPT_NO_XLAT_CFG_NAMES  STMTS(genshelloptOptions.fOptSet |= \
199abb0f93cSkardel                                     OPTPROC_NXLAT_OPT_CFG;)
200abb0f93cSkardel # define OPT_NO_XLAT_OPT_NAMES  STMTS(genshelloptOptions.fOptSet |= \
201abb0f93cSkardel                                     OPTPROC_NXLAT_OPT|OPTPROC_NXLAT_OPT_CFG;)
202abb0f93cSkardel 
203abb0f93cSkardel # define OPT_XLAT_CFG_NAMES     STMTS(genshelloptOptions.fOptSet &= \
204abb0f93cSkardel                                   ~(OPTPROC_NXLAT_OPT|OPTPROC_NXLAT_OPT_CFG);)
205abb0f93cSkardel # define OPT_XLAT_OPT_NAMES     STMTS(genshelloptOptions.fOptSet &= \
206abb0f93cSkardel                                   ~OPTPROC_NXLAT_OPT;)
207abb0f93cSkardel 
208abb0f93cSkardel #else   /* ENABLE_NLS */
209abb0f93cSkardel # define OPT_NO_XLAT_CFG_NAMES
210abb0f93cSkardel # define OPT_NO_XLAT_OPT_NAMES
211abb0f93cSkardel 
212abb0f93cSkardel # define OPT_XLAT_CFG_NAMES
213abb0f93cSkardel # define OPT_XLAT_OPT_NAMES
214abb0f93cSkardel 
215abb0f93cSkardel # ifndef _
216abb0f93cSkardel #   define _(_s)  _s
217abb0f93cSkardel # endif
218abb0f93cSkardel #endif  /* ENABLE_NLS */
219abb0f93cSkardel 
220*eabc0478Schristos 
221abb0f93cSkardel #ifdef  __cplusplus
222abb0f93cSkardel }
223abb0f93cSkardel #endif
224abb0f93cSkardel #endif /* AUTOOPTS_GENSHELL_H_GUARD */
2258585484eSchristos 
226abb0f93cSkardel /* genshell.h ends here */
227