forked from SDL-Hercules-390/hyperion
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhetmap.c
344 lines (294 loc) · 7.76 KB
/
hetmap.c
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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
/*
|| ----------------------------------------------------------------------------
||
|| HETMAP.C (c) Copyright Leland Lucius, 2000-2003
|| Released under terms of the Q Public License.
||
|| Displays information about the structure of a Hercules Emulated Tape.
||
|| ----------------------------------------------------------------------------
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <unistd.h>
#include <fcntl.h>
#include <string.h>
#include <stdlib.h>
#include "hetlib.h"
#include "sllib.h"
#include "hercules.h"
/*
|| Local constant data
*/
static const char sep[] = "---------------------\n";
static const char help[] =
"%s - Print a map of an HET tape file\n\n"
"Usage: %s [options] filename\n\n"
"Options:\n"
" -a print all label and file information (default: on)\n"
" -d print only dataset information (default: off)\n"
" -f print only file information (default: off)\n"
" -h display usage summary\n"
" -l print only label information (default: off)\n";
#ifdef EXTERNALGUI
/* Special flag to indicate whether or not we're being
run under the control of the external GUI facility. */
int extgui = 0;
/* Previous reported file position */
static long prevpos = 0;
/* Report progress every this many bytes */
#define PROGRESS_MASK (~0x3FFFF /* 256K */)
#endif /*EXTERNALGUI*/
/*
|| Print terse dataset information (from VOL1/EOF1/EOF2)
*/
void
printdataset( char *buf, int len, int fileno )
{
SLLABEL lab;
SLFMT fmt;
char crtdt[ 9 ];
char expdt[ 9 ];
char recfm[ 4 ];
if( sl_islabel( &lab, buf, len ) == FALSE )
{
return;
}
sl_fmtlab( &fmt, &lab );
if( sl_isvol( buf, 1 ) )
{
printf( "vol=%-17.17s owner=%s\n\n",
fmt.slvol.volser,
fmt.slvol.owner);
}
else if( sl_iseof( buf, 1 ) )
{
printf( "seq=%-17d file#=%d\n",
atoi( fmt.slds1.dsseq ),
fileno );
printf( "dsn=%-17.17s crtdt=%-8.8s expdt=%-8.8s blocks=%d\n",
fmt.slds1.dsid,
sl_fmtdate( crtdt, fmt.slds1.crtdt, TRUE ),
sl_fmtdate( expdt, fmt.slds1.expdt, TRUE ),
atoi( fmt.slds1.blkhi ) * 1000000 + atoi( fmt.slds1.blklo ) );
}
else if( sl_iseof( buf, 2 ) )
{
recfm[ 0 ] = '\0';
strcat( strcat( strcat( recfm,
fmt.slds2.recfm ),
fmt.slds2.blkattr ),
fmt.slds2.ctrl );
printf( "job=%17.17s recfm=%-3.3s lrecl=%-5d blksize=%-5d\n\n",
fmt.slds2.jobid,
recfm,
atoi( fmt.slds2.lrecl ),
atoi( fmt.slds2.blksize ) );
}
return;
}
/*
|| Print all label fields
*/
void
printlabel( char *buf, int len )
{
SLLABEL lab;
SLFMT fmt;
int i;
if( sl_islabel( &lab, buf, len ) == FALSE )
{
return;
}
sl_fmtlab( &fmt, &lab );
printf( sep );
for( i = 0; fmt.key[ i ] != NULL; i++ )
{
printf("%-20.20s: '%s'\n", fmt.key[ i ] , fmt.val[ i ] );
}
return;
}
/*
|| Prints usage information
*/
void
usage( char *name )
{
printf( help, name, name );
}
/*
|| Standard main
*/
int
main( int argc, char *argv[] )
{
char buf[ HETMAX_BLOCKSIZE ];
HETB *hetb;
int rc;
int fileno;
U32 blocks;
U32 uminsz;
U32 umaxsz;
U32 ubytes;
U32 cminsz;
U32 cmaxsz;
U32 cbytes;
U32 totblocks;
U32 totubytes;
U32 totcbytes;
U32 opts;
#define O_ALL 0xC0
#define O_FILES 0X80
#define O_LABELS 0X40
#define O_DATASETS 0X20
#ifdef EXTERNALGUI
if (argc >= 1 && strncmp(argv[argc-1],"EXTERNALGUI",11) == 0)
{
extgui = 1;
argc--;
}
#endif /*EXTERNALGUI*/
opts = O_ALL;
/* Display the program identification message */
display_version (stderr, "Hercules HET map program ");
while( TRUE )
{
rc = getopt( argc, argv, "adfhlt" );
if( rc == -1 )
{
break;
}
switch( rc )
{
case 'a':
opts = O_ALL;
break;
case 'd':
opts = O_DATASETS;
break;
case 'f':
opts = O_FILES;
break;
case 'h':
usage( argv[ 0 ] );
exit( 1 );
break;
case 'l':
opts = O_LABELS;
break;
default:
usage( argv[ 0 ] );
exit( 1 );
break;
}
}
argc -= optind;
if( argc != 1 )
{
usage( argv[ 0 ] );
exit( 1 );
}
if( opts & O_ALL )
{
printf( sep );
printf( "%-20.20s: %s\n", "Filename", argv[ optind ] );
}
rc = het_open( &hetb, argv[ optind ], 0 );
if( rc < 0 )
{
printf( "het_open() returned %d\n", rc );
het_close( &hetb );
exit( 1 );
}
fileno = 0;
blocks = 0;
uminsz = 0;
umaxsz = 0;
ubytes = 0;
cminsz = 0;
cmaxsz = 0;
cbytes = 0;
totblocks = 0;
totubytes = 0;
totcbytes = 0;
while( TRUE )
{
#ifdef EXTERNALGUI
if( extgui )
{
/* Report progress every nnnK */
long curpos = ftell( hetb->fd );
if( ( curpos & PROGRESS_MASK ) != ( prevpos & PROGRESS_MASK ) )
{
prevpos = curpos;
fprintf( stderr, "IPOS=%ld\n", curpos );
}
}
#endif /*EXTERNALGUI*/
rc = het_read( hetb, buf );
if( rc == HETE_EOT )
{
break;
}
if( rc == HETE_TAPEMARK )
{
fileno += 1;
if( opts & O_FILES )
{
printf( sep );
printf( "%-20.20s: %d\n", "File #", fileno );
printf( "%-20.20s: %d\n", "Blocks", blocks );
printf( "%-20.20s: %d\n", "Min Blocksize", uminsz );
printf( "%-20.20s: %d\n", "Max Blocksize", umaxsz );
printf( "%-20.20s: %d\n", "Uncompressed bytes", ubytes );
printf( "%-20.20s: %d\n", "Min Blocksize-Comp", cminsz );
printf( "%-20.20s: %d\n", "Max Blocksize-Comp", cmaxsz );
printf( "%-20.20s: %d\n", "Compressed bytes", cbytes );
}
totblocks += blocks;
totubytes += ubytes;
totcbytes += cbytes;
blocks = 0;
uminsz = 0;
umaxsz = 0;
ubytes = 0;
cminsz = 0;
cmaxsz = 0;
cbytes = 0;
continue;
}
if( rc < 0 )
{
printf( "het_read() returned %d\n", rc );
break;
}
blocks += 1;
ubytes += hetb->ublksize;
cbytes += hetb->cblksize;
if( uminsz == 0 || hetb->ublksize < uminsz ) uminsz = hetb->ublksize;
if( hetb->ublksize > umaxsz ) umaxsz = hetb->ublksize;
if( cminsz == 0 || hetb->cblksize < cminsz ) cminsz = hetb->cblksize;
if( hetb->cblksize > cmaxsz ) cmaxsz = hetb->cblksize;
if( opts & O_LABELS )
{
printlabel( buf, rc );
}
if( opts & O_DATASETS )
{
printdataset( buf, rc, fileno );
}
}
if( opts & O_FILES )
{
printf( sep );
printf( "%-20.20s:\n", "Summary" );
printf( "%-20.20s: %d\n", "Files", fileno );
printf( "%-20.20s: %d\n", "Blocks", totblocks );
printf( "%-20.20s: %d\n", "Uncompressed bytes", totubytes );
printf( "%-20.20s: %d\n", "Compressed bytes", totcbytes );
printf( "%-20.20s: %d\n", "Reduction", totubytes - totcbytes );
}
het_close( &hetb );
return 0;
}