src/Pure/Thy/thy_read.ML
changeset 1323 ae24fa249266
parent 1320 b94ef890dbf2
child 1332 a60d1abb06c0
equal deleted inserted replaced
1322:9b3d3362a048 1323:ae24fa249266
   387 
   387 
   388                   (*Make a HTML link out of a theory name*)
   388                   (*Make a HTML link out of a theory name*)
   389                   fun make_link t =
   389                   fun make_link t =
   390                     let val path = path_of t;
   390                     let val path = path_of t;
   391                     in "<A HREF = \"" ^
   391                     in "<A HREF = \"" ^
   392                        tack_on (relative_path tpath path) t ^
   392                        tack_on (relative_path tpath path) ("." ^ t) ^
   393                        ".html\">" ^ t ^ "</A>" end;
   393                        ".html\">" ^ t ^ "</A>" end;
   394               in if not (id mem theories) then (result, implode l)
   394               in if not (id mem theories) then (result, implode l)
   395                  else if id mem thy_files then
   395                  else if id mem thy_files then
   396                    make_links rest (result ^ implode pre ^ make_link id)
   396                    make_links rest (result ^ implode pre ^ make_link id)
   397                  else make_links rest (result ^ implode pre ^ id)
   397                  else make_links rest (result ^ implode pre ^ id)
   415          ".ML\">" ^ tname ^ ".ML</A>:</H2>\n"
   415          ".ML\">" ^ tname ^ ".ML</A>:</H2>\n"
   416       end;
   416       end;
   417 
   417 
   418     (** Make chart of super-theories **)
   418     (** Make chart of super-theories **)
   419 
   419 
   420     val sup_out = open_out (tack_on tpath tname ^ "_sup.html");
   420     val sup_out = open_out (tack_on tpath ("." ^ tname ^ "_sup.html"));
   421     val sub_out = open_out (tack_on tpath tname ^ "_sub.html");
   421     val sub_out = open_out (tack_on tpath ("." ^ tname ^ "_sub.html"));
   422 
   422 
   423     (*Theories that already have been listed in this chart*)
   423     (*Theories that already have been listed in this chart*)
   424     val listed = ref [];
   424     val listed = ref [];
   425 
   425 
   426     val wanted_theories =
   426     val wanted_theories =
   445                 | mk_offset (l::ls) cur =
   445                 | mk_offset (l::ls) cur =
   446                     implode (replicate (l - cur) "    ") ^ "|   " ^
   446                     implode (replicate (l - cur) "    ") ^ "|   " ^
   447                     mk_offset ls (l+1);
   447                     mk_offset ls (l+1);
   448             in output (sup_out,
   448             in output (sup_out,
   449                  " " ^ mk_offset continued 0 ^
   449                  " " ^ mk_offset continued 0 ^
   450                  "\\__" ^ (if is_pure then t else "<A HREF=\"" ^ 
   450                  "\\__" ^ (if is_pure then t else
   451                              tack_on rel_path t ^ ".html\">" ^ t ^ "</A>") ^
   451                              "<A HREF=\"" ^ tack_on rel_path ("." ^ t) ^
       
   452                              ".html\">" ^ t ^ "</A>") ^
   452                  (if repeated then "..." else " ") ^
   453                  (if repeated then "..." else " ") ^
   453                  "<A HREF = \"" ^ tack_on rel_path t ^
   454                  "<A HREF = \"" ^ tack_on rel_path ("." ^ t) ^
   454                  "_sub.html\"><IMG ALIGN=BOTTOM BORDER=0 SRC = \"" ^
   455                  "_sub.html\"><IMG ALIGN=BOTTOM BORDER=0 SRC = \"" ^
   455                  tack_on gif_path "red_arrow.gif\" ALT = \\/></A>" ^
   456                  tack_on gif_path "red_arrow.gif\" ALT = \\/></A>" ^
   456                  (if is_pure then ""
   457                  (if is_pure then ""
   457                   else "<A HREF = \"" ^ tack_on rel_path t ^
   458                   else "<A HREF = \"" ^ tack_on rel_path ("." ^ t) ^
   458                        "_sup.html\"><IMG ALIGN=BOTTOM BORDER=0 SRC = \"" ^
   459                        "_sup.html\"><IMG ALIGN=BOTTOM BORDER=0 SRC = \"" ^
   459                        tack_on gif_path "blue_arrow.gif\
   460                        tack_on gif_path "blue_arrow.gif\
   460                        \\" ALT = /\\></A>") ^
   461                        \\" ALT = /\\></A>") ^
   461                  "\n");
   462                  "\n");
   462               if repeated then ()
   463               if repeated then ()
   468 
   469 
   469         val relatives =
   470         val relatives =
   470           filter (fn s => s mem wanted_theories) (parents_of tname);
   471           filter (fn s => s mem wanted_theories) (parents_of tname);
   471       in mk_entry relatives end;
   472       in mk_entry relatives end;
   472   in if is_some (!cur_htmlfile) then
   473   in if is_some (!cur_htmlfile) then
   473        error "thyfile2html: Last theory's HTML has not been closed."
   474        error "thyfile2html: Last theory's HTML file has not been closed."
   474      else ();
   475      else ();
   475      cur_htmlfile := Some (open_out (tack_on tpath tname ^ ".html"));
   476      cur_htmlfile := Some (open_out (tack_on tpath ("." ^ tname ^ ".html")));
   476      output (the (!cur_htmlfile), gettext (tack_on tpath tname ^ ".thy"));
   477      output (the (!cur_htmlfile), gettext (tack_on tpath tname ^ ".thy"));
   477 
   478 
   478      mk_charthead sup_out tname "Ancestors" true gif_path index_path package;
   479      mk_charthead sup_out tname "Ancestors" true gif_path index_path package;
   479      output(sup_out,
   480      output(sup_out,
   480        "<A HREF=\"" ^ tname ^ ".html\">" ^ tname ^ "</A> \
   481        "<A HREF=\"." ^ tname ^ ".html\">" ^ tname ^ "</A> \
   481        \<A HREF = \"" ^ tname ^
   482        \<A HREF = \"." ^ tname ^
   482        "_sub.html\"><IMG ALIGN=BOTTOM BORDER=0 SRC = \"" ^
   483        "_sub.html\"><IMG ALIGN=BOTTOM BORDER=0 SRC = \"" ^
   483        tack_on gif_path "red_arrow.gif\" ALT = \\/></A>\n");
   484        tack_on gif_path "red_arrow.gif\" ALT = \\/></A>\n");
   484      list_ancestors tname 0 [];
   485      list_ancestors tname 0 [];
   485      output (sup_out, "</PRE><HR></BODY></HTML>");
   486      output (sup_out, "</PRE><HR></BODY></HTML>");
   486      close_out sup_out;
   487      close_out sup_out;
   487 
   488 
   488      mk_charthead sub_out tname "Children" false gif_path index_path package;
   489      mk_charthead sub_out tname "Children" false gif_path index_path package;
   489      output(sub_out,
   490      output(sub_out,
   490        "<A HREF=\"" ^ tname ^ ".html\">" ^ tname ^ "</A> \
   491        "<A HREF=\"." ^ tname ^ ".html\">" ^ tname ^ "</A> \
   491        \<A HREF = \"" ^ tname ^ "_sup.html\"><IMG SRC = \"" ^
   492        \<A HREF = \"." ^ tname ^ "_sup.html\"><IMG SRC = \"" ^
   492        tack_on gif_path "blue_arrow.gif\" BORDER=0 ALT = \\/></A>\n");
   493        tack_on gif_path "blue_arrow.gif\" BORDER=0 ALT = \\/></A>\n");
   493      close_out sub_out
   494      close_out sub_out
   494   end;
   495   end;
   495 
   496 
   496 
   497 
   593            let val is_pure = t = "Pure" orelse t = "CPure";
   594            let val is_pure = t = "Pure" orelse t = "CPure";
   594                val path = if is_pure then (!index_path) else path_of t;
   595                val path = if is_pure then (!index_path) else path_of t;
   595 
   596 
   596                val gif_path = relative_path path (!gif_path);
   597                val gif_path = relative_path path (!gif_path);
   597                val rel_path = relative_path path abs_path;
   598                val rel_path = relative_path path abs_path;
   598 
   599                val tpath = tack_on rel_path ("." ^ tname);
   599                val out = open_append (tack_on path t ^ "_sub.html");
   600 
       
   601                val out = open_append (tack_on path ("." ^ t ^ "_sub.html"));
   600            in output (out,
   602            in output (out,
   601                 " |\n \\__<A HREF=\"" ^ tack_on rel_path tname ^ ".html\">" ^
   603                 " |\n \\__<A HREF=\"" ^
   602                 tname ^ "</A> <A HREF = \"" ^
   604                 tack_on rel_path ("." ^ tname) ^ ".html\">" ^ tname ^
   603                 tack_on rel_path tname ^
   605                 "</A> <A HREF = \"" ^ tpath ^ "_sub.html\">\
   604                 "_sub.html\"><IMG ALIGN=BOTTOM BORDER=0 SRC = \"" ^
   606                 \<IMG ALIGN=BOTTOM BORDER=0 SRC = \"" ^
   605                 tack_on gif_path "red_arrow.gif\" ALT = \\/></A>\
   607                 tack_on gif_path "red_arrow.gif\" ALT = \\/></A>\
   606                 \<A HREF = \"" ^ tack_on rel_path tname ^ "_sup.html\">\
   608                 \<A HREF = \"" ^ tpath ^ "_sup.html\">\
   607                 \<IMG ALIGN=BOTTOM BORDER=0 SRC = \"" ^
   609                 \<IMG ALIGN=BOTTOM BORDER=0 SRC = \"" ^
   608                 tack_on gif_path "blue_arrow.gif\" ALT = /\\></A>\n");
   610                 tack_on gif_path "blue_arrow.gif\" ALT = /\\></A>\n");
   609               close_out out
   611               close_out out
   610            end;
   612            end;
   611 
   613 
   612          val theory_list =
   614          val theory_list =
   613            open_append (tack_on (!index_path) "theory_list.txt");
   615            open_append (tack_on (!index_path) ".theory_list.txt");
   614      in output (theory_list, tname ^ " " ^ abs_path ^ "\n");
   616      in output (theory_list, tname ^ " " ^ abs_path ^ "\n");
   615         close_out theory_list;
   617         close_out theory_list;
   616 
   618 
   617         seq add_to_parents new_parents
   619         seq add_to_parents new_parents
   618      end
   620      end
   996 
   998 
   997 (* Misc HTML functions *)
   999 (* Misc HTML functions *)
   998 
  1000 
   999 (*Init HTML generator by setting paths and creating new files*)
  1001 (*Init HTML generator by setting paths and creating new files*)
  1000 fun init_html () =
  1002 fun init_html () =
  1001   let val pure_out = open_out "Pure_sub.html";
  1003   let val pure_out = open_out ".Pure_sub.html";
  1002       val cpure_out = open_out "CPure_sub.html";
  1004       val cpure_out = open_out ".CPure_sub.html";
  1003       val theory_list = close_out (open_out "theory_list.txt");
  1005       val theory_list = close_out (open_out ".theory_list.txt");
  1004 
  1006 
  1005       val rel_gif_path = relative_path (pwd ()) (!gif_path);
  1007       val rel_gif_path = relative_path (pwd ()) (!gif_path);
  1006       val package = hd (rev (space_explode "/" (pwd ())));
  1008       val package = hd (rev (space_explode "/" (pwd ())));
  1007   in make_html := true;
  1009   in make_html := true;
  1008      index_path := pwd();
  1010      index_path := pwd();
  1017      close_out cpure_out
  1019      close_out cpure_out
  1018   end;
  1020   end;
  1019 
  1021 
  1020 (*Generate index.html*)
  1022 (*Generate index.html*)
  1021 fun make_chart () = if not (!make_html) then () else
  1023 fun make_chart () = if not (!make_html) then () else
  1022   let val theory_list = open_in (tack_on (!index_path) "theory_list.txt");
  1024   let val theory_list = open_in (tack_on (!index_path) ".theory_list.txt");
  1023       val theories = space_explode "\n" (input (theory_list, 999999));
  1025       val theories = space_explode "\n" (input (theory_list, 999999));
  1024       val dummy = close_in theory_list;
  1026       val dummy = close_in theory_list;
  1025 
  1027 
  1026       (*Path to Isabelle's main directory = $gif_path/.. *)
  1028       (*Path to Isabelle's main directory = $gif_path/.. *)
  1027       val base_path = "/" ^
  1029       val base_path = "/" ^
  1037               val (name, path) = take_prefix (not_equal " ") (explode t);
  1039               val (name, path) = take_prefix (not_equal " ") (explode t);
  1038 
  1040 
  1039               val tname = implode name
  1041               val tname = implode name
  1040               val tpath =
  1042               val tpath =
  1041                 tack_on (relative_path (!index_path) (implode (tl path)))
  1043                 tack_on (relative_path (!index_path) (implode (tl path)))
  1042                         tname;
  1044                         ("." ^ tname);
  1043               val subdir = space_explode "/"
  1045               val subdir = space_explode "/"
  1044                                  (relative_path base_path (implode (tl path)));
  1046                                  (relative_path base_path (implode (tl path)));
  1045               val level_diff = length subdir - length curdir;
  1047               val level_diff = length subdir - length curdir;
  1046             in "\n" ^
  1048             in "\n" ^
  1047                (if subdir <> curdir then
  1049                (if subdir <> curdir then