ref: 7ae7351ace73a70cbbaf5a2da016005485d0d43b
parent: f4624471579e0cfb531ffc733cdbe007ecdfed9d
author: henesy <devnull@localhost>
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;
+}