Added to repository.
authorbvassche <bvassche@d57e44dd-8a1f-0410-8b47-8ef2f437770f>
Sun, 25 Oct 2009 12:39:10 +0000 (12:39 +0000)
committerbvassche <bvassche@d57e44dd-8a1f-0410-8b47-8ef2f437770f>
Sun, 25 Oct 2009 12:39:10 +0000 (12:39 +0000)
git-svn-id: https://scst.svn.sourceforge.net/svnroot/scst/trunk@1274 d57e44dd-8a1f-0410-8b47-8ef2f437770f

scripts/filter-trace-entry-exit [new file with mode: 0755]

diff --git a/scripts/filter-trace-entry-exit b/scripts/filter-trace-entry-exit
new file mode 100755 (executable)
index 0000000..9aa07ed
--- /dev/null
@@ -0,0 +1,69 @@
+#!/usr/bin/gawk -f
+
+############################################################################
+#
+# Script for filtering TRACE_ENTRY(), TRACE_EXIT() and TRACE_EXIT_RES()
+# statements from a patch.
+#
+# Copyright (C) 2009 Bart Van Assche <bart.vanassche@gmail.com>
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation, version 2
+# of the License.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+############################################################################
+
+function categorize_line() {
+  is_blank = 0
+  is_trace_entry = 0
+  is_trace_exit = 0
+  if ($0 ~ "^+$")
+    is_blank = 1
+  else if ($0 ~ "^+\tTRACE_ENTRY\\(\\);$")
+    is_trace_exit = 1
+  else if ($0 ~ "^+\tTRACE_EXIT\\(\\);$" || $0 ~ "^+\tTRACE_EXIT_RES\\(.*\\);$")
+    is_trace_exit = 1
+}
+
+function print_conditionally() {
+  if (! previous_is_trace_entry                                  \
+      && ! (before_previous_is_trace_entry && previous_is_blank) \
+      && ! previous_is_trace_exit                                \
+      && ! (previous_is_blank && is_trace_exit))
+    print previous_line
+}
+
+function shift_state_variables() {
+  previous_line = $0
+  before_previous_is_blank       = previous_is_blank
+  before_previous_is_trace_entry = previous_is_trace_entry
+  before_previous_is_trace_exit  = previous_is_trace_exit
+  previous_is_blank              = is_blank
+  previous_is_trace_entry        = is_trace_entry
+  previous_is_trace_exit         = is_trace_exit
+}
+
+BEGIN {
+  previous_is_blank       = 0
+  previous_is_trace_entry = 0
+  previous_is_trace_exit  = 0
+  getline
+  categorize_line()
+  shift_state_variables()
+}
+
+{
+  categorize_line()
+  print_conditionally()
+  shift_state_variables()
+}
+
+END {
+  print_conditionally()
+}