/* REXX */ /* */ /* AUTHOR: Mark Zelden */ /* */ /* Last Updated 10/07/2013 */ /* */ help_start = HELP_INCL() /**********************************************************/ /* This edit macro will add a character string prefix */ /* to the beginning of a line before the first non-blank */ /* character. The prefix can optionally be limited to */ /* specific lines if labels are used. Excluded lines */ /* are omitted from the operation. */ /* */ /* EXAMPLES: */ /* PREFIX2 "'" */ /* PREFIX2 'DSN=' .A .B */ /* */ /* */ /* ** NOTE If you execute PREFIX2 with no parms or with */ /* a parm of "?", the comment section of this */ /* code with examples will be displayed as */ /* "help" note lines. Use the "RESET" */ /* command to remove them. */ /* */ /**********************************************************/ help_end = HELP_INCL() /* TRACE ?R */ Address ISREDIT "MACRO (parm label1 label2)" /* Address ISPEXEC "CONTROL ERRORS RETURN" */ /* */ If parm = '?' then do Call HELP_NOTELINES Exit 1 /* return cursor to command line */ End If parm = '' then do zedsmsg = 'NO PREFIX SPECIFIED' zedlmsg = 'YOU MUST PASS A PARM STRING', 'FOR PREFIX2 TO ADD.' Address ISPEXEC "SETMSG MSG(ISRZ001)" /* msg - with alarm */ Call HELP_NOTELINES Exit 4 End /* */ Call FIND_LABELS /* find out if labels are being used */ /* */ /* HOUSE KEEPING */ /* */ "(width) = DATA_WIDTH " /* length of line */ count = 0 /* count of changed lines */ truncat = 0 /* lines truncated count */ truncmsg = "'*** THE PREFIX WAS TRUNCATED ON THE NEXT LINE ***'" /* */ /* If the prefix 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) /***********************************************/ /* BEGIN PREFIX PROCESSING */ /***********************************************/ Do until lastln = firstln-1 /* copy the data in the current line to variable 'data1' */ "(data1) = LINE "firstln "ISREDIT (chkexcl) = XSTATUS" firstln If chkexcl = "NX" then do len1 = Length(Strip(data1,L)) len2 = width-len1-Length(parm)+1 If len2 < 1 then do len2 = 1 parmt = Substr(parm,1,width-len1) data1 = Overlay(parmt,data1,len2) truncat = truncat + 1 "ISREDIT LINE_BEFORE" firstln "= NOTELINE " truncmsg End Else data1 = Overlay(parm,data1,len2) count = count + 1 End /* copy the prefixed 'data1' back into the current line */ "LINE" firstln "= (data1)" firstln = firstln + 1 End /* do until */ /***********************************************/ /* END PREFIX PROCESSING */ /***********************************************/ If truncat = 0 then do zedsmsg = count 'LINES CHANGED' zedlmsg = 'PREFIX "'parm'" WAS ADDED ON' count 'LINES.' Address ISPEXEC "SETMSG MSG(ISRZ000)" /* msg - no alarm */ Exit 1 /* return cursor to command line */ End Else do zedsmsg = 'TRUNCATED ON' truncat 'LINES' zedlmsg = 'PREFIX "'parm'" WAS ADDED ON' count 'LINES', '('truncat 'LINES WERE TRUNCATED).' Address ISPEXEC "SETMSG MSG(ISRZ001)" /* msg - with alarm */ Exit 4 End /*********************************/ /* 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