/* tee.c - Dual output */ /* Sends output to a file and to stdout */ /* ABZ 13/07/1990 */ #include #define STDERR 2 main(ac,av) unsigned ac; char *av[]; { FILE *f_ptr; unsigned here; unsigned c; char *out; out="a"; here=1; if (av[here][0]=='-') { if (av[here][1]!='w') err_exit(av[0]); /* No options */ out="w"; here++; } if (ac< 2 || ac != here+1) err_exit(av[0]); /* Wrong num. of params */ f_ptr=fopen(av[here],out); if (f_ptr==NULL) { perror(av[here]); /* report error */ exit(1); } while((c=getchar()) != EOF) { putchar(c); putc(c,f_ptr); } fclose(f_ptr); } err_exit(s) char *s; { pr_error("Usage: "); pr_error(s); pr_error(" [-w] \n"); exit(1); } pr_error(s) /* Writes string to error output */ char *s; { write (STDERR,s,strlen(s)); }