forked from SDL-Hercules-390/hyperion
-
Notifications
You must be signed in to change notification settings - Fork 0
/
voldsext.cmd
529 lines (412 loc) · 14.9 KB
/
voldsext.cmd
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
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
@if defined TRACEON (@echo on) else (@echo off)
REM If this batch file works, then it was written by Fish.
REM If it doesn't then I don't know who the heck wrote it.
setlocal
goto :init
::-----------------------------------------------------------------------------
:: VOLDSEXT.CMD
::-----------------------------------------------------------------------------
:help
echo.
echo NAME
echo.
echo %~nx0 -- Volume datasets extract
echo.
echo SYNOPSIS
echo.
echo %~nx0 ^<filename^> [{sf=}shadowname] [dsname] [memname]
echo.
echo ARGUMENTS
echo.
echo filename Name of dasd image file.
echo.
echo OPTIONS
echo.
echo shadowname Shadow file name. See NOTES for format.
echo.
echo dsname Dataset holding the member(s) to be extracted.
echo.
echo memname Specific member to be extracted.
echo.
echo NOTES
echo.
echo The entire shadowname argument (including the "sf=" prefix)
echo should be surrounded with double quotes if the path contains
echo any blanks (e.g. "sf=path with blanks"). This is different
echo than the way such arguments are passed to Hercules utilities.
echo Hercules utilities use the format sf="path with blanks" where
echo only the path but not the sf= prefix is quoted. When passed
echo to %~nx0 however, use the format "sf=path with blanks"
echo where the entire argument is quoted if it contains any blanks.
echo.
echo %~n0 first uses dasdls to obtain a list of all datasets on
echo the specified volume and then for each listed dataset (or for
echo only the specific dataset if dsname is specified), it uses the
echo dasdcat utility to extract either the specified member or all
echo members into (a) separate file(s).
echo.
echo Each extracted member is placed in its own file in a directory
echo created with the same name as the dataset it came from, which
echo itself is created within a directory created with the same name
echo as the actual VOLSER name of the dasd image file.
echo.
echo EXIT STATUS
echo.
echo 0 Success
echo 1 Failure
echo.
echo AUTHOR
echo.
echo "Fish" (David B. Trout)
echo.
echo VERSION
echo.
echo 1.1 (January 29, 2016)
set /a "rc=1"
goto :exit
::-----------------------------------------------------------------------------
:: INIT
::-----------------------------------------------------------------------------
:init
@REM Define some constants...
set "return=goto :EOF"
set "break=goto :break"
set "TRACE=if defined DEBUG echo"
set "@nx0=%~nx0"
set /a "rc=0"
set "basedir=%cd%"
set "dasdls=dasdls.exe"
set "dasdcat=dasdcat.exe"
set "filename="
goto :parse_args
::-----------------------------------------------------------------------------
:: parse_args
::-----------------------------------------------------------------------------
:parse_args
set /a "rc=0"
if /i "%~1" == "" goto :help
if /i "%~1" == "?" goto :help
if /i "%~1" == "/?" goto :help
if /i "%~1" == "-?" goto :help
if /i "%~1" == "--help" goto :help
call :load_tools
if not "%rc%" == "0" goto :exit
set "filename="
set "shadowname="
set "sfn_argument="
set "dsname="
set "memname="
goto :parse_options_loop
::-----------------------------------------------------------------------------
:: load_tools
::-----------------------------------------------------------------------------
:load_tools
call :fullpath "%dasdls%" dasdls
if not defined # (
echo ERROR: "%dasdls%" not found. 1>&2
set /a "rc=1"
)
call :fullpath "%dasdcat%" dasdcat
if not defined # (
echo ERROR: "%dasdcat%" not found. 1>&2
set /a "rc=1"
)
%return%
::-----------------------------------------------------------------------------
:: fullpath
::-----------------------------------------------------------------------------
:fullpath
set "@=%path%"
set "path=.;%path%"
set "#=%~$PATH:1"
set "path=%@%"
if defined # set "%~2=%#%"
%return%
::-----------------------------------------------------------------------------
:: parse_options_loop
::-----------------------------------------------------------------------------
:parse_options_loop
if "%~1" == "" goto :options_loop_end
set "opt=%~1"
set "optflag=%opt:~0,1%"
set "optname=%opt:~1%"
shift /1
if "%optflag%" == "-" goto :parse_opt
if "%optflag%" == "/" goto :parse_opt
if defined filename goto :parse_got_filename
set "filename=%opt%"
goto :parse_options_loop
:parse_got_filename
if defined shadowname goto :parse_got_shadowname
if /i not "%opt:~0,3%" == "sf=" goto :parse_got_shadowname
set "shadowname=%opt:~3%"
goto :parse_options_loop
:parse_got_shadowname
if defined dsname goto :parse_got_dsname
set "dsname=%opt%"
goto :parse_options_loop
:parse_got_dsname
if defined memname goto :parse_got_memname
set "memname=%opt%"
goto :parse_options_loop
:parse_got_memname
goto :parse_bad_opt
:parse_opt
goto :parse_bad_opt
:parse_bad_opt
echo ERROR: Unrecognized option '%opt%' 1>&2
set /a "rc=1"
goto :parse_options_loop
:options_loop_end
goto :validate_args
::-----------------------------------------------------------------------------
:: validate_args
::-----------------------------------------------------------------------------
:validate_args
if not defined filename goto :missing_filename
call :fullpath "%filename%" filename
if not defined # (
echo ERROR: "%filename%" not found. 1>&2
set /a "rc=1"
)
goto :validate_shadowname
:missing_filename
echo ERROR: filename is required 1>&2
set /a "rc=1"
goto :validate_shadowname
:validate_shadowname
if not defined shadowname goto :validate_args_done
call :fullpath "%shadowname%" shadowname
if not defined # (
echo ERROR: "%shadowname%" not found. 1>&2
set /a "rc=1"
) else (
@REM -------------------------------------------------------------
@REM
@REM PROGRAMMING NOTE #1
@REM
@REM The "sf=" command-line argument is quoted differently when
@REM passed to Hercules utilities than the way it is quoted when
@REM passed to this batch file.
@REM
@REM When passed to this batch file, then entire argument must
@REM be surrounded in double quotes (if it contains any blanks),
@REM
@REM whereas only the shadow filename itself should be surrounded
@REM in quotes when passed to Hercules dasdls/dasdcat utilities:
@REM
@REM
@REM "sf=path with blanks" (this batch file's format)
@REM sf="path with blanks" (Hercules utilities format)
@REM
@REM -------------------------------------------------------------
@REM
@REM PROGRAMMING NOTE #2
@REM
@REM Because the 'for' statement in the 'dasdls_sub' subroutine
@REM specifies '=' as its delimiter ("delims=="), the shadowname
@REM argument cannot be directly passed to dasdls since the "sf="
@REM prefix contains an '=' resulting in it being removed because
@REM it's seen as a delimiter by the 'for' statement (believe it
@REM or not!) resulting in a string such as "sf C:\shadow path"
@REM being passed to dasdls (note missing '=' following "sf"!!)
@REM causing dasdls to either crash or not use the shadow file.
@REM
@REM As a workaround we set a new variable equal to the exact
@REM command line argument string to be passed to dasdls thereby
@REM hiding the '=' altogether from Microsoft's brain dead 'for'
@REM statement parser.
@REM
@REM (Why the FRICK it's using the specified delimiter(s) to parse
@REM the COMMAND LINE with instead of only using it to parse the
@REM command's resulting OUTPUT with is anyone's guess!!)
@REM
@REM -------------------------------------------------------------
set sfn_argument=sf="%shadowname%"
)
goto :validate_args_done
:validate_args_done
if not "%rc%" == "0" (
goto :exit
)
goto :BEGIN
::-----------------------------------------------------------------------------
:: BEGIN
::-----------------------------------------------------------------------------
:BEGIN
echo.
call :dasdls_sub
goto :exit
::-----------------------------------------------------------------------------
:: dasdls_sub
::-----------------------------------------------------------------------------
:dasdls_sub
set "did_volser_line="
set "abort="
set "ocd=%cd%"
set /a "rc=0"
set /a "dsncnt=0"
if not defined sfn_argument goto :dasdls_filename_only
@REM Refer to the PROGRAMMING NOTE(s) much further above. We MUST use an
@REM '=' for our delimiter in the below 'for' statement so we can extract
@REM the VOLSER name from dasdls's first line of output.
for /f "tokens=1* delims==" %%a in ('""%dasdls%" "%filename%" %sfn_argument%" 2^>nul') do (
call :process_dsn "%%a" "%%b"
if defined abort %break%
)
:break
%break%
:dasdls_filename_only
for /f "tokens=1* delims==" %%a in ('""%dasdls%" "%filename%"" 2^>nul') do (
call :process_dsn "%%a" "%%b"
if defined abort %break%
)
:break
echo ** Total datasets processed on volume '%volser%' = %dsncnt% **
if /i not "%cd%" == "%ocd%" popd
%return%
::-----------------------------------------------------------------------------
:: process_dsn
::-----------------------------------------------------------------------------
:process_dsn
set "save_volser=%volser%"
set "dsn=%~1"
set "volser=%~2"
if not defined did_volser_line (
@REM The first line of dasdls contains the volser,
@REM but we need to skip any Hercules msgs first...
call :is_hercules_msg "%dsn%"
if defined # %return%
set "did_volser_line=1"
if not exist "%volser%" mkdir "%volser%"
call :isdir "%volser%"
if not defined # (
echo ERROR: Could not create directory "%volser%" or file exists and is not a directory. 1>&2
set /a "rc=1"
set "abort=yes"
) else (
echo Processing volume '%volser%' ...
pushd "%volser%"
)
%return%
)
@REM Remaining lines of dasdls are the dataset names...
set "volser=%save_volser%"
@REM Are we extracting from all datasets,
@REM or from just one specific dataset?
if not defined dsname (
@REM Extract from ALL datasets...
call :process_dsname
set /a "dsncnt=dsncnt+1"
) else (
@REM Extract from only one specific dataset...
if /i "%dsn%" == "%dsname%" (
call :process_dsname
set /a "dsncnt=dsncnt+1"
)
)
%return%
::-----------------------------------------------------------------------------
:: is_hercules_msg
::-----------------------------------------------------------------------------
:is_hercules_msg
set "msgid=%~1"
set "msgid=%msgid:~0,9%"
set "#="
if /i not "%msgid:~0,3%" == "HHC" %return%
call :isnum "%msgid:~3,-1%"
if not defined isnum %return%
set "#=1"
if /i "%msgid:~-1%" == "I" %return%
if /i "%msgid:~-1%" == "W" %return%
if /i "%msgid:~-1%" == "E" %return%
if /i "%msgid:~-1%" == "D" %return%
if /i "%msgid:~-1%" == "S" %return%
if /i "%msgid:~-1%" == "A" %return%
set "#="
%return%
::-----------------------------------------------------------------------------
:: isnum
::-----------------------------------------------------------------------------
:isnum
set "@=%~1"
set "isnum="
for /f "delims=0123456789" %%i in ("%@%/") do if "%%i" == "/" set "isnum=1"
%return%
::-----------------------------------------------------------------------------
:: process_dsname
::-----------------------------------------------------------------------------
:process_dsname
echo Processing volume '%volser%' dataset '%dsn%' ...
if not exist "%dsn%" mkdir "%dsn%"
call :isdir "%dsn%"
if not defined # (
echo ERROR: Could not create directory "%dsn%" or file exists and is not a directory. 1>&2
set /a "rc=1"
%return%
)
pushd "%dsn%"
set "member="
set /a "memcnt=0"
for /f "tokens=1*" %%a in ('""%dasdcat%" -i "%filename%" %sfn_argument% %dsn%/?" 2^>nul') do (
@REM Member names can't have blanks so if %%b is non-empty
@REM then we know it's not a member name line. Otherwise
@REM if %%b is empty then we know it's a member name line.
if "%%b" == "" (
@REM Are we extracting all members from this dataset,
@REM or just one specific member?
if not defined memname (
@REM Extract ALL members from this dataset...
echo Extracting volume '%volser%' dataset '%dsn%' member '%%a' ...
call :process_member "%%a"
set /a "memcnt=memcnt+1"
) else (
@REM Extract only one specific member...
if /i "%%a" == "%memname%" (
echo Extracting volume '%volser%' dataset '%dsn%' member '%%a' ...
call :process_member "%%a"
set /a "memcnt=memcnt+1"
%break%
)
)
)
)
:break
popd
if defined memname (
if %memcnt% EQU 0 (
echo ERROR: Member '%memname%' not found in dataset '%dsn%' on volume '%volser%'. 1>&2
)
)
echo ** Total members extracted from volume '%volser%' dataset '%dsn%' = %memcnt% **
%return%
::-----------------------------------------------------------------------------
:: isdir
::-----------------------------------------------------------------------------
:isdir
set "#=%~a1"
if not defined # %return%
if /i "%#:~0,1%" == "d" %return%
set "#="
%return%
::-----------------------------------------------------------------------------
:: process_member
::-----------------------------------------------------------------------------
:process_member
set "member=%~1"
@REM Try to cat the member first in 80-byte card image format,
@REM but if that doesn't work (which it won't for load modules
@REM for example), then cat it in as-is binary format...
"%dasdcat%" -i "%filename%" %sfn_argument% %dsn%/%member%:cs > "%member%.txt" 2>nul
set /a "rc=%errorlevel%"
if %rc% EQU 0 %return%
del "%member%.txt"
"%dasdcat%" -i "%filename%" %sfn_argument% %dsn%/%member% > "%member%" 2>nul
set /a "rc=%errorlevel%"
%return%
::-----------------------------------------------------------------------------
:: EXIT
::-----------------------------------------------------------------------------
:exit
endlocal & exit /b %rc%
::-----------------------------------------------------------------------------