ifcvt.c (noce_try_addcc): Do not call emit_conditional_add with weird operands.
[official-gcc.git] / gcc / po / exgettext
blob0cf8a25b6b5e42efd9980f11c7cbf998687b4abb
1 #! /bin/sh
2 # Wrapper around gettext for programs using the msgid convention.
3 # Copyright 1998, 2001, 2002 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 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)
11 # any later version.
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.
24 LANG=C
25 LANGUAGE=C
26 LC_ALL=C
27 export LANG LANGUAGE LC_ALL
29 # Set AWK if environment has not already set it.
30 AWK=${AWK-awk}
32 # The arguments to this wrapper are: the program to execute, the
33 # name of the "package", and the path to the source directory.
35 if [ $# -ne 3 ]
36 then echo "usage: $0 <xgettext> <package> <srcdir>"
37 exit 1
40 xgettext=$1
41 package=$2
42 srcdir=$3
44 nl='
47 set -e
49 # Create temporary directory for scratch files.
50 T=exg$$.d
51 mkdir $T
52 trap "rm -r $T" 0
54 pwd=`${PWDCMD-pwd}`
55 kopt=$pwd/$T/keyword-options
56 emsg=$pwd/$T/emsgids.c
57 posr=$pwd/$T/po-sources
59 # Locate files to scan, and generate the list. All .c, .h, and .def files
60 # in $srcdir are examined, likewise $srcdir/config and $srcdir/config/*
61 # (directories). Also, all subdirectories of $srcdir that contain a
62 # config-lang.in. Exclusions come from $srcdir/po/EXCLUDE.
64 # Then generate keyword options for xgettext, by scanning for declarations
65 # of functions whose parameter names end in "msgid".
67 # Finally, generate a source file containing all %e strings from
68 # driver specs, so those can be translated too.
70 # All in one huge awk script.
72 echo "scanning for keywords and %e strings..." >&2
74 ( cd $srcdir
75 lang_subdirs=`echo */config-lang.in | sed -e 's|config-lang\.in||g'`
76 for dir in "" config/ config/*/ $lang_subdirs
77 do for glob in '*.c' '*.h' '*.def'
78 do eval echo $dir$glob
79 done
80 done | tr ' ' "$nl" | grep -v '\*' |
81 $AWK -v excl=po/EXCLUDES -v posr=$posr -v kopt=$kopt -v emsg=$emsg '
82 function keyword_option(line) {
83 paren_index = index(line, "(")
84 name = substr(line, 1, paren_index - 1)
85 sub(/[^0-9A-Z_a-z]*$/, "", name)
86 sub(/[ ]+PARAMS/, "", name)
87 sub(/[ ]+VPARAMS/, "", name)
88 sub(/.*[^0-9A-Z_a-z]/, "", name)
90 args = substr(line, paren_index)
91 sub(/msgid[,\)].*/, "", args)
92 for (n = 1; sub(/^[^,]*,/, "", args); n++) {
93 continue
96 if (n == 1) { keyword = name }
97 else { keyword = name ":" n }
99 if (! keyword_seen[keyword]++) {
100 print "--keyword=" keyword > kopt
104 function spec_error_string (line) {
105 while ((percent_index = index(line, "%e")) != 0) {
106 escape = substr(line, percent_index - 1, 1)
107 line = substr(line, percent_index + 2)
108 if (escape == "%") return
110 bracket_index = index(line, "}")
111 if (bracket_index == 0) return
113 msgid = substr(line, 1, bracket_index - 1)
114 if (index(msgid, "%") != 0) return
116 printf("#line %d \"%s\"\n", lineno, file) > emsg
117 printf("_(\"%s\")\n", msgid) > emsg
119 line = substr(line, bracket_index + 1)
123 BEGIN {
124 while ((getline < excl) > 0) {
125 if ($0 ~ /^#/ || $0 ~ /^[ ]*$/)
126 continue
127 excludes[$1] = 1
131 { if (!($0 in excludes)) {
132 print > posr
133 files[NR] = $0
137 END {
138 for (f in files) {
139 file = files[f]
140 lineno = 1
141 while (getline < file) {
142 if (/^(#[ ]*define[ ]*)?[A-Za-z_].*\(.*msgid[,\)]/) {
143 keyword_option($0)
144 } else if (/%e/) {
145 spec_error_string($0)
147 lineno++
150 print emsg > posr
154 # Run the xgettext command, with temporary added as a file to scan.
155 echo "running xgettext..." >&2
156 $xgettext --default-domain=$package --directory=$srcdir \
157 --add-comments `cat $kopt` --files-from=$posr \
158 --language=c -o po/$package.pot