TCL Scripting

This is a discussion on TCL Scripting within the Tech Board forums, part of the Community Boards category; Hi, I want to ask someone to explain to me the syntax below. This syntax is a TCL script. And ...

  1. #1
    Registered User
    Join Date
    Aug 2009
    Posts
    2

    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
    }

  2. #2
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    What don't you understand?
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  3. #3
    Registered User
    Join Date
    Oct 2008
    Posts
    1,262
    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.

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,484
    Moved to tech (other post deleted)
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  5. #5
    Registered User
    Join Date
    Aug 2009
    Posts
    2
    Like [set prefix], $, expr, switch, and ev. what does it do ?

  6. #6
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,484
    Tcl Tutorial
    While you're working out what it does, you'll be learning how to change it to do what you want.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. cgi scripting using c
    By cmay in forum C Programming
    Replies: 18
    Last Post: 07-15-2009, 10:05 AM
  2. Reviving my old scripting language.
    By suzakugaiden in forum Game Programming
    Replies: 4
    Last Post: 06-15-2006, 03:02 PM
  3. Scripting
    By loopshot in forum Game Programming
    Replies: 2
    Last Post: 03-24-2006, 05:29 PM
  4. Free scripting library?
    By PsychoBrat in forum Windows Programming
    Replies: 3
    Last Post: 11-09-2002, 02:49 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21