OSSP CVS Repository

ossp - Check-in [2539]
Not logged in
[Honeypot]  [Browse]  [Home]  [Login]  [Reports
[Search]  [Ticket]  [Timeline
  [Patchset]  [Tagging/Branching

Check-in Number: 2539
Date: 2002-Sep-20 20:16:41 (local)
2002-Sep-20 18:16:41 (UTC)
User:rse
Branch:
Comment: upgrade to POPT 1.7
Tickets:
Inspections:
Files:
ossp-pkg/popt/VERSION      1.1 -> 1.2     1 inserted, 1 deleted
ossp-pkg/popt/popt.c      1.2 -> 1.3     233 inserted, 44 deleted
ossp-pkg/popt/popt.h      1.2 -> 1.3     16 inserted, 4 deleted

ossp-pkg/popt/VERSION 1.1 -> 1.2

--- VERSION      2002/01/30 14:05:32     1.1
+++ VERSION      2002/09/20 18:16:41     1.2
@@ -2,5 +2,5 @@
   VERSION -- Version Information for OSSP popt (syntax: Text)
   [automatically generated and maintained by GNU shtool]
 
-  This is OSSP popt, Version 0.1.0 (27-Jan-2002)
+  This is OSSP popt, Version 1.7.0 (20-Sep-2002)
 


ossp-pkg/popt/popt.c 1.2 -> 1.3

--- popt.c       2002/03/15 08:49:48     1.2
+++ popt.c       2002/09/20 18:16:41     1.3
@@ -25,7 +25,7 @@
  *
  *  NOTICE:
  *  This is an automatically generated, stripped down version of the
- *  POPT 1.6.4 library from Red Hat, Inc. This version is still
+ *  POPT 1.7 library from Red Hat, Inc. This version is still
  *  distributed under above Open Source license, but Red Hat is no longer
  *  responsible for this version. Contact The OSSP Project instead.
  */
@@ -34,7 +34,16 @@
 #include "config.h"
 #endif
 
+#if defined (__GLIBC__) && defined(__LCLINT__)
+
+extern __const __int32_t *__ctype_tolower;
+
+extern __const __int32_t *__ctype_toupper;
+
+#endif
+
 #include <ctype.h>
+
 #include <errno.h>
 #include <fcntl.h>
 #include <limits.h>
@@ -61,6 +70,8 @@
 #define alloca __builtin_alloca
 #endif
 
+char *strdup(const char *str);
+
 #include "popt.h"
 
 #ifndef H_POPTINT
@@ -74,12 +85,15 @@
 }
 
 typedef unsigned int __pbm_bits;
+
 #define __PBM_NBITS             (8 * sizeof (__pbm_bits))
 #define __PBM_IX(d)             ((d) / __PBM_NBITS)
 #define __PBM_MASK(d)           ((__pbm_bits) 1 << (((unsigned)(d)) % __PBM_NBITS))
+
 typedef struct {
         __pbm_bits bits[1];
 } pbm_set;
+
 #define __PBM_BITS(set) ((set)->bits)
 
 #define PBM_ALLOC(d)    calloc(__PBM_IX (d) + 1, sizeof(__pbm_bits))
@@ -90,36 +104,52 @@
 
 struct optionStackEntry {
         int argc;
+
         const char **argv;
+
         pbm_set *argb;
         int next;
+
         const char *nextArg;
+
         const char *nextCharArg;
+
         popt_item currAlias;
         int stuffed;
 };
 
 struct popt_context_s {
         struct optionStackEntry optionStack[POPT_OPTION_DEPTH];
+
         struct optionStackEntry *os;
+
         const char **leftovers;
         int numLeftovers;
         int nextLeftover;
+
         const struct popt_option *options;
         int restLeftover;
+
         const char *appName;
+
         popt_item aliases;
         int numAliases;
         int flags;
+
         popt_item execs;
         int numExecs;
+
         const char **finalArgv;
         int finalArgvCount;
         int finalArgvAlloced;
+
         popt_item doExec;
+
         const char *execPath;
         int execAbsolute;
+
         const char *otherHelp;
+
         pbm_set *arg_strip;
 };
 
@@ -133,7 +163,7 @@
 #define _(foo) foo
 #endif
 
-#if defined(HAVE_DGETTEXT) && !defined(__LCLINT__)
+#if defined(HAVE_DCGETTEXT) && !defined(__LCLINT__)
 #define D_(dom, str) dgettext(dom, str)
 #define POPT_(foo) D_("popt", foo)
 #else
@@ -355,9 +385,11 @@
         con->doExec = NULL;
 
         if (con->finalArgv != NULL)
-                for (i = 0; i < con->finalArgvCount; i++)
+                for (i = 0; i < con->finalArgvCount; i++) {
                         con->finalArgv[i] = _free(con->finalArgv[i]);
 
+                }
+
         con->finalArgvCount = 0;
         con->arg_strip = PBM_FREE(con->arg_strip);
         return;
@@ -542,6 +574,7 @@
                 return POPT_ERROR_NOARG;
 
         rc = execvp(argv[0], (char *const *)argv);
+
         return POPT_ERROR_ERRNO;
 }
 
@@ -705,25 +738,25 @@
 
 }
 
