/* REXX */ /* */ /* AUTHOR: MARK ZELDEN */ /* */ /* Last Updated 08/23/2007 */ /* */ /* TRACE ?R */ Address ISREDIT "MACRO (parm type label1 label2)" /* Address ISPEXEC "CONTROL ERRORS RETURN" */ /***************************************************************/ /* */ /* This edit macro will insert a character string either */ /* AFTER or BEFORE all or specified lines. Excluded lines */ /* are always omitted. If "PASTE" is used as the first */ /* parm passed to the Macro (in place of a character string), */ /* the macro will insert lines that were previously "CUT" */ /* from the ISPF Default Clipboard. Note that you must be */ /* running ISPF 4.8 (OS/390 2.8) or above to use the "PASTE" */ /* option. */ /* */ /***************************************************************/ /* COMMAND SYNTAX: */ /* */ /* INSLINE 'data to insert' < A | B > (.label1) (.label2) */ /* INSLINE PASTE < A | B > (.label1) (.label2) */ /* */ /***************************************************************/ /* INSERT "AFTER" EXAMPLES */ /* INSLINE 'insert this after every line' A */ /* INSLINE 'insert this after every line' A .FROM .TO */ /* INSLINE PASTE A .FROM .TO */ /* */ /* INSERT "BEFORE" EXAMPLES */ /* INSLINE 'insert this before every line' B */ /* INSLINE 'insert this before every line' B .FROM .TO */ /* INSLINE PASTE B .FROM .TO */ /* */ /***************************************************************/ /***********************************************/ /* VERIFY INPUT PARAMETERS */ /***********************************************/ type = Translate(type) /* ensure upper case */ If parm = '' then do zedsmsg = 'No insert data' zedlmsg = 'You must specify the data to insert', 'as the first parameter or "PASTE".' Address ISPEXEC "SETMSG MSG(ISRZ001)" /* msg - with alarm */ Exit 12 End If type = '' then do zedsmsg = 'No insert type' zedlmsg = 'You must specify an insert type of "A"', 'or "B" as the second parameter.' Address ISPEXEC "SETMSG MSG(ISRZ001)" /* msg - with alarm */ Exit 12 End If type <> 'A' & type<> 'B' then do zedsmsg = 'Invalid insert type' zedlmsg = 'You must specify an insert type of "A"', 'or "B" as the second parameter.' Address ISPEXEC "SETMSG MSG(ISRZ001)" /* msg - with alarm */ Exit 12 End /***********************************************/ /* FIND OUT IF LABELS ARE BEING USED */ /***********************************************/ Call FIND_LABELS /* find out if labels are being used */ /***********************************************/ /* IF THE DATA IS IS DELIMTED BY SINGLE OR */ /* DOUBLE QUOTES - THEN REMOVE THE DELIMITERS */ /***********************************************/ If Substr(parm,1,1) = '''' | Substr(parm,1,1) = '"' then parm = Substr(parm,2,Length(parm)-2) /***********************************************/ /* Verify ISPF release for "PASTE" option */ /***********************************************/ If Translate(parm) = 'PASTE' then do Address ISPEXEC "VGET ZENVIR" If Substr(ZENVIR,6,3) < 4.8 then do zedsmsg = '"PASTE" not supported' zedlmsg = 'You must be running ISPF Verion 4.8 (OS/390 2.8)', 'or above to use the "PASTE" option.' Address ISPEXEC "SETMSG MSG(ISRZ001)" /* msg - with alarm */ Exit 12 End End /***********************************************/ /* MAKE SURE DATA WILL "FIT" */ /***********************************************/ "(width) = DATA_WIDTH " /* length of line */ If Length(parm) > width then do width = width + 0 /* remove leading zeros */ zedsmsg = 'Data too long' zedlmsg = 'The insert data is too ling to fit on a line', '(MAXLEN =' width || ').' Address ISPEXEC "SETMSG MSG(ISRZ001)" /* msg - with alarm */ Exit 12 End /***********************************************/ /* BEGIN INSERT PROCESSING */ /***********************************************/ If type = 'A' then line_type = 'LINE_AFTER' else line_type = 'LINE_BEFORE' count = lastln - firstln + 1 Do count "ISREDIT (chkexcl) = XSTATUS" firstln If chkexcl = "X" then do /* is line excluded? */ firstln = firstln + 1 /* yes, skip it */ count = count-1 /* correct total count */ iterate /* get next record */ End /******************************************************/ /* INSERT DATA FROM MACRO INVOCATION PARM */ /******************************************************/ If Translate(parm) <> 'PASTE' then do /* line_type firstln "= DATALINE '" || parm || "'" */ line_type firstln "= DATALINE (parm)" firstln = firstln + 2 /* bump up line counter */ End /******************************************************/ /* INSERT DATA FROM ISPF DEFAULT CLIPBOARD (PASTE) */ /******************************************************/ Else do nextln=firstln+1 /* point to next line */ "ISREDIT LABEL (firstln) = .HERE" /* add label for paste */ If lastln >= nextln then "ISREDIT LABEL (nextln) = .NEXT" Address ISPEXEC "CONTROL ERRORS RETURN" If type = 'A' then "PASTE AFTER .HERE KEEP" /* paste data */ Else "PASTE BEFORE .HERE KEEP" /* paste data */ If RC = 12 then do zedsmsg = 'No "CUT" data' zedlmsg = 'There is no data to "PASTE" from the ISPF' , 'Default Clipboard.' Address ISPEXEC "SETMSG MSG(ISRZ001)" /* msg - with alarm */ Exit 12 End /* if RC = 12 */ Address ISPEXEC "CONTROL ERRORS CANCEL" "(firstln) = LINENUM .NEXT" /* bump up line counter */ "(lastln) = LINENUM .ZLAST" /* fix last line pointer */ End /* else do */ End /***********************************************/ /* END INSERT PROCESSING */ /***********************************************/ If type = 'A' then mtype = 'after' Else mtype = 'before' If Translate(parm) = 'PASTE' then do zedsmsg = count 'PASTES inserted' zedlmsg = 'Data was inserted via PASTE' mtype count 'lines.' End Else do zedsmsg = count 'lines inserted' zedlmsg = parm 'was inserted' mtype count 'lines.' End Address ISPEXEC "SETMSG MSG(ISRZ000)" /* msg - no alarm */ Exit 0 /*********************************/ /* SUB-ROUTINE TO FIND LABELS */ /*********************************/ FIND_LABELS: If label1 = '' then do firstln = 1 "(lastln) = LINENUM .ZLAST" End Else do If label2 = '' then label2 = label1 firstsv = 'NOTFOUND' lastsv = 'NOTFOUND' label1 = Translate(label1) label2 = Translate(label2) "(saveln) = DISPLAY_LINES" "UP MAX" Do forever "LOCATE LAB NEXT" if rc <> 0 then leave "(labline,junk) = DISPLAY_LINES" "(lab,junk) = LABEL" labline if lab = label1 then firstsv = labline if lab = label2 then lastsv = labline End If label1 ='.ZFIRST' | label1 = '.ZF' then firstsv = 1 If label1 ='.ZLAST' | label1 = '.ZL' then , "(firstsv) = LINENUM .ZLAST" If label2 ='.ZFIRST' | label2 = '.ZF' then lastsv = 1 If label2 ='.ZLAST' | label2 = '.ZL' then , "(lastsv) = LINENUM .ZLAST" /* */ /* return display lines to originial position */ /* */ "UP MAX" If saveln <> 1 then "DOWN " saveln /* don't scroll if at top */ /* */ If firstsv = 'NOTFOUND' then do zedsmsg = 'RANGE LABEL ERROR' zedlmsg = 'THE SPECIFIED RANGE LABEL "' || label1 '" WAS', 'NOT FOUND' Address ISPEXEC "SETMSG MSG(ISRZ001)" /* msg - with alarm */ Exit 12 End If lastsv = 'NOTFOUND' then do zedsmsg = 'RANGE LABEL ERROR' zedlmsg = 'THE SPECIFIED RANGE LABEL "' || label2 '" WAS', 'NOT FOUND' Address ISPEXEC "SETMSG MSG(ISRZ001)" /* msg - with alarm */ Exit 12 End firstln = Min(firstsv,lastsv) lastln = Max(firstsv,lastsv) End Return