home *** CD-ROM | disk | FTP | other *** search
/ Zodiac Super OZ / MEDIADEPOT.ISO / FILES / 16 / FREEDOS.ZIP / FD_A4PRE.ZIP / SOURCE / MICROC.ZIP / TEE.C < prev    next >
C/C++ Source or Header  |  1994-01-04  |  2KB  |  72 lines

  1. /*
  2.    This program is free software; you can redistribute it and/or modify
  3.    it under the terms of the GNU General Public License as published by
  4.    the Free Software Foundation; either version 2 of the License, or
  5.    (at your option) any later version.
  6.  
  7.    This program is distributed in the hope that it will be useful,
  8.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  9.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  10.    GNU General Public License for more details.
  11.  
  12.    You should have received a copy of the GNU General Public License
  13.    along with this program; if not, write to the Free Software
  14.    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15.    */
  16.  
  17. #include <stdio.h>
  18. #include "freedos.h"
  19. #include "getopt.c"
  20.  
  21. void usage (void);
  22.  
  23. main (int argc, char **argv)
  24.  
  25. {
  26.     int i;
  27.     char ch;
  28.     FILE *fp;
  29.  
  30.     /* Check the command line */
  31.  
  32.     while ((i = getopt (argc, argv, "?", NULL)) != EOF)
  33.         {
  34.         switch (i)
  35.             {
  36.             default:
  37.                 usage ();
  38.                 break;
  39.             }
  40.         }
  41.  
  42.     if (argc != 2)
  43.         usage ();
  44.  
  45.     /* Open the output file */
  46.  
  47.     if ((fp = fopen (argv[1], "w")) == NULL)
  48.         {
  49.         fprintf (stderr, "Cannot open output file %s\n", argv[1]);
  50.         exit (2);
  51.         }
  52.  
  53.     /* Tee the input */
  54.  
  55.     while ((ch = fgetc (stdin)) != EOF)
  56.         {
  57.         fputc (ch, stdout);
  58.         fputc (ch, fp);
  59.         }
  60.  
  61.     fclose (fp);
  62.     exit (0);
  63. }
  64.  
  65. void usage (void)
  66.  
  67.     {
  68.     printp ("TEE", "Saves a copy of its input to a file and to standard output");
  69.     printu ("TEE", "filename");
  70.     exit (1);
  71.     }
  72.