corrected copyright notices
[gnutls.git] / src / psk-args.c
blob35630e93a48799c8b9f1443191741c39fa3d4601
1 /* -*- buffer-read-only: t -*- vi: set ro:
2 *
3 * DO NOT EDIT THIS FILE (psk-args.c)
4 *
5 * It has been AutoGen-ed November 8, 2012 at 11:35:48 PM by AutoGen 5.16
6 * From the definitions psk-args.def
7 * and the template file options
9 * Generated from AutoOpts 36:4:11 templates.
11 * AutoOpts is a copyrighted work. This source file is not encumbered
12 * by AutoOpts licensing, but is provided under the licensing terms chosen
13 * by the psktool author or copyright holder. AutoOpts is
14 * licensed under the terms of the LGPL. The redistributable library
15 * (``libopts'') is licensed under the terms of either the LGPL or, at the
16 * users discretion, the BSD license. See the AutoOpts and/or libopts sources
17 * for details.
19 * The psktool program is copyrighted and licensed
20 * under the following terms:
22 * Copyright (C) 2000-2012 Free Software Foundation, all rights reserved.
23 * This is free software. It is licensed for use, modification and
24 * redistribution under the terms of the
25 * GNU General Public License, version 3 or later
26 * <http://gnu.org/licenses/gpl.html>
28 * psktool is free software: you can redistribute it and/or modify it
29 * under the terms of the GNU General Public License as published by the
30 * Free Software Foundation, either version 3 of the License, or
31 * (at your option) any later version.
33 * psktool is distributed in the hope that it will be useful, but
34 * WITHOUT ANY WARRANTY; without even the implied warranty of
35 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
36 * See the GNU General Public License for more details.
38 * You should have received a copy of the GNU General Public License along
39 * with this program. If not, see <http://www.gnu.org/licenses/>.
42 #ifndef __doxygen__
43 #define OPTION_CODE_COMPILE 1
44 #include "psk-args.h"
45 #include <sys/types.h>
47 #include <limits.h>
48 #include <stdio.h>
49 #include <stdlib.h>
50 #include <errno.h>
52 #ifdef __cplusplus
53 extern "C" {
54 #endif
55 extern FILE * option_usage_fp;
57 /* TRANSLATORS: choose the translation for option names wisely because you
58 cannot ever change your mind. */
59 #define zCopyright (psktool_opt_strs+0)
60 #define zLicenseDescrip (psktool_opt_strs+278)
63 #ifndef NULL
64 # define NULL 0
65 #endif
68 * psktool option static const strings
70 static char const psktool_opt_strs[1505] =
71 /* 0 */ "psktool @VERSION@\n"
72 "Copyright (C) 2000-2012 Free Software Foundation, all rights reserved.\n"
73 "This is free software. It is licensed for use, modification and\n"
74 "redistribution under the terms of the\n"
75 "GNU General Public License, version 3 or later\n"
76 " <http://gnu.org/licenses/gpl.html>\n\0"
77 /* 278 */ "psktool is free software: you can redistribute it and/or modify it under\n"
78 "the terms of the GNU General Public License as published by the Free\n"
79 "Software Foundation, either version 3 of the License, or (at your option)\n"
80 "any later version.\n\n"
81 "psktool is distributed in the hope that it will be useful, but WITHOUT ANY\n"
82 "WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS\n"
83 "FOR A PARTICULAR PURPOSE. See the GNU General Public License for more\n"
84 "details.\n\n"
85 "You should have received a copy of the GNU General Public License along\n"
86 "with this program. If not, see <http://www.gnu.org/licenses/>.\n\0"
87 /* 881 */ "Enable debugging.\0"
88 /* 899 */ "DEBUG\0"
89 /* 905 */ "debug\0"
90 /* 911 */ "specify the key size in bytes\0"
91 /* 941 */ "KEYSIZE\0"
92 /* 949 */ "keysize\0"
93 /* 957 */ "specify a username\0"
94 /* 976 */ "USERNAME\0"
95 /* 985 */ "username\0"
96 /* 994 */ "specify a password file.\0"
97 /* 1019 */ "PASSWD\0"
98 /* 1026 */ "passwd\0"
99 /* 1033 */ "Display extended usage information and exit\0"
100 /* 1077 */ "help\0"
101 /* 1082 */ "Extended usage information passed thru pager\0"
102 /* 1127 */ "more-help\0"
103 /* 1137 */ "Output version information and exit\0"
104 /* 1173 */ "version\0"
105 /* 1181 */ "PSKTOOL\0"
106 /* 1189 */ "psktool - GnuTLS PSK tool - Ver. @VERSION@\n"
107 "USAGE: %s [ -<flag> [<val>] | --<name>[{=| }<val>] ]...\n\0"
108 /* 1290 */ "bug-gnutls@gnu.org\0"
109 /* 1309 */ "\n\n\0"
110 /* 1312 */ "\n"
111 "Program that generates random keys for use with TLS-PSK. The keys are\n"
112 "stored in hexadecimal format in a key file.\n\0"
113 /* 1429 */ "psktool @VERSION@\0"
114 /* 1447 */ "psktool [options]\n"
115 "psktool --help for usage instructions.\n";
118 * debug option description:
120 #define DEBUG_DESC (psktool_opt_strs+881)
121 #define DEBUG_NAME (psktool_opt_strs+899)
122 #define DEBUG_name (psktool_opt_strs+905)
123 #define DEBUG_FLAGS (OPTST_DISABLED \
124 | OPTST_SET_ARGTYPE(OPARG_TYPE_NUMERIC))
127 * keysize option description:
129 #define KEYSIZE_DESC (psktool_opt_strs+911)
130 #define KEYSIZE_NAME (psktool_opt_strs+941)
131 #define KEYSIZE_name (psktool_opt_strs+949)
132 #define KEYSIZE_FLAGS (OPTST_DISABLED \
133 | OPTST_SET_ARGTYPE(OPARG_TYPE_NUMERIC))
136 * username option description:
138 #define USERNAME_DESC (psktool_opt_strs+957)
139 #define USERNAME_NAME (psktool_opt_strs+976)
140 #define USERNAME_name (psktool_opt_strs+985)
141 #define USERNAME_FLAGS (OPTST_DISABLED \
142 | OPTST_SET_ARGTYPE(OPARG_TYPE_STRING))
145 * passwd option description:
147 #define PASSWD_DESC (psktool_opt_strs+994)
148 #define PASSWD_NAME (psktool_opt_strs+1019)
149 #define PASSWD_name (psktool_opt_strs+1026)
150 #define PASSWD_FLAGS (OPTST_DISABLED \
151 | OPTST_SET_ARGTYPE(OPARG_TYPE_STRING))
154 * Help/More_Help/Version option descriptions:
156 #define HELP_DESC (psktool_opt_strs+1033)
157 #define HELP_name (psktool_opt_strs+1077)
158 #ifdef HAVE_WORKING_FORK
159 #define MORE_HELP_DESC (psktool_opt_strs+1082)
160 #define MORE_HELP_name (psktool_opt_strs+1127)
161 #define MORE_HELP_FLAGS (OPTST_IMM | OPTST_NO_INIT)
162 #else
163 #define MORE_HELP_DESC NULL
164 #define MORE_HELP_name NULL
165 #define MORE_HELP_FLAGS (OPTST_OMITTED | OPTST_NO_INIT)
166 #endif
167 #ifdef NO_OPTIONAL_OPT_ARGS
168 # define VER_FLAGS (OPTST_IMM | OPTST_NO_INIT)
169 #else
170 # define VER_FLAGS (OPTST_SET_ARGTYPE(OPARG_TYPE_STRING) | \
171 OPTST_ARG_OPTIONAL | OPTST_IMM | OPTST_NO_INIT)
172 #endif
173 #define VER_DESC (psktool_opt_strs+1137)
174 #define VER_name (psktool_opt_strs+1173)
176 * Declare option callback procedures
178 extern tOptProc
179 optionBooleanVal, optionNestedVal, optionNumericVal,
180 optionPagedUsage, optionPrintVersion, optionResetOpt,
181 optionStackArg, optionTimeDate, optionTimeVal,
182 optionUnstackArg, optionVendorOption;
183 static tOptProc
184 doOptDebug, doOptKeysize, doUsageOpt;
185 #define VER_PROC optionPrintVersion
187 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
189 * Define the psktool Option Descriptions.
190 * This is an array of OPTION_CT entries, one for each
191 * option that the psktool program responds to.
193 static tOptDesc optDesc[OPTION_CT] = {
194 { /* entry idx, value */ 0, VALUE_OPT_DEBUG,
195 /* equiv idx, value */ 0, VALUE_OPT_DEBUG,
196 /* equivalenced to */ NO_EQUIVALENT,
197 /* min, max, act ct */ 0, 1, 0,
198 /* opt state flags */ DEBUG_FLAGS, 0,
199 /* last opt argumnt */ { NULL }, /* --debug */
200 /* arg list/cookie */ NULL,
201 /* must/cannot opts */ NULL, NULL,
202 /* option proc */ doOptDebug,
203 /* desc, NAME, name */ DEBUG_DESC, DEBUG_NAME, DEBUG_name,
204 /* disablement strs */ NULL, NULL },
206 { /* entry idx, value */ 1, VALUE_OPT_KEYSIZE,
207 /* equiv idx, value */ 1, VALUE_OPT_KEYSIZE,
208 /* equivalenced to */ NO_EQUIVALENT,
209 /* min, max, act ct */ 0, 1, 0,
210 /* opt state flags */ KEYSIZE_FLAGS, 0,
211 /* last opt argumnt */ { NULL }, /* --keysize */
212 /* arg list/cookie */ NULL,
213 /* must/cannot opts */ NULL, NULL,
214 /* option proc */ doOptKeysize,
215 /* desc, NAME, name */ KEYSIZE_DESC, KEYSIZE_NAME, KEYSIZE_name,
216 /* disablement strs */ NULL, NULL },
218 { /* entry idx, value */ 2, VALUE_OPT_USERNAME,
219 /* equiv idx, value */ 2, VALUE_OPT_USERNAME,
220 /* equivalenced to */ NO_EQUIVALENT,
221 /* min, max, act ct */ 0, 1, 0,
222 /* opt state flags */ USERNAME_FLAGS, 0,
223 /* last opt argumnt */ { NULL }, /* --username */
224 /* arg list/cookie */ NULL,
225 /* must/cannot opts */ NULL, NULL,
226 /* option proc */ NULL,
227 /* desc, NAME, name */ USERNAME_DESC, USERNAME_NAME, USERNAME_name,
228 /* disablement strs */ NULL, NULL },
230 { /* entry idx, value */ 3, VALUE_OPT_PASSWD,
231 /* equiv idx, value */ 3, VALUE_OPT_PASSWD,
232 /* equivalenced to */ NO_EQUIVALENT,
233 /* min, max, act ct */ 0, 1, 0,
234 /* opt state flags */ PASSWD_FLAGS, 0,
235 /* last opt argumnt */ { NULL }, /* --passwd */
236 /* arg list/cookie */ NULL,
237 /* must/cannot opts */ NULL, NULL,
238 /* option proc */ NULL,
239 /* desc, NAME, name */ PASSWD_DESC, PASSWD_NAME, PASSWD_name,
240 /* disablement strs */ NULL, NULL },
242 { /* entry idx, value */ INDEX_OPT_VERSION, VALUE_OPT_VERSION,
243 /* equiv idx value */ NO_EQUIVALENT, VALUE_OPT_VERSION,
244 /* equivalenced to */ NO_EQUIVALENT,
245 /* min, max, act ct */ 0, 1, 0,
246 /* opt state flags */ VER_FLAGS, 0,
247 /* last opt argumnt */ { NULL },
248 /* arg list/cookie */ NULL,
249 /* must/cannot opts */ NULL, NULL,
250 /* option proc */ VER_PROC,
251 /* desc, NAME, name */ VER_DESC, NULL, VER_name,
252 /* disablement strs */ NULL, NULL },
256 { /* entry idx, value */ INDEX_OPT_HELP, VALUE_OPT_HELP,
257 /* equiv idx value */ NO_EQUIVALENT, VALUE_OPT_HELP,
258 /* equivalenced to */ NO_EQUIVALENT,
259 /* min, max, act ct */ 0, 1, 0,
260 /* opt state flags */ OPTST_IMM | OPTST_NO_INIT, 0,
261 /* last opt argumnt */ { NULL },
262 /* arg list/cookie */ NULL,
263 /* must/cannot opts */ NULL, NULL,
264 /* option proc */ doUsageOpt,
265 /* desc, NAME, name */ HELP_DESC, NULL, HELP_name,
266 /* disablement strs */ NULL, NULL },
268 { /* entry idx, value */ INDEX_OPT_MORE_HELP, VALUE_OPT_MORE_HELP,
269 /* equiv idx value */ NO_EQUIVALENT, VALUE_OPT_MORE_HELP,
270 /* equivalenced to */ NO_EQUIVALENT,
271 /* min, max, act ct */ 0, 1, 0,
272 /* opt state flags */ MORE_HELP_FLAGS, 0,
273 /* last opt argumnt */ { NULL },
274 /* arg list/cookie */ NULL,
275 /* must/cannot opts */ NULL, NULL,
276 /* option proc */ optionPagedUsage,
277 /* desc, NAME, name */ MORE_HELP_DESC, NULL, MORE_HELP_name,
278 /* disablement strs */ NULL, NULL }
282 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
284 * Define the psktool Option Environment
286 #define zPROGNAME (psktool_opt_strs+1181)
287 #define zUsageTitle (psktool_opt_strs+1189)
288 #define zRcName NULL
289 #define apzHomeList NULL
290 #define zBugsAddr (psktool_opt_strs+1290)
291 #define zExplain (psktool_opt_strs+1309)
292 #define zDetail (psktool_opt_strs+1312)
293 #define zFullVersion (psktool_opt_strs+1429)
294 /* extracted from optcode.tlib near line 350 */
296 #if defined(ENABLE_NLS)
297 # define OPTPROC_BASE OPTPROC_TRANSLATE | OPTPROC_NXLAT_OPT
298 static tOptionXlateProc translate_option_strings;
299 #else
300 # define OPTPROC_BASE OPTPROC_NONE
301 # define translate_option_strings NULL
302 #endif /* ENABLE_NLS */
305 #define psktool_full_usage (NULL)
307 #define psktool_short_usage (psktool_opt_strs+1447)
309 #endif /* not defined __doxygen__ */
312 * Create the static procedure(s) declared above.
315 * The callout function that invokes the optionUsage function.
317 * @param pOptions the AutoOpts option description structure
318 * @param pOptDesc the descriptor for the "help" (usage) option.
319 * @noreturn
321 static void
322 doUsageOpt(tOptions * pOptions, tOptDesc * pOptDesc)
324 optionUsage(&psktoolOptions, PSKTOOL_EXIT_SUCCESS);
325 /* NOTREACHED */
326 (void)pOptDesc;
327 (void)pOptions;
330 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
332 * Code to handle the debug option.
334 * @param pOptions the psktool options data structure
335 * @param pOptDesc the option descriptor for this option.
337 static void
338 doOptDebug(tOptions* pOptions, tOptDesc* pOptDesc)
340 static struct {long rmin, rmax;} const rng[1] = {
341 { 0 , 9999 } };
342 int ix;
344 if (pOptions <= OPTPROC_EMIT_LIMIT)
345 goto emit_ranges;
346 optionNumericVal(pOptions, pOptDesc);
348 for (ix = 0; ix < 1; ix++) {
349 if (pOptDesc->optArg.argInt < rng[ix].rmin)
350 continue; /* ranges need not be ordered. */
351 if (pOptDesc->optArg.argInt == rng[ix].rmin)
352 return;
353 if (rng[ix].rmax == LONG_MIN)
354 continue;
355 if (pOptDesc->optArg.argInt <= rng[ix].rmax)
356 return;
359 option_usage_fp = stderr;
361 emit_ranges:
363 optionShowRange(pOptions, pOptDesc, (void *)rng, 1);
366 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
368 * Code to handle the keysize option.
370 * @param pOptions the psktool options data structure
371 * @param pOptDesc the option descriptor for this option.
373 static void
374 doOptKeysize(tOptions* pOptions, tOptDesc* pOptDesc)
376 static struct {long rmin, rmax;} const rng[1] = {
377 { 0 , 512 } };
378 int ix;
380 if (pOptions <= OPTPROC_EMIT_LIMIT)
381 goto emit_ranges;
382 optionNumericVal(pOptions, pOptDesc);
384 for (ix = 0; ix < 1; ix++) {
385 if (pOptDesc->optArg.argInt < rng[ix].rmin)
386 continue; /* ranges need not be ordered. */
387 if (pOptDesc->optArg.argInt == rng[ix].rmin)
388 return;
389 if (rng[ix].rmax == LONG_MIN)
390 continue;
391 if (pOptDesc->optArg.argInt <= rng[ix].rmax)
392 return;
395 option_usage_fp = stderr;
397 emit_ranges:
399 optionShowRange(pOptions, pOptDesc, (void *)rng, 1);
401 /* extracted from optmain.tlib near line 1113 */
404 * The directory containing the data associated with psktool.
406 #ifndef PKGDATADIR
407 # define PKGDATADIR ""
408 #endif
411 * Information about the person or institution that packaged psktool
412 * for the current distribution.
414 #ifndef WITH_PACKAGER
415 # define psktool_packager_info NULL
416 #else
417 static char const psktool_packager_info[] =
418 "Packaged by " WITH_PACKAGER
420 # ifdef WITH_PACKAGER_VERSION
421 " ("WITH_PACKAGER_VERSION")"
422 # endif
424 # ifdef WITH_PACKAGER_BUG_REPORTS
425 "\nReport psktool bugs to " WITH_PACKAGER_BUG_REPORTS
426 # endif
427 "\n";
428 #endif
429 #ifndef __doxygen__
431 #endif /* __doxygen__ */
433 * The option definitions for psktool. The one structure that
434 * binds them all.
436 tOptions psktoolOptions = {
437 OPTIONS_STRUCT_VERSION,
438 0, NULL, /* original argc + argv */
439 ( OPTPROC_BASE
440 + OPTPROC_ERRSTOP
441 + OPTPROC_SHORTOPT
442 + OPTPROC_LONGOPT
443 + OPTPROC_NO_REQ_OPT
444 + OPTPROC_NO_ARGS
445 + OPTPROC_GNUUSAGE
446 + OPTPROC_MISUSE ),
447 0, NULL, /* current option index, current option */
448 NULL, NULL, zPROGNAME,
449 zRcName, zCopyright, zLicenseDescrip,
450 zFullVersion, apzHomeList, zUsageTitle,
451 zExplain, zDetail, optDesc,
452 zBugsAddr, /* address to send bugs to */
453 NULL, NULL, /* extensions/saved state */
454 optionUsage, /* usage procedure */
455 translate_option_strings, /* translation procedure */
457 * Indexes to special options
459 { INDEX_OPT_MORE_HELP, /* more-help option index */
460 NO_EQUIVALENT, /* save option index */
461 NO_EQUIVALENT, /* '-#' option index */
462 NO_EQUIVALENT /* index of default opt */
464 7 /* full option count */, 4 /* user option count */,
465 psktool_full_usage, psktool_short_usage,
466 NULL, NULL,
467 PKGDATADIR, psktool_packager_info
470 #if ENABLE_NLS
471 #include <stdio.h>
472 #include <stdlib.h>
473 #include <string.h>
474 #include <unistd.h>
475 #include <autoopts/usage-txt.h>
477 static char* AO_gettext(char const* pz);
478 static void coerce_it(void** s);
481 * AutoGen specific wrapper function for gettext.
482 * It relies on the macro _() to convert from English to the target
483 * language, then strdup-duplicates the result string.
485 * @param[in] pz the input text used as a lookup key.
486 * @returns the translated text (if there is one),
487 * or the original text (if not).
489 static char *
490 AO_gettext(char const* pz)
492 char* pzRes;
493 if (pz == NULL)
494 return NULL;
495 pzRes = _(pz);
496 if (pzRes == pz)
497 return pzRes;
498 pzRes = strdup(pzRes);
499 if (pzRes == NULL) {
500 fputs(_("No memory for duping translated strings\n"), stderr);
501 exit(PSKTOOL_EXIT_FAILURE);
503 return pzRes;
506 static void coerce_it(void** s) { *s = AO_gettext(*s);
510 * Translate all the translatable strings in the psktoolOptions
511 * structure defined above. This is done only once.
513 static void
514 translate_option_strings(void)
516 tOptions * const pOpt = &psktoolOptions;
519 * Guard against re-translation. It won't work. The strings will have
520 * been changed by the first pass through this code. One shot only.
522 if (option_usage_text.field_ct != 0) {
524 * Do the translations. The first pointer follows the field count
525 * field. The field count field is the size of a pointer.
527 tOptDesc * pOD = pOpt->pOptDesc;
528 char ** ppz = (char**)(void*)&(option_usage_text);
529 int ix = option_usage_text.field_ct;
531 do {
532 ppz++;
533 *ppz = AO_gettext(*ppz);
534 } while (--ix > 0);
536 coerce_it((void*)&(pOpt->pzCopyright));
537 coerce_it((void*)&(pOpt->pzCopyNotice));
538 coerce_it((void*)&(pOpt->pzFullVersion));
539 coerce_it((void*)&(pOpt->pzUsageTitle));
540 coerce_it((void*)&(pOpt->pzExplain));
541 coerce_it((void*)&(pOpt->pzDetail));
542 coerce_it((void*)&(pOpt->pzPackager));
543 coerce_it((void*)&(pOpt->pzShortUsage));
544 option_usage_text.field_ct = 0;
546 for (ix = pOpt->optCt; ix > 0; ix--, pOD++)
547 coerce_it((void*)&(pOD->pzText));
550 if ((pOpt->fOptSet & OPTPROC_NXLAT_OPT_CFG) == 0) {
551 tOptDesc * pOD = pOpt->pOptDesc;
552 int ix;
554 for (ix = pOpt->optCt; ix > 0; ix--, pOD++) {
555 coerce_it((void*)&(pOD->pz_Name));
556 coerce_it((void*)&(pOD->pz_DisableName));
557 coerce_it((void*)&(pOD->pz_DisablePfx));
559 /* prevent re-translation */
560 psktoolOptions.fOptSet |= OPTPROC_NXLAT_OPT_CFG | OPTPROC_NXLAT_OPT;
564 #endif /* ENABLE_NLS */
566 #ifdef __cplusplus
568 #endif
569 /* psk-args.c ends here */