1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
|
include <error.h>
include <fset.h>
include <printf.h>
include <mach.h>
include "vt.h"
define MAX_RANGES 100
# VTEXAMINE -- Examine a vacuum telescope tape. Decode and print the
# header and tell the user info about number and length of records
# on the tape.
procedure t_vtexamine()
char input[SZ_FNAME] # input template
char files[SZ_LINE] # which files to examine
bool headers # print headers?
char tapename[SZ_FNAME]
int filerange[2 * MAX_RANGES + 1]
int nfiles, filenumber, nrecords
bool clgetb()
int decode_ranges(), get_next_number()
int vtexamine(), mtfile(), mtneedfileno()
errchk vtexamine
begin
call fseti (STDOUT, F_FLUSHNL, YES)
# Find out if user wants to see header info.
headers = clgetb ("headers")
# Get input file(s)
call clgstr ("input", input, SZ_FNAME)
if (mtfile (input) == NO || mtneedfileno (input) == NO)
call strcpy ("1", files, SZ_LINE)
else
call clgstr ("files", files, SZ_LINE)
if (decode_ranges (files, filerange, MAX_RANGES, nfiles) == ERR)
call error (0, "Illegal file number list.")
call printf ("\n")
# Loop over files.
filenumber = 0
while (get_next_number (filerange, filenumber) != EOF) {
# Assemble the appropriate tape file name.
call strcpy (input, tapename, SZ_FNAME)
if (mtfile(input) == YES && mtneedfileno (input) == YES)
call mtfname (input, filenumber, tapename, SZ_FNAME)
iferr {
nrecords = vtexamine (tapename, headers)
} then {
call eprintf ("Error reading file: %s\n")
call pargstr (tapename)
call erract (EA_WARN)
next
} else if (nrecords == 0) {
call printf ("Tape at EOT\n")
break
}
} # End while.
end
# VTEXAMINE -- examine a tape (or disk) file. Report about size and
# number of records and, if requested, decode and print the header
# information.
int procedure vtexamine (input, headers)
char input[ARB] # input file name
bool headers
int in, bufsize, totrecords
int nrecords, totbytes, lastrecsize
int recsize
bool trufls
pointer hs, sp
pointer pchar, hpchar
int mtopen(), fstati(), get_next_record()
errchk mtopen, close, get_next_record
begin
call smark (sp)
call salloc (hs, VT_LENHSTRUCT, TY_STRUCT)
in = mtopen (input, READ_ONLY, 0)
bufsize = fstati (in, F_BUFSIZE)
call malloc (pchar, bufsize, TY_CHAR)
call malloc (hpchar, bufsize, TY_SHORT)
call printf ("File %s: ")
call pargstr (input)
totrecords = 0
nrecords = 0
totbytes = 0
lastrecsize = 0
# First read the header file.
recsize = get_next_record (in, Memc[pchar], bufsize, recsize,
SZ_VTHDR * SZB_SHORT/SZB_CHAR)
if (recsize == EOF)
return (totrecords)
call amovs (Memc[pchar], Mems[hpchar], SZ_VTHDR * SZB_SHORT/SZB_CHAR)
nrecords = nrecords + 1
totrecords = totrecords + 1
totbytes = totbytes + recsize
lastrecsize = recsize
trufls = TRUE
if (headers)
call decodeheader (hpchar, hs, trufls)
call printf ("\n")
# Loop through the rest of the records.
while (get_next_record (in, Memc[pchar], bufsize, recsize,
lastrecsize) != EOF) {
if (recsize == lastrecsize)
nrecords = nrecords + 1
else {
call printf ("\t %d %d-byte records\n")
call pargi (nrecords)
call pargi (lastrecsize)
nrecords = 1
lastrecsize = recsize
}
totrecords = totrecords + 1
totbytes = totbytes + recsize
} # End while.
if (nrecords > 0 ) {
call printf ("\t %d %d-byte records\n")
call pargi (nrecords)
call pargi (lastrecsize)
}
# Print total number of records and bytes.
call printf ("\t Total %d records, %d bytes\n")
call pargi (totrecords)
call pargi (totbytes)
call mfree (pchar, TY_CHAR)
call mfree (hpchar, TY_SHORT)
call sfree (sp)
call close (in)
return (totrecords)
end
# GET_NEXT_RECORD -- Read the next record from tape (or disk) and,
# if an error is found, patch up the data as best we can and use it.
# Also, tell the user about the error.
int procedure get_next_record(fd, buffer, bufsize, recsize, lastbufsize)
int bufsize
char buffer[bufsize]
int recsize, lastbufsize
pointer fd
int read(), fstati()
bool eofflag
errchk read
begin
eofflag = false
iferr {
if (read (fd, buffer, bufsize) == EOF)
eofflag = true
recsize = fstati (fd, F_SZBBLK)
} then {
call fseti (fd, F_VALIDATE, lastbufsize)
recsize = read (fd, buffer, bufsize)
recsize = fstati (fd, F_SZBBLK)
}
if (BYTE_SWAP2 == YES)
call bswap2 (buffer, 1, buffer, 1, SZ_VTHDR*SZB_SHORT)
if (eofflag)
return (EOF)
else
return (recsize)
end
|