ed

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

commit 473d4e15bf2c40b9b7e703a1bbe5408ba04dfece
parent c8026372a752928e9ccbb6545e5238890c5e2f4e
Author: Byron Torres <b@torresjrjr.com>
Date:   Sun, 12 Sep 2021 15:00:03 +0100

Add examples, complete cmd_write()

Diffstat:
Mcommand.ha | 28+++++++++++++++++++---------
Med.ha | 14+++++++++++++-
2 files changed, 32 insertions(+), 10 deletions(-)

diff --git a/command.ha b/command.ha @@ -20,19 +20,29 @@ fn cmd_edit(buf: *buffer, fname: filename) void = { // 'w' command fn cmd_write(buf: *buffer, fname: filename) void = { - const flags = [fs::flags::WRONLY, fs::flags::NOCTTY, fs::flags::CLOEXEC]; - match (fname) { - void => void, + const mode = fs::mode::USER_RW | fs::mode::GROUP_R | fs::mode::OTHER_R; + const flags = [ + fs::flags::WRONLY, + fs::flags::TRUNC, + fs::flags::NOCTTY, + fs::flags::CLOEXEC, + ]; + const file = match (fname) { + void => abort("TODO"), fname: str => match (os::open(fname, flags...)) { - err: fs::error => fmt::fatal("Error {}", fs::strerror(err)), - f: io::file => { - const n = buf_write(buf, &f); - if (!surpress) { - fmt::println(n)?; - }; + fs::error => match (os::create(fname, mode)) { + err: fs::error => fmt::fatal("Error {}", fs::strerror(err)), + file: io::file => file, }, + file: io::file => file, }, }; + + const n = buf_write(buf, &file); + if (!surpress) { + fmt::println(n)?; + }; + }; // 'r' command diff --git a/ed.ha b/ed.ha @@ -58,9 +58,21 @@ export fn main() void = { parse_cmd(command); break; }; + + // test examples + print_buffer(buf); + + cmd_edit(buf, fname); + print_buffer(buf); + + cmd_read(buf, "./tmp/gpl.txt"); + print_buffer(buf); + + cmd_write(buf, "./tmp/out"); + print_buffer(buf); }; -// "3,7,/a/,+3m4" +// "3,7,/a/,+2m4" // str -> struct { // prefix_ranges: []addr, // "2" "+2" "-1" // primary_command: command, // e E f q Q r w !