Le dim 21/09/2003 à 10:18, Dimitrie O. Paun a écrit :
> On September 20, 2003 01:05 pm, Vincent Béron wrote:
> > What is needed is a parser to get at least the structure of the .rc
> > files, to identify the layout of the menus and the ID of the strings,
> > and then compare those between languages. Or something based on that
> > (removing quoted text and comments, then diff? That'd be possible in sh
> > probably).
> 
> I think a parser is a bit too fancy. And even if we compare the structure,
> we still can't tell if the strings are translated. What we need is a bit
> of help from the translator. They should include a meta comment in the
> first kilobyte stating what version of the master file they translated.
> 
> Something like this:
> 
> MASTER: [<lang>] <version>
> 
> The <lang> is the 2 letter code of the master language. It is optional,
> if not present it defaults to English (En).
> 
> The <version> is the CVS version of the translated file, like 1.25.

I think a combination of both is helpful. One in knowing what is
uptodate (the MASTER), and one knowing what is not (the attached script,
or a variation of).

It's not particularly fast (would need to be ported in Perl, where
hashtables exist, for example), but it gets the job done in knowing
which resources have the same structure as the master language. Missing
lines, menus, stringtables, etc. are also found and reported.

The ww file is needed because my csplit dies with a "Memory exhausted"
when used in a pipe following sed for commdlg, but not when used with
cat. I'm stomped on that one.

Ideally, it'd be integrated with Make.rules, so it knows where it is and
what are the rc files to check.

Comments (especially from those translating parts of Wine)?

Vincent
#!/bin/sh

# 0009 == English
MASTER_LANG="0009"
TOPDIR=../..
WRC=${TOPDIR}/tools/wrc/wrc
UNICODE=${TOPDIR}/libs/unicode
INCLUDE="-I. -I${TOPDIR}/include"
if [ -z "$1" ]; then
	RC_FILE=rsrc.rc
else
	RC_FILE="$1"
fi

LD_LIBRARY_PATH="${UNICODE}" ${WRC} --nostdinc ${INCLUDE} --debug=0x02 ${RC_FILE} |\
	grep -v "^Internal resource-tree dump:$" |\
	sed -e '/[[:space:]]L"/s/\([[:space:]]\)L"/\1"/' \
		-e '/[[:space:]]".*"/s/\([[:space:]]\)".*"/\1""/' \
		-e '/[[:space:]]"[^"]*$/ {
		:join
		N
		s/\n//
		t tj
		:tj
		s/".*"/""/
		t next
		b join
		}
		:next' >ww
cat ww |\
	csplit -k -q -n 4 -z - "/^Resource: /" "{*}"

unset LANG1
unset TYPE
unset LANGUAGES
NB_LANGUAGES=0
for FILE in xx????; do
	TYPE=`grep "^Resource: .*$" ${FILE} |\
		sed -e "s/^Resource: //"`
	case "${TYPE}" in
		"DIALOG"|"MENU"|"STRINGTABLE")
			LANG1=`grep "^LANGUAGE .*" ${FILE} |\
				sed -e "s/LANGUAGE \(.*\), .*$/\1/"`
			COUNTER1=0
			FOUND=0
			while [ ${COUNTER1} -lt ${NB_LANGUAGES} ]; do
				if [ "${LANGUAGES[${COUNTER1}]}" = "${LANG1}" ]; then
					FOUND=1
					break
				fi
				COUNTER1=$[${COUNTER1}+1]
			done
			if [ $FOUND -eq 0 ]; then
				LANGUAGES[${NB_LANGUAGES}]="${LANG1}"
				NB_LANGUAGES=$[${NB_LANGUAGES}+1]
			fi
			;;
	esac
done
unset LANG1
unset TYPE

for TYPE_TRAITE in DIALOG MENU STRINGTABLE; do
echo "${TYPE_TRAITE}:"

