/* Key: + = added. - = removed. * = changed. & = comment. Updates: - 30/10/2004 + $array_interpret alias, the arrays have built-in support for this alias, so you shouldn't need to use it but if you want to it's documented further down in the file. * You may now specify more than one array in /array_destroy. * You may now specify *arrayname(value) as an item for an array to point to another array, the value of the item in the array must contain ONLY the pointer, you cannot put a pointer in between strings. Example: &alias array_test { & array_set test2 hello hello world & array_set test pointer *test2(hello) & array_set test3 test *test(pointer) & array_set test3 test! testing & echo -a $array_search(test3,en,*test(pointer),1) & array_destroy test test2 test3 &} &The above alias is the equivalant to the following in older versions: &alias array_test { & array_set test2 hello hello world & array_set test pointer $array_get(test2,hello) & array_set test3 test $array_get(test,pointer) & array_set test3 test! testing & echo -a $array_search(test3,en,$array_get(test,pointer),1) & array_destroy test test2 test3 &} */ ;$array_count(array) ; ;This will show the amount of items in "array". alias array_count { if ($isid) { return $var($+(%,$1[*]),0) } } ;/array_destroy [array 2] [array n] [...] ; ;This will destroy the specified arrays. alias array_destroy { if (!$isid) { while ($0) { while ($var($1[*],1)) { unset $ifmatch } tokenize 32 $2- } } } ;/array_exec ; ;This will pass every item in the specified array to the specified alias. alias array_exec { if (!$isid) { var %i = 0 while ($array_interpret($array_get($1,%i))) { $2- $ifmatch inc %i } } } ;$array_get(array,n) ; ;This will get the "nth" item in "array". alias array_get { if ($isid) { return $array_interpret($eval($+(%,$1,[,$2,]),2)) } } ;$array_interpret(data) ; ;This is the support for pointers to other arrays, you probably won't need to use this. alias array_interpret { if ($isid) { if ($left($1,1) == *) { if ($array_get($mid($gettok($1,1,40),2),$gettok($gettok($1,2,40),1,41))) { return $ifmatch } } return $1 } } ;/array_list ; ;"123" means you can either use 1, 2 or 3. ; ;This will list information about every array. ; ;Method:1 will show the amount of items in each array. ;Method:2 will show the amount of items in each array, and the actual items in each array. ;Method:3 will show the size of each array. alias array_list { if (!$isid) { var %array, %i = 1, %method = $mid($1,$calc($pos($1,:) +1),1) if (%method == 1) { while ($var(*[*],%i)) { if (!$istok(%array,$gettok($var(*[*],%i),1,91),32)) { echo -a $gettok($var(*[*],%i),1,91) => $var($+($gettok($var(*[*],%i),1,91),[*]),0) %array = $addtok(%array,$gettok($var(*[*],%i),1,91),32) } inc %i } } elseif (%method == 2) { while ($var(*[*],%i)) { if (!$istok(%array,$gettok($var(*[*],%i),1,91),32)) { echo -a $gettok($var(*[*],%i),1,91) => $var($+($gettok($var(*[*],%i),1,91),[*]),0) var %g = 0 while ($array_get($remove($gettok($var(*[*],%i),1,91),%),%g)) { echo -a $str($chr(160),4) $+($gettok($var(*[*],%i),1,91),[,%g,]) => $array_interpret($eval($+(%,$remove($gettok($var(*[*],%i),1,91),%),[,%g,]),2)) inc %g } %array = $addtok(%array,$gettok($var(*[*],%i),1,91),32) } inc %i } } elseif (%method == 3) { while ($var(*[*],%i)) { var %bytes if (!$istok(%array,$gettok($var(*[*],%i),1,91),32)) { var %g = 0 while ($array_get($remove($gettok($var(*[*],%i),1,91),%),%g)) { inc %bytes $len($eval($+(%,$remove($gettok($var(*[*],%i),1,91),%),[,%g,]),2)) inc %g } echo -a $gettok($var(*[*],%i),1,91) => %bytes %array = $addtok(%array,$gettok($var(*[*],%i),1,91),32) } inc %i } } } } ;/array_merge [array 2|array 3|array N|....] ; ;Merges one or more arrays into a new array. alias array_merge { if (!$isid) { var %i = 1, %array while (%i <= $calc($gettok($1-,0,32) -1)) { var %g = 0 while ($array_interpret($array_get($gettok($1-,%i,32),%g))) { %array = $+(%array,$cr,$ifmatch) inc %g } inc %i } .echo -q $explode(%array,$cr,$gettok($1-,-1,32)) } } ;/array_pop ; ;Removes the last item from an array. alias array_pop { if (!$isid) { array_unset $1 $calc($array_count($1) -1) } } ;$array_rand(array) ; ;Returns a random item from "array". alias array_rand { if ($isid) { return $array_interpret($array_get($1,$rand(0,$array_count($1)))) } } ;/array_reverse ; ;This will reverse the specified array, for example: ; ;/array_reverse laughing ; ;%laughing[0] lol ;%laughing[1] lmao ;%laughing[2] rofl ;%laughing[3] roofles ; ;Will become: ; ;%laughing[0] roofles ;%laughing[1] rofl ;%laughing[2] lmao ;%laughing[3] lol alias array_reverse { if (!$isid) { var %i = 0 while (%i <= $array_count($1)) { var %array = $+(%array,$cr,$array_get($1,$calc($array_count($1) - %i))) inc %i } .echo -q $explode(%array,$cr,$1) } } ;$array_search(array,"enrsw",search string,n) ; ;Returns the "nth" match for "search string" in "array". ; ;"enrsw" means you can either use e, r, s or w (n can be used on it's own or with a flag). ; ;e means the search string is an exact match. ;n means the match will not be evaluated. ;r means the search string is a regular expression. ;s means the match must start with the search string (eg: $array_search(array,s,cat,1) will return the first match for "cat*" in "array", it would match "catalogue"). ;w means the search string is a wildcard match. alias array_search { if ($isid) { var %i = 1, %n = 0, %eval = $regex($2,/n/), %temp = $regex($2,/([ersw])/), %match var %flag = $regml(1) while ($var($1[*],%i)) { if (%flag == e) { if ($array_interpret($3) == $array_interpret($var($1[*],%i).value)) { inc %n %match = $array_interpret($3) } } elseif (%flag == r) { if ($regex($array_interpret($var($1[*],%i).value),$array_interpret($3))) { inc %n %match = $array_interpret($var($1[*],%i).value) } } elseif (%flag == s) { if ($array_interpret($3) $+ * iswm $array_interpret($var($1[*],%i).value)) { inc %n %match = $array_interpret($var($1[*],%i).value) } } elseif (%flag == w) { if ($array_interpret($3) iswm $array_interpret($var($1[*],%i).value)) { inc %n %match = $array_interpret($var($1[*],%i).value) } } if (%n == $4) && ($4 != 0) && (%match) { return $iif(!%eval,$eval(%match,2),%match) } elseif ($4 == 0) && (%i == $var($1[*],0)) { return %n } inc %i } } } ;/array_set ; ;This will add "data" into the "nth" item in an array. alias array_set { if (!$isid) { set $+(%,$1[,$2]) $3- } } ;/array_shift ; ;Removes the first item from an array. alias array_shift { if (!$isid) { array_unset $1 0 } } ;/array_show ; ;"123" means you can either use 1, 2 or 3. ; ;This will show information about an array. ; ;method:1 will show how many items are in the array. ;method:2 will show each item and its value in the array. ;method:3 will show the amount of bytes in an array. alias array_show { if (!$isid) { var %method = $mid($2,$calc($pos($2,:) +1),1) if (%method == 1) { echo -a $+(%,$1) => $array_count($1) } elseif (%method == 2) { var %i = 0 while ($array_get($1,%i)) { echo -a $+(%,$1[,%i,]) => $array_interpret($eval($+(%,$1[,%i,]),2)) inc %i } } elseif (%method == 3) { var %i = 0, %bytes while ($array_get($1,%i)) { inc %bytes $len($ifmatch) inc %i } echo -a $+(%,$1) => %bytes } } } ;/array_shuffle ; ;Shuffles an array. ;This may take a while if the array has 100 or more items. alias array_shuffle { if (!$isid) { var %item while ($gettok(%item,0,13) != $array_count($1)) { var %rand = $array_rand($1) if (!$istok(%item,%rand,32)) { var %item = $+(%item,$cr,%rand) } } .echo -q $explode(%item,$cr,$1) } } ;/array_sort ; ;Sorts an array in alphanumerical or numerical order. ;if you specify the optional r switch, then the sorting will be reversed. alias array_sort { if (!$isid) { .echo -q $implode($1,$cr,array_temp) .echo -q $explode($sorttok(%array_temp,13,$2),$cr,$1) unset %array_temp } } ;/array_unset ; ;Unsets the Nth item in array. alias array_unset { if (!$isid) { if ($eval($+(%,$1[,$2]),2)) { unset $+(%,$1[,$2]) var %i = 1 while ($var($1[*],%i)) { set $+(%,$1[,$calc(%i -1),]) $var($1[*],%i).value inc %i } unset $+(%,$1[,$calc($array_count($1) -1),]) } } } ;$explode(text,char,array) ; ;I can really only explain how this works by showing an example: ; ;.echo -q $explode(lol!lmao!rofl!roofles,!,laughing) ; ;The code above will create the following array: ; ;%laughing[0] lol ;%laughing[1] lmao ;%laughing[2] rofl ;%laughing[3] roofles ; ;It basically seperates "text" by "char", then adds each token to "array" ;It returns the amount of items added to "array", you can silence it by using .echo -q $explode() ; ;Note: exploding data into an array will destroy the specified array if it already exists. alias explode { if ($isid) { array_destroy $3 var %i = 1 while ($gettok($1,%i,$asc($2))) { set $+(%,$3[,$calc(%i - 1),]) $ifmatch inc %i } return $var($+(%,$3[*]),0) } } ;$implode(array,char,var) ; ;I can really only explain how this works by showing an example: ;The example presumes you have used the $explode() example above to create the "laughing" array. ; ;.echo -q $implode(laughing,!,laughing_variable) ; ;The code above will put the "laughing" array into the "%laughing_variable" variable with each item seperated by ! ; ;It basically puts each key from "array" into "var" seperated by "char". ;It returns the amount of items imported to "var" from "array", you can silence it by using .echo -q $implode() ; ;Note: imploding arrays into a variable will cause the old variable (if it existed) to be deleted. alias implode { if ($isid) { var %i = 0 while ($array_get($1,%i)) { set $+(%,$3) $+($eval($+(%,$3),2),$2,$ifmatch) inc %i } } }