duskos

dusk os fork
git clone git://git.alexwennerberg.com/duskos
Log | Files | Refs | README | LICENSE

commit 540484288a8afccaa29866f49efd11611e6b7999
parent aa1704927fffa465a29f3924cdec8e5192547a54
Author: Virgil Dupras <hsoft@hardcoded.net>
Date:   Tue, 17 Jan 2023 21:15:03 -0500

text/ed: fix a bunch of bugs

Diffstat:
Mfs/tests/text/ed.fs | 6+++---
Mfs/text/ed.fs | 17++++++++---------
2 files changed, 11 insertions(+), 12 deletions(-)

diff --git a/fs/tests/text/ed.fs b/fs/tests/text/ed.fs @@ -16,10 +16,10 @@ capture L S" (oh well maybe grow)\n ^\n3 / 17\n" #s= capture H S" (oh well maybe grow)\n^\n3 / 17\n" #s= -9 l 6 capture dc -S" (oh well grow)\n ^\n3 / 17\n" #s= +4 l 5 capture dc +S" (oh maybe grow)\n ^\n3 / 17\n" #s= 2 capture dl -S" tests that process text\n ^\n3 / 15\n" #s= +S" tests that process text\n ^\n3 / 15\n" #s= L capture i abc S" tests that process textabc\n ^\n3 / 15\n" #s= capture o appended line diff --git a/fs/text/ed.fs b/fs/text/ed.fs @@ -21,8 +21,8 @@ extends IO struct[ Edbuf : _newline ( self -- line ) Line SZ swap buf Arena :allot dup Line SZ 0 fill ; - : _sel$ ( self -- ) - 0 over to lpos dup lines swap to sel ; + : _sel$ ( self -- ) 0 over to lpos dup lines swap to sel ; + : _sel$$ ( self -- ) 0 over to cpos _sel$ ; : _cbounds ( self -- ) dup cpos over sel Line cnt min swap to cpos ; : _sel! ( line self -- ) tuck to sel _cbounds ; @@ -102,9 +102,9 @@ extends IO struct[ Edbuf : :delchars ( n self -- ) dup >r sel >r \ V1=self V2=sel V2 Line cnt V1 cpos - min ( bounded-n ) ?dup if - dup neg V2 to+ Line cnt ( n ) V2 Line ptr V1 cpos + 2dup + ( n dst src ) - swap rot move then rdrop rdrop ; + swap V2 Line cnt V1 cpos - move ( n ) + neg V2 to+ Line cnt then rdrop rdrop ; : :dellines ( n self -- ) over not if 2drop exit then >r \ V1=self @@ -119,10 +119,6 @@ Edbuf :new structbind Edbuf edbuf 1 value print? 20 value pagesz -: edload ( -- ) - 0 file :seek edbuf :empty - edbuf :self file :spit - edbuf lines to edbuf sel ; : s ( -- ) edbuf :cprint edbuf :linecnt edbuf lpos .f" %d / %d\n" ; : ?s print? if s then ; @@ -139,7 +135,10 @@ Edbuf :new structbind Edbuf edbuf : i console :readline edbuf :puts ?s ; : o edbuf :appendline i ; : O edbuf :insertline i ; +: edload ( -- ) + 0 file :seek edbuf :empty + edbuf :self file :spit edbuf _sel$$ ; : edsave ( -- ) - 0 g H 0 file :seek + edbuf _sel$$ 0 file :seek file :self edbuf :spit file :truncate file :flush 0 file :seek ;