don't bother resolving onbld python module deps
[unleashed.git] / bin / less / brac.c
blobb27ea6162f5566f3ac447a5c163ab254f64a6afc
1 /*
2 * Copyright (C) 1984-2012 Mark Nudelman
3 * Modified for use with illumos by Garrett D'Amore.
4 * Copyright 2014 Garrett D'Amore <garrett@damore.org>
6 * You may distribute under the terms of either the GNU General Public
7 * License or the Less License, as specified in the README file.
9 * For more information, see the README file.
13 * Routines to perform bracket matching functions.
16 #include "less.h"
17 #include "position.h"
20 * Try to match the n-th open bracket
21 * which appears in the top displayed line (forwdir),
22 * or the n-th close bracket
23 * which appears in the bottom displayed line (!forwdir).
24 * The characters which serve as "open bracket" and
25 * "close bracket" are given.
27 void
28 match_brac(int obrac, int cbrac, int forwdir, int n)
30 int c;
31 int nest;
32 off_t pos;
33 int (*chget)(void);
36 * Seek to the line containing the open bracket.
37 * This is either the top or bottom line on the screen,
38 * depending on the type of bracket.
40 pos = position((forwdir) ? TOP : BOTTOM);
41 if (pos == -1 || ch_seek(pos)) {
42 if (forwdir)
43 error("Nothing in top line", NULL);
44 else
45 error("Nothing in bottom line", NULL);
46 return;
50 * Look thru the line to find the open bracket to match.
52 do {
53 if ((c = ch_forw_get()) == '\n' || c == EOI) {
54 if (forwdir)
55 error("No bracket in top line", NULL);
56 else
57 error("No bracket in bottom line", NULL);
58 return;
60 } while (c != obrac || --n > 0);
63 * Position the file just "after" the open bracket
64 * (in the direction in which we will be searching).
65 * If searching forward, we are already after the bracket.
66 * If searching backward, skip back over the open bracket.
68 if (!forwdir)
69 (void) ch_back_get();
72 * Search the file for the matching bracket.
74 chget = (forwdir) ? ch_forw_get : ch_back_get;
75 nest = 0;
76 while ((c = (*chget)()) != EOI) {
77 if (c == obrac) {
78 nest++;
79 } 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);
86 return;
89 error("No matching bracket", NULL);