mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Feb 2003
Posts: 26
M
MRN Offline OP
Ameglian cow
OP Offline
Ameglian cow
M
Joined: Feb 2003
Posts: 26
mIRC is the strangest thing. Lately, I've had problems with timers, and I still do, but this is strange.

I'm trying to script a little alias that counts aliases.

I'm executeing this little selfwritten alias with this:

//echo -s > $count.alias($script(1))

Is this making any problems? First, what is the problem? Well, if I run this alias (count.alias), it will execute aliases and scripts!

In the 50th line in my first remote file, is this line;

; v0.021 Added dialog cel, instead of halting the whole script by using $?

What does my alias do? It RUNS the "$?", asking for something. It's commented out in the remote file, but it still runs.

This is the count.alias I use.

Code:
alias count.alias {
  var -s %1 $1
  var -s %x $lines($1)

  var %a 0

  :loop
  inc %a
  if (%a < = %x) {
    var -s %b $read( [ %1 ] , [ %a ] )
    if ($chr(44) isin %b) { goto loop }
    var -s %c $gettok( [ %b ] ,1,32)
    if (%c == alias) { echo -s alias funnet, og som første ord! >> %b << | halt } | else { goto loop }

  } | else { goto loop }
  echo -s loop ferdig
}


I just want to read, not execute.

Is it becuase I use []'s? Any suggestions? smile

Joined: Aug 2004
Posts: 7,252
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
The evaluation being performed using the [ ] is likely the problem. Also, I noted that you have an incorrect format in your $read line
Code:
alias count.alias {
  var -s %1 = $1
  var -s %x = $lines($1)
  var %a = 1
  while %a <= %x {
    var -s %b = $read(%1,n,%a)
    if ($chr(44) !isin %b) {
      var -s %c $gettok(%b,1,32)
      if (%c == alias) {
        echo -s alias funnet, og som første ord! >> %b << 
      }
    }
    inc %a
  }
  echo -s loop ferdig
}

Joined: Jan 2004
Posts: 2,127
Hoopy frood
Offline
Hoopy frood
Joined: Jan 2004
Posts: 2,127
Code:
alias count.alias {
window -h @count.alias
filter -fwc " $+ $1 $+ " @count.alias alias *
return $line(@count.alias,0)
}


Joined: Jan 2003
Posts: 2,523
Q
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
This doesn't display a message for each alias found, but it's easy to modify it using the -k switch to specify an alias as the outfile. A cleaner method (avoids a temp @window) that also catches aliases in .ini files would be
Code:
alias count.alias {
  filter -ffg $qt($1) nul /^(?:n\d+=)?alias /i
  return $filtered
}
nul is a device name in Windows and any output there is lost.
The only case where this might not give the correct number is when users have something like this in their scripts:
Code:
alias blah1 {
alias blah2 return something
}
ie they don't indent their code properly themselves and they don't use the mIRC Editor to edit their scripts (the Editor indents lines when you click OK). In this case, /blah2 will be recognized as an alias (it may or may not be, depending on whether /blah1 was run; either way, it will be in another file, in Aliases). This is a rare enough case imo to be completely ignored though.

Edit: also, it won't work correctly with ini files that contain more than one type of sections. For that, /loadbuf -t and a hidden @window would be most convenient

Last edited by qwerty; 13/05/07 03:30 PM.

