Browse Source

Adapt tmp_file module to new rc

 + Split logs in two parts:
   + One with tuple of string and int list
   + Another with tuple of entry (object) and int list
 + Remove useless argument of some function.
 + Doesn't build, since this creates type problem in command def.
Leo 8 years ago
parent
commit
bb52e6dae0
3 changed files with 42 additions and 20 deletions
  1. 1 1
      src/command_def.ml
  2. 31 16
      src/tmp_file.ml
  3. 10 3
      src/tmp_file.mli

+ 1 - 1
src/command_def.ml

@@ -154,7 +154,7 @@ let reset =
         * num: number to reset *)
         * num: number to reset *)
        let rc = Lazy.force rc in
        let rc = Lazy.force rc in
        match ( num, cmd ) with
        match ( num, cmd ) with
-       | ( num, None ) | ( num, Some [] ) -> Tmp_file.reset2num ~rc num
+       | ( num, None ) | ( num, Some [] ) -> Tmp_file.reset2num num
        | ( num, Some cmd_list ) ->
        | ( num, Some cmd_list ) ->
          List.iter ~f:(fun cmd -> Tmp_file.reset_cmd ~rc num cmd) cmd_list
          List.iter ~f:(fun cmd -> Tmp_file.reset_cmd ~rc num cmd) cmd_list
     )
     )

+ 31 - 16
src/tmp_file.ml

@@ -144,30 +144,45 @@ let get_current () =
   failwith "Deprecated"
   failwith "Deprecated"
 ;;
 ;;
 
 
+(* Types used to return accurate logs *)
+type accurate_log =
+  (Rc.entry * int) list
+;;
+type accurate_log_simple =
+  (string * int) list
+;;
+
 (* Get number of launch for each command in rc file, as follow:
 (* Get number of launch for each command in rc file, as follow:
- * (command:string, number of the command:int) list *)
-let get_accurate_log ?rc_name ~tmp () =
+ * (Rc.entry, number of launch for the command:int) list *)
+let get_accurate_log_complete ?rc_name ~tmp () =
   let open List in
   let open List in
-
-  (* Read rc *)
-  (* XXX Forcing evaluation of lazy value Const.rc_file before it is
-   *   necessary *)
-  let name : string = Option.value ~default:(Lazy.force !Const.rc_file) rc_name
-  in
-  let rc =  File_com.init_rc ~rc:(Lazy.return name) () in
-
-  let rc_in_tmp = get_log ~rc_tmp:(Assoc.find tmp.Tmp_biniou_t.rc name
+  let rc = Rc.init ?rc:rc_name () in
+  let rc_in_tmp = get_log ~rc_tmp:(Assoc.find tmp.Tmp_biniou_t.rc rc#get_name
                                    |> Option.value ~default:[])
                                    |> Option.value ~default:[])
   in
   in
-  map rc.Settings_t.progs ~f:(fun key ->
+  map rc#entries ~f:(fun entry ->
+         let key = entry#command in
          Assoc.find rc_in_tmp key
          Assoc.find rc_in_tmp key
          |> Option.value ~default:0
          |> Option.value ~default:0
-         |> (function number -> (key,number)))
+         |> (function number -> (entry, number)))
+;;
+
+(* Get (may transform an existing log) number of launch for each command in rc file, as follow:
+ * (command:string, number of launch for the command:int) list *)
+let get_accurate_log ?entry_log ~tmp () =
+  let entry_log =
+    match entry_log with
+    | None -> get_accurate_log_complete ~tmp ()
+    | Some log -> log
+  in
+  entry_log |>
+  List.map ~f:(fun (entry, nb_of_launch) -> (entry#command, nb_of_launch))
 ;;
 ;;
 
 
 (* Reset number of launch for a given command
 (* Reset number of launch for a given command
  * cmd: number of the command to be reseted
  * cmd: number of the command to be reseted
  * num: number to reset *)
  * num: number to reset *)
+(* FIXME cmd is not very clear for a command number *)
 let reset_cmd ~rc num cmd =
 let reset_cmd ~rc num cmd =
   (* Debugging *)
   (* Debugging *)
   [(num,"num") ; (cmd,"cmd")]
   [(num,"num") ; (cmd,"cmd")]
@@ -177,9 +192,9 @@ let reset_cmd ~rc num cmd =
   let ac_log = get_accurate_log ~tmp:(init ()) () in
   let ac_log = get_accurate_log ~tmp:(init ()) () in
   (* The command (string) corresponding to the number *)
   (* The command (string) corresponding to the number *)
   let cmd_str =
   let cmd_str =
-    File_com.num_cmd2cmd ~rc cmd
+    rc#entry ~n:cmd
     |> function
     |> function
-      Some s -> s
+      Some s -> s#command
     | None -> failwith "Out of bound"
     | None -> failwith "Out of bound"
   in
   in
 
 
@@ -199,7 +214,7 @@ let reset_cmd ~rc num cmd =
 
 
 (* Reset all commands to a number
 (* Reset all commands to a number
  * num: number to reset *)
  * num: number to reset *)
-let reset2num ~rc num =
+let reset2num num =
   (* Debugging *)
   (* Debugging *)
   "Num: " ^ (Int.to_string num)
   "Num: " ^ (Int.to_string num)
   |> Messages.debug;
   |> Messages.debug;

+ 10 - 3
src/tmp_file.mli

@@ -43,10 +43,17 @@ val init : unit -> t
 val verify_key_exist : key:'a -> 'a -> bool
 val verify_key_exist : key:'a -> 'a -> bool
 val is_prog_in_rc : 'a list -> 'a -> bool
 val is_prog_in_rc : 'a list -> 'a -> bool
 val log : cmd:string -> ?func:(int -> int) -> unit -> unit
 val log : cmd:string -> ?func:(int -> int) -> unit -> unit
+
 (** Return current state *)
 (** Return current state *)
 val get_current : unit -> int
 val get_current : unit -> int
-val get_accurate_log : ?rc_name:string -> tmp:t -> unit -> (string * int) list
+
+(* Accurate logs *)
+type accurate_log = (Rc.entry * int) list
+type accurate_log_simple = (string * int) list
+val get_accurate_log_complete : ?rc_name:string lazy_t -> tmp:t -> unit -> accurate_log
+val get_accurate_log : ?entry_log:accurate_log -> tmp:t -> unit -> accurate_log_simple
+
 (* Resetting command *)
 (* Resetting command *)
-val reset_cmd : rc:Settings_t.rc_file -> int -> int -> unit
-val reset2num : rc:Settings_t.rc_file -> int -> unit
+val reset_cmd : rc:Rc.t -> int -> int -> unit
+val reset2num : int -> unit
 val reset_all : unit -> unit
 val reset_all : unit -> unit