mIRC Home    About    Download    Register    News    Help

Print Thread
Page 1 of 2 1 2
File Handle routine, EOF halts execution... #227863 26/11/10 07:20 AM
Joined: Apr 2003
Posts: 342
M
MeStinkBAD Offline OP
Fjord artisan
OP Offline
Fjord artisan
M
Joined: Apr 2003
Posts: 342
I've done some testing and when using $fread and it encounters the end of file, the entire execution of the script terminates w/o warning.


Beware of MeStinkBAD! He knows more than he actually does!
Re: File Handle routine, EOF halts execution... [Re: MeStinkBAD] #227867 26/11/10 11:26 AM
Joined: Dec 2002
Posts: 4,588
Khaled Offline
Hoopy frood
Offline
Hoopy frood
Joined: Dec 2002
Posts: 4,588
Please provide a short example script that reproduces this issue.

Re: File Handle routine, EOF halts execution... [Re: Khaled] #228020 03/12/10 08:36 AM
Joined: Apr 2003
Posts: 342
M
MeStinkBAD Offline OP
Fjord artisan
OP Offline
Fjord artisan
M
Joined: Apr 2003
Posts: 342
Code:
alias eoftest {
  /timer.fclose 1 1 /fclose mirc.ini
  /fopen mirc.ini mirc.ini

  while (!$feof && !$ferr) { 
    var %line = $fread(mirc.ini)
  }
  /fclose mirc.ini
  /timer.fclose off
}


If the timer executes then the bug exists...

* Note I've come up w/ this code on the fly it's not exactly tested.



Beware of MeStinkBAD! He knows more than he actually does!
Re: File Handle routine, EOF halts execution... [Re: MeStinkBAD] #228030 03/12/10 10:08 PM
Joined: Sep 2005
Posts: 2,878
H
hixxy Offline
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,878
You should maybe provide some code that you've tested and reproduces the bug, as that one works fine:

Quote:
* Timer .fclose activated
-
* fopen opened 'mirc.ini' (C:\Users\Matt\AppData\Roaming\mIRC\mirc.ini)
-
* fclose closed 'mirc.ini' (C:\Users\Matt\AppData\Roaming\mIRC\mirc.ini)
-
* Timer .fclose halted
-


Running the public beta.

Re: File Handle routine, EOF halts execution... [Re: hixxy] #228089 06/12/10 05:35 PM
Joined: Apr 2003
Posts: 342
M
MeStinkBAD Offline OP
Fjord artisan
OP Offline
Fjord artisan
M
Joined: Apr 2003
Posts: 342
Please try reading from the following file as it is the file I was reading from... and try to make sure it does indeed get every line.

http://db.tt/kFpHqD9



Beware of MeStinkBAD! He knows more than he actually does!
Re: File Handle routine, EOF halts execution... [Re: MeStinkBAD] #228166 10/12/10 09:17 PM
Joined: Sep 2005
Posts: 2,878
H
hixxy Offline
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,878
Code:
alias eoftest {
  /timer.fclose 1 1 /fclose mirc.ini
  /fopen mirc.ini sjis-0208-1997-std.txt
  var %i = 0
  while (!$feof && !$ferr) { 
    var %line = $fread(mirc.ini)
    inc %i
  }
  echo -s ~ Line: %i || Lines: $lines(sjis-0208-1997-std.txt)
  /fclose mirc.ini
  /timer.fclose off
}


Quote:
* Timer .fclose activated
-
* fopen opened 'mirc.ini' (C:\Users\Matt\AppData\Roaming\mIRC\sjis-0208-1997-std.txt)
-
~ Line: 9067 || Lines: 9066
-
* fclose closed 'mirc.ini' (C:\Users\Matt\AppData\Roaming\mIRC\sjis-0208-1997-std.txt)
-
* Timer .fclose halted
-


Still not able to reproduce this problem.

What does this return?

Code:
//echo -a $os $version $md5($mircexe,2) $file($mircexe).sig $script(0) $dll(0) $com(0)

