2 # $Id: tracemunch,v 1.6 2005/03/12 21:48:23 tom Exp $
3 ##############################################################################
4 # Copyright (c) 1998-2002,2005 Free Software Foundation, Inc. #
6 # Permission is hereby granted, free of charge, to any person obtaining a #
7 # copy of this software and associated documentation files (the "Software"), #
8 # to deal in the Software without restriction, including without limitation #
9 # the rights to use, copy, modify, merge, publish, distribute, distribute #
10 # with modifications, sublicense, and/or sell copies of the Software, and to #
11 # permit persons to whom the Software is furnished to do so, subject to the #
12 # following conditions: #
14 # The above copyright notice and this permission notice shall be included in #
15 # all copies or substantial portions of the Software. #
17 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR #
18 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, #
19 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL #
20 # THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER #
21 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING #
22 # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER #
23 # DEALINGS IN THE SOFTWARE. #
25 # Except as contained in this notice, the name(s) of the above copyright #
26 # holders shall not be used in advertising or otherwise to promote the sale, #
27 # use or other dealings in this Software without prior written #
29 ##############################################################################
30 # tracemunch -- compactify ncurses trace logs
32 # The error logs produced by ncurses with tracing enabled can be very tedious
33 # to wade through. This script helps by compacting runs of log lines that
34 # can be conveniently expressed as higher-level operations.
37 our $putattr="PutAttrChar\\({{ '(.)' = 0[0-7]+ }}\\) at \\(([0-9]+), ([0-9]+)\\)";
38 our $waddnstr="waddnstr\\(0x([0-9a-f]+),\"([^\"]+)\",[0-9]+\\) called {A_NORMAL}";
51 $arg =~ s/$curscr/curscr/g if ($curscr);
52 $arg =~ s/$newscr/newscr/g if ($newscr);
53 $arg =~ s/$stdscr/stdscr/g if ($stdscr);
54 for $n (0..$#win_addr) {
55 $arg =~ s/$win_addr[$n]/window$n/g if $win_addr[$n];
68 # Transform window pointer addresses so it's easier to compare logs
69 $awaiting = "curscr" if ($_ =~ /creating curscr/);
70 $awaiting = "newscr" if ($_ =~ /creating newscr/);
71 $awaiting = "stdscr" if ($_ =~ /creating stdscr/);
72 if ($_ =~ /^create :window 0x([0-9a-f]+)/) {
74 if ($awaiting eq "curscr") {
76 } elsif ($awaiting eq "newscr") {
78 } elsif ($awaiting eq "stdscr") {
81 $win_addr[$win_nums] = $addr;
82 $win_nums = $win_nums + 1;
85 } elsif ($_ =~ /^\.\.\.deleted win=0x([0-9a-f]+)/) {
88 if ($addr eq $curscr) {
90 } elsif ($addr eq $newscr) {
92 } elsif ($addr eq $stdscr) {
95 for $n (0..$#win_addr) {
96 if ($win_addr[$n] eq $addr) {
103 # Compactify runs of PutAttrChar calls (TR_CHARPUT)
104 if ($_ =~ /$putattr/)
106 my $putattr_chars = $1;
111 if ($_ =~ /$putattr/) {
112 $putattr_chars .= $1;
117 print "RUN of PutAttrChar()s: \"$putattr_chars\" from ${starty}, ${startx}\n";
121 # Compactify runs of waddnstr calls (TR_CALLS)
122 if ($_ =~ /$waddnstr/)
124 my $waddnstr_chars = $2;
128 if ($_ =~ /$waddnstr/ && $1 eq $winaddr) {
129 $waddnstr_chars .= $2;
134 my $winaddstr = &transaddr($winaddr);
135 print "RUN of waddnstr()s: $winaddr, \"$waddnstr_chars\"\n";
139 # More transformations can go here
141 # Repeated runs of anything
142 my $anyline = &transaddr($_);
145 if (&transaddr($_) eq $anyline) {
151 if ($repeatcount > 1) {
152 print "${repeatcount} REPEATS OF $anyline";
161 # tracemunch ends here