diff options
author | Bruno Haible <bruno@clisp.org> | 2003-09-24 10:36:11 +0000 |
---|---|---|
committer | Bruno Haible <bruno@clisp.org> | 2009-06-23 12:11:01 +0200 |
commit | 7044c95bd8783c1d28ccc3bf7196cd4201fdcdb5 (patch) | |
tree | 156071a614b64b26e83204b7e9c0d79bf475de31 | |
parent | ff75d3f15dec756e0596525b541b50495b75db58 (diff) | |
download | external_gettext-7044c95bd8783c1d28ccc3bf7196cd4201fdcdb5.zip external_gettext-7044c95bd8783c1d28ccc3bf7196cd4201fdcdb5.tar.gz external_gettext-7044c95bd8783c1d28ccc3bf7196cd4201fdcdb5.tar.bz2 |
Additional API for libgettextpo.
-rw-r--r-- | NEWS | 5 | ||||
-rw-r--r-- | gettext-tools/ChangeLog | 6 | ||||
-rw-r--r-- | gettext-tools/src/ChangeLog | 10 | ||||
-rw-r--r-- | gettext-tools/src/Makefile.am | 4 | ||||
-rw-r--r-- | gettext-tools/src/gettext-po.c | 112 | ||||
-rw-r--r-- | gettext-tools/src/gettext-po.h | 23 | ||||
-rw-r--r-- | gettext-tools/windows/gettextpo.def | 5 | ||||
-rw-r--r-- | gettext-tools/windows/gettextpo.rc | 8 |
8 files changed, 167 insertions, 6 deletions
@@ -30,6 +30,11 @@ Version 0.12.2 - September 2003 - Glade: xgettext now also supports Glade version 2. +* libgettextpo library: + + - New functions for testing the obsolete/fuzzy/*-format flags of a message. + - New convenience functions for extracting and analyzing the header entry. + * Portability: - C format strings with positions, as they arise when a translator needs to diff --git a/gettext-tools/ChangeLog b/gettext-tools/ChangeLog index 6be5302..a45c20f 100644 --- a/gettext-tools/ChangeLog +++ b/gettext-tools/ChangeLog @@ -1,3 +1,9 @@ +2003-09-18 Bruno Haible <bruno@clisp.org> + + * windows/gettextpo.def: Add po_file_domain_header, po_header_field, + po_message_is_obsolete, po_message_is_fuzzy, po_message_is_format. + * windows/gettextpo.rc: Bump version number to 0.12.2. + 2003-09-16 Bruno Haible <bruno@clisp.org> Portability to SunOS 4. diff --git a/gettext-tools/src/ChangeLog b/gettext-tools/src/ChangeLog index ddcd691..01f8b5f 100644 --- a/gettext-tools/src/ChangeLog +++ b/gettext-tools/src/ChangeLog @@ -1,3 +1,13 @@ +2003-09-18 Bruno Haible <bruno@clisp.org> + + * gettext-po.h (po_file_domain_header, po_header_field, + po_message_is_obsolete, po_message_is_fuzzy, po_message_is_format): New + declarations. + * gettext-po.c (po_file_domain_header, po_header_field, + po_message_is_obsolete, po_message_is_fuzzy, po_message_is_format): New + functions. + * Makefile.am (LTV_CURRENT, LTV_REVISION, LTV_AGE): Bump to 1:0:1. + 2003-09-14 Bruno Haible <bruno@clisp.org> * plural-count.c: Include plural-count.h. diff --git a/gettext-tools/src/Makefile.am b/gettext-tools/src/Makefile.am index f59a59b..3293c1a 100644 --- a/gettext-tools/src/Makefile.am +++ b/gettext-tools/src/Makefile.am @@ -106,9 +106,9 @@ msgl-charset.c po-time.c plural.c plural-table.c $(FORMAT_SOURCE) libgettextpo_la_SOURCES = gettext-po.c # Libtool's library version information for libgettextpo. # See the libtool documentation, section "Library interface versions". -LTV_CURRENT=0 +LTV_CURRENT=1 LTV_REVISION=0 -LTV_AGE=0 +LTV_AGE=1 # x-python needs table of Unicode character names. LIBUNINAME = ../libuniname/libuniname.a diff --git a/gettext-tools/src/gettext-po.c b/gettext-tools/src/gettext-po.c index 85dc4ac..4e71e62 100644 --- a/gettext-tools/src/gettext-po.c +++ b/gettext-tools/src/gettext-po.c @@ -105,6 +105,76 @@ po_file_domains (po_file_t file) } +/* Return the header entry of a domain of a PO file in memory. + The domain NULL denotes the default domain. + Return NULL if there is no header entry. */ + +const char * +po_file_domain_header (po_file_t file, const char *domain) +{ + message_list_ty *mlp; + size_t j; + + if (domain == NULL) + domain = MESSAGE_DOMAIN_DEFAULT; + mlp = msgdomain_list_sublist (file->mdlp, domain, false); + if (mlp != NULL) + for (j = 0; j < mlp->nitems; j++) + if (mlp->item[j]->msgid[0] == '\0' && !mlp->item[j]->obsolete) + { + const char *header = mlp->item[j]->msgstr; + + if (header != NULL) + return xstrdup (header); + else + return NULL; + } + return NULL; +} + + +/* Return the value of a field in a header entry. + The return value is either a freshly allocated string, to be freed by the + caller, or NULL. */ + +char * +po_header_field (const char *header, const char *field) +{ + size_t len = strlen (field); + const char *line; + + for (line = header;;) + { + if (strncmp (line, field, len) == 0 + && line[len] == ':' && line[len + 1] == ' ') + { + const char *value_start; + const char *value_end; + char *value; + + value_start = line + len + 2; + value_end = strchr (value_start, '\n'); + if (value_end == NULL) + value_end = value_start + strlen (value_start); + + value = (char *) xmalloc (value_end - value_start + 1); + memcpy (value, value_start, value_end - value_start); + value[value_end - value_start] = '\0'; + + return value; + } + + line = strchr (line, '\n'); + if (line != NULL) + line++; + else + break; + } + + return NULL; +} + + /* Create an iterator for traversing a domain of a PO file in memory. The domain NULL denotes the default domain. */ @@ -208,3 +278,45 @@ po_message_msgstr_plural (po_message_t message, int index) else return NULL; } + + +/* Return true if the message is marked obsolete. */ + +int +po_message_is_obsolete (po_message_t message) +{ + message_ty *mp = (message_ty *) message; + + return (mp->obsolete ? 1 : 0); +} + + +/* Return true if the message is marked fuzzy. */ + +int +po_message_is_fuzzy (po_message_t message) +{ + message_ty *mp = (message_ty *) message; + + return (mp->is_fuzzy ? 1 : 0); +} + + +/* Return true if the message is marked as being a format string of the given + type (e.g. "c-format"). */ + +int +po_message_is_format (po_message_t message, const char *format_type) +{ + message_ty *mp = (message_ty *) message; + size_t len = strlen (format_type); + size_t i; + + if (len >= 7 && memcmp (format_type + len - 7, "-format", 7) == 0) + for (i = 0; i < NFORMATS; i++) + if (strlen (format_language[i]) == len - 7 + && memcmp (format_language[i], format_type, len - 7) == 0) + /* The given format_type corresponds to (enum format_type) i. */ + return (possible_format_p (mp->is_format[i]) ? 1 : 0); + return 0; +} diff --git a/gettext-tools/src/gettext-po.h b/gettext-tools/src/gettext-po.h index 27788e6..8753522 100644 --- a/gettext-tools/src/gettext-po.h +++ b/gettext-tools/src/gettext-po.h @@ -56,6 +56,19 @@ extern void po_file_free (po_file_t file); extern const char * const * po_file_domains (po_file_t file); +/* =========================== Header entry API ============================ */ + +/* Return the header entry of a domain of a PO file in memory. + The domain NULL denotes the default domain. + Return NULL if there is no header entry. */ +extern const char * po_file_domain_header (po_file_t file, const char *domain); + +/* Return the value of a field in a header entry. + The return value is either a freshly allocated string, to be freed by the + caller, or NULL. */ +extern char * po_header_field (const char *header, const char *field); + + /* ======================= po_message_iterator_t API ======================= */ /* Create an iterator for traversing a domain of a PO file in memory. @@ -87,6 +100,16 @@ extern const char * po_message_msgstr (po_message_t message); NULL when the index is out of range or for a message without plural. */ extern const char * po_message_msgstr_plural (po_message_t message, int index); +/* Return true if the message is marked obsolete. */ +extern int po_message_is_obsolete (po_message_t message); + +/* Return true if the message is marked fuzzy. */ +extern int po_message_is_fuzzy (po_message_t message); + +/* Return true if the message is marked as being a format string of the given + type (e.g. "c-format"). */ +extern int po_message_is_format (po_message_t message, const char *format_type); + #ifdef __cplusplus } diff --git a/gettext-tools/windows/gettextpo.def b/gettext-tools/windows/gettextpo.def index 089da20..1dfb2d6 100644 --- a/gettext-tools/windows/gettextpo.def +++ b/gettext-tools/windows/gettextpo.def @@ -1,8 +1,13 @@ LIBRARY gettextpo EXPORTS po_file_domains +po_file_domain_header po_file_free po_file_read +po_header_field +po_message_is_format +po_message_is_fuzzy +po_message_is_obsolete po_message_iterator po_message_iterator_free po_message_msgid diff --git a/gettext-tools/windows/gettextpo.rc b/gettext-tools/windows/gettextpo.rc index 8a853ad..02cde7a 100644 --- a/gettext-tools/windows/gettextpo.rc +++ b/gettext-tools/windows/gettextpo.rc @@ -4,8 +4,8 @@ #include <winver.h> VS_VERSION_INFO VERSIONINFO - FILEVERSION 0,12,0,0 - PRODUCTVERSION 0,12,0,0 + FILEVERSION 0,12,2,0 + PRODUCTVERSION 0,12,2,0 FILEFLAGSMASK 0x3fL /* VS_FFI_FILEFLAGSMASK */ #ifdef _DEBUG FILEFLAGS 0x1L /* VS_FF_DEBUG */ @@ -23,13 +23,13 @@ BEGIN VALUE "Comments", "This library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License. You should have received a copy of the GNU General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA\0" VALUE "CompanyName", "Free Software Foundation\0" VALUE "FileDescription", "GPLed libgettextpo for Windows NT/2000/XP and Windows 95/98/ME\0" - VALUE "FileVersion", "0.12\0" + VALUE "FileVersion", "0.12.2\0" VALUE "InternalName", "gettextpo.dll\0" VALUE "LegalCopyright", "Copyright (C) 1995-2003\0" VALUE "LegalTrademarks", "\0" VALUE "OriginalFilename", "gettextpo.dll\0" VALUE "ProductName", "libgettextpo: public API for PO files\0" - VALUE "ProductVersion", "0.12\0" + VALUE "ProductVersion", "0.12.2\0" END END BLOCK "VarFileInfo" |