1#!/usr/bin/env perl 2# Copyright (C) 2013 Red Hat, Inc. 3# 4# Authors: 5# Markus Armbruster <armbru@redhat.com> 6# 7# This work is licensed under the terms of the GNU GPL, version 2 or 8# later. See the COPYING file in the top-level directory. 9 10# Usage: cleanup-trace-events.pl trace-events 11# 12# Print cleaned up trace-events to standard output. 13 14use warnings; 15use strict; 16 17my $buf = ''; 18my %seen = (); 19 20sub out { 21 print $buf; 22 $buf = ''; 23 %seen = (); 24} 25 26while (<>) { 27 if (/^(disable )?([a-z_0-9]+)\(/) { 28 open GREP, '-|', 'git', 'grep', '-lw', "trace_$2" 29 or die "run git grep: $!"; 30 my $fname; 31 while ($fname = <GREP>) { 32 chomp $fname; 33 next if $seen{$fname} || $fname eq 'trace-events'; 34 $seen{$fname} = 1; 35 $buf = "# $fname\n" . $buf; 36 } 37 unless (close GREP) { 38 die "close git grep: $!" 39 if $!; 40 next; 41 } 42 } elsif (/^# ([^ ]*\.[ch])$/) { 43 out; 44 next; 45 } elsif (!/^#|^$/) { 46 warn "unintelligible line"; 47 } 48 $buf .= $_; 49} 50 51out; 52