xref: /netbsd-src/external/bsd/ntp/dist/sntp/libopts/genshell.c (revision 7788a0781fe6ff2cce37368b4578a7ade0850cb1)
1 /*	$NetBSD: genshell.c,v 1.1.1.2 2012/01/31 21:27:49 kardel Exp $	*/
2 
3 /*   -*- buffer-read-only: t -*- vi: set ro:
4  *
5  *  DO NOT EDIT THIS FILE   (genshell.c)
6  *
7  *  It has been AutoGen-ed  April 29, 2011 at 03:43:59 PM by AutoGen 5.11.9
8  *  From the definitions    genshell.def
9  *  and the template file   options
10  *
11  * Generated from AutoOpts 35:0:10 templates.
12  *
13  *  AutoOpts is a copyrighted work.  This source 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  * This source file is copyrighted and licensed under the following terms:
22  *
23  * genshellopt copyright (c) 1999-2011 Bruce Korb - all rights reserved
24  *
25  * genshellopt is free software: you can redistribute it and/or modify it
26  * under the terms of the GNU General Public License as published by the
27  * Free Software Foundation, either version 3 of the License, or
28  * (at your option) any later version.
29  *
30  * genshellopt is distributed in the hope that it will be useful, but
31  * WITHOUT ANY WARRANTY; without even the implied warranty of
32  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
33  * See the GNU General Public License for more details.
34  *
35  * You should have received a copy of the GNU General Public License along
36  * with this program.  If not, see <http://www.gnu.org/licenses/>.
37 
38  */
39 
40 #include <sys/types.h>
41 
42 #include <limits.h>
43 #include <stdio.h>
44 #include <stdlib.h>
45 
46 #define OPTION_CODE_COMPILE 1
47 #include "genshell.h"
48 
49 #ifdef  __cplusplus
50 extern "C" {
51 #endif
52 extern FILE * option_usage_fp;
53 
54 /* TRANSLATORS: choose the translation for option names wisely because you
55                 cannot ever change your mind. */
56 static char const zCopyright[260] =
57 "genshellopt 1\n\
58 Copyright (C) 1999-2011 Bruce Korb, all rights reserved.\n\
59 This is free software. It is licensed for use, modification and\n\
60 redistribution under the terms of the\n\
61 GNU General Public License, version 3 or later\n\
62     <http://gnu.org/licenses/gpl.html>\n";
63 static char const zCopyrightNotice[611] =
64 "genshellopt is free software: you can redistribute it and/or modify it\n\
65 under the terms of the GNU General Public License as published by the\n\
66 Free Software Foundation, either version 3 of the License, or (at your\n\
67 option) any later version.\n\n\
68 genshellopt is distributed in the hope that it will be useful, but WITHOUT\n\
69 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or\n\
70 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License\n\
71 for more details.\n\n\
72 You should have received a copy of the GNU General Public License along\n\
73 with this program.  If not, see <http://www.gnu.org/licenses/>.\n";
74 
75 extern tUsageProc genshelloptUsage;
76 
77 #ifndef NULL
78 #  define NULL 0
79 #endif
80 
81 /*
82  *  Script option description:
83  */
84 static char const zScriptText[] =
85         "Output Script File";
86 static char const zScript_NAME[]             = "SCRIPT";
87 static char const zScript_Name[]             = "script";
88 #define SCRIPT_FLAGS       (OPTST_DISABLED \
89         | OPTST_SET_ARGTYPE(OPARG_TYPE_STRING))
90 
91 /*
92  *  Shell option description:
93  */
94 static char const zShellText[] =
95         "Shell name (follows \"#!\" magic)";
96 static char const zShell_NAME[]              = "SHELL";
97 static char const zNotShell_Name[]           = "no-shell";
98 static char const zNotShell_Pfx[]            = "no";
99 #define zShell_Name                  (zNotShell_Name + 3)
100 #define SHELL_FLAGS       (OPTST_INITENABLED \
101         | OPTST_SET_ARGTYPE(OPARG_TYPE_STRING))
102 
103 /*
104  *  Help/More_Help/Version option descriptions:
105  */
106 static char const zHelpText[]          = "Display extended usage information and exit";
107 static char const zHelp_Name[]         = "help";
108 #ifdef HAVE_WORKING_FORK
109 #define OPTST_MORE_HELP_FLAGS   (OPTST_IMM | OPTST_NO_INIT)
110 static char const zMore_Help_Name[]    = "more-help";
111 static char const zMore_HelpText[]     = "Extended usage information passed thru pager";
112 #else
113 #define OPTST_MORE_HELP_FLAGS   (OPTST_OMITTED | OPTST_NO_INIT)
114 #define zMore_Help_Name   NULL
115 #define zMore_HelpText    NULL
116 #endif
117 #ifdef NO_OPTIONAL_OPT_ARGS
118 #  define OPTST_VERSION_FLAGS   OPTST_IMM | OPTST_NO_INIT
119 #else
120 #  define OPTST_VERSION_FLAGS   OPTST_SET_ARGTYPE(OPARG_TYPE_STRING) | \
121                                 OPTST_ARG_OPTIONAL | OPTST_IMM | OPTST_NO_INIT
122 #endif
123 
124 static char const zVersionText[]       = "Output version information and exit";
125 static char const zVersion_Name[]      = "version";
126 /*
127  *  Declare option callback procedures
128  */
129 extern tOptProc
130     optionBooleanVal,    optionNestedVal,     optionNumericVal,
131     optionPagedUsage,    optionPrintVersion,  optionResetOpt,
132     optionStackArg,      optionTimeDate,      optionTimeVal,
133     optionUnstackArg,    optionVersionStderr;
134 static tOptProc
135     doUsageOpt;
136 
137 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
138  *
139  *  Define the Genshellopt Option Descriptions.
140  */
141 static tOptDesc optDesc[GENSHELL_OPTION_CT] = {
142   {  /* entry idx, value */ 0, VALUE_GENSHELL_OPT_SCRIPT,
143      /* equiv idx, value */ 0, VALUE_GENSHELL_OPT_SCRIPT,
144      /* equivalenced to  */ NO_EQUIVALENT,
145      /* min, max, act ct */ 0, 1, 0,
146      /* opt state flags  */ SCRIPT_FLAGS, 0,
147      /* last opt argumnt */ { NULL },
148      /* arg list/cookie  */ NULL,
149      /* must/cannot opts */ NULL, NULL,
150      /* option proc      */ NULL,
151      /* desc, NAME, name */ zScriptText, zScript_NAME, zScript_Name,
152      /* disablement strs */ NULL, NULL },
153 
154   {  /* entry idx, value */ 1, VALUE_GENSHELL_OPT_SHELL,
155      /* equiv idx, value */ 1, VALUE_GENSHELL_OPT_SHELL,
156      /* equivalenced to  */ NO_EQUIVALENT,
157      /* min, max, act ct */ 0, 1, 0,
158      /* opt state flags  */ SHELL_FLAGS, 0,
159      /* last opt argumnt */ { NULL },
160      /* arg list/cookie  */ NULL,
161      /* must/cannot opts */ NULL, NULL,
162      /* option proc      */ NULL,
163      /* desc, NAME, name */ zShellText, zShell_NAME, zShell_Name,
164      /* disablement strs */ zNotShell_Name, zNotShell_Pfx },
165 
166   {  /* entry idx, value */ INDEX_GENSHELL_OPT_VERSION, VALUE_GENSHELL_OPT_VERSION,
167      /* equiv idx value  */ NO_EQUIVALENT, 0,
168      /* equivalenced to  */ NO_EQUIVALENT,
169      /* min, max, act ct */ 0, 1, 0,
170      /* opt state flags  */ OPTST_VERSION_FLAGS, 0,
171      /* last opt argumnt */ { NULL },
172      /* arg list/cookie  */ NULL,
173      /* must/cannot opts */ NULL, NULL,
174      /* option proc      */ optionPrintVersion,
175      /* desc, NAME, name */ zVersionText, NULL, zVersion_Name,
176      /* disablement strs */ NULL, NULL },
177 
178 
179 
180   {  /* entry idx, value */ INDEX_GENSHELL_OPT_HELP, VALUE_GENSHELL_OPT_HELP,
181      /* equiv idx value  */ NO_EQUIVALENT, 0,
182      /* equivalenced to  */ NO_EQUIVALENT,
183      /* min, max, act ct */ 0, 1, 0,
184      /* opt state flags  */ OPTST_IMM | OPTST_NO_INIT, 0,
185      /* last opt argumnt */ { NULL },
186      /* arg list/cookie  */ NULL,
187      /* must/cannot opts */ NULL, NULL,
188      /* option proc      */ doUsageOpt,
189      /* desc, NAME, name */ zHelpText, NULL, zHelp_Name,
190      /* disablement strs */ NULL, NULL },
191 
192   {  /* entry idx, value */ INDEX_GENSHELL_OPT_MORE_HELP, VALUE_GENSHELL_OPT_MORE_HELP,
193      /* equiv idx value  */ NO_EQUIVALENT, 0,
194      /* equivalenced to  */ NO_EQUIVALENT,
195      /* min, max, act ct */ 0, 1, 0,
196      /* opt state flags  */ OPTST_MORE_HELP_FLAGS, 0,
197      /* last opt argumnt */ { NULL },
198      /* arg list/cookie  */ NULL,
199      /* must/cannot opts */ NULL,  NULL,
200      /* option proc      */ optionPagedUsage,
201      /* desc, NAME, name */ zMore_HelpText, NULL, zMore_Help_Name,
202      /* disablement strs */ NULL, NULL }
203 };
204 
205 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
206  *
207  *  Define the Genshellopt Option Environment
208  */
209 static char const zPROGNAME[12] = "GENSHELLOPT";
210 static char const zUsageTitle[121] =
211 "genshellopt - Generate Shell Option Processing Script - Ver. 1\n\
212 USAGE:  %s [ -<flag> [<val>] | --<name>[{=| }<val>] ]...\n";
213 #define zRcName     NULL
214 #define apzHomeList NULL
215 
216 static char const zBugsAddr[36]    = "autogen-users@lists.sourceforge.net";
217 static char const zExplain[] = "\n\
218 Note that ``shell'' is only useful if the output file does not already\n\
219 exist.  If it does, then the shell name and optional first argument will\n\
220 be extracted from the script file.\n";
221 static char const zDetail[237] = "\n\
222 If the script file already exists and contains Automated Option Processing\n\
223 text, the second line of the file through the ending tag will be replaced\n\
224 by the newly generated text.  The first ``#!''  line will be regenerated.\n";
225 static char const zFullVersion[] = GENSHELLOPT_FULL_VERSION;
226 /* extracted from optcode.tlib near line 515 */
227 
228 #if defined(ENABLE_NLS)
229 # define OPTPROC_BASE OPTPROC_TRANSLATE
230   static tOptionXlateProc translate_option_strings;
231 #else
232 # define OPTPROC_BASE OPTPROC_NONE
233 # define translate_option_strings NULL
234 #endif /* ENABLE_NLS */
235 
236 
237 #define genshellopt_full_usage NULL
238 #define genshellopt_short_usage NULL
239 #ifndef  PKGDATADIR
240 # define PKGDATADIR ""
241 #endif
242 
243 #ifndef  WITH_PACKAGER
244 # define genshellopt_packager_info NULL
245 #else
246 static char const genshellopt_packager_info[] =
247     "Packaged by " WITH_PACKAGER
248 
249 # ifdef WITH_PACKAGER_VERSION
250         " ("WITH_PACKAGER_VERSION")"
251 # endif
252 
253 # ifdef WITH_PACKAGER_BUG_REPORTS
254     "\nReport genshellopt bugs to " WITH_PACKAGER_BUG_REPORTS
255 # endif
256     "\n";
257 #endif
258 
259 tOptions genshelloptOptions = {
260     OPTIONS_STRUCT_VERSION,
261     0, NULL,                    /* original argc + argv    */
262     ( OPTPROC_BASE
263     + OPTPROC_ERRSTOP
264     + OPTPROC_SHORTOPT
265     + OPTPROC_LONGOPT
266     + OPTPROC_NO_REQ_OPT
267     + OPTPROC_NEGATIONS
268     + OPTPROC_NO_ARGS ),
269     0, NULL,                    /* current option index, current option */
270     NULL,         NULL,         zPROGNAME,
271     zRcName,      zCopyright,   zCopyrightNotice,
272     zFullVersion, apzHomeList,  zUsageTitle,
273     zExplain,     zDetail,      optDesc,
274     zBugsAddr,                  /* address to send bugs to */
275     NULL, NULL,                 /* extensions/saved state  */
276     genshelloptUsage, /* usage procedure */
277     translate_option_strings,   /* translation procedure */
278     /*
279      *  Indexes to special options
280      */
281     { INDEX_GENSHELL_OPT_MORE_HELP, /* more-help option index */
282       NO_EQUIVALENT, /* save option index */
283       NO_EQUIVALENT, /* '-#' option index */
284       NO_EQUIVALENT /* index of default opt */
285     },
286     5 /* full option count */, 2 /* user option count */,
287     genshellopt_full_usage, genshellopt_short_usage,
288     NULL, NULL,
289     PKGDATADIR, genshellopt_packager_info
290 };
291 
292 /*
293  *  Create the static procedure(s) declared above.
294  */
295 static void
296 doUsageOpt(tOptions * pOptions, tOptDesc * pOptDesc)
297 {
298     (void)pOptions;
299     GENSHELL_USAGE(GENSHELLOPT_EXIT_SUCCESS);
300 }
301 /* extracted from optcode.tlib near line 666 */
302 
303 #if ENABLE_NLS
304 #include <stdio.h>
305 #include <stdlib.h>
306 #include <string.h>
307 #include <unistd.h>
308 #include <autoopts/usage-txt.h>
309 
310 static char* AO_gettext(char const* pz);
311 static void  coerce_it(void** s);
312 
313 static char*
314 AO_gettext(char const* pz)
315 {
316     char* pzRes;
317     if (pz == NULL)
318         return NULL;
319     pzRes = _(pz);
320     if (pzRes == pz)
321         return pzRes;
322     pzRes = strdup(pzRes);
323     if (pzRes == NULL) {
324         fputs(_("No memory for duping translated strings\n"), stderr);
325         exit(GENSHELLOPT_EXIT_FAILURE);
326     }
327     return pzRes;
328 }
329 
330 static void coerce_it(void** s) { *s = AO_gettext(*s);
331 }
332 
333 /*
334  *  This invokes the translation code (e.g. gettext(3)).
335  */
336 static void
337 translate_option_strings(void)
338 {
339     tOptions * const pOpt = &genshelloptOptions;
340 
341     /*
342      *  Guard against re-translation.  It won't work.  The strings will have
343      *  been changed by the first pass through this code.  One shot only.
344      */
345     if (option_usage_text.field_ct != 0) {
346         /*
347          *  Do the translations.  The first pointer follows the field count
348          *  field.  The field count field is the size of a pointer.
349          */
350         tOptDesc * pOD = pOpt->pOptDesc;
351         char **    ppz = (char**)(void*)&(option_usage_text);
352         int        ix  = option_usage_text.field_ct;
353 
354         do {
355             ppz++;
356             *ppz = AO_gettext(*ppz);
357         } while (--ix > 0);
358 
359         coerce_it((void*)&(pOpt->pzCopyright));
360         coerce_it((void*)&(pOpt->pzCopyNotice));
361         coerce_it((void*)&(pOpt->pzFullVersion));
362         coerce_it((void*)&(pOpt->pzUsageTitle));
363         coerce_it((void*)&(pOpt->pzExplain));
364         coerce_it((void*)&(pOpt->pzDetail));
365         coerce_it((void*)&(pOpt->pzPackager));
366         option_usage_text.field_ct = 0;
367 
368         for (ix = pOpt->optCt; ix > 0; ix--, pOD++)
369             coerce_it((void*)&(pOD->pzText));
370     }
371 
372     if ((pOpt->fOptSet & OPTPROC_NXLAT_OPT_CFG) == 0) {
373         tOptDesc * pOD = pOpt->pOptDesc;
374         int        ix;
375 
376         for (ix = pOpt->optCt; ix > 0; ix--, pOD++) {
377             coerce_it((void*)&(pOD->pz_Name));
378             coerce_it((void*)&(pOD->pz_DisableName));
379             coerce_it((void*)&(pOD->pz_DisablePfx));
380         }
381         /* prevent re-translation */
382         genshelloptOptions.fOptSet |= OPTPROC_NXLAT_OPT_CFG | OPTPROC_NXLAT_OPT;
383     }
384 }
385 
386 #endif /* ENABLE_NLS */
387 
388 #ifdef  __cplusplus
389 }
390 #endif
391 /* genshell.c ends here */
392