diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2011-08-16 08:13:10 +0000 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2011-08-16 08:13:10 +0000 |
commit | 56ac2b6a5d6eb829a7da8eecc04cbf5f9339e61b (patch) | |
tree | 5dc8009ac82abcfa8f22aa1ef38c85244af77a25 /src | |
parent | ae9ea0011da4ba01e5639611d61c442af8d42817 (diff) | |
download | gdbm-56ac2b6a5d6eb829a7da8eecc04cbf5f9339e61b.tar.gz gdbm-56ac2b6a5d6eb829a7da8eecc04cbf5f9339e61b.tar.bz2 |
Internationalization.
* Makefile.am (SUBDIRS): Add po.
(EXTRA_DIST): Add build-aux/config.rpath.
* configure.ac (AC_CONFIG_FILES): Add po/Makefile.in.
* bootstrap: New file.
* src/Makefile.am (AM_CPPFLAGS): Define LOCALEDIR
(noinst_HEADERS): Add gettext.h
(LIBADD): New variable.
* src/gettext.h: New file.
* po/.cvsignore: New file.
* po/Makevars: New file.
* po/POTFILES.in: New file.
* src/gdbmdefs.h: Define DEFAULT_TEXT_DOMAIN, _, N_
Include gettext.h
* src/bucket.c: Add NLS markers.
* src/falloc.c: Likewise.
* src/findkey.c: Likewise.
* src/gdbmerrno.c: Likewise.
* src/gdbmfetch.c: Likewise.
* src/gdbmseq.c: Likewise.
* src/gdbmstore.c: Likewise.
* src/update.c: Likewise.
* src/testgdbm.c: Add NLS markers.
(main): Initialize I18N.
Diffstat (limited to 'src')
-rw-r--r-- | src/Makefile.am | 5 | ||||
-rw-r--r-- | src/bucket.c | 14 | ||||
-rw-r--r-- | src/falloc.c | 12 | ||||
-rw-r--r-- | src/findkey.c | 6 | ||||
-rw-r--r-- | src/gdbmdefs.h | 5 | ||||
-rw-r--r-- | src/gdbmerrno.c | 58 | ||||
-rw-r--r-- | src/gdbmfetch.c | 2 | ||||
-rw-r--r-- | src/gdbmseq.c | 2 | ||||
-rw-r--r-- | src/gdbmstore.c | 6 | ||||
-rw-r--r-- | src/gettext.h | 280 | ||||
-rw-r--r-- | src/testgdbm.c | 243 | ||||
-rw-r--r-- | src/update.c | 13 |
12 files changed, 473 insertions, 173 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index c2c2483..db85972 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -17,3 +17,3 @@ # Flags -AM_CPPFLAGS=-DIN_GDBM +AM_CPPFLAGS=-DIN_GDBM -DLOCALEDIR=\"$(localedir)\" @@ -24,2 +24,3 @@ noinst_HEADERS = \ gdbmdefs.h\ + gettext.h\ proto.h\ @@ -35,2 +36,4 @@ VI_AGE = 0 lib_LTLIBRARIES = libgdbm.la +LIBADD = @LTLIBINTL@ + libgdbm_la_SOURCES = \ diff --git a/src/bucket.c b/src/bucket.c index f8c48b9..cda2389 100644 --- a/src/bucket.c +++ b/src/bucket.c @@ -66,3 +66,3 @@ _gdbm_get_bucket (GDBM_FILE dbf, int dir_index) if(_gdbm_init_cache(dbf, DEFAULT_CACHESIZE) == -1) - _gdbm_fatal(dbf, "couldn't init cache"); + _gdbm_fatal(dbf, _("couldn't init cache")); } @@ -96,3 +96,3 @@ _gdbm_get_bucket (GDBM_FILE dbf, int dir_index) if (file_pos != bucket_adr) - _gdbm_fatal (dbf, "lseek error"); + _gdbm_fatal (dbf, _("lseek error")); @@ -100,3 +100,3 @@ _gdbm_get_bucket (GDBM_FILE dbf, int dir_index) if (num_bytes != dbf->header->bucket_size) - _gdbm_fatal (dbf, "read error"); + _gdbm_fatal (dbf, _("read error")); } @@ -147,3 +147,3 @@ _gdbm_split_bucket (GDBM_FILE dbf, int next_insert) if(_gdbm_init_cache(dbf, DEFAULT_CACHESIZE) == -1) - _gdbm_fatal(dbf, "couldn't init cache"); + _gdbm_fatal(dbf, _("couldn't init cache")); } @@ -187,3 +187,3 @@ _gdbm_split_bucket (GDBM_FILE dbf, int next_insert) new_dir = (off_t *) malloc (dir_size); - if (new_dir == NULL) _gdbm_fatal (dbf, "malloc error"); + if (new_dir == NULL) _gdbm_fatal (dbf, _("malloc error")); for (index = 0; @@ -310,6 +310,6 @@ _gdbm_write_bucket (GDBM_FILE dbf, cache_elem *ca_entry) if (file_pos != ca_entry->ca_adr) - _gdbm_fatal (dbf, "lseek error"); + _gdbm_fatal (dbf, _("lseek error")); num_bytes = __write (dbf, ca_entry->ca_bucket, dbf->header->bucket_size); if (num_bytes != dbf->header->bucket_size) - _gdbm_fatal (dbf, "write error"); + _gdbm_fatal (dbf, _("write error")); ca_entry->ca_changed = FALSE; diff --git a/src/falloc.c b/src/falloc.c index 2a54d53..d0af4a6 100644 --- a/src/falloc.c +++ b/src/falloc.c @@ -180,3 +180,3 @@ pop_avail_block (GDBM_FILE dbf) new_blk = (avail_block *) malloc (new_el.av_size); - if (new_blk == NULL) _gdbm_fatal(dbf, "malloc failed"); + if (new_blk == NULL) _gdbm_fatal(dbf, _("malloc failed")); @@ -184,5 +184,5 @@ pop_avail_block (GDBM_FILE dbf) file_pos = __lseek (dbf, new_el.av_adr, L_SET); - if (file_pos != new_el.av_adr) _gdbm_fatal (dbf, "lseek error"); + if (file_pos != new_el.av_adr) _gdbm_fatal (dbf, _("lseek error")); num_bytes = __read (dbf, new_blk, new_el.av_size); - if (num_bytes != new_el.av_size) _gdbm_fatal (dbf, "read error"); + if (num_bytes != new_el.av_size) _gdbm_fatal (dbf, _("read error")); @@ -258,3 +258,3 @@ push_avail_block (GDBM_FILE dbf) temp = (avail_block *) malloc (av_size); - if (temp == NULL) _gdbm_fatal (dbf, "malloc error"); + if (temp == NULL) _gdbm_fatal (dbf, _("malloc error")); /* Set the size to be correct AFTER the pop_avail_block. */ @@ -281,5 +281,5 @@ push_avail_block (GDBM_FILE dbf) file_pos = __lseek (dbf, av_adr, L_SET); - if (file_pos != av_adr) _gdbm_fatal (dbf, "lseek error"); + if (file_pos != av_adr) _gdbm_fatal (dbf, _("lseek error")); num_bytes = __write (dbf, temp, av_size); - if (num_bytes != av_size) _gdbm_fatal (dbf, "write error"); + if (num_bytes != av_size) _gdbm_fatal (dbf, _("write error")); free (temp); diff --git a/src/findkey.c b/src/findkey.c index 12c7226..7933c2f 100644 --- a/src/findkey.c +++ b/src/findkey.c @@ -56,3 +56,3 @@ _gdbm_read_entry (GDBM_FILE dbf, int elem_loc) data_ca->dptr = (char *) malloc (key_size+data_size); - if (data_ca->dptr == NULL) _gdbm_fatal (dbf, "malloc error"); + if (data_ca->dptr == NULL) _gdbm_fatal (dbf, _("malloc error")); @@ -62,5 +62,5 @@ _gdbm_read_entry (GDBM_FILE dbf, int elem_loc) if (file_pos != dbf->bucket->h_table[elem_loc].data_pointer) - _gdbm_fatal (dbf, "lseek error"); + _gdbm_fatal (dbf, _("lseek error")); num_bytes = __read (dbf, data_ca->dptr, key_size+data_size); - if (num_bytes != key_size+data_size) _gdbm_fatal (dbf, "read error"); + if (num_bytes != key_size+data_size) _gdbm_fatal (dbf, _("read error")); diff --git a/src/gdbmdefs.h b/src/gdbmdefs.h index e45abf8..28995de 100644 --- a/src/gdbmdefs.h +++ b/src/gdbmdefs.h @@ -22,2 +22,7 @@ #include "gdbm.h" +#define DEFAULT_TEXT_DOMAIN PACKAGE +#include "gettext.h" + +#define _(s) gettext (s) +#define N_(s) s diff --git a/src/gdbmerrno.c b/src/gdbmerrno.c index 00d9271..16c07c2 100644 --- a/src/gdbmerrno.c +++ b/src/gdbmerrno.c @@ -21,3 +21,3 @@ -#include "gdbm.h" +#include "gdbmdefs.h" @@ -30,26 +30,26 @@ gdbm_error gdbm_errno = GDBM_NO_ERROR; const char * const gdbm_errlist[_GDBM_MAX_ERRNO+1] = { - "No error", /* GDBM_NO_ERROR */ - "Malloc error", /* GDBM_MALLOC_ERROR */ - "Block size error", /* GDBM_BLOCK_SIZE_ERROR */ - "File open error", /* GDBM_FILE_OPEN_ERROR */ - "File write error", /* GDBM_FILE_WRITE_ERROR */ - "File seek error", /* GDBM_FILE_SEEK_ERROR */ - "File read error", /* GDBM_FILE_READ_ERROR */ - "Bad magic number", /* GDBM_BAD_MAGIC_NUMBER */ - "Empty database", /* GDBM_EMPTY_DATABASE */ - "Can't be reader", /* GDBM_CANT_BE_READER */ - "Can't be writer", /* GDBM_CANT_BE_WRITER */ - "Reader can't delete", /* GDBM_READER_CANT_DELETE */ - "Reader can't store", /* GDBM_READER_CANT_STORE */ - "Reader can't reorganize", /* GDBM_READER_CANT_REORGANIZE */ - "Unknown update", /* GDBM_UNKNOWN_UPDATE */ - "Item not found", /* GDBM_ITEM_NOT_FOUND */ - "Reorganize failed", /* GDBM_REORGANIZE_FAILED */ - "Cannot replace", /* GDBM_CANNOT_REPLACE */ - "Illegal data", /* GDBM_ILLEGAL_DATA */ - "Option already set", /* GDBM_OPT_ALREADY_SET */ - "Illegal option", /* GDBM_OPT_ILLEGAL */ - "Byte-swapped file", /* GDBM_BYTE_SWAPPED */ - "Wrong file offset", /* GDBM_BAD_FILE_OFFSET */ - "Bad file flags" /* GDBM_BAD_OPEN_FLAGS */ + N_("No error"), /* GDBM_NO_ERROR */ + N_("Malloc error"), /* GDBM_MALLOC_ERROR */ + N_("Block size error"), /* GDBM_BLOCK_SIZE_ERROR */ + N_("File open error"), /* GDBM_FILE_OPEN_ERROR */ + N_("File write error"), /* GDBM_FILE_WRITE_ERROR */ + N_("File seek error"), /* GDBM_FILE_SEEK_ERROR */ + N_("File read error"), /* GDBM_FILE_READ_ERROR */ + N_("Bad magic number"), /* GDBM_BAD_MAGIC_NUMBER */ + N_("Empty database"), /* GDBM_EMPTY_DATABASE */ + N_("Can't be reader"), /* GDBM_CANT_BE_READER */ + N_("Can't be writer"), /* GDBM_CANT_BE_WRITER */ + N_("Reader can't delete"), /* GDBM_READER_CANT_DELETE */ + N_("Reader can't store"), /* GDBM_READER_CANT_STORE */ + N_("Reader can't reorganize"), /* GDBM_READER_CANT_REORGANIZE */ + N_("Unknown update"), /* GDBM_UNKNOWN_UPDATE */ + N_("Item not found"), /* GDBM_ITEM_NOT_FOUND */ + N_("Reorganize failed"), /* GDBM_REORGANIZE_FAILED */ + N_("Cannot replace"), /* GDBM_CANNOT_REPLACE */ + N_("Illegal data"), /* GDBM_ILLEGAL_DATA */ + N_("Option already set"), /* GDBM_OPT_ALREADY_SET */ + N_("Illegal option"), /* GDBM_OPT_ILLEGAL */ + N_("Byte-swapped file"), /* GDBM_BYTE_SWAPPED */ + N_("Wrong file offset"), /* GDBM_BAD_FILE_OFFSET */ + N_("Bad file flags") /* GDBM_BAD_OPEN_FLAGS */ }; @@ -57,7 +57,7 @@ const char * const gdbm_errlist[_GDBM_MAX_ERRNO+1] = { const char * -gdbm_strerror(gdbm_error error) +gdbm_strerror (gdbm_error error) { - if(((int)error < _GDBM_MIN_ERRNO) || ((int)error > _GDBM_MAX_ERRNO)) + if (((int)error < _GDBM_MIN_ERRNO) || ((int)error > _GDBM_MAX_ERRNO)) { - return("Unknown error"); + return _("Unknown error"); } @@ -65,3 +65,3 @@ gdbm_strerror(gdbm_error error) { - return(gdbm_errlist[(int)error]); + return gettext (gdbm_errlist[(int)error]); } diff --git a/src/gdbmfetch.c b/src/gdbmfetch.c index 39c9cd2..9095d6d 100644 --- a/src/gdbmfetch.c +++ b/src/gdbmfetch.c @@ -55,3 +55,3 @@ gdbm_fetch (GDBM_FILE dbf, datum key) return_val.dptr = (char *) malloc (return_val.dsize); - if (return_val.dptr == NULL) _gdbm_fatal (dbf, "malloc error"); + if (return_val.dptr == NULL) _gdbm_fatal (dbf, _("malloc error")); memcpy (return_val.dptr, find_data, return_val.dsize); diff --git a/src/gdbmseq.c b/src/gdbmseq.c index cd2421a..4323185 100644 --- a/src/gdbmseq.c +++ b/src/gdbmseq.c @@ -72,3 +72,3 @@ get_next_key (GDBM_FILE dbf, int elem_loc, datum *return_val) return_val->dptr = (char *) malloc (return_val->dsize); - if (return_val->dptr == NULL) _gdbm_fatal (dbf, "malloc error"); + if (return_val->dptr == NULL) _gdbm_fatal (dbf, _("malloc error")); memcpy (return_val->dptr, find_data, return_val->dsize); diff --git a/src/gdbmstore.c b/src/gdbmstore.c index 35a6863..5f1bb67 100644 --- a/src/gdbmstore.c +++ b/src/gdbmstore.c @@ -140,7 +140,7 @@ gdbm_store (GDBM_FILE dbf, datum key, datum content, int flags) file_pos = __lseek (dbf, file_adr, L_SET); - if (file_pos != file_adr) _gdbm_fatal (dbf, "lseek error"); + if (file_pos != file_adr) _gdbm_fatal (dbf, _("lseek error")); num_bytes = __write (dbf, key.dptr, key.dsize); - if (num_bytes != key.dsize) _gdbm_fatal (dbf, "write error"); + if (num_bytes != key.dsize) _gdbm_fatal (dbf, _("write error")); num_bytes = __write (dbf, content.dptr, content.dsize); - if (num_bytes != content.dsize) _gdbm_fatal (dbf, "write error"); + if (num_bytes != content.dsize) _gdbm_fatal (dbf, _("write error")); diff --git a/src/gettext.h b/src/gettext.h new file mode 100644 index 0000000..e76b592 --- /dev/null +++ b/src/gettext.h @@ -0,0 +1,280 @@ +/* Convenience header for conditional use of GNU <libintl.h>. + Copyright (C) 1995-1998, 2000-2002, 2004-2006, 2009 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, 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 + Library General Public License for more details. + + You should have received a copy of the GNU General Public + License along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. */ + +#ifndef _LIBGETTEXT_H +#define _LIBGETTEXT_H 1 + +/* NLS can be disabled through the configure --disable-nls option. */ +#if ENABLE_NLS + +/* Get declarations of GNU message catalog functions. */ +# include <libintl.h> + +/* You can set the DEFAULT_TEXT_DOMAIN macro to specify the domain used by + the gettext() and ngettext() macros. This is an alternative to calling + textdomain(), and is useful for libraries. */ +# ifdef DEFAULT_TEXT_DOMAIN +# undef gettext +# define gettext(Msgid) \ + dgettext (DEFAULT_TEXT_DOMAIN, Msgid) +# undef ngettext +# define ngettext(Msgid1, Msgid2, N) \ + dngettext (DEFAULT_TEXT_DOMAIN, Msgid1, Msgid2, N) +# endif + +#else + +/* Solaris /usr/include/locale.h includes /usr/include/libintl.h, which + chokes if dcgettext is defined as a macro. So include it now, to make + later inclusions of <locale.h> a NOP. We don't include <libintl.h> + as well because people using "gettext.h" will not include <libintl.h>, + and also including <libintl.h> would fail on SunOS 4, whereas <locale.h> + is OK. */ +#if defined(__sun) +# include <locale.h> +#endif + +/* Many header files from the libstdc++ coming with g++ 3.3 or newer include + <libintl.h>, which chokes if dcgettext is defined as a macro. So include + it now, to make later inclusions of <libintl.h> a NOP. */ +#if defined(__cplusplus) && defined(__GNUG__) && (__GNUC__ >= 3) +# include <cstdlib> +# if (__GLIBC__ >= 2) || _GLIBCXX_HAVE_LIBINTL_H +# include <libintl.h> +# endif +#endif + +/* Disabled NLS. + The casts to 'const char *' serve the purpose of producing warnings + for invalid uses of the value returned from these functions. + On pre-ANSI systems without 'const', the config.h file is supposed to + contain "#define const". */ +# undef gettext +# define gettext(Msgid) ((const char *) (Msgid)) +# undef dgettext +# define dgettext(Domainname, Msgid) ((void) (Domainname), gettext (Msgid)) +# undef dcgettext +# define dcgettext(Domainname, Msgid, Category) \ + ((void) (Category), dgettext (Domainname, Msgid)) +# undef ngettext +# define ngettext(Msgid1, Msgid2, N) \ + ((N) == 1 \ + ? ((void) (Msgid2), (const char *) (Msgid1)) \ + : ((void) (Msgid1), (const char *) (Msgid2))) +# undef dngettext +# define dngettext(Domainname, Msgid1, Msgid2, N) \ + ((void) (Domainname), ngettext (Msgid1, Msgid2, N)) +# undef dcngettext +# define dcngettext(Domainname, Msgid1, Msgid2, N, Category) \ + ((void) (Category), dngettext(Domainname, Msgid1, Msgid2, N)) +# undef textdomain +# define textdomain(Domainname) ((const char *) (Domainname)) +# undef bindtextdomain +# define bindtextdomain(Domainname, Dirname) \ + ((void) (Domainname), (const char *) (Dirname)) +# undef bind_textdomain_codeset +# define bind_textdomain_codeset(Domainname, Codeset) \ + ((void) (Domainname), (const char *) (Codeset)) + +#endif + +/* A pseudo function call that serves as a marker for the automated + extraction of messages, but does not call gettext(). The run-time + translation is done at a different place in the code. + The argument, String, should be a literal string. Concatenated strings + and other string expressions won't work. + The macro's expansion is not parenthesized, so that it is suitable as + initializer for static 'char[]' or 'const char[]' variables. */ +#define gettext_noop(String) String + +/* The separator between msgctxt and msgid in a .mo file. */ +#define GETTEXT_CONTEXT_GLUE "\004" + +/* Pseudo function calls, taking a MSGCTXT and a MSGID instead of just a + MSGID. MSGCTXT and MSGID must be string literals. MSGCTXT should be + short and rarely need to change. + The letter 'p' stands for 'particular' or 'special'. */ +#ifdef DEFAULT_TEXT_DOMAIN +# define pgettext(Msgctxt, Msgid) \ + pgettext_aux (DEFAULT_TEXT_DOMAIN, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, LC_MESSAGES) +#else +# define pgettext(Msgctxt, Msgid) \ + pgettext_aux (NULL, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, LC_MESSAGES) +#endif +#define dpgettext(Domainname, Msgctxt, Msgid) \ + pgettext_aux (Domainname, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, LC_MESSAGES) +#define dcpgettext(Domainname, Msgctxt, Msgid, Category) \ + pgettext_aux (Domainname, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, Category) +#ifdef DEFAULT_TEXT_DOMAIN +# define npgettext(Msgctxt, Msgid, MsgidPlural, N) \ + npgettext_aux (DEFAULT_TEXT_DOMAIN, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, MsgidPlural, N, LC_MESSAGES) +#else +# define npgettext(Msgctxt, Msgid, MsgidPlural, N) \ + npgettext_aux (NULL, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, MsgidPlural, N, LC_MESSAGES) +#endif +#define dnpgettext(Domainname, Msgctxt, Msgid, MsgidPlural, N) \ + npgettext_aux (Domainname, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, MsgidPlural, N, LC_MESSAGES) +#define dcnpgettext(Domainname, Msgctxt, Msgid, MsgidPlural, N, Category) \ + npgettext_aux (Domainname, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, MsgidPlural, N, Category) + +#ifdef __GNUC__ +__inline +#else +#ifdef __cplusplus +inline +#endif +#endif +static const char * +pgettext_aux (const char *domain, + const char *msg_ctxt_id, const char *msgid, + int category) +{ + const char *translation = dcgettext (domain, msg_ctxt_id, category); + if (translation == msg_ctxt_id) + return msgid; + else + return translation; +} + +#ifdef __GNUC__ +__inline +#else +#ifdef __cplusplus +inline +#endif +#endif +static const char * +npgettext_aux (const char *domain, + const char *msg_ctxt_id, const char *msgid, + const char *msgid_plural, unsigned long int n, + int category) +{ + const char *translation = + dcngettext (domain, msg_ctxt_id, msgid_plural, n, category); + if (translation == msg_ctxt_id || translation == msgid_plural) + return (n == 1 ? msgid : msgid_plural); + else + return translation; +} + +/* The same thing extended for non-constant arguments. Here MSGCTXT and MSGID + can be arbitrary expressions. But for string literals these macros are + less efficient than those above. */ + +#include <string.h> + +#define _LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS \ + (((__GNUC__ >= 3 || __GNUG__ >= 2) && !__STRICT_ANSI__) \ + /* || __STDC_VERSION__ >= 199901L */ ) + +#if !_LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS +#include <stdlib.h> +#endif + +#define pgettext_expr(Msgctxt, Msgid) \ + dcpgettext_expr (NULL, Msgctxt, Msgid, LC_MESSAGES) +#define dpgettext_expr(Domainname, Msgctxt, Msgid) \ + dcpgettext_expr (Domainname, Msgctxt, Msgid, LC_MESSAGES) + +#ifdef __GNUC__ +__inline +#else +#ifdef __cplusplus +inline +#endif +#endif +static const char * +dcpgettext_expr (const char *domain, + const char *msgctxt, const char *msgid, + int category) +{ + size_t msgctxt_len = strlen (msgctxt) + 1; + size_t msgid_len = strlen (msgid) + 1; + const char *translation; +#if _LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS + char msg_ctxt_id[msgctxt_len + msgid_len]; +#else + char buf[1024]; + char *msg_ctxt_id = + (msgctxt_len + msgid_len <= sizeof (buf) + ? buf + : (char *) malloc (msgctxt_len + msgid_len)); + if (msg_ctxt_id != NULL) +#endif + { + memcpy (msg_ctxt_id, msgctxt, msgctxt_len - 1); + msg_ctxt_id[msgctxt_len - 1] = '\004'; + memcpy (msg_ctxt_id + msgctxt_len, msgid, msgid_len); + translation = dcgettext (domain, msg_ctxt_id, category); +#if !_LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS + if (msg_ctxt_id != buf) + free (msg_ctxt_id); +#endif + if (translation != msg_ctxt_id) + return translation; + } + return msgid; +} + +#define npgettext_expr(Msgctxt, Msgid, MsgidPlural, N) \ + dcnpgettext_expr (NULL, Msgctxt, Msgid, MsgidPlural, N, LC_MESSAGES) +#define dnpgettext_expr(Domainname, Msgctxt, Msgid, MsgidPlural, N) \ + dcnpgettext_expr (Domainname, Msgctxt, Msgid, MsgidPlural, N, LC_MESSAGES) + +#ifdef __GNUC__ +__inline +#else +#ifdef __cplusplus +inline +#endif +#endif +static const char * +dcnpgettext_expr (const char *domain, + const char *msgctxt, const char *msgid, + const char *msgid_plural, unsigned long int n, + int category) +{ + size_t msgctxt_len = strlen (msgctxt) + 1; + size_t msgid_len = strlen (msgid) + 1; + const char *translation; +#if _LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS + char msg_ctxt_id[msgctxt_len + msgid_len]; +#else + char buf[1024]; + char *msg_ctxt_id = + (msgctxt_len + msgid_len <= sizeof (buf) + ? buf + : (char *) malloc (msgctxt_len + msgid_len)); + if (msg_ctxt_id != NULL) +#endif + { + memcpy (msg_ctxt_id, msgctxt, msgctxt_len - 1); + msg_ctxt_id[msgctxt_len - 1] = '\004'; + memcpy (msg_ctxt_id + msgctxt_len, msgid, msgid_len); + translation = dcngettext (domain, msg_ctxt_id, msgid_plural, n, category); +#if !_LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS + if (msg_ctxt_id != buf) + free (msg_ctxt_id); +#endif + if (!(translation == msg_ctxt_id || translation == msgid_plural)) + return translation; + } + return (n == 1 ? msgid : msgid_plural); +} + +#endif /* _LIBGETTEXT_H */ diff --git a/src/testgdbm.c b/src/testgdbm.c index 276f649..fb6b846 100644 --- a/src/testgdbm.c +++ b/src/testgdbm.c @@ -34,2 +34,5 @@ #include <stdarg.h> +#ifdef HAVE_LOCALE_H +# include <locale.h> +#endif @@ -77,6 +80,7 @@ print_bucket (FILE *fp, hash_bucket *bucket, char *mesg) - fprintf (fp, "******* %s **********\n\nbits = %d\ncount= %d\nHash Table:\n", + fprintf (fp, + _("******* %s **********\n\nbits = %d\ncount= %d\nHash Table:\n"), mesg, bucket->bucket_bits, bucket->count); fprintf (fp, - " # hash value key size data size data adr home\n"); + _(" # hash value key size data size data adr home\n")); for (index = 0; index < gdbm_file->header->bucket_elems; index++) @@ -90,4 +94,4 @@ print_bucket (FILE *fp, hash_bucket *bucket, char *mesg) - fprintf (fp, "\nAvail count = %1d\n", bucket->av_count); - fprintf (fp, "Avail adr size\n"); + fprintf (fp, _("\nAvail count = %1d\n"), bucket->av_count); + fprintf (fp, _("Avail adr size\n")); for (index = 0; index < bucket->av_count; index++) @@ -115,3 +119,3 @@ _gdbm_avail_list_size (GDBM_FILE dbf, size_t min_size) if (av_stk == NULL) - error (2, "Out of memory"); + error (2, _("Out of memory")); @@ -150,3 +154,3 @@ _gdbm_print_avail_list (FILE *fp, GDBM_FILE dbf) /* Print the the header avail block. */ - fprintf (fp, "\nheader block\nsize = %d\ncount = %d\n", + fprintf (fp, _("\nheader block\nsize = %d\ncount = %d\n"), dbf->header->avail.size, dbf->header->avail.count); @@ -165,3 +169,3 @@ _gdbm_print_avail_list (FILE *fp, GDBM_FILE dbf) if (av_stk == NULL) - error (2, "Out of memory"); + error (2, _("Out of memory")); @@ -183,4 +187,4 @@ _gdbm_print_avail_list (FILE *fp, GDBM_FILE dbf) /* Print the block! */ - fprintf (fp, "\nblock = %d\nsize = %d\ncount = %d\n", temp, - av_stk->size, av_stk->count); + fprintf (fp, _("\nblock = %d\nsize = %d\ncount = %d\n"), temp, + av_stk->size, av_stk->count); for (temp = 0; temp < av_stk->count; temp++) @@ -203,5 +207,4 @@ _gdbm_print_bucket_cache (FILE *fp, GDBM_FILE dbf) { - fprintf - (fp, - "Bucket Cache (size %d):\n Index: Address Changed Data_Hash \n", + fprintf (fp, + _("Bucket Cache (size %d):\n Index: Address Changed Data_Hash \n"), dbf->cache_size); @@ -213,3 +216,3 @@ _gdbm_print_bucket_cache (FILE *fp, GDBM_FILE dbf) (unsigned long) dbf->bucket_cache[index].ca_adr, - (changed ? "True" : "False"), + (changed ? _("True") : _("False")), dbf->bucket_cache[index].ca_data.hash_val); @@ -218,3 +221,3 @@ _gdbm_print_bucket_cache (FILE *fp, GDBM_FILE dbf) else - fprintf (fp, "Bucket cache has not been initialized.\n"); + fprintf (fp, _("Bucket cache has not been initialized.\n")); } @@ -224,18 +227,18 @@ usage () { - printf ("Usage: %s OPTIONS\n", progname); - printf ("Test and modify a GDBM database.\n"); + printf (_("Usage: %s OPTIONS\n"), progname); + printf (_("Test and modify a GDBM database.\n")); printf ("\n"); - printf ("OPTIONS are:\n\n"); - printf (" -b SIZE set block size\n"); - printf (" -c SIZE set cache size\n"); - printf (" -g FILE operate on FILE instead of `junk.gdbm'\n"); - printf (" -h print this help summary\n"); - printf (" -l disable file locking\n"); - printf (" -m disable file mmap\n"); - printf (" -n create database\n"); - printf (" -r open database in read-only mode\n"); - printf (" -s synchronize to the disk after each write\n"); - printf (" -v print program version\n"); + printf (_("OPTIONS are:\n\n")); + printf (_(" -b SIZE set block size\n")); + printf (_(" -c SIZE set cache size\n")); + printf (_(" -g FILE operate on FILE instead of `junk.gdbm'\n")); + printf (_(" -h print this help summary\n")); + printf (_(" -l disable file locking\n")); + printf (_(" -m disable file mmap\n")); + printf (_(" -n create database\n")); + printf (_(" -r open database in read-only mode\n")); + printf (_(" -s synchronize to the disk after each write\n")); + printf (_(" -v print program version\n")); printf ("\n"); - printf ("Report bugs to <%s>.\n", PACKAGE_BUGREPORT); + printf (_("Report bugs to <%s>.\n"), PACKAGE_BUGREPORT); } @@ -278,3 +281,3 @@ read_from_file (const char *name, int replace) { - error (0, "cannot open file `%s' for reading: %s", + error (0, _("cannot open file `%s' for reading: %s"), name, strerror (errno)); @@ -289,3 +292,3 @@ read_from_file (const char *name, int replace) { - error (0, "%s:%d: line too long", name, line); + error (0, _("%s:%d: line too long"), name, line); continue; @@ -297,3 +300,3 @@ read_from_file (const char *name, int replace) { - error (0, "%s:%d: malformed line", name, line); + error (0, _("%s:%d: malformed line"), name, line); continue; @@ -308,3 +311,3 @@ read_from_file (const char *name, int replace) if (gdbm_store (gdbm_file, key, data, flag) != 0) - error (0, "%d: item not inserted: %s", + error (0, _("%d: item not inserted: %s"), line, gdbm_strerror (gdbm_errno)); @@ -366,3 +369,6 @@ count_handler (char *arg[NARGS] ARG_UNUSED, FILE *fp, { - fprintf (fp, "There are %d items in the database.\n", get_record_count ()); + int count = get_record_count (); + fprintf (fp, ngettext ("There is %d item in the database.\n", + "There are %d items in the database.\n", count), + count); } @@ -380,5 +386,5 @@ delete_handler (char *arg[NARGS], FILE *fp, void *call_data ARG_UNUSED) if (gdbm_errno == GDBM_ITEM_NOT_FOUND) - error (0, "Item not found"); + error (0, _("Item not found")); else - error (0, "Can't delete: %s", gdbm_strerror (gdbm_errno)); + error (0, _("Can't delete: %s"), gdbm_strerror (gdbm_errno)); } @@ -401,3 +407,3 @@ fetch_handler (char *arg[NARGS], FILE *fp, void *call_data ARG_UNUSED) else - fprintf (stderr, "No such item found.\n"); + fprintf (stderr, _("No such item found.\n")); } @@ -426,3 +432,3 @@ nextkey_handler (char *arg[NARGS], FILE *fp, void *call_data ARG_UNUSED) { - fprintf (stderr, "No such item found.\n"); + fprintf (stderr, _("No such item found.\n")); free (key_data.dptr); @@ -444,3 +450,3 @@ store_handler (char *arg[NARGS], FILE *fp, void *call_data ARG_UNUSED) if (gdbm_store (gdbm_file, key, data, GDBM_REPLACE) != 0) - fprintf (stderr, "Item not inserted.\n"); + fprintf (stderr, _("Item not inserted.\n")); } @@ -463,3 +469,3 @@ firstkey_handler (char *arg[NARGS], FILE *fp, void *call_data ARG_UNUSED) else - fprintf (fp, "No such item found.\n"); + fprintf (fp, _("No such item found.\n")); } @@ -482,3 +488,3 @@ next_on_last_handler (char *arg[NARGS] ARG_UNUSED, FILE *fp, else - fprintf (stderr, "No such item found.\n"); + fprintf (stderr, _("No such item found.\n")); } @@ -491,5 +497,5 @@ reorganize_handler (char *arg[NARGS] ARG_UNUSED, FILE *fp ARG_UNUSED, if (gdbm_reorganize (gdbm_file)) - fprintf (stderr, "Reorganization failed.\n"); + fprintf (stderr, _("Reorganization failed.\n")); else - fprintf (stderr, "Reorganization succeeded.\n"); + fprintf (stderr, _("Reorganization succeeded.\n")); } @@ -525,6 +531,6 @@ print_current_bucket_handler (char *arg[NARGS] ARG_UNUSED, FILE *fp, { - print_bucket (fp, gdbm_file->bucket, "Current bucket"); - fprintf (fp, "\n current directory entry = %d.\n", + print_bucket (fp, gdbm_file->bucket, _("Current bucket")); + fprintf (fp, _("\n current directory entry = %d.\n"), gdbm_file->bucket_dir); - fprintf (fp, " current bucket address = %lu.\n", + fprintf (fp, _(" current bucket address = %lu.\n"), (unsigned long) gdbm_file->cache_entry->ca_adr); @@ -539,3 +545,3 @@ getnum (int *pnum, char *arg, char **endp) { - printf ("not a number (stopped near %s)\n", p); + printf (_("not a number (stopped near %s)\n"), p); return 1; @@ -548,3 +554,3 @@ getnum (int *pnum, char *arg, char **endp) { - printf ("not a number (stopped near %s)\n", p); + printf (_("not a number (stopped near %s)\n"), p); return 1; @@ -567,3 +573,3 @@ print_bucket_begin (char *arg[NARGS], size_t *exp_count, void **data ARG_UNUSED) { - fprintf (stderr, "Not a bucket.\n"); + fprintf (stderr, _("Not a bucket.\n")); return 1; @@ -592,4 +598,4 @@ print_dir_handler (char *arg[NARGS] ARG_UNUSED, FILE *out, - fprintf (out, "Hash table directory.\n"); - fprintf (out, " Size = %d. Bits = %d. \n\n", + fprintf (out, _("Hash table directory.\n")); + fprintf (out, _(" Size = %d. Bits = %d. \n\n"), gdbm_file->header->dir_size, gdbm_file->header->dir_bits); @@ -612,16 +618,16 @@ print_header_handler (char *arg[NARGS] ARG_UNUSED, FILE *fp, void *call_data) { - fprintf (fp, "\nFile Header: \n\n"); - fprintf (fp, " table = %lu\n", + fprintf (fp, _("\nFile Header: \n\n")); + fprintf (fp, _(" table = %lu\n"), (unsigned long) gdbm_file->header->dir); - fprintf (fp, " table size = %d\n", gdbm_file->header->dir_size); - fprintf (fp, " table bits = %d\n", gdbm_file->header->dir_bits); - fprintf (fp, " block size = %d\n", gdbm_file->header->block_size); - fprintf (fp, " bucket elems = %d\n", gdbm_file->header->bucket_elems); - fprintf (fp, " bucket size = %d\n", gdbm_file->header->bucket_size); - fprintf (fp, " header magic = %x\n", gdbm_file->header->header_magic); - fprintf (fp, " next block = %lu\n", + fprintf (fp, _(" table size = %d\n"), gdbm_file->header->dir_size); + fprintf (fp, _(" table bits = %d\n"), gdbm_file->header->dir_bits); + fprintf (fp, _(" block size = %d\n"), gdbm_file->header->block_size); + fprintf (fp, _(" bucket elems = %d\n"), gdbm_file->header->bucket_elems); + fprintf (fp, _(" bucket size = %d\n"), gdbm_file->header->bucket_size); + fprintf (fp, _(" header magic = %x\n"), gdbm_file->header->header_magic); + fprintf (fp, _(" next block = %lu\n"), (unsigned long) gdbm_file->header->next_block); - fprintf (fp, " avail size = %d\n", gdbm_file->header->avail.size); - fprintf (fp, " avail count = %d\n", gdbm_file->header->avail.count); - fprintf (fp, " avail nx blk = %lu\n", + fprintf (fp, _(" avail size = %d\n"), gdbm_file->header->avail.size); + fprintf (fp, _(" avail count = %d\n"), gdbm_file->header->avail.count); + fprintf (fp, _(" avail nx blk = %lu\n"), (unsigned long) gdbm_file->header->avail.next_block); @@ -637,3 +643,3 @@ hash_handler (char *arg[NARGS], FILE *fp, void *call_data) key.dsize = strlen (arg[0]) + key_z; - fprintf (fp, "hash value = %x. \n", _gdbm_hash (key)); + fprintf (fp, _("hash value = %x. \n"), _gdbm_hash (key)); } @@ -693,3 +699,3 @@ list_handler (char *arg[NARGS] ARG_UNUSED, FILE *fp, void *call_data) if (!data.dptr) - error (0, "cannot fetch data (key %.*s)", key.dsize, key.dptr); + error (0, _("cannot fetch data (key %.*s)"), key.dsize, key.dptr); else @@ -726,3 +732,3 @@ export_handler (char *arg[NARGS], FILE *fp, void *call_data ARG_UNUSED) if (gdbm_export (gdbm_file, arg[0], flags, 0600) == -1) - error (0, "gdbm_export failed, %s", gdbm_strerror (gdbm_errno)); + error (0, _("gdbm_export failed, %s"), gdbm_strerror (gdbm_errno)); } @@ -739,5 +745,11 @@ import_handler (char *arg[NARGS], FILE *fp, void *call_data ARG_UNUSED) if (gdbm_import (gdbm_file, arg[0], flag) == -1) - error (0, "gdbm_import failed, %s", gdbm_strerror (gdbm_errno)); + error (0, _("gdbm_import failed, %s"), gdbm_strerror (gdbm_errno)); } +static const char * +boolstr(int val) +{ + return val ? _("yes") : _("no"); +} + /* S - print current program status */ @@ -747,5 +759,5 @@ status_handler (char *arg[NARGS] ARG_UNUSED, FILE *fp, { - fprintf (fp, "Database file: %s\n", file_name); - fprintf (fp, "Zero terminated keys: %s\n", key_z ? "yes" : "no"); - fprintf (fp, "Zero terminated data: %s\n", data_z ? "yes" : "no"); + fprintf (fp, _("Database file: %s\n"), file_name); + fprintf (fp, _("Zero terminated keys: %s\n"), boolstr (key_z)); + fprintf (fp, _("Zero terminated data: %s\n"), boolstr (data_z)); } @@ -758,3 +770,3 @@ key_z_handler (char *arg[NARGS] ARG_UNUSED, FILE *fp, key_z = !key_z; - fprintf (fp, "Zero terminated keys: %s\n", key_z ? "yes" : "no"); + fprintf (fp, _("Zero terminated keys: %s\n"), boolstr (key_z)); } @@ -767,3 +779,3 @@ data_z_handler (char *arg[NARGS] ARG_UNUSED, FILE *fp, data_z = !data_z; - fprintf (fp, "Zero terminated data: %s\n", data_z ? "yes" : "no"); + fprintf (fp, "Zero terminated data: %s\n", boolstr (data_z)); } @@ -787,56 +799,54 @@ struct command command_tab[] = { { 'c', NULL, count_handler, NULL, - { NULL, NULL, }, "count (number of entries)" }, + { NULL, NULL, }, N_("count (number of entries)") }, { 'd', NULL, delete_handler, NULL, - { "key", NULL, }, "delete" }, + { N_("key"), NULL, }, N_("delete") }, { 'e', NULL, export_handler, NULL, - { "file", "[truncate]", }, "export" }, + { N_("file"), "[truncate]", }, N_("export") }, { 'f', NULL, fetch_handler, NULL, - { "key", NULL }, "fetch" }, + { N_("key"), NULL }, N_("fetch") }, { 'i', NULL, import_handler, NULL, - { "file", "[replace]", }, "import" }, + { N_("file"), "[replace]", }, N_("import") }, { 'l', list_begin, list_handler, NULL, - { NULL, NULL }, "list" }, + { NULL, NULL }, N_("list") }, { 'n', NULL, nextkey_handler, NULL, - { "[key]", NULL }, "nextkey" }, - { 'q', NULL, quit_handler, NULL, - { NULL, NULL }, "quit" }, + { N_("[key]"), NULL }, N_("nextkey") }, { 's', NULL, store_handler, NULL, - { "key", "data" }, "store" }, + { N_("key"), N_("data") }, N_("store") }, { |