Reformat.
This commit is contained in:
parent
d48e7399ee
commit
e43905afeb
195
util/ack/run.c
195
util/ack/run.c
|
@ -17,58 +17,71 @@
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
|
||||||
#ifndef NORCSID
|
#ifndef NORCSID
|
||||||
static char rcs_id[] = "$Id$" ;
|
static char rcs_id[] = "$Id$";
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define ARG_MORE 40 /* The size of args chunks to allocate */
|
#define ARG_MORE 40 /* The size of args chunks to allocate */
|
||||||
|
|
||||||
static int run_exec(trf *, const char *);
|
static int run_exec(trf*, const char*);
|
||||||
static void x_arg(char *);
|
static void x_arg(char*);
|
||||||
|
|
||||||
static char **arglist ; /* The first argument */
|
static char** arglist; /* The first argument */
|
||||||
static unsigned argcount ; /* The current number of arguments */
|
static unsigned argcount; /* The current number of arguments */
|
||||||
static unsigned argmax; /* The maximum number of arguments so far */
|
static unsigned argmax; /* The maximum number of arguments so far */
|
||||||
|
|
||||||
int runphase(trf *phase) {
|
int runphase(trf* phase)
|
||||||
register list_elem *elem ;
|
{
|
||||||
char *prog ; int result ;
|
register list_elem* elem;
|
||||||
|
char* prog;
|
||||||
|
int result;
|
||||||
|
|
||||||
prog=phase->t_prog ;
|
prog = phase->t_prog;
|
||||||
if ( v_flag || debug ) {
|
if (v_flag || debug)
|
||||||
if ( v_flag==1 && !debug ) {
|
{
|
||||||
vprint("%s",phase->t_name) ;
|
if (v_flag == 1 && !debug)
|
||||||
if ( !phase->t_combine ) {
|
{
|
||||||
vprint(" %s%s\n",p_basename,
|
vprint("%s", phase->t_name);
|
||||||
strrchr(in.p_path,SUFCHAR) ) ;
|
if (!phase->t_combine)
|
||||||
} else {
|
{
|
||||||
scanlist(l_first(phase->t_inputs), elem) {
|
vprint(" %s%s\n", p_basename, strrchr(in.p_path, SUFCHAR));
|
||||||
vprint(" %s",p_cont(*elem)->p_path);
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
scanlist(l_first(phase->t_inputs), elem)
|
||||||
|
{
|
||||||
|
vprint(" %s", p_cont(*elem)->p_path);
|
||||||
}
|
}
|
||||||
vprint("\n") ;
|
vprint("\n");
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
/* list all args */
|
/* list all args */
|
||||||
vprint("%s",prog) ;
|
vprint("%s", prog);
|
||||||
scanlist(l_first(phase->t_flags), elem) {
|
scanlist(l_first(phase->t_flags), elem)
|
||||||
vprint(" %s",l_content(*elem)) ;
|
{
|
||||||
|
vprint(" %s", l_content(*elem));
|
||||||
}
|
}
|
||||||
scanlist(l_first(phase->t_args), elem) {
|
scanlist(l_first(phase->t_args), elem)
|
||||||
vprint(" %s",l_content(*elem)) ;
|
{
|
||||||
|
vprint(" %s", l_content(*elem));
|
||||||
}
|
}
|
||||||
vprint("\n") ;
|
vprint("\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
argcount=0 ;
|
argcount = 0;
|
||||||
x_arg(phase->t_name) ;
|
x_arg(phase->t_name);
|
||||||
scanlist(l_first(phase->t_flags), elem) {
|
scanlist(l_first(phase->t_flags), elem)
|
||||||
x_arg(l_content(*elem)) ;
|
{
|
||||||
|
x_arg(l_content(*elem));
|
||||||
}
|
}
|
||||||
scanlist(l_first(phase->t_args), elem) {
|
scanlist(l_first(phase->t_args), elem)
|
||||||
x_arg(l_content(*elem)) ;
|
{
|
||||||
|
x_arg(l_content(*elem));
|
||||||
}
|
}
|
||||||
x_arg( (char *)0 ) ;
|
x_arg((char*)0);
|
||||||
result=run_exec(phase,prog) ;
|
result = run_exec(phase, prog);
|
||||||
return result ;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
static char* build_command_line(const char* prog)
|
static char* build_command_line(const char* prog)
|
||||||
|
@ -76,8 +89,8 @@ static char* build_command_line(const char* prog)
|
||||||
/* Calculate the maximum length of the command line. */
|
/* Calculate the maximum length of the command line. */
|
||||||
|
|
||||||
int len = strlen(prog);
|
int len = strlen(prog);
|
||||||
for (int i=1; i<(argcount-1); i++)
|
for (int i = 1; i < (argcount - 1); i++)
|
||||||
len += strlen(arglist[i])*2 + 1;
|
len += strlen(arglist[i]) * 2 + 1;
|
||||||
|
|
||||||
/* Now actually build the command line. */
|
/* Now actually build the command line. */
|
||||||
|
|
||||||
|
@ -85,7 +98,7 @@ static char* build_command_line(const char* prog)
|
||||||
strcpy(cmdline, prog);
|
strcpy(cmdline, prog);
|
||||||
char* p = cmdline + strlen(prog);
|
char* p = cmdline + strlen(prog);
|
||||||
|
|
||||||
for (int i=1; i<(argcount-1); i++)
|
for (int i = 1; i < (argcount - 1); i++)
|
||||||
{
|
{
|
||||||
const char* word = arglist[i];
|
const char* word = arglist[i];
|
||||||
*p++ = ' ';
|
*p++ = ' ';
|
||||||
|
@ -105,37 +118,44 @@ static char* build_command_line(const char* prog)
|
||||||
return cmdline;
|
return cmdline;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int run_exec(trf *phase, const char *prog) {
|
static int run_exec(trf* phase, const char* prog)
|
||||||
int status, child, waitchild ;
|
{
|
||||||
|
int status, child, waitchild;
|
||||||
int oldstdin = -1;
|
int oldstdin = -1;
|
||||||
int oldstdout = -1;
|
int oldstdout = -1;
|
||||||
|
|
||||||
fflush(stdout) ;
|
fflush(stdout);
|
||||||
fflush(stderr) ;
|
fflush(stderr);
|
||||||
|
|
||||||
if ( phase->t_stdin ) {
|
if (phase->t_stdin)
|
||||||
|
{
|
||||||
if (!in.p_path)
|
if (!in.p_path)
|
||||||
fatal("no input file for %s",phase->t_name) ;
|
fatal("no input file for %s", phase->t_name);
|
||||||
|
|
||||||
oldstdin = dup(0);
|
oldstdin = dup(0);
|
||||||
close(0) ;
|
close(0);
|
||||||
if (open(in.p_path,0)!=0) {
|
if (open(in.p_path, 0) != 0)
|
||||||
error("cannot open %s",in.p_path) ;
|
{
|
||||||
exit(1) ;
|
error("cannot open %s", in.p_path);
|
||||||
|
exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( phase->t_stdout ) {
|
if (phase->t_stdout)
|
||||||
if ( !out.p_path ) {
|
{
|
||||||
fatal("no output file for %s",phase->t_name) ;
|
if (!out.p_path)
|
||||||
|
{
|
||||||
|
fatal("no output file for %s", phase->t_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
oldstdout = dup(1);
|
oldstdout = dup(1);
|
||||||
close(1) ;
|
close(1);
|
||||||
if ( creat(out.p_path,0666)!=1 ) {
|
if (creat(out.p_path, 0666) != 1)
|
||||||
close(1); dup(2);
|
{
|
||||||
error("cannot create %s",out.p_path) ;
|
close(1);
|
||||||
exit(1) ;
|
dup(2);
|
||||||
|
error("cannot create %s", out.p_path);
|
||||||
|
exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -143,52 +163,59 @@ static int run_exec(trf *phase, const char *prog) {
|
||||||
status = system(cmdline);
|
status = system(cmdline);
|
||||||
free(cmdline);
|
free(cmdline);
|
||||||
|
|
||||||
if ( oldstdin != -1 ) {
|
if (oldstdin != -1)
|
||||||
|
{
|
||||||
close(0);
|
close(0);
|
||||||
dup2(oldstdin, 0);
|
dup2(oldstdin, 0);
|
||||||
close(oldstdin);
|
close(oldstdin);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( oldstdout != -1 ) {
|
if (oldstdout != -1)
|
||||||
|
{
|
||||||
close(1);
|
close(1);
|
||||||
dup2(oldstdout, 1);
|
dup2(oldstdout, 1);
|
||||||
close(oldstdout);
|
close(oldstdout);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( status ) {
|
if (status)
|
||||||
switch ( status&0177 ) {
|
{
|
||||||
case 0 :
|
switch (status & 0177)
|
||||||
break ;
|
{
|
||||||
case SIGHUP:
|
case 0:
|
||||||
case SIGINT:
|
break;
|
||||||
case SIGQUIT:
|
case SIGHUP:
|
||||||
case SIGTERM:
|
case SIGINT:
|
||||||
quit(-5) ;
|
case SIGQUIT:
|
||||||
default:
|
case SIGTERM:
|
||||||
error("%s died with signal %d",
|
quit(-5);
|
||||||
prog,status&0177) ;
|
default:
|
||||||
|
error("%s died with signal %d", prog, status & 0177);
|
||||||
}
|
}
|
||||||
/* The assumption is that processes voluntarely
|
/* The assumption is that processes voluntarely
|
||||||
dying with a non-zero status already produced
|
dying with a non-zero status already produced
|
||||||
some sort of error message to the outside world.
|
some sort of error message to the outside world.
|
||||||
*/
|
*/
|
||||||
n_error++ ;
|
n_error++;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return 1 ;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void x_arg(char *string) {
|
static void x_arg(char* string)
|
||||||
|
{
|
||||||
/* Add one execute argument to the argument vector */
|
/* Add one execute argument to the argument vector */
|
||||||
if ( argcount==argmax ) {
|
if (argcount == argmax)
|
||||||
if ( argmax==0 ) {
|
{
|
||||||
argmax= 2*ARG_MORE ;
|
if (argmax == 0)
|
||||||
arglist= (char **)getcore(argmax*sizeof (char *)) ;
|
{
|
||||||
} else {
|
argmax = 2 * ARG_MORE;
|
||||||
argmax += ARG_MORE ;
|
arglist = (char**)getcore(argmax * sizeof(char*));
|
||||||
arglist= (char **)changecore((char *)arglist,
|
}
|
||||||
argmax*sizeof (char *)) ;
|
else
|
||||||
|
{
|
||||||
|
argmax += ARG_MORE;
|
||||||
|
arglist = (char**)changecore((char*)arglist, argmax * sizeof(char*));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*(arglist+argcount++) = string ;
|
*(arglist + argcount++) = string;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue