geoff@callan.UUCP (Geoff Kuenning) (08/25/84)
: This is a shar archive. Extract with sh, not csh. : The rest of this file will extract: : README tee.c echo extracting - README sed 's/^X//' > README << '/*EOF' X Oops. Nothing like saying you are posting something and then forgetting X to include it to make you feel stupid. Here's my promised public-domain X version of 'tee', which uses 'fcopen' instead of 'fopen'. X X Geoff Kuenning X Callan Data Systems X ...!ihnp4!wlbr!callan!geoff /*EOF echo extracting - tee.c sed 's/^X//' > tee.c << '/*EOF' Xstatic char Sccs_Id[] = "@(#)mytee.c 1.3 3/23/84 00:09:49"; X X#include <stdio.h> X Xextern FILE * fcopen (); /* Open a file or a command */ X Xint main ( /* Tee, but using fcopen () */ X argc, /* Argument count */ X argv) /* Argument vector */ X register int argc; /* Argument count */ X register char * argv[]; /* Argument vector */ X { X register int ch; /* Character read from input stream */ X char buf[100]; /* Buffer for error message */ X FILE * files[_NFILE]; /* Array of output streams */ X register int curfile; /* Current file index */ X int nobufs = 0; /* Nonzero to suppress stdio buffers */ X register int numfiles; /* Total number of files open */ X char * opentype = "w"; /* Type of open to do */ X int status; /* Return status from program */ X X/* X Open all files X*/ X if (argc > 1 && *argv[1] == '-') X { X ++argv; X --argc; X while (*++(argv[0])) X if (**argv == 'a') X opentype = "a"; X else if (**argv == 'u') X nobufs = 1; X else X { X fprintf (stderr, "Usage: tee [-au] [files]\n"); X return 1; X } X } X for (numfiles = 0; --argc > 0 && numfiles < _NFILE; ) X { X files[numfiles] = fcopen (*++argv, opentype); X if (files[numfiles] == (FILE *) NULL) X { X sprintf (buf, "tee: Failed to open %s", *argv); X perror (buf); X status = 1; X } X else X { X if (nobufs || isatty (fileno (files[numfiles]))) X setbuf (files[numfiles], (char *) NULL); X numfiles++; X } X } X if (nobufs || isatty (fileno (stdout))) X setbuf (stdout, (char *) NULL); X/* X Copy input to all output files and standard output X*/ X while ((ch = getchar ()) != EOF) X { X for (curfile = 0; curfile < numfiles; curfile++) X putc (ch, files[curfile]); X putc (ch, stdout); X } X for (curfile = 0; curfile < numfiles; curfile++) X status |= fcclose (files[curfile]); X return status; X } /*EOF exit -- Geoff Kuenning Callan Data Systems ...!ihnp4!wlbr!callan!geoff