2 # Wrapper around gettext for programs using the msgid convention.
4 # Copyright (C) 1998, 2001 Free Software Foundation, Inc.
6 # Written by Paul Eggert <eggert@twinsun.com>.
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 2, or (at your option)
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with GNU CC; see the file COPYING. If not, write to
20 # the Free Software Foundation, 59 Temple Place - Suite 330,
21 # Boston, MA 02111-1307, USA.
23 # Always operate in the C locale.
27 export LANG LANGUAGE LC_ALL
29 # Set AWK if environment has not already set it.
32 # The argument to this wrapper is the xgettext command to be executed.
33 # Extract the xgettext program name from the rest of the command.
37 # Save work if we're just wrapping a no-op.
42 # Find the files to be scanned, and the directory to scan them from.
49 directory
=`expr " $i" : ' --directory=\(.*\)'`;;
51 files_from
=`expr " $i" : ' --files-from=\(.*\)'`
52 files
=`$AWK '/^[^#]/ { print }' $files_from`;;
56 # Generate keyword options for xgettext,
57 # by scanning for declarations of functions
58 # whose parameter names end in "msgid".
59 generate_keyword_options
='
60 /^[A-Z_a-z].*\(.*msgid[,)]/ {
62 paren_index = index($0, "(")
64 name = substr($0, 1, paren_index - 1)
65 sub(/[^0-9A-Z_a-z]*$/, "", name)
66 sub(/[ ]+PARAMS/, "", name)
67 sub(/[ ]+VPARAMS/, "", name)
68 sub(/.*[^0-9A-Z_a-z]/, "", name)
70 args = substr($0, paren_index)
71 sub(/msgid[,)].*/, "", args)
72 for (n = 1; sub(/^[^,]*,/, "", args); n++) {
82 if (! keyword_seen[keyword]++) {
83 print "--keyword=" keyword
89 $AWK "$generate_keyword_options" $files < /dev/null
92 # Generate temporary file reflecting the %e strings in the scanned files.
98 while ((percent_index = index(line, "%e")) != 0) {
99 line = substr(line, percent_index + 2)
100 bracket_index = index(line, "}")
101 if (bracket_index == 0) {
104 msgid = substr(line, 1, bracket_index - 1)
105 if (index(msgid, "%") != 0) {
108 printf "#line %d \"%s\"\n", FNR, FILENAME
109 printf "_(\"%s\")\n", msgid
110 line = substr(line, bracket_index + 1)
115 $AWK "$generate_emsgids" $files < /dev
/null
116 ) > $directory/$tmp ||
exit
118 # Run the xgettext command, with temporary added as a file to scan.
119 "$xgettext" $keyword_options ${1+"$@"} $tmp ||
exit
122 # If we don't get here, `make clean' will remove this file later.
123 rm -f $directory/$tmp