about summary refs log tree commit diff
path: root/intl
diff options
context:
space:
mode:
Diffstat (limited to 'intl')
-rw-r--r--intl/dcgettext.c56
-rw-r--r--intl/l10nflist.c79
-rw-r--r--intl/loadmsgcat.c12
-rw-r--r--intl/localealias.c55
4 files changed, 185 insertions, 17 deletions
diff --git a/intl/dcgettext.c b/intl/dcgettext.c
index a18be16631..5c14dca218 100644
--- a/intl/dcgettext.c
+++ b/intl/dcgettext.c
@@ -1,6 +1,8 @@
 /* dcgettext.c -- implementation of the dcgettext(3) function
-Copyright (C) 1995, 1996 Free Software Foundation, Inc.
-Written by Ulrich Drepper <drepper@gnu.ai.mit.edu>, 1995.
+   Copyright (C) 1995, 1996 Free Software Foundation, Inc.
+
+This file is part of the GNU C Library.  Its master source is NOT part of
+the C library, however.  The master source lives in /gd/gnu/lib.
 
 The GNU C Library is free software; you can redistribute it and/or
 modify it under the terms of the GNU Library General Public License as
@@ -14,8 +16,8 @@ Library General Public License for more details.
 
 You should have received a copy of the GNU Library General Public
 License along with the GNU C Library; see the file COPYING.LIB.  If
-not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-Boston, MA 02111-1307, USA.  */
+not, write to the Free Software Foundation, Inc., 675 Mass Ave,
+Cambridge, MA 02139, USA.  */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
@@ -160,6 +162,42 @@ 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 __
@@ -178,6 +216,9 @@ DCGETTEXT (domainname, msgid, category)
      const char *msgid;
      int category;
 {
+#ifndef HAVE_ALLOCA
+  struct block_list *alloca_list = NULL;
+#endif
   struct loaded_l10nfile *domain;
   struct binding *binding;
   const char *categoryname;
@@ -227,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;
 	}
 
@@ -240,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;
 	}
@@ -262,6 +306,7 @@ 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
@@ -279,6 +324,7 @@ DCGETTEXT (domainname, msgid, category)
 
   /* 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
@@ -310,6 +356,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;
 	}
@@ -338,6 +385,7 @@ DCGETTEXT (domainname, msgid, category)
 
 	  if (retval != NULL)
 	    {
+	      FREE_BLOCKS (block_list);
 	      errno = saved_errno;
 	      return retval;
 	    }
diff --git a/intl/l10nflist.c b/intl/l10nflist.c
index b0fdf51d73..00e3c8950a 100644
--- a/intl/l10nflist.c
+++ b/intl/l10nflist.c
@@ -1,7 +1,9 @@
 /* Copyright (C) 1995, 1996 Free Software Foundation, Inc.
-This file is part of the GNU C Library.
 Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, 1995.
 
+This file is part of the GNU C Library.  Its master source is NOT part of
+the C library, however.  The master source lives in /gd/gnu/lib.
+
 The GNU C Library is free software; you can redistribute it and/or
 modify it under the terms of the GNU Library General Public License as
 published by the Free Software Foundation; either version 2 of the
@@ -14,16 +16,83 @@ Library General Public License for more details.
 
 You should have received a copy of the GNU Library General Public
 License along with the GNU C Library; see the file COPYING.LIB.  If
-not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-Boston, MA 02111-1307, USA.  */
+not, write to the Free Software Foundation, Inc., 675 Mass Ave,
+Cambridge, MA 02139, USA.  */
 
-#include <argz.h>
+#if defined _LIBC && (defined __ARGZ_COUNT || defined __ARGZ_STRINGIFY)
+# include <argz.h>
+#endif
 #include <ctype.h>
 #include <stdlib.h>
 #include <string.h>
 
 #include "loadinfo.h"
 
+/* Define function which are usually not available.  */
+
+#if !defined _LIBC && !defined __ARGZ_COUNT
+/* Returns the number of strings in ARGZ.  */
+static size_t __argz_count __P ((const char *argz, size_t len));
+
+static size_t
+__argz_count (argz, len)
+     const char *argz;
+     size_t len;
+{
+  size_t count = 0;
+  while (len > 0)
+    {
+      size_t part_len = strlen(argz);
+      argz += part_len + 1;
+      len -= part_len + 1;
+      count++;
+    }
+  return count;
+}
+#endif	/* !_LIBC && !__ARGZ_COUNT */
+
+#if !defined _LIBC && !defined __ARGZ_STRINGIFY
+/* Make '\0' separated arg vector ARGZ printable by converting all the '\0's
+   except the last into the character SEP.  */
+static void __argz_stringify __P ((char *argz, size_t len, int sep));
+
+static void
+__argz_stringify (argz, len, sep)
+     char *argz;
+     size_t len;
+     int sep;
+{
+  while (len > 0)
+    {
+      size_t part_len = strlen(argz);
+      argz += part_len;
+      len -= part_len + 1;
+      if (len > 0)
+	*argz++ = sep;
+    }
+}
+#endif	/* !_LIBC && !__ARGZ_COUNT */
+
+#if !defined _LIBC && !defined __ARGZ_NEXT
+static char *
+__argz_next (char *argz, size_t argz_len, const char *entry)
+{
+  if (entry)
+    {
+      if (entry < argz + argz_len)
+        entry = strchr (entry, '\0') + 1;
+
+      return entry >= argz + argz_len ? NULL : (char *) entry;
+    }
+  else
+    if (argz_len > 0)
+      return argz;
+    else
+      return 0;
+}
+#endif
+
+
 /* Return number of bits set in X.  */
 static int pop __P ((int x));
 
