_gnutls_strdatum_to_buf() will account for NULL input.
[gnutls.git] / src / tpmtool-args.c
blob749633e30fad02f5e087bed131e04484ad2619d2
1 /* -*- buffer-read-only: t -*- vi: set ro:
2 *
3 * DO NOT EDIT THIS FILE (tpmtool-args.c)
4 *
5 * It has been AutoGen-ed November 8, 2012 at 11:35:56 PM by AutoGen 5.16
6 * From the definitions tpmtool-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 tpmtool 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 tpmtool 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 * tpmtool 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 * tpmtool 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 "tpmtool-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 (tpmtool_opt_strs+0)
60 #define zLicenseDescrip (tpmtool_opt_strs+278)
63 #ifndef NULL
64 # define NULL 0
65 #endif
68 * tpmtool option static const strings
70 static char const tpmtool_opt_strs[2126] =
71 /* 0 */ "tpmtool @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 */ "tpmtool 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 "tpmtool 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 */ "Input file\0"
91 /* 922 */ "INFILE\0"
92 /* 929 */ "infile\0"
93 /* 936 */ "Output file\0"
94 /* 948 */ "OUTFILE\0"
95 /* 956 */ "outfile\0"
96 /* 964 */ "Generate an RSA private-public key pair\0"
97 /* 1004 */ "GENERATE_RSA\0"
98 /* 1017 */ "generate-rsa\0"
99 /* 1030 */ "Any generated key will be registered in the TPM\0"
100 /* 1078 */ "REGISTER\0"
101 /* 1087 */ "register\0"
102 /* 1096 */ "Any generated key will be a signing key\0"
103 /* 1136 */ "SIGNING\0"
104 /* 1144 */ "signing\0"
105 /* 1152 */ "Any generated key will be a legacy key\0"
106 /* 1191 */ "LEGACY\0"
107 /* 1198 */ "legacy\0"
108 /* 1205 */ "Any registered key will be a user key\0"
109 /* 1243 */ "USER\0"
110 /* 1248 */ "user\0"
111 /* 1253 */ "Any registred key will be a system key\0"
112 /* 1292 */ "SYSTEM\0"
113 /* 1299 */ "system\0"
114 /* 1306 */ "Prints the public key of the provided key\0"
115 /* 1348 */ "PUBKEY\0"
116 /* 1355 */ "pubkey\0"
117 /* 1362 */ "Lists all stored keys in the TPM\0"
118 /* 1395 */ "LIST\0"
119 /* 1400 */ "list\0"
120 /* 1405 */ "Delete the key identified by the given URL (UUID).\0"
121 /* 1456 */ "DELETE\0"
122 /* 1463 */ "delete\0"
123 /* 1470 */ "Specify the security level [low, legacy, normal, high, ultra].\0"
124 /* 1533 */ "SEC_PARAM\0"
125 /* 1543 */ "sec-param\0"
126 /* 1553 */ "Specify the number of bits for key generate\0"
127 /* 1597 */ "BITS\0"
128 /* 1602 */ "bits\0"
129 /* 1607 */ "Use the DER format for keys.\0"
130 /* 1636 */ "INDER\0"
131 /* 1642 */ "no-inder\0"
132 /* 1651 */ "no\0"
133 /* 1654 */ "Use DER format for output keys\0"
134 /* 1685 */ "OUTDER\0"
135 /* 1692 */ "no-outder\0"
136 /* 1702 */ "Display extended usage information and exit\0"
137 /* 1746 */ "help\0"
138 /* 1751 */ "Extended usage information passed thru pager\0"
139 /* 1796 */ "more-help\0"
140 /* 1806 */ "Output version information and exit\0"
141 /* 1842 */ "version\0"
142 /* 1850 */ "TPMTOOL\0"
143 /* 1858 */ "tpmtool - GnuTLS TPM tool - Ver. @VERSION@\n"
144 "USAGE: %s [ -<flag> [<val>] | --<name>[{=| }<val>] ]...\n\0"
145 /* 1959 */ "bug-gnutls@gnu.org\0"
146 /* 1978 */ "\n\n\0"
147 /* 1981 */ "\n"
148 "Program that allows handling cryptographic data from the TPM chip.\n\0"
149 /* 2050 */ "tpmtool @VERSION@\0"
150 /* 2068 */ "tpmtool [options]\n"
151 "tpmtool --help for usage instructions.\n";
154 * debug option description:
156 #define DEBUG_DESC (tpmtool_opt_strs+881)
157 #define DEBUG_NAME (tpmtool_opt_strs+899)
158 #define DEBUG_name (tpmtool_opt_strs+905)
159 #define DEBUG_FLAGS (OPTST_DISABLED \
160 | OPTST_SET_ARGTYPE(OPARG_TYPE_NUMERIC))
163 * infile option description:
165 #define INFILE_DESC (tpmtool_opt_strs+911)
166 #define INFILE_NAME (tpmtool_opt_strs+922)
167 #define INFILE_name (tpmtool_opt_strs+929)
168 #define INFILE_FLAGS (OPTST_DISABLED \
169 | OPTST_SET_ARGTYPE(OPARG_TYPE_FILE))
172 * outfile option description:
174 #define OUTFILE_DESC (tpmtool_opt_strs+936)
175 #define OUTFILE_NAME (tpmtool_opt_strs+948)
176 #define OUTFILE_name (tpmtool_opt_strs+956)
177 #define OUTFILE_FLAGS (OPTST_DISABLED \
178 | OPTST_SET_ARGTYPE(OPARG_TYPE_STRING))
181 * generate-rsa option description:
183 #define GENERATE_RSA_DESC (tpmtool_opt_strs+964)
184 #define GENERATE_RSA_NAME (tpmtool_opt_strs+1004)
185 #define GENERATE_RSA_name (tpmtool_opt_strs+1017)
186 #define GENERATE_RSA_FLAGS (OPTST_DISABLED)
189 * register option description with
190 * "Must also have options" and "Incompatible options":
192 #define REGISTER_DESC (tpmtool_opt_strs+1030)
193 #define REGISTER_NAME (tpmtool_opt_strs+1078)
194 #define REGISTER_name (tpmtool_opt_strs+1087)
195 static int const aRegisterMustList[] = {
196 INDEX_OPT_GENERATE_RSA, NO_EQUIVALENT };
197 #define REGISTER_FLAGS (OPTST_DISABLED)
200 * signing option description with
201 * "Must also have options" and "Incompatible options":
203 #define SIGNING_DESC (tpmtool_opt_strs+1096)
204 #define SIGNING_NAME (tpmtool_opt_strs+1136)
205 #define SIGNING_name (tpmtool_opt_strs+1144)
206 static int const aSigningMustList[] = {
207 INDEX_OPT_GENERATE_RSA, NO_EQUIVALENT };
208 static int const aSigningCantList[] = {
209 INDEX_OPT_LEGACY, NO_EQUIVALENT };
210 #define SIGNING_FLAGS (OPTST_DISABLED)
213 * legacy option description with
214 * "Must also have options" and "Incompatible options":
216 #define LEGACY_DESC (tpmtool_opt_strs+1152)
217 #define LEGACY_NAME (tpmtool_opt_strs+1191)
218 #define LEGACY_name (tpmtool_opt_strs+1198)
219 static int const aLegacyMustList[] = {
220 INDEX_OPT_GENERATE_RSA, NO_EQUIVALENT };
221 static int const aLegacyCantList[] = {
222 INDEX_OPT_SIGNING, NO_EQUIVALENT };
223 #define LEGACY_FLAGS (OPTST_DISABLED)
226 * user option description with
227 * "Must also have options" and "Incompatible options":
229 #define USER_DESC (tpmtool_opt_strs+1205)
230 #define USER_NAME (tpmtool_opt_strs+1243)
231 #define USER_name (tpmtool_opt_strs+1248)
232 static int const aUserMustList[] = {
233 INDEX_OPT_REGISTER, NO_EQUIVALENT };
234 static int const aUserCantList[] = {
235 INDEX_OPT_SYSTEM, NO_EQUIVALENT };
236 #define USER_FLAGS (OPTST_DISABLED)
239 * system option description with
240 * "Must also have options" and "Incompatible options":
242 #define SYSTEM_DESC (tpmtool_opt_strs+1253)
243 #define SYSTEM_NAME (tpmtool_opt_strs+1292)
244 #define SYSTEM_name (tpmtool_opt_strs+1299)
245 static int const aSystemMustList[] = {
246 INDEX_OPT_REGISTER, NO_EQUIVALENT };
247 static int const aSystemCantList[] = {
248 INDEX_OPT_USER, NO_EQUIVALENT };
249 #define SYSTEM_FLAGS (OPTST_DISABLED)
252 * pubkey option description:
254 #define PUBKEY_DESC (tpmtool_opt_strs+1306)
255 #define PUBKEY_NAME (tpmtool_opt_strs+1348)
256 #define PUBKEY_name (tpmtool_opt_strs+1355)
257 #define PUBKEY_FLAGS (OPTST_DISABLED \
258 | OPTST_SET_ARGTYPE(OPARG_TYPE_STRING))
261 * list option description:
263 #define LIST_DESC (tpmtool_opt_strs+1362)
264 #define LIST_NAME (tpmtool_opt_strs+1395)
265 #define LIST_name (tpmtool_opt_strs+1400)
266 #define LIST_FLAGS (OPTST_DISABLED)
269 * delete option description:
271 #define DELETE_DESC (tpmtool_opt_strs+1405)
272 #define DELETE_NAME (tpmtool_opt_strs+1456)
273 #define DELETE_name (tpmtool_opt_strs+1463)
274 #define DELETE_FLAGS (OPTST_DISABLED \
275 | OPTST_SET_ARGTYPE(OPARG_TYPE_STRING))
278 * sec-param option description:
280 #define SEC_PARAM_DESC (tpmtool_opt_strs+1470)
281 #define SEC_PARAM_NAME (tpmtool_opt_strs+1533)
282 #define SEC_PARAM_name (tpmtool_opt_strs+1543)
283 #define SEC_PARAM_FLAGS (OPTST_DISABLED \
284 | OPTST_SET_ARGTYPE(OPARG_TYPE_STRING))
287 * bits option description:
289 #define BITS_DESC (tpmtool_opt_strs+1553)
290 #define BITS_NAME (tpmtool_opt_strs+1597)
291 #define BITS_name (tpmtool_opt_strs+1602)
292 #define BITS_FLAGS (OPTST_DISABLED \
293 | OPTST_SET_ARGTYPE(OPARG_TYPE_NUMERIC))
296 * inder option description:
298 #define INDER_DESC (tpmtool_opt_strs+1607)
299 #define INDER_NAME (tpmtool_opt_strs+1636)
300 #define NOT_INDER_name (tpmtool_opt_strs+1642)
301 #define NOT_INDER_PFX (tpmtool_opt_strs+1651)
302 #define INDER_name (NOT_INDER_name + 3)
303 #define INDER_FLAGS (OPTST_DISABLED)
306 * outder option description:
308 #define OUTDER_DESC (tpmtool_opt_strs+1654)
309 #define OUTDER_NAME (tpmtool_opt_strs+1685)
310 #define NOT_OUTDER_name (tpmtool_opt_strs+1692)
311 #define NOT_OUTDER_PFX (tpmtool_opt_strs+1651)
312 #define OUTDER_name (NOT_OUTDER_name + 3)
313 #define OUTDER_FLAGS (OPTST_DISABLED)
316 * Help/More_Help/Version option descriptions:
318 #define HELP_DESC (tpmtool_opt_strs+1702)
319 #define HELP_name (tpmtool_opt_strs+1746)
320 #ifdef HAVE_WORKING_FORK
321 #define MORE_HELP_DESC (tpmtool_opt_strs+1751)
322 #define MORE_HELP_name (tpmtool_opt_strs+1796)
323 #define MORE_HELP_FLAGS (OPTST_IMM | OPTST_NO_INIT)
324 #else
325 #define MORE_HELP_DESC NULL
326 #define MORE_HELP_name NULL
327 #define MORE_HELP_FLAGS (OPTST_OMITTED | OPTST_NO_INIT)
328 #endif
329 #ifdef NO_OPTIONAL_OPT_ARGS
330 # define VER_FLAGS (OPTST_IMM | OPTST_NO_INIT)
331 #else
332 # define VER_FLAGS (OPTST_SET_ARGTYPE(OPARG_TYPE_STRING) | \
333 OPTST_ARG_OPTIONAL | OPTST_IMM | OPTST_NO_INIT)
334 #endif
335 #define VER_DESC (tpmtool_opt_strs+1806)
336 #define VER_name (tpmtool_opt_strs+1842)
338 * Declare option callback procedures
340 extern tOptProc
341 optionBooleanVal, optionNestedVal, optionNumericVal,
342 optionPagedUsage, optionPrintVersion, optionResetOpt,
343 optionStackArg, optionTimeDate, optionTimeVal,
344 optionUnstackArg, optionVendorOption;
345 static tOptProc
346 doOptDebug, doOptInfile, doUsageOpt;
347 #define VER_PROC optionPrintVersion
349 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
351 * Define the tpmtool Option Descriptions.
352 * This is an array of OPTION_CT entries, one for each
353 * option that the tpmtool program responds to.
355 static tOptDesc optDesc[OPTION_CT] = {
356 { /* entry idx, value */ 0, VALUE_OPT_DEBUG,
357 /* equiv idx, value */ 0, VALUE_OPT_DEBUG,
358 /* equivalenced to */ NO_EQUIVALENT,
359 /* min, max, act ct */ 0, 1, 0,
360 /* opt state flags */ DEBUG_FLAGS, 0,
361 /* last opt argumnt */ { NULL }, /* --debug */
362 /* arg list/cookie */ NULL,
363 /* must/cannot opts */ NULL, NULL,
364 /* option proc */ doOptDebug,
365 /* desc, NAME, name */ DEBUG_DESC, DEBUG_NAME, DEBUG_name,
366 /* disablement strs */ NULL, NULL },
368 { /* entry idx, value */ 1, VALUE_OPT_INFILE,
369 /* equiv idx, value */ 1, VALUE_OPT_INFILE,
370 /* equivalenced to */ NO_EQUIVALENT,
371 /* min, max, act ct */ 0, 1, 0,
372 /* opt state flags */ INFILE_FLAGS, 0,
373 /* last opt argumnt */ { NULL }, /* --infile */
374 /* arg list/cookie */ NULL,
375 /* must/cannot opts */ NULL, NULL,
376 /* option proc */ doOptInfile,
377 /* desc, NAME, name */ INFILE_DESC, INFILE_NAME, INFILE_name,
378 /* disablement strs */ NULL, NULL },
380 { /* entry idx, value */ 2, VALUE_OPT_OUTFILE,
381 /* equiv idx, value */ 2, VALUE_OPT_OUTFILE,
382 /* equivalenced to */ NO_EQUIVALENT,
383 /* min, max, act ct */ 0, 1, 0,
384 /* opt state flags */ OUTFILE_FLAGS, 0,
385 /* last opt argumnt */ { NULL }, /* --outfile */
386 /* arg list/cookie */ NULL,
387 /* must/cannot opts */ NULL, NULL,
388 /* option proc */ NULL,
389 /* desc, NAME, name */ OUTFILE_DESC, OUTFILE_NAME, OUTFILE_name,
390 /* disablement strs */ NULL, NULL },
392 { /* entry idx, value */ 3, VALUE_OPT_GENERATE_RSA,
393 /* equiv idx, value */ 3, VALUE_OPT_GENERATE_RSA,
394 /* equivalenced to */ NO_EQUIVALENT,
395 /* min, max, act ct */ 0, 1, 0,
396 /* opt state flags */ GENERATE_RSA_FLAGS, 0,
397 /* last opt argumnt */ { NULL }, /* --generate-rsa */
398 /* arg list/cookie */ NULL,
399 /* must/cannot opts */ NULL, NULL,
400 /* option proc */ NULL,
401 /* desc, NAME, name */ GENERATE_RSA_DESC, GENERATE_RSA_NAME, GENERATE_RSA_name,
402 /* disablement strs */ NULL, NULL },
404 { /* entry idx, value */ 4, VALUE_OPT_REGISTER,
405 /* equiv idx, value */ 4, VALUE_OPT_REGISTER,
406 /* equivalenced to */ NO_EQUIVALENT,
407 /* min, max, act ct */ 0, 1, 0,
408 /* opt state flags */ REGISTER_FLAGS, 0,
409 /* last opt argumnt */ { NULL }, /* --register */
410 /* arg list/cookie */ NULL,
411 /* must/cannot opts */ aRegisterMustList, NULL,
412 /* option proc */ NULL,
413 /* desc, NAME, name */ REGISTER_DESC, REGISTER_NAME, REGISTER_name,
414 /* disablement strs */ NULL, NULL },
416 { /* entry idx, value */ 5, VALUE_OPT_SIGNING,
417 /* equiv idx, value */ 5, VALUE_OPT_SIGNING,
418 /* equivalenced to */ NO_EQUIVALENT,
419 /* min, max, act ct */ 0, 1, 0,
420 /* opt state flags */ SIGNING_FLAGS, 0,
421 /* last opt argumnt */ { NULL }, /* --signing */
422 /* arg list/cookie */ NULL,
423 /* must/cannot opts */ aSigningMustList, aSigningCantList,
424 /* option proc */ NULL,
425 /* desc, NAME, name */ SIGNING_DESC, SIGNING_NAME, SIGNING_name,
426 /* disablement strs */ NULL, NULL },
428 { /* entry idx, value */ 6, VALUE_OPT_LEGACY,
429 /* equiv idx, value */ 6, VALUE_OPT_LEGACY,
430 /* equivalenced to */ NO_EQUIVALENT,
431 /* min, max, act ct */ 0, 1, 0,
432 /* opt state flags */ LEGACY_FLAGS, 0,
433 /* last opt argumnt */ { NULL }, /* --legacy */
434 /* arg list/cookie */ NULL,
435 /* must/cannot opts */ aLegacyMustList, aLegacyCantList,
436 /* option proc */ NULL,
437 /* desc, NAME, name */ LEGACY_DESC, LEGACY_NAME, LEGACY_name,
438 /* disablement strs */ NULL, NULL },
440 { /* entry idx, value */ 7, VALUE_OPT_USER,
441 /* equiv idx, value */ 7, VALUE_OPT_USER,
442 /* equivalenced to */ NO_EQUIVALENT,
443 /* min, max, act ct */ 0, 1, 0,
444 /* opt state flags */ USER_FLAGS, 0,
445 /* last opt argumnt */ { NULL }, /* --user */
446 /* arg list/cookie */ NULL,
447 /* must/cannot opts */ aUserMustList, aUserCantList,
448 /* option proc */ NULL,
449 /* desc, NAME, name */ USER_DESC, USER_NAME, USER_name,
450 /* disablement strs */ NULL, NULL },
452 { /* entry idx, value */ 8, VALUE_OPT_SYSTEM,
453 /* equiv idx, value */ 8, VALUE_OPT_SYSTEM,
454 /* equivalenced to */ NO_EQUIVALENT,
455 /* min, max, act ct */ 0, 1, 0,
456 /* opt state flags */ SYSTEM_FLAGS, 0,
457 /* last opt argumnt */ { NULL }, /* --system */
458 /* arg list/cookie */ NULL,
459 /* must/cannot opts */ aSystemMustList, aSystemCantList,
460 /* option proc */ NULL,
461 /* desc, NAME, name */ SYSTEM_DESC, SYSTEM_NAME, SYSTEM_name,
462 /* disablement strs */ NULL, NULL },
464 { /* entry idx, value */ 9, VALUE_OPT_PUBKEY,
465 /* equiv idx, value */ 9, VALUE_OPT_PUBKEY,
466 /* equivalenced to */ NO_EQUIVALENT,
467 /* min, max, act ct */ 0, 1, 0,
468 /* opt state flags */ PUBKEY_FLAGS, 0,
469 /* last opt argumnt */ { NULL }, /* --pubkey */
470 /* arg list/cookie */ NULL,
471 /* must/cannot opts */ NULL, NULL,
472 /* option proc */ NULL,
473 /* desc, NAME, name */ PUBKEY_DESC, PUBKEY_NAME, PUBKEY_name,
474 /* disablement strs */ NULL, NULL },
476 { /* entry idx, value */ 10, VALUE_OPT_LIST,
477 /* equiv idx, value */ 10, VALUE_OPT_LIST,
478 /* equivalenced to */ NO_EQUIVALENT,
479 /* min, max, act ct */ 0, 1, 0,
480 /* opt state flags */ LIST_FLAGS, 0,
481 /* last opt argumnt */ { NULL }, /* --list */
482 /* arg list/cookie */ NULL,
483 /* must/cannot opts */ NULL, NULL,
484 /* option proc */ NULL,
485 /* desc, NAME, name */ LIST_DESC, LIST_NAME, LIST_name,
486 /* disablement strs */ NULL, NULL },
488 { /* entry idx, value */ 11, VALUE_OPT_DELETE,
489 /* equiv idx, value */ 11, VALUE_OPT_DELETE,
490 /* equivalenced to */ NO_EQUIVALENT,
491 /* min, max, act ct */ 0, 1, 0,
492 /* opt state flags */ DELETE_FLAGS, 0,
493 /* last opt argumnt */ { NULL }, /* --delete */
494 /* arg list/cookie */ NULL,
495 /* must/cannot opts */ NULL, NULL,
496 /* option proc */ NULL,
497 /* desc, NAME, name */ DELETE_DESC, DELETE_NAME, DELETE_name,
498 /* disablement strs */ NULL, NULL },
500 { /* entry idx, value */ 12, VALUE_OPT_SEC_PARAM,
501 /* equiv idx, value */ 12, VALUE_OPT_SEC_PARAM,
502 /* equivalenced to */ NO_EQUIVALENT,
503 /* min, max, act ct */ 0, 1, 0,
504 /* opt state flags */ SEC_PARAM_FLAGS, 0,
505 /* last opt argumnt */ { NULL }, /* --sec-param */
506 /* arg list/cookie */ NULL,
507 /* must/cannot opts */ NULL, NULL,
508 /* option proc */ NULL,
509 /* desc, NAME, name */ SEC_PARAM_DESC, SEC_PARAM_NAME, SEC_PARAM_name,
510 /* disablement strs */ NULL, NULL },
512 { /* entry idx, value */ 13, VALUE_OPT_BITS,
513 /* equiv idx, value */ 13, VALUE_OPT_BITS,
514 /* equivalenced to */ NO_EQUIVALENT,
515 /* min, max, act ct */ 0, 1, 0,
516 /* opt state flags */ BITS_FLAGS, 0,
517 /* last opt argumnt */ { NULL }, /* --bits */
518 /* arg list/cookie */ NULL,
519 /* must/cannot opts */ NULL, NULL,
520 /* option proc */ optionNumericVal,
521 /* desc, NAME, name */ BITS_DESC, BITS_NAME, BITS_name,
522 /* disablement strs */ NULL, NULL },
524 { /* entry idx, value */ 14, VALUE_OPT_INDER,
525 /* equiv idx, value */ 14, VALUE_OPT_INDER,
526 /* equivalenced to */ NO_EQUIVALENT,
527 /* min, max, act ct */ 0, 1, 0,
528 /* opt state flags */ INDER_FLAGS, 0,
529 /* last opt argumnt */ { NULL }, /* --inder */
530 /* arg list/cookie */ NULL,
531 /* must/cannot opts */ NULL, NULL,
532 /* option proc */ NULL,
533 /* desc, NAME, name */ INDER_DESC, INDER_NAME, INDER_name,
534 /* disablement strs */ NOT_INDER_name, NOT_INDER_PFX },
536 { /* entry idx, value */ 15, VALUE_OPT_OUTDER,
537 /* equiv idx, value */ 15, VALUE_OPT_OUTDER,
538 /* equivalenced to */ NO_EQUIVALENT,
539 /* min, max, act ct */ 0, 1, 0,
540 /* opt state flags */ OUTDER_FLAGS, 0,
541 /* last opt argumnt */ { NULL }, /* --outder */
542 /* arg list/cookie */ NULL,
543 /* must/cannot opts */ NULL, NULL,
544 /* option proc */ NULL,
545 /* desc, NAME, name */ OUTDER_DESC, OUTDER_NAME, OUTDER_name,
546 /* disablement strs */ NOT_OUTDER_name, NOT_OUTDER_PFX },
548 { /* entry idx, value */ INDEX_OPT_VERSION, VALUE_OPT_VERSION,
549 /* equiv idx value */ NO_EQUIVALENT, VALUE_OPT_VERSION,
550 /* equivalenced to */ NO_EQUIVALENT,
551 /* min, max, act ct */ 0, 1, 0,
552 /* opt state flags */ VER_FLAGS, 0,
553 /* last opt argumnt */ { NULL },
554 /* arg list/cookie */ NULL,
555 /* must/cannot opts */ NULL, NULL,
556 /* option proc */ VER_PROC,
557 /* desc, NAME, name */ VER_DESC, NULL, VER_name,
558 /* disablement strs */ NULL, NULL },
562 { /* entry idx, value */ INDEX_OPT_HELP, VALUE_OPT_HELP,
563 /* equiv idx value */ NO_EQUIVALENT, VALUE_OPT_HELP,
564 /* equivalenced to */ NO_EQUIVALENT,
565 /* min, max, act ct */ 0, 1, 0,
566 /* opt state flags */ OPTST_IMM | OPTST_NO_INIT, 0,
567 /* last opt argumnt */ { NULL },
568 /* arg list/cookie */ NULL,
569 /* must/cannot opts */ NULL, NULL,
570 /* option proc */ doUsageOpt,
571 /* desc, NAME, name */ HELP_DESC, NULL, HELP_name,
572 /* disablement strs */ NULL, NULL },
574 { /* entry idx, value */ INDEX_OPT_MORE_HELP, VALUE_OPT_MORE_HELP,
575 /* equiv idx value */ NO_EQUIVALENT, VALUE_OPT_MORE_HELP,
576 /* equivalenced to */ NO_EQUIVALENT,
577 /* min, max, act ct */ 0, 1, 0,
578 /* opt state flags */ MORE_HELP_FLAGS, 0,
579 /* last opt argumnt */ { NULL },
580 /* arg list/cookie */ NULL,
581 /* must/cannot opts */ NULL, NULL,
582 /* option proc */ optionPagedUsage,
583 /* desc, NAME, name */ MORE_HELP_DESC, NULL, MORE_HELP_name,
584 /* disablement strs */ NULL, NULL }
588 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
590 * Define the tpmtool Option Environment
592 #define zPROGNAME (tpmtool_opt_strs+1850)
593 #define zUsageTitle (tpmtool_opt_strs+1858)
594 #define zRcName NULL
595 #define apzHomeList NULL
596 #define zBugsAddr (tpmtool_opt_strs+1959)
597 #define zExplain (tpmtool_opt_strs+1978)
598 #define zDetail (tpmtool_opt_strs+1981)
599 #define zFullVersion (tpmtool_opt_strs+2050)
600 /* extracted from optcode.tlib near line 350 */
602 #if defined(ENABLE_NLS)
603 # define OPTPROC_BASE OPTPROC_TRANSLATE | OPTPROC_NXLAT_OPT
604 static tOptionXlateProc translate_option_strings;
605 #else
606 # define OPTPROC_BASE OPTPROC_NONE
607 # define translate_option_strings NULL
608 #endif /* ENABLE_NLS */
611 #define tpmtool_full_usage (NULL)
613 #define tpmtool_short_usage (tpmtool_opt_strs+2068)
615 #endif /* not defined __doxygen__ */
618 * Create the static procedure(s) declared above.
621 * The callout function that invokes the optionUsage function.
623 * @param pOptions the AutoOpts option description structure
624 * @param pOptDesc the descriptor for the "help" (usage) option.
625 * @noreturn
627 static void
628 doUsageOpt(tOptions * pOptions, tOptDesc * pOptDesc)
630 optionUsage(&tpmtoolOptions, TPMTOOL_EXIT_SUCCESS);
631 /* NOTREACHED */
632 (void)pOptDesc;
633 (void)pOptions;
636 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
638 * Code to handle the debug option.
640 * @param pOptions the tpmtool options data structure
641 * @param pOptDesc the option descriptor for this option.
643 static void
644 doOptDebug(tOptions* pOptions, tOptDesc* pOptDesc)
646 static struct {long rmin, rmax;} const rng[1] = {
647 { 0 , 9999 } };
648 int ix;
650 if (pOptions <= OPTPROC_EMIT_LIMIT)
651 goto emit_ranges;
652 optionNumericVal(pOptions, pOptDesc);
654 for (ix = 0; ix < 1; ix++) {
655 if (pOptDesc->optArg.argInt < rng[ix].rmin)
656 continue; /* ranges need not be ordered. */
657 if (pOptDesc->optArg.argInt == rng[ix].rmin)
658 return;
659 if (rng[ix].rmax == LONG_MIN)
660 continue;
661 if (pOptDesc->optArg.argInt <= rng[ix].rmax)
662 return;
665 option_usage_fp = stderr;
667 emit_ranges:
669 optionShowRange(pOptions, pOptDesc, (void *)rng, 1);
672 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
674 * Code to handle the infile option.
676 * @param pOptions the tpmtool options data structure
677 * @param pOptDesc the option descriptor for this option.
679 static void
680 doOptInfile(tOptions* pOptions, tOptDesc* pOptDesc)
682 static teOptFileType const type =
683 FTYPE_MODE_MUST_EXIST + FTYPE_MODE_NO_OPEN;
684 static tuFileMode mode;
685 #ifndef O_CLOEXEC
686 # define O_CLOEXEC 0
687 #endif
688 mode.file_flags = O_CLOEXEC;
690 optionFileCheck(pOptions, pOptDesc, type, mode);
692 /* extracted from optmain.tlib near line 1113 */
695 * The directory containing the data associated with tpmtool.
697 #ifndef PKGDATADIR
698 # define PKGDATADIR ""
699 #endif
702 * Information about the person or institution that packaged tpmtool
703 * for the current distribution.
705 #ifndef WITH_PACKAGER
706 # define tpmtool_packager_info NULL
707 #else
708 static char const tpmtool_packager_info[] =
709 "Packaged by " WITH_PACKAGER
711 # ifdef WITH_PACKAGER_VERSION
712 " ("WITH_PACKAGER_VERSION")"
713 # endif
715 # ifdef WITH_PACKAGER_BUG_REPORTS
716 "\nReport tpmtool bugs to " WITH_PACKAGER_BUG_REPORTS
717 # endif
718 "\n";
719 #endif
720 #ifndef __doxygen__
722 #endif /* __doxygen__ */
724 * The option definitions for tpmtool. The one structure that
725 * binds them all.
727 tOptions tpmtoolOptions = {
728 OPTIONS_STRUCT_VERSION,
729 0, NULL, /* original argc + argv */
730 ( OPTPROC_BASE
731 + OPTPROC_ERRSTOP
732 + OPTPROC_SHORTOPT
733 + OPTPROC_LONGOPT
734 + OPTPROC_NO_REQ_OPT
735 + OPTPROC_NEGATIONS
736 + OPTPROC_NO_ARGS
737 + OPTPROC_GNUUSAGE
738 + OPTPROC_MISUSE ),
739 0, NULL, /* current option index, current option */
740 NULL, NULL, zPROGNAME,
741 zRcName, zCopyright, zLicenseDescrip,
742 zFullVersion, apzHomeList, zUsageTitle,
743 zExplain, zDetail, optDesc,
744 zBugsAddr, /* address to send bugs to */
745 NULL, NULL, /* extensions/saved state */
746 optionUsage, /* usage procedure */
747 translate_option_strings, /* translation procedure */
749 * Indexes to special options
751 { INDEX_OPT_MORE_HELP, /* more-help option index */
752 NO_EQUIVALENT, /* save option index */
753 NO_EQUIVALENT, /* '-#' option index */
754 NO_EQUIVALENT /* index of default opt */
756 19 /* full option count */, 16 /* user option count */,
757 tpmtool_full_usage, tpmtool_short_usage,
758 NULL, NULL,
759 PKGDATADIR, tpmtool_packager_info
762 #if ENABLE_NLS
763 #include <stdio.h>
764 #include <stdlib.h>
765 #include <string.h>
766 #include <unistd.h>
767 #include <autoopts/usage-txt.h>
769 static char* AO_gettext(char const* pz);
770 static void coerce_it(void** s);
773 * AutoGen specific wrapper function for gettext.
774 * It relies on the macro _() to convert from English to the target
775 * language, then strdup-duplicates the result string.
777 * @param[in] pz the input text used as a lookup key.
778 * @returns the translated text (if there is one),
779 * or the original text (if not).
781 static char *
782 AO_gettext(char const* pz)
784 char* pzRes;
785 if (pz == NULL)
786 return NULL;
787 pzRes = _(pz);
788 if (pzRes == pz)
789 return pzRes;
790 pzRes = strdup(pzRes);
791 if (pzRes == NULL) {
792 fputs(_("No memory for duping translated strings\n"), stderr);
793 exit(TPMTOOL_EXIT_FAILURE);
795 return pzRes;
798 static void coerce_it(void** s) { *s = AO_gettext(*s);
802 * Translate all the translatable strings in the tpmtoolOptions
803 * structure defined above. This is done only once.
805 static void
806 translate_option_strings(void)
808 tOptions * const pOpt = &tpmtoolOptions;
811 * Guard against re-translation. It won't work. The strings will have
812 * been changed by the first pass through this code. One shot only.
814 if (option_usage_text.field_ct != 0) {
816 * Do the translations. The first pointer follows the field count
817 * field. The field count field is the size of a pointer.
819 tOptDesc * pOD = pOpt->pOptDesc;
820 char ** ppz = (char**)(void*)&(option_usage_text);
821 int ix = option_usage_text.field_ct;
823 do {
824 ppz++;
825 *ppz = AO_gettext(*ppz);
826 } while (--ix > 0);
828 coerce_it((void*)&(pOpt->pzCopyright));
829 coerce_it((void*)&(pOpt->pzCopyNotice));
830 coerce_it((void*)&(pOpt->pzFullVersion));
831 coerce_it((void*)&(pOpt->pzUsageTitle));
832 coerce_it((void*)&(pOpt->pzExplain));
833 coerce_it((void*)&(pOpt->pzDetail));
834 coerce_it((void*)&(pOpt->pzPackager));
835 coerce_it((void*)&(pOpt->pzShortUsage));
836 option_usage_text.field_ct = 0;
838 for (ix = pOpt->optCt; ix > 0; ix--, pOD++)
839 coerce_it((void*)&(pOD->pzText));
842 if ((pOpt->fOptSet & OPTPROC_NXLAT_OPT_CFG) == 0) {
843 tOptDesc * pOD = pOpt->pOptDesc;
844 int ix;
846 for (ix = pOpt->optCt; ix > 0; ix--, pOD++) {
847 coerce_it((void*)&(pOD->pz_Name));
848 coerce_it((void*)&(pOD->pz_DisableName));
849 coerce_it((void*)&(pOD->pz_DisablePfx));
851 /* prevent re-translation */
852 tpmtoolOptions.fOptSet |= OPTPROC_NXLAT_OPT_CFG | OPTPROC_NXLAT_OPT;
856 #endif /* ENABLE_NLS */
858 #ifdef __cplusplus
860 #endif
861 /* tpmtool-args.c ends here */