]> git.ipfire.org Git - thirdparty/ntp.git/commitdiff
Upgrade to autogen-5.14 (and libopts-36.1.11)
authorHarlan Stenn <stenn@ntp.org>
Wed, 25 Jan 2012 09:54:11 +0000 (09:54 +0000)
committerHarlan Stenn <stenn@ntp.org>
Wed, 25 Jan 2012 09:54:11 +0000 (09:54 +0000)
bk: 4f1fd1436EBEzIqX4BtMcHZ5IBFlbw

26 files changed:
ChangeLog
sntp/include/autogen-version.def
sntp/libopts/Makefile.am
sntp/libopts/ag-char-map.h
sntp/libopts/autoopts.c
sntp/libopts/autoopts/options.h
sntp/libopts/autoopts/usage-txt.h
sntp/libopts/check.c [new file with mode: 0644]
sntp/libopts/configfile.c
sntp/libopts/enum.c [moved from sntp/libopts/enumeration.c with 100% similarity]
sntp/libopts/env.c [moved from sntp/libopts/environment.c with 93% similarity]
sntp/libopts/file.c
sntp/libopts/find.c [new file with mode: 0644]
sntp/libopts/genshell.c
sntp/libopts/genshell.h
sntp/libopts/libopts.c
sntp/libopts/load.c
sntp/libopts/m4/libopts.m4
sntp/libopts/proto.h
sntp/libopts/reset.c
sntp/libopts/sort.c
sntp/libopts/text_mmap.c
sntp/libopts/usage.c
sntp/libopts/value-type.h
sntp/libopts/version.c
sntp/libopts/xat-attribute.h

index cb79fabf0becede7ef2034c5369fc0a1fc29b58f..75b2c5b5edab31c1ae9f9265968d00885b9200cb 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,4 @@
+* Upgrade to autogen-5.14 (and libopts-36.1.11).
 (4.2.7p251) 2012/01/17 Released by Harlan Stenn <stenn@ntp.org>
 * [Bug 2115] ntptrace should accept both rootdispersion and rootdisp.
 (4.2.7p250) 2012/01/15 Released by Harlan Stenn <stenn@ntp.org>
index f548afa1b5696380028eb395708383c9996a2de0..96c37208482d29c2b4f3b3b253b6b058500e4ab2 100644 (file)
@@ -1,2 +1,2 @@
-#assert (version-compare >= autogen-version "5.12")
+#assert (version-compare >= autogen-version "5.14")
 guard-option-names;
index a94972e057718eb441f93ec420781471cb58c38d..0108d85957ff5d291fe356bba282de00506540c1 100644 (file)
@@ -7,22 +7,23 @@ noinst_LTLIBRARIES      = libopts.la
 endif
 libopts_la_SOURCES      = libopts.c
 libopts_la_CPPFLAGS     = -I$(top_srcdir)
-libopts_la_LDFLAGS      = -version-info  35:0:10
+libopts_la_LDFLAGS      = -version-info  36:1:11
 EXTRA_DIST              = \
     COPYING.gplv3           COPYING.lgplv3          COPYING.mbsd  \
     MakeDefs.inc            README                  ag-char-map.h  \
-    autoopts/usage-txt.h    autoopts/options.h      autoopts/project.h  \
+    autoopts/options.h      autoopts/usage-txt.h    autoopts/project.h  \
     autoopts.c              autoopts.h              boolean.c  \
-    compat/strdup.c         compat/compat.h         compat/windows-config.h  \
-    compat/snprintf.c       compat/strchr.c         compat/pathfind.c  \
-    configfile.c            cook.c                  enumeration.c  \
-    environment.c           file.c                  genshell.c  \
-    genshell.h              load.c                  m4/liboptschk.m4  \
-    m4/libopts.m4           makeshell.c             nested.c  \
-    numeric.c               parse-duration.c        parse-duration.h  \
-    pgusage.c               proto.h                 putshell.c  \
-    reset.c                 restore.c               save.c  \
-    sort.c                  stack.c                 streqvcmp.c  \
-    text_mmap.c             time.c                  tokenize.c  \
-    usage.c                 value-type.c            value-type.h  \
-    version.c               xat-attribute.c         xat-attribute.h
+    check.c                 compat/pathfind.c       compat/compat.h  \
+    compat/strdup.c         compat/snprintf.c       compat/strchr.c  \
+    compat/windows-config.h configfile.c            cook.c  \
+    enum.c                  env.c                   file.c  \
+    find.c                  genshell.c              genshell.h  \
+    load.c                  m4/libopts.m4           m4/liboptschk.m4  \
+    makeshell.c             nested.c                numeric.c  \
+    parse-duration.c        parse-duration.h        pgusage.c  \
+    proto.h                 putshell.c              reset.c  \
+    restore.c               save.c                  sort.c  \
+    stack.c                 streqvcmp.c             text_mmap.c  \
+    time.c                  tokenize.c              usage.c  \
+    value-type.c            value-type.h            version.c  \
+    xat-attribute.c         xat-attribute.h
index b4f088ef3a4baa3c425a26988401c523f119cf4f..0fb9794d41f9dc72e3dbc226ae98e2fc760214f3 100644 (file)
@@ -1,10 +1,10 @@
 /*
- *   Character mapping generated 04/29/11 15:43:58
+ *   Character mapping generated 12/29/11 12:02:33
  *
  *  This file contains the character classifications
  *  used by AutoGen and AutoOpts for identifying tokens.
  *  This file is part of AutoGen.
- *  AutoGen Copyright (c) 1992-2011 by Bruce Korb - all rights reserved
+ *  Copyright (c) 1992-2011 Bruce Korb - all rights reserved
  *  AutoGen is free software: you can redistribute it and/or modify it under the
  *  terms of the GNU General Public License as published by the Free Software
  *  Foundation, either version 3 of the License, or (at your option) any later
@@ -77,7 +77,7 @@
 //   used by AutoGen and AutoOpts for identifying tokens.
 // 
 //   This file is part of AutoGen.
-//   AutoGen Copyright (c) 1992-2011 by Bruce Korb - all rights reserved
+//   Copyright (c) 1992-2011 Bruce Korb - all rights reserved
 // 
 //   AutoGen is free software: you can redistribute it and/or modify it under the
 //   terms of the GNU General Public License as published by the Free Software
index 657818181b82b7a8590fc61398dc209cad2aa12e..c1129f2a0128efd092cf92984e691ee9209ac41d 100644 (file)
@@ -2,7 +2,7 @@
 /**
  * \file autoopts.c
  *
- *  Time-stamp:      "2011-03-25 17:55:07 bkorb"
+ *  Time-stamp:      "2011-08-07 14:31:49 bkorb"
  *
  *  This file contains all of the routines that must be linked into
  *  an executable to use the generated option processing.  The optional
@@ -36,7 +36,7 @@
 
 static char const   zNil[] = "";
 static arg_types_t  argTypes             = { NULL };
-static char         zOptFmtLine[16]      = { NUL };
+static char         zOptFmtLine[32]      = { NUL };
 static ag_bool      displayEnum          = AG_FALSE;
 static char const   pkgdatadir_default[] = PKGDATADIR;
 static char const * program_pkgdatadir   = pkgdatadir_default;
@@ -47,25 +47,19 @@ static tePagerState pagerState           = PAGER_STATE_INITIAL;
 
 /* = = = START-STATIC-FORWARD = = = */
 static tSuccess
-findOptDesc(tOptions* pOpts, tOptState* pOptState);
+next_opt_arg_must(tOptions * pOpts, tOptState* pOptState);
 
 static tSuccess
-next_opt_arg_must(tOptions* pOpts, tOptState* pOptState);
+next_opt_arg_may(tOptions * pOpts, tOptState* pOptState);
 
 static tSuccess
-next_opt_arg_may(tOptions* pOpts, tOptState* pOptState);
+next_opt_arg_none(tOptions * pOpts, tOptState* pOptState);
 
 static tSuccess
-next_opt_arg_none(tOptions* pOpts, tOptState* pOptState);
+next_opt(tOptions * pOpts, tOptState * pOptState);
 
 static tSuccess
-nextOption(tOptions* pOpts, tOptState* pOptState);
-
-static tSuccess
-doPresets(tOptions* pOpts);
-
-static int
-checkConsistency(tOptions* pOpts);
+doPresets(tOptions * pOpts);
 /* = = = END-STATIC-FORWARD = = = */
 
 LOCAL void *
@@ -130,7 +124,7 @@ ao_strdup(char const *str)
  *  invokes the handler procedure, if any.
  */
 LOCAL tSuccess
