home *** CD-ROM | disk | FTP | other *** search
/ minnie.tuhs.org / unixen.tar / unixen / PDP-11 / Distributions / dec / Ultrix-3.0 / wat.c < prev    next >
C/C++ Source or Header  |  1991-11-08  |  2KB  |  95 lines

  1. #include <stdio.h>
  2.  
  3. #include <sys/types.h>
  4. #include <sys/ioctl.h>
  5. #include <sys/mtio.h>
  6. #include <sys/dir.h>
  7.  
  8. main (argc,argv)
  9.   int argc ;
  10.   char ** argv ;
  11. {
  12.     register int fd, bytes ;
  13.     FILE * lfd, * dfd ;
  14.     char * buffer ;
  15.     char line[256] ;
  16.     struct mtop mt_command;
  17.     extern char * malloc() ;
  18.  
  19.     if ( argc != 3 )
  20.     {
  21.         fprintf (stderr,"Usage: %s log-file dump-file\n",argv[0]) ;
  22.         exit (1) ;
  23.     }
  24.  
  25.     buffer = malloc (65535) ;
  26.  
  27.     if ( ( fd = open ("/dev/rmt1600a",1) ) < 0 )
  28.     {
  29.         fprintf (stderr,"%s: can't open tape unit /dev/rmt1600a\n",
  30.             argv[0]) ;
  31.         exit (1) ;
  32.     }
  33.  
  34.     if ( ( lfd = fopen (argv[1],"r") ) == NULL )
  35.     {
  36.         perror (argv[1]) ;
  37.         exit (1) ;
  38.     }
  39.  
  40.     if ( ( dfd = fopen (argv[2],"r") ) == NULL )
  41.     {
  42.         perror (argv[2]) ;
  43.         exit (1) ;
  44.     }
  45.  
  46.     while ( fgets (line,sizeof(line),lfd) != NULL )
  47.     {
  48.         if ( strncmp (line,"EOF",3) == 0 )
  49.         {
  50.             mt_command.mt_op = MTWEOF ;
  51.             mt_command.mt_count = 1 ;
  52.  
  53.             if ( ioctl (fd,MTIOCTOP,&mt_command) != 0 )
  54.                 fprintf (stderr,"tape EOF problem?\n") ;
  55.  
  56.             fprintf (stderr,"\n end of file.\n") ;
  57.         }
  58.         else if ( strncmp (line,"EOT",3) == 0 )
  59.         {
  60.             fprintf (stderr,"End of Tape.\n") ;
  61.             break ;
  62.         }
  63.         else
  64.         {
  65.             bytes = atoi (line) ;
  66.  
  67.             if ( bytes <= 0 || (bytes%512) != 0 )
  68.             {
  69.                 fprintf (stderr,"bogus write line?\n") ;
  70.                 break ;
  71.             }
  72.  
  73.             if ( fread (buffer,1,bytes,dfd) != bytes )
  74.             {
  75.                 fprintf (stderr,"bad read chunk?\n") ;
  76.                 break ;
  77.             }
  78.  
  79.             if ( write (fd,buffer,bytes) != bytes )
  80.             {
  81.                 fprintf (stderr,"tape write error?\n") ;
  82.                 break ;
  83.             }
  84.  
  85.             fprintf (stderr,".") ;
  86.         }
  87.     }
  88.  
  89.     (void) close (fd) ;
  90.     (void) fclose (lfd) ;
  91.     (void) fclose (dfd) ;
  92.  
  93.     exit (0) ;
  94. }
  95.