~ubuntu-branches/ubuntu/gutsy/ntp/gutsy

« back to all changes in this revision

Viewing changes to libopts/genshell.c

  • Committer: Bazaar Package Importer
  • Author(s): Steve Kowalik
  • Date: 2007-05-18 22:41:56 UTC
  • mfrom: (1.2.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20070518224156-563ruqxsxvqvoy8h
Tags: 1:4.2.4p0+dfsg-1ubuntu1
* Merge from Debian unstable.
* Remaining Ubuntu changes:
  - Update version in conflicts/replaces to that which was shipped in edgy,
    which was later than that in Debian (due to the ubuntuX).
  - Change default server to ntp.ubuntu.com.
  - Remove stop links from rc0 and rc6
  - Call dh_installinit with --error-handler
  - Set Ubuntu maintainer address.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*   -*- buffer-read-only: t -*- vi: set ro:
 
2
 *  
 
3
 *  DO NOT EDIT THIS FILE   (genshell.c)
 
4
 *  
 
5
 *  It has been AutoGen-ed  Thursday October 12, 2006 at 05:44:47 PM PDT
 
6
 *  From the definitions    genshell.def
 
7
 *  and the template file   options
 
8
 *
 
9
 * Generated from AutoOpts 27:5:3 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-2006 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-2006 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
  {  /* entry idx, value */ INDEX_OPT_VERSION, VALUE_OPT_VERSION,
 
149
     /* equiv idx value  */ NO_EQUIVALENT, 0,
 
150
     /* equivalenced to  */ NO_EQUIVALENT,
 
151
     /* min, max, act ct */ 0, 1, 0,
 
152
     /* opt state flags  */ OPTST_SET_ARGTYPE(OPARG_TYPE_STRING)
 
153
                          | OPTST_ARG_OPTIONAL, 0,
 
154
     /* last opt argumnt */ { NULL },
 
155
     /* arg list/cookie  */ NULL,
 
156
     /* must/cannot opts */ NULL, NULL,
 
157
     /* option proc      */ optionPrintVersion,
 
158
     /* desc, NAME, name */ zVersionText, NULL, zVersion_Name,
 
159
     /* disablement strs */ NULL, NULL },
 
160
 
 
161
  {  /* entry idx, value */ INDEX_OPT_HELP, VALUE_OPT_HELP,
 
162
     /* equiv idx value  */ NO_EQUIVALENT, 0,
 
163
     /* equivalenced to  */ NO_EQUIVALENT,
 
164
     /* min, max, act ct */ 0, 1, 0,
 
165
     /* opt state flags  */ OPTST_IMM, 0,
 
166
     /* last opt argumnt */ { NULL },
 
167
     /* arg list/cookie  */ NULL,
 
168
     /* must/cannot opts */ NULL, NULL,
 
169
     /* option proc      */ doUsageOpt,
 
170
     /* desc, NAME, name */ zHelpText, NULL, zHelp_Name,
 
171
     /* disablement strs */ NULL, NULL },
 
172
 
 
173
  {  /* entry idx, value */ INDEX_OPT_MORE_HELP, VALUE_OPT_MORE_HELP,
 
174
     /* equiv idx value  */ NO_EQUIVALENT, 0,
 
175
     /* equivalenced to  */ NO_EQUIVALENT,
 
176
     /* min, max, act ct */ 0, 1, 0,
 
177
     /* opt state flags  */ OPTST_IMM, 0,
 
178
     /* last opt argumnt */ { NULL },
 
179
     /* arg list/cookie  */ NULL,
 
180
     /* must/cannot opts */ NULL,  NULL,
 
181
     /* option proc      */ optionPagedUsage,
 
182
     /* desc, NAME, name */ zMore_HelpText, NULL, zMore_Help_Name,
 
183
     /* disablement strs */ NULL, NULL }
 
184
};
 
185
 
 
186
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 
187
 *
 
188
 *  Define the Genshellopt Option Environment
 
189
 */
 
190
tSCC   zPROGNAME[]   = "GENSHELLOPT";
 
191
tSCC   zUsageTitle[] =
 
192
"genshellopt - Generate Shell Option Processing Script - Ver. 1\n\
 
193
USAGE:  %s [ -<flag> [<val>] | --<name>[{=| }<val>] ]...\n";
 
194
#define zRcName     NULL
 
195
#define apzHomeList NULL
 
196
 
 
197
tSCC   zBugsAddr[]    = "autogen-users@lists.sourceforge.net";
 
198
tSCC   zExplain[]     = "\n\
 
199
Note that `shell' is only useful if the output file does not already\n\
 
200
exist.  If it does, then the shell name and optional first argument\n\
 
201
will be extracted from the script file.\n";
 
202
tSCC    zDetail[]     = "\n\
 
203
If the script file already exists and contains Automated Option Processing\n\
 
204
text, the second line of the file through the ending tag will be replaced\n\
 
205
by the newly generated text.  The first `#!' line will be regenerated.\n";
 
206
tSCC    zFullVersion[] = GENSHELLOPT_FULL_VERSION;
 
207
/* extracted from optcode near line 368 */
 
208
 
 
209
#if defined(ENABLE_NLS)
 
210
# define OPTPROC_BASE OPTPROC_TRANSLATE
 
211
  static tOptionXlateProc translate_option_strings;
 
212
#else
 
213
# define OPTPROC_BASE OPTPROC_NONE
 
