* locale/programs/xmalloc.c: Test _LIBC as well as STDC_HEADERS.

* locale/programs/ld-collate.c (collate_finish): Use error_at_line
	instead of error_with_loc.

	* locale/weight.h: Use u_int32_t instead of u32_t.
	* string/strxfrm.c: Likewise.

	* string/strxfrm.c: Find weight.h in ../locale; don't #include
	"localeinfo.h".
	* string/strcoll.c: Likewise.

	* locale/programs/simple-hash.c, locale/programs/simple-hash.h,
 	locale/programs/xmalloc.c, locale/programs/xstrdup.c: Helper functions
 	for locale related programs.
 	locale/programs/charmap.c, locale/programs/charset.c,
 	locale/programs/charset.h, locale/programs/config.h,
 	locale/programs/ctypedump.c, locale/programs/ld-collate.c,
 	locale/programs/ld-ctype.c, locale/programs/ld-messages.c,
 	locale/programs/ld-monetary.c, locale/programs/ld-numeric.c,
 	locale/programs/ld-time.c, locale/programs/linereader.c,
 	locale/programs/linereader.h, locale/programs/locale.c,
 	locale/programs/localedef.c, locale/programs/locales.h,
 	locale/programs/locfile-kw.gperf, locale/programs/locfile-kw.h,
 	locale/programs/locfile-token.h, locale/programs/locfile.c,
 	locale/programs/locfile.h, locale/programs/stringtrans.c,
 	locale/programs/stringtrans.h: Implementation of locale related
 	programs.
This commit is contained in:
Roland McGrath 1996-03-28 09:16:15 +00:00
parent 19bc17a905
commit 0393dfd6c2
21 changed files with 801 additions and 147 deletions

View File

@ -1,5 +1,17 @@
Thu Mar 28 03:25:10 1996 Roland McGrath <roland@charlie-brown.gnu.ai.mit.edu>
* locale/programs/xmalloc.c: Test _LIBC as well as STDC_HEADERS.
* locale/programs/ld-collate.c (collate_finish): Use error_at_line
instead of error_with_loc.
* locale/weight.h: Use u_int32_t instead of u32_t.
* string/strxfrm.c: Likewise.
* string/strxfrm.c: Find weight.h in ../locale; don't #include
"localeinfo.h".
* string/strcoll.c: Likewise.
* intl/Makefile (copysrc): Add missing > in sed cmd.
Sat Mar 23 17:52:49 1996 Ulrich Drepper <drepper@gnu.ai.mit.edu>
@ -49,8 +61,9 @@ Sat Mar 23 17:52:49 1996 Ulrich Drepper <drepper@gnu.ai.mit.edu>
_NL_CTYPE_MAP_NAMES, _NL_CTYPE_WIDTH): New internal values for
extended LC_CTYPE and LC_COLLATE implementation.
* locale/simple-hash.c, locale/simple-hash.h, locale/xmalloc.c,
locale/xstrdup.c: Helper functions for locale related programs.
* locale/programs/simple-hash.c, locale/programs/simple-hash.h,
locale/programs/xmalloc.c, locale/programs/xstrdup.c: Helper functions
for locale related programs.
* locale/C-collate.c, locale/C-ctype.c,
locale/C-messages.c, locale/C-monetary.c,
@ -72,19 +85,19 @@ Sat Mar 23 17:52:49 1996 Ulrich Drepper <drepper@gnu.ai.mit.edu>
for collation tables.
* locale/programs/charmap-kw.gperf, locale/programs/charmap-kw.h,
locale/programs/charmap.c, locale/programs/charset.c,
locale/programs/charset.h, locale/programs/config.h,
locale/programs/ctypedump.c, locale/programs/ld-collate.c,
locale/programs/ld-ctype.c, locale/programs/ld-messages.c,
locale/programs/ld-monetary.c, locale/programs/ld-numeric.c,
locale/programs/ld-time.c, locale/programs/linereader.c,
locale/programs/linereader.h, locale/programs/locale.c,
locale/programs/localedef.c, locale/programs/locales.h,
locale/programs/locfile-kw.gperf, locale/programs/locfile-kw.h,
locale/programs/locfile-token.h, locale/programs/locfile.c,
locale/programs/locfile.h, locale/programs/stringtrans.c,
locale/programs/stringtrans.h: Implementation of locale related
programs.
locale/programs/charmap.c, locale/programs/charset.c,
locale/programs/charset.h, locale/programs/config.h,
locale/programs/ctypedump.c, locale/programs/ld-collate.c,
locale/programs/ld-ctype.c, locale/programs/ld-messages.c,
locale/programs/ld-monetary.c, locale/programs/ld-numeric.c,
locale/programs/ld-time.c, locale/programs/linereader.c,
locale/programs/linereader.h, locale/programs/locale.c,
locale/programs/localedef.c, locale/programs/locales.h,
locale/programs/locfile-kw.gperf, locale/programs/locfile-kw.h,
locale/programs/locfile-token.h, locale/programs/locfile.c,
locale/programs/locfile.h, locale/programs/stringtrans.c,
locale/programs/stringtrans.h: Implementation of locale related
programs.
* locale/weight.h: Functions to access collation tables.

