Missed one in last change.
[official-gcc.git] / gcc / po / exgettext
blob83e39239dcf3cbb02adc59757852e9c54a7f1fef
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 | tr ' ' "$nl" | grep -v '\*' |
83 $AWK -v excl=po/EXCLUDES -v posr=$posr -v kopt=$kopt -v emsg=$emsg '
84 function keyword_option(line) {
85 paren_index = index(line, "(")
86 name = substr(line, 1, paren_index - 1)
87 sub(/[^0-9A-Z_a-z]*$/, "", name)
88 sub(/[ ]+PARAMS/, "", name)
89 sub(/[ ]+VPARAMS/, "", name)
90 sub(/.*[^0-9A-Z_a-z]/, "", name)
92 args = substr(line, paren_index)
93 sub(/msgid[,\)].*/, "", args)
94 for (n = 1; sub(/^[^,]*,/, "", args); n++) {
95 continue
98 if (n == 1) { keyword = name }
99 else { keyword = name ":" n }
101 if (! keyword_seen[keyword]++) {
102 print "--keyword=" keyword > kopt
106 function spec_error_string (line) {
107 while ((percent_index = index(line, "%e")) != 0) {
108 escape = substr(line, percent_index - 1, 1)
109 line = substr(line, percent_index + 2)
110 if (escape == "%") return
112 bracket_index = index(line, "}")
113 if (bracket_index == 0) return
115 msgid = substr(line, 1, bracket_index - 1)
116 if (index(msgid, "%") != 0) return
118 printf("#line %d \"%s\"\n", lineno, file) > emsg
119 printf("_(\"%s\")\n", msgid) > emsg
121 line = substr(line, bracket_index + 1)
125 BEGIN {
126 while ((getline < excl) > 0) {
127 if ($0 ~ /^#/ || $0 ~ /^[ ]*$/)
128 continue
129 excludes[$1] = 1
133 { if (!($0 in excludes)) {
134 print > posr
135 files[NR] = $0
139 END {
140 for (f in files) {
141 file = files[f]
142 lineno = 1
143 while (getline < file) {
144 if (/^(#[ ]*define[ ]*)?[A-Za-z_].*\(.*msgid[,\)]/) {
145 keyword_option($0)
146 } else if (/%e/) {
147 spec_error_string($0)
149 lineno++
152 print emsg > posr
156 # Run the xgettext command, with temporary added as a file to scan.
157 echo "running xgettext..." >&2
158 $xgettext --default-domain=$package --directory=$srcdir \
159 --add-comments `cat $kopt` --files-from=$posr \
160 --language=c -o po/$package.pot