Re: File Handle routine, EOF halts execution... [Re: hixxy] #228197 12/12/10 02:30 AM
Joined: Apr 2003
Posts: 342
M
MeStinkBAD Offline OP
Fjord artisan
OP Offline
Fjord artisan
M
Joined: Apr 2003
Posts: 342
Code:
#_DEFAULT.PROPERTIES OFF

[start]

[CONST]
SJISSPEC=$mircdir $+ sjis-0208-1997-std.txt

#_DEFAULT.PROPERTIES END

ALIAS __SJISspec { return $readini($script,CONST,SJISSPEC) }

ALIAS DEC2HEX {
  var %pad = $len($base($$1,10,16))
  if (2 \\ %pad) { %pad = %pad + 1 }
  
  if ($isid) { return $base($$1,10,16,%pad) }
  elseif ($1 isnum) { echo -aspe 0x $+ $base($$1,10,16,%pad) }
}
ALIAS HEX2DEC {
  if ($left($1,2) == 0x) || ($left($1,2) == U+) { tokenize 32 $right($1,-2) }
  if ($isid) { return $base($$1,16,10,1) }
  else { echo -aspe  $base($$1,16,10,1) }
}

alias import_sjis {
  if ($hget(sjis)) { /.hfree sjis }
  /hmake sjis 10000
  /.fopen sjis $qt($__SJISspec)
  while (!$fopen(sjis).eof && !$ferr) {
    tokenize 09 $fread(sjis)
    if ($0 > 2) { var %sjis = $1, %utfc = $2, %desc = $3- }
    else { var %sjis = $1, %utfc, %desc = $2- }

    if ($+($#,*) iswm %sjis) continue
    if ($hex2dec(%sjis) < 128) continue

    if (<doublebytes> isin %desc) { /hadd sjis $hex2dec(%sjis) <doublebytes> }
    elseif (<cjk> isin %desc) { /hadd sjis $hex2dec(%sjis) $hex2dec(%utfc) $chr($hex2dec(%utfc)) }
    elseif ($left(%utfc,2) == U+) { /hadd sjis $hex2dec(%sjis) $hex2dec(%utfc) $chr($hex2dec(%utfc)) }
  }
  :error
  /fclose sjis
}


Okay that is the actual (and quite embarrassingly ugly) code I wrote the demonstrated the issue... well I found the problem... has nothing to do with file handles. Of course the code works perfectly fine in 6.35. It performed identically except that it would close the handle properly. In 7.15 it would not. Something was amuck... but it was so long ago... i didn't report the issue well over a week I had discovered it because I didn't really have easy access to it. I didn't have access to it when I did report the problem. Of course I suppose file handles are working exactly as they should...

The cause of the problem? I'll highlight it below...

if ($isid) { return $base($$1,16,10,1) }

Yeah I never actually really use $$. I mean I don't quite understand why $$ would break or halt execution. I don't know if it halts or breaks execution. I don't think it knows itself. CLearly it once simply acted as a break... now I guess it acts as a "halt" for "consistently". One would think that $$ would likely act like $!... I mean why doesn't %% behave like $$? Why doesn't %! behave like $!? Does it matter? No. But You are going to have a hard time arguing this is for constancy when I see no constancy.



Beware of MeStinkBAD! He knows more than he actually does!
Re: File Handle routine, EOF halts execution... [Re: MeStinkBAD] #228199 12/12/10 03:19 AM
Joined: Apr 2010
Posts: 924
F
FroggieDaFrog Offline
Hoopy frood
Offline
Hoopy frood
F
Joined: Apr 2010
Posts: 924
it says in the help file and i qupte
Quote:
The double $$ means that this command will only be executed if a parameter is specified.


I can see how it could me mis-inturpertated(SP?!) but generally, if you read the help file, the $$ and it's uses are one of the first things you use. Look at the default aliases that come with mIRC. smirk

Your argument is invalid for the %%var. How is mIRC supposed to know that the 2nd % isn't part of the variable name. I have seen many scripts use %%varname to mark the variable as a tempory variable to been cleaned up later. You CAN'T create an alias like "alias $myalias { stuff }"


I am SReject
My Stuff
Re: File Handle routine, EOF halts execution... [Re: FroggieDaFrog] #228200 12/12/10 03:29 AM
Joined: Apr 2003
Posts: 342
M
MeStinkBAD Offline OP
Fjord artisan
OP Offline
Fjord artisan
M
Joined: Apr 2003
Posts: 342
Originally Posted By: FroggieDaFrog
it says in the help file and i qupte
Quote:
The double $$ means that this command will only be executed if a parameter is specified.


I can see how it could me mis-inturpertated(SP?!) but generally, if you read the help file, the $$ and it's uses are one of the first things you use. Look at the default aliases that come with mIRC. smirk

Your argument is invalid for the %%var. How is mIRC supposed to know that the 2nd % isn't part of the variable name. I have seen many scripts use %%varname to mark the variable as a tempory variable to been cleaned up later. You CAN'T create an alias like "alias $myalias { stuff }"


Type "/alias $myalias { stuff }" before stating you can't possible create it...


Beware of MeStinkBAD! He knows more than he actually does!
Re: File Handle routine, EOF halts execution... [Re: MeStinkBAD] #228201 12/12/10 03:47 AM
Joined: Apr 2010
Posts: 924
F
FroggieDaFrog Offline
Hoopy frood
Offline
Hoopy frood
F
Joined: Apr 2010
Posts: 924
Code:
alias $myalias {
  echo -a $!MyAlias Triggered
  return $!MyAlias Triggered
}
alias MyAliasTest {
  echo -a $!MyAlias: $MyAlias
  echo -a Trying /$MyAlias:
  $myAlias
  echo -a Trying /$$MyAlias:
  $$MyAlias
  echo -a $!$MyAlias: $$MyAlias
}


How about before criticizing you thoroughly test code yourself. NONE return! Yes, you can add "$somealias" to your aliases section, but you can never access the alias.


Last edited by FroggieDaFrog; 12/12/10 03:49 AM.

I am SReject
My Stuff
Re: File Handle routine, EOF halts execution... [Re: MeStinkBAD] #228203 12/12/10 04:08 AM
Joined: Oct 2004
Posts: 8,327
Riamus2 Offline
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,327
$$ is used as a way to stop output if there isn't a value. It's useful when you don't want to throw an error message if some value isn't included. Of course, you can include error checking to verify that the value is there, but $$ is easier and does the same thing. A basic example is something like:

msg $chan $$?="Message"

Without the $$, it will give an error if you press cancel or ok without any text. With $$, it will simply halt the msg without throwing an error.

As far as naming identifiers, yes, you can name an identifier something like $identifier if you want to. However, it will be of limited use. You cannot call it using $identifier or $$identifier because both will point to an identifier named "identifier". $$identifier will just halt if nothing is returned. You *can* call it using $$$identifier. The limitation is that this will always halt if nothing is returned. If that's okay with whatever your script is doing, then it isn't a problem. But, if there are times with the identifier can return $null and you want the script to continue without halting, then that's not going to be possible with that naming scheme.


Invision Support
#Invision on irc.irchighway.net
Re: File Handle routine, EOF halts execution... [Re: Riamus2] #228207 12/12/10 05:43 AM
Joined: Feb 2006
Posts: 546
J
jaytea Offline
Fjord artisan
Offline
Fjord artisan
J
Joined: Feb 2006
Posts: 546
Originally Posted By: Riamus2
The limitation is that this will always halt if nothing is returned. If that's okay with whatever your script is doing, then it isn't a problem. But, if there are times with the identifier can return $null and you want the script to continue without halting, then that's not going to be possible with that naming scheme.


you can actually call it normally with $/$identifier - that / can be ~ or . or a character combination that resembles a valid command prefix such as /. or // or /!. etc.

speaking of which, perhaps one day Khaled will let us overwrite internal identifiers (again?) :P

oh, and you can also call it as a command in the usual way: $!identifier. but who would use this style of naming?


"The only excuse for making a useless script is that one admires it intensely" - Oscar Wilde
Re: File Handle routine, EOF halts execution... [Re: jaytea] #228218 12/12/10 02:37 PM
Joined: Oct 2004
Posts: 8,327
Riamus2 Offline
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,327
Ah, I see. So then it's possible to name it with $ and use it "normally". I don't think it's worth doing, but it's possible. smile


Invision Support
#Invision on irc.irchighway.net
Re: File Handle routine, EOF halts execution... [Re: jaytea] #228551 29/12/10 12:41 AM
Joined: Apr 2003
Posts: 342
M
MeStinkBAD Offline OP
Fjord artisan
OP Offline
Fjord artisan
M
Joined: Apr 2003
Posts: 342
I need to point out that $$ did NOT halt execution in mIRC 6.2 or w/e. That's the bug. I really think that $$ causing execution to abruptly halt without any notification is really quite dangerous.

Originally Posted By: jaytea
you can actually call it normally with $/$identifier - that / can be ~ or . or a character combination that resembles a valid command prefix such as /. or // or /!. etc.


Then why does $$ also behave this way?

Quote:
oh, and you can also call it as a command in the usual way: $!identifier. but who would use this style of naming?


Khaled would... lol


Beware of MeStinkBAD! He knows more than he actually does!
Re: File Handle routine, EOF halts execution... [Re: MeStinkBAD] #228553 29/12/10 05:02 AM
Joined: Oct 2003
Posts: 3,918
A
argv0 Offline
Hoopy frood
Offline
Hoopy frood
A
Joined: Oct 2003
Posts: 3,918
Since when did $$ not halt execution? That was its purpose since the construct was made.


- argv[0] on EFnet #mIRC
- "Life is a pointer to an integer without a cast"
Re: File Handle routine, EOF halts execution... [Re: argv0] #228556 29/12/10 11:10 AM
Joined: Oct 2004
Posts: 8,327
Riamus2 Offline
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,327
Yeah, I've used $$ to halt execution when something is missing for as long as I remember. I don't know when that was added, but it's been there a very long time.


Invision Support
#Invision on irc.irchighway.net
Re: File Handle routine, EOF halts execution... [Re: jaytea] #228557 29/12/10 12:32 PM
Joined: Jul 2006
Posts: 3,588
W
Wims Offline
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 3,588
Originally Posted By: jaytea
that / can be ~ or .
Hum, $~ident construct will only call the internal function, it will not work for custom alias


Looking for a good help channel about mIRC? Check #mircscripting @ irc.swiftirc.net
Re: File Handle routine, EOF halts execution... [Re: Wims] #228558 29/12/10 01:44 PM
Joined: Apr 2003
Posts: 342
M
MeStinkBAD Offline OP
Fjord artisan
OP Offline
Fjord artisan
M
Joined: Apr 2003
Posts: 342
$$ would break out of the routine in the past,like calling /return instead of halt. Now it calls /halt.

If you don't believe me go try running that code in version 6. Performs just fine.

Last edited by MeStinkBAD; 29/12/10 01:46 PM.

Beware of MeStinkBAD! He knows more than he actually does!
Re: File Handle routine, EOF halts execution... [Re: MeStinkBAD] #228559 29/12/10 09:08 PM
Joined: Jul 2006
Posts: 3,588
W
Wims Offline
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 3,588
Quote:
I need to point out that $$ did NOT halt execution in mIRC 6.2 or w/e. That's the bug.

Quote:
$$ would break out of the routine in the past,like calling /return instead of halt
I tried on mIRC 6.2, $$ halt.


Looking for a good help channel about mIRC? Check #mircscripting @ irc.swiftirc.net
Re: File Handle routine, EOF halts execution... [Re: Wims] #228589 02/01/11 02:09 PM
Joined: Apr 2003
Posts: 342
M
MeStinkBAD Offline OP
Fjord artisan
OP Offline
Fjord artisan
M
Joined: Apr 2003
Posts: 342


Explain....


Beware of MeStinkBAD! He knows more than he actually does!
Page 1 of 2 1 2