214
# define translate_option_strings NULL
 
215
#endif /* ENABLE_NLS */
 
216
 
 
217
tOptions genshelloptOptions = {
 
218
    OPTIONS_STRUCT_VERSION,
 
219
    0, NULL,                    /* original argc + argv    */
 
220
    ( OPTPROC_BASE
 
221
    + OPTPROC_ERRSTOP
 
222
    + OPTPROC_SHORTOPT
 
223
    + OPTPROC_LONGOPT
 
224
    + OPTPROC_NO_REQ_OPT
 
225
    + OPTPROC_NEGATIONS
 
226
    + OPTPROC_NO_ARGS ),
 
227
    0, NULL,                    /* current option index, current option */
 
228
    NULL,         NULL,         zPROGNAME,
 
229
    zRcName,      zCopyright,   zCopyrightNotice,
 
230
    zFullVersion, apzHomeList,  zUsageTitle,
 
231
    zExplain,     zDetail,      optDesc,
 
232
    zBugsAddr,                  /* address to send bugs to */
 
233
    NULL, NULL,                 /* extensions/saved state  */
 
234
    genshelloptUsage,       /* usage procedure */
 
235
    translate_option_strings,   /* translation procedure */
 
236
    /*
 
237
     *  Indexes to special options
 
238
     */
 
239
    { INDEX_OPT_MORE_HELP,
 
240
       0 /* no option state saving */,
 
241
      NO_EQUIVALENT /* index of '-#' option */,
 
242
      NO_EQUIVALENT /* index of default opt */
 
243
    },
 
244
    OPTION_CT, 2 /* user option count */
 
245
};
 
246
 
 
247
/*
 
248
 *  Create the static procedure(s) declared above.
 
249
 */
 
250
static void
 
251
doUsageOpt(
 
252
    tOptions*   pOptions,
 
253
    tOptDesc*   pOptDesc )
 
254
{
 
255
    USAGE( EXIT_SUCCESS );
 
256
}
 
257
/* extracted from optcode near line 465 */
 
258
 
 
259
#if ENABLE_NLS
 
260
#include <stdio.h>
 
261
#include <stdlib.h>
 
262
#include <string.h>
 
263
#include <unistd.h>
 
264
#include <autoopts/usage-txt.h>
 
265
 
 
266
static char* AO_gettext( char const* pz );
 
267
static void  coerce_it(void** s);
 
268
 
 
269
static char*
 
270
AO_gettext( char const* pz )
 
271
{
 
272
    char* pzRes;
 
273
    if (pz == NULL)
 
274
        return NULL;
 
275
    pzRes = _(pz);
 
276
    if (pzRes == pz)
 
277
        return pzRes;
 
278
    pzRes = strdup( pzRes );
 
279
    if (pzRes == NULL) {
 
280
        fputs( _("No memory for duping translated strings\n"), stderr );
 
281
        exit( EXIT_FAILURE );
 
282
    }
 
283
    return pzRes;
 
284
}
 
285
 
 
286
static void coerce_it(void** s) { *s = AO_gettext(*s); }
 
287
#define COERSION(_f) \
 
288
  coerce_it((void*)&(genshelloptOptions._f))
 
289
 
 
290
/*
 
291
 *  This invokes the translation code (e.g. gettext(3)).
 
292
 */
 
293
static void
 
294
translate_option_strings( void )
 
295
{
 
296
    /*
 
297
     *  Guard against re-translation.  It won't work.  The strings will have
 
298
     *  been changed by the first pass through this code.  One shot only.
 
299
     */
 
300
    if (option_usage_text.field_ct == 0)
 
301
        return;
 
302
    /*
 
303
     *  Do the translations.  The first pointer follows the field count field.
 
304
     *  The field count field is the size of a pointer.
 
305
     */
 
306
    {
 
307
        char** ppz = (char**)(void*)&(option_usage_text);
 
308
        int    ix  = option_usage_text.field_ct;
 
309
 
 
310
        do {
 
311
            ppz++;
 
312
            *ppz = AO_gettext(*ppz);
 
313
        } while (--ix > 0);
 
314
    }
 
315
    option_usage_text.field_ct = 0;
 
316
 
 
317
    {
 
318
        tOptDesc* pOD = genshelloptOptions.pOptDesc;
 
319
        int       ix  = genshelloptOptions.optCt;
 
320
 
 
321
        for (;;) {
 
322
            pOD->pzText           = AO_gettext(pOD->pzText);
 
323
            pOD->pz_NAME          = AO_gettext(pOD->pz_NAME);
 
324
            pOD->pz_Name          = AO_gettext(pOD->pz_Name);
 
325
            pOD->pz_DisableName   = AO_gettext(pOD->pz_DisableName);
 
326
            pOD->pz_DisablePfx    = AO_gettext(pOD->pz_DisablePfx);
 
327
            if (--ix <= 0)
 
328
                break;
 
329
            pOD++;
 
330
        }
 
331
    }
 
332
    COERSION(pzCopyright);
 
333
    COERSION(pzCopyNotice);
 
334
    COERSION(pzFullVersion);
 
335
    COERSION(pzUsageTitle);
 
336
    COERSION(pzExplain);
 
337
    COERSION(pzDetail);
 
338
}
 
339
 
 
340
#endif /* ENABLE_NLS */
 
341
 
 
342
#ifdef  __cplusplus
 
343
}
 
344
#endif