Re: [fpc-pascal] read lines at end of file

2011-04-11 Thread Robert Wolfe

On 04/11/2011 12:32 PM, John Lee wrote:
Need to read the last 4 lines (txt) of a very large log file 100M 
bytes, 100k lines or more  lots of times - of course I can read 
through the file in the normal way but this is rather slow. Is there a 
way to 'read lines from the end'? I note that unix tail or its port to 
windows does this very fast so guess there must be a fast way to do it 
in pascal too?


TIA for any ideas John




___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Hmm, could first have the reader enumerate the number of lines in the 
file, then read through the files using the "total number of lines - 4" 
variable and then start displaying the lines after that variable has 
been reached.  If necessary, I would be happy to see what I can come up 
with here and then post it to the mailing list.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Re: Re[2]: [fpc-pascal] read lines at end of file

2011-04-11 Thread johnelee1944
So the idea is to open file eg as file of array [1:65536] of char or  
something similar, seek & read to end of file, then go through the last  
array converting to strings by finding crlfs correct? Is this the simplest  
way? If not any outline code?


John

On , José Mejuto  wrote:

Hello FPC-Pascal,





Monday, April 11, 2011, 7:55:01 PM, you wrote:





>> The idea is easy, instead reading forward, you read backwards in



>> blocks of, say, 64 Kb and count lines back. If not enougth lines you



>> insert another 64 Kb before and so on. Average line is usually less



>> than 100 bytes, so each 64 Kb are usually more than 600 lines. Read of



>> 64 Kb usually takes the same time as read any lower amount when the



>> block is 4096 bytes aligned.





MG> You can not really read backwards. You can use



MG> something like TFileStream.Seek(-4096,soEnd).





I think that the "read backwards in blocks" already stated that fact,



but nice annotation.





--



Best regards,



José





___



fpc-pascal maillist - fpc-pascal@lists.freepascal.org



http://lists.freepascal.org/mailman/listinfo/fpc-pascal



___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] generic, specialize keywords in mode delphi in FPC trunk

2011-04-11 Thread cobines
2011/4/12 Paul Ishenin :
> 12.04.2011 4:22, cobines wrote:
>>
>> Hello.
>>
>> Following program:
>>
>> program a;
>> {$mode delphi}
>> type
>>   generic TGen  = class end;
>>   TSpc = specialize TGen;
>> begin
>> end.
>>
>> compiles with FPC 2.4.2, but not with 2.5.1 rev. 17306:
>>
>> a.pas(4,11) Fatal: Syntax error, "=" expected but "identifier TGEN" found
>> a.pas(5,21) Error: Identifier not found "specialize"
>> a.pas(5,21) Error: Error in type definition
>> a.pas(5,21) Fatal: Syntax error, ";" expected but "identifier TGEN" found
>>
>> "generic" and "specialize" are not allowed in delphi mode in 2.5.1 but
>> they are required in 2.4.2.
>>
>> Is this a conscious change? There is no mention of this on Wiki User
>> Changes 2.4.4 or User Changes Trunk pages.
>
> In mode delphi FPC understands delphi generic syntax. I did not write a line
> to the
>
> User Changes Trunk because this work is not finished. But looking at my free
> time I don't think it will be finished by me, so I will add a note there
> today.


OK.
Thanks.

--
cobines
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


[fpc-pascal] Re: generic, specialize keywords in mode delphi in FPC trunk

2011-04-11 Thread leledumbo
Since FPC in Delphi mode supports Delphi style generics syntax, FPC's own
generics syntax was removed from this mode. You can still use it from ObjFPC
mode.

--
View this message in context: 
http://free-pascal-general.1045716.n5.nabble.com/generic-specialize-keywords-in-mode-delphi-in-FPC-trunk-tp4296801p4296946.html
Sent from the Free Pascal - General mailing list archive at Nabble.com.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] generic, specialize keywords in mode delphi in FPC trunk

2011-04-11 Thread Paul Ishenin

12.04.2011 4:22, cobines wrote:

Hello.

Following program:

program a;
{$mode delphi}
type
   generic TGen  = class end;
   TSpc = specialize TGen;
begin
end.

compiles with FPC 2.4.2, but not with 2.5.1 rev. 17306:

a.pas(4,11) Fatal: Syntax error, "=" expected but "identifier TGEN" found
a.pas(5,21) Error: Identifier not found "specialize"
a.pas(5,21) Error: Error in type definition
a.pas(5,21) Fatal: Syntax error, ";" expected but "identifier TGEN" found

