import gettext-0.21-8.el9

c9-beta imports/c9-beta/gettext-0.21-8.el9
MSVSphere Packaging Team 1 year ago
commit d1f08aa9be

@ -0,0 +1 @@
9d75b47baed1a612c0120991c4b6d9cf95e0d430 SOURCES/gettext-0.21.tar.xz

1
.gitignore vendored

@ -0,0 +1 @@
SOURCES/gettext-0.21.tar.xz

@ -0,0 +1,68 @@
diff --git a/gettext-tools/src/msgl-cat.c b/gettext-tools/src/msgl-cat.c
index 990d39e..9814502 100644
--- a/gettext-tools/src/msgl-cat.c
+++ b/gettext-tools/src/msgl-cat.c
@@ -306,6 +306,7 @@ catenate_msgdomain_list (string_list_ty *file_list,
mp->msgid);
multiline_error (xstrdup (""),
xasprintf ("%s\n", errormsg));
+ free (errormsg);
}
}
else
diff --git a/gettext-tools/src/x-csharp.c b/gettext-tools/src/x-csharp.c
index 5cf72ad..7a0e5d3 100644
--- a/gettext-tools/src/x-csharp.c
+++ b/gettext-tools/src/x-csharp.c
@@ -560,6 +560,7 @@ comment_line_end (size_t chars_to_remove)
buffer[buflen] = '\0';
savable_comment_add (buffer);
lexical_context = lc_outside;
+ free (buffer);
}
diff --git a/gettext-tools/src/x-java.c b/gettext-tools/src/x-java.c
index eff1e6f..7e1bb78 100644
--- a/gettext-tools/src/x-java.c
+++ b/gettext-tools/src/x-java.c
@@ -460,6 +460,7 @@ comment_line_end (size_t chars_to_remove)
--buflen;
buffer[buflen] = '\0';
savable_comment_add (buffer);
+ free (buffer);
}
diff --git a/gettext-tools/src/x-rst.c b/gettext-tools/src/x-rst.c
index cde1ee6..fca441e 100644
--- a/gettext-tools/src/x-rst.c
+++ b/gettext-tools/src/x-rst.c
@@ -651,6 +651,7 @@ extract_rsj (FILE *f,
else
goto invalid_rsj;
+ free (s1);
/* Parse a comma. */
c = phase2_getc ();
if (c == '}')
@@ -667,6 +668,7 @@ extract_rsj (FILE *f,
fp = NULL;
real_file_name = NULL;
+ free (logical_file_name);
logical_file_name = NULL;
line_number = 0;
diff --git a/gettext-tools/src/xg-arglist-callshape.c b/gettext-tools/src/xg-arglist-callshape.c
index 06b7076..2189aac 100644
--- a/gettext-tools/src/xg-arglist-callshape.c
+++ b/gettext-tools/src/xg-arglist-callshape.c
@@ -118,6 +118,7 @@ split_keywordspec (const char *spec,
memcpy (xcomment, xcomment_start, xcomment_len);
xcomment[xcomment_len] = '\0';
string_list_append (&xcomments, xcomment);
+ free (xcomment);
}
else
break;

@ -0,0 +1,128 @@
diff --git a/Makefile.am b/Makefile.am
index 815e3c7..e897de7 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -19,7 +19,7 @@
AUTOMAKE_OPTIONS = 1.5 gnu no-dependencies
ACLOCAL_AMFLAGS = -I m4
-SUBDIRS = gnulib-local gettext-runtime libtextstyle gettext-tools
+SUBDIRS = gnulib-local gettext-runtime gettext-tools
changelog_etc = \
gettext-runtime/ChangeLog.0 \
@@ -123,7 +123,6 @@ distcheck-hook:
test "`sed 1,16d $(srcdir)/gettext-runtime/intl/xsize.h | md5sum`" = "`sed 1,16d $(srcdir)/gettext-tools/gnulib-lib/xsize.h | md5sum`"
cmp -s $(srcdir)/gettext-runtime/man/help2man $(srcdir)/gettext-tools/man/help2man
cmp -s $(srcdir)/gettext-runtime/man/x-to-1.in $(srcdir)/gettext-tools/man/x-to-1.in
- cmp -s $(srcdir)/libtextstyle/m4/libtextstyle.m4 $(srcdir)/gettext-tools/gnulib-m4/libtextstyle.m4
cmp -s $(srcdir)/gettext-tools/examples/hello-java-awt/m4/TestAWT.java $(srcdir)/gettext-tools/examples/hello-java-swing/m4/TestAWT.java
cmp -s $(srcdir)/gettext-tools/examples/hello-java-awt/m4/TestAWT.class $(srcdir)/gettext-tools/examples/hello-java-swing/m4/TestAWT.class
test "`sed 1,15d $(srcdir)/gnulib-local/lib/alloca.in.h | md5sum`" = "`sed 1,15d $(srcdir)/gettext-runtime/libasprintf/alloca.in.h | md5sum`"
diff --git a/configure.ac b/configure.ac
index 49689fb..2d23b44 100644
--- a/configure.ac
+++ b/configure.ac
@@ -37,7 +37,7 @@ dnl Checks for typedefs, structures, and compiler characteristics.
dnl Checks for library functions.
-AC_CONFIG_SUBDIRS([gettext-runtime libtextstyle gettext-tools])
+AC_CONFIG_SUBDIRS([gettext-runtime gettext-tools])
AM_EXTRA_RECURSIVE_TARGETS([maintainer-update-po])
@@ -49,7 +49,7 @@ AC_CANONICAL_HOST
dnl Optional Features: AC_ARG_ENABLE calls
dnl Optional Packages: AC_ARG_WITH calls
dnl Some influential environment variables: AC_ARG_VAR calls
-esyscmd([{ cd gettext-runtime && autoconf --trace=AC_ARG_ENABLE:'$n([$1],[$2])' --trace=AC_ARG_WITH:'$n([$1],[$2])' --trace=AC_ARG_VAR:'$n($@)' && cd ..; cd libtextstyle && autoconf --trace=AC_ARG_ENABLE:'$n([$1],[$2])' --trace=AC_ARG_WITH:'$n([$1],[$2])' --trace=AC_ARG_VAR:'$n($@)' && cd ..; { cd gettext-tools && autoconf --trace=AC_ARG_ENABLE:'$n([$1],[$2])' --trace=AC_ARG_WITH:'$n([$1],[$2])' --trace=AC_ARG_VAR:'$n($@)' && cd ..; } | grep -v installed.libtextstyle | grep -v installed.csharp | grep -v 'installed C#'; } | sed -f build-aux/ac-help.sed ])
+esyscmd([{ cd gettext-runtime && autoconf --trace=AC_ARG_ENABLE:'$n([$1],[$2])' --trace=AC_ARG_WITH:'$n([$1],[$2])' --trace=AC_ARG_VAR:'$n($@)' && cd ..; { cd gettext-tools && autoconf --trace=AC_ARG_ENABLE:'$n([$1],[$2])' --trace=AC_ARG_WITH:'$n([$1],[$2])' --trace=AC_ARG_VAR:'$n($@)' && cd ..; } | grep -v installed.csharp | grep -v 'installed C#'; } | sed -f build-aux/ac-help.sed ])
AC_CONFIG_FILES([Makefile])
diff --git a/gettext-tools/Makefile.am b/gettext-tools/Makefile.am
index 449a797..c5719c2 100644
--- a/gettext-tools/Makefile.am
+++ b/gettext-tools/Makefile.am
@@ -19,7 +19,7 @@
AUTOMAKE_OPTIONS = 1.5 gnu no-dependencies
ACLOCAL_AMFLAGS = -I m4 -I ../gettext-runtime/m4 -I ../m4 -I gnulib-m4 -I libgrep/gnulib-m4 -I libgettextpo/gnulib-m4
-SUBDIRS = intl gnulib-lib libgrep src libgettextpo po its projects styles emacs misc man m4 tests system-tests gnulib-tests examples doc
+SUBDIRS = intl gnulib-lib libgrep libgettextpo src po its projects styles emacs misc man m4 tests system-tests gnulib-tests examples doc
EXTRA_DIST = misc/DISCLAIM
MOSTLYCLEANFILES = core *.stackdump
diff --git a/gettext-tools/libgettextpo/textstyle.in.h b/gettext-tools/libgettextpo/textstyle.in.h
index 536b51b..585ce66 100644
--- a/gettext-tools/libgettextpo/textstyle.in.h
+++ b/gettext-tools/libgettextpo/textstyle.in.h
@@ -213,7 +213,8 @@ typedef ostream_t file_ostream_t;
static inline file_ostream_t
file_ostream_create (FILE *fp)
{
- return fp;
+ /* Closing the stream we return should not close 'fp'. */
+ return fdopen (dup (fileno (fp)), "w");
}
/* --------------------------- From fd-ostream.h --------------------------- */
@@ -413,6 +414,30 @@ html_styled_ostream_create (ostream_t destination _GL_UNUSED,
return NULL;
}
+/* ----------------------- From noop-styled-ostream.h ----------------------- */
+
+/* noop_styled_ostream_t is a subtype of ostream_t. */
+typedef ostream_t noop_styled_ostream_t;
+
+#define noop_styled_ostream_write_mem ostream_write_mem
+#define noop_styled_ostream_flush ostream_flush
+#define noop_styled_ostream_free ostream_free
+#define noop_styled_ostream_begin_use_class styled_ostream_begin_use_class
+#define noop_styled_ostream_end_use_class styled_ostream_end_use_class
+#define noop_styled_ostream_get_hyperlink_ref styled_ostream_get_hyperlink_ref
+#define noop_styled_ostream_get_hyperlink_id styled_ostream_get_hyperlink_id
+#define noop_styled_ostream_set_hyperlink styled_ostream_set_hyperlink
+#define noop_styled_ostream_flush_to_current_style styled_ostream_flush_to_current_style
+
+static inline ostream_t
+noop_styled_ostream_create (ostream_t destination, bool pass_ownership)
+{
+ if (pass_ownership)
+ return destination;
+ else
+ return fdopen (dup (fileno (destination)), "w");
+}
+
/* ------------------------------ From color.h ------------------------------ */
#define color_test_mode false
diff --git a/gettext-tools/src/Makefile.am b/gettext-tools/src/Makefile.am
index 764ffad..eccfbbd 100644
--- a/gettext-tools/src/Makefile.am
+++ b/gettext-tools/src/Makefile.am
@@ -292,19 +292,9 @@ cldr_plurals_SOURCES = cldr-plural.y cldr-plural-exp.c cldr-plurals.c
cldr_plurals_CFLAGS = $(AM_CFLAGS) $(INCXML)
cldr_plurals_LDADD = libgettextsrc.la $(LDADD)
-if USE_INSTALLED_LIBTEXTSTYLE
-LT_LIBTEXTSTYLE = @LTLIBTEXTSTYLE@
-else
-# How to get the include files of libtextstyle.
-textstyle.h textstyle/stdbool.h textstyle/version.h textstyle/woe32dll.h:
- here=`pwd`; \
- cd ../../libtextstyle/lib && \
- $(MAKE) install-nobase_includeHEADERS install-nobase_nodist_includeHEADERS includedir="$$here"
-BUILT_SOURCES += textstyle.h textstyle/stdbool.h textstyle/version.h textstyle/woe32dll.h
-MOSTLYCLEANFILES += textstyle.h textstyle/stdbool.h textstyle/version.h textstyle/woe32dll.h
-# Where to find the built libtextstyle library.
-LT_LIBTEXTSTYLE = ../../libtextstyle/lib/libtextstyle.la
-endif
+# Use the dummy libtextstyle from gnulib, as libgettextpo does.
+LT_LIBTEXTSTYLE =
+AM_CPPFLAGS += -I../libgettextpo -I$(top_srcdir)/libgettextpo
# How to build libgettextsrc.la.
# Need ../gnulib-lib/libgettextlib.la.

@ -0,0 +1,44 @@
From 175e0bc72808d564074c4adcc72aeadb74adfcc6 Mon Sep 17 00:00:00 2001
From: Paul Eggert <eggert@cs.ucla.edu>
Date: Thu, 27 Aug 2020 17:52:58 -0700
Subject: [PATCH] perror, strerror_r: remove unportable tests
Problem reported by Florian Weimer in:
https://lists.gnu.org/r/bug-gnulib/2020-08/msg00220.html
* tests/test-perror2.c (main):
* tests/test-strerror_r.c (main): Omit unportable tests.
---
ChangeLog | 8 ++++++++
tests/test-perror2.c | 3 ---
tests/test-strerror_r.c | 3 ---
3 files changed, 8 insertions(+), 6 deletions(-)
diff --git a/gettext-tools/gnulib-tests/test-perror2.c b/gettext-tools/gnulib-tests/test-perror2.c
index 1d14eda7b..c6214dd25 100644
--- a/gettext-tools/gnulib-tests/test-perror2.c
+++ b/gettext-tools/gnulib-tests/test-perror2.c
@@ -79,9 +79,6 @@ main (void)
errno = -5;
perror ("");
ASSERT (!ferror (stderr));
- ASSERT (msg1 == msg2 || msg1 == msg4 || STREQ (msg1, str1));
- ASSERT (msg2 == msg4 || STREQ (msg2, str2));
- ASSERT (msg3 == msg4 || STREQ (msg3, str3));
ASSERT (STREQ (msg4, str4));
free (str1);
diff --git a/gettext-tools/gnulib-tests/test-strerror_r.c b/gettext-tools/gnulib-tests/test-strerror_r.c
index b11d6fd9f..c1dbcf837 100644
--- a/gettext-tools/gnulib-tests/test-strerror_r.c
+++ b/gettext-tools/gnulib-tests/test-strerror_r.c
@@ -165,9 +165,6 @@ main (void)
strerror_r (EACCES, buf, sizeof buf);
strerror_r (-5, buf, sizeof buf);
- ASSERT (msg1 == msg2 || msg1 == msg4 || STREQ (msg1, str1));
- ASSERT (msg2 == msg4 || STREQ (msg2, str2));
- ASSERT (msg3 == msg4 || STREQ (msg3, str3));
ASSERT (STREQ (msg4, str4));
free (str1);

@ -0,0 +1,116 @@
diff -urp '--exclude=*~' gettext-0.21.orig/gettext-tools/gnulib-lib/javacomp.c gettext-0.21/gettext-tools/gnulib-lib/javacomp.c
--- gettext-0.21.orig/gettext-tools/gnulib-lib/javacomp.c 2022-03-09 12:22:05.000000000 +0900
+++ gettext-0.21/gettext-tools/gnulib-lib/javacomp.c 2022-03-20 18:23:53.636052943 +0900
@@ -116,9 +116,8 @@ default_target_version (void)
&& (java_version_cache[1] >= '2'
&& java_version_cache[1] <= '7')
&& java_version_cache[2] == '\0')
- /* Assume that these (not yet released) Java versions will behave
- like the preceding ones. */
- java_version_cache = "11";
+ /* It's one of the valid target version values. */
+ ;
else
java_version_cache = "1.1";
}
@@ -128,7 +127,7 @@ default_target_version (void)
/* ======================= Source version dependent ======================= */
/* Convert a source version to an index. */
-#define SOURCE_VERSION_BOUND 8 /* exclusive upper bound */
+#define SOURCE_VERSION_BOUND 14 /* exclusive upper bound */
static unsigned int
source_version_index (const char *source_version)
{
@@ -144,7 +143,7 @@ source_version_index (const char *source
else if (source_version[0] == '9' && source_version[1] == '\0')
return 5;
else if (source_version[0] == '1'
- && (source_version[1] >= '0' && source_version[1] <= '1')
+ && (source_version[1] >= '0' && source_version[1] <= '7')
&& source_version[2] == '\0')
return source_version[1] - '0' + 6;
error (EXIT_FAILURE, 0, _("invalid source_version argument to compile_java_class"));
@@ -171,6 +170,10 @@ get_goodcode_snippet (const char *source
return "class conftest { public void m() { var i = new Integer(0); } }\n";
if (strcmp (source_version, "11") == 0)
return "class conftest { Readable r = (var b) -> 0; }\n";
+ if (source_version[0] == '1'
+ && (source_version[1] >= '2' && source_version[1] <= '7')
+ && source_version[2] == '\0')
+ return "class conftest { Readable r = (var b) -> 0; }\n";
error (EXIT_FAILURE, 0, _("invalid source_version argument to compile_java_class"));
return NULL;
}
@@ -197,6 +200,10 @@ get_failcode_snippet (const char *source
return "class conftestfail { Readable r = (var b) -> 0; }\n";
if (strcmp (source_version, "11") == 0)
return NULL;
+ if (source_version[0] == '1'
+ && (source_version[1] >= '2' && source_version[1] <= '7')
+ && source_version[2] == '\0')
+ return NULL;
error (EXIT_FAILURE, 0, _("invalid source_version argument to compile_java_class"));
return NULL;
}
@@ -204,7 +211,7 @@ get_failcode_snippet (const char *source
/* ======================= Target version dependent ======================= */
/* Convert a target version to an index. */
-#define TARGET_VERSION_BOUND 11 /* exclusive upper bound */
+#define TARGET_VERSION_BOUND 17 /* exclusive upper bound */
static unsigned int
target_version_index (const char *target_version)
{
@@ -215,7 +222,7 @@ target_version_index (const char *target
else if (target_version[0] == '9' && target_version[1] == '\0')
return 8;
else if (target_version[0] == '1'
- && (target_version[1] >= '0' && target_version[1] <= '1')
+ && (target_version[1] >= '0' && target_version[1] <= '7')
&& target_version[2] == '\0')
return target_version[1] - '0' + 9;
error (EXIT_FAILURE, 0, _("invalid target_version argument to compile_java_class"));
@@ -245,10 +252,10 @@ corresponding_classfile_version (const c
return 52;
if (strcmp (target_version, "9") == 0)
return 53;
- if (strcmp (target_version, "10") == 0)
- return 54;
- if (strcmp (target_version, "11") == 0)
- return 55;
+ if (target_version[0] == '1'
+ && (target_version[1] >= '0' && target_version[1] <= '7')
+ && target_version[2] == '\0')
+ return target_version[1] + 54;
error (EXIT_FAILURE, 0, _("invalid target_version argument to compile_java_class"));
return 0;
}
@@ -2439,7 +2446,7 @@ compile_java_class (const char * const *
}
}
- error (0, 0, _("Java compiler not found, try installing gcj or set $JAVAC"));
+ /* error (0, 0, _("Java compiler not found, try installing gcj or set $JAVAC")); */
err = true;
done2:
diff -urp '--exclude=*~' gettext-0.21.orig/gettext-tools/src/write-java.c gettext-0.21/gettext-tools/src/write-java.c
--- gettext-0.21.orig/gettext-tools/src/write-java.c 2022-03-09 12:17:21.000000000 +0900
+++ gettext-0.21/gettext-tools/src/write-java.c 2022-03-20 18:26:06.941734979 +0900
@@ -1209,8 +1209,14 @@ msgdomain_write_java (message_list_ty *m
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,
+ if (1
+ && (compile_java_class (java_sources, 1, NULL, 0, "17", "17", directory,
+ true, false, true, verbose > 0)) /* assume JDK 17 */
+ && (compile_java_class (java_sources, 1, NULL, 0, "11", "11", directory,
+ true, false, true, verbose > 0)) /* assume JDK 11 */
+ && (compile_java_class (java_sources, 1, NULL, 0, "1.5", "1.6", directory,
true, false, true, verbose > 0))
+ )
{
if (!verbose)
error (0, 0,

@ -0,0 +1,45 @@
.TH MSGHACK "1" "June 2013" "msghack" "User Commands"
.SH NAME
msghack \- alter PO files in ways
.SH SYNOPSIS
.B msghack
[\fIOPTION\fR] \fIfile.po \fR[\fIref.po\fR]
.SH DESCRIPTION
.PP
This program can be used to alter .po files in ways no sane mind would think about.
.TP
\fB\-o\fR
result will be written to FILE
.TP
\fB\-\-invert\fR
invert a po file by switching msgid and msgstr
.TP
\fB\-\-master\fR
join any number of files in a master\-formatted catalog
.TP
\fB\-\-empty\fR
empty the contents of the .po file, creating a .pot
.TP
\fB\-\-append\fR
append entries from ref.po that don't exist in file.po
.PP
Note: It is just a replacement of msghack for backward support.
.PP
This program can be used to alter .po files in ways no sane mind would think about.
.TP
\fB\-o\fR
result will be written to FILE
.TP
\fB\-\-invert\fR
invert a po file by switching msgid and msgstr
.TP
\fB\-\-master\fR
join any number of files in a master\-formatted catalog
.TP
\fB\-\-empty\fR
empty the contents of the .po file, creating a .pot
.TP
\fB\-\-append\fR
append entries from ref.po that don't exist in file.po
.PP
Note: It is just a replacement of msghack for backward support.

@ -0,0 +1,417 @@
#!/usr/bin/python3
## -*- coding: utf-8 -*-
## Copyright (C) 2001, 2004, 2008, 2012 Red Hat, Inc.
## Copyright (C) 2001 Trond Eivind Glomsrød <teg@redhat.com>
## 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 <http://www.gnu.org/licenses/>.
"""
A msghack replacement
"""
import sys
class GTMessage:
"""
A class containing a message, its msgid and various references pointing at it
"""
def __init__(self,id=None,message=None,refs=[]):
"""
The constructor for the GTMessage class
@self The object instance
@message The message
@id The messageid associated with the object
"""
self._message=message.strip()
self._id=id.strip()
self._refs=[]
for ref in refs:
self._refs.append(ref)
def __str__(self):
"""
Return a string representation of the object
@self The object instance
"""
res=""
for ref in self._refs:
res=res+ref+"\n"
res=res+"msgid %s\nmsgstr %s\n" % (self._id,self._message)
return res
def invertedStrings(self):
"""
Returns a string representation, but with msgid and msgstr inverted.
Note: Don't invert the "" string
@self The object instance
"""
res=""
for ref in self._refs:
res=res+ref+"\n"
if not self._id=="\"\"":
res=res+"msgid %s\nmsgstr %s\n" % (self._message,self._id)
else:
res=res+"msgid %s\nmsgstr %s\n" % (self._id,self._message)
return res
def emptyMsgStrings(self):
"""
Return a string representation of the object, but leave the msgstr
empty - create a pot file from a po file
Note: Won't remove the "" string
@self The object instance
"""
res=""
for ref in self._refs:
res=res+ref+"\n"
if not self._id=="\"\"":
res=res+"msgid %s\nmsgstr \"\"\n" % (self._id)
else:
res=res+"msgid %s\nmsgstr %s\n" % (self._id,self._message)
return res
def compareMessage(self,msg):
"""
Return if the messages have identical msgids, 0 otherwise
@self The object instance
@msg The message to compare to
"""
if self._id == msg._id:
return 1
return 0
class GTMasterMessage:
"""
A class containing a message, its msgid and various references pointing at it
The difference between GTMessage and GTMasterMessage is that this class
can do less operations, but is able to store multiple msgstrs with identifiers
(usually language, like 'msgst(no)'
"""
def __init__(self,id=None,refs=[]):
"""
The constructor for the GTMessage class
@self The object instance
@id The messageid associated with the object
"""
self._id=id
self._refs=[]
self._messages=[]
for ref in refs:
self._refs.append(ref)
def addMessage(self,message,identifier):
"""
Add a new message and identifier to the GTMasterMessage object
@self The object instance
@message The message to append
@identifier The identifier of the message
"""
self._messages.append((identifier,message))
def __str__(self):
"""
Return a string representation of the object
@self The object instance
"""
res=""
for ref in self._refs:
res=res+ref+"\n"
res=res+"msgid %s\n" % self._id
for message in self._messages:
res=res+"msgstr(%s) %s\n" %(message[0],message[1])
res=res+"\n"
return res
class GTFile:
"""
A class containing the GTMessages contained in a file
"""
def __init__(self,filename):
"""
The constructor of the GTMFile class
@self The object instance
@filename The file to initialize from
"""
self._filename=filename
self._messages=[]
self.readFile(filename)
def __str__(self):
"""
Return a string representation of the object
@self The object instance
"""
res=""
for message in self._messages:
res=res+str(message)+"\n"
return res
def invertedStrings(self):
"""
Return a string representation of the object, with msgid and msgstr
swapped. Will remove duplicates...
@self The object instance
"""
msght={}
msgar=[]
for message in self._messages:
if message._id=='""' and len(msgar)==0:
msgar.append(GTMessage(message._id,message._message,message._refs))
continue
msg=GTMessage(message._message,message._id,message._refs)
if msg._id not in msght:
msght[msg._id]=msg
msgar.append(msg)
else:
msg2=msght[msg._id]
for ref in msg._refs:
msg2._refs.append(ref)
res=""
for message in msgar:
res=res+str(message)+"\n"
return res
def msgidDupes(self):
"""
Search for duplicates in the msgids.
@self The object instance
"""
msgids={}
res=""
for message in self._messages:
msgid=message._id
if msgid in msgids:
res=res+"Duplicate: %s\n" % (msgid)
else:
msgids[msgid]=1
return res
def getMsgstr(self,msgid):
"""
Return the msgstr matching the given id. 'None' if missing
@self The object instance
@msgid The msgid key
"""
for message in self._messages:
if msgid == message._id:
return message._message
return None
def emptyMsgStrings(self):
"""
Return a string representation of the object, but leave the msgstr
empty - create a pot file from a po file
@self The object instance
"""
res=""
for message in self._messages:
res=res+message.emptyMsgStrings()+"\n"
return res
def append(self,B):
"""
Append entries from dictionary B which aren't
already present in this dictionary
@self The object instance
@B the dictionary to append messages from
"""
for message in B._messages:
if not self.getMsgstr(message._id):
self._messages.append(message)
def readFile(self,filename):
"""
Read the contents of a file into the GTFile object
@self The object instance
@filename The name of the file to read
"""
file=open(filename,"r")
msgid=""
msgstr=""
refs=[]
lines=[]
inmsgid=0
inmsgstr=0
templines=file.readlines()
for line in templines:
lines.append(line.strip())
for line in lines:
pos=line.find('"')
pos2=line.rfind('"')
if line and line[0]=="#":
refs.append(line.strip())
if inmsgstr==0 and line[:6]=="msgstr":
msgstr=""
inmsgstr=1
inmsgid=0
if inmsgstr==1:
if pos==-1:
inmsgstr=0
#Handle entries with and without "" consistently
if msgid[:2]=='""' and len(msgid)>4:
msgid=msgid[2:]
if msgstr[:2]=='""' and len(msgstr)>4:
msgstr=msgstr[2:]
message=GTMessage(msgid,msgstr,refs)
self._messages.append(message)
msgstr=""
msgid=""
refs=[]
else:
msgstr=msgstr+line[pos:pos2+1]+"\n"
if inmsgid==0 and line[:5]=="msgid":
msgid=""
inmsgid=1
if inmsgid==1:
if pos==-1:
inmsgid=0
else:
msgid=msgid+line[pos:pos2+1]+"\n"
if msgstr and msgid:
message=GTMessage(msgid,msgstr,refs)
self._messages.append(message)
class GTMaster:
"""
A class containing a master catalogue of gettext dictionaries
"""
def __init__(self,dicts):
"""
The constructor for the GTMaster class
@self The object instance
@dicts An array of dictionaries to merge
"""
self._messages=[]
self.createMaster(dicts)
def createMaster(self,dicts):
"""
Create the master catalogue
@self The object instance
@dicts An array of dictionaries to merge
"""
self._master=dicts[0]
self._dicts=dicts[1:]
for message in self._master._messages:
gtm=GTMasterMessage(message._id,message._refs)
gtm.addMessage(message._message,self._master._filename[:-3])
for dict in self._dicts:
res=dict.getMsgstr(message._id)
if(res):
gtm.addMessage(res,dict._filename[:-3])
self._messages.append(gtm)
def __str__(self):
"""
Return a string representation of the object
@self The object instance
"""
res=""
for message in self._messages:
res=res+str(message)+"\n"
return res
def printUsage():
"Print the usage messages"
print("Usage: " + str(sys.argv[0]) + " [OPTION] file.po [ref.po]\n\
This program can be used to alter .po files in ways no sane mind would think about.\n\
-o result will be written to FILE\n\
--invert invert a po file by switching msgid and msgstr\n\
--master join any number of files in a master-formatted catalog\n\
--empty empty the contents of the .po file, creating a .pot\n\
--append append entries from ref.po that don't exist in file.po\n\
\n\
Note: It is just a replacement of msghack for backward support.\n")
if __name__=="__main__":
output=None
res=None
if("-o") in sys.argv:
if (len(sys.argv)<=sys.argv.index("-o")+1):
print("file.po and ref.po are not specified!\n")
printUsage()
exit(1)
output=sys.argv[sys.argv.index("-o")+1]
sys.argv.remove("-o")
sys.argv.remove(output)
if("--invert") in sys.argv:
if (len(sys.argv)<=sys.argv.index("--invert")+1):
print("file.po is not specified!\n")
printUsage()
exit(1)
file=sys.argv[sys.argv.index("--invert")+1]
gtf=GTFile(file)
res1=gtf.msgidDupes()
if res1:
sys.stderr.write(res1)
sys.exit(1)
res=str(gtf.invertedStrings())
elif("--empty") in sys.argv:
if (len(sys.argv)<=sys.argv.index("--empty")+1):
print("file.po is not specified!\n")
printUsage()
exit(1)
file=sys.argv[sys.argv.index("--empty")+1]
gtf=GTFile(file)
res=str(gtf.emptyMsgStrings())
elif("--master") in sys.argv:
if (len(sys.argv)<=sys.argv.index("--master")+1):
print("file.po is not specified!\n")
printUsage()
exit(1)
loc=sys.argv.index("--master")+1
gtfs=[]
for file in sys.argv[loc:]:
gtfs.append(GTFile(file))
master=GTMaster(gtfs)
res=str(master)
elif("--append") in sys.argv:
if (len(sys.argv)<=sys.argv.index("--append")+2):
print("file.po and/or ref.po are not specified!\n")
printUsage()
exit(1)
file=sys.argv[sys.argv.index("--append")+1]
file2=sys.argv[sys.argv.index("--append")+2]
gtf=GTFile(file)
gtf2=GTFile(file2)
gtf.append(gtf2)
res=str(gtf)
else:
#print("Not implemented: "+str(sys.argv))
printUsage()
sys.exit(1)
if not output:
print(res)
else:
file=open(output,"w")
file.write(res)
sys.exit(0)

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save