1 /* $NetBSD: ntpdc-opts.c,v 1.1.1.2 2012/01/31 21:26:59 kardel Exp $ */ 2 3 /* 4 * EDIT THIS FILE WITH CAUTION (ntpdc-opts.c) 5 * 6 * It has been AutoGen-ed December 24, 2011 at 06:34:16 PM by AutoGen 5.12 7 * From the definitions ntpdc-opts.def 8 * and the template file options 9 * 10 * Generated from AutoOpts 35:0:10 templates. 11 * 12 * AutoOpts is a copyrighted work. This source file is not encumbered 13 * by AutoOpts licensing, but is provided under the licensing terms chosen 14 * by the ntpdc author or copyright holder. AutoOpts is 15 * licensed under the terms of the LGPL. The redistributable library 16 * (``libopts'') is licensed under the terms of either the LGPL or, at the 17 * users discretion, the BSD license. See the AutoOpts and/or libopts sources 18 * for details. 19 * 20 * This source file is copyrighted and licensed under the following terms: 21 * 22 * see html/copyright.html 23 * 24 */ 25 26 #include <sys/types.h> 27 28 #include <limits.h> 29 #include <stdio.h> 30 #include <stdlib.h> 31 32 #define OPTION_CODE_COMPILE 1 33 #include "ntpdc-opts.h" 34 35 #ifdef __cplusplus 36 extern "C" { 37 #endif 38 extern FILE * option_usage_fp; 39 40 /* TRANSLATORS: choose the translation for option names wisely because you 41 cannot ever change your mind. */ 42 static char const zCopyright[39] = 43 "ntpdc 4.2.6p5\n\ 44 see html/copyright.html\n"; 45 static char const zLicenseDescrip[25] = 46 "see html/copyright.html\n"; 47 48 extern tUsageProc optionUsage; 49 50 /* 51 * global included definitions 52 */ 53 #ifdef __windows 54 extern int atoi(const char*); 55 #else 56 # include <stdlib.h> 57 #endif 58 59 #ifndef NULL 60 # define NULL 0 61 #endif 62 63 /* 64 * Ipv4 option description with 65 * "Must also have options" and "Incompatible options": 66 */ 67 static char const zIpv4Text[] = 68 "Force IPv4 DNS name resolution"; 69 static char const zIpv4_NAME[] = "IPV4"; 70 static char const zIpv4_Name[] = "ipv4"; 71 static const int 72 aIpv4CantList[] = { 73 INDEX_OPT_IPV6, NO_EQUIVALENT }; 74 #define IPV4_FLAGS (OPTST_DISABLED) 75 76 /* 77 * Ipv6 option description with 78 * "Must also have options" and "Incompatible options": 79 */ 80 static char const zIpv6Text[] = 81 "Force IPv6 DNS name resolution"; 82 static char const zIpv6_NAME[] = "IPV6"; 83 static char const zIpv6_Name[] = "ipv6"; 84 static const int 85 aIpv6CantList[] = { 86 INDEX_OPT_IPV4, NO_EQUIVALENT }; 87 #define IPV6_FLAGS (OPTST_DISABLED) 88 89 /* 90 * Command option description: 91 */ 92 static char const zCommandText[] = 93 "run a command and exit"; 94 static char const zCommand_NAME[] = "COMMAND"; 95 static char const zCommand_Name[] = "command"; 96 #define COMMAND_FLAGS (OPTST_DISABLED | OPTST_STACKED \ 97 | OPTST_SET_ARGTYPE(OPARG_TYPE_STRING)) 98 99 /* 100 * Listpeers option description with 101 * "Must also have options" and "Incompatible options": 102 */ 103 static char const zListpeersText[] = 104 "Print a list of the peers"; 105 static char const zListpeers_NAME[] = "LISTPEERS"; 106 static char const zListpeers_Name[] = "listpeers"; 107 static const int 108 aListpeersCantList[] = { 109 INDEX_OPT_COMMAND, NO_EQUIVALENT }; 110 #define LISTPEERS_FLAGS (OPTST_DISABLED) 111 112 /* 113 * Peers option description with 114 * "Must also have options" and "Incompatible options": 115 */ 116 static char const zPeersText[] = 117 "Print a list of the peers"; 118 static char const zPeers_NAME[] = "PEERS"; 119 static char const zPeers_Name[] = "peers"; 120 static const int 121 aPeersCantList[] = { 122 INDEX_OPT_COMMAND, NO_EQUIVALENT }; 123 #define PEERS_FLAGS (OPTST_DISABLED) 124 125 /* 126 * Showpeers option description with 127 * "Must also have options" and "Incompatible options": 128 */ 129 static char const zShowpeersText[] = 130 "Show a list of the peers"; 131 static char const zShowpeers_NAME[] = "SHOWPEERS"; 132 static char const zShowpeers_Name[] = "showpeers"; 133 static const int 134 aShowpeersCantList[] = { 135 INDEX_OPT_COMMAND, NO_EQUIVALENT }; 136 #define SHOWPEERS_FLAGS (OPTST_DISABLED) 137 138 /* 139 * Interactive option description with 140 * "Must also have options" and "Incompatible options": 141 */ 142 static char const zInteractiveText[] = 143 "Force ntpq to operate in interactive mode"; 144 static char const zInteractive_NAME[] = "INTERACTIVE"; 145 static char const zInteractive_Name[] = "interactive"; 146 static const int 147 aInteractiveCantList[] = { 148 INDEX_OPT_COMMAND, 149 INDEX_OPT_LISTPEERS, 150 INDEX_OPT_PEERS, 151 INDEX_OPT_SHOWPEERS, NO_EQUIVALENT }; 152 #define INTERACTIVE_FLAGS (OPTST_DISABLED) 153 154 /* 155 * Debug_Level option description: 156 */ 157 static char const zDebug_LevelText[] = 158 "Increase output debug message level"; 159 static char const zDebug_Level_NAME[] = "DEBUG_LEVEL"; 160 static char const zDebug_Level_Name[] = "debug-level"; 161 #define DEBUG_LEVEL_FLAGS (OPTST_DISABLED) 162 163 /* 164 * Set_Debug_Level option description: 165 */ 166 static char const zSet_Debug_LevelText[] = 167 "Set the output debug message level"; 168 static char const zSet_Debug_Level_NAME[] = "SET_DEBUG_LEVEL"; 169 static char const zSet_Debug_Level_Name[] = "set-debug-level"; 170 #define SET_DEBUG_LEVEL_FLAGS (OPTST_DISABLED \ 171 | OPTST_SET_ARGTYPE(OPARG_TYPE_STRING)) 172 173 /* 174 * Numeric option description: 175 */ 176 static char const zNumericText[] = 177 "numeric host addresses"; 178 static char const zNumeric_NAME[] = "NUMERIC"; 179 static char const zNumeric_Name[] = "numeric"; 180 #define NUMERIC_FLAGS (OPTST_DISABLED) 181 182 /* 183 * Help/More_Help/Version option descriptions: 184 */ 185 static char const zHelpText[] = "Display extended usage information and exit"; 186 static char const zHelp_Name[] = "help"; 187 #ifdef HAVE_WORKING_FORK 188 #define OPTST_MORE_HELP_FLAGS (OPTST_IMM | OPTST_NO_INIT) 189 static char const zMore_Help_Name[] = "more-help"; 190 static char const zMore_HelpText[] = "Extended usage information passed thru pager"; 191 #else 192 #define OPTST_MORE_HELP_FLAGS (OPTST_OMITTED | OPTST_NO_INIT) 193 #define zMore_Help_Name NULL 194 #define zMore_HelpText NULL 195 #endif 196 #ifdef NO_OPTIONAL_OPT_ARGS 197 # define OPTST_VERSION_FLAGS OPTST_IMM | OPTST_NO_INIT 198 #else 199 # define OPTST_VERSION_FLAGS OPTST_SET_ARGTYPE(OPARG_TYPE_STRING) | \ 200 OPTST_ARG_OPTIONAL | OPTST_IMM | OPTST_NO_INIT 201 #endif 202 203 static char const zVersionText[] = "Output version information and exit"; 204 static char const zVersion_Name[] = "version"; 205 static char const zSave_OptsText[] = "Save the option state to a config file"; 206 static char const zSave_Opts_Name[] = "save-opts"; 207 static char const zLoad_OptsText[] = "Load options from a config file"; 208 static char const zLoad_Opts_NAME[] = "LOAD_OPTS"; 209 static char const zNotLoad_Opts_Name[] = "no-load-opts"; 210 static char const zNotLoad_Opts_Pfx[] = "no"; 211 #define zLoad_Opts_Name (zNotLoad_Opts_Name + 3) 212 /* 213 * Declare option callback procedures 214 */ 215 #if defined(TEST_NTPDC_OPTS) 216 /* 217 * Under test, omit argument processing, or call optionStackArg, 218 * if multiple copies are allowed. 219 */ 220 static tOptProc 221 doUsageOpt; 222 223 /* 224 * #define map the "normal" callout procs to the test ones... 225 */ 226 #define SET_DEBUG_LEVEL_OPT_PROC optionStackArg 227 228 229 #else /* NOT defined TEST_NTPDC_OPTS */ 230 /* 231 * When not under test, there are different procs to use 232 */ 233 extern tOptProc 234 optionBooleanVal, optionNestedVal, optionNumericVal, 235 optionPagedUsage, optionPrintVersion, optionResetOpt, 236 optionStackArg, optionTimeDate, optionTimeVal, 237 optionUnstackArg, optionVersionStderr; 238 static tOptProc 239 doOptSet_Debug_Level, doUsageOpt; 240 241 /* 242 * #define map the "normal" callout procs 243 */ 244 #define SET_DEBUG_LEVEL_OPT_PROC doOptSet_Debug_Level 245 246 #define SET_DEBUG_LEVEL_OPT_PROC doOptSet_Debug_Level 247 #endif /* defined(TEST_NTPDC_OPTS) */ 248 #ifdef TEST_NTPDC_OPTS 249 # define DOVERPROC optionVersionStderr 250 #else 251 # define DOVERPROC optionPrintVersion 252 #endif /* TEST_NTPDC_OPTS */ 253 254 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 255 * 256 * Define the Ntpdc Option Descriptions. 257 */ 258 static tOptDesc optDesc[OPTION_CT] = { 259 { /* entry idx, value */ 0, VALUE_OPT_IPV4, 260 /* equiv idx, value */ 0, VALUE_OPT_IPV4, 261 /* equivalenced to */ NO_EQUIVALENT, 262 /* min, max, act ct */ 0, 1, 0, 263 /* opt state flags */ IPV4_FLAGS, 0, 264 /* last opt argumnt */ { NULL }, 265 /* arg list/cookie */ NULL, 266 /* must/cannot opts */ NULL, aIpv4CantList, 267 /* option proc */ NULL, 268 /* desc, NAME, name */ zIpv4Text, zIpv4_NAME, zIpv4_Name, 269 /* disablement strs */ NULL, NULL }, 270 271 { /* entry idx, value */ 1, VALUE_OPT_IPV6, 272 /* equiv idx, value */ 1, VALUE_OPT_IPV6, 273 /* equivalenced to */ NO_EQUIVALENT, 274 /* min, max, act ct */ 0, 1, 0, 275 /* opt state flags */ IPV6_FLAGS, 0, 276 /* last opt argumnt */ { NULL }, 277 /* arg list/cookie */ NULL, 278 /* must/cannot opts */ NULL, aIpv6CantList, 279 /* option proc */ NULL, 280 /* desc, NAME, name */ zIpv6Text, zIpv6_NAME, zIpv6_Name, 281 /* disablement strs */ NULL, NULL }, 282 283 { /* entry idx, value */ 2, VALUE_OPT_COMMAND, 284 /* equiv idx, value */ 2, VALUE_OPT_COMMAND, 285 /* equivalenced to */ NO_EQUIVALENT, 286 /* min, max, act ct */ 0, NOLIMIT, 0, 287 /* opt state flags */ COMMAND_FLAGS, 0, 288 /* last opt argumnt */ { NULL }, 289 /* arg list/cookie */ NULL, 290 /* must/cannot opts */ NULL, NULL, 291 /* option proc */ optionStackArg, 292 /* desc, NAME, name */ zCommandText, zCommand_NAME, zCommand_Name, 293 /* disablement strs */ NULL, NULL }, 294 295 { /* entry idx, value */ 3, VALUE_OPT_LISTPEERS, 296 /* equiv idx, value */ 3, VALUE_OPT_LISTPEERS, 297 /* equivalenced to */ NO_EQUIVALENT, 298 /* min, max, act ct */ 0, 1, 0, 299 /* opt state flags */ LISTPEERS_FLAGS, 0, 300 /* last opt argumnt */ { NULL }, 301 /* arg list/cookie */ NULL, 302 /* must/cannot opts */ NULL, aListpeersCantList, 303 /* option proc */ NULL, 304 /* desc, NAME, name */ zListpeersText, zListpeers_NAME, zListpeers_Name, 305 /* disablement strs */ NULL, NULL }, 306 307 { /* entry idx, value */ 4, VALUE_OPT_PEERS, 308 /* equiv idx, value */ 4, VALUE_OPT_PEERS, 309 /* equivalenced to */ NO_EQUIVALENT, 310 /* min, max, act ct */ 0, 1, 0, 311 /* opt state flags */ PEERS_FLAGS, 0, 312 /* last opt argumnt */ { NULL }, 313 /* arg list/cookie */ NULL, 314 /* must/cannot opts */ NULL, aPeersCantList, 315 /* option proc */ NULL, 316 /* desc, NAME, name */ zPeersText, zPeers_NAME, zPeers_Name, 317 /* disablement strs */ NULL, NULL }, 318 319 { /* entry idx, value */ 5, VALUE_OPT_SHOWPEERS, 320 /* equiv idx, value */ 5, VALUE_OPT_SHOWPEERS, 321 /* equivalenced to */ NO_EQUIVALENT, 322 /* min, max, act ct */ 0, 1, 0, 323 /* opt state flags */ SHOWPEERS_FLAGS, 0, 324 /* last opt argumnt */ { NULL }, 325 /* arg list/cookie */ NULL, 326 /* must/cannot opts */ NULL, aShowpeersCantList, 327 /* option proc */ NULL, 328 /* desc, NAME, name */ zShowpeersText, zShowpeers_NAME, zShowpeers_Name, 329 /* disablement strs */ NULL, NULL }, 330 331 { /* entry idx, value */ 6, VALUE_OPT_INTERACTIVE, 332 /* equiv idx, value */ 6, VALUE_OPT_INTERACTIVE, 333 /* equivalenced to */ NO_EQUIVALENT, 334 /* min, max, act ct */ 0, 1, 0, 335 /* opt state flags */ INTERACTIVE_FLAGS, 0, 336 /* last opt argumnt */ { NULL }, 337 /* arg list/cookie */ NULL, 338 /* must/cannot opts */ NULL, aInteractiveCantList, 339 /* option proc */ NULL, 340 /* desc, NAME, name */ zInteractiveText, zInteractive_NAME, zInteractive_Name, 341 /* disablement strs */ NULL, NULL }, 342 343 { /* entry idx, value */ 7, VALUE_OPT_DEBUG_LEVEL, 344 /* equiv idx, value */ 7, VALUE_OPT_DEBUG_LEVEL, 345 /* equivalenced to */ NO_EQUIVALENT, 346 /* min, max, act ct */ 0, NOLIMIT, 0, 347 /* opt state flags */ DEBUG_LEVEL_FLAGS, 0, 348 /* last opt argumnt */ { NULL }, 349 /* arg list/cookie */ NULL, 350 /* must/cannot opts */ NULL, NULL, 351 /* option proc */ NULL, 352 /* desc, NAME, name */ zDebug_LevelText, zDebug_Level_NAME, zDebug_Level_Name, 353 /* disablement strs */ NULL, NULL }, 354 355 { /* entry idx, value */ 8, VALUE_OPT_SET_DEBUG_LEVEL, 356 /* equiv idx, value */ 8, VALUE_OPT_SET_DEBUG_LEVEL, 357 /* equivalenced to */ NO_EQUIVALENT, 358 /* min, max, act ct */ 0, NOLIMIT, 0, 359 /* opt state flags */ SET_DEBUG_LEVEL_FLAGS, 0, 360 /* last opt argumnt */ { NULL }, 361 /* arg list/cookie */ NULL, 362 /* must/cannot opts */ NULL, NULL, 363 /* option proc */ SET_DEBUG_LEVEL_OPT_PROC, 364 /* desc, NAME, name */ zSet_Debug_LevelText, zSet_Debug_Level_NAME, zSet_Debug_Level_Name, 365 /* disablement strs */ NULL, NULL }, 366 367 { /* entry idx, value */ 9, VALUE_OPT_NUMERIC, 368 /* equiv idx, value */ 9, VALUE_OPT_NUMERIC, 369 /* equivalenced to */ NO_EQUIVALENT, 370 /* min, max, act ct */ 0, 1, 0, 371 /* opt state flags */ NUMERIC_FLAGS, 0, 372 /* last opt argumnt */ { NULL }, 373 /* arg list/cookie */ NULL, 374 /* must/cannot opts */ NULL, NULL, 375 /* option proc */ NULL, 376 /* desc, NAME, name */ zNumericText, zNumeric_NAME, zNumeric_Name, 377 /* disablement strs */ NULL, NULL }, 378 379 { /* entry idx, value */ INDEX_OPT_VERSION, VALUE_OPT_VERSION, 380 /* equiv idx value */ NO_EQUIVALENT, 0, 381 /* equivalenced to */ NO_EQUIVALENT, 382 /* min, max, act ct */ 0, 1, 0, 383 /* opt state flags */ OPTST_VERSION_FLAGS, 0, 384 /* last opt argumnt */ { NULL }, 385 /* arg list/cookie */ NULL, 386 /* must/cannot opts */ NULL, NULL, 387 /* option proc */ DOVERPROC, 388 /* desc, NAME, name */ zVersionText, NULL, zVersion_Name, 389 /* disablement strs */ NULL, NULL }, 390 391 392 393 { /* entry idx, value */ INDEX_OPT_HELP, VALUE_OPT_HELP, 394 /* equiv idx value */ NO_EQUIVALENT, 0, 395 /* equivalenced to */ NO_EQUIVALENT, 396 /* min, max, act ct */ 0, 1, 0, 397 /* opt state flags */ OPTST_IMM | OPTST_NO_INIT, 0, 398 /* last opt argumnt */ { NULL }, 399 /* arg list/cookie */ NULL, 400 /* must/cannot opts */ NULL, NULL, 401 /* option proc */ doUsageOpt, 402 /* desc, NAME, name */ zHelpText, NULL, zHelp_Name, 403 /* disablement strs */ NULL, NULL }, 404 405 { /* entry idx, value */ INDEX_OPT_MORE_HELP, VALUE_OPT_MORE_HELP, 406 /* equiv idx value */ NO_EQUIVALENT, 0, 407 /* equivalenced to */ NO_EQUIVALENT, 408 /* min, max, act ct */ 0, 1, 0, 409 /* opt state flags */ OPTST_MORE_HELP_FLAGS, 0, 410 /* last opt argumnt */ { NULL }, 411 /* arg list/cookie */ NULL, 412 /* must/cannot opts */ NULL, NULL, 413 /* option proc */ optionPagedUsage, 414 /* desc, NAME, name */ zMore_HelpText, NULL, zMore_Help_Name, 415 /* disablement strs */ NULL, NULL }, 416 417 { /* entry idx, value */ INDEX_OPT_SAVE_OPTS, VALUE_OPT_SAVE_OPTS, 418 /* equiv idx value */ NO_EQUIVALENT, 0, 419 /* equivalenced to */ NO_EQUIVALENT, 420 /* min, max, act ct */ 0, 1, 0, 421 /* opt state flags */ OPTST_SET_ARGTYPE(OPARG_TYPE_STRING) 422 | OPTST_ARG_OPTIONAL | OPTST_NO_INIT, 0, 423 /* last opt argumnt */ { NULL }, 424 /* arg list/cookie */ NULL, 425 /* must/cannot opts */ NULL, NULL, 426 /* option proc */ NULL, 427 /* desc, NAME, name */ zSave_OptsText, NULL, zSave_Opts_Name, 428 /* disablement strs */ NULL, NULL }, 429 430 { /* entry idx, value */ INDEX_OPT_LOAD_OPTS, VALUE_OPT_LOAD_OPTS, 431 /* equiv idx value */ NO_EQUIVALENT, 0, 432 /* equivalenced to */ NO_EQUIVALENT, 433 /* min, max, act ct */ 0, NOLIMIT, 0, 434 /* opt state flags */ OPTST_SET_ARGTYPE(OPARG_TYPE_STRING) 435 | OPTST_DISABLE_IMM, 0, 436 /* last opt argumnt */ { NULL }, 437 /* arg list/cookie */ NULL, 438 /* must/cannot opts */ NULL, NULL, 439 /* option proc */ optionLoadOpt, 440 /* desc, NAME, name */ zLoad_OptsText, zLoad_Opts_NAME, zLoad_Opts_Name, 441 /* disablement strs */ zNotLoad_Opts_Name, zNotLoad_Opts_Pfx } 442 }; 443 444 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 445 * 446 * Define the Ntpdc Option Environment 447 */ 448 static char const zPROGNAME[6] = "NTPDC"; 449 static char const zUsageTitle[127] = 450 "ntpdc - vendor-specific NTP query program - Ver. 4.2.6p5\n\ 451 USAGE: %s [ -<flag> [<val>] | --<name>[{=| }<val>] ]... [ host ...]\n"; 452 static char const zRcName[7] = ".ntprc"; 453 static char const * const apzHomeList[3] = { 454 "$HOME", 455 ".", 456 NULL }; 457 458 static char const zBugsAddr[34] = "http://bugs.ntp.org, bugs@ntp.org"; 459 #define zExplain NULL 460 static char const zDetail[601] = "\n\ 461 The [= prog-name =] utility program is used to query an NTP daemon about\n\ 462 its current state and to request changes in that state. It uses NTP mode\n\ 463 7 control message formats described in the source code. The program may\n\ 464 be run either in interactive mode or controlled using command line\n\ 465 arguments. Extensive state and statistics information is available\n\ 466 through the [= prog-name =] interface. In addition, nearly all the\n\ 467 configuration options which can be specified at startup using ntpd's\n\ 468 configuration file may also be specified at run time using [= prog-name =]\n\ 469 .\n"; 470 static char const zFullVersion[] = NTPDC_FULL_VERSION; 471 /* extracted from optcode.tlib near line 515 */ 472 473 #if defined(ENABLE_NLS) 474 # define OPTPROC_BASE OPTPROC_TRANSLATE 475 static tOptionXlateProc translate_option_strings; 476 #else 477 # define OPTPROC_BASE OPTPROC_NONE 478 # define translate_option_strings NULL 479 #endif /* ENABLE_NLS */ 480 481 482 #define ntpdc_full_usage NULL 483 #define ntpdc_short_usage NULL 484 #ifndef PKGDATADIR 485 # define PKGDATADIR "" 486 #endif 487 488 #ifndef WITH_PACKAGER 489 # define ntpdc_packager_info NULL 490 #else 491 static char const ntpdc_packager_info[] = 492 "Packaged by " WITH_PACKAGER 493 494 # ifdef WITH_PACKAGER_VERSION 495 " ("WITH_PACKAGER_VERSION")" 496 # endif 497 498 # ifdef WITH_PACKAGER_BUG_REPORTS 499 "\nReport ntpdc bugs to " WITH_PACKAGER_BUG_REPORTS 500 # endif 501 "\n"; 502 #endif 503 504 tOptions ntpdcOptions = { 505 OPTIONS_STRUCT_VERSION, 506 0, NULL, /* original argc + argv */ 507 ( OPTPROC_BASE 508 + OPTPROC_ERRSTOP 509 + OPTPROC_SHORTOPT 510 + OPTPROC_LONGOPT 511 + OPTPROC_NO_REQ_OPT 512 + OPTPROC_ENVIRON 513 + OPTPROC_MISUSE ), 514 0, NULL, /* current option index, current option */ 515 NULL, NULL, zPROGNAME, 516 zRcName, zCopyright, zLicenseDescrip, 517 zFullVersion, apzHomeList, zUsageTitle, 518 zExplain, zDetail, optDesc, 519 zBugsAddr, /* address to send bugs to */ 520 NULL, NULL, /* extensions/saved state */ 521 optionUsage, /* usage procedure */ 522 translate_option_strings, /* translation procedure */ 523 /* 524 * Indexes to special options 525 */ 526 { INDEX_OPT_MORE_HELP, /* more-help option index */ 527 INDEX_OPT_SAVE_OPTS, /* save option index */ 528 NO_EQUIVALENT, /* '-#' option index */ 529 NO_EQUIVALENT /* index of default opt */ 530 }, 531 15 /* full option count */, 10 /* user option count */, 532 ntpdc_full_usage, ntpdc_short_usage, 533 NULL, NULL, 534 PKGDATADIR, ntpdc_packager_info 535 }; 536 537 /* 538 * Create the static procedure(s) declared above. 539 */ 540 static void 541 doUsageOpt(tOptions * pOptions, tOptDesc * pOptDesc) 542 { 543 (void)pOptions; 544 USAGE(NTPDC_EXIT_SUCCESS); 545 } 546 547 #if ! defined(TEST_NTPDC_OPTS) 548 549 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 550 * 551 * For the set-debug-level option. 552 */ 553 static void 554 doOptSet_Debug_Level(tOptions* pOptions, tOptDesc* pOptDesc) 555 { 556 /* extracted from debug-opt.def, line 27 */ 557 DESC(DEBUG_LEVEL).optOccCt = atoi( pOptDesc->pzLastArg ); 558 } 559 #endif /* defined(TEST_NTPDC_OPTS) */ 560 /* extracted from optmain.tlib near line 128 */ 561 562 #if defined(TEST_NTPDC_OPTS) /* TEST MAIN PROCEDURE: */ 563 564 extern void optionPutShell(tOptions*); 565 566 int 567 main(int argc, char ** argv) 568 { 569 int res = NTPDC_EXIT_SUCCESS; 570 (void)optionProcess(&ntpdcOptions, argc, argv); 571 optionPutShell(&ntpdcOptions); 572 res = ferror(stdout); 573 if (res != 0) 574 fputs("output error writing to stdout\n", stderr); 575 return res; 576 } 577 #endif /* defined TEST_NTPDC_OPTS */ 578 /* extracted from optcode.tlib near line 666 */ 579 580 #if ENABLE_NLS 581 #include <stdio.h> 582 #include <stdlib.h> 583 #include <string.h> 584 #include <unistd.h> 585 #include <autoopts/usage-txt.h> 586 587 static char* AO_gettext(char const* pz); 588 static void coerce_it(void** s); 589 590 static char* 591 AO_gettext(char const* pz) 592 { 593 char* pzRes; 594 if (pz == NULL) 595 return NULL; 596 pzRes = _(pz); 597 if (pzRes == pz) 598 return pzRes; 599 pzRes = strdup(pzRes); 600 if (pzRes == NULL) { 601 fputs(_("No memory for duping translated strings\n"), stderr); 602 exit(NTPDC_EXIT_FAILURE); 603 } 604 return pzRes; 605 } 606 607 static void coerce_it(void** s) { *s = AO_gettext(*s); 608 } 609 610 /* 611 * This invokes the translation code (e.g. gettext(3)). 612 */ 613 static void 614 translate_option_strings(void) 615 { 616 tOptions * const pOpt = &ntpdcOptions; 617 618 /* 619 * Guard against re-translation. It won't work. The strings will have 620 * been changed by the first pass through this code. One shot only. 621 */ 622 if (option_usage_text.field_ct != 0) { 623 /* 624 * Do the translations. The first pointer follows the field count 625 * field. The field count field is the size of a pointer. 626 */ 627 tOptDesc * pOD = pOpt->pOptDesc; 628 char ** ppz = (char**)(void*)&(option_usage_text); 629 int ix = option_usage_text.field_ct; 630 631 do { 632 ppz++; 633 *ppz = AO_gettext(*ppz); 634 } while (--ix > 0); 635 636 coerce_it((void*)&(pOpt->pzCopyright)); 637 coerce_it((void*)&(pOpt->pzCopyNotice)); 638 coerce_it((void*)&(pOpt->pzFullVersion)); 639 coerce_it((void*)&(pOpt->pzUsageTitle)); 640 coerce_it((void*)&(pOpt->pzExplain)); 641 coerce_it((void*)&(pOpt->pzDetail)); 642 coerce_it((void*)&(pOpt->pzPackager)); 643 option_usage_text.field_ct = 0; 644 645 for (ix = pOpt->optCt; ix > 0; ix--, pOD++) 646 coerce_it((void*)&(pOD->pzText)); 647 } 648 649 if ((pOpt->fOptSet & OPTPROC_NXLAT_OPT_CFG) == 0) { 650 tOptDesc * pOD = pOpt->pOptDesc; 651 int ix; 652 653 for (ix = pOpt->optCt; ix > 0; ix--, pOD++) { 654 coerce_it((void*)&(pOD->pz_Name)); 655 coerce_it((void*)&(pOD->pz_DisableName)); 656 coerce_it((void*)&(pOD->pz_DisablePfx)); 657 } 658 /* prevent re-translation */ 659 ntpdcOptions.fOptSet |= OPTPROC_NXLAT_OPT_CFG | OPTPROC_NXLAT_OPT; 660 } 661 } 662 663 #endif /* ENABLE_NLS */ 664 665 #ifdef __cplusplus 666 } 667 #endif 668 /* ntpdc-opts.c ends here */ 669