PATCH: simplifying regular expressions
Ben Elliston <[email protected]>
| Newsgroups | gmane.comp.sysutils.dejagnu.general |
|---|---|
| Message-ID | <[email protected]> |
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."
}
_______________________________________________
DejaGnu mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/dejagnu
signature.asc
(application/pgp-signature, 833 B)
-----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEFS8+rdM1/2KWERKFZ9rcPj90NkkFAlwM65kACgkQZ9rcPj90 Nkmjcg/8CjaSHp5itWx5f+XdcR0DR++wP4Xj6/KvqsOL4RFiITVoevd+Wkn0VmA/ +R7AmWHuCA19h1N4XPw464Gq+YbgmI45uBs0y/dPLJAeSX/R5D9SQMjsOA7dwi6q CJGE/W5JibIxfOjD1RzVtfbGqfFiw+sD6rI1h0GatQBwxWVY3HVb1EwwJebw2NRT IrzcQUcKqWaNTvEHeRo8IxxOCgr2ffUdeLP0un8Q2GiEtXK26u4Riv2Jd8mj7gcZ qrk0ayIlKVZAGnHSQ3DnEzqHlmbdMoN3uCeGx2gWAJWvA/TvXJ25uGOjw8Tb//bR jy5sgmyJoolQeHHlVcbYZtSPp9aoN8w8mm9Brn7RPXcwOWz5dgZ+NmNU7B24s1n+ qiDejok/1c0dxs6CiWGXD4X1eJ7JUrnyMNAMWsSahGavePP6a5o0N8jKEub4IUhU dDBUwo+QKXyTboNBSTNWyMbIbjw5aYcJLUqUaIP4//zMhMFQqqutLvRyjwtGHE/A LrXWm2ho1HoTM+jlhLuTe0wIIOw7hooMOURhNxX/Qy0R1QFis/xqUikA7jpCsiVI pDdofWOSPR/RW+NiXyDKwvULDjUi8VwDJ8EepNZo+JY8z1kggaQxJn+LFBXgpIOd 29Hwq0sKd0BDV0/BRNZKfWc/DGKvCJWyYH+hBFmgSQhyMYBETw8= =F0Hy -----END PGP SIGNATURE-----