Annotation of researchv10no/cmd/tee.c, revision 1.1.1.1

1.1       root        1: /*
                      2:  * tee-- pipe fitting
                      3:  */
                      4: 
                      5: #include       <signal.h>
                      6: int    aflag;
                      7: int    openf[100];
                      8: 
                      9: char in[512];
                     10: 
                     11: 
                     12: main(argc,argv)
                     13: char *argv[];
                     14: {
                     15:        register i, j;
                     16:        int r, n;
                     17: 
                     18:        while(argc > 1 && argv[1][0] == '-') {
                     19:                switch(argv[1][1]) {
                     20:                case 'a':
                     21:                        aflag++;
                     22:                        break;
                     23: 
                     24:                case 'i':
                     25:                        signal(SIGINT, SIG_IGN);
                     26:                        break;
                     27: 
                     28:                }
                     29:                argv++;
                     30:                argc--;
                     31:        }
                     32: 
                     33:        n = 0;
                     34:        while(argc-- > 1) {
                     35:                if(aflag) {
                     36:                        openf[n] = open(argv[1], 1);
                     37:                        if(openf[n] < 0)
                     38:                                openf[n] = creat(argv[1], 0666);
                     39:                        lseek(openf[n], 0L, 2);
                     40:                } else
                     41:                        openf[n] = creat(argv[1], 0666);
                     42:                if(openf[n] < 0) {
                     43:                        puts("tee: cannot open ");
                     44:                        puts(argv[1]);
                     45:                        puts("\n");
                     46:                } else
                     47:                        n++;
                     48:                argv++;
                     49:        }
                     50:        openf[n++] = 1;
                     51: 
                     52:        for(;;) {
                     53:                r = read(0, in, 512);
                     54:                if(r <= 0)
                     55:                        exit(0);
                     56:                for(i=0; i<n; i++)
                     57:                        write(openf[i], in, r);
                     58:        }
                     59: }
                     60: 
                     61: puts(s)
                     62: char *s;
                     63: {
                     64:        while(*s)
                     65:                write(2, s++, 1);
                     66: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.