xref: /freebsd/contrib/ntp/sntp/libopts/genshell.c (revision 195ebc7e9e4b129de810833791a19dfb4349d6a9)
1 /*   -*- buffer-read-only: t -*- vi: set ro:
2  *
3  *  DO NOT EDIT THIS FILE   (genshell.c)
4  *
5  *  It has been AutoGen-ed  Saturday May  5, 2007 at 12:02:35 PM PDT
6  *  From the definitions    genshell.def
7  *  and the template file   options
8  *
9  * Generated from AutoOpts 29:0:4 templates.
10  */
11 
12 /*
13  *  This file was produced by an AutoOpts template.  AutoOpts is a
14  *  copyrighted work.  This source file is not encumbered by AutoOpts
15  *  licensing, but is provided under the licensing terms chosen by the
16  *  genshellopt author or copyright holder.  AutoOpts is licensed under
17  *  the terms of the LGPL.  The redistributable library (``libopts'') is
18  *  licensed under the terms of either the LGPL or, at the users discretion,
19  *  the BSD license.  See the AutoOpts and/or libopts sources for details.
20  *
21  * This source file is copyrighted and licensed under the following terms:
22  *
23  * genshellopt copyright 1999-2007 Bruce Korb - all rights reserved
24  *
25  * genshellopt is free software; you can redistribute it and/or
26  * modify it under the terms of the GNU Lesser General Public
27  * License as published by the Free Software Foundation; either
28  * version 2.1 of the License, or (at your option) any later version.
29  *
30  * genshellopt is distributed in the hope that it will be useful,
31  * but WITHOUT ANY WARRANTY; without even the implied warranty of
32  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
33  * Lesser General Public License for more details.
34  *
35  * You should have received a copy of the GNU Lesser General Public
36  * License along with genshellopt.  If not, write to:
37  * 	The Free Software Foundation, Inc.,
38  * 	51 Franklin Street, Fifth Floor
39  * 	Boston, MA  02110-1301, USA.
40  */
41 
42 
43 #include <limits.h>
44 
45 #define OPTION_CODE_COMPILE 1
46 #include "genshell.h"
47 
48 #ifdef  __cplusplus
49 extern "C" {
50 #endif
51 tSCC zCopyright[] =
52        "genshellopt copyright (c) 1999-2007 Bruce Korb, all rights reserved";
53 tSCC zCopyrightNotice[] =
54        "genshellopt is free software; you can redistribute it and/or\n\
55 modify it under the terms of the GNU Lesser General Public\n\
56 License as published by the Free Software Foundation; either\n\
57 version 2.1 of the License, or (at your option) any later version.\n\n\
58 genshellopt is distributed in the hope that it will be useful,\n\
59 but WITHOUT ANY WARRANTY; without even the implied warranty of\n\
60 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n\
61 Lesser General Public License for more details.\n\n\
62 You should have received a copy of the GNU Lesser General Public\n\
63 License along with genshellopt.  If not, write to:\n\
64 \tThe Free Software Foundation, Inc.,\n\
65 \t51 Franklin Street, Fifth Floor\n\
66 \tBoston, MA  02110-1301, USA.";
67 extern tUsageProc genshelloptUsage;
68 
69 #ifndef NULL
70 #  define NULL 0
71 #endif
72 #ifndef EXIT_SUCCESS
73 #  define  EXIT_SUCCESS 0
74 #endif
75 #ifndef EXIT_FAILURE
76 #  define  EXIT_FAILURE 1
77 #endif
78 /*
79  *  Script option description:
80  */
81 tSCC    zScriptText[] =
82         "Output Script File";
83 tSCC    zScript_NAME[]             = "SCRIPT";
84 tSCC    zScript_Name[]             = "script";
85 #define SCRIPT_FLAGS       (OPTST_DISABLED \
86         | OPTST_SET_ARGTYPE(OPARG_TYPE_STRING))
87 
88 /*
89  *  Shell option description:
90  */
91 tSCC    zShellText[] =
92         "Shell name (follows \"#!\" magic)";
93 tSCC    zShell_NAME[]              = "SHELL";
94 tSCC    zNotShell_Name[]           = "no-shell";
95 tSCC    zNotShell_Pfx[]            = "no";
96 #define zShell_Name                  (zNotShell_Name + 3)
97 #define SHELL_FLAGS       (OPTST_INITENABLED \
98         | OPTST_SET_ARGTYPE(OPARG_TYPE_STRING))
99 
100 /*
101  *  Help/More_Help/Version option descriptions:
102  */
103 tSCC zHelpText[]       = "Display usage information and exit";
104 tSCC zHelp_Name[]      = "help";
105 
106 tSCC zMore_HelpText[]  = "Extended usage information passed thru pager";
107 tSCC zMore_Help_Name[] = "more-help";
108 
109 tSCC zVersionText[]    = "Output version information and exit";
110 tSCC zVersion_Name[]   = "version";
111 /*
112  *  Declare option callback procedures
113  */
114 extern tOptProc
115     optionPagedUsage, optionPrintVersion;
116 static tOptProc
117     doUsageOpt;
118 
119 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
120  *
121  *  Define the Genshellopt Option Descriptions.
122  */
123 static tOptDesc optDesc[ OPTION_CT ] = {
124   {  /* entry idx, value */ 0, VALUE_OPT_SCRIPT,
125      /* equiv idx, value */ 0, VALUE_OPT_SCRIPT,
126      /* equivalenced to  */ NO_EQUIVALENT,
127      /* min, max, act ct */ 0, 1, 0,
128      /* opt state flags  */ SCRIPT_FLAGS, 0,
129      /* last opt argumnt */ { NULL },
130      /* arg list/cookie  */ NULL,
131      /* must/cannot opts */ NULL, NULL,
132      /* option proc      */ NULL,
133      /* desc, NAME, name */ zScriptText, zScript_NAME, zScript_Name,
134      /* disablement strs */ NULL, NULL },
135 
136   {  /* entry idx, value */ 1, VALUE_OPT_SHELL,
137      /* equiv idx, value */ 1, VALUE_OPT_SHELL,
138      /* equivalenced to  */ NO_EQUIVALENT,
139      /* min, max, act ct */ 0, 1, 0,
140      /* opt state flags  */ SHELL_FLAGS, 0,
141      /* last opt argumnt */ { NULL },
142      /* arg list/cookie  */ NULL,
143      /* must/cannot opts */ NULL, NULL,
144      /* option proc      */ NULL,
145      /* desc, NAME, name */ zShellText, zShell_NAME, zShell_Name,
146      /* disablement strs */ zNotShell_Name, zNotShell_Pfx },
147 
148 #ifdef NO_OPTIONAL_OPT_ARGS
149 #  define VERSION_OPT_FLAGS     OPTST_IMM | OPTST_NO_INIT
150 #else
151 #  define VERSION_OPT_FLAGS     OPTST_SET_ARGTYPE(OPARG_TYPE_STRING) | \
152                                 OPTST_ARG_OPTIONAL | OPTST_IMM | OPTST_NO_INIT
153 #endif
154 
155   {  /* entry idx, value */ INDEX_OPT_VERSION, VALUE_OPT_VERSION,
156      /* equiv idx value  */ NO_EQUIVALENT, 0,
157      /* equivalenced to  */ NO_EQUIVALENT,
158      /* min, max, act ct */ 0, 1, 0,
159      /* opt state flags  */ VERSION_OPT_FLAGS, 0,
160      /* last opt argumnt */ { NULL },
161      /* arg list/cookie  */ NULL,
162      /* must/cannot opts */ NULL, NULL,
163      /* option proc      */ optionPrintVersion,
164      /* desc, NAME, name */ zVersionText, NULL, zVersion_Name,
165      /* disablement strs */ NULL, NULL },
166 
167 #undef VERSION_OPT_FLAGS
168 
169 
170   {  /* entry idx, value */ INDEX_OPT_HELP, VALUE_OPT_HELP,
171      /* equiv idx value  */ NO_EQUIVALENT, 0,
172      /* equivalenced to  */ NO_EQUIVALENT,
173      /* min, max, act ct */ 0, 1, 0,
174      /* opt state flags  */ OPTST_IMM | OPTST_NO_INIT, 0,
175      /* last opt argumnt */ { NULL },
176      /* arg list/cookie  */ NULL,
177      /* must/cannot opts */ NULL, NULL,
178      /* option proc      */ doUsageOpt,
179      /* desc, NAME, name */ zHelpText, NULL, zHelp_Name,
180      /* disablement strs */ NULL, NULL },
181 
182   {  /* entry idx, value */ INDEX_OPT_MORE_HELP, VALUE_OPT_MORE_HELP,
183      /* equiv idx value  */ NO_EQUIVALENT, 0,
184      /* equivalenced to  */ NO_EQUIVALENT,
185      /* min, max, act ct */ 0, 1, 0,
186      /* opt state flags  */ OPTST_IMM | OPTST_NO_INIT, 0,
187      /* last opt argumnt */ { NULL },
188      /* arg list/cookie  */ NULL,
189      /* must/cannot opts */ NULL,  NULL,
190      /* option proc      */ optionPagedUsage,
191      /* desc, NAME, name */ zMore_HelpText, NULL, zMore_Help_Name,
192      /* disablement strs */ NULL, NULL }
193 };
194 
195 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
196  *
197  *  Define the Genshellopt Option Environment
198  */
199 tSCC   zPROGNAME[]   = "GENSHELLOPT";
200 tSCC   zUsageTitle[] =
201 "genshellopt - Generate Shell Option Processing Script - Ver. 1\n\
202 USAGE:  %s [ -<flag> [<val>] | --<name>[{=| }<val>] ]...\n";
203 #define zRcName     NULL
204 #define apzHomeList NULL
205 
206 tSCC   zBugsAddr[]    = "autogen-users@lists.sourceforge.net";
207 tSCC   zExplain[]     = "\n\
208 Note that `shell' is only useful if the output file does not already\n\
209 exist.  If it does, then the shell name and optional first argument\n\
210 will be extracted from the script file.\n";
211 tSCC    zDetail[]     = "\n\
212 If the script file already exists and contains Automated Option Processing\n\
213 text, the second line of the file through the ending tag will be replaced\n\
214 by the newly generated text.  The first `#!' line will be regenerated.\n";
215 tSCC    zFullVersion[] = GENSHELLOPT_FULL_VERSION;
216 /* extracted from optcode.tpl near line 408 */
217 
218 #if defined(ENABLE_NLS)
219 # define OPTPROC_BASE OPTPROC_TRANSLATE
220   static tOptionXlateProc translate_option_strings;
221 #else
222 # define OPTPROC_BASE OPTPROC_NONE
223 # define translate_option_strings NULL
224 #endif /* ENABLE_NLS */
225 
226 tOptions genshelloptOptions = {
227     OPTIONS_STRUCT_VERSION,
228     0, NULL,                    /* original argc + argv    */
229     ( OPTPROC_BASE
230     + OPTPROC_ERRSTOP
231     + OPTPROC_SHORTOPT
232     + OPTPROC_LONGOPT
233     + OPTPROC_NO_REQ_OPT
234     + OPTPROC_NEGATIONS
235     + OPTPROC_NO_ARGS ),
236     0, NULL,                    /* current option index, current option */
237     NULL,         NULL,         zPROGNAME,
238     zRcName,      zCopyright,   zCopyrightNotice,
239     zFullVersion, apzHomeList,  zUsageTitle,
240     zExplain,     zDetail,      optDesc,
241     zBugsAddr,                  /* address to send bugs to */
242     NULL, NULL,                 /* extensions/saved state  */
243     genshelloptUsage,       /* usage procedure */
244     translate_option_strings,   /* translation procedure */
245     /*
246      *  Indexes to special options
247      */
248     { INDEX_OPT_MORE_HELP,
249        0 /* no option state saving */,
250       NO_EQUIVALENT /* index of '-#' option */,
251       NO_EQUIVALENT /* index of default opt */
252     },
253     5 /* full option count */, 2 /* user option count */
254 };
255 
256 /*
257  *  Create the static procedure(s) declared above.
258  */
259 static void
260 doUsageOpt(
261     tOptions*   pOptions,
262     tOptDesc*   pOptDesc )
263 {
264     USAGE( EXIT_SUCCESS );
265 }
266 /* extracted from optcode.tpl near line 514 */
267 
268 #if ENABLE_NLS
269 #include <stdio.h>
270 #include <stdlib.h>
271 #include <string.h>
272 #include <unistd.h>
273 #include <autoopts/usage-txt.h>
274 
275 static char* AO_gettext( char const* pz );
276 static void  coerce_it(void** s);
277 
278 static char*
279 AO_gettext( char const* pz )
280 {
281     char* pzRes;
282     if (pz == NULL)
283         return NULL;
284     pzRes = _(pz);
285     if (pzRes == pz)
286         return pzRes;
287     pzRes = strdup( pzRes );
288     if (pzRes == NULL) {
289         fputs( _("No memory for duping translated strings\n"), stderr );
290         exit( EXIT_FAILURE );
291     }
292     return pzRes;
293 }
294 
295 static void coerce_it(void** s) { *s = AO_gettext(*s); }
296 #define COERSION(_f) \
297   coerce_it((void*)&(genshelloptOptions._f))
298 
299 /*
300  *  This invokes the translation code (e.g. gettext(3)).
301  */
302 static void
303 translate_option_strings( void )
304 {
305     /*
306      *  Guard against re-translation.  It won't work.  The strings will have
307      *  been changed by the first pass through this code.  One shot only.
308      */
309     if (option_usage_text.field_ct == 0)
310         return;
311     /*
312      *  Do the translations.  The first pointer follows the field count field.
313      *  The field count field is the size of a pointer.
314      */
315     {
316         char** ppz = (char**)(void*)&(option_usage_text);
317         int    ix  = option_usage_text.field_ct;
318 
319         do {
320             ppz++;
321             *ppz = AO_gettext(*ppz);
322         } while (--ix > 0);
323     }
324     option_usage_text.field_ct = 0;
325 
326     {
327         tOptDesc* pOD = genshelloptOptions.pOptDesc;
328         int       ix  = genshelloptOptions.optCt;
329 
330         for (;;) {
331             pOD->pzText           = AO_gettext(pOD->pzText);
332             pOD->pz_NAME          = AO_gettext(pOD->pz_NAME);
333             pOD->pz_Name          = AO_gettext(pOD->pz_Name);
334             pOD->pz_DisableName   = AO_gettext(pOD->pz_DisableName);
335             pOD->pz_DisablePfx    = AO_gettext(pOD->pz_DisablePfx);
336             if (--ix <= 0)
337                 break;
338             pOD++;
339         }
340     }
341     COERSION(pzCopyright);
342     COERSION(pzCopyNotice);
343     COERSION(pzFullVersion);
344     COERSION(pzUsageTitle);
345     COERSION(pzExplain);
346     COERSION(pzDetail);
347 }
348 
349 #endif /* ENABLE_NLS */
350 
351 #ifdef  __cplusplus
352 }
353 #endif
354 /* genshell.c ends here */
355