home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Simtel MSDOS 1992 June
/
SIMTEL_0692.cdr
/
msdos
/
sprint
/
balance.arc
/
balance.spm
Wrap
Text File
|
1989-07-02
|
2KB
|
60 lines
; Macro for checking delimiter balance in 100K+ Ventura 2.0 ASCII
; files. It would be great if it worked better.
; It remembers the value of "modf" in "w" and error codes in "i"
; so change these if used elsewhere.
; Delimiters are () <>, checks all for a match
#define w
#define i
swapmark : if (inbuff themark) swap themark
; balini1: inserts ^A (the default) before every occurrence
; of the given character.
balini1: ->y
r to markE
while (y csearch) (1 insert $ c)
; balinit: stores "modf" and calls balini1 on all delimiters
; balinit: set themark
balinit: set markE
modf ->w
mark ('(' balini1 ')' balini1
'<' balini1 '>' balini1
)
; balterm: removes all the ^A's and restores "modf".
balterm: exitmenus mark (r toend while (1 csearch) (1 del)) w ->modf
; isopendelim: returns true if the current character is an open delimiter.
isopendelim: current case ('(' 1, '<' 1, $ 0)
; closer: returns the closing delimiter matching the given open one.
closer: case ('(' ')', '<' '>')
; nextdelim: moves to the next delimiter
nextdelim: 1 csearch $ c
; balerr: prints appropriate error message, calls balterm, and aborts.
balerr: (balterm $)
case ( 1 message "\nNo closing delimiter" abort,
2 message "\nMismatched closing delimiter" abort,
3 message "\nExtra closing delimiter" abort)
; bal1: checks from point through the end until
; 1. it finds an error (unclosed or mismatch closing delimiter),
; 2. it reaches the end of the file or an extra closing delimiter
; and then it stops.
bal1: while (nextdelim isopendelim)
{set themark (current closer ; get the current delimiter's match
($ c bal1 $) ; store it
= current ? ($ c set themark ) ; if it matches, go to next
: (if isend { ; otherwise
1->i ; if it's the end,
} ; tell ballerr ok
else { ; else
2->i ; tell ballerr mismatch
}
(swap themark $) ; go back to error
balerr) ; and bail out
)
}
; balance: the macro to be executed by the user.
balance: message "checking..>>"
balinit
mark ( bal1
if !isend (3->i balerr)
)
balterm
message "\nno errors to end."