4646 /* */
4747 /* */
4848 /*----------------------------------------------------------*/
49-
5049/* Is TXTRPLCE allocated? If yes, then turn on Trace */
5150 isItThere = ,
5251 BPXWDYN ( "INFO FI(TXTRPLCE) INRTDSN(DSNVAR) INRDSNT(myDSNT)" )
5352 If isItThere = 0 then TraceRc = 'Y'
54-
5553 /* A processor provides these Endevor values as arguments */
5654 ARG Reference OnStack
57-
5855 /* INPUTS are optional, but can name dataset names */
5956 /* for OLDTXT and NEWTXT */
6057 isItThere = ,
6966 End ; /* Do in# = 1 to inp.0 */
7067 If OLDTXT = '' then ,
7168 Do
72- say 'TXTRPLCE: Execting an assignment for OLDTXT'
69+ say 'TXTRPLCE: Expecting an assignment for OLDTXT'
7370 Exit ( 12 )
7471 End ; /* If OLDTXT = ''*/
7572 If NEWTXT = '' then NEWTXT = OLDTXT
7875 String = "ALLOC DD(NEWTXT) DA(" NEWTXT ") SHR REUSE"
7976 CALL BPXWDYN STRING ;
8077 End ; /* If isItThere = 0 */
81-
8278 /* Set Defaults / initial values.... */
8379 $numbers = '0123456789' /* chars for numeric values */
8480 AlphaChars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
8581 $OptionCommentChar = '*'
8682 ShowReplaceResults = 'Y'
8783 TXT. = ''
8884 OptionsType = 'REXX'
89-
9085 Drop MaxReturnCode
9186 TXT.Reference.MaxReturnCode = 4 /* Value for MaxReturncode */
9287 TXT.Reference.where. = 'AFTER' /* either BEFORE/AFTER */
9691 TXT.Reference.REPLACE. = ''
9792 TXT.Reference.Insertx. = ''
9893 TXT.Reference.InsertAtEnd. = ''
99-
10094 NumberInstructions = 0 ; /* Assume zero, unless we find some*/
101-
10295 If TraceRc = 'Y' then Trace r
10396 /* Get Options for tailoring and processing the JCL */
10497 /* If Options are in a YAML format, comment the 1st line */
10598 /* If no Options are designated for Reference, then exit */
10699 If OnStack /= 'Stack' &,
107100 OnStack /= 'STACK' then ,
108101 Call ProcessInputOptions ; /* Must read and validate them */
109-
110102 /* At this point, OPTIONS statements are validated as OK, */
111103 /* and are found on the stack... */
112104 NumberInstructions = QUEUED ()
113105 If NumberInstructions = 0 then ,
114106 Do
115107 Say 'TXTRPLCE: finds no instructions for tailoring'
116- Exit
108+ Exit ( 4 )
117109 End
118110 Do optCount = 1 to NumberInstructions
119111 Parse pull nextOption
120112 If TraceRc = 'Y' then ,
121113 Say 'TXTRPLCE:' nextOption
122114 interpret nextOption
123115 End ;
124-
125116 /* Using Options tailor the JCL */
126117 /* Yaml converted options are a bit different */
127118 If OptionsType = 'YAML' then ,
128119 Call TailorNEWTXTfromOldViaYaml ;
129120 Else
130121 Call TailorNEWTXTfromOldViaOptions ;
131-
132122 If TraceRc = 'Y' then ,
133123 Say 'TXTRPLCE: exiting '
134-
135124 Exit ( 1 ) ; /* Successful update */
136-
137125ProcessInputOptions:
138-
139126 /* Determine from 1st record if OPTIONS are in YAML format */
140127 If TraceRc = 'Y' then Trace r
141128 "EXECIO 1 DISKR OPTIONS " /* may be in Rexx or Yaml format*/
@@ -158,24 +145,54 @@ ProcessInputOptions:
158145 what = OPTVALDT ( OPTIONS Y )
159146 OptionsType = 'Rexx'
160147 End ; /* If Substr(FirstOption,1,1) = '%' */
161-
148+ isItThere = ,
149+ BPXWDYN ( "INFO FI(VARIABLE) INRTDSN(DSNVAR) INRDSNT(myDSNT)" )
150+ If isItThere = 0 then Call Process_VARIABLE_input
162151 NumberInstructions = QUEUED ()
163152 Return ;
164-
153+ Process_VARIABLE_input:
154+ /* Read the VARIABLE data (variables provided by Endevor) */
155+ /* Variables can be mixture of C1* variables of Endevor, */
156+ /* processor variables and Site Symbol variables. */
157+ /* Append new instructions onto the Stack */
158+ "EXECIO * DISKR VARIABLE ( Stem var. Finis"
159+ If OptionsType = 'YAML' then ,
160+ VarPrefix = 'TXT.' Reference '.Change'
161+ Else ,
162+ VarPrefix = 'TXT.' Reference
163+ indx# = QUEUED () + 1
164+ Do v# = 1 to var.0
165+ ndvrVariable = var.v#
166+ whereText = WordIndex ( ndvrVariable , 1 )
167+ if whereText = 0 then Iterate ;
168+ If Substr ( ndvrVariable , whereText , 1 ) = '#' |,
169+ Substr ( ndvrVariable , whereText , 1 ) = '*' then Iterate ;
170+ PARSE VAR ndvrVariable $keyword "=" $keyValue
171+ $keyword = Strip ( $keyword )
172+ $keyValue = Strip ( $keyValue )
173+ Queue VarPrefix ".Findtxt." indx# "='&" $keyword "'"
174+ Queue VarPrefix ".Replace." indx# "=" $keyValue
175+ If TraceRc = 'Y' then ,
176+ Do
177+ Say 'TXTRPLCE:'
178+ Say VarPrefix ".Findtxt." indx# "='&" $keyword "'"
179+ Say VarPrefix ".Replace." indx# "=" $keyValue
180+ End
181+ indx# = indx# + 1
182+ End ; /* Do v# = 1 to var.0 */
183+ say VarPrefix ".Findtxt.0=" indx#
184+ Queue VarPrefix ".Findtxt.0=" indx#
185+ Return ;
165186TailorNEWTXTfromOldViaYaml:
166-
167187 /* Read the OLDTXT file */
168188 "EXECIO * DISKR OLDTXT ( Stem txtrec. Finis"
169-
170189 /* If anything is to be inserted at End, do it here */
171190 Do j# = 1 to txtrec.0
172191 If TXT.Reference.InsertAtEnd.j# = '' then leave ;
173192 txtrec# = txtrec.0 + 1 ;
174193 txtrec.txtrec# = TXT.Reference.InsertAtEnd.j#
175194 txtrec.0 = txtrec#
176195 End ; /* Do j# = 1 to txtrec.0 */
177-
178-
179196 /* Scan each record of the text file */
180197 Do j# = 1 to txtrec.0
181198 textline = txtrec.j#
@@ -198,17 +215,14 @@ TailorNEWTXTfromOldViaYaml:
198215 If newDDnameTxt /= '' then ,
199216 Do ; Call ReplaceDDname ; Iterate ; end ;
200217 End /* If Substr(textline,1,2) = '//' & ... */
201-
202218/* If TraceRc = 'Y' then Trace r */
203219 textline = txtrec.j#
204-
205220 /* Execute the Search and replace string actions */
206221 Do rpl# = 1 to NumberInstructions
207222 findString = TXT.Reference.Change.FindTxt.rpl#
208223 If findString = '' then iterate ;
209224 whereTxt = Pos ( findString , textline )
210225 If whereTxt = 0 then iterate ;
211-
212226 replaceString = TXT.Reference.Change.Replace.rpl#
213227 If replaceString /= '' then ,
214228 Do
@@ -222,18 +236,15 @@ TailorNEWTXTfromOldViaYaml:
222236 If insertWhere /= 'BEFORE' then ,
223237 insertWhere = 'AFTER'
224238 Saved_textline = textline
225-
226239 If inserttextlines /= '' &,
227240 ShowReplaceResults = 'Y' then ,
228241 Say 'Inserting Text lines' insertWhere ,
229242 findString
230-
231243 If insertWhere = 'AFTER' then ,
232244 Do
233245 Queue textline
234246 thistextlineQueued = 'Y'
235247 End
236-
237248 Do yamlcounter = 1 to NumberInstructions
238249 textline =,
239250 TXT.Reference.Change.Insertx.rpl#.yamlcounter
@@ -243,27 +254,20 @@ TailorNEWTXTfromOldViaYaml:
243254 Say " In:" textline
244255 Queue textline
245256 End /* Do yamlcounter = 1 to $Opts.0 */
246-
247257 If insertWhere /= 'AFTER' then ,
248258 Queue Saved_textline
249259 End /* else .. If replaceString /= '' */
250-
251260 End ; /* Do rpl# = 1 to NumberInstructions */
252261 /* Write line of JCL to output */
253-
254262 If thistextlineQueued /= 'Y' then ,
255263 Do
256264 Call ReplaceVariablesOnly ;
257- Queue textline
265+ If textline /= '' then Queue textline
258266 End
259267 End ; /* Do j# = 1 to txtrec.0 */
260-
261268 "EXECIO" QUEUED () "DISKW NEWTXT ( Finis"
262-
263269 Return ;
264-
265270TailorNEWTXTfromOldViaOptions:
266-
267271 /* Read the OLDTXT file */
268272 "EXECIO * DISKR OLDTXT ( Stem txtrec. Finis"
269273 /* Scan each record of the JCL */
@@ -288,10 +292,8 @@ TailorNEWTXTfromOldViaOptions:
288292 If newDDnameTxt /= '' then ,
289293 Do ; Call ReplaceDDname ; Iterate ; end ;
290294 End
291-
292295/* If TraceRc = 'Y' then Trace r */
293296 textline = txtrec.j#
294-
295297 /* Execute the Search and replace string actions */
296298 Do rpl# = 1 to NumberInstructions
297299 findString = TXT.Reference.FindTxt.rpl#
@@ -325,20 +327,15 @@ TailorNEWTXTfromOldViaOptions:
325327 End /* else .. If replaceString /= '' */
326328 End ; /* Do rpl# = 1 to NumberInstructions */
327329 /* Write line of TXT to output */
328-
329330 If thistextlineQueued /= 'Y' then ,
330331 Do
331332 Call ReplaceVariablesOnly ;
332333 Queue textline
333334 End
334335 End ; /* Do j# = 1 to txtrec.0 */
335-
336336 "EXECIO" QUEUED () "DISKW NEWTXT ( Finis"
337-
338337 Return ;
339-
340338ReplaceDDname:
341-
342339/* If TraceRc = 'Y' then Trace r */
343340 If ShowReplaceResults = 'Y' then ,
344341 Say 'TXTRPLCE: Replacing the Step' thisStepName 'DDname' ,
@@ -388,14 +385,10 @@ ReplaceDDname:
388385 "EXECIO 2 DISKW ERRORS (Finis"
389386 Exit ( 12 )
390387 End /* Else */
391-
392388 j# = j# + 1 ;
393389 Call SkiptoNextLabel ;
394-
395390 Return
396-
397391SkiptoNextLabel:
398-
399392 SkipThirdChars = ' *'
400393 /* Find next JCL line with a label in position 3 */
401394 Do forever
@@ -410,11 +403,8 @@ SkiptoNextLabel:
410403 End ;
411404 j# = j# + 1 ;
412405 End ; /* Do forever */
413-
414406 Return
415-
416407ReplaceText:
417-
418408 Saved_textline = textline ;
419409 If whereTXT = 1 then ,
420410 textline = replaceString || ,
@@ -423,7 +413,6 @@ ReplaceText:
423413 textline = substr ( textline , 1 ,( whereTXT - 1 )) ||,
424414 replaceString || ,
425415 substr ( textline , whereTXT + Length ( findString ))
426-
427416 If ShowReplaceResults = 'Y' then ,
428417 Do
429418 Say "Txt line" j# "Changed:"
@@ -433,11 +422,8 @@ ReplaceText:
433422 Else ,
434423 Say " AF:***not-shown***"
435424 End
436-
437425 Return
438-
439426ReplaceVariablesOnly:
440-
441427 Do upd# = 1 to NumberInstructions
442428 If OptionsType = 'YAML' then ,
443429 Do
@@ -455,11 +441,8 @@ ReplaceVariablesOnly:
455441 If whereTxt = 0 then iterate ;
456442 Call ReplaceText ;
457443 End ; /* Do upd# = 1 to NumberInstructions */
458-
459444 Return
460-
461445Inserttextlines:
462-
463446 /* Apply Search and Replace actions to inserted lines */
464447 Save_textline = textline ;
465448 textline = inserttextlines
@@ -472,12 +455,9 @@ Inserttextlines:
472455 If replaceString /= '' then ,
473456 Call ReplaceText ;
474457 End ; /*Do rpl# = 1 to NumberInstructions */
475-
476458 inserttextlines = textline /* line(s) to be inserted */
477459 textline = Save_textline /* The line that triggered insert */
478-
479460 leadingSlashSlash = Pos ( '//' , inserttextlines )
480-
481461 If leadingSlashSlash = 1 then , /* Yes // in new jcl lines */
482462 Do Forever
483463 whereNextSlashSlash = Pos ( '//' , inserttextlines , 3 )
@@ -499,7 +479,4 @@ Inserttextlines:
499479 "EXECIO 2 DISKW ERRORS (Finis"
500480 Exit ( 12 )
501481 End /* Else */
502-
503-
504482 Return
505-
0 commit comments