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