Codebase list ocaml-stdio / upstream/0.14.0+git20220215.1.f006beb
Import upstream version 0.14.0+git20220215.1.f006beb Debian Janitor 1 year, 11 months ago
12 changed file(s) with 86 addition(s) and 96 deletion(s). Raw diff Collapse all Expand all
00 The MIT License
11
2 Copyright (c) 2016--2020 Jane Street Group, LLC <opensource@janestreet.com>
2 Copyright (c) 2016--2022 Jane Street Group, LLC <opensource@janestreet.com>
33
44 Permission is hereby granted, free of charge, to any person obtaining a copy
55 of this software and associated documentation files (the "Software"), to deal
0 # Standard IO Library for OCaml
1
2 Stdio provides input/output functions for OCaml. It re-exports the
3 buffered channels of the stdlib distributed with OCaml but with some
4 improvements.
5
6 API documentation for the latest release can be found
7 [here][https://ocaml.janestreet.com/ocaml-core/latest/doc/stdio/index.html].
+0
-6
README.org less more
0
1 * Standard IO Library for OCaml
2
3 Stdio provides input/output functions for OCaml. It re-exports the
4 buffered channels of the stdlib distributed with OCaml but with some
5 improvements.
11 (preprocess no_preprocessing)
22 (lint
33 (pps ppx_base -check-doc-comments -type-conv-keep-w32=impl
4 -apply=js_style,type_conv)))
4 -apply=js_style,type_conv)))
5
6 (documentation)
+0
-4
src/import.ml less more
0 open! Base
1
2 module Sexplib = Base.Exported_for_specific_uses.Sexplib
3 module Ppx_sexp_conv_lib = Base.Exported_for_specific_uses.Ppx_sexp_conv_lib
00 open! Base
1 open! Import
21
32 type t = Caml.in_channel
43
54 let equal (t1 : t) t2 = phys_equal t1 t2
6
7 let seek = Caml.LargeFile.seek_in
8 let pos = Caml.LargeFile.pos_in
5 let seek = Caml.LargeFile.seek_in
6 let pos = Caml.LargeFile.pos_in
97 let length = Caml.LargeFile.in_channel_length
10
118 let stdin = Caml.stdin
129
1310 let create ?(binary = true) file =
14 let flags = [Open_rdonly] in
11 let flags = [ Open_rdonly ] in
1512 let flags = if binary then Open_binary :: flags else flags in
1613 Caml.open_in_gen flags 0o000 file
1714 ;;
1815
1916 let close = Caml.close_in
20
2117 let with_file ?binary file ~f = Exn.protectx (create ?binary file) ~f ~finally:close
2218
23 let may_eof f = try Some (f ()) with End_of_file -> None
19 let may_eof f =
20 try Some (f ()) with
21 | End_of_file -> None
22 ;;
2423
2524 let input t ~buf ~pos ~len = Caml.input t buf pos len
26 let really_input t ~buf ~pos ~len =
27 may_eof (fun () -> Caml.really_input t buf pos len)
28 let really_input_exn t ~buf ~pos ~len =
29 Caml.really_input t buf pos len
25 let really_input t ~buf ~pos ~len = may_eof (fun () -> Caml.really_input t buf pos len)
26 let really_input_exn t ~buf ~pos ~len = Caml.really_input t buf pos len
3027 let input_byte t = may_eof (fun () -> Caml.input_byte t)
3128 let input_char t = may_eof (fun () -> Caml.input_char t)
3229 let input_binary_int t = may_eof (fun () -> Caml.input_binary_int t)
3330 let unsafe_input_value t = may_eof (fun () -> Caml.input_value t)
3431 let input_buffer t buf ~len = may_eof (fun () -> Caml.Buffer.add_channel buf t len)
35
3632 let set_binary_mode = Caml.set_binary_mode_in
3733
3834 let input_all t =
4844 ;;
4945
5046 let trim ~fix_win_eol line =
51 if fix_win_eol then begin
47 if fix_win_eol
48 then (
5249 let len = String.length line in
53 if len > 0
54 && Char.equal (String.get line (len - 1)) '\r'
50 if len > 0 && Char.equal (String.get line (len - 1)) '\r'
5551 then String.sub line ~pos:0 ~len:(len - 1)
56 else line
57 end
52 else line)
5853 else line
54 ;;
5955
6056 let input_line ?(fix_win_eol = true) t =
6157 match may_eof (fun () -> Caml.input_line t) with
6662 let input_line_exn ?(fix_win_eol = true) t =
6763 let line = Caml.input_line t in
6864 trim ~fix_win_eol line
65 ;;
6966
7067 let fold_lines ?fix_win_eol t ~init ~f =
7168 let rec loop ac =
7774 ;;
7875
7976 let input_lines ?fix_win_eol t =
80 List.rev
81 (fold_lines ?fix_win_eol t ~init:[] ~f:(fun lines line -> line :: lines))
77 List.rev (fold_lines ?fix_win_eol t ~init:[] ~f:(fun lines line -> line :: lines))
8278 ;;
8379
8480 let iter_lines ?fix_win_eol t ~f =
8682 ;;
8783
8884 let read_lines ?fix_win_eol fname = with_file fname ~f:(input_lines ?fix_win_eol)
89
9085 let read_all fname = with_file fname ~f:input_all
88 *)
99
1010 open! Base
11 open! Import
1211
1312 type t = Caml.in_channel
1413
2625 [fname], and closes it afterwards. *)
2726 val with_file : ?binary:bool (** defaults to [true] *) -> string -> f:(t -> 'a) -> 'a
2827
28
2929 (** [close t] closes [t], or does nothing if [t] is already closed, and may raise an
3030 exception. *)
3131 val close : t -> unit
3232
3333 val input : t -> buf:bytes -> pos:int -> len:int -> int
34 val really_input : t -> buf:bytes -> pos:int -> len:int -> unit option
34
35 val really_input : t -> buf:bytes -> pos:int -> len:int -> unit option
3536
3637 (** Same as [Pervasives.really_input], for backwards compatibility *)
3738 val really_input_exn : t -> buf:bytes -> pos:int -> len:int -> unit
39
3840
3941 (** Read one character from the given input channel. Return [None] if there are no more
4042 characters to read. *)
5254 (** Ocaml's built-in marshal format *)
5355 val unsafe_input_value : t -> _ option
5456
57
5558 (** [input_buffer t buf ~len] reads at most [len] characters from the input channel [t]
5659 and stores them at the end of buffer [buf]. Return [None] if the channel contains
5760 fewer than [len] characters. In this case, the characters are still added to the
6467 the newline ("\n") character at the end, and, if [fix_win_eol] the trailing
6568 "\r\n" is dropped.
6669 *)
67 val input_line : ?fix_win_eol:bool (** defaults to [true] *) -> t -> string option
70 val input_line : ?fix_win_eol:bool (** defaults to [true] *) -> t -> string option
71
6872 val input_line_exn : ?fix_win_eol:bool (** defaults to [true] *) -> t -> string
6973
7074 (** [fold_lines ?fix_win_eol t ~init ~f] folds over the lines read from [t]
00 open! Base
1 open! Import
21
32 type t = Caml.out_channel
43
54 let equal (t1 : t) t2 = phys_equal t1 t2
6
7 let seek = Caml.LargeFile.seek_out
8 let pos = Caml.LargeFile.pos_out
5 let seek = Caml.LargeFile.seek_out
6 let pos = Caml.LargeFile.pos_out
97 let length = Caml.LargeFile.out_channel_length
10
118 let stdout = Caml.stdout
129 let stderr = Caml.stderr
1310
2017 ;;
2118
2219 type 'a with_create_args =
23 ?binary:bool
24 -> ?append:bool
25 -> ?fail_if_exists:bool
26 -> ?perm:int
27 -> 'a
20 ?binary:bool -> ?append:bool -> ?fail_if_exists:bool -> ?perm:int -> 'a
2821
29 let create ?(binary = true) ?(append = false) ?(fail_if_exists = false) ?(perm = 0o666) file =
30 let flags = [Open_wronly; Open_creat] in
22 let create
23 ?(binary = true)
24 ?(append = false)
25 ?(fail_if_exists = false)
26 ?(perm = 0o666)
27 file
28 =
29 let flags = [ Open_wronly; Open_creat ] in
3130 let flags = (if binary then Open_binary else Open_text) :: flags in
3231 let flags = (if append then Open_append else Open_trunc) :: flags in
33 let flags = (if fail_if_exists then Open_excl :: flags else flags) in
32 let flags = if fail_if_exists then Open_excl :: flags else flags in
3433 Caml.open_out_gen flags perm file
3534 ;;
3635
3736 let set_binary_mode = Caml.set_binary_mode_out
38
3937 let flush = Caml.flush
40
4138 let close = Caml.close_out
4239 let close_no_err = Caml.close_out_noerr
43
4440 let output t ~buf ~pos ~len = Caml.output t buf pos len
4541 let output_substring t ~buf ~pos ~len = Caml.output_substring t buf pos len
4642 let output_string = Caml.output_string
5046 let output_binary_int = Caml.output_binary_int
5147 let output_buffer = Caml.Buffer.output_buffer
5248 let output_value = Caml.output_value
53
5449 let newline t = output_string t "\n"
5550
5651 let output_lines t lines =
57 List.iter lines ~f:(fun line -> output_string t line; newline t)
52 List.iter lines ~f:(fun line ->
53 output_string t line;
54 newline t)
5855 ;;
5956
60 let printf = Caml.Printf.printf
61 let eprintf = Caml.Printf.eprintf
62 let fprintf = Caml.Printf.fprintf
57 let printf = Caml.Printf.printf
58 let eprintf = Caml.Printf.eprintf
59 let fprintf = Caml.Printf.fprintf
6360 let kfprintf = Caml.Printf.kfprintf
64
6561 let print_string = Caml.print_string
6662 let print_endline = Caml.print_endline
6763 let prerr_endline = Caml.prerr_endline
7066 print_endline
7167 (match mach with
7268 | Some () -> Sexp.to_string_mach sexp
73 | None -> Sexp.to_string_hum sexp)
69 | None -> Sexp.to_string_hum sexp)
7470 ;;
7571
7672 let eprint_s ?mach sexp =
7773 prerr_endline
7874 (match mach with
7975 | Some () -> Sexp.to_string_mach sexp
80 | None -> Sexp.to_string_hum sexp)
76 | None -> Sexp.to_string_hum sexp)
8177 ;;
82
8378
8479 let with_file ?binary ?append ?fail_if_exists ?perm file ~f =
8580 Exn.protectx (create ?binary ?append ?fail_if_exists ?perm file) ~f ~finally:close
8681 ;;
8782
8883 let write_lines file lines = with_file file ~f:(fun t -> output_lines t lines)
89
9084 let write_all file ~data = with_file file ~f:(fun t -> output_string t data)
1212 *)
1313
1414 open! Base
15 open! Import
1615
1716 type t = Caml.out_channel [@@deriving_inline sexp_of]
18 include
19 sig [@@@ocaml.warning "-32"] val sexp_of_t : t -> Ppx_sexp_conv_lib.Sexp.t
20 end[@@ocaml.doc "@inline"]
17
18 include sig
19 [@@@ocaml.warning "-32"]
20
21 val sexp_of_t : t -> Sexplib0.Sexp.t
22 end
23 [@@ocaml.doc "@inline"]
24
2125 [@@@end]
2226
2327 include Equal.S with type t := t
2630 val stderr : t
2731
2832 type 'a with_create_args =
29 ?binary:bool (** defaults to [true] *)
30 -> ?append:bool (** defaults to [false] *)
33 ?binary:bool (** defaults to [true] *)
34 -> ?append:bool (** defaults to [false] *)
3135 -> ?fail_if_exists:bool (** defaults to [false] *)
3236 -> ?perm:int
3337 -> 'a
34
3538
3639 val create : (string -> t) with_create_args
3740 val with_file : (string -> f:(t -> 'a) -> 'a) with_create_args
6366 val close_no_err : t -> unit
6467
6568 val set_binary_mode : t -> bool -> unit
66
6769 val flush : t -> unit
68
6970 val output : t -> buf:bytes -> pos:int -> len:int -> unit
7071 val output_string : t -> string -> unit
7172 val output_substring : t -> buf:string -> pos:int -> len:int -> unit
7475 val output_byte : t -> int -> unit
7576 val output_binary_int : t -> int -> unit
7677 val output_buffer : t -> Buffer.t -> unit
77 val output_value : t -> _ -> unit (** OCaml's internal Marshal format *)
78
79 (** OCaml's internal Marshal format *)
80 val output_value : t -> _ -> unit
7881
7982 val newline : t -> unit
8083
9295
9396 (** [print_s sexp] outputs [sexp] on [stdout], by default using [Sexp.to_string_hum],
9497 or, with [~mach:()], [Sexp.to_string_mach]. *)
95 val print_s : ?mach : unit -> Sexp.t -> unit
98 val print_s : ?mach:unit -> Sexp.t -> unit
9699
97100 (** [eprint_s sexp] outputs [sexp] on [stderr], by default using [Sexp.to_string_hum],
98101 or, with [~mach:()], [Sexp.to_string_mach]. *)
99 val eprint_s : ?mach : unit -> Sexp.t -> unit
102 val eprint_s : ?mach:unit -> Sexp.t -> unit
100103
101104 (** [eprintf fmt] is the same as [fprintf stderr fmt] *)
102105 val eprintf : ('a, t, unit) format -> 'a
122125
123126 (** The first argument of these is the file name to write to. *)
124127 val write_lines : string -> string list -> unit
128
125129 val write_all : string -> data:string -> unit
126130
127131
128
00 open! Base
1 open! Import
2
3 module In_channel = In_channel
1 module In_channel = In_channel
42 module Out_channel = Out_channel
53
6 let stdin = In_channel.stdin
4 let stdin = In_channel.stdin
75 let stdout = Out_channel.stdout
86 let stderr = Out_channel.stderr
9
10 let eprintf = Out_channel.eprintf
11 let printf = Out_channel.printf
12 let print_s = Out_channel.print_s
13 let eprint_s = Out_channel.eprint_s
14 let print_string = Out_channel.print_string
7 let eprintf = Out_channel.eprintf
8 let printf = Out_channel.printf
9 let print_s = Out_channel.print_s
10 let eprint_s = Out_channel.eprint_s
11 let print_string = Out_channel.print_string
1512 let print_endline = Out_channel.print_endline
1613 let prerr_endline = Out_channel.prerr_endline
00 open! Base
1 open! Import
2
3 module In_channel = In_channel
1 module In_channel = In_channel
42 module Out_channel = Out_channel
53
64 (** Same as {!In_channel.stdin} *)
1614 val printf : ('a, Out_channel.t, unit) format -> 'a
1715
1816 (** Same as {!Out_channel.print_s} *)
19 val print_s : ?mach : unit -> Sexp.t -> unit
17 val print_s : ?mach:unit -> Sexp.t -> unit
2018
2119 (** Same as {!Out_channel.eprint_s} *)
22 val eprint_s : ?mach : unit -> Sexp.t -> unit
20 val eprint_s : ?mach:unit -> Sexp.t -> unit
2321
2422 (** Same as {!Out_channel.eprintf} *)
2523 val eprintf : ('a, Out_channel.t, unit) format -> 'a
00 opam-version: "2.0"
1 version: "v0.14.0"
2 maintainer: "opensource@janestreet.com"
3 authors: ["Jane Street Group, LLC <opensource@janestreet.com>"]
1 maintainer: "Jane Street developers"
2 authors: ["Jane Street Group, LLC"]
43 homepage: "https://github.com/janestreet/stdio"
54 bug-reports: "https://github.com/janestreet/stdio/issues"
65 dev-repo: "git+https://github.com/janestreet/stdio.git"
109 ["dune" "build" "-p" name "-j" jobs]
1110 ]
1211 depends: [
13 "ocaml" {>= "4.04.2"}
14 "base" {>= "v0.14" & < "v0.15"}
15 "dune" {>= "2.0.0"}
12 "ocaml" {>= "4.08.0"}
13 "base"
14 "dune" {>= "2.0.0"}
1615 ]
1716 synopsis: "Standard IO library for OCaml"
1817 description: "