ref: a2f8ba07fa6696bfd9a07a870bacec9ad973a53c
parent: 8dc249c8fd81431d5adceae019e84e66ba56e0de
author: henesy <unknown>
date: Mon May 31 08:18:46 EDT 2021
add hd and tl commands for sh interactive list manipulation
--- /dev/null
+++ b/appl/cmd/hd.b
@@ -1,0 +1,37 @@
+implement Hd;
+
+include "sys.m";
+ sys: Sys;
+
+include "draw.m";
+
+include "string.m";
+
+stderr: ref Sys->FD;
+
+Hd: module {
+ init: fn(nil: ref Draw->Context, argv: list of string);
+};
+
+
+init(nil: ref Draw->Context, argv: list of string)
+{
+ sys = load Sys Sys->PATH;
+ stderr = sys->fildes(2);
+ str := load String String->PATH;
+
+ if(len argv < 2)
+ usage();
+
+ argv = tl argv;
+
+ out := str->quoted(hd str->unquoted(str->quoted(argv)) :: nil);
+ sys->print("%s\n", out);
+
+ exit;
+}
+
+usage() {
+ sys->fprint(stderr, "usage: hd (list 'of tokens')\n");
+ exit;
+}
--- a/appl/cmd/mkfile
+++ b/appl/cmd/mkfile
@@ -80,6 +80,7 @@
grep.dis\
gunzip.dis\
gzip.dis\
+ hd.dis\
idea.dis\
import.dis\
iostats.dis\
@@ -156,6 +157,7 @@
time.dis\
timestamp.dis\
tkcmd.dis\
+ tl.dis\
touch.dis\
touchcal.dis\
tokenize.dis\
--- /dev/null
+++ b/appl/cmd/tl.b
@@ -1,0 +1,37 @@
+implement Tl;
+
+include "sys.m";
+ sys: Sys;
+
+include "draw.m";
+
+include "string.m";
+
+stderr: ref Sys->FD;
+
+Tl: module {
+ init: fn(nil: ref Draw->Context, argv: list of string);
+};
+
+
+init(nil: ref Draw->Context, argv: list of string)
+{
+ sys = load Sys Sys->PATH;
+ stderr = sys->fildes(2);
+ str := load String String->PATH;
+
+ if(len argv < 2)
+ usage();
+
+ argv = tl argv;
+
+ out := str->quoted(tl str->unquoted(str->quoted(argv)));
+ sys->print("%s\n", out);
+
+ exit;
+}
+
+usage() {
+ sys->fprint(stderr, "usage: tl (list 'of tokens')\n");
+ exit;
+}