mIRC Home    About    Download    Register    News    Help

Print Thread
#140849 30/01/06 10:57 PM
Joined: Jun 2005
Posts: 127
H
HAMM3R Offline OP
Vogon poet
OP Offline
Vogon poet
H
Joined: Jun 2005
Posts: 127
Code:
alias count.aliases { 
  var %x = 1,%z = 0
  while (%x <= $lines($1)) {
    if ($gettok($read($1,%x),1,32) == alias) { inc %z }
    inc %x
  }
  return %z
}


$count.aliases(path\to\file.mrc) should return the number of aliases, but it doesnt. After some debugging ive noticed it's only gettting to the first 3 lines of the file, even though it has 80 some lines. Any ideas? Also, if anyone knows of a faster way to do this, please let me know. Thanks...

Austin


-- HAMM3R (aka: alhammer)
http://www.HAMM3R.net
#140850 30/01/06 11:09 PM
Joined: Feb 2004
Posts: 2,019
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2004
Posts: 2,019
Code:
alias count.aliases {
  if (!$isfile($1)) return No such file: $1
  filter -ff $+(",$1,") nul alias *
  return $filtered
}


Naturally, this looks only at non-aliases files, as in those where aliases must be prefixed with the word "alias".


Gone.
#140851 30/01/06 11:22 PM
Joined: Jun 2005
Posts: 127
H
HAMM3R Offline OP
Vogon poet
OP Offline
Vogon poet
H
Joined: Jun 2005
Posts: 127
Ahh. I haven't really used the filter command before. Thanks Fiber. Im going to read up on filter as it seems to be a very usefull command. Again, thanks!

Edit: How would i adapt this to return the alias name ($2 in the line) rather than the number of total aliases? Something like a comma seperated list (join,part,hop,quit). It's just an idea, not vital at all. Thanks.

Last edited by HAMM3R; 30/01/06 11:28 PM.

-- HAMM3R (aka: alhammer)
http://www.HAMM3R.net
#140852 30/01/06 11:57 PM
Joined: Feb 2004
Posts: 2,019
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2004
Posts: 2,019
Code:
alias count.aliases {
  if (!$isfile($1)) return
  set -u %count.aliases 
  filter -fk $+(",$1,") _count.aliases alias *
  return $filtered - %count.aliases
}

alias -l _count.aliases {
  tokenize 32 $1
  var %alias = $iif($2 != -l,$2,$3)
  if ($len(%alias %count.aliases) < 920) {
    set -u %count.aliases $addtok(%count.aliases,%alias,44)
  }
}


It will discard any variable names when the length of the total list starts exceeding 920 characters. You wouldn't be able to return them if they exceed the string too long limit, there are of course ways to store those alias names in a binvar or something, but that will probably confuse you. It also ignores doubles in the aliases names because of $addtok.

EDIT: Here's an example with binvars:

Code:
alias countaliases {
  if (!$isfile($1)) return No such file: $1
  bset -c &aliases 1 32
  filter -fk $+(",$1,") _countaliases alias *
  hadd -bm aliases $md5($1) &aliases
  return $filtered - $bvar(&aliases,1,920).text
}

alias _countaliases {
  tokenize 32 $1
  bset -t &aliases $calc(1+$bvar(&aliases,0)) $$iif($2 != -l,$2,$3) $+ ,
}


Example:

//echo -a $countaliases($mircdirown files\test.mrc)

Now hash table "aliases" will contain an item named $md5($mircdirown files\test.mrc) and to access the data without having to worry about the string too long limit, you can put it in a binvar like this:

//!.echo -q $hget(aliases,$md5($mircdirown files\test.mrc),&data) | echo -a Total bytes: $bvar(&data,0)

Which in term let's you retrieve chunks from this bvar with $bvar.

The reason I use $md5 is to get rid of spaces in your filepath, as you know hash table items must not contain spaces.

#140853 31/01/06 12:35 AM
Joined: Jun 2005
Posts: 127
H
HAMM3R Offline OP
Vogon poet
OP Offline
Vogon poet
H
Joined: Jun 2005
Posts: 127
Yet again you've produced exactly what I needed. A million thanks Fiber.


-- HAMM3R (aka: alhammer)
http://www.HAMM3R.net
#140854 31/01/06 12:44 AM
Joined: Sep 2005
Posts: 2,881
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,881
I'd take multiline comments into account.

#140855 31/01/06 12:46 AM
Joined: Feb 2004
Posts: 2,019
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2004
Posts: 2,019
I don't care enough. But feel free to add it smile


Gone.

Link Copied to Clipboard