From 36dcacf452063ad0d281d74d841df9ce9123d198 Mon Sep 17 00:00:00 2001 From: "Michael D. Lowis" Date: Thu, 5 Apr 2018 16:27:26 -0400 Subject: [PATCH] identified potentially unused functions in buf.c --- inc/edit.h | 10 +++---- lib/buf.c | 79 +++++++++++++++++++++++++++++------------------------- lib/view.c | 1 - 3 files changed, 47 insertions(+), 43 deletions(-) diff --git a/inc/edit.h b/inc/edit.h index ee9edb1..3fcecce 100644 --- a/inc/edit.h +++ b/inc/edit.h @@ -53,19 +53,19 @@ void buf_del(Buf* buf); void buf_undo(Buf* buf); void buf_redo(Buf* buf); -void buf_loglock(Buf* buf); +//void buf_loglock(Buf* buf); void buf_logclear(Buf* buf); void buf_lastins(Buf* buf); bool buf_iseol(Buf* buf, size_t pos); size_t buf_bol(Buf* buf, size_t pos); size_t buf_eol(Buf* buf, size_t pos); -size_t buf_bow(Buf* buf, size_t pos); -size_t buf_eow(Buf* buf, size_t pos); +//size_t buf_bow(Buf* buf, size_t pos); +//size_t buf_eow(Buf* buf, size_t pos); -void buf_selline(Buf* buf); +//void buf_selline(Buf* buf); void buf_selword(Buf* buf, bool (*isword)(Rune)); -void buf_selblock(Buf* buf, Rune beg, Rune end); +//void buf_selblock(Buf* buf, Rune beg, Rune end); void buf_selall(Buf* buf); void buf_selctx(Buf* buf, bool (*isword)(Rune)); diff --git a/lib/buf.c b/lib/buf.c index cf47ea0..7665010 100644 --- a/lib/buf.c +++ b/lib/buf.c @@ -12,6 +12,7 @@ static void log_clear(Log** list); static void syncgap(Buf* buf, size_t off); static int bytes_match(Buf* buf, size_t mbeg, size_t mend, char* str); static Rune nextrune(Buf* buf, size_t off, int move, bool (*testfn)(Rune)); +static void selblock(Buf* buf, Rune first, Rune last); void buf_init(Buf* buf) { /* cleanup old data if there is any */ @@ -275,40 +276,6 @@ void buf_selword(Buf* buf, bool (*isword)(Rune)) { buf->selection = sel; } -void buf_selblock(Buf* buf, Rune first, Rune last) { - Sel sel = getsel(buf); - int balance = 0, dir; - size_t beg, end = sel.end; - - /* figure out which end of the block we're starting at */ - if (buf_getrat(buf, end) == first) - dir = +1, balance++, beg = end++; - else if (buf_getrat(buf, end) == last) - dir = -1, balance--, beg = end--; - else - return; - - /* scan for a blanced set of braces */ - while (true) { - if (buf_getrat(buf, end) == first) - balance++; - else if (buf_getrat(buf, end) == last) - balance--; - - if (balance == 0 || end >= buf_end(buf) || end == 0) - break; - else - end += dir; - } - - /* bail if we failed to find a block */ - if (balance != 0) return; - - /* update the passed in selection */ - if (end > beg) beg++; else end++; - buf->selection.beg = beg, buf->selection.end = end; -} - void buf_selall(Buf* buf) { buf->selection = (Sel){ .beg = 0, .end = buf_end(buf) }; } @@ -317,11 +284,11 @@ void buf_selctx(Buf* buf, bool (*isword)(Rune)) { size_t bol = buf_bol(buf, buf->selection.end); Rune r = buf_getc(buf); if (r == '(' || r == ')') - buf_selblock(buf, '(', ')'); + selblock(buf, '(', ')'); else if (r == '[' || r == ']') - buf_selblock(buf, '[', ']'); + selblock(buf, '[', ']'); else if (r == '{' || r == '}') - buf_selblock(buf, '{', '}'); + selblock(buf, '{', '}'); else if (buf->selection.end == bol || r == '\n') buf_selline(buf); else if (risword(r)) @@ -466,3 +433,41 @@ bool buf_insel(Buf* buf, size_t off) { Sel sel = getsel(buf); return (off >= sel.beg && off < sel.end); } + +/******************************************************************************/ + +static void selblock(Buf* buf, Rune first, Rune last) { + Sel sel = getsel(buf); + int balance = 0, dir; + size_t beg, end = sel.end; + + /* figure out which end of the block we're starting at */ + if (buf_getrat(buf, end) == first) + dir = +1, balance++, beg = end++; + else if (buf_getrat(buf, end) == last) + dir = -1, balance--, beg = end--; + else + return; + + /* scan for a blanced set of braces */ + while (true) { + if (buf_getrat(buf, end) == first) + balance++; + else if (buf_getrat(buf, end) == last) + balance--; + + if (balance == 0 || end >= buf_end(buf) || end == 0) + break; + else + end += dir; + } + + /* bail if we failed to find a block */ + if (balance != 0) return; + + /* update the passed in selection */ + if (end > beg) beg++; else end++; + buf->selection.beg = beg, buf->selection.end = end; +} + + diff --git a/lib/view.c b/lib/view.c index c19c90a..16b5fd8 100644 --- a/lib/view.c +++ b/lib/view.c @@ -142,7 +142,6 @@ char* view_fetch(View* view, size_t row, size_t col, bool (*isword)(Rune)) { char* str = NULL; size_t off = getoffset(view, row, col); if (off != SIZE_MAX) { - puts("fetch"); /* str = buf_fetchat(buf, isword, off) */ // Sel sel = { .beg = off, .end = off }; // if (buf_insel(BUF, NULL, off)) -- 2.51.0