(* A simple Standard ML program for creating skeletal home pages.
The program reads as input a user name and an email address
and produces as output the HTML-source of a simple, but
"personalised" home page.
HTML code which is produced by a program is referred to
as "dynamic HTML". So the present program produces dynamic HTML
as output.
*)
(***************** auxiliary functions *************)
(* [writeln s] prints line s on a line of its own *)
fun writeln(s)= (TextIO.output(TextIO.stdOut, s);
TextIO.output(TextIO.stdOut, "\n"))
fun tag1 t = "<"^t^">"
fun tag2 t = ""^t^">"
(* [maerke t text] evaluerer til strengen "text" *)
fun maerke t text = concat["<",t,">",text,"",t,">"]
(* [start title] writes the beginning of a web page *)
fun start(title) =
(writeln "Content-type: text/html\r\n\r\n";
writeln(tag1 "html");
writeln(maerke "title" title);
writeln(tag1 "body bgcolor=\"CCCCCC\"");
writeln(tag1 "font face=\"Arial, Helvetica, sans-serif\" size=\"-1\"")
)
(* [finish()] writes the final tags of a web-page *)
fun finish() =
(writeln(tag2 "font");
writeln(tag2 "body");
writeln(tag2 "html"))
fun italics text = concat["",text,""]
fun mailto(name,email) = concat[tag1("a href=mailto:"^email), name, tag2 "a"]
fun h3 text = writeln(maerke "h3" text)
fun p text = writeln(maerke "p" text)
fun hr()= writeln(tag1 "hr")
(******************* code for generating page starts here ***********)
fun accept_from_form() =
case (Mosmlcgi.cgi_field_string "email",
Mosmlcgi.cgi_field_string "name",
Mosmlcgi.cgi_field_string "linie")
of (SOME e, SOME n, SOME l) =>
(* now generate the form using n for the name and
e as email *)
(start("Hjemmeside for " ^ n);
h3 (n ^ "'s hjemmeside");
p ("Jeg er studerende på \
\IT-højskolen i København\
\ på " ^ l);
h3 "Mine interesser";
p "(kommer senere)";
hr();
p (italics("Denne side vedligholdes af " ^ n ^ " ("^ mailto(e,e)^")"));
finish()
)
| _ => writeln "Fejl i blanket: forventede tre felter"
(* apply the function accept_from_form to actually run the program *)
val _ = accept_from_form()