Sync usage with man page.
[netbsd-mini2440.git] / external / gpl2 / xcvs / dist / contrib / debug_check_log.sh
blobea5534468f5ad5be78b6b63ae718230ee4abcaaf
1 #!/bin/sh
3 # Copyright (C) 2000-2005 The Free Software Foundation, Inc.
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2, or (at your option)
8 # any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
16 # This program is intended to take a check.log file generated by a failed run of
17 # sanity.sh as input and run expr line by line on it. It seems a much easier
18 # way of spotting a single failed line in a 100 line test result.
22 # Contributed by Derek R. Price <derek.price@openavenue.com>
27 usage ()
29 echo "\
30 usage: $0 [-afh] [file...]
32 -a process alternate pattern
33 -f process first pattern (default)
34 -h print this text
36 file files to process (default = check.log)"
39 # Do a line by line match with expr
41 # INPUTS
42 # $1 = text file name
43 # $2 = pattern file name
44 expr_line_by_line ()
46 dcl_line=0
47 dcl_wrong=
48 # We are assuming a newline at the end of the file. The way sanity.sh
49 # uses echo to create the log message guarantees this newline and since
50 # expr ignores the last newline when the anchor is present anyhow, no
51 # information is being lost in the transition
52 while test $dcl_line -lt `wc -l <$1` -a $dcl_line -lt `wc -l <$2`; do
53 dcl_line=`expr $dcl_line + 1`
54 if test `sed -ne${dcl_line}p <$1 |wc -c` -eq 1 \
55 -a `sed -ne${dcl_line}p <$2 |wc -c` -eq 1; then
56 # This is a workaround for what I am calling a bug in GNU
57 # expr - it won't match the empty string to the empty
58 # string. In this case the assumption is that a single
59 # character is always a newline. Since we already checked
60 # for the end of the file, we know sed will echo the
61 # newline.
63 elif expr "`sed -ne${dcl_line}p <$1`" : \
64 "`sed -ne${dcl_line}p <$2`\$" >/dev/null; then
66 else
67 echo "$dcl_line: `sed -ne${dcl_line}p <$1`"
68 echo "$dcl_line: `sed -ne${dcl_line}p <$2`\$"
69 dcl_wrong="$dcl_wrong $dcl_line"
71 done
72 if test `wc -l <$1` -ne `wc -l <$2`; then
73 echo "output & pattern contain differing number of lines"
74 elif test -z "$dcl_wrong"; then
75 echo "no mismatched lines"
76 else
77 echo "mismatched lines: $dcl_wrong"
81 # Process a single check.log file
83 # INPUTS
84 # $1 = filename
85 process_check_log ()
87 # abort if we can't find any expressions
88 if grep '^\*\* got: $' <$1 >/dev/null; then
90 else
91 echo "WARNING: No expressions in file: $1" >&2
92 echo " Either not a check.log or sanity.sh exited for some other reason," >&2
93 echo " like bad exit status. Try tail." >&2
94 return
97 dcl_exprfiles=""
98 if grep '^\*\* or: $' <$1 >/dev/null; then
99 # file contains a second regex
100 if test $dcl_dofirst -eq 1; then
101 # get the first pattern
102 sed -ne '/^\*\* expected: $/,/^\*\* or: $/p' <$1 >/tmp/dcle$$
103 dcl_exprfiles="$dcl_exprfiles /tmp/dcle$$"
105 if test $dcl_doalternate -eq 1; then
106 # get the alternate pattern
107 sed -ne '/^\*\* or: $/,/^\*\* got: $/p' <$1 >/tmp/dclo$$
108 dcl_exprfiles="$dcl_exprfiles /tmp/dclo$$"
109 else
110 echo "WARNING: Ignoring alternate pattern in file: $1" >&2
112 else
113 # file doesn't contain a second regex
114 if test $dcl_dofirst = 1; then
115 # get the only pattern
116 sed -ne '/^\*\* expected: $/,/^\*\* got: $/p' <$1 >/tmp/dcle$$
117 dcl_exprfiles="$dcl_exprfiles /tmp/dcle$$"
119 if test $dcl_doalternate -eq 1; then
120 echo "WARNING: No alternate pattern in file: $1" >&2
124 # and get the actual output
125 sed -ne '/^\*\* got: $/,$p' <$1 >/tmp/dclg$$
126 sed -ne '1D
128 p' </tmp/dclg$$ >/tmp/dclh$$
129 mv /tmp/dclh$$ /tmp/dclg$$
131 # compare the output against each pattern requested
132 for dcl_f in $dcl_exprfiles; do
133 sed -ne '1D
135 p' <$dcl_f >/tmp/dclp$$
136 mv /tmp/dclp$$ $dcl_f
138 case $dcl_f in
139 /tmp/dcle*)
140 echo "********** $1 : Primary **********"
142 /tmp/dclo*)
143 echo "********** $1 : Alternate **********"
145 esac
147 expr_line_by_line /tmp/dclg$$ $dcl_f
149 rm $dcl_f
150 done
152 rm /tmp/dclg$$
156 ### MAIN
159 # set up defaults
160 dcl_doalternate=0
161 dcl_dofirst=0
163 # process options
164 while getopts afh arg; do
165 case $arg in
167 dcl_doalternate=1
170 dcl_dofirst=1
172 \?|h)
173 usage
174 exit 1
176 esac
177 done
179 # dispose of processed args
180 shift `expr $OPTIND - 1`
181 OPTIND=1
183 # set the default mode
184 if test $dcl_doalternate -eq 0; then
185 dcl_dofirst=1
188 # set default arg
189 if test $# -eq 0; then
190 if test -f src/check.log && test -r src/check.log; then
191 set src/check.log
192 else
193 set check.log
197 for file in "$@"; do
198 process_check_log $file;
199 done
201 exit 0