OSDN Git Service

gcc/
[pf3gnuchains/gcc-fork.git] / gcc / po / exgettext
index 6b1073e..3408cb7 100644 (file)
@@ -1,29 +1,35 @@
 #! /bin/sh
-# Wrapper around gettext for GCC sources.
-# Copyright 1998, 2001 Free Software Foundation, Inc.
+# Wrapper around gettext for programs using the msgid convention.
+# Copyright 1998, 2001, 2002, 2003 Free Software Foundation, Inc.
 
 # Written by Paul Eggert <eggert@twinsun.com>.
 # Revised by Zack Weinberg <zackw@stanford.edu> for no-POTFILES operation.
 
-# This file is part of GNU CC.
+# This file is part of GCC.
 
-# GNU CC is free software; you can redistribute it and/or modify
+# GCC is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
 # the Free Software Foundation; either version 2, or (at your option)
 # any later version.
 
-# GNU CC is distributed in the hope that it will be useful,
+# GCC is distributed in the hope that it will be useful,
 # but WITHOUT ANY WARRANTY; without even the implied warranty of
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 # GNU General Public License for more details.
 
 # You should have received a copy of the GNU General Public License
-# along with GNU CC; see the file COPYING.  If not, write to
+# along with GCC; see the file COPYING.  If not, write to
 # the Free Software Foundation, 59 Temple Place - Suite 330,
 # Boston, MA 02111-1307, USA.
 
-# Set environment to default value, if not already set.
-: ${AWK=awk}
+# Always operate in the C locale.
+LANG=C
+LANGUAGE=C
+LC_ALL=C
+export LANG LANGUAGE LC_ALL
+
+# Set AWK if environment has not already set it.
+AWK=${AWK-awk}
 
 # The arguments to this wrapper are: the program to execute, the
 # name of the "package", and the path to the source directory.
@@ -47,13 +53,13 @@ T=exg$$.d
 mkdir $T
 trap "rm -r $T" 0
 
-pwd=`pwd`
+pwd=`${PWDCMD-pwd}`
 kopt=$pwd/$T/keyword-options
 emsg=$pwd/$T/emsgids.c
 posr=$pwd/$T/po-sources
 
-# Locate files to scan, and generate the list.  All .c and .h files in
-# $srcdir are examined, likewise $srcdir/config and $srcdir/config/*
+# Locate files to scan, and generate the list.  All .c, .h, and .def files
+# in $srcdir are examined, likewise $srcdir/config and $srcdir/config/*
 # (directories).  Also, all subdirectories of $srcdir that contain a
 # config-lang.in.  Exclusions come from $srcdir/po/EXCLUDE.
 #
@@ -68,14 +74,13 @@ posr=$pwd/$T/po-sources
 echo "scanning for keywords and %e strings..." >&2
 
 ( cd $srcdir
-  lang_subdirs=`echo */config-lang.in | sed -e 's|/config-lang\.in||g'`
-  { echo *.[ch]
-    echo config/*.[ch]
-    echo config/*/*.[ch]
-    for l in $lang_subdirs
-    do echo $l/*.[ch]
-    done
-  } | tr ' ' "$nl" | 
+  lang_subdirs=`echo */config-lang.in | sed -e 's|config-lang\.in||g'`
+  { for dir in "" config/ config/*/ $lang_subdirs
+    do  for glob in '*.c' '*.h' '*.def'
+        do  eval echo $dir$glob
+        done
+    done;
+  } | tr ' ' "$nl" | grep -v '\*' |
   $AWK -v excl=po/EXCLUDES -v posr=$posr -v kopt=$kopt -v emsg=$emsg '
 function keyword_option(line) {
     paren_index = index(line, "(")
@@ -103,18 +108,21 @@ function spec_error_string (line) {
     while ((percent_index = index(line, "%e")) != 0) {
        escape = substr(line, percent_index - 1, 1)
        line = substr(line, percent_index + 2)
-       if (escape == "%") return
+       if (escape == "%") continue
 
        bracket_index = index(line, "}")
+       quote_index = index(line, "\"")
        if (bracket_index == 0) return
+       if (quote_index != 0 && bracket_index > quote_index) return
 
        msgid = substr(line, 1, bracket_index - 1)
-       if (index(msgid, "%") != 0) return
+       line = substr(line, bracket_index + 1)
+
+       if (index(msgid, "%") != 0) continue
 
        printf("#line %d \"%s\"\n", lineno, file) > emsg
        printf("_(\"%s\")\n", msgid) > emsg
 
-       line = substr(line, bracket_index + 1)
     }
 }
 
@@ -149,8 +157,36 @@ END {
 }'
 )
 
+echo "scanning option files..." >&2
+
+( cd $srcdir; find . -name '*.opt' -print |
+  $AWK '{
+    file = $1
+    lineno = 1
+    field = 0
+    while (getline < file) {
+       if (/^[ \t]*(;|$)/ || !/^[^ \t]/) {
+           field = 0
+       } else {
+           if (field == 2) {
+               line = $0
+               gsub(".*\t", "", line)
+               printf("#line %d \"%s\"\n", lineno, file)
+               printf("_(\"%s\")\n", line)
+           }
+           field++;
+       }
+       lineno++;
+    }
+  }') >> $emsg
+
 # Run the xgettext command, with temporary added as a file to scan.
 echo "running xgettext..." >&2
 $xgettext --default-domain=$package --directory=$srcdir \
          --add-comments `cat $kopt` --files-from=$posr \
-         -o po/$package.pot
+         --copyright-holder="Free Software Foundation, Inc." \
+         --msgid-bugs-address="http://gcc.gnu.org/bugs.html" \
+         --language=c -o po/$package.pot.tmp
+# Remove local paths from .pot file.
+sed "s:$srcdir/::g;s:$pwd/::g;" <po/$package.pot.tmp >po/$package.pot
+rm po/$package.pot.tmp