home *** CD-ROM | disk | FTP | other *** search
/ minnie.tuhs.org / unixen.tar / unixen / PDP-11 / Trees / V7 / usr / src / cmd / standalone / mymktape.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-02-03  |  1.5 KB  |  80 lines

  1. /* A modified version of /usr/src/cmd/standalone/maketape.c
  2.  * which runs under 32-bit little-endian UNIXes (e.g FreeBSD, Linux)
  3.  * and which produces tape images suitable for Bob Supnik's emulator
  4.  * or Ersatz 2.0
  5.  */
  6.  
  7. #include <stdio.h>
  8. #include <fcntl.h>
  9.  
  10.  
  11. #define MAXB 30
  12. int mt;
  13. int fd;
  14. char    buf[MAXB*512];
  15. char    name[50];
  16. int    blksz;
  17.  
  18. main(argc, argv)
  19. int    argc;
  20. char    *argv[];
  21. {
  22.     int i, j, k, size, end=0;
  23.     FILE *mf;
  24.  
  25.     if (argc != 3) {
  26.         fprintf(stderr, "Usage: maketape tapedrive makefile\n");
  27.         exit(0);
  28.     }
  29.     if ((mt = creat(argv[1], 0666)) < 0) {
  30.         perror(argv[1]);
  31.         exit(1);
  32.     }
  33.     if ((mf = fopen(argv[2], "r")) == NULL) {
  34.         perror(argv[2]);
  35.         exit(2);
  36.     }
  37.  
  38.     j = 0;
  39.     k = 0;
  40.     for (;;) {
  41.         if ((i = fscanf(mf, "%s %d", name, &blksz))== EOF)
  42.             break;
  43.         if (i != 2) {
  44.             fprintf(stderr, "Help! Scanf didn't read 2 things (%d)\n", i);
  45.             exit(1);
  46.         }
  47.         if (blksz <= 0 || blksz > MAXB) {
  48.             fprintf(stderr, "Block size %d is invalid\n", blksz);
  49.             continue;
  50.         }
  51.         if (strcmp(name, "*") == 0) {
  52.             write(mt, &end, 4);
  53.             close(mt);
  54.             mt = open(argv[1], O_WRONLY|O_APPEND);
  55.             j = 0;
  56.             k++;
  57.             continue;
  58.         }
  59.         fd = open(name, O_RDONLY);
  60.         if (fd < 0) {
  61.             perror(name);
  62.             continue;
  63.         }
  64.         printf("%s: block %d, file %d\n", name, j, k);
  65.  
  66.         size= 512*blksz;
  67.         while ((i=read(fd, buf, 512*blksz)) > 0) {
  68.             j++;
  69.             /* Write 32-bit size out as tape marker */
  70.             write(mt, &size, 4);
  71.             write(mt, buf, 512*blksz);
  72.             /* Write 32-bit size out as tape marker */
  73.             write(mt, &size, 4);
  74.         }
  75.     }
  76.     write(mt, &end, 4);
  77.     write(mt, &end, 4);
  78.     exit(0);
  79. }
  80.