Annotation of embedaddon/ntp/sntp/libopts/genshell.c, revision 1.1.1.1

1.1       misho       1: /*   -*- buffer-read-only: t -*- vi: set ro:
                      2:  *  
                      3:  *  DO NOT EDIT THIS FILE   (genshell.c)
                      4:  *  
                      5:  *  It has been AutoGen-ed  April 29, 2011 at 03:43:59 PM by AutoGen 5.11.9
                      6:  *  From the definitions    genshell.def
                      7:  *  and the template file   options
                      8:  *
                      9:  * Generated from AutoOpts 35:0:10 templates.
                     10:  *
                     11:  *  AutoOpts is a copyrighted work.  This source file is not encumbered
                     12:  *  by AutoOpts licensing, but is provided under the licensing terms chosen
                     13:  *  by the genshellopt author or copyright holder.  AutoOpts is
                     14:  *  licensed under the terms of the LGPL.  The redistributable library
                     15:  *  (``libopts'') is licensed under the terms of either the LGPL or, at the
                     16:  *  users discretion, the BSD license.  See the AutoOpts and/or libopts sources
                     17:  *  for details.
                     18:  *
                     19:  * This source file is copyrighted and licensed under the following terms:
                     20:  *
                     21:  * genshellopt copyright (c) 1999-2011 Bruce Korb - all rights reserved
                     22:  *
                     23:  * genshellopt is free software: you can redistribute it and/or modify it
                     24:  * under the terms of the GNU General Public License as published by the
                     25:  * Free Software Foundation, either version 3 of the License, or
                     26:  * (at your option) any later version.
                     27:  * 
                     28:  * genshellopt is distributed in the hope that it will be useful, but
                     29:  * WITHOUT ANY WARRANTY; without even the implied warranty of
                     30:  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
                     31:  * See the GNU General Public License for more details.
                     32:  * 
                     33:  * You should have received a copy of the GNU General Public License along
                     34:  * with this program.  If not, see <http://www.gnu.org/licenses/>.
                     35: 
                     36:  */
                     37: 
                     38: #include <sys/types.h>
                     39: 
                     40: #include <limits.h>
                     41: #include <stdio.h>
                     42: #include <stdlib.h>
                     43: 
                     44: #define OPTION_CODE_COMPILE 1
                     45: #include "genshell.h"
                     46: 
                     47: #ifdef  __cplusplus
                     48: extern "C" {
                     49: #endif
                     50: extern FILE * option_usage_fp;
                     51: 
                     52: /* TRANSLATORS: choose the translation for option names wisely because you
                     53:                 cannot ever change your mind. */
                     54: static char const zCopyright[260] =
                     55: "genshellopt 1\n\
                     56: Copyright (C) 1999-2011 Bruce Korb, all rights reserved.\n\
                     57: This is free software. It is licensed for use, modification and\n\
                     58: redistribution under the terms of the\n\
                     59: GNU General Public License, version 3 or later\n\
                     60:     <http://gnu.org/licenses/gpl.html>\n";
                     61: static char const zCopyrightNotice[611] =
                     62: "genshellopt is free software: you can redistribute it and/or modify it\n\
                     63: under the terms of the GNU General Public License as published by the\n\
                     64: Free Software Foundation, either version 3 of the License, or (at your\n\
                     65: option) any later version.\n\n\
                     66: genshellopt is distributed in the hope that it will be useful, but WITHOUT\n\
                     67: ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or\n\
                     68: FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License\n\
                     69: for more details.\n\n\
                     70: You should have received a copy of the GNU General Public License along\n\
                     71: with this program.  If not, see <http://www.gnu.org/licenses/>.\n";
                     72: 
                     73: extern tUsageProc genshelloptUsage;
                     74: 
                     75: #ifndef NULL
                     76: #  define NULL 0
                     77: #endif
                     78: 
                     79: /*
                     80:  *  Script option description:
                     81:  */
                     82: static char const zScriptText[] =
                     83:         "Output Script File";
                     84: static char const zScript_NAME[]             = "SCRIPT";
                     85: static char const zScript_Name[]             = "script";
                     86: #define SCRIPT_FLAGS       (OPTST_DISABLED \
                     87:         | OPTST_SET_ARGTYPE(OPARG_TYPE_STRING))
                     88: 
                     89: /*
                     90:  *  Shell option description:
                     91:  */
                     92: static char const zShellText[] =
                     93:         "Shell name (follows \"#!\" magic)";
                     94: static char const zShell_NAME[]              = "SHELL";
                     95: static char const zNotShell_Name[]           = "no-shell";
                     96: static char const zNotShell_Pfx[]            = "no";
                     97: #define zShell_Name                  (zNotShell_Name + 3)
                     98: #define SHELL_FLAGS       (OPTST_INITENABLED \
                     99:         | OPTST_SET_ARGTYPE(OPARG_TYPE_STRING))
                    100: 
                    101: /*
                    102:  *  Help/More_Help/Version option descriptions:
                    103:  */
                    104: static char const zHelpText[]          = "Display extended usage information and exit";
                    105: static char const zHelp_Name[]         = "help";
                    106: #ifdef HAVE_WORKING_FORK
                    107: #define OPTST_MORE_HELP_FLAGS   (OPTST_IMM | OPTST_NO_INIT)
                    108: static char const zMore_Help_Name[]    = "more-help";
                    109: static char const zMore_HelpText[]     = "Extended usage information passed thru pager";
                    110: #else
                    111: #define OPTST_MORE_HELP_FLAGS   (OPTST_OMITTED | OPTST_NO_INIT)
                    112: #define zMore_Help_Name   NULL
                    113: #define zMore_HelpText    NULL
                    114: #endif
                    115: #ifdef NO_OPTIONAL_OPT_ARGS
                    116: #  define OPTST_VERSION_FLAGS   OPTST_IMM | OPTST_NO_INIT
                    117: #else
                    118: #  define OPTST_VERSION_FLAGS   OPTST_SET_ARGTYPE(OPARG_TYPE_STRING) | \
                    119:                                 OPTST_ARG_OPTIONAL | OPTST_IMM | OPTST_NO_INIT
                    120: #endif
                    121: 
                    122: static char const zVersionText[]       = "Output version information and exit";
                    123: static char const zVersion_Name[]      = "version";
                    124: /*
                    125:  *  Declare option callback procedures
                    126:  */
                    127: extern tOptProc
                    128:     optionBooleanVal,    optionNestedVal,     optionNumericVal,
                    129:     optionPagedUsage,    optionPrintVersion,  optionResetOpt,
                    130:     optionStackArg,      optionTimeDate,      optionTimeVal,
                    131:     optionUnstackArg,    optionVersionStderr;
                    132: static tOptProc
                    133:     doUsageOpt;
                    134: 
                    135: /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
                    136:  *
                    137:  *  Define the Genshellopt Option Descriptions.
                    138:  */
                    139: static tOptDesc optDesc[GENSHELL_OPTION_CT] = {
                    140:   {  /* entry idx, value */ 0, VALUE_GENSHELL_OPT_SCRIPT,
                    141:      /* equiv idx, value */ 0, VALUE_GENSHELL_OPT_SCRIPT,
                    142:      /* equivalenced to  */ NO_EQUIVALENT,
                    143:      /* min, max, act ct */ 0, 1, 0,
                    144:      /* opt state flags  */ SCRIPT_FLAGS, 0,
                    145:      /* last opt argumnt */ { NULL },
                    146:      /* arg list/cookie  */ NULL,
                    147:      /* must/cannot opts */ NULL, NULL,
                    148:      /* option proc      */ NULL,
                    149:      /* desc, NAME, name */ zScriptText, zScript_NAME, zScript_Name,
                    150:      /* disablement strs */ NULL, NULL },
                    151: 
                    152:   {  /* entry idx, value */ 1, VALUE_GENSHELL_OPT_SHELL,
                    153:      /* equiv idx, value */ 1, VALUE_GENSHELL_OPT_SHELL,
                    154:      /* equivalenced to  */ NO_EQUIVALENT,
                    155:      /* min, max, act ct */ 0, 1, 0,
                    156:      /* opt state flags  */ SHELL_FLAGS, 0,
                    157:      /* last opt argumnt */ { NULL },
                    158:      /* arg list/cookie  */ NULL,
                    159:      /* must/cannot opts */ NULL, NULL,
                    160:      /* option proc      */ NULL,
                    161:      /* desc, NAME, name */ zShellText, zShell_NAME, zShell_Name,
                    162:      /* disablement strs */ zNotShell_Name, zNotShell_Pfx },
                    163: 
                    164:   {  /* entry idx, value */ INDEX_GENSHELL_OPT_VERSION, VALUE_GENSHELL_OPT_VERSION,
                    165:      /* equiv idx value  */ NO_EQUIVALENT, 0,
                    166:      /* equivalenced to  */ NO_EQUIVALENT,
                    167:      /* min, max, act ct */ 0, 1, 0,
                    168:      /* opt state flags  */ OPTST_VERSION_FLAGS, 0,
                    169:      /* last opt argumnt */ { NULL },
                    170:      /* arg list/cookie  */ NULL,
                    171:      /* must/cannot opts */ NULL, NULL,
                    172:      /* option proc      */ optionPrintVersion,
                    173:      /* desc, NAME, name */ zVersionText, NULL, zVersion_Name,
                    174:      /* disablement strs */ NULL, NULL },
                    175: 
                    176: 
                    177: 
                    178:   {  /* entry idx, value */ INDEX_GENSHELL_OPT_HELP, VALUE_GENSHELL_OPT_HELP,
                    179:      /* equiv idx value  */ NO_EQUIVALENT, 0,
                    180:      /* equivalenced to  */ NO_EQUIVALENT,
                    181:      /* min, max, act ct */ 0, 1, 0,
                    182:      /* opt state flags  */ OPTST_IMM | OPTST_NO_INIT, 0,
                    183:      /* last opt argumnt */ { NULL },
                    184:      /* arg list/cookie  */ NULL,
                    185:      /* must/cannot opts */ NULL, NULL,
                    186:      /* option proc      */ doUsageOpt,
                    187:      /* desc, NAME, name */ zHelpText, NULL, zHelp_Name,
                    188:      /* disablement strs */ NULL, NULL },
                    189: 
                    190:   {  /* entry idx, value */ INDEX_GENSHELL_OPT_MORE_HELP, VALUE_GENSHELL_OPT_MORE_HELP,
                    191:      /* equiv idx value  */ NO_EQUIVALENT, 0,
                    192:      /* equivalenced to  */ NO_EQUIVALENT,
                    193:      /* min, max, act ct */ 0, 1, 0,
                    194:      /* opt state flags  */ OPTST_MORE_HELP_FLAGS, 0,
                    195:      /* last opt argumnt */ { NULL },
                    196:      /* arg list/cookie  */ NULL,
                    197:      /* must/cannot opts */ NULL,  NULL,
                    198:      /* option proc      */ optionPagedUsage,
                    199:      /* desc, NAME, name */ zMore_HelpText, NULL, zMore_Help_Name,
                    200:      /* disablement strs */ NULL, NULL }
                    201: };
                    202: 
                    203: /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
                    204:  *
                    205:  *  Define the Genshellopt Option Environment
                    206:  */
                    207: static char const zPROGNAME[12] = "GENSHELLOPT";
                    208: static char const zUsageTitle[121] =
                    209: "genshellopt - Generate Shell Option Processing Script - Ver. 1\n\
                    210: USAGE:  %s [ -<flag> [<val>] | --<name>[{=| }<val>] ]...\n";
                    211: #define zRcName     NULL
                    212: #define apzHomeList NULL
                    213: 
                    214: static char const zBugsAddr[36]    = "autogen-users@lists.sourceforge.net";
                    215: static char const zExplain[] = "\n\
                    216: Note that ``shell'' is only useful if the output file does not already\n\
                    217: exist.  If it does, then the shell name and optional first argument will\n\
                    218: be extracted from the script file.\n";
                    219: static char const zDetail[237] = "\n\
                    220: If the script file already exists and contains Automated Option Processing\n\
                    221: text, the second line of the file through the ending tag will be replaced\n\
                    222: by the newly generated text.  The first ``#!''  line will be regenerated.\n";
                    223: static char const zFullVersion[] = GENSHELLOPT_FULL_VERSION;
                    224: /* extracted from optcode.tlib near line 515 */
                    225: 
                    226: #if defined(ENABLE_NLS)
                    227: # define OPTPROC_BASE OPTPROC_TRANSLATE
                    228:   static tOptionXlateProc translate_option_strings;
                    229: #else
                    230: # define OPTPROC_BASE OPTPROC_NONE
                    231: # define translate_option_strings NULL
                    232: #endif /* ENABLE_NLS */
                    233: 
                    234: 
                    235: #define genshellopt_full_usage NULL
                    236: #define genshellopt_short_usage NULL
                    237: #ifndef  PKGDATADIR
                    238: # define PKGDATADIR ""
                    239: #endif
                    240: 
                    241: #ifndef  WITH_PACKAGER
                    242: # define genshellopt_packager_info NULL
                    243: #else
                    244: static char const genshellopt_packager_info[] =
                    245:     "Packaged by " WITH_PACKAGER
                    246: 
                    247: # ifdef WITH_PACKAGER_VERSION
                    248:         " ("WITH_PACKAGER_VERSION")"
                    249: # endif
                    250: 
                    251: # ifdef WITH_PACKAGER_BUG_REPORTS
                    252:     "\nReport genshellopt bugs to " WITH_PACKAGER_BUG_REPORTS
                    253: # endif
                    254:     "\n";
                    255: #endif
                    256: 
                    257: tOptions genshelloptOptions = {
                    258:     OPTIONS_STRUCT_VERSION,
                    259:     0, NULL,                    /* original argc + argv    */
                    260:     ( OPTPROC_BASE
                    261:     + OPTPROC_ERRSTOP
                    262:     + OPTPROC_SHORTOPT
                    263:     + OPTPROC_LONGOPT
                    264:     + OPTPROC_NO_REQ_OPT
                    265:     + OPTPROC_NEGATIONS
                    266:     + OPTPROC_NO_ARGS ),
                    267:     0, NULL,                    /* current option index, current option */
                    268:     NULL,         NULL,         zPROGNAME,
                    269:     zRcName,      zCopyright,   zCopyrightNotice,
                    270:     zFullVersion, apzHomeList,  zUsageTitle,
                    271:     zExplain,     zDetail,      optDesc,
                    272:     zBugsAddr,                  /* address to send bugs to */
                    273:     NULL, NULL,                 /* extensions/saved state  */
                    274:     genshelloptUsage, /* usage procedure */
                    275:     translate_option_strings,   /* translation procedure */
                    276:     /*
                    277:      *  Indexes to special options
                    278:      */
                    279:     { INDEX_GENSHELL_OPT_MORE_HELP, /* more-help option index */
                    280:       NO_EQUIVALENT, /* save option index */
                    281:       NO_EQUIVALENT, /* '-#' option index */
                    282:       NO_EQUIVALENT /* index of default opt */
                    283:     },
                    284:     5 /* full option count */, 2 /* user option count */,
                    285:     genshellopt_full_usage, genshellopt_short_usage,
                    286:     NULL, NULL,
                    287:     PKGDATADIR, genshellopt_packager_info
                    288: };
                    289: 
                    290: /*
                    291:  *  Create the static procedure(s) declared above.
                    292:  */
                    293: static void
                    294: doUsageOpt(tOptions * pOptions, tOptDesc * pOptDesc)
                    295: {
                    296:     (void)pOptions;
                    297:     GENSHELL_USAGE(GENSHELLOPT_EXIT_SUCCESS);
                    298: }
                    299: /* extracted from optcode.tlib near line 666 */
                    300: 
                    301: #if ENABLE_NLS
                    302: #include <stdio.h>
                    303: #include <stdlib.h>
                    304: #include <string.h>
                    305: #include <unistd.h>
                    306: #include <autoopts/usage-txt.h>
                    307: 
                    308: static char* AO_gettext(char const* pz);
                    309: static void  coerce_it(void** s);
                    310: 
                    311: static char*
                    312: AO_gettext(char const* pz)
                    313: {
                    314:     char* pzRes;
                    315:     if (pz == NULL)
                    316:         return NULL;
                    317:     pzRes = _(pz);
                    318:     if (pzRes == pz)
                    319:         return pzRes;
                    320:     pzRes = strdup(pzRes);
                    321:     if (pzRes == NULL) {
                    322:         fputs(_("No memory for duping translated strings\n"), stderr);
                    323:         exit(GENSHELLOPT_EXIT_FAILURE);
                    324:     }
                    325:     return pzRes;
                    326: }
                    327: 
                    328: static void coerce_it(void** s) { *s = AO_gettext(*s);
                    329: }
                    330: 
                    331: /*
                    332:  *  This invokes the translation code (e.g. gettext(3)).
                    333:  */
                    334: static void
                    335: translate_option_strings(void)
                    336: {
                    337:     tOptions * const pOpt = &genshelloptOptions;
                    338: 
                    339:     /*
                    340:      *  Guard against re-translation.  It won't work.  The strings will have
                    341:      *  been changed by the first pass through this code.  One shot only.
                    342:      */
                    343:     if (option_usage_text.field_ct != 0) {
                    344:         /*
                    345:          *  Do the translations.  The first pointer follows the field count
                    346:          *  field.  The field count field is the size of a pointer.
                    347:          */
                    348:         tOptDesc * pOD = pOpt->pOptDesc;
                    349:         char **    ppz = (char**)(void*)&(option_usage_text);
                    350:         int        ix  = option_usage_text.field_ct;
                    351: 
                    352:         do {
                    353:             ppz++;
                    354:             *ppz = AO_gettext(*ppz);
                    355:         } while (--ix > 0);
                    356: 
                    357:         coerce_it((void*)&(pOpt->pzCopyright));
                    358:         coerce_it((void*)&(pOpt->pzCopyNotice));
                    359:         coerce_it((void*)&(pOpt->pzFullVersion));
                    360:         coerce_it((void*)&(pOpt->pzUsageTitle));
                    361:         coerce_it((void*)&(pOpt->pzExplain));
                    362:         coerce_it((void*)&(pOpt->pzDetail));
                    363:         coerce_it((void*)&(pOpt->pzPackager));
                    364:         option_usage_text.field_ct = 0;
                    365: 
                    366:         for (ix = pOpt->optCt; ix > 0; ix--, pOD++)
                    367:             coerce_it((void*)&(pOD->pzText));
                    368:     }
                    369: 
                    370:     if ((pOpt->fOptSet & OPTPROC_NXLAT_OPT_CFG) == 0) {
                    371:         tOptDesc * pOD = pOpt->pOptDesc;
                    372:         int        ix;
                    373: 
                    374:         for (ix = pOpt->optCt; ix > 0; ix--, pOD++) {
                    375:             coerce_it((void*)&(pOD->pz_Name));
                    376:             coerce_it((void*)&(pOD->pz_DisableName));
                    377:             coerce_it((void*)&(pOD->pz_DisablePfx));
                    378:         }
                    379:         /* prevent re-translation */
                    380:         genshelloptOptions.fOptSet |= OPTPROC_NXLAT_OPT_CFG | OPTPROC_NXLAT_OPT;
                    381:     }
                    382: }
                    383: 
                    384: #endif /* ENABLE_NLS */
                    385: 
                    386: #ifdef  __cplusplus
                    387: }
                    388: #endif
                    389: /* genshell.c ends here */

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>