ntpsnmpd-opts.c revision 1.1.1.1.6.1 1 /* $NetBSD: ntpsnmpd-opts.c,v 1.1.1.1.6.1 2012/04/17 00:03:49 yamt Exp $ */
2
3 /*
4 * EDIT THIS FILE WITH CAUTION (ntpsnmpd-opts.c)
5 *
6 * It has been AutoGen-ed December 24, 2011 at 06:34:36 PM by AutoGen 5.12
7 * From the definitions ntpsnmpd-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 ntpsnmpd 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 "ntpsnmpd-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[42] =
43 "ntpsnmpd 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 * Nofork option description:
56 */
57 static char const zNoforkText[] =
58 "Do not fork";
59 static char const zNofork_NAME[] = "NOFORK";
60 static char const zNofork_Name[] = "nofork";
61 #define NOFORK_FLAGS (OPTST_DISABLED)
62
63 /*
64 * Syslog option description:
65 */
66 static char const zSyslogText[] =
67 "Log to syslog()";
68 static char const zSyslog_NAME[] = "SYSLOG";
69 static char const zSyslog_Name[] = "syslog";
70 #define SYSLOG_FLAGS (OPTST_DISABLED)
71
72 /*
73 * Agentxsocket option description:
74 */
75 static char const zAgentxsocketText[] =
76 "The socket address ntpsnmpd uses to connect to net-snmpd";
77 static char const zAgentxsocket_NAME[] = "AGENTXSOCKET";
78 static char const zAgentxsocket_Name[] = "agentxsocket";
79 static char const zAgentxsocketDefaultArg[] = "unix:/var/agentx/master";
80 #define AGENTXSOCKET_FLAGS (OPTST_DISABLED \
81 | OPTST_SET_ARGTYPE(OPARG_TYPE_STRING))
82
83 /*
84 * Help/More_Help/Version option descriptions:
85 */
86 static char const zHelpText[] = "Display extended usage information and exit";
87 static char const zHelp_Name[] = "help";
88 #ifdef HAVE_WORKING_FORK
89 #define OPTST_MORE_HELP_FLAGS (OPTST_IMM | OPTST_NO_INIT)
90 static char const zMore_Help_Name[] = "more-help";
91 static char const zMore_HelpText[] = "Extended usage information passed thru pager";
92 #else
93 #define OPTST_MORE_HELP_FLAGS (OPTST_OMITTED | OPTST_NO_INIT)
94 #define zMore_Help_Name NULL
95 #define zMore_HelpText NULL
96 #endif
97 #ifdef NO_OPTIONAL_OPT_ARGS
98 # define OPTST_VERSION_FLAGS OPTST_IMM | OPTST_NO_INIT
99 #else
100 # define OPTST_VERSION_FLAGS OPTST_SET_ARGTYPE(OPARG_TYPE_STRING) | \
101 OPTST_ARG_OPTIONAL | OPTST_IMM | OPTST_NO_INIT
102 #endif
103
104 static char const zVersionText[] = "Output version information and exit";
105 static char const zVersion_Name[] = "version";
106 static char const zSave_OptsText[] = "Save the option state to a config file";
107 static char const zSave_Opts_Name[] = "save-opts";
108 static char const zLoad_OptsText[] = "Load options from a config file";
109 static char const zLoad_Opts_NAME[] = "LOAD_OPTS";
110 static char const zNotLoad_Opts_Name[] = "no-load-opts";
111 static char const zNotLoad_Opts_Pfx[] = "no";
112 #define zLoad_Opts_Name (zNotLoad_Opts_Name + 3)
113 /*
114 * Declare option callback procedures
115 */
116 #if defined(TEST_NTPSNMPD_OPTS)
117 /*
118 * Under test, omit argument processing, or call optionStackArg,
119 * if multiple copies are allowed.
120 */
121 static tOptProc
122 doUsageOpt;
123
124 #else /* NOT defined TEST_NTPSNMPD_OPTS */
125 /*
126 * When not under test, there are different procs to use
127 */
128 extern tOptProc
129 optionBooleanVal, optionNestedVal, optionNumericVal,
130 optionPagedUsage, optionPrintVersion, optionResetOpt,
131 optionStackArg, optionTimeDate, optionTimeVal,
132 optionUnstackArg, optionVersionStderr;
133 static tOptProc
134 doUsageOpt;
135 #endif /* defined(TEST_NTPSNMPD_OPTS) */
136 #ifdef TEST_NTPSNMPD_OPTS
137 # define DOVERPROC optionVersionStderr
138 #else
139 # define DOVERPROC optionPrintVersion
140 #endif /* TEST_NTPSNMPD_OPTS */
141
142 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
143 *
144 * Define the Ntpsnmpd Option Descriptions.
145 */
146 static tOptDesc optDesc[OPTION_CT] = {
147 { /* entry idx, value */ 0, VALUE_OPT_NOFORK,
148 /* equiv idx, value */ 0, VALUE_OPT_NOFORK,
149 /* equivalenced to */ NO_EQUIVALENT,
150 /* min, max, act ct */ 0, 1, 0,
151 /* opt state flags */ NOFORK_FLAGS, 0,
152 /* last opt argumnt */ { NULL },
153 /* arg list/cookie */ NULL,
154 /* must/cannot opts */ NULL, NULL,
155 /* option proc */ NULL,
156 /* desc, NAME, name */ zNoforkText, zNofork_NAME, zNofork_Name,
157 /* disablement strs */ NULL, NULL },
158
159 { /* entry idx, value */ 1, VALUE_OPT_SYSLOG,
160 /* equiv idx, value */ 1, VALUE_OPT_SYSLOG,
161 /* equivalenced to */ NO_EQUIVALENT,
162 /* min, max, act ct */ 0, 1, 0,
163 /* opt state flags */ SYSLOG_FLAGS, 0,
164 /* last opt argumnt */ { NULL },
165 /* arg list/cookie */ NULL,
166 /* must/cannot opts */ NULL, NULL,
167 /* option proc */ NULL,
168 /* desc, NAME, name */ zSyslogText, zSyslog_NAME, zSyslog_Name,
169 /* disablement strs */ NULL, NULL },
170
171 { /* entry idx, value */ 2, VALUE_OPT_AGENTXSOCKET,
172 /* equiv idx, value */ 2, VALUE_OPT_AGENTXSOCKET,
173 /* equivalenced to */ NO_EQUIVALENT,
174 /* min, max, act ct */ 0, 1, 0,
175 /* opt state flags */ AGENTXSOCKET_FLAGS, 0,
176 /* last opt argumnt */ { zAgentxsocketDefaultArg },
177 /* arg list/cookie */ NULL,
178 /* must/cannot opts */ NULL, NULL,
179 /* option proc */ NULL,
180 /* desc, NAME, name */ zAgentxsocketText, zAgentxsocket_NAME, zAgentxsocket_Name,
181 /* disablement strs */ NULL, NULL },
182
183 { /* entry idx, value */ INDEX_OPT_VERSION, VALUE_OPT_VERSION,
184 /* equiv idx value */ NO_EQUIVALENT, 0,
185 /* equivalenced to */ NO_EQUIVALENT,
186 /* min, max, act ct */ 0, 1, 0,
187 /* opt state flags */ OPTST_VERSION_FLAGS, 0,
188 /* last opt argumnt */ { NULL },
189 /* arg list/cookie */ NULL,
190 /* must/cannot opts */ NULL, NULL,
191 /* option proc */ DOVERPROC,
192 /* desc, NAME, name */ zVersionText, NULL, zVersion_Name,
193 /* disablement strs */ NULL, NULL },
194
195
196
197 { /* entry idx, value */ INDEX_OPT_HELP, VALUE_OPT_HELP,
198 /* equiv idx value */ NO_EQUIVALENT, 0,
199 /* equivalenced to */ NO_EQUIVALENT,
200 /* min, max, act ct */ 0, 1, 0,
201 /* opt state flags */ OPTST_IMM | OPTST_NO_INIT, 0,
202 /* last opt argumnt */ { NULL },
203 /* arg list/cookie */ NULL,
204 /* must/cannot opts */ NULL, NULL,
205 /* option proc */ doUsageOpt,
206 /* desc, NAME, name */ zHelpText, NULL, zHelp_Name,
207 /* disablement strs */ NULL, NULL },
208
209 { /* entry idx, value */ INDEX_OPT_MORE_HELP, VALUE_OPT_MORE_HELP,
210 /* equiv idx value */ NO_EQUIVALENT, 0,
211 /* equivalenced to */ NO_EQUIVALENT,
212 /* min, max, act ct */ 0, 1, 0,
213 /* opt state flags */ OPTST_MORE_HELP_FLAGS, 0,
214 /* last opt argumnt */ { NULL },
215 /* arg list/cookie */ NULL,
216 /* must/cannot opts */ NULL, NULL,
217 /* option proc */ optionPagedUsage,
218 /* desc, NAME, name */ zMore_HelpText, NULL, zMore_Help_Name,
219 /* disablement strs */ NULL, NULL },
220
221 { /* entry idx, value */ INDEX_OPT_SAVE_OPTS, VALUE_OPT_SAVE_OPTS,
222 /* equiv idx value */ NO_EQUIVALENT, 0,
223 /* equivalenced to */ NO_EQUIVALENT,
224 /* min, max, act ct */ 0, 1, 0,
225 /* opt state flags */ OPTST_SET_ARGTYPE(OPARG_TYPE_STRING)
226 | OPTST_ARG_OPTIONAL | OPTST_NO_INIT, 0,
227 /* last opt argumnt */ { NULL },
228 /* arg list/cookie */ NULL,
229 /* must/cannot opts */ NULL, NULL,
230 /* option proc */ NULL,
231 /* desc, NAME, name */ zSave_OptsText, NULL, zSave_Opts_Name,
232 /* disablement strs */ NULL, NULL },
233
234 { /* entry idx, value */ INDEX_OPT_LOAD_OPTS, VALUE_OPT_LOAD_OPTS,
235 /* equiv idx value */ NO_EQUIVALENT, 0,
236 /* equivalenced to */ NO_EQUIVALENT,
237 /* min, max, act ct */ 0, NOLIMIT, 0,
238 /* opt state flags */ OPTST_SET_ARGTYPE(OPARG_TYPE_STRING)
239 | OPTST_DISABLE_IMM, 0,
240 /* last opt argumnt */ { NULL },
241 /* arg list/cookie */ NULL,
242 /* must/cannot opts */ NULL, NULL,
243 /* option proc */ optionLoadOpt,
244 /* desc, NAME, name */ zLoad_OptsText, zLoad_Opts_NAME, zLoad_Opts_Name,
245 /* disablement strs */ zNotLoad_Opts_Name, zNotLoad_Opts_Pfx }
246 };
247
248 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
249 *
250 * Define the Ntpsnmpd Option Environment
251 */
252 static char const zPROGNAME[9] = "NTPSNMPD";
253 static char const zUsageTitle[103] =
254 "ntpsnmpd - NTP SNMP MIB agent - Ver. 4.2.6p5\n\
255 USAGE: %s [ -<flag> [<val>] | --<name>[{=| }<val>] ]...\n";
256 static char const zRcName[7] = ".ntprc";
257 static char const * const apzHomeList[3] = {
258 "$HOME",
259 ".",
260 NULL };
261
262 static char const zBugsAddr[34] = "http://bugs.ntp.org, bugs (at) ntp.org";
263 #define zExplain NULL
264 #define zDetail NULL
265 static char const zFullVersion[] = NTPSNMPD_FULL_VERSION;
266 /* extracted from optcode.tlib near line 515 */
267
268 #if defined(ENABLE_NLS)
269 # define OPTPROC_BASE OPTPROC_TRANSLATE
270 static tOptionXlateProc translate_option_strings;
271 #else
272 # define OPTPROC_BASE OPTPROC_NONE
273 # define translate_option_strings NULL
274 #endif /* ENABLE_NLS */
275
276
277 #define ntpsnmpd_full_usage NULL
278 #define ntpsnmpd_short_usage NULL
279 #ifndef PKGDATADIR
280 # define PKGDATADIR ""
281 #endif
282
283 #ifndef WITH_PACKAGER
284 # define ntpsnmpd_packager_info NULL
285 #else
286 static char const ntpsnmpd_packager_info[] =
287 "Packaged by " WITH_PACKAGER
288
289 # ifdef WITH_PACKAGER_VERSION
290 " ("WITH_PACKAGER_VERSION")"
291 # endif
292
293 # ifdef WITH_PACKAGER_BUG_REPORTS
294 "\nReport ntpsnmpd bugs to " WITH_PACKAGER_BUG_REPORTS
295 # endif
296 "\n";
297 #endif
298
299 tOptions ntpsnmpdOptions = {
300 OPTIONS_STRUCT_VERSION,
301 0, NULL, /* original argc + argv */
302 ( OPTPROC_BASE
303 + OPTPROC_ERRSTOP
304 + OPTPROC_SHORTOPT
305 + OPTPROC_LONGOPT
306 + OPTPROC_NO_REQ_OPT
307 + OPTPROC_ENVIRON
308 + OPTPROC_NO_ARGS
309 + OPTPROC_MISUSE ),
310 0, NULL, /* current option index, current option */
311 NULL, NULL, zPROGNAME,
312 zRcName, zCopyright, zLicenseDescrip,
313 zFullVersion, apzHomeList, zUsageTitle,
314 zExplain, zDetail, optDesc,
315 zBugsAddr, /* address to send bugs to */
316 NULL, NULL, /* extensions/saved state */
317 optionUsage, /* usage procedure */
318 translate_option_strings, /* translation procedure */
319 /*
320 * Indexes to special options
321 */
322 { INDEX_OPT_MORE_HELP, /* more-help option index */
323 INDEX_OPT_SAVE_OPTS, /* save option index */
324 NO_EQUIVALENT, /* '-#' option index */
325 NO_EQUIVALENT /* index of default opt */
326 },
327 8 /* full option count */, 3 /* user option count */,
328 ntpsnmpd_full_usage, ntpsnmpd_short_usage,
329 NULL, NULL,
330 PKGDATADIR, ntpsnmpd_packager_info
331 };
332
333 /*
334 * Create the static procedure(s) declared above.
335 */
336 static void
337 doUsageOpt(tOptions * pOptions, tOptDesc * pOptDesc)
338 {
339 (void)pOptions;
340 USAGE(NTPSNMPD_EXIT_SUCCESS);
341 }
342 /* extracted from optmain.tlib near line 128 */
343
344 #if defined(TEST_NTPSNMPD_OPTS) /* TEST MAIN PROCEDURE: */
345
346 extern void optionPutShell(tOptions*);
347
348 int
349 main(int argc, char ** argv)
350 {
351 int res = NTPSNMPD_EXIT_SUCCESS;
352 (void)optionProcess(&ntpsnmpdOptions, argc, argv);
353 optionPutShell(&ntpsnmpdOptions);
354 res = ferror(stdout);
355 if (res != 0)
356 fputs("output error writing to stdout\n", stderr);
357 return res;
358 }
359 #endif /* defined TEST_NTPSNMPD_OPTS */
360 /* extracted from optcode.tlib near line 666 */
361
362 #if ENABLE_NLS
363 #include <stdio.h>
364 #include <stdlib.h>
365 #include <string.h>
366 #include <unistd.h>
367 #include <autoopts/usage-txt.h>
368
369 static char* AO_gettext(char const* pz);
370 static void coerce_it(void** s);
371
372 static char*
373 AO_gettext(char const* pz)
374 {
375 char* pzRes;
376 if (pz == NULL)
377 return NULL;
378 pzRes = _(pz);
379 if (pzRes == pz)
380 return pzRes;
381 pzRes = strdup(pzRes);
382 if (pzRes == NULL) {
383 fputs(_("No memory for duping translated strings\n"), stderr);
384 exit(NTPSNMPD_EXIT_FAILURE);
385 }
386 return pzRes;
387 }
388
389 static void coerce_it(void** s) { *s = AO_gettext(*s);
390 }
391
392 /*
393 * This invokes the translation code (e.g. gettext(3)).
394 */
395 static void
396 translate_option_strings(void)
397 {
398 tOptions * const pOpt = &ntpsnmpdOptions;
399
400 /*
401 * Guard against re-translation. It won't work. The strings will have
402 * been changed by the first pass through this code. One shot only.
403 */
404 if (option_usage_text.field_ct != 0) {
405 /*
406 * Do the translations. The first pointer follows the field count
407 * field. The field count field is the size of a pointer.
408 */
409 tOptDesc * pOD = pOpt->pOptDesc;
410 char ** ppz = (char**)(void*)&(option_usage_text);
411 int ix = option_usage_text.field_ct;
412
413 do {
414 ppz++;
415 *ppz = AO_gettext(*ppz);
416 } while (--ix > 0);
417
418 coerce_it((void*)&(pOpt->pzCopyright));
419 coerce_it((void*)&(pOpt->pzCopyNotice));
420 coerce_it((void*)&(pOpt->pzFullVersion));
421 coerce_it((void*)&(pOpt->pzUsageTitle));
422 coerce_it((void*)&(pOpt->pzExplain));
423 coerce_it((void*)&(pOpt->pzDetail));
424 coerce_it((void*)&(pOpt->pzPackager));
425 option_usage_text.field_ct = 0;
426
427 for (ix = pOpt->optCt; ix > 0; ix--, pOD++)
428 coerce_it((void*)&(pOD->pzText));
429 }
430
431 if ((pOpt->fOptSet & OPTPROC_NXLAT_OPT_CFG) == 0) {
432 tOptDesc * pOD = pOpt->pOptDesc;
433 int ix;
434
435 for (ix = pOpt->optCt; ix > 0; ix--, pOD++) {
436 coerce_it((void*)&(pOD->pz_Name));
437 coerce_it((void*)&(pOD->pz_DisableName));
438 coerce_it((void*)&(pOD->pz_DisablePfx));
439 }
440 /* prevent re-translation */
441 ntpsnmpdOptions.fOptSet |= OPTPROC_NXLAT_OPT_CFG | OPTPROC_NXLAT_OPT;
442 }
443 }
444
445 #endif /* ENABLE_NLS */
446
447 #ifdef __cplusplus
448 }
449 #endif
450 /* ntpsnmpd-opts.c ends here */
451