1 (* Copyright (C) 2004-2011, HELM Team.
3 * This file is part of HELM, an Hypertextual, Electronic
4 * Library of Mathematics, developed at the Computer Science
5 * Department, University of Bologna, Italy.
7 * HELM is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
12 * HELM is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with HELM; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
22 * For details, see the HELM World-Wide-Web page,
23 * http://helm.cs.unibo.it/
26 exception SvnError of string;;
28 let exec_process cmd =
29 let (stdout, stdin, stderr) as chs = Unix.open_process_full cmd [||] in
30 let outlines = ref [] in
31 let errlines = ref [] in
34 outlines := input_line stdout :: !outlines;
40 errlines := input_line stderr :: !errlines;
44 match (Unix.close_process_full chs) with
45 | Unix.WEXITED errno ->
46 let output = "std out =\n" ^ String.concat "\n" (List.rev !outlines) in
47 let errors = "std err =\n" ^ String.concat "\n" (List.rev !errlines) in
48 errno, output ^ "\n\n" ^ errors
52 let rt_dir = Helm_registry.get "matita.rt_base_dir" in
53 let repo = Helm_registry.get "matita.weblib" in
55 let errno, outstr = exec_process
56 ("svn co " ^ repo ^ " " ^ rt_dir ^ "/users/" ^ user ^ "/")
59 else raise (SvnError outstr)
61 let html_of_library uid =
63 let newid () = incr i; ("node" ^ string_of_int !i) in
65 let basedir = (Helm_registry.get "matita.rt_base_dir") ^ "/users/" ^ uid in
69 let name = Filename.basename text in
70 let name = if name <> "." then name else "cic:/matita" in
71 "<span class=\"trigger\" onClick=\"showBranch('" ^ id ^ "')\">\n" ^
72 "<img src=\"treeview/closed.gif\" id=\"I" ^ id ^ "\"/>\n" ^
73 name ^ "<br/></span>\n" ^
74 "<span class=\"branch\" id=\"" ^ id ^ "\">\n" ^
78 "<img src=\"treeview/doc.gif\"/>\n" ^
79 "<a href=\"javascript:retrieveFile('" ^ text ^ "')\">" ^
80 (Filename.basename text) ^ "</a><br/>"
84 let lpath filename = path ^ "/" ^ filename in
85 let gpath filename = basedir ^ "/" ^ path ^ "/" ^ filename in
87 List.filter (fun x -> String.sub x 0 1 <> ".")
88 (Array.to_list (Sys.readdir (basedir ^ "/" ^ path))) in
89 let subdirs = List.filter (fun x -> Sys.is_directory (gpath x)) dirlist in
93 let i = String.rindex x '.' in
94 let len = String.length x - i in
95 not (Sys.is_directory (gpath x)) &&
96 (String.sub x 0 1 <> ".") && (String.sub x i len = ".ma")
97 with Not_found | Invalid_argument _ -> false) dirlist in
99 String.concat "\n" (List.map (fun x -> aux (lpath x)) subdirs) in
102 (List.map (fun x -> leaf (lpath x)) scripts)
104 branch path (subdirtags ^ "\n" ^ scripttags)
108 prerr_endline "BEGIN TREE";prerr_endline res;prerr_endline "END TREE";