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:
9: main(argc, argv)
10: int argc;
11: char *argv[];
12: {
13: int i, j, k;
14: FILE *mf;
15:
16: if (argc != 3) {
17: fprintf(stderr, "Usage: maketape tapedrive makefile\n");
18: exit(0);
19: }
20: if ((mt = creat(argv[1], 0666)) < 0) {
21: perror(argv[1]);
22: exit(1);
23: }
24: if ((mf = fopen(argv[2], "r")) == NULL) {
25: perror(argv[2]);
26: exit(2);
27: }
28:
29: j = 0;
30: k = 0;
31: for (;;) {
32: if ((i = fscanf(mf, "%s %d", name, &blksz))== EOF)
33: exit(0);
34: if (i != 2) {
35: fprintf(stderr, "Help! Scanf didn't read 2 things (%d)\n", i);
36: exit(1);
37: }
38: if (blksz <= 0 || blksz > MAXB) {
39: fprintf(stderr, "Block size %d is invalid\n", blksz);
40: continue;
41: }
42: if (strcmp(name, "*") == 0) {
43: close(mt);
44: mt = open(argv[1], 2);
45: j = 0;
46: k++;
47: continue;
48: }
49: fd = open(name, 0);
50: if (fd < 0) {
51: perror(name);
52: continue;
53: }
54: printf("%s: block %d, file %d\n", name, j, k);
55: while (read(fd, buf, 512*blksz) > 0) {
56: j++;
57: write(mt, buf, 512*blksz);
58: }
59: }
60: }
Defined functions
main
defined in line
9;
never used
Defined variables
blksz
defined in line
7; used 6 times
buf
defined in line
5; used 2 times
fd
defined in line
4; used 3 times
mt
defined in line
3; used 4 times
name
defined in line
6; used 5 times
Defined macros
MAXB
defined in line
2; used 2 times