1: #include <stdio.h>
2: #define MAXB 30
3: int mt;
4: int fd;
5: char buf[MAXB*512];
6: char name[50];
7: int blksz;
8: int cnt,ii;
9:
10: main(argc, argv)
11: int argc;
12: char *argv[];
13: {
14: int i, j, k;
15: FILE *mf;
16:
17: if (argc != 3) {
18: fprintf(stderr, "Usage: maketape tapedrive makefile\n");
19: exit(0);
20: }
21: if ((mt = creat(argv[1], 0666)) < 0) {
22: perror(argv[1]);
23: exit(1);
24: }
25: if ((mf = fopen(argv[2], "r")) == NULL) {
26: perror(argv[2]);
27: exit(2);
28: }
29:
30: j = 0;
31: k = 0;
32: for (;;) {
33: if ((i = fscanf(mf, "%s %d", name, &blksz))== EOF)
34: exit(0);
35: if (i != 2) {
36: fprintf(stderr, "Help! Scanf didn't read 2 things (%d)\n", i);
37: exit(1);
38: }
39: if (blksz <= 0 || blksz > MAXB) {
40: fprintf(stderr, "Block size %d is invalid\n", blksz);
41: continue;
42: }
43: if (strcmp(name, "*") == 0) {
44: close(mt);
45: sleep(3);
46: mt = open(argv[1], 2);
47: j = 0;
48: k++;
49: continue;
50: }
51: fd = open(name, 0);
52: if (fd < 0) {
53: perror(name);
54: continue;
55: }
56: printf("%s: block %d, file %d\n", name, j, k);
57:
58: /*
59: * wfj fix to final block output.
60: * we pad the last record with nulls
61: * (instead of the bell std. of padding with trash).
62: * this allows you to access text files on the
63: * tape without garbage at the end of the file.
64: * (note that there is no record length associated
65: * with tape files)
66: */
67:
68: while ( (cnt=read(fd, buf, 512*blksz)) == 512*blksz) {
69: j++;
70: write(mt, buf, 512*blksz);
71: }
72: if ( cnt>0)
73: {
74: for(ii=cnt; ii < 512*blksz; ii++)
75: buf[ii] = '\0';
76: write(mt, buf, 512*blksz);
77: }
78: }
79: }
Defined functions
main
defined in line
10;
never used
Defined variables
blksz
defined in line
7; used 9 times
buf
defined in line
5; used 4 times
cnt
defined in line
8; used 9 times
fd
defined in line
4; used 3 times
ii
defined in line
8; used 4 times
mt
defined in line
3; used 5 times
name
defined in line
6; used 5 times
Defined macros
MAXB
defined in line
2; used 2 times