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