/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
Joined: Nov 2006
Posts: 1,559
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Nov 2006
Posts: 1,559
Yepp, filter might be the best sollution. Its btw much faster than loop every line.
Give this a try:
Code:
alias info.mirc {
  ; ----- REMOTE STATS STUFF -----
  ; count remotes (incl. events, aliases, menus, dialogs)
  var %r.nr = 1, %r.size = 0, %r.lines = 0, %r.aliases.glob = 0, %r.aliases.loc = 0
  var %events = 0, %menus = 0, %dialogs = 0
  while ($script(%r.nr)) {
    var %file = $+(",$shortfn($ifmatch),")
    inc %r.size $file(%file).size | inc %r.lines $lines(%file)
    filter -gff %file nul ^(?i)alias (?!-l) | inc %r.aliases.glob $filtered
    filter -gff %file nul ^(?i)alias -l\s | inc %r.aliases.loc $filtered
    filter -gff %file nul ^(?i)(on|ctcp|raw) .+:.+ | inc %events $filtered
    filter -gff %file nul ^(?i)menu .+{ | inc %menus $filtered
    filter -gff %file nul ^(?i)dialog .+{ | inc %dialogs $filtered
    inc %r.nr
  }
  var %r.aliases.tot = $calc(%r.aliases.glob  + %r.aliases.loc), %r.av.lines = $round($calc(%r.lines / $script(0)),0)

  ; ----- BELOW: SOME OTHER STATS STUFF :) -----
  ; count aliases
  var %a.nr = 1, %a.size = 0, %a.lines = 0
  while ($alias(%a.nr)) {
    var %file = $+(",$shortfn($ifmatch),")
    inc %a.size $file(%file).size
    inc %a.lines $lines(%file)
    inc %a.nr
  }
  var %a.av.lines = $round($calc(%a.lines / $alias(0)),0)

  ; count timers
  var %t.nr = 1, %loops
  while ($timer(%t.nr)) {
    if ($timer($ifmatch).reps == 0) { inc %loops }
    inc %t.nr
  }

  ; count groups
  var %g.nr = 1, %actgroups
  while ($group(%g.nr).status) {
    if ($ifmatch == on) { inc %actgroups }
    inc %g.nr
  }

  ; count hashtables
  var %h.nr = 1, %tables = 0, %items = 0
  while ($hget(%h.nr)) { inc %tables | inc %items $hget($v1,0).item | inc %h.nr }
  var %h.av.items = $round($calc(%items / %tables),0)

  ; ----- example output -----
  ECHO -a Remote-Files: $script(0) Lines: %r.lines $chr(91) $+ av.: %r.av.lines $+ $chr(93) Size: $bytes(%r.size).suf $&
    Aliases(Remote): %r.aliases.tot $iif((%r.aliases.tot > 0),$chr(91) $+ global: %r.aliases.glob $+ $chr(44) local: %r.aliases.loc $+ $chr(93))
  ECHO -a Alias-Files: $alias(0) Lines: %a.lines $chr(91) $+ av.: %a.av.lines $+ $chr(93) Size: $bytes(%a.size).suf
  ECHO -a Menus: %menus ### Dialogs: %dialogs ### Events: %events ### Timer: $timer(0) $iif(($timer(1)),$chr(91) $+ Loops: %loops $+ $chr(93)) 
  ECHO -a Groups: $group(0) $iif(($group(1)),$chr(91) $+ active: %actgroups $+ $chr(93)) $&
    ### Hashtables: %tables $iif((%tables > 0),$chr(91) $+ Items: %items $+ $chr(44) av.: %h.av.items $+ $chr(93))
}


EDIT: arf, qwerty had been faster than me regarding "nul", 'think he filtered his exlanatory code directly into the forum wink

Last edited by Horstl; 13/05/07 02:57 PM.
Joined: Dec 2002
Posts: 580
N
Fjord artisan
Offline
Fjord artisan
N
Joined: Dec 2002
Posts: 580
I can't reproduce this problem with the script as you have given it...

Why would you want to count the number of [aliases] section headers?? There should only ever be one. A more useful alias would count the number of actual aliases...

Code:
alias countaliases {
  var %file $1
  var %lines $lines(%file)
  var %index 1 | var %ln | var %depth 0 | var %count 0
  while (%index <= %lines) {
    set %ln $read(%file, nt, %index)
    var %pos $pos(%ln, $chr(59))
    if (%pos) set %ln $left(%ln, ($calc(%pos - 1)))
    if (!%ln) { inc %index | continue }
    if (%depth == 0) {
      if ([aliases] isin %ln) noop
      else if ([remotes] isin %ln) noop
      else if (popup] isin %ln) noop
      else if ($chr(35) == $left(%ln, 1)) noop
      else if ($chr(123) !isin %ln) && ($chr(125) !isin %ln) inc %count
      else if (alias == $left(%ln, 5)) || (=alias isin %ln) inc %count
    }
    if ($chr(123) isin %ln) inc %depth $count(%ln, $chr(123))
    if ($chr(125) isin %ln) dec %depth $count(%ln, $chr(125))
    inc %index
  }
  if (%depth != 0) { echo -a countaliases: Missmatched curly brackets in %file }
  return %count
}


