(* Guestfs Browser. * Copyright (C) 2010 Red Hat Inc. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *) open Printf let (+^) = Int64.add let (-^) = Int64.sub let ( *^ ) = Int64.mul let (/^) = Int64.div type ('a, 'b) either = Left of 'a | Right of 'b let verbose = ref false let set_verbose_flag () = verbose := true let verbose () = !verbose let write_flag = ref false let set_write_flag () = write_flag := true let write_flag () = !write_flag let debug fs = let f str = if verbose () then ( prerr_string Config.package; prerr_string ": "; prerr_string str; prerr_newline () ) in ksprintf f fs let failwith fs = let f str = if verbose () then (prerr_string str; prerr_newline ()); raise (Failure str) in ksprintf f fs let utf8_rarrow = "\xe2\x86\x92" let human_size_1k i = if i < 1024L then sprintf "%LdK" i else if i < 1024L *^ 1024L then sprintf "%.1fM" (Int64.to_float i /. 1024.) else sprintf "%.1fG" (Int64.to_float i /. 1024. /. 1024.)