X-Git-Url: http://git.annexia.org/?p=virt-top.git;a=blobdiff_plain;f=virt-top%2Fvirt_top_utils.ml;h=c5dc97df20ea378479d9257481171ba328e003c2;hp=53c9bf1084d4d4b235019ee0000ad60f139978a7;hb=4e1409917c38f8bf57838f5119f58edbcad41937;hpb=3126bfee333b5c635dc60a54265936af06117f6a diff --git a/virt-top/virt_top_utils.ml b/virt-top/virt_top_utils.ml old mode 100755 new mode 100644 index 53c9bf1..c5dc97d --- a/virt-top/virt_top_utils.ml +++ b/virt-top/virt_top_utils.ml @@ -1,5 +1,5 @@ (* 'top'-like tool for libvirt domains. - (C) Copyright 2007 Richard W.M. Jones, Red Hat Inc. + (C) Copyright 2007-2009 Richard W.M. Jones, Red Hat Inc. http://libvirt.org/ This program is free software; you can redistribute it and/or modify @@ -21,6 +21,8 @@ open Printf +open Virt_top_gettext.Gettext + module C = Libvirt.Connect module D = Libvirt.Domain module N = Libvirt.Network @@ -33,6 +35,9 @@ let (-^) = Int64.sub let ( *^ ) = Int64.mul let (/^) = Int64.div +(* failwithf is a printf-like version of failwith. *) +let failwithf fs = ksprintf failwith fs + (* Input a whole file as a list of lines. *) let input_all_lines chan = let lines = ref [] in @@ -104,10 +109,13 @@ let read_config_file filename = (* Pad a string to the full width with spaces. If too long, truncate. *) let pad width str = - let n = String.length str in - if n = width then str - else if n > width then String.sub str 0 width - else (* if n < width then *) str ^ String.make (width-n) ' ' + if width <= 0 then "" + else ( + let n = String.length str in + if n = width then str + else if n > width then String.sub str 0 width + else (* if n < width then *) str ^ String.make (width-n) ' ' + ) module Show = struct (* Show a percentage in 4 chars. *)