ncurses: Update to work without version tag.
[dragonfly.git] / contrib / ncurses / test / tracemunch
1 #!/usr/bin/perl -w
2 # $Id: tracemunch,v 1.3 2002/09/22 16:31:18 tom Exp $
3 ##############################################################################
4 # Copyright (c) 1998,2002 Free Software Foundation, Inc.                     #
5 #                                                                            #
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:                                                      #
13 #                                                                            #
14 # The above copyright notice and this permission notice shall be included in #
15 # all copies or substantial portions of the Software.                        #
16 #                                                                            #
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.                                                  #
24 #                                                                            #
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               #
28 # authorization.                                                             #
29 ##############################################################################
30 # tracemunch -- compactify ncurses trace logs
31 #
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.
35 #
36
37 $putattr="PutAttrChar\\('(.)' = 0x.., {A_NORMAL}\\) at \\(([0-9]+), ([0-9]+)\\)";
38 $waddnstr="waddnstr\\(0x([0-9a-f]+),\"([^\"]+)\",[0-9]+\\) called {A_NORMAL}";
39
40 $win_nums=0;
41
42 sub transaddr
43 {
44     $arg = $_[0];
45
46     $arg =~ s/$curscr/curscr/ if ($curscr);
47     $arg =~ s/$newscr/newscr/ if ($newscr);
48     $arg =~ s/$stdscr/stdscr/ if ($stdscr);
49     for $n (0..$#win_addr) {
50         $arg =~ s/$win_addr[$n]/window$n/ if $win_addr[$n];
51     }
52
53     return $arg;
54 }
55
56 while (<STDIN>)
57 {
58 CLASSIFY: {
59         # Transform window pointer addresses so it's easier to compare logs
60         $awaiting = "curscr" if ($_ =~ /creating curscr/);
61         $awaiting = "newscr" if ($_ =~ /creating newscr/);
62         $awaiting = "stdscr" if ($_ =~ /creating stdscr/);
63         if ($_ =~ /^create :window 0x([0-9a-f]+)/) {
64             $addr = "0x$1";
65             if ($awaiting eq "curscr") {
66                 $curscr = $addr;
67             } elsif ($awaiting eq "newscr") {
68                 $newscr = $addr;
69             } elsif ($awaiting eq "stdscr") {
70                 $stdscr = $addr;
71             } else {
72                 $win_addr[$win_nums] = $addr;
73                 $win_nums = $win_nums + 1;
74             }
75             $awaiting = "";
76         } elsif ($_ =~ /^\.\.\.deleted win=0x([0-9a-f]+)/) {
77             $addr = "0x$1";
78             if ($addr eq $curscr) {
79                 $curscr = "";
80             } elsif ($addr eq $newscr) {
81                 $newscr = "";
82             } elsif ($addr eq $stdscr) {
83                 $stdscr = "";
84             } else {
85                 for $n (0..$#win_addr) {
86                     if ($win_addr[$n] eq $addr) {
87                         $win_addr[$n] = "";
88                     }
89                 }
90             }
91         }
92
93         # Compactify runs of PutAttrChar calls (TR_CHARPUT)
94         if ($_ =~ /$putattr/)
95         {
96                 $putattr_chars = $1;
97                 $starty = $2;
98                 $startx = $3;
99                 while (<STDIN>)
100                 {
101                         if ($_ =~ /$putattr/) {
102                                 $putattr_chars .= $1;
103                         } else {
104                                 last;
105                         }
106                 }
107                 print "RUN of PutAttrChar()s: \"$putattr_chars\" from ${starty}, ${startx}\n";
108                 redo CLASSIFY;
109         }
110
111         # Compactify runs of waddnstr calls (TR_CALLS)
112         if ($_ =~ /$waddnstr/)
113         {
114                 $waddnstr_chars = $2;
115                 $winaddr = $1;
116                 while (<STDIN>)
117                 {
118                         if ($_ =~ /$waddnstr/ && $1 eq $winaddr) {
119                                 $waddnstr_chars .= $2;
120                         } else {
121                                 last;
122                         }
123                 }
124                 $winaddstr = &transaddr($winaddr);
125                 print "RUN of waddnstr()s: $winaddr, \"$waddnstr_chars\"\n";
126                 redo CLASSIFY;
127         }
128
129         # More transformations can go here
130
131         # Repeated runs of anything
132         $anyline = &transaddr($_);
133         $repeatcount = 1;
134         while (<STDIN>) {
135             if (&transaddr($_) eq $anyline) {
136                 $repeatcount++;
137             } else {
138                 last;
139             }
140         }
141         if ($repeatcount > 1) {
142                 print "${repeatcount} REPEATS OF $anyline";
143         } else {
144                 print $anyline
145         }
146         redo CLASSIFY if $_;
147
148         } # :CLASSIFY
149 }
150
151 # tracemunch ends here