"generic" and "specialize" are not allowed in delphi mode in 2.5.1 but
they are required in 2.4.2.

Is this a conscious change? There is no mention of this on Wiki User
Changes 2.4.4 or User Changes Trunk pages.
In mode delphi FPC understands delphi generic syntax. I did not write a 
line to the


User Changes Trunk because this work is not finished. But looking at my free 
time I don't think it will be finished by me, so I will add a note there today.

Best regards,
Paul Ishenin

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


[fpc-pascal] generic, specialize keywords in mode delphi in FPC trunk

2011-04-11 Thread cobines
Hello.

Following program:

program a;
{$mode delphi}
type
  generic TGen = class end;
  TSpc = specialize TGen;
begin
end.

compiles with FPC 2.4.2, but not with 2.5.1 rev. 17306:

a.pas(4,11) Fatal: Syntax error, "=" expected but "identifier TGEN" found
a.pas(5,21) Error: Identifier not found "specialize"
a.pas(5,21) Error: Error in type definition
a.pas(5,21) Fatal: Syntax error, ";" expected but "identifier TGEN" found

"generic" and "specialize" are not allowed in delphi mode in 2.5.1 but
they are required in 2.4.2.

Is this a conscious change? There is no mention of this on Wiki User
Changes 2.4.4 or User Changes Trunk pages.

--
cobines
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re[2]: [fpc-pascal] read lines at end of file

2011-04-11 Thread José Mejuto
Hello FPC-Pascal,

Monday, April 11, 2011, 7:55:01 PM, you wrote:

>> The idea is easy, instead reading forward, you read backwards in
>> blocks of, say, 64 Kb and count lines back. If not enougth lines you
>> insert another 64 Kb before and so on. Average line is usually less
>> than 100 bytes, so each 64 Kb are usually more than 600 lines. Read of
>> 64 Kb usually takes the same time as read any lower amount when the
>> block is 4096 bytes aligned.

MG> You can not really read backwards. You can use
MG> something like TFileStream.Seek(-4096,soEnd).

I think that the "read backwards in blocks" already stated that fact,
but nice annotation.

-- 
Best regards,
 José

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] read lines at end of file

2011-04-11 Thread Mattias Gaertner
On Mon, 11 Apr 2011 19:45:10 +0200
José Mejuto  wrote:

> Hello FPC-Pascal,
> 
> Monday, April 11, 2011, 6:32:20 PM, you wrote:
> 
> JL> Need to read the last 4 lines (txt) of a very large log file 100M bytes,
> JL> 100k lines or more  lots of times - of course I can read through the file 
> in
> JL> the normal way but this is rather slow. Is there a way to 'read lines from
> JL> the end'? I note that unix tail or its port to windows does this very fast
> JL> so guess there must be a fast way to do it in pascal too?
> 
> The idea is easy, instead reading forward, you read backwards in
> blocks of, say, 64 Kb and count lines back. If not enougth lines you
> insert another 64 Kb before and so on. Average line is usually less
> than 100 bytes, so each 64 Kb are usually more than 600 lines. Read of
> 64 Kb usually takes the same time as read any lower amount when the
> block is 4096 bytes aligned.

You can not really read backwards. You can use
something like TFileStream.Seek(-4096,soEnd).


Mattias
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] read lines at end of file

2011-04-11 Thread José Mejuto
Hello FPC-Pascal,

Monday, April 11, 2011, 6:32:20 PM, you wrote:

JL> Need to read the last 4 lines (txt) of a very large log file 100M bytes,
JL> 100k lines or more  lots of times - of course I can read through the file in
JL> the normal way but this is rather slow. Is there a way to 'read lines from
JL> the end'? I note that unix tail or its port to windows does this very fast
JL> so guess there must be a fast way to do it in pascal too?

The idea is easy, instead reading forward, you read backwards in
blocks of, say, 64 Kb and count lines back. If not enougth lines you
insert another 64 Kb before and so on. Average line is usually less
than 100 bytes, so each 64 Kb are usually more than 600 lines. Read of
64 Kb usually takes the same time as read any lower amount when the
block is 4096 bytes aligned.

-- 
Best regards,
 José

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


[fpc-pascal] read lines at end of file

2011-04-11 Thread John Lee
Need to read the last 4 lines (txt) of a very large log file 100M bytes,
100k lines or more  lots of times - of course I can read through the file in
the normal way but this is rather slow. Is there a way to 'read lines from
the end'? I note that unix tail or its port to windows does this very fast
so guess there must be a fast way to do it in pascal too?

TIA for any ideas John
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal