home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 21 / CD_ASCQ_21_040595.iso / dos / prg / c / freedos3 / source / jh_utils / tee.c < prev    next >
C/C++ Source or Header  |  1995-01-07  |  2KB  |  76 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. /***********************************************************************
  18.  * This program saves a copy of its input to a file and prints a copy to
  19.  * the standard output.
  20.  *
  21.  * Author: James Hall
  22.  */
  23.  
  24. #include <stdio.h>
  25. #include "getopt.h"
  26. #include "freedos.h"
  27.  
  28.  
  29. void usage (void);
  30.  
  31.  
  32. main (int argc, char **argv)
  33. {
  34.   int i;
  35.   char ch;
  36.   FILE *pFile;
  37.  
  38.   /* Check the command line */
  39.  
  40.   while ((i = getopt (argc, argv, "?")) != EOF)
  41.     {
  42.       switch (i)
  43.     {
  44.     default:
  45.       usage ();
  46.       break;
  47.     }
  48.     }
  49.  
  50.   if (argc != 2)
  51.     {
  52.       usage ();
  53.     }
  54.  
  55.   /* Open the output file */
  56.  
  57.   if ((pFile = fopen (argv[1], "w")) == NULL)
  58.     {
  59.       fprintf (stderr, "Cannot open output file %s\n", argv[1]);
  60.       exit (2);
  61.     }
  62.  
  63.   /* Tee the input */
  64.  
  65.   outtee (stdin, pFile, stdout);
  66.   exit (0);
  67. }
  68.  
  69. void 
  70. usage (void)
  71. {
  72.   printp ("TEE", "Saves a copy of its input to a file and prints it.");
  73.   printu ("TEE", "file");
  74.   exit (1);
  75. }
  76.