libgnorba: Remove GnomeObject stuff.
support: Merge newer popt in from canonical source.
svn path=/trunk/; revision=842
#ifndef H_POPT
#define H_POPT
+#ifdef __cplusplus
+extern "C" {
+#endif
+
#include <stdio.h> /* for FILE * */
#define POPT_OPTION_DEPTH 10
void poptSetOtherOptionHelp(poptContext con, const char * text);
const char * poptGetInvocationName(poptContext con);
+#ifdef __cplusplus
+}
+#endif
+
#endif
} 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);
}
}
void poptResetContext(poptContext con) {
+ int i;
+
con->os = con->optionStack;
con->os->currAlias = NULL;
con->os->nextCharArg = NULL;
con->nextLeftover = 0;
con->restLeftover = 0;
con->doExec = NULL;
+
+ for (i = 0; i < con->finalArgvCount; i++)
+ free(con->finalArgv[i]);
+
con->finalArgvCount = 0;
}
#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);
static const struct poptOption * findOption(const struct poptOption * table,
const char * longName,
- const char shortName,
+ char shortName,
poptCallbackType * callback,
void ** callbackData,
int singleDash) {
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,
*callbackData = NULL;
*callback = NULL;
if (cb) {
- *callback = cb->arg;
+ *callback = (poptCallbackType)cb->arg;
if (!(cb->argInfo & POPT_CBFLAG_INC_DATA))
*callbackData = cb->descrip;
}
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)
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);
}
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;
}
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 }
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)
fprintf(f," %-*s ", maxLeftCol, left);
else {
fprintf(f," %s\n", left);
- return;
+ goto out;
}
helpLength = strlen(help);
}
if (helpLength) fprintf(f, "%s\n", help);
+
+out:
+ free(left);
}
static int maxArgWidth(const struct poptOption * opt,
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;
if (!str) {
str = s;
- memset(str, 0, sizeof(str));
+ memset(str, 0, sizeof(s));
}
while (opt->longName || opt->shortName || opt->arg) {
#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
#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;
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;