]> git.lizzy.rs Git - plan9front.git/blob - rc/bin/blogcom
tcp17019: make service proto and netdir arguments optional (for aux/listen1)
[plan9front.git] / rc / bin / blogcom
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