ed

[hare] The standard editor
Log | Files | Refs | README | LICENSE

commit b9d8945d34c6e559a87400a99c7c4f6fadabcd2b
parent d525d4b5711b5d5b1a1205c92a208840e14a033a
Author: Byron Torres <b@torresjrjr.com>
Date:   Sun, 11 Dec 2022 02:30:12 +0000

remove .cmd from session{}

Diffstat:
Mcommand.ha | 8++++----
Mmain.ha | 32++++++++++++++++----------------
2 files changed, 20 insertions(+), 20 deletions(-)

diff --git a/command.ha b/command.ha @@ -43,12 +43,12 @@ fn exec_addrs(s: *session, cmd: *command) (void | error) = { }; // Executes the session's .cmd command. -fn execute(s: *session) (void | error) = { +fn execute(s: *session, cmd: *command) (void | error) = { // TODO: move this into the cmd_* functions? - exec_addrs(s, &s.cmd)?; - defer delete(s.cmd.linenums[..]); // TODO: write finish_cmd() + exec_addrs(s, cmd)?; + defer delete(cmd.linenums[..]); // TODO: write finish_cmd() - s.cmd.cmdfn(s, &s.cmd)?; + cmd.cmdfn(s, cmd)?; }; fn get_range(s: *session, lns: *[]size, a: size, b: size) ((size, size) | badaddress) = { diff --git a/main.ha b/main.ha @@ -9,7 +9,6 @@ use strings; type session = struct { buf: buffer, mode: mode, - cmd: command, helpmode: bool, lasterror: str, suppressmode: bool, @@ -30,22 +29,23 @@ export fn main() void = { ('s', "suppress byte counts and '!' prompt"), "[file]", ]; - const cmd = getopt::parse(os::args, help...); - defer getopt::finish(&cmd); + const main_cmd = getopt::parse(os::args, help...); + defer getopt::finish(&main_cmd); - const s = session { + let s = session { buf = buffer { lines = [ alloc(line { ... }) ], trash = [], ... }, - cmd = command { ... }, prompt = "*", ... }; - for (let i = 0z; i < len(cmd.opts); i += 1) { - const opt = cmd.opts[i]; + let cmd = command { ... }; + + for (let i = 0z; i < len(main_cmd.opts); i += 1) { + const opt = main_cmd.opts[i]; switch (opt.0) { case 'p' => s.prompt = opt.1; @@ -55,24 +55,24 @@ export fn main() void = { }; }; - if (len(cmd.args) > 1) { + if (len(main_cmd.args) > 1) { exit_usage(help); }; - if (len(cmd.args) == 1) { - switch (cmd.args[0]) { + if (len(main_cmd.args) == 1) { + switch (main_cmd.args[0]) { case "-" => fmt::fatal("Invalid filename '-'"); case "" => fmt::fatal("Invalid filename ''"); case => - s.buf.filename = cmd.args[0]; + s.buf.filename = main_cmd.args[0]; }; }; if (len(s.buf.filename) != 0) { - s.cmd.arg = s.buf.filename; - cmd_edit(&s, &s.cmd): void; + cmd.arg = s.buf.filename; + cmd_edit(&s, &cmd): void; }; for (true) :repl { @@ -101,16 +101,16 @@ export fn main() void = { switch (s.mode) { case mode::COMMAND => - if (parse(&s.cmd, input)) { + if (parse(&cmd, input)) { // TODO: handle all ": void"s - execute(&s): void; + execute(&s, &cmd): void; }; case mode::INPUT => if (input == ".") { s.mode = mode::COMMAND; continue; }; - append(s.cmd.input, input); + append(cmd.input, input); }; };