[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
PATCH: simplifying regular expressions
From: |
Ben Elliston |
Subject: |
PATCH: simplifying regular expressions |
Date: |
Sun, 9 Dec 2018 21:16:58 +1100 |
User-agent: |
NeoMutt/20170609 (1.8.3) |
A lot of regular expressions in DejaGnu are complex for no good
reason. This is because the regexps are placed inside quotes ("..")
wich are processed before being passed to the relevant function (be it
'expect', 'regexp', 'regsub', etc). As long as the string is a
constant, it is possible to put the regexp in braces and eliminate one
additional level of backslash quoting. Here are a few examples from
lib/telnet.exp. As you can see, the regexps become quite a bit
clearer, even for these fairly simple cases.
Any objections if I go through and clean up a bunch of these?
Cheers,
Ben
@@ -119,7 +119,7 @@ proc telnet_open { hostname args } {
perror "telnet: need a password"
break
}
- -re "advance.*y/n.*\\?" {
+ -re {advance.*y/n.*\?} {
exp_send "n\n"
exp_continue
}
@@ -140,7 +140,7 @@ proc telnet_open { hostname args } {
sleep 20
exp_continue
}
- -re "Escape character is.*\\.\[\r\n\]" {
+ -re {Escape character is.*\.[\r\n]} {
if { $raw || [board_info $connhost exists dont_wait_for_prompt]
} {
set result 0
} else {
@@ -170,7 +170,7 @@ proc telnet_open { hostname args } {
warning "telnet: connection closed by foreign host."
break
}
- -re "\[\r\n\]+" {
+ -re {[\r\n]+} {
exp_continue
}
timeout {
@@ -227,11 +227,11 @@ proc telnet_binary { hostname } {
remote_send $hostname "toggle binary\n"
exp_continue
}
- -re "Negotiating binary.*\[\r\n\].*$" { }
+ -re {Negotiating binary.*[\r\n].*$} { }
-re "binary.*unknown argument.*telnet> *$" {
remote_send $hostname "mode character\n"
}
- -re "Already operating in binary.*\[\r\n\].*$" { }
+ -re {Already operating in binary.*[\r\n].*$} { }
timeout {
warning "Never got binary response from telnet."
}
signature.asc
Description: PGP signature
- PATCH: simplifying regular expressions,
Ben Elliston <=