mIRC Home    About    Download    Register    News    Help

Print Thread
EOL character and text files issue #201292 24/06/08 12:49 PM
Joined: Oct 2007
Posts: 11
B
Biggoude Offline OP
Pikka bird
OP Offline
Pikka bird
B
Joined: Oct 2007
Posts: 11
Hello,
I tried many ways but the problem seems always occur:
When a EOL character ($crlf for exemple) is in a line on a text file, the $read or $fread do a return whatever if there is some text after (on the same line).
It appears with many commands like $replace. I tried to put the line in a %var or directly in an alias but nothing seems to work.

Exemple line:

this is the text that will be read $crlf and text that won't be read $crlf $crlf .. and again

So, is it possible to read this kein of line? Is it a bug?

ps: command N in $read(..,n,..) don't work too.

Thanks and have a nice day !

Re: EOL character and text files issue [Re: Biggoude] #201294 24/06/08 01:09 PM
Joined: Dec 2002
Posts: 2,962
S
starbucks_mafia Offline
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,962
I'm not sure I follow. In your example line, are the $crlf's meant to be actual newlines or the actual identifier '$crlf'?

I'm getting the correct values either way:
Quote:
//write test.txt one $crlf two $crlf three
; test.txt now contains three lines separated by carriage-return + line-feeds
//echo -a $read(test.txt, n, 1) -- should be: one
one -- should be one
//echo -a $read(test.txt, n, 2) -- should be: two
two -- should be two
//echo -a $read(test.txt, n, 3) -- should be: three
three -- should be three
; All returned correctly!
//write -c test.txt
; test.txt has been cleared
//write test.txt one $!crlf two $!crlf three $!crlf
; test.txt now contains one line with the text $crlf appearing between each word
//echo -a $read(test.txt, n, 1) -- should be: one $!crlf two $!crlf three
one $crlf two $crlf three -- should be: one $crlf two $crlf three


All seems fine here.

Edit:

On reading your post again it seems you misunderstand how EOL characters work. You cannot have an EOL character in the middle of a line because it is the End-Of-Line character - it's literally the character that represents where a line ends in a text file. If you use something like:
Code:
//write test.txt one $crlf two $crlf three

you are actually writing three lines to the file at once. It's not a mIRC bug, it's how text files work. If you open the file in any text editor you'll see it as three lines aswell.

Last edited by starbucks_mafia; 24/06/08 01:13 PM.

Spelling mistakes, grammatical errors, and stupid comments are intentional.
Re: EOL character and text files issue [Re: Biggoude] #201296 24/06/08 01:34 PM
Joined: Oct 2007
Posts: 11
B
Biggoude Offline OP
Pikka bird
OP Offline
Pikka bird
B
Joined: Oct 2007
Posts: 11
Here is a text file containing some EOL in ONE line:

http://www.megaupload.com/?d=ZSVI29OC

I know how work EOF, i know and use C language and i agree it is not simple to handle but i think the link will explain much better smile
thanks for your reply.

Re: EOL character and text files issue [Re: Biggoude] #201297 24/06/08 01:49 PM
Joined: Dec 2002
Posts: 2,962
S
starbucks_mafia Offline
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,962
Right, that file isn't using using carriage-return + line-feeds ($crlf) as EOL characters, it's using only carriage returns ($cr) which are also an EOL character in their own right on some OSes. Some basic Windows-specific text editors might not recognise them as EOL characters (eg. Notepad) but more advanced ones do (eg. Wordpad) - and so does mIRC.


Spelling mistakes, grammatical errors, and stupid comments are intentional.
Re: EOL character and text files issue [Re: Biggoude] #201300 24/06/08 02:04 PM
Joined: Oct 2007
Posts: 11
B
Biggoude Offline OP
Pikka bird
OP Offline
Pikka bird
B
Joined: Oct 2007
Posts: 11
Yes, you're right.
So i think i have my answer smile
mIRC thinks the $cr is the real EOL and stop the line.
May be you know some .DLL that can read all the line?
Thank you very much, i can stop trying my research and my experiments !
Best regards.

Re: EOL character and text files issue [Re: Biggoude] #201302 24/06/08 02:30 PM
Joined: Dec 2002
Posts: 2,962
S
starbucks_mafia Offline
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,962
Well you can use /bread to read the entire file into a binary variable and then assign each peice to a text variable from there.

Or you could strip/replace the loose carriage returns in the file and then read it in as usual.

Code:
replace_cr {
  ; Replace all stray occurrences of CR with spaces in the file (doesn't affect CRLFs)
  var %file = $qt($1-)
  bread %file 0 $file(%file) &cr
  var %i = 1, %pos
  while $bfind(&cr, %i, 13) {
    %pos = $v1
    %i = %pos + 1
    ; Ignore if it's part of a CRLF
    if ($bvar(&cr, %i) != 10) bset &cr %pos 32
  }
  bwrite %file 0 -1 &cr
}

strip_cr {
  ; Remove all stray occurrences of CR from the file (doesn't affect CRLFs)
  var %file = $qt($1-)
  bread %file 0 $file(%file) &cr
  var %i = 1, %pos
  while $bfind(&cr, %i, 13) {
    %pos = $v1
    %i = %pos + 1
    ; Ignore if it's part of a CRLF
    if ($bvar(&cr, %i) != 10) {
      bcopy -c &cr %pos &cr %i -1
      %i = %pos
    }
  }
  write -c %file
  bwrite %file 0 -1 &cr
}


Warning: Both of the above aliases overwrite the original file with the new one.


Spelling mistakes, grammatical errors, and stupid comments are intentional.
Re: EOL character and text files issue [Re: Biggoude] #201304 24/06/08 02:48 PM
Joined: Oct 2007
Posts: 11
B
Biggoude Offline OP
Pikka bird
OP Offline
Pikka bird
B
Joined: Oct 2007
Posts: 11
Very usefull script. It works perfectly and it cleans all my file from all the $cr in it.
I didn't think about the use of /bread and i'm glad you did smile
Thanks a lot to have taken time about my problem, and also to be able to read my english!

Note for the programmer(s): The command N in the $read function may be able to treat $cr as plain text ?

Best regards and have a good day !
Thanks again !

Re: EOL character and text files issue [Re: Biggoude] #201970 10/07/08 08:14 PM
Joined: Apr 2003
Posts: 342
M
MeStinkBAD Offline
Fjord artisan
Offline
Fjord artisan
M
Joined: Apr 2003
Posts: 342
Originally Posted By: Biggoude
Yes, you're right.
So i think i have my answer smile
mIRC thinks the $cr is the real EOL and stop the line.
May be you know some .DLL that can read all the line?
Thank you very much, i can stop trying my research and my experiments !
Best regards.


Umm... a line may be ended by a linefeed character, a return character, or a return character followed by a linefeed character.

A $cr IS a real EOL character. $lf also is a very real EOL character. CR+LF is also a real EOL combination. In any case, you aren't going to find a text document with some CRs and some CRLFs. Stripping CRs characters will only leave you with a text file that is just one long string.


Beware of MeStinkBAD! He knows more than he actually does!