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