Skip to content
Snippets Groups Projects
Commit 9f3d8206 authored by Michele Alberti's avatar Michele Alberti
Browse files

[journal] Port to Filepath for session filename.

No internal representation change.
parent d991ac9c
No related branches found
No related tags found
No related merge requests found
...@@ -113,9 +113,11 @@ let now () = Unix.localtime (Unix.time ()) ...@@ -113,9 +113,11 @@ let now () = Unix.localtime (Unix.time ())
let default_filename = "frama_c_journal.ml" let default_filename = "frama_c_journal.ml"
let filename = ref default_filename let filename = ref default_filename
let get_session_file = ref (fun _ -> assert false) let get_session_file = ref (fun _ -> assert false)
let get_name () = let get_name () =
let f = !filename in let f = !filename in
if f == default_filename then !get_session_file f else f if f == default_filename
then !get_session_file f
else Datatype.Filepath.of_string f
let set_name s = filename := s let set_name s = filename := s
...@@ -136,11 +138,12 @@ let print_header fmt = ...@@ -136,11 +138,12 @@ let print_header fmt =
"(* Run the user commands *)@;@[<hv 2>let run () =@;@[<hv 0>" "(* Run the user commands *)@;@[<hv 2>let run () =@;@[<hv 0>"
let print_trailer fmt = let print_trailer fmt =
let name = Format.asprintf "%a" Datatype.Filepath.pretty (get_name ()) in
Format.fprintf fmt "@[(* Main *)@]@\n"; Format.fprintf fmt "@[(* Main *)@]@\n";
Format.fprintf fmt "@[<hv 2>let main () =@;"; Format.fprintf fmt "@[<hv 2>let main () =@;";
Format.fprintf fmt Format.fprintf fmt
"@[<hv 0>@[<hv 2>Journal.keep_file@;\"%s\";@]@;" "@[<hv 0>@[<hv 2>Journal.keep_file@;\"%s\";@]@;"
(get_name ()); name;
Format.fprintf fmt "try run ()@;"; Format.fprintf fmt "try run ()@;";
Format.fprintf fmt "@[<v>with@;@[<hv 2>| Unreachable ->@ "; Format.fprintf fmt "@[<v>with@;@[<hv 2>| Unreachable ->@ ";
Format.fprintf fmt Format.fprintf fmt
...@@ -155,7 +158,7 @@ let print_trailer fmt = ...@@ -155,7 +158,7 @@ let print_trailer fmt =
Format.fprintf fmt "@[(* Registering *)@]@\n"; Format.fprintf fmt "@[(* Registering *)@]@\n";
Format.fprintf fmt Format.fprintf fmt
"@[<hv 2>let main : unit -> unit =@;@[<hv 2>Dynamic.register@;~plugin:%S@;\"main\"@;" "@[<hv 2>let main : unit -> unit =@;@[<hv 2>Dynamic.register@;~plugin:%S@;\"main\"@;"
(String.capitalize_ascii (Filename.basename (get_name ()))); (String.capitalize_ascii (Filename.basename name));
Format.fprintf fmt Format.fprintf fmt
"@[<hv 2>(Datatype.func@;Datatype.unit@;Datatype.unit)@]@;"; "@[<hv 2>(Datatype.func@;Datatype.unit@;Datatype.unit)@]@;";
Format.fprintf fmt "~journalize:false@;main@]@]@\n@\n"; Format.fprintf fmt "~journalize:false@;main@]@]@\n@\n";
...@@ -173,7 +176,7 @@ let keep_file s = preserved_files := s :: !preserved_files ...@@ -173,7 +176,7 @@ let keep_file s = preserved_files := s :: !preserved_files
let get_filename = let get_filename =
let cpt = ref 0 in let cpt = ref 0 in
let rec get_filename first = let rec get_filename first =
let name = get_name () in let name = Format.asprintf "%a" Datatype.Filepath.pretty (get_name ()) in
if (not first && Sys.file_exists name) || List.mem name !preserved_files if (not first && Sys.file_exists name) || List.mem name !preserved_files
then begin then begin
incr cpt; incr cpt;
......
...@@ -83,7 +83,7 @@ end ...@@ -83,7 +83,7 @@ end
(** {2 Journal management} *) (** {2 Journal management} *)
(* ****************************************************************************) (* ****************************************************************************)
val get_name: unit -> string val get_name: unit -> Datatype.Filepath.t
(** @return the filename which the journal will be written into. *) (** @return the filename which the journal will be written into. *)
val set_name: string -> unit val set_name: string -> unit
...@@ -110,7 +110,7 @@ val keep_file: string -> unit ...@@ -110,7 +110,7 @@ val keep_file: string -> unit
(** This function has not to be used explicitly. Only offers functions (** This function has not to be used explicitly. Only offers functions
retrieving when running a journal file. *) retrieving when running a journal file. *)
val get_session_file: (string -> string) ref val get_session_file: (string -> Datatype.Filepath.t) ref
(* (*
Local Variables: Local Variables:
......
...@@ -417,11 +417,7 @@ struct ...@@ -417,11 +417,7 @@ struct
end) end)
let () = let () =
if is_kernel () if is_kernel ()
then then Journal.get_session_file := (fun s -> Session.file ~error:false s)
Journal.get_session_file :=
(fun s ->
let f = Session.file ~error:false s in
Format.asprintf "%a" Datatype.Filepath.pretty f)
module Config = module Config =
Make_specific_dir Make_specific_dir
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment