xref: /netbsd-src/external/bsd/ntp/dist/sntp/sntp-opts.h (revision bdc22b2e01993381dcefeff2bc9b56ca75a4235c)
1 /*	$NetBSD: sntp-opts.h,v 1.11 2018/04/07 00:19:53 christos Exp $	*/
2 
3 /*
4  *  EDIT THIS FILE WITH CAUTION  (sntp-opts.h)
5  *
6  *  It has been AutoGen-ed  February 27, 2018 at 10:25:31 AM by AutoGen 5.18.5
7  *  From the definitions    sntp-opts.def
8  *  and the template file   options
9  *
10  * Generated from AutoOpts 41:0:16 templates.
11  *
12  *  AutoOpts is a copyrighted work.  This header 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  * The sntp program is copyrighted and licensed
21  * under the following terms:
22  *
23  *  Copyright (C) 1992-2017 The University of Delaware and Network Time Foundation, all rights reserved.
24  *  This is free software. It is licensed for use, modification and
25  *  redistribution under the terms of the NTP License, copies of which
26  *  can be seen at:
27  *    <http://ntp.org/license>
28  *    <http://opensource.org/licenses/ntp-license.php>
29  *
30  *  Permission to use, copy, modify, and distribute this software and its
31  *  documentation for any purpose with or without fee is hereby granted,
32  *  provided that the above copyright notice appears in all copies and that
33  *  both the copyright notice and this permission notice appear in
34  *  supporting documentation, and that the name The University of Delaware not be used in
35  *  advertising or publicity pertaining to distribution of the software
36  *  without specific, written prior permission. The University of Delaware and Network Time Foundation makes no
37  *  representations about the suitability this software for any purpose. It
38  *  is provided "as is" without express or implied warranty.
39  */
40 /**
41  *  This file contains the programmatic interface to the Automated
42  *  Options generated for the sntp program.
43  *  These macros are documented in the AutoGen info file in the
44  *  "AutoOpts" chapter.  Please refer to that doc for usage help.
45  */
46 #ifndef AUTOOPTS_SNTP_OPTS_H_GUARD
47 #define AUTOOPTS_SNTP_OPTS_H_GUARD 1
48 #include "config.h"
49 #include <autoopts/options.h>
50 
51 /**
52  *  Ensure that the library used for compiling this generated header is at
53  *  least as new as the version current when the header template was released
54  *  (not counting patch version increments).  Also ensure that the oldest
55  *  tolerable version is at least as old as what was current when the header
56  *  template was released.
57  */
58 #define AO_TEMPLATE_VERSION 167936
59 #if (AO_TEMPLATE_VERSION < OPTIONS_MINIMUM_VERSION) \
60  || (AO_TEMPLATE_VERSION > OPTIONS_STRUCT_VERSION)
61 # error option template version mismatches autoopts/options.h header
62   Choke Me.
63 #endif
64 
65 /**
66  *  Enumeration of each option type for sntp
67  */
68 typedef enum {
69     INDEX_OPT_IPV4             =  0,
70     INDEX_OPT_IPV6             =  1,
71     INDEX_OPT_AUTHENTICATION   =  2,
72     INDEX_OPT_BROADCAST        =  3,
73     INDEX_OPT_CONCURRENT       =  4,
74     INDEX_OPT_DEBUG_LEVEL      =  5,
75     INDEX_OPT_SET_DEBUG_LEVEL  =  6,
76     INDEX_OPT_GAP              =  7,
77     INDEX_OPT_KOD              =  8,
78     INDEX_OPT_KEYFILE          =  9,
79     INDEX_OPT_LOGFILE          = 10,
80     INDEX_OPT_STEPLIMIT        = 11,
81     INDEX_OPT_NTPVERSION       = 12,
82     INDEX_OPT_USERESERVEDPORT  = 13,
83     INDEX_OPT_STEP             = 14,
84     INDEX_OPT_SLEW             = 15,
85     INDEX_OPT_TIMEOUT          = 16,
86     INDEX_OPT_WAIT             = 17,
87     INDEX_OPT_VERSION          = 18,
88     INDEX_OPT_HELP             = 19,
89     INDEX_OPT_MORE_HELP        = 20,
90     INDEX_OPT_SAVE_OPTS        = 21,
91     INDEX_OPT_LOAD_OPTS        = 22
92 } teOptIndex;
93 /** count of all options for sntp */
94 #define OPTION_CT    23
95 /** sntp version */
96 #define SNTP_VERSION       "4.2.8p11"
97 /** Full sntp version text */
98 #define SNTP_FULL_VERSION  "sntp 4.2.8p11"
99 
100 /**
101  *  Interface defines for all options.  Replace "n" with the UPPER_CASED
102  *  option name (as in the teOptIndex enumeration above).
103  *  e.g. HAVE_OPT(IPV4)
104  */
105 #define         DESC(n) (sntpOptions.pOptDesc[INDEX_OPT_## n])
106 /** 'true' if an option has been specified in any way */
107 #define     HAVE_OPT(n) (! UNUSED_OPT(& DESC(n)))
108 /** The string argument to an option. The argument type must be \"string\". */
109 #define      OPT_ARG(n) (DESC(n).optArg.argString)
110 /** Mask the option state revealing how an option was specified.
111  *  It will be one and only one of \a OPTST_SET, \a OPTST_PRESET,
112  * \a OPTST_DEFINED, \a OPTST_RESET or zero.
113  */
114 #define    STATE_OPT(n) (DESC(n).fOptState & OPTST_SET_MASK)
115 /** Count of option's occurrances *on the command line*. */
116 #define    COUNT_OPT(n) (DESC(n).optOccCt)
117 /** mask of \a OPTST_SET and \a OPTST_DEFINED. */
118 #define    ISSEL_OPT(n) (SELECTED_OPT(&DESC(n)))
119 /** 'true' if \a HAVE_OPT would yield 'false'. */
120 #define ISUNUSED_OPT(n) (UNUSED_OPT(& DESC(n)))
121 /** 'true' if OPTST_DISABLED bit not set. */
122 #define  ENABLED_OPT(n) (! DISABLED_OPT(& DESC(n)))
123 /** number of stacked option arguments.
124  *  Valid only for stacked option arguments. */
125 #define  STACKCT_OPT(n) (((tArgList*)(DESC(n).optCookie))->useCt)
126 /** stacked argument vector.
127  *  Valid only for stacked option arguments. */
128 #define STACKLST_OPT(n) (((tArgList*)(DESC(n).optCookie))->apzArgs)
129 /** Reset an option. */
130 #define    CLEAR_OPT(n) STMTS( \
131                 DESC(n).fOptState &= OPTST_PERSISTENT_MASK;   \
132                 if ((DESC(n).fOptState & OPTST_INITENABLED) == 0) \
133                     DESC(n).fOptState |= OPTST_DISABLED; \
134                 DESC(n).optCookie = NULL )
135 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
136 /**
137  *  Enumeration of sntp exit codes
138  */
139 typedef enum {
140     SNTP_EXIT_SUCCESS         = 0,
141     SNTP_EXIT_FAILURE         = 1,
142     SNTP_EXIT_USAGE_ERROR     = 64,
143     SNTP_EXIT_NO_CONFIG_INPUT = 66,
144     SNTP_EXIT_LIBOPTS_FAILURE = 70
145 }   sntp_exit_code_t;
146 /** @} */
147 /**
148  *  Make sure there are no #define name conflicts with the option names
149  */
150 #ifndef     NO_OPTION_NAME_WARNINGS
151 # ifdef    IPV4
152 #  warning undefining IPV4 due to option name conflict
153 #  undef   IPV4
154 # endif
155 # ifdef    IPV6
156 #  warning undefining IPV6 due to option name conflict
157 #  undef   IPV6
158 # endif
159 # ifdef    AUTHENTICATION
160 #  warning undefining AUTHENTICATION due to option name conflict
161 #  undef   AUTHENTICATION
162 # endif
163 # ifdef    BROADCAST
164 #  warning undefining BROADCAST due to option name conflict
165 #  undef   BROADCAST
166 # endif
167 # ifdef    CONCURRENT
168 #  warning undefining CONCURRENT due to option name conflict
169 #  undef   CONCURRENT
170 # endif
171 # ifdef    DEBUG_LEVEL
172 #  warning undefining DEBUG_LEVEL due to option name conflict
173 #  undef   DEBUG_LEVEL
174 # endif
175 # ifdef    SET_DEBUG_LEVEL
176 #  warning undefining SET_DEBUG_LEVEL due to option name conflict
177 #  undef   SET_DEBUG_LEVEL
178 # endif
179 # ifdef    GAP
180 #  warning undefining GAP due to option name conflict
181 #  undef   GAP
182 # endif
183 # ifdef    KOD
184 #  warning undefining KOD due to option name conflict
185 #  undef   KOD
186 # endif
187 # ifdef    KEYFILE
188 #  warning undefining KEYFILE due to option name conflict
189 #  undef   KEYFILE
190 # endif
191 # ifdef    LOGFILE
192 #  warning undefining LOGFILE due to option name conflict
193 #  undef   LOGFILE
194 # endif
195 # ifdef    STEPLIMIT
196 #  warning undefining STEPLIMIT due to option name conflict
197 #  undef   STEPLIMIT
198 # endif
199 # ifdef    NTPVERSION
200 #  warning undefining NTPVERSION due to option name conflict
201 #  undef   NTPVERSION
202 # endif
203 # ifdef    USERESERVEDPORT
204 #  warning undefining USERESERVEDPORT due to option name conflict
205 #  undef   USERESERVEDPORT
206 # endif
207 # ifdef    STEP
208 #  warning undefining STEP due to option name conflict
209 #  undef   STEP
210 # endif
211 # ifdef    SLEW
212 #  warning undefining SLEW due to option name conflict
213 #  undef   SLEW
214 # endif
215 # ifdef    TIMEOUT
216 #  warning undefining TIMEOUT due to option name conflict
217 #  undef   TIMEOUT
218 # endif
219 # ifdef    WAIT
220 #  warning undefining WAIT due to option name conflict
221 #  undef   WAIT
222 # endif
223 #else  /* NO_OPTION_NAME_WARNINGS */
224 # undef IPV4
225 # undef IPV6
226 # undef AUTHENTICATION
227 # undef BROADCAST
228 # undef CONCURRENT
229 # undef DEBUG_LEVEL
230 # undef SET_DEBUG_LEVEL
231 # undef GAP
232 # undef KOD
233 # undef KEYFILE
234 # undef LOGFILE
235 # undef STEPLIMIT
236 # undef NTPVERSION
237 # undef USERESERVEDPORT
238 # undef STEP
239 # undef SLEW
240 # undef TIMEOUT
241 # undef WAIT
242 #endif  /*  NO_OPTION_NAME_WARNINGS */
243 
244 /**
245  *  Interface defines for specific options.
246  * @{
247  */
248 #define VALUE_OPT_IPV4           '4'
249 #define VALUE_OPT_IPV6           '6'
250 #define VALUE_OPT_AUTHENTICATION 'a'
251 
252 #define OPT_VALUE_AUTHENTICATION (DESC(AUTHENTICATION).optArg.argInt)
253 #define VALUE_OPT_BROADCAST      'b'
254 #define VALUE_OPT_CONCURRENT     'c'
255 #define VALUE_OPT_DEBUG_LEVEL    'd'
256 #define VALUE_OPT_SET_DEBUG_LEVEL 'D'
257 
258 #define OPT_VALUE_SET_DEBUG_LEVEL (DESC(SET_DEBUG_LEVEL).optArg.argInt)
259 #define VALUE_OPT_GAP            'g'
260 
261 #define OPT_VALUE_GAP            (DESC(GAP).optArg.argInt)
262 #define VALUE_OPT_KOD            'K'
263 #define VALUE_OPT_KEYFILE        'k'
264 #define VALUE_OPT_LOGFILE        'l'
265 #define VALUE_OPT_STEPLIMIT      'M'
266 
267 #define OPT_VALUE_STEPLIMIT      (DESC(STEPLIMIT).optArg.argInt)
268 #define VALUE_OPT_NTPVERSION     'o'
269 
270 #define OPT_VALUE_NTPVERSION     (DESC(NTPVERSION).optArg.argInt)
271 #define VALUE_OPT_USERESERVEDPORT 'r'
272 #define VALUE_OPT_STEP           'S'
273 #define VALUE_OPT_SLEW           's'
274 #define VALUE_OPT_TIMEOUT        't'
275 
276 #define OPT_VALUE_TIMEOUT        (DESC(TIMEOUT).optArg.argInt)
277 #define VALUE_OPT_WAIT           0x1001
278 
279 #define SET_OPT_WAIT   STMTS( \
280         DESC(WAIT).optActualIndex = 17; \
281         DESC(WAIT).optActualValue = VALUE_OPT_WAIT; \
282         DESC(WAIT).fOptState &= OPTST_PERSISTENT_MASK; \
283         DESC(WAIT).fOptState |= OPTST_SET )
284 #define DISABLE_OPT_WAIT   STMTS( \
285         DESC(WAIT).fOptState &= OPTST_PERSISTENT_MASK; \
286         DESC(WAIT).fOptState |= OPTST_SET | OPTST_DISABLED; \
287         DESC(WAIT).optArg.argString = NULL )
288 /** option flag (value) for help-value option */
289 #define VALUE_OPT_HELP          '?'
290 /** option flag (value) for more-help-value option */
291 #define VALUE_OPT_MORE_HELP     '!'
292 /** option flag (value) for version-value option */
293 #define VALUE_OPT_VERSION       0x1002
294 /** option flag (value) for save-opts-value option */
295 #define VALUE_OPT_SAVE_OPTS     '>'
296 /** option flag (value) for load-opts-value option */
297 #define VALUE_OPT_LOAD_OPTS     '<'
298 #define SET_OPT_SAVE_OPTS(a)   STMTS( \
299         DESC(SAVE_OPTS).fOptState &= OPTST_PERSISTENT_MASK; \
300         DESC(SAVE_OPTS).fOptState |= OPTST_SET; \
301         DESC(SAVE_OPTS).optArg.argString = (char const*)(a))
302 /*
303  *  Interface defines not associated with particular options
304  */
305 #define ERRSKIP_OPTERR  STMTS(sntpOptions.fOptSet &= ~OPTPROC_ERRSTOP)
306 #define ERRSTOP_OPTERR  STMTS(sntpOptions.fOptSet |= OPTPROC_ERRSTOP)
307 #define RESTART_OPT(n)  STMTS( \
308                 sntpOptions.curOptIdx = (n); \
309                 sntpOptions.pzCurOpt  = NULL )
310 #define START_OPT       RESTART_OPT(1)
311 #define USAGE(c)        (*sntpOptions.pUsageProc)(&sntpOptions, c)
312 
313 #ifdef  __cplusplus
314 extern "C" {
315 #endif
316 
317 
318 /* * * * * *
319  *
320  *  Declare the sntp option descriptor.
321  */
322 extern tOptions sntpOptions;
323 
324 #if defined(ENABLE_NLS)
325 # ifndef _
326 #   include <stdio.h>
327 #   ifndef HAVE_GETTEXT
328       extern char * gettext(char const *);
329 #   else
330 #     include <libintl.h>
331 #   endif
332 
333 # ifndef ATTRIBUTE_FORMAT_ARG
334 #   define ATTRIBUTE_FORMAT_ARG(_a)
335 # endif
336 
337 static inline char* aoGetsText(char const* pz) ATTRIBUTE_FORMAT_ARG(1);
338 static inline char* aoGetsText(char const* pz) {
339     if (pz == NULL) return NULL;
340     return (char*)gettext(pz);
341 }
342 #   define _(s)  aoGetsText(s)
343 # endif /* _() */
344 
345 # define OPT_NO_XLAT_CFG_NAMES  STMTS(sntpOptions.fOptSet |= \
346                                     OPTPROC_NXLAT_OPT_CFG;)
347 # define OPT_NO_XLAT_OPT_NAMES  STMTS(sntpOptions.fOptSet |= \
348                                     OPTPROC_NXLAT_OPT|OPTPROC_NXLAT_OPT_CFG;)
349 
350 # define OPT_XLAT_CFG_NAMES     STMTS(sntpOptions.fOptSet &= \
351                                   ~(OPTPROC_NXLAT_OPT|OPTPROC_NXLAT_OPT_CFG);)
352 # define OPT_XLAT_OPT_NAMES     STMTS(sntpOptions.fOptSet &= \
353                                   ~OPTPROC_NXLAT_OPT;)
354 
355 #else   /* ENABLE_NLS */
356 # define OPT_NO_XLAT_CFG_NAMES
357 # define OPT_NO_XLAT_OPT_NAMES
358 
359 # define OPT_XLAT_CFG_NAMES
360 # define OPT_XLAT_OPT_NAMES
361 
362 # ifndef _
363 #   define _(_s)  _s
364 # endif
365 #endif  /* ENABLE_NLS */
366 
367 #ifdef  __cplusplus
368 }
369 #endif
370 #endif /* AUTOOPTS_SNTP_OPTS_H_GUARD */
371 
372 /* sntp-opts.h ends here */
373