#! /bin/sh
LANG=C
LANGUAGE=C
LC_ALL=C
export LANG LANGUAGE LC_ALL
AWK=${AWK-awk}
if [ $then echo "usage: $0 <xgettext> <package> <srcdir>"
exit 1
fi
xgettext=$1
package=$2
srcdir=$3
nl='
'
set -e
T=exg$$.d
mkdir $T
trap "rm -r $T" 0
pwd=`${PWDCMD-pwd}`
kopt=$pwd/$T/keyword-options
emsg=$pwd/$T/emsgids.c
posr=$pwd/$T/po-sources
extra_files=$pwd/options.c
echo "scanning for keywords and %e strings..." >&2
( cd $srcdir
lang_subdirs=`echo */config-lang.in | sed -e 's|config-lang\.in||g'`
{ for dir in "" config/ config/*/ $lang_subdirs
do for glob in '*.c' '*.h' '*.def'
do eval echo $dir$glob
done
done;
echo $extra_files;
} | tr ' ' "$nl" | grep -v '\*' |
$AWK -v excl=po/EXCLUDES -v posr=$posr -v kopt=$kopt -v emsg=$emsg '
function keyword_option(line) {
paren_index = index(line, "(")
name = substr(line, 1, paren_index - 1)
sub(/[^0-9A-Z_a-z]*$/, "", name)
sub(/[ ]+PARAMS/, "", name)
sub(/[ ]+VPARAMS/, "", name)
sub(/.*[^0-9A-Z_a-z]/, "", name)
args = substr(line, paren_index)
sub(/msgid[,\)].*/, "", args)
for (n = 1; sub(/^[^,]*,/, "", args); n++) {
continue
}
if (n == 1) { keyword = name }
else { keyword = name ":" n }
if (! keyword_seen[keyword]++) {
print "--keyword=" keyword > kopt
}
}
function spec_error_string (line) {
while ((percent_index = index(line, "%e")) != 0) {
escape = substr(line, percent_index - 1, 1)
line = substr(line, percent_index + 2)
if (escape == "%") continue
bracket_index = index(line, "}")
quote_index = index(line, "\"")
if (bracket_index == 0) return
if (quote_index != 0 && bracket_index > quote_index) return
msgid = substr(line, 1, bracket_index - 1)
line = substr(line, bracket_index + 1)
if (index(msgid, "%") != 0) continue
printf("#line %d \"%s\"\n", lineno, file) > emsg
printf("_(\"%s\")\n", msgid) > emsg
}
}
BEGIN {
while ((getline < excl) > 0) {
if ($0 ~ /^ continue
excludes[$1] = 1
}
}
{ if (!($0 in excludes)) {
print > posr
files[NR] = $0
}
}
END {
for (f in files) {
file = files[f]
lineno = 1
while (getline < file) {
if (/^( keyword_option($0)
} else if (/%e/) {
spec_error_string($0)
}
lineno++
}
}
print emsg > posr
}'
)
echo "running xgettext..." >&2
$xgettext --default-domain=$package --directory=$srcdir \
--add-comments `cat $kopt` --files-from=$posr \
--copyright-holder="Free Software Foundation, Inc." \
--msgid-bugs-address="http://gcc.gnu.org/bugs.html" \
--language=c -o po/$package.pot.tmp
sed "s:$srcdir/::g;s:$pwd/::g;" <po/$package.pot.tmp >po/$package.pot
rm po/$package.pot.tmp