changeset 1475:f15b2346b20a

.
author Jim Meyering <jim@meyering.net>
date Fri, 14 Aug 1998 14:09:21 +0000
parents 3b5966802618
children 2fc06b743001
files lib/bumpalloc.h lib/diacrit.c lib/diacrit.h
diffstat 3 files changed, 225 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
new file mode 100644
--- /dev/null
+++ b/lib/bumpalloc.h
@@ -0,0 +1,61 @@
+/* BUMP_ALLOC macro - increase table allocation by one element.
+   Copyright (C) 1990, 1991, 1993 Free Software Foundation, Inc.
+   François Pinard <pinard@iro.umontreal.ca>, 1990.
+
+   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.  */
+
+/*-------------------------------------------------------------------------.
+| Bump the allocation of the array pointed to by TABLE whenever required.  |
+| The table already has already COUNT elements in it, this macro ensure it |
+| has enough space to accommodate at least one more element.  Space is	   |
+| allocated (2 ^ EXPONENT) elements at a time.  Each element of the array  |
+| is of type TYPE.							   |
+`-------------------------------------------------------------------------*/
+
+/* Routines `xmalloc' and `xrealloc' are called to do the actual memory
+   management.  This implies that the program will abort with an `Memory
+   exhausted!' error if any problem arise.
+   
+   To work correctly, at least EXPONENT and TYPE should always be the
+   same for all uses of this macro for any given TABLE.  A secure way to
+   achieve this is to never use this macro directly, but use it to define
+   other macros, which would then be TABLE-specific.
+   
+   The first time through, COUNT is usually zero.  Note that COUNT is not
+   updated by this macro, but it should be update elsewhere, later.  This
+   is convenient, because it allows TABLE[COUNT] to refer to the new
+   element at the end.  Once its construction is completed, COUNT++ will
+   record it in the table.  Calling this macro several times in a row
+   without updating COUNT is a bad thing to do.  */
+
+#define BUMP_ALLOC(Table, Count, Exponent, Type) \
+  BUMP_ALLOC_WITH_SIZE ((Table), (Count), (Exponent), Type, sizeof (Type))
+
+/* In cases `sizeof TYPE' would not always yield the correct value for
+   the size of each element entry, this macro accepts a supplementary
+   SIZE argument.  The EXPONENT, TYPE and SIZE parameters should still
+   have the same value for all macro calls related to a specific TABLE.  */
+
+#define BUMP_ALLOC_WITH_SIZE(Table, Count, Exponent, Type, Size) \
+  do									\
+    {									\
+      if (((Count) & (~(~0 << (Exponent)))) == 0)			\
+	if ((Count) == 0)						\
+	  (Table) = (Type *) xmalloc ((1 << (Exponent)) * (Size));	\
+	else								\
+	  (Table) = (Type *)						\
+	    xrealloc ((Table), ((Count) + (1 << (Exponent))) * (Size));	\
+    }									\
+  while (0)
new file mode 100644
--- /dev/null
+++ b/lib/diacrit.c
@@ -0,0 +1,148 @@
+/* Diacritics processing for a few character codes.
+   Copyright (C) 1990, 1991, 1992, 1993 Free Software Foundation, Inc.
+   François Pinard <pinard@iro.umontreal.ca>, 1988.
+
+   All this file is a temporary hack, waiting for locales in GNU.
+*/
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include "diacrit.h"
+
+/* ISO 8859-1 Latin-1 code is used as the underlying character set.  If
+   MSDOS is defined, IBM-PC's character set code is used instead.  */
+
+/*--------------------------------------------------------------------.
+| For each alphabetic character, returns what it would be without its |
+| possible diacritic symbol.					      |
+`--------------------------------------------------------------------*/
+
+const char diacrit_base[256] =
+{
+  0,      0,      0,      0,      0,      0,      0,      0,
+  0,      0,      0,      0,      0,      0,      0,      0,
+  0,      0,      0,      0,      0,      0,      0,      0,
+  0,      0,      0,      0,      0,      0,      0,      0,
+  0,      0,      0,      0,      0,      0,      0,      0,
+  0,      0,      0,      0,      0,      0,      0,      0,
+  0,      0,      0,      0,      0,      0,      0,      0,
+  0,      0,      0,      0,      0,      0,      0,      0,
+  0,      'A',    'B',    'C',    'D',    'E',    'F',    'G',
+  'H',    'I',    'J',    'K',    'L',    'M',    'N',    'O',
+  'P',    'Q',    'R',    'S',    'T',    'U',    'V',    'W',
+  'X',    'Y',    'Z',    0,      0,      0,      0,      0,
+  0,      'a',    'b',    'c',    'd',    'e',    'f',    'g',
+  'h',    'i',    'j',    'k',    'l',    'm',    'n',    'o',
+  'p',    'q',    'r',    's',    't',    'u',    'v',    'w',
+  'x',    'y',    'z',    0,      0,      0,      0,      0,
+
+#ifdef MSDOS
+
+  'C',    'u',    'e',    'a',    'a',    'a',    'a',    'c',
+  'e',    'e',    'e',    'i',    'i',    'i',    'A',    'A',
+  'E',    'e',    'E',    'o',    'o',    'o',    'u',    'u',
+  'y',    'O',    'U',    0,      0,      0,      0,      0,
+  'a',    'i',    'o',    'u',    'n',    'N',    0,      0,
+  0,      0,      0,      0,      0,      0,      0,      0,
+  0,      0,      0,      0,      0,      0,      0,      0,
+  0,      0,      0,      0,      0,      0,      0,      0,
+  0,      0,      0,      0,      0,      0,      0,      0,
+  0,      0,      0,      0,      0,      0,      0,      0,
+  0,      0,      0,      0,      0,      0,      0,      0,
+  0,      0,      0,      0,      0,      0,      0,      0,
+  0,      0,      0,      0,      0,      0,      0,      0,
+  0,      0,      0,      0,      0,      0,      0,      0,
+  0,      0,      0,      0,      0,      0,      0,      0,
+  0,      0,      0,      0,      0,      0,      0,      0,
+
+#else /* not MSDOS */
+
+  0,      0,      0,      0,      0,      0,      0,      0,
+  0,      0,      0,      0,      0,      0,      0,      0,
+  0,      0,      0,      0,      0,      0,      0,      0,
+  0,      0,      0,      0,      0,      0,      0,      0,
+  0,      0,      0,      0,      0,      0,      0,      0,
+  0,      0,      0,      0,      0,      0,      0,      0,
+  0,      0,      0,      0,      0,      0,      0,      0,
+  0,      0,      0,      0,      0,      0,      0,      0,
+  'A',    'A',    'A',    'A',    'A',    'A',    'A',    'C',
+  'E',    'E',    'E',    'E',    'I',    'I',    'I',    'I',
+  0,      'N',    'O',    'O',    'O',    'O',    'O',    0,
+  'O',    'U',    'U',    'U',    'U',    'Y',    0,      0,
+  'a',    'a',    'a',    'a',    'a',    'a',    'a',    'c',
+  'e',    'e',    'e',    'e',    'i',    'i',    'i',    'i',
+  0,      'n',    'o',    'o',    'o',    'o',    'o',    0,
+  'o',    'u',    'u',    'u',    'u',    'y',    0,      'y',
+
+#endif /* not MSDOS */
+};
+
+/*------------------------------------------------------------------------.
+| For each alphabetic character, returns a code of what its diacritic is, |
+| according to the following codes: 1 (eE) over aA for latin diphtongs; 2 |
+| (') acute accent; 3 (`) grave accent; 4 (^) circumflex accent; 5 (")	  |
+| umlaut or diaraesis; 6 (~) tilda; 7 (,) cedilla; 8 (o) covering degree  |
+| symbol; 9 (|) slashed character.					  |
+`------------------------------------------------------------------------*/
+
+const char diacrit_diac[256] =
+{
+  0,      0,      0,      0,      0,      0,      0,      0,
+  0,      0,      0,      0,      0,      0,      0,      0,
+  0,      0,      0,      0,      0,      0,      0,      0,
+  0,      0,      0,      0,      0,      0,      0,      0,
+  0,      0,      0,      0,      0,      0,      0,      0,
+  0,      0,      0,      0,      0,      0,      0,      0,
+  0,      0,      0,      0,      0,      0,      0,      0,
+  0,      0,      0,      0,      0,      0,      0,      0,
+  0,      0,      0,      0,      0,      0,      0,      0,
+  0,      0,      0,      0,      0,      0,      0,      0,
+  0,      0,      0,      0,      0,      0,      0,      0,
+  0,      0,      0,      0,      0,      0,      4,      0,
+  3,      0,      0,      0,      0,      0,      0,      0,
+  0,      0,      0,      0,      0,      0,      0,      0,
+  0,      0,      0,      0,      0,      0,      0,      0,
+  0,      0,      0,      0,      0,      0,      6,      0,
+
+#ifdef MSDOS
+
+  7,      5,      2,      4,      5,      3,      8,      7,
+  4,      5,      3,      5,      4,      3,      5,      8,
+  2,      1,      1,      4,      5,      3,      4,      3,
+  5,      5,      5,      0,      0,      0,      0,      0,
+  2,      2,      2,      2,      6,      6,      0,      0,
+  0,      0,      0,      0,      0,      0,      0,      0,
+  0,      0,      0,      0,      0,      0,      0,      0,
+  0,      0,      0,      0,      0,      0,      0,      0,
+  0,      0,      0,      0,      0,      0,      0,      0,
+  0,      0,      0,      0,      0,      0,      0,      0,
+  0,      0,      0,      0,      0,      0,      0,      0,
+  0,      0,      0,      0,      0,      0,      0,      0,
+  0,      0,      0,      0,      0,      0,      0,      0,
+  0,      0,      0,      0,      0,      0,      0,      0,
+  0,      0,      0,      0,      0,      0,      0,      0,
+  0,      0,      0,      0,      0,      0,      0,      0,
+
+#else /* not MSDOS */
+
+  0,      0,      0,      0,      0,      0,      0,      0,
+  0,      0,      0,      0,      0,      0,      0,      0,
+  0,      0,      0,      0,      0,      0,      0,      0,
+  0,      0,      0,      0,      0,      0,      0,      0,
+  0,      0,      0,      0,      0,      0,      0,      0,
+  0,      0,      0,      0,      0,      0,      0,      0,
+  0,      0,      0,      0,      0,      0,      0,      0,
+  0,      0,      0,      0,      0,      0,      0,      0,
+  3,      2,      4,      6,      5,      8,      1,      7,
+  3,      2,      4,      5,      3,      2,      4,      5,
+  0,      6,      3,      2,      4,      6,      5,      0,
+  9,      3,      2,      4,      5,      2,      0,      0,
+  3,      2,      4,      6,      5,      8,      1,      7,
+  3,      2,      4,      5,      3,      2,      4,      5,
+  0,      6,      3,      2,      4,      6,      5,      0,
+  9,      3,      2,      4,      5,      2,      0,      0,
+
+#endif /* not MSDOS */
+};
new file mode 100644
--- /dev/null
+++ b/lib/diacrit.h
@@ -0,0 +1,16 @@
+/* Diacritics processing for a few character codes.
+   Copyright (C) 1990, 1991, 1992, 1993 Free Software Foundation, Inc.
+   François Pinard <pinard@iro.umontreal.ca>, 1988.
+
+   All this file is a temporary hack, waiting for locales in GNU.
+*/
+
+extern const char diacrit_base[]; /* characters without diacritics */
+extern const char diacrit_diac[]; /* diacritic code for each character */
+
+/* Returns CHAR without its diacritic.  CHAR is known to be alphabetic.  */
+#define tobase(Char) (diacrit_base[(unsigned char) (Char)])
+
+/* Returns a diacritic code for CHAR.  CHAR is known to be alphabetic.  */
+#define todiac(Char) (diacrit_diac[(unsigned char) (Char)])
+