mirror of
https://github.com/Mercury-Language/mercury.git
synced 2026-05-01 17:24:34 +00:00
Estimated hours taken: 10
library/io.m:
library/io.nu.nl:
Implement io__read_line_as_string/{3,4}.
Also sneaked in here are some trivial whitespace fixes in some
of the pragma c_code which did not comply with our coding
standards (to do with type casting).
samples/cat.m:
samples/sort.m:
Use io__read_line_as_string.
tests/general/Mmakefile:
tests/general/read_line_as_string.exp:
tests/general/read_line_as_string.m:
Test case for io__read_line_as_string.
NEWS:
Mention the above change.
32 lines
669 B
Mathematica
32 lines
669 B
Mathematica
:- module read_line_as_string.
|
|
|
|
:- interface.
|
|
:- import_module io.
|
|
|
|
:- pred main(io__state :: di, io__state :: uo) is det.
|
|
|
|
:- implementation.
|
|
|
|
main -->
|
|
io__open_input("read_line_as_string.exp", Result),
|
|
( { Result = ok(Stream) } ->
|
|
io__set_input_stream(Stream, _),
|
|
io__read_line_as_string(Result2),
|
|
cat(Result2)
|
|
;
|
|
io__write_string("Error opening file!")
|
|
).
|
|
|
|
:- pred cat(io__result(string)::in, io__state::di, io__state::uo) is det.
|
|
|
|
cat(Result) -->
|
|
( { Result = ok(Line) },
|
|
io__write_string(Line),
|
|
io__read_line_as_string(NextResult),
|
|
cat(NextResult)
|
|
; { Result = eof }
|
|
; { Result = error(_Error) },
|
|
io__write_string("Error reading file!")
|
|
).
|
|
|