Skip to content
Snippets Groups Projects
Commit af85d405 authored by Andre Maroneze's avatar Andre Maroneze
Browse files

[Kernel] use Filepath for option -ocode

parent 8ca1cf3c
No related branches found
No related tags found
No related merge requests found
...@@ -719,10 +719,12 @@ module PrintReturn = ...@@ -719,10 +719,12 @@ module PrintReturn =
module CodeOutput = struct module CodeOutput = struct
let () = Parameter_customize.set_group inout_source let () = Parameter_customize.set_group inout_source
include P.Empty_string include P.Filepath
(struct (struct
let option_name = "-ocode" let option_name = "-ocode"
let arg_name = "filename" let arg_name = "filename"
let existence = Filepath.Indifferent
let file_kind = "source"
let help = let help =
"when printing code, redirects the output to file <filename>" "when printing code, redirects the output to file <filename>"
end) end)
...@@ -731,22 +733,23 @@ module CodeOutput = struct ...@@ -731,22 +733,23 @@ module CodeOutput = struct
let output job = let output job =
let file = get () in let file = get () in
if file = "" if Filepath.Normalized.(is_special_stdout file || is_empty file)
then Log.print_delayed job then Log.print_delayed job
else else
try try
let fmt = let fmt =
try fst (Hashtbl.find streams file) try fst (Hashtbl.find streams file)
with Not_found -> with Not_found ->
let out = open_out file in let out = open_out (file:>string) in
let fmt = Format.formatter_of_out_channel out in let fmt = Format.formatter_of_out_channel out in
Hashtbl.add streams file (fmt,out) ; fmt Hashtbl.add streams file (fmt,out) ; fmt
in in
job fmt job fmt
with Sys_error s -> with Sys_error s ->
warning warning
"Fail to open file \"%s\" for code output@\nSystem error: %s.@\n\ "Fail to open file \"%a\" for code output@\nSystem error: %s.@\n\
Code is output on stdout instead." file s ; Code is output on stdout instead."
Filepath.Normalized.pretty file s ;
Log.print_delayed job Log.print_delayed job
let close_all () = let close_all () =
...@@ -757,8 +760,8 @@ module CodeOutput = struct ...@@ -757,8 +760,8 @@ module CodeOutput = struct
close_out cout ; close_out cout ;
with Sys_error s -> with Sys_error s ->
failure failure
"Fail to close output file \"%s\"@\nSystem error: %s." "Fail to close output file \"%a\"@\nSystem error: %s."
file s) Filepath.Normalized.pretty file s)
streams streams
let () = Extlib.safe_at_exit close_all let () = Extlib.safe_at_exit close_all
......
...@@ -328,7 +328,7 @@ module PrintReturn : Parameter_sig.Bool ...@@ -328,7 +328,7 @@ module PrintReturn : Parameter_sig.Bool
(** Behavior of option "-ocode". (** Behavior of option "-ocode".
@plugin development guide *) @plugin development guide *)
module CodeOutput : sig module CodeOutput : sig
include Parameter_sig.String include Parameter_sig.Filepath
val output: (Format.formatter -> unit) -> unit val output: (Format.formatter -> unit) -> unit
end end
......
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