summaryrefslogtreecommitdiff
path: root/support/poptparse.c
diff options
context:
space:
mode:
authorElliot Lee <sopwith@src.gnome.org>1999-10-29 19:16:05 +0000
committerElliot Lee <sopwith@src.gnome.org>1999-10-29 19:16:05 +0000
commit8c686af4f60f006d9e25df5f3beb379ca8045a92 (patch)
tree0e91de956d23aae880097567d0b91a11828655e4 /support/poptparse.c
parentc4f37e5ec5758b4ac49ac31b3f810846802f6ecc (diff)
downloadshared-mime-info-8c686af4f60f006d9e25df5f3beb379ca8045a92.tar.gz
builds now. Integrate new popt. Don't install this library. Link
* liboafgnome/: builds now. * support/: Integrate new popt. Don't install this library. * libgnome/Makefile.am: Link ../support/libgnomesupport.la in as part of libgnome.la * */Makefile.am: Reflect this * configure.in: Use AM_PATH_ORBIT macro svn path=/trunk/; revision=984
Diffstat (limited to 'support/poptparse.c')
-rw-r--r--support/poptparse.c105
1 files changed, 55 insertions, 50 deletions
diff --git a/support/poptparse.c b/support/poptparse.c
index fa708155..65c948b6 100644
--- a/support/poptparse.c
+++ b/support/poptparse.c
@@ -2,53 +2,53 @@
file accompanying popt source distributions, available from
ftp://ftp.redhat.com/pub/code/popt */
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
+#include "system.h"
+#include "poptint.h"
-#include <ctype.h>
-#include <stdlib.h>
-#include <string.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
+#define POPT_ARGV_ARRAY_GROW_DELTA 5
-#include "popt-gnome.h"
+int poptDupArgv(int argc, const char **argv,
+ int * argcPtr, const char *** argvPtr)
+{
+ size_t nb = (argc + 1) * sizeof(*argv);
+ const char ** argv2;
+ char * dst;
+ int i;
-#define POPT_ARGV_ARRAY_GROW_DELTA 5
+ for (i = 0; i < argc; i++) {
+ if (argv[i] == NULL)
+ return POPT_ERROR_NOARG;
+ nb += strlen(argv[i]) + 1;
+ }
+
+ dst = malloc(nb);
+ argv2 = (void *) dst;
+ dst += (argc + 1) * sizeof(*argv);
+
+ for (i = 0; i < argc; i++) {
+ argv2[i] = dst;
+ dst += strlen(strcpy(dst, argv[i])) + 1;
+ }
+ argv2[argc] = NULL;
+
+ *argvPtr = argv2;
+ *argcPtr = argc;
+ return 0;
+}
-int poptParseArgvString(const char * s, int * argcPtr, char *** argvPtr) {
- char * buf, * bufStart, * dst;
+int poptParseArgvString(const char * s, int * argcPtr, const char *** argvPtr)
+{
const char * src;
char quote = '\0';
int argvAlloced = POPT_ARGV_ARRAY_GROW_DELTA;
- char ** argv = malloc(sizeof(*argv) * argvAlloced);
- const char ** argv2;
+ const char ** argv = malloc(sizeof(*argv) * argvAlloced);
int argc = 0;
- int i, buflen;
-
- buflen = strlen(s) + 1;
- bufStart = buf = alloca(buflen);
- memset(buf, '\0', buflen);
+ int buflen = strlen(s) + 1;
+ char * buf = memset(alloca(buflen), 0, buflen);
- src = s;
argv[argc] = buf;
- while (*src) {
+ for (src = s; *src; src++) {
if (quote == *src) {
quote = '\0';
} else if (quote) {
@@ -81,33 +81,38 @@ int poptParseArgvString(const char * s, int * argcPtr, char *** argvPtr) {
free(argv);
return POPT_ERROR_BADQUOTE;
}
- /* fallthrough */
+ /*@fallthrough@*/
default:
*buf++ = *src;
+ break;
}
-
- src++;
}
if (strlen(argv[argc])) {
argc++, buf++;
}
- dst = malloc((argc + 1) * sizeof(*argv) + (buf - bufStart));
- argv2 = (void *) dst;
- dst += (argc + 1) * sizeof(*argv);
- memcpy(argv2, argv, argc * sizeof(*argv));
- argv2[argc] = NULL;
- memcpy(dst, bufStart, buf - bufStart);
+#if 0
+ { char * dst = malloc((argc + 1) * sizeof(*argv) + (buf - argv[0]));
+ const char ** argv2 = (void *) dst;
+ int i;
- for (i = 0; i < argc; i++) {
- argv2[i] = dst + (argv[i] - bufStart);
+ dst += (argc + 1) * sizeof(*argv);
+ memcpy(argv2, argv, argc * sizeof(*argv));
+ argv2[argc] = NULL;
+ memcpy(dst, argv[0], buf - argv[0]);
+
+ for (i = 0; i < argc; i++)
+ argv2[i] = dst + (argv[i] - argv[0]);
+
+ *argvPtr = argv2;
+ *argcPtr = argc;
}
+#else
+ (void) poptDupArgv(argc, argv, argcPtr, argvPtr);
+#endif
free(argv);
- *argvPtr = (char **)argv2; /* XXX don't change the API */
- *argcPtr = argc;
-
return 0;
}