-
TCL Scripting
Hi,
I want to ask someone to explain to me the syntax below. This syntax is a TCL script. And I want to modify it in order for it to work with my RADIUS Billing Server.
Code:
proc do_get_card_number {} {
global state
global account
global pin
global promptFlag
global count
global accountLen
global pinLen
global retryCnt
global prefix
global param1
global param2
set cardLen [expr $accountLen + $pinLen]
set param1(maxDigits) $cardLen
if {$count == 0} {
set ev [playPrompt param1 info [set prefix]_enter_card_num.au]
} else {
switch -regexp $promptFlag {
{1} {set ev [playPrompt param1 info [set prefix]_invalid_digits.au]}
{2} {set ev [playPrompt param1 info [set prefix]_auth_fail.au]}
{3} {set ev [playPrompt param1 info [set prefix]_no_card_entered.au]}
}
}
switch -regexp $ev {
{collect success} {set number $info(digits)
set numberlen [string length $number]
if {$numberlen == $cardLen} {
set account [ string range $number 0 [expr $accountLen -1]]
set pin [ string range $number $accountLen [expr $cardLen -1]]
set state do_first_authorize
} else {
incr count
set promptFlag 1
if {$count < $retryCnt} {
set state do_get_card_number
} else {
# no more tries
set ev [playPrompt param2 info [set prefix]_final.au]
set state end
}
}
}
{collect aborted} {set state do_get_card_number}
{collect fail} -
{collect timeout} {incr count
set promptFlag 3
if {$count < $retryCnt} {
set state do_get_card_number
} else {
set ev [playPrompt param2 info [set prefix]_final.au]
set state end
}
}
default {set state end}
}
return 0
}
proc do_first_authorize {} {
global state
global pin
global account
global count
global retryCnt
global promptFlag
global prefix
global param2
global amt
global returncode
set ev [authorize $account $pin "" [ani] info]
set returncode [getVariable radius returnCode]
switch -regexp $ev {
{authorized} {set amt [getVariable radius creditAmount]
set state do_get_dest
}
{authorization failed} {incr count
set promptFlag 2
if {$returncode == "Uknown variable name"} {
set ev [playPrompt param2 info [set prefix]_no_aaa.au]
set state end
return 0
}
if { $count < $retryCnt } {
set state do_get_card_number
} else {
set state do_first_authorize_fail
}
}
default {set state end}
}
return 0
}
-
What don't you understand?
-
Completely offtopic... I've looked at TCL a few times... And every time the same thought forms in my brain: That's gotta be one of, if not the, most horrible languages ever invented. That includes brainfok
Seriously, I'd rather code amsn in brainfok than in this piece of sht.
The forum filters out the bad words, so I had to do it like this.
-
Moved to tech (other post deleted)
-
Like [set prefix], $, expr, switch, and ev. what does it do ?
-
Tcl Tutorial
While you're working out what it does, you'll be learning how to change it to do what you want.