build: Remove bogus directory list in ocaml-dep.sh.in
[virt-top.git] / src / top.ml
index 204f3b6..75fbcb9 100644 (file)
@@ -18,7 +18,6 @@
 *)
 
 open Printf
-open ExtList
 open Curses
 
 open Opt_gettext.Gettext
@@ -33,12 +32,6 @@ module N = Libvirt.Network
 
 let rcfile = ".virt-toprc"
 
-(* Hooks for CSV support (see [opt_csv.ml]). *)
-let csv_start : (string -> unit) ref =
-  ref (
-    fun _ -> failwith (s_"virt-top was compiled without support for CSV files")
-  )
-
 (* Hook for calendar support (see [opt_calendar.ml]). *)
 let parse_date_time : (string -> float) ref =
   ref (
@@ -84,7 +77,7 @@ let start_up () =
   and set_net_mode () = display_mode := NetDisplay
   and set_block_mode () = display_mode := BlockDisplay
   and set_csv filename =
-    (!csv_start) filename;
+    Csv_output.csv_set_filename filename;
     csv_enabled := true
   and no_init_file () = init_file := NoInitFile
   and set_init_file filename = init_file := InitFile filename
@@ -296,17 +289,20 @@ let millisleep n =
  *)
 let get_string maxlen =
   ignore (echo ());
-  let str = String.create maxlen in
-  let ok = getstr str in (* Safe because binding calls getnstr. *)
+  let str = Bytes.create maxlen in
+  (* Safe because binding calls getnstr.  However the unsafe cast
+   * to string is required because ocaml-curses needs to be fixed.
+   *)
+  let ok = getstr (Obj.magic str) in
   ignore (noecho ());
   if not ok then ""
   else (
     (* Chop at first '\0'. *)
     try
-      let i = String.index str '\000' in
-      String.sub str 0 i
+      let i = Bytes.index str '\000' in
+      Bytes.sub_string str 0 i
     with
-      Not_found -> str (* it is full maxlen bytes *)
+      Not_found -> Bytes.to_string str (* it is full maxlen bytes *)
   )
 
 (* Main loop. *)
@@ -319,7 +315,7 @@ let rec main_loop ((_, batch_mode, script_mode, csv_enabled, stream_mode, _, _,
 
   while not !quit do
     (* Collect stats. *)
-    let state = collect setup !block_in_bytes in
+    let state = collect setup in
     let pcpu_display =
       if !display_mode = PCPUDisplay then Some (collect_pcpu state)
       else None in
@@ -331,7 +327,7 @@ let rec main_loop ((_, batch_mode, script_mode, csv_enabled, stream_mode, _, _,
 
     (* Update CSV file. *)
     if csv_enabled then
-      Csv_output.append_csv setup csv_flags state;
+      Csv_output.append_csv setup csv_flags !block_in_bytes state;
 
     (* Append to stream output file. *)
     if stream_mode then
@@ -417,7 +413,7 @@ and change_delay () =
        delay := int_of_float (newdelay *. 1000.); false
       )
     with
-      Failure "float_of_string" ->
+      Failure _ ->
        print_msg (s_"Not a valid number"); true in
   refresh ();
   sleep (if error then 2 else 1)