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