Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.sys.acorn.programmer > #2007
| From | Dave Stratford <daves@orpheusmail.co.uk> |
|---|---|
| Subject | Re: Reading text files with cr / lf line terminators |
| Newsgroups | comp.sys.acorn.programmer |
| Date | 2012-08-07 14:52 +0100 |
| Message-ID | <52bb88f6d0daves@orpheusmail.co.uk> (permalink) |
| References | <52bb693e1fdaves@orpheusmail.co.uk> <mpro.m8dtqj00364oe00zk.vinceh@softrock.co.uk> <mpro.m8dugr003qcq900zk.vinceh@softrock.co.uk> |
| Organization | Hexagon Systems Limited |
In article <mpro.m8dugr003qcq900zk.vinceh@softrock.co.uk>,
Vince M Hudd <vinceh@softrock.co.uk> wrote:
> Vince M Hudd <vinceh@softrock.co.uk> wrote:
> > Dave Stratford <daves@orpheusmail.co.uk> wrote:
> [...]
> > I don't think you'll be able to get the terminator from the actual line
> > returned by GET$, but you should be able to read it from the file, so you
> > could probably do something like:
> Typical, you post, and it isn't until you read your own post when you think
> "D'oh!"
> Why bother checking the line ending on every line? Why not just check the
> line ending (and that of the previous line) when a blank line is
> encountered?
> ----8<----
> REM Your line to read a line from the file
> line$ = GET$#file%
> REM [re]initialise validblank% every time
> REM If it's blank, check if it's validly so
> IF line$ = "" THEN validblank% = FN_IsItReallyBlank(file%)
> REM rest of your code, and somewhere, this function
> DEF FN_IsItReallyBlank(handle%)
> LOCAL oldterm%, newterm%
> REM Go back two bytes in the file
> PTR#handle% = (PTR#handle%)-2
> REM Read those two bytes as the old terminator and new terminator
> oldterm%=BGET#Handle%
> newterm%=BGET#Handle%
> REM Compare them, return TRUE if they're the same, FALSE if not
> IF oldterm%=newterm% THEN =TRUE ELSE =FALSE
> ----8<----
> The outcome is the same - you have a variable, validblank% containing TRUE
> if a blank line is a valid one, FALSE if it's the result of a mixed
> terminator. The advantage is far fewer additional byte reads from the file
> when the file only has single line terminators.
> (Again, untested in the usual tradition of usenet, etc)
By itself this doesn't work, as it wouldn't catch validly empty blank
lines with a PC/DOS style CRLF line terminator, but with a small tweak it
worked fine:
=== 8< ===
DEF FN_CheckBlank(handle%)
LOCAL oldterm%, newterm%, prev1%, prev2%, curr1%, curr2%
REM Go back two bytes in the file
PTR#handle% = (PTR#handle%)-2
REM Read those two bytes as the old terminator and new terminator
oldterm%=BGET#handle%
newterm%=BGET#handle%
IF (oldterm%=10 AND newterm%=13) OR (oldterm%=13 AND newterm%=10) THEN
REM here we have a cr/lf terminator, so go back another two characters to
see if they too were a cr/lf terminator for a pc/dos style end of line.
PTR#handle% = (PTR#handle%)-4
prev1%=BGET#handle%
prev2%=BGET#handle%
curr1%=BGET#handle%
curr2%=BGET#handle%
IF prev1% = curr1% AND prev2% = curr2% THEN =TRUE ELSE =FALSE
ELSE
IF oldterm%=newterm% THEN =TRUE ELSE =FALSE
ENDIF
=== 8< ===
Many thanks,
Dave
--
_ _________________________________________
/ \._._ |_ _ _ /' Orpheus Internet Services
\_/| |_)| |(/_|_|_> / 'Internet for Everyone'
_______ | ___________./ http://www.orpheusinternet.co.uk
Back to comp.sys.acorn.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Reading text files with cr / lf line terminators Dave Stratford <daves@orpheusmail.co.uk> - 2012-08-07 09:05 +0100
Re: Reading text files with cr / lf line terminators Vince M Hudd <vinceh@softrock.co.uk> - 2012-08-07 12:11 +0100
Re: Reading text files with cr / lf line terminators Vince M Hudd <vinceh@softrock.co.uk> - 2012-08-07 12:26 +0100
Re: Reading text files with cr / lf line terminators Dave Stratford <daves@orpheusmail.co.uk> - 2012-08-07 14:52 +0100
Re: Reading text files with cr / lf line terminators Ron <beeb@woosh.co.nz> - 2012-08-07 23:35 +1200
Re: Reading text files with cr / lf line terminators Alan Adams <alan@adamshome.org.uk> - 2012-08-07 14:21 +0100
Re: Reading text files with cr / lf line terminators Jeremy Nicoll - news posts <jn.nntp.scrap007@wingsandbeaks.org.uk> - 2012-08-07 15:09 +0100
Re: Reading text files with cr / lf line terminators Ron <beeb@woosh.co.nz> - 2012-08-08 03:01 +1200
Re: Reading text files with cr / lf line terminators Ron <beeb@woosh.co.nz> - 2012-08-08 04:13 +1200
Re: Reading text files with cr / lf line terminators Jeremy Nicoll - news posts <jn.nntp.scrap007@wingsandbeaks.org.uk> - 2012-08-07 15:20 +0100
Re: Reading text files with cr / lf line terminators jgh@arcade.demon.co.uk (Jonathan Graham Harston) - 2012-08-08 22:41 +0100
csiph-web