msg_cmp.sh revision 1.1 1 #! /bin/sh
2 # $NetBSD: msg_cmp.sh,v 1.1 2019/06/11 13:01:14 martin Exp $
3
4 #-
5 # Copyright (c) 2019 The NetBSD Foundation, Inc.
6 # All rights reserved.
7 #
8 # This code is derived from software contributed to The NetBSD Foundation
9 # by David Laight.
10 #
11 # Redistribution and use in source and binary forms, with or without
12 # modification, are permitted provided that the following conditions
13 # are met:
14 # 1. Redistributions of source code must retain the above copyright
15 # notice, this list of conditions and the following disclaimer.
16 # 2. Redistributions in binary form must reproduce the above copyright
17 # notice, this list of conditions and the following disclaimer in the
18 # documentation and/or other materials provided with the distribution.
19 #
20 # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
21 # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22 # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
24 # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 # POSSIBILITY OF SUCH DAMAGE.
31 #
32
33
34 # Compare two (binary) sysinst msg files and report identical messages.
35 # Used to find untranslated strings.
36
37 usage()
38 {
39 echo "usage: msg_cmp.sh msg_defs.h file1 file2" >&2
40 exit 1
41 }
42
43 [ "$#" = 3 ] || usage
44
45 msg_defs=$1
46 msg_long="((msg)(long)"
47 close_paren=")"
48
49 TMP1=/tmp/mct1.$$
50 TMP2=/tmp/mct2.$$
51 inp1=$2
52 inp2=$3
53
54 # Read header file and set up map of message names to numbers
55
56 exec <$msg_defs || exit 2
57
58 while read define MSG_name number rest
59 do
60 [ -z "$number" -o -n "$rest" ] && continue
61 [ "$define" = "#define" ] || continue
62 name="${MSG_name#MSG_}"
63 [ "$name" = "${MSG_name}" ] && continue
64 msg_number="${number#$msg_long}"
65 [ "$msg_number" = "$number" ] && continue
66 msg_number="${msg_number%$close_paren}"
67
68 varname=MSGNAME_$msg_number
69 eval $varname=$name
70 done
71
72 # Make the sysinst binary message files usable with text tools
73 set -- $(tr '\000' '\n' < $inp1); off1=$(( $(( $2 + 2 )) \* 8 ))
74 set -- $(tr '\000' '\n' < $inp2); off2=$(( $(( $2 + 2 )) \* 8 ))
75 dd bs=1 skip=$off1 if=$inp1 2>/dev/null | tr '\n' '~' | tr '\000' '\n' > $TMP1
76 dd bs=1 skip=$off2 if=$inp2 2>/dev/null | tr '\n' '~' | tr '\000' '\n' > $TMP2
77
78 # Open both input files
79 exec 3< $TMP1
80 exec 4< $TMP2
81
82 # Compare lines
83 IFS=''
84 NUM=0
85 HDR="Messages identical to the english version:"
86
87 while
88 read -r l1 <&3 && read -r l2 <&4
89 do
90 NUM=$(( $NUM + 1 ))
91 if [ "$l1" != "$l2" ]; then
92 continue
93 fi
94 [ -z "$hdr_done" ] && hdr_done=1 && printf "%s\n" $HDR
95 varname=MSGNAME_$NUM
96 eval $( printf "msg=$%s" $varname )
97 printf "%s (%d):\t%s\n" $msg $NUM $l1
98 done
99
100 rm $TMP1 $TMP2
101
102