changelog shortlog tags branches changeset files revisions annotate raw help

Mercurial > hg > plan9front / rc/bin/blogcom

changeset 7243: 34f64dcbbc25
parent: af5d94af9e23
author: cinap_lenrek@felloff.net
date: Fri, 17 May 2019 18:14:10 +0200
permissions: -rwxr-xr-x
description: 7l: don't hardcode 4k pagesize, use INITRND
1 #!/bin/rc
2 if(~ $#1 0)
3  file=/lib/blogcom
4 if not
5  file=$1
6 awk ' BEGIN { w = 0; s = ""; nss = 0; srand() }
7 function ends() {
8  ss[nss++] = s;
9  s = "";
10 }
11 {
12  split($0, a, "")
13  for(i = 1; i <= length($0); i++){
14  if(a[i] == "{"){
15  w = 1;
16  delete ws;
17  nws = 0;
18  ws[nws] = "";
19  }
20  else if(a[i] == "}"){
21  nws++;
22  s = s ws[int(rand()*nws)]
23  w = 0;
24  }
25  else if(a[i] == "|"){
26  if(w)
27  ws[++nws] = "";
28  else
29  ends();
30  }
31  else if(w)
32  ws[nws] = ws[nws] a[i];
33  else{
34  s = s a[i];
35  }
36  }
37 }
38 /[^|]$/ { if(w) ws[nws] = ws[nws] " "; else s = s " "; }
39 END { ends(); print ss[int(rand()*nss)] } ' $file | fmt