43 |
43 |
44 (** paths **) |
44 (** paths **) |
45 |
45 |
46 val output_path = Path.variable "ISABELLE_BROWSER_INFO"; |
46 val output_path = Path.variable "ISABELLE_BROWSER_INFO"; |
47 |
47 |
48 fun top_path sess_path offset = |
|
49 Path.append (Path.appends (replicate (offset + length sess_path) Path.parent)); |
|
50 |
|
51 val tex_ext = Path.ext "tex"; |
48 val tex_ext = Path.ext "tex"; |
52 val tex_path = tex_ext o Path.basic; |
49 val tex_path = tex_ext o Path.basic; |
53 val html_ext = Path.ext "html"; |
50 val html_ext = Path.ext "html"; |
54 val html_path = html_ext o Path.basic; |
51 val html_path = html_ext o Path.basic; |
55 val graph_path = Path.ext "graph" o Path.basic; |
52 val graph_path = Path.ext "graph" o Path.basic; |
59 |
56 |
60 val session_path = Path.basic ".session"; |
57 val session_path = Path.basic ".session"; |
61 val session_entries_path = Path.unpack ".session/entries"; |
58 val session_entries_path = Path.unpack ".session/entries"; |
62 val pre_index_path = Path.unpack ".session/pre-index"; |
59 val pre_index_path = Path.unpack ".session/pre-index"; |
63 |
60 |
|
61 fun mk_rel_path [] ys = Path.make ys |
|
62 | mk_rel_path xs [] = Path.appends (replicate (length xs) Path.parent) |
|
63 | mk_rel_path (ps as x::xs) (qs as y::ys) = if x=y then mk_rel_path xs ys else |
|
64 Path.appends (replicate (length ps) Path.parent @ [Path.make qs]); |
64 |
65 |
65 |
66 |
66 (** additional theory data **) |
67 (** additional theory data **) |
67 |
68 |
68 structure BrowserInfoArgs = |
69 structure BrowserInfoArgs = |
117 val path' = Path.append (Path.make session) (html_path name) |
118 val path' = Path.append (Path.make session) (html_path name) |
118 in |
119 in |
119 {name = name, ID = ID_of session name, dir = dir_of session, |
120 {name = name, ID = ID_of session name, dir = dir_of session, |
120 path = if null session then "" else |
121 path = if null session then "" else |
121 if is_some remote_path andalso not is_local then |
122 if is_some remote_path andalso not is_local then |
122 Url.pack (Url.append (the remote_path) (Url.file path')) |
123 Url.pack (Url.append (the remote_path) (Url.file |
123 else Path.pack (top_path curr_sess 2 path'), |
124 (Path.append (Path.make session) (html_path name)))) |
|
125 else Path.pack (Path.append |
|
126 (mk_rel_path curr_sess session) (html_path name)), |
124 unfold = unfold andalso (length session = 1), |
127 unfold = unfold andalso (length session = 1), |
125 parents = map (fn s => ID_of (#session (get_info (ThyInfo.theory s))) s) |
128 parents = map (fn s => ID_of (#session (get_info (ThyInfo.theory s))) s) |
126 (ThyInfo.get_preds name)} |
129 (ThyInfo.get_preds name)} |
127 end) (ThyInfo.names ()); |
130 end) (ThyInfo.names ()); |
128 |
131 |
157 |
160 |
158 val empty_browser_info = make_browser_info (Symtab.empty, Buffer.empty, Buffer.empty, [], []); |
161 val empty_browser_info = make_browser_info (Symtab.empty, Buffer.empty, Buffer.empty, [], []); |
159 |
162 |
160 fun initial_browser_info remote_path graph_path curr_sess = make_browser_info |
163 fun initial_browser_info remote_path graph_path curr_sess = make_browser_info |
161 (Symtab.empty, Buffer.empty, Buffer.empty, make_graph remote_path false curr_sess, |
164 (Symtab.empty, Buffer.empty, Buffer.empty, make_graph remote_path false curr_sess, |
162 if_none (try get_graph graph_path) (make_graph remote_path true [""])); |
165 if_none (try get_graph graph_path) (make_graph remote_path true [hd curr_sess])); |
163 |
166 |
164 fun map_browser_info f {theories, tex_index, html_index, graph, all_graph} = |
167 fun map_browser_info f {theories, tex_index, html_index, graph, all_graph} = |
165 make_browser_info (f (theories, tex_index, html_index, graph, all_graph)); |
168 make_browser_info (f (theories, tex_index, html_index, graph, all_graph)); |
166 |
169 |
167 |
170 |
216 |
219 |
217 (* session_info *) |
220 (* session_info *) |
218 |
221 |
219 type session_info = |
222 type session_info = |
220 {name: string, parent: string, session: string, path: string list, html_prefix: Path.T, |
223 {name: string, parent: string, session: string, path: string list, html_prefix: Path.T, |
221 doc_format: string, doc_prefixes: (Path.T * Path.T option) option, graph_path: Path.T, |
224 doc_format: string, doc_prefixes: (Path.T * Path.T option) option, |
222 all_graph_path: Path.T, remote_path: Url.T option}; |
225 all_graph_path: Path.T, remote_path: Url.T option}; |
223 |
226 |
224 fun make_session_info (name, parent, session, path, html_prefix, doc_format, doc_prefixes, |
227 fun make_session_info (name, parent, session, path, html_prefix, doc_format, doc_prefixes, |
225 graph_path, all_graph_path, remote_path) = |
228 all_graph_path, remote_path) = |
226 {name = name, parent = parent, session = session, path = path, html_prefix = html_prefix, |
229 {name = name, parent = parent, session = session, path = path, html_prefix = html_prefix, |
227 doc_format = doc_format, doc_prefixes = doc_prefixes, graph_path = graph_path, |
230 doc_format = doc_format, doc_prefixes = doc_prefixes, |
228 all_graph_path = all_graph_path, remote_path = remote_path}: session_info; |
231 all_graph_path = all_graph_path, remote_path = remote_path}: session_info; |
229 |
232 |
230 |
233 |
231 (* state *) |
234 (* state *) |
232 |
235 |
268 fun name_of_session elems = space_implode "/" ("Isabelle" :: elems); |
271 fun name_of_session elems = space_implode "/" ("Isabelle" :: elems); |
269 |
272 |
270 fun could_copy inpath outpath = |
273 fun could_copy inpath outpath = |
271 if File.exists inpath then (File.copy inpath outpath; true) |
274 if File.exists inpath then (File.copy inpath outpath; true) |
272 else false; |
275 else false; |
|
276 |
|
277 fun copy_files path1 path2 = |
|
278 (File.mkdir path2; |
|
279 File.system_command |
|
280 ("cp " ^ File.sysify_path path1 ^ " " ^ File.sysify_path path2)); |
273 |
281 |
274 fun init false _ _ _ _ _ = (browser_info := empty_browser_info; session_info := None) |
282 fun init false _ _ _ _ _ = (browser_info := empty_browser_info; session_info := None) |
275 | init true doc path name dump_path (remote_path, first_time) = |
283 | init true doc path name dump_path (remote_path, first_time) = |
276 let |
284 let |
277 val parent_name = name_of_session (take (length path - 1, path)); |
285 val parent_name = name_of_session (take (length path - 1, path)); |
283 |
291 |
284 val (doc_prefixes, document_path) = |
292 val (doc_prefixes, document_path) = |
285 if doc = "" then (None, None) |
293 if doc = "" then (None, None) |
286 else (Some (Path.append html_prefix doc_path, dump_path), Some (Path.ext doc doc_path)); |
294 else (Some (Path.append html_prefix doc_path, dump_path), Some (Path.ext doc doc_path)); |
287 |
295 |
288 val graph_prefix = Path.appends [out_path, Path.unpack "graph/data", sess_prefix]; |
296 val graph_up_lnk = (Url.file index_path, session_name); |
289 val graph_path = Path.append graph_prefix (Path.basic "session.graph"); |
297 val all_graph_path = Path.appends [out_path, |
290 val graph_lnk = Url.file (top_path path 0 (Path.appends |
298 Path.basic (hd path), graph_path "all_sessions"]; |
291 [Path.unpack "graph/data", sess_prefix, Path.basic "medium.html"])); |
299 |
292 val graph_up_lnk = |
300 val _ = |
293 (Url.file (top_path path 2 (Path.append sess_prefix index_path)), session_name); |
301 (copy_files (Path.unpack "~~/lib/browser/awtUtilities/*.class") |
294 val codebase = Url.file (top_path path 1 Path.current); |
302 (Path.append html_prefix (Path.basic "awtUtilities")); |
295 val all_graph_path = Path.appends [out_path, Path.unpack "graph/data", |
303 copy_files (Path.unpack "~~/lib/browser/GraphBrowser/*.class") |
296 Path.basic (hd path), Path.basic "all_sessions.graph"]; |
304 (Path.append html_prefix (Path.basic "GraphBrowser"))); |
297 |
|
298 val _ = (File.mkdir html_prefix; File.mkdir graph_prefix); |
|
299 |
305 |
300 fun prep_readme readme = |
306 fun prep_readme readme = |
301 let val readme_path = Path.basic readme in |
307 let val readme_path = Path.basic readme in |
302 if could_copy readme_path (Path.append html_prefix readme_path) then Some readme_path |
308 if could_copy readme_path (Path.append html_prefix readme_path) then Some readme_path |
303 else None |
309 else None |
310 Url.append (the remote_path) (Url.file (Path.append sess_prefix parent_index_path)) |
316 Url.append (the remote_path) (Url.file (Path.append sess_prefix parent_index_path)) |
311 else Url.file parent_index_path; |
317 else Url.file parent_index_path; |
312 |
318 |
313 val index_text = HTML.begin_index (index_up_lnk, parent_name) |
319 val index_text = HTML.begin_index (index_up_lnk, parent_name) |
314 (Url.file index_path, session_name) (apsome Url.file opt_readme) |
320 (Url.file index_path, session_name) (apsome Url.file opt_readme) |
315 (apsome Url.file document_path) graph_lnk; |
321 (apsome Url.file document_path) (Url.unpack "medium.html"); |
316 in |
322 in |
317 File.mkdir (Path.append html_prefix session_path); |
323 File.mkdir (Path.append html_prefix session_path); |
318 File.write (Path.append html_prefix session_entries_path) ""; |
324 File.write (Path.append html_prefix session_entries_path) ""; |
319 if is_some doc_prefixes then File.copy_all doc_path html_prefix else (); |
325 if is_some doc_prefixes then File.copy_all doc_path html_prefix else (); |
320 seq (fn (name, txt) => File.write (Path.append graph_prefix (Path.basic name)) txt) |
326 seq (fn (name, txt) => File.write (Path.append html_prefix (Path.basic name)) txt) |
321 (HTML.applet_pages session_name codebase graph_up_lnk (length path = 1)); |
327 (HTML.applet_pages session_name graph_up_lnk (length path = 1)); |
322 session_info := Some (make_session_info (name, parent_name, session_name, path, |
328 session_info := Some (make_session_info (name, parent_name, session_name, path, |
323 html_prefix, doc, doc_prefixes, graph_path, all_graph_path, remote_path)); |
329 html_prefix, doc, doc_prefixes, all_graph_path, remote_path)); |
324 browser_info := initial_browser_info remote_path all_graph_path path; |
330 browser_info := initial_browser_info remote_path all_graph_path path; |
325 add_html_index index_text |
331 add_html_index index_text |
326 end; |
332 end; |
327 |
333 |
328 |
334 |
343 fun write_texes src name (path, None) = write_tex src name path |
349 fun write_texes src name (path, None) = write_tex src name path |
344 | write_texes src name (path, Some path') = (write_tex src name path; write_tex src name path'); |
350 | write_texes src name (path, Some path') = (write_tex src name path; write_tex src name path'); |
345 |
351 |
346 |
352 |
347 fun finish () = with_session () |
353 fun finish () = with_session () |
348 (fn {name, html_prefix, doc_format, doc_prefixes, graph_path, all_graph_path, path, ...} => |
354 (fn {name, html_prefix, doc_format, doc_prefixes, all_graph_path, path, ...} => |
349 let |
355 let |
350 val {theories, tex_index, html_index, graph, all_graph} = ! browser_info; |
356 val {theories, tex_index, html_index, graph, all_graph} = ! browser_info; |
351 |
357 |
352 fun finish_node (a, {tex_source, html_source = _, html}) = |
358 fun finish_node (a, {tex_source, html_source = _, html}) = |
353 (doc_prefixes |> apsome (write_texes tex_source a); |
359 (doc_prefixes |> apsome (write_texes tex_source a); |
355 in |
361 in |
356 seq finish_node (Symtab.dest theories); |
362 seq finish_node (Symtab.dest theories); |
357 Buffer.write (Path.append html_prefix pre_index_path) html_index; |
363 Buffer.write (Path.append html_prefix pre_index_path) html_index; |
358 doc_prefixes |> apsome (write_texes tex_index doc_indexN); |
364 doc_prefixes |> apsome (write_texes tex_index doc_indexN); |
359 doc_prefixes |> apsome (isatool_document doc_format o #1); |
365 doc_prefixes |> apsome (isatool_document doc_format o #1); |
360 put_graph graph graph_path; |
366 put_graph graph (Path.append html_prefix (graph_path "session")); |
361 put_graph all_graph all_graph_path; |
367 put_graph all_graph all_graph_path; |
362 create_index html_prefix; |
368 create_index html_prefix; |
363 update_index (Path.append html_prefix Path.parent) name; |
369 update_index (Path.append html_prefix Path.parent) name; |
364 browser_info := empty_browser_info; |
370 browser_info := empty_browser_info; |
365 session_info := None |
371 session_info := None |
386 fun token_source name mk_toks = |
392 fun token_source name mk_toks = |
387 with_session () (fn _ => add_tex_source name (Latex.token_source (mk_toks ()))); |
393 with_session () (fn _ => add_tex_source name (Latex.token_source (mk_toks ()))); |
388 |
394 |
389 |
395 |
390 fun parent_link remote_path curr_session name = |
396 fun parent_link remote_path curr_session name = |
391 let |
397 let val {session, is_local} = get_info (ThyInfo.theory name) |
392 val {session, is_local} = get_info (ThyInfo.theory name); |
|
393 val path = Path.append (Path.make session) (html_path name) |
|
394 in (if null session then None else |
398 in (if null session then None else |
395 Some (if is_some remote_path andalso not is_local then |
399 Some (if is_some remote_path andalso not is_local then |
396 Url.append (the remote_path) (Url.file path) |
400 Url.append (the remote_path) (Url.file |
397 else Url.file (top_path curr_session 0 path)), name) |
401 (Path.append (Path.make session) (html_path name))) |
|
402 else Url.file (Path.append (mk_rel_path curr_session session) |
|
403 (html_path name))), name) |
398 end; |
404 end; |
399 |
405 |
400 fun begin_theory name raw_parents orig_files thy = |
406 fun begin_theory name raw_parents orig_files thy = |
401 with_session thy (fn {session, path, html_prefix, remote_path, ...} => |
407 with_session thy (fn {session, path, html_prefix, remote_path, ...} => |
402 let |
408 let |
427 name parents files_html (Buffer.content html_source) |
433 name parents files_html (Buffer.content html_source) |
428 in (tex_source, Buffer.empty, Buffer.add txt html) end; |
434 in (tex_source, Buffer.empty, Buffer.add txt html) end; |
429 |
435 |
430 fun make_entry unfold all = |
436 fun make_entry unfold all = |
431 {name = name, ID = ID_of path name, dir = dir_of path, unfold = unfold, |
437 {name = name, ID = ID_of path name, dir = dir_of path, unfold = unfold, |
432 path = Path.pack (top_path (if all then [""] else path) 2 |
438 path = Path.pack (Path.append |
433 (Path.append (Path.make path) (html_path name))), |
439 (mk_rel_path (if all then [hd path] else path) path) (html_path name)), |
434 parents = map (fn s => ID_of (#session (get_info (ThyInfo.theory s))) s) raw_parents}; |
440 parents = map (fn s => ID_of (#session (get_info (ThyInfo.theory s))) s) raw_parents}; |
435 |
441 |
436 in |
442 in |
437 change_theory_info name prep_html_source; |
443 change_theory_info name prep_html_source; |
438 add_all_graph_entry (make_entry (length path = 1) true); |
444 add_all_graph_entry (make_entry (length path = 1) true); |