src/Pure/Thy/browser_info.ML
author wenzelm
Thu, 11 Mar 1999 12:34:10 +0100
changeset 6348 fdcbeaddd5fc
parent 6342 13424bbc2d8b
child 6351 74763258b78b
permissions -rw-r--r--
include 'README'; tuned;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6330
e1faf0f6f2b8 checkpoint -- basic functionality only;
wenzelm
parents: 4706
diff changeset
     1
(*  Title:      Pure/Thy/browser_info.ML
3603
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
     2
    ID:         $Id$
6330
e1faf0f6f2b8 checkpoint -- basic functionality only;
wenzelm
parents: 4706
diff changeset
     3
    Author:     Stefan Berghofer and Markus Wenzel, TU Muenchen
e1faf0f6f2b8 checkpoint -- basic functionality only;
wenzelm
parents: 4706
diff changeset
     4
e1faf0f6f2b8 checkpoint -- basic functionality only;
wenzelm
parents: 4706
diff changeset
     5
Theory browsing information (HTML and graph files).
e1faf0f6f2b8 checkpoint -- basic functionality only;
wenzelm
parents: 4706
diff changeset
     6
e1faf0f6f2b8 checkpoint -- basic functionality only;
wenzelm
parents: 4706
diff changeset
     7
TODO:
6339
b995ab768117 maintain current/parent index;
wenzelm
parents: 6330
diff changeset
     8
  - href parent theories (this vs. ancestor session!?);
6342
13424bbc2d8b report session path;
wenzelm
parents: 6339
diff changeset
     9
  - usedir: exclude arrow gifs;
6330
e1faf0f6f2b8 checkpoint -- basic functionality only;
wenzelm
parents: 4706
diff changeset
    10
  - symlink ".parent", ".top" (URLs!?);
e1faf0f6f2b8 checkpoint -- basic functionality only;
wenzelm
parents: 4706
diff changeset
    11
*)
3603
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
    12
6330
e1faf0f6f2b8 checkpoint -- basic functionality only;
wenzelm
parents: 4706
diff changeset
    13
signature BASIC_BROWSER_INFO =
e1faf0f6f2b8 checkpoint -- basic functionality only;
wenzelm
parents: 4706
diff changeset
    14
sig
e1faf0f6f2b8 checkpoint -- basic functionality only;
wenzelm
parents: 4706
diff changeset
    15
  val section: string -> unit
e1faf0f6f2b8 checkpoint -- basic functionality only;
wenzelm
parents: 4706
diff changeset
    16
end;
3870
6913700d7c79 Added ack to Mateja Jamnik.
nipkow
parents: 3868
diff changeset
    17
6330
e1faf0f6f2b8 checkpoint -- basic functionality only;
wenzelm
parents: 4706
diff changeset
    18
signature BROWSER_INFO =
e1faf0f6f2b8 checkpoint -- basic functionality only;
wenzelm
parents: 4706
diff changeset
    19
sig
e1faf0f6f2b8 checkpoint -- basic functionality only;
wenzelm
parents: 4706
diff changeset
    20
  include BASIC_BROWSER_INFO
6342
13424bbc2d8b report session path;
wenzelm
parents: 6339
diff changeset
    21
  val init: bool -> string list -> string -> unit
6330
e1faf0f6f2b8 checkpoint -- basic functionality only;
wenzelm
parents: 4706
diff changeset
    22
  val finish: unit -> unit
