|
|
1.1 root 1:
2: /*
3: swcinp( filecnt,fileptr ) is responsible for switching between
4: input files for standard input. filecnt is the number of
5: input filnames specified on the command line and fileptr is
6: points to an array of character pointers.
7:
8: all files on the command line are read before the standard
9: input provided by the shell. after all input is exhausted
10: a -1 is returned to indicate EOF.
11: */
12:
13: int swcinp( filecnt,fileptr )
14: int filecnt;
15: char *fileptr[];
16:
17: {
18: static int curfile = -1,
19: originp = 0;
20: register int fd;
21:
22: if (filecnt == 0) {
23: if (originp == 0) {
24: --originp;
25: fd = 0;
26: } else {
27: fd = -1;
28: }
29: } else {
30: if (originp == -1)
31: return originp;
32: if (originp == 0)
33: originp = dup( 0 );
34: close( 0 );
35: fd = -1;
36: if (curfile < filecnt - 1) {
37: do {
38: fd = open( fileptr[++curfile],0 );
39: if (fd != 0) {
40: register int len = 0;
41: write( 2,"can't open ",11 );
42: while ( fileptr[curfile][len] != '\0' )
43: len++;
44: write( 2,fileptr[curfile],len );
45: write( 2,"\n",1 );
46: }
47: } while ( fd != 0 && curfile < filecnt - 1 );
48: }
49: if ( curfile == filecnt - 1 && fd != 0 ) {
50: if (originp > 0) {
51: fd = dup( originp );
52: close( originp );
53: originp = -1;
54: } else {
55: fd = -1;
56: }
57: }
58: }
59:
60: return fd;
61: }
62:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.