From: Michael D. Lowis Date: Wed, 7 Mar 2018 02:54:07 +0000 (-0500) Subject: added scaffolding for syncong the gap and performing edits X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=434fe47fc6205a706033c6bc78d8bc84b1d30148;p=archive%2Fgapbuf.git added scaffolding for syncong the gap and performing edits --- diff --git a/buf.c b/buf.c index 9f9b90b..e2e9bd1 100644 --- a/buf.c +++ b/buf.c @@ -39,6 +39,16 @@ static void selupdate(Buf* buf, Sel* dest, Sel* src) { dest->beg = src->beg, dest->end = src->end, dest->col = src->col; } +static char getb(Buf* buf, Sel* sel) { + char* ptr = buf->bufstart + sel->end; + if (ptr >= buf->gapstart) + ptr += (buf->gapend - buf->gapstart); + return *ptr; +} + +static void syncgap(Buf* buf, Sel* sel) { +} + /******************************************************************************/ void buf_init(Buf* buf, void (*errfn)(char*)) { @@ -115,7 +125,7 @@ void buf_save(Buf* buf) { int buf_getc(Buf* buf, Sel* sel) { Sel lsel = selconvert(buf, sel); - return 0; + return getb(buf, &lsel); } void buf_putc(Buf* buf, Sel* sel, int rune, int fmtopts) { @@ -125,12 +135,17 @@ void buf_putc(Buf* buf, Sel* sel, int rune, int fmtopts) { void buf_puts(Buf* buf, Sel* sel, char* str, int fmtopts) { Sel lsel = selconvert(buf, sel); + syncgap(buf, &lsel); selupdate(buf, sel, &lsel); } -void buf_last(Buf* buf, Sel* sel) { +void buf_del(Buf* buf, Sel* sel) { + Sel lsel = selconvert(buf, sel); + syncgap(buf, &lsel); + selupdate(buf, sel, &lsel); } -void buf_del(Buf* buf, Sel* sel) { +size_t buf_size(Buf* buf) { + return (buf->bufend - buf->bufstart) - (buf->gapend - buf->gapstart); } diff --git a/edit.h b/edit.h index 7b56e30..d054646 100644 --- a/edit.h +++ b/edit.h @@ -52,9 +52,10 @@ void buf_del(Buf* buf, Sel* sel); int buf_getc(Buf* buf, Sel* sel); void buf_putc(Buf* buf, Sel* sel, int rune, int fmtopts); void buf_puts(Buf* buf, Sel* sel, char* str, int fmtopts); -void buf_last(Buf* buf, Sel* sel); +size_t buf_size(Buf* buf); #if 0 +void buf_last(Buf* buf, Sel* sel); void buf_chomp(Buf* buf); void buf_undo(Buf* buf, Sel* sel); void buf_redo(Buf* buf, Sel* sel);