From 9f6de73fe0dc43d727f84d13eeeb5c9196e222fa Mon Sep 17 00:00:00 2001 From: "Michael D. Lowis" Date: Tue, 6 Mar 2018 21:01:32 -0500 Subject: [PATCH] removed selection arg from buf_load --- buf.c | 20 ++++++-------------- edit.h | 13 +++---------- testbuf.c | 36 +++++++++++------------------------- 3 files changed, 20 insertions(+), 49 deletions(-) diff --git a/buf.c b/buf.c index 95c34f5..cc45ad8 100644 --- 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 1dcca79..ed7b1b6 100644 --- 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); diff --git a/testbuf.c b/testbuf.c index e56012c..e9ac58d 100644 --- 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); -- 2.52.0