aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2011-08-16 08:13:10 +0000
committerSergey Poznyakoff <gray@gnu.org.ua>2011-08-16 08:13:10 +0000
commit56ac2b6a5d6eb829a7da8eecc04cbf5f9339e61b (patch)
tree5dc8009ac82abcfa8f22aa1ef38c85244af77a25 /src
parentae9ea0011da4ba01e5639611d61c442af8d42817 (diff)
downloadgdbm-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.am5
-rw-r--r--src/bucket.c14
-rw-r--r--src/falloc.c12
-rw-r--r--src/findkey.c6
-rw-r--r--src/gdbmdefs.h5
-rw-r--r--src/gdbmerrno.c58
-rw-r--r--src/gdbmfetch.c2
-rw-r--r--src/gdbmseq.c2
-rw-r--r--src/gdbmstore.c6
-rw-r--r--src/gettext.h280
-rw-r--r--src/testgdbm.c243
-rw-r--r--src/update.c13
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
@@ -12,30 +12,33 @@
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# 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
EXTRA_DIST = gdbm.h.in
# The libraries
VI_CURRENT = 4
VI_REVISION = 0
VI_AGE = 0
lib_LTLIBRARIES = libgdbm.la
+LIBADD = @LTLIBINTL@
+
libgdbm_la_SOURCES = \
gdbmopen.c\
gdbmdelete.c\
gdbmfetch.c\
gdbmstore.c\
gdbmclose.c\
diff --git a/src/bucket.c b/src/bucket.c
index f8c48b9..cda2389 100644
--- a/src/bucket.c
+++ b/src/bucket.c
@@ -61,13 +61,13 @@ _gdbm_get_bucket (GDBM_FILE dbf, int dir_index)
dbf->bucket_dir = dir_index;
bucket_adr = dbf->dir [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. */
if (dbf->cache_entry->ca_adr != bucket_adr)
{
/* Look in the cache. */
@@ -91,17 +91,17 @@ _gdbm_get_bucket (GDBM_FILE dbf, int dir_index)
dbf->cache_entry->ca_data.elem_loc = -1;
dbf->cache_entry->ca_changed = FALSE;
/* 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;
}
@@ -142,13 +142,13 @@ _gdbm_split_bucket (GDBM_FILE dbf, int next_insert)
/* No directories are yet old. */
old_count = 0;
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)
{
/* Initialize the "new" buckets in the cache. */
do
@@ -182,13 +182,13 @@ _gdbm_split_bucket (GDBM_FILE dbf, int next_insert)
/* Double the directory size if necessary. */
if (dbf->header->dir_bits == dbf->bucket->bucket_bits)
{
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++)
{
new_dir[2*index] = dbf->dir[index];
new_dir[2*index+1] = dbf->dir[index];
}
@@ -305,14 +305,14 @@ _gdbm_write_bucket (GDBM_FILE dbf, cache_elem *ca_entry)
{
int num_bytes; /* The return value for write. */
off_t file_pos; /* The return value for lseek. */
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
@@ -175,19 +175,19 @@ pop_avail_block (GDBM_FILE dbf)
new_el.av_adr = dbf->header->avail.next_block;
new_el.av_size = ( ( (dbf->header->avail.size * sizeof (avail_elem)) >> 1)
+ sizeof (avail_block));
/* 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;
while (index < new_blk->count)
{
while(index < new_blk->count
@@ -253,13 +253,13 @@ push_avail_block (GDBM_FILE dbf)
new_loc = get_block (av_size, dbf);
av_adr = new_loc.av_adr;
/* 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;
temp->next_block = dbf->header->avail.next_block;
dbf->header->avail.next_block = av_adr;
for (index = 1; index < dbf->header->avail.count; index++)
@@ -276,15 +276,15 @@ push_avail_block (GDBM_FILE dbf)
new_loc.av_adr += av_size;
new_loc.av_size -= av_size;
_gdbm_free (dbf, new_loc.av_adr, new_loc.av_size);
/* 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);
}
/* Get_elem returns an element in the AV_TABLE block which is
diff --git a/src/findkey.c b/src/findkey.c
index 12c7226..7933c2f 100644
--- a/src/findkey.c
+++ b/src/findkey.c
@@ -51,21 +51,21 @@ _gdbm_read_entry (GDBM_FILE dbf, int elem_loc)
data_ca->elem_loc = elem_loc;
data_ca->hash_val = dbf->bucket->h_table[elem_loc].hash_value;
if (key_size+data_size == 0)
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
@@ -17,12 +17,17 @@
You should have received a copy of the GNU General Public License
along with GDBM. If not, see <http://www.gnu.org/licenses/>. */
#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. */
/* The available file space is stored in an "avail" table. The one with
most activity is contained in the file header. (See below.) When that
one filles up, it is split in half and half is pushed on an "avail
diff --git a/src/gdbmerrno.c b/src/gdbmerrno.c
index 00d9271..16c07c2 100644
--- a/src/gdbmerrno.c
+++ b/src/gdbmerrno.c
@@ -16,53 +16,53 @@
You should have received a copy of the GNU General Public License
along with GDBM. If not, see <http://www.gnu.org/licenses/>. */
/* 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;
/* this is not static so that applications may access the array if they
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 *
-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");
}
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
@@ -50,13 +50,13 @@ gdbm_fetch (GDBM_FILE dbf, datum key)
/* This is the item. Return the associated data. */
return_val.dsize = dbf->bucket->h_table[elem_loc].data_size;
if (return_val.dsize == 0)
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);
}
/* Check for an error and return. */
if (return_val.dptr == NULL) gdbm_errno = GDBM_ITEM_NOT_FOUND;
return return_val;
diff --git a/src/gdbmseq.c b/src/gdbmseq.c
index cd2421a..4323185 100644
--- a/src/gdbmseq.c
+++ b/src/gdbmseq.c
@@ -67,13 +67,13 @@ get_next_key (GDBM_FILE dbf, int elem_loc, datum *return_val)
find_data = _gdbm_read_entry (dbf, elem_loc);
return_val->dsize = dbf->bucket->h_table[elem_loc].key_size;
if (return_val->dsize == 0)
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);
}
/* Start the visit of all keys in the database. This produces something in
hash order, not in any sorted order. */
diff --git a/src/gdbmstore.c b/src/gdbmstore.c
index 35a6863..5f1bb67 100644
--- a/src/gdbmstore.c
+++ b/src/gdbmstore.c
@@ -135,17 +135,17 @@ gdbm_store (GDBM_FILE dbf, datum key, datum content, int flags)
dbf->bucket->h_table[elem_loc].data_pointer = file_adr;
dbf->bucket->h_table[elem_loc].key_size = key.dsize;
dbf->bucket->h_table[elem_loc].data_size = content.dsize;
/* 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;
dbf->bucket_changed = TRUE;
/* Write everything that is needed to the disk. */
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
@@ -29,12 +29,15 @@
#include <signal.h>
#include <sys/ioctl.h>
#ifdef HAVE_SYS_TERMIOS_H
# include <sys/termios.h>
#endif
#include <stdarg.h>
+#ifdef HAVE_LOCALE_H
+# include <locale.h>
+#endif
const char *progname; /* Program name */
char *prompt = "testgdbm> ";
char *file_name = NULL; /* Database file name */
@@ -72,27 +75,28 @@ bucket_print_lines (hash_bucket *bucket)
/* Debug procedure to print the contents of the current hash bucket. */
void
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,
bucket->h_table[index].key_size,
bucket->h_table[index].data_size,
(unsigned long) bucket->h_table[index].data_pointer,
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,
bucket->bucket_avail[index].av_size);
}
@@ -110,13 +114,13 @@ _gdbm_avail_list_size (GDBM_FILE dbf, size_t min_size)
/* Initialize the variables for a pass throught the avail stack. */
temp = dbf->header->avail.next_block;
size = (((dbf->header->avail.size * sizeof (avail_elem)) >> 1)
+ 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)
{
if (__lseek (dbf, temp, L_SET) != temp)
{
@@ -145,13 +149,13 @@ _gdbm_print_avail_list (FILE *fp, GDBM_FILE dbf)
{
int temp;
int size;
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++)
{
fprintf (fp, " %15d %10lu \n",
dbf->header->avail.av_table[temp].av_size,
(unsigned long) dbf->header->avail.av_table[temp].av_adr);
@@ -160,13 +164,13 @@ _gdbm_print_avail_list (FILE *fp, GDBM_FILE dbf)
/* Initialize the variables for a pass throught the avail stack. */
temp = dbf->header->avail.next_block;
size = (((dbf->header->avail.size * sizeof (avail_elem)) >> 1)
+ 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)
{
if (__lseek (dbf, temp, L_SET) != temp)
{
@@ -178,14 +182,14 @@ _gdbm_print_avail_list (FILE *fp, GDBM_FILE dbf)
{
error (0, "read: %s", strerror (errno));
break;
}
/* 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++)
{
fprintf (fp, " %15d %10lu \n", av_stk->av_table[temp].av_size,
(unsigned long) av_stk->av_table[temp].av_adr);
}
temp = av_stk->next_block;
@@ -198,49 +202,48 @@ _gdbm_print_bucket_cache (FILE *fp, GDBM_FILE dbf)
{
int index;
char changed;
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++)
{
changed = dbf->bucket_cache[index].ca_changed;
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
version ()
{
printf ("testgdbm (%s) %s\n", PACKAGE_NAME, PACKAGE_VERSION);
@@ -273,43 +276,43 @@ read_from_file (const char *name, int replace)
FILE *fp;
int flag = replace ? GDBM_REPLACE : 0;
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;
}
while (fgets (buf, sizeof buf, fp))
{
char *p;
if (!trimnl (buf))
{
- error (0, "%s:%d: line too long", name, line);
+ error (0, _("%s:%d: line too long"), name, line);
continue;
}
line++;
p = strchr (buf, ' ');
if (!p)
{
- error (0, "%s:%d: malformed line", name, line);
+ error (0, _("%s:%d: malformed line"), name, line);
continue;
}