Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Don't use sed in coq2html binary #72

Open
wants to merge 1 commit into
base: mca2html
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions common.ml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,37 @@ let shell cmd =
prerr_endline ("Common.shell Error: " ^ cmd);
exit status
end

let wrap_result f x =
try Ok (f x) with
| exn -> Error exn

let unwrap_result = function
| Ok x -> x
| Error exn -> raise exn

let file_using_r filename f =
let read_ch = open_in filename in
let result = wrap_result f read_ch in
close_in read_ch;
unwrap_result result

let file_using_w filename f =
let write_ch = open_out filename in
let result = wrap_result f write_ch in
close_out write_ch;
unwrap_result result

let read_lines filename =
file_using_r filename begin fun read_ch ->
let rec iter store =
try iter (input_line read_ch :: store) with
| End_of_file -> List.rev store
in
iter []
end

let write_lines filename lines =
file_using_w filename begin fun out_ch ->
List.iter (Printf.fprintf out_ch "%s\n") lines
end
4 changes: 4 additions & 0 deletions common.mli
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
val shell : string -> unit


val read_lines : string -> string list
val write_lines : string -> string list -> unit
12 changes: 7 additions & 5 deletions generate_index.ml
Original file line number Diff line number Diff line change
Expand Up @@ -228,11 +228,13 @@ let overwrite_dot_file_with_url xref_table dot_file = (* dirty *)
!%{|"%s" [URL="%s"]|} name url
in
let links = String.concat "; " (List.map node_with_node all_hb_defs) in
let tmp = dot_file ^ ".sed" in
let cmd = !%{|sed '2i %s' %s > %s|} links dot_file tmp in
Common.shell cmd;
Common.shell (!%"mv %s %s" tmp dot_file)

let lines = Common.read_lines dot_file in
let lines = match lines with (* insert links to second line *)
| line1 :: rest -> line1 :: links :: rest
| [] ->
failwith ("empty lines: " ^ dot_file)
in
Common.write_lines dot_file lines

let generate_hierarchy_graph title xref_table output_dir dot_file =
overwrite_dot_file_with_url xref_table dot_file;
Expand Down
Loading