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 | 54 | ||||
-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 | 241 | ||||
-rw-r--r-- | src/update.c | 13 |
12 files changed, 470 insertions, 170 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index c2c2483..db85972 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -15,13 +15,14 @@ # along with GDBM. If not, see <http://www.gnu.org/licenses/>. # Flags -AM_CPPFLAGS=-DIN_GDBM +AM_CPPFLAGS=-DIN_GDBM -DLOCALEDIR=\"$(localedir)\" # Headers include_HEADERS = gdbm.h noinst_HEADERS = \ gdbmconst.h\ gdbmdefs.h\ + gettext.h\ proto.h\ systems.h @@ -33,6 +34,8 @@ VI_REVISION = 0 VI_AGE = 0 lib_LTLIBRARIES = libgdbm.la +LIBADD = @LTLIBINTL@ + libgdbm_la_SOURCES = \ gdbmopen.c\ gdbmdelete.c\ diff --git a/src/bucket.c b/src/bucket.c index f8c48b9..cda2389 100644 --- a/src/bucket.c +++ b/src/bucket.c @@ -64,7 +64,7 @@ _gdbm_get_bucket (GDBM_FILE dbf, int dir_index) if (dbf->bucket_cache == NULL) { if(_gdbm_init_cache(dbf, DEFAULT_CACHESIZE) == -1) - _gdbm_fatal(dbf, "couldn't init cache"); + _gdbm_fatal(dbf, _("couldn't init cache")); } /* Is that one is not already current, we must find it. */ @@ -94,11 +94,11 @@ _gdbm_get_bucket (GDBM_FILE dbf, int dir_index) /* Read the bucket. */ file_pos = __lseek (dbf, bucket_adr, L_SET); if (file_pos != bucket_adr) - _gdbm_fatal (dbf, "lseek error"); + _gdbm_fatal (dbf, _("lseek error")); num_bytes = __read (dbf, dbf->bucket, dbf->header->bucket_size); if (num_bytes != dbf->header->bucket_size) - _gdbm_fatal (dbf, "read error"); + _gdbm_fatal (dbf, _("read error")); } return; @@ -145,7 +145,7 @@ _gdbm_split_bucket (GDBM_FILE dbf, int next_insert) if (dbf->bucket_cache == NULL) { if(_gdbm_init_cache(dbf, DEFAULT_CACHESIZE) == -1) - _gdbm_fatal(dbf, "couldn't init cache"); + _gdbm_fatal(dbf, _("couldn't init cache")); } while (dbf->bucket->count == dbf->header->bucket_elems) @@ -185,7 +185,7 @@ _gdbm_split_bucket (GDBM_FILE dbf, int next_insert) dir_size = dbf->header->dir_size * 2; dir_adr = _gdbm_alloc (dbf, dir_size); 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; index < dbf->header->dir_size/sizeof (off_t); index++) { @@ -308,10 +308,10 @@ _gdbm_write_bucket (GDBM_FILE dbf, cache_elem *ca_entry) file_pos = __lseek (dbf, ca_entry->ca_adr, L_SET); 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; ca_entry->ca_data.hash_val = -1; ca_entry->ca_data.elem_loc = -1; diff --git a/src/falloc.c b/src/falloc.c index 2a54d53..d0af4a6 100644 --- a/src/falloc.c +++ b/src/falloc.c @@ -178,13 +178,13 @@ pop_avail_block (GDBM_FILE dbf) /* Allocate space for the block. */ 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")); /* Read the block. */ 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")); /* Add the elements from the new block to the header. */ index = 0; @@ -256,7 +256,7 @@ push_avail_block (GDBM_FILE dbf) /* Split the header block. */ 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. */ temp->size = dbf->header->avail.size; temp->count = 0; @@ -279,9 +279,9 @@ push_avail_block (GDBM_FILE dbf) /* Update the disk. */ 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 @@ -54,15 +54,15 @@ _gdbm_read_entry (GDBM_FILE dbf, int elem_loc) data_ca->dptr = (char *) malloc (1); else 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")); /* Read into the cache. */ file_pos = __lseek (dbf, dbf->bucket->h_table[elem_loc].data_pointer, L_SET); 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")); return data_ca->dptr; } diff --git a/src/gdbmdefs.h b/src/gdbmdefs.h index e45abf8..28995de 100644 --- a/src/gdbmdefs.h +++ b/src/gdbmdefs.h @@ -20,6 +20,11 @@ #include "systems.h" #include "gdbmconst.h" #include "gdbm.h" +#define DEFAULT_TEXT_DOMAIN PACKAGE +#include "gettext.h" + +#define _(s) gettext (s) +#define N_(s) s /* The type definitions are next. */ diff --git a/src/gdbmerrno.c b/src/gdbmerrno.c index 00d9271..16c07c2 100644 --- a/src/gdbmerrno.c +++ b/src/gdbmerrno.c @@ -19,7 +19,7 @@ /* Include system configuration before all else. */ #include "autoconf.h" -#include "gdbm.h" +#include "gdbmdefs.h" /* The dbm error number is placed in the variable GDBM_ERRNO. */ gdbm_error gdbm_errno = GDBM_NO_ERROR; @@ -28,30 +28,30 @@ gdbm_error gdbm_errno = GDBM_NO_ERROR; like. it must be in the same order as the error codes! */ 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 */ }; const char * @@ -59,10 +59,10 @@ gdbm_strerror(gdbm_error error) { if (((int)error < _GDBM_MIN_ERRNO) || ((int)error > _GDBM_MAX_ERRNO)) { - return("Unknown error"); + return _("Unknown error"); } else { - 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 @@ -53,7 +53,7 @@ gdbm_fetch (GDBM_FILE dbf, datum key) return_val.dptr = (char *) malloc (1); else 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 @@ -70,7 +70,7 @@ get_next_key (GDBM_FILE dbf, int elem_loc, datum *return_val) return_val->dptr = (char *) malloc (1); else 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 @@ -138,11 +138,11 @@ gdbm_store (GDBM_FILE dbf, datum key, datum content, int flags) /* Write the data to the file. */ 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")); /* Current bucket has changed. */ dbf->cache_entry->ca_changed = TRUE; 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 @@ -32,6 +32,9 @@ # include <sys/termios.h> #endif #include <stdarg.h> +#ifdef HAVE_LOCALE_H +# include <locale.h> +#endif const char *progname; /* Program name */ @@ -75,10 +78,11 @@ print_bucket (FILE *fp, hash_bucket *bucket, char *mesg) { int index; - 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++) fprintf (fp, " %4d %12x %11d %11d %11lu %5d\n", index, bucket->h_table[index].hash_value, @@ -88,8 +92,8 @@ print_bucket (FILE *fp, hash_bucket *bucket, char *mesg) bucket->h_table[index].hash_value % gdbm_file->header->bucket_elems); - 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++) fprintf (fp, "%9lu%9d\n", (unsigned long) bucket->bucket_avail[index].av_adr, @@ -113,7 +117,7 @@ _gdbm_avail_list_size (GDBM_FILE dbf, size_t min_size) + sizeof (avail_block)); av_stk = (avail_block *) malloc (size); if (av_stk == NULL) - error (2, "Out of memory"); + error (2, _("Out of memory")); /* Traverse the stack. */ while (temp) @@ -148,7 +152,7 @@ _gdbm_print_avail_list (FILE *fp, GDBM_FILE dbf) avail_block *av_stk; /* 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); for (temp = 0; temp < dbf->header->avail.count; temp++) { @@ -163,7 +167,7 @@ _gdbm_print_avail_list (FILE *fp, GDBM_FILE dbf) + sizeof (avail_block)); av_stk = (avail_block *) malloc (size); if (av_stk == NULL) - error (2, "Out of memory"); + error (2, _("Out of memory")); /* Print the stack. */ while (temp) @@ -181,7 +185,7 @@ _gdbm_print_avail_list (FILE *fp, GDBM_FILE dbf) } /* Print the block! */ - fprintf (fp, "\nblock = %d\nsize = %d\ncount = %d\n", temp, + fprintf (fp, _("\nblock = %d\nsize = %d\ncount = %d\n"), temp, av_stk->size, av_stk->count); for (temp = 0; temp < av_stk->count; temp++) { @@ -201,9 +205,8 @@ _gdbm_print_bucket_cache (FILE *fp, GDBM_FILE dbf) if (dbf->bucket_cache != NULL) { - 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); for (index = 0; index < dbf->cache_size; index++) { @@ -211,33 +214,33 @@ _gdbm_print_bucket_cache (FILE *fp, GDBM_FILE dbf) fprintf (fp, " %5d: %7lu %7s %x\n", index, (unsigned long) dbf->bucket_cache[index].ca_adr, - (changed ? "True" : "False"), + (changed ? _("True") : _("False")), dbf->bucket_cache[index].ca_data.hash_val); } } else - fprintf (fp, "Bucket cache has not been initialized.\n"); + fprintf (fp, _("Bucket cache has not been initialized.\n")); } void 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); } void @@ -276,7 +279,7 @@ read_from_file (const char *name, int replace) fp = fopen (name, "r"); if (!fp) { - error (0, "cannot open file `%s' for reading: %s", + error (0, _("cannot open file `%s' for reading: %s"), name, strerror (errno)); return; } @@ -287,7 +290,7 @@ read_from_file (const char *name, int replace) if (!trimnl (buf)) { - error (0, "%s:%d: line too long", name, line); + error (0, _("%s:%d: line too long"), name, line); continue; } @@ -295,7 +298,7 @@ read_from_file (const char *name, int replace) p = strchr (buf, ' '); if (!p) { - error (0, "%s:%d: malformed line", name, line); + error (0, _("%s:%d: malformed line"), name, line); continue; } @@ -306,7 +309,7 @@ read_from_file (const char *name, int replace) data.dptr = p; data.dsize = strlen (p) + data_z; 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)); } fclose (fp); @@ -364,7 +367,10 @@ void count_handler (char *arg[NARGS] ARG_UNUSED, FILE *fp, void *call_data ARG_UNUSED) { - 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); } /* d key - delete */ @@ -378,9 +384,9 @@ delete_handler (char *arg[NARGS], FILE *fp, void *call_data ARG_UNUSED) if (gdbm_delete (gdbm_file, key_data) != 0) { 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)); } } @@ -399,7 +405,7 @@ fetch_handler (char *arg[NARGS], FILE *fp, void *call_data ARG_UNUSED) free (return_data.dptr); } else - fprintf (stderr, "No such item found.\n"); + fprintf (stderr, _("No such item found.\n")); } /* n [key] - next key */ @@ -424,7 +430,7 @@ nextkey_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")); free (key_data.dptr); key_data.dptr = NULL; } @@ -442,7 +448,7 @@ store_handler (char *arg[NARGS], FILE *fp, void *call_data ARG_UNUSED) data.dptr = arg[1]; data.dsize = strlen (arg[1]) + data_z; if (gdbm_store (gdbm_file, key, data, GDBM_REPLACE) != 0) - fprintf (stderr, "Item not inserted.\n"); + fprintf (stderr, _("Item not inserted.\n")); } /* 1 - begin iteration */ @@ -461,7 +467,7 @@ firstkey_handler (char *arg[NARGS], FILE *fp, void *call_data ARG_UNUSED) free (return_data.dptr); } else - fprintf (fp, "No such item found.\n"); + fprintf (fp, _("No such item found.\n")); } /* 2 - continue iteration */ @@ -480,7 +486,7 @@ next_on_last_handler (char *arg[NARGS] ARG_UNUSED, FILE *fp, free (return_data.dptr); } else - fprintf (stderr, "No such item found.\n"); + fprintf (stderr, _("No such item found.\n")); } /* r - reorganize */ @@ -489,9 +495,9 @@ reorganize_handler (char *arg[NARGS] ARG_UNUSED, FILE *fp ARG_UNUSED, void *call_data 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")); } /* A - print available list */ @@ -523,10 +529,10 @@ void print_current_bucket_handler (char *arg[NARGS] ARG_UNUSED, FILE *fp, void *call_data ARG_UNUSED) { - 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); } @@ -537,7 +543,7 @@ getnum (int *pnum, char *arg, char **endp) unsigned long x = strtoul (arg, &p, 10); if (*p && !isspace (*p)) { - printf ("not a number (stopped near %s)\n", p); + printf (_("not a number (stopped near %s)\n"), p); return 1; } while (*p && isspace (*p)) @@ -546,7 +552,7 @@ getnum (int *pnum, char *arg, char **endp) *endp = p; else if (*p) { - printf ("not a number (stopped near %s)\n", p); + printf (_("not a number (stopped near %s)\n"), p); return 1; } *pnum = x; @@ -565,7 +571,7 @@ print_bucket_begin (char *arg[NARGS], size_t *exp_count, void **data ARG_UNUSED) if (temp >= gdbm_file->header->dir_size / 4) { - fprintf (stderr, "Not a bucket.\n"); + fprintf (stderr, _("Not a bucket.\n")); return 1; } _gdbm_get_bucket (gdbm_file, temp); @@ -590,8 +596,8 @@ print_dir_handler (char *arg[NARGS] ARG_UNUSED, FILE *out, { int i; - 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); for (i = 0; i < gdbm_file->header->dir_size / 4; i++ |