Re: How to read carriage return codes?
Carlo Capelli <[email protected]>
| Newsgroups | gmane.comp.ai.prolog.swi |
|---|---|
| Message-ID | <CABty9ww06YL5KrT=G2ais6A0=Hx7DtPe20kgoOyyEWs0u2gHBw@mail.gmail.com> |
Hi Wouter I have this old code I used to transfer files with arbitrary encodings... copy_file(Source, Target) :- open(Source, read, S, [type(binary)]), open(Target, write, T, [type(binary)]), copy_stream_data(S, T), close(S), close(T). bye Carlo 2013/7/30 Wouter Beek <[email protected]> > 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 > > > _______________________________________________ > SWI-Prolog mailing list > [email protected] > https://lists.iai.uni-bonn.de/mailman/listinfo.cgi/swi-prolog > -------------- next part -------------- HTML attachment scrubbed and removed