/* REXX ELEMLEN This demonstration program will calculate the length of storage required for a PL/I declared variable. This rtn has few diagnostic features and is meant to be called only by another REXX rtn. Written by Frank Clarke 20010514 rexxhead@yahoo.com Impact Analysis . SYSPROC TRAPOUT Modification History 20021119 fxc upgrade from v.19991109 to v.20021008; 20040708 fxc recognize CTL and CONTROLLED 20051206 fxc QUIET; 20240423 fxc DUMP_QUEUE quiet; 20250404 fxc clip too-long lines; 20250810 fxc adjust HELP; 20250918 fxc SPACEOUT; new BACKEND; 20250925 fxc chg setting of sw. to sw.0; */ arg argline address TSO /* REXXSKEL ver.20021008 */ arg parms "((" opts signal on syntax signal on novalue call TOOLKIT_INIT /* conventional start-up -*/ rc = Trace( "O" ); rc = Trace( tv ) info = parms /* to enable parsing */ call A_INIT /* -*/ call B_ANALYZE /* -*/ push parms response if \sw.0nested then call DUMP_QUEUE 'quiet' /* -*/ exit /*@ ELEMLEN */ /* . ----------------------------------------------------------------- */ A_INIT: /*@ */ address TSO parse value "0 0 0 0 0 0 0 0 0 0 0 0" with, stg_len , . parse value "" with t1 t2, varn arrspec arrlim , response , . return /*@ A_INIT */ /* . ----------------------------------------------------------------- */ B_ANALYZE: /*@ */ address TSO call BA_GET_VARNAME /* -*/ call BB_WHAT_TYPE /* -*/ if sw.0nodata then return /* no data type */ call BC_CALC_SPACE /* -*/ if sw.0baseelem then do response = "Align on" baseelem return /* */ end /* BASED */ if sw.0baseptr then do response = "Pointer aligned" return /* */ end /* BASED */ if arrlim = "Indet" then, stg_tot = "Indet" else, stg_tot = stg_len * arrlim response = "Length" stg_len "Depth" arrlim "Total" stg_tot return /*@ B_ANALYZE */ /* Parse the variable name from the input. Is it an array-spec? . ----------------------------------------------------------------- */ BA_GET_VARNAME: /*@ */ address TSO parse var info t1 info /* first token */ if Datatype( t1,"W" ) then do /* whole number */ if t1 = 1 then sw.0lvl1 = 1 parse var info t1 info /* variable name */ end varn = t1 if Left( info,1 ) = "( " then, /* separated arrayspec */ parse var info "(" arrspec ")" info if arrspec <> "" then, varn = varn"("Space( arrspec,0 )")" parse var varn "(" arrspec ")" /* maybe was original */ if arrspec = "" then arrlim = 1 /* not an array */ else, if Pos( ":",arrspec ) > 0 then do /* range */ parse var arrspec lolim ":" hilim if Datatype( hilim,"W" ) + Datatype( lolim,"W" ) < 2 then do arrlim = "Indet" if sw.0lvl1 then arrlim = 1 /* based or controlled */ end else, arrlim = hilim - lolim + 1 /* 3:5 = 5-3+1=3 */ end else arrlim = arrspec if Datatype( arrlim,"W" ) = 0 then arrlim = "Indet" return /*@ BA_GET_VARNAME */ /* Determine type: BIN, DEC, CHAR, PIC, PTR. What else? . ----------------------------------------------------------------- */ BB_WHAT_TYPE: /*@ */ address TSO slug = Space( info,0 ) /* squeeze all spaces out */ if slug = "" then do sw.0nodata = "1" response = "Group of" arrlim return /* has no type */ end info = Space( info,1 ) /* compress */ reserve = "" do while info <> "" if Left( info,3 ) = "DEC" then do if Left( info,7 ) = "DECIMAL" then L = 7 ; else L = 3 info = Delstr( info,1,L ) sw.0decimal = "1" call BBP_SNIP_PAREN /* -*/ end /* DEC */ else, if Left( info,3 ) = "PIC" then do if Left( info,7 ) = "PICTURE" then L = 7 ; else L = 3 info = Delstr( info,1,L ) sw.0pic = "1" call BBQ_SNIP_QUOTE /* -*/ end /* PIC */ else, if Left( info,3 ) = "BIN" then do if Left( info,6 ) = "BINARY" then L = 6 ; else L = 3 info = Delstr( info,1,L ) sw.0binary = "1" call BBP_SNIP_PAREN /* -*/ end /* BIN */ else, if Left( info,3 ) = "BIT" then do info = Delstr( info,1,3 ) sw.0bit = "1" call BBP_SNIP_PAREN /* -*/ end /* BIT */ else, if Left( info,4 ) = "CHAR" then do if Left( info,9 ) = "CHARACTER" then L = 9 ; else L = 4 info = Delstr( info,1,L ) sw.0char = "1" call BBP_SNIP_PAREN /* -*/ end /* CHAR */ else, if Left( info,3 ) = "VAR" then do if Left( info,7 ) = "VARYING" then L = 7 ; else L = 3 info = Strip( Delstr( info,1,L ) ) sw.0varchar = "1" end /* VAR */ else, if Left( info,3 ) = "CTL" then do info = Strip( Delstr( info,1,3 ) ) sw.0Ctl = 1 if arrlim = "Indet" then arrlim = 1 end /* CTL */ else, if Left( info,10 ) = "CONTROLLED" then do info = Strip( Delstr( info,1,10 ) ) sw.0Ctl = 1 if arrlim = "Indet" then arrlim = 1 end /* CONTROLLED */ else, if Left( info,5 ) = "BASED" then do info = Strip( Delstr( info,1,5 ) ) if Left( info,5 ) = "( ADDR" then do parse var info "(" . "(" baseelem "))" info info = Space( info,1 ) /* compress */ sw.0baseelem = "1" end /* ADDR */ else do parse var info "(" baseptr ")" info info = Space( info,1 ) /* compress */ sw.0baseptr = "1" end /* */ end /* BASED */ else, if Left( info,3 ) = "PTR" then do L = 3 info = Delstr( info,1,L ) info = Space( info,1 ) /* compress */ sw.0ptr = "1" end /* PTR */ else, if Left( info,7 ) = "POINTER" then do L = 7 info = Delstr( info,1,L ) info = Space( info,1 ) /* compress */ sw.0ptr = "1" end /* POINTER */ else, if Left( info,5 ) = "FLOAT" then do L = 5 info = Delstr( info,1,L ) info = Space( info,1 ) /* compress */ sw.0float = "1" call BBP_SNIP_PAREN /* -*/ end /* FLOAT */ else, if Left( info,5 ) = "FIXED" then do L = 5 info = Delstr( info,1,L ) info = Space( info,1 ) /* compress */ sw.0fixed = "1" call BBP_SNIP_PAREN /* -*/ end /* FIXED */ else, do parse var info badt info if sw.0Quiet = 0 then, say "Unrecognized token:" badt end end /* while info <> empty */ return /*@ BB_WHAT_TYPE */ /* For CHAR, DEC, and BIN, bounded by bananas. . ----------------------------------------------------------------- */ BBP_SNIP_PAREN: /*@ */ address TSO info = Strip( info ) if Left( info,1 ) <> "( " then return parse var info slug ")" info reserve = reserve slug")" info = Space( info,1 ) return /*@ BBP_SNIP_PAREN */ /* For PIC, what's between the quotes? . ----------------------------------------------------------------- */ BBQ_SNIP_QUOTE: /*@ */ address TSO info = Strip( info ) if Left( info,1 ) <> "'" then return parse var info "'"slug "'" info reserve = reserve "'"slug"'" info = Space( info,1 ) return /*@ BBQ_SNIP_QUOTE */ /* How much storage is implied by the dataspec? . ----------------------------------------------------------------- */ BC_CALC_SPACE: /*@ */ address TSO if sw.0fixed | sw.0float then, if sw.0decimal + sw.0binary = 0 then, sw.0decimal = 1 if sw.0decimal then do parse var reserve "(" dataspec ")" reserve parse var dataspec dataspec "," stg_len = (dataspec+2)%2 /* 5+2 %2 = 3 */ end ; else, /* DEC */ if sw.0binary then do parse var reserve "(" dataspec ")" reserve parse var dataspec dataspec "," if dataspec < 16 then stg_len = 2 ; else, if dataspec < 32 then stg_len = 4 ; else, if dataspec < 64 then stg_len = 8 end ; else, /* BIN */ if sw.0bit then do parse var reserve "(" dataspec ")" reserve stg_len = (dataspec + 7) % 8 end ; else, /* BIN */ if sw.0char then do parse var reserve "(" dataspec ")" reserve stg_len = dataspec if sw.0varchar then stg_len = stg_len + 2 end ; else, /* CHAR */ if sw.0ptr then do stg_len = 4 end ; else, /* PTR */ if sw.0baseelem then do stg_len = 0 end ; else, /* BASEELEM */ if sw.0baseptr then do stg_len = 0 end ; else, /* BASEPTR */ if sw.0pic then do parse var reserve "'" dataspec "'" reserve pt = Pos( ")",dataspec ) if pt <> 0 then do /* multiplier... */ multspec = Substr( Dataspec,1,pt+1 ) dataspec = Delstr( Dataspec,1,pt+1 ) parse var multspec "(" factor ")" end ; else factor = 0 /* pt <> 0 */ dataspec = Translate( dataspec," ","V" ) dataspec = Space( dataspec,0 ) /* squeeze */ stg_len = Length( dataspec ) + factor end /* PIC */ return /*@ BC_CALC_SPACE */ /* . ----------------------------------------------------------------- */ LOCAL_PREINIT: /*@ customize opts */ address TSO sw.0Quiet = SWITCH( "QUIET" ) return /*@ LOCAL_PREINIT */ /* subroutines below LOCAL_PREINIT are not selected by SHOWFLOW */ /* . ----------------------------------------------------------------- */ HELP: /*@ */ address TSO;"CLEAR" if helpmsg <> "" then say helpmsg ex_nam = Left( exec_name,8 ) /* predictable size */ say " " say " "ex_nam" demonstrates how to calculate the storage occupied by a " say " PL/I variable by examining the declaration. " say " " say " Syntax: "ex_nam" " say " " say " text a single PL/I data declaration. The process does " say " not respond well to embedded comments. The routine " say " will determine whether this is an array and whether " say " it is binary, decimal, character or picture. If " say " picture, the spec is checked for a repetition spec " say " and this length is included in the total length. " "NEWSTACK"; pull ; "CLEAR" ; "DELSTACK" say " Debugging tools provided include: " say " " say " TRACE tv: will use value following TRACE to place the execution in" say " 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" (( trace ?r branch " if sysvar( "SYSISPF" ) = "ACTIVE" then, 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 ) /* 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( '5d40'x,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 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 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" )", info if wordpos( dlm,back ) = 0 then /* search for ending delimiter*/ helpmsg = helpmsg, "No matching second delimiter( "dlm" ) with KEYPHRS( "kp" )", info 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','5d'x ) /* 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.0nested = sysvar( "SYSNEST" ) = "YES" sw.0batch = sysvar( "SYSENV" ) = "BACK" sw.0inispf = sysvar( "SYSISPF" ) = "ACTIVE" parse value KEYWD( "TRACE" ) "N" with tv . 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 . 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 */