From: Bruno Haible Date: Sun, 21 Oct 2007 15:15:35 +0000 (+0000) Subject: New functions for inspecting supported format types. X-Git-Tag: v0.17~92 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=82ccef939477748d4adebcdc418095c235bfd6c3;p=thirdparty%2Fgettext.git New functions for inspecting supported format types. --- diff --git a/NEWS b/NEWS index 2820eec1d..d0b6374c5 100644 --- a/NEWS +++ b/NEWS @@ -21,6 +21,10 @@ Version 0.16.2 - January 2007 xgettext has a new option --kde that triggers the recognition and marking of KDE 4 format strings. +* libgettextpo library: + - New functions are available for querying the list of supported format + types. + * Documentation: - The "Users" chapter has been completely rewritten. - A complete example showing the use of GNU gettext in Java with the Qt/Jambi diff --git a/gettext-tools/libgettextpo/ChangeLog b/gettext-tools/libgettextpo/ChangeLog index 381b99be3..50e2c2a4f 100644 --- a/gettext-tools/libgettextpo/ChangeLog +++ b/gettext-tools/libgettextpo/ChangeLog @@ -1,3 +1,11 @@ +2007-10-21 Bruno Haible + + * gettext-po.h.in (LIBGETTEXTPO_VERSION): Bump version number. + (po_format_list, po_format_pretty_name): New declarations. + * gettext-po.c: Include xvasprintf.h. + (po_format_list, po_format_pretty_name): New functions. + Reported by Dwayne Bailey . + 2007-10-20 Bruno Haible * gettext-po.c (po_message_check_format): Update call to check_message, diff --git a/gettext-tools/libgettextpo/gettext-po.c b/gettext-tools/libgettextpo/gettext-po.c index a4ca30088..cb5091b35 100644 --- a/gettext-tools/libgettextpo/gettext-po.c +++ b/gettext-tools/libgettextpo/gettext-po.c @@ -40,6 +40,7 @@ #include "po-error.h" #include "po-xerror.h" #include "format.h" +#include "xvasprintf.h" #include "msgl-check.h" #include "gettext.h" @@ -1112,6 +1113,45 @@ po_filepos_start_line (po_filepos_t filepos) } +/* Return a NULL terminated array of the supported format types. */ + +const char * const * +po_format_list (void) +{ + static const char * const * whole_list /* = NULL */; + if (whole_list == NULL) + { + const char **list = XNMALLOC (NFORMATS + 1, const char *); + size_t i; + for (i = 0; i < NFORMATS; i++) + list[i] = xasprintf ("%s-format", format_language[i]); + list[i] = NULL; + whole_list = list; + } + return whole_list; +} + + +/* Return the pretty name associated with a format type. + For example, for "csharp-format", return "C#". + Return NULL if the argument is not a supported format type. */ + +const char * +po_format_pretty_name (const char *format_type) +{ + 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 format_language_pretty[i]; + return NULL; +} + + /* Test whether an entire file PO file is valid, like msgfmt does it. If it is invalid, pass the reasons to the handler. */ diff --git a/gettext-tools/libgettextpo/gettext-po.h.in b/gettext-tools/libgettextpo/gettext-po.h.in index 433356b56..679895f63 100644 --- a/gettext-tools/libgettextpo/gettext-po.h.in +++ b/gettext-tools/libgettextpo/gettext-po.h.in @@ -1,5 +1,5 @@ /* Public API for GNU gettext PO files - contained in libgettextpo. - Copyright (C) 2003-2006 Free Software Foundation, Inc. + Copyright (C) 2003-2007 Free Software Foundation, Inc. Written by Bruno Haible , 2003. This program is free software: you can redistribute it and/or modify @@ -28,7 +28,7 @@ extern "C" { /* =========================== Meta Information ============================ */ /* Version number: (major<<16) + (minor<<8) + subminor */ -#define LIBGETTEXTPO_VERSION 0x001000 +#define LIBGETTEXTPO_VERSION 0x001002 extern int libgettextpo_version; /* ================================= Types ================================= */ @@ -312,6 +312,17 @@ extern const char * po_filepos_file (po_filepos_t filepos); extern size_t po_filepos_start_line (po_filepos_t filepos); +/* ============================ Format type API ============================= */ + +/* Return a NULL terminated array of the supported format types. */ +extern const char * const * po_format_list (void); + +/* Return the pretty name associated with a format type. + For example, for "csharp-format", return "C#". + Return NULL if the argument is not a supported format type. */ +extern const char * po_format_pretty_name (const char *format_type); + + /* ============================= Checking API ============================== */ /* Test whether an entire file PO file is valid, like msgfmt does it.