ed

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

commit 0adb2d9e14c504dac21aead2245307081f62eb7c
parent af74e3ddff6faa6deeeffdb1a23006e0715757c0
Author: Byron Torres <b@torresjrjr.com>
Date:   Sun, 21 Nov 2021 23:16:53 +0000

Update types for newer harec

Diffstat:
Maddress.ha | 6+++---
Mbuffer.ha | 13++++++++-----
Moperation.ha | 9+++++----
Mparse.ha | 16++++++++--------
4 files changed, 24 insertions(+), 20 deletions(-)

diff --git a/address.ha b/address.ha @@ -61,7 +61,7 @@ fn addr_regex(buf: *buffer, ln: *linenode, re: str, dir: bool) *linenode = { switch (strings::contains(txt, re)) { // TODO: use real regex case false => switch (dir) { - case true => + case true => ln = ln.next; case false => ln = ln.prev; @@ -75,7 +75,7 @@ fn addr_regex(buf: *buffer, ln: *linenode, re: str, dir: bool) *linenode = { abort("Unreachable"); }; -// Searches for the first linenode which matches a regular expression. +// Searches for a marked linenode. fn addr_mark(buf: *buffer, mark: rune) *linenode = { let ln = buf.head; for (true) { @@ -97,7 +97,7 @@ fn addr_mark(buf: *buffer, mark: rune) *linenode = { abort("Unreachable"); }; -// Searches for the first linenode which matches a regular expression. +// Searches for a linenode offsetted from another. fn addr_offset(buf: *buffer, ln: *linenode, n: uint) *linenode = { for (n != 0) { match (ln.value) { diff --git a/buffer.ha b/buffer.ha @@ -1,5 +1,6 @@ use bufio; use fmt; +use io; // Holds text and state. type buffer = struct { @@ -38,10 +39,11 @@ type tailnode = void; // Initialises a new buffer. fn new_buffer() *buffer = { const head = alloc(linenode { value = headnode, ... }); - const tail = alloc(linenode { value = tailnode, prev = head }); + const tail = alloc(linenode { value = tailnode, prev = head, ... }); head.next = tail; const cur = cursor { num = 0, node = head }; return alloc(buffer { + fname = void, cur = cur, head = head, tail = tail, @@ -50,10 +52,10 @@ fn new_buffer() *buffer = { }); }; -// Reads text from *io::stream, writes to a buffer. +// Reads text from io::handle, writes to a buffer. // Buffer should be empty, otherwise, existing linenodes will be leaked. // TODO: Clear buffer before reading? -fn buf_read(buf: *buffer, source: *io::stream) size = { +fn buf_read(buf: *buffer, source: io::handle) size = { const localhead = buf.head; const localtail = buf.tail; @@ -80,6 +82,7 @@ fn buf_read(buf: *buffer, source: *io::stream) size = { value = value, prev = prevnode, next = localtail, + ... }); prevnode.next = ln; @@ -91,8 +94,8 @@ fn buf_read(buf: *buffer, source: *io::stream) size = { return n; }; -// Write contents of buffer to *io::stream. -fn buf_write(buf: *buffer, dest: *io::stream) size = { +// Write contents of buffer to io::handle. +fn buf_write(buf: *buffer, dest: io::handle) size = { let ln = buf.head; let n = 0z; diff --git a/operation.ha b/operation.ha @@ -1,6 +1,7 @@ -use os; use fmt; use fs; +use io; +use os; // 'e' command fn op_edit(buf: *buffer, args: arg...) void = { @@ -13,7 +14,7 @@ fn op_edit(buf: *buffer, args: arg...) void = { case err: fs::error => fmt::fatal("Error {}", fs::strerror(err)); case f: io::file => - yield buf_read(scratch, &f); + yield buf_read(scratch, f); }; }; @@ -53,7 +54,7 @@ fn op_write(buf: *buffer, args: arg...) void = { }; }; - const n = buf_write(buf, &file); + const n = buf_write(buf, file); if (!surpress) { fmt::println(n)?; }; @@ -71,7 +72,7 @@ fn op_read(buf: *buffer, args: arg...) void = { case err: fs::error => fmt::fatal("Error {}", fs::strerror(err)); case f: io::file => - yield buf_read(scratch, &f); + yield buf_read(scratch, f); }; }; diff --git a/parse.ha b/parse.ha @@ -103,21 +103,21 @@ fn construct_ops(cmd: command) []op = { let op = switch (cmd.main) { case "e" => - yield op { func = &op_edit, }; + yield op { func = &op_edit, ... }; case "r" => - yield op { func = &op_read, }; + yield op { func = &op_read, ... }; case "w" => - yield op { func = &op_write, }; + yield op { func = &op_write, ... }; case "d" => - yield op { func = &op_delete, }; + yield op { func = &op_delete, ... }; case "n" => - yield op { func = &op_numbered, }; + yield op { func = &op_numbered, ... }; case "p" => - yield op { func = &op_print, }; + yield op { func = &op_print, ... }; case " p" => - yield op { func = &print_buffer, }; // DEBUG ONLY + yield op { func = &print_buffer, ... }; // DEBUG ONLY case => - yield op { func = &print_buffer, }; // TODO + yield op { func = &print_buffer, ... }; // TODO }; append(ops, op);