detect unix or dos line endings



>>>>> "Edwin" == Edwin Woollett <woollett at charter.net> writes:

    Edwin> On May 24, Raymond Toy wrote:
    Ray> ---------------------------------------
    Ray> .... the maxima language allows you to
    Ray> escape to Lisp using ?.  Thus you can use ?read\-char to read a
    Ray> character from a stream and then use other maxima functions to
    Ray> determine if you've encountered LF or CR/LF or plain CR (Mac)
    Ray> end-of-line sequences.
    Ray> ---------------------------------------

    Edwin> The common lisp cookbook talks about
    Edwin> using a second argument NIL in the
    Edwin> lisp function read-char to get a return
    Edwin> value of NIL is end-of-line is found, but
    Edwin> I am probably not adapting this idea
    Edwin> correctly below??

[snip]

    Edwin> /* so there is the second expected end of line char LF */

    Edwin> /* but, what if there had only been one end of line char,
    Edwin> as in unix or mac file?  As an experiment, we go
    Edwin> for another char, not knowing if it is the end of file
    Edwin> */
    Edwin> (%i14) cs : string(?read\-char(ss,nil));

You want false, here, not nil.  nil is the maxima symbol nil, which
will be treated as true by READ-CHAR.  "false" will get converted to
CL:NIL, which is what you want to pass to READ-CHAR.

So

  cs: string(?read\-char(ss,false));

will return false when you reach the end of the file instead of
signaling an eof error.

Ray