home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / C / Applications / Moscow ML 1.42 / examples / cgi / cgiex2.sml < prev    next >
Encoding:
Text File  |  1997-08-18  |  1.2 KB  |  40 lines  |  [TEXT/R*ch]

  1. (* File mosml/examples/cgi/cgiex2.sml 
  2.  
  3.    Example CGI program, which may be invoked by the webserver to
  4.    handle requests transmitted from the example HTML FORM in file
  5.    upload.html.  See file README2 for instructions.
  6.  
  7.  *)
  8.  
  9. open Mosmlcgi;
  10.  
  11. fun prtint i = print (Int.toString i)
  12. fun prtline sus = (print (Substring.string sus); print "\n")
  13. fun lines s = Substring.fields (fn c => c = #"\n") (Substring.all s)
  14.  
  15. fun processfile filedata =
  16.     (case part_data (valOf (cgi_part "action")) of
  17.      "count characters" => 
  18.          (print "File contains "; 
  19.           prtint (size filedata); 
  20.           print " characters\n")
  21.        | "count lines" => 
  22.          (print "File contains "; 
  23.           prtint (length (lines filedata)); 
  24.           print " lines\n")
  25.        | "sort" => 
  26.          (print "Sorted file:<P>\n<PRE>";
  27.           app prtline (Listsort.sort Substring.compare (lines filedata));
  28.           print "</PRE>\n")
  29.        | _ => 
  30.          print "Unknown action\n")
  31.     handle Option => print "No action\n"
  32.  
  33. val _ = 
  34.     (print "Content-type: text/html\n\n";
  35.      print "<HTML><BODY>";
  36.      (case cgi_part "filecontents" of
  37.       SOME part => processfile (part_data part)
  38.     | NONE      => print "No file\n");
  39.      print "</BODY></HTML>")
  40.