2 # Wrapper around gettext for programs using the msgid convention.
4 # Copyright (C) 1998, 2001, 2004, 2009-2013 Free Software Foundation, Inc.
6 # Written by Paul Eggert <eggert@twinsun.com>.
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 3 of the License, or
11 # (at your option) 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 this program. If not, see <http://www.gnu.org/licenses/>.
21 # Always operate in the C locale.
25 export LANG LANGUAGE LC_ALL
27 # Set AWK if environment has not already set it.
30 # The argument to this wrapper is the xgettext command to be executed.
31 # Extract the xgettext program name from the rest of the command.
35 # Save work if we're just wrapping a no-op.
40 # Find the files to be scanned, and the directory to scan them from.
47 directory=`expr " $i" : ' --directory=\(.*\)'`;;
49 files_from=`expr " $i" : ' --files-from=\(.*\)'`
50 files=`$AWK '/^[^#]/ { print }' $files_from`;;
54 # Generate keyword options for xgettext,
55 # by scanning for declarations of functions
56 # whose parameter names end in "msgid".
57 generate_keyword_options='
58 /^[A-Z_a-z].*\(.*msgid[,)]/ {
60 paren_index = index($0, "(")
62 name = substr($0, 1, paren_index - 1)
63 sub(/[^0-9A-Z_a-z]*$/, "", name)
64 sub(/[ ]+PARAMS/, "", name)
65 sub(/[ ]+VPARAMS/, "", name)
66 sub(/.*[^0-9A-Z_a-z]/, "", name)
68 args = substr($0, paren_index)
69 sub(/msgid[,)].*/, "", args)
70 for (n = 1; sub(/^[^,]*,/, "", args); n++) {
80 if (! keyword_seen[keyword]++) {
81 print "--keyword=" keyword
87 $AWK "$generate_keyword_options" $files < /dev/null
90 # Run the xgettext command, with extra input containing the extra
91 # msgids that it wouldn't normally find.
95 while ((percent_index = index(line, "%e")) != 0) {
96 line = substr(line, percent_index + 2)
97 bracket_index = index(line, "}")
98 if (bracket_index == 0) {
101 msgid = substr(line, 1, bracket_index - 1)
102 if (index(msgid, "%") != 0) {
105 printf "#line %d \"%s\"\n", FNR, FILENAME
106 printf "_(\"%s\")\n", msgid
107 line = substr(line, bracket_index + 1)
112 $AWK "$generate_emsgids" $files < /dev/null
113 ) | "$xgettext" $keyword_options ${1+"$@"} -