View File

@ -1,19 +1,23 @@
/* bindtextdom.c -- implementation of the bindtextdomain(3) function
Copyright (C) 1995 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 2, or (at your option)
any later version.
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.
This program is distributed in the hope that it will be useful,
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
License, or (at your option) any later version.
The GNU C Library 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 General Public License for more details.
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
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., 675 Mass Ave,
Cambridge, MA 02139, USA. */
#ifdef HAVE_CONFIG_H
# include <config.h>

View File

@ -1,19 +1,23 @@
/* dcgettext.c -- implementation of the dcgettext(3) function
Copyright (C) 1995 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 2, or (at your option)
any later version.
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.
This program is distributed in the hope that it will be useful,
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
License, or (at your option) any later version.
The GNU C Library 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 General Public License for more details.
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
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., 675 Mass Ave,
Cambridge, MA 02139, USA. */
#ifdef HAVE_CONFIG_H
# include <config.h>

View File

@ -1,19 +1,23 @@
/* dgettext.c -- implementation of the dgettext(3) function
Copyright (C) 1995 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 2, or (at your option)
any later version.
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.
This program is distributed in the hope that it will be useful,
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
License, or (at your option) any later version.
The GNU C Library 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 General Public License for more details.
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
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., 675 Mass Ave,
Cambridge, MA 02139, USA. */
#ifdef HAVE_CONFIG_H
# include <config.h>

View File

@ -2,24 +2,29 @@
Copyright (C) 1995, 1996 Free Software Foundation, Inc.
Written by Ulrich Drepper <drepper@gnu.ai.mit.edu>, 1995.
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 2, or (at your option)
any later version.
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.
This program is distributed in the hope that it will be useful,
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
License, or (at your option) any later version.
The GNU C Library 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 General Public License for more details.
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
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., 675 Mass Ave,
Cambridge, MA 02139, USA. */
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <ctype.h>
#include <errno.h>
#include <stdio.h>
#include <sys/types.h>

View File

@ -1,19 +1,23 @@
/* gettext.c -- implementation of gettext(3) function
Copyright (C) 1995 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 2, or (at your option)
any later version.
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.
This program is distributed in the hope that it will be useful,
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
License, or (at your option) any later version.
The GNU C Library 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 General Public License for more details.
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
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., 675 Mass Ave,
Cambridge, MA 02139, USA. */
#ifdef HAVE_CONFIG_H
# include <config.h>

View File

@ -1,20 +1,23 @@
/* gettext.h - internal header for GNU gettext internationalization functions
Copyright (C) 1995 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 2, or (at your option)
any later version.
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.
This program is distributed in the hope that it will be useful,
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
License, or (at your option) any later version.
The GNU C Library 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 General Public License for more details.
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 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. */
#ifndef _GETTEXT_H
#define _GETTEXT_H 1

View File

