123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147 |
- open Core.Std;;
- type t = Tmp_biniou_t.tmp_file;;
- let write (tmp_file:t) =
-
- 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
- ;;
- let rec read () =
-
- let name = Const.tmp_file in
-
- let file_content = In_channel.read_all name in
- try
- Tmp_biniou_b.tmp_file_of_string file_content
-
- with _ ->
-
- Messages.ok "Reinitialises tmp file\n";
- Sys.remove name;
- create_tmp_file ();
- read ()
- and create_tmp_file () =
- Tmp_biniou_v.create_tmp_file ~command:[] ~number:0 ()
-
- |> write
- ;;
- let rec init () =
-
- let file_exists = Sys.file_exists Const.tmp_file in
- match file_exists with
- | `No -> create_tmp_file ();
- init ()
- | `Unknown -> begin
- Sys.remove Const.tmp_file;
- init ()
- end
- | `Yes -> read ()
- ;;
- let verify_key_exist ~key entry =
- if entry = key then
- true
- else
- false
- ;;
- let rec is_prog_in_rc list_from_rc_file program =
- match list_from_rc_file with
-
- | [] -> false
- | hd :: tl -> if hd = program then true else is_prog_in_rc tl program
- ;;
- let log ?(func= (+) 1 ) () =
-
- let file = init () in
-
- write { file with Tmp_biniou_t.number = (func file.Tmp_biniou_t.number)}
- ;;
- let get_current () =
-
- let tmp_file = init () in
-
- tmp_file.Tmp_biniou_t.number;
- ;;
- let reset cmd_num =
- let n = get_current () in
- sprintf "Last N was %i" n
- |> Messages.info;
- sprintf "Restore with 'oclaunch -r %i'" n
- |> Messages.tips;
- match cmd_num with
- | 0 ->
- Sys.file_exists Const.tmp_file
- |> (function
- | `No -> Messages.ok "Tmp file already removed"
- | `Unknown -> Messages.warning "Error while removing tmp file"
- | `Yes -> Sys.remove Const.tmp_file; Messages.ok "Tmp file removed"
- )
- | n when n > 0 ->
-
- log ~func:((fun a b -> a) n) ();
- sprintf "Tmp file reseted to %i" n |> Messages.ok
- | _ -> Messages.warning "Invalid number"
- ;;
|