src/Pure/Thy/browser_info.ML
changeset 3834 278f0a1e5986
parent 3748 e5d2399a154f
child 3868 86981c4bffdb
equal deleted inserted replaced
3833:370e845c391f 3834:278f0a1e5986
    57 
    57 
    58 
    58 
    59 (*Path of Isabelle's main (source) directory
    59 (*Path of Isabelle's main (source) directory
    60   FIXME: this value should be provided by isatool!*)
    60   FIXME: this value should be provided by isatool!*)
    61 val base_path = ref (
    61 val base_path = ref (
    62   "/" ^ space_implode "/" (rev (tl (tl (rev (space_explode "/" (OS.FileSys.getDir ())))))));
    62   "/" ^ space_implode "/" (rev (tl (tl (rev (BAD_space_explode "/" (OS.FileSys.getDir ())))))));
    63 
    63 
    64 
    64 
    65 (* copy contents of file *)  (* FIXME: move to library?*)
    65 (* copy contents of file *)  (* FIXME: move to library?*)
    66 
    66 
    67 fun copy_file infile outfile =
    67 fun copy_file infile outfile =
   477 
   477 
   478 (*Generate index.html*)
   478 (*Generate index.html*)
   479 fun finish_html () = if not (!make_html) then () else
   479 fun finish_html () = if not (!make_html) then () else
   480   let val tlist_path = tack_on (!index_path) "theory_list.txt";
   480   let val tlist_path = tack_on (!index_path) "theory_list.txt";
   481       val theory_list = TextIO.openIn tlist_path;
   481       val theory_list = TextIO.openIn tlist_path;
   482       val theories = space_explode "\n" (TextIO.inputAll theory_list);
   482       val theories = BAD_space_explode "\n" (TextIO.inputAll theory_list);
   483       val dummy = (TextIO.closeIn theory_list; OS.FileSys.remove tlist_path);
   483       val dummy = (TextIO.closeIn theory_list; OS.FileSys.remove tlist_path);
   484 
   484 
   485       val rel_gif_path = relative_path (!index_path) (gif_path ());
   485       val rel_gif_path = relative_path (!index_path) (gif_path ());
   486 
   486 
   487       (*Make entry for main chart of all theories.*)
   487       (*Make entry for main chart of all theories.*)
   507         then take the last directory of index_path*)
   507         then take the last directory of index_path*)
   508       val inside_isabelle = (!original_path) subdir_of (!base_path);
   508       val inside_isabelle = (!original_path) subdir_of (!base_path);
   509       val subdir =
   509       val subdir =
   510         if inside_isabelle then relative_path (html_path (!base_path)) (!index_path)
   510         if inside_isabelle then relative_path (html_path (!base_path)) (!index_path)
   511         else base_name (!index_path);
   511         else base_name (!index_path);
   512       val subdirs = space_explode "/" subdir;
   512       val subdirs = BAD_space_explode "/" subdir;
   513 
   513 
   514       (*Look for index.html in superdirectories; stop when Isabelle's
   514       (*Look for index.html in superdirectories; stop when Isabelle's
   515         main directory is reached*)
   515         main directory is reached*)
   516       fun find_super_index [] n = ("", n)
   516       fun find_super_index [] n = ("", n)
   517         | find_super_index (p::ps) n =
   517         | find_super_index (p::ps) n =
   519           in if file_exists (index_path ^ "/index.html") then (index_path, n)
   519           in if file_exists (index_path ^ "/index.html") then (index_path, n)
   520              else if length subdirs - n > 0 then find_super_index ps (n+1)
   520              else if length subdirs - n > 0 then find_super_index ps (n+1)
   521              else ("", n)
   521              else ("", n)
   522           end;
   522           end;
   523       val (super_index, level_diff) =
   523       val (super_index, level_diff) =
   524         find_super_index (rev (space_explode "/" (!index_path))) 1;
   524         find_super_index (rev (BAD_space_explode "/" (!index_path))) 1;
   525       val level = length subdirs - level_diff;
   525       val level = length subdirs - level_diff;
   526 
   526 
   527       (*Add link to current directory to 'super' index.html*)
   527       (*Add link to current directory to 'super' index.html*)
   528       fun link_directory () =
   528       fun link_directory () =
   529         let val old_index = TextIO.openIn (super_index ^ "/index.html");
   529         let val old_index = TextIO.openIn (super_index ^ "/index.html");
   557        \View <A HREF=\"" ^ rel_graph_path ^ "\">graph</A> of theories<P>\n" ^
   557        \View <A HREF=\"" ^ rel_graph_path ^ "\">graph</A> of theories<P>\n" ^
   558        (if super_index = "" then "" else
   558        (if super_index = "" then "" else
   559         ("<A HREF = \"" ^ relative_path (!index_path) super_index ^ 
   559         ("<A HREF = \"" ^ relative_path (!index_path) super_index ^ 
   560          "/index.html\">Back</A> to the index of " ^
   560          "/index.html\">Back</A> to the index of " ^
   561          (if not inside_isabelle then
   561          (if not inside_isabelle then
   562             hd (tl (rev (space_explode "/" (!index_path))))
   562             hd (tl (rev (BAD_space_explode "/" (!index_path))))
   563           else if level = 0 then "Isabelle logics"
   563           else if level = 0 then "Isabelle logics"
   564           else space_implode "/" (take (level, subdirs))))) ^
   564           else space_implode "/" (take (level, subdirs))))) ^
   565        "\n" ^
   565        "\n" ^
   566        (if file_exists (tack_on (!index_path) "README.html") then
   566        (if file_exists (tack_on (!index_path) "README.html") then
   567           "<BR>View the <A HREF = \"README.html\">ReadMe</A> file.\n"
   567           "<BR>View the <A HREF = \"README.html\">ReadMe</A> file.\n"
   645       (*copy graph file, adjust relative paths for theory files*)
   645       (*copy graph file, adjust relative paths for theory files*)
   646       fun copy_graph infile outfile unfold =
   646       fun copy_graph infile outfile unfold =
   647         let val is = TextIO.openIn infile;
   647         let val is = TextIO.openIn infile;
   648             val (inp_dir, _) = split_filename infile;
   648             val (inp_dir, _) = split_filename infile;
   649             val (outp_dir, _) = split_filename outfile;
   649             val (outp_dir, _) = split_filename outfile;
   650             val entries = map (space_explode " ")
   650             val entries = map (BAD_space_explode " ")
   651                             (space_explode "\n" (TextIO.inputAll is));
   651                             (BAD_space_explode "\n" (TextIO.inputAll is));
   652 
   652 
   653             fun thyfile f = if f = "\"\"" then f else
   653             fun thyfile f = if f = "\"\"" then f else
   654               let val (dir, name) =
   654               let val (dir, name) =
   655                     split_filename (implode (rev (tl (rev (tl (explode f))))));
   655                     split_filename (implode (rev (tl (rev (tl (explode f))))));
   656                   val abs_path = normalize_path (tack_on inp_dir dir);
   656                   val abs_path = normalize_path (tack_on inp_dir dir);
   761                 (quote (relative_path (fst (split_filename (!large_graph_file))) thy_file)) ^
   761                 (quote (relative_path (fst (split_filename (!large_graph_file))) thy_file)) ^
   762                 " > " ^ (space_implode " " (map quote parents)) ^ " ;\n" ;
   762                 " > " ^ (space_implode " " (map quote parents)) ^ " ;\n" ;
   763 
   763 
   764       fun exists_entry id infile =
   764       fun exists_entry id infile =
   765         let val is = TextIO.openIn(infile);
   765         let val is = TextIO.openIn(infile);
   766             val IDs = map (hd o tl o (space_explode " "))
   766             val IDs = map (hd o tl o (BAD_space_explode " "))
   767                             (space_explode "\n" (TextIO.inputAll is));
   767                             (BAD_space_explode "\n" (TextIO.inputAll is));
   768             val _ = TextIO.closeIn is
   768             val _ = TextIO.closeIn is
   769         in id mem IDs end;
   769         in id mem IDs end;
   770 
   770 
   771       fun mk_entry outfile entry_str =
   771       fun mk_entry outfile entry_str =
   772         if exists_entry thy_ID outfile then ()
   772         if exists_entry thy_ID outfile then ()