home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Frozen Fish 1: Amiga
/
FrozenFish-Apr94.iso
/
bbs
/
alib
/
d7xx
/
d770
/
uedit.lha
/
Uedit
/
Jenkins2.LZH
/
MatchingBraces
< prev
next >
Wrap
Text File
|
1991-04-08
|
6KB
|
192 lines
========== MatchingBraces ===================================================
COPYRIGHT 1990
Robert A. Jenkins, Ph.D.
22901 Shagbark Lane
Miller Woods, IL 60411
(708) 758-0344
(708) 759-7063 answering machine
All Rights Reserved
Rick Stiles may distribute it as he pleases.
Thanks for writing and continually improving Uedit!
=============================================================================
I hate to think of how many hours I have wasted looking for unmatched braces
in my Uedit commands. Eventually I wrote this command so that the computer
would do the looking for me.
If you place the cursor on the < and hit shftCtl-[ repeatedly, it will walk
through the command, inverting the regions between matching braces. It keeps
a count of left minus right starting with < so it can warn you of extra
rights at the end of the command, but if you do not start at < the count may
be off. If you place the cursor on a left { it will show you each brace and
the current count of the level of nesting.
Finds first left { after cursor.
Scans, skipping literal and comments, counting right-left until
right-left = 0, so we have found a matching right }.
Displays the matching {} region in invert.
Uses virtual-e and virtual-f
n50 = char
n51 = # of unmatched left
n52 = flag (no, trace msg)
n53 = # right minus left = unmatched left
=============================================================================
Find matching braces { }
<shftCtl-[:
equateNum(n52,0) ..0 = no trace messages
putMsg("Searching, please wait...")
copyChar(curFile,n50)
if (eqNum(n50,"{")) equateNum(n52,1) ..display trace msgs
.. find first {
while (not eqNum(n50,">")) {
runKey(virtual-e) ..skip literal and comment
if (not runKey(virtual-f)) { .. check eFile
putMsg("NO LEFT { FOUND IN FILE")
return }
if (eqNum(n50,"<")) equateNum(n53,0) ..reset n53 since <
if (eqNum(n50,"}")) { ..found right
incNum(n53)
refreshDisplay }
if (eqNum(n50,"{")) { ..found left
equateNum(n51,1) ..# unmatched left
decNum(n53)
refreshDisplay
goto label(1) }
if (eqNum(n50,"}")) if (gtNum(n53,0)) {
putMsg(" ")
incLoc(curFile,atCursor)
alertUser("UNMATCHED RIGHT }")
equateNum(n53,0)
return }
incLoc(curFile,atCursor)
copyChar(curFile,n50) }
incLoc(curFile,atCursor)
putMsg ("NO (MORE) LEFT { FOUND IN <command>")
refreshDisplay
return
label(1) ..found first left, scan tallying right-left
if (eqNum(n52,1)) alertUser("found first left {")
equateLoc(curFile,sInvert,atCursor) .. mark first left
incLoc(curFile,atCursor)
equateLoc(curFile,eInvert,atCursor)
decNum(n53)
while (not eqNum(n50,">")) { ..scan, tally { and }
runKey(virtual-e)
if (not runKey(virtual-f)) {
alertUser("MATCHING RIGHT } NOT FOUND")
return }
if (eqNum(n50,"{")) { ..found nested left
incNum(n51)
decNum(n53)
refreshDisplay
if (eqNum(n52,1)) {
putMsg(n51)
alertUser("found nested left {") } }
if (eqNum(n50,"}")) { ..nested or final right
decNum(n51)
incNum(n53)
refreshDisplay
if (eqNum(n52,1)) {
putMsg(n51)
alertUser("found right }") }
if (eqNum(n51,0)) goto label(2) } ..final right
incLoc(curFile,atCursor)
copyChar(curFile,n50) }
moveCursor(curFile,eInvert) ..go back to first left
freeBuf(buf50)
toWord(buf50,n51)
insertRgn(buf50,eFile," MATCHING RIGHT } NOT FOUND",all)
alertUser(buf50)
return
label(2) ..found matching right }
if (eqNum(n52,1)) alertUser("found matching right")
equateLoc(curFile,eInvert,atCursor)
incLoc(curFile,eInvert)
moveCursor(curFile,sInvert)
incLoc(curFile,atCursor)
putMsg("{} region displayed in invert")
refreshDisplay
>
Skip over literal and comment
<virtual-e:
copyChar(curFile,n50)
if (eqNum(n50,"\"")) {
..alertUser("start of comment")
incLoc(curFile,atCursor)
copyChar(curFile,n50)
while (not eqNum(n50,"\"")) {
moveCursor(curFile,eChar)
copyChar(curFile,n50) }
incLoc(curFile,atCursor)
copyChar(curFile,n50)
..alertUser("after comment")
}
if (eqNum(n50,".")) {
incLoc(curFile,atCursor)
copyChar(curFile,n50)
if (eqNum(n50,".")) {
moveCursor(curFile,sLine)
moveCursor(curFile,downLine)
copyChar(curFile,n50)
if (eqNum(n50,">")) {
decLoc(curFile,atCursor)
copyChar(curFile,n50) } } }
>Saturday 23-Feb-91 17:54:53
Check eFile
<virtual-f:
if (eqLoc(curFile,atCursor,eFile)) {
equateLoc(curFile,atCursor,eInvert)
returnFalse }
returnTrue
>
Test suite:
< { }>
<{
}>
< { }>
< { { } }>
< { { { } } }>
< { { { { } } } }>
< {"("} >
< { "literal" "}" }>
<.. comment { }
{ { "literal" } }>
< {}
.. comment
>
< {} {
..comment
}
>
< { { { } } { } }>
< { { { } } { } { { } } }>
< { { { { } } { } } }>
One matching right } not found
< { { { { } } { } } >
Two matching right } not found
< { { { { { } } { } } >
One unmatched right { in file
< { { { { } } { } } } }>
Two unmatched right } in file
< { { { { } } { } } } } }>