Import upstream version 0.14.0+git20220215.1.f006beb
Debian Janitor
1 year, 11 months ago
0 | 0 | The MIT License |
1 | 1 | |
2 | Copyright (c) 2016--2020 Jane Street Group, LLC <opensource@janestreet.com> | |
2 | Copyright (c) 2016--2022 Jane Street Group, LLC <opensource@janestreet.com> | |
3 | 3 | |
4 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy |
5 | 5 | 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 | ||
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. |
1 | 1 | (preprocess no_preprocessing) |
2 | 2 | (lint |
3 | 3 | (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 | 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 |
0 | 0 | open! Base |
1 | open! Import | |
2 | 1 | |
3 | 2 | type t = Caml.in_channel |
4 | 3 | |
5 | 4 | 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 | |
9 | 7 | let length = Caml.LargeFile.in_channel_length |
10 | ||
11 | 8 | let stdin = Caml.stdin |
12 | 9 | |
13 | 10 | let create ?(binary = true) file = |
14 | let flags = [Open_rdonly] in | |
11 | let flags = [ Open_rdonly ] in | |
15 | 12 | let flags = if binary then Open_binary :: flags else flags in |
16 | 13 | Caml.open_in_gen flags 0o000 file |
17 | 14 | ;; |
18 | 15 | |
19 | 16 | let close = Caml.close_in |
20 | ||
21 | 17 | let with_file ?binary file ~f = Exn.protectx (create ?binary file) ~f ~finally:close |
22 | 18 | |
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 | ;; | |
24 | 23 | |
25 | 24 | 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 | |
30 | 27 | let input_byte t = may_eof (fun () -> Caml.input_byte t) |
31 | 28 | let input_char t = may_eof (fun () -> Caml.input_char t) |
32 | 29 | let input_binary_int t = may_eof (fun () -> Caml.input_binary_int t) |
33 | 30 | let unsafe_input_value t = may_eof (fun () -> Caml.input_value t) |
34 | 31 | let input_buffer t buf ~len = may_eof (fun () -> Caml.Buffer.add_channel buf t len) |
35 | ||
36 | 32 | let set_binary_mode = Caml.set_binary_mode_in |
37 | 33 | |
38 | 34 | let input_all t = |
48 | 44 | ;; |
49 | 45 | |
50 | 46 | let trim ~fix_win_eol line = |
51 | if fix_win_eol then begin | |
47 | if fix_win_eol | |
48 | then ( | |
52 | 49 | 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' | |
55 | 51 | then String.sub line ~pos:0 ~len:(len - 1) |
56 | else line | |
57 | end | |
52 | else line) | |
58 | 53 | else line |
54 | ;; | |
59 | 55 | |
60 | 56 | let input_line ?(fix_win_eol = true) t = |
61 | 57 | match may_eof (fun () -> Caml.input_line t) with |
66 | 62 | let input_line_exn ?(fix_win_eol = true) t = |
67 | 63 | let line = Caml.input_line t in |
68 | 64 | trim ~fix_win_eol line |
65 | ;; | |
69 | 66 | |
70 | 67 | let fold_lines ?fix_win_eol t ~init ~f = |
71 | 68 | let rec loop ac = |
77 | 74 | ;; |
78 | 75 | |
79 | 76 | 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)) | |
82 | 78 | ;; |
83 | 79 | |
84 | 80 | let iter_lines ?fix_win_eol t ~f = |
86 | 82 | ;; |
87 | 83 | |
88 | 84 | let read_lines ?fix_win_eol fname = with_file fname ~f:(input_lines ?fix_win_eol) |
89 | ||
90 | 85 | let read_all fname = with_file fname ~f:input_all |
8 | 8 | *) |
9 | 9 | |
10 | 10 | open! Base |
11 | open! Import | |
12 | 11 | |
13 | 12 | type t = Caml.in_channel |
14 | 13 | |
26 | 25 | [fname], and closes it afterwards. *) |
27 | 26 | val with_file : ?binary:bool (** defaults to [true] *) -> string -> f:(t -> 'a) -> 'a |
28 | 27 | |
28 | ||
29 | 29 | (** [close t] closes [t], or does nothing if [t] is already closed, and may raise an |
30 | 30 | exception. *) |
31 | 31 | val close : t -> unit |
32 | 32 | |
33 | 33 | 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 | |
35 | 36 | |
36 | 37 | (** Same as [Pervasives.really_input], for backwards compatibility *) |
37 | 38 | val really_input_exn : t -> buf:bytes -> pos:int -> len:int -> unit |
39 | ||
38 | 40 | |
39 | 41 | (** Read one character from the given input channel. Return [None] if there are no more |
40 | 42 | characters to read. *) |
52 | 54 | (** Ocaml's built-in marshal format *) |
53 | 55 | val unsafe_input_value : t -> _ option |
54 | 56 | |
57 | ||
55 | 58 | (** [input_buffer t buf ~len] reads at most [len] characters from the input channel [t] |
56 | 59 | and stores them at the end of buffer [buf]. Return [None] if the channel contains |
57 | 60 | fewer than [len] characters. In this case, the characters are still added to the |
64 | 67 | the newline ("\n") character at the end, and, if [fix_win_eol] the trailing |
65 | 68 | "\r\n" is dropped. |
66 | 69 | *) |
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 | ||
68 | 72 | val input_line_exn : ?fix_win_eol:bool (** defaults to [true] *) -> t -> string |
69 | 73 | |
70 | 74 | (** [fold_lines ?fix_win_eol t ~init ~f] folds over the lines read from [t] |
0 | 0 | open! Base |
1 | open! Import | |
2 | 1 | |
3 | 2 | type t = Caml.out_channel |
4 | 3 | |
5 | 4 | 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 | |
9 | 7 | let length = Caml.LargeFile.out_channel_length |
10 | ||
11 | 8 | let stdout = Caml.stdout |
12 | 9 | let stderr = Caml.stderr |
13 | 10 | |
20 | 17 | ;; |
21 | 18 | |
22 | 19 | 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 | |
28 | 21 | |
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 | |
31 | 30 | let flags = (if binary then Open_binary else Open_text) :: flags in |
32 | 31 | 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 | |
34 | 33 | Caml.open_out_gen flags perm file |
35 | 34 | ;; |
36 | 35 | |
37 | 36 | let set_binary_mode = Caml.set_binary_mode_out |
38 | ||
39 | 37 | let flush = Caml.flush |
40 | ||
41 | 38 | let close = Caml.close_out |
42 | 39 | let close_no_err = Caml.close_out_noerr |
43 | ||
44 | 40 | let output t ~buf ~pos ~len = Caml.output t buf pos len |
45 | 41 | let output_substring t ~buf ~pos ~len = Caml.output_substring t buf pos len |
46 | 42 | let output_string = Caml.output_string |
50 | 46 | let output_binary_int = Caml.output_binary_int |
51 | 47 | let output_buffer = Caml.Buffer.output_buffer |
52 | 48 | let output_value = Caml.output_value |
53 | ||
54 | 49 | let newline t = output_string t "\n" |
55 | 50 | |
56 | 51 | 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) | |
58 | 55 | ;; |
59 | 56 | |
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 | |
63 | 60 | let kfprintf = Caml.Printf.kfprintf |
64 | ||
65 | 61 | let print_string = Caml.print_string |
66 | 62 | let print_endline = Caml.print_endline |
67 | 63 | let prerr_endline = Caml.prerr_endline |
70 | 66 | print_endline |
71 | 67 | (match mach with |
72 | 68 | | Some () -> Sexp.to_string_mach sexp |
73 | | None -> Sexp.to_string_hum sexp) | |
69 | | None -> Sexp.to_string_hum sexp) | |
74 | 70 | ;; |
75 | 71 | |
76 | 72 | let eprint_s ?mach sexp = |
77 | 73 | prerr_endline |
78 | 74 | (match mach with |
79 | 75 | | Some () -> Sexp.to_string_mach sexp |
80 | | None -> Sexp.to_string_hum sexp) | |
76 | | None -> Sexp.to_string_hum sexp) | |
81 | 77 | ;; |
82 | ||
83 | 78 | |
84 | 79 | let with_file ?binary ?append ?fail_if_exists ?perm file ~f = |
85 | 80 | Exn.protectx (create ?binary ?append ?fail_if_exists ?perm file) ~f ~finally:close |
86 | 81 | ;; |
87 | 82 | |
88 | 83 | let write_lines file lines = with_file file ~f:(fun t -> output_lines t lines) |
89 | ||
90 | 84 | let write_all file ~data = with_file file ~f:(fun t -> output_string t data) |
12 | 12 | *) |
13 | 13 | |
14 | 14 | open! Base |
15 | open! Import | |
16 | 15 | |
17 | 16 | 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 | ||
21 | 25 | [@@@end] |
22 | 26 | |
23 | 27 | include Equal.S with type t := t |
26 | 30 | val stderr : t |
27 | 31 | |
28 | 32 | 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] *) | |
31 | 35 | -> ?fail_if_exists:bool (** defaults to [false] *) |
32 | 36 | -> ?perm:int |
33 | 37 | -> 'a |
34 | ||
35 | 38 | |
36 | 39 | val create : (string -> t) with_create_args |
37 | 40 | val with_file : (string -> f:(t -> 'a) -> 'a) with_create_args |
63 | 66 | val close_no_err : t -> unit |
64 | 67 | |
65 | 68 | val set_binary_mode : t -> bool -> unit |
66 | ||
67 | 69 | val flush : t -> unit |
68 | ||
69 | 70 | val output : t -> buf:bytes -> pos:int -> len:int -> unit |
70 | 71 | val output_string : t -> string -> unit |
71 | 72 | val output_substring : t -> buf:string -> pos:int -> len:int -> unit |
74 | 75 | val output_byte : t -> int -> unit |
75 | 76 | val output_binary_int : t -> int -> unit |
76 | 77 | 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 | |
78 | 81 | |
79 | 82 | val newline : t -> unit |
80 | 83 | |
92 | 95 | |
93 | 96 | (** [print_s sexp] outputs [sexp] on [stdout], by default using [Sexp.to_string_hum], |
94 | 97 | 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 | |
96 | 99 | |
97 | 100 | (** [eprint_s sexp] outputs [sexp] on [stderr], by default using [Sexp.to_string_hum], |
98 | 101 | 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 | |
100 | 103 | |
101 | 104 | (** [eprintf fmt] is the same as [fprintf stderr fmt] *) |
102 | 105 | val eprintf : ('a, t, unit) format -> 'a |
122 | 125 | |
123 | 126 | (** The first argument of these is the file name to write to. *) |
124 | 127 | val write_lines : string -> string list -> unit |
128 | ||
125 | 129 | val write_all : string -> data:string -> unit |
126 | 130 | |
127 | 131 | |
128 |
0 | 0 | open! Base |
1 | open! Import | |
2 | ||
3 | module In_channel = In_channel | |
1 | module In_channel = In_channel | |
4 | 2 | module Out_channel = Out_channel |
5 | 3 | |
6 | let stdin = In_channel.stdin | |
4 | let stdin = In_channel.stdin | |
7 | 5 | let stdout = Out_channel.stdout |
8 | 6 | 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 | |
15 | 12 | let print_endline = Out_channel.print_endline |
16 | 13 | let prerr_endline = Out_channel.prerr_endline |
0 | 0 | open! Base |
1 | open! Import | |
2 | ||
3 | module In_channel = In_channel | |
1 | module In_channel = In_channel | |
4 | 2 | module Out_channel = Out_channel |
5 | 3 | |
6 | 4 | (** Same as {!In_channel.stdin} *) |
16 | 14 | val printf : ('a, Out_channel.t, unit) format -> 'a |
17 | 15 | |
18 | 16 | (** Same as {!Out_channel.print_s} *) |
19 | val print_s : ?mach : unit -> Sexp.t -> unit | |
17 | val print_s : ?mach:unit -> Sexp.t -> unit | |
20 | 18 | |
21 | 19 | (** Same as {!Out_channel.eprint_s} *) |
22 | val eprint_s : ?mach : unit -> Sexp.t -> unit | |
20 | val eprint_s : ?mach:unit -> Sexp.t -> unit | |
23 | 21 | |
24 | 22 | (** Same as {!Out_channel.eprintf} *) |
25 | 23 | val eprintf : ('a, Out_channel.t, unit) format -> 'a |
0 | 0 | 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"] | |
4 | 3 | homepage: "https://github.com/janestreet/stdio" |
5 | 4 | bug-reports: "https://github.com/janestreet/stdio/issues" |
6 | 5 | dev-repo: "git+https://github.com/janestreet/stdio.git" |
10 | 9 | ["dune" "build" "-p" name "-j" jobs] |
11 | 10 | ] |
12 | 11 | 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"} | |
16 | 15 | ] |
17 | 16 | synopsis: "Standard IO library for OCaml" |
18 | 17 | description: " |