From 874edd44fc41aff555b8cc39d91b6576095135df Mon Sep 17 00:00:00 2001 From: Ben Elliston Date: Wed, 12 Dec 2018 12:57:00 +1100 Subject: * config/gdb-comm.exp, config/gdb_stub.exp, config/vxworks.exp, lib/dg.exp, lib/ftp.exp, lib/kermit.exp, lib/rlogin.exp, lib/telnet.exp, runtest.exp, testsuite/lib/libsup.exp: Simplify some regular expressions in constant strings by placing them inside braces instead of quotes. This allows one level of backslash quoting to be removed. --- ChangeLog | 9 +++++++++ config/gdb-comm.exp | 20 ++++++++++---------- config/gdb_stub.exp | 4 ++-- config/vxworks.exp | 14 +++++++------- lib/dg.exp | 4 ++-- lib/ftp.exp | 2 +- lib/kermit.exp | 2 +- lib/rlogin.exp | 6 +++--- lib/telnet.exp | 10 +++++----- runtest.exp | 17 +++++++++-------- testsuite/lib/libsup.exp | 2 +- 11 files changed, 50 insertions(+), 40 deletions(-) diff --git a/ChangeLog b/ChangeLog index 6911c81..69a22dc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,14 @@ 2018-12-12 Ben Elliston + * config/gdb-comm.exp, config/gdb_stub.exp, config/vxworks.exp, + lib/dg.exp, lib/ftp.exp, lib/kermit.exp, lib/rlogin.exp, + lib/telnet.exp, runtest.exp, testsuite/lib/libsup.exp: Simplify + some regular expressions in constant strings by placing them + inside braces instead of quotes. This allows one level of + backslash quoting to be removed. + +2018-12-12 Ben Elliston + * doc/dejagnu.texi: Acknowledge contributions to the manual from others. diff --git a/config/gdb-comm.exp b/config/gdb-comm.exp index c9ef574..fca0bbb 100644 --- a/config/gdb-comm.exp +++ b/config/gdb-comm.exp @@ -86,7 +86,7 @@ proc gdb_comm_file_cmd { arg } { verbose "\t\tKilling previous program being debugged" exp_continue } - -re "Load new symbol table from \".*\".*y or n.*$" { + -re {Load new symbol table from ".*".*y or n.*$} { remote_send host "y\n" remote_expect host 60 { -re "Reading symbols from.*done.*$gdb_prompt $" { @@ -157,7 +157,7 @@ proc gdb_comm_start { dest } { # The variable gdb_prompt is a regexp which matches the gdb prompt. Set it # if it is not already set. if {![board_info $dest exists gdb_prompt]} then { - set gdb_prompt "\\(gdb\\)" + set gdb_prompt {\(gdb\)} } else { set gdb_prompt [board_info $dest gdb_prompt] } @@ -199,7 +199,7 @@ proc gdb_comm_add_breakpoint { function } { -re "Breakpoint.*$gdb_prompt $" { return "" } -re "Function.*not defined.*$gdb_prompt $" { return "undef" } -re "No symbol table.*$gdb_prompt $" { return "undef" } - -re ".*Make breakpoint pending.*\\\? \\(y or \\\[n\\\]\\) $" { + -re {.*Make breakpoint pending.*\? \(y or \[n\]\) $} { remote_send host "y\n" return "maybe" } @@ -225,7 +225,7 @@ proc quit_gdb { } { remote_send host "y\n" exp_continue } - -re ".*\[*\]\[*\]\[*\].*EXIT code" { } + -re {.*[*][*][*].*EXIT code} { } default { } } } @@ -285,11 +285,11 @@ proc gdb_comm_load { dest prog args } { set textoff [board_info $dest gdb_sect_offset] remote_send host "sect .text $textoff\n" remote_expect host 10 { - -re "(0x\[0-9a-z]+) - 0x\[0-9a-z\]+ is \\.data" { + -re {(0x[0-9a-z]+) - 0x[0-9a-z]+ is \.data} { set dataoff $expect_out(1,string) exp_continue } - -re "(0x\[0-9a-z\]+) - 0x\[0-9a-z\]+ is \\.bss" { + -re {(0x[0-9a-z]+) - 0x[0-9a-z]+ is \.bss} { set bssoff $expect_out(1,string) exp_continue } @@ -425,7 +425,7 @@ proc gdb_comm_load { dest prog args } { remote_send host "y\n" exp_continue } - -re "Continuing( at |\\.| with no signal\\.)\[^\r\n\]*\[\r\n\]" { + -re {Continuing( at |\.| with no signal\.)[^\r\n]*[\r\n]} { exp_continue } -re ".*Start it from the beginning?.*y or n.*" { @@ -434,14 +434,14 @@ proc gdb_comm_load { dest prog args } { -re ".*$gdb_prompt $" { remote_send host "signal 0\n" remote_expect host 10 { - -re "signal 0\[\r\n\]+" { exp_continue } - -re "Continuing(\\.| with no signal\\.)\[\r\n\]" {} + -re {signal 0[\r\n]+} { exp_continue } + -re {Continuing(\.| with no signal\.)[\r\n]} {} } } } exp_continue } - -re "(run\[\r\n\]*|)Starting program: \[^\r\n\]*\[\r\n\]" { + -re {(run[\r\n]*|)Starting program: [^\r\n]*[\r\n]} { exp_continue } -re "$gdb_prompt (signal 0|continue)\[\r\n\]+Continuing(\\.| with no signal\\.)\[\r\n\]" { diff --git a/config/gdb_stub.exp b/config/gdb_stub.exp index b0bf61c..6ad22a1 100644 --- a/config/gdb_stub.exp +++ b/config/gdb_stub.exp @@ -37,7 +37,7 @@ proc gdb_stub_init { dest args } { if {[board_info $dest exists gdb_prompt]} { set gdb_prompt [board_info $dest gdb_prompt] } else { - set gdb_prompt "\\(gdb\\)" + set gdb_prompt {\(gdb\)} } return 1 @@ -384,7 +384,7 @@ proc gdb_stub_start { dest } { remote_send host "jump relocd\n" exp_continue } - -re "Continuing at.*\[\r\n\]" { } + -re {Continuing at.*[\r\n]} { } default { return { "fail" "" } } diff --git a/config/vxworks.exp b/config/vxworks.exp index abf999d..b49a3f6 100644 --- a/config/vxworks.exp +++ b/config/vxworks.exp @@ -50,7 +50,7 @@ proc ${board}_init { dest } { set boot_mon 0 set boot_mon_prompt "VxWorks Boot" } - -re "\[0-9\]\[\r\n\]+ *\[0-9\]\[\r\n\]" { + -re {[0-9][\r\n]+ *[0-9][\r\n]} { remote_send $dest "\n" exp_continue } @@ -72,7 +72,7 @@ proc ${board}_init { dest } { } remote_send $dest "p\n" remote_expect $dest 20 { - -re "file name\[ \t\]+: (\[^ \r\n\]+)\[ \r\n\]+" { + -re {file name[ \t]+: ([^ \r\n]+)[ \r\n]+} { set curr_file $expect_out(1,string) exp_continue } @@ -88,11 +88,11 @@ proc ${board}_init { dest } { # Oh boy. remote_send $dest "c\n" remote_expect $dest 20 { - -re "file name\[ \t\]+:.*$" { + -re {file name[ \t]+:.*$} { remote_send $dest "$desired_kernel\n" exp_continue } - -re "\[a-z() \t\]+:.*$" { + -re {[a-z() \t]+:.*$} { remote_send $dest "\n" exp_continue } @@ -141,7 +141,7 @@ proc vxworks_exec { dest program pargs inp outp } { remote_send $dest "$program $pargs$suffix\n" # FIXME: The value 300 below should probably be a parameter passed in. remote_expect $dest 300 { - -re "\\\[VxWorks Boot\\\]:" { + -re {\[VxWorks Boot\]:} { remote_send $dest "@\n" sleep 20 exp_continue @@ -286,7 +286,7 @@ proc vxworks_ld { dest prog } { remote_send $dest "\n" remote_expect $dest 30 { -re ".*$shell_prompt $" { set x 20 } - -re "\\\[VxWorks Boot\\\]:" { + -re {\[VxWorks Boot\]:} { remote_send $dest "@\n" sleep 20 exp_continue @@ -382,7 +382,7 @@ proc vxworks_run { dest function pargs inp outp } { verbose "$function aborted" set result 1 } - -re "\[\r\n\]syntax error\[\r\n\]" { + -re {[\r\n]syntax error[\r\n]} { verbose "weirdness after task started" set result -1 } diff --git a/lib/dg.exp b/lib/dg.exp index 68c63a3..8ad8fd9 100644 --- a/lib/dg.exp +++ b/lib/dg.exp @@ -568,7 +568,7 @@ proc dg-runtest { testcases options default-extra-options } { # proc dg-trim-dirname { dir_name file_name } { set special_character "\[\?\+\-\.\(\)\$\|\]" - regsub -all -- $special_character $dir_name "\\\\&" dir_name + regsub -all -- $special_character $dir_name {\\&} dir_name regsub "^$dir_name/?" $file_name "" file_name return $file_name } @@ -843,7 +843,7 @@ proc dg-test { args } { # It would be a bit cumbersome though. if {${dg-final-code} ne ""} { - regsub -all "\\\\(\[{}\])" ${dg-final-code} "\\1" dg-final-code + regsub -all {\\([{}])} ${dg-final-code} {\1} dg-final-code # Note that the use of `args' here makes this a varargs proc. proc dg-final-proc { args } ${dg-final-code} verbose "Running dg-final tests." 3 diff --git a/lib/ftp.exp b/lib/ftp.exp index e1cc1a9..ad3d8e9 100644 --- a/lib/ftp.exp +++ b/lib/ftp.exp @@ -186,7 +186,7 @@ proc ftp_download {host localfile remotefile} { set loop 0 set remotefile "" } - -re "(^|\[\r\n\])150.*connection for (.*) \[(\]\[0-9.,\]+\\)\[\r\n\]" { + -re {(^|[\r\n])150.*connection for (.*) [(][0-9.,]+\)[\r\n]} { set remotefile $expect_out(2,string) exp_continue } diff --git a/lib/kermit.exp b/lib/kermit.exp index 6d06969..5630582 100644 --- a/lib/kermit.exp +++ b/lib/kermit.exp @@ -138,7 +138,7 @@ proc kermit_command {dest args} { } send -i $shell_id "c\r" expect { - -i $shell_id -re ".*other options.\[\r\n\]+" { } + -i $shell_id -re {.*other options.[\r\n]+} { } -i $shell_id timeout { perror "Unable to resume Kermit connection." return -1 diff --git a/lib/rlogin.exp b/lib/rlogin.exp index 30d2d1e..b16fcc2 100644 --- a/lib/rlogin.exp +++ b/lib/rlogin.exp @@ -70,7 +70,7 @@ proc rlogin_open { arg } { set result 0 break } - -re "TERM = .*\\)\[ ]*$" { + -re {TERM = .*\)[ ]*$} { send "dumb\r\n" expect { "Terminal type is*$" { @@ -143,8 +143,8 @@ proc rlogin_spawn { dest cmdline } { if { $shell_id ne "" && $shell_id > 0 } { remote_send $dest "echo k\r" remote_expect $dest 20 { - -re "\\(gdb\\)" { - set shell_prompt "\\(gdb\\)" + -re {\(gdb\)} { + set shell_prompt {\(gdb\)} # gdb uses 'shell command'. set prefix "shell " set ok 1 diff --git a/lib/telnet.exp b/lib/telnet.exp index 219684a..abb7db0 100644 --- a/lib/telnet.exp +++ b/lib/telnet.exp @@ -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." } diff --git a/runtest.exp b/runtest.exp index 0bfca7d..09ffcf0 100644 --- a/runtest.exp +++ b/runtest.exp @@ -1563,16 +1563,16 @@ proc process_target_variants { target_list } { set result {} foreach x $target_list { if {[regexp "\\(" $x]} { - regsub "^.*\\((\[^()\]*)\\)$" "$x" "\\1" variant_list - regsub "\\(\[^(\]*$" "$x" "" x + regsub {^.*\(([^()]*)\)$} $x {\1} variant_list + regsub {\([^(]*$} $x "" x set list [process_target_variants $x] set result {} foreach x $list { set result [concat $result [iterate_target_variants $x [split $variant_list ","]]] } } elseif {[regexp "\{" $x]} { - regsub "^.*\{(\[^\{\}\]*)\}$" "$x" "\\1" variant_list - regsub "\{\[^\{\]*$" "$x" "" x + regsub "^.*\{(\[^\{\}\]*)\}$" $x {\1} variant_list + regsub "\{\[^\{\]*$" $x "" x set list [process_target_variants $x] foreach x $list { foreach i [split $variant_list ","] { @@ -1639,11 +1639,12 @@ if {[info exists errorInfo]} { unset errorInfo } + # make sure we have only single path delimiters -regsub -all "\(\[^/\]\)//*" $srcdir "\\1/" srcdir -regsub -all "\(\[^/\]\)//*" $objdir "\\1/" objdir -regsub -all "\(\[^/\]\)//*" $testsuitedir "\\1/" testsuitedir -regsub -all "\(\[^/\]\)//*" $testbuilddir "\\1/" testbuilddir +regsub -all {([^/])//*} $srcdir {\1/} srcdir +regsub -all {([^/])//*} $objdir {\1/} objdir +regsub -all {([^/])//*} $testsuitedir {\1/} testsuitedir +regsub -all {([^/])//*} $testbuilddir {\1/} testbuilddir if {![info exists target_list]} { # Make sure there is at least one target machine. It's probably a Unix box, diff --git a/testsuite/lib/libsup.exp b/testsuite/lib/libsup.exp index 9512e5e..4d167e1 100644 --- a/testsuite/lib/libsup.exp +++ b/testsuite/lib/libsup.exp @@ -196,7 +196,7 @@ proc config_test { cmd true false msg } { } expect { - -re "Checking pattern*with*\[\r\n\]" { + -re {Checking pattern*with*[\r\n]} { exp_continue } -re "\r\n1\r\n" { -- cgit v1.1