Browse Source

Add tmp file template

 - Correct some mistakes
Leo 10 years ago
parent
commit
6c08dc8f85
4 changed files with 27 additions and 6 deletions
  1. 1 1
      Makefile
  2. 2 0
      const.ml
  3. 10 1
      oclaunch.ml
  4. 14 4
      tmp_file.ml

+ 1 - 1
Makefile

@@ -5,4 +5,4 @@ atdgen-tmp:
 	atdgen -j settings.atd
 
 code:
-	corebuild -pkg yojson,atdgen oclaunch.byte
+	corebuild -pkg yojson,atdgen,core_extended oclaunch.byte

+ 2 - 0
const.ml

@@ -42,3 +42,5 @@ open Core.Std;;
 let rc_file = "rc_test.json";; (* TODO Dev value, change this *)
 (* Set tmp file, in witch stock launches *)
 let tmp_file = "tmp_test.json";; (* TODO Dev value, change this *)
+(* Template for the tmp file *)
+let (tmp_file_template:Yojson.Basic.json) = `Assoc [ ( "cmd", `List [] ) ];;

+ 10 - 1
oclaunch.ml

@@ -41,8 +41,17 @@ let rc_content = File_com.init_rc ~rc:Const.rc_file;;
 
 (* Obtain data from tmp file *)
 let tmp_content = Tmp_file.init ~tmp:Const.tmp_file;;
+(* Generate structure of tmp file *)
+Tmp_file.create_struct ~tmp_file:tmp_content;;
 
 (*
-(* Execute each item in config file *)
+(* Function to determinate what is the next command to
+ * execute *)
+let what_next =
+
+
+(* Execute each item (one by one)in config file *)
+Exec_cmd.excute
+
 List.map ~f:Exec_cmd.execute rc_content.progs;;
 *)

+ 14 - 4
tmp_file.ml

@@ -41,12 +41,22 @@ let create_tmp_file ~name =
   Out_channel.create name (* TODO create file in /tmp *)
 ;;
 
+(* Function to create the structure of the tmp file *)
+let create_struct ~tmp_file ~template =
+  "tmp"
+;;
+
 (* Function to open tmp file *)
-let init ~tmp =
+let rec init ~tmp =
   (* If file do not exists, create it *)
   let file_exists = (Sys.file_exists tmp) in
     match file_exists with
-      | `No | `Unknown -> create_tmp_file ~name:tmp
+      | `No -> let file = create_tmp_file ~name:tmp in
+          init ~tmp:tmp
+      | `Unknown -> begin
+          Core_extended.Shell.rm tmp;
+          init ~tmp:tmp
+        end
       | `Yes -> Yojson.Basic.from_file tmp
 ;;
 
@@ -66,8 +76,8 @@ let stock_tmp ~key ~value ~target =
 ;;
 
 (* Return true if a program is in the rc file *)
-let rec is_prog_in_rc list_from_rc_file program = (* TODO restaure ?(liste_from_rc_file=rc_content.progs) *)
-    match liste_from_rc_file with
+let rec is_prog_in_rc list_from_rc_file program = (* TODO restaure ?(list_from_rc_file=rc_content.progs) *)
+    match list_from_rc_file with
     (* | None -> is_prog_in_rc program ~liste_from_rc_file:rc_content.progs *)
     | [] -> false
     | hd :: tl -> if hd = program then true else is_prog_in_rc tl program