shithub: pointless

Download patch

ref: 88702036dd2a9a54247dc2729bd8dcb9141f8867
author: Tevo <[email protected]>
date: Sun Nov 8 19:50:12 EST 2020

Initial implementation

--- /dev/null
+++ b/generate
@@ -1,0 +1,36 @@
+#!/bin/rc -e
+
+rfork en
+
+fn usage {
+	aux/usage
+	exit usage
+}
+
+args='dir'
+flagfmt='o:outdir outdir'
+
+if(! eval `{aux/getflags $*})
+	usage
+
+if(~ $#outdir 0)
+	outdir=`{pwd}^/out
+
+if(! ~ $#* 1)
+	usage
+
+mkdir -p $outdir
+dircp $1 $outdir
+
+for(index in `{walk $outdir | grep 'index\.rc$'}) @{
+	cd `{basename -d $index}
+	. index.rc
+	rm index.rc
+}
+
+for(ptless in `{walk $outdir | grep '\.ptless$'}) @{
+	cd `{basename -d $ptless}
+	ptless=`{basename $ptless}
+	pointless.awk $ptless >`{echo $ptless | sed 's@\[email protected]@'}
+	rm $ptless
+}
--- /dev/null
+++ b/pointless.awk
@@ -1,0 +1,48 @@
+#!/bin/awk -f
+
+BEGIN {
+	inexec = 0
+}
+
+/<exec.*>/ {
+	execline = NR
+	inexec = 1
+	delete args
+	prog = ""
+	# is there a better way to represent whitespace?
+	gsub("^.*<exec[ 	]*", "")
+	gsub("[ 	]*>.*$", "")
+	shell = $1
+	if(length(shell) == 0)
+		shell = "/bin/rc"
+	for(c = 2; c <= NF; c++)
+ 		args[c-2] = $c
+}
+
+/<\/exec>/ {
+	if(!inexec) {
+		print "error: </exec> without opening at " FILENAME ":" NR >"/fd/2"
+		exit "noopening"
+	}
+	system("{" shell "} <<'__POINTLESS_EOF__'\n" prog "\n__POINTLESS_EOF__")
+	inexec = 0
+	lastexec = NR
+}
+
+{
+	if(inexec)
+	{
+		if(execline != NR)
+			prog = prog "\n" $0
+	}
+	else
+		if(lastexec != NR)
+			print
+}
+
+END {
+	if(inexec) {
+		print "error: dangling exec at " FILENAME ":" execline >"/fd/2"
+		exit "nofinish"
+	}
+}