Version 0.3.0.
[virt-dmesg.git] / src / utils.mli
1 (* virt-dmesg
2  * (C) Copyright 2008-2011 Red Hat Inc.
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17  *)
18
19 (** Utility functions. *)
20
21 module StringMap :
22   sig
23     type key = String.t
24     type 'a t = 'a Map.Make (String).t
25     val empty : 'a t
26     val is_empty : 'a t -> bool
27     val add : key -> 'a -> 'a t -> 'a t
28     val find : key -> 'a t -> 'a
29     val remove : key -> 'a t -> 'a t
30     val mem : key -> 'a t -> bool
31     val iter : (key -> 'a -> unit) -> 'a t -> unit
32     val map : ('a -> 'b) -> 'a t -> 'b t
33     val mapi : (key -> 'a -> 'b) -> 'a t -> 'b t
34     val fold : (key -> 'a -> 'b -> 'b) -> 'a t -> 'b -> 'b
35     val compare : ('a -> 'a -> int) -> 'a t -> 'a t -> int
36     val equal : ('a -> 'a -> bool) -> 'a t -> 'a t -> bool
37   end
38   (** Map strings -> any type.  Used for symbol tables. *)
39
40 type symbol_table = int64 StringMap.t
41   (** A symbol table is a map from strings (symbols) to virtual addresses. *)
42
43 val ( +^ ) : int64 -> int64 -> int64
44 val ( -^ ) : int64 -> int64 -> int64
45 val ( *^ ) : int64 -> int64 -> int64
46 val ( /^ ) : int64 -> int64 -> int64
47 val ( &^ ) : int64 -> int64 -> int64
48   (** 64 bit operators. *)
49
50 val frequency : 'a list -> (int * 'a) list
51   (** Take a list of items, and return the list (count, item)
52       in order from most frequent to least frequent occurring
53       in the original list. *)
54
55 val filter_map : ('a -> 'b option) -> 'a list -> 'b list
56   (** [filter_map f as] maps each 'a' to 'b', but if the function
57       returns [None] then the element is removed from the output. *)
58
59 val replace_chars : (char -> string) -> string -> string
60   (** [replace_chars f s] returns a string where all chars [c] of [s]
61       have been replaced by the string returned by [f c]. *)
62
63 val set_debug : unit -> unit
64   (** If called, enables debugging. *)
65
66 val debug : ('a, unit, string, unit) format4 -> 'a
67   (** If debugging is enabled, this prints the string to stdout
68       followed by a newline character. *)
69
70 val error : ('a, unit, string, unit) format4 -> 'a
71   (** Print the name of the program and the error message to stderr
72       followed by a newline character.  Note this function doesn't
73       exit the program.  If you want to do that, call [exit 1]
74       after. *)
75
76 val set_program_name : string -> unit
77   (** Set the program name. *)
78
79 val get_program_name : unit -> string
80   (** Get the program name. *)