shithub: 9ferno

Download patch

ref: b4b0d20f9f62065378f9aac05cc07df601bf4568
parent: 670f0522666ee17979bb50708af67692c630a54c
author: henesy <unknown>
date: Thu Oct 3 04:02:17 EDT 2019

add ind and unind for use in acme from petes a+.b and a-.b

--- a/.hgignore
+++ b/.hgignore
@@ -59,6 +59,7 @@
 ^dis/*/.*.dis
 ^appl/.*.dis
 ^appl/.*.sbl
+^acme/dis/.*.dis
 ^tmp/.*
 ^contrib/.*
 ^usr/\.*
--- /dev/null
+++ b/appl/acme/acme/bin/src/ind.b
@@ -1,0 +1,49 @@
+implement APlus;
+
+include "sys.m"; sys: Sys;
+include "draw.m";
+include "bufio.m"; bufio: Bufio;
+	Iobuf: import bufio;
+
+APlus: module {
+	init: fn(nil: ref Draw->Context, args: list of string);
+};
+
+pname: string;
+
+init(nil: ref Draw->Context, args: list of string)
+{
+	sys = load Sys Sys->PATH;
+	bufio = load Bufio Bufio->PATH;
+
+	indents := "\t";
+
+	if(args != nil) {
+		pname = hd args;
+		args = tl args;
+	} else {
+		pname = "a+";
+	}
+
+	if(args != nil)
+		indents = hd args;
+
+	indent(indents);
+}
+
+indent(s: string)
+{
+	stdin := bufio->fopen(sys->fildes(0), bufio->OREAD);
+	if(stdin == nil) {
+		sys->fprint(sys->fildes(2), "%s: Couldn't create a bufio:  %r\n", pname);
+		raise "fail:errors";
+	}
+
+	while((line := stdin.gets('\n')) != nil) {
+		if(line == "\n") {
+			sys->print("\n");
+		} else {
+			sys->print("%s%s", s, line);
+		}
+	}
+}
--- a/appl/acme/acme/bin/src/mkfile
+++ b/appl/acme/acme/bin/src/mkfile
@@ -9,6 +9,8 @@
 	spout.dis\
 	awd.dis\
 	cd.dis\
+	ind.dis\
+	unind.dis\
 
 MODULES=\
 	
--- /dev/null
+++ b/appl/acme/acme/bin/src/unind.b
@@ -1,0 +1,47 @@
+implement AMinus;
+
+include "sys.m"; sys: Sys;
+include "draw.m";
+include "bufio.m"; bufio: Bufio;
+	Iobuf: import bufio;
+
+AMinus: module {
+	init: fn(nil: ref Draw->Context, args: list of string);
+};
+
+pname: string;
+
+init(nil: ref Draw->Context, args: list of string)
+{
+	sys = load Sys Sys->PATH;
+	bufio = load Bufio Bufio->PATH;
+
+	indents := "\t";
+
+	if(args != nil) {
+		pname = hd args;
+		args = tl args;
+	} else {
+		pname = "a-";
+	}
+
+	if(args != nil)
+		indents = hd args;
+
+	unindent(indents);
+}
+
+unindent(s: string)
+{
+	stdin := bufio->fopen(sys->fildes(0), bufio->OREAD);
+	if(stdin == nil) {
+		sys->fprint(sys->fildes(2), "%s: Couldn't create a bufio:  %r\n", pname);
+		raise "fail:errors";
+	}
+
+	while((line := stdin.gets('\n')) != nil) {
+		if(len line >= len s && line[0:len s] == s)
+			line = line[len s:];
+		sys->print("%s", line);
+	}
+}