\documentclass{article}
\input camila.mac
\begin{document}

\INCLUDE{str.cam}
\INCLUDE{txt.cam}
\INCLUDE{int.cam}
\INCLUDE{ff.cam}
$\begin{array}{l}
ffsPLUS:{A \pfunc{B}^{\star}} \tfunc{{A \pfunc{B}^{\star}}} \\ ffsPLUS(s) \deff \\ \rule{3ex}{0pt}  
\COND{
s = \emptyset}{\left(  \right)}{plus-red(\left(  \right),s)}
\end{array}$

\traco

$\begin{array}{l}
ffsUNION:{\set{A \pfunc{B}}} \tfunc{{\set{A \pfunc{B}}}} \\ ffsUNION(s) \deff \\ \rule{3ex}{0pt}  
\LET 
ffUnion = plus 
\IN 
\COND{
s = \emptyset}{\left(  \right)}{ffUnion-red(\left(  \right),s)} 
\TEL
\end{array}$

\traco

$\begin{array}{l}
ffsCount:A \times B \times {\set{A \pfunc{B}}} \tfunc{NAT0} \\ ffsCount(a,v,r) \deff \\ \rule{3ex}{0pt}  
card(\{t \asor t \in r \wedge 

a \in 
dom(t) \wedge 
 t(a) = v\})
\end{array}$

\traco

$\begin{array}{l}
ffsHistogr:A \times {\set{A \pfunc{B}}} \tfunc{B \pfunc{NAT}} \\ ffsHistogr(a,r) \deff \\ \rule{3ex}{0pt}  \left( \begin{array}{c}
 v \\ 
ffsCount(a,v,r) 
\end{array} \right)_{v \in 
ffsPro(a,r)}
\end{array}$

\traco

$\begin{array}{l}
ffsPro:A \times {\set{A \pfunc{B}}} \tfunc{{\set{B}}} \\ ffsPro(a,r) \deff \\ \rule{3ex}{0pt}  \{ t(a) \asor t \in r \wedge 
a \in 
dom(t)\}
\end{array}$

\traco

$\begin{array}{l}
ffsAtts:{\set{A \pfunc{B}}} \tfunc{{\set{A}}} \\ ffsAtts(r) \deff \\ \rule{3ex}{0pt}  
\bigcup (\{
dom(t) \asor t \in r\})
\end{array}$

\traco

$\begin{array}{l}
ffsJoin:{\set{A \pfunc{B}}} \times {\set{A \pfunc{B}}} \tfunc{{\set{A \pfunc{B}}}} \\ ffsJoin(f,g) \deff \\ \rule{3ex}{0pt}  \{tf \plus tg \asor tf \in f, tg \in g \wedge 

tf \mapdr 
dom(tg) = 
tg \mapdr 
dom(tf)\}
\end{array}$

\traco

$\begin{array}{l}
ffsRename:A \pfunc{A} \times {\set{A \pfunc{B}}} \tfunc{{\set{A \pfunc{B}}}} \\ ffsRename(r,f) \deff \\ \rule{3ex}{0pt}  
\LET 
g = 
\LAMBDA{a}
\COND{
a \in 
dom(r)}{ r(a)}{a} 
\IN  

g \hookrightarrow\star \hbox{-set} (f) 
\TEL
\end{array}$

\traco

$\begin{array}{l}
ffsColSUM:A \times {\set{A \pfunc{B}}} \tfunc{int} \\ ffsColSUM(a,r) \deff \\ \rule{3ex}{0pt}  
intSUM(\enlist{ t(a) \asor t \in r \wedge 

a \in 
dom(t) \wedge \is{int}( t(a))})
\end{array}$

\traco

$\begin{array}{l}
ffsColSUMseq:{\set{A \pfunc{B}}} \times {A^{\star}} \tfunc{{int^{\star}}} \\ ffsColSUMseq(t,l) \deff \\ \rule{3ex}{0pt}  \enlist{
ffsColSUM(a,t) \asor a \in l}
\end{array}$

