xref: /freebsd/contrib/ntp/ntpq/ntpq-opts.h (revision e0c4386e)
1 /*
2  *  EDIT THIS FILE WITH CAUTION  (ntpq-opts.h)
3  *
4  *  It has been AutoGen-ed  June  6, 2023 at 04:38:02 AM by AutoGen 5.18.16
5  *  From the definitions    ntpq-opts.def
6  *  and the template file   options
7  *
8  * Generated from AutoOpts 42:1:17 templates.
9  *
10  *  AutoOpts is a copyrighted work.  This header 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  * The ntpq program is copyrighted and licensed
19  * under the following terms:
20  *
21  *  Copyright (C) 1992-2023 The University of Delaware and Network Time Foundation, all rights reserved.
22  *  This is free software. It is licensed for use, modification and
23  *  redistribution under the terms of the NTP License, copies of which
24  *  can be seen at:
25  *    <http://ntp.org/license>
26  *    <http://opensource.org/licenses/ntp-license.php>
27  *
28  *  Permission to use, copy, modify, and distribute this software and its
29  *  documentation for any purpose with or without fee is hereby granted,
30  *  provided that the above copyright notice appears in all copies and that
31  *  both the copyright notice and this permission notice appear in
32  *  supporting documentation, and that the name The University of Delaware not be used in
33  *  advertising or publicity pertaining to distribution of the software
34  *  without specific, written prior permission. The University of Delaware and Network Time Foundation makes no
35  *  representations about the suitability this software for any purpose. It
36  *  is provided "as is" without express or implied warranty.
37  */
38 /**
39  *  This file contains the programmatic interface to the Automated
40  *  Options generated for the ntpq program.
41  *  These macros are documented in the AutoGen info file in the
42  *  "AutoOpts" chapter.  Please refer to that doc for usage help.
43  */
44 #ifndef AUTOOPTS_NTPQ_OPTS_H_GUARD
45 #define AUTOOPTS_NTPQ_OPTS_H_GUARD 1
46 #include "config.h"
47 #include <autoopts/options.h>
48 #include <stdarg.h>
49 #include <stdnoreturn.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 172033
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 #if GCC_VERSION > 40400
66 #define NOT_REACHED __builtin_unreachable();
67 #else
68 #define NOT_REACHED
69 #endif
70 
71 /**
72  *  Enumeration of each option type for ntpq
73  */
74 typedef enum {
75     INDEX_OPT_IPV4             =  0,
76     INDEX_OPT_IPV6             =  1,
77     INDEX_OPT_COMMAND          =  2,
78     INDEX_OPT_DEBUG_LEVEL      =  3,
79     INDEX_OPT_SET_DEBUG_LEVEL  =  4,
80     INDEX_OPT_INTERACTIVE      =  5,
81     INDEX_OPT_NUMERIC          =  6,
82     INDEX_OPT_OLD_RV           =  7,
83     INDEX_OPT_PEERS            =  8,
84     INDEX_OPT_REFID            =  9,
85     INDEX_OPT_UNCONNECTED      = 10,
86     INDEX_OPT_WIDE             = 11,
87     INDEX_OPT_VERSION          = 12,
88     INDEX_OPT_HELP             = 13,
89     INDEX_OPT_MORE_HELP        = 14,
90     INDEX_OPT_SAVE_OPTS        = 15,
91     INDEX_OPT_LOAD_OPTS        = 16
92 } teOptIndex;
93 /** count of all options for ntpq */
94 #define OPTION_CT    17
95 /** ntpq version */
96 #define NTPQ_VERSION       "4.2.8p17"
97 /** Full ntpq version text */
98 #define NTPQ_FULL_VERSION  "ntpq 4.2.8p17"
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) (ntpqOptions.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 ntpq exit codes
138  */
139 typedef enum {
140     NTPQ_EXIT_SUCCESS         = 0,
141     NTPQ_EXIT_FAILURE         = 1,
142     NTPQ_EXIT_USAGE_ERROR     = 64,
143     NTPQ_EXIT_NO_CONFIG_INPUT = 66,
144     NTPQ_EXIT_LIBOPTS_FAILURE = 70
145 }   ntpq_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    COMMAND
160 #  warning undefining COMMAND due to option name conflict
161 #  undef   COMMAND
162 # endif
163 # ifdef    DEBUG_LEVEL
164 #  warning undefining DEBUG_LEVEL due to option name conflict
165 #  undef   DEBUG_LEVEL
166 # endif
167 # ifdef    SET_DEBUG_LEVEL
168 #  warning undefining SET_DEBUG_LEVEL due to option name conflict
169 #  undef   SET_DEBUG_LEVEL
170 # endif
171 # ifdef    INTERACTIVE
172 #  warning undefining INTERACTIVE due to option name conflict
173 #  undef   INTERACTIVE
174 # endif
175 # ifdef    NUMERIC
176 #  warning undefining NUMERIC due to option name conflict
177 #  undef   NUMERIC
178 # endif
179 # ifdef    OLD_RV
180 #  warning undefining OLD_RV due to option name conflict
181 #  undef   OLD_RV
182 # endif
183 # ifdef    PEERS
184 #  warning undefining PEERS due to option name conflict
185 #  undef   PEERS
186 # endif
187 # ifdef    REFID
188 #  warning undefining REFID due to option name conflict
189 #  undef   REFID
190 # endif
191 # ifdef    UNCONNECTED
192 #  warning undefining UNCONNECTED due to option name conflict
193 #  undef   UNCONNECTED
194 # endif
195 # ifdef    WIDE
196 #  warning undefining WIDE due to option name conflict
197 #  undef   WIDE
198 # endif
199 #else  /* NO_OPTION_NAME_WARNINGS */
200 # undef IPV4
201 # undef IPV6
202 # undef COMMAND
203 # undef DEBUG_LEVEL
204 # undef SET_DEBUG_LEVEL
205 # undef INTERACTIVE
206 # undef NUMERIC
207 # undef OLD_RV
208 # undef PEERS
209 # undef REFID
210 # undef UNCONNECTED
211 # undef WIDE
212 #endif  /*  NO_OPTION_NAME_WARNINGS */
213 
214 /**
215  *  Interface defines for specific options.
216  * @{
217  */
218 #define VALUE_OPT_IPV4           '4'
219 #define VALUE_OPT_IPV6           '6'
220 #define VALUE_OPT_COMMAND        'c'
221 #define VALUE_OPT_DEBUG_LEVEL    'd'
222 #define VALUE_OPT_SET_DEBUG_LEVEL 'D'
223 
224 #define OPT_VALUE_SET_DEBUG_LEVEL (DESC(SET_DEBUG_LEVEL).optArg.argInt)
225 #define VALUE_OPT_INTERACTIVE    'i'
226 #define VALUE_OPT_NUMERIC        'n'
227 #define VALUE_OPT_OLD_RV         0x1001
228 #define VALUE_OPT_PEERS          'p'
229 #define VALUE_OPT_REFID          'r'
230 
231 typedef enum {
232     REFID_HASH, REFID_IPV4
233 } te_Refid;
234 #define OPT_REFID_VAL2STR(_v)    optionKeywordName(&DESC(REFID), (_v))
235 #define OPT_VALUE_REFID          (DESC(REFID).optArg.argEnum)
236 #define VALUE_OPT_UNCONNECTED    'u'
237 #define VALUE_OPT_WIDE           'w'
238 /** option flag (value) for help-value option */
239 #define VALUE_OPT_HELP          '?'
240 /** option flag (value) for more-help-value option */
241 #define VALUE_OPT_MORE_HELP     '!'
242 /** option flag (value) for version-value option */
243 #define VALUE_OPT_VERSION       0x1002
244 /** option flag (value) for save-opts-value option */
245 #define VALUE_OPT_SAVE_OPTS     '>'
246 /** option flag (value) for load-opts-value option */
247 #define VALUE_OPT_LOAD_OPTS     '<'
248 #define SET_OPT_SAVE_OPTS(a)   STMTS( \
249         DESC(SAVE_OPTS).fOptState &= OPTST_PERSISTENT_MASK; \
250         DESC(SAVE_OPTS).fOptState |= OPTST_SET; \
251         DESC(SAVE_OPTS).optArg.argString = (char const*)(a))
252 /*
253  *  Interface defines not associated with particular options
254  */
255 #define ERRSKIP_OPTERR  STMTS(ntpqOptions.fOptSet &= ~OPTPROC_ERRSTOP)
256 #define ERRSTOP_OPTERR  STMTS(ntpqOptions.fOptSet |= OPTPROC_ERRSTOP)
257 #define RESTART_OPT(n)  STMTS( \
258                 ntpqOptions.curOptIdx = (n); \
259                 ntpqOptions.pzCurOpt  = NULL )
260 #define START_OPT       RESTART_OPT(1)
261 #define USAGE(c)        (*ntpqOptions.pUsageProc)(&ntpqOptions, c)
262 
263 #ifdef  __cplusplus
264 extern "C" {
265 #endif
266 
267 
268 /* * * * * *
269  *
270  *  Declare the ntpq option descriptor.
271  */
272 extern tOptions ntpqOptions;
273 
274 #if defined(ENABLE_NLS)
275 # ifndef _
276 #   include <stdio.h>
277 #   ifndef HAVE_GETTEXT
278       extern char * gettext(char const *);
279 #   else
280 #     include <libintl.h>
281 #   endif
282 
283 # ifndef ATTRIBUTE_FORMAT_ARG
284 #   define ATTRIBUTE_FORMAT_ARG(_a)
285 # endif
286 
287 static inline char* aoGetsText(char const* pz) ATTRIBUTE_FORMAT_ARG(1);
288 static inline char* aoGetsText(char const* pz) {
289     if (pz == NULL) return NULL;
290     return (char*)gettext(pz);
291 }
292 #   define _(s)  aoGetsText(s)
293 # endif /* _() */
294 
295 # define OPT_NO_XLAT_CFG_NAMES  STMTS(ntpqOptions.fOptSet |= \
296                                     OPTPROC_NXLAT_OPT_CFG;)
297 # define OPT_NO_XLAT_OPT_NAMES  STMTS(ntpqOptions.fOptSet |= \
298                                     OPTPROC_NXLAT_OPT|OPTPROC_NXLAT_OPT_CFG;)
299 
300 # define OPT_XLAT_CFG_NAMES     STMTS(ntpqOptions.fOptSet &= \
301                                   ~(OPTPROC_NXLAT_OPT|OPTPROC_NXLAT_OPT_CFG);)
302 # define OPT_XLAT_OPT_NAMES     STMTS(ntpqOptions.fOptSet &= \
303                                   ~OPTPROC_NXLAT_OPT;)
304 
305 #else   /* ENABLE_NLS */
306 # define OPT_NO_XLAT_CFG_NAMES
307 # define OPT_NO_XLAT_OPT_NAMES
308 
309 # define OPT_XLAT_CFG_NAMES
310 # define OPT_XLAT_OPT_NAMES
311 
312 # ifndef _
313 #   define _(_s)  _s
314 # endif
315 #endif  /* ENABLE_NLS */
316 
317 
318 #ifdef  __cplusplus
319 }
320 #endif
321 #endif /* AUTOOPTS_NTPQ_OPTS_H_GUARD */
322 
323 /* ntpq-opts.h ends here */
324