Edit: It's not "perfect"... Strange programming styles or putting vars, popups, or user ini sections in the same file that has remotes or alias, might mess with it, but with some tweaking, it should work nicely...

Last edited by NaquadaServ; 13/05/07 03:10 PM.

NaquadaBomb
www.mirc-dll.com
Joined: Jan 2007
Posts: 1,156
D
Hoopy frood
Offline
Hoopy frood
D
Joined: Jan 2007
Posts: 1,156
Ok so I didn't read every word of this post, but if you want to find out how many aliases you have, why not use:

Quote:
$alias(0) return the number of alias files loaded

Joined: Aug 2004
Posts: 7,252
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
That counts the number of files loaded in the Aliases section.
It doesn't count aliases that are scripted in the Remotes section

Joined: Feb 2003
Posts: 26
M
MRN Offline OP
Ameglian cow
OP Offline
Ameglian cow
M
Joined: Feb 2003
Posts: 26
Thanks for all replies (will read the thread after this reply), but what I was trying to script, was how many lines each alias in a script was.

Alias a contained 113 lines, but alias b containted 735 lines. Perhaps alias b could be split up in several aliases, and make the scriptfile become under the 64kb limit.

Although counting the lines is a bad idea, it gives the an idea. I should perhaps count the bytes instead...

I've never used /filter to be honest, and I wasn't thinking of @windows blush

Joined: Aug 2004
Posts: 7,252
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
First off, you'd need to determine the number of characters in each line, and then total them, so actually counting the number of lines is (next to, if not completely) useless.
Secondly: The 64k limit that you're referring to, isn't a literal file size limit, but rather the limit of the file size that can be edited using the Remote Editor.
Remote files can be created/edited using any text editor, as long as it's saved in DOS Text format (this is the default for programs like Notepad).
Files that are bigger than 64k can be loaded and used in mIRC, they just can't be edited using the Remote Editor without creating problems.

Joined: Feb 2003
Posts: 26
M
MRN Offline OP
Ameglian cow
OP Offline
Ameglian cow
M
Joined: Feb 2003
Posts: 26
I made my alias work! smile (Too long to post, it should be a kind of "spoiler" function here, as in some other boards)

@windows did the trick, and changing from counting lines to count bytes instead (or also) wasn't too hard.

But since the mIRC editor is flawed, do you pro scripters use an another editor?

Joined: Aug 2004
Posts: 7,252
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
Please clarify what you mean by
Quote:
But since the mIRC editor is flawed

I use the mIRC editor for most of my scripting, as you'd have to have a huge file to hit the 64k mark.

Joined: Jan 2003
Posts: 2,523
Q
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
The Editor can handle more than 64k, at least in a non-ini format; I have a 200kb .mrc file loaded and Editor saves it just fine.


/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
Joined: Dec 2002
Posts: 2,031
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Dec 2002
Posts: 2,031
Originally Posted By: qwerty
I have a 200kb .mrc loaded and Editor saves it just fine.


I have that+ in a few ini files and everything works fine also.

Joined: Aug 2004
Posts: 7,252
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
Sorry, folks... I forgot a 0 at the end of 64, meaning that the 64k should've been 640k. That was the maximum I was able to handle on a system that had 256M of ram. It may be higher with more ram. I'm not sure as I've split and redone the code that was 640k several times, and it'd be difficult to try to recombine them all into one code again.


Link Copied to Clipboard