Commit | Line | Data |
---|---|---|
34e49164 C |
1 | (*###########################################################################*) |
2 | (* Globals *) | |
3 | (*###########################################################################*) | |
4 | ||
5 | (* Some conventions: | |
6 | * | |
ae4735db C |
7 | * When I have some _xxx variables before some functions, it's |
8 | * because I want to show that those functions internally use a global | |
34e49164 C |
9 | * variable. That does not mean I want people to modify this global. |
10 | * In fact they are kind of private, but I still want to show them. | |
11 | * Maybe one day OCaml will have an effect type system so I don't need this. | |
ae4735db C |
12 | * |
13 | * The variables that are called _init_xxx show the internal init | |
34e49164 | 14 | * side effect of the module (like static var trick used in C/C++) |
ae4735db | 15 | * |
34e49164 | 16 | * Why not split the functionnalities of this file in different files ? |
ae4735db | 17 | * Because when I write ocaml script I want simply to load one |
34e49164 C |
18 | * file, common.ml, and that's it. Cf common_extra.ml for more on this. |
19 | *) | |
20 | ||
21 | ||
22 | (*****************************************************************************) | |
23 | (* Flags *) | |
24 | (*****************************************************************************) | |
ae4735db | 25 | (* see the corresponding section for the use of those flags. See also |
34e49164 C |
26 | * the "Flags and actions" section at the end of this file. |
27 | *) | |
28 | ||
29 | (* if set then will not do certain finalize so faster to go back in replay *) | |
30 | val debugger : bool ref | |
31 | ||
32 | type prof = PALL | PNONE | PSOME of string list | |
33 | val profile : prof ref | |
485bce71 C |
34 | val show_trace_profile : bool ref |
35 | ||
34e49164 C |
36 | |
37 | val verbose_level : int ref | |
38 | ||
39 | (* forbid pr2_once to do the once "optimisation" *) | |
40 | val disable_pr2_once : bool ref | |
41 | ||
42 | ||
43 | ||
44 | (* works with new_temp_file *) | |
45 | val save_tmp_files : bool ref | |
46 | ||
47 | ||
48 | ||
49 | (*****************************************************************************) | |
50 | (* Module side effect *) | |
51 | (*****************************************************************************) | |
ae4735db | 52 | (* |
34e49164 C |
53 | * I define a few unit tests via some let _ = example (... = ...). |
54 | * I also initialize the random seed, cf _init_random . | |
55 | * I also set Gc.stack_size, cf _init_gc_stack . | |
56 | *) | |
57 | ||
58 | (*****************************************************************************) | |
59 | (* Semi globals *) | |
60 | (*****************************************************************************) | |
61 | (* cf the _xxx variables in this file *) | |
62 | ||
63 | (*###########################################################################*) | |
64 | (* Basic features *) | |
65 | (*###########################################################################*) | |
66 | ||
67 | type filename = string | |
485bce71 | 68 | type dirname = string |
34e49164 C |
69 | |
70 | (* Trick in case you dont want to do an 'open Common' while still wanting | |
71 | * more pervasive types than the one in Pervasives. Just do the selective | |
72 | * open Common.BasicType. | |
73 | *) | |
74 | module BasicType : sig | |
75 | type filename = string | |
76 | end | |
77 | ||
78 | (* Same spirit. Trick found in Jane Street core lib, but originated somewhere | |
79 | * else I think: the ability to open nested modules. *) | |
80 | module Infix : sig | |
81 | val ( +> ) : 'a -> ('a -> 'b) -> 'b | |
82 | val ( =~ ) : string -> string -> bool | |
83 | val ( ==~ ) : string -> Str.regexp -> bool | |
84 | end | |
85 | ||
86 | ||
87 | (* | |
88 | * Another related trick, found via Jon Harrop to have an extended standard | |
89 | * lib is to do something like | |
ae4735db | 90 | * |
34e49164 C |
91 | * module List = struct |
92 | * include List | |
93 | * val map2 : ... | |
94 | * end | |
ae4735db | 95 | * |
34e49164 C |
96 | * And then can put this "module extension" somewhere to open it. |
97 | *) | |
98 | ||
99 | ||
100 | ||
ae4735db C |
101 | (* This module defines the Timeout and UnixExit exceptions. |
102 | * You have to make sure that those exn are not intercepted. So | |
34e49164 | 103 | * avoid exn handler such as try (...) with _ -> cos Timeout will not bubble up |
ae4735db C |
104 | * enough. In such case, add a case before such as |
105 | * with Timeout -> raise Timeout | _ -> ... | |
34e49164 C |
106 | * The same is true for UnixExit (see below). |
107 | *) | |
108 | ||
109 | (*****************************************************************************) | |
110 | (* Debugging/logging *) | |
111 | (*****************************************************************************) | |
112 | ||
113 | val _tab_level_print: int ref | |
114 | val indent_do : (unit -> 'a) -> 'a | |
115 | val reset_pr_indent : unit -> unit | |
116 | ||
117 | (* The following functions first indent _tab_level_print spaces. | |
118 | * They also add the _prefix_pr, for instance used in MPI to show which | |
119 | * worker is talking. | |
708f4980 | 120 | * update: for pr2, it can also print into a log file. |
ae4735db | 121 | * |
34e49164 | 122 | * The use of 2 in pr2 is because 2 is under UNIX the second descriptor |
ae4735db | 123 | * which corresponds to stderr. |
34e49164 C |
124 | *) |
125 | val _prefix_pr : string ref | |
708f4980 | 126 | |
34e49164 | 127 | val pr : string -> unit |
34e49164 | 128 | val pr_no_nl : string -> unit |
34e49164 | 129 | val pr_xxxxxxxxxxxxxxxxx : unit -> unit |
708f4980 C |
130 | |
131 | (* pr2 print on stderr, but can also in addition print into a file *) | |
132 | val _chan_pr2: out_channel option ref | |
ae4735db | 133 | val print_to_stderr : bool ref |
708f4980 C |
134 | val pr2 : string -> unit |
135 | val pr2_no_nl : string -> unit | |
34e49164 C |
136 | val pr2_xxxxxxxxxxxxxxxxx : unit -> unit |
137 | ||
138 | (* use Dumper.dump *) | |
139 | val pr2_gen: 'a -> unit | |
140 | val dump: 'a -> string | |
141 | ||
142 | (* see flag: val disable_pr2_once : bool ref *) | |
143 | val _already_printed : (string, bool) Hashtbl.t | |
144 | val pr2_once : string -> unit | |
145 | ||
708f4980 C |
146 | val mk_pr2_wrappers: bool ref -> (string -> unit) * (string -> unit) |
147 | ||
148 | ||
978fd7e5 | 149 | val redirect_stdout_opt : filename option -> (unit -> 'a) -> 'a |
34e49164 C |
150 | val redirect_stdout_stderr : filename -> (unit -> unit) -> unit |
151 | val redirect_stdin : filename -> (unit -> unit) -> unit | |
152 | val redirect_stdin_opt : filename option -> (unit -> unit) -> unit | |
153 | ||
708f4980 C |
154 | val with_pr2_to_string: (unit -> unit) -> string list |
155 | ||
34e49164 C |
156 | val fprintf : out_channel -> ('a, out_channel, unit) format -> 'a |
157 | val printf : ('a, out_channel, unit) format -> 'a | |
158 | val eprintf : ('a, out_channel, unit) format -> 'a | |
159 | val sprintf : ('a, unit, string) format -> 'a | |
160 | ||
161 | (* alias *) | |
162 | val spf : ('a, unit, string) format -> 'a | |
163 | ||
164 | (* default = stderr *) | |
ae4735db | 165 | val _chan : out_channel ref |
34e49164 | 166 | (* generate & use a /tmp/debugml-xxx file *) |
ae4735db | 167 | val start_log_file : unit -> unit |
34e49164 C |
168 | |
169 | (* see flag: val verbose_level : int ref *) | |
170 | val log : string -> unit | |
171 | val log2 : string -> unit | |
172 | val log3 : string -> unit | |
173 | val log4 : string -> unit | |
174 | ||
175 | val if_log : (unit -> unit) -> unit | |
176 | val if_log2 : (unit -> unit) -> unit | |
177 | val if_log3 : (unit -> unit) -> unit | |
178 | val if_log4 : (unit -> unit) -> unit | |
179 | ||
180 | val pause : unit -> unit | |
181 | ||
182 | (* was used by fix_caml *) | |
183 | val _trace_var : int ref | |
184 | val add_var : unit -> unit | |
185 | val dec_var : unit -> unit | |
186 | val get_var : unit -> int | |
187 | ||
188 | val print_n : int -> string -> unit | |
189 | val printerr_n : int -> string -> unit | |
190 | ||
191 | val _debug : bool ref | |
192 | val debugon : unit -> unit | |
193 | val debugoff : unit -> unit | |
194 | val debug : (unit -> unit) -> unit | |
195 | ||
196 | (* see flag: val debugger : bool ref *) | |
197 | ||
198 | ||
199 | (*****************************************************************************) | |
200 | (* Profiling (cpu/mem) *) | |
201 | (*****************************************************************************) | |
202 | ||
203 | val get_mem : unit -> unit | |
204 | val memory_stat : unit -> string | |
205 | ||
206 | val timenow : unit -> string | |
207 | ||
208 | val _count1 : int ref | |
209 | val _count2 : int ref | |
210 | val _count3 : int ref | |
211 | val _count4 : int ref | |
212 | val _count5 : int ref | |
213 | ||
214 | val count1 : unit -> unit | |
215 | val count2 : unit -> unit | |
216 | val count3 : unit -> unit | |
217 | val count4 : unit -> unit | |
218 | val count5 : unit -> unit | |
219 | val profile_diagnostic_basic : unit -> string | |
220 | ||
221 | val time_func : (unit -> 'a) -> 'a | |
222 | ||
223 | ||
224 | ||
225 | (* see flag: type prof = PALL | PNONE | PSOME of string list *) | |
226 | (* see flag: val profile : prof ref *) | |
227 | ||
228 | val _profile_table : (string, (float ref * int ref)) Hashtbl.t ref | |
229 | val profile_code : string -> (unit -> 'a) -> 'a | |
230 | val profile_diagnostic : unit -> string | |
231 | ||
485bce71 C |
232 | val profile_code_exclusif : string -> (unit -> 'a) -> 'a |
233 | val profile_code_inside_exclusif_ok : string -> (unit -> 'a) -> 'a | |
234 | ||
34e49164 C |
235 | val report_if_take_time : int -> string -> (unit -> 'a) -> 'a |
236 | ||
237 | (* similar to profile_code but print some information during execution too *) | |
238 | val profile_code2 : string -> (unit -> 'a) -> 'a | |
239 | ||
240 | (*****************************************************************************) | |
241 | (* Test *) | |
242 | (*****************************************************************************) | |
243 | ||
244 | val example : bool -> unit | |
245 | (* generate failwith <string> when pb *) | |
ae4735db | 246 | val example2 : string -> bool -> unit |
34e49164 | 247 | (* use Dumper to report when pb *) |
ae4735db | 248 | val assert_equal : 'a -> 'a -> unit |
34e49164 C |
249 | |
250 | val _list_bool : (string * bool) list ref | |
251 | val example3 : string -> bool -> unit | |
252 | val test_all : unit -> unit | |
253 | ||
b1b2de81 | 254 | |
34e49164 | 255 | (* regression testing *) |
ae4735db | 256 | type score_result = Ok | Pb of string |
b1b2de81 C |
257 | type score = (string (* usually a filename *), score_result) Hashtbl.t |
258 | type score_list = (string (* usually a filename *) * score_result) list | |
34e49164 | 259 | val empty_score : unit -> score |
ae4735db | 260 | val regression_testing : |
34e49164 | 261 | score -> filename (* old score file on disk (usually in /tmp) *) -> unit |
b1b2de81 C |
262 | val regression_testing_vs: score -> score -> score |
263 | val total_scores : score -> int (* good *) * int (* total *) | |
34e49164 | 264 | val print_score : score -> unit |
b1b2de81 | 265 | val print_total_score: score -> unit |
34e49164 C |
266 | |
267 | ||
268 | (* quickcheck spirit *) | |
269 | type 'a gen = unit -> 'a | |
270 | ||
271 | (* quickcheck random generators *) | |
272 | val ig : int gen | |
273 | val lg : 'a gen -> 'a list gen | |
274 | val pg : 'a gen -> 'b gen -> ('a * 'b) gen | |
275 | val polyg : int gen | |
276 | val ng : string gen | |
277 | ||
278 | val oneofl : 'a list -> 'a gen | |
279 | val oneof : 'a gen list -> 'a gen | |
280 | val always : 'a -> 'a gen | |
281 | val frequency : (int * 'a gen) list -> 'a gen | |
282 | val frequencyl : (int * 'a) list -> 'a gen | |
283 | ||
284 | val laws : string -> ('a -> bool) -> 'a gen -> 'a option | |
285 | ||
ae4735db | 286 | (* example of use: |
34e49164 C |
287 | * let b = laws "unit" (fun x -> reverse [x] = [x]) ig |
288 | *) | |
289 | ||
290 | val statistic_number : 'a list -> (int * 'a) list | |
291 | val statistic : 'a list -> (int * 'a) list | |
292 | ||
293 | val laws2 : | |
294 | string -> ('a -> bool * 'b) -> 'a gen -> 'a option * (int * 'b) list | |
295 | ||
296 | (*****************************************************************************) | |
297 | (* Persistence *) | |
298 | (*****************************************************************************) | |
299 | ||
0708f913 | 300 | (* just wrappers around Marshal *) |
34e49164 | 301 | val get_value : filename -> 'a |
485bce71 | 302 | val read_value : filename -> 'a (* alias *) |
34e49164 C |
303 | val write_value : 'a -> filename -> unit |
304 | val write_back : ('a -> 'b) -> filename -> unit | |
305 | ||
0708f913 C |
306 | (* wrappers that also use profile_code *) |
307 | val marshal__to_string: 'a -> Marshal.extern_flags list -> string | |
308 | val marshal__from_string: string -> int -> 'a | |
309 | ||
34e49164 C |
310 | (*****************************************************************************) |
311 | (* Counter *) | |
312 | (*****************************************************************************) | |
313 | val _counter : int ref | |
314 | val _counter2 : int ref | |
315 | val _counter3 : int ref | |
316 | ||
317 | val counter : unit -> int | |
318 | val counter2 : unit -> int | |
319 | val counter3 : unit -> int | |
320 | ||
321 | type timestamp = int | |
322 | ||
323 | (*****************************************************************************) | |
324 | (* String_of and (pretty) printing *) | |
325 | (*****************************************************************************) | |
326 | ||
327 | val string_of_string : (string -> string) -> string | |
328 | val string_of_list : ('a -> string) -> 'a list -> string | |
329 | val string_of_unit : unit -> string | |
330 | val string_of_array : ('a -> string) -> 'a array -> string | |
331 | val string_of_option : ('a -> string) -> 'a option -> string | |
332 | ||
333 | val print_bool : bool -> unit | |
334 | val print_option : ('a -> 'b) -> 'a option -> unit | |
335 | val print_list : ('a -> 'b) -> 'a list -> unit | |
336 | val print_between : (unit -> unit) -> ('a -> unit) -> 'a list -> unit | |
337 | ||
338 | (* use Format internally *) | |
339 | val pp_do_in_box : (unit -> unit) -> unit | |
340 | val pp_f_in_box : (unit -> 'a) -> 'a | |
341 | val pp_do_in_zero_box : (unit -> unit) -> unit | |
342 | val pp : string -> unit | |
343 | ||
344 | (* convert something printed using Format to print into a string *) | |
345 | val format_to_string : (unit -> unit) (* printer *) -> string | |
346 | ||
347 | (* works with _tab_level_print enabling to mix some calls to pp, pr2 | |
348 | * and indent_do to sometimes use advanced indentation pretty printing | |
349 | * (with the pp* functions) and sometimes explicit and simple indendation | |
350 | * printing (with pr* and indent_do) *) | |
351 | val adjust_pp_with_indent : (unit -> unit) -> unit | |
352 | val adjust_pp_with_indent_and_header : string -> (unit -> unit) -> unit | |
353 | ||
0708f913 | 354 | |
ae4735db | 355 | val mk_str_func_of_assoc_conv: |
0708f913 C |
356 | ('a * string) list -> (string -> 'a) * ('a -> string) |
357 | ||
34e49164 C |
358 | (*****************************************************************************) |
359 | (* Macro *) | |
360 | (*****************************************************************************) | |
361 | ||
362 | (* was working with my macro.ml4 *) | |
363 | val macro_expand : string -> unit | |
364 | ||
365 | (*****************************************************************************) | |
366 | (* Composition/Control *) | |
367 | (*****************************************************************************) | |
368 | ||
369 | val ( +> ) : 'a -> ('a -> 'b) -> 'b | |
370 | val ( +!> ) : 'a ref -> ('a -> 'a) -> unit | |
371 | val ( $ ) : ('a -> 'b) -> ('b -> 'c) -> 'a -> 'c | |
372 | ||
373 | val compose : ('a -> 'b) -> ('c -> 'a) -> 'c -> 'b | |
374 | val flip : ('a -> 'b -> 'c) -> 'b -> 'a -> 'c | |
375 | ||
376 | val curry : ('a * 'b -> 'c) -> 'a -> 'b -> 'c | |
377 | val uncurry : ('a -> 'b -> 'c) -> 'a * 'b -> 'c | |
378 | ||
379 | val id : 'a -> 'a | |
380 | val do_nothing : unit -> unit | |
381 | ||
382 | val forever : (unit -> unit) -> unit | |
383 | ||
384 | val applyn : int -> ('a -> 'a) -> 'a -> 'a | |
385 | ||
386 | class ['a] shared_variable_hook : | |
387 | 'a -> | |
388 | object | |
389 | val mutable data : 'a | |
390 | val mutable registered : (unit -> unit) list | |
391 | method get : 'a | |
392 | method modify : ('a -> 'a) -> unit | |
393 | method register : (unit -> unit) -> unit | |
394 | method set : 'a -> unit | |
395 | end | |
396 | ||
397 | val fixpoint : ('a -> 'a) -> 'a -> 'a | |
398 | val fixpoint_for_object : ((< equal : 'a -> bool; .. > as 'a) -> 'a) -> 'a -> 'a | |
399 | ||
400 | val add_hook : ('a -> ('a -> 'b) -> 'b) ref -> ('a -> ('a -> 'b) -> 'b) -> unit | |
401 | val add_hook_action : ('a -> unit) -> ('a -> unit) list ref -> unit | |
402 | val run_hooks_action : 'a -> ('a -> unit) list ref -> unit | |
403 | ||
404 | type 'a mylazy = (unit -> 'a) | |
405 | ||
406 | (* emacs spirit *) | |
407 | val save_excursion : 'a ref -> (unit -> 'b) -> 'b | |
708f4980 C |
408 | val save_excursion_and_disable : bool ref -> (unit -> 'b) -> 'b |
409 | val save_excursion_and_enable : bool ref -> (unit -> 'b) -> 'b | |
34e49164 C |
410 | |
411 | (* emacs spirit *) | |
412 | val unwind_protect : (unit -> 'a) -> (exn -> 'b) -> 'a | |
413 | ||
414 | (* java spirit *) | |
415 | val finalize : (unit -> 'a) -> (unit -> 'b) -> 'a | |
416 | ||
417 | val memoized : ('a, 'b) Hashtbl.t -> 'a -> (unit -> 'b) -> 'b | |
418 | ||
91eba41f C |
419 | val cache_in_ref : 'a option ref -> (unit -> 'a) -> 'a |
420 | ||
34e49164 C |
421 | |
422 | (* take file from which computation is done, an extension, and the function | |
ae4735db | 423 | * and will compute the function only once and then save result in |
34e49164 C |
424 | * file ^ extension |
425 | *) | |
ae4735db C |
426 | val cache_computation : |
427 | ?verbose:bool -> ?use_cache:bool -> filename -> string (* extension *) -> | |
34e49164 C |
428 | (unit -> 'a) -> 'a |
429 | ||
ae4735db C |
430 | (* a more robust version where the client describes the dependencies of the |
431 | * computation so it will relaunch the computation in 'f' if needed. | |
34e49164 C |
432 | *) |
433 | val cache_computation_robust : | |
ae4735db C |
434 | filename -> |
435 | string (* extension for marshalled object *) -> | |
436 | (filename list * 'x) -> | |
437 | string (* extension for marshalled dependencies *) -> | |
438 | (unit -> 'a) -> | |
34e49164 | 439 | 'a |
ae4735db | 440 | |
34e49164 C |
441 | |
442 | ||
443 | val once : ('a -> unit) -> ('a -> unit) | |
444 | ||
445 | val before_leaving : ('a -> unit) -> 'a -> 'a | |
446 | ||
447 | (* do some finalize, signal handling, unix exit conversion, etc *) | |
448 | val main_boilerplate : (unit -> unit) -> unit | |
449 | ||
450 | ||
451 | (* cf also the timeout function below that are control related too *) | |
452 | ||
453 | ||
454 | (*****************************************************************************) | |
455 | (* Concurrency *) | |
456 | (*****************************************************************************) | |
457 | ||
458 | (* how ensure really atomic file creation ? hehe :) *) | |
ae4735db | 459 | exception FileAlreadyLocked |
34e49164 C |
460 | val acquire_file_lock : filename -> unit |
461 | val release_file_lock : filename -> unit | |
462 | ||
463 | (*****************************************************************************) | |
464 | (* Error managment *) | |
465 | (*****************************************************************************) | |
466 | exception Todo | |
467 | exception Impossible | |
468 | exception Here | |
469 | exception ReturnExn | |
470 | ||
0708f913 | 471 | exception Multi_found |
91eba41f | 472 | |
34e49164 C |
473 | exception WrongFormat of string |
474 | ||
475 | ||
476 | val internal_error : string -> 'a | |
477 | val myassert : bool -> unit | |
478 | val warning : string -> 'a -> 'a | |
479 | val error_cant_have : 'a -> 'b | |
480 | ||
481 | val exn_to_s : exn -> string | |
91eba41f C |
482 | (* alias *) |
483 | val string_of_exn : exn -> string | |
34e49164 | 484 | |
ae4735db | 485 | type error = Error of string |
b1b2de81 C |
486 | |
487 | type evotype = unit | |
488 | val evoval : evotype | |
489 | ||
34e49164 C |
490 | (*****************************************************************************) |
491 | (* Environment *) | |
492 | (*****************************************************************************) | |
493 | ||
494 | val check_stack_size: int -> unit | |
495 | val check_stack_nbfiles: int -> unit | |
ae4735db | 496 | |
34e49164 C |
497 | (* internally common.ml set Gc. parameters *) |
498 | val _init_gc_stack : unit | |
499 | ||
500 | (*****************************************************************************) | |
501 | (* Arguments and command line *) | |
502 | (*****************************************************************************) | |
503 | ||
504 | type arg_spec_full = Arg.key * Arg.spec * Arg.doc | |
505 | type cmdline_options = arg_spec_full list | |
506 | ||
507 | ||
508 | type options_with_title = string * string * arg_spec_full list | |
509 | type cmdline_sections = options_with_title list | |
510 | ||
511 | ||
ae4735db | 512 | (* A wrapper around Arg modules that have more logical argument order, |
34e49164 C |
513 | * and returns the remaining args. |
514 | *) | |
ae4735db | 515 | val parse_options : |
34e49164 C |
516 | cmdline_options -> Arg.usage_msg -> string array -> string list |
517 | ||
518 | (* Another wrapper that does Arg.align automatically *) | |
519 | val usage : Arg.usage_msg -> cmdline_options -> unit | |
520 | ||
521 | ||
522 | ||
523 | (* Work with the options_with_title type way to organize a long | |
524 | * list of command line switches. | |
525 | *) | |
ae4735db | 526 | val short_usage : |
34e49164 | 527 | Arg.usage_msg -> short_opt:cmdline_options -> unit |
ae4735db C |
528 | val long_usage : |
529 | Arg.usage_msg -> short_opt:cmdline_options -> long_opt:cmdline_sections -> | |
34e49164 C |
530 | unit |
531 | ||
532 | (* With the options_with_title way, we don't want the default -help and --help | |
533 | * so need adapter of Arg module, not just wrapper. | |
534 | *) | |
535 | val arg_align2 : cmdline_options -> cmdline_options | |
ae4735db C |
536 | val arg_parse2 : |
537 | cmdline_options -> Arg.usage_msg -> (unit -> unit) (* short_usage func *) -> | |
34e49164 C |
538 | string list |
539 | ||
540 | ||
541 | ||
542 | ||
543 | ||
544 | (* The action lib. Useful to debug supart of your system. cf some of | |
545 | * my main.ml for example of use. *) | |
546 | type flag_spec = Arg.key * Arg.spec * Arg.doc | |
ae4735db | 547 | type action_spec = Arg.key * Arg.doc * action_func |
34e49164 C |
548 | and action_func = (string list -> unit) |
549 | ||
550 | type cmdline_actions = action_spec list | |
551 | exception WrongNumberOfArguments | |
552 | ||
553 | val mk_action_0_arg : (unit -> unit) -> action_func | |
554 | val mk_action_1_arg : (string -> unit) -> action_func | |
555 | val mk_action_2_arg : (string -> string -> unit) -> action_func | |
556 | val mk_action_3_arg : (string -> string -> string -> unit) -> action_func | |
557 | ||
558 | val mk_action_n_arg : (string list -> unit) -> action_func | |
559 | ||
ae4735db | 560 | val options_of_actions: |
34e49164 | 561 | string ref (* the action ref *) -> cmdline_actions -> cmdline_options |
ae4735db | 562 | val action_list: |
34e49164 | 563 | cmdline_actions -> Arg.key list |
ae4735db | 564 | val do_action: |
34e49164 C |
565 | Arg.key -> string list (* args *) -> cmdline_actions -> unit |
566 | ||
567 | (*****************************************************************************) | |
568 | (* Equality *) | |
569 | (*****************************************************************************) | |
570 | ||
571 | (* Using the generic (=) is tempting, but it backfires, so better avoid it *) | |
572 | ||
573 | (* To infer all the code that use an equal, and that should be | |
574 | * transformed, is not that easy, because (=) is used by many | |
575 | * functions, such as List.find, List.mem, and so on. The strategy to find | |
576 | * them is to turn what you were previously using into a function, because | |
577 | * (=) return an exception when applied to a function, then you simply | |
578 | * use ocamldebug to detect where the code has to be transformed by | |
579 | * finding where the exception was launched from. | |
580 | *) | |
581 | ||
582 | val (=|=) : int -> int -> bool | |
583 | val (=<=) : char -> char -> bool | |
584 | val (=$=) : string -> string -> bool | |
585 | val (=:=) : bool -> bool -> bool | |
586 | ||
587 | val (=*=): 'a -> 'a -> bool | |
588 | ||
589 | (* if want to restrict the use of '=', uncomment this: | |
590 | * | |
b1b2de81 | 591 | * val (=): unit -> unit -> bool |
ae4735db | 592 | * |
34e49164 C |
593 | * But it will not forbid you to use caml functions like List.find, List.mem |
594 | * which internaly use this convenient but evolution-unfriendly (=) | |
595 | *) | |
596 | ||
597 | ||
598 | ||
34e49164 C |
599 | (*###########################################################################*) |
600 | (* And now basic types *) | |
601 | (*###########################################################################*) | |
602 | ||
603 | (*****************************************************************************) | |
604 | (* Bool *) | |
605 | (*****************************************************************************) | |
606 | ||
607 | val ( ||| ) : 'a -> 'a -> 'a | |
608 | val ( ==> ) : bool -> bool -> bool | |
609 | val xor : 'a -> 'a -> bool | |
610 | ||
611 | ||
0708f913 | 612 | |
34e49164 C |
613 | (*****************************************************************************) |
614 | (* Char *) | |
615 | (*****************************************************************************) | |
616 | ||
617 | val string_of_char : char -> string | |
618 | val string_of_chars : char list -> string | |
619 | ||
620 | val is_single : char -> bool | |
621 | val is_symbol : char -> bool | |
622 | val is_space : char -> bool | |
623 | val is_upper : char -> bool | |
624 | val is_lower : char -> bool | |
625 | val is_alpha : char -> bool | |
626 | val is_digit : char -> bool | |
627 | ||
628 | val cbetween : char -> char -> char -> bool | |
629 | ||
630 | (*****************************************************************************) | |
631 | (* Num *) | |
632 | (*****************************************************************************) | |
633 | ||
634 | val ( /! ) : int -> int -> int | |
635 | ||
636 | val do_n : int -> (unit -> unit) -> unit | |
637 | val foldn : ('a -> int -> 'a) -> 'a -> int -> 'a | |
638 | ||
34e49164 C |
639 | val pi : float |
640 | val pi2 : float | |
641 | val pi4 : float | |
642 | ||
643 | val deg_to_rad : float -> float | |
644 | ||
645 | val clampf : float -> float | |
646 | ||
647 | val square : float -> float | |
648 | val power : int -> int -> int | |
649 | ||
650 | val between : 'a -> 'a -> 'a -> bool | |
651 | val between_strict : int -> int -> int -> bool | |
652 | val bitrange : int -> int -> bool | |
653 | ||
654 | val prime1 : int -> int option | |
655 | val prime : int -> int option | |
656 | ||
657 | val sum : int list -> int | |
658 | val product : int list -> int | |
659 | ||
660 | val decompose : int -> int list | |
661 | ||
662 | val mysquare : int -> int | |
663 | val sqr : float -> float | |
664 | ||
665 | type compare = Equal | Inf | Sup | |
666 | val ( <=> ) : 'a -> 'a -> compare | |
667 | val ( <==> ) : 'a -> 'a -> int | |
668 | ||
669 | type uint = int | |
670 | ||
671 | val int_of_stringchar : string -> int | |
672 | val int_of_base : string -> int -> int | |
673 | val int_of_stringbits : string -> int | |
674 | val int_of_octal : string -> int | |
675 | val int_of_all : string -> int | |
676 | ||
677 | (* useful but sometimes when want grep for all places where do modif, | |
678 | * easier to have just code using ':=' and '<-' to do some modifications. | |
679 | * In the same way avoid using {contents = xxx} to build some ref. | |
680 | *) | |
681 | val ( += ) : int ref -> int -> unit | |
682 | val ( -= ) : int ref -> int -> unit | |
683 | ||
ae4735db | 684 | val pourcent: int -> int -> int |
34e49164 C |
685 | val pourcent_float: int -> int -> float |
686 | val pourcent_float_of_floats: float -> float -> float | |
687 | ||
91eba41f C |
688 | val pourcent_good_bad: int -> int -> int |
689 | val pourcent_good_bad_float: int -> int -> float | |
690 | ||
691 | type 'a max_with_elem = int ref * 'a ref | |
ae4735db | 692 | val update_max_with_elem: |
91eba41f | 693 | 'a max_with_elem -> is_better:(int -> int ref -> bool) -> int * 'a -> unit |
34e49164 C |
694 | (*****************************************************************************) |
695 | (* Numeric/overloading *) | |
696 | (*****************************************************************************) | |
697 | ||
698 | type 'a numdict = | |
699 | NumDict of | |
700 | (('a -> 'a -> 'a) * ('a -> 'a -> 'a) * ('a -> 'a -> 'a) * ('a -> 'a)) | |
701 | val add : 'a numdict -> 'a -> 'a -> 'a | |
702 | val mul : 'a numdict -> 'a -> 'a -> 'a | |
703 | val div : 'a numdict -> 'a -> 'a -> 'a | |
704 | val neg : 'a numdict -> 'a -> 'a | |
705 | ||
706 | val numd_int : int numdict | |
707 | val numd_float : float numdict | |
708 | ||
709 | val testd : 'a numdict -> 'a -> 'a | |
710 | ||
711 | ||
ae4735db | 712 | module ArithFloatInfix : sig |
34e49164 C |
713 | val (+) : float -> float -> float |
714 | val (-) : float -> float -> float | |
715 | val (/) : float -> float -> float | |
716 | val ( * ) : float -> float -> float | |
717 | ||
718 | ||
719 | val (+..) : int -> int -> int | |
720 | val (-..) : int -> int -> int | |
721 | val (/..) : int -> int -> int | |
722 | val ( *..) : int -> int -> int | |
723 | ||
724 | val (+=) : float ref -> float -> unit | |
725 | end | |
726 | ||
727 | (*****************************************************************************) | |
728 | (* Random *) | |
729 | (*****************************************************************************) | |
730 | ||
731 | val _init_random : unit | |
732 | val random_list : 'a list -> 'a | |
733 | val randomize_list : 'a list -> 'a list | |
734 | val random_subset_of_list : int -> 'a list -> 'a list | |
735 | ||
736 | ||
737 | (*****************************************************************************) | |
738 | (* Tuples *) | |
739 | (*****************************************************************************) | |
740 | ||
741 | type 'a pair = 'a * 'a | |
742 | type 'a triple = 'a * 'a * 'a | |
743 | ||
744 | val fst3 : 'a * 'b * 'c -> 'a | |
745 | val snd3 : 'a * 'b * 'c -> 'b | |
746 | val thd3 : 'a * 'b * 'c -> 'c | |
747 | ||
748 | val sndthd : 'a * 'b * 'c -> 'b * 'c | |
749 | ||
750 | val map_fst : ('a -> 'b) -> 'a * 'c -> 'b * 'c | |
751 | val map_snd : ('a -> 'b) -> 'c * 'a -> 'c * 'b | |
752 | ||
753 | val pair : ('a -> 'b) -> 'a * 'a -> 'b * 'b | |
754 | ||
755 | val snd : 'a * 'b -> 'b (* alias *) | |
756 | val fst : 'a * 'b -> 'a (* alias *) | |
757 | ||
758 | val double : 'a -> 'a * 'a | |
759 | val swap : 'a * 'b -> 'b * 'a | |
760 | ||
761 | (* maybe a sign of bad programming if use those functions :) *) | |
762 | val tuple_of_list1 : 'a list -> 'a | |
763 | val tuple_of_list2 : 'a list -> 'a * 'a | |
764 | val tuple_of_list3 : 'a list -> 'a * 'a * 'a | |
765 | val tuple_of_list4 : 'a list -> 'a * 'a * 'a * 'a | |
766 | val tuple_of_list5 : 'a list -> 'a * 'a * 'a * 'a * 'a | |
767 | val tuple_of_list6 : 'a list -> 'a * 'a * 'a * 'a * 'a * 'a | |
768 | ||
769 | (*****************************************************************************) | |
770 | (* Maybe *) | |
771 | (*****************************************************************************) | |
772 | ||
773 | type ('a, 'b) either = Left of 'a | Right of 'b | |
774 | type ('a, 'b, 'c) either3 = Left3 of 'a | Middle3 of 'b | Right3 of 'c | |
775 | ||
776 | val just : 'a option -> 'a | |
777 | val some : 'a option -> 'a (* alias *) | |
778 | ||
779 | val fmap : ('a -> 'b) -> 'a option -> 'b option | |
780 | val map_option : ('a -> 'b) -> 'a option -> 'b option (* alias *) | |
781 | ||
782 | val do_option : ('a -> unit) -> 'a option -> unit | |
783 | ||
784 | val optionise : (unit -> 'a) -> 'a option | |
785 | ||
786 | val some_or : 'a option -> 'a -> 'a | |
787 | ||
788 | val partition_either : | |
789 | ('a -> ('b, 'c) either) -> 'a list -> 'b list * 'c list | |
978fd7e5 C |
790 | val partition_either3 : |
791 | ('a -> ('b, 'c, 'd) either3) -> 'a list -> 'b list * 'c list * 'd list | |
34e49164 C |
792 | |
793 | val filter_some : 'a option list -> 'a list | |
794 | val map_filter : ('a -> 'b option) -> 'a list -> 'b list | |
795 | val find_some : ('a -> 'b option) -> 'a list -> 'b | |
796 | ||
0708f913 C |
797 | val list_to_single_or_exn: 'a list -> 'a |
798 | ||
799 | (*****************************************************************************) | |
800 | (* TriBool *) | |
801 | (*****************************************************************************) | |
802 | type bool3 = True3 | False3 | TrueFalsePb3 of string | |
803 | ||
804 | ||
34e49164 C |
805 | (*****************************************************************************) |
806 | (* Strings *) | |
807 | (*****************************************************************************) | |
808 | ||
809 | val slength : string -> int (* alias *) | |
810 | val concat : string -> string list -> string (* alias *) | |
811 | ||
812 | val i_to_s : int -> string | |
813 | val s_to_i : string -> int | |
814 | ||
815 | (* strings take space in memory. Better when can share the space used by | |
816 | * similar strings. | |
817 | *) | |
818 | val _shareds : (string, string) Hashtbl.t | |
819 | val shared_string : string -> string | |
820 | ||
821 | val chop : string -> string | |
822 | val chop_dirsymbol : string -> string | |
823 | ||
824 | val ( <!!> ) : string -> int * int -> string | |
825 | val ( <!> ) : string -> int -> char | |
826 | ||
91eba41f C |
827 | val take_string: int -> string -> string |
828 | val take_string_safe: int -> string -> string | |
829 | ||
34e49164 C |
830 | val split_on_char : char -> string -> string list |
831 | ||
832 | val lowercase : string -> string | |
833 | ||
834 | val quote : string -> string | |
835 | ||
836 | val null_string : string -> bool | |
837 | val is_blank_string : string -> bool | |
838 | val is_string_prefix : string -> string -> bool | |
839 | ||
840 | ||
841 | val plural : int -> string -> string | |
842 | ||
843 | val showCodeHex : int list -> unit | |
844 | ||
845 | val size_mo_ko : int -> string | |
846 | val size_ko : int -> string | |
847 | ||
ae4735db | 848 | val edit_distance: string -> string -> int |
34e49164 | 849 | |
ae4735db | 850 | val md5sum_of_string : string -> string |
485bce71 | 851 | |
34e49164 C |
852 | (*****************************************************************************) |
853 | (* Regexp *) | |
854 | (*****************************************************************************) | |
855 | ||
856 | val regexp_alpha : Str.regexp | |
485bce71 | 857 | val regexp_word : Str.regexp |
34e49164 C |
858 | |
859 | val _memo_compiled_regexp : (string, Str.regexp) Hashtbl.t | |
860 | val ( =~ ) : string -> string -> bool | |
861 | val ( ==~ ) : string -> Str.regexp -> bool | |
862 | ||
863 | ||
864 | ||
865 | val regexp_match : string -> string -> string | |
866 | ||
867 | val matched : int -> string -> string | |
868 | ||
869 | (* not yet politypic functions in ocaml *) | |
870 | val matched1 : string -> string | |
871 | val matched2 : string -> string * string | |
872 | val matched3 : string -> string * string * string | |
873 | val matched4 : string -> string * string * string * string | |
874 | val matched5 : string -> string * string * string * string * string | |
875 | val matched6 : string -> string * string * string * string * string * string | |
876 | val matched7 : string -> string * string * string * string * string * string * string | |
877 | ||
878 | val string_match_substring : Str.regexp -> string -> bool | |
879 | ||
880 | val split : string (* sep regexp *) -> string -> string list | |
881 | val join : string (* sep *) -> string list -> string | |
882 | ||
883 | val split_list_regexp : string -> string list -> (string * string list) list | |
884 | ||
885 | val all_match : string (* regexp *) -> string -> string list | |
ae4735db | 886 | val global_replace_regexp : |
485bce71 C |
887 | string (* regexp *) -> (string -> string) -> string -> string |
888 | ||
889 | val regular_words: string -> string list | |
890 | val contain_regular_word: string -> bool | |
34e49164 C |
891 | |
892 | (*****************************************************************************) | |
893 | (* Filenames *) | |
894 | (*****************************************************************************) | |
895 | ||
896 | (* now at beginning of this file: type filename = string *) | |
897 | val dirname : string -> string | |
898 | val basename : string -> string | |
899 | ||
900 | val filesuffix : filename -> string | |
901 | val fileprefix : filename -> string | |
902 | ||
903 | val adjust_ext_if_needed : filename -> string -> filename | |
904 | ||
905 | (* db for dir, base *) | |
906 | val db_of_filename : filename -> (string * filename) | |
907 | val filename_of_db : (string * filename) -> filename | |
908 | ||
909 | (* dbe for dir, base, ext *) | |
910 | val dbe_of_filename : filename -> string * string * string | |
911 | val dbe_of_filename_nodot : filename -> string * string * string | |
912 | (* Left (d,b,e) | Right (d,b) if file has no extension *) | |
ae4735db | 913 | val dbe_of_filename_safe : |
34e49164 C |
914 | filename -> (string * string * string, string * string) either |
915 | ||
916 | val filename_of_dbe : string * string * string -> filename | |
917 | ||
918 | (* ex: replace_ext "toto.c" "c" "var" *) | |
919 | val replace_ext: filename -> string -> string -> filename | |
920 | ||
921 | (* remove the ., .. *) | |
922 | val normalize_path : filename -> filename | |
923 | ||
924 | val relative_to_absolute : filename -> filename | |
925 | ||
91eba41f C |
926 | val is_relative: filename -> bool |
927 | val is_absolute: filename -> bool | |
928 | ||
34e49164 C |
929 | val filename_without_leading_path : string -> filename -> filename |
930 | ||
931 | (*****************************************************************************) | |
932 | (* i18n *) | |
933 | (*****************************************************************************) | |
ae4735db | 934 | type langage = |
34e49164 C |
935 | | English |
936 | | Francais | |
937 | | Deutsch | |
938 | ||
939 | (*****************************************************************************) | |
940 | (* Dates *) | |
941 | (*****************************************************************************) | |
942 | ||
943 | (* can also use ocamlcalendar, but heavier, use many modules ... *) | |
944 | ||
ae4735db | 945 | type month = |
34e49164 C |
946 | | Jan | Feb | Mar | Apr | May | Jun |
947 | | Jul | Aug | Sep | Oct | Nov | Dec | |
948 | type year = Year of int | |
949 | type day = Day of int | |
950 | ||
951 | type date_dmy = DMY of day * month * year | |
952 | ||
953 | type hour = Hour of int | |
954 | type minute = Min of int | |
955 | type second = Sec of int | |
956 | ||
957 | type time_hms = HMS of hour * minute * second | |
958 | ||
959 | type full_date = date_dmy * time_hms | |
960 | ||
961 | ||
962 | (* intervalle *) | |
963 | type days = Days of int | |
964 | ||
965 | type time_dmy = TimeDMY of day * month * year | |
966 | ||
967 | ||
968 | (* from Unix *) | |
969 | type float_time = float | |
970 | ||
971 | ||
972 | val mk_date_dmy : int -> int -> int -> date_dmy | |
973 | ||
974 | ||
975 | val check_date_dmy : date_dmy -> unit | |
976 | val check_time_dmy : time_dmy -> unit | |
977 | val check_time_hms : time_hms -> unit | |
978 | ||
979 | val int_to_month : int -> string | |
980 | val int_of_month : month -> int | |
981 | val month_of_string : string -> month | |
982 | val month_of_string_long : string -> month | |
983 | val string_of_month : month -> string | |
984 | ||
985 | val string_of_date_dmy : date_dmy -> string | |
986 | val string_of_unix_time : ?langage:langage -> Unix.tm -> string | |
987 | val short_string_of_unix_time : ?langage:langage -> Unix.tm -> string | |
988 | val string_of_floattime: ?langage:langage -> float_time -> string | |
989 | val short_string_of_floattime: ?langage:langage -> float_time -> string | |
990 | ||
991 | val floattime_of_string: string -> float_time | |
992 | ||
993 | val dmy_to_unixtime: date_dmy -> float_time * Unix.tm | |
994 | val unixtime_to_dmy: Unix.tm -> date_dmy | |
995 | val unixtime_to_floattime: Unix.tm -> float_time | |
0708f913 | 996 | val floattime_to_unixtime: float_time -> Unix.tm |
34e49164 C |
997 | |
998 | val sec_to_days : int -> string | |
999 | val sec_to_hours : int -> string | |
1000 | ||
1001 | val today : unit -> float_time | |
1002 | val yesterday : unit -> float_time | |
1003 | val tomorrow : unit -> float_time | |
1004 | ||
1005 | val lastweek : unit -> float_time | |
1006 | val lastmonth : unit -> float_time | |
1007 | ||
1008 | val week_before: float_time -> float_time | |
1009 | val month_before: float_time -> float_time | |
1010 | val week_after: float_time -> float_time | |
1011 | ||
1012 | val days_in_week_of_day : float_time -> float_time list | |
1013 | ||
1014 | val first_day_in_week_of_day : float_time -> float_time | |
1015 | val last_day_in_week_of_day : float_time -> float_time | |
1016 | ||
1017 | val day_secs: float_time | |
1018 | ||
1019 | val rough_days_since_jesus : date_dmy -> days | |
1020 | val rough_days_between_dates : date_dmy -> date_dmy -> days | |
1021 | ||
1022 | val string_of_unix_time_lfs : Unix.tm -> string | |
1023 | ||
485bce71 C |
1024 | val is_more_recent : date_dmy -> date_dmy -> bool |
1025 | val max_dmy : date_dmy -> date_dmy -> date_dmy | |
1026 | val min_dmy : date_dmy -> date_dmy -> date_dmy | |
1027 | val maximum_dmy : date_dmy list -> date_dmy | |
1028 | val minimum_dmy : date_dmy list -> date_dmy | |
34e49164 C |
1029 | |
1030 | (*****************************************************************************) | |
1031 | (* Lines/Words/Strings *) | |
1032 | (*****************************************************************************) | |
1033 | ||
1034 | val list_of_string : string -> char list | |
1035 | ||
1036 | val lines : string -> string list | |
1037 | val unlines : string list -> string | |
1038 | ||
1039 | val words : string -> string list | |
1040 | val unwords : string list -> string | |
1041 | ||
1042 | val split_space : string -> string list | |
1043 | ||
1044 | val lines_with_nl : string -> string list | |
1045 | ||
1046 | val nblines : string -> int | |
1047 | ||
1048 | (*****************************************************************************) | |
1049 | (* Process/Files *) | |
1050 | (*****************************************************************************) | |
1051 | val cat : filename -> string list | |
1052 | val cat_orig : filename -> string list | |
91eba41f C |
1053 | val cat_array: filename -> string array |
1054 | ||
1055 | val uncat: string list -> filename -> unit | |
34e49164 C |
1056 | |
1057 | val interpolate : string -> string list | |
1058 | ||
1059 | val echo : string -> string | |
1060 | ||
1061 | val usleep : int -> unit | |
1062 | ||
1063 | val process_output_to_list : string -> string list | |
1064 | val cmd_to_list : string -> string list (* alias *) | |
1065 | val cmd_to_list_and_status : string -> string list * Unix.process_status | |
1066 | ||
1067 | val command2 : string -> unit | |
91eba41f | 1068 | val _batch_mode: bool ref |
34e49164 | 1069 | val command2_y_or_no : string -> bool |
0708f913 | 1070 | val command2_y_or_no_exit_if_no : string -> unit |
34e49164 C |
1071 | |
1072 | val do_in_fork : (unit -> unit) -> int | |
1073 | ||
1074 | val mkdir: ?mode:Unix.file_perm -> string -> unit | |
1075 | ||
1076 | val read_file : filename -> string | |
1077 | val write_file : file:filename -> string -> unit | |
1078 | ||
1079 | val filesize : filename -> int | |
1080 | val filemtime : filename -> float | |
1081 | ||
1082 | val nblines_file : filename -> int | |
1083 | ||
1084 | val lfile_exists : filename -> bool | |
1085 | val is_directory : filename -> bool | |
1086 | ||
1087 | val capsule_unix : ('a -> unit) -> 'a -> unit | |
1088 | ||
1089 | val readdir_to_kind_list : string -> Unix.file_kind -> string list | |
1090 | val readdir_to_dir_list : string -> string list | |
1091 | val readdir_to_file_list : string -> string list | |
1092 | val readdir_to_link_list : string -> string list | |
1093 | val readdir_to_dir_size_list : string -> (string * int) list | |
1094 | ||
1095 | val glob : string -> filename list | |
ae4735db | 1096 | val files_of_dir_or_files : |
34e49164 C |
1097 | string (* ext *) -> string list -> filename list |
1098 | val files_of_dir_or_files_no_vcs : | |
1099 | string (* ext *) -> string list -> filename list | |
1100 | (* use a post filter =~ for the ext filtering *) | |
1101 | val files_of_dir_or_files_no_vcs_post_filter : | |
1102 | string (* regexp *) -> string list -> filename list | |
1103 | ||
1104 | ||
1105 | val sanity_check_files_and_adjust : | |
1106 | string (* ext *) -> string list -> filename list | |
1107 | ||
1108 | ||
1109 | type rwx = [ `R | `W | `X ] list | |
1110 | val file_perm_of : u:rwx -> g:rwx -> o:rwx -> Unix.file_perm | |
1111 | ||
1112 | val has_env : string -> bool | |
1113 | ||
1114 | (* scheme spirit. do a finalize so no leak. *) | |
ae4735db | 1115 | val with_open_outfile : |
34e49164 | 1116 | filename -> ((string -> unit) * out_channel -> 'a) -> 'a |
ae4735db | 1117 | val with_open_infile : |
34e49164 | 1118 | filename -> (in_channel -> 'a) -> 'a |
ae4735db | 1119 | val with_open_outfile_append : |
34e49164 C |
1120 | filename -> ((string -> unit) * out_channel -> 'a) -> 'a |
1121 | ||
ae4735db | 1122 | val with_open_stringbuf : |
34e49164 C |
1123 | (((string -> unit) * Buffer.t) -> unit) -> string |
1124 | ||
1125 | exception Timeout | |
1126 | ||
ae4735db | 1127 | (* subtil: have to make sure that Timeout is not intercepted before here. So |
34e49164 | 1128 | * avoid exn handler such as try (...) with _ -> cos Timeout will not bubble up |
ae4735db C |
1129 | * enough. In such case, add a case before such as |
1130 | * with Timeout -> raise Timeout | _ -> ... | |
1131 | * | |
34e49164 C |
1132 | * The same is true for UnixExit (see below). |
1133 | *) | |
1134 | val timeout_function : int -> (unit -> 'a) -> 'a | |
1135 | ||
1136 | val timeout_function_opt : int option -> (unit -> 'a) -> 'a | |
1137 | ||
1138 | ||
ae4735db C |
1139 | (* creation of /tmp files, a la gcc |
1140 | * ex: new_temp_file "cocci" ".c" will give "/tmp/cocci-3252-434465.c" | |
34e49164 C |
1141 | *) |
1142 | val _temp_files_created : string list ref | |
1143 | (* see flag: val save_tmp_files : bool ref *) | |
1144 | val new_temp_file : string (* prefix *) -> string (* suffix *) -> filename | |
1145 | val erase_temp_files : unit -> unit | |
978fd7e5 | 1146 | val erase_this_temp_file : filename -> unit |
34e49164 C |
1147 | |
1148 | (* If the user use some exit 0 in his code, then no one can intercept this | |
1149 | * exit and do something before exiting. There is exn handler for exit 0 | |
1150 | * so better never use exit 0 but instead use an exception and just at | |
1151 | * the very toplevel transform this exn in a unix exit code. | |
ae4735db | 1152 | * |
34e49164 C |
1153 | * subtil: same problem than with Timeout. Do not intercept such exception |
1154 | * with some blind try (...) with _ -> ... | |
1155 | *) | |
ae4735db | 1156 | exception UnixExit of int |
34e49164 C |
1157 | val exn_to_real_unixexit : (unit -> 'a) -> 'a |
1158 | ||
1159 | ||
1160 | ||
1161 | ||
1162 | ||
1163 | ||
1164 | ||
1165 | ||
1166 | (*###########################################################################*) | |
1167 | (* And now collection-like types. See also ocollection.mli *) | |
1168 | (*###########################################################################*) | |
1169 | ||
1170 | (*****************************************************************************) | |
1171 | (* List *) | |
1172 | (*****************************************************************************) | |
1173 | ||
485bce71 | 1174 | |
34e49164 C |
1175 | (* tail recursive efficient map (but that also reverse the element!) *) |
1176 | val map_eff_rev : ('a -> 'b) -> 'a list -> 'b list | |
1177 | (* tail recursive efficient map, use accumulator *) | |
1178 | val acc_map : ('a -> 'b) -> 'a list -> 'b list | |
1179 | ||
1180 | ||
1181 | val zip : 'a list -> 'b list -> ('a * 'b) list | |
1182 | val zip_safe : 'a list -> 'b list -> ('a * 'b) list | |
1183 | val unzip : ('a * 'b) list -> 'a list * 'b list | |
1184 | ||
1185 | val take : int -> 'a list -> 'a list | |
1186 | val take_safe : int -> 'a list -> 'a list | |
1187 | val take_until : ('a -> bool) -> 'a list -> 'a list | |
1188 | val take_while : ('a -> bool) -> 'a list -> 'a list | |
1189 | ||
1190 | val drop : int -> 'a list -> 'a list | |
1191 | val drop_while : ('a -> bool) -> 'a list -> 'a list | |
1192 | val drop_until : ('a -> bool) -> 'a list -> 'a list | |
1193 | ||
1194 | val span : ('a -> bool) -> 'a list -> 'a list * 'a list | |
1195 | ||
1196 | val skip_until : ('a list -> bool) -> 'a list -> 'a list | |
b1b2de81 | 1197 | val skipfirst : (* Eq a *) 'a -> 'a list -> 'a list |
34e49164 C |
1198 | |
1199 | (* cf also List.partition *) | |
1200 | val fpartition : ('a -> 'b option) -> 'a list -> 'b list * 'a list | |
1201 | ||
1202 | val groupBy : ('a -> 'a -> bool) -> 'a list -> 'a list list | |
1203 | val exclude_but_keep_attached: ('a -> bool) -> 'a list -> ('a * 'a list) list | |
b1b2de81 C |
1204 | val group_by_post: ('a -> bool) -> 'a list -> ('a list * 'a) list * 'a list |
1205 | val group_by_pre: ('a -> bool) -> 'a list -> 'a list * ('a * 'a list) list | |
0708f913 | 1206 | val group_by_mapped_key: ('a -> 'b) -> 'a list -> ('b * 'a list) list |
34e49164 | 1207 | |
91eba41f C |
1208 | (* Use hash internally to not be in O(n2). If you want to use it on a |
1209 | * simple list, then first do a List.map to generate a key, for instance the | |
1210 | * first char of the element, and then use this function. | |
1211 | *) | |
34e49164 C |
1212 | val group_assoc_bykey_eff : ('a * 'b) list -> ('a * 'b list) list |
1213 | ||
1214 | val splitAt : int -> 'a list -> 'a list * 'a list | |
1215 | ||
1216 | val split_when: ('a -> bool) -> 'a list -> 'a list * 'a * 'a list | |
1217 | val split_gen_when: ('a list -> 'a list option) -> 'a list -> 'a list list | |
1218 | ||
1219 | val pack : int -> 'a list -> 'a list list | |
1220 | ||
1221 | ||
1222 | val enum : int -> int -> int list | |
1223 | val repeat : 'a -> int -> 'a list | |
1224 | val generate : int -> 'a -> 'a list | |
1225 | ||
1226 | ||
1227 | ||
1228 | val index_list : 'a list -> ('a * int) list | |
1229 | val index_list_1 : 'a list -> ('a * int) list | |
1230 | val index_list_and_total : 'a list -> ('a * int * int) list | |
1231 | ||
1232 | val iter_index : ('a -> int -> 'b) -> 'a list -> unit | |
1233 | val map_index : ('a -> int -> 'b) -> 'a list -> 'b list | |
1234 | val filter_index : (int -> 'a -> bool) -> 'a list -> 'a list | |
1235 | val fold_left_with_index : ('a -> 'b -> int -> 'a) -> 'a -> 'b list -> 'a | |
1236 | ||
1237 | val nth : 'a list -> int -> 'a | |
b1b2de81 | 1238 | val rang : (* Eq a *) 'a -> 'a list -> int |
34e49164 C |
1239 | |
1240 | val last_n : int -> 'a list -> 'a list | |
1241 | ||
1242 | ||
1243 | ||
1244 | val snoc : 'a -> 'a list -> 'a list | |
1245 | val cons : 'a -> 'a list -> 'a list | |
1246 | val uncons : 'a list -> 'a * 'a list | |
1247 | val safe_tl : 'a list -> 'a list | |
1248 | val head_middle_tail : 'a list -> 'a * 'a list * 'a | |
1249 | val last : 'a list -> 'a | |
1250 | val list_init : 'a list -> 'a list | |
1251 | val list_last : 'a list -> 'a | |
1252 | val removelast : 'a list -> 'a list | |
1253 | ||
1254 | val inits : 'a list -> 'a list list | |
1255 | val tails : 'a list -> 'a list list | |
1256 | ||
1257 | ||
1258 | val ( ++ ) : 'a list -> 'a list -> 'a list | |
1259 | ||
1260 | val foldl1 : ('a -> 'a -> 'a) -> 'a list -> 'a | |
1261 | val fold_k : ('a -> 'b -> ('a -> 'a) -> 'a) -> ('a -> 'a) -> 'a -> 'b list -> 'a | |
1262 | val fold_right1 : ('a -> 'a -> 'a) -> 'a list -> 'a | |
1263 | val fold_left : ('a -> 'b -> 'a) -> 'a -> 'b list -> 'a | |
1264 | ||
1265 | val rev_map : ('a -> 'b) -> 'a list -> 'b list | |
1266 | ||
1267 | val join_gen : 'a -> 'a list -> 'a list | |
1268 | ||
1269 | val do_withenv : | |
1270 | (('a -> 'b) -> 'c -> 'd) -> ('e -> 'a -> 'b * 'e) -> 'e -> 'c -> 'd * 'e | |
1271 | val map_withenv : ('a -> 'b -> 'c * 'a) -> 'a -> 'b list -> 'c list * 'a | |
113803cf | 1272 | val map_withkeep: ('a -> 'b) -> 'a list -> ('b * 'a) list |
34e49164 C |
1273 | |
1274 | val collect_accu : ('a -> 'b list) -> 'b list -> 'a list -> 'b list | |
1275 | val collect : ('a -> 'b list) -> 'a list -> 'b list | |
1276 | ||
1277 | val remove : 'a -> 'a list -> 'a list | |
1278 | ||
1279 | val exclude : ('a -> bool) -> 'a list -> 'a list | |
1280 | ||
1281 | (* Not like unix uniq command line tool that only delete contiguous repeated | |
1282 | * line. Here we delete any repeated line (here list element). | |
1283 | *) | |
1284 | val uniq : 'a list -> 'a list | |
ae4735db | 1285 | val uniq_eff: 'a list -> 'a list |
91eba41f | 1286 | |
113803cf C |
1287 | val has_no_duplicate: 'a list -> bool |
1288 | val is_set_as_list: 'a list -> bool | |
1289 | val get_duplicates: 'a list -> 'a list | |
1290 | ||
34e49164 C |
1291 | val doublon : 'a list -> bool |
1292 | ||
1293 | val reverse : 'a list -> 'a list (* alias *) | |
1294 | val rev : 'a list -> 'a list (* alias *) | |
1295 | val rotate : 'a list -> 'a list | |
1296 | ||
1297 | val map_flatten : ('a -> 'b list) -> 'a list -> 'b list | |
1298 | ||
1299 | val map2 : ('a -> 'b) -> 'a list -> 'b list | |
1300 | val map3 : ('a -> 'b) -> 'a list -> 'b list | |
1301 | ||
1302 | ||
1303 | val maximum : 'a list -> 'a | |
1304 | val minimum : 'a list -> 'a | |
1305 | ||
1306 | val min_with : ('a -> 'b) -> 'a list -> 'a | |
1307 | val two_mins_with : ('a -> 'b) -> 'a list -> 'a * 'a | |
1308 | ||
b1b2de81 | 1309 | val all_assoc : (* Eq a *) 'a -> ('a * 'b) list -> 'b list |
34e49164 C |
1310 | val prepare_want_all_assoc : ('a * 'b) list -> ('a * 'b list) list |
1311 | ||
1312 | val or_list : bool list -> bool | |
1313 | val and_list : bool list -> bool | |
1314 | ||
485bce71 C |
1315 | val sum_float : float list -> float |
1316 | val sum_int : int list -> int | |
ae4735db | 1317 | val avg_list: int list -> float |
485bce71 | 1318 | |
34e49164 C |
1319 | val return_when : ('a -> 'b option) -> 'a list -> 'b |
1320 | ||
1321 | ||
1322 | val grep_with_previous : ('a -> 'a -> bool) -> 'a list -> 'a list | |
1323 | val iter_with_previous : ('a -> 'a -> 'b) -> 'a list -> unit | |
1324 | ||
ae4735db | 1325 | val iter_with_before_after : |
34e49164 C |
1326 | ('a list -> 'a -> 'a list -> unit) -> 'a list -> unit |
1327 | ||
1328 | val get_pair : 'a list -> ('a * 'a) list | |
1329 | ||
1330 | val permutation : 'a list -> 'a list list | |
1331 | ||
1332 | val remove_elem_pos : int -> 'a list -> 'a list | |
1333 | val insert_elem_pos : ('a * int) -> 'a list -> 'a list | |
1334 | val uncons_permut : 'a list -> (('a * int) * 'a list) list | |
1335 | val uncons_permut_lazy : 'a list -> (('a * int) * 'a list Lazy.t) list | |
1336 | ||
1337 | ||
1338 | val pack_sorted : ('a -> 'a -> bool) -> 'a list -> 'a list list | |
1339 | ||
1340 | val keep_best : ('a * 'a -> 'a option) -> 'a list -> 'a list | |
1341 | val sorted_keep_best : ('a -> 'a -> 'a option) -> 'a list -> 'a list | |
1342 | ||
91eba41f | 1343 | |
34e49164 C |
1344 | val cartesian_product : 'a list -> 'b list -> ('a * 'b) list |
1345 | ||
1346 | (* old stuff *) | |
1347 | val surEnsemble : 'a list -> 'a list list -> 'a list list | |
1348 | val realCombinaison : 'a list -> 'a list list | |
1349 | val combinaison : 'a list -> ('a * 'a) list | |
1350 | val insere : 'a -> 'a list list -> 'a list list | |
1351 | val insereListeContenant : 'a list -> 'a -> 'a list list -> 'a list list | |
1352 | val fusionneListeContenant : 'a * 'a -> 'a list list -> 'a list list | |
1353 | ||
1354 | (*****************************************************************************) | |
1355 | (* Arrays *) | |
1356 | (*****************************************************************************) | |
1357 | ||
b1b2de81 C |
1358 | val array_find_index : (int -> bool) -> 'a array -> int |
1359 | val array_find_index_via_elem : ('a -> bool) -> 'a array -> int | |
1360 | ||
1361 | (* for better type checking, as sometimes when have an 'int array', can | |
1362 | * easily mess up the index from the value. | |
1363 | *) | |
ae4735db | 1364 | type idx = Idx of int |
b1b2de81 C |
1365 | val next_idx: idx -> idx |
1366 | val int_of_idx: idx -> int | |
1367 | ||
1368 | val array_find_index_typed : (idx -> bool) -> 'a array -> idx | |
34e49164 | 1369 | |
91eba41f C |
1370 | (*****************************************************************************) |
1371 | (* Matrix *) | |
1372 | (*****************************************************************************) | |
1373 | ||
34e49164 C |
1374 | type 'a matrix = 'a array array |
1375 | ||
1376 | val map_matrix : ('a -> 'b) -> 'a matrix -> 'b matrix | |
1377 | ||
ae4735db | 1378 | val make_matrix_init: |
91eba41f C |
1379 | nrow:int -> ncolumn:int -> (int -> int -> 'a) -> 'a matrix |
1380 | ||
ae4735db | 1381 | val iter_matrix: |
91eba41f C |
1382 | (int -> int -> 'a -> unit) -> 'a matrix -> unit |
1383 | ||
ae4735db | 1384 | val nb_rows_matrix: 'a matrix -> int |
91eba41f C |
1385 | val nb_columns_matrix: 'a matrix -> int |
1386 | ||
1387 | val rows_of_matrix: 'a matrix -> 'a list list | |
1388 | val columns_of_matrix: 'a matrix -> 'a list list | |
1389 | ||
1390 | val all_elems_matrix_by_row: 'a matrix -> 'a list | |
1391 | ||
34e49164 C |
1392 | (*****************************************************************************) |
1393 | (* Fast array *) | |
1394 | (*****************************************************************************) | |
1395 | ||
1396 | (* ?? *) | |
1397 | ||
1398 | (*****************************************************************************) | |
1399 | (* Set. But have a look too at set*.mli; it's better. Or use Hashtbl. *) | |
1400 | (*****************************************************************************) | |
1401 | ||
1402 | type 'a set = 'a list | |
1403 | ||
1404 | val empty_set : 'a set | |
1405 | ||
1406 | val insert_set : 'a -> 'a set -> 'a set | |
1407 | val single_set : 'a -> 'a set | |
1408 | val set : 'a list -> 'a set | |
1409 | ||
113803cf C |
1410 | val is_set: 'a list -> bool |
1411 | ||
34e49164 C |
1412 | val exists_set : ('a -> bool) -> 'a set -> bool |
1413 | val forall_set : ('a -> bool) -> 'a set -> bool | |
1414 | ||
1415 | val filter_set : ('a -> bool) -> 'a set -> 'a set | |
1416 | val fold_set : ('a -> 'b -> 'a) -> 'a -> 'b set -> 'a | |
1417 | val map_set : ('a -> 'b) -> 'a set -> 'b set | |
1418 | ||
1419 | val member_set : 'a -> 'a set -> bool | |
1420 | val find_set : ('a -> bool) -> 'a list -> 'a | |
1421 | ||
1422 | val sort_set : ('a -> 'a -> int) -> 'a list -> 'a list | |
1423 | ||
1424 | val iter_set : ('a -> unit) -> 'a list -> unit | |
1425 | ||
1426 | val top_set : 'a set -> 'a | |
1427 | ||
1428 | val inter_set : 'a set -> 'a set -> 'a set | |
1429 | val union_set : 'a set -> 'a set -> 'a set | |
1430 | val minus_set : 'a set -> 'a set -> 'a set | |
1431 | ||
1432 | val union_all : ('a set) list -> 'a set | |
1433 | ||
1434 | val big_union_set : ('a -> 'b set) -> 'a set -> 'b set | |
1435 | val card_set : 'a set -> int | |
1436 | ||
1437 | val include_set : 'a set -> 'a set -> bool | |
1438 | val equal_set : 'a set -> 'a set -> bool | |
1439 | val include_set_strict : 'a set -> 'a set -> bool | |
1440 | ||
1441 | (* could put them in Common.Infix *) | |
1442 | val ( $*$ ) : 'a set -> 'a set -> 'a set | |
1443 | val ( $+$ ) : 'a set -> 'a set -> 'a set | |
1444 | val ( $-$ ) : 'a set -> 'a set -> 'a set | |
1445 | ||
1446 | val ( $?$ ) : 'a -> 'a set -> bool | |
1447 | val ( $<$ ) : 'a set -> 'a set -> bool | |
1448 | val ( $<=$ ) : 'a set -> 'a set -> bool | |
1449 | val ( $=$ ) : 'a set -> 'a set -> bool | |
1450 | ||
1451 | val ( $@$ ) : 'a list -> 'a list -> 'a list | |
1452 | ||
1453 | val nub : 'a list -> 'a list | |
1454 | ||
ae4735db C |
1455 | (* use internally a hash and return |
1456 | * - the common part, | |
1457 | * - part only in a, | |
34e49164 C |
1458 | * - part only in b |
1459 | *) | |
ae4735db | 1460 | val diff_two_say_set_eff : 'a list -> 'a list -> |
34e49164 C |
1461 | 'a list * 'a list * 'a list |
1462 | ||
1463 | (*****************************************************************************) | |
1464 | (* Set as normal list *) | |
1465 | (*****************************************************************************) | |
1466 | ||
ae4735db | 1467 | (* cf above *) |
34e49164 C |
1468 | |
1469 | (*****************************************************************************) | |
1470 | (* Set as sorted list *) | |
1471 | (*****************************************************************************) | |
1472 | ||
1473 | ||
1474 | (*****************************************************************************) | |
1475 | (* Sets specialized *) | |
1476 | (*****************************************************************************) | |
1477 | ||
ae4735db | 1478 | (* |
34e49164 C |
1479 | module StringSet = Set.Make(struct type t = string let compare = compare end) |
1480 | *) | |
ae4735db | 1481 | |
34e49164 C |
1482 | |
1483 | (*****************************************************************************) | |
1484 | (* Assoc. But have a look too at Mapb.mli; it's better. Or use Hashtbl. *) | |
1485 | (*****************************************************************************) | |
1486 | ||
1487 | type ('a, 'b) assoc = ('a * 'b) list | |
1488 | ||
b1b2de81 | 1489 | val assoc_to_function : (* Eq a *) ('a, 'b) assoc -> ('a -> 'b) |
34e49164 C |
1490 | |
1491 | val empty_assoc : ('a, 'b) assoc | |
1492 | val fold_assoc : ('a -> 'b -> 'a) -> 'a -> 'b list -> 'a | |
1493 | val insert_assoc : 'a -> 'a list -> 'a list | |
1494 | val map_assoc : ('a -> 'b) -> 'a list -> 'b list | |
1495 | val filter_assoc : ('a -> bool) -> 'a list -> 'a list | |
1496 | ||
1497 | val assoc : 'a -> ('a * 'b) list -> 'b | |
1498 | ||
1499 | val keys : ('a * 'b) list -> 'a list | |
1500 | val lookup : 'a -> ('a * 'b) list -> 'b | |
1501 | ||
1502 | val del_assoc : 'a -> ('a * 'b) list -> ('a * 'b) list | |
1503 | val replace_assoc : 'a * 'b -> ('a * 'b) list -> ('a * 'b) list | |
1504 | val apply_assoc : 'a -> ('b -> 'b) -> ('a * 'b) list -> ('a * 'b) list | |
1505 | ||
1506 | val big_union_assoc : ('a -> 'b set) -> 'a list -> 'b set | |
1507 | ||
1508 | val assoc_reverse : ('a * 'b) list -> ('b * 'a) list | |
1509 | val assoc_map : ('a * 'b) list -> ('a * 'b) list -> ('a * 'a) list | |
1510 | ||
1511 | val lookup_list : 'a -> ('a, 'b) assoc list -> 'b | |
1512 | val lookup_list2 : 'a -> ('a, 'b) assoc list -> 'b * int | |
1513 | ||
1514 | val assoc_option : 'a -> ('a, 'b) assoc -> 'b option | |
485bce71 | 1515 | val assoc_with_err_msg : 'a -> ('a, 'b) assoc -> 'b |
34e49164 | 1516 | |
113803cf C |
1517 | val sort_by_val_lowfirst: ('a,'b) assoc -> ('a * 'b) list |
1518 | val sort_by_val_highfirst: ('a,'b) assoc -> ('a * 'b) list | |
1519 | ||
1520 | val sort_by_key_lowfirst: (int,'b) assoc -> (int * 'b) list | |
1521 | val sort_by_key_highfirst: (int,'b) assoc -> (int * 'b) list | |
91eba41f | 1522 | |
0708f913 C |
1523 | val sortgen_by_key_lowfirst: ('a,'b) assoc -> ('a * 'b) list |
1524 | val sortgen_by_key_highfirst: ('a,'b) assoc -> ('a * 'b) list | |
1525 | ||
34e49164 C |
1526 | (*****************************************************************************) |
1527 | (* Assoc, specialized. *) | |
1528 | (*****************************************************************************) | |
1529 | ||
1530 | module IntMap : | |
1531 | sig | |
1532 | type key = int | |
1533 | type +'a t | |
1534 | val empty : 'a t | |
1535 | val is_empty : 'a t -> bool | |
1536 | val add : key -> 'a -> 'a t -> 'a t | |
1537 | val find : key -> 'a t -> 'a | |
1538 | val remove : key -> 'a t -> 'a t | |
1539 | val mem : key -> 'a t -> bool | |
1540 | val iter : (key -> 'a -> unit) -> 'a t -> unit | |
1541 | val map : ('a -> 'b) -> 'a t -> 'b t | |
1542 | val mapi : (key -> 'a -> 'b) -> 'a t -> 'b t | |
1543 | val fold : (key -> 'a -> 'b -> 'b) -> 'a t -> 'b -> 'b | |
1544 | val compare : ('a -> 'a -> int) -> 'a t -> 'a t -> int | |
1545 | val equal : ('a -> 'a -> bool) -> 'a t -> 'a t -> bool | |
1546 | end | |
1547 | val intmap_to_list : 'a IntMap.t -> (IntMap.key * 'a) list | |
1548 | val intmap_string_of_t : 'a -> 'b -> string | |
1549 | ||
1550 | module IntIntMap : | |
1551 | sig | |
1552 | type key = int * int | |
1553 | type +'a t | |
1554 | val empty : 'a t | |
1555 | val is_empty : 'a t -> bool | |
1556 | val add : key -> 'a -> 'a t -> 'a t | |
1557 | val find : key -> 'a t -> 'a | |
1558 | val remove : key -> 'a t -> 'a t | |
1559 | val mem : key -> 'a t -> bool | |
1560 | val iter : (key -> 'a -> unit) -> 'a t -> unit | |
1561 | val map : ('a -> 'b) -> 'a t -> 'b t | |
1562 | val mapi : (key -> 'a -> 'b) -> 'a t -> 'b t | |
1563 | val fold : (key -> 'a -> 'b -> 'b) -> 'a t -> 'b -> 'b | |
1564 | val compare : ('a -> 'a -> int) -> 'a t -> 'a t -> int | |
1565 | val equal : ('a -> 'a -> bool) -> 'a t -> 'a t -> bool | |
1566 | end | |
1567 | val intintmap_to_list : 'a IntIntMap.t -> (IntIntMap.key * 'a) list | |
1568 | val intintmap_string_of_t : 'a -> 'b -> string | |
1569 | ||
1570 | ||
1571 | (*****************************************************************************) | |
1572 | (* Hash *) | |
1573 | (*****************************************************************************) | |
1574 | ||
1575 | (* Note that Hashtbl keep old binding to a key so if want a hash | |
1576 | * of a list, then can use the Hashtbl as is. Use Hashtbl.find_all then | |
1577 | * to get the list of bindings | |
ae4735db C |
1578 | * |
1579 | * Note that Hashtbl module use different convention :( the object is | |
34e49164 C |
1580 | * the first argument, not last as for List or Map. |
1581 | *) | |
1582 | ||
1583 | (* obsolete: can use directly the Hashtbl module *) | |
1584 | val hcreate : unit -> ('a, 'b) Hashtbl.t | |
1585 | val hadd : 'a * 'b -> ('a, 'b) Hashtbl.t -> unit | |
1586 | val hmem : 'a -> ('a, 'b) Hashtbl.t -> bool | |
1587 | val hfind : 'a -> ('a, 'b) Hashtbl.t -> 'b | |
1588 | val hreplace : 'a * 'b -> ('a, 'b) Hashtbl.t -> unit | |
1589 | val hiter : ('a -> 'b -> unit) -> ('a, 'b) Hashtbl.t -> unit | |
1590 | val hfold : ('a -> 'b -> 'c -> 'c) -> ('a, 'b) Hashtbl.t -> 'c -> 'c | |
1591 | val hremove : 'a -> ('a, 'b) Hashtbl.t -> unit | |
1592 | ||
1593 | ||
1594 | val hfind_default : 'a -> (unit -> 'b) -> ('a, 'b) Hashtbl.t -> 'b | |
1595 | val hfind_option : 'a -> ('a, 'b) Hashtbl.t -> 'b option | |
ae4735db | 1596 | val hupdate_default : |
34e49164 C |
1597 | 'a -> ('b -> 'b) -> (unit -> 'b) -> ('a, 'b) Hashtbl.t -> unit |
1598 | ||
1599 | val hash_to_list : ('a, 'b) Hashtbl.t -> ('a * 'b) list | |
1600 | val hash_to_list_unsorted : ('a, 'b) Hashtbl.t -> ('a * 'b) list | |
1601 | val hash_of_list : ('a * 'b) list -> ('a, 'b) Hashtbl.t | |
1602 | ||
1603 | ||
ae4735db | 1604 | val hkeys : ('a, 'b) Hashtbl.t -> 'a list |
34e49164 C |
1605 | |
1606 | (*****************************************************************************) | |
1607 | (* Hash sets *) | |
1608 | (*****************************************************************************) | |
1609 | ||
ae4735db | 1610 | type 'a hashset = ('a, bool) Hashtbl.t |
34e49164 C |
1611 | |
1612 | ||
1613 | (* common use of hashset, in a hash of hash *) | |
1614 | val hash_hashset_add : 'a -> 'b -> ('a, 'b hashset) Hashtbl.t -> unit | |
1615 | ||
ae4735db | 1616 | val hashset_to_set : |
34e49164 C |
1617 | < fromlist : ('a ) list -> 'c; .. > -> ('a, 'b) Hashtbl.t -> 'c |
1618 | ||
1619 | val hashset_to_list : 'a hashset -> 'a list | |
1620 | val hashset_of_list : 'a list -> 'a hashset | |
1621 | ||
1622 | ||
1623 | (*****************************************************************************) | |
1624 | (* Stack *) | |
1625 | (*****************************************************************************) | |
1626 | ||
1627 | type 'a stack = 'a list | |
1628 | val empty_stack : 'a stack | |
1629 | val push : 'a -> 'a stack -> 'a stack | |
1630 | val top : 'a stack -> 'a | |
1631 | val pop : 'a stack -> 'a stack | |
1632 | ||
91eba41f C |
1633 | val top_option: 'a stack -> 'a option |
1634 | ||
34e49164 C |
1635 | val push2 : 'a -> 'a stack ref -> unit |
1636 | val pop2: 'a stack ref -> 'a | |
1637 | ||
91eba41f C |
1638 | (*****************************************************************************) |
1639 | (* Stack with undo/redo support *) | |
1640 | (*****************************************************************************) | |
1641 | ||
1642 | type 'a undo_stack = 'a list * 'a list | |
1643 | val empty_undo_stack : 'a undo_stack | |
1644 | val push_undo : 'a -> 'a undo_stack -> 'a undo_stack | |
1645 | val top_undo : 'a undo_stack -> 'a | |
1646 | val pop_undo : 'a undo_stack -> 'a undo_stack | |
1647 | val redo_undo: 'a undo_stack -> 'a undo_stack | |
1648 | val undo_pop: 'a undo_stack -> 'a undo_stack | |
1649 | ||
1650 | val top_undo_option: 'a undo_stack -> 'a option | |
1651 | ||
34e49164 C |
1652 | |
1653 | (*****************************************************************************) | |
1654 | (* Binary tree *) | |
1655 | (*****************************************************************************) | |
1656 | type 'a bintree = Leaf of 'a | Branch of ('a bintree * 'a bintree) | |
1657 | ||
1658 | (*****************************************************************************) | |
1659 | (* N-ary tree *) | |
1660 | (*****************************************************************************) | |
1661 | ||
1662 | (* no empty tree, must have one root at least *) | |
1663 | type 'a tree = Tree of 'a * ('a tree) list | |
1664 | ||
1665 | val tree_iter : ('a -> unit) -> 'a tree -> unit | |
1666 | ||
1667 | ||
1668 | (*****************************************************************************) | |
1669 | (* N-ary tree with updatable childrens *) | |
1670 | (*****************************************************************************) | |
1671 | ||
b1b2de81 | 1672 | (* no empty tree, must have one root at least *) |
ae4735db C |
1673 | type 'a treeref = |
1674 | | NodeRef of 'a * 'a treeref list ref | |
34e49164 | 1675 | |
ae4735db | 1676 | val treeref_node_iter: |
b1b2de81 | 1677 | (('a * 'a treeref list ref) -> unit) -> 'a treeref -> unit |
ae4735db C |
1678 | val treeref_node_iter_with_parents: |
1679 | (('a * 'a treeref list ref) -> ('a list) -> unit) -> | |
b1b2de81 | 1680 | 'a treeref -> unit |
34e49164 | 1681 | |
ae4735db C |
1682 | val find_treeref: |
1683 | (('a * 'a treeref list ref) -> bool) -> | |
b1b2de81 C |
1684 | 'a treeref -> 'a treeref |
1685 | ||
ae4735db C |
1686 | val treeref_children_ref: |
1687 | 'a treeref -> 'a treeref list ref | |
b1b2de81 C |
1688 | |
1689 | val find_treeref_with_parents_some: | |
1690 | ('a * 'a treeref list ref -> 'a list -> 'c option) -> | |
1691 | 'a treeref -> 'c | |
1692 | ||
1693 | val find_multi_treeref_with_parents_some: | |
1694 | ('a * 'a treeref list ref -> 'a list -> 'c option) -> | |
1695 | 'a treeref -> 'c list | |
1696 | ||
1697 | ||
ae4735db | 1698 | (* Leaf can seem redundant, but sometimes want to directly see if |
b1b2de81 C |
1699 | * a children is a leaf without looking if the list is empty. |
1700 | *) | |
ae4735db C |
1701 | type ('a, 'b) treeref2 = |
1702 | | NodeRef2 of 'a * ('a, 'b) treeref2 list ref | |
b1b2de81 C |
1703 | | LeafRef2 of 'b |
1704 | ||
1705 | ||
ae4735db C |
1706 | val find_treeref2: |
1707 | (('a * ('a, 'b) treeref2 list ref) -> bool) -> | |
b1b2de81 C |
1708 | ('a, 'b) treeref2 -> ('a, 'b) treeref2 |
1709 | ||
ae4735db C |
1710 | val treeref_node_iter_with_parents2: |
1711 | (('a * ('a, 'b) treeref2 list ref) -> ('a list) -> unit) -> | |
b1b2de81 C |
1712 | ('a, 'b) treeref2 -> unit |
1713 | ||
ae4735db | 1714 | val treeref_node_iter2: |
b1b2de81 C |
1715 | (('a * ('a, 'b) treeref2 list ref) -> unit) -> ('a, 'b) treeref2 -> unit |
1716 | ||
1717 | (* | |
1718 | ||
34e49164 | 1719 | |
ae4735db | 1720 | val treeref_children_ref: ('a, 'b) treeref -> ('a, 'b) treeref list ref |
34e49164 | 1721 | |
91eba41f C |
1722 | val find_treeref_with_parents_some: |
1723 | ('a * ('a, 'b) treeref list ref -> 'a list -> 'c option) -> | |
1724 | ('a, 'b) treeref -> 'c | |
34e49164 | 1725 | |
91eba41f C |
1726 | val find_multi_treeref_with_parents_some: |
1727 | ('a * ('a, 'b) treeref list ref -> 'a list -> 'c option) -> | |
1728 | ('a, 'b) treeref -> 'c list | |
b1b2de81 | 1729 | *) |
34e49164 C |
1730 | |
1731 | (*****************************************************************************) | |
1732 | (* Graph. But have a look too at Ograph_*.mli; it's better *) | |
1733 | (*****************************************************************************) | |
1734 | ||
1735 | type 'a graph = 'a set * ('a * 'a) set | |
1736 | ||
1737 | val add_node : 'a -> 'a graph -> 'a graph | |
1738 | val del_node : 'a -> 'a graph -> 'a graph | |
1739 | ||
1740 | val add_arc : 'a * 'a -> 'a graph -> 'a graph | |
1741 | val del_arc : 'a * 'a -> 'a graph -> 'a graph | |
1742 | ||
1743 | val successors : 'a -> 'a graph -> 'a set | |
1744 | val predecessors : 'a -> 'a graph -> 'a set | |
1745 | ||
1746 | val nodes : 'a graph -> 'a set | |
1747 | ||
1748 | val fold_upward : ('a -> 'b -> 'a) -> 'b set -> 'a -> 'b graph -> 'a | |
1749 | ||
1750 | val empty_graph : 'a list * 'b list | |
1751 | ||
1752 | ||
1753 | (*****************************************************************************) | |
1754 | (* Generic op *) | |
1755 | (*****************************************************************************) | |
1756 | ||
1757 | (* mostly alias to functions in List *) | |
1758 | ||
1759 | val map : ('a -> 'b) -> 'a list -> 'b list | |
1760 | val filter : ('a -> bool) -> 'a list -> 'a list | |
1761 | val fold : ('a -> 'b -> 'a) -> 'a -> 'b list -> 'a | |
1762 | ||
1763 | val member : 'a -> 'a list -> bool | |
1764 | ||
1765 | val iter : ('a -> unit) -> 'a list -> unit | |
1766 | ||
1767 | val find : ('a -> bool) -> 'a list -> 'a | |
1768 | ||
1769 | val exists : ('a -> bool) -> 'a list -> bool | |
1770 | val forall : ('a -> bool) -> 'a list -> bool | |
1771 | ||
1772 | val big_union : ('a -> 'b set) -> 'a list -> 'b set | |
1773 | ||
1774 | (* same than [] but easier to search for, because [] can also be a pattern *) | |
1775 | val empty_list : 'a list | |
1776 | ||
1777 | val sort : ('a -> 'a -> int) -> 'a list -> 'a list | |
1778 | ||
1779 | val length : 'a list -> int | |
1780 | ||
1781 | val null : 'a list -> bool | |
1782 | ||
1783 | val head : 'a list -> 'a | |
1784 | val tail : 'a list -> 'a list | |
1785 | ||
1786 | val is_singleton : 'a list -> bool | |
1787 | ||
1788 | ||
1789 | ||
1790 | ||
1791 | ||
1792 | ||
1793 | ||
1794 | ||
1795 | ||
1796 | (*###########################################################################*) | |
1797 | (* And now misc functions *) | |
1798 | (*###########################################################################*) | |
1799 | ||
1800 | (*****************************************************************************) | |
1801 | (* DB (LFS) *) | |
1802 | (*****************************************************************************) | |
1803 | ||
1804 | (* cf oassocbdb.ml or oassocdbm.ml *) | |
1805 | ||
1806 | (*****************************************************************************) | |
1807 | (* GUI (LFS, CComment, otimetracker) *) | |
1808 | (*****************************************************************************) | |
1809 | ||
1810 | (* cf ocamlgtk and my gui.ml *) | |
1811 | ||
1812 | ||
1813 | (*****************************************************************************) | |
1814 | (* Graphics (otimetracker) *) | |
1815 | (*****************************************************************************) | |
1816 | ||
1817 | (* cf ocamlgl and my opengl.ml *) | |
1818 | ||
1819 | ||
1820 | ||
1821 | (*****************************************************************************) | |
1822 | (* Geometry (ICFP raytracer) *) | |
1823 | (*****************************************************************************) | |
1824 | ||
1825 | type vector = float * float * float | |
1826 | ||
1827 | type point = vector | |
1828 | type color = vector | |
1829 | ||
1830 | val dotproduct : vector * vector -> float | |
1831 | ||
1832 | val vector_length : vector -> float | |
1833 | ||
1834 | val minus_point : point * point -> vector | |
1835 | ||
1836 | val distance : point * point -> float | |
1837 | ||
1838 | val normalise : vector -> vector | |
1839 | ||
1840 | val mult_coeff : vector -> float -> vector | |
1841 | ||
1842 | val add_vector : vector -> vector -> vector | |
1843 | val mult_vector : vector -> vector -> vector | |
1844 | val sum_vector : vector list -> vector | |
1845 | ||
1846 | ||
1847 | (*****************************************************************************) | |
1848 | (* Pics (ICFP raytracer) *) | |
1849 | (*****************************************************************************) | |
1850 | type pixel = int * int * int | |
1851 | val write_ppm : int -> int -> pixel list -> filename -> unit | |
1852 | val test_ppm1 : unit -> unit | |
1853 | ||
1854 | (*****************************************************************************) | |
1855 | (* Diff (LFS) *) | |
1856 | (*****************************************************************************) | |
1857 | ||
1858 | type diff = Match | BnotinA | AnotinB | |
1859 | val diff : (int -> int -> diff -> unit) -> string list * string list -> unit | |
1860 | val diff2 : (int -> int -> diff -> unit) -> string * string -> unit | |
1861 | ||
1862 | (*****************************************************************************) | |
1863 | (* Parsers (aop-colcombet) *) | |
1864 | (*****************************************************************************) | |
1865 | ||
1866 | val parserCommon : Lexing.lexbuf -> ('a -> Lexing.lexbuf -> 'b) -> 'a -> 'b | |
1867 | val getDoubleParser : | |
1868 | ('a -> Lexing.lexbuf -> 'b) -> 'a -> (string -> 'b) * (string -> 'b) | |
1869 | ||
1870 | (*****************************************************************************) | |
1871 | (* Parsers (cocci) *) | |
1872 | (*****************************************************************************) | |
1873 | ||
1874 | ||
1875 | (* Currently lexing.ml does not handle the line number position. | |
ae4735db | 1876 | * Even if there is some fields in the lexing structure, they are not |
34e49164 | 1877 | * maintained by the lexing engine :( So the following code does not work: |
ae4735db C |
1878 | * |
1879 | * let pos = Lexing.lexeme_end_p lexbuf in | |
1880 | * sprintf "at file %s, line %d, char %d" pos.pos_fname pos.pos_lnum | |
1881 | * (pos.pos_cnum - pos.pos_bol) in | |
1882 | * | |
34e49164 C |
1883 | * Hence those functions to overcome the previous limitation. |
1884 | *) | |
1885 | ||
1886 | type parse_info = { | |
1887 | str: string; | |
1888 | charpos: int; | |
1889 | ||
1890 | line: int; | |
1891 | column: int; | |
1892 | file: filename; | |
ae4735db | 1893 | } |
34e49164 C |
1894 | val fake_parse_info : parse_info |
1895 | val string_of_parse_info : parse_info -> string | |
485bce71 | 1896 | val string_of_parse_info_bis : parse_info -> string |
34e49164 C |
1897 | |
1898 | (* array[i] will contain the (line x col) of the i char position *) | |
1899 | val full_charpos_to_pos : filename -> (int * int) array | |
1900 | ||
1901 | (* fill in the line and column field of parse_info that were not set | |
1902 | * during lexing because of limitations of ocamllex. *) | |
ae4735db | 1903 | val complete_parse_info : |
34e49164 C |
1904 | filename -> (int * int) array -> parse_info -> parse_info |
1905 | ||
ae4735db | 1906 | val full_charpos_to_pos_large: |
708f4980 C |
1907 | filename -> (int -> (int * int)) |
1908 | ||
ae4735db | 1909 | val complete_parse_info_large : |
708f4980 C |
1910 | filename -> (int -> (int * int)) -> parse_info -> parse_info |
1911 | ||
34e49164 C |
1912 | (* return line x col x str_line from a charpos. This function is quite |
1913 | * expensive so don't use it to get the line x col from every token in | |
1914 | * a file. Instead use full_charpos_to_pos. | |
1915 | *) | |
1916 | val info_from_charpos : int -> filename -> (int * int * string) | |
1917 | ||
1918 | val error_message : filename -> (string * int) -> string | |
1919 | val error_message_short : filename -> (string * int) -> string | |
1920 | ||
ae4735db | 1921 | (* add a 'decalage/shift' argument to handle stuff such as cpp which includes |
34e49164 C |
1922 | * files and who can make shift. |
1923 | *) | |
1924 | val error_messagebis : filename -> (string * int) -> int -> string | |
1925 | ||
1926 | (*****************************************************************************) | |
1927 | (* Scope managment (cocci) *) | |
1928 | (*****************************************************************************) | |
1929 | ||
1930 | (* for example of use, see the code used in coccinelle *) | |
1931 | type ('a, 'b) scoped_env = ('a, 'b) assoc list | |
1932 | ||
b1b2de81 | 1933 | val lookup_env : (* Eq a *) 'a -> ('a, 'b) scoped_env -> 'b |
34e49164 C |
1934 | val member_env_key : 'a -> ('a, 'b) scoped_env -> bool |
1935 | ||
1936 | val new_scope : ('a, 'b) scoped_env ref -> unit | |
1937 | val del_scope : ('a, 'b) scoped_env ref -> unit | |
1938 | ||
1939 | val do_in_new_scope : ('a, 'b) scoped_env ref -> (unit -> unit) -> unit | |
ae4735db | 1940 | |
34e49164 C |
1941 | val add_in_scope : ('a, 'b) scoped_env ref -> 'a * 'b -> unit |
1942 | ||
1943 | ||
1944 | ||
1945 | ||
1946 | (* for example of use, see the code used in coccinelle *) | |
1947 | type ('a, 'b) scoped_h_env = { | |
1948 | scoped_h : ('a, 'b) Hashtbl.t; | |
1949 | scoped_list : ('a, 'b) assoc list; | |
1950 | } | |
1951 | val empty_scoped_h_env : unit -> ('a, 'b) scoped_h_env | |
1952 | val clone_scoped_h_env : ('a, 'b) scoped_h_env -> ('a, 'b) scoped_h_env | |
1953 | ||
1954 | val lookup_h_env : 'a -> ('a, 'b) scoped_h_env -> 'b | |
1955 | val member_h_env_key : 'a -> ('a, 'b) scoped_h_env -> bool | |
1956 | ||
1957 | val new_scope_h : ('a, 'b) scoped_h_env ref -> unit | |
1958 | val del_scope_h : ('a, 'b) scoped_h_env ref -> unit | |
1959 | ||
1960 | val do_in_new_scope_h : ('a, 'b) scoped_h_env ref -> (unit -> unit) -> unit | |
1961 | ||
1962 | val add_in_scope_h : ('a, 'b) scoped_h_env ref -> 'a * 'b -> unit | |
1963 | ||
1964 | (*****************************************************************************) | |
1965 | (* Terminal (LFS) *) | |
1966 | (*****************************************************************************) | |
1967 | ||
91eba41f C |
1968 | (* don't forget to call Common_extra.set_link () *) |
1969 | ||
34e49164 | 1970 | val _execute_and_show_progress_func : |
ae4735db C |
1971 | (int (* length *) -> ((unit -> unit) -> unit) -> unit) ref |
1972 | val execute_and_show_progress : | |
34e49164 C |
1973 | int (* length *) -> ((unit -> unit) -> unit) -> unit |
1974 | ||
1975 | (*****************************************************************************) | |
1976 | (* Flags and actions *) | |
1977 | (*****************************************************************************) | |
1978 | ||
1979 | val cmdline_flags_devel : unit -> cmdline_options | |
1980 | val cmdline_flags_verbose : unit -> cmdline_options | |
1981 | val cmdline_flags_other : unit -> cmdline_options | |
1982 | ||
1983 | (*****************************************************************************) | |
1984 | (* Misc/test *) | |
1985 | (*****************************************************************************) | |
1986 | ||
1987 | val generic_print : 'a -> string -> string | |
1988 | ||
1989 | class ['a] olist : | |
1990 | 'a list -> | |
1991 | object | |
1992 | val xs : 'a list | |
1993 | method fold : ('b -> 'a -> 'b) -> 'b -> 'b | |
1994 | method view : 'a list | |
1995 | end | |
1996 | ||
1997 | val typing_sux_test : unit -> unit | |
1998 |