/tryocaml/js_of_ocaml-patched/compiler/util.ml
OCaml | 78 lines | 42 code | 14 blank | 22 comment | 4 complexity | 0bad8c99647922560452690a3f1dcde0 MD5 | raw file
Possible License(s): GPL-2.0
1(* Js_of_ocaml compiler 2 * http://www.ocsigen.org/js_of_ocaml/ 3 * Copyright (C) 2010 Jérôme Vouillon 4 * Laboratoire PPS - CNRS Université Paris Diderot 5 * 6 * This program is free software; you can redistribute it and/or modify 7 * it under the terms of the GNU Lesser General Public License as published by 8 * the Free Software Foundation, with linking exception; 9 * either version 2.1 of the License, or (at your option) any later version. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU Lesser General Public License for more details. 15 * 16 * You should have received a copy of the GNU Lesser General Public License 17 * along with this program; if not, write to the Free Software 18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 19 *) 20 21module Int = struct type t = int let compare (x : int) y = compare x y end 22module IntSet = Set.Make (Int) 23module IntMap = Map.Make (Int) 24 25module StringSet = Set.Make (String) 26 27let opt_map f x = match x with None -> None | Some v -> Some (f v) 28let opt_iter f x = match x with None -> () | Some v -> f v 29let opt_bind x f = match x with None -> None | Some v -> f v 30let opt_filter p x = 31 match x with None -> None | Some v -> if p v then Some v else None 32 33(****) 34 35let rec find_in_paths paths name = 36 match paths with 37 [] -> 38 raise Not_found 39 | path :: rem -> 40 let file = Filename.concat path name in 41 if Sys.file_exists file then file else find_in_paths rem name 42 43let read_file f = 44 let ch = open_in_bin f in 45 let b = Buffer.create 4096 in 46 let s = String.create 4096 in 47 while 48 let n = input ch s 0 4096 in 49 Buffer.add_substring b s 0 n; 50 n <> 0 51 do () done; 52 close_in ch; 53 Buffer.contents b 54 55(****) 56 57let debugs = ref [] 58 59let debug s = 60 let state = ref false in 61 debugs := (s, state) :: !debugs; 62 fun () -> !state 63 64let set_debug s = 65 try List.assoc s !debugs := true with Not_found -> () 66 67(****) 68 69let disabled_lst = ref [] 70 71let disabled s = 72 let state = ref false in 73 disabled_lst := (s, state) :: !disabled_lst; 74 fun () -> !state 75 76let set_disabled s = 77 try List.assoc s !disabled_lst := true with Not_found -> 78 Format.eprintf "%s: no disable option named '%s'@." Sys.argv.(0) s; exit 1