* Routines to perform bracket matching functions.
* Try to match the n-th open bracket
* which appears in the top displayed line (forwdir),
* or the n-th close bracket
* which appears in the bottom displayed line (!forwdir).
* The characters which serve as "open bracket" and
* "close bracket" are given.
match_brac(obrac
, cbrac
, forwdir
, n
)
extern int ch_forw_get(), ch_back_get();
* Seek to the line containing the open bracket.
* This is either the top or bottom line on the screen,
* depending on the type of bracket.
pos
= position((forwdir
) ? TOP
: BOTTOM
);
if (pos
== NULL_POSITION
|| ch_seek(pos
))
error("Nothing in top line", NULL_PARG
);
error("Nothing in bottom line", NULL_PARG
);
* Look thru the line to find the open bracket to match.
if ((c
= ch_forw_get()) == '\n' || c
== EOI
)
error("No bracket in top line", NULL_PARG
);
error("No bracket in bottom line", NULL_PARG
);
} while (c
!= obrac
|| --n
> 0);
* Position the file just "after" the open bracket
* (in the direction in which we will be searching).
* If searching forward, we are already after the bracket.
* If searching backward, skip back over the open bracket.
* Search the file for the matching bracket.
chget
= (forwdir
) ? ch_forw_get
: ch_back_get
;
while ((c
= (*chget
)()) != EOI
)
else if (c
== cbrac
&& --nest
< 0)
* Found the matching bracket.
* If searching backward, put it on the top line.
* If searching forward, put it on the bottom line.
jump_line_loc(ch_tell(), forwdir
? -1 : 1);
error("No matching bracket", NULL_PARG
);