ntpsnmpd-opts.c revision 1.1 1 1.1 kardel /* $NetBSD: ntpsnmpd-opts.c,v 1.1 2009/12/13 16:56:34 kardel Exp $ */
2 1.1 kardel
3 1.1 kardel /*
4 1.1 kardel * EDIT THIS FILE WITH CAUTION (ntpsnmpd-opts.c)
5 1.1 kardel *
6 1.1 kardel * It has been AutoGen-ed December 10, 2009 at 05:03:45 AM by AutoGen 5.10
7 1.1 kardel * From the definitions ntpsnmpd-opts.def
8 1.1 kardel * and the template file options
9 1.1 kardel *
10 1.1 kardel * Generated from AutoOpts 33:0:8 templates.
11 1.1 kardel */
12 1.1 kardel
13 1.1 kardel /*
14 1.1 kardel * This file was produced by an AutoOpts template. AutoOpts is a
15 1.1 kardel * copyrighted work. This source file is not encumbered by AutoOpts
16 1.1 kardel * licensing, but is provided under the licensing terms chosen by the
17 1.1 kardel * ntpsnmpd author or copyright holder. AutoOpts is licensed under
18 1.1 kardel * the terms of the LGPL. The redistributable library (``libopts'') is
19 1.1 kardel * licensed under the terms of either the LGPL or, at the users discretion,
20 1.1 kardel * the BSD license. See the AutoOpts and/or libopts sources for details.
21 1.1 kardel *
22 1.1 kardel * This source file is copyrighted and licensed under the following terms:
23 1.1 kardel *
24 1.1 kardel * ntpsnmpd copyright (c) 1970-2009 David L. Mills and/or others - all rights reserved
25 1.1 kardel *
26 1.1 kardel * see html/copyright.html
27 1.1 kardel */
28 1.1 kardel
29 1.1 kardel #include <sys/types.h>
30 1.1 kardel #include <limits.h>
31 1.1 kardel #include <stdio.h>
32 1.1 kardel #include <stdlib.h>
33 1.1 kardel
34 1.1 kardel #define OPTION_CODE_COMPILE 1
35 1.1 kardel #include "ntpsnmpd-opts.h"
36 1.1 kardel
37 1.1 kardel #ifdef __cplusplus
38 1.1 kardel extern "C" {
39 1.1 kardel #endif
40 1.1 kardel
41 1.1 kardel /* TRANSLATORS: choose the translation for option names wisely because you
42 1.1 kardel cannot ever change your mind. */
43 1.1 kardel tSCC zCopyright[] =
44 1.1 kardel "ntpsnmpd copyright (c) 1970-2009 David L. Mills and/or others, all rights reserved"
45 1.1 kardel /* extracted from ../include/copyright.def near line 8 */
46 1.1 kardel ;
47 1.1 kardel tSCC zCopyrightNotice[24] =
48 1.1 kardel "see html/copyright.html";
49 1.1 kardel
50 1.1 kardel extern tUsageProc optionUsage;
51 1.1 kardel
52 1.1 kardel #ifndef NULL
53 1.1 kardel # define NULL 0
54 1.1 kardel #endif
55 1.1 kardel #ifndef EXIT_SUCCESS
56 1.1 kardel # define EXIT_SUCCESS 0
57 1.1 kardel #endif
58 1.1 kardel #ifndef EXIT_FAILURE
59 1.1 kardel # define EXIT_FAILURE 1
60 1.1 kardel #endif
61 1.1 kardel
62 1.1 kardel /*
63 1.1 kardel * Nofork option description:
64 1.1 kardel */
65 1.1 kardel tSCC zNoforkText[] =
66 1.1 kardel "Do not fork";
67 1.1 kardel tSCC zNofork_NAME[] = "NOFORK";
68 1.1 kardel tSCC zNofork_Name[] = "nofork";
69 1.1 kardel #define NOFORK_FLAGS (OPTST_DISABLED)
70 1.1 kardel
71 1.1 kardel /*
72 1.1 kardel * Syslog option description:
73 1.1 kardel */
74 1.1 kardel tSCC zSyslogText[] =
75 1.1 kardel "Log to syslog()";
76 1.1 kardel tSCC zSyslog_NAME[] = "SYSLOG";
77 1.1 kardel tSCC zSyslog_Name[] = "syslog";
78 1.1 kardel #define SYSLOG_FLAGS (OPTST_DISABLED)
79 1.1 kardel
80 1.1 kardel /*
81 1.1 kardel * Help/More_Help/Version option descriptions:
82 1.1 kardel */
83 1.1 kardel tSCC zHelpText[] = "Display extended usage information and exit";
84 1.1 kardel tSCC zHelp_Name[] = "help";
85 1.1 kardel #ifdef HAVE_WORKING_FORK
86 1.1 kardel #define OPTST_MORE_HELP_FLAGS (OPTST_IMM | OPTST_NO_INIT)
87 1.1 kardel tSCC zMore_Help_Name[] = "more-help";
88 1.1 kardel tSCC zMore_HelpText[] = "Extended usage information passed thru pager";
89 1.1 kardel #else
90 1.1 kardel #define OPTST_MORE_HELP_FLAGS (OPTST_OMITTED | OPTST_NO_INIT)
91 1.1 kardel #define zMore_Help_Name NULL
92 1.1 kardel #define zMore_HelpText NULL
93 1.1 kardel #endif
94 1.1 kardel #ifdef NO_OPTIONAL_OPT_ARGS
95 1.1 kardel # define OPTST_VERSION_FLAGS OPTST_IMM | OPTST_NO_INIT
96 1.1 kardel #else
97 1.1 kardel # define OPTST_VERSION_FLAGS OPTST_SET_ARGTYPE(OPARG_TYPE_STRING) | \
98 1.1 kardel OPTST_ARG_OPTIONAL | OPTST_IMM | OPTST_NO_INIT
99 1.1 kardel #endif
100 1.1 kardel
101 1.1 kardel tSCC zVersionText[] = "Output version information and exit";
102 1.1 kardel tSCC zVersion_Name[] = "version";
103 1.1 kardel tSCC zSave_OptsText[] = "Save the option state to a config file";
104 1.1 kardel tSCC zSave_Opts_Name[] = "save-opts";
105 1.1 kardel tSCC zLoad_OptsText[] = "Load options from a config file";
106 1.1 kardel tSCC zLoad_Opts_NAME[] = "LOAD_OPTS";
107 1.1 kardel tSCC zNotLoad_Opts_Name[] = "no-load-opts";
108 1.1 kardel tSCC zNotLoad_Opts_Pfx[] = "no";
109 1.1 kardel #define zLoad_Opts_Name (zNotLoad_Opts_Name + 3)
110 1.1 kardel /*
111 1.1 kardel * Declare option callback procedures
112 1.1 kardel */
113 1.1 kardel #if defined(TEST_NTPSNMPD_OPTS)
114 1.1 kardel /*
115 1.1 kardel * Under test, omit argument processing, or call optionStackArg,
116 1.1 kardel * if multiple copies are allowed.
117 1.1 kardel */
118 1.1 kardel extern tOptProc
119 1.1 kardel optionPagedUsage, optionVersionStderr;
120 1.1 kardel static tOptProc
121 1.1 kardel doUsageOpt;
122 1.1 kardel
123 1.1 kardel #else /* NOT defined TEST_NTPSNMPD_OPTS */
124 1.1 kardel /*
125 1.1 kardel * When not under test, there are different procs to use
126 1.1 kardel */
127 1.1 kardel extern tOptProc
128 1.1 kardel optionPagedUsage, optionPrintVersion;
129 1.1 kardel static tOptProc
130 1.1 kardel doUsageOpt;
131 1.1 kardel #endif /* defined(TEST_NTPSNMPD_OPTS) */
132 1.1 kardel #ifdef TEST_NTPSNMPD_OPTS
133 1.1 kardel # define DOVERPROC optionVersionStderr
134 1.1 kardel #else
135 1.1 kardel # define DOVERPROC optionPrintVersion
136 1.1 kardel #endif /* TEST_NTPSNMPD_OPTS */
137 1.1 kardel
138 1.1 kardel /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
139 1.1 kardel *
140 1.1 kardel * Define the Ntpsnmpd Option Descriptions.
141 1.1 kardel */
142 1.1 kardel static tOptDesc optDesc[ OPTION_CT ] = {
143 1.1 kardel { /* entry idx, value */ 0, VALUE_OPT_NOFORK,
144 1.1 kardel /* equiv idx, value */ 0, VALUE_OPT_NOFORK,
145 1.1 kardel /* equivalenced to */ NO_EQUIVALENT,
146 1.1 kardel /* min, max, act ct */ 0, 1, 0,
147 1.1 kardel /* opt state flags */ NOFORK_FLAGS, 0,
148 1.1 kardel /* last opt argumnt */ { NULL },
149 1.1 kardel /* arg list/cookie */ NULL,
150 1.1 kardel /* must/cannot opts */ NULL, NULL,
151 1.1 kardel /* option proc */ NULL,
152 1.1 kardel /* desc, NAME, name */ zNoforkText, zNofork_NAME, zNofork_Name,
153 1.1 kardel /* disablement strs */ NULL, NULL },
154 1.1 kardel
155 1.1 kardel { /* entry idx, value */ 1, VALUE_OPT_SYSLOG,
156 1.1 kardel /* equiv idx, value */ 1, VALUE_OPT_SYSLOG,
157 1.1 kardel /* equivalenced to */ NO_EQUIVALENT,
158 1.1 kardel /* min, max, act ct */ 0, 1, 0,
159 1.1 kardel /* opt state flags */ SYSLOG_FLAGS, 0,
160 1.1 kardel /* last opt argumnt */ { NULL },
161 1.1 kardel /* arg list/cookie */ NULL,
162 1.1 kardel /* must/cannot opts */ NULL, NULL,
163 1.1 kardel /* option proc */ NULL,
164 1.1 kardel /* desc, NAME, name */ zSyslogText, zSyslog_NAME, zSyslog_Name,
165 1.1 kardel /* disablement strs */ NULL, NULL },
166 1.1 kardel
167 1.1 kardel { /* entry idx, value */ INDEX_OPT_VERSION, VALUE_OPT_VERSION,
168 1.1 kardel /* equiv idx value */ NO_EQUIVALENT, 0,
169 1.1 kardel /* equivalenced to */ NO_EQUIVALENT,
170 1.1 kardel /* min, max, act ct */ 0, 1, 0,
171 1.1 kardel /* opt state flags */ OPTST_VERSION_FLAGS, 0,
172 1.1 kardel /* last opt argumnt */ { NULL },
173 1.1 kardel /* arg list/cookie */ NULL,
174 1.1 kardel /* must/cannot opts */ NULL, NULL,
175 1.1 kardel /* option proc */ DOVERPROC,
176 1.1 kardel /* desc, NAME, name */ zVersionText, NULL, zVersion_Name,
177 1.1 kardel /* disablement strs */ NULL, NULL },
178 1.1 kardel
179 1.1 kardel
180 1.1 kardel
181 1.1 kardel { /* entry idx, value */ INDEX_OPT_HELP, VALUE_OPT_HELP,
182 1.1 kardel /* equiv idx value */ NO_EQUIVALENT, 0,
183 1.1 kardel /* equivalenced to */ NO_EQUIVALENT,
184 1.1 kardel /* min, max, act ct */ 0, 1, 0,
185 1.1 kardel /* opt state flags */ OPTST_IMM | OPTST_NO_INIT, 0,
186 1.1 kardel /* last opt argumnt */ { NULL },
187 1.1 kardel /* arg list/cookie */ NULL,
188 1.1 kardel /* must/cannot opts */ NULL, NULL,
189 1.1 kardel /* option proc */ doUsageOpt,
190 1.1 kardel /* desc, NAME, name */ zHelpText, NULL, zHelp_Name,
191 1.1 kardel /* disablement strs */ NULL, NULL },
192 1.1 kardel
193 1.1 kardel { /* entry idx, value */ INDEX_OPT_MORE_HELP, VALUE_OPT_MORE_HELP,
194 1.1 kardel /* equiv idx value */ NO_EQUIVALENT, 0,
195 1.1 kardel /* equivalenced to */ NO_EQUIVALENT,
196 1.1 kardel /* min, max, act ct */ 0, 1, 0,
197 1.1 kardel /* opt state flags */ OPTST_MORE_HELP_FLAGS, 0,
198 1.1 kardel /* last opt argumnt */ { NULL },
199 1.1 kardel /* arg list/cookie */ NULL,
200 1.1 kardel /* must/cannot opts */ NULL, NULL,
201 1.1 kardel /* option proc */ optionPagedUsage,
202 1.1 kardel /* desc, NAME, name */ zMore_HelpText, NULL, zMore_Help_Name,
203 1.1 kardel /* disablement strs */ NULL, NULL },
204 1.1 kardel
205 1.1 kardel { /* entry idx, value */ INDEX_OPT_SAVE_OPTS, VALUE_OPT_SAVE_OPTS,
206 1.1 kardel /* equiv idx value */ NO_EQUIVALENT, 0,
207 1.1 kardel /* equivalenced to */ NO_EQUIVALENT,
208 1.1 kardel /* min, max, act ct */ 0, 1, 0,
209 1.1 kardel /* opt state flags */ OPTST_SET_ARGTYPE(OPARG_TYPE_STRING)
210 1.1 kardel | OPTST_ARG_OPTIONAL | OPTST_NO_INIT, 0,
211 1.1 kardel /* last opt argumnt */ { NULL },
212 1.1 kardel /* arg list/cookie */ NULL,
213 1.1 kardel /* must/cannot opts */ NULL, NULL,
214 1.1 kardel /* option proc */ NULL,
215 1.1 kardel /* desc, NAME, name */ zSave_OptsText, NULL, zSave_Opts_Name,
216 1.1 kardel /* disablement strs */ NULL, NULL },
217 1.1 kardel
218 1.1 kardel { /* entry idx, value */ INDEX_OPT_LOAD_OPTS, VALUE_OPT_LOAD_OPTS,
219 1.1 kardel /* equiv idx value */ NO_EQUIVALENT, 0,
220 1.1 kardel /* equivalenced to */ NO_EQUIVALENT,
221 1.1 kardel /* min, max, act ct */ 0, NOLIMIT, 0,
222 1.1 kardel /* opt state flags */ OPTST_SET_ARGTYPE(OPARG_TYPE_STRING)
223 1.1 kardel | OPTST_DISABLE_IMM, 0,
224 1.1 kardel /* last opt argumnt */ { NULL },
225 1.1 kardel /* arg list/cookie */ NULL,
226 1.1 kardel /* must/cannot opts */ NULL, NULL,
227 1.1 kardel /* option proc */ optionLoadOpt,
228 1.1 kardel /* desc, NAME, name */ zLoad_OptsText, zLoad_Opts_NAME, zLoad_Opts_Name,
229 1.1 kardel /* disablement strs */ zNotLoad_Opts_Name, zNotLoad_Opts_Pfx }
230 1.1 kardel };
231 1.1 kardel
232 1.1 kardel /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
233 1.1 kardel *
234 1.1 kardel * Define the Ntpsnmpd Option Environment
235 1.1 kardel */
236 1.1 kardel tSCC zPROGNAME[] = "NTPSNMPD";
237 1.1 kardel tSCC zUsageTitle[] =
238 1.1 kardel "ntpsnmpd - NTP SNMP MIB agent - Ver. 4.2.6\n\
239 1.1 kardel USAGE: %s [ -<flag> | --<name> ]...\n";
240 1.1 kardel tSCC zRcName[] = ".ntprc";
241 1.1 kardel tSCC* apzHomeList[] = {
242 1.1 kardel "$HOME",
243 1.1 kardel ".",
244 1.1 kardel NULL };
245 1.1 kardel
246 1.1 kardel tSCC zBugsAddr[] = "http://bugs.ntp.org, bugs (at) ntp.org";
247 1.1 kardel #define zExplain NULL
248 1.1 kardel #define zDetail NULL
249 1.1 kardel tSCC zFullVersion[] = NTPSNMPD_FULL_VERSION;
250 1.1 kardel /* extracted from /usr/local/gnu/share/autogen/optcode.tpl near line 495 */
251 1.1 kardel
252 1.1 kardel #if defined(ENABLE_NLS)
253 1.1 kardel # define OPTPROC_BASE OPTPROC_TRANSLATE
254 1.1 kardel static tOptionXlateProc translate_option_strings;
255 1.1 kardel #else
256 1.1 kardel # define OPTPROC_BASE OPTPROC_NONE
257 1.1 kardel # define translate_option_strings NULL
258 1.1 kardel #endif /* ENABLE_NLS */
259 1.1 kardel
260 1.1 kardel
261 1.1 kardel #define ntpsnmpd_full_usage NULL
262 1.1 kardel #define ntpsnmpd_short_usage NULL
263 1.1 kardel tOptions ntpsnmpdOptions = {
264 1.1 kardel OPTIONS_STRUCT_VERSION,
265 1.1 kardel 0, NULL, /* original argc + argv */
266 1.1 kardel ( OPTPROC_BASE
267 1.1 kardel + OPTPROC_ERRSTOP
268 1.1 kardel + OPTPROC_SHORTOPT
269 1.1 kardel + OPTPROC_LONGOPT
270 1.1 kardel + OPTPROC_NO_REQ_OPT
271 1.1 kardel + OPTPROC_ENVIRON
272 1.1 kardel + OPTPROC_NO_ARGS ),
273 1.1 kardel 0, NULL, /* current option index, current option */
274 1.1 kardel NULL, NULL, zPROGNAME,
275 1.1 kardel zRcName, zCopyright, zCopyrightNotice,
276 1.1 kardel zFullVersion, apzHomeList, zUsageTitle,
277 1.1 kardel zExplain, zDetail, optDesc,
278 1.1 kardel zBugsAddr, /* address to send bugs to */
279 1.1 kardel NULL, NULL, /* extensions/saved state */
280 1.1 kardel optionUsage, /* usage procedure */
281 1.1 kardel translate_option_strings, /* translation procedure */
282 1.1 kardel /*
283 1.1 kardel * Indexes to special options
284 1.1 kardel */
285 1.1 kardel { INDEX_OPT_MORE_HELP, /* more-help option index */
286 1.1 kardel INDEX_OPT_SAVE_OPTS, /* save option index */
287 1.1 kardel NO_EQUIVALENT, /* '-#' option index */
288 1.1 kardel NO_EQUIVALENT /* index of default opt */
289 1.1 kardel },
290 1.1 kardel 7 /* full option count */, 2 /* user option count */,
291 1.1 kardel ntpsnmpd_full_usage, ntpsnmpd_short_usage,
292 1.1 kardel NULL, NULL
293 1.1 kardel };
294 1.1 kardel
295 1.1 kardel /*
296 1.1 kardel * Create the static procedure(s) declared above.
297 1.1 kardel */
298 1.1 kardel static void
299 1.1 kardel doUsageOpt(
300 1.1 kardel tOptions* pOptions,
301 1.1 kardel tOptDesc* pOptDesc )
302 1.1 kardel {
303 1.1 kardel (void)pOptions;
304 1.1 kardel USAGE( EXIT_SUCCESS );
305 1.1 kardel }
306 1.1 kardel /* extracted from /usr/local/gnu/share/autogen/optmain.tpl near line 109 */
307 1.1 kardel
308 1.1 kardel #if defined(TEST_NTPSNMPD_OPTS) /* TEST MAIN PROCEDURE: */
309 1.1 kardel
310 1.1 kardel extern void optionPutShell( tOptions* );
311 1.1 kardel
312 1.1 kardel int
313 1.1 kardel main(int argc, char** argv)
314 1.1 kardel {
315 1.1 kardel int res = EXIT_SUCCESS;
316 1.1 kardel (void)optionProcess( &ntpsnmpdOptions, argc, argv );
317 1.1 kardel optionPutShell( &ntpsnmpdOptions );
318 1.1 kardel return res;
319 1.1 kardel }
320 1.1 kardel #endif /* defined TEST_NTPSNMPD_OPTS */
321 1.1 kardel /* extracted from /usr/local/gnu/share/autogen/optcode.tpl near line 627 */
322 1.1 kardel
323 1.1 kardel #if ENABLE_NLS
324 1.1 kardel #include <stdio.h>
325 1.1 kardel #include <stdlib.h>
326 1.1 kardel #include <string.h>
327 1.1 kardel #include <unistd.h>
328 1.1 kardel #include <autoopts/usage-txt.h>
329 1.1 kardel
330 1.1 kardel static char* AO_gettext( char const* pz );
331 1.1 kardel static void coerce_it(void** s);
332 1.1 kardel
333 1.1 kardel static char*
334 1.1 kardel AO_gettext( char const* pz )
335 1.1 kardel {
336 1.1 kardel char* pzRes;
337 1.1 kardel if (pz == NULL)
338 1.1 kardel return NULL;
339 1.1 kardel pzRes = _(pz);
340 1.1 kardel if (pzRes == pz)
341 1.1 kardel return pzRes;
342 1.1 kardel pzRes = strdup( pzRes );
343 1.1 kardel if (pzRes == NULL) {
344 1.1 kardel fputs( _("No memory for duping translated strings\n"), stderr );
345 1.1 kardel exit( EXIT_FAILURE );
346 1.1 kardel }
347 1.1 kardel return pzRes;
348 1.1 kardel }
349 1.1 kardel
350 1.1 kardel static void coerce_it(void** s) { *s = AO_gettext(*s); }
351 1.1 kardel #define COERSION(_f) \
352 1.1 kardel coerce_it((void*)&(ntpsnmpdOptions._f))
353 1.1 kardel
354 1.1 kardel /*
355 1.1 kardel * This invokes the translation code (e.g. gettext(3)).
356 1.1 kardel */
357 1.1 kardel static void
358 1.1 kardel translate_option_strings( void )
359 1.1 kardel {
360 1.1 kardel /*
361 1.1 kardel * Guard against re-translation. It won't work. The strings will have
362 1.1 kardel * been changed by the first pass through this code. One shot only.
363 1.1 kardel */
364 1.1 kardel if (option_usage_text.field_ct != 0) {
365 1.1 kardel
366 1.1 kardel /*
367 1.1 kardel * Do the translations. The first pointer follows the field count
368 1.1 kardel * field. The field count field is the size of a pointer.
369 1.1 kardel */
370 1.1 kardel tOptDesc* pOD = ntpsnmpdOptions.pOptDesc;
371 1.1 kardel char** ppz = (char**)(void*)&(option_usage_text);
372 1.1 kardel int ix = option_usage_text.field_ct;
373 1.1 kardel
374 1.1 kardel do {
375 1.1 kardel ppz++;
376 1.1 kardel *ppz = AO_gettext(*ppz);
377 1.1 kardel } while (--ix > 0);
378 1.1 kardel
379 1.1 kardel COERSION(pzCopyright);
380 1.1 kardel COERSION(pzCopyNotice);
381 1.1 kardel COERSION(pzFullVersion);
382 1.1 kardel COERSION(pzUsageTitle);
383 1.1 kardel COERSION(pzExplain);
384 1.1 kardel COERSION(pzDetail);
385 1.1 kardel option_usage_text.field_ct = 0;
386 1.1 kardel
387 1.1 kardel for (ix = ntpsnmpdOptions.optCt; ix > 0; ix--, pOD++)
388 1.1 kardel coerce_it((void*)&(pOD->pzText));
389 1.1 kardel }
390 1.1 kardel
391 1.1 kardel if ((ntpsnmpdOptions.fOptSet & OPTPROC_NXLAT_OPT_CFG) == 0) {
392 1.1 kardel tOptDesc* pOD = ntpsnmpdOptions.pOptDesc;
393 1.1 kardel int ix;
394 1.1 kardel
395 1.1 kardel for (ix = ntpsnmpdOptions.optCt; ix > 0; ix--, pOD++) {
396 1.1 kardel coerce_it((void*)&(pOD->pz_Name));
397 1.1 kardel coerce_it((void*)&(pOD->pz_DisableName));
398 1.1 kardel coerce_it((void*)&(pOD->pz_DisablePfx));
399 1.1 kardel }
400 1.1 kardel /* prevent re-translation */
401 1.1 kardel ntpsnmpdOptions.fOptSet |= OPTPROC_NXLAT_OPT_CFG | OPTPROC_NXLAT_OPT;
402 1.1 kardel }
403 1.1 kardel }
404 1.1 kardel
405 1.1 kardel #endif /* ENABLE_NLS */
406 1.1 kardel
407 1.1 kardel #ifdef __cplusplus
408 1.1 kardel }
409 1.1 kardel #endif
410 1.1 kardel /* ntpsnmpd-opts.c ends here */
411