libgnorba: Remove GnomeObject stuff.
authorElliot Lee <sopwith@src.gnome.org>
Tue, 6 Jul 1999 20:29:42 +0000 (20:29 +0000)
committerElliot Lee <sopwith@src.gnome.org>
Tue, 6 Jul 1999 20:29:42 +0000 (20:29 +0000)
libgnorba: Remove GnomeObject stuff.

support: Merge newer popt in from canonical source.

svn path=/trunk/; revision=842

support/popt-gnome.h
support/popt.c
support/poptconfig.c
support/popthelp.c
support/poptint.h
support/poptparse.c

index 6dc2765..2fea9e8 100644 (file)
@@ -5,6 +5,10 @@
 #ifndef H_POPT
 #define H_POPT
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 #include <stdio.h>                     /* for FILE * */
 
 #define POPT_OPTION_DEPTH      10
@@ -112,4 +116,8 @@ void poptPrintUsage(poptContext con, FILE * f, int flags);
 void poptSetOtherOptionHelp(poptContext con, const char * text);
 const char * poptGetInvocationName(poptContext con);
 
+#ifdef  __cplusplus
+}
+#endif
+
 #endif
index f146924..29d43ed 100644 (file)
@@ -52,7 +52,7 @@ static void invokeCallbacks(poptContext con, const struct poptOption * table,
        } else if (((opt->argInfo & POPT_ARG_MASK) == POPT_ARG_CALLBACK) &&
                   ((!post && (opt->argInfo & POPT_CBFLAG_PRE)) ||
                    ( post && (opt->argInfo & POPT_CBFLAG_POST)))) {
-           cb = opt->arg;
+           cb = (poptCallbackType)opt->arg;
            cb(con, post ? POPT_CALLBACK_REASON_POST : POPT_CALLBACK_REASON_PRE,
               NULL, NULL, opt->descrip);
        }
