commit 91088df2692cc0c89f0828c12dd8ff8850e39de3
Author:     Quentin Rameau <[email protected]>
AuthorDate: Sat Jun 18 15:03:30 2016 +0200
Commit:     Quentin Rameau <[email protected]>
CommitDate: Sat Jun 18 15:03:30 2016 +0200

    [driver] use struct items int tool
    
    Replace args and nargs with our defined struct items.

diff --git a/driver/posix/scc.c b/driver/posix/scc.c
index f8bf4c7..71d8185 100644
--- a/driver/posix/scc.c
+++ b/driver/posix/scc.c
@@ -29,10 +29,10 @@ enum {
 
 static struct tool {
        char   cmd[PATH_MAX];
-       char **args;
        char   bin[16];
        char  *outfile;
-       int    nparams, nargs, in, out, init;
+       struct items args;
+       int    nparams, in, out, init;
        pid_t  pid;
 } tools[] = {
        [CC1]    = { .bin = "cc1",   .cmd = PREFIX "/libexec/scc/", },
@@ -69,10 +69,10 @@ addarg(int tool, char *arg)
 {
        struct tool *t = &tools[tool];
 
-       if (t->nargs < 1)
-               t->nargs = 1;
+       if (t->args.n < 1)
+               t->args.n = 1;
 
-       t->args = newitem(t->args, t->nargs++, arg);
+       t->args.s = newitem(t->args.s, t->args.n++, arg);
 }
 
 static void
@@ -80,10 +80,10 @@ setargv0(int tool, char *arg)
 {
        struct tool *t = &tools[tool];
 
-       if (t->nargs > 0)
-               t->args[0] = arg;
+       if (t->args.n > 0)
+               t->args.s[0] = arg;
        else
-               t->args = newitem(t->args, t->nargs++, arg);
+               t->args.s = newitem(t->args.s, t->args.n++, arg);
 }
 
 static int
@@ -126,7 +126,7 @@ inittool(int tool)
        }
 
        setargv0(tool, t->bin);
-       t->nparams = t->nargs;
+       t->nparams = t->args.n;
        t->init = 1;
 
        return tool;
@@ -239,7 +239,7 @@ spawn(int tool)
                        dup2(t->out, 1);
                if (t->in > -1)
                        dup2(t->in, 0);
-               execvp(t->cmd, t->args);
+               execvp(t->cmd, t->args.s);
                fprintf(stderr, "scc: execvp %s: %s\n",
                        t->cmd, strerror(errno));
                _exit(1);
@@ -289,9 +289,9 @@ validatetools(void)
                        }
                        if (tool >= failed && t->outfile)
                                unlink(t->outfile);
-                       for (i = t->nparams; i < t->nargs; ++i)
-                               free(t->args[i]);
-                       t->nargs = t->nparams;
+                       for (i = t->nparams; i < t->args.n; ++i)
+                               free(t->args.s[i]);
+                       t->args.n = t->nparams;
                        t->pid = 0;
                }
        }

Reply via email to