]> git.mdlowis.com Git - archive/gapbuf.git/commitdiff
removed selection arg from buf_load
authorMichael D. Lowis <mike@mdlowis.com>
Wed, 7 Mar 2018 02:01:32 +0000 (21:01 -0500)
committerMichael D. Lowis <mike@mdlowis.com>
Wed, 7 Mar 2018 02:01:32 +0000 (21:01 -0500)
buf.c
edit.h
testbuf.c

diff --git a/buf.c b/buf.c
index 95c34f5e21a129505dedbf4cfd08390589daa9b0..cc45ad8f8c335a87aeded2e8da954cde29be0a92 100644 (file)
--- a/buf.c
+++ b/buf.c
@@ -54,23 +54,18 @@ void buf_init(Buf* buf, void (*errfn)(char*)) {
         buf->bufstart = NULL;
     }
     /* reset the state to defaults */
-    buf->modified    = false;
+    memset(buf, 0, sizeof(Buf));
     buf->expand_tabs = true;
-    buf->crlf        = 0;
     buf->bufsize     = pagealign(1);
     buf->bufstart    = emalloc(buf->bufsize * sizeof(Rune));
     buf->bufend      = buf->bufstart + buf->bufsize;
     buf->gapstart    = buf->bufstart;
     buf->gapend      = buf->bufend;
-    buf->undo        = NULL;
-    buf->redo        = NULL;
     buf->errfn       = errfn;
-    buf->path        = NULL;
 }
 