-handle_opt(tOptions* pOpts, tOptState* pOptState)
+handle_opt(tOptions * pOpts, tOptState* pOptState)
 {
     /*
      *  Save a copy of the option procedure pointer.
@@ -248,336 +242,8 @@ handle_opt(tOptions* pOpts, tOptState* pOptState)
     return SUCCESS;
 }
 
-
-/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- *
- *  HUNT FOR OPTIONS IN THE ARGUMENT LIST
- *
- *  The next four procedures are "private" to nextOption().
- *  nextOption() uses findOptDesc() to find the next descriptor and it, in
- *  turn, uses longOptionFind() and shortOptionFind() to actually do the hunt.
- *
- *  longOptionFind
- *
- *  Find the long option descriptor for the current option
- */
-LOCAL tSuccess
-longOptionFind(tOptions* pOpts, char* pzOptName, tOptState* pOptState)
-{
-    ag_bool    disable  = AG_FALSE;
-    char*      pzEq     = strchr(pzOptName, '=');
-    tOptDesc*  pOD      = pOpts->pOptDesc;
-    int        idx      = 0;
-    int        idxLim   = pOpts->optCt;
-    int        matchCt  = 0;
-    int        matchIdx = 0;
-    int        nameLen;
-    char       opt_name_buf[128];
-
-    /*
-     *  IF the value is attached to the name,
-     *  copy it off so we can NUL terminate.
-     */
-    if (pzEq != NULL) {
-        nameLen = (int)(pzEq - pzOptName);
-        if (nameLen >= sizeof(opt_name_buf))
-            return FAILURE;
-        memcpy(opt_name_buf, pzOptName, nameLen);
-        opt_name_buf[nameLen] = NUL;
-        pzOptName = opt_name_buf;
-        pzEq++;
-
-    } else nameLen = strlen(pzOptName);
-
-    do  {
-        /*
-         *  If option disabled or a doc option, skip to next
-         */
-        if (pOD->pz_Name == NULL)
-            continue;
-
-        if (  SKIP_OPT(pOD)
-           && (pOD->fOptState != (OPTST_OMITTED | OPTST_NO_INIT)))
-            continue;
-
-        if (strneqvcmp(pzOptName, pOD->pz_Name, nameLen) == 0) {
-            /*
-             *  IF we have a complete match
-             *  THEN it takes priority over any already located partial
-             */
-            if (pOD->pz_Name[ nameLen ] == NUL) {
-                matchCt  = 1;
-                matchIdx = idx;
-                break;
-            }
-        }
-
-        /*
-         *  IF       there is a disable name
-         *     *AND* no argument value has been supplied
-         *              (disabled options may have no argument)
-         *     *AND* the option name matches the disable name
-         *  THEN ...
-         */
-        else if (  (pOD->pz_DisableName != NULL)
-                && (strneqvcmp(pzOptName, pOD->pz_DisableName, nameLen) == 0)
-                )  {
-            disable  = AG_TRUE;
-
-            /*
-             *  IF we have a complete match
-             *  THEN it takes priority over any already located partial
-             */
-            if (pOD->pz_DisableName[ nameLen ] == NUL) {
-                matchCt  = 1;
-                matchIdx = idx;
-                break;
-            }
-        }
-
-        else
-            continue;
-
-        /*
-         *  We found a partial match, either regular or disabling.
-         *  Remember the index for later.
-         */
-        matchIdx = idx;
-
-        if (++matchCt > 1)
-            break;
-
-    } while (pOD++, (++idx < idxLim));
-
-    /*
-     *  Make sure we either found an exact match or found only one partial
-     */
-    if (matchCt == 1) {
-        pOD = pOpts->pOptDesc + matchIdx;
-
-        if (SKIP_OPT(pOD)) {
-            fprintf(stderr, zDisabledErr, pOpts->pzProgName, pOD->pz_Name);
-            if (pOD->pzText != NULL)
-                fprintf(stderr, " -- %s", pOD->pzText);
-            fputc('\n', stderr);
-            (*pOpts->pUsageProc)(pOpts, EXIT_FAILURE);
-            /* NOTREACHED */
-        }
-
-        /*
-         *  IF we found a disablement name,
-         *  THEN set the bit in the callers' flag word
-         */
-        if (disable)
-            pOptState->flags |= OPTST_DISABLED;
-
-        pOptState->pOD      = pOD;
-        pOptState->pzOptArg = pzEq;
-        pOptState->optType  = TOPT_LONG;
-        return SUCCESS;
-    }
-
-    /*
-     *  IF there is no equal sign
-     *     *AND* we are using named arguments
-     *     *AND* there is a default named option,
-     *  THEN return that option.
-     */
-    if (  (pzEq == NULL)
-       && NAMED_OPTS(pOpts)
-       && (pOpts->specOptIdx.default_opt != NO_EQUIVALENT)) {
-        pOptState->pOD = pOpts->pOptDesc + pOpts->specOptIdx.default_opt;
-
-        pOptState->pzOptArg = pzOptName;
-        pOptState->optType  = TOPT_DEFAULT;
-        return SUCCESS;
-    }
-
-    /*
-     *  IF we are to stop on errors (the default, actually)
-     *  THEN call the usage procedure.
-     */
-    if ((pOpts->fOptSet & OPTPROC_ERRSTOP) != 0) {
-        fprintf(stderr, (matchCt == 0) ? zIllOptStr : zAmbigOptStr,
-                pOpts->pzProgPath, pzOptName);
-        (*pOpts->pUsageProc)(pOpts, EXIT_FAILURE);
-    }
-
-    return FAILURE;
-}
-
-
-/*
- *  shortOptionFind
- *
- *  Find the short option descriptor for the current option
- */
-LOCAL tSuccess
-shortOptionFind(tOptions* pOpts, uint_t optValue, tOptState* pOptState)
-{
-    tOptDesc*  pRes = pOpts->pOptDesc;
-    int        ct   = pOpts->optCt;
-
-    /*
-     *  Search the option list
-     */
-    do  {
-        if (optValue != pRes->optValue)
-            continue;
-
-        if (SKIP_OPT(pRes)) {
-            if (  (pRes->fOptState == (OPTST_OMITTED | OPTST_NO_INIT))
-               && (pRes->pz_Name != NULL)) {
-                fprintf(stderr, zDisabledErr, pOpts->pzProgPath, pRes->pz_Name);
-                if (pRes->pzText != NULL)
-                    fprintf(stderr, " -- %s", pRes->pzText);
-                fputc('\n', stderr);
-                (*pOpts->pUsageProc)(pOpts, EXIT_FAILURE);
-                /* NOTREACHED */
-            }
-            goto short_opt_error;
-        }
-
-        pOptState->pOD     = pRes;
-        pOptState->optType = TOPT_SHORT;
-        return SUCCESS;
-
-    } while (pRes++, --ct > 0);
-
-    /*
-     *  IF    the character value is a digit
-     *    AND there is a special number option ("-n")
-     *  THEN the result is the "option" itself and the
-     *       option is the specially marked "number" option.
-     */
-    if (  IS_DEC_DIGIT_CHAR(optValue)
-       && (pOpts->specOptIdx.number_option != NO_EQUIVALENT) ) {
-        pOptState->pOD = \
-        pRes           = pOpts->pOptDesc + pOpts->specOptIdx.number_option;
-        (pOpts->pzCurOpt)--;
-        pOptState->optType = TOPT_SHORT;
-        return SUCCESS;
-    }
-
-short_opt_error:
-
-    /*
-     *  IF we are to stop on errors (the default, actually)
-     *  THEN call the usage procedure.
-     */
-    if ((pOpts->fOptSet & OPTPROC_ERRSTOP) != 0) {
-        fprintf(stderr, zIllOptChr, pOpts->pzProgPath, optValue);
-        (*pOpts->pUsageProc)(pOpts, EXIT_FAILURE);
-    }
-
-    return FAILURE;
-}
-
-
-/*
- *  findOptDesc
- *
- *  Find the option descriptor for the current option
- */
 static tSuccess
-findOptDesc(tOptions* pOpts, tOptState* pOptState)
-{
-    /*
-     *  IF we are continuing a short option list (e.g. -xyz...)
-     *  THEN continue a single flag option.
-     *  OTHERWISE see if there is room to advance and then do so.
-     */
-    if ((pOpts->pzCurOpt != NULL) && (*pOpts->pzCurOpt != NUL))
-        return shortOptionFind(pOpts, (tAoUC)*(pOpts->pzCurOpt), pOptState);
-
-    if (pOpts->curOptIdx >= pOpts->origArgCt)
-        return PROBLEM; /* NORMAL COMPLETION */
-
-    pOpts->pzCurOpt = pOpts->origArgVect[ pOpts->curOptIdx ];
-
-    /*
-     *  IF all arguments must be named options, ...
-     */
-    if (NAMED_OPTS(pOpts)) {
-        char *   pz  = pOpts->pzCurOpt;
-        int      def;
-        tSuccess res; 
-        tAoUS *  def_opt;
-
-        pOpts->curOptIdx++;
-
-        if (*pz != '-')
-            return longOptionFind(pOpts, pz, pOptState);
-
-        /*
-         *  The name is prefixed with one or more hyphens.  Strip them off
-         *  and disable the "default_opt" setting.  Use heavy recasting to
-         *  strip off the "const" quality of the "default_opt" field.
-         */
-        while (*(++pz) == '-')   ;
-        def_opt = (void *)&(pOpts->specOptIdx.default_opt);
-        def = *def_opt;
-        *def_opt = NO_EQUIVALENT;
-        res = longOptionFind(pOpts, pz, pOptState);
-        *def_opt = def;
-        return res;
-    }
-
-    /*
-     *  Note the kind of flag/option marker
-     */
-    if (*((pOpts->pzCurOpt)++) != '-')
-        return PROBLEM; /* NORMAL COMPLETION - this + rest are operands */
-
-    /*
-     *  Special hack for a hyphen by itself
-     */
-    if (*(pOpts->pzCurOpt) == NUL)
-        return PROBLEM; /* NORMAL COMPLETION - this + rest are operands */
-
-    /*
-     *  The current argument is to be processed as an option argument
-     */
-    pOpts->curOptIdx++;
-
-    /*
-     *  We have an option marker.
-     *  Test the next character for long option indication
-     */
-    if (pOpts->pzCurOpt[0] == '-') {
-        if (*++(pOpts->pzCurOpt) == NUL)
-            /*
-             *  NORMAL COMPLETION - NOT this arg, but rest are operands
-             */
-            return PROBLEM;
-
-        /*
-         *  We do not allow the hyphen to be used as a flag value.
-         *  Therefore, if long options are not to be accepted, we punt.
-         */
-        if ((pOpts->fOptSet & OPTPROC_LONGOPT) == 0) {
-            fprintf(stderr, zIllOptStr, pOpts->pzProgPath,
-                    zIllegal, pOpts->pzCurOpt-2);
-            return FAILURE;
-        }
-
-        return longOptionFind(pOpts, pOpts->pzCurOpt, pOptState);
-    }
-
-    /*
-     *  If short options are not allowed, then do long
-     *  option processing.  Otherwise the character must be a
-     *  short (i.e. single character) option.
-     */
-    if ((pOpts->fOptSet & OPTPROC_SHORTOPT) != 0)
-        return shortOptionFind(pOpts, (tAoUC)*(pOpts->pzCurOpt), pOptState);
-
-    return longOptionFind(pOpts, pOpts->pzCurOpt, pOptState);
-}
-
-
-static tSuccess
-next_opt_arg_must(tOptions* pOpts, tOptState* pOptState)
+next_opt_arg_must(tOptions * pOpts, tOptState* pOptState)
 {
     /*
      *  An option argument is required.  Long options can either have
@@ -631,7 +297,7 @@ next_opt_arg_must(tOptions* pOpts, tOptState* pOptState)
 
 
 static tSuccess
-next_opt_arg_may(tOptions* pOpts, tOptState* pOptState)
+next_opt_arg_may(tOptions * pOpts, tOptState* pOptState)
 {
     /*
      *  An option argument is optional.
@@ -698,7 +364,7 @@ next_opt_arg_may(tOptions* pOpts, tOptState* pOptState)
 
 
 static tSuccess
-next_opt_arg_none(tOptions* pOpts, tOptState* pOptState)
+next_opt_arg_none(tOptions * pOpts, tOptState* pOptState)
 {
     /*
      *  No option argument.  Make sure next time around we find
@@ -723,20 +389,20 @@ next_opt_arg_none(tOptions* pOpts, tOptState* pOptState)
     return SUCCESS;
 }
 
-/*
- *  nextOption
- *
+/**
  *  Find the option descriptor and option argument (if any) for the
  *  next command line argument.  DO NOT modify the descriptor.  Put
  *  all the state in the state argument so that the option can be skipped
  *  without consequence (side effect).
+ *
+ * @param pOpts     the program option descriptor
+ * @param pOptState the state of the next found option
  */
 static tSuccess
-nextOption(tOptions* pOpts, tOptState* pOptState)
+next_opt(tOptions * pOpts, tOptState * pOptState)
 {
     {
-        tSuccess res;
-        res = findOptDesc(pOpts, pOptState);
+        tSuccess res = find_opt(pOpts, pOptState);
         if (! SUCCESSFUL(res))
             return res;
     }
@@ -747,38 +413,7 @@ nextOption(tOptions* pOpts, tOptState* pOptState)
         return FAILURE;
     }
 
-    pOptState->flags |= (pOptState->pOD->fOptState & OPTST_PERSISTENT_MASK);
-
-    /*
-     *  Figure out what to do about option arguments.  An argument may be
-     *  required, not associated with the option, or be optional.  We detect the
-     *  latter by examining for an option marker on the next possible argument.
-     *  Disabled mode option selection also disables option arguments.
-     */
-    {
-        enum { ARG_NONE, ARG_MAY, ARG_MUST } arg_type = ARG_NONE;
-        tSuccess res;
-
-        if ((pOptState->flags & OPTST_DISABLED) != 0)
-            arg_type = ARG_NONE;
-
-        else if (OPTST_GET_ARGTYPE(pOptState->flags) == OPARG_TYPE_NONE)
-            arg_type = ARG_NONE;
-
-        else if (pOptState->flags & OPTST_ARG_OPTIONAL)
-            arg_type = ARG_MAY;
-
-        else
-            arg_type = ARG_MUST;
-
-        switch (arg_type) {
-        case ARG_MUST: res = next_opt_arg_must(pOpts, pOptState); break;
-        case ARG_MAY:  res = next_opt_arg_may( pOpts, pOptState); break;
-        case ARG_NONE: res = next_opt_arg_none(pOpts, pOptState); break;
-        }
-
-        return res;
-    }
+    return get_opt_arg(pOpts, pOptState);
 }
 
 
@@ -798,10 +433,17 @@ nextOption(tOptions* pOpts, tOptState* pOptState)
 /**
  *  scan the command line for immediate action options.
  *  This is only called the first time through.
+ *  While this procedure is active, the OPTPROC_IMMEDIATE is true.
+ *
+ *  @param pOpts   program options descriptor
+ *  @returns SUCCESS or FAILURE
  */
 LOCAL tSuccess
-doImmediateOpts(tOptions* pOpts)
+immediate_opts(tOptions * pOpts)
 {
+    tSuccess  res;
+
+    pOpts->fOptSet  |= OPTPROC_IMMEDIATE;
     pOpts->curOptIdx = 1;     /* start by skipping program name */
     pOpts->pzCurOpt  = NULL;
 
@@ -812,9 +454,10 @@ doImmediateOpts(tOptions* pOpts)
     for (;;) {
         tOptState optState = OPTSTATE_INITIALIZER(PRESET);
 
-        switch (nextOption(pOpts, &optState)) {
+        res = next_opt(pOpts, &optState);
+        switch (res) {
         case FAILURE: goto   failed_option;
-        case PROBLEM: return SUCCESS; /* no more args */
+        case PROBLEM: res = SUCCESS; goto leave;
         case SUCCESS: break;
         }
 
@@ -831,7 +474,10 @@ doImmediateOpts(tOptions* pOpts)
     if ((pOpts->fOptSet & OPTPROC_ERRSTOP) != 0)
         (*pOpts->pUsageProc)(pOpts, EXIT_FAILURE);
 
-    return FAILURE;
+leave:
+
+    pOpts->fOptSet &= ~OPTPROC_IMMEDIATE;
+    return res;
 }
 
 /**
@@ -839,14 +485,18 @@ doImmediateOpts(tOptions* pOpts)
  * interspersed options and arguments for the few non-standard programs that
  * require it.)  Thus, do not rewind option indexes because some programs
  * choose to re-invoke after a non-option.
+ *
+ *  @param pOpts   program options descriptor
+ *  @returns SUCCESS or FAILURE
  */
 LOCAL tSuccess
-doRegularOpts(tOptions* pOpts)
+regular_opts(tOptions * pOpts)
 {
+    /* assert:  pOpts->fOptSet & OPTPROC_IMMEDIATE == 0 */
     for (;;) {
         tOptState optState = OPTSTATE_INITIALIZER(DEFINED);
 
-        switch (nextOption(pOpts, &optState)) {
+        switch (next_opt(pOpts, &optState)) {
         case FAILURE: goto   failed_option;
         case PROBLEM: return SUCCESS; /* no more args */
         case SUCCESS: break;
@@ -877,11 +527,11 @@ doRegularOpts(tOptions* pOpts)
  *  check for preset values from a config files or envrionment variables
  */
 static tSuccess
-doPresets(tOptions* pOpts)
+doPresets(tOptions * pOpts)
 {
     tOptDesc * pOD = NULL;
 
-    if (! SUCCESSFUL(doImmediateOpts(pOpts)))
+    if (! SUCCESSFUL(immediate_opts(pOpts)))
         return FAILURE;
 
     /*
@@ -905,145 +555,28 @@ doPresets(tOptions* pOpts)
      *  THEN do any environment presets and leave.
      */
     if (pOpts->papzHomeList == NULL) {
-        doEnvPresets(pOpts, ENV_ALL);
+        env_presets(pOpts, ENV_ALL);
     }
     else {
-        doEnvPresets(pOpts, ENV_IMM);
+        env_presets(pOpts, ENV_IMM);
 
         /*
          *  Check to see if environment variables have disabled presetting.
          */
         if ((pOD != NULL) && ! DISABLED_OPT(pOD))
-            internalFileLoad(pOpts);
+            intern_file_load(pOpts);
 
         /*
          *  ${PROGRAM_LOAD_OPTS} value of "no" cannot disable other environment
          *  variable options.  Only the loading of .rc files.
          */
-        doEnvPresets(pOpts, ENV_NON_IMM);
+        env_presets(pOpts, ENV_NON_IMM);
     }
     pOpts->fOptSet &= ~OPTPROC_PRESETTING;
 
     return SUCCESS;
 }
 
-
-/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- *
- *  VERIFY OPTION CONSISTENCY
- *
- *  Make sure that the argument list passes our consistency tests.
- */
-static int
-checkConsistency(tOptions* pOpts)
-{
-    int        errCt = 0;
-    tOptDesc*  pOD   = pOpts->pOptDesc;
-    int        oCt   = pOpts->presetOptCt;
-
-    /*
-     *  FOR each of "oCt" options, ...
-     */
-    for (;;) {
-        const int*  pMust = pOD->pOptMust;
-        const int*  pCant = pOD->pOptCant;
-
-        /*
-         *  IF the current option was provided on the command line
-         *  THEN ensure that any "MUST" requirements are not
-         *       "DEFAULT" (unspecified) *AND* ensure that any
-         *       "CANT" options have not been SET or DEFINED.
-         */
-        if (SELECTED_OPT(pOD)) {
-            if (pMust != NULL) for (;;) {
-                tOptDesc*  p = pOpts->pOptDesc + *(pMust++);
-                if (UNUSED_OPT(p)) {
-                    const tOptDesc* pN = pOpts->pOptDesc + pMust[-1];
-                    errCt++;
-                    fprintf(stderr, zReqFmt, pOD->pz_Name, pN->pz_Name);
-                }
-
-                if (*pMust == NO_EQUIVALENT)
-                    break;
-            }
-
-            if (pCant != NULL) for (;;) {
-                tOptDesc*  p = pOpts->pOptDesc + *(pCant++);
-                if (SELECTED_OPT(p)) {
-                    const tOptDesc* pN = pOpts->pOptDesc + pCant[-1];
-                    errCt++;
-                    fprintf(stderr, zCantFmt, pOD->pz_Name, pN->pz_Name);
-                }
-
-                if (*pCant == NO_EQUIVALENT)
-                    break;
-            }
-        }
-
-        /*
-         *  IF       this option is not equivalenced to another,
-         *        OR it is equivalenced to itself (is the equiv. root)
-         *  THEN we need to make sure it occurs often enough.
-         */
-        if (  (pOD->optEquivIndex == NO_EQUIVALENT)
-           || (pOD->optEquivIndex == pOD->optIndex) )   do {
-            /*
-             *  IF the occurrence counts have been satisfied,
-             *  THEN there is no problem.
-             */
-            if (pOD->optOccCt >= pOD->optMinCt)
-                break;
-
-            /*
-             *  IF MUST_SET means SET and PRESET are okay,
-             *  so min occurrence count doesn't count
-             */
-            if (  (pOD->fOptState & OPTST_MUST_SET)
-               && (pOD->fOptState & (OPTST_PRESET | OPTST_SET)) )
-                break;
-
-            errCt++;
-            if (pOD->optMinCt > 1)
-                 fprintf(stderr, zNotEnough, pOD->pz_Name, pOD->optMinCt);
-            else fprintf(stderr, zNeedOne, pOD->pz_Name);
-        } while (0);
-
-        if (--oCt <= 0)
-            break;
-        pOD++;
-    }
-
-    /*
-     *  IF we are stopping on errors, check to see if any remaining
-     *  arguments are required to be there or prohibited from being there.
-     */
-    if ((pOpts->fOptSet & OPTPROC_ERRSTOP) != 0) {
-
-        /*
-         *  Check for prohibition
-         */
-        if ((pOpts->fOptSet & OPTPROC_NO_ARGS) != 0) {
-            if (pOpts->origArgCt > pOpts->curOptIdx) {
-                fprintf(stderr, zNoArgs, pOpts->pzProgName);
-                ++errCt;
-            }
-        }
-
-        /*
-         *  ELSE not prohibited, check for being required
-         */
-        else if ((pOpts->fOptSet & OPTPROC_ARGS_REQ) != 0) {
-            if (pOpts->origArgCt <= pOpts->curOptIdx) {
-                fprintf(stderr, zArgsMust, pOpts->pzProgName);
-                ++errCt;
-            }
-        }
-    }
-
-    return errCt;
-}
-
-
 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  *
  *  THESE ROUTINES ARE CALLABLE FROM THE GENERATED OPTION PROCESSING CODE
@@ -1099,7 +632,7 @@ checkConsistency(tOptions* pOpts)
 int
 optionProcess(tOptions * pOpts, int argCt, char ** argVect)
 {
-    if (! SUCCESSFUL(validateOptionsStruct(pOpts, argVect[0])))
+    if (! SUCCESSFUL(validate_struct(pOpts, argVect[0])))
         exit(EX_SOFTWARE);
 
     /*
@@ -1146,7 +679,7 @@ optionProcess(tOptions * pOpts, int argCt, char ** argVect)
         pOpts->pzCurOpt  = NULL;
     }
 
-    if (! SUCCESSFUL(doRegularOpts(pOpts)))
+    if (! SUCCESSFUL(regular_opts(pOpts)))
         return pOpts->origArgCt;
 
     /*
@@ -1171,7 +704,7 @@ optionProcess(tOptions * pOpts, int argCt, char ** argVect)
      *  THEN look for too few occurrences of required options
      */
     if ((pOpts->fOptSet & OPTPROC_ERRSTOP) != 0) {
-        if (checkConsistency(pOpts) != 0)
+        if (! is_consistent(pOpts))
             (*pOpts->pUsageProc)(pOpts, EXIT_FAILURE);
     }
 
index c2925e7999bf22638e3d0922b3a564d2dd01c60e..1e59faa61b7d6db40ffe12a430d19a24cd3b915c 100644 (file)
@@ -2,7 +2,7 @@
  *  
  *  DO NOT EDIT THIS FILE   (options.h)
  *  
- *  It has been AutoGen-ed  April 29, 2011 at 03:44:02 PM by AutoGen 5.11.9
+ *  It has been AutoGen-ed  December 29, 2011 at 12:02:36 PM by AutoGen 5.14
  *  From the definitions    funcs.def
  *  and the template file   options_h
  *
@@ -11,7 +11,7 @@
  *
  *  Automated Options Copyright (C) 1992-2011 by Bruce Korb
  *
- *  AutoOpts is free software: you can redistribute it and/or modify it
+ *   *  AutoOpts is free software: you can redistribute it and/or modify it
  *  under the terms of the GNU Lesser General Public License as published
  *  by the Free Software Foundation, either version 3 of the License, or
  *  (at your option) any later version.
@@ -23,7 +23,6 @@
  *  
  *  You should have received a copy of the GNU Lesser General Public License
  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.";
-
  */
 #ifndef AUTOOPTS_OPTIONS_H_GUARD
 #define AUTOOPTS_OPTIONS_H_GUARD 1
@@ -45,9 +44,9 @@
 #if defined(HAVE_SYSEXITS_H)
 #  include <sysexits.h>
 #endif /* HAVE_SYSEXITS_H */
-
-#ifndef EX_USAGE
-#  define EX_USAGE              64
+// END-CONFIGURED-HEADERS
+#ifndef  EX_USAGE
+# define EX_USAGE               64
 #endif
 
 /*
  *  See the relevant generated header file to determine which and what
  *  values for "opt_name" are available.
  */
-#define  OPTIONS_STRUCT_VERSION  143360
-#define  OPTIONS_VERSION_STRING  "35:0:10"
-#define  OPTIONS_MINIMUM_VERSION 102400
-#define  OPTIONS_MIN_VER_STRING  "25:0:0"
-
+#define OPTIONS_STRUCT_VERSION      147457
+#define OPTIONS_VERSION_STRING      "36:1:11"
+#define OPTIONS_MINIMUM_VERSION     102400
+#define OPTIONS_MIN_VER_STRING      "25:0:0"
+#define OPTIONS_VER_TO_NUM(_v, _r)  (((_v) * 4096) + (_r))
+       
 typedef enum {
     OPARG_TYPE_NONE             =  0,
     OPARG_TYPE_STRING           =  1,    /* default type/ vanilla string      */
@@ -220,6 +220,8 @@ typedef enum {
 # define OPTST_ARG_OPTIONAL   0
 #endif
 
+#define VENDOR_OPTION_VALUE   'W'
+
 #define OPTST_PERSISTENT_MASK (~OPTST_MUTABLE_MASK)
 
 #define SELECTED_OPT(_od)     ((_od)->fOptState  & OPTST_SELECTED_MASK)
@@ -256,8 +258,10 @@ typedef enum {
     OPTPROC_GNUUSAGE_ID        =  12, /* emit usage in GNU style        */
     OPTPROC_TRANSLATE_ID       =  13, /* Translate strings in tOptions  */
     OPTPROC_MISUSE_ID          =  14, /* no usage on usage error        */
+    OPTPROC_IMMEDIATE_ID       =  15, /* immediate options active       */
     OPTPROC_NXLAT_OPT_CFG_ID   =  16, /* suppress for config only       */
     OPTPROC_NXLAT_OPT_ID       =  17, /* suppress xlation always        */
+    OPTPROC_VENDOR_OPT_ID      =  18, /* vendor options active          */
     OPTPROC_PRESETTING_ID      =  19  /* opt processing in preset state */
 } optproc_state_enum_t;
 
@@ -277,10 +281,12 @@ typedef enum {
 #define OPTPROC_GNUUSAGE       (1U << OPTPROC_GNUUSAGE_ID)
 #define OPTPROC_TRANSLATE      (1U << OPTPROC_TRANSLATE_ID)
 #define OPTPROC_MISUSE         (1U << OPTPROC_MISUSE_ID)
+#define OPTPROC_IMMEDIATE      (1U << OPTPROC_IMMEDIATE_ID)
 #define OPTPROC_NXLAT_OPT_CFG  (1U << OPTPROC_NXLAT_OPT_CFG_ID)
 #define OPTPROC_NXLAT_OPT      (1U << OPTPROC_NXLAT_OPT_ID)
+#define OPTPROC_VENDOR_OPT     (1U << OPTPROC_VENDOR_OPT_ID)
 #define OPTPROC_PRESETTING     (1U << OPTPROC_PRESETTING_ID)
-#define OPTPROC_STATE_MASK     0x000B7FFFU
+#define OPTPROC_STATE_MASK     0x000FFFFFU
 
 #define OPTPROC_NO_XLAT_MASK   ( \
         OPTPROC_NXLAT_OPT |     OPTPROC_NXLAT_OPT_CFG \
@@ -406,11 +412,10 @@ struct optSpecIndex {
 typedef void (tOptionXlateProc)(void);
 
 /*
- * Everything marked "PUBLIC" is also marked "const".
- * Public access is not a license to modify.  Other fields
- * are used and modified by the library.  They are also
- * subject to change without any notice.  Do not even
- * look at these outside of libopts.
+ * Everything marked "PUBLIC" is also marked "const".  Public access is not
+ * a license to modify.  Other fields are used and modified by the library.
+ * They are also subject to change without any notice.
+ * Do not even look at these outside of libopts.
  */
 struct options {
     int const           structVersion;
@@ -483,7 +488,9 @@ typedef struct {
 #define strequate       option_strequate
 #define strtransform    option_strtransform
 
-/*
+/**
+ *  Everything needed to be known about an mmap-ed file.
+ *
  *  This is an output only structure used by text_mmap and text_munmap.
  *  Clients must not alter the contents and must provide it to both
  *  the text_mmap and text_munmap procedures.  BE ADVISED: if you are
@@ -493,15 +500,14 @@ typedef struct {
  *  is not zero, then there *may* not be a terminating NUL.
  */
 typedef struct {
-    void*       txt_data;      /* text file data   */
-    size_t      txt_size;      /* actual file size */
-    size_t      txt_full_size; /* mmaped mem size  */
-    int         txt_fd;        /* file descriptor  */
-    int         txt_zero_fd;   /* fd for /dev/zero */
-    int         txt_errno;     /* warning code     */
-    int         txt_prot;      /* "prot" flags     */
-    int         txt_flags;     /* mapping type     */
-    int         txt_alloc;     /* if we malloced memory */
+    void *      txt_data;      /*@< text file data   */
+    size_t      txt_size;      /*@< actual file size */
+    size_t      txt_full_size; /*@< mmaped mem size  */
+    int         txt_fd;        /*@< file descriptor  */
+    int         txt_zero_fd;   /*@< fd for /dev/zero */
+    int         txt_errno;     /*@< warning code     */
+    int         txt_prot;      /*@< "prot" flags     */
+    int         txt_flags;     /*@< mapping type     */
 } tmap_info_t;
 
 #define TEXT_MMAP_FAILED_ADDR(a)  ((void*)(a) ==  (void*)MAP_FAILED)
@@ -562,7 +568,7 @@ CPLUSPLUS_OPENER
 extern token_list_t* ao_string_tokenize(char const*);
 
 
-/* From: configfile.c line 80
+/* From: configfile.c line 77
  *
  * configFileLoad - parse a configuration file
  *
@@ -582,7 +588,7 @@ extern token_list_t* ao_string_tokenize(char const*);
 extern const tOptionValue* configFileLoad(char const*);
 
 
-/* From: configfile.c line 1059
+/* From: configfile.c line 1057
  *
  * optionFileLoad - Load the locatable config files, in order
  *
@@ -612,7 +618,7 @@ extern const tOptionValue* configFileLoad(char const*);
 extern int optionFileLoad(tOptions*, char const*);
 
 
-/* From: configfile.c line 212
+/* From: configfile.c line 209
  *
  * optionFindNextValue - find a hierarcicaly valued option instance
  *
@@ -631,7 +637,7 @@ extern int optionFileLoad(tOptions*, char const*);
 extern const tOptionValue* optionFindNextValue(const tOptDesc*, const tOptionValue*, char const*, char const*);
 
 
-/* From: configfile.c line 138
+/* From: configfile.c line 135
  *
  * optionFindValue - find a hierarcicaly valued option instance
  *
@@ -661,7 +667,7 @@ extern const tOptionValue* optionFindValue(const tOptDesc*, char const*, char co
 extern void optionFree(tOptions*);
 
 
-/* From: configfile.c line 281
+/* From: configfile.c line 278
  *
  * optionGetValue - get a specific value from a hierarcical list
  *
@@ -674,12 +680,14 @@ extern void optionFree(tOptions*);
  *  This routine will find an entry in a nested value option or configurable.
  *  If "valueName" is NULL, then the first entry is returned.  Otherwise,
  *  the first entry with a name that exactly matches the argument will be
- *  returned.
+ *  returned.  If there is no matching value, NULL is returned and errno is
+ *  set to ENOENT. If the provided option value is not a hierarchical value,
+ *  NULL is also returned and errno is set to EINVAL.
  */
 extern const tOptionValue* optionGetValue(const tOptionValue*, char const*);
 
 
-/* From: load.c line 478
+/* From: load.c line 477
  *
  * optionLoadLine - process a string for an option name and value
  *
@@ -703,7 +711,7 @@ extern const tOptionValue* optionGetValue(const tOptionValue*, char const*);
 extern void optionLoadLine(tOptions*, char const*);
 
 
-/* From: configfile.c line 340
+/* From: configfile.c line 338
  *
  * optionNextValue - get the next value from a hierarchical list
  *
@@ -722,7 +730,7 @@ extern void optionLoadLine(tOptions*, char const*);
 extern const tOptionValue* optionNextValue(const tOptionValue*, const tOptionValue*);
 
 
-/* From: usage.c line 195
+/* From: usage.c line 202
  *
  * optionOnlyUsage - Print usage text for just the options
  *
@@ -737,7 +745,7 @@ extern const tOptionValue* optionNextValue(const tOptionValue*, const tOptionVal
 extern void optionOnlyUsage(tOptions*, int);
 
 
-/* From: autoopts.c line 1065
+/* From: autoopts.c line 598
  *
  * optionProcess - this is the main option processing routine
  *
@@ -1050,6 +1058,8 @@ extern void optionUnstackArg(tOptions*, tOptDesc*);
 
 extern void optionUsage(tOptions*, int);
 
+extern void optionVendorOption(tOptions *, tOptDesc *);
+
 extern void optionVersionStderr(tOptions*, tOptDesc*);
 
 extern void* text_mmap(char const*, int, int, tmap_info_t*);
index de92663424b938ee1d538fdd7972811b07305b13..20492a4666741ffc7fca9d56a78f570e1699da12 100644 (file)
@@ -2,17 +2,23 @@
  *  
  *  DO NOT EDIT THIS FILE   (usage-txt.h)
  *  
- *  It has been AutoGen-ed  April 29, 2011 at 03:44:00 PM by AutoGen 5.11.9
+ *  It has been AutoGen-ed  December 29, 2011 at 12:02:34 PM by AutoGen 5.14
  *  From the definitions    usage-txt.def
  *  and the template file   usage-txt.tpl
  *
  *  This file handles all the bookkeeping required for tracking all the little
- *  tiny strings used by the AutoOpts library.  There are 142
+ *  tiny strings used by the AutoOpts library.  There are 145
  *  of them.  This is not versioned because it is entirely internal to the
  *  library and accessed by client code only in a very well-controlled way:
  *  they may substitute translated strings using a procedure that steps through
  *  all the string pointers.
  *
+ *  Copyright (C) 1992-2011 Bruce Korb, all rights reserved.
+ *  This is free software. It is licensed for use, modification and
+ *  redistribution under the terms of the
+ *  GNU Lesser General Public License, version 3 or later
+ *     <http://gnu.org/licenses/lgpl.html>
+ *
  *  AutoOpts is free software: you can redistribute it and/or modify it
  *  under the terms of the GNU Lesser General Public License as published
  *  by the Free Software Foundation, either version 3 of the License, or
@@ -25,7 +31,6 @@
  *  
  *  You should have received a copy of the GNU Lesser General Public License
  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.";
-
  */
 #ifndef AUTOOPTS_USAGE_TXT_H_GUARD
 #define AUTOOPTS_USAGE_TXT_H_GUARD 1
@@ -45,7 +50,7 @@ typedef struct {
   char*     utpz_GnuTimeArg;
   char*     utpz_GnuNumArg;
   char*     utpz_GnuStrArg;
-  cch_t*    apz_str[ 135 ];
+  cch_t*    apz_str[ 138 ];
 } usage_text_t;
 
 /*
@@ -71,135 +76,138 @@ extern usage_text_t option_usage_text;
 #define zAll                  (option_usage_text.apz_str[ 10])
 #define zAlt                  (option_usage_text.apz_str[ 11])
 #define zAmbigKey             (option_usage_text.apz_str[ 12])
-#define zAmbigOptStr          (option_usage_text.apz_str[ 13])
-#define zArgsMust             (option_usage_text.apz_str[ 14])
-#define zAtMost               (option_usage_text.apz_str[ 15])
-#define zAuto                 (option_usage_text.apz_str[ 16])
-#define zBadPipe              (option_usage_text.apz_str[ 17])
-#define zBadVerArg            (option_usage_text.apz_str[ 18])
-#define zCantFmt              (option_usage_text.apz_str[ 19])
-#define zCantSave             (option_usage_text.apz_str[ 20])
-#define zCfgAO_Flags          (option_usage_text.apz_str[ 21])
-#define zCfgProg              (option_usage_text.apz_str[ 22])
-#define zDefaultOpt           (option_usage_text.apz_str[ 23])
-#define zDis                  (option_usage_text.apz_str[ 24])
-#define zDisabledErr          (option_usage_text.apz_str[ 25])
-#define zDisabledOpt          (option_usage_text.apz_str[ 26])
-#define zDisabledWhy          (option_usage_text.apz_str[ 27])
-#define zEnab                 (option_usage_text.apz_str[ 28])
-#define zEquiv                (option_usage_text.apz_str[ 29])
-#define zErrOnly              (option_usage_text.apz_str[ 30])
-#define zExamineFmt           (option_usage_text.apz_str[ 31])
-#define zFiveSpaces           (option_usage_text.apz_str[ 32])
-#define zFlagOkay             (option_usage_text.apz_str[ 33])
-#define zFmtFmt               (option_usage_text.apz_str[ 34])
-#define zForkFail             (option_usage_text.apz_str[ 35])
-#define zFreopenFail          (option_usage_text.apz_str[ 36])
-#define zFSErrOptLoad         (option_usage_text.apz_str[ 37])
-#define zFSErrReadFile        (option_usage_text.apz_str[ 38])
-#define zFSOptError           (option_usage_text.apz_str[ 39])
-#define zFSOptErrMayExist     (option_usage_text.apz_str[ 40])
-#define zFSOptErrMustExist    (option_usage_text.apz_str[ 41])
-#define zFSOptErrNoExist      (option_usage_text.apz_str[ 42])
-#define zFSOptErrOpen         (option_usage_text.apz_str[ 43])
-#define zFSOptErrFopen        (option_usage_text.apz_str[ 44])
-#define zFileCannotExist      (option_usage_text.apz_str[ 45])
-#define zFileMustExist        (option_usage_text.apz_str[ 46])
-#define zGenshell             (option_usage_text.apz_str[ 47])
+#define zAmbigList            (option_usage_text.apz_str[ 13])
+#define zAmbigOptStr          (option_usage_text.apz_str[ 14])
+#define zAmbiguous            (option_usage_text.apz_str[ 15])
+#define zArgsMust             (option_usage_text.apz_str[ 16])
+#define zAtMost               (option_usage_text.apz_str[ 17])
+#define zAuto                 (option_usage_text.apz_str[ 18])
+#define zBadPipe              (option_usage_text.apz_str[ 19])
+#define zBadVerArg            (option_usage_text.apz_str[ 20])
+#define zCantFmt              (option_usage_text.apz_str[ 21])
+#define zCantSave             (option_usage_text.apz_str[ 22])
+#define zCfgAO_Flags          (option_usage_text.apz_str[ 23])
+#define zCfgProg              (option_usage_text.apz_str[ 24])
+#define zDefaultOpt           (option_usage_text.apz_str[ 25])
+#define zDis                  (option_usage_text.apz_str[ 26])
+#define zDisabledErr          (option_usage_text.apz_str[ 27])
+#define zDisabledOpt          (option_usage_text.apz_str[ 28])
+#define zDisabledWhy          (option_usage_text.apz_str[ 29])
+#define zEnab                 (option_usage_text.apz_str[ 30])
+#define zEquiv                (option_usage_text.apz_str[ 31])
+#define zErrOnly              (option_usage_text.apz_str[ 32])
+#define zExamineFmt           (option_usage_text.apz_str[ 33])
+#define zFiveSpaces           (option_usage_text.apz_str[ 34])
+#define zFlagOkay             (option_usage_text.apz_str[ 35])
+#define zFmtFmt               (option_usage_text.apz_str[ 36])
+#define zForkFail             (option_usage_text.apz_str[ 37])
+#define zFreopenFail          (option_usage_text.apz_str[ 38])
+#define zFSErrOptLoad         (option_usage_text.apz_str[ 39])
+#define zFSErrReadFile        (option_usage_text.apz_str[ 40])
+#define zFSOptError           (option_usage_text.apz_str[ 41])
+#define zFSOptErrMayExist     (option_usage_text.apz_str[ 42])
+#define zFSOptErrMustExist    (option_usage_text.apz_str[ 43])
+#define zFSOptErrNoExist      (option_usage_text.apz_str[ 44])
+#define zFSOptErrOpen         (option_usage_text.apz_str[ 45])
+#define zFSOptErrFopen        (option_usage_text.apz_str[ 46])
+#define zFileCannotExist      (option_usage_text.apz_str[ 47])
+#define zFileMustExist        (option_usage_text.apz_str[ 48])
+#define zGenshell             (option_usage_text.apz_str[ 49])
 #define zGnuBoolArg           (option_usage_text.utpz_GnuBoolArg)
-#define zGnuBreak             (option_usage_text.apz_str[ 48])
+#define zGnuBreak             (option_usage_text.apz_str[ 50])
 #define zGnuKeyArg            (option_usage_text.utpz_GnuKeyArg)
 #define zGnuFileArg           (option_usage_text.utpz_GnuFileArg)
 #define zGnuKeyLArg           (option_usage_text.utpz_GnuKeyLArg)
 #define zGnuTimeArg           (option_usage_text.utpz_GnuTimeArg)
-#define zGnuNestArg           (option_usage_text.apz_str[ 49])
+#define zGnuNestArg           (option_usage_text.apz_str[ 51])
 #define zGnuNumArg            (option_usage_text.utpz_GnuNumArg)
-#define zGnuOptArg            (option_usage_text.apz_str[ 50])
-#define zGnuOptFmt            (option_usage_text.apz_str[ 51])
+#define zGnuOptArg            (option_usage_text.apz_str[ 52])
+#define zGnuOptFmt            (option_usage_text.apz_str[ 53])
 #define zGnuStrArg            (option_usage_text.utpz_GnuStrArg)
-#define zIllOptChr            (option_usage_text.apz_str[ 52])
-#define zIllOptStr            (option_usage_text.apz_str[ 53])
-#define zIllegal              (option_usage_text.apz_str[ 54])
-#define zIntRange             (option_usage_text.apz_str[ 55])
-#define zInvalOptDesc         (option_usage_text.apz_str[ 56])
-#define zLowerBits            (option_usage_text.apz_str[ 57])
-#define zMembers              (option_usage_text.apz_str[ 58])
-#define zMisArg               (option_usage_text.apz_str[ 59])
-#define zMultiEquiv           (option_usage_text.apz_str[ 60])
-#define zMust                 (option_usage_text.apz_str[ 61])
-#define zNeedOne              (option_usage_text.apz_str[ 62])
-#define zNoArg                (option_usage_text.apz_str[ 63])
-#define zNoArgv               (option_usage_text.apz_str[ 64])
-#define zNoArgs               (option_usage_text.apz_str[ 65])
-#define zNoCreat              (option_usage_text.apz_str[ 66])
-#define zNoFlags              (option_usage_text.apz_str[ 67])
-#define zNoKey                (option_usage_text.apz_str[ 68])
-#define zNoLim                (option_usage_text.apz_str[ 69])
-#define zNoPreset             (option_usage_text.apz_str[ 70])
-#define zNoResetArg           (option_usage_text.apz_str[ 71])
-#define zNoRq_NoShrtTtl       (option_usage_text.apz_str[ 72])
-#define zNoRq_ShrtTtl         (option_usage_text.apz_str[ 73])
-#define zNoStat               (option_usage_text.apz_str[ 74])
-#define zNoState              (option_usage_text.apz_str[ 75])
-#define zNone                 (option_usage_text.apz_str[ 76])
-#define zNotDef               (option_usage_text.apz_str[ 77])
-#define zNotCmdOpt            (option_usage_text.apz_str[ 78])
-#define zNotEnough            (option_usage_text.apz_str[ 79])
-#define zNotFile              (option_usage_text.apz_str[ 80])
-#define zNotNumber            (option_usage_text.apz_str[ 81])
-#define zNotDate              (option_usage_text.apz_str[ 82])
-#define zNotDuration          (option_usage_text.apz_str[ 83])
-#define zNrmOptFmt            (option_usage_text.apz_str[ 84])
-#define zNumberOpt            (option_usage_text.apz_str[ 85])
-#define zOneSpace             (option_usage_text.apz_str[ 86])
-#define zOnlyOne              (option_usage_text.apz_str[ 87])
-#define zOptsOnly             (option_usage_text.apz_str[ 88])
-#define zOutputFail           (option_usage_text.apz_str[ 89])
-#define zPathFmt              (option_usage_text.apz_str[ 90])
-#define zPlsSendBugs          (option_usage_text.apz_str[ 91])
-#define zPreset               (option_usage_text.apz_str[ 92])
-#define zPresetFile           (option_usage_text.apz_str[ 93])
-#define zPresetIntro          (option_usage_text.apz_str[ 94])
-#define zProhib               (option_usage_text.apz_str[ 95])
-#define zReorder              (option_usage_text.apz_str[ 96])
-#define zRange                (option_usage_text.apz_str[ 97])
-#define zRangeAbove           (option_usage_text.apz_str[ 98])
-#define zRangeLie             (option_usage_text.apz_str[ 99])
-#define zRangeOnly            (option_usage_text.apz_str[100])
-#define zRangeOr              (option_usage_text.apz_str[101])
-#define zRangeErr             (option_usage_text.apz_str[102])
-#define zRangeExact           (option_usage_text.apz_str[103])
-#define zRangeScaled          (option_usage_text.apz_str[104])
-#define zRangeUpto            (option_usage_text.apz_str[105])
-#define zResetNotConfig       (option_usage_text.apz_str[106])
-#define zReqFmt               (option_usage_text.apz_str[107])
-#define zReqOptFmt            (option_usage_text.apz_str[108])
-#define zReqThese             (option_usage_text.apz_str[109])
-#define zReq_NoShrtTtl        (option_usage_text.apz_str[110])
-#define zReq_ShrtTtl          (option_usage_text.apz_str[111])
-#define zSepChars             (option_usage_text.apz_str[112])
-#define zSetMemberSettings    (option_usage_text.apz_str[113])
-#define zShrtGnuOptFmt        (option_usage_text.apz_str[114])
-#define zSixSpaces            (option_usage_text.apz_str[115])
-#define zStdBoolArg           (option_usage_text.apz_str[116])
-#define zStdBreak             (option_usage_text.apz_str[117])
-#define zStdFileArg           (option_usage_text.apz_str[118])
-#define zStdKeyArg            (option_usage_text.apz_str[119])
-#define zStdKeyLArg           (option_usage_text.apz_str[120])
-#define zStdTimeArg           (option_usage_text.apz_str[121])
-#define zStdNestArg           (option_usage_text.apz_str[122])
-#define zStdNoArg             (option_usage_text.apz_str[123])
-#define zStdNumArg            (option_usage_text.apz_str[124])
-#define zStdOptArg            (option_usage_text.apz_str[125])
-#define zStdReqArg            (option_usage_text.apz_str[126])
-#define zStdStrArg            (option_usage_text.apz_str[127])
-#define zTabHyp               (option_usage_text.apz_str[128])
-#define zTabHypAnd            (option_usage_text.apz_str[129])
-#define zTabout               (option_usage_text.apz_str[130])
-#define zThreeSpaces          (option_usage_text.apz_str[131])
-#define zTwoSpaces            (option_usage_text.apz_str[132])
-#define zUpTo                 (option_usage_text.apz_str[133])
-#define zValidKeys            (option_usage_text.apz_str[134])
+#define zIllOptChr            (option_usage_text.apz_str[ 54])
+#define zIllOptStr            (option_usage_text.apz_str[ 55])
+#define zIllVendOptStr        (option_usage_text.apz_str[ 56])
+#define zIntRange             (option_usage_text.apz_str[ 57])
+#define zInvalOptDesc         (option_usage_text.apz_str[ 58])
+#define zLowerBits            (option_usage_text.apz_str[ 59])
+#define zMembers              (option_usage_text.apz_str[ 60])
+#define zMisArg               (option_usage_text.apz_str[ 61])
+#define zMultiEquiv           (option_usage_text.apz_str[ 62])
+#define zMust                 (option_usage_text.apz_str[ 63])
+#define zNeedOne              (option_usage_text.apz_str[ 64])
+#define zNoArg                (option_usage_text.apz_str[ 65])
+#define zNoArgv               (option_usage_text.apz_str[ 66])
+#define zNoArgs               (option_usage_text.apz_str[ 67])
+#define zNoCreat              (option_usage_text.apz_str[ 68])
+#define zNoFlags              (option_usage_text.apz_str[ 69])
+#define zNoKey                (option_usage_text.apz_str[ 70])
+#define zNoLim                (option_usage_text.apz_str[ 71])
+#define zNoPreset             (option_usage_text.apz_str[ 72])
+#define zNoResetArg           (option_usage_text.apz_str[ 73])
+#define zNoRq_NoShrtTtl       (option_usage_text.apz_str[ 74])
+#define zNoRq_ShrtTtl         (option_usage_text.apz_str[ 75])
+#define zNoStat               (option_usage_text.apz_str[ 76])
+#define zNoState              (option_usage_text.apz_str[ 77])
+#define zNone                 (option_usage_text.apz_str[ 78])
+#define zNotDef               (option_usage_text.apz_str[ 79])
+#define zNotCmdOpt            (option_usage_text.apz_str[ 80])
+#define zNotEnough            (option_usage_text.apz_str[ 81])
+#define zNotFile              (option_usage_text.apz_str[ 82])
+#define zNotNumber            (option_usage_text.apz_str[ 83])
+#define zNotDate              (option_usage_text.apz_str[ 84])
+#define zNotDuration          (option_usage_text.apz_str[ 85])
+#define zNrmOptFmt            (option_usage_text.apz_str[ 86])
+#define zNumberOpt            (option_usage_text.apz_str[ 87])
+#define zOnlyOne              (option_usage_text.apz_str[ 88])
+#define zOptsOnly             (option_usage_text.apz_str[ 89])
+#define zOutputFail           (option_usage_text.apz_str[ 90])
+#define zPathFmt              (option_usage_text.apz_str[ 91])
+#define zPlsSendBugs          (option_usage_text.apz_str[ 92])
+#define zPreset               (option_usage_text.apz_str[ 93])
+#define zPresetFile           (option_usage_text.apz_str[ 94])
+#define zPresetIntro          (option_usage_text.apz_str[ 95])
+#define zProhib               (option_usage_text.apz_str[ 96])
+#define zReorder              (option_usage_text.apz_str[ 97])
+#define zRange                (option_usage_text.apz_str[ 98])
+#define zRangeAbove           (option_usage_text.apz_str[ 99])
+#define zRangeLie             (option_usage_text.apz_str[100])
+#define zRangeOnly            (option_usage_text.apz_str[101])
+#define zRangeOr              (option_usage_text.apz_str[102])
+#define zRangeErr             (option_usage_text.apz_str[103])
+#define zRangeExact           (option_usage_text.apz_str[104])
+#define zRangeScaled          (option_usage_text.apz_str[105])
+#define zRangeUpto            (option_usage_text.apz_str[106])
+#define zResetNotConfig       (option_usage_text.apz_str[107])
+#define zReqFmt               (option_usage_text.apz_str[108])
+#define zReqOptFmt            (option_usage_text.apz_str[109])
+#define zReqThese             (option_usage_text.apz_str[110])
+#define zReq_NoShrtTtl        (option_usage_text.apz_str[111])
+#define zReq_ShrtTtl          (option_usage_text.apz_str[112])
+#define zSepChars             (option_usage_text.apz_str[113])
+#define zSetMemberSettings    (option_usage_text.apz_str[114])
+#define zShrtGnuOptFmt        (option_usage_text.apz_str[115])
+#define zSixSpaces            (option_usage_text.apz_str[116])
+#define zStdBoolArg           (option_usage_text.apz_str[117])
+#define zStdBreak             (option_usage_text.apz_str[118])
+#define zStdFileArg           (option_usage_text.apz_str[119])
+#define zStdKeyArg            (option_usage_text.apz_str[120])
+#define zStdKeyLArg           (option_usage_text.apz_str[121])
+#define zStdTimeArg           (option_usage_text.apz_str[122])
+#define zStdNestArg           (option_usage_text.apz_str[123])
+#define zStdNoArg             (option_usage_text.apz_str[124])
+#define zStdNumArg            (option_usage_text.apz_str[125])
+#define zStdOptArg            (option_usage_text.apz_str[126])
+#define zStdReqArg            (option_usage_text.apz_str[127])
+#define zStdStrArg            (option_usage_text.apz_str[128])
+#define zTabHyp               (option_usage_text.apz_str[129])
+#define zTabHypAnd            (option_usage_text.apz_str[130])
+#define zTabout               (option_usage_text.apz_str[131])
+#define zThreeSpaces          (option_usage_text.apz_str[132])
+#define zTwoSpaces            (option_usage_text.apz_str[133])
+#define zUpTo                 (option_usage_text.apz_str[134])
+#define zValidKeys            (option_usage_text.apz_str[135])
+#define zVendOptsAre          (option_usage_text.apz_str[136])
+#define zVendIntro            (option_usage_text.apz_str[137])
 
   /*
    *  First, set up the strings.  Some of these are writable.  These are all in
@@ -214,160 +222,163 @@ extern usage_text_t option_usage_text;
   static char    eng_zGnuTimeArg[] = "=Tim";
   static char    eng_zGnuNumArg[] = "=num";
   static char    eng_zGnuStrArg[] = "=str";
-static char const usage_txt[4435] =
-    "malloc of %d bytes failed\n\0"
-    "AutoOpts function called without option descriptor\n\0"
-    "\tThis exceeds the compiled library version:  \0"
-    "Automated Options Processing Error!\n"
-    "\t%s called AutoOpts function with structure version %d:%d:%d.\n\0"
-    "realloc of %d bytes at 0x%p failed\n\0"
-    "\tThis is less than the minimum library version:  \0"
-    "strdup of %d byte string failed\n\0"
-    "Automated Options version %s\n"
-    "\tcopyright (c) 1999-2011 by Bruce Korb - all rights reserved\n\0"
-    "AutoOpts lib error: defaulted to option with optional arg\n\0"
-    "(AutoOpts bug):  Aliasing option is out of range.\0"
-    "all\0"
-    "\t\t\t\t- an alternate for %s\n\0"
-    "%s error:  the keyword `%s' is ambiguous for %s\n\0"
-    "%s: ambiguous option -- %s\n\0"
-    "%s: Command line arguments required\n\0"
-    "%d %s%s options allowed\n\0"
-    "version and help options:\0"
-    "Error %d (%s) from the pipe(2) syscall\n\0"
-    "ERROR: version option argument '%c' invalid.  Use:\n"
-    "\t'v' - version only\n"
-    "\t'c' - version and copyright\n"
-    "\t'n' - version and copyright notice\n\0"
-    "ERROR:  %s option conflicts with the %s option\n\0"
-    "%s(optionSaveState): error: cannot allocate %d bytes\n\0"
-    "auto-options\0"
-    "program\0"
-    "\t\t\t\t- default option for unnamed options\n\0"
-    "\t\t\t\t- disabled as --%s\n\0"
-    "%s: The ``%s'' option has been disabled\0"
-    " --- %-14s %s\n\0"
-    "This option has been disabled\0"
-    "\t\t\t\t- enabled by default\n\0"
-    "-equivalence\0"
-    "ERROR:  only \0"
-    " - examining environment variables named %s_*\n\0"
-    "     \0"
-    "Options are specified by doubled hyphens and their name or by a single\n"
-    "hyphen and the flag character.\n\0"
-    "%%-%ds %%s\n\0"
-    "fs error %d (%s) on fork - cannot obtain %s usage\n\0"
-    "fs error %d (%s) on freopen\n\0"
-    "File error %d (%s) opening %s for loading options\n\0"
-    "fs error %d (%s) reading file %s\n\0"
-    "fs error %d (%s) on %s %s for option %s\n\0"
-    "stat-ing for directory\0"
-    "stat-ing for regular file\0"
-    "stat-ing for non-existant file\0"
-    "open-ing file\0"
-    "fopen-ing file\0"
-    "\t\t\t\t- file must not pre-exist\n\0"
-    "\t\t\t\t- file must pre-exist\n\0"
-    "\n"
-    "= = = = = = = =\n\n"
-    "This incarnation of genshell will produce\n"
-    "a shell script to parse the options for %s:\n\n\0"
-    "\n"
-    "%s\n\n\0"
-    "=Cplx\0"
-    "[=arg]\0"
-    "--%2$s%1$s\0"
-    "%s: illegal option -- %c\n\0"
-    "%s: illegal option -- %s\n\0"
-    "illegal\0"
-    "  or an integer from %d through %d\n\0"
-    "AutoOpts ERROR:  invalid option descriptor for %s\n\0"
-    "  or an integer mask with any of the lower %d bits set\n\0"
-    "\t\t\t\t- is a set membership option\n\0"
-    "%s: option `%s' requires an argument\n\0"
-    "Equivalenced option '%s' was equivalenced to both\n"
-    "\t'%s' and '%s'\0"
-    "\t\t\t\t- must appear between %d and %d times\n\0"
-    "ERROR:  The %s option is required\n\0"
-    "%s: option `%s' cannot have an argument\n\0"
-    "%s: cannot allocate new argument vector\n\0"
-    "%s: Command line arguments not allowed\n\0"
-    "error %d (%s) creating %s\n\0"
-    "Options are specified by single or double hyphens and their name.\n\0"
-    "%s error:  `%s' does not match any %s keywords\n\0"
-    "\t\t\t\t- may appear multiple times\n\0"
-    "\t\t\t\t- may not be preset\n\0"
-    "The 'reset-option' option requires an argument\n\0"
-    "   Arg Option-Name    Description\n\0"
-    "  Flg Arg Option-Name    Description\n\0"
-    "error %d (%s) stat-ing %s\n\0"
-    "%s(optionRestore): error: no saved option state\n\0"
-    "none\0"
-    "'%s' not defined\n\0"
-    "'%s' is not a command line option\n\0"
-    "ERROR:  The %s option must appear %d times\n\0"
-    "error:  cannot load options from non-regular file %s\n\0"
-    "%s error:  `%s' is not a recognizable number\n\0"
-    "%s error:  `%s' is not a recognizable date/time\n\0"
-    "%s error:  `%s' is not a recognizable time duration\n\0"
-    " %3s %s\0"
-    "The '-#<number>' option may omit the hash char\n\0"
-    " \0"
-    "one %s%s option allowed\n\0"
-    "All arguments are named options.\n\0"
-    "Write failure to output file\0"
-    " - reading file %s\0"
-    "\n"
-    "please send bug reports to:  %s\n\0"
-    "\t\t\t\t- may NOT appear - preset only\n\0"
-    "#  preset/initialization file\n"
-    "#  %s#\n\0"
-    "\n"
-    "The following option preset mechanisms are supported:\n\0"
-    "prohibits these options:\n\0"
-    "Operands and options may be intermixed.  They will be reordered.\n\0"
-    "%s%ld to %ld\0"
-    "%sgreater than or equal to %ld\0"
-    "%sIt must lie in one of the ranges:\n\0"
-    "%sIt must be in the range:\n\0"
-    ", or\n\0"
-    "%s error:  %s option value ``%s'' is out of range.\n\0"
-    "%s%ld exactly\0"
-    "%sis scalable with a suffix: k/K/m/M/g/G/t/T\n\0"
-    "%sless than or equal to %ld\0"
-    "The --reset-option has not been configured.\n\0"
-    "ERROR:  %s option requires the %s option\n\0"
-    " %3s %-14s %s\0"
-    "requires these options:\n\0"
-    "   Arg Option-Name   Req?  Description\n\0"
-    "  Flg Arg Option-Name   Req?  Description\n\0"
-    "-_^\0"
-    "or you may use a numeric representation.  Preceding these with a '!' will\n"
-    "clear the bits, specifying 'none' will clear all bits, and 'all' will set them\n"
-    "all.  Multiple entries may be passed as an option argument list.\n\0"
-    "%s\0"
-    "      \0"
-    "T/F\0"
-    "\n"
-    "%s\n\n"
-    "%s\0"
-    "Fil\0"
-    "KWd\0"
-    "Mbr\0"
-    "Tim\0"
-    "Cpx\0"
-    "no \0"
-    "Num\0"
-    "opt\0"
-    "YES\0"
-    "Str\0"
-    "\t\t\t\t- \0"
-    "\t\t\t\t-- and \0"
-    "\t\t\t\t%s\n\0"
-    "   \0"
-    "  \0"
-    "\t\t\t\t- may appear up to %d times\n\0"
-    "The valid \"%s\" option keywords are:\n\0";
+static char const usage_txt[4619] =
+/*     0 */ "malloc of %d bytes failed\n\0"
+/*    27 */ "AutoOpts function called without option descriptor\n\0"
+/*    79 */ "\tThis exceeds the compiled library version:  \0"
+/*   125 */ "Automated Options Processing Error!\n"
+            "\t%s called AutoOpts function with structure version %d:%d:%d.\n\0"
+/*   224 */ "realloc of %d bytes at 0x%p failed\n\0"
+/*   260 */ "\tThis is less than the minimum library version:  \0"
+/*   310 */ "strdup of %d byte string failed\n\0"
+/*   343 */ "Automated Options version %s\n"
+            "\tcopyright (c) 1999-2011 by Bruce Korb - all rights reserved\n\0"
+/*   434 */ "AutoOpts lib error: defaulted to option with optional arg\n\0"
+/*   493 */ "(AutoOpts bug):  Aliasing option is out of range.\0"
+/*   543 */ "all\0"
+/*   547 */ "\t\t\t\t- an alternate for %s\n\0"
+/*   574 */ "%s error:  the keyword `%s' is ambiguous for %s\n\0"
+/*   623 */ "  The following options match:\n\0"
+/*   655 */ "%s: ambiguous option name: %s (matches %d options)\n\0"
+/*   707 */ "  %s%s\n\0"
+/*   715 */ "%s: Command line arguments required\n\0"
+/*   752 */ "%d %s%s options allowed\n\0"
+/*   777 */ "version and help options:\0"
+/*   803 */ "Error %d (%s) from the pipe(2) syscall\n\0"
+/*   843 */ "ERROR: version option argument '%c' invalid.  Use:\n"
+            "\t'v' - version only\n"
+            "\t'c' - version and copyright\n"
+            "\t'n' - version and copyright notice\n\0"
+/*   980 */ "ERROR:  %s option conflicts with the %s option\n\0"
+/*  1028 */ "%s(optionSaveState): error: cannot allocate %d bytes\n\0"
+/*  1082 */ "auto-options\0"
+/*  1095 */ "program\0"
+/*  1103 */ "\t\t\t\t- default option for unnamed options\n\0"
+/*  1145 */ "\t\t\t\t- disabled as --%s\n\0"
+/*  1169 */ "%s: The ``%s'' option has been disabled\0"
+/*  1209 */ " --- %-14s %s\n\0"
+/*  1224 */ "This option has been disabled\0"
+/*  1254 */ "\t\t\t\t- enabled by default\n\0"
+/*  1280 */ "-equivalence\0"
+/*  1293 */ "ERROR:  only \0"
+/*  1307 */ " - examining environment variables named %s_*\n\0"
+/*  1354 */ "     \0"
+/*  1360 */ "Options are specified by doubled hyphens and their name or by a single\n"
+            "hyphen and the flag character.\n\0"
+/*  1463 */ "%%-%ds %%s\n\0"
+/*  1475 */ "fs error %d (%s) on fork - cannot obtain %s usage\n\0"
+/*  1526 */ "fs error %d (%s) on freopen\n\0"
+/*  1555 */ "File error %d (%s) opening %s for loading options\n\0"
+/*  1606 */ "fs error %d (%s) reading file %s\n\0"
+/*  1640 */ "fs error %d (%s) on %s %s for option %s\n\0"
+/*  1681 */ "stat-ing for directory\0"
+/*  1704 */ "stat-ing for regular file\0"
+/*  1730 */ "stat-ing for non-existant file\0"
+/*  1761 */ "open-ing file\0"
+/*  1775 */ "fopen-ing file\0"
+/*  1790 */ "\t\t\t\t- file must not pre-exist\n\0"
+/*  1821 */ "\t\t\t\t- file must pre-exist\n\0"
+/*  1848 */ "\n"
+            "= = = = = = = =\n\n"
+            "This incarnation of genshell will produce\n"
+            "a shell script to parse the options for %s:\n\n\0"
+/*  1954 */ "\n"
+            "%s\n\n\0"
+/*  1960 */ "=Cplx\0"
+/*  1966 */ "[=arg]\0"
+/*  1973 */ "--%2$s%1$s\0"
+/*  1984 */ "%s: illegal option -- %c\n\0"
+/*  2010 */ "%s: illegal option -- %s\n\0"
+/*  2036 */ "%s: unknown vendor extension option -- %s\n\0"
+/*  2079 */ "  or an integer from %d through %d\n\0"
+/*  2115 */ "AutoOpts ERROR:  invalid option descriptor for %s\n\0"
+/*  2166 */ "  or an integer mask with any of the lower %d bits set\n\0"
+/*  2222 */ "\t\t\t\t- is a set membership option\n\0"
+/*  2256 */ "%s: option `%s' requires an argument\n\0"
+/*  2294 */ "Equivalenced option '%s' was equivalenced to both\n"
+            "\t'%s' and '%s'\0"
+/*  2359 */ "\t\t\t\t- must appear between %d and %d times\n\0"
+/*  2402 */ "ERROR:  The %s option is required\n\0"
+/*  2437 */ "%s: option `%s' cannot have an argument\n\0"
+/*  2478 */ "%s: cannot allocate new argument vector\n\0"
+/*  2519 */ "%s: Command line arguments not allowed\n\0"
+/*  2559 */ "error %d (%s) creating %s\n\0"
+/*  2586 */ "Options are specified by single or double hyphens and their name.\n\0"
+/*  2653 */ "%s error:  `%s' does not match any %s keywords\n\0"
+/*  2701 */ "\t\t\t\t- may appear multiple times\n\0"
+/*  2734 */ "\t\t\t\t- may not be preset\n\0"
+/*  2759 */ "The 'reset-option' option requires an argument\n\0"
+/*  2807 */ "   Arg Option-Name    Description\n\0"
+/*  2842 */ "  Flg Arg Option-Name    Description\n\0"
+/*  2880 */ "error %d (%s) stat-ing %s\n\0"
+/*  2907 */ "%s(optionRestore): error: no saved option state\n\0"
+/*  2956 */ "none\0"
+/*  2961 */ "'%s' not defined\n\0"
+/*  2979 */ "'%s' is not a command line option\n\0"
+/*  3014 */ "ERROR:  The %s option must appear %d times\n\0"
+/*  3058 */ "error:  cannot load options from non-regular file %s\n\0"
+/*  3112 */ "%s error:  `%s' is not a recognizable number\n\0"
+/*  3158 */ "%s error:  `%s' is not a recognizable date/time\n\0"
+/*  3207 */ "%s error:  `%s' is not a recognizable time duration\n\0"
+/*  3260 */ " %3s %s\0"
+/*  3268 */ "The '-#<number>' option may omit the hash char\n\0"
+/*  3316 */ "one %s%s option allowed\n\0"
+/*  3341 */ "All arguments are named options.\n\0"
+/*  3375 */ "Write failure to output file\0"
+/*  3404 */ " - reading file %s\0"
+/*  3423 */ "\n"
+            "please send bug reports to:  %s\n\0"
+/*  3457 */ "\t\t\t\t- may NOT appear - preset only\n\0"
+/*  3493 */ "#  preset/initialization file\n"
+            "#  %s#\n\0"
+/*  3531 */ "\n"
+            "The following option preset mechanisms are supported:\n\0"
+/*  3587 */ "prohibits these options:\n\0"
+/*  3613 */ "Operands and options may be intermixed.  They will be reordered.\n\0"
+/*  3679 */ "%s%ld to %ld\0"
+/*  3692 */ "%sgreater than or equal to %ld\0"
+/*  3723 */ "%sIt must lie in one of the ranges:\n\0"
+/*  3760 */ "%sIt must be in the range:\n\0"
+/*  3788 */ ", or\n\0"
+/*  3794 */ "%s error:  %s option value ``%s'' is out of range.\n\0"
+/*  3846 */ "%s%ld exactly\0"
+/*  3860 */ "%sis scalable with a suffix: k/K/m/M/g/G/t/T\n\0"
+/*  3906 */ "%sless than or equal to %ld\0"
+/*  3934 */ "The --reset-option has not been configured.\n\0"
+/*  3979 */ "ERROR:  %s option requires the %s option\n\0"
+/*  4021 */ " %3s %-14s %s\0"
+/*  4035 */ "requires these options:\n\0"
+/*  4060 */ "   Arg Option-Name   Req?  Description\n\0"
+/*  4100 */ "  Flg Arg Option-Name   Req?  Description\n\0"
+/*  4143 */ "-_^\0"
+/*  4147 */ "or you may use a numeric representation.  Preceding these with a '!' will\n"
+            "clear the bits, specifying 'none' will clear all bits, and 'all' will set them\n"
+            "all.  Multiple entries may be passed as an option argument list.\n\0"
+/*  4366 */ "%s\0"
+/*  4369 */ "      \0"
+/*  4376 */ "T/F\0"
+/*  4380 */ "\n"
+            "%s\n\n"
+            "%s\0"
+/*  4388 */ "Fil\0"
+/*  4392 */ "KWd\0"
+/*  4396 */ "Mbr\0"
+/*  4400 */ "Tim\0"
+/*  4404 */ "Cpx\0"
+/*  4408 */ "no \0"
+/*  4412 */ "Num\0"
+/*  4416 */ "opt\0"
+/*  4420 */ "YES\0"
+/*  4424 */ "Str\0"
+/*  4428 */ "\t\t\t\t- \0"
+/*  4435 */ "\t\t\t\t-- and \0"
+/*  4447 */ "\t\t\t\t%s\n\0"
+/*  4455 */ "   \0"
+/*  4459 */ "  \0"
+/*  4462 */ "\t\t\t\t- may appear up to %d times\n\0"
+/*  4495 */ "The valid \"%s\" option keywords are:\n\0"
+/*  4532 */ "These additional options are:\0"
+/*  4562 */ "The next option supports vendor supported extra options:";
 
 
   /*
@@ -376,44 +387,45 @@ static char const usage_txt[4435] =
    *  Aren't you glad you don't maintain this by hand?
    */
   usage_text_t option_usage_text = {
-    142,
+    145,
     eng_zGnuBoolArg, eng_zGnuKeyArg,  eng_zGnuFileArg, eng_zGnuKeyLArg,
     eng_zGnuTimeArg, eng_zGnuNumArg,  eng_zGnuStrArg,
     {
       usage_txt +   0, usage_txt +  27, usage_txt +  79, usage_txt + 125,
       usage_txt + 224, usage_txt + 260, usage_txt + 310, usage_txt + 343,
       usage_txt + 434, usage_txt + 493, usage_txt + 543, usage_txt + 547,
-      usage_txt + 574, usage_txt + 623, usage_txt + 651, usage_txt + 688,
-      usage_txt + 713, usage_txt + 739, usage_txt + 779, usage_txt + 916,
-      usage_txt + 964, usage_txt +1018, usage_txt +1031, usage_txt +1039,
-      usage_txt +1081, usage_txt +1105, usage_txt +1145, usage_txt +1160,
-      usage_txt +1190, usage_txt +1216, usage_txt +1229, usage_txt +1243,
-      usage_txt +1290, usage_txt +1296, usage_txt +1399, usage_txt +1411,
-      usage_txt +1462, usage_txt +1491, usage_txt +1542, usage_txt +1576,
-      usage_txt +1617, usage_txt +1640, usage_txt +1666, usage_txt +1697,
-      usage_txt +1711, usage_txt +1726, usage_txt +1757, usage_txt +1784,
-      usage_txt +1890, usage_txt +1896, usage_txt +1902, usage_txt +1909,
-      usage_txt +1920, usage_txt +1946, usage_txt +1972, usage_txt +1980,
-      usage_txt +2016, usage_txt +2067, usage_txt +2123, usage_txt +2157,
-      usage_txt +2195, usage_txt +2260, usage_txt +2303, usage_txt +2338,
-      usage_txt +2379, usage_txt +2420, usage_txt +2460, usage_txt +2487,
-      usage_txt +2554, usage_txt +2602, usage_txt +2635, usage_txt +2660,
-      usage_txt +2708, usage_txt +2743, usage_txt +2781, usage_txt +2808,
-      usage_txt +2857, usage_txt +2862, usage_txt +2880, usage_txt +2915,
-      usage_txt +2959, usage_txt +3013, usage_txt +3059, usage_txt +3108,
-      usage_txt +3161, usage_txt +3169, usage_txt +3217, usage_txt +3219,
-      usage_txt +3244, usage_txt +3278, usage_txt +3307, usage_txt +3326,
-      usage_txt +3360, usage_txt +3396, usage_txt +3434, usage_txt +3490,
-      usage_txt +3516, usage_txt +3582, usage_txt +3595, usage_txt +3626,
-      usage_txt +3663, usage_txt +3691, usage_txt +3697, usage_txt +3749,
-      usage_txt +3763, usage_txt +3809, usage_txt +3837, usage_txt +3882,
-      usage_txt +3924, usage_txt +3938, usage_txt +3963, usage_txt +4003,
-      usage_txt +4046, usage_txt +4050, usage_txt +4269, usage_txt +4272,
-      usage_txt +4279, usage_txt +4283, usage_txt +4291, usage_txt +4295,
-      usage_txt +4299, usage_txt +4303, usage_txt +4307, usage_txt +4311,
-      usage_txt +4315, usage_txt +4319, usage_txt +4323, usage_txt +4327,
-      usage_txt +4331, usage_txt +4338, usage_txt +4350, usage_txt +4358,
-      usage_txt +4362, usage_txt +4365, usage_txt +4398
+      usage_txt + 574, usage_txt + 623, usage_txt + 655, usage_txt + 707,
+      usage_txt + 715, usage_txt + 752, usage_txt + 777, usage_txt + 803,
+      usage_txt + 843, usage_txt + 980, usage_txt +1028, usage_txt +1082,
+      usage_txt +1095, usage_txt +1103, usage_txt +1145, usage_txt +1169,
+      usage_txt +1209, usage_txt +1224, usage_txt +1254, usage_txt +1280,
+      usage_txt +1293, usage_txt +1307, usage_txt +1354, usage_txt +1360,
+      usage_txt +1463, usage_txt +1475, usage_txt +1526, usage_txt +1555,
+      usage_txt +1606, usage_txt +1640, usage_txt +1681, usage_txt +1704,
+      usage_txt +1730, usage_txt +1761, usage_txt +1775, usage_txt +1790,
+      usage_txt +1821, usage_txt +1848, usage_txt +1954, usage_txt +1960,
+      usage_txt +1966, usage_txt +1973, usage_txt +1984, usage_txt +2010,
+      usage_txt +2036, usage_txt +2079, usage_txt +2115, usage_txt +2166,
+      usage_txt +2222, usage_txt +2256, usage_txt +2294, usage_txt +2359,
+      usage_txt +2402, usage_txt +2437, usage_txt +2478, usage_txt +2519,
+      usage_txt +2559, usage_txt +2586, usage_txt +2653, usage_txt +2701,
+      usage_txt +2734, usage_txt +2759, usage_txt +2807, usage_txt +2842,
+      usage_txt +2880, usage_txt +2907, usage_txt +2956, usage_txt +2961,
+      usage_txt +2979, usage_txt +3014, usage_txt +3058, usage_txt +3112,
+      usage_txt +3158, usage_txt +3207, usage_txt +3260, usage_txt +3268,
+      usage_txt +3316, usage_txt +3341, usage_txt +3375, usage_txt +3404,
+      usage_txt +3423, usage_txt +3457, usage_txt +3493, usage_txt +3531,
+      usage_txt +3587, usage_txt +3613, usage_txt +3679, usage_txt +3692,
+      usage_txt +3723, usage_txt +3760, usage_txt +3788, usage_txt +3794,
+      usage_txt +3846, usage_txt +3860, usage_txt +3906, usage_txt +3934,
+      usage_txt +3979, usage_txt +4021, usage_txt +4035, usage_txt +4060,
+      usage_txt +4100, usage_txt +4143, usage_txt +4147, usage_txt +4366,
+      usage_txt +4369, usage_txt +4376, usage_txt +4380, usage_txt +4388,
+      usage_txt +4392, usage_txt +4396, usage_txt +4400, usage_txt +4404,
+      usage_txt +4408, usage_txt +4412, usage_txt +4416, usage_txt +4420,
+      usage_txt +4424, usage_txt +4428, usage_txt +4435, usage_txt +4447,
+      usage_txt +4455, usage_txt +4459, usage_txt +4462, usage_txt +4495,
+      usage_txt +4532, usage_txt +4562
     }
   };
 
diff --git a/sntp/libopts/check.c b/sntp/libopts/check.c
new file mode 100644 (file)
index 0000000..b4355b4
--- /dev/null
@@ -0,0 +1,164 @@
+/**
+ * @file check.c
+ *
+ * @brief consistency checks.
+ *
+ *  Time-stamp:      "2011-05-24 17:50:10 bkorb"
+ *
+ *  This file contains the routines that deal with processing quoted strings
+ *  into an internal format.
+ *
+ *  This file is part of AutoOpts, a companion to AutoGen.
+ *  AutoOpts is free software.
+ *  AutoOpts is Copyright (c) 1992-2011 by Bruce Korb - all rights reserved
+ *
+ *  AutoOpts is available under any one of two licenses.  The license
+ *  in use must be one of these two and the choice is under the control
+ *  of the user of the license.
+ *
+ *   The GNU Lesser General Public License, version 3 or later
+ *      See the files "COPYING.lgplv3" and "COPYING.gplv3"
+ *
+ *   The Modified Berkeley Software Distribution License
+ *      See the file "COPYING.mbsd"
+ *
+ *  These files have the following md5sums:
+ *
+ *  43b91e8ca915626ed3818ffb1b71248b pkg/libopts/COPYING.gplv3
+ *  06a1a2e4760c90ea5e1dad8dfaac4d39 pkg/libopts/COPYING.lgplv3
+ *  66a5cedaf62c4b2637025f049f9b826f pkg/libopts/COPYING.mbsd
+ */
+
+/**
+ *  Check for conflicts based on "must" and "cannot" attributes.
+ */
+static ag_bool
+has_conflict(tOptions * pOpts, tOptDesc * pOD)
+{
+    if (pOD->pOptMust != NULL) {
+        int const * pMust = pOD->pOptMust;
+
+        while (*pMust != NO_EQUIVALENT) {
+            tOptDesc * p = pOpts->pOptDesc + *(pMust++);
+            if (UNUSED_OPT(p)) {
+                const tOptDesc * pN = pOpts->pOptDesc + pMust[-1];
+                fprintf(stderr, zReqFmt, pOD->pz_Name, pN->pz_Name);
+                return AG_TRUE;
+            }
+        }
+    }
+
+    if (pOD->pOptCant != NULL) {
+        int const * pCant = pOD->pOptCant;
+
+        while (*pCant != NO_EQUIVALENT) {
+            tOptDesc * p = pOpts->pOptDesc + *(pCant++);
+            if (SELECTED_OPT(p)) {
+                const tOptDesc* pN = pOpts->pOptDesc + pCant[-1];
+                fprintf(stderr, zCantFmt, pOD->pz_Name, pN->pz_Name);
+                return AG_TRUE;
+            }
+        }
+    }
+
+    return AG_FALSE;
+}
+
+/**
+ *  Check that the option occurs often enough.  Too often is already checked.
+ */
+static ag_bool
+occurs_enough(tOptions * pOpts, tOptDesc * pOD)
+{
+    /*
+     *  IF the occurrence counts have been satisfied,
+     *  THEN there is no problem.
+     */
+    if (pOD->optOccCt >= pOD->optMinCt)
+        return AG_TRUE;
+
+    /*
+     *  IF MUST_SET means SET and PRESET are okay,
+     *  so min occurrence count doesn't count
+     */
+    if (  (pOD->fOptState & OPTST_MUST_SET)
+       && (pOD->fOptState & (OPTST_PRESET | OPTST_SET)) )
+        return AG_TRUE;
+
+    if (pOD->optMinCt > 1)
+         fprintf(stderr, zNotEnough, pOD->pz_Name, pOD->optMinCt);
+    else fprintf(stderr, zNeedOne, pOD->pz_Name);
+    return AG_FALSE;
+}
+
+/**
+ *  Verify option consistency.
+ *
+ *  Make sure that the argument list passes our consistency tests.
+ */
+LOCAL ag_bool
+is_consistent(tOptions * pOpts)
+{
+    tOptDesc * pOD   = pOpts->pOptDesc;
+    int        oCt   = pOpts->presetOptCt;
+
+    /*
+     *  FOR each of "oCt" options, ...
+     */
+    for (;;) {
+        /*
+         *  IF the current option was provided on the command line
+         *  THEN ensure that any "MUST" requirements are not
+         *       "DEFAULT" (unspecified) *AND* ensure that any
+         *       "CANT" options have not been SET or DEFINED.
+         */
+        if (SELECTED_OPT(pOD)) {
+            if (has_conflict(pOpts, pOD))
+                return AG_FALSE;
+        }
+
+        /*
+         *  IF       this option is not equivalenced to another,
+         *        OR it is equivalenced to itself (is the equiv. root)
+         *  THEN we need to make sure it occurs often enough.
+         */
+        if (  (pOD->optEquivIndex == NO_EQUIVALENT)
+           || (pOD->optEquivIndex == pOD->optIndex) )
+
+            if (! occurs_enough(pOpts, pOD))
+                return AG_FALSE;
+
+        if (--oCt <= 0)
+            break;
+        pOD++;
+    }
+
+    /*
+     *  IF we are stopping on errors, check to see if any remaining
+     *  arguments are required to be there or prohibited from being there.
+     */
+    if ((pOpts->fOptSet & OPTPROC_ERRSTOP) != 0) {
+
+        /*
+         *  Check for prohibition
+         */
+        if ((pOpts->fOptSet & OPTPROC_NO_ARGS) != 0) {
+            if (pOpts->origArgCt > pOpts->curOptIdx) {
+                fprintf(stderr, zNoArgs, pOpts->pzProgName);
+                return AG_FALSE;
+            }
+        }
+
+        /*
+         *  ELSE not prohibited, check for being required
+         */
+        else if ((pOpts->fOptSet & OPTPROC_ARGS_REQ) != 0) {
+            if (pOpts->origArgCt <= pOpts->curOptIdx) {
+                fprintf(stderr, zArgsMust, pOpts->pzProgName);
+                return AG_FALSE;
+            }
+        }
+    }
+
+    return AG_TRUE;
+}
index 35e82d591f9f234830b2c017feee0e72b59dc5fa..758ce272da697bde9ab0463c362ca49f183cd056 100644 (file)
@@ -1,7 +1,7 @@
 /**
  * \file configfile.c
  *
- *  Time-stamp:      "2011-04-06 09:31:24 bkorb"
+ *  Time-stamp:      "2011-12-17 12:51:30 bkorb"
  *
  *  configuration/rc/ini file handling.
  *
@@ -26,9 +26,6 @@
  *  66a5cedaf62c4b2637025f049f9b826f pkg/libopts/COPYING.mbsd
  */
 
-static void
-set_usage_flags(tOptions * opts, char const * flg_txt);
-
 /* = = = START-STATIC-FORWARD = = = */
 static void
 file_preset(tOptions * opts, char const * fname, int dir);
@@ -291,7 +288,9 @@ optionFindNextValue(const tOptDesc * pOptDesc, const tOptionValue * pPrevVal,
  *  This routine will find an entry in a nested value option or configurable.
  *  If "valueName" is NULL, then the first entry is returned.  Otherwise,
  *  the first entry with a name that exactly matches the argument will be
- *  returned.
+ *  returned.  If there is no matching value, NULL is returned and errno is
+ *  set to ENOENT. If the provided option value is not a hierarchical value,
+ *  NULL is also returned and errno is set to EINVAL.
  *
  * err:
  *  The returned result is NULL and errno is set:
@@ -304,27 +303,26 @@ optionFindNextValue(const tOptDesc * pOptDesc, const tOptionValue * pPrevVal,
  *  @end itemize
 =*/
 const tOptionValue*
-optionGetValue(const tOptionValue* pOld, char const* pzValName)
+optionGetValue(tOptionValue const * pOld, char const * pzValName)
 {
-    tArgList*     pAL;
-    tOptionValue* pRes = NULL;
+    tArgList *     pAL;
+    tOptionValue * pRes = NULL;
 
     if ((pOld == NULL) || (pOld->valType != OPARG_TYPE_HIERARCHY)) {
         errno = EINVAL;
-        return NULL;
+        return pRes;
     }
     pAL = pOld->v.nestVal;
 
     if (pAL->useCt > 0) {
-        int    ct    = pAL->useCt;
-        void** papOV = (void**)(pAL->apzArgs);
+        int     ct    = pAL->useCt;
+        void ** papOV = (void**)(pAL->apzArgs);
 
         if (pzValName == NULL) {
             pRes = (tOptionValue*)*papOV;
-        }
 
-        else do {
-            tOptionValue* pOV = *(papOV++);
+        else do {
+            tOptionValue * pOV = *(papOV++);
             if (strcmp(pOV->pzName, pzValName) == 0) {
                 pRes = pOV;
                 break;
@@ -408,7 +406,7 @@ file_preset(tOptions * opts, char const * fname, int dir)
 {
     tmap_info_t   cfgfile;
     tOptState     optst = OPTSTATE_INITIALIZER(PRESET);
-    tAoUL         st_flags = optst.flags;
+    unsigned long st_flags = optst.flags;
     char *        ftext =
         text_mmap(fname, PROT_READ|PROT_WRITE, MAP_PRIVATE, &cfgfile);
 
@@ -961,7 +959,7 @@ handle_struct(tOptions * pOpts, tOptState * pOS, char * pzText, int dir)
  *  (see "optionFileLoad()", the implementation for --load-opts)
  */
 LOCAL void
-internalFileLoad(tOptions* pOpts)
+intern_file_load(tOptions* pOpts)
 {
     uint32_t  svfl;
     int       idx;
@@ -1090,9 +1088,9 @@ internalFileLoad(tOptions* pOpts)
  *       always be returned.
 =*/
 int
-optionFileLoad(tOptions* pOpts, char const* pzProgram)
+optionFileLoad(tOptions * pOpts, char const * pzProgram)
 {
-    if (! SUCCESSFUL(validateOptionsStruct(pOpts, pzProgram)))
+    if (! SUCCESSFUL(validate_struct(pOpts, pzProgram)))
         return -1;
 
     {
@@ -1101,7 +1099,7 @@ optionFileLoad(tOptions* pOpts, char const* pzProgram)
         *pp = pzProgram;
     }
 
-    internalFileLoad(pOpts);
+    intern_file_load(pOpts);
     return 0;
 }
 
@@ -1118,7 +1116,7 @@ optionFileLoad(tOptions* pOpts, char const* pzProgram)
  *  pOptDesc->optArg.argString.
 =*/
 void
-optionLoadOpt(tOptions* pOpts, tOptDesc* pOptDesc)
+optionLoadOpt(tOptions * pOpts, tOptDesc * pOptDesc)
 {
     struct stat sb;
 
@@ -1327,13 +1325,19 @@ skip_unkn(char* pzText)
  *  worry about validity.  (Some entry points are free to assume that
  *  the call is not the first to the library and, thus, that this has
  *  already been called.)
+ *
+ *  Upon successful completion, pzProgName and pzProgPath are set.
+ *
+ *  @param pOpts      program options descriptor
+ *  @param pzProgram  name of program, from argv[]
+ *  @returns SUCCESS or FAILURE
  */
 LOCAL tSuccess
-validateOptionsStruct(tOptions* pOpts, char const* pzProgram)
+validate_struct(tOptions * pOpts, char const * pzProgram)
 {
     if (pOpts == NULL) {
         fputs(zAO_Bad, stderr);
-        exit(EX_CONFIG);
+        return FAILURE;
     }
 
     /*
@@ -1383,9 +1387,15 @@ validateOptionsStruct(tOptions* pOpts, char const* pzProgram)
         char const *  pz = strrchr(pzProgram, DIRCH);
         char const ** pp =
             (char const **)(void **)&(pOpts->pzProgName);
-        if (pz == NULL)
-             *pp = pzProgram;
-        else *pp = pz+1;
+
+        if (pz != NULL) {
+            *pp = pz+1;
+        } else {
+            *pp = pzProgram;
+            pz = pathfind(getenv("PATH"), (char *)pzProgram, "rx");
+            if (pz != NULL)
+                pzProgram = (void *)pz;
+        }
 
         pp  = (char const **)(void **)&(pOpts->pzProgPath);
         *pp = pzProgram;
similarity index 93%
rename from sntp/libopts/environment.c
rename to sntp/libopts/env.c
index 8530230ea7e6e5a118d3ad51735408cd5390b232..c8e9154af4cd6badfc96acc87d01aaad8d6a66d4 100644 (file)
@@ -2,7 +2,7 @@
 /**
  * \file environment.c
  *
- * Time-stamp:      "2011-04-06 09:35:55 bkorb"
+ * Time-stamp:      "2011-07-19 17:43:34 bkorb"
  *
  *  This file contains all of the routines that must be linked into
  *  an executable to use the generated option processing.  The optional
 /* = = = START-STATIC-FORWARD = = = */
 static void
 do_env_opt(tOptState * os, char * env_name,
-            tOptions* pOpts, teEnvPresetType type);
+            tOptions * pOpts, teEnvPresetType type);
 /* = = = END-STATIC-FORWARD = = = */
 
 /*
  *  doPrognameEnv - check for preset values from the ${PROGNAME}
  *  environment variable.  This is accomplished by parsing the text into
  *  tokens, temporarily replacing the arg vector and calling
- *  doImmediateOpts and/or doRegularOpts.
+ *  immediate_opts and/or regular_opts.
  */
 LOCAL void
-doPrognameEnv(tOptions* pOpts, teEnvPresetType type)
+doPrognameEnv(tOptions * pOpts, teEnvPresetType type)
 {
     char const*   pczOptStr = getenv(pOpts->pzPROGNAME);
     token_list_t* pTL;
@@ -87,17 +87,17 @@ doPrognameEnv(tOptions* pOpts, teEnvPresetType type)
 
     switch (type) {
     case ENV_IMM:
-        (void)doImmediateOpts(pOpts);
+        (void)immediate_opts(pOpts);
         break;
 
     case ENV_ALL:
-        (void)doImmediateOpts(pOpts);
+        (void)immediate_opts(pOpts);
         pOpts->curOptIdx = 1;
         pOpts->pzCurOpt  = NULL;
         /* FALLTHROUGH */
 
     case ENV_NON_IMM:
-        (void)doRegularOpts(pOpts);
+        (void)regular_opts(pOpts);
     }
 
     /*
@@ -111,7 +111,7 @@ doPrognameEnv(tOptions* pOpts, teEnvPresetType type)
 
 static void
 do_env_opt(tOptState * os, char * env_name,
-            tOptions* pOpts, teEnvPresetType type)
+            tOptions * pOpts, teEnvPresetType type)
 {
     os->pzOptArg = getenv(env_name);
     if (os->pzOptArg == NULL)
@@ -177,11 +177,11 @@ do_env_opt(tOptState * os, char * env_name,
 }
 
 /*
- *  doEnvPresets - check for preset values from the envrionment
+ *  env_presets - check for preset values from the envrionment
  *  This routine should process in all, immediate or normal modes....
  */
 LOCAL void
-doEnvPresets(tOptions* pOpts, teEnvPresetType type)
+env_presets(tOptions * pOpts, teEnvPresetType type)
 {
     int        ct;
     tOptState  st;
index bb6adf63bc0f3a695106d3f462ad29f9effd66ca..23994748cae9609b35eceb39d569bcde5971f739 100644 (file)
@@ -2,7 +2,7 @@
 /**
  * \file file.c
  *
- *  Time-stamp:      "2010-07-10 11:00:59 bkorb"
+ *  Time-stamp:      "2011-08-06 08:49:35 bkorb"
  *
  *  This file is part of AutoOpts, a companion to AutoGen.
  *  AutoOpts is free software.
  *  66a5cedaf62c4b2637025f049f9b826f pkg/libopts/COPYING.mbsd
  */
 
+/**
+ *  Make sure the directory containing the subject file exists and that
+ *  the file exists or does not exist, per the option requirements.
+ *
+ * @param ftype file existence type flags
+ * @param pOpts program option descriptor
+ * @param pOD   the option descriptor
+ */
+static void
+check_existence(teOptFileType ftype, tOptions * pOpts, tOptDesc * pOD)
+{
+    char const * fname = pOD->optArg.argString;
+    struct stat sb;
+
+    errno = 0;
+
+    switch (ftype & FTYPE_MODE_EXIST_MASK) {
+    case FTYPE_MODE_MUST_NOT_EXIST:
+        if ((stat(fname, &sb) == 0) || (errno != ENOENT)) {
+            if (errno == 0)
+                errno = EINVAL;
+            fprintf(stderr, zFSOptError, errno, strerror(errno),
+                    zFSOptErrNoExist, fname, pOD->pz_Name);
+            pOpts->pUsageProc(pOpts, EXIT_FAILURE);
+            /* NOTREACHED */
+        }
+        /* FALLTHROUGH */
+
+    default:
+    case FTYPE_MODE_MAY_EXIST:
+    {
+        char * p = strrchr(fname, DIRCH);
+        size_t l;
+
+        if (p == NULL)
+            /*
+             *  The file may or may not exist and its directory is ".".
+             *  Assume that "." exists.
+             */
+            break;
+
+        l = p - fname;
+        p = AGALOC(l + 1, "fname");
+        memcpy(p, fname, l);
+        p[l] = NUL;
+
+        if ((stat(p, &sb) != 0) || (errno = EINVAL, ! S_ISDIR(sb.st_mode))) {
+            fprintf(stderr, zFSOptError, errno, strerror(errno),
+                    zFSOptErrMayExist, fname, pOD->pz_Name);
+            pOpts->pUsageProc(pOpts, EXIT_FAILURE);
+            /* NOTREACHED */
+        }
+        AGFREE(p);
+        break;
+    }
+
+    case FTYPE_MODE_MUST_EXIST:
+        if (  (stat(fname, &sb) != 0)
+           || (errno = EINVAL, ! S_ISREG(sb.st_mode)) ) {
+            fprintf(stderr, zFSOptError, errno, strerror(errno),
+                    zFSOptErrMustExist, fname,
+                    pOD->pz_Name);
+            pOpts->pUsageProc(pOpts, EXIT_FAILURE);
+            /* NOTREACHED */
+        }
+        break;
+    }
+}
+
+/**
+ *  Open the specified file with open(2) and save the FD.
+ *
+ * @param pOpts program option descriptor
+ * @param pOD   the option descriptor
+ * @param mode  the open mode (uses int flags value)
+ */
+static void
+open_file_fd(tOptions * pOpts, tOptDesc * pOD, tuFileMode mode)
+{
+    int fd = open(pOD->optArg.argString, mode.file_flags);
+    if (fd < 0) {
+        fprintf(stderr, zFSOptError, errno, strerror(errno),
+                zFSOptErrOpen, pOD->optArg.argString, pOD->pz_Name);
+        pOpts->pUsageProc(pOpts, EXIT_FAILURE);
+        /* NOTREACHED */
+    }
+
+    if ((pOD->fOptState & OPTST_ALLOC_ARG) != 0)
+        pOD->optCookie = (void *)pOD->optArg.argString;
+    else
+        AGDUPSTR(pOD->optCookie, pOD->optArg.argString, "file name");
+
+    pOD->optArg.argFd = fd;
+    pOD->fOptState &= ~OPTST_ALLOC_ARG;
+}
+
+/**
+ *  Open the specified file with open(2) and save the FD.
+ *
+ * @param pOpts program option descriptor
+ * @param pOD   the option descriptor
+ * @param mode  the open mode (uses "char *" mode value)
+ */
+static void
+fopen_file_fp(tOptions * pOpts, tOptDesc * pOD, tuFileMode mode)
+{
+    FILE* fp = fopen(pOD->optArg.argString, mode.file_mode);
+    if (fp == NULL) {
+        fprintf(stderr, zFSOptError, errno, strerror(errno),
+                zFSOptErrFopen, pOD->optArg.argString, pOD->pz_Name);
+        pOpts->pUsageProc(pOpts, EXIT_FAILURE);
+        /* NOTREACHED */
+    }
+
+    if ((pOD->fOptState & OPTST_ALLOC_ARG) != 0)
+        pOD->optCookie = (void *)pOD->optArg.argString;
+    else
+        AGDUPSTR(pOD->optCookie, pOD->optArg.argString, "file name");
+
+    pOD->optArg.argFp = fp;
+    pOD->fOptState &= ~OPTST_ALLOC_ARG;
+}
+
 /*=export_func  optionFileCheck
  * private:
  *
  *   (FILE* pointer).
 =*/
 void
-optionFileCheck(tOptions* pOpts, tOptDesc* pOD,
+optionFileCheck(tOptions * pOpts, tOptDesc * pOD,
                 teOptFileType ftype, tuFileMode mode)
 {
     if (pOpts <= OPTPROC_EMIT_LIMIT) {
@@ -67,101 +190,13 @@ optionFileCheck(tOptions* pOpts, tOptDesc* pOD,
         return;
     }
 
-    {
-        struct stat sb;
-
-        errno = 0;
-
-        switch (ftype & FTYPE_MODE_EXIST_MASK) {
-        case FTYPE_MODE_MUST_NOT_EXIST:
-            if (  (stat(pOD->optArg.argString, &sb) == 0)
-               || (errno != ENOENT) ){
-                if (errno == 0)
-                    errno = EINVAL;
-                fprintf(stderr, zFSOptError, errno, strerror(errno),
-                        zFSOptErrNoExist, pOD->optArg.argString, pOD->pz_Name);
-                pOpts->pUsageProc(pOpts, EXIT_FAILURE);
-                /* NOTREACHED */
-            }
-            /* FALLTHROUGH */
-
-        default:
-        case FTYPE_MODE_MAY_EXIST:
-        {
-            char * p = strrchr(pOD->optArg.argString, DIRCH);
-            if (p == NULL)
-                break; /* assume "." always exists. */
-
-            *p = NUL;
-            if (  (stat(pOD->optArg.argString, &sb) != 0)
-               || (errno = EINVAL, ! S_ISDIR(sb.st_mode)) ){
-                fprintf(stderr, zFSOptError, errno, strerror(errno),
-                        zFSOptErrMayExist, pOD->optArg.argString, pOD->pz_Name);
-                pOpts->pUsageProc(pOpts, EXIT_FAILURE);
-                /* NOTREACHED */
-            }
-            if (p != NULL)
-                *p = DIRCH;
-            break;
-        }
-
-        case FTYPE_MODE_MUST_EXIST:
-            if (  (stat(pOD->optArg.argString, &sb) != 0)
-               || (errno = EINVAL, ! S_ISREG(sb.st_mode)) ){
-                fprintf(stderr, zFSOptError, errno, strerror(errno),
-                        zFSOptErrMustExist, pOD->optArg.argString,
-                        pOD->pz_Name);
-                pOpts->pUsageProc(pOpts, EXIT_FAILURE);
-                /* NOTREACHED */
-            }
-            break;
-        }
-    }
+    check_existence(ftype, pOpts, pOD);
 
     switch (ftype & FTYPE_MODE_OPEN_MASK) {
     default:
-    case FTYPE_MODE_NO_OPEN:
-        break;
-
-    case FTYPE_MODE_OPEN_FD:
-    {
-        int fd = open(pOD->optArg.argString, mode.file_flags);
-        if (fd < 0) {
-            fprintf(stderr, zFSOptError, errno, strerror(errno),
-                    zFSOptErrOpen, pOD->optArg.argString, pOD->pz_Name);
-            pOpts->pUsageProc(pOpts, EXIT_FAILURE);
-            /* NOTREACHED */
-        }
-
-        if ((pOD->fOptState & OPTST_ALLOC_ARG) != 0)
-            pOD->optCookie = (void *)pOD->optArg.argString;
-        else
-            AGDUPSTR(pOD->optCookie, pOD->optArg.argString, "file name");
-
-        pOD->optArg.argFd = fd;
-        pOD->fOptState &= ~OPTST_ALLOC_ARG;
-        break;
-    }
-
-    case FTYPE_MODE_FOPEN_FP:
-    {
-        FILE* fp = fopen(pOD->optArg.argString, mode.file_mode);
-        if (fp == NULL) {
-            fprintf(stderr, zFSOptError, errno, strerror(errno),
-                    zFSOptErrFopen, pOD->optArg.argString, pOD->pz_Name);
-            pOpts->pUsageProc(pOpts, EXIT_FAILURE);
-            /* NOTREACHED */
-        }
-
-        if ((pOD->fOptState & OPTST_ALLOC_ARG) != 0)
-            pOD->optCookie = (void *)pOD->optArg.argString;
-        else
-            AGDUPSTR(pOD->optCookie, pOD->optArg.argString, "file name");
-
-        pOD->optArg.argFp = fp;
-        pOD->fOptState &= ~OPTST_ALLOC_ARG;
-        break;
-    }
+    case FTYPE_MODE_NO_OPEN:  break;
+    case FTYPE_MODE_OPEN_FD:  open_file_fd( pOpts, pOD, mode); break;
+    case FTYPE_MODE_FOPEN_FP: fopen_file_fp(pOpts, pOD, mode); break;
     }
 }
 /*
diff --git a/sntp/libopts/find.c b/sntp/libopts/find.c
new file mode 100644 (file)
index 0000000..7a9ba17
--- /dev/null
@@ -0,0 +1,568 @@
+/**
+ * @file check.c
+ *
+ * @brief Hunt for options in the option descriptor list
+ *
+ *  Time-stamp:      "2011-08-07 13:15:45 bkorb"
+ *
+ *  This file contains the routines that deal with processing quoted strings
+ *  into an internal format.
+ *
+ *  This file is part of AutoOpts, a companion to AutoGen.
+ *  AutoOpts is free software.
+ *  AutoOpts is Copyright (c) 1992-2011 by Bruce Korb - all rights reserved
+ *
+ *  AutoOpts is available under any one of two licenses.  The license
+ *  in use must be one of these two and the choice is under the control
+ *  of the user of the license.
+ *
+ *   The GNU Lesser General Public License, version 3 or later
+ *      See the files "COPYING.lgplv3" and "COPYING.gplv3"
+ *
+ *   The Modified Berkeley Software Distribution License
+ *      See the file "COPYING.mbsd"
+ *
+ *  These files have the following md5sums:
+ *
+ *  43b91e8ca915626ed3818ffb1b71248b pkg/libopts/COPYING.gplv3
+ *  06a1a2e4760c90ea5e1dad8dfaac4d39 pkg/libopts/COPYING.lgplv3
+ *  66a5cedaf62c4b2637025f049f9b826f pkg/libopts/COPYING.mbsd
+ */
+
+/**
+ * find the name and name length we are looking for
+ */
+static int
+parse_opt(char const ** nm_pp, char ** arg_pp, char * buf, size_t bufsz)
+{
+    int  res = 0;
+    char const * p = *nm_pp;
+    *arg_pp  = NULL;
+
+    for (;;) {
+        switch (*(p++)) {
+        case NUL: return res;
+
+        case '=':
+            if (res >= bufsz)
+                return -1;
+
+            memcpy(buf, *nm_pp, res);
+
+            buf[res] = NUL;
+            *nm_pp   = buf;
+            *arg_pp  = (char *)p;
+            return res;
+
+        default:
+            res++;
+        }
+    }
+}
+
+/**
+ *  print out the options that match the given name.
+ *
+ * @param pOpts      option data
+ * @param opt_name   name of option to look for
+ */
+static void
+opt_ambiguities(tOptions * opts, char const * name, int nm_len)
+{
+    char const * const hyph =
+        NAMED_OPTS(opts) ? "" : "--";
+
+    tOptDesc * pOD = opts->pOptDesc;
+    int        idx = 0;
+
+    fputs(zAmbigList, stderr);
+    do  {
+        if (strneqvcmp(name, pOD->pz_Name, nm_len) == 0)
+            fprintf(stderr, zAmbiguous, hyph, pOD->pz_Name);
+
+        else if (  (pOD->pz_DisableName != NULL)
+                && (strneqvcmp(name, pOD->pz_DisableName, nm_len) == 0)
+                )
+            fprintf(stderr, zAmbiguous, hyph, pOD->pz_DisableName);
+    } while (pOD++, (++idx < opts->optCt));
+}
+
+/**
+ *  Determine the number of options that match the name
+ *
+ * @param pOpts      option data
+ * @param opt_name   name of option to look for
+ * @param nm_len     length of provided name
+ * @param index      pointer to int for option index
+ * @param disable    pointer to bool to mark disabled option
+ * @return count of options that match
+ */
+static int
+opt_match_ct(tOptions * opts, char const * name, int nm_len,
+             int * ixp, ag_bool * disable)
+{
+    int   matchCt  = 0;
+    int   idx      = 0;
+    int   idxLim   = opts->optCt;
+    tOptDesc * pOD = opts->pOptDesc;
+
+    do  {
+        /*
+         *  If option disabled or a doc option, skip to next
+         */
+        if (pOD->pz_Name == NULL)
+            continue;
+
+        if (  SKIP_OPT(pOD)
+           && (pOD->fOptState != (OPTST_OMITTED | OPTST_NO_INIT)))
+            continue;
+
+        if (strneqvcmp(name, pOD->pz_Name, nm_len) == 0) {
+            /*
+             *  IF we have a complete match
+             *  THEN it takes priority over any already located partial
+             */
+            if (pOD->pz_Name[ nm_len ] == NUL) {
+                *ixp = idx;
+                return 1;
+            }
+        }
+
+        /*
+         *  IF       there is a disable name
+         *     *AND* the option name matches the disable name
+         *  THEN ...
+         */
+        else if (  (pOD->pz_DisableName != NULL)
+                && (strneqvcmp(name, pOD->pz_DisableName, nm_len) == 0)
+                )  {
+            *disable = AG_TRUE;
+
+            /*
+             *  IF we have a complete match
+             *  THEN it takes priority over any already located partial
+             */
+            if (pOD->pz_DisableName[ nm_len ] == NUL) {
+                *ixp = idx;
+                return 1;
+            }
+        }
+
+        else
+            continue; /* does not match any option */
+
+        /*
+         *  We found a full or partial match, either regular or disabling.
+         *  Remember the index for later.
+         */
+        *ixp = idx;
+        ++matchCt;
+
+    } while (pOD++, (++idx < idxLim));
+
+    return matchCt;
+}
+
+/**
+ *  Set the option to the indicated option number.
+ *
+ * @param opts      option data
+ * @param arg       option argument (if glued to name)
+ * @param idx       option index
+ * @param disable   mark disabled option
+ * @param st        state about current option
+ */
+static tSuccess
+opt_set(tOptions * opts, char * arg, int idx, ag_bool disable, tOptState * st)
+{
+    tOptDesc * pOD = opts->pOptDesc + idx;
+
+    if (SKIP_OPT(pOD)) {
+        if ((opts->fOptSet & OPTPROC_ERRSTOP) == 0)
+            return FAILURE;
+
+        fprintf(stderr, zDisabledErr, opts->pzProgName, pOD->pz_Name);
+        if (pOD->pzText != NULL)
+            fprintf(stderr, " -- %s", pOD->pzText);
+        fputc('\n', stderr);
+        (*opts->pUsageProc)(opts, EXIT_FAILURE);
+        /* NOTREACHED */
+        _exit(EXIT_FAILURE); /* to be certain */
+    }
+
+    /*
+     *  IF we found a disablement name,
+     *  THEN set the bit in the callers' flag word
+     */
+    if (disable)
+        st->flags |= OPTST_DISABLED;
+
+    st->pOD      = pOD;
+    st->pzOptArg = arg;
+    st->optType  = TOPT_LONG;
+
+    return SUCCESS;
+}
+
+/**
+ *  An option was not found.  Check for default option and set it
+ *  if there is one.  Otherwise, handle the error.
+ *
+ * @param opts   option data
+ * @param name   name of option to look for
+ * @param arg    option argument
+ * @param st     state about current option
+ *
+ * @return success status
+ */
+static tSuccess
+opt_unknown(tOptions * opts, char const * name, char * arg, tOptState * st)
+{
+    /*
+     *  IF there is no equal sign
+     *     *AND* we are using named arguments
+     *     *AND* there is a default named option,
+     *  THEN return that option.
+     */
+    if (  (arg == NULL)
+       && NAMED_OPTS(opts)
+       && (opts->specOptIdx.default_opt != NO_EQUIVALENT)) {
+
+        st->pOD      = opts->pOptDesc + opts->specOptIdx.default_opt;
+        st->pzOptArg = name;
+        st->optType  = TOPT_DEFAULT;
+        return SUCCESS;
+    }
+
+    if ((opts->fOptSet & OPTPROC_ERRSTOP) != 0) {
+        fprintf(stderr, zIllOptStr, opts->pzProgPath, name);
+        (*opts->pUsageProc)(opts, EXIT_FAILURE);
+        /* NOTREACHED */
+        _exit(EXIT_FAILURE); /* to be certain */
+    }
+
+    return FAILURE;
+}
+
+/**
+ *  Several options match the provided name.
+ *
+ * @param opts      option data
+ * @param name      name of option to look for
+ * @param match_ct  number of matching options
+ *
+ * @return success status (always FAILURE, if it returns)
+ */
+static tSuccess
+opt_ambiguous(tOptions * opts, char const * name, int match_ct)
+{
+    if ((opts->fOptSet & OPTPROC_ERRSTOP) != 0) {
+        fprintf(stderr, zAmbigOptStr, opts->pzProgPath, name, match_ct);
+        if (match_ct <= 4)
+            opt_ambiguities(opts, name, strlen(name));
+        (*opts->pUsageProc)(opts, EXIT_FAILURE);
+        /* NOTREACHED */
+        _exit(EXIT_FAILURE); /* to be certain */
+    }
+    return FAILURE;
+}
+
+/*=export_func  optionVendorOption
+ * private:
+ *
+ * what:  Process a vendor option
+ * arg:   + tOptions * + pOpts    + program options descriptor +
+ * arg:   + tOptDesc * + pOptDesc + the descriptor for this arg +
+ *
+ * doc:
+ *  For POSIX specified utilities, the options are constrained to the options,
+ *  @xref{config attributes, Program Configuration}.  AutoOpts clients should
+ *  never specify this directly.  It gets referenced when the option
+ *  definitions contain a "vendor-opt" attribute.
+=*/
+void
+optionVendorOption(tOptions * pOpts, tOptDesc * pOD)
+{
+    tOptState     opt_st   = OPTSTATE_INITIALIZER(PRESET);
+    unsigned long st_flags = opt_st.flags;
+    tSuccess      res;
+    char const *  vopt_str = pOD->optArg.argString;
+
+    if ((pOpts->fOptSet & OPTPROC_VENDOR_OPT) == 0)
+        goto illegal;
+
+    if ((pOD->fOptState & OPTPROC_IMMEDIATE) == 0)
+        st_flags = OPTST_DEFINED;
+    res = opt_find_long(pOpts, vopt_str, &opt_st);
+
+    switch (res) {
+    case FAILURE:
+    case PROBLEM:
+    illegal:
+        fprintf(stderr, zIllVendOptStr, vopt_str);
+        (*pOpts->pUsageProc)(pOpts, EXIT_FAILURE);
+        /* NOTREACHED */
+
+    case SUCCESS:
+        if (! SUCCESSFUL(get_opt_arg(pOpts, &opt_st)))
+            goto illegal;
+
+        /*
+         *  See if we are in immediate handling state.
+         */
+        if (pOpts->fOptSet & OPTPROC_IMMEDIATE) {
+            /*
+             *  See if the enclosed option is okay with that state.
+             */
+            if (DO_IMMEDIATELY(opt_st.flags))
+                (void)handle_opt(pOpts, &opt_st);
+
+        } else {
+            /*
+             *  non-immediate direction.
+             *  See if the enclosed option is okay with that state.
+             */
+            if (DO_NORMALLY(opt_st.flags) || DO_SECOND_TIME(opt_st.flags))
+                (void)handle_opt(pOpts, &opt_st);
+        }
+    }
+}
+
+/**
+ *  Find the option descriptor by full name.
+ *
+ * @param pOpts      option data
+ * @param opt_name   name of option to look for
+ * @param pOptState  state about current option
+ *
+ * @return success status
+ */
+LOCAL tSuccess
+opt_find_long(tOptions * pOpts, char const * opt_name, tOptState * pOptState)
+{
+    char    name_buf[128];
+    char *  opt_arg;
+    int     nm_len = parse_opt(&opt_name, &opt_arg, name_buf, sizeof(name_buf));
+
+    int     matchIdx = 0;
+    ag_bool disable  = AG_FALSE;
+    int     match_ct =
+        opt_match_ct(pOpts, opt_name, nm_len, &matchIdx, &disable);
+
+    /*
+     *  See if we found one match, no matches or multiple matches.
+     */
+    switch (match_ct) {
+    case 1:  return opt_set(pOpts, opt_arg, matchIdx, disable, pOptState);
+    case 0:  return opt_unknown(pOpts, opt_name, opt_arg, pOptState);
+    default: return opt_ambiguous(pOpts, opt_name, match_ct);
+    }
+}
+
+
+/**
+ *  Find the short option descriptor for the current option
+ *
+ * @param pOpts      option data
+ * @param optValue   option flag character
+ * @param pOptState  state about current option
+ */
+LOCAL tSuccess
+opt_find_short(tOptions* pOpts, uint_t optValue, tOptState* pOptState)
+{
+    tOptDesc*  pRes = pOpts->pOptDesc;
+    int        ct   = pOpts->optCt;
+
+    /*
+     *  Search the option list
+     */
+    do  {
+        if (optValue != pRes->optValue)
+            continue;
+
+        if (SKIP_OPT(pRes)) {
+            if (  (pRes->fOptState == (OPTST_OMITTED | OPTST_NO_INIT))
+               && (pRes->pz_Name != NULL)) {
+                fprintf(stderr, zDisabledErr, pOpts->pzProgPath, pRes->pz_Name);
+                if (pRes->pzText != NULL)
+                    fprintf(stderr, " -- %s", pRes->pzText);
+                fputc('\n', stderr);
+                (*pOpts->pUsageProc)(pOpts, EXIT_FAILURE);
+                /* NOTREACHED */
+                _exit(EXIT_FAILURE); /* to be certain */
+            }
+            goto short_opt_error;
+        }
+
+        pOptState->pOD     = pRes;
+        pOptState->optType = TOPT_SHORT;
+        return SUCCESS;
+
+    } while (pRes++, --ct > 0);
+
+    /*
+     *  IF    the character value is a digit
+     *    AND there is a special number option ("-n")
+     *  THEN the result is the "option" itself and the
+     *       option is the specially marked "number" option.
+     */
+    if (  IS_DEC_DIGIT_CHAR(optValue)
+       && (pOpts->specOptIdx.number_option != NO_EQUIVALENT) ) {
+        pOptState->pOD = \
+        pRes           = pOpts->pOptDesc + pOpts->specOptIdx.number_option;
+        (pOpts->pzCurOpt)--;
+        pOptState->optType = TOPT_SHORT;
+        return SUCCESS;
+    }
+
+short_opt_error:
+
+    /*
+     *  IF we are to stop on errors (the default, actually)
+     *  THEN call the usage procedure.
+     */
+    if ((pOpts->fOptSet & OPTPROC_ERRSTOP) != 0) {
+        fprintf(stderr, zIllOptChr, pOpts->pzProgPath, optValue);
+        (*pOpts->pUsageProc)(pOpts, EXIT_FAILURE);
+        /* NOTREACHED */
+        _exit(EXIT_FAILURE); /* to be certain */
+    }
+
+    return FAILURE;
+}
+
+LOCAL tSuccess
+get_opt_arg(tOptions * pOpts, tOptState * pOptState)
+{
+    pOptState->flags |= (pOptState->pOD->fOptState & OPTST_PERSISTENT_MASK);
+
+    /*
+     *  Figure out what to do about option arguments.  An argument may be
+     *  required, not associated with the option, or be optional.  We detect the
+     *  latter by examining for an option marker on the next possible argument.
+     *  Disabled mode option selection also disables option arguments.
+     */
+    {
+        enum { ARG_NONE, ARG_MAY, ARG_MUST } arg_type = ARG_NONE;
+        tSuccess res;
+
+        if ((pOptState->flags & OPTST_DISABLED) != 0)
+            arg_type = ARG_NONE;
+
+        else if (OPTST_GET_ARGTYPE(pOptState->flags) == OPARG_TYPE_NONE)
+            arg_type = ARG_NONE;
+
+        else if (pOptState->flags & OPTST_ARG_OPTIONAL)
+            arg_type = ARG_MAY;
+
+        else
+            arg_type = ARG_MUST;
+
+        switch (arg_type) {
+        case ARG_MUST: res = next_opt_arg_must(pOpts, pOptState); break;
+        case ARG_MAY:  res = next_opt_arg_may( pOpts, pOptState); break;
+        case ARG_NONE: res = next_opt_arg_none(pOpts, pOptState); break;
+        }
+
+        return res;
+    }
+}
+
+/**
+ *  Find the option descriptor for the current option
+ */
+LOCAL tSuccess
+find_opt(tOptions * pOpts, tOptState * pOptState)
+{
+    /*
+     *  IF we are continuing a short option list (e.g. -xyz...)
+     *  THEN continue a single flag option.
+     *  OTHERWISE see if there is room to advance and then do so.
+     */
+    if ((pOpts->pzCurOpt != NULL) && (*pOpts->pzCurOpt != NUL))
+        return opt_find_short(pOpts, (tAoUC)*(pOpts->pzCurOpt), pOptState);
+
+    if (pOpts->curOptIdx >= pOpts->origArgCt)
+        return PROBLEM; /* NORMAL COMPLETION */
+
+    pOpts->pzCurOpt = pOpts->origArgVect[ pOpts->curOptIdx ];
+
+    /*
+     *  IF all arguments must be named options, ...
+     */
+    if (NAMED_OPTS(pOpts)) {
+        char *   pz  = pOpts->pzCurOpt;
+        int      def;
+        tSuccess res; 
+        tAoUS *  def_opt;
+
+        pOpts->curOptIdx++;
+
+        if (*pz != '-')
+            return opt_find_long(pOpts, pz, pOptState);
+
+        /*
+         *  The name is prefixed with one or more hyphens.  Strip them off
+         *  and disable the "default_opt" setting.  Use heavy recasting to
+         *  strip off the "const" quality of the "default_opt" field.
+         */
+        while (*(++pz) == '-')   ;
+        def_opt = (void *)&(pOpts->specOptIdx.default_opt);
+        def = *def_opt;
+        *def_opt = NO_EQUIVALENT;
+        res = opt_find_long(pOpts, pz, pOptState);
+        *def_opt = def;
+        return res;
+    }
+
+    /*
+     *  Note the kind of flag/option marker
+     */
+    if (*((pOpts->pzCurOpt)++) != '-')
+        return PROBLEM; /* NORMAL COMPLETION - this + rest are operands */
+
+    /*
+     *  Special hack for a hyphen by itself
+     */
+    if (*(pOpts->pzCurOpt) == NUL)
+        return PROBLEM; /* NORMAL COMPLETION - this + rest are operands */
+
+    /*
+     *  The current argument is to be processed as an option argument
+     */
+    pOpts->curOptIdx++;
+
+    /*
+     *  We have an option marker.
+     *  Test the next character for long option indication
+     */
+    if (pOpts->pzCurOpt[0] == '-') {
+        if (*++(pOpts->pzCurOpt) == NUL)
+            /*
+             *  NORMAL COMPLETION - NOT this arg, but rest are operands
+             */
+            return PROBLEM;
+
+        /*
+         *  We do not allow the hyphen to be used as a flag value.
+         *  Therefore, if long options are not to be accepted, we punt.
+         */
+        if ((pOpts->fOptSet & OPTPROC_LONGOPT) == 0) {
+            fprintf(stderr, zIllOptStr, pOpts->pzProgPath,
+                    pOpts->pzCurOpt-2);
+            return FAILURE;
+        }
+
+        return opt_find_long(pOpts, pOpts->pzCurOpt, pOptState);
+    }
+
+    /*
+     *  If short options are not allowed, then do long
+     *  option processing.  Otherwise the character must be a
+     *  short (i.e. single character) option.
+     */
+    if ((pOpts->fOptSet & OPTPROC_SHORTOPT) != 0)
+        return opt_find_short(pOpts, (tAoUC)*(pOpts->pzCurOpt), pOptState);
+
+    return opt_find_long(pOpts, pOpts->pzCurOpt, pOptState);
+}
index 05f2f1da46bbf511cef8418f4fb32f2b8a635821..fb9618555737f6469cb15b4f240d94a631220507 100644 (file)
@@ -2,11 +2,11 @@
  *  
  *  DO NOT EDIT THIS FILE   (genshell.c)
  *  
- *  It has been AutoGen-ed  April 29, 2011 at 03:43:59 PM by AutoGen 5.11.9
+ *  It has been AutoGen-ed  January 18, 2012 at 05:16:53 AM by AutoGen 5.14
  *  From the definitions    genshell.def
  *  and the template file   options
  *
- * Generated from AutoOpts 35:0:10 templates.
+ * Generated from AutoOpts 36:0:11 templates.
  *
  *  AutoOpts is a copyrighted work.  This source file is not encumbered
  *  by AutoOpts licensing, but is provided under the licensing terms chosen
  *  users discretion, the BSD license.  See the AutoOpts and/or libopts sources
  *  for details.
  *
- * This source file is copyrighted and licensed under the following terms:
+ * The genshellopt program is copyrighted and licensed
+ * under the following terms:
  *
- * genshellopt copyright (c) 1999-2011 Bruce Korb - all rights reserved
+ *  Copyright (C) 1999-2011 Bruce Korb, all rights reserved.
+ *  This is free software. It is licensed for use, modification and
+ *  redistribution under the terms of the
+ *  GNU General Public License, version 3 or later
+ *      <http://gnu.org/licenses/gpl.html>
  *
- * genshellopt is free software: you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- * 
- * genshellopt is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- * See the GNU General Public License for more details.
- * 
- * You should have received a copy of the GNU General Public License along
- * with this program.  If not, see <http://www.gnu.org/licenses/>.
-
+ *  genshellopt is free software: you can redistribute it and/or modify it
+ *  under the terms of the GNU General Public License as published by the
+ *  Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *  
+ *  genshellopt is distributed in the hope that it will be useful, but
+ *  WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ *  See the GNU General Public License for more details.
+ *  
+ *  You should have received a copy of the GNU General Public License along
+ *  with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
 #include <sys/types.h>
@@ -43,7 +47,6 @@
 
 #define OPTION_CODE_COMPILE 1
 #include "genshell.h"
-
 #ifdef  __cplusplus
 extern "C" {
 #endif
@@ -51,24 +54,8 @@ extern FILE * option_usage_fp;
 
 /* TRANSLATORS: choose the translation for option names wisely because you
                 cannot ever change your mind. */
-static char const zCopyright[260] =
-"genshellopt 1\n\
-Copyright (C) 1999-2011 Bruce Korb, all rights reserved.\n\
-This is free software. It is licensed for use, modification and\n\
-redistribution under the terms of the\n\
-GNU General Public License, version 3 or later\n\
-    <http://gnu.org/licenses/gpl.html>\n";
-static char const zCopyrightNotice[611] =
-"genshellopt is free software: you can redistribute it and/or modify it\n\
-under the terms of the GNU General Public License as published by the\n\
-Free Software Foundation, either version 3 of the License, or (at your\n\
-option) any later version.\n\n\
-genshellopt is distributed in the hope that it will be useful, but WITHOUT\n\
-ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or\n\
-FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License\n\
-for more details.\n\n\
-You should have received a copy of the GNU General Public License along\n\
-with this program.  If not, see <http://www.gnu.org/licenses/>.\n";
+#define zCopyright      (genshellopt_opt_strs+0)
+#define zLicenseDescrip (genshellopt_opt_strs+260)
 
 extern tUsageProc genshelloptUsage;
 
@@ -77,60 +64,105 @@ extern tUsageProc genshelloptUsage;
 #endif
 
 /*
- *  Script option description:
+ *  genshellopt option static const strings
  */
-static char const zScriptText[] =
-        "Output Script File";
-static char const zScript_NAME[]             = "SCRIPT";
-static char const zScript_Name[]             = "script";
-#define SCRIPT_FLAGS       (OPTST_DISABLED \
+static char const genshellopt_opt_strs[1690] =
+/*     0 */ "genshellopt 1\n"
+            "Copyright (C) 1999-2011 Bruce Korb, all rights reserved.\n"
+            "This is free software. It is licensed for use, modification and\n"
+            "redistribution under the terms of the\n"
+            "GNU General Public License, version 3 or later\n"
+            "    <http://gnu.org/licenses/gpl.html>\n\0"
+/*   260 */ "genshellopt is free software: you can redistribute it and/or modify it\n"
+            "under the terms of the GNU General Public License as published by the Free\n"
+            "Software Foundation, either version 3 of the License, or (at your option)\n"
+            "any later version.\n\n"
+            "genshellopt is distributed in the hope that it will be useful, but WITHOUT\n"
+            "ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or\n"
+            "FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for\n"
+            "more details.\n\n"
+            "You should have received a copy of the GNU General Public License along\n"
+            "with this program.  If not, see <http://www.gnu.org/licenses/>.\n\0"
+/*   871 */ "Output Script File\0"
+/*   890 */ "SCRIPT\0"
+/*   897 */ "script\0"
+/*   904 */ "Shell name (follows \"#!\" magic)\0"
+/*   936 */ "SHELL\0"
+/*   942 */ "no-shell\0"
+/*   951 */ "no\0"
+/*   954 */ "Display extended usage information and exit\0"
+/*   998 */ "help\0"
+/*  1003 */ "Extended usage information passed thru pager\0"
+/*  1048 */ "more-help\0"
+/*  1058 */ "Output version information and exit\0"
+/*  1094 */ "version\0"
+/*  1102 */ "GENSHELLOPT\0"
+/*  1114 */ "genshellopt - Generate Shell Option Processing Script - Ver. 1\n"
+            "USAGE:  %s [ -<flag> [<val>] | --<name>[{=| }<val>] ]...\n\0"
+/*  1235 */ "autogen-users@lists.sourceforge.net\0"
+/*  1271 */ "\n"
+            "Note that ``shell'' is only useful if the output file does not already\n"
+            "exist.  If it does, then the shell name and optional first argument will be\n"
+            "extracted from the script file.\n\0"
+/*  1452 */ "\n"
+            "If the script file already exists and contains Automated Option Processing\n"
+            "text, the second line of the file through the ending tag will be replaced\n"
+            "by the newly generated text.  The first ``#!'' line will be regenerated.\n\0"
+/*  1676 */ "genshellopt 1";
+
+/*
+ *  script option description:
+ */
+#define SCRIPT_DESC      (genshellopt_opt_strs+871)
+#define SCRIPT_NAME      (genshellopt_opt_strs+890)
+#define SCRIPT_name      (genshellopt_opt_strs+897)
+#define SCRIPT_FLAGS     (OPTST_DISABLED \
         | OPTST_SET_ARGTYPE(OPARG_TYPE_STRING))
 
 /*
- *  Shell option description:
+ *  shell option description:
  */
-static char const zShellText[] =
-        "Shell name (follows \"#!\" magic)";
-static char const zShell_NAME[]              = "SHELL";
-static char const zNotShell_Name[]           = "no-shell";
-static char const zNotShell_Pfx[]            = "no";
-#define zShell_Name                  (zNotShell_Name + 3)
-#define SHELL_FLAGS       (OPTST_INITENABLED \
+#define SHELL_DESC      (genshellopt_opt_strs+904)
+#define SHELL_NAME      (genshellopt_opt_strs+936)
+#define NOT_SHELL_name  (genshellopt_opt_strs+942)
+#define NOT_SHELL_PFX   (genshellopt_opt_strs+951)
+#define SHELL_name      (NOT_SHELL_name + 3)
+#define SHELL_FLAGS     (OPTST_INITENABLED \
         | OPTST_SET_ARGTYPE(OPARG_TYPE_STRING))
 
 /*
  *  Help/More_Help/Version option descriptions:
  */
-static char const zHelpText[]          = "Display extended usage information and exit";
-static char const zHelp_Name[]         = "help";
+#define HELP_DESC       (genshellopt_opt_strs+954)
+#define HELP_name       (genshellopt_opt_strs+998)
 #ifdef HAVE_WORKING_FORK
-#define OPTST_MORE_HELP_FLAGS   (OPTST_IMM | OPTST_NO_INIT)
-static char const zMore_Help_Name[]    = "more-help";
-static char const zMore_HelpText[]     = "Extended usage information passed thru pager";
+#define MORE_HELP_DESC  (genshellopt_opt_strs+1003)
+#define MORE_HELP_name  (genshellopt_opt_strs+1048)
+#define MORE_HELP_FLAGS (OPTST_IMM | OPTST_NO_INIT)
 #else
-#define OPTST_MORE_HELP_FLAGS   (OPTST_OMITTED | OPTST_NO_INIT)
-#define zMore_Help_Name   NULL
-#define zMore_HelpText    NULL
+#define MORE_HELP_DESC  NULL
+#define MORE_HELP_name  NULL
+#define MORE_HELP_FLAGS (OPTST_OMITTED | OPTST_NO_INIT)
 #endif
 #ifdef NO_OPTIONAL_OPT_ARGS
-#  define OPTST_VERSION_FLAGS   OPTST_IMM | OPTST_NO_INIT
+#  define VER_FLAGS     (OPTST_IMM | OPTST_NO_INIT)
 #else
-#  define OPTST_VERSION_FLAGS   OPTST_SET_ARGTYPE(OPARG_TYPE_STRING) | \
-                                OPTST_ARG_OPTIONAL | OPTST_IMM | OPTST_NO_INIT
+#  define VER_FLAGS     (OPTST_SET_ARGTYPE(OPARG_TYPE_STRING) | \
+                         OPTST_ARG_OPTIONAL | OPTST_IMM | OPTST_NO_INIT)
 #endif
-
-static char const zVersionText[]       = "Output version information and exit";
-static char const zVersion_Name[]      = "version";
+#define VER_DESC        (genshellopt_opt_strs+1058)
+#define VER_name        (genshellopt_opt_strs+1094)
 /*
  *  Declare option callback procedures
  */
 extern tOptProc
-    optionBooleanVal,    optionNestedVal,     optionNumericVal,
-    optionPagedUsage,    optionPrintVersion,  optionResetOpt,
-    optionStackArg,      optionTimeDate,      optionTimeVal,
-    optionUnstackArg,    optionVersionStderr;
+    optionBooleanVal,   optionNestedVal,    optionNumericVal,
+    optionPagedUsage,   optionPrintVersion, optionResetOpt,
+    optionStackArg,     optionTimeDate,     optionTimeVal,
+    optionUnstackArg,   optionVendorOption;
 static tOptProc
     doUsageOpt;
+#define VER_PROC        optionPrintVersion
 
 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  *
@@ -142,11 +174,11 @@ static tOptDesc optDesc[GENSHELL_OPTION_CT] = {
      /* equivalenced to  */ NO_EQUIVALENT,
      /* min, max, act ct */ 0, 1, 0,
      /* opt state flags  */ SCRIPT_FLAGS, 0,
-     /* last opt argumnt */ { NULL },
+     /* last opt argumnt */ { NULL }, /* --script */
      /* arg list/cookie  */ NULL,
      /* must/cannot opts */ NULL, NULL,
      /* option proc      */ NULL,
-     /* desc, NAME, name */ zScriptText, zScript_NAME, zScript_Name,
+     /* desc, NAME, name */ SCRIPT_DESC, SCRIPT_NAME, SCRIPT_name,
      /* disablement strs */ NULL, NULL },
 
   {  /* entry idx, value */ 1, VALUE_GENSHELL_OPT_SHELL,
@@ -154,29 +186,29 @@ static tOptDesc optDesc[GENSHELL_OPTION_CT] = {
      /* equivalenced to  */ NO_EQUIVALENT,
      /* min, max, act ct */ 0, 1, 0,
      /* opt state flags  */ SHELL_FLAGS, 0,
-     /* last opt argumnt */ { NULL },
+     /* last opt argumnt */ { NULL }, /* --shell */
      /* arg list/cookie  */ NULL,
      /* must/cannot opts */ NULL, NULL,
      /* option proc      */ NULL,
-     /* desc, NAME, name */ zShellText, zShell_NAME, zShell_Name,
-     /* disablement strs */ zNotShell_Name, zNotShell_Pfx },
+     /* desc, NAME, name */ SHELL_DESC, SHELL_NAME, SHELL_name,
+     /* disablement strs */ NOT_SHELL_name, NOT_SHELL_PFX },
 
   {  /* entry idx, value */ INDEX_GENSHELL_OPT_VERSION, VALUE_GENSHELL_OPT_VERSION,
-     /* equiv idx value  */ NO_EQUIVALENT, 0,
+     /* equiv idx value  */ NO_EQUIVALENT, VALUE_GENSHELL_OPT_VERSION,
      /* equivalenced to  */ NO_EQUIVALENT,
      /* min, max, act ct */ 0, 1, 0,
-     /* opt state flags  */ OPTST_VERSION_FLAGS, 0,
+     /* opt state flags  */ VER_FLAGS, 0,
      /* last opt argumnt */ { NULL },
      /* arg list/cookie  */ NULL,
      /* must/cannot opts */ NULL, NULL,
-     /* option proc      */ optionPrintVersion,
-     /* desc, NAME, name */ zVersionText, NULL, zVersion_Name,
+     /* option proc      */ VER_PROC,
+     /* desc, NAME, name */ VER_DESC, NULL, VER_name,
      /* disablement strs */ NULL, NULL },
 
 
 
   {  /* entry idx, value */ INDEX_GENSHELL_OPT_HELP, VALUE_GENSHELL_OPT_HELP,
-     /* equiv idx value  */ NO_EQUIVALENT, 0,
+     /* equiv idx value  */ NO_EQUIVALENT, VALUE_GENSHELL_OPT_HELP,
      /* equivalenced to  */ NO_EQUIVALENT,
      /* min, max, act ct */ 0, 1, 0,
      /* opt state flags  */ OPTST_IMM | OPTST_NO_INIT, 0,
@@ -184,44 +216,36 @@ static tOptDesc optDesc[GENSHELL_OPTION_CT] = {
      /* arg list/cookie  */ NULL,
      /* must/cannot opts */ NULL, NULL,
      /* option proc      */ doUsageOpt,
-     /* desc, NAME, name */ zHelpText, NULL, zHelp_Name,
+     /* desc, NAME, name */ HELP_DESC, NULL, HELP_name,
      /* disablement strs */ NULL, NULL },
 
   {  /* entry idx, value */ INDEX_GENSHELL_OPT_MORE_HELP, VALUE_GENSHELL_OPT_MORE_HELP,
-     /* equiv idx value  */ NO_EQUIVALENT, 0,
+     /* equiv idx value  */ NO_EQUIVALENT, VALUE_GENSHELL_OPT_MORE_HELP,
      /* equivalenced to  */ NO_EQUIVALENT,
      /* min, max, act ct */ 0, 1, 0,
-     /* opt state flags  */ OPTST_MORE_HELP_FLAGS, 0,
+     /* opt state flags  */ MORE_HELP_FLAGS, 0,
      /* last opt argumnt */ { NULL },
      /* arg list/cookie  */ NULL,
      /* must/cannot opts */ NULL,  NULL,
      /* option proc      */ optionPagedUsage,
-     /* desc, NAME, name */ zMore_HelpText, NULL, zMore_Help_Name,
+     /* desc, NAME, name */ MORE_HELP_DESC, NULL, MORE_HELP_name,
      /* disablement strs */ NULL, NULL }
 };
 
+
 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  *
  *  Define the Genshellopt Option Environment
  */
-static char const zPROGNAME[12] = "GENSHELLOPT";
-static char const zUsageTitle[121] =
-"genshellopt - Generate Shell Option Processing Script - Ver. 1\n\
-USAGE:  %s [ -<flag> [<val>] | --<name>[{=| }<val>] ]...\n";
-#define zRcName     NULL
-#define apzHomeList NULL
-
-static char const zBugsAddr[36]    = "autogen-users@lists.sourceforge.net";
-static char const zExplain[] = "\n\
-Note that ``shell'' is only useful if the output file does not already\n\
-exist.  If it does, then the shell name and optional first argument will\n\
-be extracted from the script file.\n";
-static char const zDetail[237] = "\n\
-If the script file already exists and contains Automated Option Processing\n\
-text, the second line of the file through the ending tag will be replaced\n\
-by the newly generated text.  The first ``#!''  line will be regenerated.\n";
-static char const zFullVersion[] = GENSHELLOPT_FULL_VERSION;
-/* extracted from optcode.tlib near line 515 */
+#define zPROGNAME       (genshellopt_opt_strs+1102)
+#define zUsageTitle     (genshellopt_opt_strs+1114)
+#define zRcName         NULL
+#define apzHomeList     NULL
+#define zBugsAddr       (genshellopt_opt_strs+1235)
+#define zExplain        (genshellopt_opt_strs+1271)
+#define zDetail         (genshellopt_opt_strs+1452)
+#define zFullVersion    (genshellopt_opt_strs+1676)
+/* extracted from optcode.tlib near line 315 */
 
 #if defined(ENABLE_NLS)
 # define OPTPROC_BASE OPTPROC_TRANSLATE
@@ -232,8 +256,21 @@ static char const zFullVersion[] = GENSHELLOPT_FULL_VERSION;
 #endif /* ENABLE_NLS */
 
 
-#define genshellopt_full_usage NULL
-#define genshellopt_short_usage NULL
+#define genshellopt_full_usage (NULL)
+
+#define genshellopt_short_usage (NULL)
+
+/*
+ *  Create the static procedure(s) declared above.
+ */
+static void
+doUsageOpt(tOptions * pOptions, tOptDesc * pOptDesc)
+{
+    (void)pOptions;
+    GENSHELL_USAGE(GENSHELLOPT_EXIT_SUCCESS);
+}
+/* extracted from optmain.tlib near line 1148 */
+
 #ifndef  PKGDATADIR
 # define PKGDATADIR ""
 #endif
@@ -266,7 +303,7 @@ tOptions genshelloptOptions = {
     + OPTPROC_NO_ARGS ),
     0, NULL,                    /* current option index, current option */
     NULL,         NULL,         zPROGNAME,
-    zRcName,      zCopyright,   zCopyrightNotice,
+    zRcName,      zCopyright,   zLicenseDescrip,
     zFullVersion, apzHomeList,  zUsageTitle,
     zExplain,     zDetail,      optDesc,
     zBugsAddr,                  /* address to send bugs to */
@@ -287,17 +324,6 @@ tOptions genshelloptOptions = {
     PKGDATADIR, genshellopt_packager_info
 };
 
-/*
- *  Create the static procedure(s) declared above.
- */
-static void
-doUsageOpt(tOptions * pOptions, tOptDesc * pOptDesc)
-{
-    (void)pOptions;
-    GENSHELL_USAGE(GENSHELLOPT_EXIT_SUCCESS);
-}
-/* extracted from optcode.tlib near line 666 */
-
 #if ENABLE_NLS
 #include <stdio.h>
 #include <stdlib.h>
index e5457a764090ff56d27d85f53608396536861352..83ffb070354187d40d5c413334d24f468a3e3302 100644 (file)
@@ -2,11 +2,11 @@
  *  
  *  DO NOT EDIT THIS FILE   (genshell.h)
  *  
- *  It has been AutoGen-ed  April 29, 2011 at 03:43:59 PM by AutoGen 5.11.9
+ *  It has been AutoGen-ed  January 18, 2012 at 05:16:53 AM by AutoGen 5.14
  *  From the definitions    genshell.def
  *  and the template file   options
  *
- * Generated from AutoOpts 35:0:10 templates.
+ * Generated from AutoOpts 36:0:11 templates.
  *
  *  AutoOpts is a copyrighted work.  This header file is not encumbered
  *  by AutoOpts licensing, but is provided under the licensing terms chosen
  *  users discretion, the BSD license.  See the AutoOpts and/or libopts sources
  *  for details.
  *
- * This source file is copyrighted and licensed under the following terms:
+ * The genshellopt program is copyrighted and licensed
+ * under the following terms:
  *
- * genshellopt copyright (c) 1999-2011 Bruce Korb - all rights reserved
+ *  Copyright (C) 1999-2011 Bruce Korb, all rights reserved.
+ *  This is free software. It is licensed for use, modification and
+ *  redistribution under the terms of the
+ *  GNU General Public License, version 3 or later
+ *      <http://gnu.org/licenses/gpl.html>
  *
- * genshellopt is free software: you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- * 
- * genshellopt is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- * See the GNU General Public License for more details.
- * 
- * You should have received a copy of the GNU General Public License along
- * with this program.  If not, see <http://www.gnu.org/licenses/>.
-
+ *  genshellopt is free software: you can redistribute it and/or modify it
+ *  under the terms of the GNU General Public License as published by the
+ *  Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *  
+ *  genshellopt is distributed in the hope that it will be useful, but
+ *  WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ *  See the GNU General Public License for more details.
+ *  
+ *  You should have received a copy of the GNU General Public License along
+ *  with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 /*
  *  This file contains the programmatic interface to the Automated
@@ -51,7 +55,7 @@
  *  tolerable version is at least as old as what was current when the header
  *  template was released.
  */
-#define AO_TEMPLATE_VERSION 143360
+#define AO_TEMPLATE_VERSION 147456
 #if (AO_TEMPLATE_VERSION < OPTIONS_MINIMUM_VERSION) \
  || (AO_TEMPLATE_VERSION > OPTIONS_STRUCT_VERSION)
 # error option template version mismatches autoopts/options.h header
@@ -121,12 +125,13 @@ typedef enum {
                 genshelloptOptions.pzCurOpt  = NULL )
 #define START_GENSHELL_OPT       RESTART_GENSHELL_OPT(1)
 #define GENSHELL_USAGE(c)        (*genshelloptOptions.pUsageProc)(&genshelloptOptions, c)
-/* extracted from opthead.tlib near line 451 */
+/* extracted from opthead.tlib near line 469 */
 
 #ifdef  __cplusplus
 extern "C" {
 #endif
 
+
 /* * * * * *
  *
  *  Declare the genshellopt option descriptor.
@@ -136,10 +141,10 @@ extern tOptions genshelloptOptions;
 #if defined(ENABLE_NLS)
 # ifndef _
 #   include <stdio.h>
-    static inline char* aoGetsText(char const* pz) {
-        if (pz == NULL) return NULL;
-        return (char*)gettext(pz);
-    }
+static inline char* aoGetsText(char const* pz) {
+    if (pz == NULL) return NULL;
+    return (char*)gettext(pz);
+}
 #   define _(s)  aoGetsText(s)
 # endif /* _() */
 
index 15a070d928c5e15bc547605eae6337baff630939..ca256eb7efb055f49e9cc0c6e572f6c4f055d99b 100644 (file)
 #include "boolean.c"
 #include "configfile.c"
 #include "cook.c"
-#include "enumeration.c"
-#include "environment.c"
+#include "check.c"
+#include "enum.c"
+#include "env.c"
 #include "file.c"
+#include "find.c"
 #include "genshell.c"
 #include "load.c"
 #include "makeshell.c"
index 024dce9301a87915465fd191e981a9d0de3071bd..e4f231d4b78ac2e8592a43607ea5c6868b99b004 100644 (file)
@@ -1,7 +1,7 @@
 
 /**
  *  \file load.c
- *  Time-stamp:      "2010-12-18 11:46:07 bkorb"
+ *  Time-stamp:      "2011-12-17 12:53:04 bkorb"
  *
  *  This file contains the routines that deal with processing text strings
  *  for options, either from a NUL-terminated string passed in or from an
 
 /* = = = START-STATIC-FORWARD = = = */
 static ag_bool
-insertProgramPath(char * pzBuf, int bufSize, char const * pzName,
-                  char const * pzProgPath);
+add_prog_path(char * pzBuf, int bufSize, char const * pzName,
+              char const * pzProgPath);
 
 static ag_bool
-insertEnvVal(char * pzBuf, int bufSize, char const * pzName,
-             char const * pzProgPath);
+add_env_val(char * pzBuf, int bufSize, char const * pzName,
+            char const * pzProgPath);
 
 static char*
-assembleArgValue(char* pzTxt, tOptionLoadMode mode);
+assemble_arg_val(char* pzTxt, tOptionLoadMode mode);
 /* = = = END-STATIC-FORWARD = = = */
 
 /*=export_func  optionMakePath
@@ -127,7 +127,7 @@ optionMakePath(char * pzBuf, int bufSize, char const * pzName,
         return AG_FALSE;
 
     case '$':
-        if (! insertProgramPath(pzBuf, bufSize, pzName, pzProgPath))
+        if (! add_prog_path(pzBuf, bufSize, pzName, pzProgPath))
             return AG_FALSE;
         break;
 
@@ -141,7 +141,7 @@ optionMakePath(char * pzBuf, int bufSize, char const * pzName,
         break;
 
     default:
-        if (! insertEnvVal(pzBuf, bufSize, pzName, pzProgPath))
+        if (! add_env_val(pzBuf, bufSize, pzName, pzProgPath))
             return AG_FALSE;
     }
 
@@ -179,10 +179,9 @@ optionMakePath(char * pzBuf, int bufSize, char const * pzName,
     return AG_TRUE;
 }
 
-
 static ag_bool
-insertProgramPath(char * pzBuf, int bufSize, char const * pzName,
-                  char const * pzProgPath)
+add_prog_path(char * pzBuf, int bufSize, char const * pzName,
+              char const * pzProgPath)
 {
     char const*    pzPath;
     char const*    pz;
@@ -243,8 +242,8 @@ insertProgramPath(char * pzBuf, int bufSize, char const * pzName,
 
 
 static ag_bool
-insertEnvVal(char * pzBuf, int bufSize, char const * pzName,
-             char const * pzProgPath)
+add_env_val(char * pzBuf, int bufSize, char const * pzName,
+            char const * pzProgPath)
 {
     char* pzDir = pzBuf;
 
@@ -316,7 +315,7 @@ mungeString(char* pzTxt, tOptionLoadMode mode)
 
 
 static char*
-assembleArgValue(char* pzTxt, tOptionLoadMode mode)
+assemble_arg_val(char* pzTxt, tOptionLoadMode mode)
 {
     static char const zBrk[] = " \t\n:=";
     char* pzEnd = strpbrk(pzTxt, zBrk);
@@ -370,9 +369,9 @@ loadOptionLine(
     while (IS_WHITESPACE_CHAR(*pzLine))  pzLine++;
 
     {
-        char* pzArg = assembleArgValue(pzLine, load_mode);
+        char* pzArg = assemble_arg_val(pzLine, load_mode);
 
-        if (! SUCCESSFUL(longOptionFind(pOpts, pzLine, pOS)))
+        if (! SUCCESSFUL(opt_find_long(pOpts, pzLine, pOS)))
             return;
         if (pOS->flags & OPTST_NO_INIT)
             return;
index 7a52b5e33dbd126dca8560257dbc9edb9f1b2ade..b18e86da3e7b9eaa352d9d775c109cc35a8f649a 100644 (file)
@@ -2,7 +2,7 @@ dnl  -*- buffer-read-only: t -*- vi: set ro:
 dnl 
 dnl DO NOT EDIT THIS FILE   (libopts.m4)
 dnl 
-dnl It has been AutoGen-ed  April 29, 2011 at 03:43:56 PM by AutoGen 5.11.9
+dnl It has been AutoGen-ed  December 29, 2011 at 12:02:31 PM by AutoGen 5.14
 dnl From the definitions    libopts.def
 dnl and the template file   conftest.tpl
 dnl
@@ -446,7 +446,7 @@ AC_DEFUN([INVOKE_LIBOPTS_MACROS],[
 
 dnl @synopsis  LIBOPTS_CHECK
 dnl
-dnl Time-stamp:        "2010-11-29 15:45:54 bkorb"
+dnl Time-stamp:        "2011-12-13 21:26:37 bkorb"
 dnl
 dnl If autoopts-config works, add the linking information to LIBS.
 dnl Otherwise, add ``libopts-${ao_rev}'' to SUBDIRS and run all
@@ -478,12 +478,12 @@ AC_DEFUN([LIBOPTS_CHECK_COMMON],[
            [ifelse($1, , [libopts], [$1])])
   AC_ARG_ENABLE([local-libopts],
     AC_HELP_STRING([--enable-local-libopts],
-       [Force using the supplied libopts tearoff code]),[
+       [Use the supplied libopts tearoff code]),[
     if test x$enableval = xyes ; then
        AC_MSG_NOTICE([Using supplied libopts tearoff])
-       LIBOPTS_LDADD='$(top_builddir)/AO_Libopts_Dir/libopts.la'
        LIBOPTS_CFLAGS='-I$(top_srcdir)/AO_Libopts_Dir'
        NEED_LIBOPTS_DIR=true
+       LIBOPTS_LDADD='$(top_builddir)/AO_Libopts_Dir/libopts.la'
     fi])
 
   AC_ARG_ENABLE([libopts-install],
index 13843c8b620ca7a9cd21e53d335a6a8afc8dfe9e..48746f19f678a05c7059161b62187047cc11efcb 100644 (file)
@@ -1,7 +1,7 @@
 /* -*- buffer-read-only: t -*- vi: set ro:
  *
  * Prototypes for autoopts
- * Generated Fri Apr 29 15:44:06 PDT 2011
+ * Generated Thu Dec 29 12:02:41 PST 2011
  */
 #ifndef AUTOOPTS_PROTO_H_GUARD
 #define AUTOOPTS_PROTO_H_GUARD 1
@@ -25,25 +25,25 @@ LOCAL char *
 ao_strdup(char const *str);
 
 LOCAL tSuccess
-handle_opt(tOptions* pOpts, tOptState* pOptState);
+handle_opt(tOptions * pOpts, tOptState* pOptState);
 
 LOCAL tSuccess
-longOptionFind(tOptions* pOpts, char* pzOptName, tOptState* pOptState);
+immediate_opts(tOptions * pOpts);
 
 LOCAL tSuccess
-shortOptionFind(tOptions* pOpts, uint_t optValue, tOptState* pOptState);
+regular_opts(tOptions * pOpts);
 
-LOCAL tSuccess
-doImmediateOpts(tOptions* pOpts);
-
-LOCAL tSuccess
-doRegularOpts(tOptions* pOpts);
+/*
+ *  Extracted from check.c
+ */
+LOCAL ag_bool
+is_consistent(tOptions * pOpts);
 
 /*
  *  Extracted from configfile.c
  */
 LOCAL void
-internalFileLoad(tOptions* pOpts);
+intern_file_load(tOptions* pOpts);
 
 LOCAL char*
 parseAttributes(
@@ -53,16 +53,31 @@ parseAttributes(
     tOptionValue*       pType );
 
 LOCAL tSuccess
-validateOptionsStruct(tOptions* pOpts, char const* pzProgram);
+validate_struct(tOptions * pOpts, char const * pzProgram);
 
 /*
- *  Extracted from environment.c
+ *  Extracted from env.c
  */
 LOCAL void
-doPrognameEnv(tOptions* pOpts, teEnvPresetType type);
+doPrognameEnv(tOptions * pOpts, teEnvPresetType type);
 
 LOCAL void
-doEnvPresets(tOptions* pOpts, teEnvPresetType type);
+env_presets(tOptions * pOpts, teEnvPresetType type);
+
+/*
+ *  Extracted from find.c
+ */
+LOCAL tSuccess
+opt_find_long(tOptions * pOpts, char const * opt_name, tOptState * pOptState);
+
+LOCAL tSuccess
+opt_find_short(tOptions* pOpts, uint_t optValue, tOptState* pOptState);
+
+LOCAL tSuccess
+get_opt_arg(tOptions * pOpts, tOptState * pOptState);
+
+LOCAL tSuccess
+find_opt(tOptions * pOpts, tOptState * pOptState);
 
 /*
  *  Extracted from load.c
@@ -105,6 +120,12 @@ optionSort(tOptions* pOpts);
 LOCAL void
 addArgListEntry(void** ppAL, void* entry);
 
+/*
+ *  Extracted from usage.c
+ */
+LOCAL void
+set_usage_flags(tOptions * opts, char const * flg_txt);
+
 #ifdef REDEF_LOCAL
 #  undef LOCAL
 #  define LOCAL
index 2959db664c3af46c3553f6abc6449e8f369404b5..59850fe76f840a0fd5a653638be20ef8caa8b8c0 100644 (file)
@@ -2,7 +2,7 @@
 /**
  * \file reset.c
  *
- *  Time-stamp:      "2010-07-10 10:56:34 bkorb"
+ *  Time-stamp:      "2011-05-24 18:07:16 bkorb"
  *
  *  This file is part of AutoOpts, a companion to AutoGen.
  *  AutoOpts is free software.
@@ -100,7 +100,7 @@ optionResetOpt( tOptions* pOpts, tOptDesc* pOD )
             return;
         }
 
-        succ = shortOptionFind(pOpts, (tAoUC)*pzArg, &opt_state);
+        succ = opt_find_short(pOpts, (tAoUC)*pzArg, &opt_state);
         if (! SUCCESSFUL(succ)) {
             fprintf(stderr, zIllOptChr, pOpts->pzProgPath, *pzArg);
             pOpts->pUsageProc(pOpts, EXIT_FAILURE);
@@ -108,7 +108,7 @@ optionResetOpt( tOptions* pOpts, tOptDesc* pOD )
             assert(0 == 1);
         }
     } else {
-        succ = longOptionFind(pOpts, (char *)pzArg, &opt_state);
+        succ = opt_find_long(pOpts, (char *)pzArg, &opt_state);
         if (! SUCCESSFUL(succ)) {
             fprintf(stderr, zIllOptStr, pOpts->pzProgPath, pzArg);
             pOpts->pUsageProc(pOpts, EXIT_FAILURE);
index 6291db1cc6ca6a97842b15fa143aa1465e0b80c9..89d716a9bbd06ef3a9774e93ecda5b01c3951fbd 100644 (file)
@@ -2,7 +2,7 @@
 /*
  * \file sort.c
  *
- * Time-stamp:      "2010-07-17 10:34:15 bkorb"
+ * Time-stamp:      "2011-05-24 18:07:14 bkorb"
  *
  *  This module implements argument sorting.
  *
@@ -132,7 +132,7 @@ checkShortOpts(tOptions* pOpts, char* pzArg, tOptState* pOS,
                char** ppzOpts, int* pOptsIdx)
 {
     while (*pzArg != NUL) {
-        if (FAILED(shortOptionFind(pOpts, (tAoUC)*pzArg, pOS)))
+        if (FAILED(opt_find_short(pOpts, (tAoUC)*pzArg, pOS)))
             return FAILURE;
 
         /*
@@ -251,7 +251,7 @@ optionSort(tOptions* pOpts)
                     pOpts->origArgVect[ (pOpts->curOptIdx)++ ];
                 goto restOperands;
             }
-            res = longOptionFind(pOpts, pzArg+2, &os);
+            res = opt_find_long(pOpts, pzArg+2, &os);
             break;
 
         default:
@@ -261,9 +261,9 @@ optionSort(tOptions* pOpts)
              *  short (i.e. single character) option.
              */
             if ((pOpts->fOptSet & OPTPROC_SHORTOPT) == 0) {
-                res = longOptionFind(pOpts, pzArg+1, &os);
+                res = opt_find_long(pOpts, pzArg+1, &os);
             } else {
-                res = shortOptionFind(pOpts, (tAoUC)pzArg[1], &os);
+                res = opt_find_short(pOpts, (tAoUC)pzArg[1], &os);
             }
             break;
         }
index 01aa7d8212553b67e7e12c22f9dc6299bd581ffc..4a7a9df28b9a804f64d0e6b6757c060551b25a19 100644 (file)
@@ -1,7 +1,9 @@
 /**
- * \file text_mmap.c
+ * @file text_mmap.c
  *
- * Time-stamp:      "2010-07-17 10:15:32 bkorb"
+ * Map a text file, ensuring the text always has an ending NUL byte.
+ *
+ * Time-stamp:      "2011-06-25 11:42:22 bkorb"
  *
  *  This file is part of AutoOpts, a companion to AutoGen.
  *  AutoOpts is free software.
  *  06a1a2e4760c90ea5e1dad8dfaac4d39 pkg/libopts/COPYING.lgplv3
  *  66a5cedaf62c4b2637025f049f9b826f pkg/libopts/COPYING.mbsd
  */
+#if defined(HAVE_MMAP)
+#  ifndef      MAP_ANONYMOUS
+#    ifdef     MAP_ANON
+#      define  MAP_ANONYMOUS   MAP_ANON
+#    endif
+#  endif
 
-#ifndef MAP_ANONYMOUS
-#  ifdef   MAP_ANON
-#  define  MAP_ANONYMOUS   MAP_ANON
+#  if ! defined(MAP_ANONYMOUS) && ! defined(HAVE_DEV_ZERO)
+     /*
+      * We must have either /dev/zero or anonymous mapping for
+      * this to work.
+      */
+#    undef HAVE_MMAP
+
+#  else
+#    ifdef _SC_PAGESIZE
+#      define GETPAGESIZE() sysconf(_SC_PAGESIZE)
+#    else
+#      define GETPAGESIZE() getpagesize()
+#    endif
 #  endif
 #endif
 
          && ((_flg & (MAP_SHARED|MAP_PRIVATE)) == MAP_SHARED))
 #define MAP_FAILED_PTR ((void*)MAP_FAILED)
 
+/**
+ * Load the contents of a text file.  There are two separate implementations,
+ * depending up on whether mmap(3) is available.
+ *
+ *  If not available, malloc the file length plus one byte.  Read it in
+ *  and NUL terminate.
+ *
+ *  If available, first check to see if the text file size is a multiple of a
+ *  page size.  If it is, map the file size plus an extra page from either
+ *  anonymous memory or from /dev/zero.  Then map the file text on top of the
+ *  first pages of the anonymous/zero pages.  Otherwise, just map the file
+ *  because there will be NUL bytes provided at the end.
+ *
+ * @param mapinfo a structure holding everything we need to know
+ *        about the mapping.
+ */
+static void
+load_text_file(tmap_info_t * mapinfo)
+{
+#if ! defined(HAVE_MMAP)
+    mapinfo->txt_data = AGALOC(mapinfo->txt_size+1, "file text");
+    if (mapinfo->txt_data == NULL) {
+        mapinfo->txt_errno = ENOMEM;
+        return;
+    }
+
+    {
+        size_t sz = mapinfo->txt_size;
+        char*  pz = mapinfo->txt_data;
+
+        while (sz > 0) {
+            ssize_t rdct = read(mapinfo->txt_fd, pz, sz);
+            if (rdct <= 0) {
+                mapinfo->txt_errno = errno;
+                fprintf(stderr, zFSErrReadFile,
+                        errno, strerror(errno), pzFile);
+                free(mapinfo->txt_data);
+                return;
+            }
+
+            pz += rdct;
+            sz -= rdct;
+        }
+
+        *pz = NUL;
+    }
+
+    mapinfo->txt_errno   = 0;
+
+#else /* HAVE mmap */
+    size_t const pgsz = GETPAGESIZE();
+    void * map_addr   = NULL;
+
+    mapinfo->txt_full_size = (mapinfo->txt_size + pgsz) & ~(pgsz - 1);
+    if (mapinfo->txt_full_size == (mapinfo->txt_size + pgsz)) {
+        /*
+         * The text is a multiple of a page boundary.  We must map an
+         * extra page so the text ends with a NUL.
+         */
+#if defined(MAP_ANONYMOUS)
+        map_addr = mmap(NULL, mapinfo->txt_full_size, PROT_READ|PROT_WRITE,
+                        MAP_ANONYMOUS|MAP_PRIVATE, AO_INVALID_FD, 0);
+#else
+        mapinfo->txt_zero_fd = open("/dev/zero", O_RDONLY);
+
+        if (mapinfo->txt_zero_fd == AO_INVALID_FD) {
+            mapinfo->txt_errno = errno;
+            return;
+        }
+        map_addr = mmap(NULL, mapinfo->txt_full_size, PROT_READ|PROT_WRITE,
+                        MAP_PRIVATE, mapinfo->txt_zero_fd, 0);
+#endif
+        if (map_addr == MAP_FAILED_PTR) {
+            mapinfo->txt_errno = errno;
+            return;
+        }
+        mapinfo->txt_flags |= MAP_FIXED;
+    }
+
+    mapinfo->txt_data =
+        mmap(map_addr, mapinfo->txt_size, mapinfo->txt_prot,
+             mapinfo->txt_flags, mapinfo->txt_fd, 0);
+
+    if (mapinfo->txt_data == MAP_FAILED_PTR)
+        mapinfo->txt_errno = errno;
+#endif /* HAVE_MMAP */
+}
+
+/**
+ * Make sure all the parameters are correct:  we have a file name that
+ * is a text file that we can read.
+ *
+ * @param fname the text file to map
+ * @param prot  the memory protections requested (read/write/etc.)
+ * @param flags mmap flags
+ * @param mapinfo a structure holding everything we need to know
+ *        about the mapping.
+ */
+static void
+validate_mmap(char const * fname, int prot, int flags, tmap_info_t * mapinfo)
+{
+    memset(mapinfo, 0, sizeof(*mapinfo));
+#if defined(HAVE_MMAP) && ! defined(MAP_ANONYMOUS)
+    mapinfo->txt_zero_fd = AO_INVALID_FD;
+#endif
+    mapinfo->txt_fd      = AO_INVALID_FD;
+    mapinfo->txt_prot    = prot;
+    mapinfo->txt_flags   = flags;
+
+    /*
+     *  Make sure we can stat the regular file.  Save the file size.
+     */
+    {
+        struct stat sb;
+        if (stat(fname, &sb) != 0) {
+            mapinfo->txt_errno = errno;
+            return;
+        }
+
+        if (! S_ISREG(sb.st_mode)) {
+            mapinfo->txt_errno = errno = EINVAL;
+            return;
+        }
+
+        mapinfo->txt_size = sb.st_size;
+    }
+
+    /*
+     *  Map mmap flags and protections into open flags and do the open.
+     */
+    {
+        /*
+         *  See if we will be updating the file.  If we can alter the memory
+         *  and if we share the data and we are *not* copy-on-writing the data,
+         *  then our updates will show in the file, so we must open with
+         *  write access.
+         */
+        int o_flag = FILE_WRITABLE(prot, flags) ? O_RDWR : O_RDONLY;
+
+        /*
+         *  If you're not sharing the file and you are writing to it,
+         *  then don't let anyone else have access to the file.
+         */
+        if (((flags & MAP_SHARED) == 0) && (prot & PROT_WRITE))
+            o_flag |= O_EXCL;
+
+        mapinfo->txt_fd = open(fname, o_flag);
+    }
+
+    if (mapinfo->txt_fd == AO_INVALID_FD)
+        mapinfo->txt_errno = errno;
+}
+
+/**
+ * Close any files opened by the mapping.
+ *
+ * @param mi a structure holding everything we need to know about the map.
+ */
+static void
+close_mmap_files(tmap_info_t * mi)
+{
+    if (mi->txt_fd == AO_INVALID_FD)
+        return;
+
+    close(mi->txt_fd);
+    mi->txt_fd = AO_INVALID_FD;
+
+#if ! defined(MAP_ANONYMOUS)
+    if (mi->txt_zero_fd == AO_INVALID_FD)
+        return;
+
+    close(mi->txt_zero_fd);
+    mi->txt_zero_fd = AO_INVALID_FD;
+#endif
+}
+
 /*=export_func  text_mmap
  * private:
  *
  * This routine will mmap a file into memory ensuring that there is at least
  * one @file{NUL} character following the file data.  It will return the
  * address where the file contents have been mapped into memory.  If there is a
- * problem, then it will return @code{MAP_FAILED} and set @file{errno}
+ * problem, then it will return @code{MAP_FAILED} and set @code{errno}
  * appropriately.
  *
- * The named file does not exist, @code{stat(2)} will set @file{errno} as it
- * will.  If the file is not a regular file, @file{errno} will be
+ * The named file does not exist, @code{stat(2)} will set @code{errno} as it
+ * will.  If the file is not a regular file, @code{errno} will be
  * @code{EINVAL}.  At that point, @code{open(2)} is attempted with the access
  * bits set appropriately for the requested @code{mmap(2)} protections and flag
- * bits.  On failure, @file{errno} will be set according to the documentation
- * for @code{open(2)}.  If @code{mmap(2)} fails, @file{errno} will be set as
+ * bits.  On failure, @code{errno} will be set according to the documentation
+ * for @code{open(2)}.  If @code{mmap(2)} fails, @code{errno} will be set as
  * that routine sets it.  If @code{text_mmap} works to this point, a valid
  * address will be returned, but there may still be ``issues''.
  *
  * If the file size is not an even multiple of the system page size, then
- * @code{text_map} will return at this point and @file{errno} will be zero.
+ * @code{text_map} will return at this point and @code{errno} will be zero.
  * Otherwise, an anonymous map is attempted.  If not available, then an attempt
  * is made to @code{mmap(2)} @file{/dev/zero}.  If any of these fail, the
  * address of the file's data is returned, bug @code{no} @file{NUL} characters
  * << use the data >>
  * text_munmap(&mi);
 =*/
-void*
-text_mmap(char const* pzFile, int prot, int flags, tmap_info_t* pMI)
+void *
+text_mmap(char const * pzFile, int prot, int flags, tmap_info_t * mi)
 {
-    memset(pMI, 0, sizeof(*pMI));
-#ifdef HAVE_MMAP
-    pMI->txt_zero_fd = -1;
-#endif
-    pMI->txt_fd = -1;
-
-    /*
-     *  Make sure we can stat the regular file.  Save the file size.
-     */
-    {
-        struct stat sb;
-        if (stat(pzFile, &sb) != 0) {
-            pMI->txt_errno = errno;
-            return MAP_FAILED_PTR;
-        }
-
-        if (! S_ISREG(sb.st_mode)) {
-            pMI->txt_errno = errno = EINVAL;
-            return MAP_FAILED_PTR;
-        }
-
-        pMI->txt_size = sb.st_size;
-    }
-
-    /*
-     *  Map mmap flags and protections into open flags and do the open.
-     */
-    {
-        int o_flag;
-        /*
-         *  See if we will be updating the file.  If we can alter the memory
-         *  and if we share the data and we are *not* copy-on-writing the data,
-         *  then our updates will show in the file, so we must open with
-         *  write access.
-         */
-        if (FILE_WRITABLE(prot,flags))
-            o_flag = O_RDWR;
-        else
-            o_flag = O_RDONLY;
-
-        /*
-         *  If you're not sharing the file and you are writing to it,
-         *  then don't let anyone else have access to the file.
-         */
-        if (((flags & MAP_SHARED) == 0) && (prot & PROT_WRITE))
-            o_flag |= O_EXCL;
-
-        pMI->txt_fd = open(pzFile, o_flag);
-    }
-
-    if (pMI->txt_fd == AO_INVALID_FD) {
-        pMI->txt_errno = errno;
+    validate_mmap(pzFile, prot, flags, mi);
+    if (mi->txt_errno != 0)
         return MAP_FAILED_PTR;
-    }
-
-#ifdef HAVE_MMAP /* * * * * WITH MMAP * * * * * */
-    /*
-     *  do the mmap.  If we fail, then preserve errno, close the file and
-     *  return the failure.
-     */
-    pMI->txt_data =
-        mmap(NULL, pMI->txt_size+1, prot, flags, pMI->txt_fd, (size_t)0);
-    if (pMI->txt_data == MAP_FAILED_PTR) {
-        pMI->txt_errno = errno;
-        goto fail_return;
-    }
-
-    /*
-     *  Most likely, everything will turn out fine now.  The only difficult
-     *  part at this point is coping with files with sizes that are a multiple
-     *  of the page size.  Handling that is what this whole thing is about.
-     */
-    pMI->txt_zero_fd = -1;
-    pMI->txt_errno   = 0;
-
-    {
-        void* pNuls;
-#ifdef _SC_PAGESIZE
-        size_t pgsz = sysconf(_SC_PAGESIZE);
-#else
-        size_t pgsz = getpagesize();
-#endif
-        /*
-         *  Compute the pagesize rounded mapped memory size.
-         *  IF this is not the same as the file size, then there are NUL's
-         *  at the end of the file mapping and all is okay.
-         */
-        pMI->txt_full_size = (pMI->txt_size + (pgsz - 1)) & ~(pgsz - 1);
-        if (pMI->txt_size != pMI->txt_full_size)
-            return pMI->txt_data;
-
-        /*
-         *  Still here?  We have to remap the trailing inaccessible page
-         *  either anonymously or to /dev/zero.
-         */
-        pMI->txt_full_size += pgsz;
-#if defined(MAP_ANONYMOUS)
-        pNuls = mmap(
-                (void*)(((char*)pMI->txt_data) + pMI->txt_size),
-                pgsz, PROT_READ|PROT_WRITE,
-                MAP_ANONYMOUS|MAP_FIXED|MAP_PRIVATE, AO_INVALID_FD, (size_t)0);
-
-        if (pNuls != MAP_FAILED_PTR)
-            return pMI->txt_data;
-
-        pMI->txt_errno = errno;
-
-#elif defined(HAVE_DEV_ZERO)
-        pMI->txt_zero_fd = open("/dev/zero", O_RDONLY);
 
-        if (pMI->txt_zero_fd == AO_INVALID_FD) {
-            pMI->txt_errno = errno;
+    load_text_file(mi);
 
-        } else {
-            pNuls = mmap(
-                    (void*)(((char*)pMI->txt_data) + pMI->txt_size), pgsz,
-                    PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED,
-                    pMI->txt_zero_fd, 0 );
+    if (mi->txt_errno == 0)
+        return mi->txt_data;
 
-            if (pNuls != MAP_FAILED_PTR)
-                return pMI->txt_data;
+    close_mmap_files(mi);
 
-            pMI->txt_errno = errno;
-            close(pMI->txt_zero_fd);
-            pMI->txt_zero_fd = -1;
-        }
-#endif
-
-        pMI->txt_full_size = pMI->txt_size;
-    }
-
-    {
-        void* p = AGALOC(pMI->txt_size+1, "file text");
-        memcpy(p, pMI->txt_data, pMI->txt_size);
-        ((char*)p)[pMI->txt_size] = NUL;
-        munmap(pMI->txt_data, pMI->txt_size );
-        pMI->txt_data = p;
-    }
-    pMI->txt_alloc = 1;
-    return pMI->txt_data;
-
-#else /* * * * * * no HAVE_MMAP * * * * * */
-
-    pMI->txt_data = AGALOC(pMI->txt_size+1, "file text");
-    if (pMI->txt_data == NULL) {
-        pMI->txt_errno = ENOMEM;
-        goto fail_return;
-    }
-
-    {
-        size_t sz = pMI->txt_size;
-        char*  pz = pMI->txt_data;
-
-        while (sz > 0) {
-            ssize_t rdct = read(pMI->txt_fd, pz, sz);
-            if (rdct <= 0) {
-                pMI->txt_errno = errno;
-                fprintf(stderr, zFSErrReadFile,
-                        errno, strerror(errno), pzFile);
-                free(pMI->txt_data);
-                goto fail_return;
-            }
-
-            pz += rdct;
-            sz -= rdct;
-        }
-
-        *pz = NUL;
-    }
-
-    /*
-     *  We never need a dummy page mapped in
-     */
-    pMI->txt_zero_fd = -1;
-    pMI->txt_errno   = 0;
-
-    return pMI->txt_data;
-
-#endif /* * * * * * no HAVE_MMAP * * * * * */
-
- fail_return:
-    if (pMI->txt_fd >= 0) {
-        close(pMI->txt_fd);
-        pMI->txt_fd = -1;
-    }
-    errno = pMI->txt_errno;
-    pMI->txt_data = MAP_FAILED_PTR;
-    return pMI->txt_data;
+    errno = mi->txt_errno;
+    mi->txt_data = MAP_FAILED_PTR;
+    return mi->txt_data;
 }
 
 
@@ -298,7 +318,7 @@ text_mmap(char const* pzFile, int prot, int flags, tmap_info_t* pMI)
  * arg:   tmap_info_t*, mapinfo, info about the mapping
  *
  * ret-type:   int
- * ret-desc:   -1 or 0.  @file{errno} will have the error code.
+ * ret-desc:   -1 or 0.  @code{errno} will have the error code.
  *
  * doc:
  *
@@ -310,68 +330,31 @@ text_mmap(char const* pzFile, int prot, int flags, tmap_info_t* pMI)
  * err: Any error code issued by munmap(2) or close(2) is possible.
 =*/
 int
-text_munmap(tmap_info_t* pMI)
+text_munmap(tmap_info_t * mi)
 {
-#ifdef HAVE_MMAP
-    int res = 0;
-    if (pMI->txt_alloc) {
-        /*
-         *  IF the user has write permission and the text is not mapped private,
-         *  then write back any changes.  Hopefully, nobody else has modified
-         *  the file in the mean time.
-         */
-        if (   ((pMI->txt_prot & PROT_WRITE) != 0)
-            && ((pMI->txt_flags & MAP_PRIVATE) == 0))  {
-
-            if (lseek(pMI->txt_fd, (size_t)0, SEEK_SET) != 0)
-                goto error_return;
-
-            res = (write(pMI->txt_fd, pMI->txt_data, pMI->txt_size) < 0)
-                ? errno : 0;
-        }
-
-        AGFREE(pMI->txt_data);
-        errno = res;
-    } else {
-        res = munmap(pMI->txt_data, pMI->txt_full_size);
-    }
-    if (res != 0)
-        goto error_return;
-
-    res = close(pMI->txt_fd);
-    if (res != 0)
-        goto error_return;
-
-    pMI->txt_fd = -1;
     errno = 0;
-    if (pMI->txt_zero_fd != -1) {
-        res = close(pMI->txt_zero_fd);
-        pMI->txt_zero_fd = -1;
-    }
 
- error_return:
-    pMI->txt_errno = errno;
-    return res;
-#else  /* HAVE_MMAP */
+#ifdef HAVE_MMAP
+    (void)munmap(mi->txt_data, mi->txt_full_size);
 
-    errno = 0;
+#else  /* don't HAVE_MMAP */
     /*
      *  IF the memory is writable *AND* it is not private (copy-on-write)
      *     *AND* the memory is "sharable" (seen by other processes)
-     *  THEN rewrite the data.
+     *  THEN rewrite the data.  Emulate mmap visibility.
      */
-    if (   FILE_WRITABLE(pMI->txt_prot, pMI->txt_flags)
-        && (lseek(pMI->txt_fd, 0, SEEK_SET) >= 0) ) {
-        write(pMI->txt_fd, pMI->txt_data, pMI->txt_size);
+    if (   FILE_WRITABLE(mi->txt_prot, mi->txt_flags)
+        && (lseek(mi->txt_fd, 0, SEEK_SET) >= 0) ) {
+        write(mi->txt_fd, mi->txt_data, mi->txt_size);
     }
 
-    close(pMI->txt_fd);
-    pMI->txt_fd = -1;
-    pMI->txt_errno = errno;
-    free(pMI->txt_data);
-
-    return pMI->txt_errno;
+    free(mi->txt_data);
 #endif /* HAVE_MMAP */
+
+    mi->txt_errno = errno;
+    close_mmap_files(mi);
+
+    return mi->txt_errno;
 }
 
 /*
index 4d106675c30436de062deadd8f8fbb8d4813ec91..e2751cb6e7af6a653a590c0b659b48e95a20835f 100644 (file)
@@ -2,7 +2,7 @@
 /*
  * \file usage.c
  *
- * Time-stamp:      "2011-02-01 14:42:37 bkorb"
+ * Time-stamp:      "2011-11-22 11:41:18 bkorb"
  *
  *  This module implements the default usage procedure for
  *  Automated Options.  It may be overridden, of course.
@@ -38,9 +38,6 @@
 #define OPTPROC_L_N_S  (OPTPROC_LONGOPT | OPTPROC_SHORTOPT)
 
 /* = = = START-STATIC-FORWARD = = = */
-static void
-set_usage_flags(tOptions * opts, char const * flg_txt);
-
 static inline ag_bool
 do_gnu_usage(tOptions * pOpts);
 
@@ -51,7 +48,18 @@ static void
 print_usage_details(tOptions * opts, int exit_code);
 
 static void
-prt_extd_usage(tOptions * pOptions, tOptDesc * pOD, arg_types_t * pAT);
+prt_conflicts(tOptions * pOptions, tOptDesc * pOD);
+
+static void
+prt_one_vendor(tOptions * pOptions, tOptDesc * pOD,
+               arg_types_t * pAT, char const * usefmt);
+
+static void
+prt_vendor_opts(tOptions * pOpts, arg_types_t * pAT, char const * pOptTitle);
+
+static void
+prt_extd_usage(tOptions * pOpts, tOptDesc * pOD,
+               arg_types_t * pAT, char const * pOptTitle);
 
 static void
 prt_ini_list(char const * const * papz, ag_bool * pInitIntro,
@@ -85,7 +93,7 @@ setStdOptFmts(tOptions* pOpts, tCC** ppT);
     _aof_(no_misuse_usage, OPTPROC_MISUSE   )   \
     _aof_(misuse_usage,    ~OPTPROC_MISUSE  )
 
-static void
+LOCAL void
 set_usage_flags(tOptions * opts, char const * flg_txt)
 {
     typedef struct {
@@ -112,8 +120,7 @@ set_usage_flags(tOptions * opts, char const * flg_txt)
 
     if (flg_txt == NULL) {
         flg_txt = getenv("AUTOOPTS_USAGE");
-        if (flg_txt == NULL)
-            return;
+        if (flg_txt == NULL) return;
     }
 
     while (IS_WHITESPACE_CHAR(*flg_txt))  flg_txt++;
@@ -216,12 +223,10 @@ optionOnlyUsage(tOptions * pOpts, int ex_code)
     /*
      *  Determine which header and which option formatting strings to use
      */
-    if (do_gnu_usage(pOpts)) {
+    if (do_gnu_usage(pOpts))
         (void)setGnuOptFmts(pOpts, &pOptTitle);
-    }
-    else {
+    else
         (void)setStdOptFmts(pOpts, &pOptTitle);
-    }
 
     prt_opt_usage(pOpts, ex_code, pOptTitle);
 
@@ -374,57 +379,192 @@ optionUsage(tOptions * pOptions, int usage_exit_code)
     exit(exit_code);
 }
 
-
 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- *
  *   PER OPTION TYPE USAGE INFORMATION
+ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+/**
+ * print option conflicts.
+ *
+ * @param pOptions the program option descriptor
+ * @param pOD      the option descriptor
+ * @param pAT      names of the option argument types
  */
 static void
-prt_extd_usage(tOptions * pOptions, tOptDesc * pOD, arg_types_t * pAT)
+prt_conflicts(tOptions * pOptions, tOptDesc * pOD)
 {
+
+    fputs(zTabHyp, option_usage_fp);
+
     /*
-     *  IF there are option conflicts or dependencies,
-     *  THEN print them here.
+     *  REQUIRED:
      */
-    if (  (pOD->pOptMust != NULL)
-       || (pOD->pOptCant != NULL) ) {
+    if (pOD->pOptMust != NULL) {
+        const int* pOptNo = pOD->pOptMust;
 
-        fputs(zTabHyp, option_usage_fp);
+        fputs(zReqThese, option_usage_fp);
+        for (;;) {
+            fprintf(option_usage_fp, zTabout,
+                    pOptions->pOptDesc[*pOptNo].pz_Name);
+            if (*++pOptNo == NO_EQUIVALENT)
+                break;
+        }
 
-        /*
-         *  DEPENDENCIES:
-         */
-        if (pOD->pOptMust != NULL) {
-            const int* pOptNo = pOD->pOptMust;
-
-            fputs(zReqThese, option_usage_fp);
-            for (;;) {
-                fprintf(option_usage_fp, zTabout,
-                        pOptions->pOptDesc[*pOptNo].pz_Name);
-                if (*++pOptNo == NO_EQUIVALENT)
-                    break;
-            }
+        if (pOD->pOptCant != NULL)
+            fputs(zTabHypAnd, option_usage_fp);
+    }
+
+    /*
+     *  CONFLICTS:
+     */
+    if (pOD->pOptCant != NULL) {
+        const int* pOptNo = pOD->pOptCant;
 
-            if (pOD->pOptCant != NULL)
-                fputs(zTabHypAnd, option_usage_fp);
+        fputs(zProhib, option_usage_fp);
+        for (;;) {
+            fprintf(option_usage_fp, zTabout,
+                    pOptions->pOptDesc[*pOptNo].pz_Name);
+            if (*++pOptNo == NO_EQUIVALENT)
+                break;
         }
+    }
+}
+
+/**
+ *  Print the usage information for a single vendor option.
+ *
+ * @param pOpts     the program option descriptor
+ * @param pOD       the option descriptor
+ * @param pAT       names of the option argument types
+ */
+static void
+prt_one_vendor(tOptions * pOptions, tOptDesc * pOD,
+               arg_types_t * pAT, char const * usefmt)
+{
+    prt_preamble(pOptions, pOD, pAT);
+
+    {
+        char z[ 80 ];
+        char const *  pzArgType;
 
         /*
-         *  CONFLICTS:
+         *  Determine the argument type string first on its usage, then,
+         *  when the option argument is required, base the type string on the
+         *  argument type.
          */
-        if (pOD->pOptCant != NULL) {
-            const int* pOptNo = pOD->pOptCant;
-
-            fputs(zProhib, option_usage_fp);
-            for (;;) {
-                fprintf(option_usage_fp, zTabout,
-                        pOptions->pOptDesc[*pOptNo].pz_Name);
-                if (*++pOptNo == NO_EQUIVALENT)
-                    break;
-            }
+        if (pOD->fOptState & OPTST_ARG_OPTIONAL) {
+            pzArgType = pAT->pzOpt;
+
+        } else switch (OPTST_GET_ARGTYPE(pOD->fOptState)) {
+        case OPARG_TYPE_NONE:        pzArgType = pAT->pzNo;   break;
+        case OPARG_TYPE_ENUMERATION: pzArgType = pAT->pzKey;  break;
+        case OPARG_TYPE_FILE:        pzArgType = pAT->pzFile; break;
+        case OPARG_TYPE_MEMBERSHIP:  pzArgType = pAT->pzKeyL; break;
+        case OPARG_TYPE_BOOLEAN:     pzArgType = pAT->pzBool; break;
+        case OPARG_TYPE_NUMERIC:     pzArgType = pAT->pzNum;  break;
+        case OPARG_TYPE_HIERARCHY:   pzArgType = pAT->pzNest; break;
+        case OPARG_TYPE_STRING:      pzArgType = pAT->pzStr;  break;
+        case OPARG_TYPE_TIME:        pzArgType = pAT->pzTime; break;
+        default:                     goto bogus_desc;
+        }
+
+        while (IS_WHITESPACE_CHAR(*pzArgType))  pzArgType++;
+        if (*pzArgType == NUL)
+            snprintf(z, sizeof(z), "%s", pOD->pz_Name);
+        else
+            snprintf(z, sizeof(z), "%s=%s", pOD->pz_Name, pzArgType);
+        fprintf(option_usage_fp, usefmt, z, pOD->pzText);
+
+        switch (OPTST_GET_ARGTYPE(pOD->fOptState)) {
+        case OPARG_TYPE_ENUMERATION:
+        case OPARG_TYPE_MEMBERSHIP:
+            displayEnum = (pOD->pOptProc != NULL) ? AG_TRUE : displayEnum;
         }
     }
 
+    return;
+
+bogus_desc:
+    fprintf(stderr, zInvalOptDesc, pOD->pz_Name);
+    exit(EX_SOFTWARE);
+}
+
+/**
+ * Print the long options processed with "-W".  These options will be the
+ * ones that do *not* have flag characters.
+ *
+ * @param pOptions the program option descriptor
+ * @param pOD      the option descriptor
+ * @param pAT      names of the option argument types
+ */
+static void
+prt_vendor_opts(tOptions * pOpts, arg_types_t * pAT, char const * pOptTitle)
+{
+    static unsigned int const not_vended_mask =
+        OPTST_NO_USAGE_MASK | OPTST_DOCUMENT;
+
+    static char const vfmtfmt[] = "%%-%us %%s\n";
+    char vfmt[sizeof(vfmtfmt)];
+
+    /*
+     *  Only handle client specified options.  The "vendor option" follows
+     *  "presetOptCt", so we won't loop/recurse indefinitely.
+     */
+    int          ct     = pOpts->presetOptCt;
+    tOptDesc *   pOD    = pOpts->pOptDesc;
+    size_t       nmlen  = 0;
+
+    fprintf(option_usage_fp, zTabout, zVendOptsAre);
+
+    do  {
+        size_t l;
+        if (  ((pOD->fOptState & not_vended_mask) != 0)
+           || IS_GRAPHIC_CHAR(pOD->optValue))
+            continue;
+
+        l = strlen(pOD->pz_Name);
+        if (l > nmlen)  nmlen = l;
+    } while (pOD++, (--ct > 0));
+
+    sprintf(vfmt, vfmtfmt, (unsigned int)nmlen + 4);
+    ct     = pOpts->presetOptCt;
+    pOD    = pOpts->pOptDesc;
+
+    do  {
+        if (  ((pOD->fOptState & not_vended_mask) != 0)
+           || IS_GRAPHIC_CHAR(pOD->optValue))
+            continue;
+
+        prt_one_vendor(pOpts, pOD, &argTypes, vfmt);
+        prt_extd_usage(pOpts, pOD, &argTypes, pOptTitle);
+
+    } while (pOD++, (--ct > 0));
+}
+
+/**
+ * Print extended usage.  Usage/help was requested.
+ *
+ * @param pOptions the program option descriptor
+ * @param pOD      the option descriptor
+ * @param pAT      names of the option argument types
+ */
+static void
+prt_extd_usage(tOptions * pOpts, tOptDesc * pOD,
+               arg_types_t * pAT, char const * pOptTitle)
+{
+    if (  ((pOpts->fOptSet & OPTPROC_VENDOR_OPT) != 0)
+       && (pOD->optActualValue == VENDOR_OPTION_VALUE)) {
+        prt_vendor_opts(pOpts, pAT, pOptTitle);
+        return;
+    }
+
+    /*
+     *  IF there are option conflicts or dependencies,
+     *  THEN print them here.
+     */
+    if (  (pOD->pOptMust != NULL)
+       || (pOD->pOptCant != NULL) )
+        prt_conflicts(pOpts, pOD);
+
     /*
      *  IF there is a disablement string
      *  THEN print the disablement info
@@ -467,7 +607,7 @@ prt_extd_usage(tOptions * pOptions, tOptDesc * pOD, arg_types_t * pAT)
     if (  (pOD->optEquivIndex != NO_EQUIVALENT)
        && (pOD->optEquivIndex != pOD->optActualIndex )  )  {
         fprintf(option_usage_fp, zAlt,
-                 pOptions->pOptDesc[ pOD->optEquivIndex ].pz_Name);
+                 pOpts->pOptDesc[ pOD->optEquivIndex ].pz_Name);
         return;
     }
 
@@ -478,10 +618,10 @@ prt_extd_usage(tOptions * pOptions, tOptDesc * pOD, arg_types_t * pAT)
      *  THEN advise that this option may not be preset.
      */
     if (  ((pOD->fOptState & OPTST_NO_INIT) != 0)
-       && (  (pOptions->papzHomeList != NULL)
-          || (pOptions->pzPROGNAME != NULL)
+       && (  (pOpts->papzHomeList != NULL)
+          || (pOpts->pzPROGNAME != NULL)
           )
-       && (pOD->optIndex < pOptions->presetOptCt)
+       && (pOD->optIndex < pOpts->presetOptCt)
        )
 
         fputs(zNoPreset, option_usage_fp);
@@ -513,12 +653,11 @@ prt_extd_usage(tOptions * pOptions, tOptDesc * pOD, arg_types_t * pAT)
         fprintf(option_usage_fp, zMust, pOD->optMinCt, pOD->optMaxCt);
     }
 
-    if (  NAMED_OPTS(pOptions)
-       && (pOptions->specOptIdx.default_opt == pOD->optIndex))
+    if (  NAMED_OPTS(pOpts)
+       && (pOpts->specOptIdx.default_opt == pOD->optIndex))
         fputs(zDefaultOpt, option_usage_fp);
 }
 
-
 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  *
  *   Figure out where all the initialization files might live.
@@ -608,8 +747,12 @@ prt_preamble(tOptions * pOptions, tOptDesc * pOD, arg_types_t * pAT)
     }
 }
 
-/*
+/**
  *  Print the usage information for a single option.
+ *
+ * @param pOpts     the program option descriptor
+ * @param pOD       the option descriptor
+ * @param pAT       names of the option argument types
  */
 static void
 prt_one_usage(tOptions * pOptions, tOptDesc * pOD, arg_types_t * pAT)
@@ -652,14 +795,14 @@ prt_one_usage(tOptions * pOptions, tOptDesc * pOD, arg_types_t * pAT)
             displayEnum = (pOD->pOptProc != NULL) ? AG_TRUE : displayEnum;
         }
     }
+
     return;
 
- bogus_desc:
+bogus_desc:
     fprintf(stderr, zInvalOptDesc, pOD->pz_Name);
     exit(EX_SOFTWARE);
 }
 
-
 /*
  *  Print out the usage information for just the options.
  */
@@ -672,6 +815,11 @@ prt_opt_usage(tOptions * pOpts, int ex_code, char const * pOptTitle)
     int         docCt  = 0;
 
     do  {
+        /*
+         * no usage --> disallowed on command line (OPTST_NO_COMMAND), or
+         * deprecated -- strongly discouraged (OPTST_DEPRECATED), or
+         * compiled out of current object code (OPTST_OMITTED)
+         */
         if ((pOD->fOptState & OPTST_NO_USAGE_MASK) != 0) {
 
             /*
@@ -703,6 +851,11 @@ prt_opt_usage(tOptions * pOpts, int ex_code, char const * pOptTitle)
             continue;
         }
 
+        /* Skip name only options when we have a vendor option */
+        if (  ((pOpts->fOptSet & OPTPROC_VENDOR_OPT) != 0)
+           && (! IS_GRAPHIC_CHAR(pOD->optValue)))
+            continue;
+
         /*
          *  IF       this is the first auto-opt maintained option
          *    *AND*  we are doing a full help
@@ -710,11 +863,15 @@ prt_opt_usage(tOptions * pOpts, int ex_code, char const * pOptTitle)
          *    *AND*  the last one was not a doc option,
          *  THEN document that the remaining options are not user opts
          */
-        if (  (pOpts->presetOptCt == optNo)
-           && (ex_code == EXIT_SUCCESS)
-           && (docCt > 0)
-           && ((pOD[-1].fOptState & OPTST_DOCUMENT) == 0) )
-            fprintf(option_usage_fp, argTypes.pzBrk, zAuto, pOptTitle);
+        if ((docCt > 0) && (ex_code == EXIT_SUCCESS)) {
+            if (pOpts->presetOptCt == optNo) {
+                if ((pOD[-1].fOptState & OPTST_DOCUMENT) == 0)
+                    fprintf(option_usage_fp, argTypes.pzBrk, zAuto, pOptTitle);
+
+            } else if ((ct == 1) &&
+                       (pOpts->fOptSet & OPTPROC_VENDOR_OPT))
+                fprintf(option_usage_fp, argTypes.pzBrk, zVendIntro, pOptTitle);
+        }
 
         prt_one_usage(pOpts, pOD, &argTypes);
 
@@ -723,9 +880,9 @@ prt_opt_usage(tOptions * pOpts, int ex_code, char const * pOptTitle)
          *  THEN print all the extra info
          */
         if (ex_code == EXIT_SUCCESS)
-            prt_extd_usage(pOpts, pOD, &argTypes);
+            prt_extd_usage(pOpts, pOD, &argTypes, pOptTitle);
 
-    }  while (pOD++, optNo++, (--ct > 0));
+    } while (pOD++, optNo++, (--ct > 0));
 
     fputc('\n', option_usage_fp);
 }
@@ -774,7 +931,7 @@ prt_prog_detail(tOptions* pOptions)
             case OPARG_TYPE_MEMBERSHIP:
                 (*(pOD->pOptProc))(OPTPROC_EMIT_USAGE, pOD);
             }
-        }  while (pOD++, optNo++, (--ct > 0));
+        } while (pOD++, optNo++, (--ct > 0));
     }
 
     /*
@@ -802,6 +959,7 @@ prt_prog_detail(tOptions* pOptions)
 static int
 setGnuOptFmts(tOptions* pOpts, tCC** ppT)
 {
+    static char const zOneSpace[] = " ";
     int  flen = 22;
     *ppT = zNoRq_ShrtTtl;
 
index 5ff917cb9e7c3b8c26b11124ff1cac551ab6b6d5..28ee23ed5129241f6066c5f92c4bf03e15154d45 100644 (file)
@@ -1,5 +1,5 @@
 /*
- *  Generated header for gperf generated source Fri Apr 29 15:43:59 PDT 2011
+ *  Generated header for gperf generated source Thu Dec 29 12:02:33 PST 2011
  *  This file enumerates the list of names and declares the
  *  procedure for mapping string names to the enum value.
  */
index aae1b87485c8a7321e54ac38bdb7e937b8bb4db1..1ebf93f26ff387e70f1b77baf919ea933c7ea866 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * Time-stamp:      "2011-04-22 12:54:28 bkorb"
+ * Time-stamp:      "2011-05-02 12:04:47 bkorb"
  *
  *  This module implements the default usage procedure for
  *  Automated Options.  It may be overridden, of course.
@@ -121,13 +121,20 @@ print_ver(tOptions * pOpts, tOptDesc * pOD, FILE * fp)
     char ch;
 
     /*
-     *  IF the optional argument flag is off, or the argument
-     *  is not provided, then just print the version.
+     *  IF we have an argument for this option, use it
+     *  Otherwise, default to version only or copyright note,
+     *  depending on whether the layout is GNU standard form or not.
      */
-    if (  ((pOD->fOptState & OPTST_ARG_OPTIONAL) == 0)
-       || (pOD->optArg.argString == NULL))
-         ch = 'v';
-    else ch = pOD->optArg.argString[0];
+    if (  (pOD->fOptState & OPTST_ARG_OPTIONAL)
+       && (pOD->optArg.argString != NULL)
+       && (pOD->optArg.argString[0] != NUL))
+
+        ch = pOD->optArg.argString[0];
+
+    else {
+        set_usage_flags(pOpts, NULL);
+        ch = (pOpts->fOptSet & OPTPROC_GNUUSAGE) ? 'c' : 'v';
+    }
 
     switch (ch) {
     case NUL: /* arg provided, but empty */
index 079c59a3d0ac0d2f1f2acbc486c817a382505483..cbcf6e5ac4297ae1ed63b0721d6ce02641988432 100644 (file)
@@ -1,5 +1,5 @@
 /*
- *  Generated header for gperf generated source Fri Apr 29 15:43:59 PDT 2011
+ *  Generated header for gperf generated source Thu Dec 29 12:02:33 PST 2011
  *  This file enumerates the list of names and declares the
  *  procedure for mapping string names to the enum value.
  */