plan9fox/rc/bin/bullshit

52 lines
1.2 KiB
Text
Raw Normal View History

2011-08-08 16:14:52 +00:00
#!/bin/rc
awk '
function min(a, b){
if(a > b)
return b
else
return a
}
2011-08-08 17:01:38 +00:00
function suffix(){
if(hassuffix = (rand() < 0.2))
return suffixes[int(rand() * nsuffix)]
return ""
}
2011-08-08 16:14:52 +00:00
$2 == "*" { protocol[nprotocol++] = $1; next }
$2 == "$" { end[nend++] = $1; next }
2011-08-08 17:01:38 +00:00
$2 == "%" { suffixes[nsuffix++] = $1; next }
2011-08-08 16:14:52 +00:00
$2 == "^" { start[nstart++] = $1; next }
$2 == "|" { noend[nword] = 1 }
{ word[nword++] = $1; next }
END {
srand()
last = -1
out = 0
2011-08-08 17:01:38 +00:00
total = int(rand() * 7) + 3
2011-08-08 16:14:52 +00:00
n = int(rand() * min(total - out, 3))
for(i = 0; i < n; i++)
printf "%s ", start[int(rand() * nstart)]
out += n
2011-08-08 17:01:38 +00:00
hassuffix = 0
2011-08-08 16:14:52 +00:00
n = int(rand() * min(total - out, 3))
for(i = 0; i < n; i++)
2011-08-08 17:01:38 +00:00
printf "%s%s ", word[last = int(rand() * nword)], suffix()
2011-08-08 16:14:52 +00:00
out += n
if(rand() > 0.5){
n = int(rand() * 3)
for(i = 0; i < n; i++)
printf "%s %s", protocol[int(rand() * nprotocol)], (i != n-1) ? "over " : ""
out += n
last = -1
2011-08-08 17:01:38 +00:00
hassuffix = 0
2011-08-08 16:14:52 +00:00
}
n = int(rand() * min(total - out, 3))
if(out + n == 1 || last == -1)
n += 2
for(i = 0; i < n; i++)
2011-08-08 17:01:38 +00:00
printf "%s%s ", word[last = int(rand() * nword)], suffix()
2011-08-12 04:47:13 +00:00
if(rand() < 0.1 || (last >= 0 && noend[last]) || hassuffix)
2011-08-12 04:43:00 +00:00
printf "%s ", end[int(rand() * nend)]
2011-08-08 16:14:52 +00:00
print ""
}
' /lib/bullshit