/* REXX PLIMSGE adds error messages in-line with the compiler listing. |**-***-***-***-***-***-***-***-***-***-***-***-***-***-***-***-**| | | | WARNING: EMBEDDED COMPONENTS. | | See text following TOOLKIT_INIT | | | |**-***-***-***-***-***-***-***-***-***-***-***-***-***-***-***-**| Written by Frank Clarke 20010307 rexxhead@yahoo.com Impact Analysis . SYSEXEC SEGMENT . SYSEXEC TRAPOUT Modification History 20010717 fxc don't sort if only 1 token; 20030723 fxc split for two compilers 20040329 fxc ignore I-level messages 20040401 fxc HIDELIST 20040507 fxc save text of every msg and post separately; save long text and post on multiple lines; 20040510 fxc full REXXSKEL; 20040727 fxc widescreen version; default to stmt.1 for messages without statement numbers; 20040730 fxc sw. glitch 20051108 fxc was finding "Message Description" in wrong section; 20231128 fxc looking for statement numbers in wrong columns; 20231201 fxc correct values of txt_pos, stm_pos, and msg_pos; 20240503 fxc change $ to @ everywhere; */ address ISREDIT "MACRO (argline)" upper argline parse var argline parms "((" opts signal on syntax signal on novalue call TOOLKIT_INIT /* conventional start-up -*/ info = parms rc = Trace("O"); rc = Trace(tv) "RESET" address ISPEXEC "CONTROL ERRORS RETURN" call A_INIT /* -*/ call B_COLLECT_REFS /* -*/ if sw.0_Build_Log then, call ZB_SAVELOG /* -*/ exit(9) /*@ PLIMSGE */ /* . ----------------------------------------------------------------- */ A_INIT: /*@ */ address ISREDIT monitor = "0" parse source sys_id how_invokt exec_name DD_nm DS_nm, as_invokt cmd_env addr_spc usr_tokn xea = 'EA'x tk_globalvars = "exec_name sw. monitor " call AS_SETUP_LOG /* -*/ parse value "" with, msgid. msgid sev stmt# msgtxt stmts. msg. , keybymsg. uniquemsglist msgkeylist . parse value "0 0 0 0 0 0 0 0 0 0 0 0 0 0" with, sw. , ss# es# msg_bgn msg_end , . call AK_KEYWDS /* -*/ if sw.0_Allmsgs then nop ; else, IgnoreList = "IBM1047I IBM1041I IBM1042I" , "IBM1085I IBM1208I" return /*@ A_INIT */ /* . ----------------------------------------------------------------- */ AK_KEYWDS: /*@ */ address TSO hidelist = KEYWD("HIDE") sw.0_Build_Log = SWITCH("LOG") sw.0_Allmsgs = SWITCH("ALL") sw.0_Preview = SWITCH("PREVIEW") if sw.0_Preview then sw.0_Allmsgs = 1 return /*@ AK_KEYWDS */ /* . ----------------------------------------------------------------- */ AS_SETUP_LOG: /*@ */ address TSO parse value "0" with, log# log. parse value Date("S") Time("S") Time("N") with, yyyymmdd sssss hhmmss . parse var yyyymmdd 4 yrdigit 5 mm 7 dd /* 9 12 14 maybe */ if Pos(yrdigit,"13579") > 0 then mm = mm + 12 /* mm=24 */ logtag = Substr("ABCDEFGHIJKLMNOPQRSTUVWX",mm,1) /* logtag=X */ subid = logtag""dd""Right(sssss,5,0) /* X1423722 ? */ vb4k.0 = "NEW CATALOG UNIT(SYSDA) SPACE(1 5) TRACKS", "RECFM(V B) LRECL(4096) BLKSIZE(0)" vb4k.1 = "SHR" /* if it already exists... */ logdsn = "@@LOG."exec_name"."subid".#CILIST" call ZL_LOGMSG("Log started by" Userid() yyyymmdd hhmmss) call ZL_LOGMSG("Arg:" argline) return /*@ AS_SETUP_LOG */ /* . ----------------------------------------------------------------- */ B_COLLECT_REFS: /*@ */ address ISREDIT call BA_DELIMIT_SECTIONS /* -*/ if sw.0_Error_Found then return call BB_FIND_MESSAGES /* -*/ if sw.0_Preview then, call BG_GET_VALIDMSGLIST /* -*/ call BP_POST_MESSAGES /* -*/ return /*@ B_COLLECT_REFS */ /* Find the Start-of-Source and label it (.SS), End-of-Source (.ES), Start-of-Messages (.SM) and End-of-Messages (.EM) . ----------------------------------------------------------------- */ BA_DELIMIT_SECTIONS: /*@ */ address ISREDIT "CAPS OFF" "SEGMENT LABELS ((" opts /* sets LBLLIST */ address ISPEXEC "VGET LBLLIST SHARED" if Pos(".SRC",lbllist) > 0 then do parse var lbllist ".SRC" ss# lbllist "LABEL" ss# "= .SS " /* start of source statements */ call ZL_LOGMSG("Source starts at" ss#) end else do zerrsm = "SEGMENT error" zerrlm = "No .SRC token in LBLLIST -- terminating error" call ZL_LOGMSG(zerrlm) address ISPEXEC "SETMSG MSG(ISRZ002)" sw.0_Error_Found = 1 return end if Pos(".ATTR",lbllist) > 0 then do parse var lbllist ".ATTR" es# lbllist "LABEL" es# "= .ES " /* end of source statements */ call ZL_LOGMSG("Source ends at" es#) end else do /* wrecked compile listing */ parse var lbllist estag es# . es# = es# - 1 /* avoid being overlayed */ zerrlm = "Used" estag "to locate source-end" call ZL_LOGMSG(zerrlm) "LABEL" es# "= .ES " /* end of source statements */ call ZL_LOGMSG("Source ends at" es#) end if Pos(".DIAG",lbllist) > 0 then do parse var lbllist ".DIAG" msg_bgn lbllist "(text) = LINE" msg_bgn if Pos("NO MESSAGES PRODUCED",text) > 0 then exit "LABEL" msg_bgn "= .SM" /* start of messages */ sm# = msg_bgn /* save the line # */ call ZL_LOGMSG("Messages start at" sm#) end else do /* wrecked compile listing */ zerrlm = "No .DIAG tag in LBLLIST" zerrsm = "" call ZL_LOGMSG(zerrlm) address ISPEXEC "SETMSG MSG(ISRZ002)" sw.0_Error_Found = 1 return end if lbllist = "" then do "LABEL .zl = .EM " /* end of messages */ "(em#) = LINENUM .EM " /* save the line # */ end else do parse var lbllist ".CNFG" cnfg# ".LINK" link# . parse value cnfg# link# with msg_end . "LABEL" msg_end "= .EM " /* end of messages */ em# = msg_end /* save the line # */ end call ZL_LOGMSG("Messages end at" em#) return /*@ BA_DELIMIT_SECTIONS */ /* Locate the messages between .SM and .EM Find 'Message Description'; this is a header line. The position of 'Message' marks the location of the whose length is 8. The next token 9 bytes further on is the severity indicator which must be S, E, W, or I The position of "Message Description" is the location of the message text which may continue onto following lines Parse out , , , and (possibly continued). In this compiler, each instance of each message is reported individually. Ignore any s in and any SEVs in Ignore any s affecting only stmt# 1 Save the KEY in a string of keys which can be sorted later. The key will be composed of stmt#.sev.msgid.line# Save msgid, severity, and text as . . ----------------------------------------------------------------- */ BB_FIND_MESSAGES: /*@ */ bb_tv = trace() /* what setting at entry ? */ address ISREDIT if sw.0_Preview then, parse value "" with ignorelist hidelist /* ZAP ! */ sevval. = 5 sevval.I = 9 sevval.W = 8 sevval.E = 7 sevval.S = 6 "LOCATE .sm" "F 'Message Description' .sm .em" "(text) = LINE .zcsr" txt_pos = Pos("Message Description",text) - 1 stm_pos = Pos("Line.File" ,text) - 4 msg_pos = Pos("Message" ,text) - 1 sev_pos = msg_pos + 9 msg = "" /* init */ do bbx = em# to sm# by -1 /* diagnostic messages */ "(text) = LINE" bbx parse var text cc 2 text /* snip off cc */ if text = "" then iterate if cc = "1" then iterate if Left(text,11) = " Message " then iterate if Left(text,txt_pos-1) = "" then do /* continued line */ text = Strip(text) msg = text msg /* prepend */ iterate end /* continued line */ /* If we get here, the left-end of text was not blank and this is therefore a statement-line */ parse var text =(stm_pos) stmt# =(txt_pos) parse value stmt# 1 with stmt# . /* ensure a value */ if Datatype(stmt#,"N") then do /* new stmt */ parse var text msgid sev . =(txt_pos) text if Pos(sev,hidelist) > 0 |, WordPos(msgid,IgnoreList) > 0 then do msg = "" /* collected text */ iterate end text = Strip(text) text = text msg /* splice ahead */ msg = "" /* collected text */ stmt# = stmt# + 0 msgtext = text key = Space(Right(stmt#,7,0)xea ||, sevval.sev || xea || msgid || xea ||bbx,0) /* 00182.0Č8ČIBM1063EČ3855 maybe */ /* now contains the actual message */ MSG.key = Strip(msgid) Strip(sev) Strip(msgtext) msgkeylist = msgkeylist key /* keep track of key */ if sw.0_Preview then do rc = Trace("O"); rc = trace(bb_tv) if WordPos(msgid,uniquemsglist) = 0 then, uniquemsglist = uniquemsglist msgid keybymsg.msgid = keybymsg.msgid key end /* PREVIEW */ end /* new stmt */ end /* bbx bottom up */ rc = Trace("O"); rc = trace(bb_tv) msgkeylist = STRSORT(msgkeylist) return /*@ BB_FIND_MESSAGES */ /* Called only if sw.0_Preview. BB_FIND_MESSAGES has prepared UNIQUEMSGLIST, a list of unique MSGIDs. For each MSGID, there is a list of the full keys (stmt# + sev + MSGID + order). Prepare an ISPF table keyed by MSGID and sorted by SEV+MSGID and showing the first available such message only. Allow the user to select any MSGIDs for exclusion. . ----------------------------------------------------------------- */ BG_GET_VALIDMSGLIST: /*@ */ address ISPEXEC call BGA_PROLOG /* -*/ call BGB_LOAD_TBL /* -*/ call BGD_DISPLAY_LIST /* -*/ call BGZ_EPILOG /* -*/ return /*@ BG_GET_VALIDMSGLIST */ /* . ----------------------------------------------------------------- */ BGA_PROLOG: /*@ */ address ISPEXEC call DEIMBED /* -*/ dd = "" /* */ do Words(ddnlist) /* each LIBDEF DD */ parse value ddnlist dd with dd ddnlist @ddn = @ddn.dd /* PLIB322 <- PLIB */ "LIBDEF ISP"dd "LIBRARY ID("@ddn") STACK" end ddnlist = ddnlist dd "TBCREATE MSGS KEYS(MSGID) NAMES(MSCT MSSEV MSTEXT)", "NOWRITE REPLACE" return /*@ BGA_PROLOG */ /* . ----------------------------------------------------------------- */ BGB_LOAD_TBL: /*@ */ address ISPEXEC do bz = 1 to Words(uniquemsglist) msgid = Word(uniquemsglist,bz) /* isolate */ textkey = Word(keybymsg.msgid,1) mstext = msg.textkey msct = Words(keybymsg.msgid) parse var textkey "." mssev "." /* numeric severity */ "TBADD MSGS" end /* bz */ "TBSORT MSGS FIELDS(MSSEV,N,A MSGID,C,A)" return /*@ BGB_LOAD_TBL */ /* . ----------------------------------------------------------------- */ BGD_DISPLAY_LIST: /*@ */ address ISPEXEC sel = "" do forever "TBTOP MSGS" "TBDISPL MSGS PANEL(MSGID01)" if rc > 4 then leave do ztdsels /* MSGID -> KEYBYMSG.msgid -> MSGKEYLIST */ /* delete all words in KEYBYMSG from MSGKEYLIST */ do bgdz = 1 to Words(KEYBYMSG.msgid) /* each key */ badkey = Word(KEYBYMSG.msgid,bgdz) /* isolate */ pt = WordPos(badkey,msgkeylist) /* where is it? */ if pt > 0 then, msgkeylist = Delword(msgkeylist,pt,1) end /* bgdz */ "TBDELETE MSGS" /* zap selected row */ if ztdsels > 1 then "TBDISPL MSGS " end /* ztdsels */ sel = "" end /* forever */ return /*@ BGD_DISPLAY_LIST */ /* . ----------------------------------------------------------------- */ BGZ_EPILOG: /*@ */ address ISPEXEC "TBEND MSGS" dd = "" do Words(ddnlist) /* each LIBDEF DD */ parse value ddnlist dd with dd ddnlist @ddn = @ddn.dd /* PLIB322 <- PLIB */ "LIBDEF ISP"dd address TSO "FREE FI("@ddn")" end ddnlist = ddnlist dd return /*@ BGZ_EPILOG */ /* For each key in msgkeylist, parse out stmt#. Locate that statement in the source listing and insert the text above that line. Messages which are too long to be written as a single NOTELINE (72 characters) will be split into multiple lines so that the entire message can be displayed. . ----------------------------------------------------------------- */ BP_POST_MESSAGES: /*@ */ address ISREDIT seq = "FIRST" do bx = 1 to Words(msgkeylist) /* each key */ key = Word(msgkeylist,bx) parse var key stmt# (xea) stmt# = stmt# + 0 /* strip zeroes */ "F WORD '"stmt#"' .SS .ES" 3 12 seq /* locate */ "(loc) = CURSOR" msgtext = MSG.key call ZL_LOGMSG(loc": MSG."key "=" msgtext) address TSO "NEWSTACK" do while Length(msgtext) > 72 /* split */ pt = LastPos(" ",msgtext,72) slug = SubStr(msgtext,1,pt) msgtext = " "DelStr(msgtext,1,pt) queue slug end /* long msg */ queue msgtext do queued() /* each queued fragment */ parse pull msgtext "LINE_BEFORE .zcsr = NOTELINE (msgtext)" end /* queued */ address TSO "DELSTACK" end /* bx */ "L FIRST SPECIAL" zcmd = "&L FIRST SPECIAL" return /*@ BP_POST_MESSAGES */ /* . ----------------------------------------------------------------- */ LOCAL_PREINIT: /*@ customize opts */ address TSO return /*@ LOCAL_PREINIT */ /* subroutines below LOCAL_PREINIT are not selected by SHOWFLOW */ /* . ----------------------------------------------------------------- */ HELP: /*@ */ address TSO say helpmsg exit /*@ HELP */ /* Parse out the embedded components at the back of the source code. . ----------------------------------------------------------------- */ DEIMBED: Procedure expose, /*@ */ (tk_globalvars) ddnlist @ddn. daid. address TSO address ISPEXEC "VGET ZSCREENW" fb80po.0 = "NEW UNIT(VIO) SPACE(5 5) TRACKS DIR(40)", "RECFM(F B) LRECL("zscreenw") BLKSIZE(0)" parse value "" with ddnlist @ddn. daid. lastln = sourceline() currln = lastln /* */ if Left(sourceline(currln),2) <> "*/" then return currln = currln - 1 /* previous line */ "NEWSTACK" address ISPEXEC do while sourceline(currln) <> "/*" text = sourceline(currln) /* save with a short name ! */ if Left(text,3) = ")))" then do /* package the queue */ parse var text ")))" ddn mbr . /* PLIB PANL001 maybe */ if Pos(ddn,ddnlist) = 0 then do /* doesn't exist */ ddnlist = ddnlist ddn /* keep track */ @ddn = ddn || Random(999) @ddn.ddn = @ddn address TSO "ALLOC FI("@ddn")" fb80po.0 "LMINIT DATAID(DAID) DDNAME("@ddn")" daid.ddn = daid end daid = daid.ddn "LMOPEN DATAID("daid") OPTION(OUTPUT)" do queued() parse pull line "LMPUT DATAID("daid") MODE(INVAR) DATALOC(LINE)" , "DATALEN("zscreenw")" end "LMMADD DATAID("daid") MEMBER("mbr")" "LMCLOSE DATAID("daid")" end /* package the queue */ else push text /* onto the top of the stack */ currln = currln - 1 /* previous line */ end /* while */ address TSO "DELSTACK" return /*@ DEIMBED */ /* . ----------------------------------------------------------------- */ ZB_SAVELOG: /*@ */ address TSO if Symbol("LOG#") = "LIT" then return /* not yet set */ "ALLOC FI(@LOG) DA("logdsn") REU" vb4k.0 "EXECIO" log# "DISKW @LOG (STEM LOG. FINIS" "FREE FI(@LOG)" return /*@ ZB_SAVELOG */ /* . ----------------------------------------------------------------- */ ZL_LOGMSG: Procedure expose, /*@ */ (tk_globalvars) log. log# rc = Trace("O") address TSO parse arg msgtext parse value log#+1 msgtext with, zz log.zz 1 log# . if monitor then say, msgtext return /*@ ZL_LOGMSG */ /* . ----------------------------------------------------------------- */ BRANCH: Procedure expose, /*@ */ sigl exec_name rc = trace("O") /* we do not want to see this */ arg brparm . origin = sigl /* where was I called from ? */ do currln = origin to 1 by -1 /* inch backward to label */ if Right(Word(Sourceline(currln),1),1) = ":" then do parse value sourceline(currln) with pgfname ":" . /* Label */ leave ; end /* name */ end /* currln */ select when brparm = "NAME" then return(pgfname) /* Return full name */ when brparm = "ID" then do /* wants the prefix */ parse var pgfname pgfpref "_" . /* get the prefix */ return(pgfpref) end /* brparm = "ID" */ otherwise say left(sigl,6) left(pgfname,40) exec_name "Time:" time("L") end /* select */ return /*@ BRANCH */ /* . ----------------------------------------------------------------- */ DUMP_QUEUE: /*@ Take whatever is in stack */ rc = trace("O") /* and write to the screen */ address TSO arg mode . "QSTACK" /* how many stacks? */ stk2dump = rc - tk_init_stacks /* remaining stacks */ if stk2dump = 0 & queued() = 0 then return if mode <> "QUIET" then, say "Total Stacks" rc , /* rc = #of stacks */ " Begin Stacks" tk_init_stacks , /* Stacks present at start */ " Excess Stacks to dump" stk2dump do dd = rc to tk_init_stacks by -1 /* empty each one. */ if mode <> "QUIET" then, say "Processing Stack #" dd " Total Lines:" queued() do queued();parse pull line;say line;end /* pump to the screen */ "DELSTACK" /* remove stack */ end /* dd = 1 to rc */ return /*@ DUMP_QUEUE */ /* Handle CLIST-form keywords added 20020513 . ----------------------------------------------------------------- */ CLKWD: Procedure expose info /*@ hide all except info */ arg kw kw = kw"(" /* form is 'KEY(DATA)' */ kw_pos = Pos(kw,info) /* find where it is, maybe */ if kw_pos = 0 then return "" /* send back a null, not found*/ rtpt = Pos(") ",info" ",kw_pos) /* locate end-paren */ slug = Substr(info,kw_pos,rtpt-kw_pos+1) /* isolate */ info = Delstr(info,kw_pos,rtpt-kw_pos+1) /* excise */ parse var slug (kw) slug /* drop kw */ slug = Reverse(Substr(Reverse(Strip(slug)),2)) return slug /*@CLKWD */ /* Handle multi-word keys 20020513 . ----------------------------------------------------------------- */ KEYWD: Procedure expose info /*@ hide all vars, except info*/ arg kw /* form is 'KEY DATA' */ kw_pos = wordpos(kw,info) /* find where it is, maybe */ if kw_pos = 0 then return "" /* send back a null, not found*/ kw_val = word(info,kw_pos+Words(kw))/* get the next word */ info = Delword(info,kw_pos,2) /* remove both */ return kw_val /*@ KEYWD */ /* . ----------------------------------------------------------------- */ KEYPHRS: Procedure expose, /*@ */ info helpmsg exec_name /* except these three */ arg kp /* form is 'KEY ;: DATA ;:' */ wp = wordpos(kp,info) /* where is it? */ if wp = 0 then return "" /* not found */ front = subword(info,1,wp-1) /* everything before kp */ back = subword(info,wp+1) /* everything after kp */ parse var back dlm back /* 1st token must be 2 bytes */ if length(dlm) <> 2 then /* Must be two bytes */ helpmsg = helpmsg "Invalid length for delimiter("dlm") with KEYPHRS("kp")" if wordpos(dlm,back) = 0 then /* search for ending delimiter*/ helpmsg = helpmsg "No matching second delimiter("dlm") with KEYPHRS("kp")" if helpmsg <> "" then call HELP /* Something is wrong */ parse var back kpval (dlm) back /* get everything b/w delim */ info = front back /* restore remainder */ return Strip(kpval) /*@ KEYPHRS */ /* . ----------------------------------------------------------------- */ NOVALUE: /*@ */ say exec_name "raised NOVALUE at line" sigl say " " say "The referenced variable is" condition("D") say " " zsigl = sigl signal SHOW_SOURCE /*@ NOVALUE */ /* . ----------------------------------------------------------------- */ SHOW_SOURCE: /*@ */ call DUMP_QUEUE /* Spill contents of stacks -*/ if sourceline() <> "0" then /* to screen */ say sourceline(zsigl) rc = trace("?R") nop exit /*@ SHOW_SOURCE */ /* . ----------------------------------------------------------------- */ SS: Procedure /*@ Show Source */ arg ssbeg ssct . /* 'call ss 122 6' maybe */ if ssct = "" then ssct = 10 if \datatype(ssbeg,"W") | \datatype(ssct,"W") then return ssend = ssbeg + ssct do ssii = ssbeg to ssend ; say Strip(sourceline(ssii),'T') ; end return /*@ SS */ /* . ----------------------------------------------------------------- */ SWITCH: Procedure expose info /*@ */ arg kw /* form is 'KEY' */ sw_val = Wordpos(kw,info) > 0 /* exists = 1; not found = 0 */ if sw_val then /* exists */ info = Delword(info,Wordpos(kw,info),1) /* remove it */ return sw_val /*@ SWITCH */ /* . ----------------------------------------------------------------- */ SYNTAX: /*@ */ errormsg = exec_name "encountered REXX error" rc "in line" sigl":", errortext(rc) say errormsg zsigl = sigl signal SHOW_SOURCE /*@ SYNTAX */ /* Can call TRAPOUT. . ----------------------------------------------------------------- */ TOOLKIT_INIT: /*@ */ address TSO info = Strip(opts,"T",")") /* clip trailing paren */ parse source sys_id how_invokt exec_name DD_nm DS_nm, as_invokt cmd_env addr_spc usr_tokn parse value "" with tv helpmsg . parse value 0 "ISR00000 YES" "Error-Press PF1" with, sw. zerrhm zerralrm zerrsm if SWITCH("TRAPOUT") then do "TRAPOUT" exec_name parms "(( TRACE R" info exit end /* trapout */ sw.nested = sysvar("SYSNEST") = "YES" sw.batch = sysvar("SYSENV") = "BACK" sw.inispf = sysvar("SYSISPF") = "ACTIVE" if Word(parms,1) = "?" then call HELP /* I won't be back */ "QSTACK" ; tk_init_stacks = rc /* How many stacks? */ parse value SWITCH("BRANCH") SWITCH("MONITOR") SWITCH("NOUPDT") with, branch monitor noupdt . parse value mvsvar("SYSNAME") sysvar("SYSNODE") with, #tk_cpu node . parse value KEYWD("TRACE") "N" with tv . tk_globalvars = "exec_name tv helpmsg sw. zerrhm zerralrm ", "zerrsm zerrlm tk_init_stacks branch monitor ", "noupdt" call LOCAL_PREINIT /* for more opts -*/ return /*@ TOOLKIT_INIT */ /* ))) PLIB MSGID01 )ATTR % TYPE(TEXT) INTENS(HIGH) SKIP(ON) + TYPE(TEXT) INTENS(LOW) SKIP(ON) _ TYPE(INPUT) INTENS(HIGH) CAPS(ON) ! TYPE(OUTPUT) INTENS(HIGH) SKIP(ON) } TYPE(OUTPUT) INTENS(HIGH) SKIP(ON) JUST(RIGHT) @ TYPE(OUTPUT) INTENS(LOW) SKIP(ON) )BODY EXPAND(||) WIDTH(&ZSCREENW) %|-| MSGIDs to be excluded +|-| %Command ===>_ZCMD %Scroll ===>_ZAMT+ +V MSGID ## ---- Text example ------ )MODEL _z!msgid }msct!mstext )INIT .ZVARS = '(SEL)' .HELP = ISR00001 )REINIT )PROC )END */