Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

GT.M reading from file system files where line endings are CR-LF...

168 views
Skip to first unread message

Sam Habiel

unread,
Mar 11, 2013, 8:20:18 PM3/11/13
to
I am working on a Unit Test suite that emulates HTML that is part of the Virtual Patient Record. HTML ends with $C(13,10) on each line. The output is saved to a file; and I am trying to read the file back.

Is there a way to tell GT.M that the terminator for a line is a $C(13,10), and not just a $C(10)? The application logic right now checks to see if a line is empty; but right now an empty line contains one character: $C(13), because the read terminates at $C(10).

Been trying to get the answer from here:
http://tinco.pair.com/bhaskar/gtm/doc/books/pg/UNIX_manual/ch09s09.html

OldMster

unread,
Mar 11, 2013, 8:53:32 PM3/11/13
to
Sam,
I don't think there is a way to make GT.M on Linux consider the combination of $c(13,10) as the terminator. You could add $c(13) as a terminator using the TERMINATOR parameter of the Use command, but that would cause your routine to read a blank line at the end of every line. I gave up on letting the M system determine the end of line a long time ago. I do single character * reads for just about everything these days, and do my own end of line interpretation. So instead of using a read command, create an extrinsic function that does the read and returns the 'line'. the extrinsic can deal with any end of line issues you want.

Mark

K.S. Bhaskar

unread,
Mar 12, 2013, 9:24:43 AM3/12/13
to
Sam --

At least for now, the best way is probably to read from a PIPE device where the command is dos2unix <file>.

Regards
-- Bhaskar

edde...@gmail.com

unread,
Mar 13, 2013, 1:43:01 PM3/13/13
to
One way to deal with this issue is to expect this difference between the worlds of Windows and Unix/Linux.
You could Read X Set X=$Translate(x,$Char(13))
so that the redundant carriage return character is ignored.
(Of course, that does pre-suppose that the text in question would never contain a meaningful occurrence of $Char(13).)

Ben Irwin

unread,
Mar 31, 2013, 9:20:36 AM3/31/13
to
Sam,

I am sorry if this is too late.

I have been trying to understand this issue a little. When I save web pages on a Linux box only $C(10) exists. If I save the web page on a Windows box then the $C(13,10) exists.

When moving web pages (ASCII Text) via FTP it is important to set the FTP transfer to ASCII and let the FTP process convert the end-of-line from Windows $C(13,10) to Linux $C(10).

It almost sounds like you are downloading the files on a Windows box and transferring to Linux via a process that isn't allowing the conversion.

Ben Irwin

unread,
Mar 31, 2013, 2:32:32 PM3/31/13
to
I agree with edde... above. The following reads the line, translates out the $C(13), then treats the rest as a normal *nix line.

WBREAD
New SRC,line
Set SRC="/home/benirwin/VISTA/DOCS/dict_CRLF.txt"
Open SRC:(readonly)
For Use SRC Read line Quit:$zeof Do
. Set line=$Translate(line,$C(13),"")
. Use 0 Write:line'="" line,!
Close SRC
Quit
0 new messages