2 # Wrapper around gettext for GCC sources.
3 # Copyright 1998 Free Software Foundation, Inc.
5 # Written by Paul Eggert <eggert@twinsun.com>.
7 # This file is part of GNU CC.
9 # GNU CC is free software; you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation; either version 2, or (at your option)
14 # GNU CC is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with GNU CC; see the file COPYING. If not, write to
21 # the Free Software Foundation, 59 Temple Place - Suite 330,
22 # Boston, MA 02111-1307, USA.
24 # Set environment to default value, if not already set.
27 # The argument to this wrapper is the xgettext command to be executed.
28 # Extract the xgettext program name from the rest of the command.
32 # Save work if we're just wrapping a no-op.
37 # Find the files to be scanned, and the directory to scan them from.
44 directory
=`expr " $i" : ' --directory=\(.*\)'`;;
46 files_from
=`expr " $i" : ' --files-from=\(.*\)'`
47 files
=`$AWK '/^[^#]/ { print }' $files_from`;;
51 # Generate keyword options for xgettext,
52 # by scanning for declarations of functions
53 # whose parameter names end in "msgid".
54 generate_keyword_options
='
55 /^[A-Z_a-z].*\(.*msgid[,)]/ {
57 paren_index = index($0, "(")
59 name = substr($0, 1, paren_index - 1)
60 sub(/[^0-9A-Z_a-z]*$/, "", name)
61 sub(/[ ]+PARAMS/, "", name)
62 sub(/[ ]+VPARAMS/, "", name)
63 sub(/.*[^0-9A-Z_a-z]/, "", name)
65 args = substr($0, paren_index)
66 sub(/msgid[,)].*/, "", args)
67 for (n = 1; sub(/^[^,]*,/, "", args); n++) {
77 if (! keyword_seen[keyword]++) {
78 print "--keyword=" keyword
84 $AWK "$generate_keyword_options" $files < /dev/null
87 # Generate temporary file reflecting the %e strings in the scanned files.
93 while ((percent_index = index(line, "%e")) != 0) {
94 line = substr(line, percent_index + 2)
95 bracket_index = index(line, "}")
96 if (bracket_index == 0) {
99 msgid = substr(line, 1, bracket_index - 1)
100 if (index(msgid, "%") != 0) {
103 printf "#line %d \"%s\"\n", FNR, FILENAME
104 printf "_(\"%s\")\n", msgid
105 line = substr(line, bracket_index + 1)
110 $AWK "$generate_emsgids" $files < /dev
/null
111 ) > $directory/$tmp ||
exit
113 # Run the xgettext command, with temporary added as a file to scan.
114 "$xgettext" $keyword_options ${1+"$@"} $tmp ||
exit
117 # If we don't get here, `make clean' will remove this file later.
118 rm -f $directory/$tmp