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