X-Git-Url: https://diplodocus.org/git/nmh/blobdiff_plain/92c3b05ef3e582d64b3cecfc261fdd66ef13a4ef..3c54bbb247ffc8fa094d754099c0b009e79d484d:/sbr/arglist.c?ds=sidebyside diff --git a/sbr/arglist.c b/sbr/arglist.c index 59d311b2..168e36b7 100644 --- a/sbr/arglist.c +++ b/sbr/arglist.c @@ -5,8 +5,12 @@ * complete copyright information. */ -#include -#include +#include "h/mh.h" +#include "r1bindex.h" +#include "brkstring.h" +#include "error.h" +#include "arglist.h" +#include "h/utils.h" /* * Split up a command into an appropriate array to pass to execvp() @@ -39,25 +43,27 @@ char ** argsplit(char *command, char **file, int *argp) { char **argvarray, *p; - int space = 0, metachar = 0, i; + int i; + bool space = false; + bool metachar = false; for (p = command; *p; p++) { if (*p == ' ' || *p == '\t') { - space = 1; + space = true; } else if (strchr(METACHARS, *p)) { - metachar = 1; + metachar = true; break; } } - argvarray = (char **)mh_xmalloc(sizeof *argvarray * (MAXARGS + 5)); + argvarray = mh_xmalloc(sizeof *argvarray * (MAXARGS + 5)); /* * The simple case - no spaces or shell metacharacters */ if (!space && !metachar) { - argvarray[0] = getcpy(r1bindex(command, '/')); + argvarray[0] = mh_xstrdup(r1bindex(command, '/')); argvarray[1] = NULL; *file = mh_xstrdup(command); if (argp) @@ -75,12 +81,12 @@ argsplit(char *command, char **file, int *argp) p = mh_xstrdup(command); split = brkstring(p, " \t", NULL); if (split[0] == NULL) { - adios(NULL, "Invalid blank command found"); + die("Invalid blank command found"); } argvarray[0] = mh_xstrdup(r1bindex(split[0], '/')); for (i = 1; split[i] != NULL; i++) { if (i > MAXARGS) { - adios(NULL, "Command exceeded argument limit"); + die("Command exceeded argument limit"); } argvarray[i] = mh_xstrdup(split[i]); }