← Back to team overview

kicad-developers team mailing list archive

Re: Using FILE_LINE_READER in pcbnew

 

Marco Mattila,

You get the highest praise I can offer, and that is that I could not have
written it any better myself.

Truly outstanding.


+    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:

http://www.w3.org/TR/REC-xml/#sec-line-ends

Quoted here:

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.

Dick






References