Updated gnulib and added hash-pjw-bare
[gnutls.git] / src / libopts / genshell.c
blob16ca2450812156612a9547920a10246016726df4
1 /* -*- buffer-read-only: t -*- vi: set ro:
2 *
3 * DO NOT EDIT THIS FILE (genshell.c)
4 *
5 * It has been AutoGen-ed May 6, 2012 at 04:20:59 PM by AutoGen 5.16pre36
6 * From the definitions genshell.def
7 * and the template file options
9 * Generated from AutoOpts 36:4:11 templates.
11 * AutoOpts is a copyrighted work. This source file is not encumbered
12 * by AutoOpts licensing, but is provided under the licensing terms chosen
13 * by the genshellopt author or copyright holder. AutoOpts is
14 * licensed under the terms of the LGPL. The redistributable library
15 * (``libopts'') is licensed under the terms of either the LGPL or, at the
16 * users discretion, the BSD license. See the AutoOpts and/or libopts sources
17 * for details.
19 * The genshellopt program is copyrighted and licensed
20 * under the following terms:
22 * Copyright (C) 1999-2012 Bruce Korb, all rights reserved.
23 * This is free software. It is licensed for use, modification and
24 * redistribution under the terms of the
25 * GNU General Public License, version 3 or later
26 * <http://gnu.org/licenses/gpl.html>
28 * genshellopt is free software: you can redistribute it and/or modify it
29 * under the terms of the GNU General Public License as published by the
30 * Free Software Foundation, either version 3 of the License, or
31 * (at your option) any later version.
33 * genshellopt is distributed in the hope that it will be useful, but
34 * WITHOUT ANY WARRANTY; without even the implied warranty of
35 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
36 * See the GNU General Public License for more details.
38 * You should have received a copy of the GNU General Public License along
39 * with this program. If not, see <http://www.gnu.org/licenses/>.
42 #ifndef __doxygen__
43 #define OPTION_CODE_COMPILE 1
44 #include "genshell.h"
45 #include <sys/types.h>
47 #include <limits.h>
48 #include <stdio.h>
49 #include <stdlib.h>
51 #ifdef __cplusplus
52 extern "C" {
53 #endif
54 extern FILE * option_usage_fp;
56 /* TRANSLATORS: choose the translation for option names wisely because you
57 cannot ever change your mind. */
58 #define zCopyright (genshellopt_opt_strs+0)
59 #define zLicenseDescrip (genshellopt_opt_strs+260)
61 extern tUsageProc genshelloptUsage;
63 #ifndef NULL
64 # define NULL 0
65 #endif
68 * genshellopt option static const strings
70 static char const genshellopt_opt_strs[1690] =
71 /* 0 */ "genshellopt 1\n"
72 "Copyright (C) 1999-2012 Bruce Korb, all rights reserved.\n"
73 "This is free software. It is licensed for use, modification and\n"
74 "redistribution under the terms of the\n"
75 "GNU General Public License, version 3 or later\n"
76 " <http://gnu.org/licenses/gpl.html>\n\0"
77 /* 260 */ "genshellopt is free software: you can redistribute it and/or modify it\n"
78 "under the terms of the GNU General Public License as published by the Free\n"
79 "Software Foundation, either version 3 of the License, or (at your option)\n"
80 "any later version.\n\n"
81 "genshellopt is distributed in the hope that it will be useful, but WITHOUT\n"
82 "ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or\n"
83 "FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for\n"
84 "more details.\n\n"
85 "You should have received a copy of the GNU General Public License along\n"
86 "with this program. If not, see <http://www.gnu.org/licenses/>.\n\0"
87 /* 871 */ "Output Script File\0"
88 /* 890 */ "SCRIPT\0"
89 /* 897 */ "script\0"
90 /* 904 */ "Shell name (follows \"#!\" magic)\0"
91 /* 936 */ "SHELL\0"
92 /* 942 */ "no-shell\0"
93 /* 951 */ "no\0"
94 /* 954 */ "Display extended usage information and exit\0"
95 /* 998 */ "help\0"
96 /* 1003 */ "Extended usage information passed thru pager\0"
97 /* 1048 */ "more-help\0"
98 /* 1058 */ "Output version information and exit\0"
99 /* 1094 */ "version\0"
100 /* 1102 */ "GENSHELLOPT\0"
101 /* 1114 */ "genshellopt - Generate Shell Option Processing Script - Ver. 1\n"
102 "USAGE: %s [ -<flag> [<val>] | --<name>[{=| }<val>] ]...\n\0"
103 /* 1235 */ "autogen-users@lists.sourceforge.net\0"
104 /* 1271 */ "\n"
105 "Note that ``shell'' is only useful if the output file does not already\n"
106 "exist. If it does, then the shell name and optional first argument will be\n"
107 "extracted from the script file.\n\0"
108 /* 1452 */ "\n"
109 "If the script file already exists and contains Automated Option Processing\n"
110 "text, the second line of the file through the ending tag will be replaced\n"
111 "by the newly generated text. The first ``#!'' line will be regenerated.\n\0"
112 /* 1676 */ "genshellopt 1";
115 * script option description:
117 #define SCRIPT_DESC (genshellopt_opt_strs+871)
118 #define SCRIPT_NAME (genshellopt_opt_strs+890)
119 #define SCRIPT_name (genshellopt_opt_strs+897)
120 #define SCRIPT_FLAGS (OPTST_DISABLED \
121 | OPTST_SET_ARGTYPE(OPARG_TYPE_STRING))
124 * shell option description:
126 #define SHELL_DESC (genshellopt_opt_strs+904)
127 #define SHELL_NAME (genshellopt_opt_strs+936)
128 #define NOT_SHELL_name (genshellopt_opt_strs+942)
129 #define NOT_SHELL_PFX (genshellopt_opt_strs+951)
130 #define SHELL_name (NOT_SHELL_name + 3)
131 #define SHELL_FLAGS (OPTST_INITENABLED \
132 | OPTST_SET_ARGTYPE(OPARG_TYPE_STRING))
135 * Help/More_Help/Version option descriptions:
137 #define HELP_DESC (genshellopt_opt_strs+954)
138 #define HELP_name (genshellopt_opt_strs+998)
139 #ifdef HAVE_WORKING_FORK
140 #define MORE_HELP_DESC (genshellopt_opt_strs+1003)
141 #define MORE_HELP_name (genshellopt_opt_strs+1048)
142 #define MORE_HELP_FLAGS (OPTST_IMM | OPTST_NO_INIT)
143 #else
144 #define MORE_HELP_DESC NULL
145 #define MORE_HELP_name NULL
146 #define MORE_HELP_FLAGS (OPTST_OMITTED | OPTST_NO_INIT)
147 #endif
148 #ifdef NO_OPTIONAL_OPT_ARGS
149 # define VER_FLAGS (OPTST_IMM | OPTST_NO_INIT)
150 #else
151 # define VER_FLAGS (OPTST_SET_ARGTYPE(OPARG_TYPE_STRING) | \
152 OPTST_ARG_OPTIONAL | OPTST_IMM | OPTST_NO_INIT)
153 #endif
154 #define VER_DESC (genshellopt_opt_strs+1058)
155 #define VER_name (genshellopt_opt_strs+1094)
157 * Declare option callback procedures
159 extern tOptProc
160 optionBooleanVal, optionNestedVal, optionNumericVal,
161 optionPagedUsage, optionPrintVersion, optionResetOpt,
162 optionStackArg, optionTimeDate, optionTimeVal,
163 optionUnstackArg, optionVendorOption;
164 static tOptProc
165 doUsageOpt;
166 #define VER_PROC optionPrintVersion
168 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
170 * Define the genshellopt Option Descriptions.
171 * This is an array of GENSHELL_OPTION_CT entries, one for each
172 * option that the genshellopt program responds to.
174 static tOptDesc optDesc[GENSHELL_OPTION_CT] = {
175 { /* entry idx, value */ 0, VALUE_GENSHELL_OPT_SCRIPT,
176 /* equiv idx, value */ 0, VALUE_GENSHELL_OPT_SCRIPT,
177 /* equivalenced to */ NO_EQUIVALENT,
178 /* min, max, act ct */ 0, 1, 0,
179 /* opt state flags */ SCRIPT_FLAGS, 0,
180 /* last opt argumnt */ { NULL }, /* --script */
181 /* arg list/cookie */ NULL,
182 /* must/cannot opts */ NULL, NULL,
183 /* option proc */ NULL,
184 /* desc, NAME, name */ SCRIPT_DESC, SCRIPT_NAME, SCRIPT_name,
185 /* disablement strs */ NULL, NULL },
187 { /* entry idx, value */ 1, VALUE_GENSHELL_OPT_SHELL,
188 /* equiv idx, value */ 1, VALUE_GENSHELL_OPT_SHELL,
189 /* equivalenced to */ NO_EQUIVALENT,
190 /* min, max, act ct */ 0, 1, 0,
191 /* opt state flags */ SHELL_FLAGS, 0,
192 /* last opt argumnt */ { NULL }, /* --shell */
193 /* arg list/cookie */ NULL,
194 /* must/cannot opts */ NULL, NULL,
195 /* option proc */ NULL,
196 /* desc, NAME, name */ SHELL_DESC, SHELL_NAME, SHELL_name,
197 /* disablement strs */ NOT_SHELL_name, NOT_SHELL_PFX },
199 { /* entry idx, value */ INDEX_GENSHELL_OPT_VERSION, VALUE_GENSHELL_OPT_VERSION,
200 /* equiv idx value */ NO_EQUIVALENT, VALUE_GENSHELL_OPT_VERSION,
201 /* equivalenced to */ NO_EQUIVALENT,
202 /* min, max, act ct */ 0, 1, 0,
203 /* opt state flags */ VER_FLAGS, 0,
204 /* last opt argumnt */ { NULL },
205 /* arg list/cookie */ NULL,
206 /* must/cannot opts */ NULL, NULL,
207 /* option proc */ VER_PROC,
208 /* desc, NAME, name */ VER_DESC, NULL, VER_name,
209 /* disablement strs */ NULL, NULL },
213 { /* entry idx, value */ INDEX_GENSHELL_OPT_HELP, VALUE_GENSHELL_OPT_HELP,
214 /* equiv idx value */ NO_EQUIVALENT, VALUE_GENSHELL_OPT_HELP,
215 /* equivalenced to */ NO_EQUIVALENT,
216 /* min, max, act ct */ 0, 1, 0,
217 /* opt state flags */ OPTST_IMM | OPTST_NO_INIT, 0,
218 /* last opt argumnt */ { NULL },
219 /* arg list/cookie */ NULL,
220 /* must/cannot opts */ NULL, NULL,
221 /* option proc */ doUsageOpt,
222 /* desc, NAME, name */ HELP_DESC, NULL, HELP_name,
223 /* disablement strs */ NULL, NULL },
225 { /* entry idx, value */ INDEX_GENSHELL_OPT_MORE_HELP, VALUE_GENSHELL_OPT_MORE_HELP,
226 /* equiv idx value */ NO_EQUIVALENT, VALUE_GENSHELL_OPT_MORE_HELP,
227 /* equivalenced to */ NO_EQUIVALENT,
228 /* min, max, act ct */ 0, 1, 0,
229 /* opt state flags */ MORE_HELP_FLAGS, 0,
230 /* last opt argumnt */ { NULL },
231 /* arg list/cookie */ NULL,
232 /* must/cannot opts */ NULL, NULL,
233 /* option proc */ optionPagedUsage,
234 /* desc, NAME, name */ MORE_HELP_DESC, NULL, MORE_HELP_name,
235 /* disablement strs */ NULL, NULL }
239 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
241 * Define the genshellopt Option Environment
243 #define zPROGNAME (genshellopt_opt_strs+1102)
244 #define zUsageTitle (genshellopt_opt_strs+1114)
245 #define zRcName NULL
246 #define apzHomeList NULL
247 #define zBugsAddr (genshellopt_opt_strs+1235)
248 #define zExplain (genshellopt_opt_strs+1271)
249 #define zDetail (genshellopt_opt_strs+1452)
250 #define zFullVersion (genshellopt_opt_strs+1676)
251 /* extracted from optcode.tlib near line 350 */
253 #if defined(ENABLE_NLS)
254 # define OPTPROC_BASE OPTPROC_TRANSLATE
255 static tOptionXlateProc translate_option_strings;
256 #else
257 # define OPTPROC_BASE OPTPROC_NONE
258 # define translate_option_strings NULL
259 #endif /* ENABLE_NLS */
262 #define genshellopt_full_usage (NULL)
264 #define genshellopt_short_usage (NULL)
266 #endif /* not defined __doxygen__ */
269 * Create the static procedure(s) declared above.
272 * The callout function that invokes the genshelloptUsage function.
274 * @param pOptions the AutoOpts option description structure
275 * @param pOptDesc the descriptor for the "help" (usage) option.
276 * @noreturn
278 static void
279 doUsageOpt(tOptions * pOptions, tOptDesc * pOptDesc)
281 genshelloptUsage(&genshelloptOptions, GENSHELLOPT_EXIT_SUCCESS);
282 /* NOTREACHED */
283 (void)pOptDesc;
284 (void)pOptions;
286 /* extracted from optmain.tlib near line 1113 */
289 * The directory containing the data associated with genshellopt.
291 #ifndef PKGDATADIR
292 # define PKGDATADIR ""
293 #endif
296 * Information about the person or institution that packaged genshellopt
297 * for the current distribution.
299 #ifndef WITH_PACKAGER
300 # define genshellopt_packager_info NULL
301 #else
302 static char const genshellopt_packager_info[] =
303 "Packaged by " WITH_PACKAGER
305 # ifdef WITH_PACKAGER_VERSION
306 " ("WITH_PACKAGER_VERSION")"
307 # endif
309 # ifdef WITH_PACKAGER_BUG_REPORTS
310 "\nReport genshellopt bugs to " WITH_PACKAGER_BUG_REPORTS
311 # endif
312 "\n";
313 #endif
314 #ifndef __doxygen__
316 #endif /* __doxygen__ */
318 * The option definitions for genshellopt. The one structure that
319 * binds them all.
321 tOptions genshelloptOptions = {
322 OPTIONS_STRUCT_VERSION,
323 0, NULL, /* original argc + argv */
324 ( OPTPROC_BASE
325 + OPTPROC_ERRSTOP
326 + OPTPROC_SHORTOPT
327 + OPTPROC_LONGOPT
328 + OPTPROC_NO_REQ_OPT
329 + OPTPROC_NEGATIONS
330 + OPTPROC_NO_ARGS ),
331 0, NULL, /* current option index, current option */
332 NULL, NULL, zPROGNAME,
333 zRcName, zCopyright, zLicenseDescrip,
334 zFullVersion, apzHomeList, zUsageTitle,
335 zExplain, zDetail, optDesc,
336 zBugsAddr, /* address to send bugs to */
337 NULL, NULL, /* extensions/saved state */
338 genshelloptUsage, /* usage procedure */
339 translate_option_strings, /* translation procedure */
341 * Indexes to special options
343 { INDEX_GENSHELL_OPT_MORE_HELP, /* more-help option index */
344 NO_EQUIVALENT, /* save option index */
345 NO_EQUIVALENT, /* '-#' option index */
346 NO_EQUIVALENT /* index of default opt */
348 5 /* full option count */, 2 /* user option count */,
349 genshellopt_full_usage, genshellopt_short_usage,
350 NULL, NULL,
351 PKGDATADIR, genshellopt_packager_info
354 #if ENABLE_NLS
355 #include <stdio.h>
356 #include <stdlib.h>
357 #include <string.h>
358 #include <unistd.h>
359 #include <autoopts/usage-txt.h>
361 static char* AO_gettext(char const* pz);
362 static void coerce_it(void** s);
365 * AutoGen specific wrapper function for gettext.
366 * It relies on the macro _() to convert from English to the target
367 * language, then strdup-duplicates the result string.
369 * @param[in] pz the input text used as a lookup key.
370 * @returns the translated text (if there is one),
371 * or the original text (if not).
373 static char *
374 AO_gettext(char const* pz)
376 char* pzRes;
377 if (pz == NULL)
378 return NULL;
379 pzRes = _(pz);
380 if (pzRes == pz)
381 return pzRes;
382 pzRes = strdup(pzRes);
383 if (pzRes == NULL) {
384 fputs(_("No memory for duping translated strings\n"), stderr);
385 exit(GENSHELLOPT_EXIT_FAILURE);
387 return pzRes;
390 static void coerce_it(void** s) { *s = AO_gettext(*s);
394 * Translate all the translatable strings in the genshelloptOptions
395 * structure defined above. This is done only once.
397 static void
398 translate_option_strings(void)
400 tOptions * const pOpt = &genshelloptOptions;
403 * Guard against re-translation. It won't work. The strings will have
404 * been changed by the first pass through this code. One shot only.
406 if (option_usage_text.field_ct != 0) {
408 * Do the translations. The first pointer follows the field count
409 * field. The field count field is the size of a pointer.
411 tOptDesc * pOD = pOpt->pOptDesc;
412 char ** ppz = (char**)(void*)&(option_usage_text);
413 int ix = option_usage_text.field_ct;
415 do {
416 ppz++;
417 *ppz = AO_gettext(*ppz);
418 } while (--ix > 0);
420 coerce_it((void*)&(pOpt->pzCopyright));
421 coerce_it((void*)&(pOpt->pzCopyNotice));
422 coerce_it((void*)&(pOpt->pzFullVersion));
423 coerce_it((void*)&(pOpt->pzUsageTitle));
424 coerce_it((void*)&(pOpt->pzExplain));
425 coerce_it((void*)&(pOpt->pzDetail));
426 coerce_it((void*)&(pOpt->pzPackager));
427 option_usage_text.field_ct = 0;
429 for (ix = pOpt->optCt; ix > 0; ix--, pOD++)
430 coerce_it((void*)&(pOD->pzText));
433 if ((pOpt->fOptSet & OPTPROC_NXLAT_OPT_CFG) == 0) {
434 tOptDesc * pOD = pOpt->pOptDesc;
435 int ix;
437 for (ix = pOpt->optCt; ix > 0; ix--, pOD++) {
438 coerce_it((void*)&(pOD->pz_Name));
439 coerce_it((void*)&(pOD->pz_DisableName));
440 coerce_it((void*)&(pOD->pz_DisablePfx));
442 /* prevent re-translation */
443 genshelloptOptions.fOptSet |= OPTPROC_NXLAT_OPT_CFG | OPTPROC_NXLAT_OPT;
447 #endif /* ENABLE_NLS */
449 #ifdef __cplusplus
451 #endif
452 /* genshell.c ends here */