Reformat.

This commit is contained in:
David Given 2022-07-16 22:33:48 +02:00
parent d48e7399ee
commit e43905afeb

View file

@ -29,30 +29,41 @@ static char **arglist ; /* The first argument */
static unsigned argcount; /* The current number of arguments */
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 ;
char* prog;
int result;
prog = phase->t_prog;
if ( v_flag || debug ) {
if ( v_flag==1 && !debug ) {
if (v_flag || debug)
{
if (v_flag == 1 && !debug)
{
vprint("%s", phase->t_name);
if ( !phase->t_combine ) {
vprint(" %s%s\n",p_basename,
strrchr(in.p_path,SUFCHAR) ) ;
} else {
scanlist(l_first(phase->t_inputs), elem) {
if (!phase->t_combine)
{
vprint(" %s%s\n", p_basename, strrchr(in.p_path, SUFCHAR));
}
else
{
scanlist(l_first(phase->t_inputs), elem)
{
vprint(" %s", p_cont(*elem)->p_path);
}
vprint("\n");
}
} else {
}
else
{
/* list all args */
vprint("%s", prog);
scanlist(l_first(phase->t_flags), elem) {
scanlist(l_first(phase->t_flags), 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("\n");
@ -60,10 +71,12 @@ int runphase(trf *phase) {
}
argcount = 0;
x_arg(phase->t_name);
scanlist(l_first(phase->t_flags), elem) {
scanlist(l_first(phase->t_flags), 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((char*)0);
@ -105,7 +118,8 @@ static char* build_command_line(const char* prog)
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 oldstdin = -1;
int oldstdout = -1;
@ -113,27 +127,33 @@ static int run_exec(trf *phase, const char *prog) {
fflush(stdout);
fflush(stderr);
if ( phase->t_stdin ) {
if (phase->t_stdin)
{
if (!in.p_path)
fatal("no input file for %s", phase->t_name);
oldstdin = dup(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);
}
}
if ( phase->t_stdout ) {
if ( !out.p_path ) {
if (phase->t_stdout)
{
if (!out.p_path)
{
fatal("no output file for %s", phase->t_name);
}
oldstdout = dup(1);
close(1);
if ( creat(out.p_path,0666)!=1 ) {
close(1); dup(2);
if (creat(out.p_path, 0666) != 1)
{
close(1);
dup(2);
error("cannot create %s", out.p_path);
exit(1);
}
@ -143,20 +163,24 @@ static int run_exec(trf *phase, const char *prog) {
status = system(cmdline);
free(cmdline);
if ( oldstdin != -1 ) {
if (oldstdin != -1)
{
close(0);
dup2(oldstdin, 0);
close(oldstdin);
}
if ( oldstdout != -1 ) {
if (oldstdout != -1)
{
close(1);
dup2(oldstdout, 1);
close(oldstdout);
}
if ( status ) {
switch ( status&0177 ) {
if (status)
{
switch (status & 0177)
{
case 0:
break;
case SIGHUP:
@ -165,8 +189,7 @@ static int run_exec(trf *phase, const char *prog) {
case SIGTERM:
quit(-5);
default:
error("%s died with signal %d",
prog,status&0177) ;
error("%s died with signal %d", prog, status & 0177);
}
/* The assumption is that processes voluntarely
dying with a non-zero status already produced
@ -178,16 +201,20 @@ static int run_exec(trf *phase, const char *prog) {
return 1;
}
static void x_arg(char *string) {
static void x_arg(char* string)
{
/* Add one execute argument to the argument vector */
if ( argcount==argmax ) {
if ( argmax==0 ) {
if (argcount == argmax)
{
if (argmax == 0)
{
argmax = 2 * ARG_MORE;
arglist = (char**)getcore(argmax * sizeof(char*));
} else {
}
else
{
argmax += ARG_MORE;
arglist= (char **)changecore((char *)arglist,
argmax*sizeof (char *)) ;
arglist = (char**)changecore((char*)arglist, argmax * sizeof(char*));
}
}
*(arglist + argcount++) = string;