src/Pure/Thy/present.ML
changeset 11580 a8409fa3985c
parent 11057 e68becb804fe
child 11856 a35af478aee4
equal deleted inserted replaced
11579:0a2617b311cc 11580:a8409fa3985c
    15 signature PRESENT =
    15 signature PRESENT =
    16 sig
    16 sig
    17   include BASIC_PRESENT
    17   include BASIC_PRESENT
    18   val write_graph: {name: string, ID: string, dir: string, unfold: bool,
    18   val write_graph: {name: string, ID: string, dir: string, unfold: bool,
    19    path: string, parents: string list} list -> Path.T -> unit
    19    path: string, parents: string list} list -> Path.T -> unit
    20   val init: bool -> string -> string list -> string -> Path.T option -> Url.T option * bool -> unit
    20   val init: bool -> string -> string list -> string -> Path.T option
       
    21     -> Url.T option * bool -> bool -> unit
    21   val finish: unit -> unit
    22   val finish: unit -> unit
    22   val init_theory: string -> unit
    23   val init_theory: string -> unit
    23   val verbatim_source: string -> (unit -> Symbol.symbol list) -> unit
    24   val verbatim_source: string -> (unit -> Symbol.symbol list) -> unit
    24   val old_symbol_source: string -> (unit -> Symbol.symbol list) -> unit
    25   val old_symbol_source: string -> (unit -> Symbol.symbol list) -> unit
    25   val theory_output: string -> string -> unit
    26   val theory_output: string -> string -> unit
   202 
   203 
   203 (* session_info *)
   204 (* session_info *)
   204 
   205 
   205 type session_info =
   206 type session_info =
   206   {name: string, parent: string, session: string, path: string list, html_prefix: Path.T,
   207   {name: string, parent: string, session: string, path: string list, html_prefix: Path.T,
   207     doc_format: string, doc_prefixes: (Path.T * Path.T option) option, remote_path: Url.T option};
   208     doc_format: string, doc_prefixes: (Path.T * Path.T option) option,
       
   209     remote_path: Url.T option, verbose: bool};
   208 
   210 
   209 fun make_session_info
   211 fun make_session_info
   210     (name, parent, session, path, html_prefix, doc_format, doc_prefixes, remote_path) =
   212     (name, parent, session, path, html_prefix, doc_format, doc_prefixes, remote_path, verbose) =
   211   {name = name, parent = parent, session = session, path = path, html_prefix = html_prefix,
   213   {name = name, parent = parent, session = session, path = path, html_prefix = html_prefix,
   212     doc_format = doc_format, doc_prefixes = doc_prefixes, remote_path = remote_path}: session_info;
   214     doc_format = doc_format, doc_prefixes = doc_prefixes, remote_path = remote_path,
       
   215     verbose = verbose}: session_info;
   213 
   216 
   214 
   217 
   215 (* state *)
   218 (* state *)
   216 
   219 
   217 val session_info = ref (None: session_info option);
   220 val session_info = ref (None: session_info option);
   259   (File.mkdir path2;
   262   (File.mkdir path2;
   260    File.system_command  (*FIXME: quote paths!?*)
   263    File.system_command  (*FIXME: quote paths!?*)
   261      ("cp " ^ File.sysify_path path1 ^ " " ^ File.sysify_path path2));
   264      ("cp " ^ File.sysify_path path1 ^ " " ^ File.sysify_path path2));
   262 
   265 
   263 
   266 
   264 fun init false _ _ _ _ _ = (browser_info := empty_browser_info; session_info := None)
   267 fun init false _ _ _ _ _ _ = (browser_info := empty_browser_info; session_info := None)
   265   | init true doc path name dump_path (remote_path, first_time) =
   268   | init true doc path name dump_path (remote_path, first_time) verbose =
   266       let
   269       let
   267         val parent_name = name_of_session (Library.take (length path - 1, path));
   270         val parent_name = name_of_session (Library.take (length path - 1, path));
   268         val session_name = name_of_session path;
   271         val session_name = name_of_session path;
   269         val sess_prefix = Path.make path;
   272         val sess_prefix = Path.make path;
   270 
   273 
   304         File.write (Path.append html_prefix session_entries_path) "";
   307         File.write (Path.append html_prefix session_entries_path) "";
   305         if is_some doc_prefixes then File.copy_all doc_path html_prefix else ();
   308         if is_some doc_prefixes then File.copy_all doc_path html_prefix else ();
   306         seq (fn (name, txt) => File.write (Path.append html_prefix (Path.basic name)) txt)
   309         seq (fn (name, txt) => File.write (Path.append html_prefix (Path.basic name)) txt)
   307           (HTML.applet_pages session_name graph_up_lnk);
   310           (HTML.applet_pages session_name graph_up_lnk);
   308         session_info := Some (make_session_info (name, parent_name, session_name, path,
   311         session_info := Some (make_session_info (name, parent_name, session_name, path,
   309           html_prefix, doc, doc_prefixes, remote_path));
   312           html_prefix, doc, doc_prefixes, remote_path, verbose));
   310         browser_info := init_browser_info remote_path path;
   313         browser_info := init_browser_info remote_path path;
   311         add_html_index index_text
   314         add_html_index index_text
   312       end;
   315       end;
   313 
   316 
   314 
   317 
   315 (* finish session *)
   318 (* finish session *)
   316 
   319 
   317 fun isatool_document doc_format doc_prefix =
   320 fun isatool_document verbose doc_format doc_prefix =
   318   let
   321   let
   319     val cmd =
   322     val cmd = "\"$ISATOOL\" document -c -o '" ^ doc_format ^ "' "
   320       "\"$ISATOOL\" document -c -o '" ^ doc_format ^ "' " ^ File.quote_sysify_path doc_prefix;
   323       ^ (if verbose then "-v " else "") ^ File.quote_sysify_path doc_prefix;
   321   in
   324   in
   322     writeln cmd;
   325     writeln cmd;
   323     if system cmd <> 0 orelse not (File.exists (Path.ext doc_format doc_prefix)) then
   326     if system cmd <> 0 orelse not (File.exists (Path.ext doc_format doc_prefix)) then
   324       error "Failed to build document"
   327       error "Failed to build document"
   325     else ()
   328     else ()
   330 fun write_texes src name (path, None) = write_tex src name path
   333 fun write_texes src name (path, None) = write_tex src name path
   331   | write_texes src name (path, Some path') = (write_tex src name path; write_tex src name path');
   334   | write_texes src name (path, Some path') = (write_tex src name path; write_tex src name path');
   332 
   335 
   333 
   336 
   334 fun finish () = with_session ()
   337 fun finish () = with_session ()
   335     (fn {name, html_prefix, doc_format, doc_prefixes, path, ...} =>
   338     (fn {name, html_prefix, doc_format, doc_prefixes, path, verbose, ...} =>
   336   let
   339   let
   337     val {theories, tex_index, html_index, graph} = ! browser_info;
   340     val {theories, tex_index, html_index, graph} = ! browser_info;
   338     val parent_html_prefix = Path.append html_prefix Path.parent;
   341     val parent_html_prefix = Path.append html_prefix Path.parent;
   339 
   342 
   340     fun finish_node (a, {tex_source, html_source = _, html}) =
   343     fun finish_node (a, {tex_source, html_source = _, html}) =
   342       Buffer.write (Path.append html_prefix (html_path a)) (Buffer.add HTML.end_theory html));
   345       Buffer.write (Path.append html_prefix (html_path a)) (Buffer.add HTML.end_theory html));
   343   in
   346   in
   344     seq finish_node (Symtab.dest theories);
   347     seq finish_node (Symtab.dest theories);
   345     Buffer.write (Path.append html_prefix pre_index_path) html_index;
   348     Buffer.write (Path.append html_prefix pre_index_path) html_index;
   346     doc_prefixes |> apsome (write_texes (Buffer.add Latex.tex_trailer tex_index) doc_indexN);
   349     doc_prefixes |> apsome (write_texes (Buffer.add Latex.tex_trailer tex_index) doc_indexN);
   347     doc_prefixes |> apsome (isatool_document doc_format o #1);
   350     doc_prefixes |> apsome (isatool_document verbose doc_format o #1);
   348     write_graph graph (Path.append html_prefix (graph_path "session"));
   351     write_graph graph (Path.append html_prefix (graph_path "session"));
   349     create_index html_prefix;
   352     create_index html_prefix;
   350     if length path > 1 then update_index parent_html_prefix name else ();
   353     if length path > 1 then update_index parent_html_prefix name else ();
   351     browser_info := empty_browser_info;
   354     browser_info := empty_browser_info;
   352     session_info := None
   355     session_info := None