2 # Wrapper around gettext for GCC sources.
3 # Copyright 1998, 2001 Free Software Foundation, Inc.
5 # Written by Paul Eggert <eggert@twinsun.com>.
6 # Revised by Zack Weinberg <zackw@stanford.edu> for no-POTFILES operation.
8 # This file is part of GNU CC.
10 # GNU CC is free software; you can redistribute it and/or modify
11 # it under the terms of the GNU General Public License as published by
12 # the Free Software Foundation; either version 2, or (at your option)
15 # GNU CC is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 # GNU General Public License for more details.
20 # You should have received a copy of the GNU General Public License
21 # along with GNU CC; see the file COPYING. If not, write to
22 # the Free Software Foundation, 59 Temple Place - Suite 330,
23 # Boston, MA 02111-1307, USA.
25 # Set environment to default value, if not already set.
28 # The arguments to this wrapper are: the program to execute, the
29 # name of the "package", and the path to the source directory.
32 then echo "usage: $0 <xgettext> <package> <srcdir>"
45 # Create temporary directory for scratch files.
51 kopt=$pwd/$T/keyword-options
52 emsg=$pwd/$T/emsgids.c
53 posr=$pwd/$T/po-sources
55 # Locate files to scan, and generate the list. All .c and .h files in
56 # $srcdir are examined, likewise $srcdir/config and $srcdir/config/*
57 # (directories). Also, all subdirectories of $srcdir that contain a
58 # config-lang.in. Exclusions come from $srcdir/po/EXCLUDE.
60 # Then generate keyword options for xgettext, by scanning for declarations
61 # of functions whose parameter names end in "msgid".
63 # Finally, generate a source file containing all %e strings from
64 # driver specs, so those can be translated too.
66 # All in one huge awk script.
68 echo "scanning for keywords and %e strings..." >&2
71 lang_subdirs=`echo */config-lang.in | sed -e 's|/config-lang\.in||g'`
75 for l in $lang_subdirs
79 $AWK -v excl=po/EXCLUDES -v posr=$posr -v kopt=$kopt -v emsg=$emsg '
80 function keyword_option(line) {
81 paren_index = index(line, "(")
82 name = substr(line, 1, paren_index - 1)
83 sub(/[^0-9A-Z_a-z]*$/, "", name)
84 sub(/[ ]+PARAMS/, "", name)
85 sub(/[ ]+VPARAMS/, "", name)
86 sub(/.*[^0-9A-Z_a-z]/, "", name)
88 args = substr(line, paren_index)
89 sub(/msgid[,\)].*/, "", args)
90 for (n = 1; sub(/^[^,]*,/, "", args); n++) {
94 if (n == 1) { keyword = name }
95 else { keyword = name ":" n }
97 if (! keyword_seen[keyword]++) {
98 print "--keyword=" keyword > kopt
102 function spec_error_string (line) {
103 while ((percent_index = index(line, "%e")) != 0) {
104 escape = substr(line, percent_index - 1, 1)
105 line = substr(line, percent_index + 2)
106 if (escape == "%") return
108 bracket_index = index(line, "}")
109 if (bracket_index == 0) return
111 msgid = substr(line, 1, bracket_index - 1)
112 if (index(msgid, "%") != 0) return
114 printf("#line %d \"%s\"\n", lineno, file) > emsg
115 printf("_(\"%s\")\n", msgid) > emsg
117 line = substr(line, bracket_index + 1)
122 while ((getline < excl) > 0) {
123 if ($0 ~ /^#/ || $0 ~ /^[ ]*$/)
129 { if (!($0 in excludes)) {
139 while (getline < file) {
140 if (/^(#[ ]*define[ ]*)?[A-Za-z_].*\(.*msgid[,\)]/) {
143 spec_error_string($0)
152 # Run the xgettext command, with temporary added as a file to scan.
153 echo "running xgettext..." >&2
154 $xgettext --default-domain=$package --directory=$srcdir \
155 --add-comments `cat $kopt` --files-from=$posr \