1 /* $NetBSD: ntpq-opts.c,v 1.1.1.2 2012/01/31 21:26:48 kardel Exp $ */ 2 3 /* 4 * EDIT THIS FILE WITH CAUTION (ntpq-opts.c) 5 * 6 * It has been AutoGen-ed December 24, 2011 at 06:34:27 PM by AutoGen 5.12 7 * From the definitions ntpq-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 ntpq 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 "ntpq-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[38] = 43 "ntpq 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 \ 97 | OPTST_SET_ARGTYPE(OPARG_TYPE_STRING)) 98 99 /* 100 * Debug_Level option description: 101 */ 102 static char const zDebug_LevelText[] = 103 "Increase output debug message level"; 104 static char const zDebug_Level_NAME[] = "DEBUG_LEVEL"; 105 static char const zDebug_Level_Name[] = "debug-level"; 106 #define DEBUG_LEVEL_FLAGS (OPTST_DISABLED) 107 108 /* 109 * Set_Debug_Level option description: 110 */ 111 static char const zSet_Debug_LevelText[] = 112 "Set the output debug message level"; 113 static char const zSet_Debug_Level_NAME[] = "SET_DEBUG_LEVEL"; 114 static char const zSet_Debug_Level_Name[] = "set-debug-level"; 115 #define SET_DEBUG_LEVEL_FLAGS (OPTST_DISABLED \ 116 | OPTST_SET_ARGTYPE(OPARG_TYPE_STRING)) 117 118 /* 119 * Peers option description with 120 * "Must also have options" and "Incompatible options": 121 */ 122 static char const zPeersText[] = 123 "Print a list of the peers"; 124 static char const zPeers_NAME[] = "PEERS"; 125 static char const zPeers_Name[] = "peers"; 126 static const int 127 aPeersCantList[] = { 128 INDEX_OPT_INTERACTIVE, NO_EQUIVALENT }; 129 #define PEERS_FLAGS (OPTST_DISABLED) 130 131 /* 132 * Interactive option description with 133 * "Must also have options" and "Incompatible options": 134 */ 135 static char const zInteractiveText[] = 136 "Force ntpq to operate in interactive mode"; 137 static char const zInteractive_NAME[] = "INTERACTIVE"; 138 static char const zInteractive_Name[] = "interactive"; 139 static const int 140 aInteractiveCantList[] = { 141 INDEX_OPT_COMMAND, 142 INDEX_OPT_PEERS, NO_EQUIVALENT }; 143 #define INTERACTIVE_FLAGS (OPTST_DISABLED) 144 145 /* 146 * Numeric option description: 147 */ 148 static char const zNumericText[] = 149 "numeric host addresses"; 150 static char const zNumeric_NAME[] = "NUMERIC"; 151 static char const zNumeric_Name[] = "numeric"; 152 #define NUMERIC_FLAGS (OPTST_DISABLED) 153 154 /* 155 * Old_Rv option description: 156 */ 157 static char const zOld_RvText[] = 158 "Always output status line with readvar"; 159 static char const zOld_Rv_NAME[] = "OLD_RV"; 160 static char const zOld_Rv_Name[] = "old-rv"; 161 #define OLD_RV_FLAGS (OPTST_DISABLED) 162 163 /* 164 * Help/More_Help/Version option descriptions: 165 */ 166 static char const zHelpText[] = "Display extended usage information and exit"; 167 static char const zHelp_Name[] = "help"; 168 #ifdef HAVE_WORKING_FORK 169 #define OPTST_MORE_HELP_FLAGS (OPTST_IMM | OPTST_NO_INIT) 170 static char const zMore_Help_Name[] = "more-help"; 171 static char const zMore_HelpText[] = "Extended usage information passed thru pager"; 172 #else 173 #define OPTST_MORE_HELP_FLAGS (OPTST_OMITTED | OPTST_NO_INIT) 174 #define zMore_Help_Name NULL 175 #define zMore_HelpText NULL 176 #endif 177 #ifdef NO_OPTIONAL_OPT_ARGS 178 # define OPTST_VERSION_FLAGS OPTST_IMM | OPTST_NO_INIT 179 #else 180 # define OPTST_VERSION_FLAGS OPTST_SET_ARGTYPE(OPARG_TYPE_STRING) | \ 181 OPTST_ARG_OPTIONAL | OPTST_IMM | OPTST_NO_INIT 182 #endif 183 184 static char const zVersionText[] = "Output version information and exit"; 185 static char const zVersion_Name[] = "version"; 186 static char const zSave_OptsText[] = "Save the option state to a config file"; 187 static char const zSave_Opts_Name[] = "save-opts"; 188 static char const zLoad_OptsText[] = "Load options from a config file"; 189 static char const zLoad_Opts_NAME[] = "LOAD_OPTS"; 190 static char const zNotLoad_Opts_Name[] = "no-load-opts"; 191 static char const zNotLoad_Opts_Pfx[] = "no"; 192 #define zLoad_Opts_Name (zNotLoad_Opts_Name + 3) 193 /* 194 * Declare option callback procedures 195 */ 196 #if defined(TEST_NTPQ_OPTS) 197 /* 198 * Under test, omit argument processing, or call optionStackArg, 199 * if multiple copies are allowed. 200 */ 201 extern tOptProc 202 optionStackArg; 203 static tOptProc 204 doUsageOpt; 205 206 /* 207 * #define map the "normal" callout procs to the test ones... 208 */ 209 #define COMMAND_OPT_PROC optionStackArg 210 #define SET_DEBUG_LEVEL_OPT_PROC optionStackArg 211 #define PEERS_OPT_PROC optionStackArg 212 213 214 #else /* NOT defined TEST_NTPQ_OPTS */ 215 /* 216 * When not under test, there are different procs to use 217 */ 218 extern tOptProc 219 ntpq_custom_opt_handler, optionBooleanVal, optionNestedVal, 220 optionNumericVal, optionPagedUsage, optionPrintVersion, 221 optionResetOpt, optionStackArg, optionTimeDate, 222 optionTimeVal, optionUnstackArg, optionVersionStderr; 223 static tOptProc 224 doOptSet_Debug_Level, doUsageOpt; 225 226 /* 227 * #define map the "normal" callout procs 228 */ 229 #define COMMAND_OPT_PROC ntpq_custom_opt_handler 230 #define SET_DEBUG_LEVEL_OPT_PROC doOptSet_Debug_Level 231 #define PEERS_OPT_PROC ntpq_custom_opt_handler 232 233 #define COMMAND_OPT_PROC ntpq_custom_opt_handler 234 #define SET_DEBUG_LEVEL_OPT_PROC doOptSet_Debug_Level 235 #define PEERS_OPT_PROC ntpq_custom_opt_handler 236 #endif /* defined(TEST_NTPQ_OPTS) */ 237 #ifdef TEST_NTPQ_OPTS 238 # define DOVERPROC optionVersionStderr 239 #else 240 # define DOVERPROC optionPrintVersion 241 #endif /* TEST_NTPQ_OPTS */ 242 243 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 244 * 245 * Define the Ntpq Option Descriptions. 246 */ 247 static tOptDesc optDesc[OPTION_CT] = { 248 { /* entry idx, value */ 0, VALUE_OPT_IPV4, 249 /* equiv idx, value */ 0, VALUE_OPT_IPV4, 250 /* equivalenced to */ NO_EQUIVALENT, 251 /* min, max, act ct */ 0, 1, 0, 252 /* opt state flags */ IPV4_FLAGS, 0, 253 /* last opt argumnt */ { NULL }, 254 /* arg list/cookie */ NULL, 255 /* must/cannot opts */ NULL, aIpv4CantList, 256 /* option proc */ NULL, 257 /* desc, NAME, name */ zIpv4Text, zIpv4_NAME, zIpv4_Name, 258 /* disablement strs */ NULL, NULL }, 259 260 { /* entry idx, value */ 1, VALUE_OPT_IPV6, 261 /* equiv idx, value */ 1, VALUE_OPT_IPV6, 262 /* equivalenced to */ NO_EQUIVALENT, 263 /* min, max, act ct */ 0, 1, 0, 264 /* opt state flags */ IPV6_FLAGS, 0, 265 /* last opt argumnt */ { NULL }, 266 /* arg list/cookie */ NULL, 267 /* must/cannot opts */ NULL, aIpv6CantList, 268 /* option proc */ NULL, 269 /* desc, NAME, name */ zIpv6Text, zIpv6_NAME, zIpv6_Name, 270 /* disablement strs */ NULL, NULL }, 271 272 { /* entry idx, value */ 2, VALUE_OPT_COMMAND, 273 /* equiv idx, value */ 2, VALUE_OPT_COMMAND, 274 /* equivalenced to */ NO_EQUIVALENT, 275 /* min, max, act ct */ 0, NOLIMIT, 0, 276 /* opt state flags */ COMMAND_FLAGS, 0, 277 /* last opt argumnt */ { NULL }, 278 /* arg list/cookie */ NULL, 279 /* must/cannot opts */ NULL, NULL, 280 /* option proc */ COMMAND_OPT_PROC, 281 /* desc, NAME, name */ zCommandText, zCommand_NAME, zCommand_Name, 282 /* disablement strs */ NULL, NULL }, 283 284 { /* entry idx, value */ 3, VALUE_OPT_DEBUG_LEVEL, 285 /* equiv idx, value */ 3, VALUE_OPT_DEBUG_LEVEL, 286 /* equivalenced to */ NO_EQUIVALENT, 287 /* min, max, act ct */ 0, NOLIMIT, 0, 288 /* opt state flags */ DEBUG_LEVEL_FLAGS, 0, 289 /* last opt argumnt */ { NULL }, 290 /* arg list/cookie */ NULL, 291 /* must/cannot opts */ NULL, NULL, 292 /* option proc */ NULL, 293 /* desc, NAME, name */ zDebug_LevelText, zDebug_Level_NAME, zDebug_Level_Name, 294 /* disablement strs */ NULL, NULL }, 295 296 { /* entry idx, value */ 4, VALUE_OPT_SET_DEBUG_LEVEL, 297 /* equiv idx, value */ 4, VALUE_OPT_SET_DEBUG_LEVEL, 298 /* equivalenced to */ NO_EQUIVALENT, 299 /* min, max, act ct */ 0, NOLIMIT, 0, 300 /* opt state flags */ SET_DEBUG_LEVEL_FLAGS, 0, 301 /* last opt argumnt */ { NULL }, 302 /* arg list/cookie */ NULL, 303 /* must/cannot opts */ NULL, NULL, 304 /* option proc */ SET_DEBUG_LEVEL_OPT_PROC, 305 /* desc, NAME, name */ zSet_Debug_LevelText, zSet_Debug_Level_NAME, zSet_Debug_Level_Name, 306 /* disablement strs */ NULL, NULL }, 307 308 { /* entry idx, value */ 5, VALUE_OPT_PEERS, 309 /* equiv idx, value */ 5, VALUE_OPT_PEERS, 310 /* equivalenced to */ NO_EQUIVALENT, 311 /* min, max, act ct */ 0, 1, 0, 312 /* opt state flags */ PEERS_FLAGS, 0, 313 /* last opt argumnt */ { NULL }, 314 /* arg list/cookie */ NULL, 315 /* must/cannot opts */ NULL, aPeersCantList, 316 /* option proc */ PEERS_OPT_PROC, 317 /* desc, NAME, name */ zPeersText, zPeers_NAME, zPeers_Name, 318 /* disablement strs */ NULL, NULL }, 319 320 { /* entry idx, value */ 6, VALUE_OPT_INTERACTIVE, 321 /* equiv idx, value */ 6, VALUE_OPT_INTERACTIVE, 322 /* equivalenced to */ NO_EQUIVALENT, 323 /* min, max, act ct */ 0, 1, 0, 324 /* opt state flags */ INTERACTIVE_FLAGS, 0, 325 /* last opt argumnt */ { NULL }, 326 /* arg list/cookie */ NULL, 327 /* must/cannot opts */ NULL, aInteractiveCantList, 328 /* option proc */ NULL, 329 /* desc, NAME, name */ zInteractiveText, zInteractive_NAME, zInteractive_Name, 330 /* disablement strs */ NULL, NULL }, 331 332 { /* entry idx, value */ 7, VALUE_OPT_NUMERIC, 333 /* equiv idx, value */ 7, VALUE_OPT_NUMERIC, 334 /* equivalenced to */ NO_EQUIVALENT, 335 /* min, max, act ct */ 0, 1, 0, 336 /* opt state flags */ NUMERIC_FLAGS, 0, 337 /* last opt argumnt */ { NULL }, 338 /* arg list/cookie */ NULL, 339 /* must/cannot opts */ NULL, NULL, 340 /* option proc */ NULL, 341 /* desc, NAME, name */ zNumericText, zNumeric_NAME, zNumeric_Name, 342 /* disablement strs */ NULL, NULL }, 343 344 { /* entry idx, value */ 8, VALUE_OPT_OLD_RV, 345 /* equiv idx, value */ 8, VALUE_OPT_OLD_RV, 346 /* equivalenced to */ NO_EQUIVALENT, 347 /* min, max, act ct */ 0, 1, 0, 348 /* opt state flags */ OLD_RV_FLAGS, 0, 349 /* last opt argumnt */ { NULL }, 350 /* arg list/cookie */ NULL, 351 /* must/cannot opts */ NULL, NULL, 352 /* option proc */ NULL, 353 /* desc, NAME, name */ zOld_RvText, zOld_Rv_NAME, zOld_Rv_Name, 354 /* disablement strs */ NULL, NULL }, 355 356 { /* entry idx, value */ INDEX_OPT_VERSION, VALUE_OPT_VERSION, 357 /* equiv idx value */ NO_EQUIVALENT, 0, 358 /* equivalenced to */ NO_EQUIVALENT, 359 /* min, max, act ct */ 0, 1, 0, 360 /* opt state flags */ OPTST_VERSION_FLAGS, 0, 361 /* last opt argumnt */ { NULL }, 362 /* arg list/cookie */ NULL, 363 /* must/cannot opts */ NULL, NULL, 364 /* option proc */ DOVERPROC, 365 /* desc, NAME, name */ zVersionText, NULL, zVersion_Name, 366 /* disablement strs */ NULL, NULL }, 367 368 369 370 { /* entry idx, value */ INDEX_OPT_HELP, VALUE_OPT_HELP, 371 /* equiv idx value */ NO_EQUIVALENT, 0, 372 /* equivalenced to */ NO_EQUIVALENT, 373 /* min, max, act ct */ 0, 1, 0, 374 /* opt state flags */ OPTST_IMM | OPTST_NO_INIT, 0, 375 /* last opt argumnt */ { NULL }, 376 /* arg list/cookie */ NULL, 377 /* must/cannot opts */ NULL, NULL, 378 /* option proc */ doUsageOpt, 379 /* desc, NAME, name */ zHelpText, NULL, zHelp_Name, 380 /* disablement strs */ NULL, NULL }, 381 382 { /* entry idx, value */ INDEX_OPT_MORE_HELP, VALUE_OPT_MORE_HELP, 383 /* equiv idx value */ NO_EQUIVALENT, 0, 384 /* equivalenced to */ NO_EQUIVALENT, 385 /* min, max, act ct */ 0, 1, 0, 386 /* opt state flags */ OPTST_MORE_HELP_FLAGS, 0, 387 /* last opt argumnt */ { NULL }, 388 /* arg list/cookie */ NULL, 389 /* must/cannot opts */ NULL, NULL, 390 /* option proc */ optionPagedUsage, 391 /* desc, NAME, name */ zMore_HelpText, NULL, zMore_Help_Name, 392 /* disablement strs */ NULL, NULL }, 393 394 { /* entry idx, value */ INDEX_OPT_SAVE_OPTS, VALUE_OPT_SAVE_OPTS, 395 /* equiv idx value */ NO_EQUIVALENT, 0, 396 /* equivalenced to */ NO_EQUIVALENT, 397 /* min, max, act ct */ 0, 1, 0, 398 /* opt state flags */ OPTST_SET_ARGTYPE(OPARG_TYPE_STRING) 399 | OPTST_ARG_OPTIONAL | OPTST_NO_INIT, 0, 400 /* last opt argumnt */ { NULL }, 401 /* arg list/cookie */ NULL, 402 /* must/cannot opts */ NULL, NULL, 403 /* option proc */ NULL, 404 /* desc, NAME, name */ zSave_OptsText, NULL, zSave_Opts_Name, 405 /* disablement strs */ NULL, NULL }, 406 407 { /* entry idx, value */ INDEX_OPT_LOAD_OPTS, VALUE_OPT_LOAD_OPTS, 408 /* equiv idx value */ NO_EQUIVALENT, 0, 409 /* equivalenced to */ NO_EQUIVALENT, 410 /* min, max, act ct */ 0, NOLIMIT, 0, 411 /* opt state flags */ OPTST_SET_ARGTYPE(OPARG_TYPE_STRING) 412 | OPTST_DISABLE_IMM, 0, 413 /* last opt argumnt */ { NULL }, 414 /* arg list/cookie */ NULL, 415 /* must/cannot opts */ NULL, NULL, 416 /* option proc */ optionLoadOpt, 417 /* desc, NAME, name */ zLoad_OptsText, zLoad_Opts_NAME, zLoad_Opts_Name, 418 /* disablement strs */ zNotLoad_Opts_Name, zNotLoad_Opts_Pfx } 419 }; 420 421 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 422 * 423 * Define the Ntpq Option Environment 424 */ 425 static char const zPROGNAME[5] = "NTPQ"; 426 static char const zUsageTitle[119] = 427 "ntpq - standard NTP query program - Ver. 4.2.6p5\n\ 428 USAGE: %s [ -<flag> [<val>] | --<name>[{=| }<val>] ]... [ host ...]\n"; 429 static char const zRcName[7] = ".ntprc"; 430 static char const * const apzHomeList[3] = { 431 "$HOME", 432 ".", 433 NULL }; 434 435 static char const zBugsAddr[34] = "http://bugs.ntp.org, bugs@ntp.org"; 436 #define zExplain NULL 437 static char const zDetail[384] = "\n\ 438 The [= prog-name =] utility program is used to query NTP servers which\n\ 439 implement the standard NTP mode 6 control message formats defined in\n\ 440 Appendix B of the NTPv3 specification RFC1305, requesting information\n\ 441 about current state and/or changes in that state. The same formats are\n\ 442 used in NTPv4, although some of the variables have changed and new ones\n\ 443 added.\n"; 444 static char const zFullVersion[] = NTPQ_FULL_VERSION; 445 /* extracted from optcode.tlib near line 515 */ 446 447 #if defined(ENABLE_NLS) 448 # define OPTPROC_BASE OPTPROC_TRANSLATE 449 static tOptionXlateProc translate_option_strings; 450 #else 451 # define OPTPROC_BASE OPTPROC_NONE 452 # define translate_option_strings NULL 453 #endif /* ENABLE_NLS */ 454 455 456 #define ntpq_full_usage NULL 457 #define ntpq_short_usage NULL 458 #ifndef PKGDATADIR 459 # define PKGDATADIR "" 460 #endif 461 462 #ifndef WITH_PACKAGER 463 # define ntpq_packager_info NULL 464 #else 465 static char const ntpq_packager_info[] = 466 "Packaged by " WITH_PACKAGER 467 468 # ifdef WITH_PACKAGER_VERSION 469 " ("WITH_PACKAGER_VERSION")" 470 # endif 471 472 # ifdef WITH_PACKAGER_BUG_REPORTS 473 "\nReport ntpq bugs to " WITH_PACKAGER_BUG_REPORTS 474 # endif 475 "\n"; 476 #endif 477 478 tOptions ntpqOptions = { 479 OPTIONS_STRUCT_VERSION, 480 0, NULL, /* original argc + argv */ 481 ( OPTPROC_BASE 482 + OPTPROC_ERRSTOP 483 + OPTPROC_SHORTOPT 484 + OPTPROC_LONGOPT 485 + OPTPROC_NO_REQ_OPT 486 + OPTPROC_ENVIRON 487 + OPTPROC_MISUSE ), 488 0, NULL, /* current option index, current option */ 489 NULL, NULL, zPROGNAME, 490 zRcName, zCopyright, zLicenseDescrip, 491 zFullVersion, apzHomeList, zUsageTitle, 492 zExplain, zDetail, optDesc, 493 zBugsAddr, /* address to send bugs to */ 494 NULL, NULL, /* extensions/saved state */ 495 optionUsage, /* usage procedure */ 496 translate_option_strings, /* translation procedure */ 497 /* 498 * Indexes to special options 499 */ 500 { INDEX_OPT_MORE_HELP, /* more-help option index */ 501 INDEX_OPT_SAVE_OPTS, /* save option index */ 502 NO_EQUIVALENT, /* '-#' option index */ 503 NO_EQUIVALENT /* index of default opt */ 504 }, 505 14 /* full option count */, 9 /* user option count */, 506 ntpq_full_usage, ntpq_short_usage, 507 NULL, NULL, 508 PKGDATADIR, ntpq_packager_info 509 }; 510 511 /* 512 * Create the static procedure(s) declared above. 513 */ 514 static void 515 doUsageOpt(tOptions * pOptions, tOptDesc * pOptDesc) 516 { 517 (void)pOptions; 518 USAGE(NTPQ_EXIT_SUCCESS); 519 } 520 521 #if ! defined(TEST_NTPQ_OPTS) 522 523 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 524 * 525 * For the set-debug-level option. 526 */ 527 static void 528 doOptSet_Debug_Level(tOptions* pOptions, tOptDesc* pOptDesc) 529 { 530 /* extracted from debug-opt.def, line 27 */ 531 DESC(DEBUG_LEVEL).optOccCt = atoi( pOptDesc->pzLastArg ); 532 } 533 #endif /* defined(TEST_NTPQ_OPTS) */ 534 /* extracted from optmain.tlib near line 128 */ 535 536 #if defined(TEST_NTPQ_OPTS) /* TEST MAIN PROCEDURE: */ 537 538 extern void optionPutShell(tOptions*); 539 540 int 541 main(int argc, char ** argv) 542 { 543 int res = NTPQ_EXIT_SUCCESS; 544 (void)optionProcess(&ntpqOptions, argc, argv); 545 optionPutShell(&ntpqOptions); 546 res = ferror(stdout); 547 if (res != 0) 548 fputs("output error writing to stdout\n", stderr); 549 return res; 550 } 551 #endif /* defined TEST_NTPQ_OPTS */ 552 /* extracted from optcode.tlib near line 666 */ 553 554 #if ENABLE_NLS 555 #include <stdio.h> 556 #include <stdlib.h> 557 #include <string.h> 558 #include <unistd.h> 559 #include <autoopts/usage-txt.h> 560 561 static char* AO_gettext(char const* pz); 562 static void coerce_it(void** s); 563 564 static char* 565 AO_gettext(char const* pz) 566 { 567 char* pzRes; 568 if (pz == NULL) 569 return NULL; 570 pzRes = _(pz); 571 if (pzRes == pz) 572 return pzRes; 573 pzRes = strdup(pzRes); 574 if (pzRes == NULL) { 575 fputs(_("No memory for duping translated strings\n"), stderr); 576 exit(NTPQ_EXIT_FAILURE); 577 } 578 return pzRes; 579 } 580 581 static void coerce_it(void** s) { *s = AO_gettext(*s); 582 } 583 584 /* 585 * This invokes the translation code (e.g. gettext(3)). 586 */ 587 static void 588 translate_option_strings(void) 589 { 590 tOptions * const pOpt = &ntpqOptions; 591 592 /* 593 * Guard against re-translation. It won't work. The strings will have 594 * been changed by the first pass through this code. One shot only. 595 */ 596 if (option_usage_text.field_ct != 0) { 597 /* 598 * Do the translations. The first pointer follows the field count 599 * field. The field count field is the size of a pointer. 600 */ 601 tOptDesc * pOD = pOpt->pOptDesc; 602 char ** ppz = (char**)(void*)&(option_usage_text); 603 int ix = option_usage_text.field_ct; 604 605 do { 606 ppz++; 607 *ppz = AO_gettext(*ppz); 608 } while (--ix > 0); 609 610 coerce_it((void*)&(pOpt->pzCopyright)); 611 coerce_it((void*)&(pOpt->pzCopyNotice)); 612 coerce_it((void*)&(pOpt->pzFullVersion)); 613 coerce_it((void*)&(pOpt->pzUsageTitle)); 614 coerce_it((void*)&(pOpt->pzExplain)); 615 coerce_it((void*)&(pOpt->pzDetail)); 616 coerce_it((void*)&(pOpt->pzPackager)); 617 option_usage_text.field_ct = 0; 618 619 for (ix = pOpt->optCt; ix > 0; ix--, pOD++) 620 coerce_it((void*)&(pOD->pzText)); 621 } 622 623 if ((pOpt->fOptSet & OPTPROC_NXLAT_OPT_CFG) == 0) { 624 tOptDesc * pOD = pOpt->pOptDesc; 625 int ix; 626 627 for (ix = pOpt->optCt; ix > 0; ix--, pOD++) { 628 coerce_it((void*)&(pOD->pz_Name)); 629 coerce_it((void*)&(pOD->pz_DisableName)); 630 coerce_it((void*)&(pOD->pz_DisablePfx)); 631 } 632 /* prevent re-translation */ 633 ntpqOptions.fOptSet |= OPTPROC_NXLAT_OPT_CFG | OPTPROC_NXLAT_OPT; 634 } 635 } 636 637 #endif /* ENABLE_NLS */ 638 639 #ifdef __cplusplus 640 } 641 #endif 642 /* ntpq-opts.c ends here */ 643