Commit | Line | Data |
---|---|---|
598b9d8d TL |
1 | #include <signal.h> |
2 | /* Magnetic Tape Manipulation Program | |
3 | ** mtm [-sn] [-lm] [-bp] [unit] | |
4 | ** | |
5 | ** skip n files | |
6 | ** list m files | |
7 | ** buffer size pK bytes | |
8 | ** on unit | |
9 | ** | |
10 | ** Assumes definition of raw magnetic tapes and the | |
11 | ** mapping of 4-7 into physical drives 0-3 | |
12 | */ | |
13 | char *buf; | |
14 | int bcnt; | |
15 | int filecnt; | |
16 | int fd; | |
17 | int unit; | |
18 | char *file ; | |
19 | ||
20 | main(argc,argv) | |
21 | int argc; | |
22 | char *argv[]; | |
23 | { | |
24 | char *p; | |
25 | int nskip, nlist, skip, list; | |
26 | int finis(); | |
27 | ||
28 | signal(SIGINT,finis); | |
29 | signal(SIGQUIT,finis); | |
30 | unit = nskip = nlist = 0; | |
31 | skip = 0; | |
32 | list = 1; | |
33 | bcnt = 2; | |
34 | file = "/dev/rmt0 "; | |
35 | filecnt=1; | |
36 | argv++; | |
37 | ||
38 | while(--argc) { | |
39 | p = *argv++; | |
40 | if(*p == '-'){ | |
41 | ++p; | |
42 | switch(*p){ | |
43 | ||
44 | case 's': | |
45 | skip++; | |
46 | list--; | |
47 | nskip = atoi(++p); | |
48 | break; | |
49 | ||
50 | case 'l': | |
51 | list++; | |
52 | nlist = atoi(++p); | |
53 | break; | |
54 | ||
55 | case 'b': | |
56 | bcnt = atoi(++p); | |
57 | if(bcnt < 30) break; | |
58 | printf("Requested buffer too big %dK\n",bcnt); | |
59 | exit(8); | |
60 | default: | |
61 | printf("Bad option\n"); | |
62 | exit(8); | |
63 | } | |
64 | } | |
65 | else{ | |
66 | ||
67 | if((*p < '0') || (*p> '9')){ | |
68 | printf("Syntax Error\n"); | |
69 | exit(8); | |
70 | } | |
71 | unit = atoi(p); | |
72 | } | |
73 | } | |
74 | ||
75 | bcnt = bcnt<<10; | |
76 | if (((int)(buf = sbrk(bcnt))) < 0) { | |
77 | printf("requested buffer too big - %dK\n",bcnt); | |
78 | exit(8); | |
79 | } | |
80 | ||
81 | unit = unit | 04; /* force to no rewind unit number */ | |
82 | sprintf(&file[8],"%d",unit); | |
83 | if((fd = open(file, 0)) < 0) { | |
84 | printf("Tape Open Error %s\n",file); | |
85 | exit(8); | |
86 | } | |
87 | ||
88 | if(skip) | |
89 | files(nskip,0); | |
90 | if(list){ | |
91 | if(nlist == 0) | |
92 | nlist = -1; | |
93 | files(nlist,1); | |
94 | finis(); | |
95 | } | |
96 | } | |
97 | ||
98 | files(nfiles,lflag) | |
99 | int nfiles, lflag; | |
100 | { | |
101 | int cnt, prevcnt, reccnt, eof; | |
102 | if(nfiles == 0)return; | |
103 | eof=0; | |
104 | for(; nfiles--; filecnt++){ | |
105 | cnt = reccnt = prevcnt = 0; | |
106 | do{ | |
107 | prevcnt = cnt; | |
108 | if((cnt = read(fd,buf,bcnt)) == 0){ /* EOF */ | |
109 | if(eof){ /* double eof */ | |
110 | printf("Double EOF after file %d\n", | |
111 | --filecnt); | |
112 | finis(); | |
113 | } | |
114 | else{ | |
115 | eof=1; | |
116 | if(lflag) | |
117 | printf(" %d Records\n",reccnt); | |
118 | } | |
119 | } | |
120 | else{ | |
121 | eof = 0; | |
122 | if((++reccnt == 1) && lflag) printf("File %d:\n",filecnt); | |
123 | if(cnt<0){ /* error */ | |
124 | if(lflag) printf(" Record %d - ERROR\n",reccnt); | |
125 | } | |
126 | else{ /*data read*/ | |
127 | if(lflag && cnt != prevcnt) | |
128 | printf(" Record %d - %d bytes\n", | |
129 | reccnt,cnt); | |
130 | } | |
131 | } | |
132 | }while(eof==0); | |
133 | } | |
134 | } | |
135 | ||
136 | ||
137 | finis() | |
138 | { | |
139 | unit -= 4; | |
140 | sprintf(&file[8],"%d",unit); | |
141 | close(fd); | |
142 | fd = open(file, 0); | |
143 | close(fd); | |
144 | printf("DONE\n"); | |
145 | exit(0); | |
146 | } |