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