-void buf_load(Buf* buf, Sel* sel, char* path) {
+void buf_load(Buf* buf, char* path) {
     /* process the file path and address */
-    if (sel) *sel = (Sel){0};
     if (!path) return;
     if (path[0] == '.' && path[1] == '/')
         path += 2;
@@ -100,7 +95,7 @@ void buf_reload(Buf* buf) {
     void (*errfn)(char*) = buf->errfn;
     char* path = buf->path;
     buf_init(buf, errfn);
-    buf_load(buf, NULL, path);
+    buf_load(buf, path);
 }
 
 void buf_save(Buf* buf) {
@@ -124,18 +119,15 @@ void buf_save(Buf* buf) {
     }
 }
 
-Rune buf_getc(Buf* buf, Sel* sel)
-{
+int buf_getc(Buf* buf, Sel* sel) {
     Sel lsel = selconvert(buf, sel);
     return 0;
 }
 
-void buf_putc(Buf* buf, Sel* sel, Rune rune, int fmtopts)
-{
+void buf_putc(Buf* buf, Sel* sel, Rune rune, int fmtopts) {
     Sel lsel = selconvert(buf, sel);
     selupdate(buf, sel, &lsel);
 }
 
-void buf_last(Buf* buf, Sel* sel)
-{
+void buf_last(Buf* buf, Sel* sel) {
 }
diff --git a/edit.h b/edit.h
index 1dcca7961b540e7d769004bc6a713649265adc56..ed7b1b6539dd5d81168333a1461b6d4e4fcdb8bd 100644 (file)
--- a/edit.h
+++ b/edit.h
@@ -41,21 +41,14 @@ typedef struct {
     bool expand_tabs;     /* tracks current mode */
     uint transid;         /* tracks the last used transaction id for log entries */
     void (*errfn)(char*); /* callback for error messages */
-    Sel selection;
+    Sel selection;        /* current selection */
 } Buf;
 
-enum {
-    LEFT  = -1,
-    RIGHT = +1,
-    UP    = -1,
-    DOWN  = +1
-};
-
 void buf_init(Buf* buf, void (*errfn)(char*));
-void buf_load(Buf* buf, Sel* sel, char* path);
+void buf_load(Buf* buf, char* path);
 void buf_reload(Buf* buf);
 void buf_save(Buf* buf);
-Rune buf_getc(Buf* buf, Sel* sel);
+int buf_getc(Buf* buf, Sel* sel);
 void buf_putc(Buf* buf, Sel* sel, Rune rune, int fmtopts);
 void buf_last(Buf* buf, Sel* sel);
 
index e56012ca79447b4f738aca563ea7eec5c95d3c7a..e9ac58d1abbeabe343202f4a04879056462f31b1 100644 (file)
--- a/testbuf.c
+++ b/testbuf.c
@@ -78,10 +78,8 @@ TEST_SUITE(BufferTests) {
     /* Loading
      *************************************************************************/
     TEST(buf_load should load a UTF-8 file from disk) {
-        Sel sel;
         buf_init(&TestBuf, NULL);
-        buf_load(&TestBuf, NULL, "testdocs/lorem.txt");
-        CHECK(sel.end             == 0);
+        buf_load(&TestBuf, "testdocs/lorem.txt");
         CHECK(TestBuf.modified    == false);
         CHECK(TestBuf.expand_tabs == true);
         CHECK(TestBuf.crlf        == 0);
@@ -94,10 +92,8 @@ TEST_SUITE(BufferTests) {
 
     TEST(buf_load should load a file from disk and jump to a specific line) {
         IGNORE("Jumping to a specific line is not implemented yet.");
-        Sel sel;
         buf_init(&TestBuf, NULL);
-        buf_load(&TestBuf, &sel, "testdocs/lorem.txt:2");
-        CHECK(sel.end             == 70);
+        buf_load(&TestBuf, "testdocs/lorem.txt:2");
         CHECK(TestBuf.modified    == false);
         CHECK(TestBuf.expand_tabs == true);
         CHECK(TestBuf.crlf        == 0);
@@ -109,10 +105,8 @@ TEST_SUITE(BufferTests) {
     }
 
     TEST(buf_load should remove ./ from file path) {
-        Sel sel;
         buf_init(&TestBuf, NULL);
-        buf_load(&TestBuf, &sel, "./testdocs/lorem.txt");
-        CHECK(sel.end             == 0);
+        buf_load(&TestBuf, "./testdocs/lorem.txt");
         CHECK(TestBuf.modified    == false);
         CHECK(TestBuf.expand_tabs == true);
         CHECK(TestBuf.crlf        == 0);
@@ -124,10 +118,8 @@ TEST_SUITE(BufferTests) {
     }
 
     TEST(buf_load should handle non-existent paths) {
-        Sel sel;
         buf_init(&TestBuf, NULL);
-        buf_load(&TestBuf, &sel, "nonexistent.txt");
-        CHECK(sel.end             == 0);
+        buf_load(&TestBuf, "nonexistent.txt");
         CHECK(TestBuf.modified    == false);
         CHECK(TestBuf.expand_tabs == true);
         CHECK(TestBuf.crlf        == 0);
@@ -139,10 +131,8 @@ TEST_SUITE(BufferTests) {
     }
 
     TEST(buf_load should handle NULL for selection) {
-        Sel sel;
         buf_init(&TestBuf, NULL);
-        buf_load(&TestBuf, NULL, "nonexistent.txt");
-        CHECK(sel.end             == 0);
+        buf_load(&TestBuf, "nonexistent.txt");
         CHECK(TestBuf.modified    == false);
         CHECK(TestBuf.expand_tabs == true);
         CHECK(TestBuf.crlf        == 0);
@@ -154,10 +144,8 @@ TEST_SUITE(BufferTests) {
     }
 
     TEST(buf_load should handle NULL for path) {
-        Sel sel;
         buf_init(&TestBuf, NULL);
-        buf_load(&TestBuf, NULL, NULL);
-        CHECK(sel.end             == 0);
+        buf_load(&TestBuf, NULL);
         CHECK(TestBuf.modified    == false);
         CHECK(TestBuf.expand_tabs == true);
         CHECK(TestBuf.crlf        == 0);
@@ -169,12 +157,10 @@ TEST_SUITE(BufferTests) {
     }
 
     TEST(buf_reload should reload the file from disk) {
-        Sel sel;
         buf_init(&TestBuf, NULL);
-        buf_load(&TestBuf, &sel, "testdocs/waf");
+        buf_load(&TestBuf, "testdocs/waf");
         TestBuf.path = "testdocs/lorem.txt";
         buf_reload(&TestBuf);
-        CHECK(sel.end             == 0);
         CHECK(TestBuf.modified    == false);
         CHECK(TestBuf.expand_tabs == true);
         CHECK(TestBuf.crlf        == 0);
@@ -189,7 +175,7 @@ TEST_SUITE(BufferTests) {
      *************************************************************************/
     TEST(buf_save should save a UTF-8 file to disk) {
         buf_init(&TestBuf, NULL);
-        buf_load(&TestBuf, NULL, "testdocs/lorem.txt");
+        buf_load(&TestBuf, "testdocs/lorem.txt");
         TestBuf.modified = true;
         buf_save(&TestBuf);
         CHECK(TestBuf.modified == false);
@@ -197,7 +183,7 @@ TEST_SUITE(BufferTests) {
 
     TEST(buf_save should save a non UTF-8 file to disk) {
         buf_init(&TestBuf, NULL);
-        buf_load(&TestBuf, NULL, "testdocs/waf");
+        buf_load(&TestBuf, "testdocs/waf");
         TestBuf.modified = true;
         buf_save(&TestBuf);
         CHECK(TestBuf.modified == false);
@@ -205,7 +191,7 @@ TEST_SUITE(BufferTests) {
 
     TEST(buf_save should save a file to disk with unix line endings) {
         buf_init(&TestBuf, NULL);
-        buf_load(&TestBuf, NULL, "testdocs/lf.txt");
+        buf_load(&TestBuf, "testdocs/lf.txt");
         TestBuf.modified = true;
         buf_save(&TestBuf);
         CHECK(TestBuf.modified == false);
@@ -213,7 +199,7 @@ TEST_SUITE(BufferTests) {
 
     TEST(buf_save should save a file to disk with dos line endings) {
         buf_init(&TestBuf, NULL);
-        buf_load(&TestBuf, NULL, "testdocs/crlf.txt");
+        buf_load(&TestBuf, "testdocs/crlf.txt");
         TestBuf.modified = true;
         buf_save(&TestBuf);
         CHECK(TestBuf.modified == false);