@@ -40,7 +109,7 @@ pop (x)
   return x;
 }
 
-
+
 struct loaded_l10nfile *
 _nl_make_l10nflist (l10nfile_list, dirlist, dirlist_len, mask, language,
 		    territory, codeset, normalized_codeset, modifier, special,
diff --git a/intl/loadmsgcat.c b/intl/loadmsgcat.c
index 90eed87fd9..4a60f6bf67 100644
--- a/intl/loadmsgcat.c
+++ b/intl/loadmsgcat.c
@@ -1,6 +1,8 @@
 /* loadmsgcat.c -- load needed message catalogs
-Copyright (C) 1995, 1996 Free Software Foundation, Inc.
-Written by Ulrich Drepper <drepper@gnu.ai.mit.edu>, 1995.
+   Copyright (C) 1995, 1996 Free Software Foundation, Inc.
+
+This file is part of the GNU C Library.  Its master source is NOT part of
+the C library, however.  The master source lives in /gd/gnu/lib.
 
 The GNU C Library is free software; you can redistribute it and/or
 modify it under the terms of the GNU Library General Public License as
@@ -14,8 +16,8 @@ Library General Public License for more details.
 
 You should have received a copy of the GNU Library General Public
 License along with the GNU C Library; see the file COPYING.LIB.  If
-not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-Boston, MA 02111-1307, USA.  */
+not, write to the Free Software Foundation, Inc., 675 Mass Ave,
+Cambridge, MA 02139, USA.  */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
@@ -160,7 +162,7 @@ _nl_load_domain (domain_file)
     }
 
   domain_file->data
-    = (struct loaded_domain *) malloc (sizeof (struct loaded_domain *));
+    = (struct loaded_domain *) malloc (sizeof (struct loaded_domain));
   if (domain_file->data == NULL)
     return;
 
diff --git a/intl/localealias.c b/intl/localealias.c
index 17b912afb3..57c4a01588 100644
--- a/intl/localealias.c
+++ b/intl/localealias.c
@@ -77,6 +77,41 @@ void free ();
 # define strcasecmp __strcasecmp
 #endif
 
+
+/* 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)
+#endif	/* have alloca */
+
+
 struct alias_map
 {
   const char *alias;
@@ -151,18 +186,25 @@ read_alias_file (fname, fname_len)
      const char *fname;
      int fname_len;
 {
+#ifndef HAVE_ALLOCA
+  struct block_list *alloca_list = NULL;
+#endif
   FILE *fp;
   char *full_fname;
   size_t added;
   static const char aliasfile[] = "/locale.alias";
 
   full_fname = (char *) alloca (fname_len + sizeof aliasfile);
+  ADD_BLOCK (block_list, full_fname);
   memcpy (full_fname, fname, fname_len);
   memcpy (&full_fname[fname_len], aliasfile, sizeof aliasfile);
 
   fp = fopen (full_fname, "r");
   if (fp == NULL)
-    return 0;
+    {
+      FREE_BLOCKS (block_list);
+      return 0;
+    }
 
   added = 0;
   while (!feof (fp))
@@ -227,14 +269,20 @@ read_alias_file (fname, fname_len)
 	      len = strlen (alias) + 1;
 	      tp = (char *) malloc (len);
 	      if (tp == NULL)
-		return added;
+		{
+		  FREE_BLOCKS (block_list);
+		  return added;
+		}
 	      memcpy (tp, alias, len);
 	      map[nmap].alias = tp;
 
 	      len = strlen (value) + 1;
 	      tp = (char *) malloc (len);
 	      if (tp == NULL)
-		return added;
+		{
+		  FREE_BLOCKS (block_list);
+		  return added;
+		}
 	      memcpy (tp, value, len);
 	      map[nmap].value = tp;
 
@@ -263,6 +311,7 @@ read_alias_file (fname, fname_len)
     qsort (map, nmap, sizeof (struct alias_map),
 	   (int (*) PARAMS ((const void *, const void *))) alias_compare);
 
+  FREE_BLOCKS (block_list);
   return added;
 }