Warning: this is a htmlized version!
The original is across this link. |
####### # # E-scripts on Expect. # # Note 1: use the eev command (defined in eev.el) and the # ee alias (in my .zshrc) to execute parts of this file. # Executing this file as a whole makes no sense. # # Note 2: be VERY careful and make sure you understand what # you're doing. # # Note 3: If you use a shell other than zsh things like |& # and the for loops may not work. # # Note 4: I always run as root. # # Note 5: some parts are too old and don't work anymore. Some # never worked. # # Note 6: the definitions for the find-xxxfile commands are on my # .emacs. # # Note 7: if you see a strange command check my .zshrc -- it may # be defined there as a function or an alias. # # Note 8: the sections without dates are always older than the # sections with dates. # # This file is at <http://angg.twu.net/a/e/expect.e> # or at <http://angg.twu.net/e/expect.e.html>. # See also <http://angg.twu.net/emacs.html>, # <http://angg.twu.net/a/.emacs[.html]>, # <http://angg.twu.net/a/.zshrc[.html]>, # <http://angg.twu.net/escripts.html>, # and <http://angg.twu.net/>. # ####### (deb-view "~/SLINK/expect5.24") (find-slink "expect5.24") (find-slink "debhelper") (find-fline "/usr/doc/expect5.24/FAQ.gz") (find-fline "/usr/doc/expect5.24/examples/") ####### # # Expect source # 99oct08 # ####### pdsc /big/slinks2/dists/slink/main/source/interpreters/expect_5.28.1-1.dsc cd /usr/src/expect-5.28.1/ debian/rules binary |& tee odrb # (find-expfile "debian/rules" "make prefix=") # (find-expfile "Makefile") # (find-expfile "exp_command.c" 1216) # (find-expfile "exp_command.c" 3181) cd /usr/src/expect-5.28.1/ make prefix=run-tmp/usr includedir=run-tmp/usr/include \ SHORT_BINDIR=/usr/bin install |& tee om ####### # # Expect source # ####### pdsc /big/slinks2/dists/slink/main/source/interpreters/expect_5.28.1-1.dsc cd /usr/src/expect-5.28.1/ debian/rules binary |& tee odrb # Ele precisa de um bocado de coisa pra compilar... # Ele não compila! Se for culpa do environment, isso deve resolver: cd /usr/src/expect-5.28.1/ (typeset +x $(set + | grep '^[A-Za-z]') export TERM # make -p -f/dev/null.make |& tee om0 # debian/rules binary |& tee odrb # debian/rules CFLAGS=-Dsetpgrp=setpgid binary |& tee odrb debian/rules binary |& tee odrb ) cd /usr/src/expect-5.28.1/ make CC="gcc -O2 -g -D_REENTRANT" SONAME=libexpect5.24.so.1 |& tee om # (find-expfile "exp_command.c" 90) # define setpgrp setpgid /* Edrx */ # (find-expfile "odrb" "Error 1") # (find-expfile "exp_command.c" 1216) # (find-expfile "exp_command.c" 3181) cd /usr/src/expect-5.28.1/ agrep -n setpgrp $(find *) cd /usr/src/expect-5.28.1/ cd /usr/src/expect-5.28.1/ awk ' function prline(indent) { printf(("%4d: %" indent "s%s\n"), NR, "", $0) } /^#/ { if (/#if/) { prline(i); ++i; } else if (/#else/) { prline(i-1); } else if (/#endif/) { --i; prline(i);; } else prline(i); } ' < exp_command.c |& tee oaec # (find-node "(gawk)Action Overview") # (find-node "(gawk)User-defined") # (find-node "(gawk)Function Example") # (find-node "(gawk)String Functions") : In function `Exp_SpawnCmd': exp_command.c:1216: too many arguments to function `setpgrp' exp_command.c: In function `Exp_DisconnectCmd': exp_command.c:3181: too many arguments to function `setpgrp' make[1]: *** [exp_command.o] Error 1 ###### # # Expect variables # ###### # (eeman "expect" "expect_out") # (eeman "expect" 651) # (eeman "expect" "any_spawn_id") # (eeman "expect" "interact_out") # (eeman "expect" "send_slow") # (eeman "expect" "send_human") # (eeman "expect" 1624) ###### # # kibitz # ###### # (find-vldifile "expect5.24.list") # (find-fline "/usr/doc/expect5.24/examples/") cd /usr/doc/expect5.24/examples/ man2t kibitz.1 man2t /usr/doc/expect5.24/examples/kibitz.1 gzip -c9 < /usr/doc/expect5.24/examples/kibitz.1 > /usr/man/man1/kibitz.1.gz ln -sf /usr/doc/expect5.24/examples/kibitz /usr/bin/kibitz # (find-fline "/usr/doc/xterm/") cd /usr/doc/expect5.24/examples/ kibitz alex /usr/doc/expect5.24/examples/kibitz alex # (find-fline "/usr/doc/expect5.24/examples/kibitz") echo 'exec echo Olaaa! > /dev/tty5' | tclsh - pdsc /debian/dists/slink/main/source/utils/bsdmainutils_4.4.0.1.dsc # (find-fline "/usr/src/bsdmainutils-4.4.0.1/") # (find-fline "/usr/src/bsdmainutils-4.4.0.1/write.c") # (find-fline "/usr/src/bsdmainutils-4.4.0.1/mesg.c") tty # (eeman "1 tty") # (eeman "4 tty") man -a console man -a chvt man -a deallocvt usr/bin/mesg base/sysvinit ###### # # kibitz # ###### cd ~/EXPECT/ grep -v '^[ ]*#' mykibitz > mykibitz0 # (find-fline "~/EXPECT/mykibitz") # (find-fline "~/EXPECT/mykibitz0") # (eeman "expect" 1614) # (find-fline "~/.zshrc" "kibitz") ###### # # On doing my own kibitz # ###### # (eeman "expect" 736) # (find-fline "~/EXPECT/mykibitz") puts $argv if {$argv=="server"} { } puts "I'm the server." exec rm -fv /tmp/toserver catch [exec mkfifo /tmp/toserver] puts "pipefd: [set pipefd [open /tmp/toserver {RDONLY NONBLOCK}]]" puts "spawn pipe: [spawn -open $pipefd]" puts "pipesid: [set pipesid $spawn_id]" puts "" puts "shellpid: [set shellpid [spawn $env(SHELL)]]" puts "shellsid: [set shellsid $spawn_id]" set timeout -1 expect { -i $pipesid -re .+ { puts hello!} } puts fuck set spawn_id $shellsid expect { -re .+ { send_user -raw $expect_out(buffer) exp_continue } -i $user_spawn_id -re .+ { send $expect_out(buffer) exp_continue } } puts "Server happy! Bye." -i $pipesid -re .+ { send $expect_out(buffer) exp_continue } expect { timeout {send "abc \177d"; continue -expect} -re .+ {send_user -raw $expect_out(buffer); continue -expect} -i $user_spawn_id -re .+ {send $expect_out(buffer); continue -expect} } # interact: # (eeman "expect" 972) # (find-expfile "") # (find-expfile "exp_inter.c") # (find-expfile "exp_inter.c" "Exp_InteractCmd") # (find-fline "$S/http/expect.nist.gov/scripts/") # (find-fline "$S/http/expect.nist.gov/scripts/noidle") -re ".*" { puts "pipe input!" } puts [set z [spawn zsh]] puts $spawn_id set spawn_id $z interact "~~" { puts "tildes!" } interact { -output $shid "~~" { puts "tildes!" } -input $inid -re ".*" { puts "oba!" } } else { puts [set fout [open /tmp/toserver {WRONLY NONBLOCK}]] puts [set fout [open /tmp/fromserver {WRONLY NONBLOCK}]] puts "Client happy! Bye." } catch [exec mkfifo /tmp/fromserver] puts [exec rm -fv /tmp/fromserver] puts [exec ls -laF /tmp] # Esse fica bloqueado até o cliente abrir a conexão: # puts [set fout [open /tmp/fromserver {WRONLY}]] set idfs [open /tmp/fromserver r] puts "$idsh $idfs $idts" ##### # # expect using tcl/tk 7.6 # ##### pdsc /debian/dists/slink/main/source/interpreters/expect_5.28.1-1.dsc # (find-expfile "exp_main_exp.c") # (find-expfile "exp_main_sub.c") # (find-expfile "exp_main_tk.c") # (find-expfile "Makefile.in" "expectk: ") cd /usr/src/expect-5.28.1/ debian/rules binary |& tee odrb # (find-expfile "odrb") # (find-expfile "exp_command.c" 1216) # (find-expfile "exp_command.c" 3181) # (find-expfile "exp_command.E" "setpgrp(0,0)") # C-c C-p c-backward-conditional # C-c C-n c-forward-conditional lynx http://www.distributedobjects.com/portfolio/archives/patterns/discussion/msg03277.html gcc -D_REENTRANT -E \ -I. \ -I/usr/include/tcl8.0-int/generic \ -I/usr/include/tk8.0-int/generic \ -I/usr/X11R6/include \ -DEXP_VERSION=\"5.28.1\" \ -DSCRIPTDIR=\"/usr/lib/expect5.28\" \ -DEXECSCRIPTDIR=\"/usr/lib/expect5.28\" \ -DTCL_DEBUGGER \ -DDFLT_STTY="\"sane\"" exp_command.c > exp_command.E # (find-expfile "debian/rules") # (find-expfile "odrb") # (find-expfile "configure.in") # (find-expfile "configure") # (find-expfile "Dbgconfig.in") # (find-expfile "Dbgconfigure") Pgrep 'm/ckage: (expect5.24|tcl|tk[48])/' apti tcl7.6-dev tk4.2-dev # The following packages will be REMOVED: # expect5.24-dev tk8.0-dev tcl8.0-dev # The following NEW packages will be installed: # tk4.2-dev tcl7.6-dev ##### # # mail about recompiling expect # ##### email -s 'recompiling expect on Slink' debian-devel@lists.debian.org <<'---' (first question:) What do I need to do to recompile expect from the sources? I have the following packages installed, ii expect5.24 5.28.1-1 ii expect5.24-dev 5.28.1-1 ii tk4.2 4.2p2-7 ii tk8.0 8.0.4-2 ii tk8.0-dev 8.0.4-2 ii tcl7.6 7.6p2-7 ii tcl8.0 8.0.4-2 ii tcl8.0-dev 8.0.4-2 but when I unpack expect_5.28.1-1.dsc and run debian/rules binary the configure script gives this warning: checking for Tcl private headers... found in /usr/include/tcl8.0-int/generic checking type of library to build... both shared and unshared creating cache .././config.cache checking for Tcl configuration... configure: warning: Can't find Tcl configuration definitions Dbgconfigure: #: No such file or directory cp: ./Dbg504/tcldbgcf.h: No such file or directory and a bit later it fails when gcc'ing exp_command.c because gcc encounters a line with "setpgrp(0,0)" (wrong number of arguments!)... I remember vaguely not being able to recompile expect on hamm also... Now for the other questions, supposing that the answer to the first question is not trivial. * Shouldn't there be, in cases like this one, some kind of "README.debian.compiling" in the source package telling users what special steps they must take? * Is there a treasure trove of compilations tricks somewhere? * Is there a script to recompile all packages from a distribution? I know that only the maintainer can PGP-sign a package, but maybe there's something around that tests if all packages compile OK... * How do I make an expectk that uses Tcl7.6 and Tk4.2? * What happened to the idea of adding a "Source-Depends" field to .dscs? Do people really care about that, or is it being forgotten? Please excuse me if I'm sounding too harsh, and, yes, I do know how much work does it take to debianize certain packages. But one of my deepest beliefs is that the most important thing a user (!) must know (besides reading and writing and running man and info and emacs and strace) is how to unpack and recompile the source code of a package, and I don't think that many people here consider this as important as me. So I've been trying to do my work silently, lurking too much, posting too little and keeping my radicalism to myself. This posting is an exception... Eduardo Ochs edrx@inx.com.br http://www.mat.puc-rio.br/~edrx/ (<--perpetual mess). --- ###### # # Tuba on Tuba # ###### # (find-fline "/usr/lib/tcl8.0/") # (find-fline "/usr/lib/tk8.0/") # (find-vldifile "tk8.0.list") # (find-tubafile "") # (find-tubafile "tuba" ".tubarc") # (find-tubafile "tuba" "proc main ") # (find-tubafile "tuba_lib.tcl") # (find-fline "~/. ###### # # fifos # ###### # (find-fline "~/EXPECT/mykibitz0") # (find-fline "~/EXPECT/mykibitz0" "mkfifo $userinfile") # (find-node "(libc)FIFO Special Files") # (find-node "(fileutils)mkfifo invocation") ####### # # dejagnu # ####### apti dejagnu # (find-vldifile "dejagnu.list") # (find-fline "/usr/doc/dejagnu/") # (find-fline "/usr/lib/dejagnu/") pdsc /big/slinks1/dists/slink/main/source/devel/dejagnu_1.3-10.dsc # (find-node "(dejagnu)Top") Uma coisa que eu não tou entendendo. O expect sempre deixa todos os processinhos rodando, ou ele pode suspendê-los, como o shell? Aliás, o sigsusp é não-trapável? Qdz, um processo percebe quando é suspendido? Ele percebe quando é "dessuspendido", né? Ele precisa disso pra redesenhar a tela, como o emacs. Se os processos não são suspendidos então não tem sentido falar em job control, a não ser que o job control só determine o que vai parar na tela e que processo recebe o que o usuário tecla. O expect sabe mandar signals para os filhinhos? Como? Uma ferramenta que poderia deixar bem mais claro como é que o expect funciona: como eu acho que o cerne do expect é um enorme "select", algo que mostrasse tudo que entra e que sai nesse select. # (find-vldifile "tcl8.0-dev.list") # (find-fline "/usr/doc/tcl8.0-dev/") # (eeman "3tcl tclvars") set tcl_traceCompile 2 for i in $(grep /usr/man/man /var/lib/dpkg/info/tcl8.0-dev.list); do echo $i; zcat $i | grep auto_path done any_spawn_id error_spawn_id tty_spawn_id user_spawn_id exp_exec_library exp_library expect_library spawn_id spawn_out timeout ##### # # expect variables # ##### puts [info vars] puts [spawn cat] foreach var { any_spawn_id error_spawn_id tty_spawn_id user_spawn_id exp_exec_library exp_library expect_library spawn_id timeout } { catch { puts "$var: [set $var]" } } puts "spawn_out(): [array get spawn_out]" diald exmh dejagnu ###### # # http://expect.nist.gov/scripts/ # ###### # (find-fline "$S/http/expect.nist.gov/scripts/") # (find-fline "~/EXPECT/dialer") ###### # # http://expect.nist.gov/doc/ # ###### # (find-fline "$S/http/expect.nist.gov/doc/") # (find-fline "$S/http/expect.nist.gov/doc/regress-talk.ps" "csh") cd $S/http/expect.nist.gov/doc/ pstotext regress.ps > /tmp/regress.txt pstotext -landscape regress-talk.ps > /tmp/regress-talk.txt pstotext scripts.ps > /tmp/scripts.txt # (find-fline "/tmp/") ##### # # http://expect.nist.gov/doc/regress.ps: listings # ##### set password [lindex $argv 2] spawn passwd [lindex $argv 1] expect "password:" send "$password\r" expect "password:" send "$password\r" expect eof # Listing 1: Non-interactive passwd script. First argument is # username. Second argument is new password. ################ expect_after { eof {exit [expr 10+$question]} timeout {exit [expr 20+$question]} } set question 0 proc test {args} { uplevel {incr question} eval [concat expect $args] } spawn passwd [lindex $argv 1] test { "No such user" {exit 1} "New password:" } send "[lindex $argv 2]\r" test { "Password too long" {exit 2} "Password too short" {exit 3} "Retype new password:" } send "[lindex $argv 3]\r" test { "Mismatch - password unchanged" {exit 4} "^\r\n$" } test { "*" {exit 5} eof } # Listing 2: Non-interactive passwd script with various tests for # behavior at boundary conditions. ################ passwd.exp bogus - - 1 passwd.exp fred abledabl abledabl 0 passwd.exp fred abcdefghijklm - 3 passwd.exp fred abc - 2 passwd.exp fred foobar bar 4 passwd.exp fred ^C - 11 # Listing 3: Example data file for testing passwd. ################ spawn csh ;# this is a comment expect "$prompt" ;# assume prompt is set already send "sleep 10\r" ;# run sleep command for 10 secs exec sleep 1 ;# give time to let sleep begin send "\cZ" ;# suspend it exec sleep 10 ;# wait for 10 seconds send "fg\r" ;# let sleep resume set timeout 5 ;# timeout expect after 5 secs expect "*$prompt" {print "control-Z stopped sleep's clock\n"} timeout {print "control-Z didn't stop sleep's clock\n"} # Listing 4: Test whether sleep counts time while suspended. ################ spawn csh expect $prompt for {set i 0} {1} {incr i} { send "a" expect { "\cG" break timeout break "a" } } print "driver accepted $i chars\n" # Listing 5: Determine longest input line acceptable to terminal # driver while in canonical mode. ################ spawn ... initialize for {} {1} {} { punish ;# punishing procedure defined elsewhere interact X ;# pass control to user } # Listing 6: Run application through a set of punishing interactions, # then let user interact. Repeat indefinitely. ################ spawn csh; set csh1 spawn_id spawn csh; set csh2 spawn_id send -i $csh1 "send tty\r" expect -i $csh1 -re "(/.*)\r" send -i $csh2 "send write $env(USER) $expect(1,string)\r" expect -i $csh1 -re "Message from .*" # Listing 7: Beginning of a script to start two processes that # interact with each other -- in this case, via write. ################ set csh [spawn csh] set cshnew [spawn csh.new] while {-1!=[gets stdin input]} { send -i $csh $input send -i $cshnew $input expect -i $csh -re ".+\r\n" set output $expect_out(buffer) expect -i $csh $output if ![string match output $expect_out(buffer)] { send_user "detected discrepancy on input $input\n" send_user "original csh output $output\n" send_user "new csh output $expect_out(buffer)\n" interact } } # Listing 8: Run two shells simultaneously from the same input, # stopping when there is a difference in their output. ################ ##### # # modem # ##### (defun eex-bounded () (interactive) (ee-strbounded 'eex "\n%*\n" "\n%*\n")) (global-set-key [f3] 'eex-bounded) # (find-fline "~/EXPECT/") # (find-fline "~/EXPECT/dialer") # (find-fline "~/EXPECT/dialer" "-open") # (find-node "(sh-utils)stty invocation") %* proc Exec {args} { puts $args puts -nonewline [eval exec $args] } set port /dev/ttyS2 Exec stty 115200 raw -echo < $port > $port Exec rm -fv /var/lock/LCK..ttyS2 /var/lock/LCK.004.066 spawn -noecho -open [open $port {RDWR NONBLOCK}] interact { "~~" return -o "Strike a key when ready . . .\r\n" {send "\n"} } %* %* proc Exec {args} { puts $args puts -nonewline [eval exec $args] } set port /dev/ttyS2 Exec stty 115200 raw -echo < $port > $port Exec rm -fv /var/lock/LCK..ttyS2 /var/lock/LCK.004.066 spawn -noecho -open [open $port {RDWR NONBLOCK}] puts yeah send {at$} expect "OK" %* expect_before "Strike a key when ready . . .\r\n" {send "\n"; exp_continue} send "at$" puts yeah expect "OK" {puts -nonewline OK} puts yeah %* (defun eexm-bounded () (interactive) (ee-strbounded 'write-ee "\n%*\n" "\n%*\n" "#!/usr/bin/expect proc Exec {args} { puts $args; puts -nonewline [eval exec $args] } set port /dev/modem exec stty 115200 raw -echo < $port > $port spawn -noecho -open [open $port {RDWR NONBLOCK}] set strike \"Strike a key when ready . . .\\r\\n\" \n" "\n" "$EET" "0777")) (global-set-key [f3] 'eexm-bounded) %* interact { "~~" return -o $strike {send "\n"} } %* %* proc expok {} { global strike expect { $strike { send "\n"; exp_continue } OK {} } } send "at$\r" expok %* %* set timeout 1 proc expok {} { global strike expect { $strike { send "\n"; exp_continue } OK { send {} } } } foreach command $argv { send "$command\r" expok } sleep 0.05 %* eet 'at$' 'at&$' 'atd$' 'ats$' # (find-fline "~/EXPECT/modem") %* set strike "Strike a key when ready . . .\r\n" proc expok {} { global strike interact { -o $strike { send "\r" } OK { send_user OK; return } } } send "at$\r" expok %* strace -q -f -o ~/s $EET close on exec "/etc/nsswitch.conf" ##### # # Simplifying the curses codes # ##### # (find-fline "/usr/doc/ncurses-base/") # (find-fline "/usr/doc/ncurses-bin/") # (find-fline "/usr/doc/ncurses-term/") # (find-vldifile "ncurses-base.list") # (find-vldifile "ncurses-bin.list") # (find-vldifile "ncurses-term.list") # See: Exploring Expect, p. 450; # (eeman "5 terminfo") # (eeman "5 termcap") # (eeman "captoinfo") # (eeman "console_codes") # (find-fline "/etc/terminfo/l/linux") pdsc /big/slinks2/dists/slink/main/source/libs/ncurses_4.2-3.dsc # (code-c-d "ncurses" "/usr/src/ncurses-4.2/") # (find-ncursesfile "misc/terminfo.src") # (find-ncursesfile "misc/terminfo.src" "linux|linux console") # (find-ncursesfile "misc/terminfo.src" "klone+sgr") # (find-ncursesfile "misc/terminfo.src" "ecma+color") # Esse bloquinho não funciona, mas o que vem depois funciona. set env(TERM) "ezork" set env(TERMCAP) {ezork: clr:^L: do:^J: cr:^M: csr:\E[%i%p1%d;%p2%dr: cm:\E[%d;%dH: } exec captoinfo exit # Esse aqui tá ok, mas ele não faz o que eu queria. set file [open /tmp/ezork.src w] puts $file {ezork|Test for groking Zork output, ind=\n, cr=\r, clear=\f, cup=\E[%p1%d;%p2%dH, csr=, } # cup=\E[%p1%d;%p2%dH, # csr=\E[%p1%d;%p2%dr, close $file set env(TERMINFO) /tmp exec tic /tmp/ezork.src set env(TERM) ezork # Esse bloco é o que funciona mais, mas o scroll dele é meio bobo. if {0} { # (find-ncursesfile "misc/terminfo.src" "linux|linux console") # (find-ncursesfile "misc/terminfo.src" "klone+sgr") # (find-ncursesfile "misc/terminfo.src" "ecma+color") set file [open /tmp/ezork.src w] puts $file {ezork|Test for groking Zork output, ind=^J, cr=^M, nel=^M^J, cols#80, lines#50, ndscr, cup=\E[%i%p1%d;%p2%dH, csr=\E[%i%p1%d;%p2%dr, clear=\E[H\E[J, dl=\E[%p1%dM, } # cup=\E[%p1%d;%p2%dH, # csr=\E[%p1%d;%p2%dr, close $file set env(TERMINFO) /tmp exec tic /tmp/ezork.src set env(TERM) ezork } ##### # # expect 5.30 # ##### # (find-fline "/big/slinks2/dists/slink/main/source/interpreters/expect_5.28.1-1.diff.gz") ##### # # autoconf 2.13 # ##### psnedeb <<'---' 27453 dists/potato/main/source/devel/autoconf_2.13-12.diff.gz 814 dists/potato/main/source/devel/autoconf_2.13-12.dsc 443844 dists/potato/main/source/devel/autoconf_2.13.orig.tar.gz --- pdsc $SDEBIAN/dists/potato/main/source/devel/autoconf_2.13-12.dsc debian/rules binary |& tee odrb dpkg -i ~/SLINK/autoconf dpkg -i /usr/src/autoconf_2.13-12_all.deb