Recent

Author Topic: Unexpected CR/LF in source file due to editor  (Read 1055 times)

440bx

  • Hero Member
  • *****
  • Posts: 2048
Unexpected CR/LF in source file due to editor
« on: March 17, 2020, 11:50:42 pm »
Hello,

This is a very minor thing that doesn't usually affect anything.  Whenever a source file is edited in the Lazarus editor, the editor automatically adds an unnecessary "CR/LF" at the end of file (in Windows, I don't know what it does in other O/Ss.)

Ideally, there shouldn't be anything after the "end." not even a line ending.

FPC v3.0.4 and Lazarus 1.8.2 on Windows 7 64bit.

winni

  • Hero Member
  • *****
  • Posts: 1999
Re: Unexpected CR/LF in source file due to editor
« Reply #1 on: March 18, 2020, 12:08:10 am »
@440bx

NO, no, no.

What you want is a file where the last readln fails.
It is a good standard that the last line ends with a lineEnding.

Because I now know that a missing LineEnding after the last line there is always an empty line after the last end in my units. Better take care ....

Btw.: There are so many failing config files in Linux that fail because of the last missing LF.

Winni

440bx

  • Hero Member
  • *****
  • Posts: 2048
Re: Unexpected CR/LF in source file due to editor
« Reply #2 on: March 18, 2020, 12:21:58 am »
What you want is a file where the last readln fails.
I fully expect readln to be smart enough to realize that the end of file implies end of line.
FPC v3.0.4 and Lazarus 1.8.2 on Windows 7 64bit.

Thaddy

  • Hero Member
  • *****
  • Posts: 10573
Re: Unexpected CR/LF in source file due to editor
« Reply #3 on: March 18, 2020, 07:45:30 am »
https://www.freepascal.org/docs-html/rtl/classes/tstrings.skiplastlinebreak.html

As the editor's content is a Tstrings descendant this should be configurable or easy to fix.
« Last Edit: March 18, 2020, 07:48:47 am by Thaddy »

440bx

  • Hero Member
  • *****
  • Posts: 2048
Re: Unexpected CR/LF in source file due to editor
« Reply #4 on: March 18, 2020, 08:00:23 am »
https://www.freepascal.org/docs-html/rtl/classes/tstrings.skiplastlinebreak.html

As the editor's content is a Tstrings descendant this should be configurable or easy to fix.
That sounds like the perfect solution. 

It's a very minor thing but, in some rare cases, that extra line ending can be a nuisance.
FPC v3.0.4 and Lazarus 1.8.2 on Windows 7 64bit.

af0815

  • Hero Member
  • *****
  • Posts: 586
Re: Unexpected CR/LF in source file due to editor
« Reply #5 on: March 18, 2020, 08:59:47 am »
What you want is a file where the last readln fails.
I fully expect readln to be smart enough to realize that the end of file implies end of line.

Why should readln be smart and do unwanted things? It should only read until end of line not guess. If it is configurable, it will be ok.
regards
Andreas

PascalDragon

  • Hero Member
  • *****
  • Posts: 2418
  • Compiler Developer
Re: Unexpected CR/LF in source file due to editor
« Reply #6 on: March 18, 2020, 09:29:03 am »
What you want is a file where the last readln fails.
I fully expect readln to be smart enough to realize that the end of file implies end of line.

Why should readln be smart and do unwanted things? It should only read until end of line not guess. If it is configurable, it will be ok.

Because if it wouldn't detect the end of the file then the ReadLn would hang forever (like it does with StdIn if no line ending is read). And you can just as easily test it:

Code: Pascal  [Select][+][-]
  1. program tread;
  2.  
  3. var
  4.   t: Text;
  5.   s: AnsiString;
  6. begin
  7.   Assign(t, ParamStr(1));
  8.   Reset(t);
  9.   while not Eof(t) do begin
  10.     Readln(t, s);
  11.     Writeln(s);
  12.   end;
  13. end.

The test file:

Code: [Select]
test
another
end.

(no line ending after end.)

Output:

Code: [Select]
PS E:\fpc\git> .\testoutput\tread.exe .\fpctests\test.txt
test
another
end.

 

TinyPortal © 2005-2018