home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_100 / 143_01 / tee.c < prev   
Text File  |  1985-11-14  |  1KB  |  59 lines

  1. /*
  2. %CC1 $1.C -X -E5000
  3. %CLINK $1 DIO  -S
  4. %DELETE    $1.CRL 
  5. */
  6. /*********************************************************************
  7. *                TEE                     *
  8. **********************************************************************
  9. *           COPYRIGHT 1983 EUGENE H. MALLORY             *
  10. *********************************************************************/
  11. #include "BDSCIO.H"
  12. #include "DIO.H"
  13.     
  14. char *version;
  15.     
  16. main(argc,argv)
  17.  
  18. int argc;
  19. char **argv;
  20.  
  21. BEGIN
  22.  
  23. int fid,c;
  24. char fcb[BUFSIZ],teeflag,fname[MAXLINE];
  25.  
  26.     dioinit(&argc,argv); /* INITIALIZE DIO BUFFERS AND FLAGS */
  27.     version = "Version 3.0";
  28.     
  29.     if (argc >=    2)
  30.     BEGIN
  31.         strcpy(fname,*++argv);
  32.         teeflag = TRUE;
  33.         fid    = fcreat(fname,fcb);
  34.         if (fid <= 0)
  35.         BEGIN
  36.             error("TEE:    Unable to create file \'%s\'.",fname);
  37.         END
  38.     END
  39.     else
  40.     BEGIN
  41.         teeflag = FALSE;
  42.     END
  43.  
  44.     while ((c=getchar()) != EOF) 
  45.     BEGIN
  46.         putchar(c);
  47.         if (teeflag) 
  48.         BEGIN
  49.         if (c == '\n') putc('\r',fcb);
  50.         putc(c,fcb);
  51.         END
  52.     END
  53.     putc(CPMEOF,fcb);
  54.     fflush(fcb);
  55.     fclose(fcb);
  56.     dioflush();
  57.     exit(0);
  58. END
  59.