#!/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 # # 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() }