]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
Additional API for libgettextpo.
authorBruno Haible <bruno@clisp.org>
Wed, 24 Sep 2003 10:36:11 +0000 (10:36 +0000)
committerBruno Haible <bruno@clisp.org>
Tue, 23 Jun 2009 10:11:01 +0000 (12:11 +0200)
NEWS
gettext-tools/ChangeLog
gettext-tools/src/ChangeLog
gettext-tools/src/Makefile.am
gettext-tools/src/gettext-po.c
gettext-tools/src/gettext-po.h
gettext-tools/windows/gettextpo.def
gettext-tools/windows/gettextpo.rc

diff --git a/NEWS b/NEWS
index 06fa7dcd839b8b2498eb3f97897675b3634a2a5d..2ae339296fcda82b5f30f5ca4f4e1cc3016010c2 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -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
index 6be53021c76d836b697e3ebdf5bc3a87cde33383..a45c20f1f47445cdf583ea4389ffa6c96226f126 100644 (file)
@@ -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.
index ddcd69162d6633e9d7a98ba3d4445d045b8b354e..01f8b5f7dcfed23b4f6936608d982155da4d6e02 100644 (file)
@@ -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.
index f59a59b029ff5d54a471f17d206c296a0ff64aa6..3293c1af73c54c7c73ffe4a45cf5065f15bc151b 100644 (file)
@@ -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
index 85dc4ac6009c453bf68383f3c5f886c126557c9a..4e71e62370882d5a894f5a53e694a3bff43a0b61 100644 (file)
@@ -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;
+}
index 27788e6b90c3a2bac5175eec4594dfd229f77d29..875352270d518966f51fd777aa8ad6e6816efd7d 100644 (file)
@@ -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
 }
index 089da20d96d320515568634fcd2a6f7cb1b58fb2..1dfb2d61fa31bc3897ebb6cebdaf8b3912c4faad 100644 (file)
@@ -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
index 8a853ad630788d2a3007b0e9f610a426b6bef502..02cde7aa2d56d99c47689179e520a967d4e9e4ca 100644 (file)
@@ -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"