xref: /netbsd-src/external/bsd/ntp/dist/ntpq/ntpq-opts.h (revision eabc0478de71e4e011a5b4e0392741e01d491794)
1 /*	$NetBSD: ntpq-opts.h,v 1.15 2024/08/18 20:47:19 christos Exp $	*/
2 
3 /*
4  *  EDIT THIS FILE WITH CAUTION  (ntpq-opts.h)
5  *
6  *  It has been AutoGen-ed  May 25, 2024 at 12:04:21 AM by AutoGen 5.18.16
7  *  From the definitions    ntpq-opts.def
8  *  and the template file   options
9  *
10  * Generated from AutoOpts 42:1:17 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 ntpq 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 ntpq program is copyrighted and licensed
21  * under the following terms:
22  *
23  *  Copyright (C) 1992-2024 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 ntpq 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_NTPQ_OPTS_H_GUARD
47 #define AUTOOPTS_NTPQ_OPTS_H_GUARD 1
48 #include "config.h"
49 #include <autoopts/options.h>
50 #include <stdarg.h>
51 #include <stdnoreturn.h>
52 
53 /**
54  *  Ensure that the library used for compiling this generated header is at
55  *  least as new as the version current when the header template was released
56  *  (not counting patch version increments).  Also ensure that the oldest
57  *  tolerable version is at least as old as what was current when the header
58  *  template was released.
59  */
60 #define AO_TEMPLATE_VERSION 172033
61 #if (AO_TEMPLATE_VERSION < OPTIONS_MINIMUM_VERSION) \
62  || (AO_TEMPLATE_VERSION > OPTIONS_STRUCT_VERSION)
63 # error option template version mismatches autoopts/options.h header
64   Choke Me.
65 #endif
66 
67 #if GCC_VERSION > 40400
68 #define NOT_REACHED __builtin_unreachable();
69 #else
70 #define NOT_REACHED
71 #endif
72 
73 /**
74  *  Enumeration of each option type for ntpq
75  */
76 typedef enum {
77     INDEX_OPT_IPV4             =  0,
78     INDEX_OPT_IPV6             =  1,
79     INDEX_OPT_COMMAND          =  2,
80     INDEX_OPT_DEBUG_LEVEL      =  3,
81     INDEX_OPT_SET_DEBUG_LEVEL  =  4,
82     INDEX_OPT_INTERACTIVE      =  5,
83     INDEX_OPT_NUMERIC          =  6,
84     INDEX_OPT_OLD_RV           =  7,
85     INDEX_OPT_PEERS            =  8,
86     INDEX_OPT_REFID            =  9,
87     INDEX_OPT_UNCONNECTED      = 10,
88     INDEX_OPT_WIDE             = 11,
89     INDEX_OPT_VERSION          = 12,
90     INDEX_OPT_HELP             = 13,
91     INDEX_OPT_MORE_HELP        = 14,
92     INDEX_OPT_SAVE_OPTS        = 15,
93     INDEX_OPT_LOAD_OPTS        = 16
94 } teOptIndex;
95 /** count of all options for ntpq */
96 #define OPTION_CT    17
97 /** ntpq version */
98 #define NTPQ_VERSION       "4.2.8p18"
99 /** Full ntpq version text */
100 #define NTPQ_FULL_VERSION  "ntpq 4.2.8p18"
101 
102 /**
103  *  Interface defines for all options.  Replace "n" with the UPPER_CASED
104  *  option name (as in the teOptIndex enumeration above).
105  *  e.g. HAVE_OPT(IPV4)
106  */
107 #define         DESC(n) (ntpqOptions.pOptDesc[INDEX_OPT_## n])
108 /** 'true' if an option has been specified in any way */
109 #define     HAVE_OPT(n) (! UNUSED_OPT(& DESC(n)))
110 /** The string argument to an option. The argument type must be \"string\". */
111 #define      OPT_ARG(n) (DESC(n).optArg.argString)
112 /** Mask the option state revealing how an option was specified.
113  *  It will be one and only one of \a OPTST_SET, \a OPTST_PRESET,
114  * \a OPTST_DEFINED, \a OPTST_RESET or zero.
115  */
116 #define    STATE_OPT(n) (DESC(n).fOptState & OPTST_SET_MASK)
117 /** Count of option's occurrances *on the command line*. */
118 #define    COUNT_OPT(n) (DESC(n).optOccCt)
119 /** mask of \a OPTST_SET and \a OPTST_DEFINED. */
120 #define    ISSEL_OPT(n) (SELECTED_OPT(&DESC(n)))
121 /** 'true' if \a HAVE_OPT would yield 'false'. */
122 #define ISUNUSED_OPT(n) (UNUSED_OPT(& DESC(n)))
123 /** 'true' if OPTST_DISABLED bit not set. */
124 #define  ENABLED_OPT(n) (! DISABLED_OPT(& DESC(n)))
125 /** number of stacked option arguments.
126  *  Valid only for stacked option arguments. */
127 #define  STACKCT_OPT(n) (((tArgList*)(DESC(n).optCookie))->useCt)
128 /** stacked argument vector.
129  *  Valid only for stacked option arguments. */
130 #define STACKLST_OPT(n) (((tArgList*)(DESC(n).optCookie))->apzArgs)
131 /** Reset an option. */
132 #define    CLEAR_OPT(n) STMTS( \
133                 DESC(n).fOptState &= OPTST_PERSISTENT_MASK;   \
134                 if ((DESC(n).fOptState & OPTST_INITENABLED) == 0) \
135                     DESC(n).fOptState |= OPTST_DISABLED; \
136                 DESC(n).optCookie = NULL )
137 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
138 /**
139  *  Enumeration of ntpq exit codes
140  */
141 typedef enum {
142     NTPQ_EXIT_SUCCESS         = 0,
143     NTPQ_EXIT_FAILURE         = 1,
144     NTPQ_EXIT_USAGE_ERROR     = 64,
145     NTPQ_EXIT_NO_CONFIG_INPUT = 66,
146     NTPQ_EXIT_LIBOPTS_FAILURE = 70
147 }   ntpq_exit_code_t;
148 /** @} */
149 /**
150  *  Make sure there are no #define name conflicts with the option names
151  */
152 #ifndef     NO_OPTION_NAME_WARNINGS
153 # ifdef    IPV4
154 #  warning undefining IPV4 due to option name conflict
155 #  undef   IPV4
156 # endif
157 # ifdef    IPV6
158 #  warning undefining IPV6 due to option name conflict
159 #  undef   IPV6
160 # endif
161 # ifdef    COMMAND
162 #  warning undefining COMMAND due to option name conflict
163 #  undef   COMMAND
164 # endif
165 # ifdef    DEBUG_LEVEL
166 #  warning undefining DEBUG_LEVEL due to option name conflict
167 #  undef   DEBUG_LEVEL
168 # endif
169 # ifdef    SET_DEBUG_LEVEL
170 #  warning undefining SET_DEBUG_LEVEL due to option name conflict
171 #  undef   SET_DEBUG_LEVEL
172 # endif
173 # ifdef    INTERACTIVE
174 #  warning undefining INTERACTIVE due to option name conflict
175 #  undef   INTERACTIVE
176 # endif
177 # ifdef    NUMERIC
178 #  warning undefining NUMERIC due to option name conflict
179 #  undef   NUMERIC
180 # endif
181 # ifdef    OLD_RV
182 #  warning undefining OLD_RV due to option name conflict
183 #  undef   OLD_RV
184 # endif
185 # ifdef    PEERS
186 #  warning undefining PEERS due to option name conflict
187 #  undef   PEERS
188 # endif
189 # ifdef    REFID
190 #  warning undefining REFID due to option name conflict
191 #  undef   REFID
192 # endif
193 # ifdef    UNCONNECTED
194 #  warning undefining UNCONNECTED due to option name conflict
195 #  undef   UNCONNECTED
196 # endif
197 # ifdef    WIDE
198 #  warning undefining WIDE due to option name conflict
199 #  undef   WIDE
200 # endif
201 #else  /* NO_OPTION_NAME_WARNINGS */
202 # undef IPV4
203 # undef IPV6
204 # undef COMMAND
205 # undef DEBUG_LEVEL
206 # undef SET_DEBUG_LEVEL
207 # undef INTERACTIVE
208 # undef NUMERIC
209 # undef OLD_RV
210 # undef PEERS
211 # undef REFID
212 # undef UNCONNECTED
213 # undef WIDE
214 #endif  /*  NO_OPTION_NAME_WARNINGS */
215 
216 /**
217  *  Interface defines for specific options.
218  * @{
219  */
220 #define VALUE_OPT_IPV4           '4'
221 #define VALUE_OPT_IPV6           '6'
222 #define VALUE_OPT_COMMAND        'c'
223 #define VALUE_OPT_DEBUG_LEVEL    'd'
224 #define VALUE_OPT_SET_DEBUG_LEVEL 'D'
225 
226 #define OPT_VALUE_SET_DEBUG_LEVEL (DESC(SET_DEBUG_LEVEL).optArg.argInt)
227 #define VALUE_OPT_INTERACTIVE    'i'
228 #define VALUE_OPT_NUMERIC        'n'
229 #define VALUE_OPT_OLD_RV         0x1001
230 #define VALUE_OPT_PEERS          'p'
231 #define VALUE_OPT_REFID          'r'
232 
233 typedef enum {
234     REFID_HASH, REFID_IPV4
235 } te_Refid;
236 #define OPT_REFID_VAL2STR(_v)    optionKeywordName(&DESC(REFID), (_v))
237 #define OPT_VALUE_REFID          (DESC(REFID).optArg.argEnum)
238 #define VALUE_OPT_UNCONNECTED    'u'
239 #define VALUE_OPT_WIDE           'w'
240 /** option flag (value) for help-value option */
241 #define VALUE_OPT_HELP          '?'
242 /** option flag (value) for more-help-value option */
243 #define VALUE_OPT_MORE_HELP     '!'
244 /** option flag (value) for version-value option */
245 #define VALUE_OPT_VERSION       0x1002
246 /** option flag (value) for save-opts-value option */
247 #define VALUE_OPT_SAVE_OPTS     '>'
248 /** option flag (value) for load-opts-value option */
249 #define VALUE_OPT_LOAD_OPTS     '<'
250 #define SET_OPT_SAVE_OPTS(a)   STMTS( \
251         DESC(SAVE_OPTS).fOptState &= OPTST_PERSISTENT_MASK; \
252         DESC(SAVE_OPTS).fOptState |= OPTST_SET; \
253         DESC(SAVE_OPTS).optArg.argString = (char const*)(a))
254 /*
255  *  Interface defines not associated with particular options
256  */
257 #define ERRSKIP_OPTERR  STMTS(ntpqOptions.fOptSet &= ~OPTPROC_ERRSTOP)
258 #define ERRSTOP_OPTERR  STMTS(ntpqOptions.fOptSet |= OPTPROC_ERRSTOP)
259 #define RESTART_OPT(n)  STMTS( \
260                 ntpqOptions.curOptIdx = (n); \
261                 ntpqOptions.pzCurOpt  = NULL )
262 #define START_OPT       RESTART_OPT(1)
263 #define USAGE(c)        (*ntpqOptions.pUsageProc)(&ntpqOptions, c)
264 
265 #ifdef  __cplusplus
266 extern "C" {
267 #endif
268 
269 
270 /* * * * * *
271  *
272  *  Declare the ntpq option descriptor.
273  */
274 extern tOptions ntpqOptions;
275 
276 #if defined(ENABLE_NLS)
277 # ifndef _
278 #   include <stdio.h>
279 #   ifndef HAVE_GETTEXT
280       extern char * gettext(char const *);
281 #   else
282 #     include <libintl.h>
283 #   endif
284 
285 # ifndef ATTRIBUTE_FORMAT_ARG
286 #   define ATTRIBUTE_FORMAT_ARG(_a)
287 # endif
288 
289 static inline char* aoGetsText(char const* pz) ATTRIBUTE_FORMAT_ARG(1);
290 static inline char* aoGetsText(char const* pz) {
291     if (pz == NULL) return NULL;
292     return (char*)gettext(pz);
293 }
294 #   define _(s)  aoGetsText(s)
295 # endif /* _() */
296 
297 # define OPT_NO_XLAT_CFG_NAMES  STMTS(ntpqOptions.fOptSet |= \
298                                     OPTPROC_NXLAT_OPT_CFG;)
299 # define OPT_NO_XLAT_OPT_NAMES  STMTS(ntpqOptions.fOptSet |= \
300                                     OPTPROC_NXLAT_OPT|OPTPROC_NXLAT_OPT_CFG;)
301 
302 # define OPT_XLAT_CFG_NAMES     STMTS(ntpqOptions.fOptSet &= \
303                                   ~(OPTPROC_NXLAT_OPT|OPTPROC_NXLAT_OPT_CFG);)
304 # define OPT_XLAT_OPT_NAMES     STMTS(ntpqOptions.fOptSet &= \
305                                   ~OPTPROC_NXLAT_OPT;)
306 
307 #else   /* ENABLE_NLS */
308 # define OPT_NO_XLAT_CFG_NAMES
309 # define OPT_NO_XLAT_OPT_NAMES
310 
311 # define OPT_XLAT_CFG_NAMES
312 # define OPT_XLAT_OPT_NAMES
313 
314 # ifndef _
315 #   define _(_s)  _s
316 # endif
317 #endif  /* ENABLE_NLS */
318 
319 
320 #ifdef  __cplusplus
321 }
322 #endif
323 #endif /* AUTOOPTS_NTPQ_OPTS_H_GUARD */
324 
325 /* ntpq-opts.h ends here */
326