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