2 * (C) Copyright 2008-2011 Red Hat Inc.
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.
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.
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.
21 module StringMap = Map.Make (String)
23 type symbol_table = int64 StringMap.t
25 let ( +^ ) = Int64.add
26 let ( -^ ) = Int64.sub
27 let ( *^ ) = Int64.mul
28 let ( /^ ) = Int64.div
29 let ( &^ ) = Int64.logand
32 let xs = List.sort compare xs in
33 let rec loop = function
36 | x :: y :: xs when x = y ->
37 let rest = loop (y :: xs) in
38 let (count, _), rest = List.hd rest, List.tl rest in
44 List.rev (List.sort compare xs)
46 let rec filter_map f = function
50 | None -> filter_map f xs
51 | Some y -> y :: filter_map f xs
53 let replace_chars f s =
54 let len = String.length s in
57 let c = String.unsafe_get s i in
58 let acc = f c :: acc in
61 String.concat "" (List.rev acc)
65 let program_name = ref "virt-dmesg"
66 let set_program_name str = program_name := str
67 let get_program_name () = !program_name
69 let debug_mode = ref false
70 let set_debug () = debug_mode := true
71 let debug fs = ksprintf (fun str -> if !debug_mode then print_endline str) fs
76 prerr_string !program_name;