kicad-developers team mailing list archive
Mailing list archive
Re: Using FILE_LINE_READER in pcbnew
Dick Hollenbeck <dick@xxxxxxxxxxx>
Thu, 13 Jan 2011 01:22:18 -0600
Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:18.104.22.168) Gecko/20101208 Thunderbird/3.1.7
You get the highest praise I can offer, and that is that I could not have
written it any better myself.
+ while( aReader->ReadLine() )
+ Line = aReader->Line();
I see you even caught the fact that if there is an absurdly long line, >
5000, that the Line pointer can change as the LINE_READER reallocates and
moves the internal buffer. I see that you only pay for the minor overhead
of traveling through the virtual functions once per line.
Everything is just plain excellently done.
> I guess that the strtok was there to take care of situations where a
> file saved in windows is opened in linux (?). Opening a board having
> \r\n line endings seems to work using FILE_LINE_READER. A file using
> \r's only would not work.
I think fgets() will hide the platform specific ugliness well enough. No
sleep lost here.
The requirement for XML parsers would make a good requirement for how
fgets() should work:
To simplify the tasks of applications
<http://www.w3.org/TR/REC-xml/#dt-app>, the XML processor
<http://www.w3.org/TR/REC-xml/#dt-xml-proc> /MUST/ behave as if it
normalized all line breaks in external parsed entities (including the
document entity) on input, before parsing, by translating both the
two-character sequence #xD #xA and any #xD that is not followed by #xA to a
single #xA character.
fgets() may not do this on all our 'supported' platforms. If what comes in
are lines of text, and \r and \n are whitespace, same as \t and ' ', then
reasonably written line using code should be fine.
(Supported platforms is an oxymoron when you think about it. Isn't a
platform supposed to support us?) If we find one that does not, or we get
grief, then we can re-implement FILE_LINE_READER::ReadLine(), whose API can
be protected contractually, because it is worth protecting. At that point a
looping fgetc() call comes to mind, under the hood of ReadLine().
Thanks for your work. I literally could not have done it better myself.