-static int poptSaveLong(const struct popt_option *opt, long aLong)
+int poptSaveLong(long *arg, int argInfo, long aLong)
 {
-        if (opt->arg == NULL)
+        if (arg == NULL || (((unsigned long)arg) & (sizeof (*arg) - 1)))
                 return POPT_ERROR_NULLARG;
 
-        if (opt->argInfo & POPT_ARGFLAG_NOT)
+        if (argInfo & POPT_ARGFLAG_NOT)
                 aLong = ~aLong;
-        switch (opt->argInfo & POPT_ARGFLAG_LOGICALOPS) {
+        switch (argInfo & POPT_ARGFLAG_LOGICALOPS) {
                 case 0:
-                        *((long *)opt->arg) = aLong;
+                        *arg = aLong;
                         break;
                 case POPT_ARGFLAG_OR:
-                        *((long *)opt->arg) |= aLong;
+                        *arg |= aLong;
                         break;
                 case POPT_ARGFLAG_AND:
-                        *((long *)opt->arg) &= aLong;
+                        *arg &= aLong;
                         break;
                 case POPT_ARGFLAG_XOR:
-                        *((long *)opt->arg) ^= aLong;
+                        *arg ^= aLong;
                         break;
                 default:
                         return POPT_ERROR_BADOPERATION;
@@ -732,25 +765,25 @@
         return 0;
 }
 
-static int poptSaveInt(const struct popt_option *opt, long aLong)
+int poptSaveInt(int *arg, int argInfo, long aLong)
 {
-        if (opt->arg == NULL)
+        if (arg == NULL || (((unsigned long)arg) & (sizeof (*arg) - 1)))
                 return POPT_ERROR_NULLARG;
 
-        if (opt->argInfo & POPT_ARGFLAG_NOT)
+        if (argInfo & POPT_ARGFLAG_NOT)
                 aLong = ~aLong;
-        switch (opt->argInfo & POPT_ARGFLAG_LOGICALOPS) {
+        switch (argInfo & POPT_ARGFLAG_LOGICALOPS) {
                 case 0:
-                        *((int *)opt->arg) = aLong;
+                        *arg = aLong;
                         break;
                 case POPT_ARGFLAG_OR:
-                        *((int *)opt->arg) |= aLong;
+                        *arg |= aLong;
                         break;
                 case POPT_ARGFLAG_AND:
-                        *((int *)opt->arg) &= aLong;
+                        *arg &= aLong;
                         break;
                 case POPT_ARGFLAG_XOR:
-                        *((int *)opt->arg) ^= aLong;
+                        *arg ^= aLong;
                         break;
                 default:
                         return POPT_ERROR_BADOPERATION;
@@ -896,12 +929,13 @@
                 if (opt == NULL)
                         return POPT_ERROR_BADOPT;
                 if (opt->arg && (opt->argInfo & POPT_ARG_MASK) == POPT_ARG_NONE) {
-                        if (poptSaveInt(opt, 1L))
+                        if (poptSaveInt((int *)opt->arg, opt->argInfo, 1L))
                                 return POPT_ERROR_BADOPERATION;
                 }
                 else if ((opt->argInfo & POPT_ARG_MASK) == POPT_ARG_VAL) {
                         if (opt->arg) {
-                                if (poptSaveInt(opt, (long)opt->val))
+                                if (poptSaveInt
+                                        ((int *)opt->arg, opt->argInfo, (long)opt->val))
                                         return POPT_ERROR_BADOPERATION;
                         }
                 }
@@ -967,13 +1001,15 @@
                                                                 POPT_ARG_LONG) {
                                                                 if (aLong == LONG_MIN || aLong == LONG_MAX)
                                                                         return POPT_ERROR_OVERFLOW;
-                                                                if (poptSaveLong(opt, aLong))
+                                                                if (poptSaveLong
+                                                                        ((long *)opt->arg, opt->argInfo, aLong))
                                                                         return POPT_ERROR_BADOPERATION;
                                                         }
                                                         else {
                                                                 if (aLong > INT_MAX || aLong < INT_MIN)
                                                                         return POPT_ERROR_OVERFLOW;
-                                                                if (poptSaveInt(opt, aLong))
+                                                                if (poptSaveInt
+                                                                        ((int *)opt->arg, opt->argInfo, aLong))
                                                                         return POPT_ERROR_BADOPERATION;
                                                         }
                                                 }
@@ -1419,6 +1455,101 @@
         return rc;
 }
 
+int poptConfigFileToString(FILE * fp, char **argstrp, int flags)
+{
+        char line[999];
+        char *argstr;
+        char *p;
+        char *q;
+        char *x;
+        int t;
+        int argvlen = 0;
+        size_t maxlinelen = sizeof (line);
+        size_t linelen;
+        int maxargvlen = 480;
+        int linenum = 0;
+
+        *argstrp = NULL;
+
+        if (fp == NULL)
+                return POPT_ERROR_NULLARG;
+
+        argstr = calloc(maxargvlen, sizeof (*argstr));
+        if (argstr == NULL)
+                return POPT_ERROR_MALLOC;
+
+        while (fgets(line, (int)maxlinelen, fp) != NULL) {
+                linenum++;
+                p = line;
+
+                while (*p != '\0' && isspace(*p))
+                        p++;
+
+                linelen = strlen(p);
+                if (linelen >= maxlinelen - 1)
+                        return POPT_ERROR_OVERFLOW;
+
+                if (*p == '\0' || *p == '\n')
+                        continue;
+                if (*p == '#')
+                        continue;
+
+                q = p;
+
+                while (*q != '\0' && (!isspace(*q)) && *q != '=')
+                        q++;
+
+                if (isspace(*q)) {
+                        *q++ = '\0';
+                        while (*q != '\0' && isspace((int)*q))
+                                q++;
+                }
+                if (*q == '\0') {
+                        q[-1] = '\0';
+                        argvlen += (t = q - p) + (sizeof (" --") - 1);
+                        if (argvlen >= maxargvlen) {
+                                maxargvlen = (t > maxargvlen) ? t * 2 : maxargvlen * 2;
+                                argstr = realloc(argstr, maxargvlen);
+                                if (argstr == NULL)
+                                        return POPT_ERROR_MALLOC;
+                        }
+                        strcat(argstr, " --");
+                        strcat(argstr, p);
+                        continue;
+                }
+                if (*q != '=')
+                        continue;
+
+                *q++ = '\0';
+
+                while (*q != '\0' && isspace(*q))
+                        q++;
+                if (*q == '\0')
+                        continue;
+
+                x = p + linelen;
+                while (isspace(*--x))
+                        *x = 0;
+
+                t = x - p;
+                argvlen += t + (sizeof ("' --='") - 1);
+                if (argvlen >= maxargvlen) {
+                        maxargvlen = (t > maxargvlen) ? t * 2 : maxargvlen * 2;
+                        argstr = realloc(argstr, maxargvlen);
+                        if (argstr == NULL)
+                                return POPT_ERROR_MALLOC;
+                }
+                strcat(argstr, " --");
+                strcat(argstr, p);
+                strcat(argstr, "=\"");
+                strcat(argstr, q);
+                strcat(argstr, "\"");
+        }
+
+        *argstrp = argstr;
+        return 0;
+}
+
 static void configLine(popt_context con, char *line)
 {
 
@@ -1582,8 +1713,10 @@
         rc = popt_readconfigfile(con, "/etc/popt");
         if (rc)
                 return rc;
+#if defined(HAVE_GETUID) && defined(HAVE_GETEUID)
         if (getuid() != geteuid())
                 return 0;
+#endif
 
         if ((home = getenv("HOME"))) {
                 fn = alloca(strlen(home) + 20);
@@ -1649,8 +1782,13 @@
         switch (opt->argInfo & POPT_ARG_MASK) {
                 case POPT_ARG_NONE:
                         return POPT_("NONE");
+#ifdef  DYING
                 case POPT_ARG_VAL:
                         return POPT_("VAL");
+#else
+                case POPT_ARG_VAL:
+                        return NULL;
+#endif
                 case POPT_ARG_INT:
                         return POPT_("INT");
                 case POPT_ARG_LONG:
@@ -1676,6 +1814,7 @@
 
         if (le == NULL)
                 return NULL;
+
         *le = '\0';
         *le++ = '(';
         strcpy(le, defstr);
@@ -1775,6 +1914,7 @@
                                 opt->longName);
         if (!*left)
                 goto out;
+
         if (argDescrip) {
                 char *le = left + strlen(left);
 
@@ -1807,6 +1947,7 @@
                                 case POPT_ARG_NONE:
                                         break;
                                 case POPT_ARG_VAL:
+#ifdef  NOTNOW
                                         {
                                                 long aLong = opt->val;
                                                 int ops = (opt->argInfo & POPT_ARGFLAG_LOGICALOPS);
@@ -1837,6 +1978,7 @@
 
                                                 *le++ = ']';
                                         }
+#endif
                                         break;
                                 case POPT_ARG_INT:
                                 case POPT_ARG_LONG:
@@ -1875,9 +2017,10 @@
         }
 
         helpLength = strlen(help);
+
         while (helpLength > lineLength) {
                 const char *ch;
-                char format[10];
+                char format[16];
 
                 ch = help + lineLength - 1;
                 while (ch > help && !isspace(*ch))
@@ -2011,6 +2154,7 @@
 
         fprintf(fp, POPT_("Usage:"));
         if (!(con->flags & POPT_CONTEXT_KEEP_FIRST)) {
+
                 fn = con->optionStack->argv[0];
 
                 if (fn == NULL)
@@ -2042,24 +2186,30 @@
                                                          const struct popt_option *opt,
                                                          const char *translation_domain)
 {
-        int len = 3;
+        int len = 4;
         char shortStr[2] = { '\0', '\0' };
         const char *item = shortStr;
         const char *argDescrip = getArgDescrip(opt, translation_domain);
 
-        if (opt->shortName != '\0') {
-                if (!(opt->argInfo & POPT_ARG_MASK))
-                        return cursor;
+        if (opt->shortName != '\0' && opt->longName != NULL) {
+                len += 2;
+                if (!(opt->argInfo & POPT_ARGFLAG_ONEDASH))
+                        len++;
+                len += strlen(opt->longName);
+        }
+        else if (opt->shortName != '\0') {
                 len++;
                 shortStr[0] = opt->shortName;
                 shortStr[1] = '\0';
         }
         else if (opt->longName) {
-                len += 1 + strlen(opt->longName);
+                len += strlen(opt->longName);
+                if (!(opt->argInfo & POPT_ARGFLAG_ONEDASH))
+                        len++;
                 item = opt->longName;
         }
 
-        if (len == 3)
+        if (len == 4)
                 return cursor;
 
         if (argDescrip)
@@ -2070,11 +2220,20 @@
                 cursor = 7;
         }
 
-        fprintf(fp, " [-%s%s%s%s]",
-                        ((opt->shortName
-                          || (opt->argInfo & POPT_ARGFLAG_ONEDASH)) ? "" : "-"), item,
-                        (argDescrip ? (opt->shortName != '\0' ? " " : "=") : ""),
-                        (argDescrip ? argDescrip : ""));
+        if (opt->longName && opt->shortName) {
+                fprintf(fp, " [-%c|-%s%s%s%s]",
+                                opt->shortName,
+                                ((opt->argInfo & POPT_ARGFLAG_ONEDASH) ? "" : "-"),
+                                opt->longName, (argDescrip ? " " : ""),
+                                (argDescrip ? argDescrip : ""));
+        }
+        else {
+                fprintf(fp, " [-%s%s%s%s]",
+                                ((opt->shortName
+                                  || (opt->argInfo & POPT_ARGFLAG_ONEDASH)) ? "" : "-"), item,
+                                (argDescrip ? (opt->shortName != '\0' ? " " : "=") : ""),
+                                (argDescrip ? argDescrip : ""));
+        }
 
         return cursor + len + 1;
 }
@@ -2101,9 +2260,15 @@
         return cursor;
 }
 
-static int singleTableUsage(popt_context con, FILE * fp,
-                                                        int cursor, const struct popt_option *opt,
-                                                        const char *translation_domain)
+typedef struct poptDone_s {
+        int nopts;
+        int maxopts;
+        const void **opts;
+}  *poptDone;
+
+static int singleTableUsage(popt_context con, FILE * fp, int cursor,
+                                                        const struct popt_option *opt,
+                                                        const char *translation_domain, poptDone done)
 {
         if (opt != NULL)
                 for (; (opt->longName || opt->shortName || opt->arg); opt++) {
@@ -2111,9 +2276,25 @@
                                 translation_domain = (const char *)opt->arg;
                         }
                         else if ((opt->argInfo & POPT_ARG_MASK) == POPT_ARG_INCLUDE_TABLE) {
-                                if (opt->arg)
-                                        cursor = singleTableUsage(con, fp, cursor, opt->arg,
-                                                                                          translation_domain);
+                                if (done) {
+                                        int i = 0;
+                                        for (i = 0; i < done->nopts; i++) {
+
+                                                const void *that = done->opts[i];
+
+                                                if (that == NULL || that != opt->arg)
+                                                        continue;
+                                                break;
+                                        }
+                                        if (opt->arg == NULL || i < done->nopts)
+                                                continue;
+
+                                        if (done->nopts < done->maxopts)
+                                                done->opts[done->nopts++] = (const void *)opt->arg;
+
+                                }
+                                cursor = singleTableUsage(con, fp, cursor, opt->arg,
+                                                                                  translation_domain, done);
                         }
                         else if ((opt->longName || opt->shortName) &&
                                          !(opt->argInfo & POPT_ARGFLAG_DOC_HIDDEN)) {
@@ -2154,13 +2335,21 @@
 
 void popt_printusage(popt_context con, FILE * fp, int flags)
 {
+        poptDone done = memset(alloca(sizeof (*done)), 0, sizeof (*done));
         int cursor;
 
+        done->nopts = 0;
+        done->maxopts = 64;
+        cursor = done->maxopts * sizeof (*done->opts);
+
+        done->opts = memset(alloca(cursor), 0, cursor);
+        done->opts[done->nopts++] = (const void *)con->options;
+
         cursor = showHelpIntro(con, fp);
         cursor += showShortOptions(con->options, fp, NULL);
-        (void)singleTableUsage(con, fp, cursor, con->options, NULL);
-        (void)itemUsage(fp, cursor, con->aliases, con->numAliases, NULL);
-        (void)itemUsage(fp, cursor, con->execs, con->numExecs, NULL);
+        cursor = singleTableUsage(con, fp, cursor, con->options, NULL, done);
+        cursor = itemUsage(fp, cursor, con->aliases, con->numAliases, NULL);
+        cursor = itemUsage(fp, cursor, con->execs, con->numExecs, NULL);
 
         if (con->otherHelp) {
                 cursor += strlen(con->otherHelp) + 1;


ossp-pkg/popt/popt.h 1.2 -> 1.3

--- popt.h       2002/03/15 08:49:49     1.2
+++ popt.h       2002/09/20 18:16:41     1.3
@@ -25,7 +25,7 @@
  *
  *  NOTICE:
  *  This is an automatically generated, stripped down version of the
- *  POPT 1.6.4 library from Red Hat, Inc. This version is still
+ *  POPT 1.7 library from Red Hat, Inc. This version is still
  *  distributed under above Open Source license, but Red Hat is no longer
  *  responsible for this version. Contact The OSSP Project instead.
  */
@@ -118,10 +118,12 @@
 }  *popt_item;
 
 extern struct popt_option popt_aliasOptions[];
+
 #define POPT_AUTOALIAS { NULL, '\0', POPT_ARG_INCLUDE_TABLE, popt_aliasOptions, \
                         0, "Options implemented via popt alias/exec:", NULL },
 
 extern struct popt_option popt_helpoptions[];
+
 #define POPT_AUTOHELP { NULL, '\0', POPT_ARG_INCLUDE_TABLE, popt_helpoptions, \
                         0, "Help options:", NULL },
 
@@ -135,9 +137,10 @@
 
 #endif
 
-enum popt_callbackreason { POPT_CALLBACK_REASON_PRE,
-        POPT_CALLBACK_REASON_POST,
-        POPT_CALLBACK_REASON_OPTION
+enum popt_callbackreason {
+        POPT_CALLBACK_REASON_PRE = 0,
+        POPT_CALLBACK_REASON_POST = 1,
+        POPT_CALLBACK_REASON_OPTION = 2
 };
 
 #ifdef __cplusplus
@@ -189,6 +192,9 @@
         int popt_parseargvstring(const char *s,
                                                          int *argcPtr, const char ***argvPtr);
 
+        int poptConfigFileToString(FILE * fp, char **argstrp, int flags)
+           ;
+
         const char *const popt_strerror(const int error);
 
         void popt_setexecpath(popt_context con, const char *path,
@@ -206,6 +212,12 @@
 
         int popt_strippedargv(popt_context con, int argc, char **argv);
 
+        int poptSaveLong(long *arg, int argInfo, long aLong)
+           ;
+
+        int poptSaveInt(int *arg, int argInfo, long aLong)
+           ;
+
 #ifdef  __cplusplus
 }
 #endif

CVSTrac 2.0.1