1 (* Copyright (C) 2004, 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/
28 let is_dir fname = (Unix.stat fname).Unix.st_kind = Unix.S_DIR
29 let is_regular fname = (Unix.stat fname).Unix.st_kind = Unix.S_REG
31 let input_file fname =
32 let size = (Unix.stat fname).Unix.st_size in
33 let buf = Buffer.create size in
34 let ic = open_in fname in
35 Buffer.add_channel buf ic size;
39 let is_proof_script fname = true (** TODO Zack *)
40 let is_proof_object fname = true (** TODO Zack *)
42 let append_phrase_sep s =
43 if not (Pcre.pmatch ~pat:(sprintf "%s$" BuildTimeConf.phrase_sep) s) then
44 s ^ BuildTimeConf.phrase_sep
48 let strip_trailing_blanks =
49 let rex = Pcre.regexp "\\s*$" in
50 fun s -> Pcre.replace ~rex s
54 Misc.domImpl#createDocument ~namespaceURI:(Some Misc.mathml_ns)
55 ~qualifiedName:(Gdome.domString "math") ~doctype:None
57 doc#get_documentElement
59 exception History_failure
61 type 'a memento = 'a array * int * int * int (* data, hd, tl, cur *)
63 class type ['a] history =
65 method add : 'a -> unit
68 method load: 'a memento -> unit
69 method save: 'a memento
72 class shell_history size =
73 let size = size + 1 in
74 let decr x = let x' = x - 1 in if x' < 0 then size + x' else x' in
75 let incr x = (x + 1) mod size in
77 val data = Array.create size ""
78 val mutable hd = 0 (* insertion point *)
79 val mutable tl = -1 (* oldest inserted item *)
80 val mutable cur = -1 (* current item for the history *)
83 if tl = -1 then tl <- hd;
85 if hd = tl then tl <- incr tl;
88 if cur = tl then raise History_failure;
92 if cur = hd then raise History_failure;
94 if cur = hd then "" else data.(cur)
95 method load (data', hd', tl', cur') =
96 assert (Array.length data = Array.length data');
97 hd <- hd'; tl <- tl'; cur <- cur';
98 Array.blit data' 0 data 0 (Array.length data')
99 method save = (Array.copy data, hd, tl, cur)
102 class ['a] browser_history ?memento size init =
104 initializer match memento with Some m -> self#load m | _ -> ()
105 val data = Array.create size init
110 if cur = tl then raise History_failure;
112 if cur = ~-1 then cur <- size - 1;
115 if cur = hd then raise History_failure;
117 if cur = size then cur <- 0;
121 if cur = size then cur <- 0;
122 if cur = tl then tl <- tl + 1;
123 if tl = size then tl <- 0;
126 method load (data', hd', tl', cur') =
127 assert (Array.length data = Array.length data');
128 hd <- hd'; tl <- tl'; cur <- cur';
129 Array.blit data' 0 data 0 (Array.length data')
130 method save = (Array.copy data, hd, tl, cur)
136 ~host:(Helm_registry.get "db.host")
137 ~user:(Helm_registry.get "db.user")
138 ~database:(Helm_registry.get "db.database")
141 fun () -> Lazy.force dbd