Annotation of embedaddon/ntp/ntpq/ntpq-opts.c, revision 1.1.1.1

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

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>