$T.REX: Difference between revisions
Content added Content deleted
m (added more whitespace. -- ~~~~) |
(added whitespace, used better indentations, changed comments, add more idiomatic code, other cosmetic changes.) |
||
Line 42: | Line 42: | ||
<br>Some REXXes doen't have a '''SOUND''' BIF, so one is included here ──► [[SOUND.REX]]. |
<br>Some REXXes doen't have a '''SOUND''' BIF, so one is included here ──► [[SOUND.REX]]. |
||
<br><br>REXX programs not included are '''$H''' which shows '''help''' and other documentation. |
<br><br>REXX programs not included are '''$H''' which shows '''help''' and other documentation. |
||
<lang rexx>/**/ trace off |
<lang rexx>/*REXX*/ trace off /* There be many dragons below. */ |
||
parse arg ! |
parse arg ! |
||
if !all(0) then exit 0 |
if !all(0) then exit 0 /*help options and boilerplate.*/ |
||
zz = !! /*save a copy of original args. */ |
zz = !! /*save a copy of original args. */ |
||
if !cms then address '' |
if !cms then address '' |
||
signal on halt /*be able to handle a HALT. */ |
signal on halt /*be able to handle a HALT. */ |
||
signal on |
signal on noValue /*catch REXX vars with noValue. */ |
||
signal on syntax /*catch REXX syntax errors. */ |
signal on syntax /*catch REXX syntax errors. */ |
||
numeric digits 300 /*be able to handle some big 'uns*/ |
numeric digits 300 /*be able to handle some big 'uns*/ |
||
Line 70: | Line 70: | ||
scr0 shics VMout VScolor VSdisp x1 x2 |
scr0 shics VMout VScolor VSdisp x1 x2 |
||
@abc = 'abcdefghijklmnopqrstuvwxyz' |
@abc = 'abcdefghijklmnopqrstuvwxyz' |
||
@abcU = @abc; upper @abcU |
|||
#ms = 0 |
#ms = 0 |
||
?.a = 0 |
?.a = 0 |
||
?.b = 0 |
?.b = 0 |
||
?.block = 0 |
?.block = 0 |
||
?.e = 0 |
?.e = 0 |
||
?.end = 0 |
?.end = 0 |
||
?.i = 0 |
?.i = 0 |
||
?.ks = 0 |
?.ks = 0 |
||
?.L = 0 |
?.L = 0 |
||
?.p = 0 |
?.p = 0 |
||
?.q = 0 |
?.q = 0 |
||
?.r = 0 |
?.r = 0 |
||
?.ruler = 0 |
?.ruler = 0 |
||
?.s = 0 |
?.s = 0 |
||
?.scale = 0 |
?.scale = 0 |
||
?.ts = 0 |
?.ts = 0 |
||
?.x = 0 |
?.x = 0 |
||
?.z = 0 |
?.z = 0 |
||
boxing = 0 |
boxing = 0 |
||
highL = 0 |
highL = 0 |
||
LLd = 0 |
LLd = 0 |
||
LLk = 0 |
LLk = 0 |
||
LLx = 0 |
LLx = 0 |
||
maxhic = 0 |
maxhic = 0 |
||
## = 1 |
## = 1 |
||
Line 102: | Line 103: | ||
?.t = 1 |
?.t = 1 |
||
?.bd |
?.bd = .2 |
||
?.bf |
?.bf = 800 |
||
?.bs |
?.bs = 2 |
||
?.o |
?.o = 9999 |
||
?.rulerb |
?.rulerb = ' ' |
||
?.scaleb |
?.scaleb = ' ' |
||
?.scaled |
?.scaled = '.' |
||
?.scalep |
?.scalep = '+' |
||
?.use |
?.use = '.' |
||
esc |
esc = '1b'x"[" |
||
his='H() H{} H[] H<> H≤≥ H«» H/\ |
his='H() H{} H[] H<> H≤≥ H«» H/\' |
||
#his=words(his) |
|||
do jh=1 for |
do jh=1 for #his |
||
hh.jh=substr(word(his,jh),2) |
hh.jh=substr(word(his,jh),2) |
||
end /*jh*/ |
end /*jh*/ |
||
colorSupport=!pcrexx | !r4 | !roo /*colors are supported by these. */ |
|||
boxCH = '+-+|+-+|' /*define some boxing characters. */ |
boxCH = '+-+|+-+|' /*define some boxing characters. */ |
||
Line 122: | Line 126: | ||
if !dos then boxCH = 'c9cdbbbabccdc8ba'x /*╔═╗║╝═╚║ <──double box.*/ |
if !dos then boxCH = 'c9cdbbbabccdc8ba'x /*╔═╗║╝═╚║ <──double box.*/ |
||
if |
if colorSupport then do /*use pre-saved color values. */ |
||
_=translate(!var('SCREEN'), ,";,") /*envVar.*/ |
|||
if \datatype(space(_,0), "W") then _='36 40' |
|||
scr0=esc || translate(0 _, ';', " ")'m' |
|||
colorC.0=scr0 |
|||
colorC.1=esc"1;33m" |
|||
end |
|||
do jz=1 while zz\=='' |
do jz=1 while zz\=='' |
||
if ?.end==1 | pos('=',zz)==0 | pos(" "?.use,' 'zz)==0 then do |
if ?.end==1 | pos('=',zz)==0 | pos(" "?.use,' 'zz)==0 then do |
||
@=@ zz |
@=@ zz |
||
Line 135: | Line 140: | ||
end |
end |
||
if left(zz,1)==' ' then lz=lz" " |
if left(zz,1)==' ' then lz=lz" " |
||
parse var zz yy1 2 yy2 3 1 yy ' ' zz |
parse var zz yy1 2 yy2 3 1 yy ' ' zz |
||
if yy1==?.use & pos('=',yy)\==0 & datatype(yy2,"U") then |
if yy1==?.use & pos('=',yy)\==0 & datatype(yy2,"U") then |
||
do 1 |
do 1 |
||
parse var yy 2 _ "=" dotv 2 _1 3 |
parse var yy 2 _ "=" dotv 2 _1 3 |
||
if datatype(_,'U') then |
if datatype(_,'U') then |
||
do |
do |
||
Line 149: | Line 154: | ||
end |
end |
||
else select |
else select |
||
when _=='BIN' then yy=valn("'"dotv"'B",'BIN',"B") |
when _=='BIN' then yy=valn("'"dotv"'B",'BIN',"B") |
||
when _=='BOX' then do |
when _=='BOX' then do |
||
if dotv=="" then ?.BOX=boxCH |
if dotv=="" then ?.BOX=boxCH |
||
else ?.BOX=dotv |
else ?.BOX=dotv |
||
iterate jz |
iterate jz |
||
end |
end |
||
when _=='DEC' then yy=valn("'"dotv"'D",'DEC',"D") |
when _=='DEC' then yy=valn("'"dotv"'D",'DEC',"D") |
||
when _=='INV' then yy=.inv(dotv) |
when _=='INV' then yy=.inv(dotv) |
||
when _=='HEX' then yy=valn("'"dotv"'X",'HEX',"X") |
when _=='HEX' then yy=valn("'"dotv"'X",'HEX',"X") |
||
when _=='USE' then do |
when _=='USE' then do |
||
dotv=tb(dotv,"USE",'.') |
dotv=tb(dotv,"USE",'.') |
||
iterate jz |
iterate jz |
||
end |
end |
||
otherwise ?._=dotv; iterate jz |
otherwise ?._=dotv; iterate jz |
||
end /*select*/ |
end /*select*/ |
||
end |
end |
||
Line 173: | Line 178: | ||
end |
end |
||
end |
end |
||
end /*1*/ |
end /*do 1*/ |
||
if @=='' then @=lz || yy |
if @=='' then @=lz || yy |
||
Line 180: | Line 185: | ||
end /*jz*/ |
end /*jz*/ |
||
if left(@,1)==' ' then @=substr(@,2) |
if left(@,1)==' ' then @=substr(@,2) /*handle this special case. */ |
||
if ?.a\==0 then call .a |
if ?.a\==0 then call .a |
||
Line 193: | Line 198: | ||
if ?.f\=='' then call .f |
if ?.f\=='' then call .f |
||
do _j=1 for |
do _j=1 for #his |
||
_=?.hi._j |
_=?.hi._j |
||
if _\=='' & \!regina then do |
if _\=='' & \!regina then do |
||
Line 201: | Line 206: | ||
end /*_j*/ |
end /*_j*/ |
||
if ?.i\==0 then do |
if ?.i\==0 then do |
||
call wn 'I',0,sw() |
|||
?.ib=tb(?.ib,'IB') |
|||
⚫ | |||
if ?.j\=='' then call .j |
if ?.j\=='' then call .j |
||
if ?.k\=='' then ?.k =valn(?.k,"K") |
if ?.k\=='' then ?.k =valn(?.k,"K") |
||
Line 270: | Line 278: | ||
end /*select*/ |
end /*select*/ |
||
if ?.block==0 then call tellIt _ |
if ?.block==0 then call tellIt _ |
||
else call blocker |
else call blocker |
||
end /*jj*/ |
end /*jj*/ |
||
end /*jt*/ |
end /*jt*/ |
||
Line 287: | Line 295: | ||
when ?.L\==0 then call sayAline |
when ?.L\==0 then call sayAline |
||
otherwise call sayNline |
otherwise call sayNline |
||
end /*select*/ |
end /*select*/ |
||
if ?.c\=='' then call VMcolor VMout,space(VScolor VSdisp) |
if ?.c\=='' then call VMcolor VMout,space(VScolor VSdisp) |
||
Line 295: | Line 303: | ||
if ?.scale>0 then call inches ?.scale,1 |
if ?.scale>0 then call inches ?.scale,1 |
||
_=abs(?.a) |
_=abs(?.a) |
||
if _==99 & \?.q then !cls |
if _==99 & \?.q then !cls |
||
else do min(99,_) |
else do min(99,_) |
||
call wit bline |
call wit bline |
||
end /*min( |
end /*min(···*/ |
||
if ?.w\=='' then call .w |
if ?.w\=='' then call .w |
||
if !pcrexx then if ?.q & LLd>79 then if LLd>sw() then say |
if !pcrexx then if ?.q & LLd>79 then if LLd>sw() then say |
||
/*(above) PC-REXX bug: wrapped lines are |
/*(above) PC-REXX bug: wrapped lines are*/ |
||
/* overwritten during cleanup. */ |
/* overwritten during cleanup. */ |
||
return 0 |
return 0 |
||
Line 310: | Line 320: | ||
.b: call wn 'B',-99,99,sd() /*B is for beeps (sounds). */ |
.b: call wn 'B',-99,99,sd() /*B is for beeps (sounds). */ |
||
if ?.bd\==.2 then do |
if ?.bd\==.2 then do |
||
_=translate(?.bd,,',') |
_=translate(?.bd,,',') |
||
__=_ |
__=_ |
||
do while __\=='' |
do while __\=='' |
||
parse var __ ?.bd __ |
parse var __ ?.bd __ |
||
call wn 'BD', .1, 9, ,"N" |
call wn 'BD', .1, 9, ,"N" |
||
end /*while*/ |
end /*while*/ |
||
?.bd=_ |
?.bd=_ |
||
end |
end |
||
if ?.bf\==800 then do |
if ?.bf\==800 then do |
||
_=translate(?.bf,,',') |
_=translate(?.bf,,',') |
||
__=_ |
__=_ |
||
do while __\=='' |
do while __\=='' |
||
parse var __ ?.bf __ |
parse var __ ?.bf __ |
||
call wn 'BF', 1, 20000 |
call wn 'BF', 1, 20000 |
||
end /*while*/ |
end /*while*/ |
||
?.bf=_ |
?.bf=_ |
||
end |
end |
||
return |
return |
||
Line 342: | Line 352: | ||
if _=='*NONE*' then ?.box= |
if _=='*NONE*' then ?.box= |
||
boxing= ?.box\=='' |
boxing= ?.box\=='' |
||
if \boxing then return |
if \boxing then return |
||
if _=='SINGLELINE' then _=boxCH |
if _=='SINGLELINE' then _=boxCH |
||
Line 351: | Line 361: | ||
end /*_*/ |
end /*_*/ |
||
_=verify(@,' ')-1 |
_=verify(@,' ')-1 |
||
if _>0 then @=@ || copies(" ", |
if _>0 then @=@ || copies(" ",_) |
||
return |
return |
||
Line 360: | Line 370: | ||
call cp 'QUERY SCREEN',1 |
call cp 'QUERY SCREEN',1 |
||
parse var cp.1 "VMOUT" VMout |
parse var cp.1 "VMOUT" VMout |
||
'QUERY VSCREEN CMS ALL(LIFO' |
'QUERY VSCREEN CMS ALL (LIFO' |
||
if rc==0 then pull "(" . . VScolor VSdisp . |
if rc==0 then pull "(" . . VScolor VSdisp . |
||
if ?.c=='BRITE' then call VMcolor "DEFAULT NONE" |
if ?.c=='BRITE' then call VMcolor "DEFAULT NONE" |
||
Line 366: | Line 376: | ||
end |
end |
||
if |
if \colorSupport then ?.c= /*Most REXXes don't support color*/ |
||
return |
return |
||
Line 386: | Line 396: | ||
/*──────────────────────────────────.EF subroutine──────────────────────*/ |
/*──────────────────────────────────.EF subroutine──────────────────────*/ |
||
ef: if ?.f\=='' then call er 61, '.F= .EF=' /*conflicting options.*/ |
ef: if ?.f\=='' then call er 61, '.F= .EF=' /*conflicting options.*/ |
||
?.f = ?.ef |
|||
return |
return |
||
Line 406: | Line 416: | ||
/*──────────────────────────────────.J subroutine───────────────────────*/ |
/*──────────────────────────────────.J subroutine───────────────────────*/ |
||
.j: upper ?.j /*Justify (or not) the text. */ |
.j: upper ?.j /*Justify (or not) the text. */ |
||
if ?.j=='' then ?.j |
if ?.j=='' then ?.j= 'N' /*Justify (or not) the text. */ |
||
else ?.j=left(?.j,1) |
else ?.j= left(?.j,1) /*just use the first letter of .J*/ |
||
if pos(?.j,"ACJLNR")==0 then call er 55, ?.j '.J=' |
if pos(?.j,"ACJLNR")==0 then call er 55, ?.j '.J=' |
||
Line 422: | Line 432: | ||
/*──────────────────────────────────.L subroutine───────────────────────*/ |
/*──────────────────────────────────.L subroutine───────────────────────*/ |
||
.L: upper ?.L /*Line(s) for the text is shown. */ |
.L: upper ?.L /*Line(s) for the text is shown. */ |
||
if !cms then do |
if !cms then do |
||
'$QWHAT DSC' |
'$QWHAT DSC' |
||
if rc==4 then ?.L=0 |
if rc==4 then ?.L=0 |
||
end |
end |
||
if ?.L=='CMSG' then ?.L="*" |
if ?.L=='CMSG' then ?.L="*" |
||
call wn 'L',-sd(),sd() |
call wn 'L',-sd(),sd() |
||
if ?.L<0 then ?.L=sd()-?.L |
if ?.L<0 then ?.L=sd()-?.L |
||
return |
return |
||
Line 473: | Line 483: | ||
if ?.s<0 then do |
if ?.s<0 then do |
||
if left(?.o,1)=='-' |
if left(?.o,1)=='-' then /*check for conflicting options*/ |
||
call er 61,"O="?.o 'S='?.s "(both can't be negative)" |
call er 61,"O="?.o 'S='?.s "(both can't be negative)" |
||
onlys = -?.s |
onlys = -?.s |
||
Line 479: | Line 489: | ||
end |
end |
||
if left(?.o,1)=="-" & left(?.s,1)=='-' then |
if left(?.o,1)=="-" & left(?.s,1)=='-' then |
||
call er 61,"O="?.o 'S='?.s "(both can't be negative)" |
call er 61,"O="?.o 'S='?.s "(both can't be negative)" |
||
return |
return |
||
Line 519: | Line 529: | ||
/*──────────────────────────────────.W subroutine───────────────────────*/ |
/*──────────────────────────────────.W subroutine───────────────────────*/ |
||
.w: if ?.q then return |
.w: if ?.q then return |
||
if ?.wb\=='' then ?.wb=tb(?.wb, 'WB') |
if ?.wb\=='' then ?.wb=tb(?.wb, 'WB') |
||
ww=translate(?.w,,"_") |
ww=translate(?.w,,"_") |
||
if ww='dd'x then ww = "press any key to continue ..." |
if ww='dd'x then ww = "press any key to continue ..." |
||
if ww='de'x then ww = "press the ENTER key to continue ..." |
if ww='de'x then ww = "press the ENTER key to continue ..." |
||
call '$T' ".C=yel" translate(ww,?.wb,' ') |
|||
if ww='dd'x then call inkey |
if ww='dd'x then call inkey |
||
if ww='de'x then pull external |
if ww='de'x then pull external |
||
return |
return |
||
Line 539: | Line 549: | ||
/*──────────────────────────────────.XK subroutine──────────────────────*/ |
/*──────────────────────────────────.XK subroutine──────────────────────*/ |
||
.xk: do ##=1 |
.xk: do ##=1 |
||
parse var @ _ (xk) @ |
parse var @ _ (xk) @ |
||
if _=='' & @=="" then leave |
if _=='' & @=="" then leave |
||
tx.## = _ |
tx.## = _ |
||
Line 565: | Line 575: | ||
call sound word(?.bf, jb_), word(word(?.bd,jb_) .2,1) |
call sound word(?.bf, jb_), word(word(?.bd,jb_) .2,1) |
||
end /*jb_*/ |
end /*jb_*/ |
||
end /*jb */ |
end /*jb */ |
||
return |
return |
||
Line 622: | Line 631: | ||
if dark & left(cc,2)=='1;' then cc="0"substr(cc,2) |
if dark & left(cc,2)=='1;' then cc="0"substr(cc,2) |
||
if !cms then do |
if !cms then do |
||
if hue='GRAY' | hue=="BLACK" then hue='WHITE' |
if hue='GRAY' | hue=="BLACK" then hue='WHITE' |
||
if hue="BROWN" then hue='YELLOW' |
if hue="BROWN" then hue='YELLOW' |
||
end |
end |
||
color.cc# = hue |
color.cc# = hue |
||
Line 679: | Line 688: | ||
else _=$scale(?.ruler 'RULE' _ 'Q') |
else _=$scale(?.ruler 'RULE' _ 'Q') |
||
parse var _ _.1 '9'x _.2 '9'x _.3 |
parse var _ _.1 '9'x _.2 '9'x _.3 |
||
do jk=1 for 3 |
do jk=1 for 3 |
||
Line 689: | Line 698: | ||
/*──────────────────────────────────MS subroutine───────────────────────*/ |
/*──────────────────────────────────MS subroutine───────────────────────*/ |
||
ms: #ms=#ms+1 /*justification and indentation. */ |
ms: #ms=#ms+1 /*justification and indentation. */ |
||
parse arg _i |
parse arg _i |
||
select |
select |
||
Line 711: | Line 720: | ||
if \?.q then do |
if \?.q then do |
||
if !cms then '$CLEAR .WL='?.L _mm |
if !cms then '$CLEAR .WL='?.L _mm |
||
if !dos then call dsay, |
if !dos then call dsay, |
||
esc || (?.L-1) || ";0f"colorC.0 || _mm || scr0 |
esc || (?.L-1) || ";0f"colorC.0 || _mm || scr0 |
||
end |
end |
||
Line 726: | Line 735: | ||
if skp() then iterate |
if skp() then iterate |
||
call wr _mm |
call wr _mm |
||
if ?.q then iterate |
if ?.q then iterate |
||
if !cms then '$CLEAR .C=BRITE' _mm |
if !cms then '$CLEAR .C=BRITE' _mm |
||
else if !dos then call dsay colorC.0 || _mm || scr0 |
else if !dos then call dsay colorC.0 || _mm || scr0 |
||
end /*jj*/ |
end /*jj*/ |
||
return |
return |
||
Line 737: | Line 746: | ||
if skp() then iterate |
if skp() then iterate |
||
if !dos then do |
if !dos then do |
||
if ?.c=='' then call dsay _mm |
if ?.c=='' then call dsay _mm |
||
else call dsay colorC.0 || _mm || scr0 |
else call dsay colorC.0 || _mm || scr0 |
||
call wr _mm |
call wr _mm |
||
end |
end |
||
else call wit _mm |
else call wit _mm |
||
end /*jj*/ |
end /*jj*/ |
||
return |
return |
||
Line 844: | Line 853: | ||
/*──────────────────────────────────VMCOLOR subroutine──────────────────*/ |
/*──────────────────────────────────VMCOLOR subroutine──────────────────*/ |
||
VMcolor: if \!cms then return |
VMcolor: if \!cms then return |
||
parse arg c1,c2 |
parse arg c1,c2 |
||
if c1\=='' then call cp "SCREEN VMOUT" c1 |
if c1\=='' then call cp "SCREEN VMOUT" c1 |
||
if c2\=='' then "SET VSCREEN CMS" c2 |
if c2\=='' then "SET VSCREEN CMS" c2 |
||
Line 852: | Line 861: | ||
/*──────────────────────────────────WN subroutine───────────────────────*/ |
/*──────────────────────────────────WN subroutine───────────────────────*/ |
||
wn: procedure expose ?. /*normalize, validate N in range.*/ |
wn: procedure expose ?. /*normalize, validate N in range.*/ |
||
arg z, L, H, d, t |
arg z, L, H, d, t |
||
_ = ?.z |
_ = ?.z |
||
parse upper var _ f 2 |
parse upper var _ f 2 |
||
m = pos(f,'MH')\==0 |
m = pos(f,'MH')\==0 |
||
if m | |
if m | f=='*' then do |
||
_ = (word(d H L sw(),1)) / word(1 2,m+1)substr(_,2) |
|||
f=='*' then do |
|||
if \datatype(_,"N") then interpret '_='translate(_,"%",'/') |
|||
?.z = _ |
|||
end |
|||
⚫ | |||
if datatype(_,"N") then ?.z = _/1 |
if datatype(_,"N") then ?.z = _/1 |
||
if \datatype(_,left(t"W",1)) then call er 53, _ '.'z"=" |
if \datatype(_,left(t"W",1)) then call er 53, _ '.'z"=" |
||
if L\=='' then if _<L|_>H |
if L\=='' then if _<L | _>H then call er 81,L H _ "value for option ."z'=' |
||
return _ |
return _ |
||
/*──────────────────────────────────WR subroutine───────────────────────*/ |
/*──────────────────────────────────WR subroutine───────────────────────*/ |
||
wr: parse arg |
wr: parse arg wr /*write [argument 1] ───> disk. */ |
||
if ?.f=='' then return /*Nothing to write? Then skip it.*/ |
if ?.f=='' then return /*Nothing to write? Then skip it.*/ |
||
if highL & ahics\=='' then wr=translate(wr,, ahics) /*has highlighting?*/ |
if highL & ahics\=='' then wr=translate(wr,, ahics) /*has highlighting?*/ |
||
Line 879: | Line 887: | ||
call lineout ?.f /*close the file. */ |
call lineout ?.f /*close the file. */ |
||
return |
return 0 |
||
/*═════════════════════════════general 1-line subs═════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════*/ |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
</lang> |
|||
/*═════════════════════════════general 1-line subs══════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════*/ |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ |