#!/usr/bin/gawk -f
# /* vim: set filetype=awk : */ # -*- awk -*-
BEGIN { Stem="/tmp/$$"; RS=""; FS="\n"; Rx=-1
Dot=dot("blue-square.jpg")
}
NR==1 {
TocF = Stem "/toc.html" ; print header() > TocF
AindexF = Stem "/attributes.html" ; print header() > AindexF
RxindexF = Stem "/treatments.html" ; print header() > RxindexF
}
#/\nConfig/ { config(); next }
/ Worth/ {
Head=$0; getline; Body=$0;
rx(++Rx,Head,Body,CrossIndex) ;
next
}
END { rxindex(Rx)
dumpIndex(AindexF,CrossIndex)
}
function rxindex(n, i) {
print "
" >>RxindexF
}
function header() {
return "\n"\
"\n"\
"\n"\
"Trade Space Browser\n"\
"\n"\
"\n"\
"\n"\
"\n"\
"\n"
}
function rx(n,head,body,xindex, str,rxF) {
rxF = Stem "/rx" n ".html";
indexes(head,n,xindex)
print header() > rxF;
print "Treatment #" n "
" body_(n,body) head_(n,head) >> rxF;
}
function indexes(what,n,xindex, tmp,m,i) {
sub(/Treatment:/,"",what)
gsub(/[ \[\]\t]/,"",what);
m=split(what,tmp,/[\n=]/);
for(i=3;i<=m;i=i+2) {
Exists[tmp[i]]=1
xindex[tmp[i],++xindex[tmp[i],0]]=n
}
}
function dumpIndex(f,xindex, i,str,sep,j,jmax,com) {
com= "sort +1 >> " AindexF
print "" | com
for(i in Exists) {
str=sep="";
if (i !~ /NoTreatment/) {
jmax=xindex[i,0]
for(j=1;j<=jmax;j++) {
print i,j,xindex[i,j]
str = str sep ""xindex[i,j]""
sep = " | ";
}
print "- ",i, " * " jmax "
- " str "
" | com
}}
print "
" | com
}
function head_(n,head) {
gsub(/Treatment:/,"",head);
gsub(/\.000000/,"",head);
gsub(/\.\./," .. ",head);
gsub(/[\(\)]/,"",head);
gsub(/\n/,"
\n",head);
sub(/\[/,"[", head);
sub(/\]/,"]
",head);
return head;
}
function body_(n,body) {
gsub(/~/,Dot,body);
gsub(/\n/,"\n",body);
gsub(/\]/,"] |
",body);
gsub(/:/,"",body);
gsub(/\[/," | [",body);
return "";
}
function dot(n) { return "" }
#saya.awk
#Print a string in key-sort order.
function saya(s,a,q1,q2,eol, com,i,j,n,tmp,str,sep) {
com="sort";
q1= q1 ? "\"" : "";
q2= q2 ? "\"" : "";
for(i in a) {
sep="";
str= s"[";
n=split(i,tmp,SUBSEP);
for(j=1;j<=n;j++) {
str=str sep q1 tmp[j] q1;
sep=",";
}
print str "] = " q2 a[i] q2 eol | com;
};
close(com);
}
|