1995-08-09 08:06:35 -07:00
|
|
|
(***********************************************************************)
|
|
|
|
(* *)
|
2011-07-27 07:17:02 -07:00
|
|
|
(* OCaml *)
|
1995-08-09 08:06:35 -07:00
|
|
|
(* *)
|
|
|
|
(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *)
|
|
|
|
(* *)
|
1996-04-30 07:53:58 -07:00
|
|
|
(* Copyright 1996 Institut National de Recherche en Informatique et *)
|
1999-11-17 10:59:06 -08:00
|
|
|
(* en Automatique. All rights reserved. This file is distributed *)
|
|
|
|
(* under the terms of the Q Public License version 1.0. *)
|
1995-08-09 08:06:35 -07:00
|
|
|
(* *)
|
|
|
|
(***********************************************************************)
|
|
|
|
|
1995-05-04 03:15:53 -07:00
|
|
|
(* Miscellaneous useful types and functions *)
|
|
|
|
|
|
|
|
val fatal_error: string -> 'a
|
|
|
|
exception Fatal_error
|
|
|
|
|
2003-04-01 17:32:09 -08:00
|
|
|
val try_finally : (unit -> 'a) -> (unit -> unit) -> 'a;;
|
|
|
|
|
1995-05-04 03:15:53 -07:00
|
|
|
val map_end: ('a -> 'b) -> 'a list -> 'b list -> 'b list
|
1996-01-04 04:51:11 -08:00
|
|
|
(* [map_end f l t] is [map f l @ t], just more efficient. *)
|
2002-02-08 08:55:44 -08:00
|
|
|
val map_left_right: ('a -> 'b) -> 'a list -> 'b list
|
|
|
|
(* Like [List.map], with guaranteed left-to-right evaluation order *)
|
1995-05-04 03:15:53 -07:00
|
|
|
val for_all2: ('a -> 'b -> bool) -> 'a list -> 'b list -> bool
|
2000-11-22 05:51:07 -08:00
|
|
|
(* Same as [List.for_all] but for a binary predicate.
|
|
|
|
In addition, this [for_all2] never fails: given two lists
|
|
|
|
with different lengths, it returns false. *)
|
1996-01-04 04:51:11 -08:00
|
|
|
val replicate_list: 'a -> int -> 'a list
|
|
|
|
(* [replicate_list elem n] is the list with [n] elements
|
|
|
|
all identical to [elem]. *)
|
1999-02-04 02:32:27 -08:00
|
|
|
val list_remove: 'a -> 'a list -> 'a list
|
|
|
|
(* [list_remove x l] returns a copy of [l] with the first
|
2000-02-28 07:47:13 -08:00
|
|
|
element equal to [x] removed. *)
|
|
|
|
val split_last: 'a list -> 'a list * 'a
|
|
|
|
(* Return the last element and the other elements of the given list. *)
|
2004-07-13 05:25:21 -07:00
|
|
|
val samelist: ('a -> 'a -> bool) -> 'a list -> 'a list -> bool
|
|
|
|
(* Like [List.for_all2] but returns [false] if the two
|
|
|
|
lists have different length. *)
|
1995-05-04 03:15:53 -07:00
|
|
|
|
1999-11-30 08:07:38 -08:00
|
|
|
val may: ('a -> unit) -> 'a option -> unit
|
|
|
|
val may_map: ('a -> 'b) -> 'a option -> 'b option
|
|
|
|
|
1995-05-04 03:15:53 -07:00
|
|
|
val find_in_path: string list -> string -> string
|
|
|
|
(* Search a file in a list of directories. *)
|
2002-06-07 00:35:38 -07:00
|
|
|
val find_in_path_uncap: string list -> string -> string
|
|
|
|
(* Same, but search also for uncapitalized name, i.e.
|
|
|
|
if name is Foo.ml, allow /path/Foo.ml and /path/foo.ml
|
|
|
|
to match. *)
|
1995-05-04 03:15:53 -07:00
|
|
|
val remove_file: string -> unit
|
1996-01-04 04:51:11 -08:00
|
|
|
(* Delete the given file if it exists. Never raise an error. *)
|
2000-12-27 21:02:43 -08:00
|
|
|
val expand_directory: string -> string -> string
|
|
|
|
(* [expand_directory alt file] eventually expands a [+] at the
|
|
|
|
beginning of file into [alt] (an alternate root directory) *)
|
1995-05-04 03:15:53 -07:00
|
|
|
|
|
|
|
val create_hashtable: int -> ('a * 'b) list -> ('a, 'b) Hashtbl.t
|
|
|
|
(* Create a hashtable of the given size and fills it with the
|
|
|
|
given bindings. *)
|
|
|
|
|
|
|
|
val copy_file: in_channel -> out_channel -> unit
|
|
|
|
(* [copy_file ic oc] reads the contents of file [ic] and copies
|
|
|
|
them to [oc]. It stops when encountering EOF on [ic]. *)
|
|
|
|
val copy_file_chunk: in_channel -> out_channel -> int -> unit
|
|
|
|
(* [copy_file_chunk ic oc n] reads [n] bytes from [ic] and copies
|
|
|
|
them to [oc]. It raises [End_of_file] when encountering
|
|
|
|
EOF on [ic]. *)
|
2012-05-30 07:52:37 -07:00
|
|
|
val string_of_file: in_channel -> string
|
|
|
|
(* [string_of_file ic] reads the contents of file [ic] and copies
|
|
|
|
them to a string. It stops when encountering EOF on [ic]. *)
|
2012-02-23 11:54:44 -08:00
|
|
|
val input_bytes : in_channel -> int -> string;;
|
|
|
|
(* [input_bytes ic n] reads [n] bytes from [ic] and returns them
|
|
|
|
in a new string. It raises [End_of_file] if EOF is encountered
|
|
|
|
before all the bytes are read. *)
|
|
|
|
|
1995-06-05 06:44:14 -07:00
|
|
|
val log2: int -> int
|
2010-01-22 04:48:24 -08:00
|
|
|
(* [log2 n] returns [s] such that [n = 1 lsl s]
|
1995-06-05 06:44:14 -07:00
|
|
|
if [n] is a power of 2*)
|
|
|
|
val align: int -> int -> int
|
|
|
|
(* [align n a] rounds [n] upwards to a multiple of [a]
|
|
|
|
(a power of 2). *)
|
1995-10-26 09:25:24 -07:00
|
|
|
val no_overflow_add: int -> int -> bool
|
|
|
|
(* [no_overflow_add n1 n2] returns [true] if the computation of
|
|
|
|
[n1 + n2] does not overflow. *)
|
|
|
|
val no_overflow_sub: int -> int -> bool
|
|
|
|
(* [no_overflow_add n1 n2] returns [true] if the computation of
|
|
|
|
[n1 - n2] does not overflow. *)
|
2002-01-10 07:52:40 -08:00
|
|
|
val no_overflow_lsl: int -> bool
|
|
|
|
(* [no_overflow_add n] returns [true] if the computation of
|
|
|
|
[n lsl 1] does not overflow. *)
|
2002-01-28 09:25:26 -08:00
|
|
|
|
|
|
|
val chop_extension_if_any: string -> string
|
|
|
|
(* Like Filename.chop_extension but returns the initial file
|
|
|
|
name if it has no extension *)
|
2002-02-08 08:55:44 -08:00
|
|
|
|
2007-02-23 05:44:51 -08:00
|
|
|
val chop_extensions: string -> string
|
|
|
|
(* Return the given file name without its extensions. The extensions
|
|
|
|
is the longest suffix starting with a period and not including
|
|
|
|
a directory separator, [.xyz.uvw] for instance.
|
|
|
|
|
|
|
|
Return the given name if it does not contain an extension. *)
|
|
|
|
|
2002-02-08 08:55:44 -08:00
|
|
|
val search_substring: string -> string -> int -> int
|
|
|
|
(* [search_substring pat str start] returns the position of the first
|
|
|
|
occurrence of string [pat] in string [str]. Search starts
|
|
|
|
at offset [start] in [str]. Raise [Not_found] if [pat]
|
|
|
|
does not occur. *)
|
2002-05-07 06:16:28 -07:00
|
|
|
|
|
|
|
val rev_split_words: string -> string list
|
|
|
|
(* [rev_split_words s] splits [s] in blank-separated words, and return
|
|
|
|
the list of words in reverse order. *)
|
2011-12-28 06:20:53 -08:00
|
|
|
|
|
|
|
val get_ref: 'a list ref -> 'a list
|
|
|
|
(* [get_ref lr] returns the content of the list reference [lr] and reset
|
|
|
|
its content to the empty list. *)
|
2012-05-30 07:52:37 -07:00
|
|
|
|
|
|
|
|
|
|
|
val fst3: 'a * 'b * 'c -> 'a
|
|
|
|
val snd3: 'a * 'b * 'c -> 'b
|
|
|
|
val thd3: 'a * 'b * 'c -> 'c
|
|
|
|
|
|
|
|
val fst4: 'a * 'b * 'c * 'd -> 'a
|
|
|
|
val snd4: 'a * 'b * 'c * 'd -> 'b
|
|
|
|
val thd4: 'a * 'b * 'c * 'd -> 'c
|
2013-04-29 22:26:57 -07:00
|
|
|
val for4: 'a * 'b * 'c * 'd -> 'd
|
2012-10-16 06:54:24 -07:00
|
|
|
|
2013-04-17 02:07:00 -07:00
|
|
|
module LongString :
|
|
|
|
sig
|
|
|
|
type t = string array
|
|
|
|
val create : int -> t
|
|
|
|
val length : t -> int
|
|
|
|
val get : t -> int -> char
|
|
|
|
val set : t -> int -> char -> unit
|
|
|
|
val blit : t -> int -> t -> int -> int -> unit
|
|
|
|
val output : out_channel -> t -> int -> int -> unit
|
|
|
|
val unsafe_blit_to_string : t -> int -> string -> int -> int -> unit
|
|
|
|
val input_bytes : in_channel -> int -> t
|
|
|
|
end
|
2012-10-16 06:54:24 -07:00
|
|
|
|
|
|
|
val edit_distance : string -> string -> int -> int option
|
|
|
|
(** [edit_distance a b cutoff] computes the edit distance between
|
|
|
|
strings [a] and [b]. To help efficiency, it uses a cutoff: if the
|
|
|
|
distance [d] is smaller than [cutoff], it returns [Some d], else
|
|
|
|
[None].
|
|
|
|
|
|
|
|
The distance algorithm currently used is Damerau-Levenshtein: it
|
|
|
|
computes the number of insertion, deletion, substitution of
|
|
|
|
letters, or swapping of adjacent letters to go from one word to the
|
|
|
|
other. The particular algorithm may change in the future.
|
|
|
|
*)
|