1616 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
1717 *)
1818
19+ let open_in_text = open_in
20+
21+ let open_out_text = open_out
22+
23+ module Deprecated : sig
24+ val open_in : string -> in_channel [@@ deprecated "use open_int_text/open_int_bin" ]
25+
26+ val open_out : string -> out_channel [@@ deprecated "use open_out_text/open_out_bin" ]
27+ end = struct
28+ let open_in = open_in
29+
30+ let open_out = open_out
31+ end
32+
1933module Poly = struct
2034 external ( < ) : 'a -> 'a -> bool = " %lessthan"
2135
@@ -1234,6 +1248,8 @@ module Fun = struct
12341248end
12351249
12361250module In_channel = struct
1251+ let stdlib_input_line = input_line
1252+
12371253 (* Read up to [len] bytes into [buf], starting at [ofs]. Return total bytes
12381254 read. *)
12391255 let read_upto ic buf ofs len =
@@ -1327,6 +1343,8 @@ module In_channel = struct
13271343 | exception End_of_file -> acc
13281344 in
13291345 List. rev (aux [] )
1346+
1347+ let input_line_exn = stdlib_input_line
13301348end
13311349[@@ if ocaml_version < (4 , 14 , 0 )]
13321350
@@ -1341,9 +1359,50 @@ module In_channel = struct
13411359 | line -> line :: input_lines ic
13421360 | exception End_of_file -> []
13431361 [@@ if ocaml_version < (5 , 1 , 0 )]
1362+
1363+ let input_line_exn = stdlib_input_line
13441364end
13451365[@@ if ocaml_version > = (4 , 14 , 0 )]
13461366
1367+ let split_lines s =
1368+ if String. equal s " "
1369+ then []
1370+ else
1371+ let sep = '\n' in
1372+ let r = ref [] in
1373+ let j = ref (String. length s) in
1374+ (* ignore trailing new line *)
1375+ if Char. equal (String. unsafe_get s (! j - 1 )) sep then decr j;
1376+ for i = ! j - 1 downto 0 do
1377+ if Char. equal (String. unsafe_get s i) sep
1378+ then (
1379+ r := String. sub s ~pos: (i + 1 ) ~len: (! j - i - 1 ) :: ! r;
1380+ j := i)
1381+ done ;
1382+ String. sub s ~pos: 0 ~len: ! j :: ! r
1383+
1384+ let input_lines_read_once ic len = really_input_string ic len |> split_lines
1385+
1386+ let file_lines_bin fname =
1387+ (* If possible, read the entire file and split it in lines.
1388+ This is faster than reading it line by line.
1389+ Otherwise, we fall back to a line-by-line read. *)
1390+ let ic = open_in_bin fname in
1391+ let len = in_channel_length ic in
1392+ let x =
1393+ if len < Sys. max_string_length
1394+ then input_lines_read_once ic len
1395+ else In_channel. input_lines ic
1396+ in
1397+ close_in ic;
1398+ x
1399+
1400+ let file_lines_text file =
1401+ let ic = open_in_text file in
1402+ let c = In_channel. input_lines ic in
1403+ close_in ic;
1404+ c
1405+
13471406let generated_name = function
13481407 | "param" | "match" | "switcher" -> true
13491408 | s -> String. is_prefix ~prefix: " cst_" s
0 commit comments