1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
|
/*
\funcref{fun\_exec}{void fun\_exec ()}
{}
{}
{xstrdup(), getexecarg(), execmd(), xrealloc()}
{fun\_print()}
{funexec.c}
{
This function is called when an {\em op\_exec} opcode is encountered
in the binary makefile. At this point, the stack is expected to hold
the following information:
\begin{itemize}
\item The last pushed value ({\em stack[sp]} holds the number of
arguments to the original {\em exec()} statement.
\item The value pushed before that ({\em stack [sp-1]}) holds the
execution mode: 0 = checked, !0 = not checked. When the execution
mode is checked, any exit status which is non-zero leads to an
error.
\item The value pushed before that ({\em stack [sp-2]}) holds the
command to execute; a string.
\item Other pushed values are the remaining arguments.
\end{itemize}
{\em fun\_exec()} initializes an array of command strings and
retrieves arguments. When the length of the command list is about to
exceed {\em MAXCMDLEN} (see {\em icm.h}), the command is flushed by
calling {\em execmd()}.
}
*/
#include "icm-exec.h"
static char **initcmd (cmd)
char **cmd;
{
register int
i;
if (cmd)
for (i = 0; cmd [i]; i++)
xrealloc (cmd [i], 0);
xrealloc (cmd, 0);
cmd = xrealloc (NULL, 3 * sizeof (char *));
cmd [0] = xstrdup (stack [sp - 2].vu.i->ls.str);
if (strlen (cmdhead))
{
cmd [1] = xstrdup (cmdhead);
cmd [2] = NULL;
}
else
cmd [1] = NULL;
return (cmd);
}
void fun_exec ()
{
register int
i,
nargs,
mode,
nextarglen,
cmdlen,
getnewarg;
int
newelement;
register char
*nextarg = NULL,
**cmd;
nargs = stack [sp].vu.intval;
mode = stack [sp - 1].vu.intval;
cmd = initcmd (NULL);
i = 3;
getnewarg = 1;
while (i <= nargs)
{
if (getnewarg)
nextarg = getexecarg (i, &newelement);
else
getnewarg = 1;
nextarglen = strlen (nextarg);
cmdlen = getcmdlen (cmd);
if (cmdlen + nextarglen + strlen (cmdtail) >= MAXCMDLEN)
{
cmd = execmd (cmd, mode);
cmd = initcmd (cmd);
getnewarg = 0;
}
else
{
cmd = addcmd (cmd, nextarg);
i += newelement;
xrealloc (nextarg, 0);
}
}
cmd = execmd (cmd, mode);
for (i = 0; cmd [i]; i++)
xrealloc (cmd [i], 0);
xrealloc (cmd, 0);
}
|