[Date Prev][Date Next][Subject Prev][Subject Next][ Date Index][ Subject Index]

Re: elements of xy4 programming



This may not be what Morris wants, either, but here is a demo program with
comments that I did several years ago. WILDFUNC is a "wildcard" routine that
SEarches for the next 3-byte function.

Note: Updating this routine for NBWin is left as an exercise for the reader.
Hint: Some NB functions have Ascii-131 as the 2nd byte.

XPLeNCODE v2.0
b-gin [UNTITLED]
{<}GLa{>}[cr|lf]{{;5wildfunc}} Template for "wild" function s
earch [CLD rev. 11/7/2000][cr|lf]{002};*;     Working co
de with comments (read in eXPanded view)[cr|lf];*;     {032}
RUN WILDFUNC.PM against itself to see it work[cr|lf];*;[cr|lf
];*; Exit codes (returned in S/G 50):[cr|lf];*; -1 = No fil
e in current window[cr|lf];*;  0 = Func not found[cr|lf];*;{032}
 1 = Found non-standard func[cr|lf];*;  2 = Found standard{032}
func[cr|lf];*;[cr|lf];*; Preliminaries[cr|lf];*; Cancel any d
isplayed menu or dialog box (func XH). Check for a file[cr|lf
];*; in the current window; if none, report the error and EXi
t[cr|lf]{<}LBa{>}[XH_]{<}IF{<}VA$WS{>}<>1{>}{<}SV50,-1{>}{<}P
RNo file{>}{<}EX{>}{<}EI{>};*;[cr|lf];*;[cr|lf];*; Freeze the
 display (DX) (optional); no need to unfreeze (DO) later,[cr|
lf];*; because we EXit when func is found (or not found); Xy|
NBWin restores[cr|lf];*; the display automatically on EXit. E
nable Error Suppression (ES 1)[cr|lf][DX_][BX_]es 1[Q2_];*;[c
r|lf];*;[cr|lf];*; Put a 1-byte Ascii-255 into Save/Get (S/G)
 52 for later use[cr|lf];*; (procedure: parse func NO [;255+1
29+163] around Ascii-129)[cr|lf]{<}SV51,[NO_]{>}{<}SV52,{129}
{>}{<}XS51,52,52,,53{>};*; <== S/G 52 has Ascii-255![cr|lf];*
;[cr|lf];*; Set some initial values (don't overwrite S/G 52 -
- we need it!)[cr|lf];*; 51=single-char parsing wildcard; 53=
initial cursor position[cr|lf]{<}SV51,{027}X{>}{<}SX53,{<}CP{
>}{>};*;[cr|lf];*;[cr|lf];*; Now let's save an array of all o
dd-numbered 1-byte Ascii chars[cr|lf];*; to S/G 54. First, w
e use an indirect method to save Ascii-1[cr|lf];*; to S/G 55.
 We do this to make WILDFUNC.PM "U2-friendly"; Ascii-1[cr|lf
];*; and -2 act as code delimiters in Help files, so they can
't[cr|lf];*; appear literally in XPL routines stored in such{032}
files (e.g.,[cr|lf];*; XYWWWEB.U2). So let's parse a func @0{032}
[;255-128-1] around Ascii-128:[cr|lf]{<}SV54,[@0_]{>}{<}SV55,
{128}{>}{<}XS54,55,,56,55{>};*; <== S/G 55 ha
s Ascii-1![cr|lf];*;[cr|lf];*; Next, we use an indirect metho
d to save an Ascii-175 right guillemet[cr|lf];*; ([255+065+07
0]) to S/G 54. This avoids unbalanced guillemets ([255+065+06
9] [255+065+070] [255+065+070]) in the[cr|lf];*; concatenatio
n that follows[cr|lf]{<}SV54,{<}|{>}{>}{<}SX54,{<}VA@54|2{>}{
>};*; <== S/G 54 has Ascii-175![cr|lf];*;[cr|lf];*; Now we're
 ready to string the whole array together, in S/G 54[cr|lf]{<
}SX54,{<}IS55{>}+"{003}{005}{007}{tab}{011}{013}{015}{017}{01
9}{021}{023}{025}{027}{029}{031}!#%')+-/13579;=?ACEGIKMOQSUWY
[]_acegikmoqsuwy{}{129}{131}{133}{135}{137}{139}{141}{143}{1
45}{147}{149}{151}{153}{155}{157}{159}{161}{163}{165}{167}{16
9}{171}{173}"+{<}IS54{>}+"{177}{179}{181}{183}{185}{187}{189}
{191}{193}{195}{197}{199}{201}{203}{205}{207}{209}{211}{213}{
215}{217}{219}{221}{223}{225}{227}{229}{231}{233}{235}{237}{2
39}{241}{243}{245}{247}{249}{251}{253}"+{<}IS52{>}{>};*; <==l
ast in series is 255[cr|lf];*;[cr|lf];*; We're ready to roll!
[cr|lf];*; Report "Working" on the PRompt line, to avoid a "b
rain-dead"[cr|lf];*; appearance while covering long stretches
 of function-less code[cr|lf]{<}PRWorking{>};*;[cr|lf];*;[cr|
lf];*; Begin loop with a threshold condition, to wit:[cr|lf];
*; Cursor NOT at end of file ( must be 0)[cr|lf]{<}LBb
{>}{<}IF{<}VA$FE{>}<1{>};*;[cr|lf];*;[cr|lf];*; Move the curs
or forward one char at a time, noting the difference[cr|lf];*
; between cursor positions. If the difference isn't 3, we ha
ven't[cr|lf];*; passed a 3-byte character, so loop back to La
Bel "b"[cr|lf]{<}SX55,{<}CP{>}{>}[CR_]{<}IF{<}CP{>}-{<}PV55{>
}<>3{>}{<}GLb{>}{<}EI{>};*;[cr|lf];*;[cr|lf];*; Otherwise, eu
reka, we found a 3-byter: DeFine it and save to a[cr|lf];*; S
/G (55 is available for re-use)[cr|lf][DF_][CL_][DF_]{<}SV55{
>}[YD_][CR_];*;[cr|lf];*;[cr|lf];*; Is it a function? We appl
y a three-pronged test:[cr|lf];*;[cr|lf];*; Prong 1: The firs
t byte must be an Ascii-255![cr|lf]{<}I
F{<}IS52{>}{238}{<}IS55{>}==0{>};*;[cr|lf];*;[cr|lf];*; Next,
 to test bytes 2 and 3, we parse them into discrete S/Gs[cr|l
f];*; (55 -- re-used yet again -- and 58, respectively). This
 parsing[cr|lf];*; procedure is interesting, but let's leave{032}
