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