@@ -92,6 +92,8 @@ poptContext poptGetContext(char * name, int argc, char ** argv,
 }
 
 void poptResetContext(poptContext con) {
+    int i;
+
     con->os = con->optionStack;
     con->os->currAlias = NULL;
     con->os->nextCharArg = NULL;
@@ -102,6 +104,10 @@ void poptResetContext(poptContext con) {
     con->nextLeftover = 0;
     con->restLeftover = 0;
     con->doExec = NULL;
+
+    for (i = 0; i < con->finalArgvCount; i++)
+       free(con->finalArgv[i]);
+
     con->finalArgvCount = 0;
 }
 
@@ -223,7 +229,18 @@ static void execCommand(poptContext con) {
 #ifdef __hpux
     setresuid(getuid(), getuid(),-1);
 #else
+/*
+ * XXX " ... on BSD systems setuid() should be preferred over setreuid()"
+ * XXX         sez' Timur Bakeyev <mc@bat.ru>
+ * XXX from Norbert Warmuth <nwarmuth@privat.circular.de>
+ */
+#if defined(HAVE_SETUID)
+    setuid(getuid());
+#elif defined (HAVE_SETREUID)
     setreuid(getuid(), getuid()); /*hlauer: not portable to hpux9.01 */
+#else
+    ; /* Can't drop privileges */
+#endif
 #endif
 
     execvp(argv[0], argv);
@@ -231,7 +248,7 @@ static void execCommand(poptContext con) {
 
 static const struct poptOption * findOption(const struct poptOption * table,
                                            const char * longName,
-                                           const char shortName,
+                                           char shortName,
                                            poptCallbackType * callback,
                                            void ** callbackData,
                                            int singleDash) {
@@ -239,6 +256,10 @@ static const struct poptOption * findOption(const struct poptOption * table,
     const struct poptOption * opt2;
     const struct poptOption * cb = NULL;
 
+    /* This happens when a single - is given */
+    if (singleDash && !shortName && !*longName)
+       shortName = '-';
+
     while (opt->longName || opt->shortName || opt->arg) {
        if ((opt->argInfo & POPT_ARG_MASK) == POPT_ARG_INCLUDE_TABLE) {
            opt2 = findOption(opt->arg, longName, shortName, callback, 
@@ -264,7 +285,7 @@ static const struct poptOption * findOption(const struct poptOption * table,
     *callbackData = NULL;
     *callback = NULL;
     if (cb) {
-       *callback = cb->arg;
+       *callback = (poptCallbackType)cb->arg;
        if (!(cb->argInfo & POPT_CBFLAG_INC_DATA))
            *callbackData = cb->descrip;
     }
@@ -397,7 +418,7 @@ int poptGetNextOpt(poptContext con) {
                  case POPT_ARG_INT:
                  case POPT_ARG_LONG:
                    aLong = strtol(con->os->nextArg, &end, 0);
-                   if (*end
+                   if (!(end && *end == '\0')
                        return POPT_ERROR_BADNUMBER;
 
                    if (aLong == LONG_MIN || aLong == LONG_MAX)
@@ -492,6 +513,7 @@ void poptFreeContext(poptContext con) {
     if (con->appName) free(con->appName);
     if (con->aliases) free(con->aliases);
     if (con->otherHelp) free(con->otherHelp);
+    if (con->execPath) free(con->execPath);
     free(con);
 }
 
index dabf6f5..63274ee 100644 (file)
@@ -87,7 +87,7 @@ int poptReadConfigFile(poptContext con, char * fn) {
     lseek(fd, 0, 0);
 
     file = alloca(fileLength + 1);
-    if ((fd = read(fd, file, fileLength)) != fileLength) {
+    if (read(fd, file, fileLength) != fileLength) {
        rc = errno;
        close(fd);
        errno = rc;
index 618f8a2..bde26c9 100644 (file)
@@ -31,7 +31,7 @@ static void displayArgs(poptContext con, enum poptCallbackReason foo,
 }
 
 struct poptOption poptHelpOptions[] = {
-    { NULL, '\0', POPT_ARG_CALLBACK, &displayArgs, '\0', NULL },
+    { NULL, '\0', POPT_ARG_CALLBACK, (void *)&displayArgs, '\0', NULL },
     { "help", '?', 0, NULL, '?', N_("Show this help message") },
     { "usage", '\0', 0, NULL, 'u', N_("Display brief usage message") },
     { NULL, '\0', 0, NULL, 0 }
@@ -73,10 +73,12 @@ static void singleOptionHelp(FILE * f, int maxLeftCol,
     int helpLength;
     const char * ch;
     char format[10];
-    char * left = alloca(maxLeftCol + 1);
+    char * left;
     const char * argDescrip = getArgDescrip(opt, translation_domain);
 
+    left = malloc(maxLeftCol + 1);
     *left = '\0';
+
     if (opt->longName && opt->shortName)
        sprintf(left, "-%c, --%s", opt->shortName, opt->longName);
     else if (opt->shortName) 
@@ -93,7 +95,7 @@ static void singleOptionHelp(FILE * f, int maxLeftCol,
        fprintf(f,"  %-*s   ", maxLeftCol, left);
     else {
        fprintf(f,"  %s\n", left); 
-       return;
+       goto out;
     }
 
     helpLength = strlen(help);
@@ -112,6 +114,9 @@ static void singleOptionHelp(FILE * f, int maxLeftCol,
     }
 
     if (helpLength) fprintf(f, "%s\n", help);
+
+out:
+    free(left);
 }
 
 static int maxArgWidth(const struct poptOption * opt,
@@ -237,7 +242,7 @@ static int singleOptionUsage(FILE * f, int cursor,
     return cursor + len + 1;
 }
 
-int singleTableUsage(FILE * f, int cursor, const struct poptOption * table,
+static int singleTableUsage(FILE * f, int cursor, const struct poptOption * table,
                     const char *translation_domain) {
     const struct poptOption * opt;
     
@@ -265,7 +270,7 @@ static int showShortOptions(const struct poptOption * opt, FILE * f,
 
     if (!str) {
        str = s;
-       memset(str, 0, sizeof(str));
+       memset(str, 0, sizeof(s));
     }
 
     while (opt->longName || opt->shortName || opt->arg) {
index 57dd839..8fc6a84 100644 (file)
@@ -49,10 +49,14 @@ struct poptContext_s {
 
 #ifdef HAVE_GETTEXT
 #define _(foo) gettext(foo)
+#else
+#define _(foo) (foo)
+#endif
+
+#ifdef HAVE_DGETTEXT
 #define D_(dom, str) dgettext(dom, str)
 #define POPT_(foo) D_("popt", foo)
 #else
-#define _(foo) (foo)
 #define POPT_(foo) (foo)
 #define D_(dom, str) (str)
 #endif
index b4e1434..720506b 100644 (file)
@@ -9,19 +9,33 @@
 #include <ctype.h>
 #include <stdlib.h>
 #include <string.h>
-#ifdef HAVE_ALLOCA_H
-#include <alloca.h>
+
+/* AIX requires this to be the first thing in the file.  */
+#ifndef __GNUC__
+# if HAVE_ALLOCA_H
+#  include <alloca.h>
+# else
+#  ifdef _AIX
+#pragma alloca
+#  else
+#   ifndef alloca /* predefined by HP cc +Olibcalls */
+char *alloca ();
+#   endif
+#  endif
+# endif
+#elif defined(__GNUC__) && defined(__STRICT_ANSI__)
+#define alloca __builtin_alloca
 #endif
 
 #include "popt-gnome.h"
 
-static const int poptArgvArrayGrowDelta = 5;
+#define POPT_ARGV_ARRAY_GROW_DELTA 5
 
 int poptParseArgvString(const char * s, int * argcPtr, char *** argvPtr) {
     char * buf, * bufStart, * dst;
     const char * src;
     char quote = '\0';
-    int argvAlloced = poptArgvArrayGrowDelta;
+    int argvAlloced = POPT_ARGV_ARRAY_GROW_DELTA;
     char ** argv = malloc(sizeof(*argv) * argvAlloced);
     char ** argv2;
     int argc = 0;
@@ -51,7 +65,7 @@ int poptParseArgvString(const char * s, int * argcPtr, char *** argvPtr) {
            if (*argv[argc]) {
                buf++, argc++;
                if (argc == argvAlloced) {
-                   argvAlloced += poptArgvArrayGrowDelta;
+                   argvAlloced += POPT_ARGV_ARRAY_GROW_DELTA;
                    argv = realloc(argv, sizeof(*argv) * argvAlloced);
                }
                argv[argc] = buf;