the full explanation for[cr|lf];*; another day. The double c
ommas in the XS statements denote a[cr|lf];*; throwaway segme
nt (actually, it's saved to S/G 00). This avoids[cr|lf];*; in
troducing a new S/G number for a mere by-product of our code[
cr|lf]{<}SX56,{<}IS52{>}+"{252}"+{<}IS55{>}{>}{<}XS56,51,,55,
57{>}{<}XS57,51,,55,58{>};*;[cr|lf];*;           {032}
   S/G 55 has byte 2 --^ ^-- S/G 58 has byte 3[cr|lf];*;[cr
|lf];*; Prong 2: The second byte must be Ascii 128, 129 or 13
0![cr|lf]{<}IF"{128}{129}{130}"{240}{<}IS55{>}{>};*;[cr|lf];*
;[cr|lf];*; Prong 3: The third byte must be an odd-numbered A
scii char![cr|lf];*; If it's even-numbered, we have a non-sta
ndard func.[cr|lf];*; Here we use the array of odd-numbered c
hars set up earlier[cr|lf];*; in S/G 54 and test for the abse
nce of S/G 58 (byte 3)[cr|lf]{<}IF{<}IS58{>}{238}{<}IS54{>}<0
{>};*; <== If TRUE, we have a non-standard func[cr|lf];*;[cr|
lf];*; A non-standard func is a rare occurrence, so let's fla
g it by beeping[cr|lf];*; 3 times (we don't need S/G 51 anymo
re, so let's re-use it)...[cr|lf]{<}SX51,3{>}{<}CUc,51{>}[BX_
]beep[Q2_]{<}LBc{>};*;[cr|lf];*;[cr|lf];*; ...as well as repo
rting our find on the PRompt line[cr|lf]{<}PRNon-standard fun
c found!{>}{<}SV50,1{>}{<}EX{>}{<}EI{>};*;[cr|lf];*;[cr|lf];*
; Note: Funcs with an even-numbered third byte look and behav
e like[cr|lf];*; regular funcs. Compare "[BC_]" (standard) wi
th "[255+129+030]" (non-standard):[cr|lf];*; put cursor on ea
ch func and issue V3 to view the constituent[cr|lf];
*; bytes. Run each func (by DeFining it and issuing RUNCODE) to[cr|lf];*; see that they both blank the command li
ne[cr|lf];*;[cr|lf];*; If all three tes
ts are passed, report Func found and EXit[cr|lf]{<}PRFunc fou
nd{>}{<}SV50,2{>}{<}EX{>}{<}EI{>};*;[cr|lf];*;[cr|lf];*; Othe
rwise, it's not a func, so move on (loop back to LaBel "b")[c
r|lf]{<}EI{>}{<}GLb{>};*;[cr|lf];*;[cr|lf];*; At this point,{032}
the threshold condition <1, at LaBel "b"[cr|lf];*; abo
ve, is FALSE and we're at the End of File. Return cursor to[c
r|lf];*; initial position, beep once, report Func not found,{032}
and EXit[cr|lf]{<}EI{>}[BX_]jmp {<}PV53{>}[Q2_][BX_]beep[Q2_]
{<}SV50,0{>}{<}PRNo func{>}{<}EX{>}{002}[cr|lf][cr|lf]
-nd
XPLeNCODE

--
Carl Distefano
cld@xxxxxxxx