Parcourir la source

Stop using biniou format for tmp file

 + The bin_prot format bundled with Core is faster, produce smaller file and remove dependancies.
 + Remove Atdgen related file but not dependency, since it's used to import configuration file.
 + Done a bit of clean-up of tmp_file.
 + All tests pass! (the long way)
Leo il y a 8 ans
Parent
commit
21b9d2400f
10 fichiers modifiés avec 39 ajouts et 640 suppressions
  1. 3 0
      CHANGELOG.md
  2. 0 54
      src/tmp_biniou.atd
  3. 0 353
      src/tmp_biniou_b.ml
  4. 0 120
      src/tmp_biniou_b.mli
  5. 0 8
      src/tmp_biniou_t.ml
  6. 0 8
      src/tmp_biniou_t.mli
  7. 0 41
      src/tmp_biniou_v.ml
  8. 0 35
      src/tmp_biniou_v.mli
  9. 30 19
      src/tmp_file.ml
  10. 6 2
      src/tmp_file.mli

+ 3 - 0
CHANGELOG.md

@@ -18,6 +18,9 @@ This version introduce major changes in the tmp and rc file.
      number of launch when nothing is actually launched).
     + Change name to improve multi-user compatibility.
     + For the future : Running infinite, daemon mode...
+    + Format changed too, from [biniou](http://mjambon.com/biniou.html) to
+      [Bin\_proto](https://github.com/janestreet/bin_prot). This is faster and
+      remove dependencies since it's included in Core library.
  + New format and structure for the rc file, using **serial expression**: (see #5)
     + Allows to add tags to command
     + Allow to contain setting

+ 0 - 54
src/tmp_biniou.atd

@@ -1,54 +0,0 @@
-(******************************************************************************)
-(* Copyright © Joly Clément, 2014                                             *)
-(*                                                                            *)
-(*  leowzukw@oclaunch.eu.org                                                  *)
-(*                                                                            *)
-(*  Ce logiciel est un programme informatique servant à exécuter              *)
-(*  automatiquement des programmes à l'ouverture du terminal.                 *)
-(*                                                                            *)
-(*  Ce logiciel est régi par la licence CeCILL soumise au droit français et   *)
-(*  respectant les principes de diffusion des logiciels libres. Vous pouvez   *)
-(*  utiliser, modifier et/ou redistribuer ce programme sous les conditions    *)
-(*  de la licence CeCILL telle que diffusée par le CEA, le CNRS et l'INRIA    *)
-(*  sur le site "http://www.cecill.info".                                     *)
-(*                                                                            *)
-(*  En contrepartie de l'accessibilité au code source et des droits de copie, *)
-(*  de modification et de redistribution accordés par cette licence, il n'est *)
-(*  offert aux utilisateurs qu'une garantie limitée.  Pour les mêmes raisons, *)
-(*  seule une responsabilité restreinte pèse sur l'auteur du programme,  le   *)
-(*  titulaire des droits patrimoniaux et les concédants successifs.           *)
-(*                                                                            *)
-(*  A cet égard  l'attention de l'utilisateur est attirée sur les risques     *)
-(*  associés au chargement,  à l'utilisation,  à la modification et/ou au     *)
-(*  développement et à la reproduction du logiciel par l'utilisateur étant    *)
-(*  donné sa spécificité de logiciel libre, qui peut le rendre complexe à     *)
-(*  manipuler et qui le réserve donc à des développeurs et des professionnels *)
-(*  avertis possédant  des  connaissances  informatiques approfondies.  Les   *)
-(*  utilisateurs sont donc invités à charger  et  tester  l'adéquation  du    *)
-(*  logiciel à leurs besoins dans des conditions permettant d'assurer la      *)
-(*  sécurité de leurs systèmes et ou de leurs données et, plus généralement,  *)
-(*  à l'utiliser et l'exploiter dans les mêmes conditions de sécurité.        *)
-(*                                                                            *)
-(*  Le fait que vous puissiez accéder à cet en-tête signifie que vous avez    *)
-(*  pris connaissance de la licence CeCILL, et que vous en avez accepté les   *)
-(*  termes.                                                                   *)
-(******************************************************************************)
-
-(* Tmp file is where launch are logged in.
- * This atd file allow to use biniou easier in tmp file. The purpuse is to save
- * place, get faster parsing and make harder manual, unwanted modification. A special command line is
- * available to change current number *)
-
-(* Store values from the configuration file *)
-type rc_entry = {
-    commands: (string * int); (* A list of command, with current number, i.e. number
-    of launches *)
-}
-
-type rc_name = string
-
-(* Source of the file *)
-type tmp_file = {
-  rc: (rc_name * (rc_entry list)) list; (* A list of rc files *)
-    daemon: int; (* The current state of the daemon, maybe by pid *)
-}

+ 0 - 353
src/tmp_biniou_b.ml

@@ -1,353 +0,0 @@
-(* Auto-generated from "tmp_biniou.atd" *)
-
-
-type rc_name = Tmp_biniou_t.rc_name
-
-type rc_entry = Tmp_biniou_t.rc_entry = { commands: (string * int) }
-
-type tmp_file = Tmp_biniou_t.tmp_file = {
-  rc: (rc_name * (rc_entry list)) list;
-  daemon: int
-}
-
-let rc_name_tag = Bi_io.string_tag
-let write_untagged_rc_name = (
-  Bi_io.write_untagged_string
-)
-let write_rc_name ob x =
-  Bi_io.write_tag ob Bi_io.string_tag;
-  write_untagged_rc_name ob x
-let string_of_rc_name ?(len = 1024) x =
-  let ob = Bi_outbuf.create len in
-  write_rc_name ob x;
-  Bi_outbuf.contents ob
-let get_rc_name_reader = (
-  Ag_ob_run.get_string_reader
-)
-let read_rc_name = (
-  Ag_ob_run.read_string
-)
-let rc_name_of_string ?pos s =
-  read_rc_name (Bi_inbuf.from_string ?pos s)
-let rc_entry_tag = Bi_io.record_tag
-let write_untagged_rc_entry : Bi_outbuf.t -> rc_entry -> unit = (
-  fun ob x ->
-    Bi_vint.write_uvint ob 1;
-    Bi_outbuf.add_char4 ob '\190' 'U' '\176' '\200';
-    (
-      fun ob x ->
-        Bi_io.write_tag ob Bi_io.tuple_tag;
-        Bi_vint.write_uvint ob 2;
-        (
-          let x, _ = x in (
-            Bi_io.write_string
-          ) ob x
-        );
-        (
-          let _, x = x in (
-            Bi_io.write_svint
-          ) ob x
-        );
-    ) ob x.commands;
-)
-let write_rc_entry ob x =
-  Bi_io.write_tag ob Bi_io.record_tag;
-  write_untagged_rc_entry ob x
-let string_of_rc_entry ?(len = 1024) x =
-  let ob = Bi_outbuf.create len in
-  write_rc_entry ob x;
-  Bi_outbuf.contents ob
-let get_rc_entry_reader = (
-  fun tag ->
-    if tag <> 21 then Ag_ob_run.read_error () else
-      fun ib ->
-        let field_commands = ref (Obj.magic (Sys.opaque_identity 0.0)) in
-        let bits0 = ref 0 in
-        let len = Bi_vint.read_uvint ib in
-        for i = 1 to len do
-          match Bi_io.read_field_hashtag ib with
-            | 1045803208 ->
-              field_commands := (
-                (
-                  fun ib ->
-                    if Bi_io.read_tag ib <> 20 then Ag_ob_run.read_error_at ib;
-                    let len = Bi_vint.read_uvint ib in
-                    if len < 2 then Ag_ob_run.missing_tuple_fields len [ 0; 1 ];
-                    let x0 =
-                      (
-                        Ag_ob_run.read_string
-                      ) ib
-                    in
-                    let x1 =
-                      (
-                        Ag_ob_run.read_int
-                      ) ib
-                    in
-                    for i = 2 to len - 1 do Bi_io.skip ib done;
-                    (x0, x1)
-                ) ib
-              );
-              bits0 := !bits0 lor 0x1;
-            | _ -> Bi_io.skip ib
-        done;
-        if !bits0 <> 0x1 then Ag_ob_run.missing_fields [| !bits0 |] [| "commands" |];
-        (
-          {
-            commands = !field_commands;
-          }
-         : rc_entry)
-)
-let read_rc_entry = (
-  fun ib ->
-    if Bi_io.read_tag ib <> 21 then Ag_ob_run.read_error_at ib;
-    let field_commands = ref (Obj.magic (Sys.opaque_identity 0.0)) in
-    let bits0 = ref 0 in
-    let len = Bi_vint.read_uvint ib in
-    for i = 1 to len do
-      match Bi_io.read_field_hashtag ib with
-        | 1045803208 ->
-          field_commands := (
-            (
-              fun ib ->
-                if Bi_io.read_tag ib <> 20 then Ag_ob_run.read_error_at ib;
-                let len = Bi_vint.read_uvint ib in
-                if len < 2 then Ag_ob_run.missing_tuple_fields len [ 0; 1 ];
-                let x0 =
-                  (
-                    Ag_ob_run.read_string
-                  ) ib
-                in
-                let x1 =
-                  (
-                    Ag_ob_run.read_int
-                  ) ib
-                in
-                for i = 2 to len - 1 do Bi_io.skip ib done;
-                (x0, x1)
-            ) ib
-          );
-          bits0 := !bits0 lor 0x1;
-        | _ -> Bi_io.skip ib
-    done;
-    if !bits0 <> 0x1 then Ag_ob_run.missing_fields [| !bits0 |] [| "commands" |];
-    (
-      {
-        commands = !field_commands;
-      }
-     : rc_entry)
-)
-let rc_entry_of_string ?pos s =
-  read_rc_entry (Bi_inbuf.from_string ?pos s)
-let _1_tag = Bi_io.array_tag
-let write_untagged__1 = (
-  Ag_ob_run.write_untagged_list
-    rc_entry_tag
-    (
-      write_untagged_rc_entry
-    )
-)
-let write__1 ob x =
-  Bi_io.write_tag ob Bi_io.array_tag;
-  write_untagged__1 ob x
-let string_of__1 ?(len = 1024) x =
-  let ob = Bi_outbuf.create len in
-  write__1 ob x;
-  Bi_outbuf.contents ob
-let get__1_reader = (
-  Ag_ob_run.get_list_reader (
-    get_rc_entry_reader
-  )
-)
-let read__1 = (
-  Ag_ob_run.read_list (
-    get_rc_entry_reader
-  )
-)
-let _1_of_string ?pos s =
-  read__1 (Bi_inbuf.from_string ?pos s)
-let _2_tag = Bi_io.array_tag
-let write_untagged__2 = (
-  Ag_ob_run.write_untagged_list
-    Bi_io.tuple_tag
-    (
-      fun ob x ->
-        Bi_vint.write_uvint ob 2;
-        (
-          let x, _ = x in (
-            write_rc_name
-          ) ob x
-        );
-        (
-          let _, x = x in (
-            fun ob x ->
-              Bi_io.write_tag ob Bi_io.tuple_tag;
-              Bi_vint.write_uvint ob 1;
-              (
-                let x = x in (
-                  write__1
-                ) ob x
-              );
-          ) ob x
-        );
-    )
-)
-let write__2 ob x =
-  Bi_io.write_tag ob Bi_io.array_tag;
-  write_untagged__2 ob x
-let string_of__2 ?(len = 1024) x =
-  let ob = Bi_outbuf.create len in
-  write__2 ob x;
-  Bi_outbuf.contents ob
-let get__2_reader = (
-  Ag_ob_run.get_list_reader (
-    fun tag ->
-      if tag <> 20 then Ag_ob_run.read_error () else
-        fun ib ->
-          let len = Bi_vint.read_uvint ib in
-          if len < 2 then Ag_ob_run.missing_tuple_fields len [ 0; 1 ];
-          let x0 =
-            (
-              read_rc_name
-            ) ib
-          in
-          let x1 =
-            (
-              fun ib ->
-                if Bi_io.read_tag ib <> 20 then Ag_ob_run.read_error_at ib;
-                let len = Bi_vint.read_uvint ib in
-                if len < 1 then Ag_ob_run.missing_tuple_fields len [ 0 ];
-                let x0 =
-                  (
-                    read__1
-                  ) ib
-                in
-                for i = 1 to len - 1 do Bi_io.skip ib done;
-                (x0)
-            ) ib
-          in
-          for i = 2 to len - 1 do Bi_io.skip ib done;
-          (x0, x1)
-  )
-)
-let read__2 = (
-  Ag_ob_run.read_list (
-    fun tag ->
-      if tag <> 20 then Ag_ob_run.read_error () else
-        fun ib ->
-          let len = Bi_vint.read_uvint ib in
-          if len < 2 then Ag_ob_run.missing_tuple_fields len [ 0; 1 ];
-          let x0 =
-            (
-              read_rc_name
-            ) ib
-          in
-          let x1 =
-            (
-              fun ib ->
-                if Bi_io.read_tag ib <> 20 then Ag_ob_run.read_error_at ib;
-                let len = Bi_vint.read_uvint ib in
-                if len < 1 then Ag_ob_run.missing_tuple_fields len [ 0 ];
-                let x0 =
-                  (
-                    read__1
-                  ) ib
-                in
-                for i = 1 to len - 1 do Bi_io.skip ib done;
-                (x0)
-            ) ib
-          in
-          for i = 2 to len - 1 do Bi_io.skip ib done;
-          (x0, x1)
-  )
-)
-let _2_of_string ?pos s =
-  read__2 (Bi_inbuf.from_string ?pos s)
-let tmp_file_tag = Bi_io.record_tag
-let write_untagged_tmp_file : Bi_outbuf.t -> tmp_file -> unit = (
-  fun ob x ->
-    Bi_vint.write_uvint ob 2;
-    Bi_outbuf.add_char4 ob '\128' '\000' 'c' '\177';
-    (
-      write__2
-    ) ob x.rc;
-    Bi_outbuf.add_char4 ob '\152' '\163' '\253' '\132';
-    (
-      Bi_io.write_svint
-    ) ob x.daemon;
-)
-let write_tmp_file ob x =
-  Bi_io.write_tag ob Bi_io.record_tag;
-  write_untagged_tmp_file ob x
-let string_of_tmp_file ?(len = 1024) x =
-  let ob = Bi_outbuf.create len in
-  write_tmp_file ob x;
-  Bi_outbuf.contents ob
-let get_tmp_file_reader = (
-  fun tag ->
-    if tag <> 21 then Ag_ob_run.read_error () else
-      fun ib ->
-        let field_rc = ref (Obj.magic (Sys.opaque_identity 0.0)) in
-        let field_daemon = ref (Obj.magic (Sys.opaque_identity 0.0)) in
-        let bits0 = ref 0 in
-        let len = Bi_vint.read_uvint ib in
-        for i = 1 to len do
-          match Bi_io.read_field_hashtag ib with
-            | 25521 ->
-              field_rc := (
-                (
-                  read__2
-                ) ib
-              );
-              bits0 := !bits0 lor 0x1;
-            | 413400452 ->
-              field_daemon := (
-                (
-                  Ag_ob_run.read_int
-                ) ib
-              );
-              bits0 := !bits0 lor 0x2;
-            | _ -> Bi_io.skip ib
-        done;
-        if !bits0 <> 0x3 then Ag_ob_run.missing_fields [| !bits0 |] [| "rc"; "daemon" |];
-        (
-          {
-            rc = !field_rc;
-            daemon = !field_daemon;
-          }
-         : tmp_file)
-)
-let read_tmp_file = (
-  fun ib ->
-    if Bi_io.read_tag ib <> 21 then Ag_ob_run.read_error_at ib;
-    let field_rc = ref (Obj.magic (Sys.opaque_identity 0.0)) in
-    let field_daemon = ref (Obj.magic (Sys.opaque_identity 0.0)) in
-    let bits0 = ref 0 in
-    let len = Bi_vint.read_uvint ib in
-    for i = 1 to len do
-      match Bi_io.read_field_hashtag ib with
-        | 25521 ->
-          field_rc := (
-            (
-              read__2
-            ) ib
-          );
-          bits0 := !bits0 lor 0x1;
-        | 413400452 ->
-          field_daemon := (
-            (
-              Ag_ob_run.read_int
-            ) ib
-          );
-          bits0 := !bits0 lor 0x2;
-        | _ -> Bi_io.skip ib
-    done;
-    if !bits0 <> 0x3 then Ag_ob_run.missing_fields [| !bits0 |] [| "rc"; "daemon" |];
-    (
-      {
-        rc = !field_rc;
-        daemon = !field_daemon;
-      }
-     : tmp_file)
-)
-let tmp_file_of_string ?pos s =
-  read_tmp_file (Bi_inbuf.from_string ?pos s)

+ 0 - 120
src/tmp_biniou_b.mli

@@ -1,120 +0,0 @@
-(* Auto-generated from "tmp_biniou.atd" *)
-
-
-type rc_name = Tmp_biniou_t.rc_name
-
-type rc_entry = Tmp_biniou_t.rc_entry = { commands: (string * int) }
-
-type tmp_file = Tmp_biniou_t.tmp_file = {
-  rc: (rc_name * (rc_entry list)) list;
-  daemon: int
-}
-
-(* Writers for type rc_name *)
-
-val rc_name_tag : Bi_io.node_tag
-  (** Tag used by the writers for type {!rc_name}.
-      Readers may support more than just this tag. *)
-
-val write_untagged_rc_name :
-  Bi_outbuf.t -> rc_name -> unit
-  (** Output an untagged biniou value of type {!rc_name}. *)
-
-val write_rc_name :
-  Bi_outbuf.t -> rc_name -> unit
-  (** Output a biniou value of type {!rc_name}. *)
-
-val string_of_rc_name :
-  ?len:int -> rc_name -> string
-  (** Serialize a value of type {!rc_name} into
-      a biniou string. *)
-
-(* Readers for type rc_name *)
-
-val get_rc_name_reader :
-  Bi_io.node_tag -> (Bi_inbuf.t -> rc_name)
-  (** Return a function that reads an untagged
-      biniou value of type {!rc_name}. *)
-
-val read_rc_name :
-  Bi_inbuf.t -> rc_name
-  (** Input a tagged biniou value of type {!rc_name}. *)
-
-val rc_name_of_string :
-  ?pos:int -> string -> rc_name
-  (** Deserialize a biniou value of type {!rc_name}.
-      @param pos specifies the position where
-                 reading starts. Default: 0. *)
-
-(* Writers for type rc_entry *)
-
-val rc_entry_tag : Bi_io.node_tag
-  (** Tag used by the writers for type {!rc_entry}.
-      Readers may support more than just this tag. *)
-
-val write_untagged_rc_entry :
-  Bi_outbuf.t -> rc_entry -> unit
-  (** Output an untagged biniou value of type {!rc_entry}. *)
-
-val write_rc_entry :
-  Bi_outbuf.t -> rc_entry -> unit
-  (** Output a biniou value of type {!rc_entry}. *)
-
-val string_of_rc_entry :
-  ?len:int -> rc_entry -> string
-  (** Serialize a value of type {!rc_entry} into
-      a biniou string. *)
-
-(* Readers for type rc_entry *)
-
-val get_rc_entry_reader :
-  Bi_io.node_tag -> (Bi_inbuf.t -> rc_entry)
-  (** Return a function that reads an untagged
-      biniou value of type {!rc_entry}. *)
-
-val read_rc_entry :
-  Bi_inbuf.t -> rc_entry
-  (** Input a tagged biniou value of type {!rc_entry}. *)
-
-val rc_entry_of_string :
-  ?pos:int -> string -> rc_entry
-  (** Deserialize a biniou value of type {!rc_entry}.
-      @param pos specifies the position where
-                 reading starts. Default: 0. *)
-
-(* Writers for type tmp_file *)
-
-val tmp_file_tag : Bi_io.node_tag
-  (** Tag used by the writers for type {!tmp_file}.
-      Readers may support more than just this tag. *)
-
-val write_untagged_tmp_file :
-  Bi_outbuf.t -> tmp_file -> unit
-  (** Output an untagged biniou value of type {!tmp_file}. *)
-
-val write_tmp_file :
-  Bi_outbuf.t -> tmp_file -> unit
-  (** Output a biniou value of type {!tmp_file}. *)
-
-val string_of_tmp_file :
-  ?len:int -> tmp_file -> string
-  (** Serialize a value of type {!tmp_file} into
-      a biniou string. *)
-
-(* Readers for type tmp_file *)
-
-val get_tmp_file_reader :
-  Bi_io.node_tag -> (Bi_inbuf.t -> tmp_file)
-  (** Return a function that reads an untagged
-      biniou value of type {!tmp_file}. *)
-
-val read_tmp_file :
-  Bi_inbuf.t -> tmp_file
-  (** Input a tagged biniou value of type {!tmp_file}. *)
-
-val tmp_file_of_string :
-  ?pos:int -> string -> tmp_file
-  (** Deserialize a biniou value of type {!tmp_file}.
-      @param pos specifies the position where
-                 reading starts. Default: 0. *)
-

+ 0 - 8
src/tmp_biniou_t.ml

@@ -1,8 +0,0 @@
-(* Auto-generated from "tmp_biniou.atd" *)
-
-
-type rc_name = string
-
-type rc_entry = { commands: (string * int) }
-
-type tmp_file = { rc: (rc_name * (rc_entry list)) list; daemon: int }

+ 0 - 8
src/tmp_biniou_t.mli

@@ -1,8 +0,0 @@
-(* Auto-generated from "tmp_biniou.atd" *)
-
-
-type rc_name = string
-
-type rc_entry = { commands: (string * int) }
-
-type tmp_file = { rc: (rc_name * (rc_entry list)) list; daemon: int }

+ 0 - 41
src/tmp_biniou_v.ml

@@ -1,41 +0,0 @@
-(* Auto-generated from "tmp_biniou.atd" *)
-
-
-type rc_name = Tmp_biniou_t.rc_name
-
-type rc_entry = Tmp_biniou_t.rc_entry = { commands: (string * int) }
-
-type tmp_file = Tmp_biniou_t.tmp_file = {
-  rc: (rc_name * (rc_entry list)) list;
-  daemon: int
-}
-
-let validate_rc_name = (
-  (fun _ _ -> None)
-)
-let validate_rc_entry : _ -> rc_entry -> _ = (
-  fun _ _ -> None
-)
-let validate__1 = (
-  fun _ _ -> None
-)
-let validate__2 = (
-  fun _ _ -> None
-)
-let validate_tmp_file : _ -> tmp_file -> _ = (
-  fun _ _ -> None
-)
-let create_rc_entry 
-  ~commands
-  () : rc_entry =
-  {
-    commands = commands;
-  }
-let create_tmp_file 
-  ~rc
-  ~daemon
-  () : tmp_file =
-  {
-    rc = rc;
-    daemon = daemon;
-  }

+ 0 - 35
src/tmp_biniou_v.mli

@@ -1,35 +0,0 @@
-(* Auto-generated from "tmp_biniou.atd" *)
-
-
-type rc_name = Tmp_biniou_t.rc_name
-
-type rc_entry = Tmp_biniou_t.rc_entry = { commands: (string * int) }
-
-type tmp_file = Tmp_biniou_t.tmp_file = {
-  rc: (rc_name * (rc_entry list)) list;
-  daemon: int
-}
-
-val validate_rc_name :
-  Ag_util.Validation.path -> rc_name -> Ag_util.Validation.error option
-  (** Validate a value of type {!rc_name}. *)
-
-val create_rc_entry :
-  commands: (string * int) ->
-  unit -> rc_entry
-  (** Create a record of type {!rc_entry}. *)
-
-val validate_rc_entry :
-  Ag_util.Validation.path -> rc_entry -> Ag_util.Validation.error option
-  (** Validate a value of type {!rc_entry}. *)
-
-val create_tmp_file :
-  rc: (rc_name * (rc_entry list)) list ->
-  daemon: int ->
-  unit -> tmp_file
-  (** Create a record of type {!tmp_file}. *)
-
-val validate_tmp_file :
-  Ag_util.Validation.path -> tmp_file -> Ag_util.Validation.error option
-  (** Validate a value of type {!tmp_file}. *)
-

+ 30 - 19
src/tmp_file.ml

@@ -1,5 +1,5 @@
 (******************************************************************************)
-(* Copyright © Joly Clément, 2014-2015                                        *)
+(* Copyright © Joly Clément, 2014-2016                                        *)
 (*                                                                            *)
 (*  leowzukw@oclaunch.eu.org                                                  *)
 (*                                                                            *)
@@ -37,14 +37,30 @@
 open Core.Std;;
 
 (* Type of the values *)
-type t = Tmp_biniou_t.tmp_file;;
+type rc_name = string [@@deriving bin_io];;
+type rc_entry = { commands: (string * int) } [@@deriving bin_io];;
+type tmp_file = { rc: (rc_name * (rc_entry list)) list; daemon: int } [@@deriving bin_io];;
+type t = tmp_file;;
+
+(* To use with Binable module *)
+module T = struct
+  type t = tmp_file [@@deriving bin_io]
+end;;
+
+(* Get Bin_prot representation of data (string) *)
+let serialise data =
+  Binable.to_string (module T) data
+;;
+(* Get data from Bin_prot representation (string) *)
+let deserialise data =
+  Binable.of_string (module T) data
+;;
 
 (* Function to write the tmp file *)
 let write (tmp_file:t) =
   (* Short name *)
   let name = Const.tmp_file in
-  let biniou_tmp = Tmp_biniou_b.string_of_tmp_file tmp_file in
-  Out_channel.write_all name ~data:biniou_tmp
+  Out_channel.write_all name ~data:(serialise tmp_file)
 ;;
 
 (* XXX Using and keyword because each function can call each other *)
@@ -55,10 +71,7 @@ let rec read () =
   (* Get the string corresponding to the file *)
   let file_content = In_channel.read_all name in
   try
-    Tmp_biniou_b.tmp_file_of_string file_content
-  (* In previous version, the JSON format was used, otherwise the file can
-   * have a bad format. In this case, the Ag_ob_run.Error("Read error (1)")
-   * exeption is throw. We catch it here *)
+    deserialise file_content
   with _ ->
     (* If file is not in the right format, delete it and create a new one.
      * Then, read it *)
@@ -67,11 +80,10 @@ let rec read () =
     create_tmp_file ();
     read ()
 
-(* Function to create the tmp file *)
+(* Function to create an empty tmp file *)
 and create_tmp_file () =
   (* An empty list, without rc, commands, launch... *)
-  Tmp_biniou_v.create_tmp_file ~daemon:0 ~rc:[] ()
-  (* Convert it to biniou *)
+  { daemon = 0; rc = [] }
   |> write
 ;;
 
@@ -92,7 +104,7 @@ let rec init () =
 (* Get a log of values from the tmp file, like this
  * (cmd,number of launch) list *)
 let get_log ~rc_tmp =
-  List.map ~f:(fun { Tmp_biniou_t.commands = (cmd,number) } ->
+  List.map ~f:(fun { commands = (cmd,number) } ->
          (cmd,number)) rc_tmp
 ;;
 
@@ -121,22 +133,21 @@ let log ~cmd ?(func= (+) 1 ) () =
   (* Get rc_file name *)
   let name = Lazy.force !Const.rc_file in
   (* Function to generate the new list with right number *)
-  let new_li (li : Tmp_biniou_t.rc_entry list) =
+  let new_li (li : rc_entry list) =
     let open List.Assoc in
     (* Only number of launch associated with commands *)
     let l = get_log ~rc_tmp:li in
     find l cmd
     |> (function None -> add l cmd Const.default_launch | Some n -> add l cmd (func n))
-    |> List.map ~f:(fun e -> { Tmp_biniou_t.commands = e})
+    |> List.map ~f:(fun e -> { commands = e})
   in
   (* Write the file with the new value *)
   let updated_li =
-    List.Assoc.(find file.Tmp_biniou_t.rc name)
+    List.Assoc.(find file.rc name)
     |> Option.value ~default:[]
     |> new_li
   in
-  write Tmp_biniou_t.{ file with rc = List.Assoc.add file.rc name
-                                        updated_li }
+  write { file with rc = List.Assoc.add file.rc name updated_li }
 ;;
 
 (* Return current number *)
@@ -157,7 +168,7 @@ type accurate_log_simple =
 let get_accurate_log_complete ?rc_name ~tmp () =
   let open List in
   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
+  let rc_in_tmp = get_log ~rc_tmp:(Assoc.find tmp.rc rc#get_name
                                    |> Option.value ~default:[])
   in
   map rc#entries ~f:(fun entry ->
@@ -234,7 +245,7 @@ let reset_all () =
     let tmp = init () in
     (* Get rc_file name *)
     let name = Lazy.force !Const.rc_file in
-    write Tmp_biniou_t.{ tmp with rc = List.Assoc.add tmp.rc name [] }
+    write { tmp with rc = List.Assoc.add tmp.rc name [] }
   in
   Messages.debug "Asking question";
   Messages.confirm "You will lose number of launch for every command. \

+ 6 - 2
src/tmp_file.mli

@@ -1,5 +1,5 @@
 (******************************************************************************)
-(* Copyright © Joly Clément, 2014                                             *)
+(* Copyright © Joly Clément, 2014-2016                                        *)
 (*                                                                            *)
 (*  leowzukw@oclaunch.eu.org                                                  *)
 (*                                                                            *)
@@ -34,7 +34,11 @@
 (*  termes.                                                                   *)
 (******************************************************************************)
 
-type t = Tmp_biniou_t.tmp_file
+type rc_name = string;;
+type rc_entry = { commands: (string * int) };;
+type tmp_file = { rc: (rc_name * (rc_entry list)) list; daemon: int };;
+type t = tmp_file;;
+
 val write : t -> unit
 
 (* Use this function to read tmp file, it will be created if necessary *)