gm2
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Gm2] TextIO.ReadRestLine includes EOL char in string result


From: Gaius Mulley
Subject: Re: [Gm2] TextIO.ReadRestLine includes EOL char in string result
Date: Fri, 30 Oct 2009 10:41:02 +0000
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.2 (gnu/linux)

"Breeden, Thomas (tmb)" <address@hidden> writes:

>> From: address@hidden [On Behalf Of SiTex Graphics]
>
>> Not entirely sure this is a bug, but TextIO.ReadRestLine includes the
>> EOL char in the string result.  The XDS and Stonybrook implementations
>> do not.
>
> It is a bug; ReadRestLine() should not read the EOL or past it.
> Verified by pulling out my trusty ISO/IEC 1014-1 document.
>
> ReadRestLine() will return "allRight" if it finds some text before an EOL or 
> EOF,
> so long as it does not find too much text for the parameter, in which case it 
> will
> return "outOfRange" (and the excess chars are discarded).
>
> Either way, you need to call SkipLine() to get past the EOL char, which 
> returns "allRight",
> unless you are positioned past the last EOL char in the file in which case it 
> returns
> "endOfInput".
>
> ReadRestLine(), however will return "endOfLine" if the line was blank with an 
> EOL at the end.
> You still have to call SkipLine() to get past that EOL char.
>
> ReadRestLine() will instead return "endOfInput" if you are positioned beyond 
> the last EOL char.
>
> At one point I got tired of my mistake prone attempts to rewrite the code for 
> reading a file line by line
> via TextIO and write the following module  whose procedures return only 
> "allRight" or "endOfInput".
> It hides all the SkipLines() and necessity for multiple tests on
> return codes:

Hi Tom and Scott,

many thanks for the bug report and clarification..

regards,
Gaius


> --------------------------------------------------------------------------------------------------------------------------------------
>     DEFINITION MODULE TextIOHelper;  
>    ...
>     PROCEDURE ReadNextLine(cid:ChanId; VAR OneLine:ARRAY OF CHAR):ReadResults;
>     PROCEDURE ReadNextNonBlankLine(cid:ChanId; VAR OneLine:ARRAY OF CHAR; VAR 
> NumSkipped:CARDINAL):ReadResults;
>
>     PROCEDURE dReadNextLine(cid:ChanId; VAR dOneLine:DynStr):ReadResults;
>          (* dOneLine must exist or .str be NIL *)
>     PROCEDURE dReadNextNonBlankLine(cid:ChanId; VAR dOneLine:DynStr; VAR 
> NumSkipped:CARDINAL):ReadResults;
>
>    (*    ReadNextLine  - silently truncates any line that won't fit in the 
> OneLine parameter
>                      - never returns endOfLine. For empty line returns 
> allRight with empty OneLine
>                      - endOfInput is returned only on the call AFTER the one 
> that returned the
>                        last line allRight.
>
>           dReadNextLine - reallocates dOneLine to be larger if necessary.
>    *)
> --------------------------------------------------------------------------------------------------------------------------------------
>  
>
> regards,
>
> Tom
> tmb"virginia.edu
>
>
> _______________________________________________
> gm2 mailing list
> address@hidden
> http://lists.nongnu.org/mailman/listinfo/gm2




reply via email to

[Prev in Thread] Current Thread [Next in Thread]