summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorElliot Lee <sopwith@src.gnome.org>1999-07-06 20:29:42 +0000
committerElliot Lee <sopwith@src.gnome.org>1999-07-06 20:29:42 +0000
commitc3885daa46991d1e4fb2f2aa7b49c8df5b26e204 (patch)
tree5c2c77e8c8dedbc6dcbce7ae656b640ccb2c4b42
parent984258c935552744012274d80886b4e72e25b4a0 (diff)
downloadgnome-common-c3885daa46991d1e4fb2f2aa7b49c8df5b26e204.tar.gz
libgnorba: Remove GnomeObject stuff.
libgnorba: Remove GnomeObject stuff. support: Merge newer popt in from canonical source. svn path=/trunk/; revision=842
-rw-r--r--support/popt-gnome.h8
-rw-r--r--support/popt.c30
-rw-r--r--support/poptconfig.c2
-rw-r--r--support/popthelp.c15
-rw-r--r--support/poptint.h6
-rw-r--r--support/poptparse.c24
6 files changed, 69 insertions, 16 deletions
diff --git a/support/popt-gnome.h b/support/popt-gnome.h
index 6dc2765..2fea9e8 100644
--- a/support/popt-gnome.h
+++ b/support/popt-gnome.h
@@ -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
diff --git a/support/popt.c b/support/popt.c
index f146924..29d43ed 100644
--- a/support/popt.c
+++ b/support/popt.c
@@ -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);
}
diff --git a/support/poptconfig.c b/support/poptconfig.c
index dabf6f5..63274ee 100644
--- a/support/poptconfig.c
+++ b/support/poptconfig.c
@@ -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;
diff --git a/support/popthelp.c b/support/popthelp.c
index 618f8a2..bde26c9 100644
--- a/support/popthelp.c
+++ b/support/popthelp.c
@@ -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) {
diff --git a/support/poptint.h b/support/poptint.h
index 57dd839..8fc6a84 100644
--- a/support/poptint.h
+++ b/support/poptint.h
@@ -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
diff --git a/support/poptparse.c b/support/poptparse.c
index b4e1434..720506b 100644
--- a/support/poptparse.c
+++ b/support/poptparse.c
@@ -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;