/* REXX */ /* */ /* AUTHOR: Mark Zelden */ /* */ /* Last Updated 10/07/2013 */ /* */ help_start = HELP_INCL() /**********************************************************/ /* This edit macro will delete all lines but the ones */ /* that contain a specified search string. The search */ /* can optionally be limited to specific columns. */ /* */ /* EXAMPLES: */ /* DELX VOL=SER=WORK01 */ /* DELX '//*' 1 3 */*/ /* */ /* */ /* ** NOTE If you execute DELX 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 col1 col2)" /* Address ISPEXEC "CONTROL ERRORS RETURN" */ If pos('&',parm) <> 0 then do parmx = Translate(parm) /* upper case */ parmx = C2X(parmx) /* change to hex for seek/find */ amp = 'Y' End If parm = '?' then do Call HELP_NOTELINES Exit 1 /* return cursor to command line */ End If parm = '' then do zedsmsg = 'NO SEARCH STRING' zedlmsg = 'YOU MUST PASS A SEARCH STRING PARM', 'TO DELX.' Address ISPEXEC "SETMSG MSG(ISRZ001)" /* msg - with alarm */ Call HELP_NOTELINES Exit 4 End /* check for numeric column numbers */ If col1 <> '' then do If Datatype(col1,Number) <> 1 then do zedsmsg = 'START COLUMN NOT NUMERIC' zedlmsg = 'THE STARTING COLUMN FOR THE', 'SEARCH MUST BE NUMERIC.' Address ISPEXEC "SETMSG MSG(ISRZ001)" /* msg - with alarm */ Exit 12 End If col2 = '' then col2 = col1 End If col2 <> '' then do If Datatype(col2,Number) <> 1 then do zedsmsg = 'END COLUMN NOT NUMERIC' zedlmsg = 'THE ENDING COLUMN FOR THE', 'SEARCH MUST BE NUMERIC.' Address ISPEXEC "SETMSG MSG(ISRZ001)" /* msg - with alarm */ Exit 12 End If col2 < col1 then do zedsmsg = 'END COL < START COL' zedlmsg = 'THE ENDING COLUMN MUST BE GREATER THAN OR', 'EQUAL TO THE STARTING COLUMN.' Address ISPEXEC "SETMSG MSG(ISRZ001)" /* msg - with alarm */ Exit 12 End If Length(Strip(Translate(parm,'','"'''''))) , > COL2-COL1+1 then do zedsmsg = 'PARM TOO LONG' zedlmsg = 'THE STRING WILL NOT FIT BETWEEN THE', 'SPECIFIED COLUMNS.' Address ISPEXEC "SETMSG MSG(ISRZ001)" /* msg - with alarm */ Exit 12 End "(width) = DATA_WIDTH " /* length of line */ width = Format(width) /* remove leading zeros */ If col1 < 1 | col2 < 1 | col1 > width | col2 > width then do zedsmsg = 'INVALID COLUMN NUMBER' zedlmsg = 'ALL COLUMN SPECIFICATIONS MUST BE' , 'BETWEEN 1 AND' width Address ISPEXEC "SETMSG MSG(ISRZ001)" /* msg - with alarm */ Exit 12 End End /* "(FIRSTLN,LASTLN) = DISPLAY_LINES" */ "(lastln) = LINENUM .ZLAST" If AMP = 'Y' then "SEEK x'"parmx"'" col1 col2" FIRST" Else "SEEK "parm col1 col2" FIRST" If rc = 0 then do "EXCLUDE ALL" If AMP = 'Y' then do "FIND x'"parmx"'" col1 col2" ALL" "SEEK x'"parmx"'" col1 col2" ALL" End Else do "FIND "parm col1 col2" ALL" "SEEK "parm col1 col2" ALL" End "DELETE ALL X" "(count,lines) = SEEK_COUNTS" count = Format(count) lines = Format(lines) del = lastln-lines parm = Translate(parm) /* upper case */ zedsmsg = del' LINES DELETED' zedlmsg = count 'OCCURRENCES OF "'parm'" WERE KEPT', 'ON 'lines 'LINES - 'del 'LINES WERE DELETED.' "RESET" Address ISPEXEC "SETMSG MSG(ISRZ000)" /* msg - no alarm */ Exit 1 /* return cursor to command line */ End Else do parm = Translate(parm) /* upper case */ zedsmsg = 'STRING NOT FOUND' zedlmsg = 'THE STRING "'parm'" WAS NOT FOUND IN THE FILE.' "RESET" Address ISPEXEC "SETMSG MSG(ISRZ001)" /* msg - with alarm */ Exit 12 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