commit 078ab7e5f7f943c82e37467a0892805f7747caef
parent 98c6605de422ebf9f5a221e3adf40d4a9da49785
Author: Byron Torres <b@torresjrjr.com>
Date: Thu, 9 Sep 2021 02:26:14 +0100
Write ed usage interface and Makefile
Diffstat:
3 files changed, 52 insertions(+), 0 deletions(-)
diff --git a/.gitignore b/.gitignore
@@ -0,0 +1,2 @@
+ed
+tmp/
diff --git a/Makefile b/Makefile
@@ -0,0 +1,17 @@
+.POSIX:
+.SUFFIXES:
+HARE=hare
+HAREFLAGS=
+
+all: ed
+
+clean:
+ rm -f ed
+
+.PHONY: all clean
+
+.SUFFIXES: .ha
+.ha:
+ $(HARE) build $(HAREFLAGS) -o $@ $<
+
+ed: ed.ha
diff --git a/ed.ha b/ed.ha
@@ -0,0 +1,33 @@
+use getopt;
+use os;
+
+export fn main() void = {
+ const help: [_]getopt::help = [
+ "standard line editor",
+ ('p', "prompt", "set the command prompt"),
+ ('s', "suppress byte counts and '!' prompt"),
+ "[file]",
+ ];
+ const cmd = getopt::parse(os::args, help...);
+ defer getopt::finish(&cmd);
+
+ let prompt = "";
+ let verbose = true;
+
+ for (let i = 0z; i < len(cmd.opts); i += 1) {
+ const opt = cmd.opts[i];
+ switch (opt.0) {
+ 'p' => prompt = opt.1,
+ 's' => verbose = false,
+ };
+ };
+
+ if (len(cmd.args) > 1) {
+ exit_usage(help);
+ };
+};
+
+@noreturn fn exit_usage(help: []getopt::help) void = {
+ getopt::printusage(os::stderr, os::args[0], help);
+ os::exit(1);
+};