]> diplodocus.org Git - nmh/blobdiff - sbr/arglist.c
Rewrite norm_charmap(), moving code into data.
[nmh] / sbr / arglist.c
index f40f1e89f786bd92a93bb384547137d3caee1da3..cd88b86b54d64cc5e383320d1226c6b845b757c5 100644 (file)
@@ -1,6 +1,4 @@
-
-/*
- * arglist.c -- Routines for handling argument lists for execvp() and friends
+/* arglist.c -- Routines for handling argument lists for execvp() and friends
  *
  * This code is Copyright (c) 2013, by the authors of nmh.  See the
  * COPYRIGHT file in the root directory of the nmh distribution for
  *
  * This code is Copyright (c) 2013, by the authors of nmh.  See the
  * COPYRIGHT file in the root directory of the nmh distribution for
@@ -61,33 +59,33 @@ argsplit(char *command, char **file, int *argp)
     if (!space && !metachar) {
        argvarray[0] = getcpy(r1bindex(command, '/'));
        argvarray[1] = NULL;
     if (!space && !metachar) {
        argvarray[0] = getcpy(r1bindex(command, '/'));
        argvarray[1] = NULL;
-       *file = getcpy(command);
+       *file = mh_xstrdup(command);
        if (argp)
            *argp = 1;
        return argvarray;
     }
 
     /*
        if (argp)
            *argp = 1;
        return argvarray;
     }
 
     /*
-     * Spaces, but no shell metacharacters; space-split into seperate
+     * Spaces, but no shell metacharacters; space-split into separate
      * arguments
      */
 
     if (space && !metachar) {
        char **split;
      * arguments
      */
 
     if (space && !metachar) {
        char **split;
-       p = getcpy(command);
+       p = mh_xstrdup(command);
        split = brkstring(p, " \t", NULL);
        if (split[0] == NULL) {
            adios(NULL, "Invalid blank command found");
        }
        split = brkstring(p, " \t", NULL);
        if (split[0] == NULL) {
            adios(NULL, "Invalid blank command found");
        }
-       argvarray[0] = getcpy(r1bindex(split[0], '/'));
+       argvarray[0] = mh_xstrdup(r1bindex(split[0], '/'));
        for (i = 1; split[i] != NULL; i++) {
            if (i > MAXARGS) {
                adios(NULL, "Command exceeded argument limit");
            }
        for (i = 1; split[i] != NULL; i++) {
            if (i > MAXARGS) {
                adios(NULL, "Command exceeded argument limit");
            }
-           argvarray[i] = getcpy(split[i]);
+           argvarray[i] = mh_xstrdup(split[i]);
        }
        argvarray[i] = NULL;
        }
        argvarray[i] = NULL;
-       *file = getcpy(split[0]);
+       *file = mh_xstrdup(split[0]);
        if (argp)
            *argp = i;
        free(p);
        if (argp)
            *argp = i;
        free(p);
@@ -110,12 +108,12 @@ argsplit(char *command, char **file, int *argp)
      *   So we put in a dummy argument (we just use /bin/sh)
      */
 
      *   So we put in a dummy argument (we just use /bin/sh)
      */
 
-    *file = getcpy("/bin/sh");
-    argvarray[0] = getcpy("sh");
-    argvarray[1] = getcpy("-c");
-    argvarray[2] = getcpy(command);
+    *file = mh_xstrdup("/bin/sh");
+    argvarray[0] = mh_xstrdup("sh");
+    argvarray[1] = mh_xstrdup("-c");
+    argvarray[2] = mh_xstrdup(command);
     argvarray[2] = add(" \"$@\"", argvarray[2]);
     argvarray[2] = add(" \"$@\"", argvarray[2]);
-    argvarray[3] = getcpy("/bin/sh");
+    argvarray[3] = mh_xstrdup("/bin/sh");
     argvarray[4] = NULL;
 
     if (argp)
     argvarray[4] = NULL;
 
     if (argp)
@@ -133,8 +131,7 @@ arglist_free(char *command, char **argvarray)
 {
     int i;
 
 {
     int i;
 
-    if (command != NULL)
-       free(command);
+    mh_xfree(command);
 
     if (argvarray != NULL) {
        for (i = 0; argvarray[i] != NULL; i++)
 
     if (argvarray != NULL) {
        for (i = 0; argvarray[i] != NULL; i++)
@@ -202,8 +199,8 @@ argsplit_insert(struct msgs_array *msgs, char *command, char **program)
      */
 
     if (msgs->size + argp >= msgs->max) {
      */
 
     if (msgs->size + argp >= msgs->max) {
-       msgs->max += MAXMSGS > argp ? MAXMSGS : argp;
-       msgs->msgs = mh_xrealloc(msgs->msgs, msgs->max * sizeof(*msgs->msgs));
+        msgs->max += max(MAXMSGS, argp);
+        msgs->msgs = mh_xrealloc(msgs->msgs, msgs->max * sizeof(*msgs->msgs));
     }
 
     for (i = msgs->size - 1; i >= 0; i--)
     }
 
     for (i = msgs->size - 1; i >= 0; i--)