-
Notifications
You must be signed in to change notification settings - Fork 414
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor IO functions and fix invalid IOs in gen_rules
- Loading branch information
Jeremie Dimino
committed
May 18, 2017
1 parent
9df1bad
commit a3ee810
Showing
22 changed files
with
167 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
open Import | ||
|
||
module P = Pervasives | ||
|
||
let open_in ?(binary=true) fn = | ||
if binary then P.open_in_bin fn else P.open_in fn | ||
|
||
let open_out ?(binary=true) fn = | ||
if binary then P.open_out_bin fn else P.open_out fn | ||
|
||
let close_in = close_in | ||
let close_out = close_out | ||
|
||
let with_file_in ?binary fn ~f = | ||
protectx (open_in ?binary fn) ~finally:close_in ~f | ||
|
||
let with_file_out ?binary fn ~f = | ||
protectx (open_out ?binary fn) ~finally:close_out ~f | ||
|
||
let with_lexbuf_from_file fn ~f = | ||
with_file_in fn ~f:(fun ic -> | ||
let lb = Lexing.from_channel ic in | ||
lb.lex_curr_p <- | ||
{ pos_fname = fn | ||
; pos_lnum = 1 | ||
; pos_bol = 0 | ||
; pos_cnum = 0 | ||
}; | ||
f lb) | ||
|
||
let input_lines = | ||
let rec loop ic acc = | ||
match input_line ic with | ||
| exception End_of_file -> List.rev acc | ||
| line -> | ||
loop ic (line :: acc) | ||
in | ||
fun ic -> loop ic [] | ||
|
||
let read_file fn = | ||
with_file_in fn ~f:(fun ic -> | ||
let len = in_channel_length ic in | ||
really_input_string ic len) | ||
|
||
let lines_of_file fn = with_file_in fn ~f:input_lines ~binary:false | ||
|
||
let write_file fn data = with_file_out fn ~f:(fun oc -> output_string oc data) | ||
|
||
let copy_channels = | ||
let buf_len = 65536 in | ||
let buf = Bytes.create buf_len in | ||
let rec loop ic oc = | ||
match input ic buf 0 buf_len with | ||
| 0 -> () | ||
| n -> output oc buf 0 n; loop ic oc | ||
in | ||
loop | ||
|
||
let copy_file ~src ~dst = | ||
with_file_in src ~f:(fun ic -> | ||
let perm = (Unix.fstat (Unix.descr_of_in_channel ic)).st_perm in | ||
protectx (P.open_out_gen | ||
[Open_wronly; Open_creat; Open_trunc; Open_binary] | ||
perm | ||
dst) | ||
~finally:close_out | ||
~f:(fun oc -> | ||
copy_channels ic oc)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
(** IO operations *) | ||
|
||
val open_in : ?binary:bool (* default true *) -> string -> in_channel | ||
val open_out : ?binary:bool (* default true *) -> string -> out_channel | ||
|
||
val close_in : in_channel -> unit | ||
val close_out : out_channel -> unit | ||
|
||
val with_file_in : ?binary:bool (* default true *) -> string -> f:(in_channel -> 'a) -> 'a | ||
val with_file_out : ?binary:bool (* default true *) -> string -> f:(out_channel -> 'a) -> 'a | ||
|
||
val with_lexbuf_from_file : string -> f:(Lexing.lexbuf -> 'a) -> 'a | ||
|
||
val lines_of_file : string -> string list | ||
|
||
val read_file : string -> string | ||
val write_file : string -> string -> unit | ||
|
||
val copy_channels : in_channel -> out_channel -> unit | ||
|
||
val copy_file : src:string -> dst:string -> unit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
open Import | ||
open! No_io | ||
|
||
module SC = Super_context | ||
|
||
|
Oops, something went wrong.