@ -1,19 +1,23 @@
/* gettextP.h -- header describing internals of gettext library
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
the Free Software Foundation; either version 2, or (at your option)
any later version.
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.
This program is distributed in the hope that it will be useful,
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
License, or (at your option) any later version.
The GNU C Library 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 General Public License for more details.
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
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., 675 Mass Ave,
Cambridge, MA 02139, USA. */
#ifndef _GETTEXTP_H
#define _GETTEXTP_H
@ -46,7 +50,7 @@ SWAP (i)
struct loaded_domain
{
struct loaded_domain *next;
struct loaded_domain *successor[31];
struct loaded_domain *successor[63];
const char *filename;
int decided;

View File

@ -1,19 +1,23 @@
/* hash-string - Implements a string hashing function.
Copyright (C) 1995 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 2, or (at your option)
any later version.
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.
This program is distributed in the hope that it will be useful,
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
License, or (at your option) any later version.
The GNU C Library 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 General Public License for more details.
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
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., 675 Mass Ave,
Cambridge, MA 02139, USA. */
#ifdef HAVE_VALUES_H
# include <values.h>

View File

@ -1,9 +1,11 @@
/* libgettext.h -- Message catalogs for internationalization.
Copyright (C) 1995 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper.
This file is derived from the file libgettext.h in the GNU gettext package.
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
@ -16,8 +18,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. */
#ifndef _LIBINTL_H
#define _LIBINTL_H 1

View File

@ -1,19 +1,23 @@
/* loadmsgcat.c -- load needed message catalogs
Copyright (C) 1995 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 2, or (at your option)
any later version.
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.
This program is distributed in the hope that it will be useful,
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
License, or (at your option) any later version.
The GNU C Library 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 General Public License for more details.
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
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., 675 Mass Ave,
Cambridge, MA 02139, USA. */
#ifdef HAVE_CONFIG_H
# include <config.h>

View File

@ -1,19 +1,23 @@
/* localealias.c -- handle aliases for locale names
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
the Free Software Foundation; either version 2, or (at your option)
any later version.
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.
This program is distributed in the hope that it will be useful,
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
License, or (at your option) any later version.
The GNU C Library 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 General Public License for more details.
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
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., 675 Mass Ave,
Cambridge, MA 02139, USA. */
#ifdef HAVE_CONFIG_H
# include <config.h>

View File

@ -1,19 +1,23 @@
/* textdomain.c -- implementation of the textdomain(3) function
Copyright (C) 1995 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 2, or (at your option)
any later version.
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.
This program is distributed in the hope that it will be useful,
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
License, or (at your option) any later version.
The GNU C Library 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 General Public License for more details.
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
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., 675 Mass Ave,
Cambridge, MA 02139, USA. */
#ifdef HAVE_CONFIG_H
# include <config.h>

View File

@ -239,7 +239,7 @@ collate_finish (struct localedef_t *locale, struct charset_t *charset)
value = 0;
if (value == 0)
error_with_loc (0, 0, patch->fname, patch->lineno,
error_at_line (0, 0, patch->fname, patch->lineno,
_("no weight defined for symbol `%s'"), patch->token);
else
*patch->where.pos = value;

View File

@ -0,0 +1,401 @@
/* hash - implement simple hashing table with string based keys.
Copyright (C) 1994, 1995, 1996 Free Software Foundation, Inc.
Written by Ulrich Drepper <drepper@gnu.ai.mit.edu>, October 1994.
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 2, 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 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#if HAVE_OBSTACK
# include <obstack.h>
#else
# include "obstack.h"
#endif
#ifdef HAVE_VALUES_H
# include <values.h>
#endif
#include "simple-hash.h"
#define obstack_chunk_alloc xmalloc
#define obstack_chunk_free free
#ifndef BITSPERBYTE
# define BITSPERBYTE 8
#endif
#ifndef LONGBITS
# define LONGBITS (sizeof (long) * BITSPERBYTE)
#endif
#ifndef bcopy
# define bcopy(s, d, n) memcpy ((d), (s), (n))
#endif
void *xmalloc __P ((size_t __n));
typedef struct hash_entry
{
unsigned long used;
const void *key;
size_t keylen;
void *data;
struct hash_entry *next;
}
hash_entry;
/* Prototypes for local functions. */
static void insert_entry_2 __P ((hash_table *htab, const void *key,
size_t keylen, unsigned long hval,
size_t idx, void *data));
static size_t lookup __P ((hash_table *htab, const void *key, size_t keylen,
unsigned long int hval));
static size_t lookup_2 __P ((hash_table *htab, const void *key,
size_t keylen, unsigned long int hval));
static unsigned long compute_hashval __P ((const void *key, size_t keylen));
static int is_prime __P ((unsigned long int candidate));
int
init_hash (htab, init_size)
hash_table *htab;
unsigned long int init_size;
{
/* We need the size to be a prime. */
init_size = next_prime (init_size);
/* Initialize the data structure. */
htab->size = init_size;
htab->filled = 0;
htab->first = NULL;
htab->table = (void *) xmalloc ((init_size + 1) * sizeof (hash_entry));
if (htab->table == NULL)
return -1;
memset (htab->table, '\0', (init_size + 1) * sizeof (hash_entry));
obstack_init (&htab->mem_pool);
return 0;
}
int
delete_hash (htab)
hash_table *htab;
{
free (htab->table);
obstack_free (&htab->mem_pool, NULL);
return 0;
}
int
insert_entry (htab, key, keylen, data)
hash_table *htab;
const void *key;
size_t keylen;
void *data;
{
unsigned long int hval = compute_hashval (key, keylen);
hash_entry *table = (hash_entry *) htab->table;
size_t idx = lookup (htab, key, keylen, hval);
if (table[idx].used)
/* We don't want to overwrite the old value. */
return -1;
else
{
/* An empty bucket has been found. */
insert_entry_2 (htab, obstack_copy (&htab->mem_pool, key, keylen),
keylen, hval, idx, data);
return 0;
}
}
static void
insert_entry_2 (htab, key, keylen, hval, idx, data)
hash_table *htab;
const void *key;
size_t keylen;
unsigned long int hval;
size_t idx;
void *data;
{
hash_entry *table = (hash_entry *) htab->table;
table[idx].used = hval;
table[idx].key = key;
table[idx].keylen = keylen;
table[idx].data = data;
/* List the new value in the list. */
if ((hash_entry *) htab->first == NULL)
{
table[idx].next = &table[idx];
*(hash_entry **) &htab->first = &table[idx];
}
else
{
table[idx].next = ((hash_entry *) htab->first)->next;
((hash_entry *) htab->first)->next = &table[idx];
*(hash_entry **) &htab->first = &table[idx];
}
++htab->filled;
if (100 * htab->filled > 90 * htab->size)
{
/* Table is filled more than 90%. Resize the table. */
unsigned long int old_size = htab->size;
htab->size = next_prime (htab->size * 2);
htab->filled = 0;
htab->first = NULL;
htab->table = (void *) xmalloc ((1 + htab->size)
* sizeof (hash_entry));
memset (htab->table, '\0', (1 + htab->size) * sizeof (hash_entry));
for (idx = 1; idx <= old_size; ++idx)
if (table[idx].used)
insert_entry_2 (htab, table[idx].key, table[idx].keylen,
table[idx].used,
lookup_2 (htab, table[idx].key, table[idx].keylen,
table[idx].used),
table[idx].data);
free (table);
}
}
int
find_entry (htab, key, keylen, result)
hash_table *htab;
const void *key;
size_t keylen;
void **result;
{
hash_entry *table = (hash_entry *) htab->table;
size_t idx = lookup (htab, key, keylen, compute_hashval (key, keylen));
if (table[idx].used == 0)
return -1;
*result = table[idx].data;
return 0;
}
int
set_entry (htab, key, keylen, newval)
hash_table *htab;
const void *key;
size_t keylen;
void *newval;
{
hash_entry *table = (hash_entry *) htab->table;
size_t idx = lookup (htab, key, keylen, compute_hashval (key, keylen));
if (table[idx].used == 0)
return -1;
table[idx].data = newval;
return 0;
}
int
iterate_table (htab, ptr, key, keylen, data)
hash_table *htab;
void **ptr;
const void **key;
size_t *keylen;
void **data;
{
if (*ptr == NULL)
{
if (htab->first == NULL)
return -1;
*ptr = (void *) ((hash_entry *) htab->first)->next;
}
else
{
if (*ptr == htab->first)
return -1;
*ptr = (void *) (((hash_entry *) *ptr)->next);
}
*key = ((hash_entry *) *ptr)->key;
*keylen = ((hash_entry *) *ptr)->keylen;
*data = ((hash_entry *) *ptr)->data;
return 0;
}
static size_t
lookup (htab, key, keylen, hval)
hash_table *htab;
const void *key;
size_t keylen;
unsigned long hval;
{
unsigned long hash;
size_t idx;
hash_entry *table = (hash_entry *) htab->table;
/* First hash function: simply take the modul but prevent zero. */
hash = 1 + hval % htab->size;
idx = hash;
if (table[idx].used)
{
if (table[idx].used == hval && table[idx].keylen == keylen
&& memcmp (key, table[idx].key, keylen) == 0)
return idx;
/* Second hash function as suggested in [Knuth]. */
hash = 1 + hval % (htab->size - 2);
do
{
if (idx <= hash)
idx = htab->size + idx - hash;
else
idx -= hash;
/* If entry is found use it. */
if (table[idx].used == hval && table[idx].keylen == keylen
&& memcmp (key, table[idx].key, keylen) == 0)
return idx;
}
while (table[idx].used);
}
return idx;
}
/* References:
[Aho,Sethi,Ullman] Compilers: Principles, Techniques and Tools, 1986
[Knuth] The Art of Computer Programming, part3 (6.4) */
static size_t
lookup_2 (htab, key, keylen, hval)
hash_table *htab;
const void *key;
size_t keylen;
unsigned long int hval;
{
unsigned long int hash;
size_t idx;
hash_entry *table = (hash_entry *) htab->table;
/* First hash function: simply take the modul but prevent zero. */
hash = 1 + hval % htab->size;
idx = hash;
if (table[idx].used)
{
if (table[idx].used == hval && table[idx].keylen == keylen
&& memcmp (table[idx].key, key, keylen) == 0)
return idx;
/* Second hash function as suggested in [Knuth]. */
hash = 1 + hval % (htab->size - 2);
do
{
if (idx <= hash)
idx = htab->size + idx - hash;
else
idx -= hash;
/* If entry is found use it. */
if (table[idx].used == hval && table[idx].keylen == keylen
&& memcmp (table[idx].key, key, keylen) == 0)
return idx;
}
while (table[idx].used);
}
return idx;
}
static unsigned long
compute_hashval (key, keylen)
const void *key;
size_t keylen;
{
size_t cnt;
unsigned long int hval, g;
/* Compute the hash value for the given string. The algorithm
is taken from [Aho,Sethi,Ullman]. */
cnt = 0;
hval = keylen;
while (cnt < keylen)
{
hval <<= 4;
hval += (unsigned long int) *(((char *) key) + cnt++);
g = hval & ((unsigned long) 0xf << (LONGBITS - 4));
if (g != 0)
{
hval ^= g >> (LONGBITS - 8);
hval ^= g;
}
}
return hval != 0 ? hval : ~((unsigned long) 0);
}
unsigned long
next_prime (seed)
unsigned long int seed;
{
/* Make it definitely odd. */
seed |= 1;
while (!is_prime (seed))
seed += 2;
return seed;
}
static int
is_prime (candidate)
unsigned long int candidate;
{
/* No even number and none less than 10 will be passed here. */
unsigned long int divn = 3;
unsigned long int sq = divn * divn;
while (sq < candidate && candidate % divn != 0)
{
++divn;
sq += 4 * divn;
++divn;
}
return candidate % divn != 0;
}

View File

@ -0,0 +1,48 @@
/* Copyright (C) 1995, 1996 Free Software Foundation, Inc.
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
License, or (at your option) any later version.
The GNU C Library 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 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. */
#ifndef _SIMPLE_HASH_H
#define _SIMPLE_HASH_H
#include <obstack.h>
typedef struct hash_table
{
unsigned long size;
unsigned long filled;
void *first;
void *table;
struct obstack mem_pool;
}
hash_table;
int init_hash __P ((hash_table *htab, unsigned long int init_size));
int delete_hash __P ((hash_table *htab));
int insert_entry __P ((hash_table *htab, const void *key, size_t keylen,
void *data));
int find_entry __P ((hash_table *htab, const void *key, size_t keylen,
void **result));
int set_entry __P ((hash_table *htab, const void *key, size_t keylen,
void *newval));
int iterate_table __P ((hash_table *htab, void **ptr,
const void **key, size_t *keylen, void **data));
unsigned long next_prime __P ((unsigned long int seed));
#endif /* simple-hash.h */

111
locale/programs/xmalloc.c Normal file
View File

@ -0,0 +1,111 @@
/* xmalloc.c -- malloc with out of memory checking
Copyright (C) 1990, 91, 92, 93, 94, 95 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 2, 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 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#if __STDC__
#define VOID void
#else
#define VOID char
#endif
#include <sys/types.h>
#if STDC_HEADERS || _LIBC
#include <stdlib.h>
#else
VOID *calloc ();
VOID *malloc ();
VOID *realloc ();
void free ();
#endif
#include <libintl.h>
#include "error.h"
#ifndef _
# define _(str) gettext (str)
#endif
#ifndef EXIT_FAILURE
#define EXIT_FAILURE 4
#endif
/* Exit value when the requested amount of memory is not available.
The caller may set it to some other value. */
int xmalloc_exit_failure = EXIT_FAILURE;
static VOID *
fixup_null_alloc (n)
size_t n;
{
VOID *p;
p = 0;
if (n == 0)
p = malloc ((size_t) 1);
if (p == 0)
error (xmalloc_exit_failure, 0, _("memory exhausted"));
return p;
}
/* Allocate N bytes of memory dynamically, with error checking. */
VOID *
xmalloc (n)
size_t n;
{
VOID *p;
p = malloc (n);
if (p == 0)
p = fixup_null_alloc (n);
return p;
}
/* Allocate memory for N elements of S bytes, with error checking. */
VOID *
xcalloc (n, s)
size_t n, s;
{
VOID *p;
p = calloc (n, s);
if (p == 0)
p = fixup_null_alloc (n);
return p;
}
/* Change the size of an allocated block of memory P to N bytes,
with error checking.
If P is NULL, run xmalloc. */
VOID *
xrealloc (p, n)
VOID *p;
size_t n;
{
if (p == 0)
return xmalloc (n);
p = realloc (p, n);
if (p == 0)
p = fixup_null_alloc (n);
return p;
}

36
locale/programs/xstrdup.c Normal file
View File

@ -0,0 +1,36 @@
/* xstrdup.c -- copy a string with out of memory checking
Copyright (C) 1990 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 2, 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 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#if defined(STDC_HEADERS) || defined(HAVE_STRING_H)
#include <string.h>
#else
#include <strings.h>
#endif
char *xmalloc ();
/* Return a newly allocated copy of STRING. */
char *
xstrdup (string)
char *string;
{
return strcpy (xmalloc (strlen (string) + 1), string);
}

View File

@ -18,7 +18,8 @@ not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
#include <alloca.h>
#include <langinfo.h>
#include "localeinfo.h"
#ifndef STRING_TYPE
# error STRING_TYPE not defined
@ -32,10 +33,11 @@ typedef struct weight_t
{
struct weight_t *prev;
struct weight_t *next;
struct data_pair {
size_t number;
u32_t *value;
} data[0];
struct data_pair
{
size_t number;
const u_int32_t *value;
} data[0];
} weight_t;
@ -70,7 +72,7 @@ get_weight (const STRING_TYPE **str, weight_t *result)
slot = (ch * (collate_nrules + 1)) % collate_hash_size;
level = 0;
while (__collate_table[slot] != (u32_t) ch)
while (__collate_table[slot] != (u_int32_t) ch)
{
if (__collate_table[slot + 1] == 0
|| ++level >= collate_hash_layers)
@ -116,7 +118,7 @@ get_weight (const STRING_TYPE **str, weight_t *result)
/* This is a comparison between a u32_t array (aka wchar_t) and
an 8-bit string. */
for (idx = 0; __collate_extra[slot + 2 + idx] != 0; ++idx)
if (__collate_extra[slot + 2 + idx] != (u32_t) str[idx])
if (__collate_extra[slot + 2 + idx] != (u_int32_t) str[idx])
break;
/* When the loop finished with all character of the collation

View File

@ -20,7 +20,6 @@ Boston, MA 02111-1307, USA. */
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include "localeinfo.h"
#ifndef STRING_TYPE
# define STRING_TYPE char
@ -30,7 +29,7 @@ Boston, MA 02111-1307, USA. */
/* Include the shared helper functions. `strxfrm'/`wcsxfrm' also use
these functions. */
#include "weight.h"
#include "../locale/weight.h"
/* Compare S1 and S2, returning less than, equal to or

View File

@ -20,7 +20,6 @@ Boston, MA 02111-1307, USA. */
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include "localeinfo.h"
#ifndef STRING_TYPE
# define STRING_TYPE char
@ -32,16 +31,15 @@ Boston, MA 02111-1307, USA. */
/* Include the shared helper functions. `strxfrm'/`wcsxfrm' also use
these functions. */
#include "weight.h"
#include "../locale/weight.h"
/* Write 32 bit value UTF-8 encoded but only if enough space is left. */
static __inline size_t
print_val (value, dest, max, act)
u32_t value;
STRING_TYPE *dest;
size_t max;
size_t act;
print_val (u_int32_t value,
STRING_TYPE *dest,
size_t max,
size_t act)
{
char tmp[6];
int idx = 0;
@ -139,7 +137,7 @@ STRXFRM (dest, src, n)
do
{
int ignore = 0;
u32_t w;
u_int32_t w;
/* Here we have to check for IGNORE entries. If these are
found we count them and go on witht he next value. */