e1faf0f6f2b8 checkpoint -- basic functionality only;
wenzelm
parents: 4706
diff changeset
    23
  val theory_source: string -> (string, 'a) Source.source -> unit
e1faf0f6f2b8 checkpoint -- basic functionality only;
wenzelm
parents: 4706
diff changeset
    24
  val begin_theory: string -> string list -> (Path.T * bool) list -> unit
e1faf0f6f2b8 checkpoint -- basic functionality only;
wenzelm
parents: 4706
diff changeset
    25
  val end_theory: string -> unit
e1faf0f6f2b8 checkpoint -- basic functionality only;
wenzelm
parents: 4706
diff changeset
    26
  val theorem: string -> thm -> unit
e1faf0f6f2b8 checkpoint -- basic functionality only;
wenzelm
parents: 4706
diff changeset
    27
end;
e1faf0f6f2b8 checkpoint -- basic functionality only;
wenzelm
parents: 4706
diff changeset
    28
e1faf0f6f2b8 checkpoint -- basic functionality only;
wenzelm
parents: 4706
diff changeset
    29
structure BrowserInfo: BROWSER_INFO =
e1faf0f6f2b8 checkpoint -- basic functionality only;
wenzelm
parents: 4706
diff changeset
    30
struct
3603
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
    31
4215
7f7519759b8c moved old file stuff from library.ML to Thy/browser_info.ML;
wenzelm
parents: 3976
diff changeset
    32
6330
e1faf0f6f2b8 checkpoint -- basic functionality only;
wenzelm
parents: 4706
diff changeset
    33
(** global browser info state **)
e1faf0f6f2b8 checkpoint -- basic functionality only;
wenzelm
parents: 4706
diff changeset
    34
e1faf0f6f2b8 checkpoint -- basic functionality only;
wenzelm
parents: 4706
diff changeset
    35
(* type theory_info *)
e1faf0f6f2b8 checkpoint -- basic functionality only;
wenzelm
parents: 4706
diff changeset
    36
e1faf0f6f2b8 checkpoint -- basic functionality only;
wenzelm
parents: 4706
diff changeset
    37
type theory_info = {source: Buffer.T, html: Buffer.T, graph: Buffer.T};
4215
7f7519759b8c moved old file stuff from library.ML to Thy/browser_info.ML;
wenzelm
parents: 3976
diff changeset
    38
6330
e1faf0f6f2b8 checkpoint -- basic functionality only;
wenzelm
parents: 4706
diff changeset
    39
fun make_theory_info (source, html, graph) =
e1faf0f6f2b8 checkpoint -- basic functionality only;
wenzelm
parents: 4706
diff changeset
    40
  {source = source, html = html, graph = graph}: theory_info;
e1faf0f6f2b8 checkpoint -- basic functionality only;
wenzelm
parents: 4706
diff changeset
    41
e1faf0f6f2b8 checkpoint -- basic functionality only;
wenzelm
parents: 4706
diff changeset
    42
val empty_theory_info = make_theory_info (Buffer.empty, Buffer.empty, Buffer.empty);
e1faf0f6f2b8 checkpoint -- basic functionality only;
wenzelm
parents: 4706
diff changeset
    43
fun map_theory_info f {source, html, graph} = make_theory_info (f (source, html, graph));
4215
7f7519759b8c moved old file stuff from library.ML to Thy/browser_info.ML;
wenzelm
parents: 3976
diff changeset
    44
7f7519759b8c moved old file stuff from library.ML to Thy/browser_info.ML;
wenzelm
parents: 3976
diff changeset
    45
6330
e1faf0f6f2b8 checkpoint -- basic functionality only;
wenzelm
parents: 4706
diff changeset
    46
(* type browser_info *)
e1faf0f6f2b8 checkpoint -- basic functionality only;
wenzelm
parents: 4706
diff changeset
    47
e1faf0f6f2b8 checkpoint -- basic functionality only;
wenzelm
parents: 4706
diff changeset
    48
type browser_info = {theories: theory_info Symtab.table, index: Buffer.T};
4215
7f7519759b8c moved old file stuff from library.ML to Thy/browser_info.ML;
wenzelm
parents: 3976
diff changeset
    49
6330
e1faf0f6f2b8 checkpoint -- basic functionality only;
wenzelm
parents: 4706
diff changeset
    50
fun make_browser_info (theories, index) =
e1faf0f6f2b8 checkpoint -- basic functionality only;
wenzelm
parents: 4706
diff changeset
    51
  {theories = theories, index = index}: browser_info;
4215
7f7519759b8c moved old file stuff from library.ML to Thy/browser_info.ML;
wenzelm
parents: 3976
diff changeset
    52
6330
e1faf0f6f2b8 checkpoint -- basic functionality only;
wenzelm
parents: 4706
diff changeset
    53
val empty_browser_info = make_browser_info (Symtab.empty, Buffer.empty);
e1faf0f6f2b8 checkpoint -- basic functionality only;
wenzelm
parents: 4706
diff changeset
    54
fun map_browser_info f {theories, index} = make_browser_info (f (theories, index));
e1faf0f6f2b8 checkpoint -- basic functionality only;
wenzelm
parents: 4706
diff changeset
    55
4215
7f7519759b8c moved old file stuff from library.ML to Thy/browser_info.ML;
wenzelm
parents: 3976
diff changeset
    56
6330
e1faf0f6f2b8 checkpoint -- basic functionality only;
wenzelm
parents: 4706
diff changeset
    57
(* state *)
e1faf0f6f2b8 checkpoint -- basic functionality only;
wenzelm
parents: 4706
diff changeset
    58
e1faf0f6f2b8 checkpoint -- basic functionality only;
wenzelm
parents: 4706
diff changeset
    59
val browser_info = ref empty_browser_info;
e1faf0f6f2b8 checkpoint -- basic functionality only;
wenzelm
parents: 4706
diff changeset
    60
e1faf0f6f2b8 checkpoint -- basic functionality only;
wenzelm
parents: 4706
diff changeset
    61
fun change_browser_info f = browser_info := map_browser_info f (! browser_info);
e1faf0f6f2b8 checkpoint -- basic functionality only;
wenzelm
parents: 4706
diff changeset
    62
e1faf0f6f2b8 checkpoint -- basic functionality only;
wenzelm
parents: 4706
diff changeset
    63
fun init_theory_info name info = change_browser_info (fn (theories, index) =>
e1faf0f6f2b8 checkpoint -- basic functionality only;
wenzelm
parents: 4706
diff changeset
    64
  (Symtab.update ((name, info), theories), index));
4215
7f7519759b8c moved old file stuff from library.ML to Thy/browser_info.ML;
wenzelm
parents: 3976
diff changeset
    65
6330
e1faf0f6f2b8 checkpoint -- basic functionality only;
wenzelm
parents: 4706
diff changeset
    66
fun change_theory_info name f = change_browser_info (fn (theories, index) =>
e1faf0f6f2b8 checkpoint -- basic functionality only;
wenzelm
parents: 4706
diff changeset
    67
  (case Symtab.lookup (theories, name) of
e1faf0f6f2b8 checkpoint -- basic functionality only;
wenzelm
parents: 4706
diff changeset
    68
    None => (warning ("Browser info: cannot access theory document " ^ quote name);
e1faf0f6f2b8 checkpoint -- basic functionality only;
wenzelm
parents: 4706
diff changeset
    69
      (theories, index))
e1faf0f6f2b8 checkpoint -- basic functionality only;
wenzelm
parents: 4706
diff changeset
    70
  | Some info => (Symtab.update ((name, map_theory_info f info), theories), index)));
e1faf0f6f2b8 checkpoint -- basic functionality only;
wenzelm
parents: 4706
diff changeset
    71
4215
7f7519759b8c moved old file stuff from library.ML to Thy/browser_info.ML;
wenzelm
parents: 3976
diff changeset
    72
6339
b995ab768117 maintain current/parent index;
wenzelm
parents: 6330
diff changeset
    73
fun add_index txt = change_browser_info (fn (theories, index) =>
b995ab768117 maintain current/parent index;
wenzelm
parents: 6330
diff changeset
    74
  (theories, Buffer.add txt index));
b995ab768117 maintain current/parent index;
wenzelm
parents: 6330
diff changeset
    75
6330
e1faf0f6f2b8 checkpoint -- basic functionality only;
wenzelm
parents: 4706
diff changeset
    76
fun add_source name txt = change_theory_info name (fn (source, html, graph) =>
e1faf0f6f2b8 checkpoint -- basic functionality only;
wenzelm
parents: 4706
diff changeset
    77
  (Buffer.add txt source, html, graph));
e1faf0f6f2b8 checkpoint -- basic functionality only;
wenzelm
parents: 4706
diff changeset
    78
e1faf0f6f2b8 checkpoint -- basic functionality only;
wenzelm
parents: 4706
diff changeset
    79
fun add_html name txt = change_theory_info name (fn (source, html, graph) =>
e1faf0f6f2b8 checkpoint -- basic functionality only;
wenzelm
parents: 4706
diff changeset
    80
  (source, Buffer.add txt html, graph));
e1faf0f6f2b8 checkpoint -- basic functionality only;
wenzelm
parents: 4706
diff changeset
    81
e1faf0f6f2b8 checkpoint -- basic functionality only;
wenzelm
parents: 4706
diff changeset
    82
fun add_graph name txt = change_theory_info name (fn (source, html, graph) =>
e1faf0f6f2b8 checkpoint -- basic functionality only;
wenzelm
parents: 4706
diff changeset
    83
  (source, html, Buffer.add txt graph));
4215
7f7519759b8c moved old file stuff from library.ML to Thy/browser_info.ML;
wenzelm
parents: 3976
diff changeset
    84
7f7519759b8c moved old file stuff from library.ML to Thy/browser_info.ML;
wenzelm
parents: 3976
diff changeset
    85
7f7519759b8c moved old file stuff from library.ML to Thy/browser_info.ML;
wenzelm
parents: 3976
diff changeset
    86
6330
e1faf0f6f2b8 checkpoint -- basic functionality only;
wenzelm
parents: 4706
diff changeset
    87
(** global session state **)
e1faf0f6f2b8 checkpoint -- basic functionality only;
wenzelm
parents: 4706
diff changeset
    88
e1faf0f6f2b8 checkpoint -- basic functionality only;
wenzelm
parents: 4706
diff changeset
    89
(* paths *)
e1faf0f6f2b8 checkpoint -- basic functionality only;
wenzelm
parents: 4706
diff changeset
    90
e1faf0f6f2b8 checkpoint -- basic functionality only;
wenzelm
parents: 4706
diff changeset
    91
val output_path = Path.variable "ISABELLE_BROWSER_INFO";
e1faf0f6f2b8 checkpoint -- basic functionality only;
wenzelm
parents: 4706
diff changeset
    92
e1faf0f6f2b8 checkpoint -- basic functionality only;
wenzelm
parents: 4706
diff changeset
    93
fun top_path sess_path = Path.append (Path.appends (replicate (length sess_path) Path.parent));
e1faf0f6f2b8 checkpoint -- basic functionality only;
wenzelm
parents: 4706
diff changeset
    94
e1faf0f6f2b8 checkpoint -- basic functionality only;
wenzelm
parents: 4706
diff changeset
    95
val html_ext = Path.ext "html";
e1faf0f6f2b8 checkpoint -- basic functionality only;
wenzelm
parents: 4706
diff changeset
    96
val html_path = html_ext o Path.basic;
e1faf0f6f2b8 checkpoint -- basic functionality only;
wenzelm
parents: 4706
diff changeset
    97
val graph_path = Path.ext "graph" o Path.basic;
e1faf0f6f2b8 checkpoint -- basic functionality only;
wenzelm
parents: 4706
diff changeset
    98
val index_path = Path.basic "index.html";
e1faf0f6f2b8 checkpoint -- basic functionality only;
wenzelm
parents: 4706
diff changeset
    99
6339
b995ab768117 maintain current/parent index;
wenzelm
parents: 6330
diff changeset
   100
val session_path = Path.basic ".session";
b995ab768117 maintain current/parent index;
wenzelm
parents: 6330
diff changeset
   101
val session_entries_path = Path.unpack ".session/entries";
b995ab768117 maintain current/parent index;
wenzelm
parents: 6330
diff changeset
   102
val pre_index_path = Path.unpack ".session/pre-index";
b995ab768117 maintain current/parent index;
wenzelm
parents: 6330
diff changeset
   103
6330
e1faf0f6f2b8 checkpoint -- basic functionality only;
wenzelm
parents: 4706
diff changeset
   104
e1faf0f6f2b8 checkpoint -- basic functionality only;
wenzelm
parents: 4706
diff changeset
   105
(* session_info *)
e1faf0f6f2b8 checkpoint -- basic functionality only;
wenzelm
parents: 4706
diff changeset
   106
e1faf0f6f2b8 checkpoint -- basic functionality only;
wenzelm
parents: 4706
diff changeset
   107
type session_info =
6342
13424bbc2d8b report session path;
wenzelm
parents: 6339
diff changeset
   108
  {name: string, parent: string, session: string, path: string list,
6330
e1faf0f6f2b8 checkpoint -- basic functionality only;
wenzelm
parents: 4706
diff changeset
   109
    html_prefix: Path.T, graph_prefix: Path.T};
e1faf0f6f2b8 checkpoint -- basic functionality only;
wenzelm
parents: 4706
diff changeset
   110
6342
13424bbc2d8b report session path;
wenzelm
parents: 6339
diff changeset
   111
fun make_session_info (name, parent, session, path, html_prefix, graph_prefix) =
13424bbc2d8b report session path;
wenzelm
parents: 6339
diff changeset
   112
  {name = name, parent = parent, session = session, path = path,
6330
e1faf0f6f2b8 checkpoint -- basic functionality only;
wenzelm
parents: 4706
diff changeset
   113
    html_prefix = html_prefix, graph_prefix = graph_prefix}: session_info;
e1faf0f6f2b8 checkpoint -- basic functionality only;
wenzelm
parents: 4706
diff changeset
   114
6348
fdcbeaddd5fc include 'README';
wenzelm
parents: 6342
diff changeset
   115
fdcbeaddd5fc include 'README';
wenzelm
parents: 6342
diff changeset
   116
(* state *)
fdcbeaddd5fc include 'README';
wenzelm
parents: 6342
diff changeset
   117
6330
e1faf0f6f2b8 checkpoint -- basic functionality only;
wenzelm
parents: 4706
diff changeset
   118
val session_info = ref (None: session_info option);
e1faf0f6f2b8 checkpoint -- basic functionality only;
wenzelm
parents: 4706
diff changeset
   119
6348
fdcbeaddd5fc include 'README';
wenzelm
parents: 6342
diff changeset
   120
fun with_session f = (case ! session_info of None => () | Some info => f info);
fdcbeaddd5fc include 'README';
wenzelm
parents: 6342
diff changeset
   121
fun with_context f = f (PureThy.get_name (Context.the_context ()));
fdcbeaddd5fc include 'README';
wenzelm
parents: 6342
diff changeset
   122
6330
e1faf0f6f2b8 checkpoint -- basic functionality only;
wenzelm
parents: 4706
diff changeset
   123
e1faf0f6f2b8 checkpoint -- basic functionality only;
wenzelm
parents: 4706
diff changeset
   124
6339
b995ab768117 maintain current/parent index;
wenzelm
parents: 6330
diff changeset
   125
b995ab768117 maintain current/parent index;
wenzelm
parents: 6330
diff changeset
   126
(** HTML output **)
b995ab768117 maintain current/parent index;
wenzelm
parents: 6330
diff changeset
   127
b995ab768117 maintain current/parent index;
wenzelm
parents: 6330
diff changeset
   128
b995ab768117 maintain current/parent index;
wenzelm
parents: 6330
diff changeset
   129
(* maintain index *)
b995ab768117 maintain current/parent index;
wenzelm
parents: 6330
diff changeset
   130
b995ab768117 maintain current/parent index;
wenzelm
parents: 6330
diff changeset
   131
val session_entries =
b995ab768117 maintain current/parent index;
wenzelm
parents: 6330
diff changeset
   132
  HTML.session_entries o map (fn name => (Path.append (Path.basic name) index_path, name));
b995ab768117 maintain current/parent index;
wenzelm
parents: 6330
diff changeset
   133
b995ab768117 maintain current/parent index;
wenzelm
parents: 6330
diff changeset
   134
fun get_entries dir =
b995ab768117 maintain current/parent index;
wenzelm
parents: 6330
diff changeset
   135
  split_lines (File.read (Path.append dir session_entries_path));
b995ab768117 maintain current/parent index;
wenzelm
parents: 6330
diff changeset
   136
b995ab768117 maintain current/parent index;
wenzelm
parents: 6330
diff changeset
   137
fun put_entries entries dir =
b995ab768117 maintain current/parent index;
wenzelm
parents: 6330
diff changeset
   138
  File.write (Path.append dir session_entries_path) (cat_lines entries);
b995ab768117 maintain current/parent index;
wenzelm
parents: 6330
diff changeset
   139
b995ab768117 maintain current/parent index;
wenzelm
parents: 6330
diff changeset
   140
b995ab768117 maintain current/parent index;
wenzelm
parents: 6330
diff changeset
   141
fun create_index dir =
b995ab768117 maintain current/parent index;
wenzelm
parents: 6330
diff changeset
   142
  File.read (Path.append dir pre_index_path) ^
b995ab768117 maintain current/parent index;
wenzelm
parents: 6330
diff changeset
   143
    session_entries (get_entries dir) ^ HTML.end_index
b995ab768117 maintain current/parent index;
wenzelm
parents: 6330
diff changeset
   144
  |> File.write (Path.append dir index_path);
b995ab768117 maintain current/parent index;
wenzelm
parents: 6330
diff changeset
   145
b995ab768117 maintain current/parent index;
wenzelm
parents: 6330
diff changeset
   146
fun update_index dir name =
b995ab768117 maintain current/parent index;
wenzelm
parents: 6330
diff changeset
   147
  (case try get_entries dir of
6348
fdcbeaddd5fc include 'README';
wenzelm
parents: 6342
diff changeset
   148
    None => warning ("Browser info: cannot access session index in " ^ quote (Path.pack dir))
6339
b995ab768117 maintain current/parent index;
wenzelm
parents: 6330
diff changeset
   149
  | Some es => (put_entries ((es \ name) @ [name]) dir; create_index dir));
6342
13424bbc2d8b report session path;
wenzelm
parents: 6339
diff changeset
   150
6339
b995ab768117 maintain current/parent index;
wenzelm
parents: 6330
diff changeset
   151
6330
e1faf0f6f2b8 checkpoint -- basic functionality only;
wenzelm
parents: 4706
diff changeset
   152
(* init session *)
e1faf0f6f2b8 checkpoint -- basic functionality only;
wenzelm
parents: 4706
diff changeset
   153
6342
13424bbc2d8b report session path;
wenzelm
parents: 6339
diff changeset
   154
fun name_of_session elems = space_implode "/" ("Isabelle" :: elems);
6339
b995ab768117 maintain current/parent index;
wenzelm
parents: 6330
diff changeset
   155
6348
fdcbeaddd5fc include 'README';
wenzelm
parents: 6342
diff changeset
   156
fun could_copy inpath outpath =
fdcbeaddd5fc include 'README';
wenzelm
parents: 6342
diff changeset
   157
  if File.exists inpath then (File.copy inpath outpath; true)
fdcbeaddd5fc include 'README';
wenzelm
parents: 6342
diff changeset
   158
  else false;
fdcbeaddd5fc include 'README';
wenzelm
parents: 6342
diff changeset
   159
6342
13424bbc2d8b report session path;
wenzelm
parents: 6339
diff changeset
   160
fun init false _ _ = (browser_info := empty_browser_info; session_info := None)
13424bbc2d8b report session path;
wenzelm
parents: 6339
diff changeset
   161
  | init true path name =
6330
e1faf0f6f2b8 checkpoint -- basic functionality only;
wenzelm
parents: 4706
diff changeset
   162
      let
6348
fdcbeaddd5fc include 'README';
wenzelm
parents: 6342
diff changeset
   163
        val parent_name = name_of_session (take (length path - 1, path));
6342
13424bbc2d8b report session path;
wenzelm
parents: 6339
diff changeset
   164
        val session_name = name_of_session path;
6339
b995ab768117 maintain current/parent index;
wenzelm
parents: 6330
diff changeset
   165
        val sess_prefix = Path.make path;
6330
e1faf0f6f2b8 checkpoint -- basic functionality only;
wenzelm
parents: 4706
diff changeset
   166
        val out_path = Path.expand output_path;
e1faf0f6f2b8 checkpoint -- basic functionality only;
wenzelm
parents: 4706
diff changeset
   167
        val html_prefix = Path.append out_path sess_prefix;
e1faf0f6f2b8 checkpoint -- basic functionality only;
wenzelm
parents: 4706
diff changeset
   168
        val graph_prefix = Path.appends [out_path, Path.unpack "graph/data", sess_prefix];
6348
fdcbeaddd5fc include 'README';
wenzelm
parents: 6342
diff changeset
   169
fdcbeaddd5fc include 'README';
wenzelm
parents: 6342
diff changeset
   170
        val _ = (File.mkdir html_prefix; File.mkdir graph_prefix);
fdcbeaddd5fc include 'README';
wenzelm
parents: 6342
diff changeset
   171
        fun prep_readme readme =
fdcbeaddd5fc include 'README';
wenzelm
parents: 6342
diff changeset
   172
          let val readme_path = Path.basic readme in
fdcbeaddd5fc include 'README';
wenzelm
parents: 6342
diff changeset
   173
            if could_copy readme_path (Path.append html_prefix readme_path) then Some readme_path
fdcbeaddd5fc include 'README';
wenzelm
parents: 6342
diff changeset
   174
            else None
fdcbeaddd5fc include 'README';
wenzelm
parents: 6342
diff changeset
   175
          end;
fdcbeaddd5fc include 'README';
wenzelm
parents: 6342
diff changeset
   176
        val opt_readme =
fdcbeaddd5fc include 'README';
wenzelm
parents: 6342
diff changeset
   177
          (case prep_readme "README.html" of None => prep_readme "README" | some => some);
fdcbeaddd5fc include 'README';
wenzelm
parents: 6342
diff changeset
   178
        val index_text = HTML.begin_index (Path.append Path.parent index_path, parent_name)
fdcbeaddd5fc include 'README';
wenzelm
parents: 6342
diff changeset
   179
          (index_path, session_name) opt_readme;
6330
e1faf0f6f2b8 checkpoint -- basic functionality only;
wenzelm
parents: 4706
diff changeset
   180
      in
6339
b995ab768117 maintain current/parent index;
wenzelm
parents: 6330
diff changeset
   181
        File.mkdir (Path.append html_prefix session_path);
b995ab768117 maintain current/parent index;
wenzelm
parents: 6330
diff changeset
   182
        File.write (Path.append html_prefix session_entries_path) "";
6342
13424bbc2d8b report session path;
wenzelm
parents: 6339
diff changeset
   183
        session_info := Some (make_session_info (name, parent_name, session_name, path,
6339
b995ab768117 maintain current/parent index;
wenzelm
parents: 6330
diff changeset
   184
          html_prefix, graph_prefix));
6330
e1faf0f6f2b8 checkpoint -- basic functionality only;
wenzelm
parents: 4706
diff changeset
   185
        browser_info := empty_browser_info;
6348
fdcbeaddd5fc include 'README';
wenzelm
parents: 6342
diff changeset
   186
        add_index index_text
6330
e1faf0f6f2b8 checkpoint -- basic functionality only;
wenzelm
parents: 4706
diff changeset
   187
      end;
e1faf0f6f2b8 checkpoint -- basic functionality only;
wenzelm
parents: 4706
diff changeset
   188
e1faf0f6f2b8 checkpoint -- basic functionality only;
wenzelm
parents: 4706
diff changeset
   189
e1faf0f6f2b8 checkpoint -- basic functionality only;
wenzelm
parents: 4706
diff changeset
   190
(* finish session *)
e1faf0f6f2b8 checkpoint -- basic functionality only;
wenzelm
parents: 4706
diff changeset
   191
6348
fdcbeaddd5fc include 'README';
wenzelm
parents: 6342
diff changeset
   192
fun finish () = with_session (fn {name, html_prefix, graph_prefix, ...} =>
6339
b995ab768117 maintain current/parent index;
wenzelm
parents: 6330
diff changeset
   193
  let
b995ab768117 maintain current/parent index;
wenzelm
parents: 6330
diff changeset
   194
    val {theories, index} = ! browser_info;
6330
e1faf0f6f2b8 checkpoint -- basic functionality only;
wenzelm
parents: 4706
diff changeset
   195
6339
b995ab768117 maintain current/parent index;
wenzelm
parents: 6330
diff changeset
   196
    fun finish_node (a, {source = _, html, graph}) =
b995ab768117 maintain current/parent index;
wenzelm
parents: 6330
diff changeset
   197
      (Buffer.write (Path.append html_prefix (html_path a)) (Buffer.add HTML.end_theory html);
b995ab768117 maintain current/parent index;
wenzelm
parents: 6330
diff changeset
   198
        Buffer.write (Path.append graph_prefix (graph_path a)) graph);
b995ab768117 maintain current/parent index;
wenzelm
parents: 6330
diff changeset
   199
  in
b995ab768117 maintain current/parent index;
wenzelm
parents: 6330
diff changeset
   200
    seq finish_node (Symtab.dest theories);
b995ab768117 maintain current/parent index;
wenzelm
parents: 6330
diff changeset
   201
    Buffer.write (Path.append html_prefix pre_index_path) index;
b995ab768117 maintain current/parent index;
wenzelm
parents: 6330
diff changeset
   202
    create_index html_prefix;
b995ab768117 maintain current/parent index;
wenzelm
parents: 6330
diff changeset
   203
    update_index (Path.append html_prefix Path.parent) name;
6330
e1faf0f6f2b8 checkpoint -- basic functionality only;
wenzelm
parents: 4706
diff changeset
   204
    browser_info := empty_browser_info;
e1faf0f6f2b8 checkpoint -- basic functionality only;
wenzelm
parents: 4706
diff changeset
   205
    session_info := None
e1faf0f6f2b8 checkpoint -- basic functionality only;
wenzelm
parents: 4706
diff changeset
   206
  end);
e1faf0f6f2b8 checkpoint -- basic functionality only;
wenzelm
parents: 4706
diff changeset
   207
e1faf0f6f2b8 checkpoint -- basic functionality only;
wenzelm
parents: 4706
diff changeset
   208
6339
b995ab768117 maintain current/parent index;
wenzelm
parents: 6330
diff changeset
   209
(* theory elements *)
6330
e1faf0f6f2b8 checkpoint -- basic functionality only;
wenzelm
parents: 4706
diff changeset
   210
6348
fdcbeaddd5fc include 'README';
wenzelm
parents: 6342
diff changeset
   211
fun theory_source name src = with_session (fn _ =>
6330
e1faf0f6f2b8 checkpoint -- basic functionality only;
wenzelm
parents: 4706
diff changeset
   212
  (init_theory_info name empty_theory_info; add_source name (HTML.source src)));
e1faf0f6f2b8 checkpoint -- basic functionality only;
wenzelm
parents: 4706
diff changeset
   213
6339
b995ab768117 maintain current/parent index;
wenzelm
parents: 6330
diff changeset
   214
b995ab768117 maintain current/parent index;
wenzelm
parents: 6330
diff changeset
   215
(* FIXME clean *)
b995ab768117 maintain current/parent index;
wenzelm
parents: 6330
diff changeset
   216
6348
fdcbeaddd5fc include 'README';
wenzelm
parents: 6342
diff changeset
   217
fun begin_theory name parents orig_files = with_session (fn {session, html_prefix, ...} =>
6330
e1faf0f6f2b8 checkpoint -- basic functionality only;
wenzelm
parents: 4706
diff changeset
   218
  let
e1faf0f6f2b8 checkpoint -- basic functionality only;
wenzelm
parents: 4706
diff changeset
   219
    val ml_path = ThyLoad.ml_path name;
e1faf0f6f2b8 checkpoint -- basic functionality only;
wenzelm
parents: 4706
diff changeset
   220
    val files = orig_files @		(* FIXME improve!? *)
e1faf0f6f2b8 checkpoint -- basic functionality only;
wenzelm
parents: 4706
diff changeset
   221
      (if is_some (ThyLoad.check_file ml_path) then [(ml_path, true)] else []);
e1faf0f6f2b8 checkpoint -- basic functionality only;
wenzelm
parents: 4706
diff changeset
   222
6348
fdcbeaddd5fc include 'README';
wenzelm
parents: 6342
diff changeset
   223
    fun prep_file (raw_path, loadit) =
6330
e1faf0f6f2b8 checkpoint -- basic functionality only;
wenzelm
parents: 4706
diff changeset
   224
      (case ThyLoad.check_file raw_path of
e1faf0f6f2b8 checkpoint -- basic functionality only;
wenzelm
parents: 4706
diff changeset
   225
        Some (path, _) =>
6348
fdcbeaddd5fc include 'README';
wenzelm
parents: 6342
diff changeset
   226
          let
fdcbeaddd5fc include 'README';
wenzelm
parents: 6342
diff changeset
   227
            val base = Path.base path;
fdcbeaddd5fc include 'README';
wenzelm
parents: 6342
diff changeset
   228
            val base_html = html_ext base;
fdcbeaddd5fc include 'README';
wenzelm
parents: 6342
diff changeset
   229
          in
fdcbeaddd5fc include 'README';
wenzelm
parents: 6342
diff changeset
   230
            File.write (Path.append html_prefix base_html) (HTML.ml_file base (File.read path));
fdcbeaddd5fc include 'README';
wenzelm
parents: 6342
diff changeset
   231
            (Some base_html, raw_path, loadit)
6330
e1faf0f6f2b8 checkpoint -- basic functionality only;
wenzelm
parents: 4706
diff changeset
   232
          end
6348
fdcbeaddd5fc include 'README';
wenzelm
parents: 6342
diff changeset
   233
      | None => (warning ("Browser info: expected to find ML file" ^ quote (Path.pack raw_path));
fdcbeaddd5fc include 'README';
wenzelm
parents: 6342
diff changeset
   234
          (None, raw_path, loadit)));
6330
e1faf0f6f2b8 checkpoint -- basic functionality only;
wenzelm
parents: 4706
diff changeset
   235
6348
fdcbeaddd5fc include 'README';
wenzelm
parents: 6342
diff changeset
   236
    val files_html = map prep_file files;
6330
e1faf0f6f2b8 checkpoint -- basic functionality only;
wenzelm
parents: 4706
diff changeset
   237
    fun prep_source (source, html, graph) =
e1faf0f6f2b8 checkpoint -- basic functionality only;
wenzelm
parents: 4706
diff changeset
   238
      let val txt =
e1faf0f6f2b8 checkpoint -- basic functionality only;
wenzelm
parents: 4706
diff changeset
   239
        HTML.begin_theory (index_path, session) name parents files_html (Buffer.content source)
6348
fdcbeaddd5fc include 'README';
wenzelm
parents: 6342
diff changeset
   240
      in (Buffer.empty, Buffer.add txt html, graph) end;
6330
e1faf0f6f2b8 checkpoint -- basic functionality only;
wenzelm
parents: 4706
diff changeset
   241
  in
6339
b995ab768117 maintain current/parent index;
wenzelm
parents: 6330
diff changeset
   242
    change_theory_info name prep_source;
b995ab768117 maintain current/parent index;
wenzelm
parents: 6330
diff changeset
   243
    add_index (HTML.theory_entry (html_path name, name))
6330
e1faf0f6f2b8 checkpoint -- basic functionality only;
wenzelm
parents: 4706
diff changeset
   244
  end);
e1faf0f6f2b8 checkpoint -- basic functionality only;
wenzelm
parents: 4706
diff changeset
   245
6339
b995ab768117 maintain current/parent index;
wenzelm
parents: 6330
diff changeset
   246
fun end_theory _ = ();
6330
e1faf0f6f2b8 checkpoint -- basic functionality only;
wenzelm
parents: 4706
diff changeset
   247
6348
fdcbeaddd5fc include 'README';
wenzelm
parents: 6342
diff changeset
   248
fun theorem name thm = with_session (fn _ => with_context add_html (HTML.theorem name thm));
fdcbeaddd5fc include 'README';
wenzelm
parents: 6342
diff changeset
   249
fun section s = with_session (fn _ => with_context add_html (HTML.section s));
6330
e1faf0f6f2b8 checkpoint -- basic functionality only;
wenzelm
parents: 4706
diff changeset
   250
e1faf0f6f2b8 checkpoint -- basic functionality only;
wenzelm
parents: 4706
diff changeset
   251
3603
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
   252
end;
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
   253
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
   254
6330
e1faf0f6f2b8 checkpoint -- basic functionality only;
wenzelm
parents: 4706
diff changeset
   255
(* FIXME
3603
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
   256
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
   257
(******************** Graph generation functions ************************)
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
   258
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
   259
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
   260
(*flag that indicates whether graph files should be generated*)
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
   261
val make_graph = ref false;
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
   262
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
   263
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
   264
(*file to use as basis for new graph files*)
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
   265
val graph_base_file = ref "";
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
   266
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
   267
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
   268
(*directory containing basic theories (gets label "base")*)
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
   269
val graph_root_dir = ref "";
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
   270
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
   271
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
   272
(*name of current graph file*)
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
   273
val graph_file = ref "";
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
   274
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
   275
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
   276
(*name of large graph file which also contains
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
   277
  theories defined in subdirectories *)
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
   278
val large_graph_file = ref "";
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
   279
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
   280
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
   281
(* initialize graph data generator *)
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
   282
fun init_graph usedir_arg =
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
   283
  let
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
   284
      (*create default graph containing only Pure, CPure and ProtoPure*)
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
   285
      fun default_graph outfile =
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
   286
        let val os = TextIO.openOut outfile;
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
   287
        in (TextIO.output(os,"\"ProtoPure\" \"ProtoPure\" \"Pure\" \"\" ;\n\
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
   288
                             \\"CPure\" \"CPure\" \"Pure\" \"\" > \"ProtoPure\" ;\n\
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
   289
                             \\"Pure\" \"Pure\" \"Pure\" \"\" > \"ProtoPure\" ;\n");
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
   290
            TextIO.closeOut os)
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
   291
        end;
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
   292
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
   293
      (*copy graph file, adjust relative paths for theory files*)
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
   294
      fun copy_graph infile outfile unfold =
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
   295
        let val is = TextIO.openIn infile;
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
   296
            val (inp_dir, _) = split_filename infile;
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
   297
            val (outp_dir, _) = split_filename outfile;
3834
278f0a1e5986 BAD_space_explode;
wenzelm
parents: 3748
diff changeset
   298
            val entries = map (BAD_space_explode " ")
278f0a1e5986 BAD_space_explode;
wenzelm
parents: 3748
diff changeset
   299
                            (BAD_space_explode "\n" (TextIO.inputAll is));
3603
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
   300
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
   301
            fun thyfile f = if f = "\"\"" then f else
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
   302
              let val (dir, name) =
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
   303
                    split_filename (implode (rev (tl (rev (tl (explode f))))));
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
   304
                  val abs_path = normalize_path (tack_on inp_dir dir);
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
   305
                  val rel_path = tack_on (relative_path outp_dir abs_path) name
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
   306
              in quote rel_path end;
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
   307
6330
e1faf0f6f2b8 checkpoint -- basic functionality only;
wenzelm
parents: 4706
diff changeset
   308
            fun process_entry (a::b::c::d::e::r) =
3603
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
   309
              if d = "+" then
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
   310
                a::b::c::((if unfold then "+ " else "") ^ (thyfile e))::r
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
   311
              else
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
   312
                a::b::c::(thyfile d)::e::r;
6330
e1faf0f6f2b8 checkpoint -- basic functionality only;
wenzelm
parents: 4706
diff changeset
   313
3603
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
   314
            val _  = TextIO.closeIn is;
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
   315
            val os = TextIO.openOut outfile;
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
   316
            val _  = TextIO.output(os, (cat_lines
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
   317
                          (map ((space_implode " ") o process_entry) entries)) ^ "\n");
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
   318
            val _  = TextIO.closeOut os;
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
   319
        in () end;
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
   320
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
   321
      (*create html page which contains graph browser applet*)
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
   322
      fun mk_applet_page abs_path large other_graph =
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
   323
        let
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
   324
          val dir_name =
4215
7f7519759b8c moved old file stuff from library.ML to Thy/browser_info.ML;
wenzelm
parents: 3976
diff changeset
   325
            (if subdir_of (!original_path, !base_path) then "Isabelle/" else "") ^
3603
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
   326
            (relative_path (normalize_path (tack_on (!graph_root_dir) "..")) (pwd ()));
6330
e1faf0f6f2b8 checkpoint -- basic functionality only;
wenzelm
parents: 4706
diff changeset
   327
          val rel_codebase =
3603
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
   328
            relative_path abs_path (tack_on (normalize_path (!output_dir)) "graph");
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
   329
          val rel_index_path = tack_on (relative_path
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
   330
            abs_path (tack_on (normalize_path (!output_dir)) "graph")) "index.html";
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
   331
          val outfile =
3748
e5d2399a154f Changed html data directory and names of graph files.
berghofe
parents: 3639
diff changeset
   332
            tack_on abs_path ((if large then "large" else "small") ^ ".html");
3603
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
   333
          val os = TextIO.openOut outfile;
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
   334
          val _ = TextIO.output(os,
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
   335
            "<HTML><HEAD><TITLE>" ^ dir_name ^ "</TITLE></HEAD>\n\
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
   336
            \<BODY><H2>" ^ dir_name ^ "</H2>\n" ^
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
   337
            (if other_graph then
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
   338
              (if large then
3748
e5d2399a154f Changed html data directory and names of graph files.
berghofe
parents: 3639
diff changeset
   339
                 "View <A HREF=\"small.html\">small graph</A> without \
3603
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
   340
                 \subdirectories<P>\n"
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
   341
               else
3748
e5d2399a154f Changed html data directory and names of graph files.
berghofe
parents: 3639
diff changeset
   342
                 "View <A HREF=\"large.html\">large graph</A> including \
3603
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
   343
                 \all subdirectories<P>\n")
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
   344
             else "") ^
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
   345
            "<A HREF=\"" ^ rel_index_path ^ "\">Back</A> to index\n<HR>\n\
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
   346
            \<APPLET CODE=\"GraphBrowser/GraphBrowser.class\" \
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
   347
            \CODEBASE=\"" ^ rel_codebase ^ "\" WIDTH=550 HEIGHT=450>\n\
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
   348
            \<PARAM NAME=\"graphfile\" VALUE=\"" ^
3748
e5d2399a154f Changed html data directory and names of graph files.
berghofe
parents: 3639
diff changeset
   349
            (if large then "large.graph" else "small.graph") ^ "\">\n\
3603
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
   350
            \</APPLET>\n<HR>\n</BODY></HTML>")
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
   351
          val _ = TextIO.closeOut os
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
   352
        in () end;
6330
e1faf0f6f2b8 checkpoint -- basic functionality only;
wenzelm
parents: 4706
diff changeset
   353
3603
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
   354
      val gpath = graph_path (pwd ());
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
   355
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
   356
  in
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
   357
    (make_graph := true;
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
   358
     base_path := normalize_path (!base_path);
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
   359
     mkdir gpath;
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
   360
     original_path := pwd ();
3748
e5d2399a154f Changed html data directory and names of graph files.
berghofe
parents: 3639
diff changeset
   361
     graph_file := tack_on gpath "small.graph";
3603
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
   362
     graph_root_dir := (if usedir_arg = "." then pwd ()
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
   363
                        else normalize_path (tack_on (pwd ()) ".."));
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
   364
     (if (!graph_base_file) = "" then
3748
e5d2399a154f Changed html data directory and names of graph files.
berghofe
parents: 3639
diff changeset
   365
        (large_graph_file := tack_on gpath "large.graph";
3603
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
   366
         default_graph (!graph_file);
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
   367
         default_graph (!large_graph_file);
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
   368
         mk_applet_page gpath false true;
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
   369
         mk_applet_page gpath true true)
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
   370
      else
4215
7f7519759b8c moved old file stuff from library.ML to Thy/browser_info.ML;
wenzelm
parents: 3976
diff changeset
   371
        (if subdir_of (fst (split_filename (!graph_file)),
7f7519759b8c moved old file stuff from library.ML to Thy/browser_info.ML;
wenzelm
parents: 3976
diff changeset
   372
            (fst (split_filename (!graph_base_file))))
3603
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
   373
         then
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
   374
           (copy_graph (!graph_base_file) (!graph_file) true;
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
   375
            mk_applet_page gpath false false)
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
   376
         else
3748
e5d2399a154f Changed html data directory and names of graph files.
berghofe
parents: 3639
diff changeset
   377
           (large_graph_file := tack_on gpath "large.graph";
3603
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
   378
            mk_applet_page gpath false true;
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
   379
            mk_applet_page gpath true true;
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
   380
            copy_graph (!graph_base_file) (!graph_file) false;
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
   381
            copy_graph (!graph_base_file) (!large_graph_file) false)));
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
   382
     graph_base_file := (!graph_file))
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
   383
  end;
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
   384
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
   385
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
   386
(*add theory to graph definition file*)
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
   387
fun mk_graph tname abs_path = if not (!make_graph) then () else
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
   388
  let val parents =
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
   389
        map (fn (t, _) => tack_on (path_of t) t)
3976
wenzelm
parents: 3870
diff changeset
   390
          (filter (fn (_, {children,...}) => tname mem children)
3603
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
   391
             (Symtab.dest(!loaded_thys)));
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
   392
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
   393
      val dir_name = relative_path
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
   394
         (normalize_path (tack_on (!graph_root_dir) "..")) abs_path;
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
   395
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
   396
      val dir_entry = "\"" ^ dir_name ^
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
   397
         (if (tack_on abs_path "") = (tack_on (!graph_root_dir) "")
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
   398
          then "/base\" + " else "\" ");
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
   399
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
   400
      val thy_file = (tack_on (html_path abs_path) tname) ^ ".html";
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
   401
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
   402
      val thy_ID = quote (tack_on abs_path tname);
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
   403
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
   404
      val entry_str_1 = (quote tname) ^ " " ^ thy_ID ^ " " ^ dir_entry ^
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
   405
                (quote (relative_path (fst (split_filename (!graph_file))) thy_file)) ^
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
   406
                " > " ^ (space_implode " " (map quote parents)) ^ " ;\n" ;
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
   407
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
   408
      val entry_str_2 = (quote tname) ^ " " ^ thy_ID ^ " " ^ dir_entry ^
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
   409
                (quote (relative_path (fst (split_filename (!large_graph_file))) thy_file)) ^
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
   410
                " > " ^ (space_implode " " (map quote parents)) ^ " ;\n" ;
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
   411
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
   412
      fun exists_entry id infile =
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
   413
        let val is = TextIO.openIn(infile);
3834
278f0a1e5986 BAD_space_explode;
wenzelm
parents: 3748
diff changeset
   414
            val IDs = map (hd o tl o (BAD_space_explode " "))
278f0a1e5986 BAD_space_explode;
wenzelm
parents: 3748
diff changeset
   415
                            (BAD_space_explode "\n" (TextIO.inputAll is));
3603
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
   416
            val _ = TextIO.closeIn is
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
   417
        in id mem IDs end;
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
   418
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
   419
      fun mk_entry outfile entry_str =
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
   420
        if exists_entry thy_ID outfile then ()
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
   421
        else
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
   422
          let val os = TextIO.openAppend outfile;
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
   423
              val _ = TextIO.output (os, entry_str);
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
   424
              val _ = TextIO.closeOut os;
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
   425
          in () end
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
   426
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
   427
  in (mk_entry (!graph_file) entry_str_1;
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
   428
      mk_entry (!large_graph_file) entry_str_2) handle _ =>
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
   429
             (make_graph:=false;
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
   430
              warning ("Unable to write to graph file " ^ (!graph_file)))
5eef2ff0eb72 This file now contains all functions for generating html
berghofe
parents:
diff changeset
   431
  end;
6342
13424bbc2d8b report session path;
wenzelm
parents: 6339
diff changeset
   432
6330
e1faf0f6f2b8 checkpoint -- basic functionality only;
wenzelm
parents: 4706
diff changeset
   433
*)