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