/* REXX PARSEDCL Annotates a PL/1 DCL with information about column-locations for each field. The process is: -- acquire the text of the DCL -- isolate each element/groupspec -- pass to ELEMLEN for the length calculation -- when finished: -- roll lengths up to parent-levels -- annotate each line with location information Written by Frank Clarke 20010914 Impact Analysis . SYSPROC ELEMLEN . SYSPROC TRAPOUT Modification History 20021104 fxc may be called as an edit macro if no parameters; */ arg argline if argline = '' then do /* called from EDIT ? */ address ISREDIT "MACRO" if rc <> 20 then do /* I'm a macro... */ address ISREDIT "(thisdsn) = DATASET" "(thismbr) = MEMBER" parse source . . execn . address TSO (execn) "'"thisdsn"("thismbr")'" /* restart with parameters */ address ISPEXEC "CONTROL DISPLAY REFRESH" exit end end address TSO /* REXXSKEL ver.20010802 */ arg parms "((" opts signal on syntax signal on novalue call TOOLKIT_INIT /* conventional start-up -*/ rc = trace(tv) info = parms /* to enable parsing */ call A_INIT /* -*/ call B_GET_TEXT /* -*/ call C_DO_ELEMENT /* -*/ if sw.0error_found then return call D_ROLL_UP /* -*/ call E_ANNOTATE /* -*/ if \sw.nested then call DUMP_QUEUE /* -*/ exit /*@ PARSEDCL */ /* . ----------------------------------------------------------------- */ A_INIT: /*@ */ if branch then call BRANCH address TSO parse value "1 1 1 0 0 0 0 0 0 0 0 0 0" with, start start. depth. length. , efflvl. end. totlen. , fillseq , . parse value "" with, elemdata. , /* declared name/type/len */ delim_q , /* */ parent. , /* */ parent_id , /* */ parent_name, /* */ spec , /* data for ELEMLEN */ text , /* workarea */ . parse var info source . group_list = "BASE" /* fq name list */ parent_q = "1" /* lvl # in DCL */ elemdata.BASE = "BASE" return /*@ A_INIT */ /* . ----------------------------------------------------------------- */ B_GET_TEXT: /*@ */ if branch then call BRANCH address TSO "ALLOC FI($DCL) DA("source") SHR REU" "EXECIO * DISKR $DCL (FINIS" /* load the queue */ "FREE FI($DCL)" return /*@ B_GET_TEXT */ /* Isolate each "line" of the DCL and pass to ELEMLEN. A "line" may span lines or be fragmentary. . ----------------------------------------------------------------- */ C_DO_ELEMENT: /*@ */ if branch then call BRANCH address TSO do while queued() > 0 /* re-evaluate every time */ pull line 73 /* shift to uppercase */ text = text Strip(Substr(line,2)) if Word(text,1) = "DCL" then text = Delword(text,1,1) /* snip */ call CA_ISOLATE_STMT /* -*/ end /* queued */ return /*@ C_DO_ELEMENT */ /* Find a comma or semicolon at the end of the statement. Isolate this fragment of text and pass it to ELEMLEN. . ----------------------------------------------------------------- */ CA_ISOLATE_STMT: /*@ */ ca_tv = trace() /* what setting at entry ? */ if branch then call BRANCH address TSO pt = 0 /* pointer */ rc = Trace("O") do forever if pt >= Length(text) then do /* end of our rope */ if queued() > 0 then, pull line 73 /* shift to uppercase */ else do;sw.0boom=1;leave;end pt = length(text) text = text Strip(Substr(line,2)) end /* end of text and no comma */ pt = pt + 1 /* advance pointer */ char = Substr(text,pt,1) /* isolate this character */ if Pos(char,",;()'/") = 0 then iterate if Pos(char,",;") > 0 then, if delim_q = "" then leave if char = "'" then , if Word(delim_q,1) = "'" then, parse var delim_q . delim_q /* remove match */ else delim_q = char delim_q if char = "(" then delim_q = char delim_q ; else, if char = ")" then , if Word(delim_q,1) = "(" then, parse var delim_q . delim_q /* remove match */ if char = "/" then, /* start of comment? */ if Substr(text,pt,2) = "615c"x then do /* slash-asterisk */ pt2 = Pos('5c61'x,text) /* asterisk-slash */ do while pt2 = 0 /* find the end */ if queued() > 0 then, /* get some more text */ pull line 73 /* shift to uppercase */ else do;sw.0boom=1;leave;end text = text Strip(Substr(line,2)) pt2 = Pos('5c61'x,text) /* asterisk-slash */ end /* while */ if sw.0boom then leave text = Delstr(text,pt,pt2-pt+2) end /* it was a comment */ end /* forever */ if sw.0boom then do "CLEAR" ; say "Premature end-of-text" sw.0error_found = '1' return end rc = trace(ca_tv) parse var text spec =(pt) . +1 text if Word(spec,1) = "DCL" then /* stacked DCL */ spec = DelWord(spec,1,1) /* snip DCL */ "NEWSTACK" "ELEMLEN" spec /* -*/ pull ans call CAA_ANALYZE_RESPONSE ans /* -*/ "DELSTACK" return /*@ CA_ISOLATE_STMT */ /* What did ELEMLEN say? What level is this element at? Group or data? How long? How deep? The response from ELEMLEN contains these elements: # name {varies} Length ## Depth ## Total ## -or- # name {varies} Group of ## In particular, {name} may contain parentheses if it is an array, or the arrayspec might be part of {varies}. In either case, the "Depth" value or the "Group" value is equivalent to any arrayspec present. The "key" of all this data must be the fully-qualified name of any element or group to guard against a duplicate element-name in different sub-structures. . ----------------------------------------------------------------- */ CAA_ANALYZE_RESPONSE: /*@ */ if branch then call BRANCH address TSO arg info /* response from ELEMLEN */ parse var info level name rest if level = "1" then do /* stacked DCL */ call D_ROLL_UP /* -*/ call E_ANNOTATE /* -*/ call A_INIT /* -*/ end /* stacked DCL */ if name = "FILLER" then do fillseq = fillseq + 1 name = name""Right(fillseq,3,0) end wdpt = 0 do Words(parent_q) /* all prior parent levels */ wdpt = wdpt + 1 /* index */ parent_lvl = Word(parent_q,wdpt) /* isolate */ if level > parent_lvl then do parent_name = Word(group_list,wdpt) leave end end /* parent_q */ fq_name = Strip(parent_name":"name , "L" , ":") group_list = Space(fq_name group_list,1) parent_q = Space(level parent_q,1) if SWITCH("GROUP") then, depth.fq_name = KEYWD("OF") /* GROUP OF ## */ else do depth.fq_name = KEYWD("DEPTH") length.fq_name = KEYWD("LENGTH") totlen.fq_name = KEYWD("TOTAL") end elemdata.fq_name = info start.fq_name = start start = start + length.fq_name /* may be zero */ end.fq_name = start - 1 return /*@ CAA_ANALYZE_RESPONSE */ if Pos("GROUP OF",rest) then do /* non-data group */ parse var rest rest "GROUP OF" depth . depth.fq_name = depth end /* All rows have been analyzed. Begin at the bottom and work up, accumulating lengths and annotating non-data group items. . ----------------------------------------------------------------- */ D_ROLL_UP: /*@ */ if branch then call BRANCH address TSO if Subword(Reverse(parent_q), 1, 2) = "1 1" then do revtext = Reverse(parent_q) revtext = Delword(revtext,1,1) /* snip one word */ parent_q = Reverse(revtext) /* restore */ revtext = Reverse(group_list) revtext = Delword(revtext,1,1) /* snip one word */ group_list = Reverse(revtext) /* restore */ end do dx = 1 to Words(group_list) fq_name = Word(group_list,dx) /* isolate */ eff_lvl = Words(Translate(fq_name,' ',':')) efflvl.fq_name = eff_lvl if length.fq_name = 0 then do /* group */ low_lvl = eff_lvl + 1 /* next deeper */ length.fq_name = length.low_lvl /* roll up */ totlen.fq_name = length.fq_name * depth.fq_name end.fq_name = start.fq_name + totlen.fq_name - 1 length.low_lvl = 0 /* reset */ end length.eff_lvl = length.eff_lvl + totlen.fq_name end /* dx */ return /*@ D_ROLL_UP */ /* From the top down, starting at presumed position 1, calculate end position as {start + length - 1}. The start position is the most recent start position of the next superior level. . ----------------------------------------------------------------- */ E_ANNOTATE: /*@ */ if branch then call BRANCH address TSO "CLEAR" do ex = Words(group_list) to 1 by -1 fq_name = Word(group_list,ex) /* isolate */ dcl_lvl = Word(parent_q ,ex) /* isolate */ eff_lvl = Words(Translate(fq_name,' ',':')) say Left( , Copies(' ',2*eff_lvl)""elemdata.fq_name , 45), Left("L="totlen.fq_name,7) , Left("St="start.fq_name,8) , Left("End="start.fq_name + totlen.fq_name - 1,8) end /* ex */ if sw.batch then return "NEWSTACK"; pull ; "DELSTACK " return /*@ E_ANNOTATE */ /* . ----------------------------------------------------------------- */ LOCAL_PREINIT: /*@ customize opts */ address TSO return /*@ LOCAL_PREINIT */ /* subroutines below LOCAL_PREINIT are not selected by SHOWFLOW */ /* . ----------------------------------------------------------------- */ HELP: /*@ */ address TSO;"CLEAR" if helpmsg <> "" then do ; say helpmsg; say ""; end ex_nam = Left(exec_name,8) /* predictable size */ say " "ex_nam" Annotates a PL/1 DCL with information about " say " column-locations for each field. " say " " say " Syntax: "ex_nam" " say " " say " names the source dataset containing a PL/I " say " DCL to be analyzed. " say " " "NEWSTACK"; pull ; "CLEAR" ; "DELSTACK " say " Debugging tools provided include: " say " " say " MONITOR: displays key information throughout processing. " say " " say " NOUPDT: by-pass all update logic. " say " " say " BRANCH: show all paragraph entries. " say " " say " TRACE tv: will use value following TRACE to place the " say " execution in REXX TRACE Mode. " say " " say " " say " Debugging tools can be accessed in the following manner: " say " " say " TSO "ex_nam" parameters (( debug-options " say " " say " For example: " say " " say " TSO "ex_nam" (( MONITOR TRACE ?R " address ISPEXEC "CONTROL DISPLAY REFRESH" exit /*@ HELP */ /* . ----------------------------------------------------------------- */ 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 "QSTACK" /* how many stacks? */ stk2dump = rc - tk_init_stacks /* remaining stacks */ if stk2dump = 0 & queued() = 0 then return 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. */ say "Processing Stack #" dd " Total Lines:" queued() do queued();pull line;say line;end /* pump to the screen */ "DELSTACK" /* remove stack */ end /* dd = 1 to rc */ return /*@ DUMP_QUEUE */ /* . ----------------------------------------------------------------- */ KEYWD: Procedure expose info /*@ hide all vars, except info*/ arg kw 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+1) /* 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 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 ssend . if ssend = "" then ssend = 10 if \datatype(ssbeg,"W") | \datatype(ssend,"W") then return ssend = ssbeg + ssend do ssii = ssbeg to ssend ; say Strip(sourceline(ssii),'T') ; end return /*@ SS */ /* . ----------------------------------------------------------------- */ SWITCH: Procedure expose info /*@ */ arg kw 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 */ 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 . sw.nested = sysvar("SYSNEST") = "YES" sw.batch = sysvar("SYSENV") = "BACK" sw.inispf = sysvar("SYSISPF") = "ACTIVE" parse value KEYWD("TRACE") "O" 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 */