Version 6 of Leam Hall

Updated 2002-01-08 18:15:48

Sorry, not much here. I realized I had made comments, and signed them with my initials, but never let anyone know who I was.

What passes for my web site (without any tcl there yet) is:

http://www.reuel.net

26 May 01 My 11th anniversary and I'm here. I've started a project, using a game as a tool to develop my programming skills. Miguel MS helped me work out some coordinate issues, and is also patiently explaining problem decomposition.

In the old RPG 'Traveller', [L1 ] you had a mechanism for space-merchanting. You could have your ship, buy stuff on one planet and sell it on another. You had to deal with crew salaries, maintenance, and capitol costs. Not to mention a big monthly payment on your ship.

27 May 01 Thanks to whomever provided the Traveller link--perfect!

As a tool to show program development, I'm putting the script on the wiki, while it's being written. People like Cameron Laird and Miguel Sofer are providing excellent assistance, and there's the hope that someone can learn from seeing the process.

Although I warn those of you who have delicate natures and treasure elegant code--beware! I am a beginning programmer, and this is pretty ugly stuff.

You have been warned!

Space Game

Another project is to answer the recurring question of "Which Tcl book should I buy?" There are several out there, and most are good. Here are my perceptions of the books I have personal experience with. My comments are very subjective, so let me know if you have any questions.

Informal Tcl Book Reviews

21 Jun 01

While loitering in the Tcl chat area, several people gave me ideas on how to improve the structure of the Space Game idea, so it is a better learing tool. Here are the thoughts so far.

 More explinations for tricky constructs like the foreach {X Y Z}
 Having a newbie to expert programmer conversation, explaining how and why.
 Keeping the code useable and easily readable.
 Reference other Wiki pages, like the man pages and "Beginning Tcl".

Personal grafitti page So I can post things for a very short time.

 #!/usr/local/bin/expect


 set timeout -1


 while { [ llength $argv ] > 0 } {
        set flag [ lindex $argv 0 ]
        switch -- $flag {
                "-t"    {
                        set user(target) [ lindex $argv 1 ]
                        set argv [ lrange $argv 2 end ]
                                }

                "-u"    {
                        set user(name) [ lindex $argv 1 ]
                        set argv [ lrange $argv 2 end ]
                                }

                "-h"    {
                   send_user "remote < -u username > \n"
                   send_user "< -t target > \n"
                   send_user "< -t target > \n"
                   send_user "< -t \" target list in double quotes \" > \n"
                   send_user "< -T target list file > \n"
                   send_user "< -h > for help info \n "
                      exit 0
                                }

                "-T"    {
                                set file [ lindex $argv 1 ]
                                set f [ open [ lindex $argv 1 ] r ]
                                while { [ gets $f line ] >= 0 } {
                                        foreach word $line {
                                        lappend user(target) $word
                                        }
                                        }
                                set argv [ lrange $argv 2 end ]
                                ;#send_user "$user(target) \n"
                                ;#exit 0
                                }
              default { break }

        }
 }


 if ![info exists prompt] {
        set prompt "(%|\\\$|#|>) "
 }

 if ![ info exists user(name) ] {
 send_user "What user should I serve as? "
 expect_user -re "(.*)\n"
 set user(name) $expect_out(1,string)
 send_user "\n"
 }

 if ![ info exists user(passwd) ] {
 stty -echo
 send_user "And please, the secret phrase for that name? "
 expect_user -re "(.*)\n"
 set user(passwd) $expect_out(1,string)
  send_user "\n"
 stty echo 
 }

 if ![info exists user(command) ] {
 send_user "Perhaps you would like me to do something for you? \n\t"
 expect_user -re "(.*)\n"
 set user(command) $expect_out(1,string)
 send_user "\n"
 }

 if ![ info exists user(target) ] {
 send_user "And where would you like me to run this errand? "
 expect_user -re "(.*)\n"
 set user(target) $expect_out(1,string)
 send_user "\n"
 }

 proc ping_test { target } {

 spawn ping $target

 while {1} {
 expect "Unreachable" {
        set good_host 0
        break
        } timeout {
        set good_host 0
        break
        } "alive" {
        set good_host 1
        break
        } default {
        set good_host 0
        break
        }
        } ;# while closeure

        return $good_host
 }


 set timeout 15


 foreach target $user(target) {
 ;#exp_internal 1 
 set good_host [ ping_test $target ]
 set bad_login 0
 set timeout 5

        if ($good_host) {

        spawn /usr/bin/telnet $target 
        set logged_in 0
        while {1} {
        set bad_login 0
                expect "login:" {
                send "$user(name)\r"
                } "ssword:" {
                send "$user(passwd)\r"
                } -re "$prompt" {
                set logged_in 1
                break
                } eof {
                set bad_login 1
                break
                } timeout {
                set bad_login 1
                close
                break
                } default {
                set bad_login 1
                break
                }
                } ;# while closure

                if ($bad_login) {
                continue
                }

                if (!$logged_in) {
                wait
                continue
                }
                send "\n\r"
                send "$user(command)\r"
                interact

        } ;# close if good_host

 } ;# while for foreach

here is the above without the while loop

 foreach target $user(target) {
    ;#exp_internal 1 
    set good_host [ ping_test $target ]
    set bad_login 0
    set timeout 5

    if ($good_host) {

        spawn /usr/bin/telnet $target 
        expect  {
            "login:" {
                send "$user(name)\r"
                exp_continue
            }
            "ssword:" {
                send "$user(passwd)\r"
                exp_continue
            }
            -re "$prompt" {
                send "\n\r"
                send "$user(command)\r"
                interact
            }
            eof {
               # fall thru to next host
            }
            timeout {
                close
                # fall thru to next host
            }
            default {
                # fall thru to next host
            }
        }

    } ;# close if good_host

 } ;# while for foreach