Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Newbie and TCL script construct 1

Status
Not open for further replies.

madasafish

Technical User
Jul 18, 2006
78
0
0
TH

I am very new to TCL but am very familiar with shell scripting and currently looking at a system that is using TCL. I want to use functions/procedures in the TCL script but keep getting an error message that it cannot find "ssName". This is the very first function there will be more and am looking to "plug" in the new function code where I have marked it "Plugin here -->". Firstly the code below errors (why?) and secondly is my logic correct for adding new sections of code in the proc and thirdly....is there a better way of doing it.

Thanks in advance,

Madasafish

Code:
proc CheckPopUpMsg $ssName {
        if $ssName = "Pin_Protect_Res_704x480_51x655" {

        # If there is an image match to the pin protect screen
        # key in the pin
        if { [lindex $ret 0] == 0 } {

                # Press clear then key in pin
                ecp_stbcontrol any down;
                ecp_stbcontrol any left;
                ecp_stbcontrol any ok;
                ecp_stbcontrol any 1;
                ecp_stbcontrol any 2;
                ecp_stbcontrol any 3;
                ecp_stbcontrol any 4;
                ecp_stbcontrol any ok;
                }
        }
        Plugin here --> if $ssName = xyz 
}


# Main Prog
set channels [ecp_getchannels]
if {[llength $channels] == 0} {
        return -code error "No channels assigned. Cannot proceed."
}

foreach channel $channels {

        set ssName "Pin_Protect_Res_704x480_51x655"
        CheckPopUpMsg $ssName   #Call the function/procedure
        set ret [ecp_imagecompare 1.0 1.0 $ssName]
        ......
        ......etc, etc
 
Hi

[ul]
[li]Do [highlight #fcc]no[/highlight]t use [highlight #fcc]sigil[/highlight] on formal parameters in the [tt]proc[/tt] declaration.[/li]
[li]Enclose [tt]if[/tt] condition in [highlight #cfc]braces[/highlight] ( {} ).[/li]
[li]Use [highlight #ccf][tt]==[/tt][/highlight] for equality check.[/li]
[/ul]
Code:
[b]proc[/b] CheckPopUpMsg [highlight #fcc]ssName[/highlight] [teal]{[/teal]
        [b]if[/b] [highlight #cfc][teal]{[/teal][/highlight][navy]$ssName[/navy] [highlight #ccf][teal]==[/teal][/highlight] [green][i]"Pin_Protect_Res_704x480_51x655"[/i][/green][highlight #cfc][teal]}[/teal][/highlight] [teal]{[/teal]

        [teal]}[/teal]
[teal]}[/teal]

Feherke.
[link feherke.github.com/][/url]
 
Thank-you Ferherke

You corrections are have the program running - thank-you!

Would you be able to advise me on the correct TCL syntax to use given the above code to obtain the following equivalent in bash shell?

Code:
#!/bin/bash

proc()
{
case $1 in
        proc1)  echo "this is proc one"
                #more code here
                ;;
        proc2)  echo "this is proc two"
                #more code here
                ;;
        proc3)  echo "this is proc three"
                #more code here
                ;;
esac
}

for x in proc1 proc3 proc2
do
        proc $x
done

#Continue with more code here

As always, thanks in advance

Madasafish
 
Hi

Just to answer your question :
Code:
[b]proc[/b] proc [teal]{[/teal]something[teal]}[/teal] [teal]\[/teal]
[teal]{[/teal]
  [b]switch[/b] [navy]$something[/navy] [teal]{[/teal]
    proc1 [teal]{[/teal]
      [b]puts[/b] [green][i]"this is proc one"[/i][/green]
      [gray]# more code here[/gray]
    [teal]}[/teal]
    proc2 [teal]{[/teal]
      [b]puts[/b] [green][i]"this is proc two"[/i][/green]
      [gray]# more code here[/gray]
    [teal]}[/teal]
    proc3 [teal]{[/teal]
      [b]puts[/b] [green][i]"this is proc three"[/i][/green]
      [gray]# more code here[/gray]
    [teal]}[/teal]
  [teal]}[/teal]
[teal]}[/teal]

[b]foreach[/b] x [teal]{[/teal]proc1 proc3 proc2[teal]}[/teal] [teal]{[/teal]
  proc [navy]$x[/navy]
[teal]}[/teal]
( Of course, calling the procedure proc is a bad idea. However it is allowed in Tcl. But be aware that the original [tt]proc[/tt] command was overwritten and you can not define more procedures later. )

But I would try to solve it as possible without the [tt]switch[/tt]. Ho idea how, hardly depends on what is your "more code here".


Feherke.
[link feherke.github.com/][/url]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top