Hash Access Alias
Posted by CrashB
Wednesday, May 26, 2004
Description: Manipulate hash tables in a more secure manner!
/*
HASH ACCESS
By: CrashB (crashb@hotpop.com)
http://crashb.kicks-ass.net/mirc.html
ABOUT:
The hash alias is basically an one-in-all alias used to manipulate hash tables.
It is useful for storing/changing hash data on the fly, saving it as you go. Why
would anyone want to do this you ask? Simply because mIRC can crash on occasion,
and when that happens, say bye-bye to all your loaded hash table info. Is that really
worth the very slight notice in speed loss, you might ask, and my answer is "yes, it
is."
I've used this alias all over the place, in one script to another. It works beautifully.
Most people unfamiliar with hash tables should be able to use this alias, as it only
requires very minimum knowledge of hash tables, if at all.
I strongly recommend that if you use this snippet, change the alias name "hash" to reflect the
alias themeing of your script. I.E. if you are naming all your aliases something like "tba_start"
and "tba_halt", then rename this alias to "tba_hash" and include it in the script (with this
usage info, might I add). This is because this alias references the file path to start in the
same directory your script is in. And the reason for this is, its a hell of a lot easier to
type users\username as the filename compared to $+(",$scriptdir,users\,username,.dat") everytime
you call the alias.
Please note that the filename cannot include spaces. Annoying, I know, but it was that or I couldn't
allow for data to include spaces... and that is just 100 times worse! Also, don't forget that
you can't use certain characters in your filenames, because Windows doesn't like them. And those
characters are: \ / : * ? " < > |
USAGE:
<> = required field
[] = optional field
/hash <filename> <item> <data>
This command stores the data in filename:item
$hash(<filename>,<item>).get
returns <data>
$hash(<filename>,<item>).del
returns <data> after deleting it
*** this was the easy way of deleting data, because I used $prop
$hash(<filename>,<N>).item
returns the Nth item in the filename
$hash(<filename>,<N>).data
returns the Nth data in the filename
$hash(<filename>,<matchtext>,<N>,[nwWrR]).ifind
searches through all the item fields in the filename and returns the Nth matching item
$hash(<filename>,<matchtext>,<N>,[nwWrR]).dfind
searches through all the data fields in the filename and returns the Nth matching data
n normal text comparison (default if nothing is specified)
w text is wildcard text
W hash table item/data is wildcard text
r text is regular expression
R hash table item/data is regular expression
*/
alias hash {
var %item $2
var %data $3-
var %file $+(",$scriptdir,$1,.dat")
var %return $null
var %save $null
if $hget(rax) != $null {
hfree hash.tmp
}
hmake hash.tmp
if $exists(%file) == $true {
hload iw_hash.tmp %file
}
if $prop == del {
var %return $hget(hash.tmp,[ %item ])
hdel hash.tmp %item
var %save 1
}
elseif $prop == get {
var %return $hget(hash.tmp,[ %item ])
}
elseif $prop == item {
var %return $hget(hash.tmp,[ %item ]).item
}
elseif $prop == data {
var %return $hget(hash.tmp,[ %item ]).data
}
elseif $prop == ifind {
var %return $hfind(hash.tmp,[ %item ],$3,$if($4 != $null,$4,n))
}
elseif $prop == dfind {
var %return $hfind(hash.tmp,[ %item ],$3,$if($4 != $null,$4,n)).data
}
else {
hadd hash.tmp %item %data
var %save 1
}
if %save == 1 {
hsave -o hash.tmp %file
}
hfree hash.tmp
return %return
}