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