2000-12-21 Benjamin Kosnik <bkoz@redhat.com>
[official-gcc.git] / gcc / exgettext
blob3087d1df80995c633b634f60c06184c791c00084
1 #! /bin/sh
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)
12 # any later version.
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.
25 : ${AWK=awk}
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.
29 xgettext=${1?}
30 shift
32 # Save work if we're just wrapping a no-op.
33 case $xgettext in
34 :) exit;;
35 esac
37 # Find the files to be scanned, and the directory to scan them from.
38 directory=.
39 files=
40 for i
42 case $i in
43 --directory=*)
44 directory=`expr " $i" : ' --directory=\(.*\)'`;;
45 --files-from=*)
46 files_from=`expr " $i" : ' --files-from=\(.*\)'`
47 files=`$AWK '/^[^#]/ { print }' $files_from`;;
48 esac
49 done
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++) {
68 continue;
71 if (n == 1) {
72 keyword = name
73 } else {
74 keyword = name ":" n
77 if (! keyword_seen[keyword]++) {
78 print "--keyword=" keyword
82 keyword_options=`(
83 cd $directory &&
84 $AWK "$generate_keyword_options" $files < /dev/null
85 )` || exit
87 # Generate temporary file reflecting the %e strings in the scanned files.
88 tmp=tmp-emsgids.c
90 generate_emsgids='
91 /%e.*}/ {
92 line = $0
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) {
97 continue
99 msgid = substr(line, 1, bracket_index - 1)
100 if (index(msgid, "%") != 0) {
101 continue
103 printf "#line %d \"%s\"\n", FNR, FILENAME
104 printf "_(\"%s\")\n", msgid
105 line = substr(line, bracket_index + 1)
109 (cd $directory &&
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
116 # Clean up.
117 # If we don't get here, `make clean' will remove this file later.
118 rm -f $directory/$tmp