forked from moshix/mvs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
recv390.c
executable file
·2175 lines (1925 loc) · 65.5 KB
/
recv390.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
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
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Things to do:
//
// 1) Add support for DSORG=PS, PDS/E, RECFM=V[B][S]
// 2) IB - blank out when ISPF stats present
// 4) Improve error handling/return, especially void functions & their calleds
// 5) Externalize translate table (or at least it's update) to accept input file
//
/*
This program reads the output of TSO TRANSMIT, which has been
(binary) file transferred from OS/390 to a PC, and produces
one file for each PDS member in the TRANSMIT dataset.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#define DIAG_GEN_FLOW
#define DIAG_GEN_MSG
#define DIAG_GEN_SNAP
// #undef DIAG_GEN_FLOW
// #undef DIAG_GEN_MSG
// #undef DIAG_GEN_SNAP
// handy macro definitions:
#define snapid " " __FILE__ " line " makestr(__LINE__) " "
#define makestr(x) whack(x)
#define whack(x) #x
#define snapset(x)
// Print string & decimal number in various formats:
#undef prtsd
#define prtsd(str, i) {char buf[256]; sprintf(buf, "%s: %d (signed), or %u (unsigned), or 0x%4.4X (hex) \n", str, i, i, i); diagmsg(buf);}
#undef diagflow
#ifndef DIAG_GEN_FLOW
#define diagflow(x)
#else
#define diagflow(x) printf(x "\n")
#endif
#undef diagmsg
#ifndef DIAG_GEN_MSG
#define diagmsg(x)
#else
#define diagmsg(x) printf(x "\n")
#endif
#undef snap
#ifndef DIAG_GEN_SNAP
#define snap(a,b,c)
#else
#define snap(a,b,c) snaplong(a,b,c)
#endif
int procdata();
int writemem();
int makerec(char *, int, int);
void openout();
int closeout(int);
char *assocmem(unsigned int);
void nextmem();
int procdir();
int cmpttr(const void *, const void *);
unsigned char*diralloc();
int parsedirblk(int);
int parsemem(int);
int printdirmem();
char *ispfdate(char *);
void juliangreg(int, int, int *, int *);
void unpackdate(unsigned char *, int *, int *);
int unpack(int);
void getblock(int, int);
void getseg(int);
int cmdline(int, char *[]);
int parseopt(char *, char *, char *);
void tranmap();
int aschex(char *);
void printhelp();
void cleanup();
int getvbin(char *, int);
void strxset(char *, int, char *, int);
void ebcdic2ascii(void *, int);
void snaplong(void *, int, char *);
int jmmsnap(void *, int, int, char *);
int halt(char *);
// ------- GLOBALS --------------------------------------------------
#define FIXED_ENTRY_LENGTH 16 // PDS member (8), ttr (3), slack - stored in "dir"
// Debugging
int ctlsnap = 0; // 1 = snap Control segments when read
int datasnap = 0; // 1 = snap Data segments when read
int snapdatablk = 0; // 1 = snap all data blocks
int getsegstats = 0; // 1 = show getseg stats ****
int prtoutrec = 0; // 1 = write records to stdout
int dbugshowclose = 0; // 1 = show FNout fclose
int dbugshowopen = 0; // 1 = show FNout fopen
int showsnapaddr = 1; // 1 = show snap addresses
int snapcr = 0; // 1 = begin snap with blank line
int snapshorthdr = 0; // 1 = snap header = title only
// Options
char opttran = '+'; // translate from EBCDIC to ASCII (makrec)
char optseq = '-'; // don't preserve sequence numbers
char opttrimblank = '+'; // trim trailing blanks
char optrdw = '-'; // no RDW
char optxmisum = '+'; // display TRANSMIT dataset summary
char optdsattr = '+'; // display dataset attributes
char optdir = '+'; // display PDS directory
char optwrite = '+'; // write output files
char opthalt = '+'; // halt for <press enter> msg in halt()
char optabout = '-'; // don't display copyright info
char opthelp = '-'; // don't display general help
char opthelptran = '-'; // don't display xlate help
char opthelprdw = '-'; // don't dispaly RDW help
char opthelpseq = '-'; // don't display SEQ help
char opthelpbug = '-'; // don't display debugging help
char optsyntax = '-'; // don't display syntax help
char optdirhex = '-'; // don't dump directory in hex
char optmap = '-'; // map translate table
// Debugging Options
char optlist = '-'; // list records on stdout
char optdumpdir = '-'; // dump IEBCOPY dir blocks
char optgetseg = '-'; // getseg segment info
char optsnapseg = '-'; // getseg snap
char optgetblock = '-'; // getblock block info
char optsnapblock = '-'; // getblock snap data block
char optsnaphalt = '-'; // snap <press enter> prompt
char optblock1 = '-'; // dump block 1
char optblock2 = '-'; // dump block 2
char *program = "recv390"; // program name
char *notprogram = " "; // blanks same length as program
int fatal = 0; // 1 = abandon execution
int unsupported = 0; // 1 = dataset not supported
int snapassumeascii = 0; // 1 = snap() won't xlate display to EBCDIC
FILE *fin = NULL;
FILE *fout = NULL;
char FNout[FILENAME_MAX] = "Dummy.txt";
char FNin[sizeof(FNout)] = "OS390.XMI";
char outext[40] = "TXT";
char dsn[80] = "";
char dsnmem[sizeof(dsn)];
char *pmem = NULL; // ptr to ASCII member name
char membername[8] = ""; // ASCII member name from assocmem
unsigned char line[255]; // EBCDIC data from TRANSMIT segment
unsigned char tranline[sizeof(line)]; // ASCII conversion of "line"
unsigned char *rec; // record buffer for makerec
unsigned char datestr[80]; // ispf date as char string from ispfdate()
int recpos = 0; // position in rec for makerec
unsigned char *block = 0; // instorage current IEBCOPY block
unsigned char *dir = 0; // instorage PDS directory storage
int dirpos = 0; // position in "dir" directory
int outdirpos = 0; // openout() dirpos for closeout()
int assocpos = 0; // assocmem() dirpos
int dirlen = 0; // length of "dir" used
int dirblkpos = 0; // position in 256 byte PDS dir block
int direntries = 0;
int ispfstats = 0; // ISPF stats available (procdir/parsemem)
int fileswritten = 0;
int databytesread = 0; // total bytes of data read
int databyteswritten = 0;
int datarecswritten = 0;
int outmembytes = 0;
int outrecbytes = 0; // # bytes output for record (writemem/makerec)
int membyteswritten = 0; // # bytes written for member
int memrecswritten = 0; // # records written for member
int warncounts = 0; // # members whose rec count didn't verify
int blocklen = 0; // IEBCOPY block length
int blocktrailer = 0; // set by getblock()
int seglen = 0; // length of TRANSMIT segment (0 - 253)
int segflag = 0; // segment flag
int segbytesread = 0;
int pos = 0; // position within block or line
int maxpos = 0; // position within block set by getblock()
int datablock = 0;
int dsorg = 0; // dataset dsorg
int recfm = 0; // dataset recfm
int blksize = 0; // dataset blksize
int lrecl = 0; // dataset lrecl
int vbfile = 0; // 1 = file is V[B] recfm
int msgfile = 0; // 1 = process msgfile
char lastmem[8]; // 8x'ff' End-of-Directory mem name
/* code page 37 below */
unsigned char trantab[256] = {
//-----------------------------------------------------------------------------------
// +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +a +b +c +d +e +f
//-----------------------------------------------------------------------------------
0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
// 00
//
0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
// 10
//
0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
// 20
//
0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
// 30
//
0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5b,0x2e,0x3c,0x28,0x2b,0x7c,
// 40 -- -- -- -- -- -- --
// sp [ . < ( + |
//
0x26,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x21,0x24,0x2a,0x29,0x3b,0x5e,
// 50 -- -- -- -- -- -- --
// & ! $ * ) ; ^
//
0x2d,0x2f,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7c,0x2c,0x25,0x5f,0x3e,0x3f,
// 60 -- -- -- -- -- -- -- --
// - / | , % _ > ?
//
0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x3a,0x23,0x40,0x27,0x3d,0x22,
// 70 -- -- -- -- -- --
// : # @ ' = "
//
//------------------------------------------------------------------------------------
// +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +a +b +c +d +e +f
//------------------------------------------------------------------------------------
0x20,0x61,0x62,0x63,0x64,0x65,0x66,0x67,0x68,0x69,0x20,0x20,0x20,0x20,0x20,0x20,
// 80 -- -- -- -- -- -- -- -- --
// a b c d e f g h i
//
0x20,0x6a,0x6b,0x6c,0x6d,0x6e,0x6f,0x70,0x71,0x72,0x20,0x20,0x20,0x20,0x20,0x20,
// 90 -- -- -- -- -- -- -- -- --
// j k l m n o p q r
//
0x20,0x7e,0x73,0x74,0x75,0x76,0x77,0x78,0x79,0x7a,0x20,0x20,0x20,0x5b,0x20,0x20,
// a0 -- -- -- -- -- -- -- -- -- --
// ~ s t u v w x y z [
//
0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5d,0x20,0x20,
// b0 --
// ]
//
0x7b,0x41,0x42,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x20,0x20,0x20,0x20,0x20,0x20,
// c0 -- -- -- -- -- -- -- -- -- --
// { A B C D E F G H I
//
0x7d,0x4a,0x4b,0x4c,0x4d,0x4e,0x4f,0x50,0x51,0x52,0x20,0x20,0x20,0x20,0x20,0x20,
// d0 -- -- -- -- -- -- -- -- -- --
// } J K L M N O P Q R
//
0x5c,0x01,0x53,0x54,0x55,0x56,0x57,0x58,0x59,0x5a,0x20,0x20,0x20,0x20,0x20,0x20,
// e0 -- -- -- -- -- -- -- -- --
// \ S T U V W X Y Z
//
0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x20,0x20,0x20,0x20,0x20,0x20};
// f0 -- -- -- -- -- -- -- -- -- --
// 0 1 2 3 4 5 6 7 8 9
//
//------------------------------------------------------------------------------------
// +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +a +b +c +d +e +f
//------------------------------------------------------------------------------------
// ------- MAIN -----------------------------------------------------
int main(int argc, char *argv[]) {
int i, x, rc;
int segtype;
int blksize;
int templen;
int tempnum;
char orignode[9] = "?";
char origuser[9] = "?";
char targnode[9] = "?";
char targuser[9] = "?";
char origtime[20] = "?";
int numfiles = 0;
int rectype;
int filenum;
char utility[9] = "?";
rc = cmdline(argc, argv);
if ((opthelp == '+') || (rc) || (fatal)) {
cleanup();
return rc;
}
getseg(ctlsnap);
x = memcmp(tranline, "INMR01", 6);
if (x != 0) {
printf("Input file not a TSO TRANSMIT dataset\n");
cleanup();
return 4;
}
while (!feof(fin)) {
// Process the Data segments
while (! (segflag & 0x20) ) {
rc = procdata(); // process Data segments
if (rc) {
cleanup();
return fatal;
}
// snap(line, seglen, "Segment emitted from procdata");
}
// Process the Control segments
rectype = 0;
x = memcmp(tranline, "INMR0", 5);
if (x == 0) {
rectype = getvbin(&tranline[pos+5], 1); // what kind of INMR0?
// printf("INMR0 record %d\n", rectype);
pos = pos + 6;
datablock = 0; // reset data blk ctr
}
if (rectype == '2') {
if (optxmisum=='+') { // show info gathered from INMR01
optxmisum = '-'; // only show it once
printf("\n");
printf("TSO TRANSMIT dataset sent to user %s at node %s\n",
targuser, targnode);
printf("from user %s at node %s ", origuser, orignode);
printf("on %.2s/%.2s/%.4s at %.2s:%.2s:%.2s\n",
origtime+4, origtime+6, origtime+0,
origtime+8, origtime+10, origtime+12);
if (numfiles > 1) {
printf("contains %d files", numfiles);
printf(", the first of which is this message:\n");
} else {
printf("contains one file.\n");
}
}
filenum = getvbin(&line[pos], 4);
pos = pos + 4;
}
// Terminate when trailer found
if (rectype == '6') {
while (!(feof(fin))) {
fgetc(fin); // Read rest of input so stats look OK
segbytesread++;
}
segbytesread--; // went one too far
cleanup();
return 0;
}
// Deal with stuff in this Control segment
while (pos < seglen) {
segtype = getvbin(&line[pos], 2);
pos = pos + 2;
// if (rectype != '2') {
// printf("Current key %.2x\n", segtype);
// printf("Current position %d seglen %d\n", pos, seglen);
// snap(&line[pos], seglen, "current position");
// }
switch (segtype) {
case 0x1001: // target node name
templen = getvbin(&line[pos+2], 2);
strxset(targnode, sizeof(targnode), &tranline[pos+4], templen);
pos = pos + 4 + templen;
break;
case 0x1002: // target userid
templen = getvbin(&line[pos+2], 2);
strxset(targuser, sizeof(targuser), &tranline[pos+4], templen);
pos = pos + 4 + templen;
break;
case 0x1011: // origin node name
templen = getvbin(&line[pos+2], 2);
strxset(orignode, sizeof(orignode), &tranline[pos+4], templen);
pos = pos + 4 + templen;
break;
case 0x1012: // origin userid
templen = getvbin(&line[pos+2], 2);
strxset(origuser, sizeof(origuser), &tranline[pos+4], templen);
pos = pos + 4 + templen;
break;
case 0x1024: // origin time stamp
templen = getvbin(&line[pos+2], 2);
strxset(origtime, sizeof(origtime), &tranline[pos+4], templen);
pos = pos + 4 + templen;
break;
case 0x102f: // number of files
templen = getvbin(&line[pos+2], 2);
numfiles = getvbin(&line[pos+4], templen);
pos = pos + 4 + templen;
break;
case 0x0042: // logical record length
templen = getvbin(&line[pos+2], 2);
lrecl = getvbin(&line[pos+4], templen);
pos = pos + 4 + templen;
break;
case 0x0030: // blocksize
templen = getvbin(&line[pos+2], 2);
blksize = getvbin(&line[pos+4], templen);
pos = pos + 4 + templen;
break;
case 0x1028: // utility name
templen = getvbin(&line[pos+2], 2);
strxset(utility, sizeof(utility), &tranline[pos+4], templen);
pos = pos + 4 + templen;
break;
case 0x0002: // dsname
tempnum = getvbin(&line[pos+0], 2);
pos = pos + 2;
memset( dsn, 0, sizeof(dsn));
for (i = 0; i < tempnum; i++) {
templen = getvbin(&line[pos], 2);
pos = pos + 2;
strncat(dsn, &tranline[pos], templen);
pos = pos + templen;
if (i + 1 != tempnum)
strncat(dsn, ".", 1);
}
break;
case 0x0028: // terminal allocation - flag only, count = 0
tempnum = getvbin(&line[pos+0], 2);
pos = pos +2;
msgfile = 1; // inline MESSAGE
break;
case 0x1023: // origin version number
case 0x1025: // destination time stamp
case 0x1026: // acknowledgement request
case 0x1027: // receive error code
case 0x1029: // user parameter string
case 0x102a: // transmitted record count
case 0x0001: // ddname
case 0x0003: // member name
case 0x000b: // secondary space quantity
case 0x000c: // dir blks
case 0x0022: // expiration date terminal
case 0x003c: // dsorg
case 0x0049: // recfm
case 0x1020: // last ref date
case 0x1021: // last chg date
case 0x1022: // create date
case 0x102c: // pri space qty
case 0x8012: // dataset type
tempnum = getvbin(&line[pos+0], 2);
pos = pos + 2;
if (tempnum != 1) {
for (i = 0; i < tempnum; i++) {
templen = getvbin(&line[pos], 2);
pos = pos + 2 + templen;
}
} else {
templen = getvbin(&line[pos], 2);
pos = pos + 2 + templen;
}
break;
default:
printf("unknown segment key %.2x\n", segtype);
printf("pos %d, seglen %d\n", pos, seglen);
snap(line, seglen, "line");
tempnum = getvbin(&line[pos+0], 2);
pos = pos + 2;
for (i = 0; i < tempnum; i++) {
templen = getvbin(&line[pos], 2);
pos = pos + 2 + templen; // just ignore it
}
break;
} // switch
} // pos < seglen
getseg(ctlsnap);
} // ! eof
cleanup();
return 0;
} /* main */
//--------------------------------------------------------------------
//* Process Data segments
// Upon entry, line & tranline contain the first segment of the
// first block from IEBCOPY, INMCOPY, AMSCIPHER or inline MESSAGE
// This code knows what to do for IEBCOPY & inline MESSAGE...
// Others: tough luck.
// Deciphering IEBCOPY data - Notes:
// TSO TRANSMIT doesn't give us the BDW & RDW from the IEBCOPY blocks.
// It does, however, set segflag x'80' & x'40' so that we can determine
// data block boundaries. MAIN resets blocknum for us whenever it sees an
// INMR0n record, so data block numbers are always relative to the most
// recently seen INMR0n segment. This is mildly useful when there's an
// imbedded MESSAGE from TSO TRANSMIT (at least during debugging).
// The TSO Customization doc for segflag says "record", but it means "block".
// Example 1: segflag x'c0' means segment contains entire block
// Example 2: segflag x'80' means segment is 1st in the block
// Example 3: segflag x'00' means segment is neither first nor last in block,
// ala VTAM middle-of-chain
// Example 4: segflag x'40' means segment is last in block
// Segflag x'20' means Control record (otherwise it's a Data record).
// Segflag x'10' says 'This is record number of next record', but I've never
// seen one.
// This code handles all the data for all members or one MESSAGE per call.
int procdata( ) {
char txtdsorg[5] = "";
char txtrecfm[4] = "";
const int eyepds = 0x00ca6d0f; // IEBCOPY PDS eyecatcher
/*
const int eyepdse = 0x01ca6d0f; // IEBCOPY PDSE eyecatcher (someday)
*/
int rc = 0;
if (msgfile) {
printf("\n");
while (! (segflag & 0x20) ) {
printf("%.*s\n", seglen, tranline);
getseg(0); // eat inline MESSAGE w/o snap
}
msgfile = 0; // only one MESSAGE per TRANSMIT
return 0;
}
getblock(1, 0); // get rest of 1st block, append line
// Contents of 1st IEBCOPY block (BDW & RDW are not present in TRANSMIT block):
//
// +00 (4) 0x00ca6d0f PDS eyecatcher
// +04 (2) dsorg
// +06 (2) blksize
// +08 (2) lrecl
// +10 (1) recfm and probably some other stuff
//
if (optblock1 == '+')
snap( block, blocklen, "Data Block One");
if (!(memcmp(block, &eyepds, 4))) {
printf("Fatal error; procdata could not verify IEBCOPY PDS eyecatcher\n");
snap(block, blocklen, "IEBCOPY header block");
fatal = 1;
return fatal;
}
dsorg = getvbin(&block[4], 2);
blksize = getvbin(&block[6], 2);
lrecl = getvbin(&block[8], 2); // lrecl from 1st IEBCOPY block
recfm = getvbin(&block[10], 1);
unsupported = 1; // assume unsupported dataset
if (dsorg & 0x8000) strcpy(txtdsorg, "ISAM");
if (dsorg & 0x4000) strcpy(txtdsorg, "PS");
if (dsorg & 0x2000) strcpy(txtdsorg, "DA");
if (dsorg & 0x0200) {
strcpy(txtdsorg, "PO");
unsupported = 0;
}
if (txtdsorg[0] == '\0')
strcpy(txtdsorg, "?");
if (dsorg & 0x01) strcat(txtdsorg, "U"); // unmovable
if (recfm & 0x80) strcpy(txtrecfm, "F");
if (recfm & 0x40) {
strcpy(txtrecfm, "V");
vbfile = 1;
}
if ((recfm & 0xc0) == 0xc0) {
strcpy(txtrecfm, "U");
optseq = '+'; // no RECFM=U sequence fields
}
if (recfm & 0x10) strcat(txtrecfm, "B");
if (recfm & 0x08) {
strcat(txtrecfm, "S");
if (!(memcmp(txtrecfm, "VBS", 3))) unsupported = 1;
}
if (recfm & 0x04) strcat(txtrecfm, "A");
if (recfm & 0x02) strcat(txtrecfm, "M");
if (optdsattr=='+') {
printf("\n");
printf("Dataset %s\n", dsn);
printf("Dsorg %s ", txtdsorg);
printf("recfm %s ", txtrecfm);
printf("blksize %d ", blksize);
printf("lrecl %d\n", lrecl);
}
if (unsupported) {
printf("\n");
printf("This dataset is not currently supported.\n\n");
rc = 1;
if (optdir=='+')
rc = halt("Press enter to display directory, enter 'x' to exit");
if (rc) {
fatal = 1;
return fatal;
}
}
getblock(0, 0); // get Data Block Two
if (optblock2=='+')
snap(block, blocklen, "Block 2");
// Contents of 2nd IEBCOPY block - secret (well ... _I_ don't know)
//
// Appears to have "dataset/member id" value that appears in blocks 4 - n
// So far, I haven't had to care. This block is mostly x'00' anyway.
getblock(0, 0); // get Data Block Three
// Contents of 3rd IEBCOPY block (assuming no BDW & RDW):
//
// +00 (8) 8x'00' directory eyecatcher
//
// FOLLOWING OCCURS FOR EACH PDS DIRECTORY BLOCK
//
// +08 (2) presumably PDS directory keylen = 8
// +10 (2) presumably pds directory blksize = 0x0100
// +12 (8) presumably high key value from CKD DASD key
//
// BEGINNING OF FIRST PDS DIRECTORY BLOCK
//
// +20 (2) length of bytes in PDS directory block used
// including space consumed by this halfword
// +22 (8) first member name begins here
//
// MORE PDS DIRECTORY BLOCKS MAY FOLLOW IN SAME IEBCOPY BLOCK
//
// Additional IEBCOPY PDS directory blocks may also follow
// when IEBCOPY decides they won't fit in current block
//
rc = procdir(); // parse & store PDS directory
if (rc)
return rc;
if (unsupported) { // at least let user see dir
fatal = 1;
return fatal;
}
rc = writemem();
if (rc) {
fatal = 1;
return fatal;
}
return rc;
} /* procdata */
//--------------------------------------------------------------------
//* Write all the data for IEBCOPY unloaded PDS members
int writemem( ) {
int outlen;
int bytesleftinblock;
int bytesinblock = 0;
int bytes;
int rc = 0;
if (optwrite=='-') {
fatal = 1;
return fatal;
}
closeout(1); // print header line
dirpos = 0 - FIXED_ENTRY_LENGTH; // prepare for nextmem()
nextmem();
openout();
while (! (segflag & 0x20)) { // have Data segment
bytesinblock = getvbin(&block[9], 3); // # data bytes in IEBCOPY block
if (vbfile) {
pos += 4; // account for VB BDW
bytesinblock -= 4;
}
databytesread += bytesinblock;
if (bytesinblock < 1) { // member EOF block
rc = closeout(0);
if (rc) {
fatal = 1;
return fatal;
}
getblock(0, 0); // ignore empty block
continue; // check for INMR06
}
outmembytes = 0; // # bytes output for block
while (outmembytes < bytesinblock) {
makerec(NULL, 0, 0); // clear output record
outrecbytes = 0; // # bytes output for rec
if (vbfile) {
lrecl = getvbin(&block[pos], 2); // record length for V[B]
lrecl -= 4;
pos += 4;
if (pos >= maxpos)
break;
}
while ((outmembytes < bytesinblock) && (outrecbytes < lrecl)) {
if (prtoutrec) // add extra debug info
printf("%.4x %.4x %.4x ", blocklen, maxpos, pos);
if (pos >= maxpos) {
getblock(0,0);
} else {
outlen = lrecl - outrecbytes; // desired # rec output bytes
bytesleftinblock = maxpos - pos; // # bytes avail in block
if (outlen > bytesleftinblock)
outlen = bytesleftinblock; // all we can output for now
makerec(&block[pos], outlen, 0); // queue [partial] record
}
}
memrecswritten++;
bytes = makerec(rec,0,prtoutrec); // [list &] output rec
if (fatal)
return fatal;
membyteswritten += bytes; // accum bytes written for mem
}
if (blocktrailer) { // was there a blk trailer?
rc = closeout(0);
if (rc) {
fatal = 1;
return fatal;
}
}
getblock(0, 0); // get new data block
} // while Data
closeout(0);
return rc;
} /* writemem */
//--------------------------------------------------------------------
//* Make record, output "lrecl" bytes when complete
// Also updates outmembytes, outrecbytes, and pos based on "len" passed
// Trim trailing blanks
int makerec(char *ptxt, int len, int showrec ) {
// char showbuf[sizeof(line)];
int bytesout, i, validseq, x;
if (rec == NULL) {
rec = malloc(lrecl);
if (rec == NULL) {
printf("Fatal error; storage allocation failed for %d bytes\n", lrecl);
fatal = 1;
return fatal;
}
}
if (ptxt == NULL) {
memset(rec, 0, sizeof(rec)); // clear record buffer
recpos = 0;
return 0;
}
// ---------------------------------------------
if (len == 0) { // output record
if (opttran=='+')
ebcdic2ascii( rec, lrecl); // ASCII-ize buffer
bytesout = lrecl;
if ((optseq == '-') && (bytesout > 8)) { // remove sequence field
validseq = 1; // assume seq field valid
if (vbfile) {
for (i=0; i < 8; i++) {
x = rec[i];
if (!isdigit(x))
validseq = 0;
}
} else {
for (i=lrecl - 1; i >= lrecl - 8; i--) {
x = rec[i];
if (!isdigit(x))
validseq = 0;
}
}
if (validseq) {
if (vbfile) {
for (i = 0; i < lrecl - 8; i++) {
rec[i] = rec[i+8]; // shove VB line over 8 bytes
}
} else {
memset(&rec[lrecl-8], ' ', 8); // blank out sequence field
}
bytesout = bytesout - 8;
}
}
if (opttrimblank == '+') { // trim trailing blanks
for (i = bytesout - 1; i > 0; i--)
if (rec[i] == ' ') {
rec[i] = '\0';
bytesout--;
} else
break;
}
if (bytesout < 0) {
bytesout = 1; // negative byte count bad
}
if (optrdw=='+') {
fprintf(fout, "%c%c%c%c",
((bytesout+4)/256), ((bytesout+4) - ((bytesout+4)/256)), 0, 0);
}
fprintf(fout, "%.*s\n", bytesout, rec); // output record
if (optlist=='+')
printf("%.*s\n", bytesout, rec); // list record
bytesout = bytesout + 2; // account for "\r"
databyteswritten += bytesout; // total data bytes written
datarecswritten++; // total data records written
recpos = 0;
return bytesout; // # bytes written
}
//----------------------------------------------
memcpy(&rec[recpos], ptxt, len); // add text to buffer
if (showrec) {
snap( rec, lrecl, "makerec fragmented rec");
}
recpos = recpos + len;
outmembytes = outmembytes + len;
outrecbytes = outrecbytes + len;
pos = pos + len;
return 0;
} /* makerec */
//--------------------------------------------------------------------
// Close previous output file
// Build output file name, open it
void openout( ) {
unsigned int i;
int c;
char blank = ' ';
memset(dsnmem, 0, sizeof(dsnmem));
strcpy(dsnmem, dsn);
strcat(dsnmem, "(");
memset(FNout, 0, sizeof(FNout));
memcpy(FNout, membername, 8);
for (i = 7; i >= 0; i--) {
if (FNout[i] == blank)
FNout[i] = '\0';
else
break;
}
strcat(dsnmem, FNout);
strcat(dsnmem, ")");
strcat(FNout, ".");
strcat(FNout, outext);
for (i = 0; i < strlen(FNout); i++) {
c = tolower(FNout[i]);
FNout[i] = (char) c;
}
if (dbugshowopen)
printf("openout: opening %s\n", FNout);
fout = fopen(FNout, "w");
if (fout) {
outdirpos = assocpos; // save for closeout()
fileswritten++; // accumulate files written
} else {
outdirpos = 0xff; // bad open
printf("Error opening %s for output\n", FNout);
}
return;
} /* openout */
//--------------------------------------------------------------------
//* Close output file, list
int closeout(int prthdr) {
int len;
int dircurlines;
int rc = 0;
char work[FILENAME_MAX];
if (prthdr) {
len = 9 + strlen(outext);
printf("\n");
memset(work, ' ', sizeof(work));
memcpy(work, "output", 6);
work[len] = 0x00;
printf("%s bytes records\n", work);
memset(work, ' ', sizeof(work));
memcpy(work, "filename", 8);
work[len] = 0x00;
printf("%s written written\n", work);
memset(work, '-', len);
work[len] = 0x00;
printf("%s ---------- ----------\n", work);
// printf( "output bytes....records\n");
// printf( "filename written written\n");
// printf( "------------ ---------- ----------\n");
}
if (!fout)
return 0;
if (dbugshowclose)
printf("closeout: closing %s\n", FNout);
fclose(fout);
fout = NULL;
memset(work, ' ', sizeof(work));
memcpy(work, FNout, strlen(FNout));
work[9+strlen(outext)] = 0x00;
printf("%s %10d %10d", work, membyteswritten, memrecswritten);
if (outdirpos == 0xff)
printf(" open err\n");
else {
dircurlines = getvbin(&dir[outdirpos+14], 2); // # lines ISPF says in member
if (dircurlines == memrecswritten)
printf(" OK\n");
else
if (dircurlines == 0)
printf(" ? no ISPF statistics\n");
else {
printf(" error; ISPF statistics records: %d\n", dircurlines);
rc = halt(NULL);
warncounts++;
if (rc)
fatal = 1;
}
}
membyteswritten = 0;
memrecswritten = 0;
nextmem();
if (assocpos < dirlen)
openout();
return rc;
} /* closeout */
//--------------------------------------------------------------------
//* Associate member name with TTR
// IEBCOPY puts the record TTR in each data block header,
// so just need to find it in our list. If we didn't find it, it
// (likely) means we have another block for the same member.
char *assocmem(unsigned int memttr) {
char *p;
int scanpos;
unsigned int curttr;
assocpos = 0;
for (scanpos = 0; scanpos < dirlen; scanpos += FIXED_ENTRY_LENGTH) {
curttr = getvbin( &dir[scanpos+8], 3);
if (curttr == memttr) {
p = &dir[scanpos];
memcpy(membername, p, 8); // copy member name to return
ebcdic2ascii( membername, 8);
p[12] = (char)0xff; // show member used (debug)
assocpos = scanpos; // tell closeout()
return membername;
}
}
return 0;
} /* assocmem */
//--------------------------------------------------------------------
//* Next member
void nextmem() {
dirpos += FIXED_ENTRY_LENGTH;
memcpy(membername, &dir[dirpos], 8); // new member name
ebcdic2ascii(membername, 8); // convert to ASCII
assocpos = dirpos;
return;
} /* nextmem */
//--------------------------------------------------------------------
//* Parse PDS directory block'(s) entries in current IEBCOPY block