2 * Routines to perform bracket matching functions.
9 * Try to match the n-th open bracket
10 * which appears in the top displayed line (forwdir),
11 * or the n-th close bracket
12 * which appears in the bottom displayed line (!forwdir).
13 * The characters which serve as "open bracket" and
14 * "close bracket" are given.
17 match_brac(obrac, cbrac, forwdir, n)
28 extern int ch_forw_get(), ch_back_get();
31 * Seek to the line containing the open bracket.
32 * This is either the top or bottom line on the screen,
33 * depending on the type of bracket.
35 pos = position((forwdir) ? TOP : BOTTOM);
36 if (pos == NULL_POSITION || ch_seek(pos))
39 error("Nothing in top line", NULL_PARG);
41 error("Nothing in bottom line", NULL_PARG);
46 * Look thru the line to find the open bracket to match.
50 if ((c = ch_forw_get()) == '\n' || c == EOI)
53 error("No bracket in top line", NULL_PARG);
55 error("No bracket in bottom line", NULL_PARG);
58 } while (c != obrac || --n > 0);
61 * Position the file just "after" the open bracket
62 * (in the direction in which we will be searching).
63 * If searching forward, we are already after the bracket.
64 * If searching backward, skip back over the open bracket.
70 * Search the file for the matching bracket.
72 chget = (forwdir) ? ch_forw_get : ch_back_get;
74 while ((c = (*chget)()) != EOI)
78 else if (c == cbrac && --nest < 0)
81 * Found the matching bracket.
82 * If searching backward, put it on the top line.
83 * If searching forward, put it on the bottom line.
85 jump_line_loc(ch_tell(), forwdir ? -1 : 1);
89 error("No matching bracket", NULL_PARG);