Skip to content

Commit f1435ab

Browse files
committed
Adjust translation on MinGW+Cygwin to change length, not position - also add output_byte
1 parent bbdd058 commit f1435ab

File tree

1 file changed

+43
-45
lines changed

1 file changed

+43
-45
lines changed

src/io/stm_tests.ml

Lines changed: 43 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -127,61 +127,59 @@ struct
127127
Open { position; length; buffered = b; binary_mode }
128128
(* output on open Out_channel *)
129129
| Output_char c, Open { position; length; buffered; binary_mode } ->
130-
let len = (* Windows text mode maps '\n' to "\r\n" *)
131-
if (Sys.win32 || Sys.cygwin) && not binary_mode && c = '\n' then 2L else 1L in
132-
Open { position = Int64.add position len;
133-
length = Int64.add length len;
134-
buffered;
135-
binary_mode; }
136-
| Output_byte _, Open { position; length; buffered; binary_mode } ->
137-
Open { position = Int64.succ position;
138-
length = Int64.succ length;
139-
buffered;
140-
binary_mode; }
141-
| Output_string str, Open { position; length; buffered; binary_mode } ->
142-
let len = (* Windows text mode maps '\n' to "\r\n" *)
143-
if (Sys.win32 || Sys.cygwin) && not binary_mode
144-
then Int64.of_int (String.length str + count_nls str)
145-
else Int64.of_int (String.length str) in
146-
Open { position = Int64.add position len;
147-
length = Int64.add length len;
148-
buffered;
149-
binary_mode; }
150-
| Output_bytes b, Open { position; length; buffered; binary_mode } ->
151-
let len = (* Windows text mode maps '\n' to "\r\n" *)
152-
if (Sys.win32 || Sys.cygwin) && not binary_mode
153-
then Int64.of_int (Bytes.length b + count_nls (String.of_bytes b))
154-
else Int64.of_int (Bytes.length b) in
155-
Open { position = Int64.add position len;
156-
length = Int64.add length len;
157-
buffered;
158-
binary_mode; }
130+
let position = Int64.succ position in
131+
let length = (* Windows text mode maps '\n' to "\r\n" *)
132+
Int64.add length
133+
(if (Sys.win32 || Sys.cygwin) && not binary_mode && c = '\n' then 2L else 1L) in
134+
Open { position; length; buffered; binary_mode; }
135+
| Output_byte i, Open { position; length; buffered; binary_mode } ->
136+
let position = Int64.succ position in
137+
let length = (* Windows text mode maps '\n' to "\r\n" *)
138+
Int64.add length
139+
(if (Sys.win32 || Sys.cygwin) && not binary_mode && (i mod 256 = 10) then 2L else 1L) in
140+
Open { position; length; buffered; binary_mode; }
141+
| Output_string arg, Open { position; length; buffered; binary_mode } ->
142+
let arg_len = String.length arg in
143+
let position = Int64.add position (Int64.of_int arg_len) in
144+
let length = (* Windows text mode maps '\n' to "\r\n" *)
145+
Int64.add length
146+
(if (Sys.win32 || Sys.cygwin) && not binary_mode
147+
then Int64.of_int (arg_len + count_nls arg)
148+
else Int64.of_int arg_len) in
149+
Open { position; length; buffered; binary_mode; }
150+
| Output_bytes arg, Open { position; length; buffered; binary_mode } ->
151+
let arg_len = Bytes.length arg in
152+
let position = Int64.add position (Int64.of_int arg_len) in
153+
let length = (* Windows text mode maps '\n' to "\r\n" *)
154+
Int64.add length
155+
(if (Sys.win32 || Sys.cygwin) && not binary_mode
156+
then Int64.of_int (arg_len + count_nls (String.of_bytes arg))
157+
else Int64.of_int arg_len) in
158+
Open { position; length; buffered; binary_mode; }
159159
| Output (b,p,l), Open { position; length; buffered; binary_mode } ->
160160
let bytes_len = Bytes.length b in
161161
if p < 0 || p >= bytes_len || l < 0 || p+l > bytes_len
162162
then s
163163
else
164-
let len = (* Windows text mode maps '\n' to "\r\n" *)
165-
if (Sys.win32 || Sys.cygwin) && not binary_mode
166-
then Int64.of_int (l + count_nls String.(sub (of_bytes b) p l))
167-
else Int64.of_int l in
168-
Open { position = Int64.add position len;
169-
length = Int64.add length len;
170-
buffered;
171-
binary_mode; }
164+
let position = Int64.add position (Int64.of_int l) in
165+
let length = (* Windows text mode maps '\n' to "\r\n" *)
166+
Int64.add length
167+
(if (Sys.win32 || Sys.cygwin) && not binary_mode
168+
then Int64.of_int (l + count_nls String.(sub (of_bytes b) p l))
169+
else Int64.of_int l) in
170+
Open { position; length; buffered; binary_mode; }
172171
| Output_substring (str,p,l), Open { position; length; buffered; binary_mode } ->
173172
let str_len = String.length str in
174173
if p < 0 || p >= str_len || l < 0 || p+l > str_len
175174
then s
176175
else
177-
let len = (* Windows text mode maps '\n' to "\r\n" *)
178-
if (Sys.win32 || Sys.cygwin) && not binary_mode
179-
then Int64.of_int (l + count_nls (String.sub str p l))
180-
else Int64.of_int l in
181-
Open { position = Int64.add position len;
182-
length = Int64.add length len;
183-
buffered;
184-
binary_mode; }
176+
let position = Int64.add position (Int64.of_int l) in
177+
let length = (* Windows text mode maps '\n' to "\r\n" *)
178+
Int64.add length
179+
(if (Sys.win32 || Sys.cygwin) && not binary_mode
180+
then Int64.of_int (l + count_nls String.(sub str p l))
181+
else Int64.of_int l) in
182+
Open { position; length; buffered; binary_mode; }
185183

186184
let init_sut () =
187185
let path = Filename.temp_file "lin-dsl-" "" in

0 commit comments

Comments
 (0)