OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [insight/] [expect/] [example/] [expectd.proto] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 578 markom
#!/depot/tcl/src/expect/e --
2
# Description: Simple fragment to begin a telnet daemon
3
# For more information, see Chapter 17 of "Exploring Expect"
4
# Author: Don Libes, NIST
5
 
6
set IAC   "\xff"
7
set DONT  "\xfe"
8
set DO    "\xfd"
9
set WONT  "\xfc"
10
set WILL  "\xfb"
11
set SB    "\xfa"                ;# subnegotation begin
12
set SE    "\xf0"                ;# subnegotation end
13
set TTYPE "\x18"
14
set SGA   "\x03"
15
set ECHO  "\x01"
16
set SEND  "\x01"
17
 
18
send "$IAC$WILL$ECHO"
19
send "$IAC$WILL$SGA"
20
send "$IAC$DO$TTYPE"
21
 
22
remove_nulls 0
23
 
24
expect_before {
25
        -re "^$IAC$DO$ECHO" {
26
                # treat as acknowledgement and ignore
27
                exp_continue
28
        }
29
        -re "^$IAC$DO$SGA" {
30
                # treat as acknowledgement and ignore
31
                exp_continue
32
        }
33
        -re "^$IAC$DO\(.)" {
34
                # refuse anything else
35
                send_user "$IAC$WONT$expect_out(1,string)"
36
                exp_continue
37
        }
38
        -re "^$IAC$WILL$TTYPE" {
39
                # respond to acknowledgement
40
                send_user "$IAC$SB$TTYPE$SEND$IAC$SE"
41
                exp_continue
42
        }
43
        -re "^$IAC$WILL$SGA" {
44
                send_user "$IAC$DO$SGA"
45
                exp_continue
46
        }
47
        -re "^$IAC$WILL\(.)" {
48
                # refuse anything else
49
                send_user "$IAC$DONT$expect_out(1,string)"
50
                exp_continue
51
        }
52
        -re "^$IAC$SB$TTYPE" {
53
                expect_user null
54
                expect_user -re "(.*)$IAC$SE"
55
                set env(TERM) [string tolower $expect_out(1,string)]
56
                # no continue!
57
        }
58
        -re "^$IAC$WONT$TTYPE" {
59
                # treat as acknowledgement and ignore
60
                set env(TERM) vt100
61
                # no continue!
62
        }
63
}
64
 
65
# do negotations up to terminal type
66
# expect
67
 
68
##############################
69
# your code goes after this point here
70
 
71
# spawn something                       ;# typically spawn something
72
# expect ...                    ;# typically do some expects, sends, etc.
73
# send ...
74
# expect ...
75
# send ...
76
 
77
# expect_before                 ;# remove all protocol nonsense
78
 
79
# let user interact
80
# interact -re "\r" {send "\r"; expect_user \n {} null}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.