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