16
16
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17
17
*)
18
18
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
+
19
33
module Poly = struct
20
34
external ( < ) : 'a -> 'a -> bool = " %lessthan"
21
35
@@ -1234,6 +1248,8 @@ module Fun = struct
1234
1248
end
1235
1249
1236
1250
module In_channel = struct
1251
+ let stdlib_input_line = input_line
1252
+
1237
1253
(* Read up to [len] bytes into [buf], starting at [ofs]. Return total bytes
1238
1254
read. *)
1239
1255
let read_upto ic buf ofs len =
@@ -1327,6 +1343,8 @@ module In_channel = struct
1327
1343
| exception End_of_file -> acc
1328
1344
in
1329
1345
List. rev (aux [] )
1346
+
1347
+ let input_line_exn = stdlib_input_line
1330
1348
end
1331
1349
[@@ if ocaml_version < (4 , 14 , 0 )]
1332
1350
@@ -1341,9 +1359,50 @@ module In_channel = struct
1341
1359
| line -> line :: input_lines ic
1342
1360
| exception End_of_file -> []
1343
1361
[@@ if ocaml_version < (5 , 1 , 0 )]
1362
+
1363
+ let input_line_exn = stdlib_input_line
1344
1364
end
1345
1365
[@@ if ocaml_version > = (4 , 14 , 0 )]
1346
1366
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
+
1347
1406
let generated_name = function
1348
1407
| "param" | "match" | "switcher" -> true
1349
1408
| s -> String. is_prefix ~prefix: " cst_" s
0 commit comments