9aa07eda0a52a07b0417f747e9ac2cb7fb09370d
[mirror/scst/.git] / scripts / filter-trace-entry-exit
1 #!/usr/bin/gawk -f
2
3 ############################################################################
4 #
5 # Script for filtering TRACE_ENTRY(), TRACE_EXIT() and TRACE_EXIT_RES()
6 # statements from a patch.
7 #
8 # Copyright (C) 2009 Bart Van Assche <bart.vanassche@gmail.com>
9 #
10 # This program is free software; you can redistribute it and/or
11 # modify it under the terms of the GNU General Public License
12 # as published by the Free Software Foundation, version 2
13 # of the License.
14 #
15 # This program is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 # GNU General Public License for more details.
19 #
20 ############################################################################
21
22 function categorize_line() {
23   is_blank = 0
24   is_trace_entry = 0
25   is_trace_exit = 0
26   if ($0 ~ "^+$")
27     is_blank = 1
28   else if ($0 ~ "^+\tTRACE_ENTRY\\(\\);$")
29     is_trace_exit = 1
30   else if ($0 ~ "^+\tTRACE_EXIT\\(\\);$" || $0 ~ "^+\tTRACE_EXIT_RES\\(.*\\);$")
31     is_trace_exit = 1
32 }
33
34 function print_conditionally() {
35   if (! previous_is_trace_entry                                  \
36       && ! (before_previous_is_trace_entry && previous_is_blank) \
37       && ! previous_is_trace_exit                                \
38       && ! (previous_is_blank && is_trace_exit))
39     print previous_line
40 }
41
42 function shift_state_variables() {
43   previous_line = $0
44   before_previous_is_blank       = previous_is_blank
45   before_previous_is_trace_entry = previous_is_trace_entry
46   before_previous_is_trace_exit  = previous_is_trace_exit
47   previous_is_blank              = is_blank
48   previous_is_trace_entry        = is_trace_entry
49   previous_is_trace_exit         = is_trace_exit
50 }
51
52 BEGIN {
53   previous_is_blank       = 0
54   previous_is_trace_entry = 0
55   previous_is_trace_exit  = 0
56   getline
57   categorize_line()
58   shift_state_variables()
59 }
60
61 {
62   categorize_line()
63   print_conditionally()
64   shift_state_variables()
65 }
66
67 END {
68   print_conditionally()
69 }