\traco

$\begin{array}{l}
ffs2txt:{\set{A \pfunc{B}}} \tfunc{txt} \\ ffs2txt(s) \deff \\ \rule{3ex}{0pt}  
\COND{
s = \emptyset}{\enlist{\!\!\mattt{
\mbox{\texttt{"No records found"}}}}}{
\LET 
r =  
ff2STRff\hbox{-set} (s)\\
A = 
ffsAtts(r)\\
x = \left( \begin{array}{c}
 a \\ 
2 + 
intMAX(\{
strlen(v) \asor v \in \{a\} \cup 
ffsPro(a,r)\}) 
\end{array} \right)_{a \in A}\\
L = \enlist{a \asor a \in A}\\
hline = \enlist{
strcat(\!\!\mattt{
\mbox{\texttt{"+"}}},
strFill(\!\!\mattt{
\mbox{\texttt{"-"}}}, x(a))) \asor a \in L} \conc \enlist{\!\!\mattt{
\mbox{\texttt{"+(cr)"}}}}\\
rl = \enlist{hline,\enlist{
strcat(\!\!\mattt{
\mbox{\texttt{"|"}}},
strCenter(a, x(a))) \asor a \in L} \conc \enlist{\!\!\mattt{
\mbox{\texttt{"|(cr)"}}}},hline} \conc \enlist{\enlist{
strcat(\!\!\mattt{
\mbox{\texttt{"|"}}},
\COND{
\neg 
a \in 
dom(t) }{
strCenter(\!\!\mattt{
""}, x(a))}{
\COND{\is{str}( t(a))}{
strCenter( t(a), x(a))}{
\COND{\is{int}( t(a))}{
strRight(
itoa( t(a)), x(a))}{
strCenter(\!\!\mattt{
\mbox{\texttt{"!"}}}, x(a))}}}) \asor a \in L} \conc \enlist{\!\!\mattt{
\mbox{\texttt{"|(cr)"}}}} \asor t \in r} \conc \enlist{hline} 
\IN 
txtFlat(rl) 
\TEL}
\end{array}$

\traco

