* de.po, zh_CN.po: Update.
[official-gcc.git] / gcc / po / exgettext
blob3408cb79066cf71505b36a268c7dc450e7ea9e55
1 #! /bin/sh
2 # Wrapper around gettext for programs using the msgid convention.
3 # Copyright 1998, 2001, 2002, 2003 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 GCC.
10 # GCC 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)
13 # any later version.
15 # GCC 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 GCC; 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 # Always operate in the C locale.
26 LANG=C
27 LANGUAGE=C
28 LC_ALL=C
29 export LANG LANGUAGE LC_ALL
31 # Set AWK if environment has not already set it.
32 AWK=${AWK-awk}
34 # The arguments to this wrapper are: the program to execute, the
35 # name of the "package", and the path to the source directory.
37 if [ $# -ne 3 ]
38 then echo "usage: $0 <xgettext> <package> <srcdir>"
39 exit 1
42 xgettext=$1
43 package=$2
44 srcdir=$3
46 nl='
49 set -e
51 # Create temporary directory for scratch files.
52 T=exg$$.d
53 mkdir $T
54 trap "rm -r $T" 0
56 pwd=`${PWDCMD-pwd}`
57 kopt=$pwd/$T/keyword-options
58 emsg=$pwd/$T/emsgids.c
59 posr=$pwd/$T/po-sources
61 # Locate files to scan, and generate the list. All .c, .h, and .def files
62 # in $srcdir are examined, likewise $srcdir/config and $srcdir/config/*
63 # (directories). Also, all subdirectories of $srcdir that contain a
64 # config-lang.in. Exclusions come from $srcdir/po/EXCLUDE.
66 # Then generate keyword options for xgettext, by scanning for declarations
67 # of functions whose parameter names end in "msgid".
69 # Finally, generate a source file containing all %e strings from
70 # driver specs, so those can be translated too.
72 # All in one huge awk script.
74 echo "scanning for keywords and %e strings..." >&2
76 ( cd $srcdir
77 lang_subdirs=`echo */config-lang.in | sed -e 's|config-lang\.in||g'`
78 { for dir in "" config/ config/*/ $lang_subdirs
79 do for glob in '*.c' '*.h' '*.def'
80 do eval echo $dir$glob
81 done
82 done;
83 } | tr ' ' "$nl" | grep -v '\*' |
84 $AWK -v excl=po/EXCLUDES -v posr=$posr -v kopt=$kopt -v emsg=$emsg '
85 function keyword_option(line) {
86 paren_index = index(line, "(")
87 name = substr(line, 1, paren_index - 1)
88 sub(/[^0-9A-Z_a-z]*$/, "", name)
89 sub(/[ ]+PARAMS/, "", name)
90 sub(/[ ]+VPARAMS/, "", name)
91 sub(/.*[^0-9A-Z_a-z]/, "", name)
93 args = substr(line, paren_index)
94 sub(/msgid[,\)].*/, "", args)
95 for (n = 1; sub(/^[^,]*,/, "", args); n++) {
96 continue
99 if (n == 1) { keyword = name }
100 else { keyword = name ":" n }
102 if (! keyword_seen[keyword]++) {
103 print "--keyword=" keyword > kopt
107 function spec_error_string (line) {
108 while ((percent_index = index(line, "%e")) != 0) {
109 escape = substr(line, percent_index - 1, 1)
110 line = substr(line, percent_index + 2)
111 if (escape == "%") continue
113 bracket_index = index(line, "}")
114 quote_index = index(line, "\"")
115 if (bracket_index == 0) return
116 if (quote_index != 0 && bracket_index > quote_index) return
118 msgid = substr(line, 1, bracket_index - 1)
119 line = substr(line, bracket_index + 1)
121 if (index(msgid, "%") != 0) continue
123 printf("#line %d \"%s\"\n", lineno, file) > emsg
124 printf("_(\"%s\")\n", msgid) > emsg
129 BEGIN {
130 while ((getline < excl) > 0) {
131 if ($0 ~ /^#/ || $0 ~ /^[ ]*$/)
132 continue
133 excludes[$1] = 1
137 { if (!($0 in excludes)) {
138 print > posr
139 files[NR] = $0
143 END {
144 for (f in files) {
145 file = files[f]
146 lineno = 1
147 while (getline < file) {
148 if (/^(#[ ]*define[ ]*)?[A-Za-z_].*\(.*msgid[,\)]/) {
149 keyword_option($0)
150 } else if (/%e/) {
151 spec_error_string($0)
153 lineno++
156 print emsg > posr
160 echo "scanning option files..." >&2
162 ( cd $srcdir; find . -name '*.opt' -print |
163 $AWK '{
164 file = $1
165 lineno = 1
166 field = 0
167 while (getline < file) {
168 if (/^[ \t]*(;|$)/ || !/^[^ \t]/) {
169 field = 0
170 } else {
171 if (field == 2) {
172 line = $0
173 gsub(".*\t", "", line)
174 printf("#line %d \"%s\"\n", lineno, file)
175 printf("_(\"%s\")\n", line)
177 field++;
179 lineno++;
181 }') >> $emsg
183 # Run the xgettext command, with temporary added as a file to scan.
184 echo "running xgettext..." >&2
185 $xgettext --default-domain=$package --directory=$srcdir \
186 --add-comments `cat $kopt` --files-from=$posr \
187 --copyright-holder="Free Software Foundation, Inc." \
188 --msgid-bugs-address="http://gcc.gnu.org/bugs.html" \
189 --language=c -o po/$package.pot.tmp
190 # Remove local paths from .pot file.
191 sed "s:$srcdir/::g;s:$pwd/::g;" <po/$package.pot.tmp >po/$package.pot
192 rm po/$package.pot.tmp