diff options
author | Jim Meyering <jim@meyering.net> | 1996-06-07 02:58:04 +0000 |
---|---|---|
committer | Jim Meyering <jim@meyering.net> | 1996-06-07 02:58:04 +0000 |
commit | 0eb8d8c2216a0e141386d9d0893054bf416b0463 (patch) | |
tree | 2f57d45bfeb9a714894be646ce65d32454b10532 /intl/dcgettext.c | |
parent | c8d8d1d8bd3887bad23cff9e687802ca0eab8e34 (diff) | |
download | idutils-0eb8d8c2216a0e141386d9d0893054bf416b0463.tar.gz idutils-0eb8d8c2216a0e141386d9d0893054bf416b0463.tar.bz2 idutils-0eb8d8c2216a0e141386d9d0893054bf416b0463.zip |
Update from gettext-0.10.16.
Diffstat (limited to 'intl/dcgettext.c')
-rw-r--r-- | intl/dcgettext.c | 112 |
1 files changed, 86 insertions, 26 deletions
diff --git a/intl/dcgettext.c b/intl/dcgettext.c index 7562f69..c3adee3 100644 --- a/intl/dcgettext.c +++ b/intl/dcgettext.c @@ -1,5 +1,5 @@ /* dcgettext.c -- implementation of the dcgettext(3) function - Copyright (C) 1995 Free Software Foundation, Inc. + Copyright (C) 1995, 1996 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 @@ -23,6 +23,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #ifdef __GNUC__ # define alloca __builtin_alloca +# define HAVE_ALLOCA 1 #else # if defined HAVE_ALLOCA_H || defined _LIBC # include <alloca.h> @@ -85,13 +86,16 @@ void free (); file and the name space must not be polluted. */ # define getcwd __getcwd # define stpcpy __stpcpy -#endif - -#if !defined HAVE_GETCWD && !defined _LIBC -char *getwd (); -# define getcwd(buf, max) getwd (buf) #else +# if !defined HAVE_GETCWD +char *getwd (); +# define getcwd(buf, max) getwd (buf) +# else char *getcwd (); +# endif +# ifndef HAVE_STPCPY +static char *stpcpy PARAMS ((char *dest, const char *src)); +# endif #endif /* Amount to increase buffer size by in each try. */ @@ -151,13 +155,49 @@ const char _nl_default_dirname[] = GNULOCALEDIR; struct binding *_nl_domain_bindings; /* Prototypes for local functions. */ -static char *find_msg PARAMS ((struct loaded_domain *domain, +static char *find_msg PARAMS ((struct loaded_l10nfile *domain_file, const char *msgid)); static const char *category_to_name PARAMS ((int category)); static const char *guess_category_value PARAMS ((int category, const char *categoryname)); +/* For those loosing systems which don't have `alloca' we have to add + some additional code emulating it. */ +#ifdef HAVE_ALLOCA +/* Nothing has to be done. */ +# define ADD_BLOCK(list, address) /* nothing */ +# define FREE_BLOCKS(list) /* nothing */ +#else +struct block_list +{ + void *address; + struct block_list *next; +}; +# define ADD_BLOCK(list, addr) \ + do { \ + struct block_list *newp = (struct block_list *) malloc (sizeof (*newp)); \ + /* If we cannot get a free block we cannot add the new element to \ + the list. */ \ + if (newp != NULL) { \ + newp->address = (addr); \ + newp->next = (list); \ + (list) = newp; \ + } \ + } while (0) +# define FREE_BLOCKS(list) \ + do { \ + while (list != NULL) { \ + struct block_list *old = list; \ + list = list->next; \ + free (old); \ + } \ + } while (0) +# undef alloca +# define alloca(size) (malloc (size)) +#endif /* have alloca */ + + /* Names for the libintl functions are a problem. They must not clash with existing names and they should follow ANSI C. But this source code is also used in GNU C Library where the names have a __ @@ -176,7 +216,10 @@ DCGETTEXT (domainname, msgid, category) const char *msgid; int category; { - struct loaded_domain *domain; +#ifndef HAVE_ALLOCA + struct block_list *alloca_list = NULL; +#endif + struct loaded_l10nfile *domain; struct binding *binding; const char *categoryname; const char *categoryvalue; @@ -225,12 +268,14 @@ DCGETTEXT (domainname, msgid, category) path_max += 2; /* The getcwd docs say to do this. */ dirname = (char *) alloca (path_max + dirname_len); + ADD_BLOCK (block_list, dirname); errno = 0; while ((ret = getcwd (dirname, path_max)) == NULL && errno == ERANGE) { path_max += PATH_INCR; dirname = (char *) alloca (path_max + dirname_len); + ADD_BLOCK (block_list, dirname); errno = 0; } @@ -238,6 +283,7 @@ DCGETTEXT (domainname, msgid, category) { /* We cannot get the current working directory. Don't signal an error but simply return the default string. */ + FREE_BLOCKS (block_list); errno = saved_errno; return (char *) msgid; } @@ -246,12 +292,7 @@ DCGETTEXT (domainname, msgid, category) we avoid the non-standard function stpcpy. In GNU C Library this function is available, though. Also allow the symbol HAVE_STPCPY to be defined. */ -#if defined _LIBC || defined HAVE_STPCPY stpcpy (stpcpy (strchr (dirname, '\0'), "/"), binding->dirname); -#else - strcat (dirname, "/"); - strcat (dirname, binding->dirname); -#endif } /* Now determine the symbolic name of CATEGORY and its value. */ @@ -260,23 +301,18 @@ DCGETTEXT (domainname, msgid, category) xdomainname = (char *) alloca (strlen (categoryname) + strlen (domainname) + 5); + ADD_BLOCK (block_list, xdomainname); /* We don't want libintl.a to depend on any other library. So we avoid the non-standard function stpcpy. In GNU C Library this function is available, though. Also allow the symbol HAVE_STPCPY to be defined. */ -#if defined _LIBC || defined HAVE_STPCPY stpcpy (stpcpy (stpcpy (stpcpy (xdomainname, categoryname), "/"), domainname), ".mo"); -#else - strcpy (xdomainname, categoryname); - strcat (xdomainname, "/"); - strcat (xdomainname, domainname); - strcat (xdomainname, ".mo"); -#endif /* Creating working area. */ single_locale = (char *) alloca (strlen (categoryvalue) + 1); + ADD_BLOCK (block_list, single_locale); /* Search for the given string. This is a loop because we perhaps @@ -308,6 +344,7 @@ DCGETTEXT (domainname, msgid, category) if (strcmp (single_locale, "C") == 0 || strcmp (single_locale, "POSIX") == 0) { + FREE_BLOCKS (block_list); errno = saved_errno; return (char *) msgid; } @@ -336,6 +373,7 @@ DCGETTEXT (domainname, msgid, category) if (retval != NULL) { + FREE_BLOCKS (block_list); errno = saved_errno; return retval; } @@ -351,18 +389,21 @@ weak_alias (__dcgettext, dcgettext); static char * -find_msg (domain, msgid) - struct loaded_domain *domain; +find_msg (domain_file, msgid) + struct loaded_l10nfile *domain_file; const char *msgid; { size_t top, act, bottom; + struct loaded_domain *domain; - if (domain->decided == 0) - _nl_load_domain (domain); + if (domain_file->decided == 0) + _nl_load_domain (domain_file); - if (domain->data == NULL) + if (domain_file->data == NULL) return NULL; + domain = (struct loaded_domain *) domain_file->data; + /* Locate the MSGID and its translation. */ if (domain->hash_size > 2 && domain->hash_tab != NULL) { @@ -435,7 +476,8 @@ find_msg (domain, msgid) /* Return string representation of locale CATEGORY. */ -static const char *category_to_name (category) +static const char * +category_to_name (category) int category; { const char *retval; @@ -531,3 +573,21 @@ static const char *guess_category_value (category, categoryname) return "C"; #endif } + +/* @@ begin of epilog @@ */ + +/* We don't want libintl.a to depend on any other library. So we + avoid the non-standard function stpcpy. In GNU C Library this + function is available, though. Also allow the symbol HAVE_STPCPY + to be defined. */ +#if !_LIBC && !HAVE_STPCPY +static char * +stpcpy (dest, src) + char *dest; + const char *src; +{ + while ((*dest++ = *src++) != '\0') + /* Do nothing. */ ; + return dest - 1; +} +#endif |