unset ID
unset LANG1
unset LANG2
unset MD5
unset MASTER
unset TYPE
NB=0
NB_MASTER=0
for FILE in xx????; do
	TYPE=`grep "^Resource: .*$" ${FILE} |\
		sed -e "s/^Resource: //"`
	case "${TYPE}" in
		"${TYPE_TRAITE}")
			ID[${NB}]=`grep "^Id: .*" ${FILE} |\
				sed -e "s/^Id: //"`
			LANG1[${NB}]=`grep "^LANGUAGE .*" ${FILE} |\
				sed -e "s/LANGUAGE \(.*\), .*$/\1/"`
			LANG2[${NB}]=`grep "^LANGUAGE .*" ${FILE} |\
				sed -e "s/LANGUAGE .*, \(.*\)$/\1/"`
			MD5[${NB}]=`grep -v "^Id: .*" ${FILE} |\
				grep -v "^LANGUAGE .*" |\
				md5sum`
			if [ "${LANG1[${NB}]}" = "${MASTER_LANG}" ]; then
				MASTER[${NB_MASTER}]=${NB}
				NB_MASTER=$[${NB_MASTER}+1]
			fi
			NB=$[${NB}+1]
			;;
		"DIALOG"|"MENU"|"STRINGTABLE")
			# Real treatment is elsewhere
			true
			;;
		"ACCELERATOR"|"BITMAP"|"CURSOR"|"GROUP_CURSOR"|"GROUP_ICON"|"ICON"|"MESSAGETABLE"|"VERSIONINFO")
			# No further treatment needed
			true
			;;
		*)
			echo "Ressource type unknown: ${TYPE}"
			exit 1
			;;
	esac
done

if [ ${NB} -ne 0 -a ${NB_MASTER} -eq 0 ]; then
	echo "Did not find the MASTER language for ${TYPE_TRAITE}s"
	exit 1
fi
COUNTER1=0
while [ ${COUNTER1} -lt ${NB_MASTER} ]; do
	COUNTER2=0
	while [ ${COUNTER2} -lt ${NB} ]; do
		if [ ${MASTER[${COUNTER1}]} -ne ${COUNTER2} ]; then
			if [ "${ID[${MASTER[${COUNTER1}]}]}" = "${ID[${COUNTER2}]}" ]; then
				if [ "${MD5[${MASTER[${COUNTER1}]}]}" != "${MD5[${COUNTER2}]}" ]; then
					echo "${MASTER[${COUNTER1}]} and ${COUNTER2}: Differences for ID ${ID[${COUNTER2}]} (language ${LANG1[${COUNTER2}]})"
				fi
			fi
		fi
		COUNTER2=$[${COUNTER2}+1]
	done
	COUNTER1=$[${COUNTER1}+1]
done
COUNTER1=0
while [ ${COUNTER1} -lt ${NB_MASTER} ]; do
	COUNTER2=0
	while [ ${COUNTER2} -lt ${NB_LANGUAGES} ]; do
		MATCHES[${COUNTER2}]=0
		COUNTER2=$[${COUNTER2}+1]
	done
	COUNTER2=0
	while [ ${COUNTER2} -lt ${NB} ]; do
		if [ "${ID[${MASTER[${COUNTER1}]}]}" = "${ID[${COUNTER2}]}" ]; then
			COUNTER3=0
			while [ ${COUNTER3} -lt ${NB_LANGUAGES} ]; do
				if [ "${LANG1[${COUNTER2}]}" = "${LANGUAGES[${COUNTER3}]}" ]; then
					break
				fi
				COUNTER3=$[${COUNTER3}+1]
			done
			MATCHES[${COUNTER3}]=1
		fi
		COUNTER2=$[${COUNTER2}+1]
	done
	COUNTER2=0
	while [ ${COUNTER2} -lt ${NB_LANGUAGES} ]; do
		if [ ${MATCHES[${COUNTER2}]} -eq 0 ]; then
			echo "${ID[${MASTER[${COUNTER1}]}]}: No equivalent for language ${LANGUAGES[${COUNTER2}]}"
		fi
		COUNTER2=$[${COUNTER2}+1]
	done
	COUNTER1=$[${COUNTER1}+1]
done

done

rm ww xx????

Reply via email to