aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlvaro Videla <[email protected]>2009-12-21 22:35:56 +0800
committerBjörn Gustavsson <[email protected]>2010-02-14 12:15:09 +0100
commit501b9236450bc1f38d3daf9d9f0dc60b72299d6c (patch)
tree3f2bc1d2d8ed00e0eb4e1d92846cce95402cb54e
parent2356f4e8c89b61b71d1afd88161b8418a47dde0b (diff)
downloadotp-501b9236450bc1f38d3daf9d9f0dc60b72299d6c.tar.gz
otp-501b9236450bc1f38d3daf9d9f0dc60b72299d6c.tar.bz2
otp-501b9236450bc1f38d3daf9d9f0dc60b72299d6c.zip
Modify rb:grep/1 to grep reports using the re module
-rw-r--r--lib/sasl/doc/src/rb.xml13
-rw-r--r--lib/sasl/src/rb.erl33
2 files changed, 33 insertions, 13 deletions
diff --git a/lib/sasl/doc/src/rb.xml b/lib/sasl/doc/src/rb.xml
index 5b49a7bced..810f7dca6b 100644
--- a/lib/sasl/doc/src/rb.xml
+++ b/lib/sasl/doc/src/rb.xml
@@ -46,17 +46,18 @@
<name>grep(RegExp)</name>
<fsummary>Search the reports for a regular expression</fsummary>
<type>
- <v>RegExp = string()</v>
+ <v>RegExp = string() | {string, Options} | mp(), {mp(), Options}</v>
</type>
<desc>
<p>All reports containing the regular expression <c>RegExp</c>
are printed.
</p>
- <p><c>RegExp</c> is a string containing the regular
- expression. Refer to the module <c>regexp</c> in the STDLIB
- reference manual
- for a definition of valid regular expressions. They are
- essentially the same as the UNIX command <c>egrep</c>.
+ <p><c>RegExp</c> can be a string containing the regular
+ expression; a tuple with the string and the options for
+ compilation; a compiled regular expression; a compiled
+ regular expression and the options for running it.
+ Refer to the module <c>re</c> and specially the function <c>re:run/3</c>
+ for a definition of valid regular expressions and options.
</p>
</desc>
</func>
diff --git a/lib/sasl/src/rb.erl b/lib/sasl/src/rb.erl
index 84b98537ae..05f1230dd1 100644
--- a/lib/sasl/src/rb.erl
+++ b/lib/sasl/src/rb.erl
@@ -90,7 +90,9 @@ help() ->
io:format("rb:list(Type) - list all reports of type Type~n"),
io:format(" currently supported types are:~n"),
print_types(),
- io:format("rb:grep(RegExp) - print reports containing RegExp~n"),
+ io:format("rb:grep(RegExp) - print reports containing RegExp.~n"),
+ io:format(" RegExp must be a valid argument for ~n"),
+ io:format(" the function re:run/2 or re:run/3.~n"),
io:format("rb:rescan() - rescans the report directory with same~n"),
io:format(" options.~n"),
io:format("rb:rescan(Options) - rescans the report directory with new~n"),
@@ -133,7 +135,6 @@ print_types() ->
io:format(" - progress~n"),
io:format(" - error~n").
-
init(Options) ->
process_flag(priority, low),
process_flag(trap_exit, true),
@@ -190,8 +191,13 @@ handle_call(show, _From, State) ->
{reply, ok, State#state{device = NewDevice}};
handle_call({grep, RegExp}, _From, State) ->
#state{dir = Dir, data = Data, device = Device, abort = Abort, log = Log} = State,
- NewDevice = print_grep_reports(Dir, Data, RegExp, Device, Abort, Log),
- {reply, ok, State#state{device = NewDevice}}.
+ try print_grep_reports(Dir, Data, RegExp, Device, Abort, Log) of
+ NewDevice ->
+ {reply, ok, State#state{device = NewDevice}}
+ catch
+ error:Error ->
+ {reply, {error, Error}, State}
+ end.
terminate(_Reason, #state{device = Device}) ->
close_device(Device).
@@ -622,15 +628,15 @@ check_rep(Fd, FilePosition, Device, RegExp, Number, Abort, Log) ->
case read_rep_msg(Fd, FilePosition) of
{Date, Msg} ->
MsgStr = lists:flatten(io_lib:format("~p",[Msg])),
- case regexp:match(MsgStr, RegExp) of
- {match, _, _} ->
+ case run_re(MsgStr, RegExp) of
+ match ->
io:format("Found match in report number ~w~n", [Number]),
case catch rb_format_supp:print(Date, Msg, Device) of
{'EXIT', _} ->
handle_bad_form(Date, Msg, Device, Abort, Log);
_ ->
{proceed,Device}
- end;
+ end;
_ ->
{proceed,Device}
end;
@@ -639,6 +645,19 @@ check_rep(Fd, FilePosition, Device, RegExp, Number, Abort, Log) ->
{proceed,Device}
end.
+run_re(Subject, {Regexp, Options}) ->
+ run_re(Subject, Regexp, Options);
+run_re(Subject, Regexp) ->
+ run_re(Subject, Regexp, []).
+
+run_re(Subject, Regexp, Options) ->
+ case re:run(Subject, Regexp, Options) of
+ nomatch ->
+ nomatch;
+ _ ->
+ match
+ end.
+
read_rep(Fd, FilePosition, Device, Abort, Log) ->
case read_rep_msg(Fd, FilePosition) of
{Date, Msg} ->