$\begin{array}{l}
ffs2TeXtxt:{\set{A \pfunc{B}}} \tfunc{txt} \\ ffs2TeXtxt(s) \deff \\ \rule{3ex}{0pt}  
\COND{
s = \emptyset}{\enlist{\!\!\mattt{
\mbox{\texttt{"No records found"}}}}}{
\LET 
r =  
ff2STRff\hbox{-set} (s)\\
A = 
ffsAtts(r)\\
L = \enlist{a \asor a \in A} 
\IN 
\COND{
L = \emptylist}{\enlist{\!\!\mattt{
\mbox{\texttt{"No attributes in table"}}}}}{
\LET 
h = 
head(L)\\
t = 
tail(L) 
\IN \enlist{\!\!\mattt{
\mbox{\texttt{"$\backslash$$\backslash$begin\{tabular\}\{"}}},
strCAT(\enlist{\!\!\mattt{
\mbox{\texttt{"|c"}}} \asor a \in L} \conc \enlist{\!\!\mattt{
\mbox{\texttt{"|\}"}}}}),\!\!\mattt{
\mbox{\texttt{"$\backslash$$\backslash$hline(cr)"}}}} \conc 
seqAddSep(\enlist{
strcat(\!\!\mattt{
\mbox{\texttt{"$\backslash$$\backslash$bf "}}},a) \asor a \in L},\!\!\mattt{\mbox{\texttt{"$\backslash$&"}}}) \conc \enlist{\!\!\mattt{
\mbox{\texttt{"$\backslash$$\backslash$$\backslash$$\backslash$$\backslash$$\backslash$hline$\backslash$$\backslash$hline(cr)"}}}} \conc \enlist{
seqAddSep(\enlist{
\COND{
a \in 
dom(t)}{ t(a)}{\!\!\mattt{
\mbox{\texttt{""\}\} $\backslash$asor a $\backslash$in L\},$\backslash$!$\backslash$!$\backslash$mattt\{"}}\&\mbox{\texttt{"\}) $\backslash$conc $\backslash$enlist\{$\backslash$!$\backslash$!$\backslash$mattt\{
"}}\\\\\\hline(cr)\mbox{\texttt{"\}\} $\backslash$asor t $\backslash$in r\} $\backslash$conc $\backslash$enlist\{$\backslash$!$\backslash$!$\backslash$mattt\{
"}}\\end{tabular}(cr)"}} 
\TEL} 
\TEL}
\end{array}$

\traco

$\begin{array}{l}
ffs2HTMLtxtOld:{\set{A \pfunc{B}}} \tfunc{txt} \\ ffs2HTMLtxtOld(s) \deff \\ \rule{3ex}{0pt}  
\COND{
s = \emptyset}{\enlist{\!\!\mattt{
\mbox{\texttt{"No records found"}}}}}{
\LET 
r = \{
ff2STRff(t) \asor t \in s\}\\
head = 
\LAMBDA{l}\enlist{\!\!\mattt{
\mbox{\texttt{"<TR>"}}}} \conc \enlist{\!\!\mattt{
\mbox{\texttt{"<TH>"}}} \conc a \conc \!\!\mattt{
\mbox{\texttt{"</TH>"}}} \asor a \in l} \conc \enlist{\!\!\mattt{
\mbox{\texttt{"</TR>(cr)"}}}}\\
row = 
\LAMBDA{l}\enlist{\!\!\mattt{
\mbox{\texttt{"<TR>"}}}} \conc \enlist{\!\!\mattt{
\mbox{\texttt{"<TD>"}}} \conc a \conc \!\!\mattt{
\mbox{\texttt{"</TD>"}}} \asor a \in l} \conc \enlist{\!\!\mattt{
\mbox{\texttt{"</TR>(cr)"}}}}\\
A = 
ffsAtts(r)\\
L = \enlist{a \asor a \in A}\\
x = \enlist{\enlist{
\COND{
a \in 
dom(t)}{ t(a)}{\!\!\mattt{
""}} \asor a \in L} \asor t \in r}\\
rl = \enlist{\!\!\mattt{
\mbox{\texttt{"<HTML>(cr)<HEAD>(cr)<TITLE>ffs2HTMLtxt [ffs.cam] output</TITLE>(cr)</HEAD>(cr)"}}},\!\!\mattt{
\mbox{\texttt{"<TABLE BORDER CELLPADDING=5 CELLSPACING=0>(cr)"}}}} \conc 
head(L) \conc  
row^* (x) \conc \enlist{\!\!\mattt{
\mbox{\texttt{"</TABLE>(cr)</HTML>(cr)"}}}} 
\IN 
txtFlat(rl) 
\TEL}
\end{array}$

\traco

$\begin{array}{l}
ffs2HTMLtxt:{\set{A \pfunc{B}}} \tfunc{txt} \\ ffs2HTMLtxt(s) \deff \\ \rule{3ex}{0pt}  
\COND{
s = \emptyset}{\enlist{\!\!\mattt{
\mbox{\texttt{"No records found"}}}}}{
\LET 
r = \{
ff2STRff(t) \asor t \in s\}\\
even = 
\LAMBDA{a}

rem(a,2) = 0\\
th = 
\LAMBDA{a}\enlist{\!\!\mattt{
\mbox{\texttt{"<td valign=$\backslash$"top$\backslash$" align=$\backslash$"center$\backslash$" nowrap "}}},\!\!\mattt{
\mbox{\texttt{" bgcolor=$\backslash$"#184A84$\backslash$"><font face=$\backslash$"Arial$\backslash$" size=$\backslash$"3$\backslash$" (cr)"}}},\!\!\mattt{
\mbox{\texttt{" color=$\backslash$"#FFFFFF$\backslash$"><strong>"}}},a,\!\!\mattt{
\mbox{\texttt{"</strong></font></td>"}}}}\\
Td = 
\LAMBDA{a,c}\enlist{\!\!\mattt{
\mbox{\texttt{"<td valign=$\backslash$"top$\backslash$" align=$\backslash$"left$\backslash$" nowrap "}}},\!\!\mattt{
\mbox{\texttt{" bgcolor=$\backslash$""}}} \conc c \conc \!\!\mattt{
\mbox{\texttt{"$\backslash$"><font face=$\backslash$"Arial$\backslash$" size=$\backslash$"3$\backslash$">"}}},a,\!\!\mattt{
\mbox{\texttt{"</font></td>(cr)"}}}}\\
head = 
\LAMBDA{l}\enlist{\!\!\mattt{
\mbox{\texttt{"<TR>(cr)"}}}} \conc \enlist{
th(a) \asor a \in l} \conc \enlist{\!\!\mattt{
\mbox{\texttt{"(cr)</TR>(cr)"}}}}\\
row = 
\LAMBDA{l,c}\enlist{\!\!\mattt{
\mbox{\texttt{"<TR>(cr)"}}}} \conc \enlist{
Td(a,c) \asor a \in l} \conc \enlist{\!\!\mattt{
\mbox{\texttt{"(cr)</TR>(cr)"}}}}\\
A = 
ffsAtts(r)\\
L = \enlist{a \asor a \in A}\\
x = \enlist{\enlist{
\COND{
a \in 
dom(t)}{ t(a)}{\!\!\mattt{
""}} \asor a \in L} \asor t \in r}\\
y = 
seq2ff(x)\\
z = \left( \begin{array}{c}
 n \\ 
row( y(n),
\COND{
even(n)}{\!\!\mattt{
\mbox{\texttt{"#FFFFFF"}}}}{\!\!\mattt{
\mbox{\texttt{"#FFFFD2"}}}}) 
\end{array} \right)_{n \in 
dom(y)}\\
rl = \enlist{\!\!\mattt{
\mbox{\texttt{"<html>(cr)<HEAD>(cr)<TITLE>ffs2HTMLtxt [ffs.cam] output</TITLE>(cr)</HEAD>(cr)"}}},\!\!\mattt{
\mbox{\texttt{"<body BGCOLOR=$\backslash$"#F4EFD8$\backslash$" TEXT=$\backslash$"#260000$\backslash$" LINK=$\backslash$"#008000$\backslash$" VLINK=$\backslash$"#800000$\backslash$">(cr)"}}},\!\!\mattt{
\mbox{\texttt{"<table border=$\backslash$"0$\backslash$"><tr><td BGCOLOR=$\backslash$"#B5D2F2$\backslash$">(cr)"}}},\!\!\mattt{
\mbox{\texttt{"<table border=$\backslash$"0$\backslash$" width=$\backslash$"100\%$\backslash$" bordercolor=$\backslash$"#FFFFFF$\backslash$" (cr)"}}},\!\!\mattt{
\mbox{\texttt{" bordercolorlight=$\backslash$"#FFFFFF$\backslash$" bordercolordark=$\backslash$"#FFFFFF$\backslash$" (cr)"}}},\!\!\mattt{
\mbox{\texttt{" cellspacing=$\backslash$"1$\backslash$" cellPadding=$\backslash$"2$\backslash$">(cr)"}}}} \conc 
head(L) \conc 
ff2seq(\emptylist,z) \conc \enlist{\!\!\mattt{
\mbox{\texttt{"</table>(cr)</td></tr></table>(cr)</body>(cr)</html>(cr)"}}}} 
\IN 
txtFlat(rl) 
\TEL}
\end{array}$

\traco
\end{document}
