Commits

Anonymous committed 41358ac

tmpl

  • Participants
  • Parent commits ec4b09d

Comments (0)

Files changed (6)

barron_logo.png

Added
New image

caml.128x58.gif

Added
New image
-#/bin/sh
+#!/bin/sh
 coqc main.v
-rm coqMain.mli
-ocamlopt nums.cmxa str.cmxa util.ml coqMain.ml reader.ml parser.ml main.ml -o index0.cgi
+ocamlopt -c coqMain.mli coqMain.ml
+ocamlopt nums.cmxa str.cmxa util.ml coqMain.ml reader.ml parser.ml main.ml -o index.cgi
 rm *.cmx *.cmi *.o *.vo
+<html>
+<meta http-equiv='Content-Type' content='text/html; charset=EUC_JP'>
+<head>
+ <title>Free Calculator</title>
+</head>
+
+<body>
+<a href='lambdavn/'>Lambda Vn</a>, 
+<a href='http://d.hatena.ne.jp/yoshihiro503/'>Coq blog</a><br>
+
+<h2>Free Calculator</h2>
+<center>
+<br>
+<form action='index.cgi' method='post' name='calc'>
+<table border=0 cellspacing=0 cellpadding=0>
+ <tr><td valign=top>
+  <table border=1 cellpadding=1 cellspacing=1 bgcolor=#7597dd id='free' width=650>
+   <tr style='background-color: #e5ecf9;'>
+    <td rowspan=2 valign=middle nowrap width=200>&nbsp;<b>Expression</b>&nbsp;</td>
+    <td nowrap width=200>&nbsp;Digit number<select name='precision'>
+     <option value='inf' selected>infinity</option>
+    </select></td>
+    <td nowrap width=200>&nbsp;</td>
+    <td rowspan=2 nowrap align=center valign=middle >&nbsp;</td>
+   </tr>
+   <tr style='background-color: #e5ecf9;'>
+    <td nowrap>&nbsp;</td>
+    <td>&nbsp;</td>
+   </tr>
+   <tr style='background-color: #ffffff;'>
+     <td colspan=4 valign=top><textarea style='border-style:none;' cols=73 rows=12 name='formula'>
+	 ::text::
+     </textarea></td>
+   </tr>
+   <tr><td height=35 valign=middle style='background-color:#e5ecf9;' colspan=4>
+       &nbsp;&nbsp;<input type='submit' value='Execution'>
+   </td></tr>
+   <tr><td bgcolor='#e5ecf9' colspan=4>&nbsp;Answer
+   </td></tr>
+   <tr style='background-color: #ffffff;'><td nowrap valign='top' colspan=4><input size='79' style=' border-style: none;' type='text' id='ans' class='text' value='::result::'>
+   </td></tr>
+  </table>
+ </td></tr>
+</table>
+</form>
+</center>
+<br>
+<div align=right>
+Powered by <a href='http://caml.inria.fr/'><img src='caml.128x58.gif' alt='powered by OCaml' border='0' height='30'/></a>
+and <a href='http://coq.inria.fr/'><img src='barron_logo.png' alt='powered by Coq' border='0' height='40'/></a>.
+</div><br>
+Original <a href='http://keisan.casio.com/has10/Free.cgi'>High precision calculator</a><br>
+Free CGI server: <a href='http://0web.cjb.net'>Zero Web Server</a><br>
+</body>
+</html>
+
   if (q.qden = XH) then sz q.qnum
   else sz q.qnum ^ "/" ^ spositive q.qden
 
+let input_all fname =
+  Util.infile fname (fun ch ->
+    let rec iter store =
+      try iter (input_line ch :: store) with
+      | End_of_file -> slist ~delim:"\n" id @@ List.rev store
+    in iter [])
+
 let main =
   let result, text =
     try
     with
     | e -> "Objective Caml " ^ Printexc.to_string e, ""
   in
+  let templ = input_all "index.template" in
+  let html = Str.global_replace (Str.regexp "::text::") text templ
+      +> Str.global_replace (Str.regexp "::result::") result
+  in
   print_string "Content-type: text/html\n";
   print_string "\n";
-  print_string
-"<html>
-<meta http-equiv='Content-Type' content='text/html; charset=EUC_JP'>
-<head>
- <title>Free Calculator</title>
-</head>
-
-<body>
-<a href='lambdavn/'>Lambda Vn</a>, 
-<a href='http://d.hatena.ne.jp/yoshihiro503/'>Coq blog</a><br>
-
-<h2>Free Calculator</h2>
-<center>
-<br>
-<form action='index.cgi' method='post' name='calc'>
-<table border=0 cellspacing=0 cellpadding=0>
- <tr><td valign=top>
-  <table border=1 cellpadding=1 cellspacing=1 bgcolor=#7597dd id='free' width=650>
-   <tr style='background-color: #e5ecf9;'>
-    <td rowspan=2 valign=middle nowrap width=200>&nbsp;<b>Expression</b>&nbsp;</td>
-    <td nowrap width=200>&nbsp;Digit number<select name='precision'>
-     <option value='inf' selected>��</option>
-    </select></td>
-    <td nowrap width=200>&nbsp;</td>
-    <td rowspan=2 nowrap align=center valign=middle >&nbsp;</td>
-   </tr>
-   <tr style='background-color: #e5ecf9;'>
-    <td nowrap>&nbsp;</td>
-    <td>&nbsp;</td>
-   </tr>
-   <tr style='background-color: #ffffff;'>
-    <td colspan=4 valign=top><textarea style='border-style:none;' cols=73 rows=12 name='formula'>
-";
-  print_string text;
-  print_string
-"</textarea>
-    </td>
-   </tr>
-   <tr><td height=35 valign=middle style='background-color:#e5ecf9;' colspan=4>
-     &nbsp;&nbsp;<input type='submit' value='Execution'>
-   </td></tr>
-   <tr><td bgcolor='#e5ecf9' colspan=4>&nbsp;Answer
-   </td></tr>
-   <tr style='background-color: #ffffff;'><td nowrap valign='top' colspan=4><input size='79' style=' border-style: none;' type='text' id='ans' class='text' value='";
-   print_string result;
-   print_string "'>
-   </td></tr>
-  </table>
- </td></tr>
-</table>
-</form>
-</center>
-<br>
-<div align=right>
-Powered by <a href='http://caml.inria.fr/'><img src='caml.128x58.gif' alt='powered by OCaml' border='0' height='30'/></a>
-and <a href='http://coq.inria.fr/'><img src='barron_logo.png' alt='powered by Coq' border='0' height='40'/></a>.
-</div><br>
-origin <a href='http://keisan.casio.jp/has10/Free.cgi'>�����ٷ׻�������</a><br>
-Free CGI server: <a href='http://0web.cjb.net'>Zero Web Server</a><br>
-
-
-</body>
-</html>
-"
+  print_string html
 let ( @@ ) f x = f x
 let ( $ ) g f x = g (f x)
+let ( +> ) x f = f x
+let id x = x
 
 let slist ?(delim="; ") f l = (String.concat delim @@ List.map f l)
 
     else iter (s.[i]::store) (i-1)
   in
   iter [] (String.length s - 1)
+
+let infile filename f =
+  let ch = open_in filename in
+  try
+    let y = f ch in
+    close_in ch; y
+  with
+  | e -> close_in ch; raise e