mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Mar 2008
Posts: 44
N
Ameglian cow
OP Offline
Ameglian cow
N
Joined: Mar 2008
Posts: 44
Hi,
Is there anyway to get the linenumber of a line I /fseek'ed to ?
..with any of the file handling identifiers/commands .

Thanks

Joined: Oct 2005
Posts: 1,741
G
Hoopy frood
Offline
Hoopy frood
G
Joined: Oct 2005
Posts: 1,741
I don't use file commands, but you may try:

$fopen(name).pos

File commands may not actually consider line breaks, so you may have to count the number of $crlf or $cr or $lf from the start of the file to the current position.

-genius_at_work

Joined: Mar 2008
Posts: 44
N
Ameglian cow
OP Offline
Ameglian cow
N
Joined: Mar 2008
Posts: 44
genius_at_work wrote. . .
Code:
I don't use file commands, but you may try: 

thanks for the reply, i use them a lot.
like you said Fopen().pos just gives the position & not the line number. - Some of the File commands do implicitly consider line breaks like fseek -n , fseek -l & $fread() which places teh pointer at the beginning of the next line after returning.


Here's what am doing,
I need to return the previous line given a certain line.
so I fseek -w to the given line, & then i need to get the text in the previous line. there is only a fseek -n that seeks to the next line & no way to get the previous line

Last edited by Nightstorm; 15/06/09 02:56 PM.
Joined: Oct 2005
Posts: 1,741
G
Hoopy frood
Offline
Hoopy frood
G
Joined: Oct 2005
Posts: 1,741
It doesn't appear that there is a built-in way to determine which line you are currently on. As I mentioned before, you could make some convoluted script to count the linebreaks somehow.

Maybe one of the file commands has undocumented arguments. Like adding ,-1 to the $fread identifier. Maybe the $readn identifier also works on the file commands.

Otherwise, this looks like an opportunity for a feature suggestion.

-genius_at_work

Joined: Oct 2003
Posts: 3,918
A
Hoopy frood
Offline
Hoopy frood
A
Joined: Oct 2003
Posts: 3,918
I'd question what it is you're trying to do.... I'm not sure of any situation where you'd be fseeking to a byte position but wanting a line number.

If you use /fseek -l you have the line number right there.

Otherwise, with just a byte position, mIRC would not really be able to implement this any more efficiently than a script-- both of which would implement it inefficiently overall. To get the line number from a position in a file, mIRC would need to loop through each byte counting the lines as it goes. You could script the same thing, it's not nearly as convoluted as it sounds.

$fopen(fp).line might be an interesting suggestion though.


- argv[0] on EFnet #mIRC
- "Life is a pointer to an integer without a cast"
Joined: Mar 2008
Posts: 44
N
Ameglian cow
OP Offline
Ameglian cow
N
Joined: Mar 2008
Posts: 44
argvo wrote..
Quote:
I'd question what it is you're trying to do....
in this instance I need to get to the previous line after seeking to a line using /fseek -w. So if i had the line number of this line (the won i seeked to with /fseek -w) then i could easily get to the previous line with /fseek -l

/fseek -l implies that you know the line number already.

btw in my script i finally used $readn after doing 1 $read first.. & then used the /fseek commands for the rest of the processing.(& keeping track of the line number after that)

argvo wrote
Quote:
Otherwise, with just a byte position, mIRC would not really be able to implement this any more efficiently than a script-- both of which would implement it inefficiently overall. To get the line number from a position in a file, mIRC would need to loop through each byte counting the lines as it goes.


what about in /fseek -l doesn't it have to do this in this case ?

Thanks for the extra info
-

Last edited by Nightstorm; 18/06/09 06:43 AM.

Link Copied to Clipboard