poptParseArgvString cleanups...
authorJeff Garzik <jgarzik@src.gnome.org>
Thu, 24 Dec 1998 20:31:34 +0000 (20:31 +0000)
committerJeff Garzik <jgarzik@src.gnome.org>
Thu, 24 Dec 1998 20:31:34 +0000 (20:31 +0000)
x
       Added array grow increment constant.
       Remove unnecessary 'dst' init.
       Remove unnecessary strcpy().
       Make arg 's' and var 'src' const-correct.

svn path=/trunk/; revision=543

support/ChangeLog
support/popt-gnome.h
support/poptparse.c

index bf06924..bd1b2ee 100644 (file)
@@ -1,3 +1,11 @@
+1998-12-24  Jeff Garzik  <jgarzik@pobox.com>
+
+       * poptparse.[ch]:  poptParseArgvString cleanups...
+       Added array grow increment constant.
+       Remove unnecessary 'dst' init.
+       Remove unnecessary strcpy().
+       Make arg 's' and var 'src' const-correct.
+
 1998-12-21  Matt Wilson  <msw@redhat.com>
 
        * poptparse.c: fix pointer assignment
index 069cab1..6dc2765 100644 (file)
@@ -104,7 +104,7 @@ int poptReadConfigFile(poptContext con, char * fn);
 int poptReadDefaultConfig(poptContext con, int useEnv);
 /* argv should be freed -- this allows ', ", and \ quoting, but ' is treated
    the same as " and both may include \ quotes */
-int poptParseArgvString(char * s, int * argcPtr, char *** argvPtr);
+int poptParseArgvString(const char * s, int * argcPtr, char *** argvPtr);
 const char * poptStrerror(const int error);
 void poptSetExecPath(poptContext con, const char * path, int allowAbsolute);
 void poptPrintHelp(poptContext con, FILE * f, int flags);
index 2e9bc73..b4e1434 100644 (file)
 
 #include "popt-gnome.h"
 
-int poptParseArgvString(char * s, int * argcPtr, char *** argvPtr) {
-    char * buf = strcpy(alloca(strlen(s) + 1), s);
-    char * bufStart = buf;
-    char * src, * dst;
+static const int poptArgvArrayGrowDelta = 5;
+
+int poptParseArgvString(const char * s, int * argcPtr, char *** argvPtr) {
+    char * buf, * bufStart, * dst;
+    const char * src;
     char quote = '\0';
-    int argvAlloced = 5;
+    int argvAlloced = poptArgvArrayGrowDelta;
     char ** argv = malloc(sizeof(*argv) * argvAlloced);
     char ** argv2;
     int argc = 0;
-    int i;
+    int i, buflen;
+
+    buflen = strlen(s) + 1;
+    bufStart = buf = alloca(buflen);
+    memset(buf, '\0', buflen);
 
     src = s;
-    dst = buf;
     argv[argc] = buf;
 
-    memset(buf, '\0', strlen(s) + 1);
-
     while (*src) {
        if (quote == *src) {
            quote = '\0';
@@ -49,7 +51,7 @@ int poptParseArgvString(char * s, int * argcPtr, char *** argvPtr) {
            if (*argv[argc]) {
                buf++, argc++;
                if (argc == argvAlloced) {
-                   argvAlloced += 5;
+                   argvAlloced += poptArgvArrayGrowDelta;
                    argv = realloc(argv, sizeof(*argv) * argvAlloced);
                }
                argv[argc] = buf;