How to read carriage return codes?
Wouter Beek <[email protected]>
| Newsgroups | gmane.comp.ai.prolog.swi |
|---|---|
| Message-ID | <CAE1un7O_4Kp6LcBN2wsUOKfANDK1+EVSHgU5FVxgkEiSjyH8Pw@mail.gmail.com> |
Hi all,
I want to read a file with CRLF line endings to a list of codes.
When I use open/3 and read_stream_to_codes/2 to do this the code list only
has linefeeds (no carriage return).
I'm probably overlooking something simple here... Is there a setting/flag
to get the CR codes as well? I'm using 64bit Windows.
The file as viewed in a Hex editor:
~~~{.hex}
0D 0A 0D 0A 0D 0A 0D 0A 0D 0A
~~~
The Prolog code:
~~~
:- module(crlf, []).
:- use_module(library(apply)).
:- use_module(library(readutil)).
:- initialization(crlf).
crlf:-
source_file(crlf, ThisFile),
file_directory_name(ThisFile, ThisDirectory),
absolute_file_name(
crlf,
File,
[access(read), extensions([txt]), relative_to(ThisDirectory)]
),
open(File, read, Stream),
read_stream_to_codes(Stream, Codes),
maplist(writeln, Codes).
~~~
The output of the Prolog code:
~~~
10
10
10
10
10
~~~
---
Cheers!,
Wouter.
E-mail: [email protected]
WWW: www.wouterbeek.com
Tel.: 0647674624
-------------- next part --------------
HTML attachment scrubbed and removed
-------------- next part --------------
-------------- next part --------------
A non-text attachment was scrubbed...
Name: crlf.pl
Type: application/octet-stream
Size: 406 bytes
Desc: not available
URL: <https://lists.iai.uni-bonn.de/pipermail/swi-prolog/attachments/20130730/5508b300/attachment.obj>