diff options
author | Ben Elliston <bje@gnu.org> | 2018-12-05 10:48:26 +1100 |
---|---|---|
committer | Ben Elliston <bje@gnu.org> | 2018-12-05 10:48:26 +1100 |
commit | d4a10385ee206e7ed40872b70040ce3b66a60e59 (patch) | |
tree | 527ce8a12ae68705b962beec623db965a85c8861 /lib | |
parent | 0d91a5aa03df4045cd87893e63156fd1469ecf77 (diff) | |
download | dejagnu-d4a10385ee206e7ed40872b70040ce3b66a60e59.zip dejagnu-d4a10385ee206e7ed40872b70040ce3b66a60e59.tar.gz dejagnu-d4a10385ee206e7ed40872b70040ce3b66a60e59.tar.bz2 |
* lib/utils.exp (grep): Handle -n.
* doc/dejagnu.texi (grep procedure): Document it.
* testsuite/runtest.all/utils.test: Add a test case.
* NEWS: Add an item.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/utils.exp | 29 |
1 files changed, 16 insertions, 13 deletions
diff --git a/lib/utils.exp b/lib/utils.exp index 0bc759f..30f61fa 100644 --- a/lib/utils.exp +++ b/lib/utils.exp @@ -201,27 +201,30 @@ proc which { file } { # Looks for occurrences of a string in a file. # return:list of lines that matched or empty string if none match. -# args: first arg is the filename, -# second is the pattern, -# third are any options. -# Options: line - puts line numbers of match in list -# +# args: first arg is optional (e.g. -n) +# second is the filename, +# third is the pattern, +# fourth is any keyword options (e.g. line) +# options: +# -n - include line numbers like grep(1) +# line - synonum for -n + proc grep { args } { + set options "" + if { [lindex $args 0] == "-n" } { + append options "line " + set args [lrange $args 1 end] + } set file [lindex $args 0] set pattern [lindex $args 1] verbose "Grepping $file for the pattern \"$pattern\"" 3 - set argc [llength $args] - if { $argc > 2 } { - for { set i 2 } { $i < $argc } { incr i } { - append options [lindex $args $i] - append options " " - } - } else { - set options "" + if { [llength $args] > 2 } { + append options [join [lrange $args 2 end]] } + set options [lsort -unique $options] set i 0 set fd [open $file r] |