xref: /netbsd-src/external/bsd/ntp/dist/sntp/sntp-opts.c (revision 7788a0781fe6ff2cce37368b4578a7ade0850cb1)
1 /*	$NetBSD: sntp-opts.c,v 1.1.1.2 2012/01/31 21:27:35 kardel Exp $	*/
2 
3 /*
4  *  EDIT THIS FILE WITH CAUTION  (sntp-opts.c)
5  *
6  *  It has been AutoGen-ed  December 24, 2011 at 06:33:53 PM by AutoGen 5.12
7  *  From the definitions    sntp-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 sntp 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 "sntp-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 "sntp 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 #ifndef NULL
51 #  define NULL 0
52 #endif
53 
54 /*
55  *  Ipv4 option description with
56  *  "Must also have options" and "Incompatible options":
57  */
58 static char const zIpv4Text[] =
59         "Force IPv4 DNS name resolution";
60 static char const zIpv4_NAME[]               = "IPV4";
61 static char const zIpv4_Name[]               = "ipv4";
62 static const int
63     aIpv4CantList[] = {
64     INDEX_OPT_IPV6, NO_EQUIVALENT };
65 #define IPV4_FLAGS       (OPTST_DISABLED)
66 
67 /*
68  *  Ipv6 option description with
69  *  "Must also have options" and "Incompatible options":
70  */
71 static char const zIpv6Text[] =
72         "Force IPv6 DNS name resolution";
73 static char const zIpv6_NAME[]               = "IPV6";
74 static char const zIpv6_Name[]               = "ipv6";
75 static const int
76     aIpv6CantList[] = {
77     INDEX_OPT_IPV4, NO_EQUIVALENT };
78 #define IPV6_FLAGS       (OPTST_DISABLED)
79 
80 /*
81  *  Normalverbose option description:
82  */
83 static char const zNormalverboseText[] =
84         "Normal verbose";
85 static char const zNormalverbose_NAME[]      = "NORMALVERBOSE";
86 static char const zNormalverbose_Name[]      = "normalverbose";
87 #define NORMALVERBOSE_FLAGS       (OPTST_DISABLED)
88 
89 /*
90  *  Kod option description:
91  */
92 static char const zKodText[] =
93         "KoD history filename";
94 static char const zKod_NAME[]                = "KOD";
95 static char const zKod_Name[]                = "kod";
96 #define KOD_FLAGS       (OPTST_DISABLED \
97         | OPTST_SET_ARGTYPE(OPARG_TYPE_STRING))
98 
99 /*
100  *  Syslog option description with
101  *  "Must also have options" and "Incompatible options":
102  */
103 static char const zSyslogText[] =
104         "Logging with syslog";
105 static char const zSyslog_NAME[]             = "SYSLOG";
106 static char const zSyslog_Name[]             = "syslog";
107 static const int
108     aSyslogCantList[] = {
109     INDEX_OPT_LOGFILE, NO_EQUIVALENT };
110 #define SYSLOG_FLAGS       (OPTST_DISABLED)
111 
112 /*
113  *  Logfile option description with
114  *  "Must also have options" and "Incompatible options":
115  */
116 static char const zLogfileText[] =
117         "Log to specified logfile";
118 static char const zLogfile_NAME[]            = "LOGFILE";
119 static char const zLogfile_Name[]            = "logfile";
120 static const int
121     aLogfileCantList[] = {
122     INDEX_OPT_SYSLOG, NO_EQUIVALENT };
123 #define LOGFILE_FLAGS       (OPTST_DISABLED \
124         | OPTST_SET_ARGTYPE(OPARG_TYPE_STRING))
125 
126 /*
127  *  Settod option description with
128  *  "Must also have options" and "Incompatible options":
129  */
130 static char const zSettodText[] =
131         "Set (step) the time with settimeofday()";
132 static char const zSettod_NAME[]             = "SETTOD";
133 static char const zSettod_Name[]             = "settod";
134 static const int
135     aSettodCantList[] = {
136     INDEX_OPT_ADJTIME, NO_EQUIVALENT };
137 #define SETTOD_FLAGS       (OPTST_DISABLED)
138 
139 /*
140  *  Adjtime option description with
141  *  "Must also have options" and "Incompatible options":
142  */
143 static char const zAdjtimeText[] =
144         "Set (slew) the time with adjtime()";
145 static char const zAdjtime_NAME[]            = "ADJTIME";
146 static char const zAdjtime_Name[]            = "adjtime";
147 static const int
148     aAdjtimeCantList[] = {
149     INDEX_OPT_SETTOD, NO_EQUIVALENT };
150 #define ADJTIME_FLAGS       (OPTST_DISABLED)
151 
152 /*
153  *  Broadcast option description:
154  */
155 static char const zBroadcastText[] =
156         "Use broadcasts to the address specified for synchronisation";
157 static char const zBroadcast_NAME[]          = "BROADCAST";
158 static char const zBroadcast_Name[]          = "broadcast";
159 #define BROADCAST_FLAGS       (OPTST_DISABLED \
160         | OPTST_SET_ARGTYPE(OPARG_TYPE_STRING))
161 
162 /*
163  *  Timeout option description:
164  */
165 static char const zTimeoutText[] =
166         "Specify the number of seconds to wait for broadcasts";
167 static char const zTimeout_NAME[]            = "TIMEOUT";
168 static char const zTimeout_Name[]            = "timeout";
169 #define zTimeoutDefaultArg           ((char const*)68)
170 #define TIMEOUT_FLAGS       (OPTST_DISABLED \
171         | OPTST_SET_ARGTYPE(OPARG_TYPE_NUMERIC))
172 
173 /*
174  *  Authentication option description:
175  */
176 static char const zAuthenticationText[] =
177         "Enable authentication with the key auth-keynumber";
178 static char const zAuthentication_NAME[]     = "AUTHENTICATION";
179 static char const zAuthentication_Name[]     = "authentication";
180 #define AUTHENTICATION_FLAGS       (OPTST_DISABLED \
181         | OPTST_SET_ARGTYPE(OPARG_TYPE_NUMERIC))
182 
183 /*
184  *  Keyfile option description:
185  */
186 static char const zKeyfileText[] =
187         "Specify a keyfile. SNTP will look in this file for the key specified with -a";
188 static char const zKeyfile_NAME[]            = "KEYFILE";
189 static char const zKeyfile_Name[]            = "keyfile";
190 #define KEYFILE_FLAGS       (OPTST_DISABLED \
191         | OPTST_SET_ARGTYPE(OPARG_TYPE_STRING))
192 
193 /*
194  *  Help/More_Help/Version option descriptions:
195  */
196 static char const zHelpText[]          = "Display extended usage information and exit";
197 static char const zHelp_Name[]         = "help";
198 #ifdef HAVE_WORKING_FORK
199 #define OPTST_MORE_HELP_FLAGS   (OPTST_IMM | OPTST_NO_INIT)
200 static char const zMore_Help_Name[]    = "more-help";
201 static char const zMore_HelpText[]     = "Extended usage information passed thru pager";
202 #else
203 #define OPTST_MORE_HELP_FLAGS   (OPTST_OMITTED | OPTST_NO_INIT)
204 #define zMore_Help_Name   NULL
205 #define zMore_HelpText    NULL
206 #endif
207 #ifdef NO_OPTIONAL_OPT_ARGS
208 #  define OPTST_VERSION_FLAGS   OPTST_IMM | OPTST_NO_INIT
209 #else
210 #  define OPTST_VERSION_FLAGS   OPTST_SET_ARGTYPE(OPARG_TYPE_STRING) | \
211                                 OPTST_ARG_OPTIONAL | OPTST_IMM | OPTST_NO_INIT
212 #endif
213 
214 static char const zVersionText[]       = "Output version information and exit";
215 static char const zVersion_Name[]      = "version";
216 static char const zSave_OptsText[]     = "Save the option state to a config file";
217 static char const zSave_Opts_Name[]    = "save-opts";
218 static char const zLoad_OptsText[]     = "Load options from a config file";
219 static char const zLoad_Opts_NAME[]    = "LOAD_OPTS";
220 static char const zNotLoad_Opts_Name[] = "no-load-opts";
221 static char const zNotLoad_Opts_Pfx[]  = "no";
222 #define zLoad_Opts_Name   (zNotLoad_Opts_Name + 3)
223 /*
224  *  Declare option callback procedures
225  */
226 #if defined(TEST_SNTP_OPTS)
227 /*
228  *  Under test, omit argument processing, or call optionStackArg,
229  *  if multiple copies are allowed.
230  */
231 static tOptProc
232     doUsageOpt;
233 
234 #else /* NOT defined TEST_SNTP_OPTS */
235 /*
236  *  When not under test, there are different procs to use
237  */
238 extern tOptProc
239     optionBooleanVal,    optionNestedVal,     optionNumericVal,
240     optionPagedUsage,    optionPrintVersion,  optionResetOpt,
241     optionStackArg,      optionTimeDate,      optionTimeVal,
242     optionUnstackArg,    optionVersionStderr;
243 static tOptProc
244     doUsageOpt;
245 #endif /* defined(TEST_SNTP_OPTS) */
246 #ifdef TEST_SNTP_OPTS
247 # define DOVERPROC optionVersionStderr
248 #else
249 # define DOVERPROC optionPrintVersion
250 #endif /* TEST_SNTP_OPTS */
251 
252 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
253  *
254  *  Define the Sntp Option Descriptions.
255  */
256 static tOptDesc optDesc[OPTION_CT] = {
257   {  /* entry idx, value */ 0, VALUE_OPT_IPV4,
258      /* equiv idx, value */ 0, VALUE_OPT_IPV4,
259      /* equivalenced to  */ NO_EQUIVALENT,
260      /* min, max, act ct */ 0, 1, 0,
261      /* opt state flags  */ IPV4_FLAGS, 0,
262      /* last opt argumnt */ { NULL },
263      /* arg list/cookie  */ NULL,
264      /* must/cannot opts */ NULL, aIpv4CantList,
265      /* option proc      */ NULL,
266      /* desc, NAME, name */ zIpv4Text, zIpv4_NAME, zIpv4_Name,
267      /* disablement strs */ NULL, NULL },
268 
269   {  /* entry idx, value */ 1, VALUE_OPT_IPV6,
270      /* equiv idx, value */ 1, VALUE_OPT_IPV6,
271      /* equivalenced to  */ NO_EQUIVALENT,
272      /* min, max, act ct */ 0, 1, 0,
273      /* opt state flags  */ IPV6_FLAGS, 0,
274      /* last opt argumnt */ { NULL },
275      /* arg list/cookie  */ NULL,
276      /* must/cannot opts */ NULL, aIpv6CantList,
277      /* option proc      */ NULL,
278      /* desc, NAME, name */ zIpv6Text, zIpv6_NAME, zIpv6_Name,
279      /* disablement strs */ NULL, NULL },
280 
281   {  /* entry idx, value */ 2, VALUE_OPT_NORMALVERBOSE,
282      /* equiv idx, value */ 2, VALUE_OPT_NORMALVERBOSE,
283      /* equivalenced to  */ NO_EQUIVALENT,
284      /* min, max, act ct */ 0, 1, 0,
285      /* opt state flags  */ NORMALVERBOSE_FLAGS, 0,
286      /* last opt argumnt */ { NULL },
287      /* arg list/cookie  */ NULL,
288      /* must/cannot opts */ NULL, NULL,
289      /* option proc      */ NULL,
290      /* desc, NAME, name */ zNormalverboseText, zNormalverbose_NAME, zNormalverbose_Name,
291      /* disablement strs */ NULL, NULL },
292 
293   {  /* entry idx, value */ 3, VALUE_OPT_KOD,
294      /* equiv idx, value */ 3, VALUE_OPT_KOD,
295      /* equivalenced to  */ NO_EQUIVALENT,
296      /* min, max, act ct */ 0, 1, 0,
297      /* opt state flags  */ KOD_FLAGS, 0,
298      /* last opt argumnt */ { NULL },
299      /* arg list/cookie  */ NULL,
300      /* must/cannot opts */ NULL, NULL,
301      /* option proc      */ NULL,
302      /* desc, NAME, name */ zKodText, zKod_NAME, zKod_Name,
303      /* disablement strs */ NULL, NULL },
304 
305   {  /* entry idx, value */ 4, VALUE_OPT_SYSLOG,
306      /* equiv idx, value */ 4, VALUE_OPT_SYSLOG,
307      /* equivalenced to  */ NO_EQUIVALENT,
308      /* min, max, act ct */ 0, 1, 0,
309      /* opt state flags  */ SYSLOG_FLAGS, 0,
310      /* last opt argumnt */ { NULL },
311      /* arg list/cookie  */ NULL,
312      /* must/cannot opts */ NULL, aSyslogCantList,
313      /* option proc      */ NULL,
314      /* desc, NAME, name */ zSyslogText, zSyslog_NAME, zSyslog_Name,
315      /* disablement strs */ NULL, NULL },
316 
317   {  /* entry idx, value */ 5, VALUE_OPT_LOGFILE,
318      /* equiv idx, value */ 5, VALUE_OPT_LOGFILE,
319      /* equivalenced to  */ NO_EQUIVALENT,
320      /* min, max, act ct */ 0, 1, 0,
321      /* opt state flags  */ LOGFILE_FLAGS, 0,
322      /* last opt argumnt */ { NULL },
323      /* arg list/cookie  */ NULL,
324      /* must/cannot opts */ NULL, aLogfileCantList,
325      /* option proc      */ NULL,
326      /* desc, NAME, name */ zLogfileText, zLogfile_NAME, zLogfile_Name,
327      /* disablement strs */ NULL, NULL },
328 
329   {  /* entry idx, value */ 6, VALUE_OPT_SETTOD,
330      /* equiv idx, value */ 6, VALUE_OPT_SETTOD,
331      /* equivalenced to  */ NO_EQUIVALENT,
332      /* min, max, act ct */ 0, 1, 0,
333      /* opt state flags  */ SETTOD_FLAGS, 0,
334      /* last opt argumnt */ { NULL },
335      /* arg list/cookie  */ NULL,
336      /* must/cannot opts */ NULL, aSettodCantList,
337      /* option proc      */ NULL,
338      /* desc, NAME, name */ zSettodText, zSettod_NAME, zSettod_Name,
339      /* disablement strs */ NULL, NULL },
340 
341   {  /* entry idx, value */ 7, VALUE_OPT_ADJTIME,
342      /* equiv idx, value */ 7, VALUE_OPT_ADJTIME,
343      /* equivalenced to  */ NO_EQUIVALENT,
344      /* min, max, act ct */ 0, 1, 0,
345      /* opt state flags  */ ADJTIME_FLAGS, 0,
346      /* last opt argumnt */ { NULL },
347      /* arg list/cookie  */ NULL,
348      /* must/cannot opts */ NULL, aAdjtimeCantList,
349      /* option proc      */ NULL,
350      /* desc, NAME, name */ zAdjtimeText, zAdjtime_NAME, zAdjtime_Name,
351      /* disablement strs */ NULL, NULL },
352 
353   {  /* entry idx, value */ 8, VALUE_OPT_BROADCAST,
354      /* equiv idx, value */ 8, VALUE_OPT_BROADCAST,
355      /* equivalenced to  */ NO_EQUIVALENT,
356      /* min, max, act ct */ 0, 1, 0,
357      /* opt state flags  */ BROADCAST_FLAGS, 0,
358      /* last opt argumnt */ { NULL },
359      /* arg list/cookie  */ NULL,
360      /* must/cannot opts */ NULL, NULL,
361      /* option proc      */ NULL,
362      /* desc, NAME, name */ zBroadcastText, zBroadcast_NAME, zBroadcast_Name,
363      /* disablement strs */ NULL, NULL },
364 
365   {  /* entry idx, value */ 9, VALUE_OPT_TIMEOUT,
366      /* equiv idx, value */ 9, VALUE_OPT_TIMEOUT,
367      /* equivalenced to  */ NO_EQUIVALENT,
368      /* min, max, act ct */ 0, 1, 0,
369      /* opt state flags  */ TIMEOUT_FLAGS, 0,
370      /* last opt argumnt */ { zTimeoutDefaultArg },
371      /* arg list/cookie  */ NULL,
372      /* must/cannot opts */ NULL, NULL,
373      /* option proc      */ optionNumericVal,
374      /* desc, NAME, name */ zTimeoutText, zTimeout_NAME, zTimeout_Name,
375      /* disablement strs */ NULL, NULL },
376 
377   {  /* entry idx, value */ 10, VALUE_OPT_AUTHENTICATION,
378      /* equiv idx, value */ 10, VALUE_OPT_AUTHENTICATION,
379      /* equivalenced to  */ NO_EQUIVALENT,
380      /* min, max, act ct */ 0, 1, 0,
381      /* opt state flags  */ AUTHENTICATION_FLAGS, 0,
382      /* last opt argumnt */ { NULL },
383      /* arg list/cookie  */ NULL,
384      /* must/cannot opts */ NULL, NULL,
385      /* option proc      */ optionNumericVal,
386      /* desc, NAME, name */ zAuthenticationText, zAuthentication_NAME, zAuthentication_Name,
387      /* disablement strs */ NULL, NULL },
388 
389   {  /* entry idx, value */ 11, VALUE_OPT_KEYFILE,
390      /* equiv idx, value */ 11, VALUE_OPT_KEYFILE,
391      /* equivalenced to  */ NO_EQUIVALENT,
392      /* min, max, act ct */ 0, 1, 0,
393      /* opt state flags  */ KEYFILE_FLAGS, 0,
394      /* last opt argumnt */ { NULL },
395      /* arg list/cookie  */ NULL,
396      /* must/cannot opts */ NULL, NULL,
397      /* option proc      */ NULL,
398      /* desc, NAME, name */ zKeyfileText, zKeyfile_NAME, zKeyfile_Name,
399      /* disablement strs */ NULL, NULL },
400 
401   {  /* entry idx, value */ INDEX_OPT_VERSION, VALUE_OPT_VERSION,
402      /* equiv idx value  */ NO_EQUIVALENT, 0,
403      /* equivalenced to  */ NO_EQUIVALENT,
404      /* min, max, act ct */ 0, 1, 0,
405      /* opt state flags  */ OPTST_VERSION_FLAGS, 0,
406      /* last opt argumnt */ { NULL },
407      /* arg list/cookie  */ NULL,
408      /* must/cannot opts */ NULL, NULL,
409      /* option proc      */ DOVERPROC,
410      /* desc, NAME, name */ zVersionText, NULL, zVersion_Name,
411      /* disablement strs */ NULL, NULL },
412 
413 
414 
415   {  /* entry idx, value */ INDEX_OPT_HELP, VALUE_OPT_HELP,
416      /* equiv idx value  */ NO_EQUIVALENT, 0,
417      /* equivalenced to  */ NO_EQUIVALENT,
418      /* min, max, act ct */ 0, 1, 0,
419      /* opt state flags  */ OPTST_IMM | OPTST_NO_INIT, 0,
420      /* last opt argumnt */ { NULL },
421      /* arg list/cookie  */ NULL,
422      /* must/cannot opts */ NULL, NULL,
423      /* option proc      */ doUsageOpt,
424      /* desc, NAME, name */ zHelpText, NULL, zHelp_Name,
425      /* disablement strs */ NULL, NULL },
426 
427   {  /* entry idx, value */ INDEX_OPT_MORE_HELP, VALUE_OPT_MORE_HELP,
428      /* equiv idx value  */ NO_EQUIVALENT, 0,
429      /* equivalenced to  */ NO_EQUIVALENT,
430      /* min, max, act ct */ 0, 1, 0,
431      /* opt state flags  */ OPTST_MORE_HELP_FLAGS, 0,
432      /* last opt argumnt */ { NULL },
433      /* arg list/cookie  */ NULL,
434      /* must/cannot opts */ NULL,  NULL,
435      /* option proc      */ optionPagedUsage,
436      /* desc, NAME, name */ zMore_HelpText, NULL, zMore_Help_Name,
437      /* disablement strs */ NULL, NULL },
438 
439   {  /* entry idx, value */ INDEX_OPT_SAVE_OPTS, VALUE_OPT_SAVE_OPTS,
440      /* equiv idx value  */ NO_EQUIVALENT, 0,
441      /* equivalenced to  */ NO_EQUIVALENT,
442      /* min, max, act ct */ 0, 1, 0,
443      /* opt state flags  */ OPTST_SET_ARGTYPE(OPARG_TYPE_STRING)
444                           | OPTST_ARG_OPTIONAL | OPTST_NO_INIT, 0,
445      /* last opt argumnt */ { NULL },
446      /* arg list/cookie  */ NULL,
447      /* must/cannot opts */ NULL,  NULL,
448      /* option proc      */ NULL,
449      /* desc, NAME, name */ zSave_OptsText, NULL, zSave_Opts_Name,
450      /* disablement strs */ NULL, NULL },
451 
452   {  /* entry idx, value */ INDEX_OPT_LOAD_OPTS, VALUE_OPT_LOAD_OPTS,
453      /* equiv idx value  */ NO_EQUIVALENT, 0,
454      /* equivalenced to  */ NO_EQUIVALENT,
455      /* min, max, act ct */ 0, NOLIMIT, 0,
456      /* opt state flags  */ OPTST_SET_ARGTYPE(OPARG_TYPE_STRING)
457 			  | OPTST_DISABLE_IMM, 0,
458      /* last opt argumnt */ { NULL },
459      /* arg list/cookie  */ NULL,
460      /* must/cannot opts */ NULL, NULL,
461      /* option proc      */ optionLoadOpt,
462      /* desc, NAME, name */ zLoad_OptsText, zLoad_Opts_NAME, zLoad_Opts_Name,
463      /* disablement strs */ zNotLoad_Opts_Name, zNotLoad_Opts_Pfx }
464 };
465 
466 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
467  *
468  *  Define the Sntp Option Environment
469  */
470 static char const zPROGNAME[5] = "SNTP";
471 static char const zUsageTitle[152] =
472 "sntp - standard Simple Network Time Protocol program - Ver. 4.2.6p5\n\
473 USAGE:  %s [ -<flag> [<val>] | --<name>[{=| }<val>] ]... \\\n\
474 \t\t[ hostname-or-IP ...]\n";
475 static char const zRcName[7] = ".ntprc";
476 static char const * const apzHomeList[3] = {
477     "$HOME",
478     ".",
479     NULL };
480 
481 static char const zBugsAddr[34]    = "http://bugs.ntp.org, bugs@ntp.org";
482 static char const zExplain[] = "\n\n";
483 static char const zDetail[352] = "\n\
484 sntp implements the Simple Network Time Protocol, and is used to query an\n\
485 NTP or SNTP server and either display the time or set the local system's\n\
486 time (given suitable privilege).\n\n\
487 It can be run interactively from the command line or as a cron job.\n\n\
488 NTP and SNTP are defined by RFC 5905, which obsoletes RFC 4330 and RFC\n\
489 1305.\n";
490 static char const zFullVersion[] = SNTP_FULL_VERSION;
491 /* extracted from optcode.tlib near line 515 */
492 
493 #if defined(ENABLE_NLS)
494 # define OPTPROC_BASE OPTPROC_TRANSLATE
495   static tOptionXlateProc translate_option_strings;
496 #else
497 # define OPTPROC_BASE OPTPROC_NONE
498 # define translate_option_strings NULL
499 #endif /* ENABLE_NLS */
500 
501 
502 #define sntp_full_usage NULL
503 #define sntp_short_usage NULL
504 #ifndef  PKGDATADIR
505 # define PKGDATADIR ""
506 #endif
507 
508 #ifndef  WITH_PACKAGER
509 # define sntp_packager_info NULL
510 #else
511 static char const sntp_packager_info[] =
512     "Packaged by " WITH_PACKAGER
513 
514 # ifdef WITH_PACKAGER_VERSION
515         " ("WITH_PACKAGER_VERSION")"
516 # endif
517 
518 # ifdef WITH_PACKAGER_BUG_REPORTS
519     "\nReport sntp bugs to " WITH_PACKAGER_BUG_REPORTS
520 # endif
521     "\n";
522 #endif
523 
524 tOptions sntpOptions = {
525     OPTIONS_STRUCT_VERSION,
526     0, NULL,                    /* original argc + argv    */
527     ( OPTPROC_BASE
528     + OPTPROC_ERRSTOP
529     + OPTPROC_SHORTOPT
530     + OPTPROC_LONGOPT
531     + OPTPROC_NO_REQ_OPT
532     + OPTPROC_ENVIRON
533     + OPTPROC_MISUSE ),
534     0, NULL,                    /* current option index, current option */
535     NULL,         NULL,         zPROGNAME,
536     zRcName,      zCopyright,   zLicenseDescrip,
537     zFullVersion, apzHomeList,  zUsageTitle,
538     zExplain,     zDetail,      optDesc,
539     zBugsAddr,                  /* address to send bugs to */
540     NULL, NULL,                 /* extensions/saved state  */
541     optionUsage, /* usage procedure */
542     translate_option_strings,   /* translation procedure */
543     /*
544      *  Indexes to special options
545      */
546     { INDEX_OPT_MORE_HELP, /* more-help option index */
547       INDEX_OPT_SAVE_OPTS, /* save option index */
548       NO_EQUIVALENT, /* '-#' option index */
549       NO_EQUIVALENT /* index of default opt */
550     },
551     17 /* full option count */, 12 /* user option count */,
552     sntp_full_usage, sntp_short_usage,
553     NULL, NULL,
554     PKGDATADIR, sntp_packager_info
555 };
556 
557 /*
558  *  Create the static procedure(s) declared above.
559  */
560 static void
561 doUsageOpt(tOptions * pOptions, tOptDesc * pOptDesc)
562 {
563     (void)pOptions;
564     USAGE(SNTP_EXIT_SUCCESS);
565 }
566 /* extracted from optmain.tlib near line 128 */
567 
568 #if defined(TEST_SNTP_OPTS) /* TEST MAIN PROCEDURE: */
569 
570 extern void optionPutShell(tOptions*);
571 
572 int
573 main(int argc, char ** argv)
574 {
575     int res = SNTP_EXIT_SUCCESS;
576     (void)optionProcess(&sntpOptions, argc, argv);
577     optionPutShell(&sntpOptions);
578     res = ferror(stdout);
579     if (res != 0)
580         fputs("output error writing to stdout\n", stderr);
581     return res;
582 }
583 #endif  /* defined TEST_SNTP_OPTS */
584 /* extracted from optcode.tlib near line 666 */
585 
586 #if ENABLE_NLS
587 #include <stdio.h>
588 #include <stdlib.h>
589 #include <string.h>
590 #include <unistd.h>
591 #include <autoopts/usage-txt.h>
592 
593 static char* AO_gettext(char const* pz);
594 static void  coerce_it(void** s);
595 
596 static char*
597 AO_gettext(char const* pz)
598 {
599     char* pzRes;
600     if (pz == NULL)
601         return NULL;
602     pzRes = _(pz);
603     if (pzRes == pz)
604         return pzRes;
605     pzRes = strdup(pzRes);
606     if (pzRes == NULL) {
607         fputs(_("No memory for duping translated strings\n"), stderr);
608         exit(SNTP_EXIT_FAILURE);
609     }
610     return pzRes;
611 }
612 
613 static void coerce_it(void** s) { *s = AO_gettext(*s);
614 }
615 
616 /*
617  *  This invokes the translation code (e.g. gettext(3)).
618  */
619 static void
620 translate_option_strings(void)
621 {
622     tOptions * const pOpt = &sntpOptions;
623 
624     /*
625      *  Guard against re-translation.  It won't work.  The strings will have
626      *  been changed by the first pass through this code.  One shot only.
627      */
628     if (option_usage_text.field_ct != 0) {
629         /*
630          *  Do the translations.  The first pointer follows the field count
631          *  field.  The field count field is the size of a pointer.
632          */
633         tOptDesc * pOD = pOpt->pOptDesc;
634         char **    ppz = (char**)(void*)&(option_usage_text);
635         int        ix  = option_usage_text.field_ct;
636 
637         do {
638             ppz++;
639             *ppz = AO_gettext(*ppz);
640         } while (--ix > 0);
641 
642         coerce_it((void*)&(pOpt->pzCopyright));
643         coerce_it((void*)&(pOpt->pzCopyNotice));
644         coerce_it((void*)&(pOpt->pzFullVersion));
645         coerce_it((void*)&(pOpt->pzUsageTitle));
646         coerce_it((void*)&(pOpt->pzExplain));
647         coerce_it((void*)&(pOpt->pzDetail));
648         coerce_it((void*)&(pOpt->pzPackager));
649         option_usage_text.field_ct = 0;
650 
651         for (ix = pOpt->optCt; ix > 0; ix--, pOD++)
652             coerce_it((void*)&(pOD->pzText));
653     }
654 
655     if ((pOpt->fOptSet & OPTPROC_NXLAT_OPT_CFG) == 0) {
656         tOptDesc * pOD = pOpt->pOptDesc;
657         int        ix;
658 
659         for (ix = pOpt->optCt; ix > 0; ix--, pOD++) {
660             coerce_it((void*)&(pOD->pz_Name));
661             coerce_it((void*)&(pOD->pz_DisableName));
662             coerce_it((void*)&(pOD->pz_DisablePfx));
663         }
664         /* prevent re-translation */
665         sntpOptions.fOptSet |= OPTPROC_NXLAT_OPT_CFG | OPTPROC_NXLAT_OPT;
666     }
667 }
668 
669 #endif /* ENABLE_NLS */
670 
671 #ifdef  __cplusplus
672 }
673 #endif
674 /* sntp-opts.c ends here */
675