summaryrefslogtreecommitdiff
path: root/rc/bin/blogcom
diff options
context:
space:
mode:
authoraiju <devnull@localhost>2013-04-30 16:57:27 +0200
committeraiju <devnull@localhost>2013-04-30 16:57:27 +0200
commit5335987c666bfc4f8220b2b5b2af6d07ccb651f6 (patch)
tree05aad8128ce0ac1f2e04647f707c8d7f16667e19 /rc/bin/blogcom
parentce62bbb8539eaa56c6646da3d445d968dabec99f (diff)
added blogcom
Diffstat (limited to 'rc/bin/blogcom')
-rw-r--r--rc/bin/blogcom39
1 files changed, 39 insertions, 0 deletions
diff --git a/rc/bin/blogcom b/rc/bin/blogcom
new file mode 100644
index 000000000..a9728b631
--- /dev/null
+++ b/rc/bin/blogcom
@@ -0,0 +1,39 @@
+#!/bin/rc
+if(~ $#1 0)
+ file=/lib/blogcom
+if not
+ file=$1
+awk ' BEGIN { w = 0; s = ""; nss = 0; srand() }
+function ends() {
+ ss[nss++] = s;
+ s = "";
+}
+{
+ split($0, a, "")
+ for(i = 1; i <= length($0); i++){
+ if(a[i] == "{"){
+ w = 1;
+ delete ws;
+ nws = 0;
+ ws[nws] = "";
+ }
+ else if(a[i] == "}"){
+ nws++;
+ s = s ws[int(rand()*nws)]
+ w = 0;
+ }
+ else if(a[i] == "|"){
+ if(w)
+ ws[++nws] = "";
+ else
+ ends();
+ }
+ else if(w)
+ ws[nws] = ws[nws] a[i];
+ else{
+ s = s a[i];
+ }
+ }
+}
+/[^|]$/ { if(w) ws[nws] = ws[nws] " "; else s = s " "; }
+END { ends(); print ss[int(rand()*nss)] } ' $file | fmt