Subject: [PATCH 1/1] Attempt to remove CSharp and Java support WIP: Can be used for ifdef later if successful --- gettext-tools/Makefile.am | 4 - gettext-tools/configure.ac | 48 - gettext-tools/examples/Makefile.am | 70 - gettext-tools/src/FILES | 33 +- gettext-tools/src/Makefile.am | 112 +- gettext-tools/src/format-csharp.c | 290 --- gettext-tools/src/format-java-printf.c | 725 ------ gettext-tools/src/format-java.c | 894 ------- gettext-tools/src/format.c | 3 - gettext-tools/src/format.h | 3 - .../src/gnu/gettext/DumpResource.java | 236 -- gettext-tools/src/gnu/gettext/GetURL.java | 81 - gettext-tools/src/message.c | 6 - gettext-tools/src/message.h | 3 - gettext-tools/src/msgcmp.c | 8 - gettext-tools/src/msgfmt.c | 171 +- gettext-tools/src/msgfmt.cs | 91 - gettext-tools/src/msgunfmt.c | 118 +- gettext-tools/src/msgunfmt.cs | 241 -- gettext-tools/src/read-csharp.h | 30 - gettext-tools/src/read-java.c | 128 - gettext-tools/src/read-java.h | 29 - gettext-tools/src/read-properties.c | 724 ------ gettext-tools/src/read-properties.h | 38 - gettext-tools/src/read-resources.c | 138 -- gettext-tools/src/urlget.c | 61 +- gettext-tools/src/write-catalog.c | 6 - gettext-tools/src/write-catalog.h | 4 - gettext-tools/src/write-csharp.c | 788 ------- gettext-tools/src/write-csharp.h | 35 - gettext-tools/src/write-java.c | 1239 ---------- gettext-tools/src/write-java.h | 39 - gettext-tools/src/write-properties.c | 306 --- gettext-tools/src/write-properties.h | 38 - gettext-tools/src/write-resources.c | 200 -- gettext-tools/src/write-resources.h | 31 - gettext-tools/src/x-csharp.c | 2080 ----------------- gettext-tools/src/x-csharp.h | 50 - gettext-tools/src/x-java.c | 1717 -------------- gettext-tools/src/x-java.h | 51 - gettext-tools/src/x-properties.h | 45 - gettext-tools/src/xgettext.c | 45 +- gettext-tools/tests/Makefile.am | 12 +- gettext-tools/tests/format-csharp-1 | 83 - gettext-tools/tests/format-csharp-2 | 73 - gettext-tools/tests/format-java-1 | 153 -- gettext-tools/tests/format-java-2 | 142 -- gettext-tools/tests/gettextpo-1-prg.c | 15 - gettext-tools/tests/lang-csharp | 206 -- gettext-tools/tests/lang-java | 227 -- gettext-tools/tests/msggrep-6 | 6 - gettext-tools/tests/msggrep-9 | 11 - gettext-tools/tests/msgunfmt-csharp-1 | 92 - gettext-tools/tests/msgunfmt-java-1 | 91 - gettext-tools/tests/xgettext-6 | 36 +- gettext-tools/tests/xgettext-csharp-1 | 70 - gettext-tools/tests/xgettext-csharp-2 | 83 - gettext-tools/tests/xgettext-csharp-3 | 171 -- gettext-tools/tests/xgettext-csharp-4 | 36 - gettext-tools/tests/xgettext-csharp-5 | 56 - gettext-tools/tests/xgettext-csharp-6 | 33 - gettext-tools/tests/xgettext-csharp-7 | 28 - gettext-tools/tests/xgettext-csharp-8 | 66 - gettext-tools/tests/xgettext-java-1 | 61 - gettext-tools/tests/xgettext-java-2 | 222 -- gettext-tools/tests/xgettext-java-3 | 31 - gettext-tools/tests/xgettext-java-4 | 32 - gettext-tools/tests/xgettext-java-5 | 56 - gettext-tools/tests/xgettext-java-6 | 33 - gettext-tools/tests/xgettext-java-7 | 29 - gettext-tools/woe32dll/gettextsrc-exports.c | 3 - gnulib-local/Makefile.am | 2 - gnulib-local/m4/java.m4 | 17 - gnulib-local/modules/java | 21 - m4/libtool.m4 | 74 - 75 files changed, 32 insertions(+), 13198 deletions(-) delete mode 100644 gettext-tools/src/format-csharp.c delete mode 100644 gettext-tools/src/format-java-printf.c delete mode 100644 gettext-tools/src/format-java.c delete mode 100644 gettext-tools/src/gnu/gettext/DumpResource.java delete mode 100644 gettext-tools/src/gnu/gettext/GetURL.java delete mode 100644 gettext-tools/src/msgfmt.cs delete mode 100644 gettext-tools/src/msgunfmt.cs delete mode 100644 gettext-tools/src/read-csharp.h delete mode 100644 gettext-tools/src/read-java.c delete mode 100644 gettext-tools/src/read-java.h delete mode 100644 gettext-tools/src/read-properties.c delete mode 100644 gettext-tools/src/read-properties.h delete mode 100644 gettext-tools/src/read-resources.c delete mode 100644 gettext-tools/src/write-csharp.c delete mode 100644 gettext-tools/src/write-csharp.h delete mode 100644 gettext-tools/src/write-java.c delete mode 100644 gettext-tools/src/write-java.h delete mode 100644 gettext-tools/src/write-properties.c delete mode 100644 gettext-tools/src/write-properties.h delete mode 100644 gettext-tools/src/write-resources.c delete mode 100644 gettext-tools/src/write-resources.h delete mode 100644 gettext-tools/src/x-csharp.c delete mode 100644 gettext-tools/src/x-csharp.h delete mode 100644 gettext-tools/src/x-java.c delete mode 100644 gettext-tools/src/x-java.h delete mode 100644 gettext-tools/src/x-properties.h delete mode 100755 gettext-tools/tests/format-csharp-1 delete mode 100755 gettext-tools/tests/format-csharp-2 delete mode 100755 gettext-tools/tests/format-java-1 delete mode 100755 gettext-tools/tests/format-java-2 delete mode 100755 gettext-tools/tests/lang-csharp delete mode 100755 gettext-tools/tests/lang-java delete mode 100755 gettext-tools/tests/msgunfmt-csharp-1 delete mode 100755 gettext-tools/tests/msgunfmt-java-1 delete mode 100755 gettext-tools/tests/xgettext-csharp-1 delete mode 100755 gettext-tools/tests/xgettext-csharp-2 delete mode 100755 gettext-tools/tests/xgettext-csharp-3 delete mode 100755 gettext-tools/tests/xgettext-csharp-4 delete mode 100755 gettext-tools/tests/xgettext-csharp-5 delete mode 100755 gettext-tools/tests/xgettext-csharp-6 delete mode 100755 gettext-tools/tests/xgettext-csharp-7 delete mode 100755 gettext-tools/tests/xgettext-csharp-8 delete mode 100755 gettext-tools/tests/xgettext-java-1 delete mode 100755 gettext-tools/tests/xgettext-java-2 delete mode 100755 gettext-tools/tests/xgettext-java-3 delete mode 100755 gettext-tools/tests/xgettext-java-4 delete mode 100755 gettext-tools/tests/xgettext-java-5 delete mode 100755 gettext-tools/tests/xgettext-java-6 delete mode 100755 gettext-tools/tests/xgettext-java-7 delete mode 100644 gnulib-local/m4/java.m4 delete mode 100644 gnulib-local/modules/java diff --git a/gettext-tools/Makefile.am b/gettext-tools/Makefile.am index 449a79754..0049191e8 100644 --- a/gettext-tools/Makefile.am +++ b/gettext-tools/Makefile.am @@ -34,10 +34,6 @@ gettextsrc_SCRIPTS = ../build-aux/config.rpath # Files installed for the examples. examplesbuildauxdir = $(docdir)/examples/build-aux -examplesbuildaux_DATA = \ - ../build-aux/javacomp.sh.in ../build-aux/javaexec.sh.in \ - ../build-aux/csharpcomp.sh.in ../build-aux/csharpexec.sh.in - # Files copied from other directories. diff --git a/gettext-tools/configure.ac b/gettext-tools/configure.ac index d58b86ed2..db4ed2e5f 100644 --- a/gettext-tools/configure.ac +++ b/gettext-tools/configure.ac @@ -33,40 +33,6 @@ AC_PROG_CC AC_PROG_INSTALL AC_PROG_YACC -gt_JAVA_CHOICE - -gt_JAVAEXEC -gt_JAVACOMP([1.5]) -AC_CHECK_PROG([JAR], [jar], [jar]) -if test -n "$HAVE_JAVACOMP" && test -n "$JAR" && test "$JAVA_CHOICE" != no; then - BUILDJAVA=yes -else - BUILDJAVA=no -fi -AC_SUBST([BUILDJAVA]) -if test -n "$HAVE_JAVAEXEC" && test $BUILDJAVA = yes; then - TESTJAVA=yes -else - TESTJAVA=no -fi -AC_SUBST([TESTJAVA]) - -gt_CSHARPCOMP -if test -n "$HAVE_CSHARPCOMP" && test "$CSHARP_CHOICE" != no; then - BUILDCSHARP=yes -else - BUILDCSHARP=no -fi -AC_SUBST([BUILDCSHARP]) - -gt_CSHARPEXEC([csharpexec-test.exe], [$srcdir/m4]) -if test -n "$HAVE_CSHARPEXEC" && test $BUILDCSHARP = yes; then - TESTCSHARP=yes -else - TESTCSHARP=no -fi -AC_SUBST([TESTCSHARP]) - dnl Check for host type. AC_CANONICAL_HOST @@ -147,20 +113,6 @@ fi AM_CONDITIONAL([USE_INSTALLED_LIBTEXTSTYLE], [test "$gt_use_installed_libtextstyle" != no]) -dnl This option allows to build gettext-tools without (re)building GNU.Gettext.dll. -AC_ARG_WITH([installed-csharp-dll], - [AS_HELP_STRING([--with-installed-csharp-dll], - [Use an already installed C# DLL.])], - [gt_use_installed_csharp_dll=$withval], - [gt_use_installed_csharp_dll=no]) -if test "$gt_use_installed_csharp_dll" = no; then - test -f ../gettext-runtime/intl-csharp/Makefile || { - AC_MSG_WARN([When building the gettext-tools package without building the entire gettext package, you need to pass the --with-installed-csharp-dll option to configure.]) - } -fi -AM_CONDITIONAL([USE_INSTALLED_CSHARP_DLL], - [test "$gt_use_installed_csharp_dll" != no]) - dnl This line internationalizes the bison generated parsers. BISON_I18N diff --git a/gettext-tools/examples/Makefile.am b/gettext-tools/examples/Makefile.am index cd478eb5e..ff303e254 100644 --- a/gettext-tools/examples/Makefile.am +++ b/gettext-tools/examples/Makefile.am @@ -240,70 +240,6 @@ EXAMPLESFILES = \ hello-smalltalk/m4/Makefile.am \ hello-smalltalk/po/Makefile.am \ \ - hello-java/INSTALL \ - hello-java/autogen.sh \ - hello-java/autoclean.sh \ - hello-java/Hello.java \ - hello-java/Makefile.am \ - hello-java/configure.ac \ - hello-java/m4/Makefile.am \ - hello-java/po/Makefile.am \ - \ - hello-java-awt/INSTALL \ - hello-java-awt/BUGS \ - hello-java-awt/autogen.sh \ - hello-java-awt/autoclean.sh \ - hello-java-awt/Hello.java \ - hello-java-awt/Makefile.am \ - hello-java-awt/configure.ac \ - hello-java-awt/m4/Makefile.am \ - hello-java-awt/m4/TestAWT.java \ - hello-java-awt/m4/TestAWT.class \ - hello-java-awt/po/Makefile.am \ - \ - hello-java-swing/INSTALL \ - hello-java-swing/BUGS \ - hello-java-swing/autogen.sh \ - hello-java-swing/autoclean.sh \ - hello-java-swing/Hello.java \ - hello-java-swing/Makefile.am \ - hello-java-swing/configure.ac \ - hello-java-swing/m4/Makefile.am \ - hello-java-swing/m4/TestAWT.java \ - hello-java-swing/m4/TestAWT.class \ - hello-java-swing/po/Makefile.am \ - \ - hello-java-qtjambi/INSTALL \ - hello-java-qtjambi/BUGS \ - hello-java-qtjambi/autogen.sh \ - hello-java-qtjambi/autoclean.sh \ - hello-java-qtjambi/Hello.java \ - hello-java-qtjambi/Makefile.am \ - hello-java-qtjambi/configure.ac \ - hello-java-qtjambi/m4/Makefile.am \ - hello-java-qtjambi/m4/Test15.java \ - hello-java-qtjambi/m4/Test15.class \ - hello-java-qtjambi/po/Makefile.am \ - \ - hello-csharp/INSTALL \ - hello-csharp/autogen.sh \ - hello-csharp/autoclean.sh \ - hello-csharp/hello.cs \ - hello-csharp/Makefile.am \ - hello-csharp/configure.ac \ - hello-csharp/m4/Makefile.am \ - hello-csharp/po/Makefile.am \ - \ - hello-csharp-forms/INSTALL \ - hello-csharp-forms/README \ - hello-csharp-forms/autogen.sh \ - hello-csharp-forms/autoclean.sh \ - hello-csharp-forms/hello.cs \ - hello-csharp-forms/Makefile.am \ - hello-csharp-forms/configure.ac \ - hello-csharp-forms/m4/Makefile.am \ - hello-csharp-forms/po/Makefile.am \ - \ hello-gawk/INSTALL \ hello-gawk/autogen.sh \ hello-gawk/autoclean.sh \ @@ -390,12 +326,6 @@ EXAMPLESDIRS = \ hello-librep \ hello-guile \ hello-smalltalk \ - hello-java \ - hello-java-awt \ - hello-java-swing \ - hello-java-qtjambi \ - hello-csharp \ - hello-csharp-forms \ hello-gawk \ hello-pascal \ hello-ycp \ diff --git a/gettext-tools/src/FILES b/gettext-tools/src/FILES index 52c1ad058..934bd3687 100644 --- a/gettext-tools/src/FILES +++ b/gettext-tools/src/FILES @@ -191,17 +191,7 @@ plural-table.c | read-mo.h | read-mo.c | Reading GNU .mo files. -| read-java.h -| read-java.c -| Reading Java ResourceBundle files. -| read-csharp.h -| read-csharp.c -| msgunfmt.cs -| Reading C# satellite assemblies. -| read-resources.h -| read-resources.c -| msgunfmt.cs -| Reading C# .resources files. +| | read-tcl.h | read-tcl.c | msgunfmt.tcl @@ -222,9 +212,6 @@ format-lisp.c Format string handling for Common Lisp. format-elisp.c Format string handling for Emacs Lisp. format-librep.c Format string handling for librep. format-scheme.c Format string handling for Scheme. -format-java.c Format string handling for Java. -format-java-printf.c Format string handling for Java, printf syntax. -format-csharp.c Format string handling for C#. format-awk.c Format string handling for awk. format-pascal.c Format string handling for Object Pascal. format-ycp.c Format string handling for YCP. @@ -259,16 +246,7 @@ msgl-check.c | write-mo.h | write-mo.c | Generating GNU .mo files. -| write-java.h -| write-java.c -| Generating Java ResourceBundle files. -| write-csharp.h -| write-csharp.c -| Generating C# satellite assemblies. -| write-resources.h -| write-resources.c -| msgfmt.cs -| Generating C# .resources files. +| | write-tcl.h | write-tcl.c | Generating Tcl .msg files. @@ -340,12 +318,7 @@ msgl-check.c | x-smalltalk.h | x-smalltalk.c | String extractor for Smalltalk. -| x-java.h -| x-java.c -| String extractor for Java. -| x-csharp.h -| x-csharp.c -| String extractor for C#. +| | x-awk.h | x-awk.c | String extractor for awk. diff --git a/gettext-tools/src/Makefile.am b/gettext-tools/src/Makefile.am index b0894211d..2b46dadce 100644 --- a/gettext-tools/src/Makefile.am +++ b/gettext-tools/src/Makefile.am @@ -37,7 +37,7 @@ lib_LTLIBRARIES = libgettextsrc.la noinst_HEADERS = pos.h message.h po-error.h po-xerror.h po-gram.h po-charset.h \ po-lex.h open-catalog.h read-catalog-abstract.h read-catalog.h \ -read-po.h read-properties.h read-stringtable.h \ +read-po.h read-stringtable.h \ str-list.h \ write-catalog.h write-po.h write-properties.h write-stringtable.h \ dir-list.h file-list.h po-gram-gen.h po-gram-gen2.h cldr-plural.h \ @@ -46,8 +46,6 @@ msgl-charset.h msgl-equal.h msgl-iconv.h msgl-ascii.h msgl-cat.h msgl-header.h \ msgl-english.h msgl-check.h msgl-fsearch.h msgfmt.h msgunfmt.h \ plural-count.h plural-eval.h plural-distrib.h \ read-mo.h write-mo.h \ -read-java.h write-java.h \ -read-csharp.h write-csharp.h \ read-resources.h write-resources.h \ read-tcl.h write-tcl.h \ write-qt.h \ @@ -58,14 +56,14 @@ xgettext.h \ rc-str-list.h xg-pos.h xg-encoding.h xg-mixed-string.h xg-arglist-context.h \ xg-arglist-callshape.h xg-arglist-parser.h xg-message.h \ x-c.h x-po.h x-sh.h x-python.h x-lisp.h x-elisp.h x-librep.h \ -x-scheme.h x-smalltalk.h x-java.h x-properties.h x-csharp.h x-awk.h x-ycp.h \ +x-scheme.h x-smalltalk.h x-properties.h x-awk.h x-ycp.h \ x-tcl.h x-perl.h x-php.h x-stringtable.h x-rst.h x-glade.h x-lua.h \ x-javascript.h x-vala.h x-gsettings.h x-desktop.h x-appdata.h EXTRA_DIST += FILES project-id aliaspath = $(localedir) -jardir = $(datadir)/gettext + pkgdatadir = $(datadir)/gettext projectsdir = $(pkgdatadir)/projects pkglibdir = $(libdir)/gettext @@ -79,12 +77,11 @@ AM_CPPFLAGS = \ DEFS = \ -DLOCALEDIR=\"$(localedir)\" -DBISON_LOCALEDIR=\"$(BISON_LOCALEDIR)\" \ -DLOCALE_ALIAS_PATH=\"$(aliaspath)\" \ - -DUSEJAVA=$(USEJAVA) \ - -DGETTEXTJAR=\"$(jardir)/gettext.jar\" \ -DLIBDIR=\"$(libdir)\" \ -DGETTEXTDATADIR=\"$(pkgdatadir)\" \ -DPROJECTSDIR=\"$(projectsdir)\" \ -DEXEEXT=\"@EXEEXT@\" @DEFS@ + # Ensure that defines SIZE_MAX in C++ mode, like it does in C mode. AM_CXXFLAGS = -D__STDC_LIMIT_MACROS @@ -93,15 +90,9 @@ OTHERPROGDEPENDENCIES = ../gnulib-lib/libgettextlib.la $(WOE32_LDADD) SED = sed YACC = @YACC@ -d -JAR = @JAR@ -JAVACOMP = $(SHELL) ../javacomp.sh -CSHARPCOMP = $(SHELL) ../csharpcomp.sh -CSHARPCOMPFLAGS = @CSHARPCOMPFLAGS@ - # All programs deal with message lists. -# All programs must read PO files. (msgunfmt also, for read-java.c, -# read-csharp.c and read-resources.c.) +# All programs must read PO files. (msgunfmt also, for read-resources.c.) # message.c -> str-list.c. # (read-catalog-abstract.c <--> po-gram-gen.y <--> po-lex.c) -> str-list.c. # (read-catalog-abstract.c <--> po-gram-gen.y <--> po-lex.c) -> open-catalog.c -> dir-list.c -> str-list.c. @@ -128,9 +119,6 @@ FORMAT_SOURCE += \ format-elisp.c \ format-librep.c \ format-scheme.c \ - format-java.c \ - format-java-printf.c \ - format-csharp.c \ format-awk.c \ format-pascal.c \ format-ycp.c \ @@ -166,7 +154,7 @@ msgcmp_SOURCES = msgcmp.c msgcmp_SOURCES += msgl-fsearch.c msgfmt_SOURCES = msgfmt.c msgfmt_SOURCES += \ - write-mo.c write-java.c write-csharp.c write-resources.c write-tcl.c \ + write-mo.c write-resources.c write-tcl.c \ write-qt.c write-desktop.c write-xml.c \ ../../gettext-runtime/intl/hash-string.c if !WOE32DLL @@ -177,7 +165,8 @@ endif msgmerge_SOURCES += msgl-fsearch.c lang-table.c plural-count.c msgunfmt_SOURCES = msgunfmt.c msgunfmt_SOURCES += \ - read-mo.c read-java.c read-csharp.c read-resources.c read-tcl.c + read-mo.c read-resources.c read-tcl.c + if !WOE32DLL xgettext_SOURCES = xgettext.c else @@ -198,8 +187,6 @@ xgettext_SOURCES += \ x-librep.c \ x-scheme.c \ x-smalltalk.c \ - x-java.c \ - x-csharp.c \ x-awk.c \ x-ycp.c \ x-tcl.c \ @@ -210,6 +197,7 @@ xgettext_SOURCES += \ x-javascript.c \ x-vala.c \ x-desktop.c + if !WOE32DLL msgattrib_SOURCES = msgattrib.c else @@ -579,88 +567,6 @@ uninstall-local: DISTCLEANFILES += user-email - -# Special rules for Java compilation. - -USEJAVA = $(USEJAVA_@BUILDJAVA@) -USEJAVA_yes = 1 -USEJAVA_no = 0 - -all-local: all-java-@BUILDJAVA@ -all-java-yes: gettext.jar -all-java-no: - -gnu/gettext/DumpResource.class: $(srcdir)/gnu/gettext/DumpResource.java - $(JAVACOMP) -d . $(srcdir)/gnu/gettext/DumpResource.java - -gnu/gettext/GetURL.class: $(srcdir)/gnu/gettext/GetURL.java - $(JAVACOMP) -d . $(srcdir)/gnu/gettext/GetURL.java - -gettext.jar: gnu/gettext/DumpResource.class gnu/gettext/GetURL.class - $(JAR) cf $@ gnu/gettext/DumpResource*.class gnu/gettext/GetURL*.class - -EXTRA_DIST += gnu/gettext/DumpResource.java gnu/gettext/GetURL.java - -CLEANFILES += gettext.jar gnu/gettext/*.class - -install-data-local: install-data-java-@BUILDJAVA@ -install-data-java-yes: all-java-yes - $(INSTALL_DATA) gettext.jar $(DESTDIR)$(jardir)/gettext.jar -install-data-java-no: - -installdirs-local: installdirs-java-@BUILDJAVA@ -installdirs-java-yes: - $(MKDIR_P) $(DESTDIR)$(jardir) -installdirs-java-no: - -uninstall-local: uninstall-java-@BUILDJAVA@ -uninstall-java-yes: - $(RM) $(DESTDIR)$(jardir)/gettext.jar -uninstall-java-no: - - -# Special rules for C# auxiliary programs. - -EXTRA_DIST += msgfmt.cs msgunfmt.cs - -CLEANFILES += \ - msgfmt.net.exe msgfmt.net.exe.mdb \ - msgunfmt.net.exe msgunfmt.net.exe.mdb - -all-local: all-csharp-@BUILDCSHARP@ -all-csharp-yes: msgfmt.net.exe msgunfmt.net.exe -all-csharp-no: - -msgfmt.net.exe: msgfmt.cs - $(CSHARPCOMP) $(CSHARPCOMPFLAGS) -o $@ $(srcdir)/msgfmt.cs - -if USE_INSTALLED_CSHARP_DLL -CSHARP_DLL_DIR = $(libdir) -else -CSHARP_DLL_DIR = ../../gettext-runtime/intl-csharp -endif -msgunfmt.net.exe: msgunfmt.cs - $(CSHARPCOMP) $(CSHARPCOMPFLAGS) -o $@ -L '$(CSHARP_DLL_DIR)' -l GNU.Gettext $(srcdir)/msgunfmt.cs - -install-exec-local: install-exec-csharp-@BUILDCSHARP@ -install-exec-csharp-yes: all-csharp-yes - $(MKDIR_P) $(DESTDIR)$(pkglibdir) - $(INSTALL_DATA) msgfmt.net.exe $(DESTDIR)$(pkglibdir)/msgfmt.net.exe - $(INSTALL_DATA) msgunfmt.net.exe $(DESTDIR)$(pkglibdir)/msgunfmt.net.exe -install-exec-csharp-no: - $(MKDIR_P) $(DESTDIR)$(pkglibdir) - -installdirs-local: install-csharp -installdirs-csharp: - $(MKDIR_P) $(DESTDIR)$(pkglibdir) - -uninstall-local: uninstall-csharp-@BUILDCSHARP@ -uninstall-csharp-yes: all-csharp-yes - $(RM) $(DESTDIR)$(pkglibdir)/msgfmt.net.exe - $(RM) $(DESTDIR)$(pkglibdir)/msgunfmt.net.exe -uninstall-csharp-no: - - # Special rules for Tcl auxiliary program. EXTRA_DIST += msgunfmt.tcl diff --git a/gettext-tools/src/format-csharp.c b/gettext-tools/src/format-csharp.c deleted file mode 100644 index 049a1fcaf..000000000 --- a/gettext-tools/src/format-csharp.c +++ /dev/null @@ -1,290 +0,0 @@ -/* C# format strings. - Copyright (C) 2003-2004, 2006-2007, 2009, 2018-2019 Free Software Foundation, Inc. - Written by Bruno Haible , 2003. - - This program 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 3 of the License, or - (at your option) any later version. - - This program 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 this program. If not, see . */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include -#include - -#include "format.h" -#include "c-ctype.h" -#include "xalloc.h" -#include "xvasprintf.h" -#include "gettext.h" - -#define _(str) gettext (str) - -/* C# format strings are described in the description of the .NET System.String - class and implemented in mcs-0.28/class/corlib/System/String.cs . - A format string consists of literal text (that is output verbatim), doubled - braces ('{{' and '}}', that lead to a single brace when output), and - directives. - A directive - - starts with '{', - - is followed by a nonnegative integer m, - - is optionally followed by ',' and an integer denoting a width, - - is optionally followed by ':' and a sequence of format specifiers. - (But the interpretation of the format specifiers is up to the IFormattable - implementation, depending on the argument's runtime value. New classes - implementing IFormattable can be defined by the user.) - - is finished with '}'. - */ - -struct spec -{ - unsigned int directives; - unsigned int numbered_arg_count; -}; - -static void * -format_parse (const char *format, bool translated, char *fdi, - char **invalid_reason) -{ - const char *const format_start = format; - struct spec spec; - struct spec *result; - - spec.directives = 0; - spec.numbered_arg_count = 0; - - for (; *format != '\0';) - { - char c = *format++; - - if (c == '{') - { - FDI_SET (format - 1, FMTDIR_START); - if (*format == '{') - format++; - else - { - /* A directive. */ - unsigned int number; - - spec.directives++; - - if (!c_isdigit (*format)) - { - *invalid_reason = - xasprintf (_("In the directive number %u, '{' is not followed by an argument number."), spec.directives); - FDI_SET (*format == '\0' ? format - 1 : format, FMTDIR_ERROR); - return NULL; - } - number = 0; - do - { - number = 10 * number + (*format - '0'); - format++; - } - while (c_isdigit (*format)); - - if (*format == ',') - { - /* Parse width. */ - format++; - if (*format == '-') - format++; - if (!c_isdigit (*format)) - { - *invalid_reason = - xasprintf (_("In the directive number %u, ',' is not followed by a number."), spec.directives); - FDI_SET (*format == '\0' ? format - 1 : format, - FMTDIR_ERROR); - return NULL; - } - do - format++; - while (c_isdigit (*format)); - } - - if (*format == ':') - { - /* Parse format specifiers. */ - do - format++; - while (*format != '\0' && *format != '}'); - } - - if (*format == '\0') - { - *invalid_reason = - xstrdup (_("The string ends in the middle of a directive: found '{' without matching '}'.")); - FDI_SET (format - 1, FMTDIR_ERROR); - return NULL; - } - - if (*format != '}') - { - *invalid_reason = - (c_isprint (*format) - ? xasprintf (_("The directive number %u ends with an invalid character '%c' instead of '}'."), spec.directives, *format) - : xasprintf (_("The directive number %u ends with an invalid character instead of '}'."), spec.directives)); - FDI_SET (format, FMTDIR_ERROR); - return NULL; - } - - format++; - - if (spec.numbered_arg_count <= number) - spec.numbered_arg_count = number + 1; - } - FDI_SET (format - 1, FMTDIR_END); - } - else if (c == '}') - { - FDI_SET (format - 1, FMTDIR_START); - if (*format == '}') - format++; - else - { - *invalid_reason = - (spec.directives == 0 - ? xstrdup (_("The string starts in the middle of a directive: found '}' without matching '{'.")) - : xasprintf (_("The string contains a lone '}' after directive number %u."), spec.directives)); - FDI_SET (*format == '\0' ? format - 1 : format, FMTDIR_ERROR); - return NULL; - } - FDI_SET (format - 1, FMTDIR_END); - } - } - - result = XMALLOC (struct spec); - *result = spec; - return result; -} - -static void -format_free (void *descr) -{ - struct spec *spec = (struct spec *) descr; - - free (spec); -} - -static int -format_get_number_of_directives (void *descr) -{ - struct spec *spec = (struct spec *) descr; - - return spec->directives; -} - -static bool -format_check (void *msgid_descr, void *msgstr_descr, bool equality, - formatstring_error_logger_t error_logger, - const char *pretty_msgid, const char *pretty_msgstr) -{ - struct spec *spec1 = (struct spec *) msgid_descr; - struct spec *spec2 = (struct spec *) msgstr_descr; - bool err = false; - - /* Check that the argument counts are the same. */ - if (equality - ? spec1->numbered_arg_count != spec2->numbered_arg_count - : spec1->numbered_arg_count < spec2->numbered_arg_count) - { - if (error_logger) - error_logger (_("number of format specifications in '%s' and '%s' does not match"), - pretty_msgid, pretty_msgstr); - err = true; - } - - return err; -} - - -struct formatstring_parser formatstring_csharp = -{ - format_parse, - format_free, - format_get_number_of_directives, - NULL, - format_check -}; - - -#ifdef TEST - -/* Test program: Print the argument list specification returned by - format_parse for strings read from standard input. */ - -#include - -static void -format_print (void *descr) -{ - struct spec *spec = (struct spec *) descr; - unsigned int i; - - if (spec == NULL) - { - printf ("INVALID"); - return; - } - - printf ("("); - for (i = 0; i < spec->numbered_arg_count; i++) - { - if (i > 0) - printf (" "); - printf ("*"); - } - printf (")"); -} - -int -main () -{ - for (;;) - { - char *line = NULL; - size_t line_size = 0; - int line_len; - char *invalid_reason; - void *descr; - - line_len = getline (&line, &line_size, stdin); - if (line_len < 0) - break; - if (line_len > 0 && line[line_len - 1] == '\n') - line[--line_len] = '\0'; - - invalid_reason = NULL; - descr = format_parse (line, false, NULL, &invalid_reason); - - format_print (descr); - printf ("\n"); - if (descr == NULL) - printf ("%s\n", invalid_reason); - - free (invalid_reason); - free (line); - } - - return 0; -} - -/* - * For Emacs M-x compile - * Local Variables: - * compile-command: "/bin/sh ../libtool --tag=CC --mode=link gcc -o a.out -static -O -g -Wall -I.. -I../gnulib-lib -I../../gettext-runtime/intl -DHAVE_CONFIG_H -DTEST format-csharp.c ../gnulib-lib/libgettextlib.la" - * End: - */ - -#endif /* TEST */ diff --git a/gettext-tools/src/format-java-printf.c b/gettext-tools/src/format-java-printf.c deleted file mode 100644 index d0f133c1a..000000000 --- a/gettext-tools/src/format-java-printf.c +++ /dev/null @@ -1,725 +0,0 @@ -/* Java printf format strings. - Copyright (C) 2001-2004, 2006-2007, 2009-2010, 2018-2019 Free Software - Foundation, Inc. - Written by Bruno Haible , 2001. - - This program 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 3 of the License, or - (at your option) any later version. - - This program 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 this program. If not, see . */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include -#include - -#include "format.h" -#include "c-ctype.h" -#include "xalloc.h" -#include "xvasprintf.h" -#include "format-invalid.h" -#include "gettext.h" - -#define _(str) gettext (str) - -/* Java printf format strings are described in java/util/Formatter.html. - A directive - - starts with '%' or '%<' or '%m$' where m is a positive integer, - - is optionally followed by any of the characters '#', '0', '-', ' ', '+', - ',', '(', - - is optionally followed by a width specification: a nonempty digit sequence, - - is optionally followed by '.' and a precision specification: a nonempty - digit sequence, - - is finished by a specifier - - '%', 'n', that need no argument, - Restrictions: - - For '%': flags other than '-' are invalid, and a precision is - invalid. - - For 'n': flags, width, and precision are invalid. - - 'b', 'B', 'h', 'H', 's', 'S', that need a general argument. - Restrictions: - Flags other than '#' and '-' are invalid. - - 'c', 'C', that need a character argument, - Restrictions: - Flags other than '-' are invalid. - A precision is invalid. - - 'd', 'o', 'x', 'X', that need an integer argument, - Restrictions: - - For 'd': The flag '#' is invalid. - - For 'o', 'x', 'X': The flag ',' is invalid. - A precision is invalid. - - 'e', 'E', 'f', 'g', 'G', 'a', 'A', that need a floating-point argument, - Restrictions: - - For 'a', 'A': The flags ',', '(' are invalid. - - 't', 'T', followed by one of - 'H', 'I', 'k', 'l', 'M', 'S', 'L', 'N', 'p', 'z', 'Z', 's', 'Q', - 'B', 'b', 'h', 'A', 'a', 'C', 'Y', 'y', 'j', 'm', 'd', 'e', - 'R', 'T', 'r', 'D', 'F', 'c' - that need a date/time argument. - Restrictions: - Flags other than '-' are invalid. - A precision is invalid. - Numbered ('%m$') and unnumbered argument specifications can be mixed in the - same string. Numbered argument specifications have no influence on the - unnumbered argument counter. - */ - -enum format_arg_type -{ - FAT_NONE = 0, - /* Basic types */ - FAT_GENERAL = 1, - FAT_CHARACTER = 2, - FAT_INTEGER = 3, - FAT_FLOATINGPOINT = 4, - FAT_DATETIME = 5 -}; -#ifdef __cplusplus -typedef int format_arg_type_t; -#else -typedef enum format_arg_type format_arg_type_t; -#endif - -enum -{ - /* Flags */ - FAT_ALTERNATE = 1 << 0, /* '#' */ - FAT_ZERO_PADDED = 1 << 1, /* '0' */ - FAT_LEFT_JUSTIFIED = 1 << 2, /* '-' */ - FAT_SPACE_SIGN = 1 << 3, /* ' ' */ - FAT_SIGN = 1 << 4, /* '+' */ - FAT_OBEY_LOCALE = 1 << 5, /* ',' */ - FAT_MONETARY = 1 << 6, /* '(' */ - /* Width */ - FAT_WIDTH = 1 << 7, - /* Precision */ - FAT_PRECISION = 1 << 8, -}; - -struct numbered_arg -{ - unsigned int number; - format_arg_type_t type; -}; - -struct spec -{ - unsigned int directives; - unsigned int numbered_arg_count; - unsigned int allocated; - struct numbered_arg *numbered; -}; - -/* Locale independent test for a decimal digit. - Argument can be 'char' or 'unsigned char'. (Whereas the argument of - isdigit must be an 'unsigned char'.) */ -#undef isdigit -#define isdigit(c) ((unsigned int) ((c) - '0') < 10) - - -static int -numbered_arg_compare (const void *p1, const void *p2) -{ - unsigned int n1 = ((const struct numbered_arg *) p1)->number; - unsigned int n2 = ((const struct numbered_arg *) p2)->number; - - return (n1 > n2 ? 1 : n1 < n2 ? -1 : 0); -} - -#define INVALID_LAST_ARG(directive_number) \ - xasprintf (_("In the directive number %u, the reference to the argument of the previous directive is invalid."), directive_number) - -#define INVALID_PRECISION_MISSING(directive_number) \ - xasprintf (_("In the directive number %u, the precision is missing."), directive_number) - -#define INVALID_FLAG_FOR(directive_number,flag_char,conv_char) \ - xasprintf (_("In the directive number %u, the flag '%c' is invalid for the conversion '%c'."), directive_number, flag_char, conv_char) - -#define INVALID_WIDTH_FOR(directive_number,conv_char) \ - xasprintf (_("In the directive number %u, a width is invalid for the conversion '%c'."), directive_number, conv_char) - -#define INVALID_PRECISION_FOR(directive_number,conv_char) \ - xasprintf (_("In the directive number %u, a precision is invalid for the conversion '%c'."), directive_number, conv_char) - -#define INVALID_DATETIME_CONVERSION_SUFFIX(directive_number,conv_char,suffix_char) \ - (c_isprint (conv_char) \ - ? xasprintf (_("In the directive number %u, for the conversion '%c', the character '%c' is not a valid conversion suffix."), directive_number, conv_char, suffix_char) \ - : xasprintf (_("The character that terminates the directive number %u, for the conversion '%c', is not a valid conversion suffix."), directive_number, conv_char)) - -static void * -format_parse (const char *format, bool translated, char *fdi, - char **invalid_reason) -{ - const char *const format_start = format; - struct spec spec; - struct spec *result; - unsigned int unnumbered_arg_count; - unsigned int last_arg_number; - - spec.directives = 0; - spec.numbered_arg_count = 0; - spec.allocated = 0; - spec.numbered = NULL; - unnumbered_arg_count = 0; - last_arg_number = 0; - - for (; *format != '\0';) - if (*format++ == '%') - { - /* A directive. */ - unsigned int number = 0; - unsigned int flags; - format_arg_type_t type; - unsigned int invalid_flags; - - FDI_SET (format - 1, FMTDIR_START); - spec.directives++; - - if (*format == '<') - { - if (last_arg_number == 0) - { - *invalid_reason = INVALID_LAST_ARG (spec.directives); - FDI_SET (format, FMTDIR_ERROR); - goto bad_format; - } - number = last_arg_number; - format++; - } - else if (isdigit (*format)) - { - const char *f = format; - unsigned int m = 0; - - do - { - m = 10 * m + (*f - '0'); - f++; - } - while (isdigit (*f)); - - if (*f == '$') - { - if (m == 0) - { - *invalid_reason = INVALID_ARGNO_0 (spec.directives); - FDI_SET (f, FMTDIR_ERROR); - goto bad_format; - } - number = m; - format = ++f; - } - } - - flags = 0; - - /* Parse flags. */ - for (;;) - { - if (*format == '#') - { - flags |= FAT_ALTERNATE; - format++; - } - else if (*format == '0') - { - flags |= FAT_ZERO_PADDED; - format++; - } - else if (*format == '-') - { - flags |= FAT_LEFT_JUSTIFIED; - format++; - } - else if (*format == ' ') - { - flags |= FAT_SPACE_SIGN; - format++; - } - else if (*format == '+') - { - flags |= FAT_SIGN; - format++; - } - else if (*format == ',') - { - flags |= FAT_OBEY_LOCALE; - format++; - } - else if (*format == '(') - { - flags |= FAT_MONETARY; - format++; - } - else - break; - } - - /* Parse width. */ - if (isdigit (*format)) - { - do format++; while (isdigit (*format)); - flags |= FAT_WIDTH; - } - - /* Parse precision. */ - if (*format == '.') - { - format++; - - if (!isdigit (*format)) - { - if (*format == '\0') - { - *invalid_reason = INVALID_UNTERMINATED_DIRECTIVE (); - FDI_SET (format - 1, FMTDIR_ERROR); - } - else - { - *invalid_reason = INVALID_PRECISION_MISSING (spec.directives); - FDI_SET (format, FMTDIR_ERROR); - } - goto bad_format; - } - - do format++; while (isdigit (*format)); - flags |= FAT_PRECISION; - } - - /* Parse conversion. */ - switch (*format) - { - case '%': - type = FAT_NONE; - invalid_flags = (FAT_ALTERNATE | FAT_ZERO_PADDED | FAT_SPACE_SIGN - | FAT_SIGN | FAT_OBEY_LOCALE | FAT_MONETARY) - | FAT_PRECISION; - break; - case 'n': - type = FAT_NONE; - invalid_flags = (FAT_ALTERNATE | FAT_ZERO_PADDED | FAT_LEFT_JUSTIFIED - | FAT_SPACE_SIGN | FAT_SIGN | FAT_OBEY_LOCALE - | FAT_MONETARY) - | FAT_WIDTH | FAT_PRECISION; - break; - case 'b': case 'B': - case 'h': case 'H': - case 's': case 'S': - type = FAT_GENERAL; - invalid_flags = (FAT_ZERO_PADDED | FAT_SPACE_SIGN | FAT_SIGN - | FAT_OBEY_LOCALE | FAT_MONETARY); - break; - case 'c': case 'C': - type = FAT_CHARACTER; - invalid_flags = (FAT_ALTERNATE | FAT_ZERO_PADDED | FAT_SPACE_SIGN - | FAT_SIGN | FAT_OBEY_LOCALE | FAT_MONETARY) - | FAT_PRECISION; - break; - case 'd': - type = FAT_INTEGER; - invalid_flags = FAT_ALTERNATE | FAT_PRECISION; - break; - case 'o': case 'x': case 'X': - type = FAT_INTEGER; - invalid_flags = FAT_OBEY_LOCALE | FAT_PRECISION; - break; - case 'e': case 'E': - case 'f': - case 'g': case 'G': - type = FAT_FLOATINGPOINT; - invalid_flags = 0; - break; - case 'a': case 'A': - type = FAT_FLOATINGPOINT; - invalid_flags = FAT_OBEY_LOCALE | FAT_MONETARY; - break; - case 't': case 'T': - type = FAT_DATETIME; - invalid_flags = (FAT_ALTERNATE | FAT_ZERO_PADDED | FAT_SPACE_SIGN - | FAT_SIGN | FAT_OBEY_LOCALE | FAT_MONETARY) - | FAT_PRECISION; - break; - default: - if (*format == '\0') - { - *invalid_reason = INVALID_UNTERMINATED_DIRECTIVE (); - FDI_SET (format - 1, FMTDIR_ERROR); - } - else - { - *invalid_reason = - INVALID_CONVERSION_SPECIFIER (spec.directives, *format); - FDI_SET (format, FMTDIR_ERROR); - } - goto bad_format; - } - - /* Report invalid flags, width, precision. */ - invalid_flags &= flags; - if (invalid_flags & FAT_ALTERNATE) - { - *invalid_reason = INVALID_FLAG_FOR (spec.directives, '#', *format); - FDI_SET (format, FMTDIR_ERROR); - goto bad_format; - } - if (invalid_flags & FAT_ZERO_PADDED) - { - *invalid_reason = INVALID_FLAG_FOR (spec.directives, '0', *format); - FDI_SET (format, FMTDIR_ERROR); - goto bad_format; - } - if (invalid_flags & FAT_LEFT_JUSTIFIED) - { - *invalid_reason = INVALID_FLAG_FOR (spec.directives, '-', *format); - FDI_SET (format, FMTDIR_ERROR); - goto bad_format; - } - if (invalid_flags & FAT_SPACE_SIGN) - { - *invalid_reason = INVALID_FLAG_FOR (spec.directives, ' ', *format); - FDI_SET (format, FMTDIR_ERROR); - goto bad_format; - } - if (invalid_flags & FAT_SIGN) - { - *invalid_reason = INVALID_FLAG_FOR (spec.directives, '+', *format); - FDI_SET (format, FMTDIR_ERROR); - goto bad_format; - } - if (invalid_flags & FAT_OBEY_LOCALE) - { - *invalid_reason = INVALID_FLAG_FOR (spec.directives, ',', *format); - FDI_SET (format, FMTDIR_ERROR); - goto bad_format; - } - if (invalid_flags & FAT_MONETARY) - { - *invalid_reason = INVALID_FLAG_FOR (spec.directives, '(', *format); - FDI_SET (format, FMTDIR_ERROR); - goto bad_format; - } - if (invalid_flags & FAT_WIDTH) - { - *invalid_reason = INVALID_WIDTH_FOR (spec.directives, *format); - FDI_SET (format, FMTDIR_ERROR); - goto bad_format; - } - if (invalid_flags & FAT_PRECISION) - { - *invalid_reason = INVALID_PRECISION_FOR (spec.directives, *format); - FDI_SET (format, FMTDIR_ERROR); - goto bad_format; - } - - if (type == FAT_DATETIME) - { - format++; - - /* Parse conversion suffix. */ - switch (*format) - { - case 'H': case 'I': case 'k': case 'l': case 'M': case 'S': - case 'L': case 'N': case 'p': case 'z': case 'Z': case 's': - case 'Q': - case 'B': case 'b': case 'h': case 'A': case 'a': case 'C': - case 'Y': case 'y': case 'j': case 'm': case 'd': case 'e': - case 'R': case 'T': case 'r': case 'D': case 'F': case 'c': - break; - default: - if (*format == '\0') - { - *invalid_reason = INVALID_UNTERMINATED_DIRECTIVE (); - FDI_SET (format - 1, FMTDIR_ERROR); - } - else - { - *invalid_reason = - INVALID_DATETIME_CONVERSION_SUFFIX (spec.directives, - format[-1], *format); - FDI_SET (format, FMTDIR_ERROR); - } - goto bad_format; - } - } - - if (type != FAT_NONE) - { - if (number == 0) - number = ++unnumbered_arg_count; - - if (spec.allocated == spec.numbered_arg_count) - { - spec.allocated = 2 * spec.allocated + 1; - spec.numbered = (struct numbered_arg *) xrealloc (spec.numbered, spec.allocated * sizeof (struct numbered_arg)); - } - spec.numbered[spec.numbered_arg_count].number = number; - spec.numbered[spec.numbered_arg_count].type = type; - spec.numbered_arg_count++; - - last_arg_number = number; - } - - FDI_SET (format, FMTDIR_END); - - format++; - } - - /* Sort the numbered argument array, and eliminate duplicates. */ - if (spec.numbered_arg_count > 1) - { - unsigned int i, j; - bool err; - - qsort (spec.numbered, spec.numbered_arg_count, - sizeof (struct numbered_arg), numbered_arg_compare); - - /* Remove duplicates: Copy from i to j, keeping 0 <= j <= i. */ - err = false; - for (i = j = 0; i < spec.numbered_arg_count; i++) - if (j > 0 && spec.numbered[i].number == spec.numbered[j-1].number) - { - enum format_arg_type type1 = spec.numbered[i].type; - enum format_arg_type type2 = spec.numbered[j-1].type; - enum format_arg_type type_both; - - if (type1 == type2) - type_both = type1; - else - { - /* Incompatible types. */ - type_both = FAT_NONE; - if (!err) - *invalid_reason = - INVALID_INCOMPATIBLE_ARG_TYPES (spec.numbered[i].number); - err = true; - } - - spec.numbered[j-1].type = type_both; - } - else - { - if (j < i) - { - spec.numbered[j].number = spec.numbered[i].number; - spec.numbered[j].type = spec.numbered[i].type; - } - j++; - } - spec.numbered_arg_count = j; - if (err) - /* *invalid_reason has already been set above. */ - goto bad_format; - } - - result = XMALLOC (struct spec); - *result = spec; - return result; - - bad_format: - if (spec.numbered != NULL) - free (spec.numbered); - return NULL; -} - -static void -format_free (void *descr) -{ - struct spec *spec = (struct spec *) descr; - - if (spec->numbered != NULL) - free (spec->numbered); - free (spec); -} - -static int -format_get_number_of_directives (void *descr) -{ - struct spec *spec = (struct spec *) descr; - - return spec->directives; -} - -static bool -format_check (void *msgid_descr, void *msgstr_descr, bool equality, - formatstring_error_logger_t error_logger, - const char *pretty_msgid, const char *pretty_msgstr) -{ - struct spec *spec1 = (struct spec *) msgid_descr; - struct spec *spec2 = (struct spec *) msgstr_descr; - bool err = false; - - if (spec1->numbered_arg_count + spec2->numbered_arg_count > 0) - { - unsigned int i, j; - unsigned int n1 = spec1->numbered_arg_count; - unsigned int n2 = spec2->numbered_arg_count; - - /* Check the argument names are the same. - Both arrays are sorted. We search for the first difference. */ - for (i = 0, j = 0; i < n1 || j < n2; ) - { - int cmp = (i >= n1 ? 1 : - j >= n2 ? -1 : - spec1->numbered[i].number > spec2->numbered[j].number ? 1 : - spec1->numbered[i].number < spec2->numbered[j].number ? -1 : - 0); - - if (cmp > 0) - { - if (error_logger) - error_logger (_("a format specification for argument %u, as in '%s', doesn't exist in '%s'"), - spec2->numbered[j].number, pretty_msgstr, - pretty_msgid); - err = true; - break; - } - else if (cmp < 0) - { - if (equality) - { - if (error_logger) - error_logger (_("a format specification for argument %u doesn't exist in '%s'"), - spec1->numbered[i].number, pretty_msgstr); - err = true; - break; - } - else - i++; - } - else - j++, i++; - } - /* Check the argument types are the same. */ - if (!err) - for (i = 0, j = 0; j < n2; ) - { - if (spec1->numbered[i].number == spec2->numbered[j].number) - { - if (spec1->numbered[i].type != spec2->numbered[j].type) - { - if (error_logger) - error_logger (_("format specifications in '%s' and '%s' for argument %u are not the same"), - pretty_msgid, pretty_msgstr, - spec2->numbered[j].number); - err = true; - break; - } - j++, i++; - } - else - i++; - } - } - - return err; -} - - -struct formatstring_parser formatstring_java_printf = -{ - format_parse, - format_free, - format_get_number_of_directives, - NULL, - format_check -}; - - -#ifdef TEST - -/* Test program: Print the argument list specification returned by - format_parse for strings read from standard input. */ - -#include - -static void -format_print (void *descr) -{ - struct spec *spec = (struct spec *) descr; - unsigned int i; - - if (spec == NULL) - { - printf ("INVALID"); - return; - } - - printf ("("); - for (i = 0; i < spec->numbered_arg_count; i++) - { - if (i > 0) - printf (" "); - switch (spec->numbered[i].type) - { - case FAT_GENERAL: - printf ("s"); - break; - case FAT_CHARACTER: - printf ("c"); - break; - case FAT_INTEGER: - printf ("d"); - break; - case FAT_FLOATINGPOINT: - printf ("f"); - break; - case FAT_DATETIME: - printf ("t"); - break; - default: - abort (); - } - } - printf (")"); -} - -int -main () -{ - for (;;) - { - char *line = NULL; - size_t line_size = 0; - int line_len; - char *invalid_reason; - void *descr; - - line_len = getline (&line, &line_size, stdin); - if (line_len < 0) - break; - if (line_len > 0 && line[line_len - 1] == '\n') - line[--line_len] = '\0'; - - invalid_reason = NULL; - descr = format_parse (line, false, NULL, &invalid_reason); - - format_print (descr); - printf ("\n"); - if (descr == NULL) - printf ("%s\n", invalid_reason); - - free (invalid_reason); - free (line); - } - - return 0; -} - -/* - * For Emacs M-x compile - * Local Variables: - * compile-command: "/bin/sh ../libtool --tag=CC --mode=link gcc -o a.out -static -O -g -Wall -I.. -I../gnulib-lib -I../../gettext-runtime/intl -DHAVE_CONFIG_H -DTEST format-java-printf.c ../gnulib-lib/libgettextlib.la" - * End: - */ - -#endif /* TEST */ diff --git a/gettext-tools/src/format-java.c b/gettext-tools/src/format-java.c deleted file mode 100644 index cd117850e..000000000 --- a/gettext-tools/src/format-java.c +++ /dev/null @@ -1,894 +0,0 @@ -/* Java MessageFormat format strings. - Copyright (C) 2001-2004, 2006-2007, 2009, 2019 Free Software Foundation, Inc. - Written by Bruno Haible , 2001. - - This program 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 3 of the License, or - (at your option) any later version. - - This program 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 this program. If not, see . */ - -#ifdef HAVE_CONFIG_H -# include -#endif -#include - -#include -#include -#include - -#include "format.h" -#include "c-ctype.h" -#include "xalloc.h" -#include "xmalloca.h" -#include "xvasprintf.h" -#include "format-invalid.h" -#include "gettext.h" - -#define _(str) gettext (str) - -/* Java MessageFormat format strings are described in - java/text/MessageFormat.html. - See also the ICU documentation class_MessageFormat.html. - - messageFormatPattern := string ( "{" messageFormatElement "}" string )* - - messageFormatElement := argument { "," elementFormat } - - elementFormat := "time" { "," datetimeStyle } - | "date" { "," datetimeStyle } - | "number" { "," numberStyle } - | "choice" { "," choiceStyle } - - datetimeStyle := "short" - | "medium" - | "long" - | "full" - | dateFormatPattern - - numberStyle := "currency" - | "percent" - | "integer" - | numberFormatPattern - - choiceStyle := choiceFormatPattern - - dateFormatPattern see SimpleDateFormat.applyPattern - - numberFormatPattern see DecimalFormat.applyPattern - - choiceFormatPattern see ChoiceFormat constructor - - In strings, literal curly braces can be used if quoted between single - quotes. A real single quote is represented by ''. - - If a pattern is used, then unquoted braces in the pattern, if any, must - match: that is, "ab {0} de" and "ab '}' de" are ok, but "ab {0'}' de" and - "ab } de" are not. - - The argument is a number from 0 to 9, which corresponds to the arguments - presented in an array to be formatted. - - It is ok to have unused arguments in the array. - - Adding a dateFormatPattern / numberFormatPattern / choiceFormatPattern - to an elementFormat is equivalent to creating a SimpleDateFormat / - DecimalFormat / ChoiceFormat and use of setFormat. For example, - - MessageFormat form = - new MessageFormat("The disk \"{1}\" contains {0,choice,0#no files|1#one file|2#{0,number} files}."); - - is equivalent to - - MessageFormat form = new MessageFormat("The disk \"{1}\" contains {0}."); - form.setFormat(1, // Number of {} occurrence in the string! - new ChoiceFormat(new double[] { 0, 1, 2 }, - new String[] { "no files", "one file", - "{0,number} files" })); - - Note: The behaviour of quotes inside a choiceFormatPattern is not clear. - Example 1: - "abc{1,choice,0#{1,number,00';'000}}def" - JDK 1.1.x: exception - JDK 1.3.x: behaves like "abc{1,choice,0#{1,number,00;000}}def" - Example 2: - "abc{1,choice,0#{1,number,00';'}}def" - JDK 1.1.x: interprets the semicolon as number suffix - JDK 1.3.x: behaves like "abc{1,choice,0#{1,number,00;}}def" - */ - -enum format_arg_type -{ - FAT_NONE, - FAT_OBJECT, /* java.lang.Object */ - FAT_NUMBER, /* java.lang.Number */ - FAT_DATE /* java.util.Date */ -}; - -struct numbered_arg -{ - unsigned int number; - enum format_arg_type type; -}; - -struct spec -{ - unsigned int directives; - unsigned int numbered_arg_count; - unsigned int allocated; - struct numbered_arg *numbered; -}; - - -/* Forward declaration of local functions. */ -static bool date_format_parse (const char *format); -static bool number_format_parse (const char *format); -static bool choice_format_parse (const char *format, struct spec *spec, - char **invalid_reason); - - -/* Quote handling: - - When we see a single-quote, ignore it, but toggle the quoting flag. - - When we see a double single-quote, ignore the first of the two. - Assumes local variables format, quoting. */ -#define HANDLE_QUOTE \ - if (*format == '\'' && *++format != '\'') \ - quoting = !quoting; - -/* Note that message_format_parse and choice_format_parse are mutually - recursive. This is because MessageFormat can use some ChoiceFormats, - and a ChoiceFormat is made up from several MessageFormats. */ - -/* Return true if a format is a valid messageFormatPattern. - Extracts argument type information into spec. */ -static bool -message_format_parse (const char *format, char *fdi, struct spec *spec, - char **invalid_reason) -{ - const char *const format_start = format; - bool quoting = false; - - for (;;) - { - HANDLE_QUOTE; - if (!quoting && *format == '{') - { - unsigned int depth; - const char *element_start; - const char *element_end; - size_t n; - char *element_alloced; - char *element; - unsigned int number; - enum format_arg_type type; - - FDI_SET (format, FMTDIR_START); - spec->directives++; - - element_start = ++format; - depth = 0; - for (; *format != '\0'; format++) - { - if (*format == '{') - depth++; - else if (*format == '}') - { - if (depth == 0) - break; - else - depth--; - } - } - if (*format == '\0') - { - *invalid_reason = - xstrdup (_("The string ends in the middle of a directive: found '{' without matching '}'.")); - FDI_SET (format - 1, FMTDIR_ERROR); - return false; - } - element_end = format++; - - n = element_end - element_start; - element = element_alloced = (char *) xmalloca (n + 1); - memcpy (element, element_start, n); - element[n] = '\0'; - - if (!c_isdigit (*element)) - { - *invalid_reason = - xasprintf (_("In the directive number %u, '{' is not followed by an argument number."), spec->directives); - FDI_SET (format - 1, FMTDIR_ERROR); - freea (element_alloced); - return false; - } - number = 0; - do - { - number = 10 * number + (*element - '0'); - element++; - } - while (c_isdigit (*element)); - - type = FAT_OBJECT; - if (*element == '\0') - ; - else if (strncmp (element, ",time", 5) == 0 - || strncmp (element, ",date", 5) == 0) - { - type = FAT_DATE; - element += 5; - if (*element == '\0') - ; - else if (*element == ',') - { - element++; - if (strcmp (element, "short") == 0 - || strcmp (element, "medium") == 0 - || strcmp (element, "long") == 0 - || strcmp (element, "full") == 0 - || date_format_parse (element)) - ; - else - { - *invalid_reason = - xasprintf (_("In the directive number %u, the substring \"%s\" is not a valid date/time style."), spec->directives, element); - FDI_SET (format - 1, FMTDIR_ERROR); - freea (element_alloced); - return false; - } - } - else - { - *element = '\0'; - element -= 4; - *invalid_reason = - xasprintf (_("In the directive number %u, \"%s\" is not followed by a comma."), spec->directives, element); - FDI_SET (format - 1, FMTDIR_ERROR); - freea (element_alloced); - return false; - } - } - else if (strncmp (element, ",number", 7) == 0) - { - type = FAT_NUMBER; - element += 7; - if (*element == '\0') - ; - else if (*element == ',') - { - element++; - if (strcmp (element, "currency") == 0 - || strcmp (element, "percent") == 0 - || strcmp (element, "integer") == 0 - || number_format_parse (element)) - ; - else - { - *invalid_reason = - xasprintf (_("In the directive number %u, the substring \"%s\" is not a valid number style."), spec->directives, element); - FDI_SET (format - 1, FMTDIR_ERROR); - freea (element_alloced); - return false; - } - } - else - { - *element = '\0'; - element -= 6; - *invalid_reason = - xasprintf (_("In the directive number %u, \"%s\" is not followed by a comma."), spec->directives, element); - FDI_SET (format - 1, FMTDIR_ERROR); - freea (element_alloced); - return false; - } - } - else if (strncmp (element, ",choice", 7) == 0) - { - type = FAT_NUMBER; /* because ChoiceFormat extends NumberFormat */ - element += 7; - if (*element == '\0') - ; - else if (*element == ',') - { - element++; - if (choice_format_parse (element, spec, invalid_reason)) - ; - else - { - FDI_SET (format - 1, FMTDIR_ERROR); - freea (element_alloced); - return false; - } - } - else - { - *element = '\0'; - element -= 6; - *invalid_reason = - xasprintf (_("In the directive number %u, \"%s\" is not followed by a comma."), spec->directives, element); - FDI_SET (format - 1, FMTDIR_ERROR); - freea (element_alloced); - return false; - } - } - else - { - *invalid_reason = - xasprintf (_("In the directive number %u, the argument number is not followed by a comma and one of \"%s\", \"%s\", \"%s\", \"%s\"."), spec->directives, "time", "date", "number", "choice"); - FDI_SET (format - 1, FMTDIR_ERROR); - freea (element_alloced); - return false; - } - freea (element_alloced); - - if (spec->allocated == spec->numbered_arg_count) - { - spec->allocated = 2 * spec->allocated + 1; - spec->numbered = (struct numbered_arg *) xrealloc (spec->numbered, spec->allocated * sizeof (struct numbered_arg)); - } - spec->numbered[spec->numbered_arg_count].number = number; - spec->numbered[spec->numbered_arg_count].type = type; - spec->numbered_arg_count++; - - FDI_SET (format - 1, FMTDIR_END); - } - /* The doc says "ab}de" is invalid. Even though JDK accepts it. */ - else if (!quoting && *format == '}') - { - FDI_SET (format, FMTDIR_START); - *invalid_reason = - xstrdup (_("The string starts in the middle of a directive: found '}' without matching '{'.")); - FDI_SET (format, FMTDIR_ERROR); - return false; - } - else if (*format != '\0') - format++; - else - break; - } - - return true; -} - -/* Return true if a format is a valid dateFormatPattern. */ -static bool -date_format_parse (const char *format) -{ - /* Any string is valid. Single-quote starts a quoted section, to be - terminated at the next single-quote or string end. Double single-quote - gives a single single-quote. Non-quoted ASCII letters are first grouped - into blocks of equal letters. Then each block (e.g. 'yyyy') is - interpreted according to some rules. */ - return true; -} - -/* Return true if a format is a valid numberFormatPattern. */ -static bool -number_format_parse (const char *format) -{ - /* Pattern Syntax: - pattern := pos_pattern{';' neg_pattern} - pos_pattern := {prefix}number{suffix} - neg_pattern := {prefix}number{suffix} - number := integer{'.' fraction}{exponent} - prefix := '\u0000'..'\uFFFD' - special_characters - suffix := '\u0000'..'\uFFFD' - special_characters - integer := min_int | '#' | '#' integer | '#' ',' integer - min_int := '0' | '0' min_int | '0' ',' min_int - fraction := '0'* '#'* - exponent := 'E' '0' '0'* - Notation: - X* 0 or more instances of X - { X } 0 or 1 instances of X - X | Y either X or Y - X..Y any character from X up to Y, inclusive - S - T characters in S, except those in T - Single-quote starts a quoted section, to be terminated at the next - single-quote or string end. Double single-quote gives a single - single-quote. - */ - bool quoting = false; - bool seen_semicolon = false; - - HANDLE_QUOTE; - for (;;) - { - /* Parse prefix. */ - while (*format != '\0' - && !(!quoting && (*format == '0' || *format == '#'))) - { - if (format[0] == '\\') - { - if (format[1] == 'u' - && c_isxdigit (format[2]) - && c_isxdigit (format[3]) - && c_isxdigit (format[4]) - && c_isxdigit (format[5])) - format += 6; - else - format += 2; - } - else - format += 1; - HANDLE_QUOTE; - } - - /* Parse integer. */ - if (!(!quoting && (*format == '0' || *format == '#'))) - return false; - while (!quoting && *format == '#') - { - format++; - HANDLE_QUOTE; - if (!quoting && *format == ',') - { - format++; - HANDLE_QUOTE; - } - } - while (!quoting && *format == '0') - { - format++; - HANDLE_QUOTE; - if (!quoting && *format == ',') - { - format++; - HANDLE_QUOTE; - } - } - - /* Parse fraction. */ - if (!quoting && *format == '.') - { - format++; - HANDLE_QUOTE; - while (!quoting && *format == '0') - { - format++; - HANDLE_QUOTE; - } - while (!quoting && *format == '#') - { - format++; - HANDLE_QUOTE; - } - } - - /* Parse exponent. */ - if (!quoting && *format == 'E') - { - const char *format_save = format; - format++; - HANDLE_QUOTE; - if (!quoting && *format == '0') - { - do - { - format++; - HANDLE_QUOTE; - } - while (!quoting && *format == '0'); - } - else - { - /* Back up. */ - format = format_save; - quoting = false; - } - } - - /* Parse suffix. */ - while (*format != '\0' - && (seen_semicolon || !(!quoting && *format == ';'))) - { - if (format[0] == '\\') - { - if (format[1] == 'u' - && c_isxdigit (format[2]) - && c_isxdigit (format[3]) - && c_isxdigit (format[4]) - && c_isxdigit (format[5])) - format += 6; - else - format += 2; - } - else - format += 1; - HANDLE_QUOTE; - } - - if (seen_semicolon || !(!quoting && *format == ';')) - break; - } - - return (*format == '\0'); -} - -/* Return true if a format is a valid choiceFormatPattern. - Extracts argument type information into spec. */ -static bool -choice_format_parse (const char *format, struct spec *spec, - char **invalid_reason) -{ - /* Pattern syntax: - pattern := | choice | choice '|' pattern - choice := number separator messageformat - separator := '<' | '#' | '\u2264' - Single-quote starts a quoted section, to be terminated at the next - single-quote or string end. Double single-quote gives a single - single-quote. - */ - bool quoting = false; - - HANDLE_QUOTE; - if (*format == '\0') - return true; - for (;;) - { - /* Don't bother looking too precisely into the syntax of the number. - It can contain various Unicode characters. */ - bool number_nonempty; - char *msgformat; - char *mp; - bool msgformat_valid; - - /* Parse number. */ - number_nonempty = false; - while (*format != '\0' - && !(!quoting && (*format == '<' || *format == '#' - || strncmp (format, "\\u2264", 6) == 0 - || *format == '|'))) - { - if (format[0] == '\\') - { - if (format[1] == 'u' - && c_isxdigit (format[2]) - && c_isxdigit (format[3]) - && c_isxdigit (format[4]) - && c_isxdigit (format[5])) - format += 6; - else - format += 2; - } - else - format += 1; - number_nonempty = true; - HANDLE_QUOTE; - } - - /* Short clause at end of pattern is valid and is ignored! */ - if (*format == '\0') - break; - - if (!number_nonempty) - { - *invalid_reason = - xasprintf (_("In the directive number %u, a choice contains no number."), spec->directives); - return false; - } - - if (*format == '<' || *format == '#') - format += 1; - else if (strncmp (format, "\\u2264", 6) == 0) - format += 6; - else - { - *invalid_reason = - xasprintf (_("In the directive number %u, a choice contains a number that is not followed by '<', '#' or '%s'."), spec->directives, "\\u2264"); - return false; - } - HANDLE_QUOTE; - - msgformat = (char *) xmalloca (strlen (format) + 1); - mp = msgformat; - - while (*format != '\0' && !(!quoting && *format == '|')) - { - *mp++ = *format++; - HANDLE_QUOTE; - } - *mp = '\0'; - - msgformat_valid = - message_format_parse (msgformat, NULL, spec, invalid_reason); - - freea (msgformat); - - if (!msgformat_valid) - return false; - - if (*format == '\0') - break; - - format++; - HANDLE_QUOTE; - } - - return true; -} - -static int -numbered_arg_compare (const void *p1, const void *p2) -{ - unsigned int n1 = ((const struct numbered_arg *) p1)->number; - unsigned int n2 = ((const struct numbered_arg *) p2)->number; - - return (n1 > n2 ? 1 : n1 < n2 ? -1 : 0); -} - -static void * -format_parse (const char *format, bool translated, char *fdi, - char **invalid_reason) -{ - struct spec spec; - struct spec *result; - - spec.directives = 0; - spec.numbered_arg_count = 0; - spec.allocated = 0; - spec.numbered = NULL; - - if (!message_format_parse (format, fdi, &spec, invalid_reason)) - goto bad_format; - - /* Sort the numbered argument array, and eliminate duplicates. */ - if (spec.numbered_arg_count > 1) - { - unsigned int i, j; - bool err; - - qsort (spec.numbered, spec.numbered_arg_count, - sizeof (struct numbered_arg), numbered_arg_compare); - - /* Remove duplicates: Copy from i to j, keeping 0 <= j <= i. */ - err = false; - for (i = j = 0; i < spec.numbered_arg_count; i++) - if (j > 0 && spec.numbered[i].number == spec.numbered[j-1].number) - { - enum format_arg_type type1 = spec.numbered[i].type; - enum format_arg_type type2 = spec.numbered[j-1].type; - enum format_arg_type type_both; - - if (type1 == type2 || type2 == FAT_OBJECT) - type_both = type1; - else if (type1 == FAT_OBJECT) - type_both = type2; - else - { - /* Incompatible types. */ - type_both = FAT_NONE; - if (!err) - *invalid_reason = - INVALID_INCOMPATIBLE_ARG_TYPES (spec.numbered[i].number); - err = true; - } - - spec.numbered[j-1].type = type_both; - } - else - { - if (j < i) - { - spec.numbered[j].number = spec.numbered[i].number; - spec.numbered[j].type = spec.numbered[i].type; - } - j++; - } - spec.numbered_arg_count = j; - if (err) - /* *invalid_reason has already been set above. */ - goto bad_format; - } - - result = XMALLOC (struct spec); - *result = spec; - return result; - - bad_format: - if (spec.numbered != NULL) - free (spec.numbered); - return NULL; -} - -static void -format_free (void *descr) -{ - struct spec *spec = (struct spec *) descr; - - if (spec->numbered != NULL) - free (spec->numbered); - free (spec); -} - -static int -format_get_number_of_directives (void *descr) -{ - struct spec *spec = (struct spec *) descr; - - return spec->directives; -} - -static bool -format_check (void *msgid_descr, void *msgstr_descr, bool equality, - formatstring_error_logger_t error_logger, - const char *pretty_msgid, const char *pretty_msgstr) -{ - struct spec *spec1 = (struct spec *) msgid_descr; - struct spec *spec2 = (struct spec *) msgstr_descr; - bool err = false; - - if (spec1->numbered_arg_count + spec2->numbered_arg_count > 0) - { - unsigned int i, j; - unsigned int n1 = spec1->numbered_arg_count; - unsigned int n2 = spec2->numbered_arg_count; - - /* Check the argument names are the same. - Both arrays are sorted. We search for the first difference. */ - for (i = 0, j = 0; i < n1 || j < n2; ) - { - int cmp = (i >= n1 ? 1 : - j >= n2 ? -1 : - spec1->numbered[i].number > spec2->numbered[j].number ? 1 : - spec1->numbered[i].number < spec2->numbered[j].number ? -1 : - 0); - - if (cmp > 0) - { - if (error_logger) - error_logger (_("a format specification for argument {%u}, as in '%s', doesn't exist in '%s'"), - spec2->numbered[j].number, pretty_msgstr, - pretty_msgid); - err = true; - break; - } - else if (cmp < 0) - { - if (equality) - { - if (error_logger) - error_logger (_("a format specification for argument {%u} doesn't exist in '%s'"), - spec1->numbered[i].number, pretty_msgstr); - err = true; - break; - } - else - i++; - } - else - j++, i++; - } - /* Check the argument types are the same. */ - if (!err) - for (i = 0, j = 0; j < n2; ) - { - if (spec1->numbered[i].number == spec2->numbered[j].number) - { - if (spec1->numbered[i].type != spec2->numbered[j].type) - { - if (error_logger) - error_logger (_("format specifications in '%s' and '%s' for argument {%u} are not the same"), - pretty_msgid, pretty_msgstr, - spec2->numbered[j].number); - err = true; - break; - } - j++, i++; - } - else - i++; - } - } - - return err; -} - - -struct formatstring_parser formatstring_java = -{ - format_parse, - format_free, - format_get_number_of_directives, - NULL, - format_check -}; - - -#ifdef TEST - -/* Test program: Print the argument list specification returned by - format_parse for strings read from standard input. */ - -#include - -static void -format_print (void *descr) -{ - struct spec *spec = (struct spec *) descr; - unsigned int last; - unsigned int i; - - if (spec == NULL) - { - printf ("INVALID"); - return; - } - - printf ("("); - last = 0; - for (i = 0; i < spec->numbered_arg_count; i++) - { - unsigned int number = spec->numbered[i].number; - - if (i > 0) - printf (" "); - if (number < last) - abort (); - for (; last < number; last++) - printf ("_ "); - switch (spec->numbered[i].type) - { - case FAT_OBJECT: - printf ("*"); - break; - case FAT_NUMBER: - printf ("Number"); - break; - case FAT_DATE: - printf ("Date"); - break; - default: - abort (); - } - last = number + 1; - } - printf (")"); -} - -int -main () -{ - for (;;) - { - char *line = NULL; - size_t line_size = 0; - int line_len; - char *invalid_reason; - void *descr; - - line_len = getline (&line, &line_size, stdin); - if (line_len < 0) - break; - if (line_len > 0 && line[line_len - 1] == '\n') - line[--line_len] = '\0'; - - invalid_reason = NULL; - descr = format_parse (line, false, NULL, &invalid_reason); - - format_print (descr); - printf ("\n"); - if (descr == NULL) - printf ("%s\n", invalid_reason); - - free (invalid_reason); - free (line); - } - - return 0; -} - -/* - * For Emacs M-x compile - * Local Variables: - * compile-command: "/bin/sh ../libtool --tag=CC --mode=link gcc -o a.out -static -O -g -Wall -I.. -I../gnulib-lib -I../../gettext-runtime/intl -DHAVE_CONFIG_H -DTEST format-java.c ../gnulib-lib/libgettextlib.la" - * End: - */ - -#endif /* TEST */ diff --git a/gettext-tools/src/format.c b/gettext-tools/src/format.c index 987c50dda..827f18248 100644 --- a/gettext-tools/src/format.c +++ b/gettext-tools/src/format.c @@ -44,9 +44,6 @@ struct formatstring_parser *formatstring_parsers[NFORMATS] = /* format_librep */ &formatstring_librep, /* format_scheme */ &formatstring_scheme, /* format_smalltalk */ &formatstring_smalltalk, - /* format_java */ &formatstring_java, - /* format_java_printf */ &formatstring_java_printf, - /* format_csharp */ &formatstring_csharp, /* format_awk */ &formatstring_awk, /* format_pascal */ &formatstring_pascal, /* format_ycp */ &formatstring_ycp, diff --git a/gettext-tools/src/format.h b/gettext-tools/src/format.h index 0ae7007a6..5477407f5 100644 --- a/gettext-tools/src/format.h +++ b/gettext-tools/src/format.h @@ -105,9 +105,6 @@ extern DLL_VARIABLE struct formatstring_parser formatstring_elisp; extern DLL_VARIABLE struct formatstring_parser formatstring_librep; extern DLL_VARIABLE struct formatstring_parser formatstring_scheme; extern DLL_VARIABLE struct formatstring_parser formatstring_smalltalk; -extern DLL_VARIABLE struct formatstring_parser formatstring_java; -extern DLL_VARIABLE struct formatstring_parser formatstring_java_printf; -extern DLL_VARIABLE struct formatstring_parser formatstring_csharp; extern DLL_VARIABLE struct formatstring_parser formatstring_awk; extern DLL_VARIABLE struct formatstring_parser formatstring_pascal; extern DLL_VARIABLE struct formatstring_parser formatstring_ycp; diff --git a/gettext-tools/src/gnu/gettext/DumpResource.java b/gettext-tools/src/gnu/gettext/DumpResource.java deleted file mode 100644 index 41f002a6f..000000000 --- a/gettext-tools/src/gnu/gettext/DumpResource.java +++ /dev/null @@ -1,236 +0,0 @@ -/* GNU gettext for Java - * Copyright (C) 2001-2003, 2007 Free Software Foundation, Inc. - * - * This program 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 3 of the License, or - * (at your option) any later version. - * - * This program 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 this program. If not, see . - */ - -package gnu.gettext; - -import java.lang.reflect.*; -import java.util.*; -import java.io.*; - -/** - * This programs dumps a resource as a PO file. The resource must be - * accessible through the CLASSPATH. - * - * @author Bruno Haible - */ -public class DumpResource { - private Writer out; - private void dumpString (String str) throws IOException { - int n = str.length(); - out.write('"'); - for (int i = 0; i < n; i++) { - char c = str.charAt(i); - if (c == 0x0008) { - out.write('\\'); out.write('b'); - } else if (c == 0x000c) { - out.write('\\'); out.write('f'); - } else if (c == 0x000a) { - out.write('\\'); out.write('n'); - } else if (c == 0x000d) { - out.write('\\'); out.write('r'); - } else if (c == 0x0009) { - out.write('\\'); out.write('t'); - } else if (c == '\\' || c == '"') { - out.write('\\'); out.write(c); - } else - out.write(c); - } - out.write('"'); - } - private void dumpMessage (String msgid, String msgid_plural, Object msgstr) throws IOException { - int separatorPos = msgid.indexOf('\u0004'); - if (separatorPos >= 0) { - String msgctxt = msgid.substring(0,separatorPos); - msgid = msgid.substring(separatorPos+1); - out.write("msgctxt "); dumpString(msgctxt); - } - out.write("msgid "); dumpString(msgid); out.write('\n'); - if (msgid_plural != null) { - out.write("msgid_plural "); dumpString(msgid_plural); out.write('\n'); - for (int i = 0; i < ((String[])msgstr).length; i++) { - out.write("msgstr[" + i + "] "); - dumpString(((String[])msgstr)[i]); - out.write('\n'); - } - } else { - out.write("msgstr "); dumpString((String)msgstr); out.write('\n'); - } - out.write('\n'); - } - private ResourceBundle catalog; - private Method lookupMethod; - // Lookup the value corresponding to a key found in catalog.getKeys(). - // Here we assume that the catalog returns a non-inherited value for - // these keys. FIXME: Not true. Better see whether handleGetObject is - // public - it is in ListResourceBundle and PropertyResourceBundle. - private Object lookup (String key) { - Object value = null; - if (lookupMethod != null) { - try { - value = lookupMethod.invoke(catalog, new Object[] { key }); - } catch (IllegalAccessException e) { - e.printStackTrace(); - } catch (InvocationTargetException e) { - e.getTargetException().printStackTrace(); - } - } else { - try { - value = catalog.getObject(key); - } catch (MissingResourceException e) { - } - } - return value; - } - private void dump () throws IOException { - lookupMethod = null; - try { - lookupMethod = catalog.getClass().getMethod("lookup", new Class[] { java.lang.String.class }); - } catch (NoSuchMethodException e) { - } catch (SecurityException e) { - } - Method pluralMethod = null; - try { - pluralMethod = catalog.getClass().getMethod("get_msgid_plural_table", new Class[0]); - } catch (NoSuchMethodException e) { - } catch (SecurityException e) { - } - Field pluralField = null; - try { - pluralField = catalog.getClass().getField("plural"); - } catch (NoSuchFieldException e) { - } catch (SecurityException e) { - } - // Search for the header entry. - { - Object header_entry = null; - Enumeration keys = catalog.getKeys(); - while (keys.hasMoreElements()) - if ("".equals(keys.nextElement())) { - header_entry = lookup(""); - break; - } - // If there is no header entry, fake one. - // FIXME: This is not needed; right after po_lex_charset_init set - // the PO charset to UTF-8. - if (header_entry == null) - header_entry = "Content-Type: text/plain; charset=UTF-8\n"; - dumpMessage("",null,header_entry); - } - // Now the other messages. - { - Enumeration keys = catalog.getKeys(); - Object plural = null; - if (pluralMethod != null) { - // msgfmt versions > 0.13.1 create a static get_msgid_plural_table() - // method. - try { - plural = pluralMethod.invoke(catalog, new Object[0]); - } catch (IllegalAccessException e) { - e.printStackTrace(); - } catch (InvocationTargetException e) { - e.getTargetException().printStackTrace(); - } - } else if (pluralField != null) { - // msgfmt versions <= 0.13.1 create a static plural field. - try { - plural = pluralField.get(catalog); - } catch (IllegalAccessException e) { - e.printStackTrace(); - } - } - if (plural instanceof String[]) { - // A GNU gettext created class with plural handling, Java2 format. - int i = 0; - while (keys.hasMoreElements()) { - String key = (String)keys.nextElement(); - Object value = lookup(key); - String key_plural = (value instanceof String[] ? ((String[])plural)[i++] : null); - if (!"".equals(key)) - dumpMessage(key,key_plural,value); - } - if (i != ((String[])plural).length) - throw new RuntimeException("wrong plural field length"); - } else if (plural instanceof Hashtable) { - // A GNU gettext created class with plural handling, Java format. - while (keys.hasMoreElements()) { - String key = (String)keys.nextElement(); - if (!"".equals(key)) { - Object value = lookup(key); - String key_plural = (value instanceof String[] ? (String)((Hashtable)plural).get(key) : null); - dumpMessage(key,key_plural,value); - } - } - } else if (plural == null) { - // No plural handling. - while (keys.hasMoreElements()) { - String key = (String)keys.nextElement(); - if (!"".equals(key)) - dumpMessage(key,null,lookup(key)); - } - } else - throw new RuntimeException("wrong plural field value"); - } - } - - public DumpResource (String resource_name, String locale_name) { - // Split locale_name into language_country_variant. - String language; - String country; - String variant; - language = locale_name; - { - int i = language.indexOf('_'); - if (i >= 0) { - country = language.substring(i+1); - language = language.substring(0,i); - } else - country = ""; - } - { - int j = country.indexOf('_'); - if (j >= 0) { - variant = country.substring(j+1); - country = country.substring(0,j); - } else - variant = ""; - } - Locale locale = new Locale(language,country,variant); - // Get the resource. - ResourceBundle catalog = ResourceBundle.getBundle(resource_name,locale); - // We are only interested in the messsages belonging to the locale - // itself, not in the inherited messages. But catalog.getLocale() exists - // only in Java2 and sometimes differs from the given locale. - try { - Writer w1 = new OutputStreamWriter(System.out,"UTF8"); - Writer w2 = new BufferedWriter(w1); - this.out = w2; - this.catalog = catalog; - dump(); - w2.close(); - w1.close(); - System.out.flush(); - } catch (IOException e) { - e.printStackTrace(); - System.exit(1); - } - } - - public static void main (String[] args) { - new DumpResource(args[0], args.length > 1 ? args[1] : ""); - System.exit(0); - } -} diff --git a/gettext-tools/src/gnu/gettext/GetURL.java b/gettext-tools/src/gnu/gettext/GetURL.java deleted file mode 100644 index 7ef42d174..000000000 --- a/gettext-tools/src/gnu/gettext/GetURL.java +++ /dev/null @@ -1,81 +0,0 @@ -/* Fetch an URL's contents. - * Copyright (C) 2001, 2008 Free Software Foundation, Inc. - * - * This program 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 3 of the License, or - * (at your option) any later version. - * - * This program 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 this program. If not, see . - */ - -package gnu.gettext; - -import java.io.*; -import java.net.*; - -/** - * Fetch an URL's contents and emit it to standard output. - * Exit code: 0 = success - * 1 = failure - * 2 = timeout - * @author Bruno Haible - */ -public class GetURL { - // Use a separate thread to signal a timeout error if the URL cannot - // be accessed and completely read within a given amount of time. - private static long timeout = 30*1000; // 30 seconds - private boolean done; - private Thread timeoutThread; - public void fetch (String s) { - URL url; - try { - url = new URL(s); - } catch (MalformedURLException e) { - System.exit(1); - return; - } - done = false; - timeoutThread = - new Thread() { - public void run () { - try { - sleep(timeout); - if (!done) { - System.exit(2); - } - } catch (InterruptedException e) { - } - } - }; - timeoutThread.start(); - try { - InputStream istream = new BufferedInputStream(url.openStream()); - OutputStream ostream = new BufferedOutputStream(System.out); - for (;;) { - int b = istream.read(); - if (b < 0) break; - ostream.write(b); - } - ostream.close(); - System.out.flush(); - istream.close(); - } catch (IOException e) { - //e.printStackTrace(); - System.exit(1); - } - done = true; - } - public static void main (String[] args) { - if (args.length != 1) - System.exit(1); - (new GetURL()).fetch(args[0]); - System.exit(0); - } -} diff --git a/gettext-tools/src/message.c b/gettext-tools/src/message.c index 05437eb15..c3f90e4e7 100644 --- a/gettext-tools/src/message.c +++ b/gettext-tools/src/message.c @@ -44,9 +44,6 @@ const char *const format_language[NFORMATS] = /* format_librep */ "librep", /* format_scheme */ "scheme", /* format_smalltalk */ "smalltalk", - /* format_java */ "java", - /* format_java_printf */ "java-printf", - /* format_csharp */ "csharp", /* format_awk */ "awk", /* format_pascal */ "object-pascal", /* format_ycp */ "ycp", @@ -77,9 +74,6 @@ const char *const format_language_pretty[NFORMATS] = /* format_librep */ "librep", /* format_scheme */ "Scheme", /* format_smalltalk */ "Smalltalk", - /* format_java */ "Java MessageFormat", - /* format_java_printf */ "Java printf", - /* format_csharp */ "C#", /* format_awk */ "awk", /* format_pascal */ "Object Pascal", /* format_ycp */ "YCP", diff --git a/gettext-tools/src/message.h b/gettext-tools/src/message.h index 5ee97187c..ca4d42653 100644 --- a/gettext-tools/src/message.h +++ b/gettext-tools/src/message.h @@ -53,9 +53,6 @@ enum format_type format_librep, format_scheme, format_smalltalk, - format_java, - format_java_printf, - format_csharp, format_awk, format_pascal, format_ycp, diff --git a/gettext-tools/src/msgcmp.c b/gettext-tools/src/msgcmp.c index a376e2ce2..68ea66436 100644 --- a/gettext-tools/src/msgcmp.c +++ b/gettext-tools/src/msgcmp.c @@ -37,7 +37,6 @@ #include "message.h" #include "read-catalog.h" #include "read-po.h" -#include "read-properties.h" #include "read-stringtable.h" #include "xmalloca.h" #include "po-charset.h" @@ -70,7 +69,6 @@ static const struct option long_options[] = { "help", no_argument, NULL, 'h' }, { "multi-domain", no_argument, NULL, 'm' }, { "no-fuzzy-matching", no_argument, NULL, 'N' }, - { "properties-input", no_argument, NULL, 'P' }, { "stringtable-input", no_argument, NULL, CHAR_MAX + 1 }, { "use-fuzzy", no_argument, NULL, CHAR_MAX + 2 }, { "use-untranslated", no_argument, NULL, CHAR_MAX + 3 }, @@ -138,10 +136,6 @@ main (int argc, char *argv[]) use_fuzzy_matching = false; break; - case 'P': - input_syntax = &input_format_properties; - break; - case 'V': do_version = true; break; @@ -249,8 +243,6 @@ Operation modifiers:\n")); printf (_("\ Input file syntax:\n")); printf (_("\ - -P, --properties-input input files are in Java .properties syntax\n")); - printf (_("\ --stringtable-input input files are in NeXTstep/GNUstep .strings\n\ syntax\n")); printf ("\n"); diff --git a/gettext-tools/src/msgfmt.c b/gettext-tools/src/msgfmt.c index d016c47ea..b42fd68c3 100644 --- a/gettext-tools/src/msgfmt.c +++ b/gettext-tools/src/msgfmt.c @@ -44,9 +44,6 @@ #include "xalloc.h" #include "msgfmt.h" #include "write-mo.h" -#include "write-java.h" -#include "write-csharp.h" -#include "write-resources.h" #include "write-tcl.h" #include "write-qt.h" #include "write-desktop.h" @@ -84,23 +81,6 @@ static bool include_untranslated = false; /* Specifies name of the output file. */ static const char *output_file_name; -/* Java mode output file specification. */ -static bool java_mode; -static bool assume_java2; -static const char *java_resource_name; -static const char *java_locale_name; -static const char *java_class_directory; -static bool java_output_source; - -/* C# mode output file specification. */ -static bool csharp_mode; -static const char *csharp_resource_name; -static const char *csharp_locale_name; -static const char *csharp_base_directory; - -/* C# resources mode output file specification. */ -static bool csharp_resources_mode; - /* Tcl mode output file specification. */ static bool tcl_mode; static const char *tcl_locale_name; @@ -186,14 +166,10 @@ static const struct option long_options[] = { "check-domain", no_argument, NULL, CHAR_MAX + 2 }, { "check-format", no_argument, NULL, CHAR_MAX + 3 }, { "check-header", no_argument, NULL, CHAR_MAX + 4 }, - { "csharp", no_argument, NULL, CHAR_MAX + 10 }, - { "csharp-resources", no_argument, NULL, CHAR_MAX + 11 }, { "desktop", no_argument, NULL, CHAR_MAX + 15 }, { "directory", required_argument, NULL, 'D' }, { "endianness", required_argument, NULL, CHAR_MAX + 13 }, { "help", no_argument, NULL, 'h' }, - { "java", no_argument, NULL, 'j' }, - { "java2", no_argument, NULL, CHAR_MAX + 5 }, { "keyword", required_argument, NULL, 'k' }, { "language", required_argument, NULL, 'L' }, { "locale", required_argument, NULL, 'l' }, @@ -296,8 +272,6 @@ main (int argc, char *argv[]) check_compatibility = true; break; case 'd': - java_class_directory = optarg; - csharp_base_directory = optarg; tcl_base_directory = optarg; desktop_base_directory = optarg; xml_base_directory = optarg; @@ -311,9 +285,6 @@ main (int argc, char *argv[]) case 'h': do_help = true; break; - case 'j': - java_mode = true; - break; case 'k': if (optarg == NULL) desktop_default_keywords = false; @@ -329,8 +300,6 @@ main (int argc, char *argv[]) } break; case 'l': - java_locale_name = optarg; - csharp_locale_name = optarg; tcl_locale_name = optarg; desktop_locale_name = optarg; xml_locale_name = optarg; @@ -344,10 +313,6 @@ main (int argc, char *argv[]) case 'P': input_syntax = &input_format_properties; break; - case 'r': - java_resource_name = optarg; - csharp_resource_name = optarg; - break; case 'S': strict_uniforum = true; break; @@ -382,10 +347,6 @@ main (int argc, char *argv[]) case CHAR_MAX + 4: /* --check-header */ check_header = true; break; - case CHAR_MAX + 5: /* --java2 */ - java_mode = true; - assume_java2 = true; - break; case CHAR_MAX + 6: /* --no-hash */ no_hash_table = true; break; @@ -398,12 +359,6 @@ main (int argc, char *argv[]) case CHAR_MAX + 9: /* --qt */ qt_mode = true; break; - case CHAR_MAX + 10: /* --csharp */ - csharp_mode = true; - break; - case CHAR_MAX + 11: /* --csharp-resources */ - csharp_resources_mode = true; - break; case CHAR_MAX + 12: /* --use-untranslated (undocumented) */ include_untranslated = true; break; @@ -421,9 +376,6 @@ main (int argc, char *argv[]) byteswap = endianness ^ ENDIANNESS; } break; - case CHAR_MAX + 14: /* --source */ - java_output_source = true; - break; case CHAR_MAX + 15: /* --desktop */ desktop_mode = true; break; @@ -476,15 +428,12 @@ There is NO WARRANTY, to the extent permitted by law.\n\ /* Check for contradicting options. */ { unsigned int modes = - (java_mode ? 1 : 0) - | (csharp_mode ? 2 : 0) - | (csharp_resources_mode ? 4 : 0) - | (tcl_mode ? 8 : 0) + (tcl_mode ? 8 : 0) | (qt_mode ? 16 : 0) | (desktop_mode ? 32 : 0) | (xml_mode ? 64 : 0); static const char *mode_options[] = - { "--java", "--csharp", "--csharp-resources", "--tcl", "--qt", + { "--tcl", "--qt", "--desktop", "--xml" }; /* More than one bit set? */ if (modes & (modes - 1)) @@ -504,44 +453,7 @@ There is NO WARRANTY, to the extent permitted by law.\n\ first_option, second_option); } } - if (java_mode) - { - if (output_file_name != NULL) - { - error (EXIT_FAILURE, 0, _("%s and %s are mutually exclusive"), - "--java", "--output-file"); - } - if (java_class_directory == NULL) - { - error (EXIT_SUCCESS, 0, - _("%s requires a \"-d directory\" specification"), - "--java"); - usage (EXIT_FAILURE); - } - } - else if (csharp_mode) - { - if (output_file_name != NULL) - { - error (EXIT_FAILURE, 0, _("%s and %s are mutually exclusive"), - "--csharp", "--output-file"); - } - if (csharp_locale_name == NULL) - { - error (EXIT_SUCCESS, 0, - _("%s requires a \"-l locale\" specification"), - "--csharp"); - usage (EXIT_FAILURE); - } - if (csharp_base_directory == NULL) - { - error (EXIT_SUCCESS, 0, - _("%s requires a \"-d directory\" specification"), - "--csharp"); - usage (EXIT_FAILURE); - } - } - else if (tcl_mode) + if (tcl_mode) { if (output_file_name != NULL) { @@ -619,27 +531,6 @@ There is NO WARRANTY, to the extent permitted by law.\n\ usage (EXIT_FAILURE); } } - else - { - if (java_resource_name != NULL) - { - error (EXIT_SUCCESS, 0, _("%s is only valid with %s or %s"), - "--resource", "--java", "--csharp"); - usage (EXIT_FAILURE); - } - if (java_locale_name != NULL) - { - error (EXIT_SUCCESS, 0, _("%s is only valid with %s, %s or %s"), - "--locale", "--java", "--csharp", "--tcl"); - usage (EXIT_FAILURE); - } - if (java_class_directory != NULL) - { - error (EXIT_SUCCESS, 0, _("%s is only valid with %s, %s or %s"), - "-d", "--java", "--csharp", "--tcl"); - usage (EXIT_FAILURE); - } - } if (desktop_mode && desktop_default_keywords) { @@ -728,7 +619,7 @@ There is NO WARRANTY, to the extent permitted by law.\n\ if (output_file_name != NULL) current_domain = new_domain (output_file_name, - strict_uniforum && !csharp_resources_mode && !qt_mode + strict_uniforum && !qt_mode ? add_mo_suffix (output_file_name) : output_file_name); @@ -782,29 +673,7 @@ There is NO WARRANTY, to the extent permitted by law.\n\ /* Now write out all domains. */ for (domain = domain_list; domain != NULL; domain = domain->next) { - if (java_mode) - { - if (msgdomain_write_java (domain->mlp, canon_encoding, - java_resource_name, java_locale_name, - java_class_directory, assume_java2, - java_output_source)) - exit_status = EXIT_FAILURE; - } - else if (csharp_mode) - { - if (msgdomain_write_csharp (domain->mlp, canon_encoding, - csharp_resource_name, csharp_locale_name, - csharp_base_directory)) - exit_status = EXIT_FAILURE; - } - else if (csharp_resources_mode) - { - if (msgdomain_write_csharp_resources (domain->mlp, canon_encoding, - domain->domain_name, - domain->file_name)) - exit_status = EXIT_FAILURE; - } - else if (tcl_mode) + if (tcl_mode) { if (msgdomain_write_tcl (domain->mlp, canon_encoding, tcl_locale_name, tcl_base_directory)) @@ -929,14 +798,6 @@ If input file is -, standard input is read.\n")); printf (_("\ Operation mode:\n")); printf (_("\ - -j, --java Java mode: generate a Java ResourceBundle class\n")); - printf (_("\ - --java2 like --java, and assume Java2 (JDK 1.2 or higher)\n")); - printf (_("\ - --csharp C# mode: generate a .NET .dll file\n")); - printf (_("\ - --csharp-resources C# resources mode: generate a .NET .resources file\n")); - printf (_("\ --tcl Tcl mode: generate a tcl/msgcat .msg file\n")); printf (_("\ --qt Qt mode: generate a Qt .qm file\n")); @@ -955,22 +816,6 @@ Output file location:\n")); If output file is -, output is written to standard output.\n")); printf ("\n"); printf (_("\ -Output file location in Java mode:\n")); - printf (_("\ - -r, --resource=RESOURCE resource name\n")); - printf (_("\ - -l, --locale=LOCALE locale name, either language or language_COUNTRY\n")); - printf (_("\ - --source produce a .java file, instead of a .class file\n")); - printf (_("\ - -d DIRECTORY base directory of classes directory hierarchy\n")); - printf (_("\ -The class name is determined by appending the locale name to the resource name,\n\ -separated with an underscore. The -d option is mandatory. The class is\n\ -written under the specified directory.\n\ -")); - printf ("\n"); - printf (_("\ Output file location in C# mode:\n")); printf (_("\ -r, --resource=RESOURCE resource name\n")); @@ -1028,8 +873,6 @@ files are read from the directory instead of the command line arguments.\n")); printf (_("\ Input file syntax:\n")); printf (_("\ - -P, --properties-input input files are in Java .properties syntax\n")); - printf (_("\ --stringtable-input input files are in NeXTstep/GNUstep .strings\n\ syntax\n")); printf ("\n"); @@ -1201,8 +1044,8 @@ msgfmt_set_domain (default_catalog_reader_ty *this, char *name) { /* If no output file was given, we change it with each 'domain' directive. */ - if (!java_mode && !csharp_mode && !csharp_resources_mode && !tcl_mode - && !qt_mode && !desktop_mode && !xml_mode && output_file_name == NULL) + if (!tcl_mode && !qt_mode && !desktop_mode && !xml_mode + && output_file_name == NULL) { size_t correct; diff --git a/gettext-tools/src/msgfmt.cs b/gettext-tools/src/msgfmt.cs deleted file mode 100644 index ca415ac3a..000000000 --- a/gettext-tools/src/msgfmt.cs +++ /dev/null @@ -1,91 +0,0 @@ -/* GNU gettext for C# - * Copyright (C) 2003-2004, 2018 Free Software Foundation, Inc. - * Written by Bruno Haible , 2003. - * - * This program 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 3 of the License, or - * (at your option) any later version. - * - * This program 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 this program. If not, see . - */ - -/* - * This program creates a .resources file from a set of key/value pairs given - * on standard input. - */ - -using System; /* String, Console, Exception */ -using System.IO; /* Stream, BufferedStream, StreamReader */ -using System.Text; /* StringBuilder, UTF8Encoding */ -using System.Resources; /* ResourceWriter */ - -namespace GNU.Gettext { - public class WriteResource { - private StreamReader reader; - // Read a NUL-terminated UTF-8 encoded string. - private String ReadString () { - StringBuilder b = new StringBuilder(); - for (;;) { - int c = reader.Read(); - if (c < 0) // EOF? - return null; - if (c == 0) // End of String? - break; - b.Append((char)c); - } - return b.ToString(); - } - // Read all msgid/msgstr pairs, register them in the ResourceWriter, - // and write the binary contents to the output stream. - private void ReadAllInput (ResourceWriter rw) { - for (;;) { - String msgid = ReadString(); - if (msgid == null) - break; - String msgstr = ReadString(); - if (msgstr == null) - break; - rw.AddResource(msgid, msgstr); - } - rw.Generate(); - } - // Read all msgid/msgstr pairs (each string being NUL-terminated and - // UTF-8 encoded) and write the .resources file to the given filename. - WriteResource (String filename) { - Stream input = new BufferedStream(Console.OpenStandardInput()); - reader = new StreamReader(input, new UTF8Encoding()); - if (filename.Equals("-")) { - BufferedStream output = new BufferedStream(Console.OpenStandardOutput()); - // A temporary output stream is needed because ResourceWriter.Generate - // expects to be able to seek in the Stream. - MemoryStream tmpoutput = new MemoryStream(); - ResourceWriter rw = new ResourceWriter(tmpoutput); - ReadAllInput(rw); - tmpoutput.WriteTo(output); - rw.Close(); - output.Close(); - } else { - ResourceWriter rw = new ResourceWriter(filename); - ReadAllInput(rw); - rw.Close(); - } - } - public static int Main (String[] args) { - try { - new WriteResource(args[0]); - } catch (Exception e) { - Console.Error.WriteLine(e); - Console.Error.WriteLine(e.StackTrace); - return 1; - } - return 0; - } - } -} diff --git a/gettext-tools/src/msgunfmt.c b/gettext-tools/src/msgunfmt.c index 9406ec8d2..39e919347 100644 --- a/gettext-tools/src/msgunfmt.c +++ b/gettext-tools/src/msgunfmt.c @@ -38,8 +38,6 @@ #include "message.h" #include "msgunfmt.h" #include "read-mo.h" -#include "read-java.h" -#include "read-csharp.h" #include "read-resources.h" #include "read-tcl.h" #include "write-catalog.h" @@ -55,20 +53,6 @@ /* Be more verbose. */ bool verbose; -/* Java mode input file specification. */ -static bool java_mode; -static const char *java_resource_name; -static const char *java_locale_name; - -/* C# mode input file specification. */ -static bool csharp_mode; -static const char *csharp_resource_name; -static const char *csharp_locale_name; -static const char *csharp_base_directory; - -/* C# resources mode input file specification. */ -static bool csharp_resources_mode; - /* Tcl mode input file specification. */ static bool tcl_mode; static const char *tcl_locale_name; @@ -81,13 +65,10 @@ static int force_po; static const struct option long_options[] = { { "color", optional_argument, NULL, CHAR_MAX + 6 }, - { "csharp", no_argument, NULL, CHAR_MAX + 4 }, - { "csharp-resources", no_argument, NULL, CHAR_MAX + 5 }, { "escape", no_argument, NULL, 'E' }, { "force-po", no_argument, &force_po, 1 }, { "help", no_argument, NULL, 'h' }, { "indent", no_argument, NULL, 'i' }, - { "java", no_argument, NULL, 'j' }, { "locale", required_argument, NULL, 'l' }, { "no-escape", no_argument, NULL, 'e' }, { "no-wrap", no_argument, NULL, CHAR_MAX + 2 }, @@ -151,7 +132,6 @@ main (int argc, char **argv) break; case 'd': - csharp_base_directory = optarg; tcl_base_directory = optarg; break; @@ -171,13 +151,7 @@ main (int argc, char **argv) message_print_style_indent (); break; - case 'j': - java_mode = true; - break; - case 'l': - java_locale_name = optarg; - csharp_locale_name = optarg; tcl_locale_name = optarg; break; @@ -190,8 +164,6 @@ main (int argc, char **argv) break; case 'r': - java_resource_name = optarg; - csharp_resource_name = optarg; break; case 's': @@ -232,14 +204,6 @@ main (int argc, char **argv) output_syntax = &output_format_stringtable; break; - case CHAR_MAX + 4: /* --csharp */ - csharp_mode = true; - break; - - case CHAR_MAX + 5: /* --csharp-resources */ - csharp_resources_mode = true; - break; - case CHAR_MAX + 6: /* --color */ if (handle_color_option (optarg) || color_test_mode) usage (EXIT_FAILURE); @@ -276,12 +240,9 @@ There is NO WARRANTY, to the extent permitted by law.\n\ /* Check for contradicting options. */ { unsigned int modes = - (java_mode ? 1 : 0) - | (csharp_mode ? 2 : 0) - | (csharp_resources_mode ? 4 : 0) - | (tcl_mode ? 8 : 0); + (tcl_mode ? 8 : 0); static const char *mode_options[] = - { "--java", "--csharp", "--csharp-resources", "--tcl" }; + { "--tcl" }; /* More than one bit set? */ if (modes & (modes - 1)) { @@ -300,39 +261,7 @@ There is NO WARRANTY, to the extent permitted by law.\n\ first_option, second_option); } } - if (java_mode) - { - if (optind < argc) - { - error (EXIT_FAILURE, 0, - _("%s and explicit file names are mutually exclusive"), - "--java"); - } - } - else if (csharp_mode) - { - if (optind < argc) - { - error (EXIT_FAILURE, 0, - _("%s and explicit file names are mutually exclusive"), - "--csharp"); - } - if (csharp_locale_name == NULL) - { - error (EXIT_SUCCESS, 0, - _("%s requires a \"-l locale\" specification"), - "--csharp"); - usage (EXIT_FAILURE); - } - if (csharp_base_directory == NULL) - { - error (EXIT_SUCCESS, 0, - _("%s requires a \"-d directory\" specification"), - "--csharp"); - usage (EXIT_FAILURE); - } - } - else if (tcl_mode) + if (tcl_mode) { if (optind < argc) { @@ -355,33 +284,9 @@ There is NO WARRANTY, to the extent permitted by law.\n\ usage (EXIT_FAILURE); } } - else - { - if (java_resource_name != NULL) - { - error (EXIT_SUCCESS, 0, _("%s is only valid with %s or %s"), - "--resource", "--java", "--csharp"); - usage (EXIT_FAILURE); - } - if (java_locale_name != NULL) - { - error (EXIT_SUCCESS, 0, _("%s is only valid with %s or %s"), - "--locale", "--java", "--csharp"); - usage (EXIT_FAILURE); - } - } /* Read the given .mo file. */ - if (java_mode) - { - result = msgdomain_read_java (java_resource_name, java_locale_name); - } - else if (csharp_mode) - { - result = msgdomain_read_csharp (csharp_resource_name, csharp_locale_name, - csharp_base_directory); - } - else if (tcl_mode) + if (tcl_mode) { result = msgdomain_read_tcl (tcl_locale_name, tcl_base_directory); } @@ -438,12 +343,6 @@ Mandatory arguments to long options are mandatory for short options too.\n")); printf (_("\ Operation mode:\n")); printf (_("\ - -j, --java Java mode: input is a Java ResourceBundle class\n")); - printf (_("\ - --csharp C# mode: input is a .NET .dll file\n")); - printf (_("\ - --csharp-resources C# resources mode: input is a .NET .resources file\n")); - printf (_("\ --tcl Tcl mode: input is a tcl/msgcat .msg file\n")); printf ("\n"); printf (_("\ @@ -454,8 +353,6 @@ Input file location:\n")); If no input file is given or if it is -, standard input is read.\n")); printf ("\n"); printf (_("\ -Input file location in Java mode:\n")); - printf (_("\ -r, --resource=RESOURCE resource name\n")); printf (_("\ -l, --locale=LOCALE locale name, either language or language_COUNTRY\n")); @@ -513,8 +410,6 @@ Output details:\n")); printf (_("\ --strict write strict uniforum style\n")); printf (_("\ - -p, --properties-output write out a Java .properties file\n")); - printf (_("\ --stringtable-output write out a NeXTstep/GNUstep .strings file\n")); printf (_("\ -w, --width=NUMBER set output page width\n")); @@ -552,8 +447,5 @@ or by email to <%s>.\n"), static void read_one_file (message_list_ty *mlp, const char *filename) { - if (csharp_resources_mode) - read_resources_file (mlp, filename); - else - read_mo_file (mlp, filename); + read_mo_file (mlp, filename); } diff --git a/gettext-tools/src/msgunfmt.cs b/gettext-tools/src/msgunfmt.cs deleted file mode 100644 index 44733f156..000000000 --- a/gettext-tools/src/msgunfmt.cs +++ /dev/null @@ -1,241 +0,0 @@ -/* GNU gettext for C# - * Copyright (C) 2003-2004, 2007 Free Software Foundation, Inc. - * Written by Bruno Haible , 2003. - * - * This program 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 3 of the License, or - * (at your option) any later version. - * - * This program 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 this program. If not, see . - */ - -/* - * This program dumps a GettextResourceSet subclass (in a satellite assembly) - * or a .resources file as a PO file. - */ - -using System; /* Object, String, Type, Console, Exception */ -using System.Reflection; /* Assembly, MethodInfo, ConstructorInfo */ -using System.Collections; /* Hashtable, DictionaryEntry */ -using System.IO; /* BufferedStream, StreamWriter, TextWriter, FileNotFoundException, Path */ -using System.Text; /* StringBuilder, UTF8Encoding */ -using System.Resources; /* ResourceReader */ -using GNU.Gettext; /* GettextResourceSet */ - -namespace GNU.Gettext { - public class DumpResource { - private TextWriter Out; - private void DumpString (String str) { - int n = str.Length; - Out.Write('"'); - for (int i = 0; i < n; i++) { - char c = str[i]; - if (c == 0x0008) { - Out.Write('\\'); Out.Write('b'); - } else if (c == 0x000c) { - Out.Write('\\'); Out.Write('f'); - } else if (c == 0x000a) { - Out.Write('\\'); Out.Write('n'); - } else if (c == 0x000d) { - Out.Write('\\'); Out.Write('r'); - } else if (c == 0x0009) { - Out.Write('\\'); Out.Write('t'); - } else if (c == '\\' || c == '"') { - Out.Write('\\'); Out.Write(c); - } else - Out.Write(c); - } - Out.Write('"'); - } - private void DumpMessage (String msgid, String msgid_plural, Object msgstr) { - int separatorPos = msgid.IndexOf('\u0004'); - if (separatorPos >= 0) { - String msgctxt = msgid.Substring(0,separatorPos); - msgid = msgid.Substring(separatorPos+1); - Out.Write("msgctxt "); DumpString(msgctxt); - } - Out.Write("msgid "); DumpString(msgid); Out.Write('\n'); - if (msgid_plural != null) { - Out.Write("msgid_plural "); DumpString(msgid_plural); Out.Write('\n'); - for (int i = 0; i < (msgstr as String[]).Length; i++) { - Out.Write("msgstr[" + i + "] "); - DumpString((msgstr as String[])[i]); - Out.Write('\n'); - } - } else { - Out.Write("msgstr "); DumpString(msgstr as String); Out.Write('\n'); - } - Out.Write('\n'); - } - - // ---------------- Dumping a GettextResourceSet ---------------- - - private void Dump (GettextResourceSet catalog) { - MethodInfo pluralMethod = - catalog.GetType().GetMethod("GetMsgidPluralTable", Type.EmptyTypes); - // Search for the header entry. - { - Object header_entry = catalog.GetObject(""); - // If there is no header entry, fake one. - // FIXME: This is not needed; right after po_lex_charset_init set - // the PO charset to UTF-8. - if (header_entry == null) - header_entry = "Content-Type: text/plain; charset=UTF-8\n"; - DumpMessage("", null, header_entry); - } - // Now the other messages. - { - Hashtable plural = null; - if (pluralMethod != null) - plural = pluralMethod.Invoke(catalog, new Object[0]) as Hashtable; - foreach (String key in catalog.Keys) - if (!"".Equals(key)) { - Object value = catalog.GetObject(key); - String key_plural = - (plural != null && value is String[] ? plural[key] as String : null); - DumpMessage(key, key_plural, value); - } - } - } - // Essentially taken from class GettextResourceManager. - private static Assembly GetSatelliteAssembly (String baseDirectory, String resourceName, String cultureName) { - String satelliteExpectedLocation = - baseDirectory - + Path.DirectorySeparatorChar + cultureName - + Path.DirectorySeparatorChar + resourceName + ".resources.dll"; - return Assembly.LoadFrom(satelliteExpectedLocation); - } - // Taken from class GettextResourceManager. - private static String ConstructClassName (String resourceName) { - // We could just return an arbitrary fixed class name, like "Messages", - // assuming that every assembly will only ever contain one - // GettextResourceSet subclass, but this assumption would break the day - // we want to support multi-domain PO files in the same format... - bool valid = (resourceName.Length > 0); - for (int i = 0; valid && i < resourceName.Length; i++) { - char c = resourceName[i]; - if (!((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || (c == '_') - || (i > 0 && c >= '0' && c <= '9'))) - valid = false; - } - if (valid) - return resourceName; - else { - // Use hexadecimal escapes, using the underscore as escape character. - String hexdigit = "0123456789abcdef"; - StringBuilder b = new StringBuilder(); - b.Append("__UESCAPED__"); - for (int i = 0; i < resourceName.Length; i++) { - char c = resourceName[i]; - if (c >= 0xd800 && c < 0xdc00 - && i+1 < resourceName.Length - && resourceName[i+1] >= 0xdc00 && resourceName[i+1] < 0xe000) { - // Combine two UTF-16 words to a character. - char c2 = resourceName[i+1]; - int uc = 0x10000 + ((c - 0xd800) << 10) + (c2 - 0xdc00); - b.Append('_'); - b.Append('U'); - b.Append(hexdigit[(uc >> 28) & 0x0f]); - b.Append(hexdigit[(uc >> 24) & 0x0f]); - b.Append(hexdigit[(uc >> 20) & 0x0f]); - b.Append(hexdigit[(uc >> 16) & 0x0f]); - b.Append(hexdigit[(uc >> 12) & 0x0f]); - b.Append(hexdigit[(uc >> 8) & 0x0f]); - b.Append(hexdigit[(uc >> 4) & 0x0f]); - b.Append(hexdigit[uc & 0x0f]); - i++; - } else if (!((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') - || (c >= '0' && c <= '9'))) { - int uc = c; - b.Append('_'); - b.Append('u'); - b.Append(hexdigit[(uc >> 12) & 0x0f]); - b.Append(hexdigit[(uc >> 8) & 0x0f]); - b.Append(hexdigit[(uc >> 4) & 0x0f]); - b.Append(hexdigit[uc & 0x0f]); - } else - b.Append(c); - } - return b.ToString(); - } - } - // Essentially taken from class GettextResourceManager. - private static GettextResourceSet InstantiateResourceSet (Assembly satelliteAssembly, String resourceName, String cultureName) { - Type clazz = satelliteAssembly.GetType(ConstructClassName(resourceName)+"_"+cultureName.Replace('-','_')); - ConstructorInfo constructor = clazz.GetConstructor(Type.EmptyTypes); - return constructor.Invoke(null) as GettextResourceSet; - } - public DumpResource (String baseDirectory, String resourceName, String cultureName) { - // We are only interested in the messages belonging to the locale - // itself, not in the inherited messages. Therefore we instantiate just - // the GettextResourceSet, not a GettextResourceManager. - Assembly satelliteAssembly = - GetSatelliteAssembly(baseDirectory, resourceName, cultureName); - GettextResourceSet catalog = - InstantiateResourceSet(satelliteAssembly, resourceName, cultureName); - BufferedStream stream = new BufferedStream(Console.OpenStandardOutput()); - Out = new StreamWriter(stream, new UTF8Encoding()); - Dump(catalog); - Out.Close(); - stream.Close(); - } - - // ----------------- Dumping a .resources file ------------------ - - public DumpResource (String filename) { - BufferedStream stream = new BufferedStream(Console.OpenStandardOutput()); - Out = new StreamWriter(stream, new UTF8Encoding()); - ResourceReader rr; - if (filename.Equals("-")) { - BufferedStream input = new BufferedStream(Console.OpenStandardInput()); - // A temporary output stream is needed because ResourceReader expects - // to be able to seek in the Stream. - byte[] contents; - { - MemoryStream tmpstream = new MemoryStream(); - byte[] buf = new byte[1024]; - for (;;) { - int n = input.Read(buf, 0, 1024); - if (n == 0) - break; - tmpstream.Write(buf, 0, n); - } - contents = tmpstream.ToArray(); - tmpstream.Close(); - } - MemoryStream tmpinput = new MemoryStream(contents); - rr = new ResourceReader(tmpinput); - } else { - rr = new ResourceReader(filename); - } - foreach (DictionaryEntry entry in rr) // uses rr.GetEnumerator() - DumpMessage(entry.Key as String, null, entry.Value as String); - rr.Close(); - Out.Close(); - stream.Close(); - } - - // -------------------------------------------------------------- - - public static int Main (String[] args) { - try { - if (args.Length > 1) - new DumpResource(args[0], args[1], args[2]); - else - new DumpResource(args[0]); - } catch (Exception e) { - Console.Error.WriteLine(e); - Console.Error.WriteLine(e.StackTrace); - return 1; - } - return 0; - } - } -} diff --git a/gettext-tools/src/read-csharp.h b/gettext-tools/src/read-csharp.h deleted file mode 100644 index 32063ea6f..000000000 --- a/gettext-tools/src/read-csharp.h +++ /dev/null @@ -1,30 +0,0 @@ -/* Reading C# satellite assemblies. - Copyright (C) 2003-2004 Free Software Foundation, Inc. - Written by Bruno Haible , 2003. - - This program 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 3 of the License, or - (at your option) any later version. - - This program 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 this program. If not, see . */ - -#ifndef _READ_CSHARP_H -#define _READ_CSHARP_H - -#include "message.h" - -/* Read the Java resource given by resource_name and locale_name. - Returns a list of messages. */ -extern msgdomain_list_ty * - msgdomain_read_csharp (const char *resource_name, - const char *locale_name, - const char *directory); - -#endif /* _READ_CSHARP_H */ diff --git a/gettext-tools/src/read-java.c b/gettext-tools/src/read-java.c deleted file mode 100644 index 78391058d..000000000 --- a/gettext-tools/src/read-java.c +++ /dev/null @@ -1,128 +0,0 @@ -/* Reading Java ResourceBundles. - Copyright (C) 2001-2003, 2006-2008, 2010-2011, 2017, 2019 Free Software - Foundation, Inc. - Written by Bruno Haible , 2001. - - This program 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 3 of the License, or - (at your option) any later version. - - This program 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 this program. If not, see . */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -/* Specification. */ -#include "read-java.h" - -#include -#include -#include -#include - -#include "msgunfmt.h" -#include "relocatable.h" -#include "javaexec.h" -#include "spawn-pipe.h" -#include "wait-process.h" -#include "read-catalog.h" -#include "read-po.h" -#include "error.h" -#include "gettext.h" - -#define _(str) gettext (str) - - -/* A Java resource name can only be manipulated by a Java virtual machine. - So we start a JVM to execute the DumpResource program, and read its - output, which is .po format without comments. */ - -struct locals -{ - /* OUT */ - msgdomain_list_ty *mdlp; -}; - -static bool -execute_and_read_po_output (const char *progname, - const char *prog_path, char **prog_argv, - void *private_data) -{ - struct locals *l = (struct locals *) private_data; - pid_t child; - int fd[1]; - FILE *fp; - int exitstatus; - - /* Open a pipe to the JVM. */ - child = create_pipe_in (progname, prog_path, prog_argv, DEV_NULL, false, - true, true, fd); - - fp = fdopen (fd[0], "r"); - if (fp == NULL) - error (EXIT_FAILURE, errno, _("fdopen() failed")); - - /* Read the message list. */ - l->mdlp = read_catalog_stream (fp, "(pipe)", "(pipe)", &input_format_po); - - fclose (fp); - - /* Remove zombie process from process list, and retrieve exit status. */ - exitstatus = - wait_subprocess (child, progname, false, false, true, true, NULL); - if (exitstatus != 0) - error (EXIT_FAILURE, 0, _("%s subprocess failed with exit code %d"), - progname, exitstatus); - - return false; -} - - -msgdomain_list_ty * -msgdomain_read_java (const char *resource_name, const char *locale_name) -{ - const char *class_name = "gnu.gettext.DumpResource"; - const char *gettextjar; - const char *args[3]; - struct locals locals; - - /* Make it possible to override the gettext.jar location. This is - necessary for running the testsuite before "make install". */ - gettextjar = getenv ("GETTEXTJAR"); - if (gettextjar == NULL || gettextjar[0] == '\0') - gettextjar = relocate (GETTEXTJAR); - - /* Assign a default value to the resource name. */ - if (resource_name == NULL) - resource_name = "Messages"; - - /* Prepare arguments. */ - args[0] = resource_name; - if (locale_name != NULL) - { - args[1] = locale_name; - args[2] = NULL; - } - else - args[1] = NULL; - - /* Dump the resource and retrieve the resulting output. - Here we use the user's CLASSPATH, not a minimal one, so that the - resource can be found. */ - if (execute_java_class (class_name, &gettextjar, 1, false, NULL, - args, - verbose, false, - execute_and_read_po_output, &locals)) - /* An error message should already have been provided. */ - exit (EXIT_FAILURE); - - return locals.mdlp; -} diff --git a/gettext-tools/src/read-java.h b/gettext-tools/src/read-java.h deleted file mode 100644 index a87e4b066..000000000 --- a/gettext-tools/src/read-java.h +++ /dev/null @@ -1,29 +0,0 @@ -/* Reading Java ResourceBundles. - Copyright (C) 2001-2002 Free Software Foundation, Inc. - Written by Bruno Haible , 2001. - - This program 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 3 of the License, or - (at your option) any later version. - - This program 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 this program. If not, see . */ - -#ifndef _READ_JAVA_H -#define _READ_JAVA_H - -#include "message.h" - -/* Read the Java resource given by resource_name and locale_name. - Returns a list of messages. */ -extern msgdomain_list_ty * - msgdomain_read_java (const char *resource_name, - const char *locale_name); - -#endif /* _READ_JAVA_H */ diff --git a/gettext-tools/src/read-properties.c b/gettext-tools/src/read-properties.c deleted file mode 100644 index 8b6c84a04..000000000 --- a/gettext-tools/src/read-properties.c +++ /dev/null @@ -1,724 +0,0 @@ -/* Reading Java .properties files. - Copyright (C) 2003, 2005-2007, 2009, 2018 Free Software Foundation, Inc. - Written by Bruno Haible , 2003. - - This program 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 3 of the License, or - (at your option) any later version. - - This program 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 this program. If not, see . */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -/* Specification. */ -#include "read-properties.h" - -#include -#include -#include -#include -#include -#include - -#include "error.h" -#include "error-progname.h" -#include "message.h" -#include "read-catalog-abstract.h" -#include "xalloc.h" -#include "xvasprintf.h" -#include "po-xerror.h" -#include "msgl-ascii.h" -#include "read-file.h" -#include "unistr.h" -#include "gettext.h" - -#define _(str) gettext (str) - -/* For compiling this file in C++ mode. */ -#ifdef __cplusplus -# define this thiss -#endif - - -/* The format of the Java .properties files is documented in the JDK - documentation for class java.util.Properties. In the case of .properties - files for PropertyResourceBundle, each non-comment line contains a - key/value pair in the form "key = value" or "key : value" or "key value", - where the key is the msgid and the value is the msgstr. Messages with - plurals are not supported in this format. - - The encoding of Java .properties files is: - - ASCII with Java \uxxxx escape sequences, - - ISO-8859-1 if non-ASCII bytes are encounterd, - - UTF-8 if non-ASCII bytes are encountered and the entire file is - valid UTF-8 (in Java 9 or newer), see - https://docs.oracle.com/javase/9/intl/internationalization-enhancements-jdk-9.htm */ - -/* Handling of comments: We copy all comments from the .properties file to - the PO file. This is not really needed; it's a service for translators - who don't like PO files and prefer to maintain the .properties file. */ - -/* Real filename, used in error messages about the input file. */ -static const char *real_file_name; - -/* File name and line number. */ -extern lex_pos_ty gram_pos; - -/* The contents of the input file. */ -static char *contents; -static size_t contents_length; - -/* True if the input file is assumed to be in UTF-8 encoding. - False if it is assumed to be in ISO-8859-1 encoding. */ -static bool assume_utf8; - -/* Current position in contents. */ -static size_t position; - -/* Phase 1: Read an input byte. - Max. 1 pushback byte. */ - -static int -phase1_getc () -{ - if (position == contents_length) - return EOF; - - return (unsigned char) contents[position++]; -} - -static inline void -phase1_ungetc (int c) -{ - if (c != EOF) - position--; -} - - -/* Phase 2: Read an input byte, treating CR/LF like a single LF. - Max. 2 pushback bytes. */ - -static unsigned char phase2_pushback[2]; -static int phase2_pushback_length; - -static int -phase2_getc () -{ - int c; - - if (phase2_pushback_length) - c = phase2_pushback[--phase2_pushback_length]; - else - { - c = phase1_getc (); - - if (c == '\r') - { - int c2 = phase1_getc (); - if (c2 == '\n') - c = c2; - else - phase1_ungetc (c2); - } - } - - if (c == '\n') - gram_pos.line_number++; - - return c; -} - -static void -phase2_ungetc (int c) -{ - if (c == '\n') - --gram_pos.line_number; - if (c != EOF) - phase2_pushback[phase2_pushback_length++] = c; -} - - -/* Phase 3: Read an input byte, treating CR/LF like a single LF, - with handling of continuation lines. - Max. 1 pushback character. */ - -static int -phase3_getc () -{ - int c = phase2_getc (); - - for (;;) - { - if (c != '\\') - return c; - - c = phase2_getc (); - if (c != '\n') - { - phase2_ungetc (c); - return '\\'; - } - - /* Skip the backslash-newline and all whitespace that follows it. */ - do - c = phase2_getc (); - while (c == ' ' || c == '\t' || c == '\r' || c == '\f'); - } -} - -static inline void -phase3_ungetc (int c) -{ - phase2_ungetc (c); -} - - -/* Converts a string from ISO-8859-1 encoding to UTF-8 encoding. */ -static char * -conv_from_iso_8859_1 (char *string) -{ - if (is_ascii_string (string)) - return string; - else - { - size_t length = strlen (string); - /* Each ISO-8859-1 character needs 2 bytes at worst. */ - unsigned char *utf8_string = XNMALLOC (2 * length + 1, unsigned char); - unsigned char *q = utf8_string; - const char *str = string; - const char *str_limit = str + length; - - while (str < str_limit) - { - unsigned int uc = (unsigned char) *str++; - int n = u8_uctomb (q, uc, 6); - assert (n > 0); - q += n; - } - *q = '\0'; - assert (q - utf8_string <= 2 * length); - - return (char *) utf8_string; - } -} - - -/* Converts a string from JAVA encoding (with \uxxxx sequences) to UTF-8 - encoding. May destructively modify the argument string. */ -static char * -conv_from_java (char *string) -{ - /* This conversion can only shrink the string, never increase its size. - So there is no need to xmalloc the result freshly. */ - const char *p = string; - unsigned char *q = (unsigned char *) string; - - while (*p != '\0') - { - if (p[0] == '\\' && p[1] == 'u') - { - unsigned int n = 0; - int i; - - for (i = 0; i < 4; i++) - { - int c1 = (unsigned char) p[2 + i]; - - if (c1 >= '0' && c1 <= '9') - n = (n << 4) + (c1 - '0'); - else if (c1 >= 'A' && c1 <= 'F') - n = (n << 4) + (c1 - 'A' + 10); - else if (c1 >= 'a' && c1 <= 'f') - n = (n << 4) + (c1 - 'a' + 10); - else - goto just_one_byte; - } - - if (i == 4) - { - unsigned int uc; - - if (n >= 0xd800 && n < 0xdc00) - { - if (p[6] == '\\' && p[7] == 'u') - { - unsigned int m = 0; - - for (i = 0; i < 4; i++) - { - int c1 = (unsigned char) p[8 + i]; - - if (c1 >= '0' && c1 <= '9') - m = (m << 4) + (c1 - '0'); - else if (c1 >= 'A' && c1 <= 'F') - m = (m << 4) + (c1 - 'A' + 10); - else if (c1 >= 'a' && c1 <= 'f') - m = (m << 4) + (c1 - 'a' + 10); - else - goto just_one_byte; - } - - if (i == 4 && (m >= 0xdc00 && m < 0xe000)) - { - /* Combine two UTF-16 words to a character. */ - uc = 0x10000 + ((n - 0xd800) << 10) + (m - 0xdc00); - p += 12; - } - else - goto just_one_byte; - } - else - goto just_one_byte; - } - else - { - uc = n; - p += 6; - } - - q += u8_uctomb (q, uc, 6); - continue; - } - } - just_one_byte: - *q++ = (unsigned char) *p++; - } - *q = '\0'; - return string; -} - - -/* Phase 4: Read the next single byte or UTF-16 code point, - treating CR/LF like a single LF, with handling of continuation lines - and of \uxxxx sequences. */ - -/* Return value of phase 4 when EOF is reached. */ -#define P4_EOF 0xffff - -/* Convert an UTF-16 code point to a return value that can be distinguished - from a single-byte return value. */ -#define UNICODE(code) (0x10000 + (code)) - -/* Test a return value of phase 4 whether it designates an UTF-16 code - point. */ -#define IS_UNICODE(p4_result) ((p4_result) >= 0x10000) - -/* Extract the UTF-16 code of a return value that satisfies IS_UNICODE. */ -#define UTF16_VALUE(p4_result) ((p4_result) - 0x10000) - -static int -phase4_getuc () -{ - int c = phase3_getc (); - - if (c == EOF) - return P4_EOF; - if (c == '\\') - { - int c2 = phase3_getc (); - - if (c2 == 't') - return '\t'; - if (c2 == 'n') - return '\n'; - if (c2 == 'r') - return '\r'; - if (c2 == 'f') - return '\f'; - if (c2 == 'u') - { - unsigned int n = 0; - int i; - - for (i = 0; i < 4; i++) - { - int c1 = phase3_getc (); - - if (c1 >= '0' && c1 <= '9') - n = (n << 4) + (c1 - '0'); - else if (c1 >= 'A' && c1 <= 'F') - n = (n << 4) + (c1 - 'A' + 10); - else if (c1 >= 'a' && c1 <= 'f') - n = (n << 4) + (c1 - 'a' + 10); - else - { - phase3_ungetc (c1); - po_xerror (PO_SEVERITY_ERROR, NULL, - real_file_name, gram_pos.line_number, (size_t)(-1), - false, _("warning: invalid \\uxxxx syntax for Unicode character")); - return 'u'; - } - } - return UNICODE (n); - } - - return c2; - } - else - return c; -} - - -/* Reads a key or value string. - Returns the string in UTF-8 encoding, or NULL if the end of the logical - line is reached. - Parsing ends: - - when returning NULL, after the end of the logical line, - - otherwise, if in_key is true, after the whitespace and possibly the - separator that follows after the string, - - otherwise, if in_key is false, after the end of the logical line. */ - -static char * -read_escaped_string (bool in_key) -{ - /* The part of the string that has already been converted to UTF-8. */ - static unsigned char *utf8_buffer; - static size_t utf8_buflen; - static size_t utf8_allocated; - /* The first half of an UTF-16 surrogate character. */ - unsigned short utf16_surr; - /* Line in which this surrogate character occurred. */ - size_t utf16_surr_line; - - /* Ensures utf8_buffer has room for N bytes. N must be <= 10. */ - #define utf8_buffer_ensure_available(n) \ - do \ - { \ - if (utf8_buflen + (n) > utf8_allocated) \ - { \ - utf8_allocated = 2 * utf8_allocated + 10; \ - utf8_buffer = \ - (unsigned char *) xrealloc (utf8_buffer, utf8_allocated); \ - } \ - } \ - while (0) - - /* Appends a lone surrogate to utf8_buffer. */ - /* Note: A half surrogate is invalid in UTF-8: - - RFC 3629 says - "The definition of UTF-8 prohibits encoding character - numbers between U+D800 and U+DFFF". - - Unicode 4.0 chapter 3 - - section 3.9, p.77, says - "Because surrogate code points are not Unicode scalar - values, any UTF-8 byte sequence that would otherwise - map to code points D800..DFFF is ill-formed." - and in table 3-6, p. 78, does not mention D800..DFFF. - - The unicode.org FAQ question "How do I convert an unpaired - UTF-16 surrogate to UTF-8?" has the answer - "By representing such an unpaired surrogate on its own - as a 3-byte sequence, the resulting UTF-8 data stream - would become ill-formed." - So use U+FFFD instead. */ - #define utf8_buffer_append_lone_surrogate(uc, line) \ - do \ - { \ - error_with_progname = false; \ - po_xerror (PO_SEVERITY_ERROR, NULL, \ - real_file_name, (line), (size_t)(-1), false, \ - xasprintf (_("warning: lone surrogate U+%04X"), (uc))); \ - error_with_progname = true; \ - utf8_buffer_ensure_available (3); \ - utf8_buffer[utf8_buflen++] = 0xef; \ - utf8_buffer[utf8_buflen++] = 0xbf; \ - utf8_buffer[utf8_buflen++] = 0xbd; \ - } \ - while (0) - - int c; - - /* Skip whitespace before the string. */ - do - c = phase3_getc (); - while (c == ' ' || c == '\t' || c == '\r' || c == '\f'); - - if (c == EOF || c == '\n') - /* Empty string. */ - return NULL; - - /* Start accumulating the string. */ - utf8_buflen = 0; - utf16_surr = 0; - utf16_surr_line = 0; - for (;;) - { - if (in_key && (c == '=' || c == ':' - || c == ' ' || c == '\t' || c == '\r' || c == '\f')) - { - /* Skip whitespace after the string. */ - while (c == ' ' || c == '\t' || c == '\r' || c == '\f') - c = phase3_getc (); - /* Skip '=' or ':' separator. */ - if (!(c == '=' || c == ':')) - phase3_ungetc (c); - break; - } - - phase3_ungetc (c); - - /* Read the next byte or UTF-16 code point. */ - c = phase4_getuc (); - if (c == P4_EOF) - break; - - /* Append it to the buffer. */ - if (IS_UNICODE (c)) - { - /* Append an UTF-16 code point. */ - /* Test whether this character and the previous one form a Unicode - surrogate pair. */ - if (utf16_surr != 0 - && (c >= UNICODE (0xdc00) && c < UNICODE (0xe000))) - { - unsigned short utf16buf[2]; - ucs4_t uc; - int len; - - utf16buf[0] = utf16_surr; - utf16buf[1] = UTF16_VALUE (c); - if (u16_mbtouc (&uc, utf16buf, 2) != 2) - abort (); - - utf8_buffer_ensure_available (6); - len = u8_uctomb (utf8_buffer + utf8_buflen, uc, 6); - if (len < 0) - { - error_with_progname = false; - po_xerror (PO_SEVERITY_ERROR, NULL, - real_file_name, gram_pos.line_number, (size_t)(-1), - false, _("warning: invalid Unicode character")); - error_with_progname = true; - } - else - utf8_buflen += len; - - utf16_surr = 0; - } - else - { - if (utf16_surr != 0) - { - utf8_buffer_append_lone_surrogate (utf16_surr, utf16_surr_line); - utf16_surr = 0; - } - - if (c >= UNICODE (0xd800) && c < UNICODE (0xdc00)) - { - utf16_surr = UTF16_VALUE (c); - utf16_surr_line = gram_pos.line_number; - } - else if (c >= UNICODE (0xdc00) && c < UNICODE (0xe000)) - utf8_buffer_append_lone_surrogate (UTF16_VALUE (c), gram_pos.line_number); - else - { - ucs4_t uc = UTF16_VALUE (c); - int len; - - utf8_buffer_ensure_available (3); - len = u8_uctomb (utf8_buffer + utf8_buflen, uc, 3); - if (len < 0) - { - error_with_progname = false; - po_xerror (PO_SEVERITY_ERROR, NULL, - real_file_name, gram_pos.line_number, (size_t)(-1), - false, _("warning: invalid Unicode character")); - error_with_progname = true; - } - else - utf8_buflen += len; - } - } - } - else - { - /* Append a single byte. */ - if (utf16_surr != 0) - { - utf8_buffer_append_lone_surrogate (utf16_surr, utf16_surr_line); - utf16_surr = 0; - } - - if (assume_utf8) - { - /* No conversion needed. */ - utf8_buffer_ensure_available (1); - utf8_buffer[utf8_buflen++] = c; - } - else - { - /* Convert the byte from ISO-8859-1 to UTF-8 on the fly. */ - ucs4_t uc = c; - int len; - - utf8_buffer_ensure_available (2); - len = u8_uctomb (utf8_buffer + utf8_buflen, uc, 2); - if (len < 0) - abort (); - utf8_buflen += len; - } - } - - c = phase3_getc (); - if (c == EOF || c == '\n') - { - if (in_key) - phase3_ungetc (c); - break; - } - } - if (utf16_surr != 0) - utf8_buffer_append_lone_surrogate (utf16_surr, utf16_surr_line); - - /* Return the result. */ - { - unsigned char *utf8_string = XNMALLOC (utf8_buflen + 1, unsigned char); - memcpy (utf8_string, utf8_buffer, utf8_buflen); - utf8_string[utf8_buflen] = '\0'; - - return (char *) utf8_string; - } - #undef utf8_buffer_append_lone_surrogate - #undef utf8_buffer_ensure_available -} - - -/* Read a .properties file from a stream, and dispatch to the various - abstract_catalog_reader_class_ty methods. */ -static void -properties_parse (abstract_catalog_reader_ty *this, FILE *file, - const char *real_filename, const char *logical_filename) -{ - /* Read the file into memory. */ - contents = fread_file (file, &contents_length); - if (contents == NULL) - { - const char *errno_description = strerror (errno); - po_xerror (PO_SEVERITY_FATAL_ERROR, NULL, NULL, 0, 0, false, - xasprintf ("%s: %s", - xasprintf (_("error while reading \"%s\""), - real_filename), - errno_description)); - return; - } - - /* Test whether it's valid UTF-8. */ - assume_utf8 = (u8_check ((uint8_t *) contents, contents_length) == NULL); - - position = 0; - real_file_name = real_filename; - gram_pos.file_name = xstrdup (real_file_name); - gram_pos.line_number = 1; - - for (;;) - { - int c; - bool comment; - bool hidden; - - c = phase2_getc (); - - if (c == EOF) - break; - - comment = false; - hidden = false; - if (c == '#') - comment = true; - else if (c == '!') - { - /* For compatibility with write-properties.c, we treat '!' not - followed by space as a fuzzy or untranslated message. */ - int c2 = phase2_getc (); - if (c2 == ' ' || c2 == '\n' || c2 == EOF) - comment = true; - else - hidden = true; - phase2_ungetc (c2); - } - else - phase2_ungetc (c); - - if (comment) - { - /* A comment line. */ - static char *buffer; - static size_t bufmax; - static size_t buflen; - - buflen = 0; - for (;;) - { - c = phase2_getc (); - - if (buflen >= bufmax) - { - bufmax += 100; - buffer = xrealloc (buffer, bufmax); - } - - if (c == EOF || c == '\n') - break; - - buffer[buflen++] = c; - } - buffer[buflen] = '\0'; - - po_callback_comment_dispatcher ( - conv_from_java ( - assume_utf8 ? buffer : conv_from_iso_8859_1 (buffer))); - } - else - { - /* A key/value pair. */ - char *msgid; - lex_pos_ty msgid_pos; - - msgid_pos = gram_pos; - msgid = read_escaped_string (true); - if (msgid == NULL) - /* Skip blank line. */ - ; - else - { - char *msgstr; - lex_pos_ty msgstr_pos; - bool force_fuzzy; - - msgstr_pos = gram_pos; - msgstr = read_escaped_string (false); - if (msgstr == NULL) - msgstr = xstrdup (""); - - /* Be sure to make the message fuzzy if it was commented out - and if it is not already header/fuzzy/untranslated. */ - force_fuzzy = (hidden && msgid[0] != '\0' && msgstr[0] != '\0'); - - po_callback_message (NULL, msgid, &msgid_pos, NULL, - msgstr, strlen (msgstr) + 1, &msgstr_pos, - NULL, NULL, NULL, - force_fuzzy, false); - } - } - } - - free (contents); - contents = NULL; - real_file_name = NULL; - gram_pos.line_number = 0; -} - -const struct catalog_input_format input_format_properties = -{ - properties_parse, /* parse */ - true /* produces_utf8 */ -}; diff --git a/gettext-tools/src/read-properties.h b/gettext-tools/src/read-properties.h deleted file mode 100644 index 9c299e6c2..000000000 --- a/gettext-tools/src/read-properties.h +++ /dev/null @@ -1,38 +0,0 @@ -/* Reading Java .properties files. - Copyright (C) 2003, 2006, 2019 Free Software Foundation, Inc. - Written by Bruno Haible , 2003. - - This program 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 3 of the License, or - (at your option) any later version. - - This program 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 this program. If not, see . */ - -#ifndef _READ_PROPERTIES_H -#define _READ_PROPERTIES_H - -#include "read-catalog-abstract.h" - - -#ifdef __cplusplus -extern "C" { -#endif - - -/* Describes a .properties file parser. */ -extern DLL_VARIABLE const struct catalog_input_format input_format_properties; - - -#ifdef __cplusplus -} -#endif - - -#endif /* _READ_PROPERTIES_H */ diff --git a/gettext-tools/src/read-resources.c b/gettext-tools/src/read-resources.c deleted file mode 100644 index 822fc5dbb..000000000 --- a/gettext-tools/src/read-resources.c +++ /dev/null @@ -1,138 +0,0 @@ -/* Reading C# .resources files. - Copyright (C) 2003-2004, 2006-2008, 2010-2011 Free Software Foundation, Inc. - Written by Bruno Haible , 2003. - - This program 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 3 of the License, or - (at your option) any later version. - - This program 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 this program. If not, see . */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -/* Specification. */ -#include "read-resources.h" - -#include -#include -#include -#include - -#include "msgunfmt.h" -#include "relocatable.h" -#include "csharpexec.h" -#include "spawn-pipe.h" -#include "wait-process.h" -#include "read-catalog.h" -#include "read-po.h" -#include "message.h" -#include "concat-filename.h" -#include "error.h" -#include "gettext.h" - -#define _(str) gettext (str) - - -/* A .resources file has such a complex format that it's most easily read - through the C# class ResourceReader. So we start a C# process to execute - the DumpResource program, and read its output, which is .po format without - comments. */ - -struct locals -{ - /* OUT */ - msgdomain_list_ty *mdlp; -}; - -static bool -execute_and_read_po_output (const char *progname, - const char *prog_path, char **prog_argv, - void *private_data) -{ - struct locals *l = (struct locals *) private_data; - pid_t child; - int fd[1]; - FILE *fp; - int exitstatus; - - /* Open a pipe to the C# execution engine. */ - child = create_pipe_in (progname, prog_path, prog_argv, NULL, false, - true, true, fd); - - fp = fdopen (fd[0], "r"); - if (fp == NULL) - error (EXIT_FAILURE, errno, _("fdopen() failed")); - - /* Read the message list. */ - l->mdlp = read_catalog_stream (fp, "(pipe)", "(pipe)", &input_format_po); - - fclose (fp); - - /* Remove zombie process from process list, and retrieve exit status. */ - exitstatus = - wait_subprocess (child, progname, false, false, true, true, NULL); - if (exitstatus != 0) - error (EXIT_FAILURE, 0, _("%s subprocess failed with exit code %d"), - progname, exitstatus); - - return false; -} - - -void -read_resources_file (message_list_ty *mlp, const char *filename) -{ - const char *args[2]; - const char *gettextexedir; - const char *gettextlibdir; - char *assembly_path; - const char *libdirs[1]; - struct locals locals; - - /* Prepare arguments. */ - args[0] = filename; - args[1] = NULL; - - /* Make it possible to override the .exe location. This is - necessary for running the testsuite before "make install". */ - gettextexedir = getenv ("GETTEXTCSHARPEXEDIR"); - if (gettextexedir == NULL || gettextexedir[0] == '\0') - gettextexedir = relocate (LIBDIR "/gettext"); - - /* Make it possible to override the .dll location. This is - necessary for running the testsuite before "make install". */ - gettextlibdir = getenv ("GETTEXTCSHARPLIBDIR"); - if (gettextlibdir == NULL || gettextlibdir[0] == '\0') - gettextlibdir = relocate (LIBDIR); - - /* Dump the resource and retrieve the resulting output. */ - assembly_path = - xconcatenated_filename (gettextexedir, "msgunfmt.net", ".exe"); - libdirs[0] = gettextlibdir; - if (execute_csharp_program (assembly_path, libdirs, 1, - args, - verbose, false, - execute_and_read_po_output, &locals)) - /* An error message should already have been provided. */ - exit (EXIT_FAILURE); - - /* Add the output to mlp. */ - { - message_list_ty *read_mlp = locals.mdlp->item[0]->messages; - size_t j; - - for (j = 0; j < read_mlp->nitems; j++) - message_list_append (mlp, read_mlp->item[j]); - } - - free (assembly_path); -} diff --git a/gettext-tools/src/urlget.c b/gettext-tools/src/urlget.c index c47f27e12..213ae32e1 100644 --- a/gettext-tools/src/urlget.c +++ b/gettext-tools/src/urlget.c @@ -38,7 +38,6 @@ #include "basename.h" #include "full-write.h" #include "execute.h" -#include "javaexec.h" #include "binary-io.h" #include "propername.h" #include "gettext.h" @@ -52,8 +51,7 @@ /* Only high-level toolkits, written in languages with exception handling, have an URL datatype and operations to fetch an URL's contents. Such - toolkits are Java (class java.net.URL), Qt (classes QUrl and QUrlOperator). - We use the Java toolkit. + toolkits are Qt (classes QUrl and QUrlOperator). Note that this program doesn't handle redirection pages; programs which wish to process HTML redirection tags need to include a HTML parser, and only full-fledged browsers like w3m, lynx, links have have both @@ -241,27 +239,6 @@ cat_file (const char *src_filename) error (EXIT_FAILURE, errno, _("error after reading \"%s\""), src_filename); } -#if USEJAVA - -/* Exit code of the Java program. */ -static int java_exitcode; - -static bool -execute_it (const char *progname, - const char *prog_path, char **prog_argv, - void *private_data) -{ - (void) private_data; - - java_exitcode = - execute (progname, prog_path, prog_argv, true, true, false, false, true, - false, NULL); - /* Exit code 0 means success, 2 means timed out. */ - return !(java_exitcode == 0 || java_exitcode == 2); -} - -#endif - /* Fetch the URL. Upon error, use the FILE as fallback. */ static void fetch (const char *url, const char *file) @@ -272,42 +249,6 @@ fetch (const char *url, const char *file) fflush (stderr); } -#if USEJAVA - /* First try: using Java. */ - { - const char *class_name = "gnu.gettext.GetURL"; - const char *gettextjar; - const char *args[2]; - - /* Make it possible to override the gettext.jar location. This is - necessary for running the testsuite before "make install". */ - gettextjar = getenv ("GETTEXTJAR"); - if (gettextjar == NULL || gettextjar[0] == '\0') - gettextjar = relocate (GETTEXTJAR); - - /* Prepare arguments. */ - args[0] = url; - args[1] = NULL; - - /* Fetch the URL's contents. */ - java_exitcode = 127; - if (!execute_java_class (class_name, &gettextjar, 1, true, NULL, - args, - false, true, - execute_it, NULL)) - { - if (verbose) - { - if (java_exitcode == 0) - fprintf (stderr, _(" done.\n")); - else if (java_exitcode == 2) - fprintf (stderr, _(" timed out.\n")); - } - return; - } - } -#endif - /* Second try: using "wget -q -O - -T 30 url". */ { static bool wget_tested; diff --git a/gettext-tools/src/write-catalog.c b/gettext-tools/src/write-catalog.c index 504bbaccd..c60979bb5 100644 --- a/gettext-tools/src/write-catalog.c +++ b/gettext-tools/src/write-catalog.c @@ -189,12 +189,6 @@ msgdomain_list_print (msgdomain_list_ty *mdlp, const char *filename, if (has_plural != NULL) { error_with_progname = false; - if (output_syntax->alternative_is_java_class) - po_xerror (PO_SEVERITY_FATAL_ERROR, NULL, - has_plural->file_name, has_plural->line_number, - (size_t)(-1), false, - _("message catalog has plural form translations, but the output format does not support them. Try generating a Java class using \"msgfmt --java\", instead of a properties file.")); - else po_xerror (PO_SEVERITY_FATAL_ERROR, NULL, has_plural->file_name, has_plural->line_number, (size_t)(-1), false, diff --git a/gettext-tools/src/write-catalog.h b/gettext-tools/src/write-catalog.h index 5813429fb..a01dcf2be 100644 --- a/gettext-tools/src/write-catalog.h +++ b/gettext-tools/src/write-catalog.h @@ -57,10 +57,6 @@ struct catalog_output_format /* Whether the PO file format is a suitable alternative output format for this one. */ bool alternative_is_po; - - /* Whether a Java class is a suitable alternative output format for this - one. */ - bool alternative_is_java_class; }; typedef const struct catalog_output_format * catalog_output_format_ty; diff --git a/gettext-tools/src/write-csharp.c b/gettext-tools/src/write-csharp.c deleted file mode 100644 index 52e32d8e2..000000000 --- a/gettext-tools/src/write-csharp.c +++ /dev/null @@ -1,788 +0,0 @@ -/* Writing C# satellite assemblies. - Copyright (C) 2003-2010, 2016, 2018-2019 Free Software Foundation, Inc. - Written by Bruno Haible , 2003. - - This program 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 3 of the License, or - (at your option) any later version. - - This program 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 this program. If not, see . */ - -#ifdef HAVE_CONFIG_H -# include -#endif -#include - -/* Specification. */ -#include "write-csharp.h" - -#include -#include -#include -#include -#include - -#include -#if !defined S_ISDIR && defined S_IFDIR -# define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR) -#endif -#if !S_IRUSR && S_IREAD -# define S_IRUSR S_IREAD -#endif -#if !S_IRUSR -# define S_IRUSR 00400 -#endif -#if !S_IWUSR && S_IWRITE -# define S_IWUSR S_IWRITE -#endif -#if !S_IWUSR -# define S_IWUSR 00200 -#endif -#if !S_IXUSR && S_IEXEC -# define S_IXUSR S_IEXEC -#endif -#if !S_IXUSR -# define S_IXUSR 00100 -#endif -#if !S_IRGRP -# define S_IRGRP (S_IRUSR >> 3) -#endif -#if !S_IWGRP -# define S_IWGRP (S_IWUSR >> 3) -#endif -#if !S_IXGRP -# define S_IXGRP (S_IXUSR >> 3) -#endif -#if !S_IROTH -# define S_IROTH (S_IRUSR >> 6) -#endif -#if !S_IWOTH -# define S_IWOTH (S_IWUSR >> 6) -#endif -#if !S_IXOTH -# define S_IXOTH (S_IXUSR >> 6) -#endif - -#include "c-ctype.h" -#include "relocatable.h" -#include "error.h" -#include "xerror.h" -#include "csharpcomp.h" -#include "message.h" -#include "msgfmt.h" -#include "msgl-iconv.h" -#include "msgl-header.h" -#include "plural-exp.h" -#include "po-charset.h" -#include "xalloc.h" -#include "xmalloca.h" -#include "concat-filename.h" -#include "fwriteerror.h" -#include "clean-temp.h" -#include "unistr.h" -#include "gettext.h" - -#define _(str) gettext (str) - - -/* Convert a resource name to a class name. - Return a nonempty string consisting of alphanumerics and underscores - and starting with a letter or underscore. */ -static char * -construct_class_name (const char *resource_name) -{ - /* This code must be kept consistent with intl.cs, function - GettextResourceManager.ConstructClassName. */ - /* We could just return an arbitrary fixed class name, like "Messages", - assuming that every assembly will only ever contain one - GettextResourceSet subclass, but this assumption would break the day - we want to support multi-domain PO files in the same format... */ - bool valid; - const char *p; - - /* Test for a valid ASCII identifier: - - nonempty, - - first character is A..Za..z_ - see x-csharp.c:is_identifier_start. - - next characters are A..Za..z_0..9 - see x-csharp.c:is_identifier_part. - */ - valid = (resource_name[0] != '\0'); - for (p = resource_name; valid && *p != '\0'; p++) - { - char c = *p; - if (!((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || (c == '_') - || (p > resource_name && c >= '0' && c <= '9'))) - valid = false; - } - if (valid) - return xstrdup (resource_name); - else - { - static const char hexdigit[] = "0123456789abcdef"; - const char *str = resource_name; - const char *str_limit = str + strlen (str); - char *class_name = XNMALLOC (12 + 6 * (str_limit - str) + 1, char); - char *b; - - b = class_name; - memcpy (b, "__UESCAPED__", 12); b += 12; - while (str < str_limit) - { - ucs4_t uc; - str += u8_mbtouc (&uc, (const unsigned char *) str, str_limit - str); - if (uc >= 0x10000) - { - *b++ = '_'; - *b++ = 'U'; - *b++ = hexdigit[(uc >> 28) & 0x0f]; - *b++ = hexdigit[(uc >> 24) & 0x0f]; - *b++ = hexdigit[(uc >> 20) & 0x0f]; - *b++ = hexdigit[(uc >> 16) & 0x0f]; - *b++ = hexdigit[(uc >> 12) & 0x0f]; - *b++ = hexdigit[(uc >> 8) & 0x0f]; - *b++ = hexdigit[(uc >> 4) & 0x0f]; - *b++ = hexdigit[uc & 0x0f]; - } - else if (!((uc >= 'A' && uc <= 'Z') || (uc >= 'a' && uc <= 'z') - || (uc >= '0' && uc <= '9'))) - { - *b++ = '_'; - *b++ = 'u'; - *b++ = hexdigit[(uc >> 12) & 0x0f]; - *b++ = hexdigit[(uc >> 8) & 0x0f]; - *b++ = hexdigit[(uc >> 4) & 0x0f]; - *b++ = hexdigit[uc & 0x0f]; - } - else - *b++ = uc; - } - *b++ = '\0'; - return (char *) xrealloc (class_name, b - class_name); - } -} - - -/* Write a string in C# Unicode notation to the given stream. */ -static void -write_csharp_string (FILE *stream, const char *str) -{ - static const char hexdigit[] = "0123456789abcdef"; - const char *str_limit = str + strlen (str); - - fprintf (stream, "\""); - while (str < str_limit) - { - ucs4_t uc; - str += u8_mbtouc (&uc, (const unsigned char *) str, str_limit - str); - if (uc == 0x0000) - fprintf (stream, "\\0"); - else if (uc == 0x0007) - fprintf (stream, "\\a"); - else if (uc == 0x0008) - fprintf (stream, "\\b"); - else if (uc == 0x0009) - fprintf (stream, "\\t"); - else if (uc == 0x000a) - fprintf (stream, "\\n"); - else if (uc == 0x000b) - fprintf (stream, "\\v"); - else if (uc == 0x000c) - fprintf (stream, "\\f"); - else if (uc == 0x000d) - fprintf (stream, "\\r"); - else if (uc == 0x0022) - fprintf (stream, "\\\""); - else if (uc == 0x005c) - fprintf (stream, "\\\\"); - else if (uc >= 0x0020 && uc < 0x007f) - fprintf (stream, "%c", (int) uc); - else if (uc < 0x10000) - fprintf (stream, "\\u%c%c%c%c", - hexdigit[(uc >> 12) & 0x0f], hexdigit[(uc >> 8) & 0x0f], - hexdigit[(uc >> 4) & 0x0f], hexdigit[uc & 0x0f]); - else - fprintf (stream, "\\U%c%c%c%c%c%c%c%c", - hexdigit[(uc >> 28) & 0x0f], hexdigit[(uc >> 24) & 0x0f], - hexdigit[(uc >> 20) & 0x0f], hexdigit[(uc >> 16) & 0x0f], - hexdigit[(uc >> 12) & 0x0f], hexdigit[(uc >> 8) & 0x0f], - hexdigit[(uc >> 4) & 0x0f], hexdigit[uc & 0x0f]); - } - fprintf (stream, "\""); -} - - -/* Write a (msgctxt, msgid) pair as a string in C# Unicode notation to the - given stream. */ -static void -write_csharp_msgid (FILE *stream, message_ty *mp) -{ - const char *msgctxt = mp->msgctxt; - const char *msgid = mp->msgid; - - if (msgctxt == NULL) - write_csharp_string (stream, msgid); - else - { - size_t msgctxt_len = strlen (msgctxt); - size_t msgid_len = strlen (msgid); - size_t combined_len = msgctxt_len + 1 + msgid_len; - char *combined; - - combined = (char *) xmalloca (combined_len + 1); - memcpy (combined, msgctxt, msgctxt_len); - combined[msgctxt_len] = MSGCTXT_SEPARATOR; - memcpy (combined + msgctxt_len + 1, msgid, msgid_len + 1); - - write_csharp_string (stream, combined); - - freea (combined); - } -} - - -/* Write C# code that returns the value for a message. If the message - has plural forms, it is an expression of type System.String[], otherwise it - is an expression of type System.String. */ -static void -write_csharp_msgstr (FILE *stream, message_ty *mp) -{ - if (mp->msgid_plural != NULL) - { - bool first; - const char *p; - - fprintf (stream, "new System.String[] { "); - for (p = mp->msgstr, first = true; - p < mp->msgstr + mp->msgstr_len; - p += strlen (p) + 1, first = false) - { - if (!first) - fprintf (stream, ", "); - write_csharp_string (stream, p); - } - fprintf (stream, " }"); - } - else - { - if (mp->msgstr_len != strlen (mp->msgstr) + 1) - abort (); - - write_csharp_string (stream, mp->msgstr); - } -} - - -/* Tests whether a plural expression, evaluated according to the C rules, - can only produce the values 0 and 1. */ -static bool -is_expression_boolean (struct expression *exp) -{ - switch (exp->operation) - { - case var: - case mult: - case divide: - case module: - case plus: - case minus: - return false; - case lnot: - case less_than: - case greater_than: - case less_or_equal: - case greater_or_equal: - case equal: - case not_equal: - case land: - case lor: - return true; - case num: - return (exp->val.num == 0 || exp->val.num == 1); - case qmop: - return is_expression_boolean (exp->val.args[1]) - && is_expression_boolean (exp->val.args[2]); - default: - abort (); - } -} - - -/* Write C# code that evaluates a plural expression according to the C rules. - The variable is called 'n'. */ -static void -write_csharp_expression (FILE *stream, const struct expression *exp, bool as_boolean) -{ - /* We use parentheses everywhere. This frees us from tracking the priority - of arithmetic operators. */ - if (as_boolean) - { - /* Emit a C# expression of type 'bool'. */ - switch (exp->operation) - { - case num: - fprintf (stream, "%s", exp->val.num ? "true" : "false"); - return; - case lnot: - fprintf (stream, "(!"); - write_csharp_expression (stream, exp->val.args[0], true); - fprintf (stream, ")"); - return; - case less_than: - fprintf (stream, "("); - write_csharp_expression (stream, exp->val.args[0], false); - fprintf (stream, " < "); - write_csharp_expression (stream, exp->val.args[1], false); - fprintf (stream, ")"); - return; - case greater_than: - fprintf (stream, "("); - write_csharp_expression (stream, exp->val.args[0], false); - fprintf (stream, " > "); - write_csharp_expression (stream, exp->val.args[1], false); - fprintf (stream, ")"); - return; - case less_or_equal: - fprintf (stream, "("); - write_csharp_expression (stream, exp->val.args[0], false); - fprintf (stream, " <= "); - write_csharp_expression (stream, exp->val.args[1], false); - fprintf (stream, ")"); - return; - case greater_or_equal: - fprintf (stream, "("); - write_csharp_expression (stream, exp->val.args[0], false); - fprintf (stream, " >= "); - write_csharp_expression (stream, exp->val.args[1], false); - fprintf (stream, ")"); - return; - case equal: - fprintf (stream, "("); - write_csharp_expression (stream, exp->val.args[0], false); - fprintf (stream, " == "); - write_csharp_expression (stream, exp->val.args[1], false); - fprintf (stream, ")"); - return; - case not_equal: - fprintf (stream, "("); - write_csharp_expression (stream, exp->val.args[0], false); - fprintf (stream, " != "); - write_csharp_expression (stream, exp->val.args[1], false); - fprintf (stream, ")"); - return; - case land: - fprintf (stream, "("); - write_csharp_expression (stream, exp->val.args[0], true); - fprintf (stream, " && "); - write_csharp_expression (stream, exp->val.args[1], true); - fprintf (stream, ")"); - return; - case lor: - fprintf (stream, "("); - write_csharp_expression (stream, exp->val.args[0], true); - fprintf (stream, " || "); - write_csharp_expression (stream, exp->val.args[1], true); - fprintf (stream, ")"); - return; - case qmop: - if (is_expression_boolean (exp->val.args[1]) - && is_expression_boolean (exp->val.args[2])) - { - fprintf (stream, "("); - write_csharp_expression (stream, exp->val.args[0], true); - fprintf (stream, " ? "); - write_csharp_expression (stream, exp->val.args[1], true); - fprintf (stream, " : "); - write_csharp_expression (stream, exp->val.args[2], true); - fprintf (stream, ")"); - return; - } - /*FALLTHROUGH*/ - case var: - case mult: - case divide: - case module: - case plus: - case minus: - fprintf (stream, "("); - write_csharp_expression (stream, exp, false); - fprintf (stream, " != 0)"); - return; - default: - abort (); - } - } - else - { - /* Emit a C# expression of type 'long'. */ - switch (exp->operation) - { - case var: - fprintf (stream, "n"); - return; - case num: - fprintf (stream, "%lu", exp->val.num); - return; - case mult: - fprintf (stream, "("); - write_csharp_expression (stream, exp->val.args[0], false); - fprintf (stream, " * "); - write_csharp_expression (stream, exp->val.args[1], false); - fprintf (stream, ")"); - return; - case divide: - fprintf (stream, "("); - write_csharp_expression (stream, exp->val.args[0], false); - fprintf (stream, " / "); - write_csharp_expression (stream, exp->val.args[1], false); - fprintf (stream, ")"); - return; - case module: - fprintf (stream, "("); - write_csharp_expression (stream, exp->val.args[0], false); - fprintf (stream, " %% "); - write_csharp_expression (stream, exp->val.args[1], false); - fprintf (stream, ")"); - return; - case plus: - fprintf (stream, "("); - write_csharp_expression (stream, exp->val.args[0], false); - fprintf (stream, " + "); - write_csharp_expression (stream, exp->val.args[1], false); - fprintf (stream, ")"); - return; - case minus: - fprintf (stream, "("); - write_csharp_expression (stream, exp->val.args[0], false); - fprintf (stream, " - "); - write_csharp_expression (stream, exp->val.args[1], false); - fprintf (stream, ")"); - return; - case qmop: - fprintf (stream, "("); - write_csharp_expression (stream, exp->val.args[0], true); - fprintf (stream, " ? "); - write_csharp_expression (stream, exp->val.args[1], false); - fprintf (stream, " : "); - write_csharp_expression (stream, exp->val.args[2], false); - fprintf (stream, ")"); - return; - case lnot: - case less_than: - case greater_than: - case less_or_equal: - case greater_or_equal: - case equal: - case not_equal: - case land: - case lor: - fprintf (stream, "("); - write_csharp_expression (stream, exp, true); - fprintf (stream, " ? 1 : 0)"); - return; - default: - abort (); - } - } -} - - -/* Write the C# code for the GettextResourceSet subclass to the given stream. - Note that we use fully qualified class names and no "using" statements, - because applications can have their own classes called X.Y.Hashtable or - X.Y.String. */ -static void -write_csharp_code (FILE *stream, const char *culture_name, const char *class_name, message_list_ty *mlp) -{ - const char *last_dot; - const char *class_name_last_part; - unsigned int plurals; - size_t j; - - fprintf (stream, - "/* Automatically generated by GNU msgfmt. Do not modify! */\n"); - - /* We chose to use a "using" statement here, to avoid a bug in the pnet-0.6.0 - compiler. */ - fprintf (stream, "using GNU.Gettext;\n"); - - /* Assign a strong name to the assembly, so that two different localizations - of the same domain can be loaded one after the other. This strong name - tells the Global Assembly Cache that they are meant to be different. */ - fprintf (stream, "[assembly: System.Reflection.AssemblyCulture("); - write_csharp_string (stream, culture_name); - fprintf (stream, ")]\n"); - - last_dot = strrchr (class_name, '.'); - if (last_dot != NULL) - { - fprintf (stream, "namespace "); - fwrite (class_name, 1, last_dot - class_name, stream); - fprintf (stream, " {\n"); - class_name_last_part = last_dot + 1; - } - else - class_name_last_part = class_name; - fprintf (stream, "public class %s : GettextResourceSet {\n", - class_name_last_part); - - /* Determine whether there are plural messages. */ - plurals = 0; - for (j = 0; j < mlp->nitems; j++) - if (mlp->item[j]->msgid_plural != NULL) - plurals++; - - /* Emit the constructor. */ - fprintf (stream, " public %s ()\n", class_name_last_part); - fprintf (stream, " : base () {\n"); - fprintf (stream, " }\n"); - - /* Emit the TableInitialized field. */ - fprintf (stream, " private bool TableInitialized;\n"); - - /* Emit the ReadResources method. */ - fprintf (stream, " protected override void ReadResources () {\n"); - /* In some implementations, such as mono < 2009-02-27, the ReadResources - method is called just once, when Table == null. In other implementations, - such as mono >= 2009-02-27, it is called at every GetObject call, and it - is responsible for doing the initialization only once, even when called - simultaneously from multiple threads. */ - fprintf (stream, " if (!TableInitialized) {\n"); - fprintf (stream, " lock (this) {\n"); - fprintf (stream, " if (!TableInitialized) {\n"); - /* In some implementations, the ResourceSet constructor initializes Table - before calling ReadResources(). In other implementations, the - ReadResources() method is expected to initialize the Table. */ - fprintf (stream, " if (Table == null)\n"); - fprintf (stream, " Table = new System.Collections.Hashtable();\n"); - fprintf (stream, " System.Collections.Hashtable t = Table;\n"); - for (j = 0; j < mlp->nitems; j++) - { - fprintf (stream, " t.Add("); - write_csharp_msgid (stream, mlp->item[j]); - fprintf (stream, ","); - write_csharp_msgstr (stream, mlp->item[j]); - fprintf (stream, ");\n"); - } - fprintf (stream, " TableInitialized = true;\n"); - fprintf (stream, " }\n"); - fprintf (stream, " }\n"); - fprintf (stream, " }\n"); - fprintf (stream, " }\n"); - - /* Emit the msgid_plural strings. Only used by msgunfmt. */ - if (plurals) - { - fprintf (stream, " public static System.Collections.Hashtable GetMsgidPluralTable () {\n"); - fprintf (stream, " System.Collections.Hashtable t = new System.Collections.Hashtable();\n"); - for (j = 0; j < mlp->nitems; j++) - if (mlp->item[j]->msgid_plural != NULL) - { - fprintf (stream, " t.Add("); - write_csharp_msgid (stream, mlp->item[j]); - fprintf (stream, ","); - write_csharp_string (stream, mlp->item[j]->msgid_plural); - fprintf (stream, ");\n"); - } - fprintf (stream, " return t;\n"); - fprintf (stream, " }\n"); - } - - /* Emit the PluralEval function. It is a subroutine for GetPluralString. */ - if (plurals) - { - message_ty *header_entry; - const struct expression *plural; - unsigned long int nplurals; - - header_entry = message_list_search (mlp, NULL, ""); - extract_plural_expression (header_entry ? header_entry->msgstr : NULL, - &plural, &nplurals); - - fprintf (stream, " protected override long PluralEval (long n) {\n"); - fprintf (stream, " return "); - write_csharp_expression (stream, plural, false); - fprintf (stream, ";\n"); - fprintf (stream, " }\n"); - } - - /* Terminate the class. */ - fprintf (stream, "}\n"); - - if (last_dot != NULL) - /* Terminate the namespace. */ - fprintf (stream, "}\n"); -} - - -int -msgdomain_write_csharp (message_list_ty *mlp, const char *canon_encoding, - const char *resource_name, const char *locale_name, - const char *directory) -{ - int retval; - struct temp_dir *tmpdir; - char *culture_name; - char *output_file; - char *class_name; - char *csharp_file_name; - FILE *csharp_file; - const char *gettextlibdir; - const char *csharp_sources[1]; - const char *libdirs[1]; - const char *libraries[1]; - - /* If no entry for this resource/domain, don't even create the file. */ - if (mlp->nitems == 0) - return 0; - - retval = 1; - - /* Convert the messages to Unicode. */ - iconv_message_list (mlp, canon_encoding, po_charset_utf8, NULL); - - /* Support for "reproducible builds": Delete information that may vary - between builds in the same conditions. */ - message_list_delete_header_field (mlp, "POT-Creation-Date:"); - - /* Create a temporary directory where we can put the C# file. - A simple temporary file would also be possible but would require us to - define our own variant of mkstemp(): On one hand the functions mktemp(), - tmpnam(), tempnam() present a security risk, and on the other hand the - function mkstemp() doesn't allow to specify a fixed suffix of the file. - It is simpler to create a temporary directory. */ - tmpdir = create_temp_dir ("msg", NULL, false); - if (tmpdir == NULL) - goto quit1; - - /* Assign a default value to the resource name. */ - if (resource_name == NULL) - resource_name = "Messages"; - - /* Convert the locale name to a .NET specific culture name. */ - culture_name = xstrdup (locale_name); - { - char *p; - for (p = culture_name; *p != '\0'; p++) - if (*p == '_') - *p = '-'; - if (strncmp (culture_name, "sr-CS", 5) == 0) - memcpy (culture_name, "sr-SP", 5); - p = strchr (culture_name, '@'); - if (p != NULL) - { - if (strcmp (p, "@latin") == 0) - strcpy (p, "-Latn"); - else if (strcmp (p, "@cyrillic") == 0) - strcpy (p, "-Cyrl"); - } - if (strcmp (culture_name, "sr-SP") == 0) - { - free (culture_name); - culture_name = xstrdup ("sr-SP-Latn"); - } - else if (strcmp (culture_name, "uz-UZ") == 0) - { - free (culture_name); - culture_name = xstrdup ("uz-UZ-Latn"); - } - } - - /* Compute the output file name. This code must be kept consistent with - intl.cs, function GetSatelliteAssembly(). */ - { - char *output_dir = xconcatenated_filename (directory, culture_name, NULL); - struct stat statbuf; - - /* Try to create the output directory if it does not yet exist. */ - if (stat (output_dir, &statbuf) < 0 && errno == ENOENT) - if (mkdir (output_dir, S_IRUSR | S_IWUSR | S_IXUSR - | S_IRGRP | S_IWGRP | S_IXGRP - | S_IROTH | S_IWOTH | S_IXOTH) < 0) - { - error (0, errno, _("failed to create directory \"%s\""), output_dir); - free (output_dir); - goto quit2; - } - - output_file = - xconcatenated_filename (output_dir, resource_name, ".resources.dll"); - - free (output_dir); - } - - /* Compute the class name. This code must be kept consistent with intl.cs, - function InstantiateResourceSet(). */ - { - char *class_name_part1 = construct_class_name (resource_name); - char *p; - - class_name = - XNMALLOC (strlen (class_name_part1) + 1 + strlen (culture_name) + 1, char); - sprintf (class_name, "%s_%s", class_name_part1, culture_name); - for (p = class_name + strlen (class_name_part1) + 1; *p != '\0'; p++) - if (*p == '-') - *p = '_'; - free (class_name_part1); - } - - /* Compute the temporary C# file name. It must end in ".cs", so that - the C# compiler recognizes that it is C# source code. */ - csharp_file_name = - xconcatenated_filename (tmpdir->dir_name, "resset.cs", NULL); - - /* Create the C# file. */ - register_temp_file (tmpdir, csharp_file_name); - csharp_file = fopen_temp (csharp_file_name, "w"); - if (csharp_file == NULL) - { - error (0, errno, _("failed to create \"%s\""), csharp_file_name); - unregister_temp_file (tmpdir, csharp_file_name); - goto quit3; - } - - write_csharp_code (csharp_file, culture_name, class_name, mlp); - - if (fwriteerror_temp (csharp_file)) - { - error (0, errno, _("error while writing \"%s\" file"), csharp_file_name); - goto quit3; - } - - /* Make it possible to override the .dll location. This is - necessary for running the testsuite before "make install". */ - gettextlibdir = getenv ("GETTEXTCSHARPLIBDIR"); - if (gettextlibdir == NULL || gettextlibdir[0] == '\0') - gettextlibdir = relocate (LIBDIR); - - /* Compile the C# file to a .dll file. */ - csharp_sources[0] = csharp_file_name; - libdirs[0] = gettextlibdir; - libraries[0] = "GNU.Gettext"; - if (compile_csharp_class (csharp_sources, 1, libdirs, 1, libraries, 1, - output_file, true, false, verbose > 0)) - { - if (!verbose) - error (0, 0, _("compilation of C# class failed, please try --verbose")); - else - error (0, 0, _("compilation of C# class failed")); - goto quit3; - } - - retval = 0; - - quit3: - free (csharp_file_name); - free (class_name); - free (output_file); - quit2: - free (culture_name); - cleanup_temp_dir (tmpdir); - quit1: - return retval; -} diff --git a/gettext-tools/src/write-csharp.h b/gettext-tools/src/write-csharp.h deleted file mode 100644 index b29ba343a..000000000 --- a/gettext-tools/src/write-csharp.h +++ /dev/null @@ -1,35 +0,0 @@ -/* Writing C# satellite assemblies. - Copyright (C) 2003-2004 Free Software Foundation, Inc. - Written by Bruno Haible , 2003. - - This program 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 3 of the License, or - (at your option) any later version. - - This program 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 this program. If not, see . */ - -#ifndef _WRITE_CSHARP_H -#define _WRITE_CSHARP_H - -#include "message.h" - -/* Write a C# satellite assembly DLL file. mlp is a list containing the - messages to be output. resource_name is the name of the resource - (with dot separators), locale_name is the locale name (with underscore - separators) or NULL, directory is the base directory. - Return 0 if ok, nonzero on error. */ -extern int - msgdomain_write_csharp (message_list_ty *mlp, - const char *canon_encoding, - const char *resource_name, - const char *locale_name, - const char *directory); - -#endif /* _WRITE_CSHARP_H */ diff --git a/gettext-tools/src/write-java.c b/gettext-tools/src/write-java.c deleted file mode 100644 index 68e0e3a73..000000000 --- a/gettext-tools/src/write-java.c +++ /dev/null @@ -1,1239 +0,0 @@ -/* Writing Java ResourceBundles. - Copyright (C) 2001-2003, 2005-2010, 2014, 2016, 2018-2019 Free Software Foundation, Inc. - Written by Bruno Haible , 2001. - - This program 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 3 of the License, or - (at your option) any later version. - - This program 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 this program. If not, see . */ - -#ifdef HAVE_CONFIG_H -# include -#endif -#include - -/* Specification. */ -#include "write-java.h" - -#include -#include -#include -#include -#include -#include - -#include -#if !defined S_ISDIR && defined S_IFDIR -# define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR) -#endif -#if !S_IRUSR && S_IREAD -# define S_IRUSR S_IREAD -#endif -#if !S_IRUSR -# define S_IRUSR 00400 -#endif -#if !S_IWUSR && S_IWRITE -# define S_IWUSR S_IWRITE -#endif -#if !S_IWUSR -# define S_IWUSR 00200 -#endif -#if !S_IXUSR && S_IEXEC -# define S_IXUSR S_IEXEC -#endif -#if !S_IXUSR -# define S_IXUSR 00100 -#endif - -#include "c-ctype.h" -#include "error.h" -#include "xerror.h" -#include "xvasprintf.h" -#include "javacomp.h" -#include "message.h" -#include "msgfmt.h" -#include "msgl-iconv.h" -#include "msgl-header.h" -#include "plural-exp.h" -#include "po-charset.h" -#include "xalloc.h" -#include "xmalloca.h" -#include "minmax.h" -#include "concat-filename.h" -#include "fwriteerror.h" -#include "clean-temp.h" -#include "unistr.h" -#include "gettext.h" - -#define _(str) gettext (str) - - -/* Check that the resource name is a valid Java class name. To simplify - things, we allow only ASCII characters in the class name. - Return the number of dots in the class name, or -1 if not OK. */ -static int -check_resource_name (const char *name) -{ - int ndots = 0; - const char *p = name; - - for (;;) - { - /* First character, see Character.isJavaIdentifierStart. */ - if (!(c_isalpha (*p) || (*p == '$') || (*p == '_'))) - return -1; - /* Following characters, see Character.isJavaIdentifierPart. */ - do - p++; - while (c_isalpha (*p) || (*p == '$') || (*p == '_') || c_isdigit (*p)); - if (*p == '\0') - break; - if (*p != '.') - return -1; - p++; - ndots++; - } - return ndots; -} - - -/* Return the Java hash code of a string mod 2^31. - The Java String.hashCode() function returns the same values across - Java implementations. - (See http://www.javasoft.com/docs/books/jls/clarify.html) - It returns a signed 32-bit integer. We add a mod 2^31 afterwards; - this removes one bit but greatly simplifies the following "mod hash_size" - and "mod (hash_size - 2)" operations. */ -static unsigned int -string_hashcode (const char *str) -{ - const char *str_limit = str + strlen (str); - int hash = 0; - while (str < str_limit) - { - ucs4_t uc; - str += u8_mbtouc (&uc, (const unsigned char *) str, str_limit - str); - if (uc < 0x10000) - /* Single UCS-2 'char'. */ - hash = 31 * hash + uc; - else - { - /* UTF-16 surrogate: two 'char's. */ - ucs4_t uc1 = 0xd800 + ((uc - 0x10000) >> 10); - ucs4_t uc2 = 0xdc00 + ((uc - 0x10000) & 0x3ff); - hash = 31 * hash + uc1; - hash = 31 * hash + uc2; - } - } - return hash & 0x7fffffff; -} - - -/* Return the Java hash code of a (msgctxt, msgid) pair mod 2^31. */ -static unsigned int -msgid_hashcode (const char *msgctxt, const char *msgid) -{ - if (msgctxt == NULL) - return string_hashcode (msgid); - else - { - size_t msgctxt_len = strlen (msgctxt); - size_t msgid_len = strlen (msgid); - size_t combined_len = msgctxt_len + 1 + msgid_len; - char *combined; - unsigned int result; - - combined = (char *) xmalloca (combined_len + 1); - memcpy (combined, msgctxt, msgctxt_len); - combined[msgctxt_len] = MSGCTXT_SEPARATOR; - memcpy (combined + msgctxt_len + 1, msgid, msgid_len + 1); - - result = string_hashcode (combined); - - freea (combined); - - return result; - } -} - - -/* Compute a good hash table size for the given set of msgids. */ -static unsigned int -compute_hashsize (message_list_ty *mlp, bool *collisionp) -{ - /* This is an O(n^2) algorithm, but should be sufficient because few - programs have more than 1000 messages in a single domain. */ -#define XXN 3 /* can be tweaked */ -#define XXS 3 /* can be tweaked */ - unsigned int n = mlp->nitems; - unsigned int *hashcodes = - (unsigned int *) xmalloca (n * sizeof (unsigned int)); - unsigned int hashsize; - unsigned int best_hashsize; - unsigned int best_score; - size_t j; - - for (j = 0; j < n; j++) - hashcodes[j] = msgid_hashcode (mlp->item[j]->msgctxt, mlp->item[j]->msgid); - - /* Try all numbers between n and 3*n. The score depends on the size of the - table -- the smaller the better -- and the number of collision lookups, - i.e. total number of times that 1 + (hashcode % (hashsize - 2)) - is added to the index during lookup. If there are collisions, only odd - hashsize values are allowed. */ - best_hashsize = 0; - best_score = UINT_MAX; - for (hashsize = n; hashsize <= XXN * n; hashsize++) - { - char *bitmap; - unsigned int score; - - /* Premature end of the loop if all future scores are known to be - larger than the already reached best_score. This relies on the - ascending loop and on the fact that score >= hashsize. */ - if (hashsize >= best_score) - break; - - bitmap = XNMALLOC (hashsize, char); - memset (bitmap, 0, hashsize); - - score = 0; - for (j = 0; j < n; j++) - { - unsigned int idx = hashcodes[j] % hashsize; - - if (bitmap[idx] != 0) - { - /* Collision. Cannot deal with it if hashsize is even. */ - if ((hashsize % 2) == 0) - /* Try next hashsize. */ - goto bad_hashsize; - else - { - unsigned int idx0 = idx; - unsigned int incr = 1 + (hashcodes[j] % (hashsize - 2)); - score += 2; /* Big penalty for the additional division */ - do - { - score++; /* Small penalty for each loop round */ - idx += incr; - if (idx >= hashsize) - idx -= hashsize; - if (idx == idx0) - /* Searching for a hole, we performed a whole round - across the table. This happens particularly - frequently if gcd(hashsize,incr) > 1. Try next - hashsize. */ - goto bad_hashsize; - } - while (bitmap[idx] != 0); - } - } - bitmap[idx] = 1; - } - - /* Big hashsize also gives a penalty. */ - score = XXS * score + hashsize; - - /* If for any incr between 1 and hashsize - 2, an whole round - (idx0, idx0 + incr, ...) is occupied, and the lookup function - must deal with collisions, then some inputs would lead to - an endless loop in the lookup function. */ - if (score > hashsize) - { - unsigned int incr; - - /* Since the set { idx0, idx0 + incr, ... } depends only on idx0 - and gcd(hashsize,incr), we only need to conside incr that - divides hashsize. */ - for (incr = 1; incr <= hashsize / 2; incr++) - if ((hashsize % incr) == 0) - { - unsigned int idx0; - - for (idx0 = 0; idx0 < incr; idx0++) - { - bool full = true; - unsigned int idx; - - for (idx = idx0; idx < hashsize; idx += incr) - if (bitmap[idx] == 0) - { - full = false; - break; - } - if (full) - /* A whole round is occupied. */ - goto bad_hashsize; - } - } - } - - if (false) - bad_hashsize: - score = UINT_MAX; - - free (bitmap); - - if (score < best_score) - { - best_score = score; - best_hashsize = hashsize; - } - } - if (best_hashsize == 0 || best_score < best_hashsize) - abort (); - - freea (hashcodes); - - /* There are collisions if and only if best_score > best_hashsize. */ - *collisionp = (best_score > best_hashsize); - return best_hashsize; -} - - -struct table_item { unsigned int index; message_ty *mp; }; - -static int -compare_index (const void *pval1, const void *pval2) -{ - return (int)((const struct table_item *) pval1)->index - - (int)((const struct table_item *) pval2)->index; -} - -/* Compute the list of messages and table indices, sorted according to the - indices. */ -static struct table_item * -compute_table_items (message_list_ty *mlp, unsigned int hashsize) -{ - unsigned int n = mlp->nitems; - struct table_item *arr = XNMALLOC (n, struct table_item); - char *bitmap; - size_t j; - - bitmap = XNMALLOC (hashsize, char); - memset (bitmap, 0, hashsize); - - for (j = 0; j < n; j++) - { - unsigned int hashcode = - msgid_hashcode (mlp->item[j]->msgctxt, mlp->item[j]->msgid); - unsigned int idx = hashcode % hashsize; - - if (bitmap[idx] != 0) - { - unsigned int incr = 1 + (hashcode % (hashsize - 2)); - do - { - idx += incr; - if (idx >= hashsize) - idx -= hashsize; - } - while (bitmap[idx] != 0); - } - bitmap[idx] = 1; - - arr[j].index = idx; - arr[j].mp = mlp->item[j]; - } - - free (bitmap); - - qsort (arr, n, sizeof (arr[0]), compare_index); - - return arr; -} - - -/* Write a string in Java Unicode notation to the given stream. */ -static void -write_java_string (FILE *stream, const char *str) -{ - static const char hexdigit[] = "0123456789abcdef"; - const char *str_limit = str + strlen (str); - - fprintf (stream, "\""); - while (str < str_limit) - { - ucs4_t uc; - str += u8_mbtouc (&uc, (const unsigned char *) str, str_limit - str); - if (uc < 0x10000) - { - /* Single UCS-2 'char'. */ - if (uc == 0x000a) - fprintf (stream, "\\n"); - else if (uc == 0x000d) - fprintf (stream, "\\r"); - else if (uc == 0x0022) - fprintf (stream, "\\\""); - else if (uc == 0x005c) - fprintf (stream, "\\\\"); - else if (uc >= 0x0020 && uc < 0x007f) - fprintf (stream, "%c", (int) uc); - else - fprintf (stream, "\\u%c%c%c%c", - hexdigit[(uc >> 12) & 0x0f], hexdigit[(uc >> 8) & 0x0f], - hexdigit[(uc >> 4) & 0x0f], hexdigit[uc & 0x0f]); - } - else - { - /* UTF-16 surrogate: two 'char's. */ - ucs4_t uc1 = 0xd800 + ((uc - 0x10000) >> 10); - ucs4_t uc2 = 0xdc00 + ((uc - 0x10000) & 0x3ff); - fprintf (stream, "\\u%c%c%c%c", - hexdigit[(uc1 >> 12) & 0x0f], hexdigit[(uc1 >> 8) & 0x0f], - hexdigit[(uc1 >> 4) & 0x0f], hexdigit[uc1 & 0x0f]); - fprintf (stream, "\\u%c%c%c%c", - hexdigit[(uc2 >> 12) & 0x0f], hexdigit[(uc2 >> 8) & 0x0f], - hexdigit[(uc2 >> 4) & 0x0f], hexdigit[uc2 & 0x0f]); - } - } - fprintf (stream, "\""); -} - - -/* Write a (msgctxt, msgid) pair as a string in Java Unicode notation to the - given stream. */ -static void -write_java_msgid (FILE *stream, message_ty *mp) -{ - const char *msgctxt = mp->msgctxt; - const char *msgid = mp->msgid; - - if (msgctxt == NULL) - write_java_string (stream, msgid); - else - { - size_t msgctxt_len = strlen (msgctxt); - size_t msgid_len = strlen (msgid); - size_t combined_len = msgctxt_len + 1 + msgid_len; - char *combined; - - combined = (char *) xmalloca (combined_len + 1); - memcpy (combined, msgctxt, msgctxt_len); - combined[msgctxt_len] = MSGCTXT_SEPARATOR; - memcpy (combined + msgctxt_len + 1, msgid, msgid_len + 1); - - write_java_string (stream, combined); - - freea (combined); - } -} - - -/* Write Java code that returns the value for a message. If the message - has plural forms, it is an expression of type String[], otherwise it is - an expression of type String. */ -static void -write_java_msgstr (FILE *stream, message_ty *mp) -{ - if (mp->msgid_plural != NULL) - { - bool first; - const char *p; - - fprintf (stream, "new java.lang.String[] { "); - for (p = mp->msgstr, first = true; - p < mp->msgstr + mp->msgstr_len; - p += strlen (p) + 1, first = false) - { - if (!first) - fprintf (stream, ", "); - write_java_string (stream, p); - } - fprintf (stream, " }"); - } - else - { - if (mp->msgstr_len != strlen (mp->msgstr) + 1) - abort (); - - write_java_string (stream, mp->msgstr); - } -} - - -/* Writes the body of the function which returns the local value for a key - named 'msgid'. */ -static void -write_lookup_code (FILE *stream, unsigned int hashsize, bool collisions) -{ - fprintf (stream, " int hash_val = msgid.hashCode() & 0x7fffffff;\n"); - fprintf (stream, " int idx = (hash_val %% %d) << 1;\n", hashsize); - if (collisions) - { - fprintf (stream, " {\n"); - fprintf (stream, " java.lang.Object found = table[idx];\n"); - fprintf (stream, " if (found == null)\n"); - fprintf (stream, " return null;\n"); - fprintf (stream, " if (msgid.equals(found))\n"); - fprintf (stream, " return table[idx + 1];\n"); - fprintf (stream, " }\n"); - fprintf (stream, " int incr = ((hash_val %% %d) + 1) << 1;\n", - hashsize - 2); - fprintf (stream, " for (;;) {\n"); - fprintf (stream, " idx += incr;\n"); - fprintf (stream, " if (idx >= %d)\n", 2 * hashsize); - fprintf (stream, " idx -= %d;\n", 2 * hashsize); - fprintf (stream, " java.lang.Object found = table[idx];\n"); - fprintf (stream, " if (found == null)\n"); - fprintf (stream, " return null;\n"); - fprintf (stream, " if (msgid.equals(found))\n"); - fprintf (stream, " return table[idx + 1];\n"); - fprintf (stream, " }\n"); - } - else - { - fprintf (stream, " java.lang.Object found = table[idx];\n"); - fprintf (stream, " if (found != null && msgid.equals(found))\n"); - fprintf (stream, " return table[idx + 1];\n"); - fprintf (stream, " return null;\n"); - } -} - - -/* Tests whether a plural expression, evaluated according to the C rules, - can only produce the values 0 and 1. */ -static bool -is_expression_boolean (struct expression *exp) -{ - switch (exp->operation) - { - case var: - case mult: - case divide: - case module: - case plus: - case minus: - return false; - case lnot: - case less_than: - case greater_than: - case less_or_equal: - case greater_or_equal: - case equal: - case not_equal: - case land: - case lor: - return true; - case num: - return (exp->val.num == 0 || exp->val.num == 1); - case qmop: - return is_expression_boolean (exp->val.args[1]) - && is_expression_boolean (exp->val.args[2]); - default: - abort (); - } -} - - -/* Write Java code that evaluates a plural expression according to the C rules. - The variable is called 'n'. */ -static void -write_java_expression (FILE *stream, const struct expression *exp, bool as_boolean) -{ - /* We use parentheses everywhere. This frees us from tracking the priority - of arithmetic operators. */ - if (as_boolean) - { - /* Emit a Java expression of type 'boolean'. */ - switch (exp->operation) - { - case num: - fprintf (stream, "%s", exp->val.num ? "true" : "false"); - return; - case lnot: - fprintf (stream, "(!"); - write_java_expression (stream, exp->val.args[0], true); - fprintf (stream, ")"); - return; - case less_than: - fprintf (stream, "("); - write_java_expression (stream, exp->val.args[0], false); - fprintf (stream, " < "); - write_java_expression (stream, exp->val.args[1], false); - fprintf (stream, ")"); - return; - case greater_than: - fprintf (stream, "("); - write_java_expression (stream, exp->val.args[0], false); - fprintf (stream, " > "); - write_java_expression (stream, exp->val.args[1], false); - fprintf (stream, ")"); - return; - case less_or_equal: - fprintf (stream, "("); - write_java_expression (stream, exp->val.args[0], false); - fprintf (stream, " <= "); - write_java_expression (stream, exp->val.args[1], false); - fprintf (stream, ")"); - return; - case greater_or_equal: - fprintf (stream, "("); - write_java_expression (stream, exp->val.args[0], false); - fprintf (stream, " >= "); - write_java_expression (stream, exp->val.args[1], false); - fprintf (stream, ")"); - return; - case equal: - fprintf (stream, "("); - write_java_expression (stream, exp->val.args[0], false); - fprintf (stream, " == "); - write_java_expression (stream, exp->val.args[1], false); - fprintf (stream, ")"); - return; - case not_equal: - fprintf (stream, "("); - write_java_expression (stream, exp->val.args[0], false); - fprintf (stream, " != "); - write_java_expression (stream, exp->val.args[1], false); - fprintf (stream, ")"); - return; - case land: - fprintf (stream, "("); - write_java_expression (stream, exp->val.args[0], true); - fprintf (stream, " && "); - write_java_expression (stream, exp->val.args[1], true); - fprintf (stream, ")"); - return; - case lor: - fprintf (stream, "("); - write_java_expression (stream, exp->val.args[0], true); - fprintf (stream, " || "); - write_java_expression (stream, exp->val.args[1], true); - fprintf (stream, ")"); - return; - case qmop: - if (is_expression_boolean (exp->val.args[1]) - && is_expression_boolean (exp->val.args[2])) - { - fprintf (stream, "("); - write_java_expression (stream, exp->val.args[0], true); - fprintf (stream, " ? "); - write_java_expression (stream, exp->val.args[1], true); - fprintf (stream, " : "); - write_java_expression (stream, exp->val.args[2], true); - fprintf (stream, ")"); - return; - } - /*FALLTHROUGH*/ - case var: - case mult: - case divide: - case module: - case plus: - case minus: - fprintf (stream, "("); - write_java_expression (stream, exp, false); - fprintf (stream, " != 0)"); - return; - default: - abort (); - } - } - else - { - /* Emit a Java expression of type 'long'. */ - switch (exp->operation) - { - case var: - fprintf (stream, "n"); - return; - case num: - fprintf (stream, "%lu", exp->val.num); - return; - case mult: - fprintf (stream, "("); - write_java_expression (stream, exp->val.args[0], false); - fprintf (stream, " * "); - write_java_expression (stream, exp->val.args[1], false); - fprintf (stream, ")"); - return; - case divide: - fprintf (stream, "("); - write_java_expression (stream, exp->val.args[0], false); - fprintf (stream, " / "); - write_java_expression (stream, exp->val.args[1], false); - fprintf (stream, ")"); - return; - case module: - fprintf (stream, "("); - write_java_expression (stream, exp->val.args[0], false); - fprintf (stream, " %% "); - write_java_expression (stream, exp->val.args[1], false); - fprintf (stream, ")"); - return; - case plus: - fprintf (stream, "("); - write_java_expression (stream, exp->val.args[0], false); - fprintf (stream, " + "); - write_java_expression (stream, exp->val.args[1], false); - fprintf (stream, ")"); - return; - case minus: - fprintf (stream, "("); - write_java_expression (stream, exp->val.args[0], false); - fprintf (stream, " - "); - write_java_expression (stream, exp->val.args[1], false); - fprintf (stream, ")"); - return; - case qmop: - fprintf (stream, "("); - write_java_expression (stream, exp->val.args[0], true); - fprintf (stream, " ? "); - write_java_expression (stream, exp->val.args[1], false); - fprintf (stream, " : "); - write_java_expression (stream, exp->val.args[2], false); - fprintf (stream, ")"); - return; - case lnot: - case less_than: - case greater_than: - case less_or_equal: - case greater_or_equal: - case equal: - case not_equal: - case land: - case lor: - fprintf (stream, "("); - write_java_expression (stream, exp, true); - fprintf (stream, " ? 1 : 0)"); - return; - default: - abort (); - } - } -} - - -/* Write the Java initialization statements for the Java 1.1.x case, - for items j, start_index <= j < end_index. */ -static void -write_java1_init_statements (FILE *stream, message_list_ty *mlp, - size_t start_index, size_t end_index) -{ - size_t j; - - for (j = start_index; j < end_index; j++) - { - fprintf (stream, " t.put("); - write_java_msgid (stream, mlp->item[j]); - fprintf (stream, ","); - write_java_msgstr (stream, mlp->item[j]); - fprintf (stream, ");\n"); - } -} - - -/* Write the Java initialization statements for the Java 2 case, - for items j, start_index <= j < end_index. */ -static void -write_java2_init_statements (FILE *stream, message_list_ty *mlp, - const struct table_item *table_items, - size_t start_index, size_t end_index) -{ - size_t j; - - for (j = start_index; j < end_index; j++) - { - const struct table_item *ti = &table_items[j]; - - fprintf (stream, " t[%d] = ", 2 * ti->index); - write_java_msgid (stream, ti->mp); - fprintf (stream, ";\n"); - fprintf (stream, " t[%d] = ", 2 * ti->index + 1); - write_java_msgstr (stream, ti->mp); - fprintf (stream, ";\n"); - } -} - - -/* Write the Java code for the ResourceBundle subclass to the given stream. - Note that we use fully qualified class names and no "import" statements, - because applications can have their own classes called X.Y.ResourceBundle - or X.Y.String. */ -static void -write_java_code (FILE *stream, const char *class_name, message_list_ty *mlp, - bool assume_java2) -{ - const char *last_dot; - unsigned int plurals; - size_t j; - - fprintf (stream, - "/* Automatically generated by GNU msgfmt. Do not modify! */\n"); - last_dot = strrchr (class_name, '.'); - if (last_dot != NULL) - { - fprintf (stream, "package "); - fwrite (class_name, 1, last_dot - class_name, stream); - fprintf (stream, ";\npublic class %s", last_dot + 1); - } - else - fprintf (stream, "public class %s", class_name); - fprintf (stream, " extends java.util.ResourceBundle {\n"); - - /* Determine whether there are plural messages. */ - plurals = 0; - for (j = 0; j < mlp->nitems; j++) - if (mlp->item[j]->msgid_plural != NULL) - plurals++; - - if (assume_java2) - { - unsigned int hashsize; - bool collisions; - struct table_item *table_items; - const char *table_eltype; - - /* Determine the hash table size and whether it leads to collisions. */ - hashsize = compute_hashsize (mlp, &collisions); - - /* Determines which indices in the table contain a message. The others - are null. */ - table_items = compute_table_items (mlp, hashsize); - - /* Emit the table of pairs (msgid, msgstr). If there are plurals, - it is of type Object[], otherwise of type String[]. We use a static - code block because that makes less code: The Java compilers also - generate code for the 'null' entries, which is dumb. */ - table_eltype = (plurals ? "java.lang.Object" : "java.lang.String"); - fprintf (stream, " private static final %s[] table;\n", table_eltype); - { - /* With the Sun javac compiler, each assignment takes 5 to 8 bytes - of bytecode, therefore for each message, up to 16 bytes are needed. - Since the bytecode of every method, including the method - that contains the static initializers, is limited to 64 KB, only ca, - 65536 / 16 = 4096 messages can be initialized in a single method. - Account for other Java compilers and for plurals by limiting it to - 1000. */ - const size_t max_items_per_method = 1000; - - if (mlp->nitems > max_items_per_method) - { - unsigned int k; - size_t start_j; - size_t end_j; - - for (k = 0, start_j = 0, end_j = start_j + max_items_per_method; - start_j < mlp->nitems; - k++, start_j = end_j, end_j = start_j + max_items_per_method) - { - fprintf (stream, " static void clinit_part_%u (%s[] t) {\n", - k, table_eltype); - write_java2_init_statements (stream, mlp, table_items, - start_j, MIN (end_j, mlp->nitems)); - fprintf (stream, " }\n"); - } - } - fprintf (stream, " static {\n"); - fprintf (stream, " %s[] t = new %s[%d];\n", table_eltype, - table_eltype, 2 * hashsize); - if (mlp->nitems > max_items_per_method) - { - unsigned int k; - size_t start_j; - - for (k = 0, start_j = 0; - start_j < mlp->nitems; - k++, start_j += max_items_per_method) - fprintf (stream, " clinit_part_%u(t);\n", k); - } - else - write_java2_init_statements (stream, mlp, table_items, - 0, mlp->nitems); - fprintf (stream, " table = t;\n"); - fprintf (stream, " }\n"); - } - - /* Emit the msgid_plural strings. Only used by msgunfmt. */ - if (plurals) - { - bool first; - fprintf (stream, " public static final java.lang.String[] get_msgid_plural_table () {\n"); - fprintf (stream, " return new java.lang.String[] { "); - first = true; - for (j = 0; j < mlp->nitems; j++) - { - struct table_item *ti = &table_items[j]; - if (ti->mp->msgid_plural != NULL) - { - if (!first) - fprintf (stream, ", "); - write_java_string (stream, ti->mp->msgid_plural); - first = false; - } - } - fprintf (stream, " };\n"); - fprintf (stream, " }\n"); - } - - if (plurals) - { - /* Emit the lookup function. It is a common subroutine for - handleGetObject and ngettext. */ - fprintf (stream, " public java.lang.Object lookup (java.lang.String msgid) {\n"); - write_lookup_code (stream, hashsize, collisions); - fprintf (stream, " }\n"); - } - - /* Emit the handleGetObject function. It is declared abstract in - ResourceBundle. It implements a local version of gettext. */ - fprintf (stream, " public java.lang.Object handleGetObject (java.lang.String msgid) throws java.util.MissingResourceException {\n"); - if (plurals) - { - fprintf (stream, " java.lang.Object value = lookup(msgid);\n"); - fprintf (stream, " return (value instanceof java.lang.String[] ? ((java.lang.String[])value)[0] : value);\n"); - } - else - write_lookup_code (stream, hashsize, collisions); - fprintf (stream, " }\n"); - - /* Emit the getKeys function. It is declared abstract in ResourceBundle. - The inner class is not avoidable. */ - fprintf (stream, " public java.util.Enumeration getKeys () {\n"); - fprintf (stream, " return\n"); - fprintf (stream, " new java.util.Enumeration() {\n"); - fprintf (stream, " private int idx = 0;\n"); - fprintf (stream, " { while (idx < %d && table[idx] == null) idx += 2; }\n", - 2 * hashsize); - fprintf (stream, " public boolean hasMoreElements () {\n"); - fprintf (stream, " return (idx < %d);\n", 2 * hashsize); - fprintf (stream, " }\n"); - fprintf (stream, " public java.lang.Object nextElement () {\n"); - fprintf (stream, " java.lang.Object key = table[idx];\n"); - fprintf (stream, " do idx += 2; while (idx < %d && table[idx] == null);\n", - 2 * hashsize); - fprintf (stream, " return key;\n"); - fprintf (stream, " }\n"); - fprintf (stream, " };\n"); - fprintf (stream, " }\n"); - } - else - { - /* Java 1.1.x uses a different hash function. If compatibility with - this Java version is required, the hash table must be built at run time, - not at compile time. */ - fprintf (stream, " private static final java.util.Hashtable table;\n"); - { - /* With the Sun javac compiler, each 'put' call takes 9 to 11 bytes - of bytecode, therefore for each message, up to 11 bytes are needed. - Since the bytecode of every method, including the method - that contains the static initializers, is limited to 64 KB, only ca, - 65536 / 11 = 5958 messages can be initialized in a single method. - Account for other Java compilers and for plurals by limiting it to - 1500. */ - const size_t max_items_per_method = 1500; - - if (mlp->nitems > max_items_per_method) - { - unsigned int k; - size_t start_j; - size_t end_j; - - for (k = 0, start_j = 0, end_j = start_j + max_items_per_method; - start_j < mlp->nitems; - k++, start_j = end_j, end_j = start_j + max_items_per_method) - { - fprintf (stream, " static void clinit_part_%u (java.util.Hashtable t) {\n", - k); - write_java1_init_statements (stream, mlp, - start_j, MIN (end_j, mlp->nitems)); - fprintf (stream, " }\n"); - } - } - fprintf (stream, " static {\n"); - fprintf (stream, " java.util.Hashtable t = new java.util.Hashtable();\n"); - if (mlp->nitems > max_items_per_method) - { - unsigned int k; - size_t start_j; - - for (k = 0, start_j = 0; - start_j < mlp->nitems; - k++, start_j += max_items_per_method) - fprintf (stream, " clinit_part_%u(t);\n", k); - } - else - write_java1_init_statements (stream, mlp, 0, mlp->nitems); - fprintf (stream, " table = t;\n"); - fprintf (stream, " }\n"); - } - - /* Emit the msgid_plural strings. Only used by msgunfmt. */ - if (plurals) - { - fprintf (stream, " public static final java.util.Hashtable get_msgid_plural_table () {\n"); - fprintf (stream, " java.util.Hashtable p = new java.util.Hashtable();\n"); - for (j = 0; j < mlp->nitems; j++) - if (mlp->item[j]->msgid_plural != NULL) - { - fprintf (stream, " p.put("); - write_java_msgid (stream, mlp->item[j]); - fprintf (stream, ","); - write_java_string (stream, mlp->item[j]->msgid_plural); - fprintf (stream, ");\n"); - } - fprintf (stream, " return p;\n"); - fprintf (stream, " }\n"); - } - - if (plurals) - { - /* Emit the lookup function. It is a common subroutine for - handleGetObject and ngettext. */ - fprintf (stream, " public java.lang.Object lookup (java.lang.String msgid) {\n"); - fprintf (stream, " return table.get(msgid);\n"); - fprintf (stream, " }\n"); - } - - /* Emit the handleGetObject function. It is declared abstract in - ResourceBundle. It implements a local version of gettext. */ - fprintf (stream, " public java.lang.Object handleGetObject (java.lang.String msgid) throws java.util.MissingResourceException {\n"); - if (plurals) - { - fprintf (stream, " java.lang.Object value = table.get(msgid);\n"); - fprintf (stream, " return (value instanceof java.lang.String[] ? ((java.lang.String[])value)[0] : value);\n"); - } - else - fprintf (stream, " return table.get(msgid);\n"); - fprintf (stream, " }\n"); - - /* Emit the getKeys function. It is declared abstract in - ResourceBundle. */ - fprintf (stream, " public java.util.Enumeration getKeys () {\n"); - fprintf (stream, " return table.keys();\n"); - fprintf (stream, " }\n"); - } - - /* Emit the pluralEval function. It is a subroutine for ngettext. */ - if (plurals) - { - message_ty *header_entry; - const struct expression *plural; - unsigned long int nplurals; - - header_entry = message_list_search (mlp, NULL, ""); - extract_plural_expression (header_entry ? header_entry->msgstr : NULL, - &plural, &nplurals); - - fprintf (stream, " public static long pluralEval (long n) {\n"); - fprintf (stream, " return "); - write_java_expression (stream, plural, false); - fprintf (stream, ";\n"); - fprintf (stream, " }\n"); - } - - /* Emit the getParent function. It is a subroutine for ngettext. */ - fprintf (stream, " public java.util.ResourceBundle getParent () {\n"); - fprintf (stream, " return parent;\n"); - fprintf (stream, " }\n"); - - fprintf (stream, "}\n"); -} - - -int -msgdomain_write_java (message_list_ty *mlp, const char *canon_encoding, - const char *resource_name, const char *locale_name, - const char *directory, - bool assume_java2, - bool output_source) -{ - int retval; - struct temp_dir *tmpdir; - int ndots; - char *class_name; - char **subdirs; - char *java_file_name; - FILE *java_file; - const char *java_sources[1]; - const char *source_dir_name; - - /* If no entry for this resource/domain, don't even create the file. */ - if (mlp->nitems == 0) - return 0; - - retval = 1; - - /* Convert the messages to Unicode. */ - iconv_message_list (mlp, canon_encoding, po_charset_utf8, NULL); - - /* Support for "reproducible builds": Delete information that may vary - between builds in the same conditions. */ - message_list_delete_header_field (mlp, "POT-Creation-Date:"); - - if (output_source) - { - tmpdir = NULL; - source_dir_name = directory; - } - else - { - /* Create a temporary directory where we can put the Java file. */ - tmpdir = create_temp_dir ("msg", NULL, false); - if (tmpdir == NULL) - goto quit1; - source_dir_name = tmpdir->dir_name; - } - - /* Assign a default value to the resource name. */ - if (resource_name == NULL) - resource_name = "Messages"; - - /* Prepare the list of subdirectories. */ - ndots = check_resource_name (resource_name); - if (ndots < 0) - { - error (0, 0, _("not a valid Java class name: %s"), resource_name); - goto quit2; - } - - if (locale_name != NULL) - class_name = xasprintf ("%s_%s", resource_name, locale_name); - else - class_name = xstrdup (resource_name); - - subdirs = (ndots > 0 ? (char **) xmalloca (ndots * sizeof (char *)) : NULL); - { - const char *p; - const char *last_dir; - int i; - - last_dir = source_dir_name; - p = resource_name; - for (i = 0; i < ndots; i++) - { - const char *q = strchr (p, '.'); - size_t n = q - p; - char *part = (char *) xmalloca (n + 1); - memcpy (part, p, n); - part[n] = '\0'; - subdirs[i] = xconcatenated_filename (last_dir, part, NULL); - freea (part); - last_dir = subdirs[i]; - p = q + 1; - } - - if (locale_name != NULL) - { - char *suffix = xasprintf ("_%s.java", locale_name); - java_file_name = xconcatenated_filename (last_dir, p, suffix); - free (suffix); - } - else - java_file_name = xconcatenated_filename (last_dir, p, ".java"); - } - - /* If OUTPUT_SOURCE, write the Java file in DIRECTORY and return. */ - if (output_source) - { - int i; - - for (i = 0; i < ndots; i++) - { - if (mkdir (subdirs[i], S_IRUSR | S_IWUSR | S_IXUSR) < 0) - { - error (0, errno, _("failed to create \"%s\""), subdirs[i]); - goto quit3; - } - } - - java_file = fopen (java_file_name, "w"); - if (java_file == NULL) - { - error (0, errno, _("failed to create \"%s\""), java_file_name); - goto quit3; - } - - write_java_code (java_file, class_name, mlp, assume_java2); - - if (fwriteerror (java_file)) - { - error (0, errno, _("error while writing \"%s\" file"), - java_file_name); - goto quit3; - } - - retval = 0; - goto quit3; - } - - /* Create the subdirectories. This is needed because some older Java - compilers verify that the source of class A.B.C really sits in a - directory whose name ends in /A/B. */ - { - int i; - - for (i = 0; i < ndots; i++) - { - register_temp_subdir (tmpdir, subdirs[i]); - if (mkdir (subdirs[i], S_IRUSR | S_IWUSR | S_IXUSR) < 0) - { - error (0, errno, _("failed to create \"%s\""), subdirs[i]); - unregister_temp_subdir (tmpdir, subdirs[i]); - goto quit3; - } - } - } - - /* Create the Java file. */ - register_temp_file (tmpdir, java_file_name); - java_file = fopen_temp (java_file_name, "w"); - if (java_file == NULL) - { - error (0, errno, _("failed to create \"%s\""), java_file_name); - unregister_temp_file (tmpdir, java_file_name); - goto quit3; - } - - write_java_code (java_file, class_name, mlp, assume_java2); - - if (fwriteerror_temp (java_file)) - { - error (0, errno, _("error while writing \"%s\" file"), java_file_name); - goto quit3; - } - - /* Compile the Java file to a .class file. - directory must be non-NULL, because when the -d option is omitted, the - Java compilers create the class files in the source file's directory - - which is in a temporary directory in our case. */ - java_sources[0] = java_file_name; - if (compile_java_class (java_sources, 1, NULL, 0, "1.5", "1.6", directory, - true, false, true, verbose > 0)) - { - if (!verbose) - error (0, 0, - _("compilation of Java class failed, please try --verbose or set $JAVAC")); - else - error (0, 0, - _("compilation of Java class failed, please try to set $JAVAC")); - goto quit3; - } - - retval = 0; - - quit3: - { - int i; - free (java_file_name); - for (i = 0; i < ndots; i++) - free (subdirs[i]); - } - freea (subdirs); - free (class_name); - quit2: - if (tmpdir != NULL) - cleanup_temp_dir (tmpdir); - quit1: - return retval; -} diff --git a/gettext-tools/src/write-java.h b/gettext-tools/src/write-java.h deleted file mode 100644 index 9f2add4ea..000000000 --- a/gettext-tools/src/write-java.h +++ /dev/null @@ -1,39 +0,0 @@ -/* Writing Java ResourceBundles. - Copyright (C) 2001-2003, 2014 Free Software Foundation, Inc. - Written by Bruno Haible , 2001. - - This program 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 3 of the License, or - (at your option) any later version. - - This program 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 this program. If not, see . */ - -#ifndef _WRITE_JAVA_H -#define _WRITE_JAVA_H - -#include - -#include "message.h" - -/* Write a Java ResourceBundle class file. mlp is a list containing the - messages to be output. resource_name is the name of the resource - (with dot separators), locale_name is the locale name (with underscore - separators) or NULL, directory is the base directory. - Return 0 if ok, nonzero on error. */ -extern int - msgdomain_write_java (message_list_ty *mlp, - const char *canon_encoding, - const char *resource_name, - const char *locale_name, - const char *directory, - bool assume_java2, - bool output_source); - -#endif /* _WRITE_JAVA_H */ diff --git a/gettext-tools/src/write-properties.c b/gettext-tools/src/write-properties.c deleted file mode 100644 index 19eb228c3..000000000 --- a/gettext-tools/src/write-properties.c +++ /dev/null @@ -1,306 +0,0 @@ -/* Writing Java .properties files. - Copyright (C) 2003, 2005-2009, 2019 Free Software Foundation, Inc. - Written by Bruno Haible , 2003. - - This program 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 3 of the License, or - (at your option) any later version. - - This program 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 this program. If not, see . */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -/* Specification. */ -#include "write-properties.h" - -#include -#include -#include -#include -#include - -#include - -#include "error.h" -#include "message.h" -#include "msgl-ascii.h" -#include "msgl-iconv.h" -#include "po-charset.h" -#include "unistr.h" -#include "write-po.h" -#include "xalloc.h" - -/* The format of the Java .properties files is documented in the JDK - documentation for class java.util.Properties. In the case of .properties - files for PropertyResourceBundle, for each message, the msgid becomes the - key (left-hand side) and the msgstr becomes the value (right-hand side) - of a "key=value" line. Messages with plurals are not supported in this - format. */ - -/* Handling of comments: We copy all comments from the PO file to the - .properties file. This is not really needed; it's a service for translators - who don't like PO files and prefer to maintain the .properties file. */ - -/* Converts a string to JAVA encoding (with \uxxxx sequences for non-ASCII - characters). */ -static const char * -conv_to_java (const char *string) -{ - /* We cannot use iconv to "JAVA" because not all iconv() implementations - know about the "JAVA" encoding. */ - static const char hexdigit[] = "0123456789abcdef"; - size_t length; - char *result; - - if (is_ascii_string (string)) - return string; - - length = 0; - { - const char *str = string; - const char *str_limit = str + strlen (str); - - while (str < str_limit) - { - ucs4_t uc; - str += u8_mbtouc (&uc, (const unsigned char *) str, str_limit - str); - length += (uc <= 0x007f ? 1 : uc < 0x10000 ? 6 : 12); - } - } - - result = XNMALLOC (length + 1, char); - - { - char *newstr = result; - const char *str = string; - const char *str_limit = str + strlen (str); - - while (str < str_limit) - { - ucs4_t uc; - str += u8_mbtouc (&uc, (const unsigned char *) str, str_limit - str); - if (uc <= 0x007f) - /* ASCII characters can be output literally. - We could treat non-ASCII ISO-8859-1 characters (0x0080..0x00FF) - the same way, but there is no point in doing this; Sun's - nativetoascii doesn't do it either. */ - *newstr++ = uc; - else if (uc < 0x10000) - { - /* Single UCS-2 'char' */ - sprintf (newstr, "\\u%c%c%c%c", - hexdigit[(uc >> 12) & 0x0f], hexdigit[(uc >> 8) & 0x0f], - hexdigit[(uc >> 4) & 0x0f], hexdigit[uc & 0x0f]); - newstr += 6; - } - else - { - /* UTF-16 surrogate: two 'char's. */ - ucs4_t uc1 = 0xd800 + ((uc - 0x10000) >> 10); - ucs4_t uc2 = 0xdc00 + ((uc - 0x10000) & 0x3ff); - sprintf (newstr, "\\u%c%c%c%c", - hexdigit[(uc1 >> 12) & 0x0f], hexdigit[(uc1 >> 8) & 0x0f], - hexdigit[(uc1 >> 4) & 0x0f], hexdigit[uc1 & 0x0f]); - newstr += 6; - sprintf (newstr, "\\u%c%c%c%c", - hexdigit[(uc2 >> 12) & 0x0f], hexdigit[(uc2 >> 8) & 0x0f], - hexdigit[(uc2 >> 4) & 0x0f], hexdigit[uc2 & 0x0f]); - newstr += 6; - } - } - *newstr = '\0'; - } - - return result; -} - -/* Writes a key or value to the stream, without newline. */ -static void -write_escaped_string (ostream_t stream, const char *str, bool in_key) -{ - static const char hexdigit[] = "0123456789abcdef"; - const char *str_limit = str + strlen (str); - bool first = true; - - while (str < str_limit) - { - ucs4_t uc; - str += u8_mbtouc (&uc, (const unsigned char *) str, str_limit - str); - /* Whitespace must be escaped. */ - if (uc == 0x0020 && (first || in_key)) - ostream_write_str (stream, "\\ "); - else if (uc == 0x0009) - ostream_write_str (stream, "\\t"); - else if (uc == 0x000a) - ostream_write_str (stream, "\\n"); - else if (uc == 0x000d) - ostream_write_str (stream, "\\r"); - else if (uc == 0x000c) - ostream_write_str (stream, "\\f"); - else if (/* Backslash must be escaped. */ - uc == '\\' - /* Possible comment introducers must be escaped. */ - || uc == '#' || uc == '!' - /* Key terminators must be escaped. */ - || uc == '=' || uc == ':') - { - char seq[2]; - seq[0] = '\\'; - seq[1] = uc; - ostream_write_mem (stream, seq, 2); - } - else if (uc >= 0x0020 && uc <= 0x007e) - { - /* ASCII characters can be output literally. - We could treat non-ASCII ISO-8859-1 characters (0x0080..0x00FF) - the same way, but there is no point in doing this; Sun's - nativetoascii doesn't do it either. */ - char seq[1]; - seq[0] = uc; - ostream_write_mem (stream, seq, 1); - } - else if (uc < 0x10000) - { - /* Single UCS-2 'char' */ - char seq[6]; - seq[0] = '\\'; - seq[1] = 'u'; - seq[2] = hexdigit[(uc >> 12) & 0x0f]; - seq[3] = hexdigit[(uc >> 8) & 0x0f]; - seq[4] = hexdigit[(uc >> 4) & 0x0f]; - seq[5] = hexdigit[uc & 0x0f]; - ostream_write_mem (stream, seq, 6); - } - else - { - /* UTF-16 surrogate: two 'char's. */ - ucs4_t uc1 = 0xd800 + ((uc - 0x10000) >> 10); - ucs4_t uc2 = 0xdc00 + ((uc - 0x10000) & 0x3ff); - char seq[6]; - seq[0] = '\\'; - seq[1] = 'u'; - seq[2] = hexdigit[(uc1 >> 12) & 0x0f]; - seq[3] = hexdigit[(uc1 >> 8) & 0x0f]; - seq[4] = hexdigit[(uc1 >> 4) & 0x0f]; - seq[5] = hexdigit[uc1 & 0x0f]; - ostream_write_mem (stream, seq, 6); - seq[0] = '\\'; - seq[1] = 'u'; - seq[2] = hexdigit[(uc2 >> 12) & 0x0f]; - seq[3] = hexdigit[(uc2 >> 8) & 0x0f]; - seq[4] = hexdigit[(uc2 >> 4) & 0x0f]; - seq[5] = hexdigit[uc2 & 0x0f]; - ostream_write_mem (stream, seq, 6); - } - first = false; - } -} - -/* Writes a message to the stream. */ -static void -write_message (ostream_t stream, const message_ty *mp, - size_t page_width, bool debug) -{ - /* Print translator comment if available. */ - message_print_comment (mp, stream); - - /* Print xgettext extracted comments. */ - message_print_comment_dot (mp, stream); - - /* Print the file position comments. */ - message_print_comment_filepos (mp, stream, false, page_width); - - /* Print flag information in special comment. */ - message_print_comment_flags (mp, stream, debug); - - /* Put a comment mark if the message is the header or untranslated or - fuzzy. */ - if (is_header (mp) - || mp->msgstr[0] == '\0' - || (mp->is_fuzzy && !is_header (mp))) - ostream_write_str (stream, "!"); - - /* Now write the untranslated string and the translated string. */ - write_escaped_string (stream, mp->msgid, true); - ostream_write_str (stream, "="); - write_escaped_string (stream, mp->msgstr, false); - - ostream_write_str (stream, "\n"); -} - -/* Writes an entire message list to the stream. */ -static void -write_properties (ostream_t stream, message_list_ty *mlp, - const char *canon_encoding, size_t page_width, bool debug) -{ - bool blank_line; - size_t j, i; - - /* Convert the messages to Unicode. */ - iconv_message_list (mlp, canon_encoding, po_charset_utf8, NULL); - for (j = 0; j < mlp->nitems; ++j) - { - message_ty *mp = mlp->item[j]; - - if (mp->comment != NULL) - for (i = 0; i < mp->comment->nitems; ++i) - mp->comment->item[i] = conv_to_java (mp->comment->item[i]); - if (mp->comment_dot != NULL) - for (i = 0; i < mp->comment_dot->nitems; ++i) - mp->comment_dot->item[i] = conv_to_java (mp->comment_dot->item[i]); - } - - /* Loop through the messages. */ - blank_line = false; - for (j = 0; j < mlp->nitems; ++j) - { - const message_ty *mp = mlp->item[j]; - - if (mp->msgid_plural == NULL && !mp->obsolete) - { - if (blank_line) - ostream_write_str (stream, "\n"); - - write_message (stream, mp, page_width, debug); - - blank_line = true; - } - } -} - -/* Output the contents of a PO file in Java .properties syntax. */ -static void -msgdomain_list_print_properties (msgdomain_list_ty *mdlp, ostream_t stream, - size_t page_width, bool debug) -{ - message_list_ty *mlp; - - if (mdlp->nitems == 1) - mlp = mdlp->item[0]->messages; - else - mlp = message_list_alloc (false); - write_properties (stream, mlp, mdlp->encoding, page_width, debug); -} - -/* Describes a PO file in Java .properties syntax. */ -const struct catalog_output_format output_format_properties = -{ - msgdomain_list_print_properties, /* print */ - true, /* requires_utf8 */ - false, /* supports_color */ - false, /* supports_multiple_domains */ - false, /* supports_contexts */ - false, /* supports_plurals */ - false, /* sorts_obsoletes_to_end */ - true, /* alternative_is_po */ - true /* alternative_is_java_class */ -}; diff --git a/gettext-tools/src/write-properties.h b/gettext-tools/src/write-properties.h deleted file mode 100644 index 7671afb30..000000000 --- a/gettext-tools/src/write-properties.h +++ /dev/null @@ -1,38 +0,0 @@ -/* Writing Java .properties files. - Copyright (C) 2003, 2006, 2019 Free Software Foundation, Inc. - Written by Bruno Haible , 2003. - - This program 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 3 of the License, or - (at your option) any later version. - - This program 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 this program. If not, see . */ - -#ifndef _WRITE_PROPERTIES_H -#define _WRITE_PROPERTIES_H - -#include "write-catalog.h" - - -#ifdef __cplusplus -extern "C" { -#endif - - -/* Describes a PO file in Java .properties syntax. */ -extern DLL_VARIABLE const struct catalog_output_format output_format_properties; - - -#ifdef __cplusplus -} -#endif - - -#endif /* _WRITE_PROPERTIES_H */ diff --git a/gettext-tools/src/write-resources.c b/gettext-tools/src/write-resources.c deleted file mode 100644 index 55c3e769b..000000000 --- a/gettext-tools/src/write-resources.c +++ /dev/null @@ -1,200 +0,0 @@ -/* Writing C# .resources files. - Copyright (C) 2003-2005, 2007-2009, 2010-2011, 2016 Free Software - Foundation, Inc. - Written by Bruno Haible , 2003. - - This program 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 3 of the License, or - (at your option) any later version. - - This program 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 this program. If not, see . */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -/* Specification. */ -#include "write-resources.h" - -#include -#include -#include -#include -#include - -#include "error.h" -#include "xerror.h" -#include "relocatable.h" -#include "csharpexec.h" -#include "spawn-pipe.h" -#include "wait-process.h" -#include "message.h" -#include "msgfmt.h" -#include "msgl-iconv.h" -#include "msgl-header.h" -#include "po-charset.h" -#include "xalloc.h" -#include "concat-filename.h" -#include "fwriteerror.h" -#include "gettext.h" - -#define _(str) gettext (str) - - -/* A .resources file has such a complex format that it's most easily generated - through the C# class ResourceWriter. So we start a C# process to execute - the WriteResource program, sending it the msgid/msgstr pairs as - NUL-terminated UTF-8 encoded strings. */ - -struct locals -{ - /* IN */ - message_list_ty *mlp; -}; - -static bool -execute_writing_input (const char *progname, - const char *prog_path, char **prog_argv, - void *private_data) -{ - struct locals *l = (struct locals *) private_data; - pid_t child; - int fd[1]; - FILE *fp; - int exitstatus; - - /* Open a pipe to the C# execution engine. */ - child = create_pipe_out (progname, prog_path, prog_argv, NULL, false, - true, true, fd); - - fp = fdopen (fd[0], "wb"); - if (fp == NULL) - error (EXIT_FAILURE, errno, _("fdopen() failed")); - - /* Write the message list. */ - { - message_list_ty *mlp = l->mlp; - size_t j; - - for (j = 0; j < mlp->nitems; j++) - { - message_ty *mp = mlp->item[j]; - - fwrite (mp->msgid, 1, strlen (mp->msgid) + 1, fp); - fwrite (mp->msgstr, 1, strlen (mp->msgstr) + 1, fp); - } - } - - if (fwriteerror (fp)) - error (EXIT_FAILURE, 0, _("error while writing to %s subprocess"), - progname); - - /* Remove zombie process from process list, and retrieve exit status. */ - /* He we can ignore SIGPIPE because WriteResource either writes to a file - - then it never gets SIGPIPE - or to standard output, and in the latter - case it has no side effects other than writing to standard output. */ - exitstatus = - wait_subprocess (child, progname, true, false, true, true, NULL); - if (exitstatus != 0) - error (EXIT_FAILURE, 0, _("%s subprocess failed with exit code %d"), - progname, exitstatus); - - return false; -} - -int -msgdomain_write_csharp_resources (message_list_ty *mlp, - const char *canon_encoding, - const char *domain_name, - const char *file_name) -{ - /* If no entry for this domain don't even create the file. */ - if (mlp->nitems != 0) - { - /* Determine whether mlp has entries with context. */ - { - bool has_context; - size_t j; - - has_context = false; - for (j = 0; j < mlp->nitems; j++) - if (mlp->item[j]->msgctxt != NULL) - has_context = true; - if (has_context) - { - multiline_error (xstrdup (""), - xstrdup (_("\ -message catalog has context dependent translations\n\ -but the C# .resources format doesn't support contexts\n"))); - return 1; - } - } - - /* Determine whether mlp has plural entries. */ - { - bool has_plural; - size_t j; - - has_plural = false; - for (j = 0; j < mlp->nitems; j++) - if (mlp->item[j]->msgid_plural != NULL) - has_plural = true; - if (has_plural) - { - multiline_error (xstrdup (""), - xstrdup (_("\ -message catalog has plural form translations\n\ -but the C# .resources format doesn't support plural handling\n"))); - return 1; - } - } - - /* Convert the messages to Unicode. */ - iconv_message_list (mlp, canon_encoding, po_charset_utf8, NULL); - - /* Support for "reproducible builds": Delete information that may vary - between builds in the same conditions. */ - message_list_delete_header_field (mlp, "POT-Creation-Date:"); - - /* Execute the WriteResource program. */ - { - const char *args[2]; - const char *gettextexedir; - char *assembly_path; - struct locals locals; - - /* Prepare arguments. */ - args[0] = file_name; - args[1] = NULL; - - /* Make it possible to override the .exe location. This is - necessary for running the testsuite before "make install". */ - gettextexedir = getenv ("GETTEXTCSHARPEXEDIR"); - if (gettextexedir == NULL || gettextexedir[0] == '\0') - gettextexedir = relocate (LIBDIR "/gettext"); - - assembly_path = - xconcatenated_filename (gettextexedir, "msgfmt.net", ".exe"); - - locals.mlp = mlp; - - if (execute_csharp_program (assembly_path, NULL, 0, - args, - verbose > 0, false, - execute_writing_input, &locals)) - /* An error message should already have been provided. */ - exit (EXIT_FAILURE); - - free (assembly_path); - } - } - - return 0; -} diff --git a/gettext-tools/src/write-resources.h b/gettext-tools/src/write-resources.h deleted file mode 100644 index c6159ffdb..000000000 --- a/gettext-tools/src/write-resources.h +++ /dev/null @@ -1,31 +0,0 @@ -/* Writing C# .resources files. - Copyright (C) 2003-2004 Free Software Foundation, Inc. - Written by Bruno Haible , 2003. - - This program 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 3 of the License, or - (at your option) any later version. - - This program 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 this program. If not, see . */ - -#ifndef _WRITE_RESOURCES_H -#define _WRITE_RESOURCES_H - -#include "message.h" - -/* Output the contents of a PO file as a binary C# .resources file. - Return 0 if ok, nonzero on error. */ -extern int - msgdomain_write_csharp_resources (message_list_ty *mlp, - const char *canon_encoding, - const char *domain_name, - const char *file_name); - -#endif /* _WRITE_RESOURCES_H */ diff --git a/gettext-tools/src/x-csharp.c b/gettext-tools/src/x-csharp.c deleted file mode 100644 index 71678b3ef..000000000 --- a/gettext-tools/src/x-csharp.c +++ /dev/null @@ -1,2080 +0,0 @@ -/* xgettext C# backend. - Copyright (C) 2003-2009, 2011, 2014, 2018-2019 Free Software Foundation, Inc. - Written by Bruno Haible , 2003. - - This program 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 3 of the License, or - (at your option) any later version. - - This program 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 this program. If not, see . */ - -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif - -/* Specification. */ -#include "x-csharp.h" - -#include -#include -#include -#include -#include - -#include "message.h" -#include "rc-str-list.h" -#include "xgettext.h" -#include "xg-pos.h" -#include "xg-encoding.h" -#include "xg-mixed-string.h" -#include "xg-arglist-context.h" -#include "xg-arglist-callshape.h" -#include "xg-arglist-parser.h" -#include "xg-message.h" -#include "c-ctype.h" -#include "error.h" -#include "error-progname.h" -#include "xalloc.h" -#include "xerror.h" -#include "xvasprintf.h" -#include "hash.h" -#include "po-charset.h" -#include "unistr.h" -#include "gettext.h" - -#define _(s) gettext(s) - -#define SIZEOF(a) (sizeof(a) / sizeof(a[0])) - - -/* The C# syntax is defined in ECMA-334, second edition. */ - - -/* ====================== Keyword set customization. ====================== */ - -/* If true extract all strings. */ -static bool extract_all = false; - -static hash_table keywords; -static bool default_keywords = true; - - -void -x_csharp_extract_all () -{ - extract_all = true; -} - - -/* Processes a --keyword option. - Non-ASCII function names can be used if given in UTF-8 encoding. */ -void -x_csharp_keyword (const char *name) -{ - if (name == NULL) - default_keywords = false; - else - { - const char *end; - struct callshape shape; - const char *colon; - - if (keywords.table == NULL) - hash_init (&keywords, 100); - - split_keywordspec (name, &end, &shape); - - /* The characters between name and end should form a valid C# - identifier sequence with dots. - A colon means an invalid parse in split_keywordspec(). */ - colon = strchr (name, ':'); - if (colon == NULL || colon >= end) - insert_keyword_callshape (&keywords, name, end - name, &shape); - } -} - -/* Finish initializing the keywords hash table. - Called after argument processing, before each file is processed. */ -static void -init_keywords () -{ - if (default_keywords) - { - /* When adding new keywords here, also update the documentation in - xgettext.texi! */ - x_csharp_keyword ("GetString"); /* Resource{Manager,Set}.GetString */ - x_csharp_keyword ("GetPluralString:1,2"); /* GettextResource{Manager,Set}.GetPluralString */ - x_csharp_keyword ("GetParticularString:1c,2"); /* Resource{Manager,Set}.GetParticularString */ - x_csharp_keyword ("GetParticularPluralString:1c,2,3"); /* Resource{Manager,Set}.GetParticularPluralString */ - default_keywords = false; - } -} - -void -init_flag_table_csharp () -{ - xgettext_record_flag ("GetString:1:pass-csharp-format"); - xgettext_record_flag ("GetPluralString:1:pass-csharp-format"); - xgettext_record_flag ("GetPluralString:2:pass-csharp-format"); - xgettext_record_flag ("GetParticularString:2:pass-csharp-format"); - xgettext_record_flag ("GetParticularPluralString:2:pass-csharp-format"); - xgettext_record_flag ("GetParticularPluralString:3:pass-csharp-format"); - xgettext_record_flag ("String.Format:1:csharp-format"); -} - - -/* ======================== Reading of characters. ======================== */ - -/* The input file stream. */ -static FILE *fp; - - -/* Phase 1: line_number handling. */ - -/* Maximum used, roughly a safer MB_LEN_MAX. */ -#define MAX_PHASE1_PUSHBACK 16 -static unsigned char phase1_pushback[MAX_PHASE1_PUSHBACK]; -static int phase1_pushback_length; - -/* Read the next single byte from the input file. */ -static int -phase1_getc () -{ - int c; - - if (phase1_pushback_length) - { - c = phase1_pushback[--phase1_pushback_length]; - if (c == '\n') - ++line_number; - return c; - } - - c = getc (fp); - if (c == EOF) - { - if (ferror (fp)) - error (EXIT_FAILURE, errno, _("error while reading \"%s\""), - real_file_name); - return EOF; - } - - if (c == '\n') - ++line_number; - return c; -} - -/* Supports MAX_PHASE1_PUSHBACK characters of pushback. */ -static void -phase1_ungetc (int c) -{ - if (c != EOF) - { - if (c == '\n') - --line_number; - if (phase1_pushback_length == SIZEOF (phase1_pushback)) - abort (); - phase1_pushback[phase1_pushback_length++] = c; - } -} - - -/* Phase 2: Conversion to Unicode. - This is done early because ECMA-334 section 9.1. says that the source is - "an ordered sequence of Unicode characters", and because the recognition - of the line terminators (ECMA-334 section 9.3.1) is hardly possible without - prior conversion to Unicode. */ - -/* End-of-file indicator for functions returning an UCS-4 character. */ -#define UEOF -1 - -/* Newline Unicode character. */ -#define UNL 0x000a - -static lexical_context_ty lexical_context; - -static int phase2_pushback[1]; -static int phase2_pushback_length; - -/* Read the next Unicode UCS-4 character from the input file. */ -static int -phase2_getc () -{ - if (phase2_pushback_length) - return phase2_pushback[--phase2_pushback_length]; - - if (xgettext_current_source_encoding == po_charset_ascii) - { - int c = phase1_getc (); - if (c == EOF) - return UEOF; - if (!c_isascii (c)) - { - multiline_error (xstrdup (""), - xasprintf ("%s\n%s\n", - non_ascii_error_message (lexical_context, - real_file_name, - line_number), - _("Please specify the source encoding through --from-code."))); - exit (EXIT_FAILURE); - } - return c; - } - else if (xgettext_current_source_encoding != po_charset_utf8) - { -#if HAVE_ICONV - /* Use iconv on an increasing number of bytes. Read only as many bytes - through phase1_getc as needed. This is needed to give reasonable - interactive behaviour when fp is connected to an interactive tty. */ - unsigned char buf[MAX_PHASE1_PUSHBACK]; - size_t bufcount; - int c = phase1_getc (); - if (c == EOF) - return UEOF; - buf[0] = (unsigned char) c; - bufcount = 1; - - for (;;) - { - unsigned char scratchbuf[6]; - const char *inptr = (const char *) &buf[0]; - size_t insize = bufcount; - char *outptr = (char *) &scratchbuf[0]; - size_t outsize = sizeof (scratchbuf); - - size_t res = iconv (xgettext_current_source_iconv, - (ICONV_CONST char **) &inptr, &insize, - &outptr, &outsize); - /* We expect that a character has been produced if and only if - some input bytes have been consumed. */ - if ((insize < bufcount) != (outsize < sizeof (scratchbuf))) - abort (); - if (outsize == sizeof (scratchbuf)) - { - /* No character has been produced. Must be an error. */ - if (res != (size_t)(-1)) - abort (); - - if (errno == EILSEQ) - { - /* An invalid multibyte sequence was encountered. */ - multiline_error (xstrdup (""), - xasprintf (_("\ -%s:%d: Invalid multibyte sequence.\n\ -Please specify the correct source encoding through --from-code.\n"), - real_file_name, line_number)); - exit (EXIT_FAILURE); - } - else if (errno == EINVAL) - { - /* An incomplete multibyte character. */ - int c; - - if (bufcount == MAX_PHASE1_PUSHBACK) - { - /* An overlong incomplete multibyte sequence was - encountered. */ - multiline_error (xstrdup (""), - xasprintf (_("\ -%s:%d: Long incomplete multibyte sequence.\n\ -Please specify the correct source encoding through --from-code.\n"), - real_file_name, line_number)); - exit (EXIT_FAILURE); - } - - /* Read one more byte and retry iconv. */ - c = phase1_getc (); - if (c == EOF) - { - multiline_error (xstrdup (""), - xasprintf (_("\ -%s:%d: Incomplete multibyte sequence at end of file.\n\ -Please specify the correct source encoding through --from-code.\n"), - real_file_name, line_number)); - exit (EXIT_FAILURE); - } - if (c == '\n') - { - multiline_error (xstrdup (""), - xasprintf (_("\ -%s:%d: Incomplete multibyte sequence at end of line.\n\ -Please specify the correct source encoding through --from-code.\n"), - real_file_name, line_number - 1)); - exit (EXIT_FAILURE); - } - buf[bufcount++] = (unsigned char) c; - } - else - error (EXIT_FAILURE, errno, _("%s:%d: iconv failure"), - real_file_name, line_number); - } - else - { - size_t outbytes = sizeof (scratchbuf) - outsize; - size_t bytes = bufcount - insize; - ucs4_t uc; - - /* We expect that one character has been produced. */ - if (bytes == 0) - abort (); - if (outbytes == 0) - abort (); - /* Push back the unused bytes. */ - while (insize > 0) - phase1_ungetc (buf[--insize]); - /* Convert the character from UTF-8 to UCS-4. */ - if (u8_mbtoucr (&uc, scratchbuf, outbytes) < (int) outbytes) - { - /* scratchbuf contains an out-of-range Unicode character - (> 0x10ffff). */ - multiline_error (xstrdup (""), - xasprintf (_("\ -%s:%d: Invalid multibyte sequence.\n\ -Please specify the source encoding through --from-code.\n"), - real_file_name, line_number)); - exit (EXIT_FAILURE); - } - return uc; - } - } -#else - /* If we don't have iconv(), the only supported values for - xgettext_global_source_encoding and thus also for - xgettext_current_source_encoding are ASCII and UTF-8. */ - abort (); -#endif - } - else - { - /* Read an UTF-8 encoded character. */ - unsigned char buf[6]; - unsigned int count; - int c; - ucs4_t uc; - - c = phase1_getc (); - if (c == EOF) - return UEOF; - buf[0] = c; - count = 1; - - if (buf[0] >= 0xc0) - { - c = phase1_getc (); - if (c == EOF) - return UEOF; - buf[1] = c; - count = 2; - } - - if (buf[0] >= 0xe0 - && ((buf[1] ^ 0x80) < 0x40)) - { - c = phase1_getc (); - if (c == EOF) - return UEOF; - buf[2] = c; - count = 3; - } - - if (buf[0] >= 0xf0 - && ((buf[1] ^ 0x80) < 0x40) - && ((buf[2] ^ 0x80) < 0x40)) - { - c = phase1_getc (); - if (c == EOF) - return UEOF; - buf[3] = c; - count = 4; - } - - if (buf[0] >= 0xf8 - && ((buf[1] ^ 0x80) < 0x40) - && ((buf[2] ^ 0x80) < 0x40) - && ((buf[3] ^ 0x80) < 0x40)) - { - c = phase1_getc (); - if (c == EOF) - return UEOF; - buf[4] = c; - count = 5; - } - - if (buf[0] >= 0xfc - && ((buf[1] ^ 0x80) < 0x40) - && ((buf[2] ^ 0x80) < 0x40) - && ((buf[3] ^ 0x80) < 0x40) - && ((buf[4] ^ 0x80) < 0x40)) - { - c = phase1_getc (); - if (c == EOF) - return UEOF; - buf[5] = c; - count = 6; - } - - u8_mbtouc (&uc, buf, count); - return uc; - } -} - -/* Supports only one pushback character. */ -static void -phase2_ungetc (int c) -{ - if (c != UEOF) - { - if (phase2_pushback_length == SIZEOF (phase2_pushback)) - abort (); - phase2_pushback[phase2_pushback_length++] = c; - } -} - - -/* Phase 3: Convert all line terminators to LF. - See ECMA-334 section 9.3.1. */ - -/* Line number defined in terms of phase3. */ -static int logical_line_number; - -static int phase3_pushback[9]; -static int phase3_pushback_length; - -/* Read the next Unicode UCS-4 character from the input file, mapping - all line terminators to U+000A, and dropping U+001A at the end of file. */ -static int -phase3_getc () -{ - int c; - - if (phase3_pushback_length) - { - c = phase3_pushback[--phase3_pushback_length]; - if (c == UNL) - ++logical_line_number; - return c; - } - - c = phase2_getc (); - - if (c == 0x000d) - { - int c1 = phase2_getc (); - - if (c1 != UEOF && c1 != 0x000a) - phase2_ungetc (c1); - - /* Seen line terminator CR or CR/LF. */ - ++logical_line_number; - return UNL; - } - - if (c == 0x0085 || c == 0x2028 || c == 0x2029) - { - /* Seen Unicode word processor newline. */ - ++logical_line_number; - return UNL; - } - - if (c == 0x001a) - { - int c1 = phase2_getc (); - - if (c1 == UEOF) - /* Seen U+001A right before the end of file. */ - return UEOF; - - phase2_ungetc (c1); - } - - if (c == UNL) - ++logical_line_number; - return c; -} - -/* Supports 9 characters of pushback. */ -static void -phase3_ungetc (int c) -{ - if (c != UEOF) - { - if (c == UNL) - --logical_line_number; - if (phase3_pushback_length == SIZEOF (phase3_pushback)) - abort (); - phase3_pushback[phase3_pushback_length++] = c; - } -} - - -/* ========================= Accumulating strings. ======================== */ - -/* See xg-mixed-string.h for the API. - In this extractor, we add only Unicode characters. */ - - -/* ======================== Accumulating comments. ======================== */ - - -/* Accumulating a single comment line. */ - -static struct mixed_string_buffer comment_buffer; - -static inline void -comment_start () -{ - mixed_string_buffer_init (&comment_buffer, lc_comment, - logical_file_name, line_number); -} - -static inline bool -comment_at_start () -{ - return mixed_string_buffer_is_empty (&comment_buffer); -} - -static inline void -comment_add (int c) -{ - mixed_string_buffer_append_unicode (&comment_buffer, c); -} - -static inline void -comment_line_end (size_t chars_to_remove) -{ - char *buffer = - mixed_string_contents_free1 (mixed_string_buffer_result (&comment_buffer)); - size_t buflen = strlen (buffer); - - buflen -= chars_to_remove; - while (buflen >= 1 - && (buffer[buflen - 1] == ' ' || buffer[buflen - 1] == '\t')) - --buflen; - buffer[buflen] = '\0'; - savable_comment_add (buffer); - lexical_context = lc_outside; -} - - -/* These are for tracking whether comments count as immediately before - keyword. */ -static int last_comment_line; -static int last_non_comment_line; - - -/* Phase 4: Replace each comment that is not inside a character constant or - string literal with a space or newline character. - See ECMA-334 section 9.3.2. */ - -static int -phase4_getc () -{ - int c0; - int c; - bool last_was_star; - - c0 = phase3_getc (); - if (c0 != '/') - return c0; - c = phase3_getc (); - switch (c) - { - default: - phase3_ungetc (c); - return c0; - - case '*': - /* C style comment. */ - comment_start (); - last_was_star = false; - for (;;) - { - c = phase3_getc (); - if (c == UEOF) - break; - /* We skip all leading white space, but not EOLs. */ - if (!(comment_at_start () && (c == ' ' || c == '\t'))) - comment_add (c); - switch (c) - { - case UNL: - comment_line_end (1); - comment_start (); - last_was_star = false; - continue; - - case '*': - last_was_star = true; - continue; - - case '/': - if (last_was_star) - { - comment_line_end (2); - break; - } - /* FALLTHROUGH */ - - default: - last_was_star = false; - continue; - } - break; - } - last_comment_line = logical_line_number; - return ' '; - - case '/': - /* C++ style comment. */ - last_comment_line = logical_line_number; - comment_start (); - for (;;) - { - c = phase3_getc (); - if (c == UNL || c == UEOF) - break; - /* We skip all leading white space, but not EOLs. */ - if (!(comment_at_start () && (c == ' ' || c == '\t'))) - comment_add (c); - } - phase3_ungetc (c); /* push back the newline, to decrement logical_line_number */ - comment_line_end (0); - phase3_getc (); /* read the newline again */ - return UNL; - } -} - -/* Supports only one pushback character. */ -static void -phase4_ungetc (int c) -{ - phase3_ungetc (c); -} - - -/* ======================= Character classification. ====================== */ - - -/* Return true if a given character is white space. - See ECMA-334 section 9.3.3. */ -static bool -is_whitespace (int c) -{ - /* Unicode character class Zs, as of Unicode 4.0. */ - /* grep '^[^;]*;[^;]*;Zs;' UnicodeData-4.0.0.txt */ - switch (c >> 8) - { - case 0x00: - return (c == 0x0020 || c == 0x00a0); - case 0x16: - return (c == 0x1680); - case 0x18: - return (c == 0x180e); - case 0x20: - return ((c >= 0x2000 && c <= 0x200b) || c == 0x202f || c == 0x205f); - case 0x30: - return (c == 0x3000); - default: - return false; - } -} - - -/* C# allows identifiers containing many Unicode characters. We recognize - them; to use an identifier with Unicode characters in a --keyword option, - it must be specified in UTF-8. */ - -static inline int -bitmap_lookup (const void *table, unsigned int uc) -{ - unsigned int index1 = uc >> 16; - if (index1 < ((const int *) table)[0]) - { - int lookup1 = ((const int *) table)[1 + index1]; - if (lookup1 >= 0) - { - unsigned int index2 = (uc >> 9) & 0x7f; - int lookup2 = ((const int *) table)[lookup1 + index2]; - if (lookup2 >= 0) - { - unsigned int index3 = (uc >> 5) & 0xf; - unsigned int lookup3 = ((const int *) table)[lookup2 + index3]; - - return (lookup3 >> (uc & 0x1f)) & 1; - } - } - } - return 0; -} - -/* Unicode character classes Lu, Ll, Lt, Lm, Lo, Nl, as of Unicode 4.0, - plus the underscore. */ -static const -struct - { - int header[1]; - int level1[3]; - int level2[3 << 7]; - /*unsigned*/ int level3[34 << 4]; - } -table_identifier_start = -{ - { 3 }, - { 4, 132, 260 }, - { - 388, 404, 420, 436, 452, 468, 484, 500, - 516, 532, 548, 564, 580, -1, 596, 612, - 628, -1, -1, -1, -1, -1, -1, -1, - 644, -1, 660, 660, 660, 660, 660, 660, - 660, 660, 660, 660, 660, 660, 676, 660, - 660, 660, 660, 660, 660, 660, 660, 660, - 660, 660, 660, 660, 660, 660, 660, 660, - 660, 660, 660, 660, 660, 660, 660, 660, - 660, 660, 660, 660, 660, 660, 660, 660, - 660, 660, 660, 660, 660, 660, 660, 692, - 660, 660, 708, -1, -1, -1, 660, 660, - 660, 660, 660, 660, 660, 660, 660, 660, - 660, 660, 660, 660, 660, 660, 660, 660, - 660, 660, 660, 724, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, 740, 756, 772, 788, - 804, 820, 836, -1, 852, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, 868, 884, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, - 660, 660, 660, 660, 660, 660, 660, 660, - 660, 660, 660, 660, 660, 660, 660, 660, - 660, 660, 660, 660, 660, 660, 660, 660, - 660, 660, 660, 660, 660, 660, 660, 660, - 660, 660, 660, 660, 660, 660, 660, 660, - 660, 660, 660, 660, 660, 660, 660, 660, - 660, 660, 660, 660, 660, 660, 660, 660, - 660, 660, 660, 660, 660, 660, 660, 660, - 660, 660, 660, 660, 660, 660, 660, 660, - 660, 660, 660, 660, 660, 660, 660, 660, - 660, 660, 660, 900, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, 660, 916, -1, -1 - }, - { - 0x00000000, 0x00000000, 0x87FFFFFE, 0x07FFFFFE, - 0x00000000, 0x04200400, 0xFF7FFFFF, 0xFF7FFFFF, - 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, - 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, - 0xFFFFFFFF, 0x007FFFFF, 0xFFFF0000, 0xFFFFFFFF, - 0xFFFFFFFF, 0xFFFFFFFF, 0x0003FFC3, 0x0000401F, - 0x00000000, 0x00000000, 0x00000000, 0x04000000, - 0xFFFFD740, 0xFFFFFFFB, 0xFFFF7FFF, 0x0FBFFFFF, - 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, - 0xFFFFFC03, 0xFFFFFFFF, 0xFFFF7FFF, 0x033FFFFF, - 0x0000FFFF, 0xFFFE0000, 0x027FFFFF, 0xFFFFFFFE, - 0x000000FF, 0x00000000, 0xFFFF0000, 0x000707FF, - 0x00000000, 0x07FFFFFE, 0x000007FF, 0xFFFEC000, - 0xFFFFFFFF, 0xFFFFFFFF, 0x002FFFFF, 0x9C00C060, - 0xFFFD0000, 0x0000FFFF, 0x0000E000, 0x00000000, - 0xFFFFFFFF, 0x0002003F, 0x00000000, 0x00000000, - 0x00000000, 0x00000000, 0x00000000, 0x00000000, - 0x00000000, 0x00000000, 0x00000000, 0x00000000, - 0xFFFFFFF0, 0x23FFFFFF, 0xFF010000, 0x00000003, - 0xFFF99FE0, 0x23C5FDFF, 0xB0000000, 0x00030003, - 0xFFF987E0, 0x036DFDFF, 0x5E000000, 0x001C0000, - 0xFFFBBFE0, 0x23EDFDFF, 0x00010000, 0x00000003, - 0xFFF99FE0, 0x23EDFDFF, 0xB0000000, 0x00020003, - 0xD63DC7E8, 0x03BFC718, 0x00000000, 0x00000000, - 0xFFFDDFE0, 0x03EFFDFF, 0x00000000, 0x00000003, - 0xFFFDDFE0, 0x23EFFDFF, 0x40000000, 0x00000003, - 0xFFFDDFE0, 0x03FFFDFF, 0x00000000, 0x00000003, - 0xFC7FFFE0, 0x2FFBFFFF, 0x0000007F, 0x00000000, - 0xFFFFFFFE, 0x000DFFFF, 0x0000007F, 0x00000000, - 0xFEF02596, 0x200DECAE, 0x3000005F, 0x00000000, - 0x00000001, 0x00000000, 0xFFFFFEFF, 0x000007FF, - 0x00000F00, 0x00000000, 0x00000000, 0x00000000, - 0xFFFFFFFF, 0x000006FB, 0x003F0000, 0x00000000, - 0x00000000, 0xFFFFFFFF, 0xFFFF003F, 0x01FFFFFF, - 0xFFFFFFFF, 0xFFFFFFFF, 0x83FFFFFF, 0xFFFFFFFF, - 0xFFFFFFFF, 0xFFFFFF07, 0xFFFFFFFF, 0x03FFFFFF, - 0xFFFFFF7F, 0xFFFFFFFF, 0x3D7F3D7F, 0xFFFFFFFF, - 0xFFFF3D7F, 0x7F3D7FFF, 0xFF7F7F3D, 0xFFFF7FFF, - 0x7F3D7FFF, 0xFFFFFFFF, 0x07FFFF7F, 0x00000000, - 0x00000000, 0xFFFFFFFF, 0xFFFFFFFF, 0x001FFFFF, - 0xFFFFFFFE, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, - 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, - 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, - 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, - 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x007F9FFF, - 0x07FFFFFE, 0xFFFFFFFF, 0xFFFFFFFF, 0x0001C7FF, - 0x0003DFFF, 0x0003FFFF, 0x0003FFFF, 0x0001DFFF, - 0xFFFFFFFF, 0x000FFFFF, 0x10800000, 0x00000000, - 0x00000000, 0xFFFFFFFF, 0xFFFFFFFF, 0x00FFFFFF, - 0xFFFFFFFF, 0x000001FF, 0x00000000, 0x00000000, - 0x1FFFFFFF, 0x00000000, 0xFFFF0000, 0x001F3FFF, - 0x00000000, 0x00000000, 0x00000000, 0x00000000, - 0x00000000, 0x00000000, 0x00000000, 0x00000000, - 0x00000000, 0x00000000, 0x00000000, 0x00000000, - 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x00000FFF, - 0x00000000, 0x00000000, 0x00000000, 0x00000000, - 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, - 0x0FFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x03FFFFFF, - 0x3F3FFFFF, 0xFFFFFFFF, 0xAAFF3F3F, 0x3FFFFFFF, - 0xFFFFFFFF, 0x5FDFFFFF, 0x0FCF1FDC, 0x1FDC1FFF, - 0x00000000, 0x00000000, 0x00000000, 0x80020000, - 0x00000000, 0x00000000, 0x00000000, 0x00000000, - 0x3E2FFC84, 0xE3FBBD50, 0x000003E0, 0xFFFFFFFF, - 0x0000000F, 0x00000000, 0x00000000, 0x00000000, - 0x000000E0, 0x1F3E03FE, 0xFFFFFFFE, 0xFFFFFFFF, - 0xE07FFFFF, 0xFFFFFFFE, 0xFFFFFFFF, 0xF7FFFFFF, - 0xFFFFFFE0, 0xFFFE1FFF, 0xFFFFFFFF, 0xFFFFFFFF, - 0x00007FFF, 0x00FFFFFF, 0x00000000, 0xFFFF0000, - 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, - 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, - 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, - 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, - 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, - 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, - 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, - 0xFFFFFFFF, 0x003FFFFF, 0x00000000, 0x00000000, - 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, - 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, - 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, - 0xFFFFFFFF, 0x0000003F, 0x00000000, 0x00000000, - 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, - 0x00001FFF, 0x00000000, 0x00000000, 0x00000000, - 0x00000000, 0x00000000, 0x00000000, 0x00000000, - 0x00000000, 0x00000000, 0x00000000, 0x00000000, - 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, - 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, - 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, - 0xFFFFFFFF, 0x0000000F, 0x00000000, 0x00000000, - 0x00000000, 0x00000000, 0x00000000, 0x00000000, - 0x00000000, 0x00000000, 0x00000000, 0x00000000, - 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, - 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, - 0xFFFFFFFF, 0xFFFF3FFF, 0xFFFFFFFF, 0x000007FF, - 0x00000000, 0x00000000, 0x00000000, 0x00000000, - 0xA0F8007F, 0x5F7FFDFF, 0xFFFFFFDB, 0xFFFFFFFF, - 0xFFFFFFFF, 0x0003FFFF, 0xFFF80000, 0xFFFFFFFF, - 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, - 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, - 0xFFFFFFFF, 0x3FFFFFFF, 0xFFFF0000, 0xFFFFFFFF, - 0xFFFCFFFF, 0xFFFFFFFF, 0x000000FF, 0x0FFF0000, - 0x00000000, 0x00000000, 0x00000000, 0xFFDF0000, - 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x1FFFFFFF, - 0x00000000, 0x07FFFFFE, 0x07FFFFFE, 0xFFFFFFC0, - 0xFFFFFFFF, 0x7FFFFFFF, 0x1CFCFCFC, 0x00000000, - 0xFFFFEFFF, 0xB7FFFF7F, 0x3FFF3FFF, 0x00000000, - 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x07FFFFFF, - 0x00000000, 0x00000000, 0x00000000, 0x00000000, - 0x00000000, 0x00000000, 0x00000000, 0x00000000, - 0x00000000, 0x00000000, 0x00000000, 0x00000000, - 0x00000000, 0x00000000, 0x00000000, 0x00000000, - 0x7FFFFFFF, 0xFFFF0000, 0x000007FF, 0x00000000, - 0x3FFFFFFF, 0x00000000, 0x00000000, 0x00000000, - 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, - 0x3FFFFFFF, 0x00000000, 0x00000000, 0x00000000, - 0x00000000, 0x00000000, 0x00000000, 0x00000000, - 0x00000000, 0x00000000, 0x00000000, 0x00000000, - 0xFFFFFD3F, 0x91BFFFFF, 0x00000000, 0x00000000, - 0x00000000, 0x00000000, 0x00000000, 0x00000000, - 0x00000000, 0x00000000, 0x00000000, 0x00000000, - 0x00000000, 0x00000000, 0x00000000, 0x00000000, - 0xFFFFFFFF, 0xFFFFFFFF, 0xFFDFFFFF, 0xFFFFFFFF, - 0xDFFFFFFF, 0xEBFFDE64, 0xFFFFFFEF, 0xFFFFFFFF, - 0xDFDFE7BF, 0x7BFFFFFF, 0xFFFDFC5F, 0xFFFFFFFF, - 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, - 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, - 0xFFFFFFFF, 0xFFFFFF0F, 0xF7FFFFFD, 0xF7FFFFFF, - 0xFFDFFFFF, 0xFFDFFFFF, 0xFFFF7FFF, 0xFFFF7FFF, - 0xFFFFFDFF, 0xFFFFFDFF, 0x000003F7, 0x00000000, - 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, - 0xFFFFFFFF, 0xFFFFFFFF, 0x007FFFFF, 0x00000000, - 0x00000000, 0x00000000, 0x00000000, 0x00000000, - 0x00000000, 0x00000000, 0x00000000, 0x00000000, - 0x3FFFFFFF, 0x00000000, 0x00000000, 0x00000000, - 0x00000000, 0x00000000, 0x00000000, 0x00000000, - 0x00000000, 0x00000000, 0x00000000, 0x00000000, - 0x00000000, 0x00000000, 0x00000000, 0x00000000 - } -}; - -/* Unicode character classes Lu, Ll, Lt, Lm, Lo, Nl, Nd, Pc, Mn, Mc, Cf, - as of Unicode 4.0. */ -static const -struct - { - int header[1]; - int level1[15]; - int level2[4 << 7]; - /*unsigned*/ int level3[36 << 4]; - } -table_identifier_part = -{ - { 15 }, - { - 16, 144, 272, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, 400 - }, - { - 528, 544, 560, 576, 592, 608, 624, 640, - 656, 672, 688, 704, 720, -1, 736, 752, - 768, -1, -1, -1, -1, -1, -1, -1, - 784, -1, 800, 800, 800, 800, 800, 800, - 800, 800, 800, 800, 800, 800, 816, 800, - 800, 800, 800, 800, 800, 800, 800, 800, - 800, 800, 800, 800, 800, 800, 800, 800, - 800, 800, 800, 800, 800, 800, 800, 800, - 800, 800, 800, 800, 800, 800, 800, 800, - 800, 800, 800, 800, 800, 800, 800, 832, - 800, 800, 848, -1, -1, -1, 800, 800, - 800, 800, 800, 800, 800, 800, 800, 800, - 800, 800, 800, 800, 800, 800, 800, 800, - 800, 800, 800, 864, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, 880, 896, 912, 928, - 944, 960, 976, -1, 992, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, - 1008, -1, 1024, 1040, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, - 800, 800, 800, 800, 800, 800, 800, 800, - 800, 800, 800, 800, 800, 800, 800, 800, - 800, 800, 800, 800, 800, 800, 800, 800, - 800, 800, 800, 800, 800, 800, 800, 800, - 800, 800, 800, 800, 800, 800, 800, 800, - 800, 800, 800, 800, 800, 800, 800, 800, - 800, 800, 800, 800, 800, 800, 800, 800, - 800, 800, 800, 800, 800, 800, 800, 800, - 800, 800, 800, 800, 800, 800, 800, 800, - 800, 800, 800, 800, 800, 800, 800, 800, - 800, 800, 800, 1056, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, 800, 1072, -1, -1, - 1088, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1 - }, - { - 0x00000000, 0x03FF0000, 0x87FFFFFE, 0x07FFFFFE, - 0x00000000, 0x04202400, 0xFF7FFFFF, 0xFF7FFFFF, - 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, - 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, - 0xFFFFFFFF, 0x007FFFFF, 0xFFFF0000, 0xFFFFFFFF, - 0xFFFFFFFF, 0xFFFFFFFF, 0x0003FFC3, 0x0000401F, - 0xFFFFFFFF, 0xFFFFFFFF, 0xE0FFFFFF, 0x0400FFFF, - 0xFFFFD740, 0xFFFFFFFB, 0xFFFF7FFF, 0x0FBFFFFF, - 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, - 0xFFFFFC7B, 0xFFFFFFFF, 0xFFFF7FFF, 0x033FFFFF, - 0x0000FFFF, 0xFFFE0000, 0x027FFFFF, 0xFFFFFFFE, - 0xFFFE00FF, 0xBBFFFFFB, 0xFFFF0016, 0x000707FF, - 0x003F000F, 0x07FFFFFE, 0x01FFFFFF, 0xFFFFC3FF, - 0xFFFFFFFF, 0xFFFFFFFF, 0xBFEFFFFF, 0x9FFFFDFF, - 0xFFFF8000, 0xFFFFFFFF, 0x0000E7FF, 0x00000000, - 0xFFFFFFFF, 0x0003FFFF, 0x00000000, 0x00000000, - 0x00000000, 0x00000000, 0x00000000, 0x00000000, - 0x00000000, 0x00000000, 0x00000000, 0x00000000, - 0xFFFFFFFE, 0xF3FFFFFF, 0xFF1F3FFF, 0x0000FFCF, - 0xFFF99FEE, 0xF3C5FDFF, 0xB080399F, 0x0003FFCF, - 0xFFF987EE, 0xD36DFDFF, 0x5E003987, 0x001FFFC0, - 0xFFFBBFEE, 0xF3EDFDFF, 0x00013BBF, 0x0000FFCF, - 0xFFF99FEE, 0xF3EDFDFF, 0xB0C0398F, 0x0002FFC3, - 0xD63DC7EC, 0xC3BFC718, 0x00803DC7, 0x0000FF80, - 0xFFFDDFEE, 0xC3EFFDFF, 0x00603DDF, 0x0000FFC3, - 0xFFFDDFEC, 0xF3EFFDFF, 0x40603DDF, 0x0000FFC3, - 0xFFFDDFEC, 0xC3FFFDFF, 0x00803DCF, 0x0000FFC3, - 0xFC7FFFEC, 0x2FFBFFFF, 0xFF5F847F, 0x000C0000, - 0xFFFFFFFE, 0x07FFFFFF, 0x03FF7FFF, 0x00000000, - 0xFEF02596, 0x3BFFECAE, 0x33FF3F5F, 0x00000000, - 0x03000001, 0xC2A003FF, 0xFFFFFEFF, 0xFFFE07FF, - 0xFEFF0FDF, 0x1FFFFFFF, 0x00000040, 0x00000000, - 0xFFFFFFFF, 0x03C7F6FB, 0x03FF03FF, 0x00000000, - 0x00000000, 0xFFFFFFFF, 0xFFFF003F, 0x01FFFFFF, - 0xFFFFFFFF, 0xFFFFFFFF, 0x83FFFFFF, 0xFFFFFFFF, - 0xFFFFFFFF, 0xFFFFFF07, 0xFFFFFFFF, 0x03FFFFFF, - 0xFFFFFF7F, 0xFFFFFFFF, 0x3D7F3D7F, 0xFFFFFFFF, - 0xFFFF3D7F, 0x7F3D7FFF, 0xFF7F7F3D, 0xFFFF7FFF, - 0x7F3D7FFF, 0xFFFFFFFF, 0x07FFFF7F, 0x0003FE00, - 0x00000000, 0xFFFFFFFF, 0xFFFFFFFF, 0x001FFFFF, - 0xFFFFFFFE, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, - 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, - 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, - 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, - 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x007F9FFF, - 0x07FFFFFE, 0xFFFFFFFF, 0xFFFFFFFF, 0x0001C7FF, - 0x001FDFFF, 0x001FFFFF, 0x000FFFFF, 0x000DDFFF, - 0xFFFFFFFF, 0xFFFFFFFF, 0x308FFFFF, 0x000003FF, - 0x03FF3800, 0xFFFFFFFF, 0xFFFFFFFF, 0x00FFFFFF, - 0xFFFFFFFF, 0x000003FF, 0x00000000, 0x00000000, - 0x1FFFFFFF, 0x0FFF0FFF, 0xFFFFFFC0, 0x001F3FFF, - 0x00000000, 0x00000000, 0x00000000, 0x00000000, - 0x00000000, 0x00000000, 0x00000000, 0x00000000, - 0x00000000, 0x00000000, 0x00000000, 0x00000000, - 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x00000FFF, - 0x00000000, 0x00000000, 0x00000000, 0x00000000, - 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, - 0x0FFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x03FFFFFF, - 0x3F3FFFFF, 0xFFFFFFFF, 0xAAFF3F3F, 0x3FFFFFFF, - 0xFFFFFFFF, 0x5FDFFFFF, 0x0FCF1FDC, 0x1FDC1FFF, - 0x0000F000, 0x80007C00, 0x00100001, 0x8002FC0F, - 0x00000000, 0x00000000, 0x1FFF0000, 0x000007E2, - 0x3E2FFC84, 0xE3FBBD50, 0x000003E0, 0xFFFFFFFF, - 0x0000000F, 0x00000000, 0x00000000, 0x00000000, - 0x000000E0, 0x1F3EFFFE, 0xFFFFFFFE, 0xFFFFFFFF, - 0xE67FFFFF, 0xFFFFFFFE, 0xFFFFFFFF, 0xFFFFFFFF, - 0xFFFFFFE0, 0xFFFE1FFF, 0xFFFFFFFF, 0xFFFFFFFF, - 0x00007FFF, 0x00FFFFFF, 0x00000000, 0xFFFF0000, - 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, - 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, - 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, - 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, - 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, - 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, - 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, - 0xFFFFFFFF, 0x003FFFFF, 0x00000000, 0x00000000, - 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, - 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, - 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, - 0xFFFFFFFF, 0x0000003F, 0x00000000, 0x00000000, - 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, - 0x00001FFF, 0x00000000, 0x00000000, 0x00000000, - 0x00000000, 0x00000000, 0x00000000, 0x00000000, - 0x00000000, 0x00000000, 0x00000000, 0x00000000, - 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, - 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, - 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, - 0xFFFFFFFF, 0x0000000F, 0x00000000, 0x00000000, - 0x00000000, 0x00000000, 0x00000000, 0x00000000, - 0x00000000, 0x00000000, 0x00000000, 0x00000000, - 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, - 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, - 0xFFFFFFFF, 0xFFFF3FFF, 0xFFFFFFFF, 0x000007FF, - 0x00000000, 0x00000000, 0x00000000, 0x00000000, - 0xE0F8007F, 0x5F7FFDFF, 0xFFFFFFDB, 0xFFFFFFFF, - 0xFFFFFFFF, 0x0003FFFF, 0xFFF80000, 0xFFFFFFFF, - 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, - 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, - 0xFFFFFFFF, 0x3FFFFFFF, 0xFFFF0000, 0xFFFFFFFF, - 0xFFFCFFFF, 0xFFFFFFFF, 0x000000FF, 0x0FFF0000, - 0x0000FFFF, 0x0018000F, 0x0000E000, 0xFFDF0000, - 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x9FFFFFFF, - 0x03FF0000, 0x87FFFFFE, 0x07FFFFFE, 0xFFFFFFE0, - 0xFFFFFFFF, 0x7FFFFFFF, 0x1CFCFCFC, 0x0E000000, - 0xFFFFEFFF, 0xB7FFFF7F, 0x3FFF3FFF, 0x00000000, - 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x07FFFFFF, - 0x00000000, 0x00000000, 0x00000000, 0x00000000, - 0x00000000, 0x00000000, 0x00000000, 0x00000000, - 0x00000000, 0x00000000, 0x00000000, 0x00000000, - 0x00000000, 0x00000000, 0x00000000, 0x00000000, - 0x7FFFFFFF, 0xFFFF0000, 0x000007FF, 0x00000000, - 0x3FFFFFFF, 0x00000000, 0x00000000, 0x00000000, - 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, - 0x3FFFFFFF, 0x000003FF, 0x00000000, 0x00000000, - 0x00000000, 0x00000000, 0x00000000, 0x00000000, - 0x00000000, 0x00000000, 0x00000000, 0x00000000, - 0xFFFFFD3F, 0x91BFFFFF, 0x00000000, 0x00000000, - 0x00000000, 0x00000000, 0x00000000, 0x00000000, - 0x00000000, 0x00000000, 0x00000000, 0x00000000, - 0x00000000, 0x00000000, 0x00000000, 0x00000000, - 0x00000000, 0x00000000, 0x00000000, 0x00000000, - 0x00000000, 0x00000000, 0x00000000, 0x00000000, - 0x00000000, 0x00000000, 0x00000000, 0xFFFFE3E0, - 0x00000FE7, 0x00003C00, 0x00000000, 0x00000000, - 0xFFFFFFFF, 0xFFFFFFFF, 0xFFDFFFFF, 0xFFFFFFFF, - 0xDFFFFFFF, 0xEBFFDE64, 0xFFFFFFEF, 0xFFFFFFFF, - 0xDFDFE7BF, 0x7BFFFFFF, 0xFFFDFC5F, 0xFFFFFFFF, - 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, - 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, - 0xFFFFFFFF, 0xFFFFFF0F, 0xF7FFFFFD, 0xF7FFFFFF, - 0xFFDFFFFF, 0xFFDFFFFF, 0xFFFF7FFF, 0xFFFF7FFF, - 0xFFFFFDFF, 0xFFFFFDFF, 0xFFFFC3F7, 0xFFFFFFFF, - 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, - 0xFFFFFFFF, 0xFFFFFFFF, 0x007FFFFF, 0x00000000, - 0x00000000, 0x00000000, 0x00000000, 0x00000000, - 0x00000000, 0x00000000, 0x00000000, 0x00000000, - 0x3FFFFFFF, 0x00000000, 0x00000000, 0x00000000, - 0x00000000, 0x00000000, 0x00000000, 0x00000000, - 0x00000000, 0x00000000, 0x00000000, 0x00000000, - 0x00000000, 0x00000000, 0x00000000, 0x00000000, - 0x00000002, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, - 0x00000000, 0x00000000, 0x00000000, 0x00000000, - 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, - 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x0000FFFF - } -}; - -/* Return true if a given character can occur as first character of an - identifier. See ECMA-334 section 9.4.2. */ -static bool -is_identifier_start (int c) -{ - return bitmap_lookup (&table_identifier_start, c); - /* In ASCII only this would be: - return ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || c == '_'); - */ -} - -/* Return true if a given character can occur as character of an identifier. - See ECMA-334 section 9.4.2. */ -static bool -is_identifier_part (int c) -{ - return bitmap_lookup (&table_identifier_part, c); - /* In ASCII only this would be: - return ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') - || (c >= '0' && c <= '9') || c == '_'); - */ -} - -static bool -is_any_character (int c) -{ - return true; -} - - -/* ======================= Preprocessor directives. ======================= */ - - -/* Phase 5: Remove preprocessor lines. See ECMA-334 section 9.5. - As a side effect, this also removes initial whitespace on every line; - this whitespace doesn't matter. */ - -static int phase5_pushback[10]; -static int phase5_pushback_length; - -static int -phase5_getc () -{ - int c; - - if (phase5_pushback_length) - return phase5_pushback[--phase5_pushback_length]; - - c = phase4_getc (); - if (c != UNL) - return c; - - do - c = phase3_getc (); - while (c != UEOF && is_whitespace (c)); - - if (c == '#') - { - /* Ignore the entire line containing the preprocessor directive - (including the // comment if it contains one). */ - do - c = phase3_getc (); - while (c != UEOF && c != UNL); - return c; - } - else - { - phase3_ungetc (c); - return UNL; - } -} - -#ifdef unused -static void -phase5_ungetc (int c) -{ - if (c != UEOF) - { - if (phase5_pushback_length == SIZEOF (phase5_pushback)) - abort (); - phase5_pushback[phase5_pushback_length++] = c; - } -} -#endif - - -/* ========================== Reading of tokens. ========================== */ - -enum token_type_ty -{ - token_type_eof, - token_type_lparen, /* ( */ - token_type_rparen, /* ) */ - token_type_lbrace, /* { */ - token_type_rbrace, /* } */ - token_type_comma, /* , */ - token_type_dot, /* . */ - token_type_string_literal, /* "abc", @"abc" */ - token_type_number, /* 1.23 */ - token_type_symbol, /* identifier, keyword, null */ - token_type_plus, /* + */ - token_type_other /* character literal, misc. operator */ -}; -typedef enum token_type_ty token_type_ty; - -typedef struct token_ty token_ty; -struct token_ty -{ - token_type_ty type; - char *string; /* for token_type_symbol */ - mixed_string_ty *mixed_string; /* for token_type_string_literal */ - refcounted_string_list_ty *comment; /* for token_type_string_literal */ - int line_number; - int logical_line_number; -}; - - -/* Free the memory pointed to by a 'struct token_ty'. */ -static inline void -free_token (token_ty *tp) -{ - if (tp->type == token_type_symbol) - free (tp->string); - if (tp->type == token_type_string_literal) - { - mixed_string_free (tp->mixed_string); - drop_reference (tp->comment); - } -} - - -/* Read a Unicode escape sequence outside string/character literals. - Reject Unicode escapes that don't fulfill the given predicate. - See ECMA-334 section 9.4.2. */ -static int -do_getc_unicode_escaped (bool (*predicate) (int)) -{ - int c; - - /* Use phase 3, because phase 4 elides comments. */ - c = phase3_getc (); - if (c == UEOF) - return '\\'; - if (c == 'u' || c == 'U') - { - unsigned char buf[8]; - int expect; - unsigned int n; - int i; - - expect = (c == 'U' ? 8 : 4); - n = 0; - for (i = 0; i < expect; i++) - { - int c1 = phase3_getc (); - - if (c1 >= '0' && c1 <= '9') - n = (n << 4) + (c1 - '0'); - else if (c1 >= 'A' && c1 <= 'F') - n = (n << 4) + (c1 - 'A' + 10); - else if (c1 >= 'a' && c1 <= 'f') - n = (n << 4) + (c1 - 'a' + 10); - else - { - phase3_ungetc (c1); - while (--i >= 0) - phase3_ungetc (buf[i]); - phase3_ungetc (c); - return '\\'; - } - - buf[i] = c1; - } - - if (n >= 0x110000) - { - error_with_progname = false; - error (0, 0, _("%s:%d: warning: invalid Unicode character"), - logical_file_name, line_number); - error_with_progname = true; - } - else if (predicate (n)) - return n; - - while (--i >= 0) - phase3_ungetc (buf[i]); - } - phase3_ungetc (c); - return '\\'; -} - - -/* Read an escape sequence inside a string literal or character literal. - See ECMA-334 sections 9.4.4.4., 9.4.4.5. */ -static int -do_getc_escaped () -{ - int c; - int n; - int i; - - /* Use phase 3, because phase 4 elides comments. */ - c = phase3_getc (); - if (c == UEOF) - return '\\'; - switch (c) - { - case 'a': - return 0x0007; - case 'b': - return 0x0008; - case 't': - return 0x0009; - case 'n': - return 0x000a; - case 'v': - return 0x000b; - case 'f': - return 0x000c; - case 'r': - return 0x000d; - case '"': - return '"'; - case '\'': - return '\''; - case '\\': - return '\\'; - case '0': - return 0x0000; - case 'x': - c = phase3_getc (); - switch (c) - { - default: - phase3_ungetc (c); - phase3_ungetc ('x'); - return '\\'; - - case '0': case '1': case '2': case '3': case '4': - case '5': case '6': case '7': case '8': case '9': - case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': - case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': - break; - } - n = 0; - for (i = 0;; i++) - { - switch (c) - { - default: - phase3_ungetc (c); - return n; - case '0': case '1': case '2': case '3': case '4': - case '5': case '6': case '7': case '8': case '9': - n = n * 16 + c - '0'; - break; - case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': - n = n * 16 + 10 + c - 'A'; - break; - case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': - n = n * 16 + 10 + c - 'a'; - break; - } - if (i == 3) - break; - c = phase3_getc (); - } - return n; - case 'u': case 'U': - phase3_ungetc (c); - return do_getc_unicode_escaped (is_any_character); - default: - /* Invalid escape sequence. */ - phase3_ungetc (c); - return '\\'; - } -} - -/* Read a regular string literal or character literal. - See ECMA-334 sections 9.4.4.4., 9.4.4.5. */ -static void -accumulate_escaped (struct mixed_string_buffer *literal, int delimiter) -{ - int c; - - for (;;) - { - /* Use phase 3, because phase 4 elides comments. */ - c = phase3_getc (); - if (c == UEOF || c == delimiter) - break; - if (c == UNL) - { - phase3_ungetc (c); - error_with_progname = false; - if (delimiter == '\'') - error (0, 0, _("%s:%d: warning: unterminated character constant"), - logical_file_name, line_number); - else - error (0, 0, _("%s:%d: warning: unterminated string constant"), - logical_file_name, line_number); - error_with_progname = true; - break; - } - if (c == '\\') - c = do_getc_escaped (); - if (literal) - mixed_string_buffer_append_unicode (literal, c); - } -} - - -/* Combine characters into tokens. Discard whitespace. */ - -/* Maximum used guaranteed to be < 4. */ -static token_ty phase6_pushback[4]; -static int phase6_pushback_length; - -static void -phase6_get (token_ty *tp) -{ - int c; - - if (phase6_pushback_length) - { - *tp = phase6_pushback[--phase6_pushback_length]; - return; - } - tp->string = NULL; - - for (;;) - { - tp->line_number = line_number; - tp->logical_line_number = logical_line_number; - c = phase5_getc (); - - if (c == UEOF) - { - tp->type = token_type_eof; - return; - } - - switch (c) - { - case UNL: - if (last_non_comment_line > last_comment_line) - savable_comment_reset (); - /* FALLTHROUGH */ - case ' ': - case '\t': - case '\f': - /* Ignore whitespace and comments. */ - continue; - } - - last_non_comment_line = tp->logical_line_number; - - switch (c) - { - case '(': - tp->type = token_type_lparen; - return; - - case ')': - tp->type = token_type_rparen; - return; - - case '{': - tp->type = token_type_lbrace; - return; - - case '}': - tp->type = token_type_rbrace; - return; - - case ',': - tp->type = token_type_comma; - return; - - case '.': - c = phase4_getc (); - if (!(c >= '0' && c <= '9')) - { - phase4_ungetc (c); - tp->type = token_type_dot; - return; - } - /* FALLTHROUGH */ - - case '0': case '1': case '2': case '3': case '4': - case '5': case '6': case '7': case '8': case '9': - { - /* Don't need to verify the complicated syntax of integers and - floating-point numbers. We assume a valid C# input. - The simplified syntax that we recognize as number is: any - sequence of alphanumeric characters, additionally '+' and '-' - immediately after 'e' or 'E' except in hexadecimal numbers. */ - bool hexadecimal = false; - - for (;;) - { - c = phase4_getc (); - if (c >= '0' && c <= '9') - continue; - if ((c >= 'A' && c <= 'Z') || (c >= 'a' &&c <= 'z')) - { - if (c == 'X' || c == 'x') - hexadecimal = true; - if ((c == 'E' || c == 'e') && !hexadecimal) - { - c = phase4_getc (); - if (!(c == '+' || c == '-')) - phase4_ungetc (c); - } - continue; - } - if (c == '.') - continue; - break; - } - phase4_ungetc (c); - tp->type = token_type_number; - return; - } - - case '"': - /* Regular string literal. */ - { - struct mixed_string_buffer literal; - - lexical_context = lc_string; - mixed_string_buffer_init (&literal, - lexical_context, - logical_file_name, - logical_line_number); - accumulate_escaped (&literal, '"'); - tp->mixed_string = mixed_string_buffer_result (&literal); - tp->comment = add_reference (savable_comment); - lexical_context = lc_outside; - tp->type = token_type_string_literal; - return; - } - - case '\'': - /* Character literal. */ - { - accumulate_escaped (NULL, '\''); - tp->type = token_type_other; - return; - } - - case '+': - c = phase4_getc (); - if (c == '+') - /* Operator ++ */ - tp->type = token_type_other; - else if (c == '=') - /* Operator += */ - tp->type = token_type_other; - else - { - /* Operator + */ - phase4_ungetc (c); - tp->type = token_type_plus; - } - return; - - case '@': - c = phase4_getc (); - if (c == '"') - { - /* Verbatim string literal. */ - struct mixed_string_buffer literal; - - lexical_context = lc_string; - mixed_string_buffer_init (&literal, lexical_context, - logical_file_name, logical_line_number); - for (;;) - { - /* Use phase 2, because phase 4 elides comments and phase 3 - mixes up the newline characters. */ - c = phase2_getc (); - if (c == UEOF) - break; - if (c == '"') - { - c = phase2_getc (); - if (c != '"') - { - phase2_ungetc (c); - break; - } - } - /* No special treatment of newline and backslash here. */ - mixed_string_buffer_append_unicode (&literal, c); - } - tp->mixed_string = mixed_string_buffer_result (&literal); - tp->comment = add_reference (savable_comment); - lexical_context = lc_outside; - tp->type = token_type_string_literal; - return; - } - /* FALLTHROUGH, so that @identifier is recognized. */ - - default: - if (c == '\\') - c = do_getc_unicode_escaped (is_identifier_start); - if (is_identifier_start (c)) - { - struct mixed_string_buffer buffer; - mixed_string_ty *mixed_string; - - mixed_string_buffer_init (&buffer, lexical_context, - logical_file_name, logical_line_number); - for (;;) - { - mixed_string_buffer_append_unicode (&buffer, c); - c = phase4_getc (); - if (c == '\\') - c = do_getc_unicode_escaped (is_identifier_part); - if (!is_identifier_part (c)) - break; - } - phase4_ungetc (c); - mixed_string = mixed_string_buffer_result (&buffer); - tp->string = mixed_string_contents (mixed_string); - mixed_string_free (mixed_string); - tp->type = token_type_symbol; - return; - } - else - { - /* Misc. operator. */ - tp->type = token_type_other; - return; - } - } - } -} - -/* Supports 3 tokens of pushback. */ -static void -phase6_unget (token_ty *tp) -{ - if (tp->type != token_type_eof) - { - if (phase6_pushback_length == SIZEOF (phase6_pushback)) - abort (); - phase6_pushback[phase6_pushback_length++] = *tp; - } -} - - -/* Compile-time optimization of string literal concatenation. - Combine "string1" + ... + "stringN" to the concatenated string if - - the token after this expression is not '.' (because then the last - string could be part of a method call expression). */ - -static token_ty phase7_pushback[2]; -static int phase7_pushback_length; - -static void -phase7_get (token_ty *tp) -{ - if (phase7_pushback_length) - { - *tp = phase7_pushback[--phase7_pushback_length]; - return; - } - - phase6_get (tp); - if (tp->type == token_type_string_literal) - { - mixed_string_ty *sum = tp->mixed_string; - - for (;;) - { - token_ty token2; - - phase6_get (&token2); - if (token2.type == token_type_plus) - { - token_ty token3; - - phase6_get (&token3); - if (token3.type == token_type_string_literal) - { - token_ty token_after; - - phase6_get (&token_after); - if (token_after.type != token_type_dot) - { - sum = mixed_string_concat_free1 (sum, token3.mixed_string); - - phase6_unget (&token_after); - free_token (&token3); - free_token (&token2); - continue; - } - phase6_unget (&token_after); - } - phase6_unget (&token3); - } - phase6_unget (&token2); - break; - } - tp->mixed_string = sum; - } -} - -/* Supports 2 tokens of pushback. */ -static void -phase7_unget (token_ty *tp) -{ - if (tp->type != token_type_eof) - { - if (phase7_pushback_length == SIZEOF (phase7_pushback)) - abort (); - phase7_pushback[phase7_pushback_length++] = *tp; - } -} - - -static void -x_csharp_lex (token_ty *tp) -{ - phase7_get (tp); -} - -/* Supports 2 tokens of pushback. */ -static void -x_csharp_unlex (token_ty *tp) -{ - phase7_unget (tp); -} - - -/* ========================= Extracting strings. ========================== */ - - -/* Context lookup table. */ -static flag_context_list_table_ty *flag_context_list_table; - - -/* The file is broken into tokens. Scan the token stream, looking for - a keyword, followed by a left paren, followed by a string. When we - see this sequence, we have something to remember. We assume we are - looking at a valid C or C++ program, and leave the complaints about - the grammar to the compiler. - - Normal handling: Look for - keyword ( ... msgid ... ) - Plural handling: Look for - keyword ( ... msgid ... msgid_plural ... ) - - We use recursion because the arguments before msgid or between msgid - and msgid_plural can contain subexpressions of the same form. */ - - -/* Extract messages until the next balanced closing parenthesis or brace, - depending on TERMINATOR. - Extracted messages are added to MLP. - Return true upon eof, false upon closing parenthesis or brace. */ -static bool -extract_parenthesized (message_list_ty *mlp, token_type_ty terminator, - flag_context_ty outer_context, - flag_context_list_iterator_ty context_iter, - struct arglist_parser *argparser) -{ - /* Current argument number. */ - int arg = 1; - /* 0 when no keyword has been seen. 1 right after a keyword is seen. */ - int state; - /* Parameters of the keyword just seen. Defined only in state 1. */ - const struct callshapes *next_shapes = NULL; - /* Context iterator that will be used if the next token is a '('. */ - flag_context_list_iterator_ty next_context_iter = - passthrough_context_list_iterator; - /* Current context. */ - flag_context_ty inner_context = - inherited_context (outer_context, - flag_context_list_iterator_advance (&context_iter)); - - /* Start state is 0. */ - state = 0; - - for (;;) - { - token_ty token; - - x_csharp_lex (&token); - switch (token.type) - { - case token_type_symbol: - { - /* Combine symbol1 . ... . symbolN to a single strings, so that - we can recognize static function calls like - GettextResource.gettext. The information present for - symbolI.....symbolN has precedence over the information for - symbolJ.....symbolN with J > I. */ - char *sum = token.string; - size_t sum_len = strlen (sum); - const char *dottedname; - flag_context_list_ty *context_list; - - for (;;) - { - token_ty token2; - - x_csharp_lex (&token2); - if (token2.type == token_type_dot) - { - token_ty token3; - - x_csharp_lex (&token3); - if (token3.type == token_type_symbol) - { - char *addend = token3.string; - size_t addend_len = strlen (addend); - - sum = - (char *) xrealloc (sum, sum_len + 1 + addend_len + 1); - sum[sum_len] = '.'; - memcpy (sum + sum_len + 1, addend, addend_len + 1); - sum_len += 1 + addend_len; - - free_token (&token3); - free_token (&token2); - continue; - } - x_csharp_unlex (&token3); - } - x_csharp_unlex (&token2); - break; - } - - for (dottedname = sum;;) - { - void *keyword_value; - - if (hash_find_entry (&keywords, dottedname, strlen (dottedname), - &keyword_value) - == 0) - { - next_shapes = (const struct callshapes *) keyword_value; - state = 1; - break; - } - - dottedname = strchr (dottedname, '.'); - if (dottedname == NULL) - { - state = 0; - break; - } - dottedname++; - } - - for (dottedname = sum;;) - { - context_list = - flag_context_list_table_lookup ( - flag_context_list_table, - dottedname, strlen (dottedname)); - if (context_list != NULL) - break; - - dottedname = strchr (dottedname, '.'); - if (dottedname == NULL) - break; - dottedname++; - } - next_context_iter = flag_context_list_iterator (context_list); - - free (sum); - continue; - } - - case token_type_lparen: - if (extract_parenthesized (mlp, token_type_rparen, - inner_context, next_context_iter, - arglist_parser_alloc (mlp, - state ? next_shapes : NULL))) - { - arglist_parser_done (argparser, arg); - return true; - } - next_context_iter = null_context_list_iterator; - state = 0; - continue; - - case token_type_rparen: - if (terminator == token_type_rparen) - { - arglist_parser_done (argparser, arg); - return false; - } - if (terminator == token_type_rbrace) - { - error_with_progname = false; - error (0, 0, - _("%s:%d: warning: ')' found where '}' was expected"), - logical_file_name, token.line_number); - error_with_progname = true; - } - next_context_iter = null_context_list_iterator; - state = 0; - continue; - - case token_type_lbrace: - if (extract_parenthesized (mlp, token_type_rbrace, - null_context, null_context_list_iterator, - arglist_parser_alloc (mlp, NULL))) - { - arglist_parser_done (argparser, arg); - return true; - } - next_context_iter = null_context_list_iterator; - state = 0; - continue; - - case token_type_rbrace: - if (terminator == token_type_rbrace) - { - arglist_parser_done (argparser, arg); - return false; - } - if (terminator == token_type_rparen) - { - error_with_progname = false; - error (0, 0, - _("%s:%d: warning: '}' found where ')' was expected"), - logical_file_name, token.line_number); - error_with_progname = true; - } - next_context_iter = null_context_list_iterator; - state = 0; - continue; - - case token_type_comma: - arg++; - inner_context = - inherited_context (outer_context, - flag_context_list_iterator_advance ( - &context_iter)); - next_context_iter = passthrough_context_list_iterator; - state = 0; - continue; - - case token_type_string_literal: - { - lex_pos_ty pos; - - pos.file_name = logical_file_name; - pos.line_number = token.line_number; - - if (extract_all) - { - char *string = mixed_string_contents (token.mixed_string); - mixed_string_free (token.mixed_string); - remember_a_message (mlp, NULL, string, true, false, - inner_context, &pos, - NULL, token.comment, true); - } - else - arglist_parser_remember (argparser, arg, token.mixed_string, - inner_context, - pos.file_name, pos.line_number, - token.comment, true); - } - drop_reference (token.comment); - next_context_iter = null_context_list_iterator; - state = 0; - continue; - - case token_type_eof: - arglist_parser_done (argparser, arg); - return true; - - case token_type_dot: - case token_type_number: - case token_type_plus: - case token_type_other: - next_context_iter = null_context_list_iterator; - state = 0; - continue; - - default: - abort (); - } - } -} - - -void -extract_csharp (FILE *f, - const char *real_filename, const char *logical_filename, - flag_context_list_table_ty *flag_table, - msgdomain_list_ty *mdlp) -{ - message_list_ty *mlp = mdlp->item[0]->messages; - - fp = f; - real_file_name = real_filename; - logical_file_name = xstrdup (logical_filename); - line_number = 1; - - lexical_context = lc_outside; - - logical_line_number = 1; - last_comment_line = -1; - last_non_comment_line = -1; - - flag_context_list_table = flag_table; - - init_keywords (); - - /* Eat tokens until eof is seen. When extract_parenthesized returns - due to an unbalanced closing parenthesis, just restart it. */ - while (!extract_parenthesized (mlp, token_type_eof, - null_context, null_context_list_iterator, - arglist_parser_alloc (mlp, NULL))) - ; - - fp = NULL; - real_file_name = NULL; - logical_file_name = NULL; - line_number = 0; -} diff --git a/gettext-tools/src/x-csharp.h b/gettext-tools/src/x-csharp.h deleted file mode 100644 index 54fb0582c..000000000 --- a/gettext-tools/src/x-csharp.h +++ /dev/null @@ -1,50 +0,0 @@ -/* xgettext C# backend. - Copyright (C) 2003-2004, 2006, 2014, 2018 Free Software Foundation, Inc. - Written by Bruno Haible , 2003. - - This program 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 3 of the License, or - (at your option) any later version. - - This program 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 this program. If not, see . */ - - -#include - -#include "message.h" -#include "xg-arglist-context.h" - - -#ifdef __cplusplus -extern "C" { -#endif - - -#define EXTENSIONS_CSHARP \ - { "cs", "C#" }, \ - -#define SCANNERS_CSHARP \ - { "C#", extract_csharp, \ - &flag_table_csharp, &formatstring_csharp, NULL }, \ - -extern void extract_csharp (FILE *fp, const char *real_filename, - const char *logical_filename, - flag_context_list_table_ty *flag_table, - msgdomain_list_ty *mdlp); - -extern void x_csharp_keyword (const char *keyword); -extern void x_csharp_extract_all (void); - -extern void init_flag_table_csharp (void); - - -#ifdef __cplusplus -} -#endif diff --git a/gettext-tools/src/x-java.c b/gettext-tools/src/x-java.c deleted file mode 100644 index 64a7f2b64..000000000 --- a/gettext-tools/src/x-java.c +++ /dev/null @@ -1,1717 +0,0 @@ -/* xgettext Java backend. - Copyright (C) 2003, 2005-2009, 2018-2019 Free Software Foundation, Inc. - Written by Bruno Haible , 2003. - - This program 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 3 of the License, or - (at your option) any later version. - - This program 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 this program. If not, see . */ - -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif - -/* Specification. */ -#include "x-java.h" - -#include -#include -#include -#include -#include - -#include "message.h" -#include "rc-str-list.h" -#include "xgettext.h" -#include "xg-pos.h" -#include "xg-encoding.h" -#include "xg-mixed-string.h" -#include "xg-arglist-context.h" -#include "xg-arglist-callshape.h" -#include "xg-arglist-parser.h" -#include "xg-message.h" -#include "error.h" -#include "error-progname.h" -#include "xalloc.h" -#include "hash.h" -#include "po-charset.h" -#include "unistr.h" -#include "unictype.h" -#include "gettext.h" - -#define _(s) gettext(s) - -#define SIZEOF(a) (sizeof(a) / sizeof(a[0])) - - -/* The Java syntax is defined in the - Java Language Specification - (available from https://docs.oracle.com/javase/specs/), - chapter 3 "Lexical Structure". */ - - -/* ====================== Keyword set customization. ====================== */ - -/* If true extract all strings. */ -static bool extract_all = false; - -static hash_table keywords; -static bool default_keywords = true; - - -void -x_java_extract_all () -{ - extract_all = true; -} - - -void -x_java_keyword (const char *name) -{ - if (name == NULL) - default_keywords = false; - else - { - const char *end; - struct callshape shape; - const char *colon; - - if (keywords.table == NULL) - hash_init (&keywords, 100); - - split_keywordspec (name, &end, &shape); - - /* The characters between name and end should form a valid Java - identifier sequence with dots. - A colon means an invalid parse in split_keywordspec(). */ - colon = strchr (name, ':'); - if (colon == NULL || colon >= end) - insert_keyword_callshape (&keywords, name, end - name, &shape); - } -} - -/* Finish initializing the keywords hash table. - Called after argument processing, before each file is processed. */ -static void -init_keywords () -{ - if (default_keywords) - { - /* When adding new keywords here, also update the documentation in - xgettext.texi! */ - x_java_keyword ("GettextResource.gettext:2"); /* static method */ - x_java_keyword ("GettextResource.ngettext:2,3"); /* static method */ - x_java_keyword ("GettextResource.pgettext:2c,3"); /* static method */ - x_java_keyword ("GettextResource.npgettext:2c,3,4"); /* static method */ - x_java_keyword ("gettext"); - x_java_keyword ("ngettext:1,2"); - x_java_keyword ("pgettext:1c,2"); - x_java_keyword ("npgettext:1c,2,3"); - x_java_keyword ("getString"); /* ResourceBundle.getString */ - default_keywords = false; - } -} - -void -init_flag_table_java () -{ - xgettext_record_flag ("GettextResource.gettext:2:pass-java-format"); - xgettext_record_flag ("GettextResource.gettext:2:pass-java-printf-format"); - xgettext_record_flag ("GettextResource.ngettext:2:pass-java-format"); - xgettext_record_flag ("GettextResource.ngettext:2:pass-java-printf-format"); - xgettext_record_flag ("GettextResource.ngettext:3:pass-java-format"); - xgettext_record_flag ("GettextResource.ngettext:3:pass-java-printf-format"); - xgettext_record_flag ("GettextResource.pgettext:3:pass-java-format"); - xgettext_record_flag ("GettextResource.pgettext:3:pass-java-printf-format"); - xgettext_record_flag ("GettextResource.npgettext:3:pass-java-format"); - xgettext_record_flag ("GettextResource.npgettext:3:pass-java-printf-format"); - xgettext_record_flag ("GettextResource.npgettext:4:pass-java-format"); - xgettext_record_flag ("GettextResource.npgettext:4:pass-java-printf-format"); - xgettext_record_flag ("gettext:1:pass-java-format"); - xgettext_record_flag ("gettext:1:pass-java-printf-format"); - xgettext_record_flag ("ngettext:1:pass-java-format"); - xgettext_record_flag ("ngettext:1:pass-java-printf-format"); - xgettext_record_flag ("ngettext:2:pass-java-format"); - xgettext_record_flag ("ngettext:2:pass-java-printf-format"); - xgettext_record_flag ("pgettext:2:pass-java-format"); - xgettext_record_flag ("pgettext:2:pass-java-printf-format"); - xgettext_record_flag ("npgettext:2:pass-java-format"); - xgettext_record_flag ("npgettext:2:pass-java-printf-format"); - xgettext_record_flag ("npgettext:3:pass-java-format"); - xgettext_record_flag ("npgettext:3:pass-java-printf-format"); - xgettext_record_flag ("getString:1:pass-java-format"); - xgettext_record_flag ("getString:1:pass-java-printf-format"); - xgettext_record_flag ("MessageFormat:1:java-format"); - xgettext_record_flag ("MessageFormat.format:1:java-format"); - xgettext_record_flag ("String.format:1:java-printf-format"); - xgettext_record_flag ("printf:1:java-printf-format"); /* PrintStream.printf */ -} - - -/* ======================== Reading of characters. ======================== */ - -/* The input file stream. */ -static FILE *fp; - - -/* Fetch the next single-byte character from the input file. - Pushback can consist of an unlimited number of 'u' followed by up to 4 - other characters. */ - -/* Special coding of multiple 'u's in the pushback buffer. */ -#define MULTIPLE_U(count) (0x1000 + (count)) - -static int phase1_pushback[5]; -static unsigned int phase1_pushback_length; - -static int -phase1_getc () -{ - int c; - - if (phase1_pushback_length) - { - c = phase1_pushback[--phase1_pushback_length]; - if (c >= MULTIPLE_U (0)) - { - if (c > MULTIPLE_U (1)) - phase1_pushback[phase1_pushback_length++] = c - 1; - return 'u'; - } - else - return c; - } - - c = getc (fp); - - if (c == EOF) - { - if (ferror (fp)) - error (EXIT_FAILURE, errno, - _("error while reading \"%s\""), real_file_name); - } - - return c; -} - -/* Supports any number of 'u' and up to 4 arbitrary characters of pushback. */ -static void -phase1_ungetc (int c) -{ - if (c != EOF) - { - if (c == 'u') - { - if (phase1_pushback_length > 0 - && phase1_pushback[phase1_pushback_length - 1] >= MULTIPLE_U (0)) - phase1_pushback[phase1_pushback_length - 1]++; - else - { - if (phase1_pushback_length == SIZEOF (phase1_pushback)) - abort (); - phase1_pushback[phase1_pushback_length++] = MULTIPLE_U (1); - } - } - else - { - if (phase1_pushback_length == SIZEOF (phase1_pushback)) - abort (); - phase1_pushback[phase1_pushback_length++] = c; - } - } -} - - -/* Fetch the next single-byte character or Unicode character from the file. - (Here, as in the Java Language Specification, when we say "Unicode - character", we actually mean "UTF-16 encoding unit".) */ - -/* Return value of phase 2, 3, 4 when EOF is reached. */ -#define P2_EOF 0xffff - -/* Convert an UTF-16 code point to a return value that can be distinguished - from a single-byte return value. */ -#define UNICODE(code) (0x10000 + (code)) - -/* Test a return value of phase 2, 3, 4 whether it designates an UTF-16 code - point. */ -#define IS_UNICODE(p2_result) ((p2_result) >= 0x10000) - -/* Extract the UTF-16 code of a return value that satisfies IS_UNICODE. */ -#define UTF16_VALUE(p2_result) ((p2_result) - 0x10000) - -/* Reduces a return value of phase 2, 3, 4 by unmasking the UNICODE bit, - so that it can be more easily compared against an ASCII character. - (RED (c) == 'x') is equivalent to (c == 'x' || c == UNICODE ('x')). */ -#define RED(p2_result) ((p2_result) & 0xffff) - -static int phase2_pushback[1]; -static int phase2_pushback_length; - -static int -phase2_getc () -{ - int c; - - if (phase2_pushback_length) - return phase2_pushback[--phase2_pushback_length]; - - c = phase1_getc (); - if (c == EOF) - return P2_EOF; - if (c == '\\') - { - c = phase1_getc (); - if (c == 'u') - { - unsigned int u_count = 1; - unsigned char buf[4]; - unsigned int n; - int i; - - for (;;) - { - c = phase1_getc (); - if (c != 'u') - break; - u_count++; - } - phase1_ungetc (c); - - n = 0; - for (i = 0; i < 4; i++) - { - c = phase1_getc (); - - if (c >= '0' && c <= '9') - n = (n << 4) + (c - '0'); - else if (c >= 'A' && c <= 'F') - n = (n << 4) + (c - 'A' + 10); - else if (c >= 'a' && c <= 'f') - n = (n << 4) + (c - 'a' + 10); - else - { - phase1_ungetc (c); - while (--i >= 0) - phase1_ungetc (buf[i]); - for (; u_count > 0; u_count--) - phase1_ungetc ('u'); - return '\\'; - } - - buf[i] = c; - } - return UNICODE (n); - } - phase1_ungetc (c); - return '\\'; - } - return c; -} - -/* Supports only one pushback character. */ -static void -phase2_ungetc (int c) -{ - if (c != P2_EOF) - { - if (phase2_pushback_length == SIZEOF (phase2_pushback)) - abort (); - phase2_pushback[phase2_pushback_length++] = c; - } -} - - -/* Fetch the next single-byte character or Unicode character from the file. - With line number handling. - Convert line terminators to '\n' or UNICODE ('\n'). */ - -static int phase3_pushback[2]; -static int phase3_pushback_length; - -static int -phase3_getc () -{ - int c; - - if (phase3_pushback_length) - { - c = phase3_pushback[--phase3_pushback_length]; - if (c == '\n') - ++line_number; - return c; - } - - c = phase2_getc (); - - /* Handle line terminators. */ - if (RED (c) == '\r') - { - int c1 = phase2_getc (); - - if (RED (c1) != '\n') - phase2_ungetc (c1); - - /* Seen line terminator CR or CR/LF. */ - if (c == '\r' || c1 == '\n') - { - ++line_number; - return '\n'; - } - else - return UNICODE ('\n'); - } - else if (RED (c) == '\n') - { - /* Seen line terminator LF. */ - if (c == '\n') - { - ++line_number; - return '\n'; - } - else - return UNICODE ('\n'); - } - - return c; -} - -/* Supports 2 characters of pushback. */ -static void -phase3_ungetc (int c) -{ - if (c != P2_EOF) - { - if (c == '\n') - --line_number; - if (phase3_pushback_length == SIZEOF (phase3_pushback)) - abort (); - phase3_pushback[phase3_pushback_length++] = c; - } -} - - -/* ========================= Accumulating strings. ======================== */ - -/* See xg-mixed-string.h for the main API. */ - -/* Append a character or Unicode character to a 'struct mixed_string_buffer'. */ -static void -mixed_string_buffer_append (struct mixed_string_buffer *bp, int c) -{ - if (IS_UNICODE (c)) - { - /* Append a Unicode character. */ - mixed_string_buffer_append_unicode (bp, UTF16_VALUE (c)); - } - else - { - /* Append a single byte. */ - mixed_string_buffer_append_char (bp, (unsigned char) c); - } -} - - -/* ======================== Accumulating comments. ======================== */ - - -/* Accumulating a single comment line. */ - -static struct mixed_string_buffer comment_buffer; - -static inline void -comment_start () -{ - mixed_string_buffer_init (&comment_buffer, lc_comment, - logical_file_name, line_number); -} - -static inline bool -comment_at_start () -{ - return mixed_string_buffer_is_empty (&comment_buffer); -} - -static inline void -comment_add (int c) -{ - mixed_string_buffer_append (&comment_buffer, c); -} - -static inline void -comment_line_end (size_t chars_to_remove) -{ - char *buffer = - mixed_string_contents_free1 (mixed_string_buffer_result (&comment_buffer)); - size_t buflen = strlen (buffer); - - buflen -= chars_to_remove; - while (buflen >= 1 - && (buffer[buflen - 1] == ' ' || buffer[buflen - 1] == '\t')) - --buflen; - buffer[buflen] = '\0'; - savable_comment_add (buffer); -} - - -/* These are for tracking whether comments count as immediately before - keyword. */ -static int last_comment_line; -static int last_non_comment_line; - - -/* Replace each comment that is not inside a character constant or string - literal with a space or newline character. */ - -static int -phase4_getc () -{ - int c0; - int c; - bool last_was_star; - - c0 = phase3_getc (); - if (RED (c0) != '/') - return c0; - c = phase3_getc (); - switch (RED (c)) - { - default: - phase3_ungetc (c); - return c0; - - case '*': - /* C style comment. */ - comment_start (); - last_was_star = false; - for (;;) - { - c = phase3_getc (); - if (c == P2_EOF) - break; - /* We skip all leading white space, but not EOLs. */ - if (!(comment_at_start () && (RED (c) == ' ' || RED (c) == '\t'))) - comment_add (c); - switch (RED (c)) - { - case '\n': - comment_line_end (1); - comment_start (); - last_was_star = false; - continue; - - case '*': - last_was_star = true; - continue; - - case '/': - if (last_was_star) - { - comment_line_end (2); - break; - } - /* FALLTHROUGH */ - - default: - last_was_star = false; - continue; - } - break; - } - last_comment_line = line_number; - return ' '; - - case '/': - /* C++ style comment. */ - last_comment_line = line_number; - comment_start (); - for (;;) - { - c = phase3_getc (); - if (RED (c) == '\n' || c == P2_EOF) - break; - /* We skip all leading white space, but not EOLs. */ - if (!(comment_at_start () && (RED (c) == ' ' || RED (c) == '\t'))) - comment_add (c); - } - phase3_ungetc (c); /* push back the newline, to decrement line_number */ - comment_line_end (0); - phase3_getc (); /* read the newline again */ - return '\n'; - } -} - -/* Supports only one pushback character. */ -static void -phase4_ungetc (int c) -{ - phase3_ungetc (c); -} - - -/* ========================== Reading of tokens. ========================== */ - -enum token_type_ty -{ - token_type_eof, - token_type_lparen, /* ( */ - token_type_rparen, /* ) */ - token_type_lbrace, /* { */ - token_type_rbrace, /* } */ - token_type_comma, /* , */ - token_type_dot, /* . */ - token_type_string_literal, /* "abc", """text block""" */ - token_type_number, /* 1.23 */ - token_type_symbol, /* identifier, keyword, null */ - token_type_plus, /* + */ - token_type_other /* character literal, misc. operator */ -}; -typedef enum token_type_ty token_type_ty; - -typedef struct token_ty token_ty; -struct token_ty -{ - token_type_ty type; - char *string; /* for token_type_symbol */ - mixed_string_ty *mixed_string; /* for token_type_string_literal */ - refcounted_string_list_ty *comment; /* for token_type_string_literal */ - int line_number; -}; - - -/* Free the memory pointed to by a 'struct token_ty'. */ -static inline void -free_token (token_ty *tp) -{ - if (tp->type == token_type_symbol) - free (tp->string); - if (tp->type == token_type_string_literal) - { - free (tp->mixed_string); - drop_reference (tp->comment); - } -} - - -/* Read an escape sequence inside a string literal or character literal. */ -static inline int -do_getc_escaped () -{ - int c; - - /* Use phase 3, because phase 4 elides comments. */ - c = phase3_getc (); - if (c == P2_EOF) - return UNICODE ('\\'); - switch (RED (c)) - { - case 'b': - return UNICODE (0x08); - case 't': - return UNICODE (0x09); - case 'n': - return UNICODE (0x0a); - case 'f': - return UNICODE (0x0c); - case 'r': - return UNICODE (0x0d); - case '"': - return UNICODE ('"'); - case '\'': - return UNICODE ('\''); - case '\\': - return UNICODE ('\\'); - case '0': case '1': case '2': case '3': - case '4': case '5': case '6': case '7': - { - int n = RED (c) - '0'; - bool maybe3digits = (n < 4); - - c = phase3_getc (); - if (RED (c) >= '0' && RED (c) <= '7') - { - n = (n << 3) + (RED (c) - '0'); - if (maybe3digits) - { - c = phase3_getc (); - if (RED (c) >= '0' && RED (c) <= '7') - n = (n << 3) + (RED (c) - '0'); - else - phase3_ungetc (c); - } - } - else - phase3_ungetc (c); - - return UNICODE (n); - } - default: - /* Invalid escape sequence. */ - phase3_ungetc (c); - return UNICODE ('\\'); - } -} - -/* Read a string literal or character literal. */ -static void -accumulate_escaped (struct mixed_string_buffer *literal, int delimiter) -{ - int c; - - for (;;) - { - /* Use phase 3, because phase 4 elides comments. */ - c = phase3_getc (); - if (c == P2_EOF || RED (c) == delimiter) - break; - if (RED (c) == '\n') - { - phase3_ungetc (c); - error_with_progname = false; - if (delimiter == '\'') - error (0, 0, _("%s:%d: warning: unterminated character constant"), - logical_file_name, line_number); - else - error (0, 0, _("%s:%d: warning: unterminated string constant"), - logical_file_name, line_number); - error_with_progname = true; - break; - } - if (RED (c) == '\\') - c = do_getc_escaped (); - mixed_string_buffer_append (literal, c); - } -} - - -/* Strip the common indentation of the non-blank lines of the given string and - remove all trailing whitespace of all lines. - Like the Java method String.stripIndent does. - */ -static void -strip_indent (mixed_string_ty *ms) -{ - size_t nsegments = ms->nsegments; - size_t minimum_indentation = SIZE_MAX; - { - size_t curr_line_indentation = 0; - bool curr_line_blank = true; - size_t i; - - for (i = 0; i < nsegments; i++) - { - struct mixed_string_segment *segment = ms->segments[i]; - - if (segment->type == utf8_encoded - || (segment->type == source_encoded - && xgettext_current_source_encoding == po_charset_utf8)) - { - /* Consider Unicode whitespace characters. */ - size_t seglength = segment->length; - size_t j; - - for (j = 0; j < seglength; ) - { - ucs4_t uc; - int bytes = - u8_mbtouc (&uc, (const uint8_t *) &segment->contents[j], - seglength - j); - j += bytes; - if (uc == 0x000a) - { - /* Newline. */ - if (!curr_line_blank) - if (minimum_indentation > curr_line_indentation) - minimum_indentation = curr_line_indentation; - curr_line_indentation = 0; - curr_line_blank = true; - } - else if (uc_is_java_whitespace (uc)) - { - /* Whitespace character. */ - if (curr_line_blank) - /* Every whitespace character counts as 1, even the TAB - character. */ - curr_line_indentation++; - } - else - { - /* Other character. */ - curr_line_blank = false; - } - } - } - else - { - /* When the encoding is not UTF-8, consider only ASCII whitespace - characters. */ - size_t seglength = segment->length; - size_t j; - - for (j = 0; j < seglength; j++) - { - char c = segment->contents[j]; - if (c == '\n') - { - /* Newline. */ - if (!curr_line_blank) - if (minimum_indentation > curr_line_indentation) - minimum_indentation = curr_line_indentation; - curr_line_indentation = 0; - curr_line_blank = true; - } - else if (c == ' ' - || (c >= 0x09 && c <= 0x0d) - || (c >= 0x1c && c <= 0x1f)) - { - /* Whitespace character. */ - if (curr_line_blank) - /* Every whitespace character counts as 1, even the TAB - character. */ - curr_line_indentation++; - } - else - { - /* Other character. */ - curr_line_blank = false; - } - } - } - } - /* The indentation of the last line matters even if is blank. */ - if (minimum_indentation > curr_line_indentation) - minimum_indentation = curr_line_indentation; - } - - /* The same loop as above, but this time remove the leading - minimum_indentation whitespace characters and all trailing whitespace - characters from every line. */ - { - size_t start_of_curr_line_i = 0; - size_t start_of_curr_line_j = 0; - size_t start_of_trailing_whitespace_i = 0; - size_t start_of_trailing_whitespace_j = 0; - size_t whitespace_to_remove = minimum_indentation; - size_t i; - - for (i = 0; i < nsegments; i++) - { - struct mixed_string_segment *segment = ms->segments[i]; - /* Perform a sliding copy from segment->contents[from_j] to - segment->contents[to_j]. 0 <= to_j <= from_j. */ - size_t to_j; - - if (segment->type == utf8_encoded - || (segment->type == source_encoded - && xgettext_current_source_encoding == po_charset_utf8)) - { - /* Consider Unicode whitespace characters. */ - size_t seglength = segment->length; - size_t from_j; - - for (to_j = from_j = 0; from_j < seglength; ) - { - ucs4_t uc; - int bytes = - u8_mbtouc (&uc, (const uint8_t *) &segment->contents[from_j], - seglength - from_j); - if (uc == 0x000a) - { - /* Newline. */ - if (whitespace_to_remove > 0) - { - /* It was a blank line with fewer than minimum_indentation - whitespace characters. Remove all this whitespace. */ - if (start_of_curr_line_i < i) - { - size_t k; - ms->segments[start_of_curr_line_i]->length = start_of_curr_line_j; - for (k = start_of_curr_line_i + 1; k < i; k++) - ms->segments[k]->length = 0; - to_j = 0; - } - else - to_j = start_of_curr_line_j; - } - else - { - /* Remove the trailing whitespace characters from the - current line. */ - if (start_of_trailing_whitespace_i < i) - { - size_t k; - ms->segments[start_of_trailing_whitespace_i]->length = start_of_trailing_whitespace_j; - for (k = start_of_trailing_whitespace_i + 1; k < i; k++) - ms->segments[k]->length = 0; - to_j = 0; - } - else - to_j = start_of_trailing_whitespace_j; - } - } - if (to_j < from_j) - memmove (&segment->contents[to_j], &segment->contents[from_j], bytes); - from_j += bytes; - to_j += bytes; - if (uc == 0x000a) - { - /* Newline. */ - start_of_curr_line_i = i; - start_of_curr_line_j = to_j; - start_of_trailing_whitespace_i = i; - start_of_trailing_whitespace_j = to_j; - whitespace_to_remove = minimum_indentation; - } - else if (uc_is_java_whitespace (uc)) - { - /* Whitespace character. */ - if (whitespace_to_remove > 0 - && --whitespace_to_remove == 0) - { - /* Remove the leading minimum_indentation whitespace - characters from the current line. */ - if (start_of_curr_line_i < i) - { - size_t k; - ms->segments[start_of_curr_line_i]->length = start_of_curr_line_j; - for (k = start_of_curr_line_i + 1; k < i; k++) - ms->segments[k]->length = 0; - to_j = 0; - } - else - to_j = start_of_curr_line_j; - } - } - else - { - /* Other character. */ - if (whitespace_to_remove > 0) - abort (); - start_of_trailing_whitespace_i = i; - start_of_trailing_whitespace_j = to_j; - } - } - } - else - { - /* When the encoding is not UTF-8, consider only ASCII whitespace - characters. */ - size_t seglength = segment->length; - size_t from_j; - - for (to_j = from_j = 0; from_j < seglength; ) - { - char c = segment->contents[from_j++]; - if (c == '\n') - { - /* Newline. */ - if (whitespace_to_remove > 0) - { - /* It was a blank line with fewer than minimum_indentation - whitespace characters. Remove all this whitespace. */ - if (start_of_curr_line_i < i) - { - size_t k; - ms->segments[start_of_curr_line_i]->length = start_of_curr_line_j; - for (k = start_of_curr_line_i + 1; k < i; k++) - ms->segments[k]->length = 0; - to_j = 0; - } - else - to_j = start_of_curr_line_j; - } - else - { - /* Remove the trailing whitespace characters from the - current line. */ - if (start_of_trailing_whitespace_i < i) - { - size_t k; - ms->segments[start_of_trailing_whitespace_i]->length = start_of_trailing_whitespace_j; - for (k = start_of_trailing_whitespace_i + 1; k < i; k++) - ms->segments[k]->length = 0; - to_j = 0; - } - else - to_j = start_of_trailing_whitespace_j; - } - } - segment->contents[to_j++] = c; - if (c == '\n') - { - /* Newline. */ - start_of_curr_line_i = i; - start_of_curr_line_j = to_j; - start_of_trailing_whitespace_i = i; - start_of_trailing_whitespace_j = to_j; - whitespace_to_remove = minimum_indentation; - } - else if (c == ' ' - || (c >= 0x09 && c <= 0x0d) - || (c >= 0x1c && c <= 0x1f)) - { - /* Whitespace character. */ - if (whitespace_to_remove > 0 - && --whitespace_to_remove == 0) - { - /* Remove the leading minimum_indentation whitespace - characters from the current line. */ - if (start_of_curr_line_i < i) - { - size_t k; - ms->segments[start_of_curr_line_i]->length = start_of_curr_line_j; - for (k = start_of_curr_line_i + 1; k < i; k++) - ms->segments[k]->length = 0; - to_j = 0; - } - else - to_j = start_of_curr_line_j; - } - } - else - { - /* Other character. */ - if (whitespace_to_remove > 0) - abort (); - start_of_trailing_whitespace_i = i; - start_of_trailing_whitespace_j = to_j; - } - } - } - if (i + 1 == nsegments) - { - /* Handle the last line. */ - if (whitespace_to_remove > 0) - { - /* It was a blank line with fewer than minimum_indentation - whitespace characters. Remove all this whitespace. */ - if (start_of_curr_line_i < i) - { - size_t k; - ms->segments[start_of_curr_line_i]->length = start_of_curr_line_j; - for (k = start_of_curr_line_i + 1; k < i; k++) - ms->segments[k]->length = 0; - to_j = 0; - } - else - to_j = start_of_curr_line_j; - } - else - { - /* Remove the trailing whitespace characters from the - current line. */ - if (start_of_trailing_whitespace_i < i) - { - size_t k; - ms->segments[start_of_trailing_whitespace_i]->length = start_of_trailing_whitespace_j; - for (k = start_of_trailing_whitespace_i + 1; k < i; k++) - ms->segments[k]->length = 0; - to_j = 0; - } - else - to_j = start_of_trailing_whitespace_j; - } - } - segment->length = to_j; - } - } -} - - -/* Combine characters into tokens. Discard whitespace. */ - -static token_ty phase5_pushback[3]; -static int phase5_pushback_length; - -static void -phase5_get (token_ty *tp) -{ - int c; - - if (phase5_pushback_length) - { - *tp = phase5_pushback[--phase5_pushback_length]; - return; - } - tp->string = NULL; - - for (;;) - { - tp->line_number = line_number; - c = phase4_getc (); - - if (c == P2_EOF) - { - tp->type = token_type_eof; - return; - } - - switch (RED (c)) - { - case '\n': - if (last_non_comment_line > last_comment_line) - savable_comment_reset (); - /* FALLTHROUGH */ - case ' ': - case '\t': - case '\f': - /* Ignore whitespace and comments. */ - continue; - } - - last_non_comment_line = tp->line_number; - - switch (RED (c)) - { - case '(': - tp->type = token_type_lparen; - return; - - case ')': - tp->type = token_type_rparen; - return; - - case '{': - tp->type = token_type_lbrace; - return; - - case '}': - tp->type = token_type_rbrace; - return; - - case ',': - tp->type = token_type_comma; - return; - - case '.': - c = phase4_getc (); - if (!(RED (c) >= '0' && RED (c) <= '9')) - { - phase4_ungetc (c); - tp->type = token_type_dot; - return; - } - /* FALLTHROUGH */ - - case '0': case '1': case '2': case '3': case '4': - case '5': case '6': case '7': case '8': case '9': - { - /* Don't need to verify the complicated syntax of integers and - floating-point numbers. We assume a valid Java input. - The simplified syntax that we recognize as number is: any - sequence of alphanumeric characters, additionally '+' and '-' - immediately after 'e' or 'E' except in hexadecimal numbers. */ - bool hexadecimal = false; - - for (;;) - { - c = phase4_getc (); - if (RED (c) >= '0' && RED (c) <= '9') - continue; - if ((RED (c) >= 'A' && RED (c) <= 'Z') - || (RED (c) >= 'a' && RED (c) <= 'z')) - { - if (RED (c) == 'X' || RED (c) == 'x') - hexadecimal = true; - if ((RED (c) == 'E' || RED (c) == 'e') && !hexadecimal) - { - c = phase4_getc (); - if (!(RED (c) == '+' || RED (c) == '-')) - phase4_ungetc (c); - } - continue; - } - if (RED (c) == '.') - continue; - break; - } - phase4_ungetc (c); - tp->type = token_type_number; - return; - } - - case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'G': - case 'H': case 'I': case 'J': case 'K': case 'L': case 'M': case 'N': - case 'O': case 'P': case 'Q': case 'R': case 'S': case 'T': case 'U': - case 'V': case 'W': case 'X': case 'Y': case 'Z': - case '_': - case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g': - case 'h': case 'i': case 'j': case 'k': case 'l': case 'm': case 'n': - case 'o': case 'p': case 'q': case 'r': case 's': case 't': case 'u': - case 'v': case 'w': case 'x': case 'y': case 'z': - /* Although Java allows identifiers containing many Unicode - characters, we recognize only identifiers consisting of ASCII - characters. This avoids conversion hassles w.r.t. the --keyword - arguments, and shouldn't be a big problem in practice. */ - { - static char *buffer; - static int bufmax; - int bufpos = 0; - for (;;) - { - if (bufpos >= bufmax) - { - bufmax = 2 * bufmax + 10; - buffer = xrealloc (buffer, bufmax); - } - buffer[bufpos++] = RED (c); - c = phase4_getc (); - if (!((RED (c) >= 'A' && RED (c) <= 'Z') - || (RED (c) >= 'a' && RED (c) <= 'z') - || (RED (c) >= '0' && RED (c) <= '9') - || RED (c) == '_')) - break; - } - phase4_ungetc (c); - if (bufpos >= bufmax) - { - bufmax = 2 * bufmax + 10; - buffer = xrealloc (buffer, bufmax); - } - buffer[bufpos] = '\0'; - tp->string = xstrdup (buffer); - tp->type = token_type_symbol; - return; - } - - case '"': - { - int c2 = phase3_getc (); - if (c2 == '"') - { - int c3 = phase3_getc (); - if (c3 == '"') - { - /* Text block. Specification: - */ - struct mixed_string_buffer block; - unsigned int consecutive_unescaped_doublequotes; - mixed_string_ty *block_content; - - /* Parse the part up to and including the first newline. */ - for (;;) - { - int ic = phase3_getc (); - if (ic == P2_EOF) - { - error_with_progname = false; - error (0, 0, _("%s:%d: warning: unterminated text block"), - logical_file_name, line_number); - error_with_progname = true; - tp->type = token_type_other; - return; - } - if (RED (ic) == ' ' || RED (ic) == '\t' || RED (ic) == '\f') - ; - else if (RED (ic) == '\n') - break; - else - { - error_with_progname = false; - error (0, 0, _("%s:%d: warning: invalid syntax in text block"), - logical_file_name, line_number); - error_with_progname = true; - tp->type = token_type_other; - return; - } - } - - /* Parse the part after the first newline. */ - mixed_string_buffer_init (&block, lc_string, - logical_file_name, line_number); - consecutive_unescaped_doublequotes = 0; - for (;;) - { - int ic = phase3_getc (); - if (RED (ic) == '"') - { - consecutive_unescaped_doublequotes++; - if (consecutive_unescaped_doublequotes == 3) - break; - } - else - { - while (consecutive_unescaped_doublequotes > 0) - { - mixed_string_buffer_append (&block, '"'); - consecutive_unescaped_doublequotes--; - } - if (ic == P2_EOF) - { - error_with_progname = false; - error (0, 0, _("%s:%d: warning: unterminated text block"), - logical_file_name, block.line_number); - error_with_progname = true; - break; - } - if (RED (ic) == '\\') - ic = do_getc_escaped (); - mixed_string_buffer_append (&block, ic); - } - } - block_content = mixed_string_buffer_result (&block); - - /* Remove the common indentation from the content. */ - strip_indent (block_content); - - tp->mixed_string = block_content; - tp->comment = add_reference (savable_comment); - tp->type = token_type_string_literal; - return; - } - phase3_ungetc (c3); - } - phase3_ungetc (c2); - } - /* String literal. */ - { - struct mixed_string_buffer literal; - - mixed_string_buffer_init (&literal, lc_string, - logical_file_name, line_number); - accumulate_escaped (&literal, '"'); - tp->mixed_string = mixed_string_buffer_result (&literal); - tp->comment = add_reference (savable_comment); - tp->type = token_type_string_literal; - return; - } - - case '\'': - /* Character literal. */ - { - struct mixed_string_buffer literal; - - mixed_string_buffer_init (&literal, lc_outside, - logical_file_name, line_number); - accumulate_escaped (&literal, '\''); - mixed_string_buffer_destroy (&literal); - tp->type = token_type_other; - return; - } - - case '+': - c = phase4_getc (); - if (RED (c) == '+') - /* Operator ++ */ - tp->type = token_type_other; - else if (RED (c) == '=') - /* Operator += */ - tp->type = token_type_other; - else - { - /* Operator + */ - phase4_ungetc (c); - tp->type = token_type_plus; - } - return; - - default: - /* Misc. operator. */ - tp->type = token_type_other; - return; - } - } -} - -/* Supports 3 tokens of pushback. */ -static void -phase5_unget (token_ty *tp) -{ - if (tp->type != token_type_eof) - { - if (phase5_pushback_length == SIZEOF (phase5_pushback)) - abort (); - phase5_pushback[phase5_pushback_length++] = *tp; - } -} - - -/* Compile-time optimization of string literal concatenation. - Combine "string1" + ... + "stringN" to the concatenated string if - - the token before this expression is not ')' (because then the first - string could be part of a cast expression), - - the token after this expression is not '.' (because then the last - string could be part of a method call expression). */ - -static token_ty phase6_pushback[2]; -static int phase6_pushback_length; - -static token_type_ty phase6_last; - -static void -phase6_get (token_ty *tp) -{ - if (phase6_pushback_length) - { - *tp = phase6_pushback[--phase6_pushback_length]; - return; - } - - phase5_get (tp); - if (tp->type == token_type_string_literal && phase6_last != token_type_rparen) - { - mixed_string_ty *sum = tp->mixed_string; - - for (;;) - { - token_ty token2; - - phase5_get (&token2); - if (token2.type == token_type_plus) - { - token_ty token3; - - phase5_get (&token3); - if (token3.type == token_type_string_literal) - { - token_ty token_after; - - phase5_get (&token_after); - if (token_after.type != token_type_dot) - { - sum = mixed_string_concat_free1 (sum, token3.mixed_string); - - phase5_unget (&token_after); - free_token (&token3); - free_token (&token2); - continue; - } - phase5_unget (&token_after); - } - phase5_unget (&token3); - } - phase5_unget (&token2); - break; - } - tp->mixed_string = sum; - } - phase6_last = tp->type; -} - -/* Supports 2 tokens of pushback. */ -static void -phase6_unget (token_ty *tp) -{ - if (tp->type != token_type_eof) - { - if (phase6_pushback_length == SIZEOF (phase6_pushback)) - abort (); - phase6_pushback[phase6_pushback_length++] = *tp; - } -} - - -static void -x_java_lex (token_ty *tp) -{ - phase6_get (tp); -} - -/* Supports 2 tokens of pushback. */ -static void -x_java_unlex (token_ty *tp) -{ - phase6_unget (tp); -} - - -/* ========================= Extracting strings. ========================== */ - - -/* Context lookup table. */ -static flag_context_list_table_ty *flag_context_list_table; - - -/* The file is broken into tokens. Scan the token stream, looking for - a keyword, followed by a left paren, followed by a string. When we - see this sequence, we have something to remember. We assume we are - looking at a valid C or C++ program, and leave the complaints about - the grammar to the compiler. - - Normal handling: Look for - keyword ( ... msgid ... ) - Plural handling: Look for - keyword ( ... msgid ... msgid_plural ... ) - - We use recursion because the arguments before msgid or between msgid - and msgid_plural can contain subexpressions of the same form. */ - - -/* Extract messages until the next balanced closing parenthesis or brace, - depending on TERMINATOR. - Extracted messages are added to MLP. - Return true upon eof, false upon closing parenthesis or brace. */ -static bool -extract_parenthesized (message_list_ty *mlp, token_type_ty terminator, - flag_context_ty outer_context, - flag_context_list_iterator_ty context_iter, - struct arglist_parser *argparser) -{ - /* Current argument number. */ - int arg = 1; - /* 0 when no keyword has been seen. 1 right after a keyword is seen. */ - int state; - /* Parameters of the keyword just seen. Defined only in state 1. */ - const struct callshapes *next_shapes = NULL; - /* Context iterator that will be used if the next token is a '('. */ - flag_context_list_iterator_ty next_context_iter = - passthrough_context_list_iterator; - /* Current context. */ - flag_context_ty inner_context = - inherited_context (outer_context, - flag_context_list_iterator_advance (&context_iter)); - - /* Start state is 0. */ - state = 0; - - for (;;) - { - token_ty token; - - x_java_lex (&token); - switch (token.type) - { - case token_type_symbol: - { - /* Combine symbol1 . ... . symbolN to a single strings, so that - we can recognize static function calls like - GettextResource.gettext. The information present for - symbolI.....symbolN has precedence over the information for - symbolJ.....symbolN with J > I. */ - char *sum = token.string; - size_t sum_len = strlen (sum); - const char *dottedname; - flag_context_list_ty *context_list; - - for (;;) - { - token_ty token2; - - x_java_lex (&token2); - if (token2.type == token_type_dot) - { - token_ty token3; - - x_java_lex (&token3); - if (token3.type == token_type_symbol) - { - char *addend = token3.string; - size_t addend_len = strlen (addend); - - sum = - (char *) xrealloc (sum, sum_len + 1 + addend_len + 1); - sum[sum_len] = '.'; - memcpy (sum + sum_len + 1, addend, addend_len + 1); - sum_len += 1 + addend_len; - - free_token (&token3); - free_token (&token2); - continue; - } - x_java_unlex (&token3); - } - x_java_unlex (&token2); - break; - } - - for (dottedname = sum;;) - { - void *keyword_value; - - if (hash_find_entry (&keywords, dottedname, strlen (dottedname), - &keyword_value) - == 0) - { - next_shapes = (const struct callshapes *) keyword_value; - state = 1; - break; - } - - dottedname = strchr (dottedname, '.'); - if (dottedname == NULL) - { - state = 0; - break; - } - dottedname++; - } - - for (dottedname = sum;;) - { - context_list = - flag_context_list_table_lookup ( - flag_context_list_table, - dottedname, strlen (dottedname)); - if (context_list != NULL) - break; - - dottedname = strchr (dottedname, '.'); - if (dottedname == NULL) - break; - dottedname++; - } - next_context_iter = flag_context_list_iterator (context_list); - - free (sum); - continue; - } - - case token_type_lparen: - if (extract_parenthesized (mlp, token_type_rparen, - inner_context, next_context_iter, - arglist_parser_alloc (mlp, - state ? next_shapes : NULL))) - { - arglist_parser_done (argparser, arg); - return true; - } - next_context_iter = null_context_list_iterator; - state = 0; - continue; - - case token_type_rparen: - if (terminator == token_type_rparen) - { - arglist_parser_done (argparser, arg); - return false; - } - if (terminator == token_type_rbrace) - { - error_with_progname = false; - error (0, 0, - _("%s:%d: warning: ')' found where '}' was expected"), - logical_file_name, token.line_number); - error_with_progname = true; - } - next_context_iter = null_context_list_iterator; - state = 0; - continue; - - case token_type_lbrace: - if (extract_parenthesized (mlp, token_type_rbrace, - null_context, null_context_list_iterator, - arglist_parser_alloc (mlp, NULL))) - { - arglist_parser_done (argparser, arg); - return true; - } - next_context_iter = null_context_list_iterator; - state = 0; - continue; - - case token_type_rbrace: - if (terminator == token_type_rbrace) - { - arglist_parser_done (argparser, arg); - return false; - } - if (terminator == token_type_rparen) - { - error_with_progname = false; - error (0, 0, - _("%s:%d: warning: '}' found where ')' was expected"), - logical_file_name, token.line_number); - error_with_progname = true; - } - next_context_iter = null_context_list_iterator; - state = 0; - continue; - - case token_type_comma: - arg++; - inner_context = - inherited_context (outer_context, - flag_context_list_iterator_advance ( - &context_iter)); - next_context_iter = passthrough_context_list_iterator; - state = 0; - continue; - - case token_type_string_literal: - { - lex_pos_ty pos; - - pos.file_name = logical_file_name; - pos.line_number = token.line_number; - - if (extract_all) - { - char *string = mixed_string_contents (token.mixed_string); - mixed_string_free (token.mixed_string); - remember_a_message (mlp, NULL, string, true, false, - inner_context, &pos, - NULL, token.comment, true); - } - else - arglist_parser_remember (argparser, arg, token.mixed_string, - inner_context, - pos.file_name, pos.line_number, - token.comment, true); - } - drop_reference (token.comment); - next_context_iter = null_context_list_iterator; - state = 0; - continue; - - case token_type_eof: - arglist_parser_done (argparser, arg); - return true; - - case token_type_dot: - case token_type_number: - case token_type_plus: - case token_type_other: - next_context_iter = null_context_list_iterator; - state = 0; - continue; - - default: - abort (); - } - } -} - - -void -extract_java (FILE *f, - const char *real_filename, const char *logical_filename, - flag_context_list_table_ty *flag_table, - msgdomain_list_ty *mdlp) -{ - message_list_ty *mlp = mdlp->item[0]->messages; - - fp = f; - real_file_name = real_filename; - logical_file_name = xstrdup (logical_filename); - line_number = 1; - - last_comment_line = -1; - last_non_comment_line = -1; - - phase6_last = token_type_eof; - - flag_context_list_table = flag_table; - - init_keywords (); - - /* Eat tokens until eof is seen. When extract_parenthesized returns - due to an unbalanced closing parenthesis, just restart it. */ - while (!extract_parenthesized (mlp, token_type_eof, - null_context, null_context_list_iterator, - arglist_parser_alloc (mlp, NULL))) - ; - - fp = NULL; - real_file_name = NULL; - logical_file_name = NULL; - line_number = 0; -} diff --git a/gettext-tools/src/x-java.h b/gettext-tools/src/x-java.h deleted file mode 100644 index c46feeee4..000000000 --- a/gettext-tools/src/x-java.h +++ /dev/null @@ -1,51 +0,0 @@ -/* xgettext Java backend. - Copyright (C) 2001-2003, 2006, 2014, 2018-2019 Free Software Foundation, Inc. - Written by Tommy Johansson , 2001. - - This program 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 3 of the License, or - (at your option) any later version. - - This program 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 this program. If not, see . */ - - -#include - -#include "message.h" -#include "xg-arglist-context.h" - - -#ifdef __cplusplus -extern "C" { -#endif - - -#define EXTENSIONS_JAVA \ - { "java", "Java" }, \ - -#define SCANNERS_JAVA \ - { "Java", extract_java, \ - &flag_table_java, \ - &formatstring_java, &formatstring_java_printf }, \ - -extern void extract_java (FILE *fp, const char *real_filename, - const char *logical_filename, - flag_context_list_table_ty *flag_table, - msgdomain_list_ty *mdlp); - -extern void x_java_keyword (const char *keyword); -extern void x_java_extract_all (void); - -extern void init_flag_table_java (void); - - -#ifdef __cplusplus -} -#endif diff --git a/gettext-tools/src/x-properties.h b/gettext-tools/src/x-properties.h deleted file mode 100644 index 20d486fcf..000000000 --- a/gettext-tools/src/x-properties.h +++ /dev/null @@ -1,45 +0,0 @@ -/* xgettext JavaProperties backend. - Copyright (C) 2003, 2006, 2014, 2018 Free Software Foundation, Inc. - Written by Bruno Haible , 2003. - - This program 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 3 of the License, or - (at your option) any later version. - - This program 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 this program. If not, see . */ - - -#include - -#include "message.h" -#include "xg-arglist-context.h" - - -#ifdef __cplusplus -extern "C" { -#endif - - -#define EXTENSIONS_PROPERTIES \ - { "properties", "JavaProperties" }, \ - -#define SCANNERS_PROPERTIES \ - { "JavaProperties", extract_properties, NULL, NULL, NULL }, \ - -/* Scan a JavaProperties file and add its translatable strings to mdlp. */ -extern void extract_properties (FILE *fp, const char *real_filename, - const char *logical_filename, - flag_context_list_table_ty *flag_table, - msgdomain_list_ty *mdlp); - - -#ifdef __cplusplus -} -#endif diff --git a/gettext-tools/src/xgettext.c b/gettext-tools/src/xgettext.c index e2e4525de..35baa93b0 100644 --- a/gettext-tools/src/xgettext.c +++ b/gettext-tools/src/xgettext.c @@ -74,7 +74,6 @@ #include "po-time.h" #include "write-catalog.h" #include "write-po.h" -#include "write-properties.h" #include "write-stringtable.h" #include "format.h" #include "propername.h" @@ -97,9 +96,6 @@ #include "x-librep.h" #include "x-scheme.h" #include "x-smalltalk.h" -#include "x-java.h" -#include "x-properties.h" -#include "x-csharp.h" #include "x-appdata.h" #include "x-awk.h" #include "x-ycp.h" @@ -179,8 +175,6 @@ static flag_context_list_table_ty flag_table_lisp; static flag_context_list_table_ty flag_table_elisp; static flag_context_list_table_ty flag_table_librep; static flag_context_list_table_ty flag_table_scheme; -static flag_context_list_table_ty flag_table_java; -static flag_context_list_table_ty flag_table_csharp; static flag_context_list_table_ty flag_table_awk; static flag_context_list_table_ty flag_table_ycp; static flag_context_list_table_ty flag_table_tcl; @@ -358,8 +352,6 @@ main (int argc, char *argv[]) init_flag_table_elisp (); init_flag_table_librep (); init_flag_table_scheme (); - init_flag_table_java (); - init_flag_table_csharp (); init_flag_table_awk (); init_flag_table_ycp (); init_flag_table_tcl (); @@ -385,8 +377,6 @@ main (int argc, char *argv[]) x_elisp_extract_all (); x_librep_extract_all (); x_scheme_extract_all (); - x_java_extract_all (); - x_csharp_extract_all (); x_awk_extract_all (); x_tcl_extract_all (); x_perl_extract_all (); @@ -464,8 +454,6 @@ main (int argc, char *argv[]) x_elisp_keyword (optarg); x_librep_keyword (optarg); x_scheme_keyword (optarg); - x_java_keyword (optarg); - x_csharp_keyword (optarg); x_awk_keyword (optarg); x_tcl_keyword (optarg); x_perl_keyword (optarg); @@ -1063,8 +1051,8 @@ Choice of input file language:\n")); printf (_("\ -L, --language=NAME recognise the specified language\n\ (C, C++, ObjectiveC, PO, Shell, Python, Lisp,\n\ - EmacsLisp, librep, Scheme, Smalltalk, Java,\n\ - JavaProperties, C#, awk, YCP, Tcl, Perl, PHP,\n\ + EmacsLisp, librep, Scheme, Smalltalk, \n\ + awk, YCP, Tcl, Perl, PHP,\n\ GCC-source, NXStringTable, RST, RSJ, Glade,\n\ Lua, JavaScript, Vala, Desktop)\n")); printf (_("\ @@ -1106,7 +1094,7 @@ Language specific options:\n")); -a, --extract-all extract all strings\n")); printf (_("\ (only languages C, C++, ObjectiveC, Shell,\n\ - Python, Lisp, EmacsLisp, librep, Scheme, Java,\n\ + Python, Lisp, EmacsLisp, librep, Scheme, \n\ C#, awk, Tcl, Perl, PHP, GCC-source, Glade,\n\ Lua, JavaScript, Vala)\n")); printf (_("\ @@ -1114,7 +1102,7 @@ Language specific options:\n")); -k, --keyword do not to use default keywords\n")); printf (_("\ (only languages C, C++, ObjectiveC, Shell,\n\ - Python, Lisp, EmacsLisp, librep, Scheme, Java,\n\ + Python, Lisp, EmacsLisp, librep, Scheme, \n\ C#, awk, Tcl, Perl, PHP, GCC-source, Glade,\n\ Lua, JavaScript, Vala, Desktop)\n")); printf (_("\ @@ -1122,7 +1110,7 @@ Language specific options:\n")); number ARG of keyword WORD\n")); printf (_("\ (only languages C, C++, ObjectiveC, Shell,\n\ - Python, Lisp, EmacsLisp, librep, Scheme, Java,\n\ + Python, Lisp, EmacsLisp, librep, Scheme, \n\ C#, awk, YCP, Tcl, Perl, PHP, GCC-source,\n\ Lua, JavaScript, Vala)\n")); printf (_("\ @@ -1171,8 +1159,6 @@ Output details:\n")); printf (_("\ --strict write out strict Uniforum conforming .po file\n")); printf (_("\ - --properties-output write out a Java .properties file\n")); - printf (_("\ --stringtable-output write out a NeXTstep/GNUstep .strings file\n")); printf (_("\ --itstool write out itstool comments\n")); @@ -1500,21 +1486,6 @@ xgettext_record_flag (const char *optionstring) break; case format_smalltalk: break; - case format_java: - flag_context_list_table_insert (&flag_table_java, 0, - name_start, name_end, - argnum, value, pass); - break; - case format_java_printf: - flag_context_list_table_insert (&flag_table_java, 1, - name_start, name_end, - argnum, value, pass); - break; - case format_csharp: - flag_context_list_table_insert (&flag_table_csharp, 0, - name_start, name_end, - argnum, value, pass); - break; case format_awk: flag_context_list_table_insert (&flag_table_awk, 0, name_start, name_end, @@ -2038,9 +2009,6 @@ language_to_extractor (const char *name) SCANNERS_LIBREP SCANNERS_SCHEME SCANNERS_SMALLTALK - SCANNERS_JAVA - SCANNERS_PROPERTIES - SCANNERS_CSHARP SCANNERS_AWK SCANNERS_YCP SCANNERS_TCL @@ -2128,9 +2096,6 @@ extension_to_language (const char *extension) EXTENSIONS_LIBREP EXTENSIONS_SCHEME EXTENSIONS_SMALLTALK - EXTENSIONS_JAVA - EXTENSIONS_PROPERTIES - EXTENSIONS_CSHARP EXTENSIONS_AWK EXTENSIONS_YCP EXTENSIONS_TCL diff --git a/gettext-tools/tests/Makefile.am b/gettext-tools/tests/Makefile.am index b2bd779e4..168be49c6 100644 --- a/gettext-tools/tests/Makefile.am +++ b/gettext-tools/tests/Makefile.am @@ -69,8 +69,6 @@ TESTS = gettext-1 gettext-2 \ msgmerge-update-1 msgmerge-update-2 msgmerge-update-3 \ msgmerge-update-4 \ msgunfmt-1 msgunfmt-2 msgunfmt-3 \ - msgunfmt-csharp-1 \ - msgunfmt-java-1 \ msgunfmt-properties-1 \ msgunfmt-tcl-1 \ msguniq-1 msguniq-2 msguniq-3 msguniq-4 msguniq-5 msguniq-6 msguniq-7 \ @@ -88,14 +86,9 @@ TESTS = gettext-1 gettext-2 \ xgettext-c-format-4 xgettext-c-format-5 \ xgettext-c-ctxt-1 xgettext-c-ctxt-2 xgettext-c-ctxt-3 \ xgettext-c-c++-1 xgettext-c-c++-2 \ - xgettext-csharp-1 xgettext-csharp-2 xgettext-csharp-3 \ - xgettext-csharp-4 xgettext-csharp-5 xgettext-csharp-6 \ - xgettext-csharp-7 xgettext-csharp-8 \ xgettext-elisp-1 xgettext-elisp-2 \ xgettext-glade-1 xgettext-glade-2 xgettext-glade-3 xgettext-glade-4 \ xgettext-glade-5 xgettext-glade-6 xgettext-glade-7 \ - xgettext-java-1 xgettext-java-2 xgettext-java-3 xgettext-java-4 \ - xgettext-java-5 xgettext-java-6 xgettext-java-7 \ xgettext-librep-1 xgettext-librep-2 \ xgettext-lisp-1 xgettext-lisp-2 \ xgettext-objc-1 xgettext-objc-2 \ @@ -127,12 +120,9 @@ TESTS = gettext-1 gettext-2 \ format-awk-1 format-awk-2 \ format-boost-1 format-boost-2 \ format-c-1 format-c-2 format-c-3 format-c-4 format-c-5 \ - format-csharp-1 format-csharp-2 \ format-elisp-1 format-elisp-2 \ format-gcc-internal-1 format-gcc-internal-2 \ format-gfc-internal-1 format-gfc-internal-2 \ - format-java-1 format-java-2 \ - format-java-printf-1 format-java-printf-2 \ format-kde-1 format-kde-2 \ format-kde-kuit-1 format-kde-kuit-2 \ format-librep-1 format-librep-2 \ @@ -156,7 +146,7 @@ TESTS = gettext-1 gettext-2 \ gettextpo-1 sentence-1 \ lang-c lang-c++ lang-objc lang-sh lang-bash lang-python-1 \ lang-python-2 lang-clisp lang-elisp lang-librep lang-guile \ - lang-smalltalk lang-java lang-csharp lang-gawk lang-pascal \ + lang-smalltalk lang-gawk lang-pascal \ lang-ycp lang-tcl lang-perl-1 lang-perl-2 lang-php lang-po lang-rst \ lang-lua lang-javascript lang-vala \ autopoint-1 autopoint-2 autopoint-3 cldr-plurals-1 diff --git a/gettext-tools/tests/format-csharp-1 b/gettext-tools/tests/format-csharp-1 deleted file mode 100755 index 0bd4a2387..000000000 --- a/gettext-tools/tests/format-csharp-1 +++ /dev/null @@ -1,83 +0,0 @@ -#! /bin/sh -. "${srcdir=.}/init.sh"; path_prepend_ . ../src - -# Test recognition of C# format strings. - -cat <<\EOF > f-cs-1.data -# Valid: one argument -"abc{0}def" -# Valid: ten arguments -"abc{9}def" -# Valid: two-digit argument numbers -"abc{00}def" -# Valid: huge argument numbers -"abc{500000000}def" -# Invalid: unterminated -"abc{" -# Invalid: unterminated -"abc{0" -# Invalid: missing number -"abc{}def" -# Invalid: non-digit -"abc{number}def" -# Invalid: non-digit -"abc{-0}def" -# Valid: two arguments -"abc{1}def{0}" -# Valid: multiple uses of same argument -"abc{1}def{0}ghi{1}" -# Invalid: invalid width -"abc{0,}def" -# Invalid: invalid width -"abc{0,-}def" -# Valid: valid width -"abc{1,-7}def" -# Valid: format specifiers -"abc{1:Gx N}def" -# Valid: width and format specifiers -"abc{1,3:Gx N}def" -# Invalid: missing opening brace -"abc1}def{0}" -# Invalid: quoted brace -"abc1'}'def{0}" -# Valid: doubled brace -"abc1}}def{0}" -# Invalid: doubled brace doesn't start a directive -"abc{{0}def" -EOF - -: ${XGETTEXT=xgettext} -n=0 -while read comment; do - read string - n=`expr $n + 1` - cat < f-cs-1-$n.in -GetString(${string}); -EOF - ${XGETTEXT} -L C# -o f-cs-1-$n.po f-cs-1-$n.in || Exit 1 - test -f f-cs-1-$n.po || Exit 1 - fail= - if echo "$comment" | grep 'Valid:' > /dev/null; then - if grep csharp-format f-cs-1-$n.po > /dev/null; then - : - else - fail=yes - fi - else - if grep csharp-format f-cs-1-$n.po > /dev/null; then - fail=yes - else - : - fi - fi - if test -n "$fail"; then - echo "Format string recognition error:" 1>&2 - cat f-cs-1-$n.in 1>&2 - echo "Got:" 1>&2 - cat f-cs-1-$n.po 1>&2 - Exit 1 - fi - rm -f f-cs-1-$n.in f-cs-1-$n.po -done < f-cs-1.data - -Exit 0 diff --git a/gettext-tools/tests/format-csharp-2 b/gettext-tools/tests/format-csharp-2 deleted file mode 100755 index 6b63dc860..000000000 --- a/gettext-tools/tests/format-csharp-2 +++ /dev/null @@ -1,73 +0,0 @@ -#! /bin/sh -. "${srcdir=.}/init.sh"; path_prepend_ . ../src - -# Test checking of Java format strings. - -cat <<\EOF > f-cs-2.data -# Invalid: invalid msgstr -msgid "abc{0}def" -msgstr "abc{" -# Valid: same arguments -msgid "abc{1}def" -msgstr "xyz{1}" -# Valid: same arguments, differently written -msgid "abc{1}def" -msgstr "xyz{01}" -# Valid: permutation -msgid "abc{2}{0}{1}def" -msgstr "xyz{1}{0}{2}" -# Invalid: too few arguments -msgid "abc{1}def{0}" -msgstr "xyz{0}" -# Invalid: too many arguments -msgid "abc{0}def" -msgstr "xyz{0}uvw{1}" -# Valid: missing non-final argument -msgid "abc{1}def{0}" -msgstr "xyz{1}" -# Valid: added non-final argument -msgid "abc{1}def" -msgstr "xyz{0}{1}" -# Invalid: different number of arguments -msgid "abc{500000000}def" -msgstr "xyz{500000001}" -# Valid: type compatibility -msgid "abc{1:X}" -msgstr "xyz{1:g}" -EOF - -: ${MSGFMT=msgfmt} -n=0 -while read comment; do - read msgid_line - read msgstr_line - n=`expr $n + 1` - cat < f-cs-2-$n.po -#, csharp-format -${msgid_line} -${msgstr_line} -EOF - fail= - if echo "$comment" | grep 'Valid:' > /dev/null; then - if ${MSGFMT} --check-format -o f-cs-2-$n.mo f-cs-2-$n.po; then - : - else - fail=yes - fi - else - ${MSGFMT} --check-format -o f-cs-2-$n.mo f-cs-2-$n.po 2> /dev/null - if test $? = 1; then - : - else - fail=yes - fi - fi - if test -n "$fail"; then - echo "Format string checking error:" 1>&2 - cat f-cs-2-$n.po 1>&2 - Exit 1 - fi - rm -f f-cs-2-$n.po f-cs-2-$n.mo -done < f-cs-2.data - -Exit 0 diff --git a/gettext-tools/tests/format-java-1 b/gettext-tools/tests/format-java-1 deleted file mode 100755 index 465e93b21..000000000 --- a/gettext-tools/tests/format-java-1 +++ /dev/null @@ -1,153 +0,0 @@ -#! /bin/sh -. "${srcdir=.}/init.sh"; path_prepend_ . ../src - -# Test recognition of Java format strings. - -cat <<\EOF > f-j-1.data -# Valid: one argument -"abc{0}def" -# Valid: ten arguments -"abc{9}def" -# Valid: two-digit argument numbers -"abc{00}def" -# Valid: huge argument numbers -"abc{500000000}def" -# Invalid: unterminated -"abc{" -# Invalid: unterminated -"abc{0" -# Invalid: missing number -"abc{}def" -# Invalid: non-digit -"abc{number}def" -# Invalid: non-digit -"abc{-0}def" -# Valid: two arguments -"abc{1}def{0}" -# Valid: multiple uses of same argument -"abc{1}def{0}ghi{1}" -# Invalid: broken elementFormat -"abc{0,}def" -# Invalid: invalid elementFormat -"abc{1,string}def" -# Valid: elementFormat of length 1 -"abc{1,number}def" -# Valid: elementFormat of length 1 -"abc{1,date}def" -# Valid: elementFormat of length 1 -"abc{1,time}def" -# Valid: elementFormat of length 1 -"abc{1,choice}def" -# Invalid: broken elementFormat -"abc{1,number,}def" -# Valid: builtin numberStyle -"abc{1,number,currency}def" -# Valid: builtin numberStyle -"abc{1,number,percent}def" -# Valid: builtin numberStyle -"abc{1,number,integer}def" -# Valid: builtin datetimeStyle -"abc{1,date,short}def" -# Valid: builtin datetimeStyle -"abc{1,date,medium}def" -# Valid: builtin datetimeStyle -"abc{1,date,long}def" -# Valid: builtin datetimeStyle -"abc{1,date,full}def" -# Valid: builtin datetimeStyle -"abc{1,time,short}def" -# Valid: builtin datetimeStyle -"abc{1,time,medium}def" -# Valid: builtin datetimeStyle -"abc{1,time,long}def" -# Valid: builtin datetimeStyle -"abc{1,time,full}def" -# Valid: dateFormatPattern -"abc{1,date,foobar}" -# Valid: dateFormatPattern -"abc{1,time,foobar}" -# Valid: dateFormatPattern with comma -"abc{1,date,foo,bar}" -# Valid: numberFormatPattern -"abc{1,number,###,##0}def" -# Invalid: numberFormatPattern -"abc{1,number,foobar}" -# Valid: empty choiceFormatPattern -"abc{1,choice,}def" -# Valid: choiceFormatPattern -"abc{1,choice,0#zero|1#one|2#many}def" -# Invalid: empty clause in choiceFormatPattern -"abc{1,choice,|0#zero|1#one|2#many}def" -# Valid: empty clause at end of choiceFormatPattern -"abc{1,choice,0#zero|1#one|2#many|}def" -# Invalid: short clause in choiceFormatPattern -"abc{1,choice,-1|0#zero|1#one|2#many}def" -# Valid: short clause at end of choiceFormatPattern -"abc{1,choice,0#zero|1#one|2#many|3}def" -# Valid: choiceFormatPattern with different argument -"abc{1,choice,1#one|2#{0,date}}def" -# Valid: choiceFormatPattern with same argument -"abc{1,choice,1#one|2#{1}}def" -# Valid: choiceFormatPattern with same argument -"abc{1,choice,1#one|2#{1,number}}def" -# Invalid: choiceFormatPattern with same argument, type conflict -"abc{1,choice,1#one|2#{1,date}}def" -# Invalid: missing opening brace -"abc1}def{0}" -# Valid: quoted brace -"abc1'}'def{0}" -# Invalid: quoted brace -"abc{1'}'def" -# Valid: unterminated quote -"abc{0}1'}" -# Valid: quoted brace, '' counts as a single quote -"abc''1'}'def{0}" -# Invalid: '' counts as a single quote -"abc{1''}def" -# Valid: quote inside elementFormat is hidden -"abc{1,date,x'y}def" -# Valid: numberFormatPattern with quote -"abc{1,number,#0';'}def" -# Invalid: numberFormatPattern with wrong number syntax -"abc{1,number,#0;}def" -# Valid: numberFormatPattern with quote -"abc{1,number,0.##'E}def" -# Valid: numberFormatPattern without quote -"abc{1,number,0.##E}def" -EOF - -: ${XGETTEXT=xgettext} -n=0 -while read comment; do - read string - n=`expr $n + 1` - cat < f-j-1-$n.in -gettext(${string}); -EOF - ${XGETTEXT} -L Java -o f-j-1-$n.po f-j-1-$n.in || Exit 1 - test -f f-j-1-$n.po || Exit 1 - fail= - if echo "$comment" | grep 'Valid:' > /dev/null; then - if grep java-format f-j-1-$n.po > /dev/null; then - : - else - fail=yes - fi - else - if grep java-format f-j-1-$n.po > /dev/null; then - fail=yes - else - : - fi - fi - if test -n "$fail"; then - echo "Format string recognition error:" 1>&2 - cat f-j-1-$n.in 1>&2 - echo "Got:" 1>&2 - cat f-j-1-$n.po 1>&2 - Exit 1 - fi - rm -f f-j-1-$n.in f-j-1-$n.po -done < f-j-1.data - -Exit 0 diff --git a/gettext-tools/tests/format-java-2 b/gettext-tools/tests/format-java-2 deleted file mode 100755 index dfef92eef..000000000 --- a/gettext-tools/tests/format-java-2 +++ /dev/null @@ -1,142 +0,0 @@ -#! /bin/sh -. "${srcdir=.}/init.sh"; path_prepend_ . ../src - -# Test checking of Java format strings. - -cat <<\EOF > f-j-2.data -# Invalid: invalid msgstr -msgid "abc{0}def" -msgstr "abc{" -# Valid: same arguments -msgid "abc{1}def" -msgstr "xyz{1}" -# Valid: same arguments, differently written -msgid "abc{1}def" -msgstr "xyz{01}" -# Valid: permutation -msgid "abc{2}{0}{1}def" -msgstr "xyz{1}{0}{2}" -# Invalid: too few arguments -msgid "abc{1}def{0}" -msgstr "xyz{0}" -# Invalid: too many arguments -msgid "abc{0}def" -msgstr "xyz{0}uvw{1}" -# Invalid: missing non-final argument -msgid "abc{1}def{0}" -msgstr "xyz{1}" -# Invalid: added non-final argument -msgid "abc{1}def" -msgstr "xyz{0}{1}" -# Invalid: different number of arguments -msgid "abc{500000000}def" -msgstr "xyz{500000001}" -# Valid: type compatibility -msgid "abc{1,number}" -msgstr "xyz{1,choice,0#zero|1#{1,number}}" -# Valid: type compatibility -msgid "abc{1,number}" -msgstr "xyz{1,number,currency}" -# Valid: type compatibility -msgid "abc{1,number}" -msgstr "xyz{1,number,percent}" -# Valid: type compatibility -msgid "abc{1,number}" -msgstr "xyz{1,number,integer}" -# Valid: type compatibility -msgid "abc{1,number}" -msgstr "xyz{1,number,###,##0}" -# Valid: type compatibility -msgid "abc{1,date}" -msgstr "xyz{1,time}" -# Valid: type compatibility -msgid "abc{1,date}" -msgstr "xyz{1,date,short}" -# Valid: type compatibility -msgid "abc{1,date}" -msgstr "xyz{1,date,medium}" -# Valid: type compatibility -msgid "abc{1,date}" -msgstr "xyz{1,date,long}" -# Valid: type compatibility -msgid "abc{1,date}" -msgstr "xyz{1,date,full}" -# Valid: type compatibility -msgid "abc{1,date}" -msgstr "xyz{1,date,yyyy-MM-dd}" -# Valid: type compatibility -msgid "abc{1,time}" -msgstr "xyz{1,time,short}" -# Valid: type compatibility -msgid "abc{1,time}" -msgstr "xyz{1,time,medium}" -# Valid: type compatibility -msgid "abc{1,time}" -msgstr "xyz{1,time,long}" -# Valid: type compatibility -msgid "abc{1,time}" -msgstr "xyz{1,time,full}" -# Valid: type compatibility -msgid "abc{1,time}" -msgstr "xyz{1,time,}" -# Valid: type compatibility -msgid "abc{1,time}" -msgstr "xyz{1,time,hh:mm:ss}" -# Invalid: type incompatibility -msgid "abc{1}" -msgstr "xyz{1,number}" -# Invalid: type incompatibility -msgid "abc{1}" -msgstr "xyz{1,date}" -# Invalid: type incompatibility -msgid "abc{1,time}" -msgstr "xyz{1,number}" -# Invalid: type incompatibility -msgid "abc{1,number}" -msgstr "xyz{1,date}" -# Invalid: type incompatibility -msgid "abc{1}" -msgstr "xyz{1,choice,0#zero|1#{1,number}}" -# Invalid: type incompatibility -msgid "abc{1}" -msgstr "xyz{1,choice,0#zero|1#{0,number}}" -# Invalid: type incompatibility -msgid "abc{0,number}{1}" -msgstr "xyz{0,choice,0#zero|1#{1,number}}" -EOF - -: ${MSGFMT=msgfmt} -n=0 -while read comment; do - read msgid_line - read msgstr_line - n=`expr $n + 1` - cat < f-j-2-$n.po -#, java-format -${msgid_line} -${msgstr_line} -EOF - fail= - if echo "$comment" | grep 'Valid:' > /dev/null; then - if ${MSGFMT} --check-format -o f-j-2-$n.mo f-j-2-$n.po; then - : - else - fail=yes - fi - else - ${MSGFMT} --check-format -o f-j-2-$n.mo f-j-2-$n.po 2> /dev/null - if test $? = 1; then - : - else - fail=yes - fi - fi - if test -n "$fail"; then - echo "Format string checking error:" 1>&2 - cat f-j-2-$n.po 1>&2 - Exit 1 - fi - rm -f f-j-2-$n.po f-j-2-$n.mo -done < f-j-2.data - -Exit 0 diff --git a/gettext-tools/tests/gettextpo-1-prg.c b/gettext-tools/tests/gettextpo-1-prg.c index 3c93c42e0..97aa48e52 100644 --- a/gettext-tools/tests/gettextpo-1-prg.c +++ b/gettext-tools/tests/gettextpo-1-prg.c @@ -254,7 +254,6 @@ main (int argc, char *argv[]) ASSERT (!po_message_is_obsolete (msg)); ASSERT (!po_message_is_fuzzy (msg)); ASSERT (!po_message_is_format (msg, "c-format")); - ASSERT (!po_message_is_format (msg, "java-format")); ASSERT (!po_message_is_range (msg, &min, &max)); } { @@ -283,7 +282,6 @@ main (int argc, char *argv[]) ASSERT (!po_message_is_obsolete (msg)); ASSERT (po_message_is_fuzzy (msg)); ASSERT (po_message_is_format (msg, "c-format")); - ASSERT (!po_message_is_format (msg, "java-format")); ASSERT (!po_message_is_range (msg, &min, &max)); } { @@ -324,7 +322,6 @@ main (int argc, char *argv[]) ASSERT (!po_message_is_obsolete (msg)); ASSERT (!po_message_is_fuzzy (msg)); ASSERT (po_message_is_format (msg, "c-format")); - ASSERT (!po_message_is_format (msg, "java-format")); ASSERT (!po_message_is_range (msg, &min, &max)); } { @@ -346,7 +343,6 @@ main (int argc, char *argv[]) ASSERT (!po_message_is_obsolete (msg)); ASSERT (!po_message_is_fuzzy (msg)); ASSERT (!po_message_is_format (msg, "c-format")); - ASSERT (!po_message_is_format (msg, "java-format")); ASSERT (!po_message_is_range (msg, &min, &max)); } { @@ -375,7 +371,6 @@ main (int argc, char *argv[]) ASSERT (!po_message_is_obsolete (msg)); ASSERT (!po_message_is_fuzzy (msg)); ASSERT (!po_message_is_format (msg, "c-format")); - ASSERT (po_message_is_format (msg, "java-format")); ASSERT (!po_message_is_range (msg, &min, &max)); } { @@ -396,7 +391,6 @@ main (int argc, char *argv[]) ASSERT (po_message_is_obsolete (msg)); ASSERT (!po_message_is_fuzzy (msg)); ASSERT (!po_message_is_format (msg, "c-format")); - ASSERT (!po_message_is_format (msg, "java-format")); ASSERT (!po_message_is_range (msg, &min, &max)); } { @@ -566,7 +560,6 @@ main (int argc, char *argv[]) po_message_set_comments (msg, arg); free (arg); } - po_message_set_format (msg, "java-format", 1); po_message_insert (iter, msg); } { @@ -909,27 +902,20 @@ main (int argc, char *argv[]) { po_message_t msg = po_message_create (); ASSERT (!po_message_is_format (msg, "c-format")); - ASSERT (!po_message_is_format (msg, "java-format")); ASSERT (!po_message_is_format (msg, "xyzzy-format")); po_message_set_format (msg, "c-format", 1); ASSERT (po_message_is_format (msg, "c-format")); - ASSERT (!po_message_is_format (msg, "java-format")); ASSERT (!po_message_is_format (msg, "xyzzy-format")); po_message_set_format (msg, "c-format", 1); ASSERT (po_message_is_format (msg, "c-format")); - ASSERT (!po_message_is_format (msg, "java-format")); ASSERT (!po_message_is_format (msg, "xyzzy-format")); - po_message_set_format (msg, "java-format", 1); ASSERT (po_message_is_format (msg, "c-format")); - ASSERT (po_message_is_format (msg, "java-format")); ASSERT (!po_message_is_format (msg, "xyzzy-format")); po_message_set_format (msg, "c-format", 0); ASSERT (!po_message_is_format (msg, "c-format")); - ASSERT (po_message_is_format (msg, "java-format")); ASSERT (!po_message_is_format (msg, "xyzzy-format")); po_message_set_format (msg, "xyzzy-format", 1); ASSERT (!po_message_is_format (msg, "c-format")); - ASSERT (po_message_is_format (msg, "java-format")); ASSERT (!po_message_is_format (msg, "xyzzy-format")); } @@ -1020,7 +1006,6 @@ main (int argc, char *argv[]) /* Test po_format_pretty_name. */ ASSERT (strcmp (po_format_pretty_name ("c-format"), "C") == 0); - ASSERT (strcmp (po_format_pretty_name ("csharp-format"), "C#") == 0); ASSERT (po_format_pretty_name ("xyzzy-format") == NULL); return 0; diff --git a/gettext-tools/tests/lang-csharp b/gettext-tools/tests/lang-csharp deleted file mode 100755 index 3ccdd5257..000000000 --- a/gettext-tools/tests/lang-csharp +++ /dev/null @@ -1,206 +0,0 @@ -#! /bin/sh -. "${srcdir=.}/init.sh"; path_prepend_ . ../src - -# Test of gettext facilities in the C# language. -# Assumes an fr_FR locale is installed. -# Assumes the following packages are installed: mono, mcs. - -# Note: This test fails when a GNU gettext version < 0.17 is installed with -# the same --prefix as mcs. mcs apparently searches ${prefix}/lib before -# searching the directory specified on the command line: -# $ mcs -out:program.exe -lib:../../gettext-runtime/intl-csharp -reference:GNU.Gettext program.cs -# program.cs(17,45): error CS0117: `GNU.Gettext.GettextResourceManager' does not contain a definition for `GetParticularPluralString' -# /usr/local/lib/GNU.Gettext.dll (Location of the symbol related to previous error) -# program.cs(18,45): error CS0117: `GNU.Gettext.GettextResourceManager' does not contain a definition for `GetParticularString' -# /usr/local/lib/GNU.Gettext.dll (Location of the symbol related to previous error) -# Compilation failed: 2 error(s), 0 warnings -# The workaround is to install GNU gettext with the same --prefix, despite -# the test failure, and run "make check" afterwards. - -# Test whether we can build and test C# programs. -test "${CSHARP_CHOICE}" != no || { - echo "Skipping test: configured with --disable-csharp" - Exit 77 -} -test "${BUILDCSHARP}" = yes || { - echo "Skipping test: C# compiler not found" - Exit 77 -} -test "${TESTCSHARP}" = yes || { - echo "Skipping test: C# engine not found" - Exit 77 -} - -cat <<\EOF > program.cs -using System; -using GNU.Gettext; -class Program { - static void Main (String[] args) { - #if __MonoCS__ - // Some systems don't set CurrentCulture and CurrentUICulture as specified - // by LC_ALL. So set it by hand. - System.Threading.Thread.CurrentThread.CurrentCulture = - System.Threading.Thread.CurrentThread.CurrentUICulture = - new System.Globalization.CultureInfo("fr-FR"); - #endif - int n = Int32.Parse(args[0]); - GettextResourceManager catalog = new GettextResourceManager("prog"); - Console.WriteLine(catalog.GetString("'Your command, please?', asked the waiter.")); - Console.WriteLine(String.Format(catalog.GetPluralString("a piece of cake","{0} pieces of cake",n), n)); - Console.WriteLine(String.Format(catalog.GetString("{0} is replaced by {1}."), "FF", "EUR")); - Console.WriteLine(String.Format(catalog.GetParticularPluralString("++","a piece of cake","{0} pieces of cake",n), n)); - Console.WriteLine(String.Format(catalog.GetParticularString("++","{0} is replaced by {1}."), "FF", "EUR")); - } -} -EOF - -: ${CSHARPCOMP="/bin/sh ../../csharpcomp.sh"} -${CSHARPCOMP} -o program.exe -L ../../../gettext-runtime/intl-csharp -l GNU.Gettext program.cs || Exit 1 - -: ${XGETTEXT=xgettext} -${XGETTEXT} -o prog.tmp --omit-header --no-location program.cs || Exit 1 -LC_ALL=C tr -d '\r' < prog.tmp > prog.pot || Exit 1 - -cat < prog.ok -msgid "'Your command, please?', asked the waiter." -msgstr "" - -#, csharp-format -msgid "a piece of cake" -msgid_plural "{0} pieces of cake" -msgstr[0] "" -msgstr[1] "" - -#, csharp-format -msgid "{0} is replaced by {1}." -msgstr "" - -#, csharp-format -msgctxt "++" -msgid "a piece of cake" -msgid_plural "{0} pieces of cake" -msgstr[0] "" -msgstr[1] "" - -#, csharp-format -msgctxt "++" -msgid "{0} is replaced by {1}." -msgstr "" -EOF - -: ${DIFF=diff} -${DIFF} prog.ok prog.pot || Exit 1 - -cat <<\EOF > fr.po -msgid "" -msgstr "" -"Content-Type: text/plain; charset=ISO-8859-1\n" -"Plural-Forms: nplurals=2; plural=(n > 1);\n" - -msgid "'Your command, please?', asked the waiter." -msgstr "«Votre commande, s'il vous plait», dit le garçon." - -# Les gateaux allemands sont les meilleurs du monde. -#, csharp-format -msgid "a piece of cake" -msgid_plural "{0} pieces of cake" -msgstr[0] "un morceau de gateau" -msgstr[1] "{0} morceaux de gateau" - -# Reverse the arguments. -#, csharp-format -msgid "{0} is replaced by {1}." -msgstr "{1} remplace {0}." - -# Euphemistic formulation. -#, csharp-format -msgctxt "++" -msgid "a piece of cake" -msgid_plural "{0} pieces of cake" -msgstr[0] "un morceau de gateau succulent" -msgstr[1] "{0} morceaux de gateau succulent" - -# Euphemistic formulation. -#, csharp-format -msgctxt "++" -msgid "{0} is replaced by {1}." -msgstr "Le nouveau {1} remplace le vieux {0}." -EOF - -: ${MSGMERGE=msgmerge} -${MSGMERGE} -q -o fr.po.tmp fr.po prog.pot || Exit 1 -LC_ALL=C tr -d '\r' < fr.po.tmp > fr.po.new || Exit 1 - -: ${DIFF=diff} -${DIFF} fr.po fr.po.new || Exit 1 - -: ${MSGFMT=msgfmt} -GETTEXTCSHARPLIBDIR=../../../gettext-runtime/intl-csharp \ -${MSGFMT} --csharp -d . -r prog -l fr fr.po || Exit 1 - -# Test which of the fr_FR locales are installed. -: ${LOCALE_FR=fr_FR} -: ${LOCALE_FR_UTF8=fr_FR.UTF-8} -if test $LOCALE_FR != none; then - LC_ALL=$LOCALE_FR ../testlocale - case $? in - 0) ;; - 77) LOCALE_FR=none;; - *) Exit 1;; - esac -fi -if test $LOCALE_FR_UTF8 != none; then - LC_ALL=$LOCALE_FR_UTF8 ../testlocale - case $? in - 0) ;; - 77) LOCALE_FR_UTF8=none;; - *) Exit 1;; - esac -fi -if test $LOCALE_FR = none && test $LOCALE_FR_UTF8 = none; then - if test -f /usr/bin/localedef; then - echo "Skipping test: no french locale is installed" - else - echo "Skipping test: no french locale is supported" - fi - Exit 77 -fi - -: ${DIFF=diff} -cat <<\EOF > prog.ok -«Votre commande, s'il vous plait», dit le garçon. -2 morceaux de gateau -EUR remplace FF. -2 morceaux de gateau succulent -Le nouveau EUR remplace le vieux FF. -EOF -cat <<\EOF > prog.oku -«Votre commande, s'il vous plait», dit le garçon. -2 morceaux de gateau -EUR remplace FF. -2 morceaux de gateau succulent -Le nouveau EUR remplace le vieux FF. -EOF - -: ${LOCALE_FR=fr_FR} -: ${LOCALE_FR_UTF8=fr_FR.UTF-8} -: ${CSHARPEXEC="/bin/sh ../../csharpexec.sh"} -if test $LOCALE_FR != none; then - # On Mac OS X, with mono 4.2.3, this test would fail, because the Console's - # output encoding is System.Text.Encoding.Default, and this is UTF-8 even - # in the fr_FR.ISO8859-1 locale. System.Text.Encoding.Default is defined - # through InternalCodePage(), which uses g_get_charset(), which uses either - # locale_charset() or nl_langinfo(CODESET) [which is "ISO8859-1" in this case] - # or "UTF-8" - depending on platform or build configuration. So, allow the - # expected result in UTF-8 encoding here too. - prepare_locale_ fr $LOCALE_FR - LANGUAGE= LC_ALL=$LOCALE_FR ${CSHARPEXEC} -L ../../../gettext-runtime/intl-csharp program.exe 2 > prog.out || Exit 1 - ${DIFF} prog.oku prog.out >/dev/null || ${DIFF} prog.ok prog.out || Exit 1 -fi -if test $LOCALE_FR_UTF8 != none; then - prepare_locale_ fr $LOCALE_FR_UTF8 - LANGUAGE= LC_ALL=$LOCALE_FR_UTF8 ${CSHARPEXEC} -L ../../../gettext-runtime/intl-csharp program.exe 2 > prog.out || Exit 1 - ${DIFF} prog.oku prog.out || Exit 1 -fi - -Exit 0 diff --git a/gettext-tools/tests/lang-java b/gettext-tools/tests/lang-java deleted file mode 100755 index 0b5c70ee7..000000000 --- a/gettext-tools/tests/lang-java +++ /dev/null @@ -1,227 +0,0 @@ -#! /bin/sh -. "${srcdir=.}/init.sh"; path_prepend_ . ../src - -# Test of gettext facilities in the Java language. -# Assumes an fr_FR locale is installed. -# Assumes the following packages are installed: java. - -# Test whether we can build and test Java programs. -test "${JAVA_CHOICE}" != no || { - echo "Skipping test: configured with --disable-java" - Exit 77 -} -test "${BUILDJAVA}" = yes || { - echo "Skipping test: Java compiler or jar not found" - Exit 77 -} -test "${TESTJAVA}" = yes || { - echo "Skipping test: Java engine not found" - Exit 77 -} - -cat <<\EOF > Program.java -import java.util.*; -import java.io.*; -import java.text.*; -import gnu.gettext.*; - -public class Program { - public static void main (String[] args) { - // Some systems (like Solaris) don't set Locale.getDefault() - // as specified by LC_ALL. So set it by hand. - Locale.setDefault(new Locale("fr","FR")); -EOF -case "$host_os" in - darwin*) -cat <<\EOF >> Program.java - // Some systems (like MacOS X) don't set System.out's character encoding - // according to LC_ALL, which is what we need for comparison purposes. - try { - System.setOut(new PrintStream(new FileOutputStream(FileDescriptor.out), - true, args[1])); - } catch (UnsupportedEncodingException e) { - } -EOF - ;; -esac -cat <<\EOF >> Program.java - int n = Integer.parseInt(args[0]); - ResourceBundle catalog = ResourceBundle.getBundle("prog"); - System.out.println(GettextResource.gettext(catalog,"'Your command, please?', asked the waiter.")); - System.out.println(MessageFormat.format(GettextResource.ngettext(catalog,"a piece of cake","{0,number} pieces of cake",n), new Object[] { new Integer(n) })); - System.out.println(MessageFormat.format(GettextResource.gettext(catalog,"{0} is replaced by {1}."), new Object[] { "FF", "EUR" })); - System.out.println(MessageFormat.format(GettextResource.npgettext(catalog,"++","a piece of cake","{0,number} pieces of cake",n), new Object[] { new Integer(n) })); - System.out.println(MessageFormat.format(GettextResource.pgettext(catalog,"++","{0} is replaced by {1}."), new Object[] { "FF", "EUR" })); - System.out.println(String.format(GettextResource.ngettext(catalog,"She has one child","She has %d children",n), n)); - System.out.println(String.format(GettextResource.gettext(catalog,"%d left-wing deputees and %d right-wing deputees"), 75, 64)); - } -} -EOF - -: ${JAVACOMP="/bin/sh ../../javacomp.sh"} -CLASSPATH=../../../gettext-runtime/intl-java/libintl.jar ${JAVACOMP} -d . Program.java 2>prog.err \ - || { cat prog.err 1>&2; Exit 1; } - -: ${XGETTEXT=xgettext} -${XGETTEXT} -o prog.tmp --omit-header --no-location Program.java || Exit 1 -LC_ALL=C tr -d '\r' < prog.tmp > prog.pot || Exit 1 - -cat < prog.ok -msgid "'Your command, please?', asked the waiter." -msgstr "" - -#, java-format -msgid "a piece of cake" -msgid_plural "{0,number} pieces of cake" -msgstr[0] "" -msgstr[1] "" - -#, java-format -msgid "{0} is replaced by {1}." -msgstr "" - -#, java-format -msgctxt "++" -msgid "a piece of cake" -msgid_plural "{0,number} pieces of cake" -msgstr[0] "" -msgstr[1] "" - -#, java-format -msgctxt "++" -msgid "{0} is replaced by {1}." -msgstr "" - -#, java-printf-format -msgid "She has one child" -msgid_plural "She has %d children" -msgstr[0] "" -msgstr[1] "" - -#, java-printf-format -msgid "%d left-wing deputees and %d right-wing deputees" -msgstr "" -EOF - -: ${DIFF=diff} -${DIFF} prog.ok prog.pot || Exit 1 - -cat <<\EOF > fr.po -msgid "" -msgstr "" -"Content-Type: text/plain; charset=ISO-8859-1\n" -"Plural-Forms: nplurals=2; plural=(n > 1);\n" - -msgid "'Your command, please?', asked the waiter." -msgstr "«Votre commande, s'il vous plait», dit le garçon." - -# Les gateaux allemands sont les meilleurs du monde. -#, java-format -msgid "a piece of cake" -msgid_plural "{0,number} pieces of cake" -msgstr[0] "un morceau de gateau" -msgstr[1] "{0,number} morceaux de gateau" - -# Reverse the arguments. -#, java-format -msgid "{0} is replaced by {1}." -msgstr "{1} remplace {0}." - -# Euphemistic formulation. -#, java-format -msgctxt "++" -msgid "a piece of cake" -msgid_plural "{0,number} pieces of cake" -msgstr[0] "un morceau de gateau succulent" -msgstr[1] "{0,number} morceaux de gateau succulent" - -# Euphemistic formulation. -#, java-format -msgctxt "++" -msgid "{0} is replaced by {1}." -msgstr "Le nouveau {1} remplace le vieux {0}." - -#, java-printf-format -msgid "She has one child" -msgid_plural "She has %d children" -msgstr[0] "Elle a un enfant" -msgstr[1] "Elle a %d enfants" - -#, java-printf-format -msgid "%d left-wing deputees and %d right-wing deputees" -msgstr "%2$d députés de droite et %d députés de gauche" -EOF - -: ${MSGMERGE=msgmerge} -${MSGMERGE} -q -o fr.po.tmp fr.po prog.pot || Exit 1 -LC_ALL=C tr -d '\r' < fr.po.tmp > fr.po.new || Exit 1 - -: ${DIFF=diff} -${DIFF} fr.po fr.po.new || Exit 1 - -: ${MSGFMT=msgfmt} -${MSGFMT} -j -d . -r prog -l fr fr.po || Exit 1 - -# Test which of the fr_FR locales are installed. -: ${LOCALE_FR=fr_FR} -: ${LOCALE_FR_UTF8=fr_FR.UTF-8} -if test $LOCALE_FR != none; then - LC_ALL=$LOCALE_FR ../testlocale - case $? in - 0) ;; - 77) LOCALE_FR=none;; - *) Exit 1;; - esac -fi -if test $LOCALE_FR_UTF8 != none; then - LC_ALL=$LOCALE_FR_UTF8 ../testlocale - case $? in - 0) ;; - 77) LOCALE_FR_UTF8=none;; - *) Exit 1;; - esac -fi -if test $LOCALE_FR = none && test $LOCALE_FR_UTF8 = none; then - if test -f /usr/bin/localedef; then - echo "Skipping test: no french locale is installed" - else - echo "Skipping test: no french locale is supported" - fi - Exit 77 -fi - -: ${DIFF=diff} -cat <<\EOF > prog.ok -«Votre commande, s'il vous plait», dit le garçon. -2 morceaux de gateau -EUR remplace FF. -2 morceaux de gateau succulent -Le nouveau EUR remplace le vieux FF. -Elle a 2 enfants -64 députés de droite et 75 députés de gauche -EOF -cat <<\EOF > prog.oku -«Votre commande, s'il vous plait», dit le garçon. -2 morceaux de gateau -EUR remplace FF. -2 morceaux de gateau succulent -Le nouveau EUR remplace le vieux FF. -Elle a 2 enfants -64 députés de droite et 75 députés de gauche -EOF - -: ${LOCALE_FR=fr_FR} -: ${LOCALE_FR_UTF8=fr_FR.UTF-8} -: ${JAVAEXEC="/bin/sh ../../javaexec.sh"} -if test $LOCALE_FR != none; then - prepare_locale_ fr $LOCALE_FR - LANGUAGE= LC_ALL=$LOCALE_FR CLASSPATH=.:../../../gettext-runtime/intl-java/libintl.jar ${JAVAEXEC} Program 2 ISO-8859-1 > prog.out || Exit 1 - ${DIFF} prog.ok prog.out || Exit 1 -fi -if test $LOCALE_FR_UTF8 != none; then - prepare_locale_ fr $LOCALE_FR_UTF8 - LANGUAGE= LC_ALL=$LOCALE_FR_UTF8 CLASSPATH=.:../../../gettext-runtime/intl-java/libintl.jar ${JAVAEXEC} Program 2 UTF-8 > prog.out || Exit 1 - ${DIFF} prog.oku prog.out || Exit 1 -fi - -Exit 0 diff --git a/gettext-tools/tests/msggrep-6 b/gettext-tools/tests/msggrep-6 index c42848340..c7bf989a2 100755 --- a/gettext-tools/tests/msggrep-6 +++ b/gettext-tools/tests/msggrep-6 @@ -87,12 +87,6 @@ Unknown\ system\ error=Unbekannter Systemfehler #, c-format %s\:\ option\ `-W\ %s'\ doesn't\ allow\ an\ argument\n=%s\: Option \u00bb-W %s\u00ab erwartet kein Argument\n -#: javacomp.c:465 -Java\ compiler\ not\ found,\ try\ installing\ gcj\ or\ set\ $JAVAC=Java-Compiler nicht gefunden; bitte \u00bbgcj\u00ab installieren oder $JAVAC setzen - -#: javaexec.c:404 -Java\ virtual\ machine\ not\ found,\ try\ installing\ gij\ or\ set\ $JAVA=Virtuelle Java-Maschine nicht gefunden; bitte \u00bbgcj\u00ab installieren oder\n$JAVA setzen - #: obstack.c:474 xerror.c:75 xmalloc.c:56 memory\ exhausted=virtueller Speicher ersch\u00f6pft diff --git a/gettext-tools/tests/msggrep-9 b/gettext-tools/tests/msggrep-9 index 207f69ec1..5d1ca63b2 100755 --- a/gettext-tools/tests/msggrep-9 +++ b/gettext-tools/tests/msggrep-9 @@ -124,17 +124,6 @@ msgstr "%s: Option msgid "%s: option `-W %s' doesn't allow an argument\n" msgstr "%s: Option »-W %s« erwartet kein Argument\n" -#: javacomp.c:465 -msgid "Java compiler not found, try installing gcj or set $JAVAC" -msgstr "" -"Java-Compiler nicht gefunden; bitte »gcj« installieren oder $JAVAC setzen" - -#: javaexec.c:404 -msgid "Java virtual machine not found, try installing gij or set $JAVA" -msgstr "" -"Virtuelle Java-Maschine nicht gefunden; bitte »gcj« installieren oder\n" -"$JAVA setzen" - #: obstack.c:474 xerror.c:75 xmalloc.c:56 msgid "memory exhausted" msgstr "virtueller Speicher erschöpft" diff --git a/gettext-tools/tests/msgunfmt-csharp-1 b/gettext-tools/tests/msgunfmt-csharp-1 deleted file mode 100755 index fbbd5cced..000000000 --- a/gettext-tools/tests/msgunfmt-csharp-1 +++ /dev/null @@ -1,92 +0,0 @@ -#! /bin/sh -. "${srcdir=.}/init.sh"; path_prepend_ . ../src - -# Test of --csharp option. - -# Test whether we can compile and execute C# programs. -test "${CSHARP_CHOICE}" != no || { - echo "Skipping test: configured with --disable-csharp" - Exit 77 -} -test "${BUILDCSHARP}" = yes || { - echo "Skipping test: C# compiler not found" - Exit 77 -} -test "${TESTCSHARP}" = yes || { - echo "Skipping test: C# engine not found" - Exit 77 -} - -test -d mu-cs-1 || mkdir mu-cs-1 - -cat <<\EOF > mu-cs-1/fr.po -msgid "" -msgstr "" -"Content-Type: text/plain; charset=ISO-8859-1\n" -"Plural-Forms: nplurals=2; plural=(n > 1);\n" - -msgid "'Your command, please?', asked the waiter." -msgstr "«Votre commande, s'il vous plait», dit le garçon." - -# Les gateaux allemands sont les meilleurs du monde. -#, csharp-format -msgid "a piece of cake" -msgid_plural "{0} pieces of cake" -msgstr[0] "un morceau de gateau" -msgstr[1] "{0} morceaux de gateau" - -# Reverse the arguments. -#, csharp-format -msgid "{0} is replaced by {1}." -msgstr "{1} remplace {0}." - -# A proximity measure. -msgid "Close" -msgstr "Proche" - -# A menu entry. -msgctxt "File" -msgid "Close" -msgstr "Fermer" -EOF - -: ${MSGFMT=msgfmt} -GETTEXTCSHARPLIBDIR=../../../gettext-runtime/intl-csharp \ -${MSGFMT} --csharp -d mu-cs-1 -r prog -l fr mu-cs-1/fr.po || Exit 1 - -: ${MSGUNFMT=msgunfmt} -GETTEXTCSHARPEXEDIR=../../src \ -GETTEXTCSHARPLIBDIR=../../../gettext-runtime/intl-csharp \ -${MSGUNFMT} --csharp -d mu-cs-1 -r prog -l fr -o mu-cs-1/prog.out || Exit 1 - -: ${MSGCAT=msgcat} -${MSGCAT} -s -o mu-cs-1/prog.sort mu-cs-1/prog.out || Exit 1 - -cat <<\EOF > mu-cs-1/prog.ok -msgid "" -msgstr "" -"Content-Type: text/plain; charset=UTF-8\n" -"Plural-Forms: nplurals=2; plural=(n > 1);\n" - -msgid "'Your command, please?', asked the waiter." -msgstr "«Votre commande, s'il vous plait», dit le garçon." - -msgid "Close" -msgstr "Proche" - -msgctxt "File" -msgid "Close" -msgstr "Fermer" - -msgid "a piece of cake" -msgid_plural "{0} pieces of cake" -msgstr[0] "un morceau de gateau" -msgstr[1] "{0} morceaux de gateau" - -msgid "{0} is replaced by {1}." -msgstr "{1} remplace {0}." -EOF -: ${DIFF=diff} -${DIFF} mu-cs-1/prog.ok mu-cs-1/prog.sort || Exit 1 - -Exit 0 diff --git a/gettext-tools/tests/msgunfmt-java-1 b/gettext-tools/tests/msgunfmt-java-1 deleted file mode 100755 index e0c3bdcad..000000000 --- a/gettext-tools/tests/msgunfmt-java-1 +++ /dev/null @@ -1,91 +0,0 @@ -#! /bin/sh -. "${srcdir=.}/init.sh"; path_prepend_ . ../src - -# Test of --java option. - -# Test whether we can compile and execute Java programs. -test "${JAVA_CHOICE}" != no || { - echo "Skipping test: configured with --disable-java" - Exit 77 -} -test "${BUILDJAVA}" = yes || { - echo "Skipping test: Java compiler or jar not found" - Exit 77 -} -test "${TESTJAVA}" = yes || { - echo "Skipping test: Java engine not found" - Exit 77 -} - -test -d mu-java-1 || mkdir mu-java-1 - -cat <<\EOF > mu-java-1/fr.po -msgid "" -msgstr "" -"Content-Type: text/plain; charset=ISO-8859-1\n" -"Plural-Forms: nplurals=2; plural=(n > 1);\n" - -msgid "'Your command, please?', asked the waiter." -msgstr "«Votre commande, s'il vous plait», dit le garçon." - -# Les gateaux allemands sont les meilleurs du monde. -#, java-format -msgid "a piece of cake" -msgid_plural "{0,number} pieces of cake" -msgstr[0] "un morceau de gateau" -msgstr[1] "{0,number} morceaux de gateau" - -# Reverse the arguments. -#, java-format -msgid "{0} is replaced by {1}." -msgstr "{1} remplace {0}." - -# A proximity measure. -msgid "Close" -msgstr "Proche" - -# A menu entry. -msgctxt "File" -msgid "Close" -msgstr "Fermer" -EOF - -: ${MSGFMT=msgfmt} -${MSGFMT} -j -d mu-java-1 -r prog -l fr mu-java-1/fr.po || Exit 1 - -: ${MSGUNFMT=msgunfmt} -CLASSPATH=mu-java-1${CLASSPATH:+:$CLASSPATH} \ -GETTEXTJAR=../../src/gettext.jar \ -${MSGUNFMT} --java -d mu-java-1 -r prog -l fr -o mu-java-1/prog.out || Exit 1 - -: ${MSGCAT=msgcat} -${MSGCAT} -s -o mu-java-1/prog.sort mu-java-1/prog.out || Exit 1 - -cat <<\EOF > mu-java-1/prog.ok -msgid "" -msgstr "" -"Content-Type: text/plain; charset=UTF-8\n" -"Plural-Forms: nplurals=2; plural=(n > 1);\n" - -msgid "'Your command, please?', asked the waiter." -msgstr "«Votre commande, s'il vous plait», dit le garçon." - -msgid "Close" -msgstr "Proche" - -msgctxt "File" -msgid "Close" -msgstr "Fermer" - -msgid "a piece of cake" -msgid_plural "{0,number} pieces of cake" -msgstr[0] "un morceau de gateau" -msgstr[1] "{0,number} morceaux de gateau" - -msgid "{0} is replaced by {1}." -msgstr "{1} remplace {0}." -EOF -: ${DIFF=diff} -${DIFF} mu-java-1/prog.ok mu-java-1/prog.sort || Exit 1 - -Exit 0 diff --git a/gettext-tools/tests/xgettext-6 b/gettext-tools/tests/xgettext-6 index 416fe7b1c..6163ed105 100755 --- a/gettext-tools/tests/xgettext-6 +++ b/gettext-tools/tests/xgettext-6 @@ -34,16 +34,6 @@ cat <<\EOF > xg-test6.jl (printk (_ "librep-format negative2")) EOF -cat <<\EOF > xg-test6.java -MessageFormat.format(gettext("java-format positive1"), - gettext("java-format negative1")); -String.format(gettext("java-printf-format positive1"), - gettext("java-printf-format negative1")); -System.err.printf(gettext("java-printf-format positive2"), - gettext("java-printf-format negative2")); -System.err.println(gettext("both java-format, java-printf-format negative3")); -EOF - cat <<\EOF > xg-test6.awk printf dcgettext ("awk-format positive1"), dcgettext ("awk-format negative1"); printf (dcgettext ("awk-format positive2"), dcgettext ("awk-format negative2")); @@ -81,7 +71,7 @@ EOF ${XGETTEXT} --omit-header --no-location -d xg-test6.tmp \ --flag=my_printf:1:python-format \ xg-test6.c xg-test6.sh xg-test6.py xg-test6.lisp xg-test6.el \ - xg-test6.jl xg-test6.java xg-test6.awk xg-test6.ycp xg-test6.tcl \ + xg-test6.jl xg-test6.awk xg-test6.ycp xg-test6.tcl \ xg-test6.pl xg-test6.php || Exit 1 LC_ALL=C tr -d '\r' < xg-test6.tmp.po > xg-test6.po || Exit 1 @@ -146,30 +136,6 @@ msgstr "" msgid "librep-format negative2" msgstr "" -#, java-format -msgid "java-format positive1" -msgstr "" - -msgid "java-format negative1" -msgstr "" - -#, java-printf-format -msgid "java-printf-format positive1" -msgstr "" - -msgid "java-printf-format negative1" -msgstr "" - -#, java-printf-format -msgid "java-printf-format positive2" -msgstr "" - -msgid "java-printf-format negative2" -msgstr "" - -msgid "both java-format, java-printf-format negative3" -msgstr "" - #, awk-format msgid "awk-format positive1" msgstr "" diff --git a/gettext-tools/tests/xgettext-csharp-1 b/gettext-tools/tests/xgettext-csharp-1 deleted file mode 100755 index cbb3c32f6..000000000 --- a/gettext-tools/tests/xgettext-csharp-1 +++ /dev/null @@ -1,70 +0,0 @@ -#!/bin/sh -. "${srcdir=.}/init.sh"; path_prepend_ . ../src - -# Some tests for C# support - -cat < xg-cs-1.cs -using GNU.Gettext; -class TestCase { - public TestCase() { - GettextResourceManager rm = new GettextResourceManager("test"); - // standard usage - String test1 = rm.GetString("Test String 1"); - /* C style comment */ - String test2 = rm.GetString("Test String 2"); - // C# "multiline" string - String test3 = rm.GetString("Test " + - "String " + - "3"); - // empty string - String test4 = rm.GetString(""); -#if false - // commented out through #if - String test5 = rm.GetString("Test String 5"); -#endif - // verbatim string - String test5 = rm.GetString(@"first line -second line -third line"); - } -} -EOF - -: ${XGETTEXT=xgettext} -${XGETTEXT} --omit-header --no-location -c -d xg-cs-1.tmp xg-cs-1.cs || Exit 1 -LC_ALL=C tr -d '\r' < xg-cs-1.tmp.po > xg-cs-1.po || Exit 1 - -cat < xg-cs-1.ok -#. standard usage -msgid "Test String 1" -msgstr "" - -#. C style comment -msgid "Test String 2" -msgstr "" - -#. C# "multiline" string -msgid "Test String 3" -msgstr "" - -#. empty string -msgid "" -msgstr "" - -#. commented out through #if -msgid "Test String 5" -msgstr "" - -#. verbatim string -msgid "" -"first line\n" -"second line\n" -"third line" -msgstr "" -EOF - -: ${DIFF=diff} -${DIFF} xg-cs-1.ok xg-cs-1.po -result=$? - -exit $result diff --git a/gettext-tools/tests/xgettext-csharp-2 b/gettext-tools/tests/xgettext-csharp-2 deleted file mode 100755 index 68b93cc14..000000000 --- a/gettext-tools/tests/xgettext-csharp-2 +++ /dev/null @@ -1,83 +0,0 @@ -#!/bin/sh -. "${srcdir=.}/init.sh"; path_prepend_ . ../src - -# More tests for C# support: UTF-8 encoded source files - -cat <<\EOF > xg-cs-2.cs -class TestCase { - public static void Main (String[] args) { - Console.WriteLine(GetString("Russian (РуÑÑкий): ЗдравÑтвуйте")); - Console.WriteLine(GetString("Vietnamese (Tiếng Việt): Chào bạn")); - Console.WriteLine(GetString("Japanese (日本語): ã“ã‚“ã«ã¡ã¯")); - Console.WriteLine(GetString("Thai (ภาษาไทย): สวัสดีครับ")); - Console.WriteLine(GetString("Script: ð’ž")); - Console.WriteLine(GetString("Russian (\u0420\u0443\u0441\u0441\u043a\u0438\u0439): \u0417\u0434\u0440\u0430\u0432\u0441\u0442\u0432\u0443\u0439\u0442\u0435")); - Console.WriteLine(GetString("Vietnamese (Ti\u1ebfng Vi\u1ec7t): Ch\u00e0o b\u1ea1n")); - Console.WriteLine(GetString("Japanese (\u65e5\u672c\u8a9e): \u3053\u3093\u306b\u3061\u306f")); - Console.WriteLine(GetString("Thai (\u0e20\u0e32\u0e29\u0e32\u0e44\u0e17\u0e22): \u0e2a\u0e27\u0e31\u0e2a\u0e14\u0e35\u0e04\u0e23\u0e31\u0e1a")); - Console.WriteLine(GetString("Script: \U0001d49e")); - // And now a comment with РуÑÑкий and 日本語 and Unicode escapes: B\u00f6se B\u00fcbchen - Console.WriteLine(GetString("This string has a multilingual comment")); - // Unicode identifiers. - String ã‚ = ""; - String ð€€ = ""; - int \u65e5\u672c\u8a9e = 1; - } -} -EOF - -: ${XGETTEXT=xgettext} -# delete POT-Creation-Date: line because the date depends on local time. -${XGETTEXT} --output xg-cs-2.tmp --add-location -c --from-code=UTF-8 xg-cs-2.cs || Exit 1 -sed -e '/\"POT-Creation-Date:.*/d' < xg-cs-2.tmp | LC_ALL=C tr -d '\r' > xg-cs-2.po || Exit 1 - -cat <<\EOF > xg-cs-2.ok -# SOME DESCRIPTIVE TITLE. -# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER -# This file is distributed under the same license as the PACKAGE package. -# FIRST AUTHOR , YEAR. -# -#, fuzzy -msgid "" -msgstr "" -"Project-Id-Version: PACKAGE VERSION\n" -"Report-Msgid-Bugs-To: \n" -"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" -"Last-Translator: FULL NAME \n" -"Language-Team: LANGUAGE \n" -"Language: \n" -"MIME-Version: 1.0\n" -"Content-Type: text/plain; charset=UTF-8\n" -"Content-Transfer-Encoding: 8bit\n" - -#: xg-cs-2.cs:3 xg-cs-2.cs:8 -msgid "Russian (РуÑÑкий): ЗдравÑтвуйте" -msgstr "" - -#: xg-cs-2.cs:4 xg-cs-2.cs:9 -msgid "Vietnamese (Tiếng Việt): Chào bạn" -msgstr "" - -#: xg-cs-2.cs:5 xg-cs-2.cs:10 -msgid "Japanese (日本語): ã“ã‚“ã«ã¡ã¯" -msgstr "" - -#: xg-cs-2.cs:6 xg-cs-2.cs:11 -msgid "Thai (ภาษาไทย): สวัสดีครับ" -msgstr "" - -#: xg-cs-2.cs:7 xg-cs-2.cs:12 -msgid "Script: ð’ž" -msgstr "" - -#. And now a comment with РуÑÑкий and 日本語 and Unicode escapes: B\u00f6se B\u00fcbchen -#: xg-cs-2.cs:14 -msgid "This string has a multilingual comment" -msgstr "" -EOF - -: ${DIFF=diff} -${DIFF} xg-cs-2.ok xg-cs-2.po -result=$? - -exit $result diff --git a/gettext-tools/tests/xgettext-csharp-3 b/gettext-tools/tests/xgettext-csharp-3 deleted file mode 100755 index a2b94fcd1..000000000 --- a/gettext-tools/tests/xgettext-csharp-3 +++ /dev/null @@ -1,171 +0,0 @@ -#!/bin/sh -. "${srcdir=.}/init.sh"; path_prepend_ . ../src - -# More tests for C# support: string syntax - -LC_ALL=C tr '%' '\015' <<\EOF > xg-cs-3.cs -class TestCase { - public static void Main (String[] args) { - // Test recognition of \u escapes. - GetString ("B\u00f6se B\u00fcbchen"); - // \u escapes with more than one u are invalid. - GetString ("Japanese: \uu65e5\uuu672c\u8A9e"); - GetString ("embedded\nnewline"); - // Spaces from end of comment are removed. %GetString("dummy"); - // Two backslashes (unlike in Java, where this is just one backslash). - GetString ("\u005c\u005c"); - // A 6-character string (unlike in Java, where this is just one backslash). - GetString ("\\u005c"); - // A single backslash. - GetString ("\\"); - // There is only one \u recognition pass. - GetString ("\u005cu005c"); - // Octal escape sequences are not recognized, except for \0. - GetString ("\134"); - // Escape sequences in strings. - GetString ("t -> \t, b -> \b, n -> \n, dquote -> \", squote -> \' ..."); - // Hex escapes are recognized. - GetString ("bel: \x07\n"); - GetString // Recognized despite comments - ( /* Even across multiline -comment! */ "this is a single " /* now comes the concatenation! */ + // after + - "long line"); - // Verbatim string literals are extracted. - GetString (@"verbatim 1"); - // In verbatim string literals, no escape sequences are recognized. - GetString (@"verbatim 2 \u005c \\ \t \b \n \'"); - // In verbatim string literals, only doubled delimiters are recognized. - GetString (@"verbatim 3 ""test"); - // Normal and verbatim string literals can be concatenated. - GetString ("left - \"quot" + @"ation"" - right"); - // Character literals are not extracted. - GetString ('x'); - // Invalid concatenations are not concatenated. - GetString ("fooba"+'r'); - // Verify that a comma inside braces is hidden. - MyGetString (new Object[] { "don't", "fool", "me" }, "this is the second argument"); - } -} -EOF - -: ${XGETTEXT=xgettext} -# delete POT-Creation-Date: line because the date depends on local time. -${XGETTEXT} --output xg-cs-3.tmp --add-location -c -kMyGetString:2 xg-cs-3.cs 2>/dev/null || Exit 1 -sed -e '/\"POT-Creation-Date:.*/d' < xg-cs-3.tmp | LC_ALL=C tr -d '\r' > xg-cs-3.po || Exit 1 - -cat <<\EOF > xg-cs-3.ok -# SOME DESCRIPTIVE TITLE. -# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER -# This file is distributed under the same license as the PACKAGE package. -# FIRST AUTHOR , YEAR. -# -#, fuzzy -msgid "" -msgstr "" -"Project-Id-Version: PACKAGE VERSION\n" -"Report-Msgid-Bugs-To: \n" -"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" -"Last-Translator: FULL NAME \n" -"Language-Team: LANGUAGE \n" -"Language: \n" -"MIME-Version: 1.0\n" -"Content-Type: text/plain; charset=UTF-8\n" -"Content-Transfer-Encoding: 8bit\n" - -#. Test recognition of \u escapes. -#: xg-cs-3.cs:4 -msgid "Böse Bübchen" -msgstr "" - -#. \u escapes with more than one u are invalid. -#: xg-cs-3.cs:6 -msgid "Japanese: \\uu65e5\\uuu672c語" -msgstr "" - -#: xg-cs-3.cs:7 -msgid "" -"embedded\n" -"newline" -msgstr "" - -#. Spaces from end of comment are removed. -#: xg-cs-3.cs:8 -msgid "dummy" -msgstr "" - -#. Two backslashes (unlike in Java, where this is just one backslash). -#: xg-cs-3.cs:10 -msgid "\\\\" -msgstr "" - -#. A 6-character string (unlike in Java, where this is just one backslash). -#. There is only one \u recognition pass. -#: xg-cs-3.cs:12 xg-cs-3.cs:16 -msgid "\\u005c" -msgstr "" - -#. A single backslash. -#: xg-cs-3.cs:14 -msgid "\\" -msgstr "" - -#. Octal escape sequences are not recognized, except for \0. -#: xg-cs-3.cs:18 -msgid "\\134" -msgstr "" - -#. Escape sequences in strings. -#: xg-cs-3.cs:20 -msgid "" -"t -> \t, b -> \b, n -> \n" -", dquote -> \", squote -> ' ..." -msgstr "" - -#. Hex escapes are recognized. -#: xg-cs-3.cs:22 -msgid "bel: \a\n" -msgstr "" - -#. Recognized despite comments -#. Even across multiline -#. comment! -#: xg-cs-3.cs:25 -msgid "this is a single long line" -msgstr "" - -#. Verbatim string literals are extracted. -#: xg-cs-3.cs:28 -msgid "verbatim 1" -msgstr "" - -#. In verbatim string literals, no escape sequences are recognized. -#: xg-cs-3.cs:30 -msgid "verbatim 2 \\u005c \\\\ \\t \\b \\n \\'" -msgstr "" - -#. In verbatim string literals, only doubled delimiters are recognized. -#: xg-cs-3.cs:32 -msgid "verbatim 3 \"test" -msgstr "" - -#. Normal and verbatim string literals can be concatenated. -#: xg-cs-3.cs:34 -msgid "left - \"quotation\" - right" -msgstr "" - -#. Invalid concatenations are not concatenated. -#: xg-cs-3.cs:38 -msgid "fooba" -msgstr "" - -#. Verify that a comma inside braces is hidden. -#: xg-cs-3.cs:40 -msgid "this is the second argument" -msgstr "" -EOF - -: ${DIFF=diff} -${DIFF} xg-cs-3.ok xg-cs-3.po -result=$? - -exit $result diff --git a/gettext-tools/tests/xgettext-csharp-4 b/gettext-tools/tests/xgettext-csharp-4 deleted file mode 100755 index 1fc2ef0c6..000000000 --- a/gettext-tools/tests/xgettext-csharp-4 +++ /dev/null @@ -1,36 +0,0 @@ -#!/bin/sh -. "${srcdir=.}/init.sh"; path_prepend_ . ../src - -# Tests for C# plural keyword support - -cat < xg-cs-4.cs -class TestCase { - public static void Main (String[] args) { - GetPluralString("test 1", "plural test"); - MyPluralString (context, "I've 1", "you've lost"); - } -} -EOF - -: ${XGETTEXT=xgettext} -${XGETTEXT} --omit-header --no-location --keyword=MyPluralString:2,3 \ - -d xg-cs-4.tmp xg-cs-4.cs || Exit 1 -LC_ALL=C tr -d '\r' < xg-cs-4.tmp.po > xg-cs-4.po || Exit 1 - -cat < xg-cs-4.ok -msgid "test 1" -msgid_plural "plural test" -msgstr[0] "" -msgstr[1] "" - -msgid "I've 1" -msgid_plural "you've lost" -msgstr[0] "" -msgstr[1] "" -EOF - -: ${DIFF=diff} -${DIFF} xg-cs-4.ok xg-cs-4.po -result=$? - -exit $result diff --git a/gettext-tools/tests/xgettext-csharp-5 b/gettext-tools/tests/xgettext-csharp-5 deleted file mode 100755 index 2d6b0c41d..000000000 --- a/gettext-tools/tests/xgettext-csharp-5 +++ /dev/null @@ -1,56 +0,0 @@ -#!/bin/sh -. "${srcdir=.}/init.sh"; path_prepend_ . ../src - -# Test C# support: --add-comments option. - -cat < xg-cs-5.cs -// This comment will not be extracted. -Console.WriteLine(GetString("help")); -// TRANSLATORS: This is an extracted comment. -Console.WriteLine(GetString("me")); -/* Not extracted either. */ -Console.WriteLine(GetString("Hey Jude")); -/* TRANSLATORS: - Nickname of the Beatles -*/ -Console.WriteLine(GetString("The Fabulous Four")); -/* TRANSLATORS: The strings get concatenated. */ -Console.WriteLine(GetString("there is not enough" + -" room on a single line for this entire long, " // confusing, eh? -+ "verbose string")); -EOF - -: ${XGETTEXT=xgettext} -${XGETTEXT} --omit-header --no-location --add-comments=TRANSLATORS: \ - -d xg-cs-5.tmp xg-cs-5.cs || Exit 1 -LC_ALL=C tr -d '\r' < xg-cs-5.tmp.po > xg-cs-5.po || Exit 1 - -cat < xg-cs-5.ok -msgid "help" -msgstr "" - -#. TRANSLATORS: This is an extracted comment. -msgid "me" -msgstr "" - -msgid "Hey Jude" -msgstr "" - -#. TRANSLATORS: -#. Nickname of the Beatles -#. -msgid "The Fabulous Four" -msgstr "" - -#. TRANSLATORS: The strings get concatenated. -msgid "" -"there is not enough room on a single line for this entire long, verbose " -"string" -msgstr "" -EOF - -: ${DIFF=diff} -${DIFF} xg-cs-5.ok xg-cs-5.po -result=$? - -exit $result diff --git a/gettext-tools/tests/xgettext-csharp-6 b/gettext-tools/tests/xgettext-csharp-6 deleted file mode 100755 index 83cf7e529..000000000 --- a/gettext-tools/tests/xgettext-csharp-6 +++ /dev/null @@ -1,33 +0,0 @@ -#!/bin/sh -. "${srcdir=.}/init.sh"; path_prepend_ . ../src - -# Test C# support: --add-comments option. - -cat <<\EOF > xg-cs-6.cs -/* a */ -/* b */ string s = /* c */ -/* d */ -/* e */ _( /* f */ "hello " /* g */ + /* h */ "world" /* i */ ); -EOF - -: ${XGETTEXT=xgettext} -${XGETTEXT} --add-comments --omit-header --no-location --keyword=_ \ - -d xg-cs-6.tmp xg-cs-6.cs || Exit 1 -LC_ALL=C tr -d '\r' < xg-cs-6.tmp.po > xg-cs-6.po || Exit 1 - -cat < xg-cs-6.ok -#. a -#. b -#. c -#. d -#. e -#. f -msgid "hello world" -msgstr "" -EOF - -: ${DIFF=diff} -${DIFF} xg-cs-6.ok xg-cs-6.po -result=$? - -exit $result diff --git a/gettext-tools/tests/xgettext-csharp-7 b/gettext-tools/tests/xgettext-csharp-7 deleted file mode 100755 index 6cb31f20e..000000000 --- a/gettext-tools/tests/xgettext-csharp-7 +++ /dev/null @@ -1,28 +0,0 @@ -#! /bin/sh -. "${srcdir=.}/init.sh"; path_prepend_ . ../src - -# Test C# support: extraction of contexts. - -cat <<\EOF > xg-cs-7.cs -Console.WriteLine(rm.GetString("help")); -Console.WriteLine(rm.GetParticularString("Help", "about")); -EOF - -: ${XGETTEXT=xgettext} -${XGETTEXT} --omit-header --no-location -d xg-cs-7.tmp xg-cs-7.cs || Exit 1 -LC_ALL=C tr -d '\r' < xg-cs-7.tmp.po > xg-cs-7.po || Exit 1 - -cat < xg-cs-7.ok -msgid "help" -msgstr "" - -msgctxt "Help" -msgid "about" -msgstr "" -EOF - -: ${DIFF=diff} -${DIFF} xg-cs-7.ok xg-cs-7.po -result=$? - -exit $result diff --git a/gettext-tools/tests/xgettext-csharp-8 b/gettext-tools/tests/xgettext-csharp-8 deleted file mode 100755 index d1c0df1e3..000000000 --- a/gettext-tools/tests/xgettext-csharp-8 +++ /dev/null @@ -1,66 +0,0 @@ -#! /bin/sh -. "${srcdir=.}/init.sh"; path_prepend_ . ../src - -# Test C# support: Unicode character escape handling - -cat <<\EOF > xg-cs-8.cs -// Valid: -string s1 = "\U00020213"; // Codepoint U+20213 -string s2 = "\uD840\uDE13"; // Encoded form of U+20213 -string s3 = "\uD840\U0000DE13"; // Encoded form of U+20213 -string s4 = "\U0000D840\uDE13"; // Encoded form of U+20213 -string s5 = "\U0000D840\U0000DE13"; // Encoded form of U+20213 -string s6 = "\xD840\xDE13"; // Encoded form of U+20213 - -// Invalid: -string i1 = "\U0020213"; // Unterminated -string i2 = "\uD840\u3032"; // Missing low surrogate -string i3 = "\uD840\uDE1"; // Unterminated after a high surrogate -EOF - -: ${XGETTEXT=xgettext} -${XGETTEXT} --output xg-cs-8.tmp --add-location xg-cs-8.cs -a 2>/dev/null || Exit 1 -sed -e '/\"POT-Creation-Date:.*/d' < xg-cs-8.tmp | LC_ALL=C tr -d '\r' > xg-cs-8.po || Exit 1 - -cat <<\EOF > xg-cs-8.ok -# SOME DESCRIPTIVE TITLE. -# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER -# This file is distributed under the same license as the PACKAGE package. -# FIRST AUTHOR , YEAR. -# -#, fuzzy -msgid "" -msgstr "" -"Project-Id-Version: PACKAGE VERSION\n" -"Report-Msgid-Bugs-To: \n" -"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" -"Last-Translator: FULL NAME \n" -"Language-Team: LANGUAGE \n" -"Language: \n" -"MIME-Version: 1.0\n" -"Content-Type: text/plain; charset=UTF-8\n" -"Content-Transfer-Encoding: 8bit\n" - -#: xg-cs-8.cs:2 xg-cs-8.cs:3 xg-cs-8.cs:4 xg-cs-8.cs:5 xg-cs-8.cs:6 -#: xg-cs-8.cs:7 -msgid "𠈓" -msgstr "" - -#: xg-cs-8.cs:10 -msgid "\\U0020213" -msgstr "" - -#: xg-cs-8.cs:11 -msgid "�〲" -msgstr "" - -#: xg-cs-8.cs:12 -msgid "�\\uDE1" -msgstr "" -EOF - -: ${DIFF=diff} -${DIFF} xg-cs-8.ok xg-cs-8.po -result=$? - -exit $result diff --git a/gettext-tools/tests/xgettext-java-1 b/gettext-tools/tests/xgettext-java-1 deleted file mode 100755 index 53fb5ee0f..000000000 --- a/gettext-tools/tests/xgettext-java-1 +++ /dev/null @@ -1,61 +0,0 @@ -#!/bin/sh -. "${srcdir=.}/init.sh"; path_prepend_ . ../src -# -# Some tests for java support -# - -cat < xg-j-1.java -class TestCase { - public TestCase() { - ResourceBundle b = ResourceBundle.getBundle("test"); - GetTextBundle b2 = (GetTextBundle)b; - // standard usage - String test1 = b.getString("Test String 1"); - // gettext usage - String test2 = b2.gettext("Test String 2"); - - /* C style comment */ - String test3 = b.getString("Test String 3"); - - // java "multiline" string - String test4 = b.getString("Test " + - "String " + - "4"); - - // empty string - String test5 = b.getString(""); - } -} -EOF - -: ${XGETTEXT=xgettext} -${XGETTEXT} --omit-header --no-location -c -d xg-j-1.tmp xg-j-1.java || Exit 1 -LC_ALL=C tr -d '\r' < xg-j-1.tmp.po > xg-j-1.po || Exit 1 - -cat < xg-j-1.ok -#. standard usage -msgid "Test String 1" -msgstr "" - -#. gettext usage -msgid "Test String 2" -msgstr "" - -#. C style comment -msgid "Test String 3" -msgstr "" - -#. java "multiline" string -msgid "Test String 4" -msgstr "" - -#. empty string -msgid "" -msgstr "" -EOF - -: ${DIFF=diff} -${DIFF} xg-j-1.ok xg-j-1.po -result=$? - -exit $result diff --git a/gettext-tools/tests/xgettext-java-2 b/gettext-tools/tests/xgettext-java-2 deleted file mode 100755 index 4fb7816ad..000000000 --- a/gettext-tools/tests/xgettext-java-2 +++ /dev/null @@ -1,222 +0,0 @@ -#!/bin/sh -. "${srcdir=.}/init.sh"; path_prepend_ . ../src -# -# More tests for java support -# - -cat <<\EOF > xg-j-2.java -class TestCase { - public static void main (String[] args) { - // Test recognition of \u escapes: Böse Bübchen - gettext ("B\u00f6se B\u00fcbchen"); - // Test recognition of \u escapes with different number of u - gettext ("Japanese: \uu65e5\uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu672c\u8A9e"); - // Test recognition of \u escapes when they form UTF-16 surrogates - // Here: U+1D49E MATHEMATICAL SCRIPT CAPITAL C - gettext ("script \ud835\udc9e = ..."); - // Test invalid surrogates. - gettext ("invalid surrogate \ud835 first half"); - gettext ("invalid surrogate \udc9e second half"); - // Don't let the line numbers be confused by \u newlines. - \u000a \u000d \u000d\u000a - gettext ("embedded\nnewline"); - // Spaces from end of comment are removed. \u000agettext("dummy"); - // Various ways to write a backslash are equivalent. - gettext ("\u005c\u005c"); - gettext ("\u005c\"); - gettext ("\\u005c"); - gettext ("\\"); - gettext ("\134"); - // Escape sequences in strings. - gettext ("t -> \t, b -> \b, n -> \n, dquote -> \", squote -> \' ..."); - // Octal escapes have 2 or 3 digits, depending on the initial digit. - gettext ("bel: \7\nnewline: \12backslash: \134\ndquote-zero: \420\n"); - // Hex escapes are not recognized - gettext ("no bel: \x07\n"); - gettext // Recognized despite comments - ( /* Even across multiline -comment! */ "this is a single " /* now comes the concatenation! */ + // after + - "long line"); - // Character literals are not extracted. - gettext ('x'); - // Invalid concatenations are not concatenated. - gettext ("fooba"+'r'); - // Verify that the static function name has priority. - GettextResource.gettext("NOT extracted", "this one is extracted"); - // Verify that a comma inside braces is hidden. - GettextResource.gettext( - new Object() { - public int foo () { - return 5, 8; - } - }, - "this is the second argument"); - // Text blocks are extracted. - gettext (""" - a one-liner block """); - gettext (""" - ibam forte via sacra sicut meus est mos - nescio quid meditans nugarum totus in illis - - accurrit quidam notus mihi nomine tantum - arreptaque manu "quid agis, dulcissime rerum?" - """); - gettext (""" - \"""a text block in a text block\""" """); - gettext (""" - testing mixed ASCII and Unicode whitespace - \u0020 line 2 - \u0020line 3 - \u0020line 4 - and trailing whitespace - as well \u0020 - also in the last line\u0020""" - ); - } -} -EOF - -: ${XGETTEXT=xgettext} -${XGETTEXT} --from-code=ISO-8859-1 -c -o xg-j-2.tmp xg-j-2.java 2>/dev/null || Exit 1 -# Don't simplify this to "grep ... < xg-j-2.tmp", otherwise OpenBSD 4.0 grep -# only outputs "Binary file (standard input) matches". -cat xg-j-2.tmp | grep -v 'POT-Creation-Date' | LC_ALL=C tr -d '\r' > xg-j-2.pot - -cat <<\EOF > xg-j-2.ok -# SOME DESCRIPTIVE TITLE. -# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER -# This file is distributed under the same license as the PACKAGE package. -# FIRST AUTHOR , YEAR. -# -#, fuzzy -msgid "" -msgstr "" -"Project-Id-Version: PACKAGE VERSION\n" -"Report-Msgid-Bugs-To: \n" -"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" -"Last-Translator: FULL NAME \n" -"Language-Team: LANGUAGE \n" -"Language: \n" -"MIME-Version: 1.0\n" -"Content-Type: text/plain; charset=UTF-8\n" -"Content-Transfer-Encoding: 8bit\n" - -#. Test recognition of \u escapes: Böse Bübchen -#: xg-j-2.java:4 -msgid "Böse Bübchen" -msgstr "" - -#. Test recognition of \u escapes with different number of u -#: xg-j-2.java:6 -msgid "Japanese: 日本語" -msgstr "" - -#. Test recognition of \u escapes when they form UTF-16 surrogates -#. Here: U+1D49E MATHEMATICAL SCRIPT CAPITAL C -#: xg-j-2.java:9 -msgid "script ð’ž = ..." -msgstr "" - -#. Test invalid surrogates. -#: xg-j-2.java:11 -msgid "invalid surrogate � first half" -msgstr "" - -#: xg-j-2.java:12 -msgid "invalid surrogate � second half" -msgstr "" - -#. Don't let the line numbers be confused by \u newlines. -#: xg-j-2.java:15 -msgid "" -"embedded\n" -"newline" -msgstr "" - -#. Spaces from end of comment are removed. -#: xg-j-2.java:16 -msgid "dummy" -msgstr "" - -#. Various ways to write a backslash are equivalent. -#: xg-j-2.java:18 xg-j-2.java:19 xg-j-2.java:20 xg-j-2.java:21 xg-j-2.java:22 -msgid "\\" -msgstr "" - -#. Escape sequences in strings. -#: xg-j-2.java:24 -msgid "" -"t -> \t, b -> \b, n -> \n" -", dquote -> \", squote -> ' ..." -msgstr "" - -#. Octal escapes have 2 or 3 digits, depending on the initial digit. -#: xg-j-2.java:26 -msgid "" -"bel: \a\n" -"newline: \n" -"backslash: \\\n" -"dquote-zero: \"0\n" -msgstr "" - -#. Hex escapes are not recognized -#: xg-j-2.java:28 -msgid "no bel: \\x07\n" -msgstr "" - -#. Recognized despite comments -#. Even across multiline -#. comment! -#: xg-j-2.java:31 -msgid "this is a single long line" -msgstr "" - -#. Invalid concatenations are not concatenated. -#: xg-j-2.java:36 -msgid "fooba" -msgstr "" - -#. Verify that the static function name has priority. -#: xg-j-2.java:38 -msgid "this one is extracted" -msgstr "" - -#: xg-j-2.java:46 -msgid "this is the second argument" -msgstr "" - -#. Text blocks are extracted. -#: xg-j-2.java:48 -msgid "a one-liner block" -msgstr "" - -#: xg-j-2.java:50 -msgid "" -"ibam forte via sacra sicut meus est mos\n" -"nescio quid meditans nugarum totus in illis\n" -"\n" -"accurrit quidam notus mihi nomine tantum\n" -"arreptaque manu \"quid agis, dulcissime rerum?\"\n" -msgstr "" - -#: xg-j-2.java:57 -msgid "\"\"\"a text block in a text block\"\"\"" -msgstr "" - -#: xg-j-2.java:59 -msgid "" -"testing mixed ASCII and Unicode whitespace\n" -"line 2\n" -"line 3\n" -" line 4\n" -"and trailing whitespace\n" -"as well\n" -"also in the last line" -msgstr "" -EOF - -: ${DIFF=diff} -${DIFF} xg-j-2.ok xg-j-2.pot -result=$? - -exit $result diff --git a/gettext-tools/tests/xgettext-java-3 b/gettext-tools/tests/xgettext-java-3 deleted file mode 100755 index b10ccaa7e..000000000 --- a/gettext-tools/tests/xgettext-java-3 +++ /dev/null @@ -1,31 +0,0 @@ -#!/bin/sh -. "${srcdir=.}/init.sh"; path_prepend_ . ../src -# -# Some tests for java plural keyword support -# - -cat < xg-j-3.java -class TestCase { - public TestCase() { - Bundle test = Bundle.getBundle(); - test.ngettext("test 1", "plural test"); - } -} -EOF - -: ${XGETTEXT=xgettext} -${XGETTEXT} --omit-header --no-location -d xg-j-3.tmp xg-j-3.java || Exit 1 -LC_ALL=C tr -d '\r' < xg-j-3.tmp.po > xg-j-3.po || Exit 1 - -cat < xg-j-3.ok -msgid "test 1" -msgid_plural "plural test" -msgstr[0] "" -msgstr[1] "" -EOF - -: ${DIFF=diff} -${DIFF} xg-j-3.ok xg-j-3.po -result=$? - -exit $result diff --git a/gettext-tools/tests/xgettext-java-4 b/gettext-tools/tests/xgettext-java-4 deleted file mode 100755 index 321eadaeb..000000000 --- a/gettext-tools/tests/xgettext-java-4 +++ /dev/null @@ -1,32 +0,0 @@ -#!/bin/sh -. "${srcdir=.}/init.sh"; path_prepend_ . ../src -# -# Some tests for java plural keyword support -# - -cat < xg-j-4.java -class TestCase { - public TestCase() { - Bundle test = Bundle.getBundle(); - test.ngettext(test, "test 1", "plural test"); - } -} -EOF - -: ${XGETTEXT=xgettext} -${XGETTEXT} --omit-header --no-location --keyword=ngettext:2,3 \ - -d xg-j-4.tmp xg-j-4.java || Exit 1 -LC_ALL=C tr -d '\r' < xg-j-4.tmp.po > xg-j-4.po || Exit 1 - -cat < xg-j-4.ok -msgid "test 1" -msgid_plural "plural test" -msgstr[0] "" -msgstr[1] "" -EOF - -: ${DIFF=diff} -${DIFF} xg-j-4.ok xg-j-4.po -result=$? - -exit $result diff --git a/gettext-tools/tests/xgettext-java-5 b/gettext-tools/tests/xgettext-java-5 deleted file mode 100755 index bd9587fbf..000000000 --- a/gettext-tools/tests/xgettext-java-5 +++ /dev/null @@ -1,56 +0,0 @@ -#!/bin/sh -. "${srcdir=.}/init.sh"; path_prepend_ . ../src - -# Test Java support: --add-comments option. - -cat < xg-j-5.java -// This comment will not be extracted. -System.out.println(gettext("help")); -// TRANSLATORS: This is an extracted comment. -System.out.println(gettext("me")); -/* Not extracted either. */ -System.out.println(gettext("Hey Jude")); -/* TRANSLATORS: - Nickname of the Beatles -*/ -System.out.println(gettext("The Fabulous Four")); -/* TRANSLATORS: The strings get concatenated. */ -System.out.println(gettext("there is not enough" + -" room on a single line for this entire long, " // confusing, eh? -+ "verbose string")); -EOF - -: ${XGETTEXT=xgettext} -${XGETTEXT} --omit-header --no-location --add-comments=TRANSLATORS: \ - -d xg-j-5.tmp xg-j-5.java || Exit 1 -LC_ALL=C tr -d '\r' < xg-j-5.tmp.po > xg-j-5.po || Exit 1 - -cat < xg-j-5.ok -msgid "help" -msgstr "" - -#. TRANSLATORS: This is an extracted comment. -msgid "me" -msgstr "" - -msgid "Hey Jude" -msgstr "" - -#. TRANSLATORS: -#. Nickname of the Beatles -#. -msgid "The Fabulous Four" -msgstr "" - -#. TRANSLATORS: The strings get concatenated. -msgid "" -"there is not enough room on a single line for this entire long, verbose " -"string" -msgstr "" -EOF - -: ${DIFF=diff} -${DIFF} xg-j-5.ok xg-j-5.po -result=$? - -exit $result diff --git a/gettext-tools/tests/xgettext-java-6 b/gettext-tools/tests/xgettext-java-6 deleted file mode 100755 index 066cfca4e..000000000 --- a/gettext-tools/tests/xgettext-java-6 +++ /dev/null @@ -1,33 +0,0 @@ -#!/bin/sh -. "${srcdir=.}/init.sh"; path_prepend_ . ../src - -# Test Java support: --add-comments option. - -cat <<\EOF > xg-j-6.java -/* a */ -/* b */ String string = /* c */ -/* d */ -/* e */ _( /* f */ "hello " /* g */ + /* h */ "world" /* i */ ); -EOF - -: ${XGETTEXT=xgettext} -${XGETTEXT} --add-comments --omit-header --no-location --keyword=_ \ - -d xg-j-6.tmp xg-j-6.java || Exit 1 -LC_ALL=C tr -d '\r' < xg-j-6.tmp.po > xg-j-6.po || Exit 1 - -cat < xg-j-6.ok -#. a -#. b -#. c -#. d -#. e -#. f -msgid "hello world" -msgstr "" -EOF - -: ${DIFF=diff} -${DIFF} xg-j-6.ok xg-j-6.po -result=$? - -exit $result diff --git a/gettext-tools/tests/xgettext-java-7 b/gettext-tools/tests/xgettext-java-7 deleted file mode 100755 index b61680cf8..000000000 --- a/gettext-tools/tests/xgettext-java-7 +++ /dev/null @@ -1,29 +0,0 @@ -#! /bin/sh -. "${srcdir=.}/init.sh"; path_prepend_ . ../src - -# Test Java support: extraction of contexts. - -cat <<\EOF > xg-j-7.java -import gnu.gettext.GettextResourceBundle; -System.out.println(GettextResourceBundle.gettext("help")); -System.out.println(GettextResourceBundle.pgettext("Help", "about")); -EOF - -: ${XGETTEXT=xgettext} -${XGETTEXT} --omit-header --no-location -d xg-j-7.tmp xg-j-7.java || Exit 1 -LC_ALL=C tr -d '\r' < xg-j-7.tmp.po > xg-j-7.po || Exit 1 - -cat < xg-j-7.ok -msgid "help" -msgstr "" - -msgctxt "Help" -msgid "about" -msgstr "" -EOF - -: ${DIFF=diff} -${DIFF} xg-j-7.ok xg-j-7.po -result=$? - -exit $result diff --git a/gettext-tools/woe32dll/gettextsrc-exports.c b/gettext-tools/woe32dll/gettextsrc-exports.c index 4477ae8d4..d51f4bb79 100644 --- a/gettext-tools/woe32dll/gettextsrc-exports.c +++ b/gettext-tools/woe32dll/gettextsrc-exports.c @@ -28,12 +28,9 @@ VARIABLE(format_language_pretty) VARIABLE(formatstring_awk) VARIABLE(formatstring_boost) VARIABLE(formatstring_c) -VARIABLE(formatstring_csharp) VARIABLE(formatstring_elisp) VARIABLE(formatstring_gcc_internal) VARIABLE(formatstring_gfc_internal) -VARIABLE(formatstring_java) -VARIABLE(formatstring_java_printf) VARIABLE(formatstring_javascript) VARIABLE(formatstring_kde) VARIABLE(formatstring_kde_kuit) diff --git a/gnulib-local/Makefile.am b/gnulib-local/Makefile.am index 9247c1c19..8c590dc17 100644 --- a/gnulib-local/Makefile.am +++ b/gnulib-local/Makefile.am @@ -157,7 +157,6 @@ lib/xmalloc.c \ lib/xstrdup.c \ m4/alloca.m4 \ m4/backupfile.m4 \ -m4/java.m4 \ m4/libxml.m4 \ m4/unionwait.m4 \ modules/backupfile \ @@ -168,7 +167,6 @@ modules/fnmatch.diff \ modules/gettext-runtime-misc \ modules/gettext-tools-misc \ modules/hash \ -modules/java \ modules/libtextstyle-dummy \ modules/libxml \ modules/markup \ diff --git a/gnulib-local/m4/java.m4 b/gnulib-local/m4/java.m4 deleted file mode 100644 index 1ad7fc18c..000000000 --- a/gnulib-local/m4/java.m4 +++ /dev/null @@ -1,17 +0,0 @@ -# java.m4 serial 2 -dnl Copyright (C) 2005, 2017 Free Software Foundation, Inc. -dnl This file is free software; the Free Software Foundation -dnl gives unlimited permission to copy and/or distribute it, -dnl with or without modifications, as long as this notice is preserved. - -# Sets JAVA_CHOICE to 'yes' or 'no', depending on the preferred use of Java. -AC_DEFUN([gt_JAVA_CHOICE], -[ - AC_MSG_CHECKING([whether to use Java]) - AC_ARG_ENABLE(java, - [ --disable-java do not build Java sources], - [JAVA_CHOICE="$enableval"], - [JAVA_CHOICE=yes]) - AC_MSG_RESULT([$JAVA_CHOICE]) - AC_SUBST([JAVA_CHOICE]) -]) diff --git a/gnulib-local/modules/java b/gnulib-local/modules/java deleted file mode 100644 index ca1cb0e1c..000000000 --- a/gnulib-local/modules/java +++ /dev/null @@ -1,21 +0,0 @@ -Description: -Find user preferences regarding the use of Java. - -Files: -m4/java.m4 - -Depends-on: - -configure.ac: -gt_JAVA_CHOICE - -Makefile.am: - -Include: - -License: -GPL - -Maintainer: -Bruno Haible - diff --git a/m4/libtool.m4 b/m4/libtool.m4 index 38b31b8e3..72a818e8d 100644 --- a/m4/libtool.m4 +++ b/m4/libtool.m4 @@ -826,7 +826,6 @@ m4_case([$1], [C], [_LT_LANG(C)], [C++], [_LT_LANG(CXX)], [Go], [_LT_LANG(GO)], - [Java], [_LT_LANG(GCJ)], [Fortran 77], [_LT_LANG(F77)], [Fortran], [_LT_LANG(FC)], [Windows Resource], [_LT_LANG(RC)], @@ -915,7 +914,6 @@ AC_PROVIDE_IFELSE([LT_PROG_RC], AU_DEFUN([AC_LIBTOOL_CXX], [LT_LANG(C++)]) AU_DEFUN([AC_LIBTOOL_F77], [LT_LANG(Fortran 77)]) AU_DEFUN([AC_LIBTOOL_FC], [LT_LANG(Fortran)]) -AU_DEFUN([AC_LIBTOOL_GCJ], [LT_LANG(Java)]) AU_DEFUN([AC_LIBTOOL_RC], [LT_LANG(Windows Resource)]) dnl aclocal-1.4 backwards compatibility: dnl AC_DEFUN([AC_LIBTOOL_CXX], []) @@ -7921,78 +7919,6 @@ fi # test yes != "$_lt_disable_FC" AC_LANG_POP ])# _LT_LANG_FC_CONFIG - -# _LT_LANG_GCJ_CONFIG([TAG]) -# -------------------------- -# Ensure that the configuration variables for the GNU Java Compiler compiler -# are suitably defined. These variables are subsequently used by _LT_CONFIG -# to write the compiler configuration to 'libtool'. -m4_defun([_LT_LANG_GCJ_CONFIG], -[AC_REQUIRE([LT_PROG_GCJ])dnl -AC_LANG_SAVE - -# Source file extension for Java test sources. -ac_ext=java - -# Object file extension for compiled Java test sources. -objext=o -_LT_TAGVAR(objext, $1)=$objext - -# Code to be used in simple compile tests -lt_simple_compile_test_code="class foo {}" - -# Code to be used in simple link tests -lt_simple_link_test_code='public class conftest { public static void main(String[[]] argv) {}; }' - -# ltmain only uses $CC for tagged configurations so make sure $CC is set. -_LT_TAG_COMPILER - -# save warnings/boilerplate of simple test code -_LT_COMPILER_BOILERPLATE -_LT_LINKER_BOILERPLATE - -# Allow CC to be a program name with arguments. -lt_save_CC=$CC -lt_save_CFLAGS=$CFLAGS -lt_save_GCC=$GCC -GCC=yes -CC=${GCJ-"gcj"} -CFLAGS=$GCJFLAGS -compiler=$CC -_LT_TAGVAR(compiler, $1)=$CC -_LT_TAGVAR(LD, $1)=$LD -_LT_CC_BASENAME([$compiler]) - -# GCJ did not exist at the time GCC didn't implicitly link libc in. -_LT_TAGVAR(archive_cmds_need_lc, $1)=no - -_LT_TAGVAR(old_archive_cmds, $1)=$old_archive_cmds -_LT_TAGVAR(reload_flag, $1)=$reload_flag -_LT_TAGVAR(reload_cmds, $1)=$reload_cmds - -## CAVEAT EMPTOR: -## There is no encapsulation within the following macros, do not change -## the running order or otherwise move them around unless you know exactly -## what you are doing... -if test -n "$compiler"; then - _LT_COMPILER_NO_RTTI($1) - _LT_COMPILER_PIC($1) - _LT_COMPILER_C_O($1) - _LT_COMPILER_FILE_LOCKS($1) - _LT_LINKER_SHLIBS($1) - _LT_LINKER_HARDCODE_LIBPATH($1) - - _LT_CONFIG($1) -fi - -AC_LANG_RESTORE - -GCC=$lt_save_GCC -CC=$lt_save_CC -CFLAGS=$lt_save_CFLAGS -])# _LT_LANG_GCJ_CONFIG - - # _LT_LANG_GO_CONFIG([TAG]) # -------------------------- # Ensure that the configuration variables for the GNU Go compiler -- 2.21.0