/* REXX */ /* */ /* AUTHOR: Mark Zelden */ /* */ /* Last Updated 10/07/2013 */ /* */ help_start = HELP_INCL() /***************************************************************/ /* */ /* 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) */ /* */ /* */ /* ** NOTE If you execute INSLINE with no parms or with */ /* a parm of "?", the comment section of this */ /* code with syntax and usage notes will be */ /* displayed as "help" note lines. Use the */ /* "RESET" command to remove them. */ /* */ /***************************************************************/ /* COMMAND EXAMPLES: */ /* */ /* 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 */ /* */ /***************************************************************/ help_end = HELP_INCL() /* TRACE ?R */ Address ISREDIT "MACRO (parm type label1 label2)" /* Address ISPEXEC "CONTROL ERRORS RETURN" */ /***********************************************/ /* VERIFY INPUT PARAMETERS */ /***********************************************/ type = Translate(type) /* ensure upper case */ If parm = '?' then do Call HELP_NOTELINES Exit 1 /* return cursor to command line */ End 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 */ Call HELP_NOTELINES Exit 4 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 1 /* return cursor to command line */ /*********************************/ /* HELP SUB-ROUTINES */ /*********************************/ HELP_INCL: Return SIGL HELP_NOTELINES: "(helpln) = DISPLAY_LINES" Do hlp = help_end-1 to help_start+1 by -1 hline = Sourceline(hlp) "ISREDIT LINE_AFTER " helpln " = NOTELINE (hline)" End hline2 = '===================' hline3 = '=== H E L P ===' "ISREDIT LINE_AFTER " helpln " = NOTELINE (hline2)" "ISREDIT LINE_AFTER " helpln " = NOTELINE (hline3)" "ISREDIT LINE_AFTER " helpln " = NOTELINE (hline2)" Return /*********************************/ /* SUB-ROUTINE TO FIND LABELS */ /*********************************/ FIND_LABELS: Address ISPEXEC "CONTROL ERRORS RETURN" If label1 = '' then do firstln = 1 "(lastln) = LINENUM .ZLAST" End Else do If label2 = '' then label2 = label1 "(firstsv) = LINENUM" label1 If RC >= 8 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 "(lastsv) = LINENUM" label2 If RC >= 8 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) Address ISPEXEC "CONTROL ERRORS" End /* else do */ Return