]> git.mdlowis.com Git - archive/gapbuf.git/commitdiff
added scaffolding for syncong the gap and performing edits master
authorMichael D. Lowis <mike@mdlowis.com>
Wed, 7 Mar 2018 02:54:07 +0000 (21:54 -0500)
committerMichael D. Lowis <mike@mdlowis.com>
Wed, 7 Mar 2018 02:54:07 +0000 (21:54 -0500)
buf.c
edit.h

diff --git a/buf.c b/buf.c
index 9f9b90bbf353b38b05e6a2eb644e56a087d4bc13..e2e9bd1670c139702df293633fe784c28a28911e 100644 (file)
--- 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 7b56e302ad6fb6d0dacf5bb10390f30c70bc0bf1..d0546469cca60f144080bb27395b70e21d00e149 100644 (file)
--- 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);