07 Nov 10, 01:17AM
i made this new tool "switch" wich is used in c++, im trying to import some usefull functions, if you're not familiar with c++ look at some examples below the code.
ahh btw i had to make 3 diferent "case" types:
*case (for simple number matching "=").
*case_cmp (use it if you're comparing with another word or letter "strcmp").
*case_str (use it if you want to take a word or a letter of a string "strstr").
and also there is the "default" and "break", if none of the cases were found, default will be executed.
switch
examples of usage:
ahh btw i had to make 3 diferent "case" types:
*case (for simple number matching "=").
*case_cmp (use it if you're comparing with another word or letter "strcmp").
*case_str (use it if you want to take a word or a letter of a string "strstr").
and also there is the "default" and "break", if none of the cases were found, default will be executed.
switch
[SELECT ALL] Code:
//switch script by =SA=macm
alias switch [ switch1 = $arg1; st = 0; def = 0]
alias case [
cnumargs = $numargs;
switch2 = [];
if (= (strcmp (getalias (concatword "arg" $cnumargs)) "break") 1) [
loop f (- $cnumargs 1) [if (= $f 0) [] [f = (+ $f 1); add2alias_ switch2 (getalias (concatword "arg" $f))]]
][
loop f $cnumargs [if (= $f 0) [] [f = (+ $f 1); add2alias_ switch2 (getalias (concatword "arg" $f))]]
];
if (= (strcmp (getalias (concatword "arg" $cnumargs)) "break") 1) [
if (= (getalias (getalias switch1)) $arg1) [
switch2; def = 1] []
] [
if (= $st 0) [
if (= (getalias (getalias switch1)) $arg1) [
switch2; st = 1; def = 1
] []
] [switch2; def = 1]
]
]
alias case_cmp [
cnumargs = $numargs;
switch2 = [];
if (= (strcmp (getalias (concatword "arg" $cnumargs)) "break") 1) [
loop f (- $cnumargs 1) [if (= $f 0) [] [f = (+ $f 1); add2alias_ switch2 (getalias (concatword "arg" $f))]]
][
loop f $cnumargs [if (= $f 0) [] [f = (+ $f 1); add2alias_ switch2 (getalias (concatword "arg" $f))]]
];
if (= (strcmp (getalias (concatword "arg" $cnumargs)) "break") 1) [
if (= (strcmp (getalias (getalias switch1)) $arg1) 1) [
switch2; def = 1] []
] [
if (= $st 0) [if (= (strcmp (getalias (getalias switch1)) $arg1) 1) [
switch2; st = 1; def = 1] []
] [switch2; def = 1]]
]
alias case_str [
cnumargs = $numargs;
switch2 = [];
if (= (strcmp (getalias (concatword "arg" $cnumargs)) "break") 1) [
loop f (- $cnumargs 1) [if (= $f 0) [] [f = (+ $f 1); add2alias_ switch2 (getalias (concatword "arg" $f))]]
][
loop f $cnumargs [if (= $f 0) [] [f = (+ $f 1); add2alias_ switch2 (getalias (concatword "arg" $f))]]
];
if (= (strcmp (getalias (concatword "arg" $cnumargs)) "break") 1) [
if (= (strstr (getalias (getalias switch1)) $arg1) 1) [
switch2; def = 1] []
] [
if (= $st 0) [if (= (strstr (getalias (getalias switch1)) $arg1) 1) [
switch2; st = 1; def = 1] []
] [switch2; def = 1]]
]
alias default [
if (= $def 0) [
cnumargs = $numargs;
switch2 = [];
loop f $cnumargs [f = (+ $f 1); add2alias_ switch2 (getalias (concatword "arg" $f))];
switch2
] [
]
]
examples of usage:
[SELECT ALL] Code:
alias test [
switch x;
case 0 echo "zero"
case 1 echo "one"
case 2 echo "two"
case 3 echo "three"
default echo "error - i dont have that number"
]
if x=1 output = one two three (switching line)
if x=8 output = error - i dont have that number
alias test1 [
switch x;
case 0 echo "zero" break;
case 1 echo "one" break;
case 2 echo "two" break
case 3 echo "three" break
default echo "error - i dont have that number"
]
if x=2 output= two
if x=6 output= error - i dont have that number
alias test2 [
con = $conline
switch con
case_str test echo "you are testing" break;
case_str n echo "no" break;
case_cmp y echo "yes" break
default echo "wtf are you doing???"
]
if there is "test" word or "test" in a word (example: testing) in the last console line output= you are testing
if there is only the "y" letter in the last console line output= yes