|
|
1.1 ! root 1: ! 2: /* ! 3: swcoup( oupptr ) switches between 2 output files: the ! 4: standard output file provided by the shell and the optional ! 5: output file provided by the -o option. ! 6: ! 7: the switching is as follows: ! 8: ! 9: program listing, compilation statisitics, execution statistics, ! 10: and dump of variables at termination go to the -o file, if ! 11: specified. ! 12: ! 13: standard output produced by the executing program goes to the ! 14: standard output file provided by the shell. ! 15: */ ! 16: ! 17: int swcoup( oupptr ) ! 18: char *oupptr; ! 19: ! 20: { ! 21: static int errflag = 0, ! 22: origoup = 0, ! 23: state = 0; ! 24: int fd,retval; ! 25: ! 26: retval = 0; ! 27: if (oupptr == 0) ! 28: return 0; ! 29: ! 30: if (errflag != 0) ! 31: return 0; ! 32: ! 33: switch ( state ) { ! 34: ! 35: /* 1st switch: standard output -> -o file */ ! 36: ! 37: case 0: origoup = dup( 1 ); ! 38: close( 1 ); ! 39: fd = creat( oupptr,0666 ); ! 40: if ( fd < 0 ) { ! 41: write( 2,"-o file open error\n",19 ); ! 42: ++errflag; ! 43: fd = dup( origoup ); ! 44: close( origoup ); ! 45: retval = -1; ! 46: } ! 47: break; ! 48: ! 49: /* 2nd switch: standard output -> shell output file */ ! 50: ! 51: case 1: close( 1 ); ! 52: fd = dup( origoup ); ! 53: close( origoup ); ! 54: break; ! 55: ! 56: /* 3rd switch: standard output -> -o file */ ! 57: ! 58: case 2: close( 1 ); ! 59: fd = open( oupptr,1 ); ! 60: if ( fd < 0 ) { ! 61: write( 2,"error reopening\n",16 ); ! 62: } ! 63: lseek( 1,0,2 ); ! 64: break; ! 65: ! 66: default: ! 67: write( 2,"swcinp too many times\n",22 ); ! 68: } ! 69: ++state; ! 70: return retval; ! 71: } ! 72:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.