-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathjam.rex
executable file
·6770 lines (6095 loc) · 209 KB
/
jam.rex
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
/*REXX*/
/* JAM - Just Another Macro language for z/OS
Copyright (c) 2008-2020, Andrew J. Armstrong
All rights reserved.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Author:
Andrew J. Armstrong <androidarmstrong@gmail.com>
*/
/*REXX*****************************************************************
** **
** NAME - JAM **
** **
** TITLE - JUST ANOTHER MACRO LANGUAGE FOR Z/OS **
** **
** FUNCTION - See the README.md file at: **
** https://github.com/abend0c1/jam **
** **
** AUTHOR - AA - Andrew J. Armstrong <androidarmstrong@gmail.com> **
** **
** HISTORY - Date By Reason (most recent at the top please) **
** -------- --- ----------------------------------------- **
** 20201218 AA Complete rewrite to make it work on Linux **
** and Windows too. **
** 20080401 AA Original version called REXX Server Pages **
** (RSP). **
** **
**********************************************************************/
trace off
parse arg sCmdLine
signal on syntax name onSyntax
numeric digits 22
g. = ''
parse source t1 t2 t3 t4 t4 t6 t7 t8 t9
g.0ZOS = wordpos(t1,'TSO MVS') > 0
g.0NIX = t1 = 'UNIX' | t8 = 'OMVS'
g.0WIN = pos('WIN',t1) > 0
g.0EBCDIC_ENVIRONMENT = g.0ZOS | t8 = 'OMVS' /* Platform is EBCDIC */
select
when g.0ZOS then do
parse arg sCmdLine ' ('sOptions
sCmdLine = strip(sCmdLine)
parse var sCmdLine sFileIn sFileOut .
sFileIn = strip(sFileIn,'BOTH',"'")
parse var sFileIn sDsnIn'('sMemIn')'
sFileOut = strip(sFileOut,'BOTH',"'")
parse var sFileOut sDsnOut'('sMemOut')'
end
when g.0NIX then do
call parseCmdLine sCmdLine,'/'
g.0IN = openFile(sFileIn)
end
when g.0WIN then do
call parseCmdLine sCmdLine,'\'
g.0IN = openFile(sFileIn)
end
otherwise do
say 'JAM0016E Unsupported environment:' t1
exit 4
end
end
call getOptions sOptions
call prolog
/*
*-------------------------------------------------------------------
*
*-------------------------------------------------------------------
*/
sLine = getLogicalLine()
do while g.0RC = 0 & \g.0QUIT
select
/*
*---------------------------------------------------------------
* Define a MACRO
*---------------------------------------------------------------
*/
when g.0MACDEF then do /* We are defining a MACRO */
parse upper var sLine '..' sVerb sAction .
if left(sLine,2) = '..' & sVerb = 'MACRO' & sAction = 'END'
then do
if debug = 1 then call sayDebug sLine
g.0MACDEF = 0 /* Not defining a macro now */
g.0MACRO = '' /* No macro name required */
end
else do
sMacroName = g.0MACRO
nMacroLine = g.0MAC.sMacroName.0 + 1 /* No. of lines so far */
if sVerb = 'INCLUDE'
then do
/* We need to include the lines into the macro definition
because it doesn't work very well to include the lines
when the macro is executed */
call includeInMacro getSub(sAction)
end
else do
g.0MAC.sMacroName.nMacroLine = strip(sLine,'TRAILING')
g.0MAC.sMacroName.0 = nMacroLine
end
end
end
/*
*---------------------------------------------------------------
* Process a JAM statement
*---------------------------------------------------------------
*/
when left(sLine,2) = '..' then do /* Possible JAM statement */
call processStatement
do while g.0RC = 0 & sPendingStatement <> ''
sLine = sPendingStatement
call processStatement
end
call putQueued
end
/*
*---------------------------------------------------------------
* Perform REXX expression substitution
*---------------------------------------------------------------
*/
when g.0EMIT then do /* We are emitting */
select
when sLine = '' then do
if blanks = 1 then queue getSub71(sLine)
end
when left(sLine,3) = '//*' then do
if comments = 1 then queue getSub71(sLine)
end
otherwise queue getSub71(sLine)
end
call putQueued
end
/*
*---------------------------------------------------------------
* Ignore this input line
*---------------------------------------------------------------
*/
otherwise nop /* Not emitting, so do nothing */
end
sLine = getLogicalLine()
end
call Epilog
return
parseCmdLine:
parse arg sFileIn sFileOut '--' sOptions,sPathSep
parse value split(sFileIn, sPathSep, '.'),
with sPathIn 'ff'x sFileNameIn 'ff'x sExtIn
if sFileOut = '-'
then do
sPathout = ''
sFileNameOut = '-'
sExtOut = ''
end
else do
parse value split(sFileOut, sPathSep, '.'),
with sPathOut 'ff'x sFileNameOut 'ff'x sExtOut .
if sPathOut = '' then sPathOut = sPathIn
if sFileNameOut = '' then sFileNameOut = sFileNameIn
if sExtOut = '' then sExtOut = '.txt'
sFileOut = sPathOut || sFileNameOut || sExtOut
end
return
onSyntax:
sSourceLine = strip(sourceline(sigl))
say 'JAM0099I' errortext(rc) 'at line' sigl':' sSourceLine
/* Display the values of some selected variables likely to appear */
if pos('sVarName',sSourceLine) > 0 then say 'JAM0100I sVarName =' sVarName
if pos('sValue' ,sSourceLine) > 0 then say 'JAM0100I sValue =' sValue
if pos('sAction' ,sSourceLine) > 0 then say 'JAM0100I sAction =' sAction
if pos('sExpr' ,sSourceLine) > 0 then say 'JAM0100I sExpr =' sExpr
return ''
getOptions: procedure expose g.
parse upper arg sOptions
do i = 1 to words(sOptions)
sOption = word(sOptions,i)
g.0OPTION.sOption = 1
end
return
emitFile: procedure expose g.
parse arg sFile,sContent
select
when sFile = '-' then do /* terminal */
do queued()
parse pull sLine
say sLine
end
end
when g.0ZOS & isDDName(sFile) then do /* DD:ddname */
parse var sFile 'DD:'sDD .
address TSO 'EXECIO * DISKW' sDD '(FINIS'
end
otherwise do
hFile = openFile(sFile,'OUTPUT')
if g.0RC = 0
then do
say 'JAM0017I Writing' sContent 'to file:' sFile
do queued()
parse pull sLine
call putLine hFile,sLine
end
call closeFile hFile
end
else say 'JAM0015E Could not open' sContent 'file for output:' sFile
end
end
return
quietly: procedure expose g. o.
parse arg sCommand
rc = outtrap('o.')
address TSO sCommand
g.0RC = rc
rc = outtrap('off')
return
/*REXX 2.0.0
Copyright (c) 2009-2020, Andrew J. Armstrong
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the
distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*REXX*****************************************************************
** **
** NAME - IO **
** **
** FUNCTION - Simple I/O routines. **
** **
** API - The routines in this module are: **
** **
** openFile(filename,options,attrs) **
** Opens the specified file with the specified options**
** and returns a file handle to be used in other I/O **
** operations. By default the file will be opened for **
** input. Specify 'OUTPUT' to open it for output. **
** For TSO, you can specify any operand of the TSO **
** ALLOCATE command in the third operand. For example:**
** rc = openFile('MY.FILE','OUTPUT','RECFM(F,B)' **
** 'LRECL(80) BLKSIZE(27920)') **
** **
** closeFile(handle) **
** Closes the file specified by 'handle' (which was **
** returned by the openFile() routine. **
** **
** getLine(handle) **
** Reads the next line from the file specified by **
** 'handle'. **
** **
** putLine(handle,data) **
** Appends the specified data to the file specified **
** by 'handle'. **
** **
** **
** AUTHOR - Andrew J. Armstrong <androidarmstrong+sf@gmail.com> **
** **
** HISTORY - Date By Reason (most recent at the top please) **
** -------- --------------------------------------------- **
** 20090822 AJA Changed from GPL to BSD license. **
** 20061017 AJA Added support for UNIX environment. **
** Tested on Ubuntu Linux 6.06 LTS. **
** 20050930 AJA Initial version. **
** **
**********************************************************************/
parse source . . sSourceFile .
parse value sourceline(1) with . sVersion
say 'Simple REXX I/O routines' sVersion
say 'You cannot invoke this rexx by itself!'
say
say 'This rexx is a collection of subroutines to be called'
say 'from your own rexx procedures. You should either:'
say ' - Append this procedure to your own rexx procedure,'
say ' or,'
say ' - Append the following line to your rexx:'
say ' /* INCLUDE' sSourceFile '*/'
say ' ...and run the rexx preprocessor:'
say ' rexxpp myrexx myrexxpp'
say ' This will create myrexxpp by appending this file to myrexx'
exit
/*-------------------------------------------------------------------*
* Open a file
*-------------------------------------------------------------------*/
openFile: procedure expose g.
parse arg sFile,sOptions,sAttrs
hFile = ''
select
when g.0ENV = 'TSO' then do
bOutput = wordpos('OUTPUT',sOptions) > 0
bQuoted = left(sFile,1) = "'"
if bQuoted then sFile = strip(sFile,,"'")
parse var sFile sDataset'('sMember')'
if sMember <> '' then sFile = sDataset
if bQuoted then sFile = "'"sFile"'"
if bOutput
then 'LMINIT DATAID(hFile) DATASET(&sFile) ENQ(EXCLU)'
else 'LMINIT DATAID(hFile) DATASET(&sFile)'
if sMember <> ''
then do /* Open a member of a PDS */
'LMOPEN DATAID(&hFile) OPTION(INPUT)' /* Input initially */
/* ...can't update ISPF stats when opened for output */
g.0MEMBER.hFile = sMember
'LMMFIND DATAID(&hFile) MEMBER('sMember') STATS(YES)'
if bOutput
then do
if rc = 0
then g.0STATS.hFile = zlvers','zlmod','zlc4date
else g.0STATS.hFile = '1,0,0000/00/00'
'LMCLOSE DATAID(&hFile)'
'LMOPEN DATAID(&hFile) OPTION(&sOptions)'
end
end
else do /* Open a sequential dataset */
'LMOPEN DATAID(&hFile) OPTION(&sOptions)'
if rc <> 0 /* If dataset does not already exist... */
then do /* Create sequential dataset then open it */
'LMCLOSE DATAID(&hFile)'
'LMFREE DATAID(&hFile)'
address TSO 'ALLOCATE DATASET('sFile') NEW CATALOG',
'SPACE(5,15) TRACKS RECFM(V,B)',
'LRECL('g.0OPTION.WRAP.1 + 4')',
'BLKSIZE(27990)' sAttrs
if bOutput
then do
'LMINIT DATAID(hFile) DATASET(&sFile) ENQ(EXCLU)'
'LMOPEN DATAID(&hFile) OPTION(&sOptions)'
end
else do
'LMINIT DATAID(hFile) DATASET(&sFile)'
'LMOPEN DATAID(&hFile) OPTION(INPUT)'
end
end
end
g.0OPTIONS.hFile = sOptions
g.0rc = rc /* Return code from LMOPEN */
end
otherwise do
if wordpos('OUTPUT',sOptions) > 0
then junk = stream(sFile,'COMMAND','OPEN WRITE REPLACE')
else junk = stream(sFile,'COMMAND','OPEN READ')
hFile = sFile
if stream(sFile,'STATUS') = 'READY'
then g.0rc = 0
else g.0rc = 4
end
end
return hFile
/*-------------------------------------------------------------------*
* Read a line from the specified file
*-------------------------------------------------------------------*/
getLine: procedure expose g.
parse arg hFile
sLine = ''
select
when g.0ENV = 'TSO' then do
'LMGET DATAID(&hFile) MODE(INVAR)',
'DATALOC(sLine) DATALEN(nLine) MAXLEN(32768)'
g.0rc = rc
sLine = strip(sLine,'TRAILING')
if sLine = '' then sLine = ' '
end
otherwise do
g.0rc = 0
if chars(hFile) > 0
then sLine = linein(hFile)
else g.0rc = 4
end
end
return sLine
/*-------------------------------------------------------------------*
* Append a line to the specified file
*-------------------------------------------------------------------*/
putLine: procedure expose g.
parse arg hFile,sLine
select
when g.0ENV = 'TSO' then do
g.0LINES = g.0LINES + 1
'LMPUT DATAID(&hFile) MODE(INVAR)',
'DATALOC(sLine) DATALEN('length(sLine)')'
end
otherwise do
junk = lineout(hFile,sLine)
rc = 0
end
end
return rc
/*-------------------------------------------------------------------*
* Close the specified file
*-------------------------------------------------------------------*/
closeFile: procedure expose g.
parse arg hFile
rc = 0
select
when g.0ENV = 'TSO' then do
if g.0MEMBER.hFile <> '', /* if its a PDS */
& wordpos('OUTPUT',g.0OPTIONS.hFile) > 0 /* opened for output */
then do
parse value date('STANDARD') with yyyy +4 mm +2 dd +2
parse var g.0STATS.hFile zlvers','zlmod','zlc4date
zlcnorc = min(g.0LINES,65535) /* Number of lines */
nVer = right(zlvers,2,'0')right(zlmod,2,'0') /* vvmm */
nVer = right(nVer+1,4,'0') /* vvmm + 1 */
parse var nVer zlvers +2 zlmod +2
if zlc4date = '0000/00/00'
then zlc4date = yyyy'/'mm'/'dd /* Creation date */
zlm4date = yyyy'/'mm'/'dd /* Modification date */
zlmtime = time() /* Modification time */
zluser = userid() /* Modification user */
'LMMREP DATAID(&hFile) MEMBER('g.0MEMBER.hFile') STATS(YES)'
end
'LMCLOSE DATAID(&hFile)'
'LMFREE DATAID(&hFile)'
end
otherwise do
if stream(hFile,'COMMAND','CLOSE') = 'UNKNOWN'
then rc = 0
else rc = 4
end
end
return rc
includeInMacro: procedure expose g. dataset
i.0 = 0
if g.0ZOS
then do
parse upper arg sDataset
sDSN = getFileName(sDataset)
sFileStatus = sysdsn("'"sDSN"'")
if sFileStatus = 'OK'
then do
call quietly "ALLOCATE FILE(INC) DSNAME('"sDSN"') INPUT SHR REUSE"
'EXECIO * DISKR INC (FINIS STEM i.'
call quietly 'FREE FILE(INC)'
end
else do
say 'JAM002W Could not read dataset:' sDSN '-' sFileStatus
end
end
else do
parse arg sFileName
call readIntoStem sFileName
end
if i.0 > 0 /* If there are any lines to include */
then do
sMacroName = g.0MACRO
do i = 1 to i.0
if g.0ZOS then i.i = normaliseSquareBrackets(i.i)
parse upper var i.i 1 sPrefix +2 1 . sVerb sDataset .
if sPrefix = '..' & sVerb = 'INCLUDE'
then do
call includeInMacro sDataset
end
else do
nMacroLine = g.0MAC.sMacroName.0 + 1
g.0MAC.sMacroName.nMacroLine = strip(i.i,'TRAILING')
g.0MAC.sMacroName.0 = nMacroLine
end
end
end
return
readIntoStem: procedure expose g. i.
parse arg sFileName
i.0 = 0
hFile = openFile(sFileName)
if g.0RC = 0
then do
sLine = getLine(hFile)
do i = 1 while g.0RC = 0
i.0 = i
i.i = sLine
sLine = getLine(hFile)
end
call closeFile(hFile)
end
else do
say 'JAM002W Could not read file:' sFileName
end
return
putQueued:
if g.0ZOS
then 'EXECIO' queued() 'DISKW OUT'
return
getLogicalLine: procedure expose g. trunc
/* Get the next logical input line (collapse continuations) */
sLine = getNextLine()
if \g.0MACDEF /* If we are not currently defining a macro */
then do /* Process continuations */
g.0CHAINED = 0 /* Set if 2+ commands are to be run as one step */
g.0CONT = 0 /* Set if a command extends to the next line */
if left(sLine,2) = '..'
then do
if trunc = 1 /* If user wants input truncated to 71 characters */
then sLine = strip(left(sLine,71),'TRAILING')
else sLine = strip( sLine ,'TRAILING')
parse var sLine '..' c .
bNotComment = left(c,1) <> '.'
sLastChar = right(sLine,1)
g.0CHAINED = sLastChar = ',' & bNotComment /* Don't chain comments */
g.0CONT = sLastChar = '-' & bNotComment /* Don't continue comments */
if g.0CHAINED | g.0CONT
then sLine = left(sLine,length(sLine)-1) /* Remove continuation */
do while g.0CONT & g.0RC = 0 /* Accumulate line continuations */
sNextLine = getLogicalLine() /* TODO: must this be recursive? */
if g.0RC = 0
then do
parse var sNextLine 3 sNextLine
sLine = sLine || strip(sNextLine)
end
end
end
end
return sLine
getNextLine: procedure expose g.
/* Get the next input line (high to low priority) as follows:
- the next override line for the current macro line (if any)
- the next line from the current macro (if any)
- the next line from the last INCLUDE operation (if any)
- the next line from the file currently being EDITed or VIEWed (if z/OS)
- the next line from the DD named IN (if z/OS)
- the next line from the file named in g.0IN (if not z/OS)
*/
g.0RC = 0
select
when g.0MACRUN then do /* if running a macro */
/* retrieve next line of the macro */
sName = g.0MACRO /* current macro name */
nLine = g.0MACLINE /* current line within that macro */
nOvers = g.0MAC.sName.nLine.0 /* number of overrides for this line */
/* don't advance the macro line until all overrides are processed */
if nOvers <> '' & g.0MAC.sName.nLine.0# < nOvers
then do /* return next override line for this macro line */
nOver = g.0MAC.sName.nLine.0# + 1
g.0MAC.sName.nLine.0# = nOver
sLine = g.0MAC.sName.nLine.nOver
end
else do /* return the next line of the current macro */
g.0MACLINE = g.0MACLINE + 1
do while g.0MACRUN & g.0MACLINE > g.0MAC.sName.0 /* at macro end */
g.0MACRUN.sName = 0 /* Not running this macro anymore */
call removeOverrides sName
parse value popStack() with sClause g.0EMIT g.0MACLINE g.0MACRO
sName = g.0MACRO
if sName = '' /* if there is no invoking macro */
then g.0MACRUN = 0 /* not running a macro now */
else do
nLine = g.0MACLINE
nOvers = g.0MAC.sName.nLine.0
if nOvers <> '' & g.0MAC.sName.nLine.0# < nOvers
then do
end
else do
g.0MACLINE = g.0MACLINE + 1 /* next line of parent macro */
end
end
end
if g.0MACRUN /* we are still running a macro */
then do
nLine = g.0MACLINE /* progress within this macro */
nOvers = g.0MAC.sName.nLine.0
if nOvers <> '' & g.0MAC.sName.nLine.0# < nOvers
then do /* return next override line for this macro line */
nOver = g.0MAC.sName.nLine.0# + 1
g.0MAC.sName.nLine.0# = nOver
sLine = g.0MAC.sName.nLine.nOver
end
else do
sLine = g.0MAC.sName.nLine
end
end
else sLine = getNextInputLine()
end
end
otherwise sLine = getNextInputLine()
end
g.0ERRLINE = sLine
return sLine
getNextInputLine: procedure expose g.
select
when g.0INCLO <= g.0INCHI then do
n = g.0INCLO
sLine = g.0INC.n /* retrieve next INCLUDEd line */
drop g.0INC.n
g.0INCLO = n + 1
end
when g.0EDITENV then do /* only on z/OS */
/* retrieve next line from file being edited */
g.0LINE = g.0LINE + 1
address ISREDIT '(sLine) = LINE' g.0LINE
g.0RC = rc
end
when g.0ZOS then do /* retrieve next line from IN DD */
'EXECIO 1 DISKR IN (STEM d.'
g.0RC = rc
sLine = d.1
end
otherwise do /* retrieve next line from disk file */
sLine = getLine(g.0IN)
end
end
if g.0ZOS
then sLine = normaliseSquareBrackets(sLine)
return sLine
normaliseSquareBrackets: procedure expose g.
/* Convert IBM037 or IBM1047 square brackets to whatever
encoding is used by THIS rexx implementation */
parse arg sLine
return translate(sLine,'[][]','babbadbd'x)
getSub71:
if trunc = 0 then return getSub(sLine)
parse arg sLine +71 sRest
return left(getSub(sLine),71) || sRest
getSub:
parse arg sSubLine
sSubLine = hardBrackets(sSubLine)
sOut = ''
nBeg = pos('[',sSubLine)
nEnd = pos(']',sSubLine)
if nBeg > 0 & nEnd = 0
then say 'JAM006W Missing terminating bracket:' g.0ERRLINE
do while nBeg > 0 & nBeg < nEnd
parse var sSubLine sBefore'['sExpr']'sSubLine
if right(strip(sExpr),1) = '?'
then do
sExpr = strip(strip(sExpr),'TRAILING','?')
parse var sExpr sVarName sPrompt
if sPrompt <> ''
then say sPrompt':'
else say 'Enter' sVarName':'
parse pull sValue
interpret sVarName "= '"toStr(sValue)"'"
end
else interpret 'sValue =' sExpr
cLeft = left(sExpr,1)
cRight = right(sExpr,1)
nWidth = length(sExpr)+2 /* +2 for the surrounding [ and ] */
select
when cLeft = ' ' & cRight = ' ' then do /* centre output */
sValue = centre(sValue,nWidth)
end
when cLeft = ' ' then do /* right justify */
sValue = right(sValue,nWidth)
end
when cRight = ' ' then do /* left justify */
sValue = left(sValue,nWidth)
end
otherwise nop
end
sOut = sOut || sBefore || sValue
nBeg = pos('[',sSubLine)
nEnd = pos(']',sSubLine)
if nBeg > 0 & nEnd = 0
then say 'JAM006W Missing terminating bracket:' g.0ERRLINE
end
if length(sSubLine) > 0 then sOut = sOut || sSubLine
return strip(softBrackets(sOut),'TRAILING')
hardBrackets: procedure
/* Convert double brackets to "hard" brackets: 'FB'x and 'FE'x */
parse arg sLine
if pos('[[',sLine) > 0
then sLine = replace('[[','FB'x,sLine) /* Insert hard Begin brackets */
if pos(']]',sLine) > 0
then sLine = replace(']]','FE'x,sLine) /* Insert hard End brackets */
return sLine
softBrackets: procedure expose ibm1047 g.
/* Convert hard brackets to either IBM1047 or IBM037 square brackets */
parse arg sLine
if g.0ZOS
then do
if ibm1047 = 1
then sLine = translate(sLine,'ADBD'x,'FBFE'x) /* Code page IBM1047 */
else sLine = translate(sLine,'BABB'x,'FBFE'x) /* Code page IBM037 */
end
else sLine = translate(sLine,'[]','FBFE'x) /* Native encoding */
return sLine
processStatement:
parse var sLine '..'sStatement
sVerb = word(sStatement,1)
/* Slurp up any continuations that are the same as this verb */
sPendingStatement = ''
bResidue = 0
g.0 = 1
g.1 = getSub(sStatement)
if debug = 1 then call sayDebug '..'g.1
do i = 2 while g.0CHAINED
sLine = getLogicalLine()
if left(sLine,2) = '..'
then do
parse var sLine '..'sStatement
sNextVerb = word(sStatement,1)
if sNextVerb = sVerb /* e.g. must continue a COPY to another COPY */
then do
g.0 = i
g.i = getSub(sStatement)
if debug = 1 then call sayDebug '..'sStatement
end
else do
g.0CHAINED = 0
sPendingStatement = '..'sStatement
end
end
else do
bResidue = 1 /* A JAM statement was chained to a */
sResidue = sLine /* non-JAM statement line */
g.0CHAINED = 0
end
end
/* Now action the verb */
upper sVerb
if g.0EMIT | inSet(sVerb,'IF ELSE END SELECT WHEN OTHERWISE')
then do
select
when sVerb = '.' then call doJAMComment
when sVerb = '*' then call doComment
when sVerb = 'ARGS' then call doArgs
when sVerb = 'ASK' then call doAsk
when sVerb = 'ASKQ' then call doAsk
when sVerb = 'ASKQU' then call doAsk
when sVerb = 'ASKU' then call doAsk
when sVerb = 'AUTO' then call doAuto
when sVerb = 'BACKUP' then call doBackup
when sVerb = 'BR14' then call doBR14
when sVerb = 'CATALOG' then call doCatalog
when sVerb = 'COMPRESS' then call doCompress
when sVerb = 'COPY' then call doCopy
when sVerb = 'DATEVARS' then call doDateVars
when sVerb = 'DELETE' then call doDelete
when sVerb = 'ELSE' then call doElse
when sVerb = 'EMPTY' then call doEmpty
when sVerb = 'END' then call doEnd
when sVerb = 'FOR' then call doFor
when sVerb = 'GET' then call doGet
when sVerb = 'GETOUT' then call doGetOut
when sVerb = '?' then call doHelp
when sVerb = 'HELP' then call doHelp
when sVerb = 'IF' then call doIf
when sVerb = 'INCLUDE' then call doInclude
when sVerb = 'JCL' then call doJCL
when sVerb = 'JOB' then call doJob
when sVerb = 'LISTCAT' then call doListcat
when sVerb = 'LISTVTOC' then call doListVTOC
when sVerb = 'MACRO' then call doMacro
when sVerb = 'MAP' then call doMap
when sVerb = 'MOUNT' then call doMount
when sVerb = 'OPTION' then call doOption
when sVerb = 'OTHERWISE' then call doOtherwise
when sVerb = 'PUT' then call doPut
when sVerb = 'QUEUE' then call doQueue
when sVerb = 'QUEUED' then call doQueued
when sVerb = 'QUIT' then call doQuit
when sVerb = 'RECOVER' then call doRecover
when sVerb = 'RENAME' then call doRename
when sVerb = 'REPRO' then call doRepro
when sVerb = 'RESTORE' then call doRestore
when sVerb = 'REXX' then call doREXX
when sVerb = 'RUNON' then call doRunOn
when sVerb = 'SAY' then call doSay
when sVerb = 'SCRATCH' then call doScratch
when sVerb = 'SELECT' then call doSelect
when sVerb = 'SET' then call doSet
when sVerb = 'SHIP' then call doShip
when sVerb = 'STEP' then call doStep
when sVerb = 'STYLE' then call doStyle
when sVerb = 'SUBMIT' then call doSubmit
when sVerb = 'SUDO' then call doSudo
when sVerb = 'TSO' then call doTSO
when sVerb = 'TABLE' then call doTable
when sVerb = 'UNCATALOG' then call doUncatalog
when sVerb = 'UNMOUNT' then call doUnmount
when sVerb = 'USS' then call doUSS
when sVerb = 'WHEN' then call doWhen
when sVerb = 'XEQ' then call doXEQ
when sVerb = 'XMIT' then call doXmit
otherwise queue sLine /* Ignore unknown verb */
end
if bResidue
then queue getSub(sResidue)
end
return
sayDebug: procedure expose g.
parse arg sDebugMessage
sDebugMessage = translate(sDebugMessage,'<>','[]')
if g.0EMIT
then say '|'sDebugMessage /* We are emitting this line */
else say '-'sDebugMessage /* We are supressing this line */
return
queueHelpForVerb: procedure expose g.
parse upper arg sVerb .
sLogicalLine = ''
do i = g.0HELPBEG.sVerb to g.0HELPEND.sVerb
sInputLine = replace('*','*',sourceline(i))
nInputLine = length(sInputLine)
if nInputLine > 0
then do
if right(sInputLine,1) = '+' /* If input line is continued */
then do
sLogicalLine = sLogicalLine || left(sInputLine, nInputLine-1)
end
else do /* Input line is not continued */
queue sLogicalLine || sInputLine
sLogicalLine = ''
end
end
else do
queue sLogicalLine
end
end
if length(sLogicalLine) > 0
then queue slogicalline
return
queueHelpFromLabel: procedure
parse arg sLabel
do i = 1 until sourceline(i) = sLabel
end
sLogicalLine = ''
do i = i+2 while sourceline(i) <> '*/'
sInputLine = sourceline(i)
nInputLine = length(sInputLine)
if nInputLine > 0
then do
if right(sInputLine,1) = '+' /* If input line is continued */
then do
sLogicalLine = sLogicalLine || left(sInputLine, nInputLine-1)
end
else do /* Input line is not continued */
queue sLogicalLine || sInputLine
sLogicalLine = ''
end
end
else do
queue sLogicalLine
end
end
if length(sLogicalLine) > 0
then queue slogicalline
return
doJAMComment:
/*
### ... [JAM comment]
This is used to add comments to a JAM input file. These comments
are ignored by the JAM processor and do not produce any output.
For example, the following simply builds a job card and ignores the
preceding comments:
...
... Build a job card
...
.. job
*/
parse var g.1 . sParms .
if sParms = '?'
then call queueHelpForVerb 'JAMComment'
return
doComment:
/*
### ..* [comment]
This will generate a comment using the specified comment text.
The default comment style is `jcl`. Other built-in
styles available include `asm`, `box`, `c`, `js`, `rexx`, and `xml`.
Styles can be added or updated by using the `..style` JAM verb.
For example:
..style xml
..* This is an XML comment
..style jcl
..* This is a JCL comment
generates:
<!--
This is an XML comment
-->
//*
//*------------------------------------------------------------------*
//* This is a JCL comment *
//*------------------------------------------------------------------*
//*
*/
parse var g.1 . sComment
if sComment = '?'
then call queueHelpForVerb 'Comment'
else do
sStyle = g.0STYLE
sFirst = g.0STYLE_FIRST.sStyle
sBorderLeft = g.0STYLE_BORDER_LEFT.sStyle
sBorderFill = g.0STYLE_BORDER_FILL.sStyle
sBorderRight = g.0STYLE_BORDER_RIGHT.sStyle
sLeft = g.0STYLE_LEFT.sStyle
sRight = g.0STYLE_RIGHT.sStyle
sLast = g.0STYLE_LAST.sStyle
nWidth = g.0STYLE_WIDTH.sStyle
nInternalWidth = nWidth - length(sRight)
if nInternalWidth <= 0 then nInternalWidth = nWidth
nMaxWidth = nInternalWidth - length(sLeft) - 2
if length(sBorderFill) > 0 /* If top and bottom borders are required */
then sBorder = left(sBorderLeft,nInternalWidth,,
left(sBorderFill,1))sBorderRight
else sBorder = '' /* else don't output a border */
if length(sFirst) > 0 then queue sFirst
if length(sBorder) > 0 then queue sBorder
do i = 1 to g.0
parse var g.i . sComment
do until length(sComment) = 0
if substr(sComment,nMaxWidth,1) = ' '
then do /* word boundary */
parse var sComment sChunk +(nMaxWidth) sComment
end
else do /* backoff to previous whole word */
nLastBlank = lastpos(' ',sComment,nMaxWidth)
if nLastBlank = 0 /* no word break, so we have to split */
then parse var sComment sChunk +(nMaxWidth) sComment
else parse var sComment sChunk +(nLastBlank) sComment
end
queue left(sLeft sChunk,nInternalwidth)sRight
sComment = strip(sComment)
end
end
if length(sBorder) > 0 then queue sBorder
if length(sLast) > 0 then queue sLast
end
return
addJCLComment: procedure expose g.
parse arg sComment