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