home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / TOOLS2.ZIP / TEE.C < prev    next >
C/C++ Source or Header  |  1988-03-22  |  1KB  |  59 lines

  1. /*
  2.     HEADER:        CUG000.00;
  3.     TITLE:        Portable TEE;
  4.     DATE:        05/23/87;
  5.     DESCRIPTION:    "Copies stdin to the specified file without changing
  6.             stdout.";
  7.     KEYWORDS:    Software tools, Text filters,tee, pipes;
  8.     FILENAME:    TEE.C;
  9.     WARNINGS:    "The author claims copyrights and authorizes
  10.             non-commercial use only.";
  11.     AUTHORS:    Michael M. Yokoyama;
  12.     COMPILERS:    vanilla;
  13. */
  14.  
  15. #include <stdio.h>
  16.  
  17. /*
  18.  * Portability Note:  The AZTEC C compilers handle the binary/text file
  19.  * dichotomy differently from most other compilers.  Uncomment the following
  20.  * #define if you are running AZTEC C:
  21.  */
  22.  
  23. /*
  24. #define putc(c,f)    aputc(c,f)
  25. */
  26.  
  27. #ifndef TRUE
  28. #define TRUE  1
  29. #endif
  30.  
  31. #ifndef FALSE
  32. #define FALSE 0
  33. #endif
  34.  
  35. int main(argc, argv)
  36. int argc;
  37. char *argv[];
  38. {
  39.     int cin, correct;
  40.     FILE *fout;
  41.  
  42.     correct = FALSE;
  43.     if (argc == 2) {
  44.         if ((fout = fopen(argv[1], "w")) == NULL) {
  45.             fprintf(stderr,"TEE:  cannot create %s\n", argv[1]);
  46.             return !0;
  47.         }
  48.         correct = TRUE;
  49.     }
  50.     else fprintf(stderr,"TEE Usage:  tee out_file\n");
  51.  
  52.     while ((cin = getchar()) != EOF) {
  53.         putchar(cin);
  54.         if (correct) putc(cin, fout);
  55.     }
  56.     if (correct) fclose(fout);
  57.     return !correct;
  58. }
  59.