Commit 3b373a64 3b373a64fe7c6cd856897a32e4834cf125797713 by Sergey Poznyakoff

Updated by gnulib-sync

1 parent 6a4be40e
......@@ -23,7 +23,7 @@
#include <stdio.h>
#if !defined _WIN32
#if !((defined _WIN32 || defined __WIN32__) && !defined __CYGWIN__)
#include <stdbool.h>
......@@ -170,13 +170,17 @@ getpass (const char *prompt)
return buf;
}
#else /* WIN32 */
#else /* W32 native */
/* Windows implementation by Martin Lambers <marlam@marlam.de>,
improved by Simon Josefsson. */
/* For PASS_MAX. */
#include <limits.h>
/* For _getch(). */
#include <conio.h>
/* For strdup(). */
#include <string.h>
#ifndef PASS_MAX
# define PASS_MAX 512
......
/* Copyright (C) 1992,1995-1999,2000-2003 Free Software Foundation, Inc.
/* Copyright (C) 1992,1995-1999,2000-2003,2005 Free Software Foundation, Inc.
This file is part of the GNU C Library.
This program is free software; you can redistribute it and/or modify
......@@ -13,9 +13,9 @@
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. */
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
#if HAVE_CONFIG_H
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <alloca.h>
......@@ -27,9 +27,7 @@
#include <stdlib.h>
#include <string.h>
#if _LIBC || HAVE_UNISTD_H
# include <unistd.h>
#endif
#include <unistd.h>
#if !_LIBC
# include "allocsa.h"
......
/* Copyright (C) 1992,1995-1999,2000-2002 Free Software Foundation, Inc.
/* Copyright (C) 1992,1995-1999,2000-2002,2005-2006 Free Software Foundation, Inc.
This file is part of the GNU C Library.
This program is free software; you can redistribute it and/or modify
......@@ -13,25 +13,20 @@
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. */
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
#if HAVE_CONFIG_H
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <errno.h>
#if !_LIBC
# if !defined errno && !defined HAVE_ERRNO_DECL
extern int errno;
# endif
# define __set_errno(ev) ((errno) = (ev))
#endif
#include <stdlib.h>
#include <string.h>
#if _LIBC || HAVE_UNISTD_H
# include <unistd.h>
#endif
#include <unistd.h>
#if !_LIBC
# define __environ environ
......
/* Report a memory allocation failure and exit.
Copyright (C) 1997, 1998, 1999, 2000, 2002, 2003, 2004 Free
Copyright (C) 1997, 1998, 1999, 2000, 2002, 2003, 2004, 2006 Free
Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
......@@ -30,7 +30,6 @@
#include "gettext.h"
#define _(msgid) gettext (msgid)
#define N_(msgid) msgid
void
xalloc_die (void)
......
# argp.m4 serial 5
dnl Copyright (C) 2003-2005 Free Software Foundation, Inc.
# argp.m4 serial 6
dnl Copyright (C) 2003-2006 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
dnl with or without modifications, as long as this notice is preserved.
......@@ -43,11 +43,19 @@ AC_DEFUN([gl_ARGP],
AC_MSG_RESULT(yes)],
[ AC_MSG_RESULT(no)] )
AC_CHECK_DECLS_ONCE(
[clearerr_unlocked feof_unlocked ferror_unlocked
fflush_unlocked fgets_unlocked fputc_unlocked fputs_unlocked
fread_unlocked fwrite_unlocked getc_unlocked
getchar_unlocked putc_unlocked putchar_unlocked])
AC_CHECK_DECLS_ONCE([clearerr_unlocked])
AC_CHECK_DECLS_ONCE([feof_unlocked])
AC_CHECK_DECLS_ONCE([ferror_unlocked])
AC_CHECK_DECLS_ONCE([fflush_unlocked])
AC_CHECK_DECLS_ONCE([fgets_unlocked])
AC_CHECK_DECLS_ONCE([fputc_unlocked])
AC_CHECK_DECLS_ONCE([fputs_unlocked])
AC_CHECK_DECLS_ONCE([fread_unlocked])
AC_CHECK_DECLS_ONCE([fwrite_unlocked])
AC_CHECK_DECLS_ONCE([getc_unlocked])
AC_CHECK_DECLS_ONCE([getchar_unlocked])
AC_CHECK_DECLS_ONCE([putc_unlocked])
AC_CHECK_DECLS_ONCE([putchar_unlocked])
AC_CHECK_FUNCS_ONCE([flockfile funlockfile])
AC_CHECK_HEADERS_ONCE([features.h linewrap.h])
])
......
# Enable extensions on systems that normally disable them.
# Copyright (C) 2003 Free Software Foundation, Inc.
# Copyright (C) 2003, 2006 Free Software Foundation, Inc.
# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.
# This file is only needed in autoconf <= 2.59. Newer versions of autoconf
# have a macro AC_USE_SYSTEM_EXTENSIONS with identical semantics.
# gl_USE_SYSTEM_EXTENSIONS
# ------------------------
# Enable extensions on systems that normally disable them,
......@@ -25,6 +28,15 @@ AC_DEFUN([gl_USE_SYSTEM_EXTENSIONS], [
#ifndef _POSIX_PTHREAD_SEMANTICS
# undef _POSIX_PTHREAD_SEMANTICS
#endif])
AC_DEFINE([__EXTENSIONS__])
AC_CACHE_CHECK([whether it is safe to define __EXTENSIONS__],
[ac_cv_safe_to_define___extensions__],
[AC_COMPILE_IFELSE(
[AC_LANG_PROGRAM([
#define __EXTENSIONS__ 1
AC_INCLUDES_DEFAULT])],
[ac_cv_safe_to_define___extensions__=yes],
[ac_cv_safe_to_define___extensions__=no])])
test $ac_cv_safe_to_define___extensions__ = yes &&
AC_DEFINE([__EXTENSIONS__])
AC_DEFINE([_POSIX_PTHREAD_SEMANTICS])
])
......
#serial 1
#serial 2
# Copyright (C) 2005 Free Software Foundation, Inc.
# Copyright (C) 2005, 2006 Free Software Foundation, Inc.
#
# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
......@@ -29,5 +29,6 @@ AC_DEFUN([gl_GETLOGIN_R],
AC_DEFUN([gl_PREREQ_GETLOGIN_R],
[
AC_CHECK_HEADERS_ONCE([unistd.h])
AC_CHECK_DECLS_ONCE([getlogin getlogin_r])
AC_CHECK_DECLS_ONCE([getlogin])
AC_CHECK_DECLS_ONCE([getlogin_r])
])
......
# getopt.m4 serial 11
dnl Copyright (C) 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
# getopt.m4 serial 12
dnl Copyright (C) 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
dnl with or without modifications, as long as this notice is preserved.
......@@ -77,4 +77,7 @@ AC_DEFUN([gl_GETOPT_IFELSE],
AC_DEFUN([gl_GETOPT], [gl_GETOPT_IFELSE([gl_GETOPT_SUBSTITUTE])])
# Prerequisites of lib/getopt*.
AC_DEFUN([gl_PREREQ_GETOPT], [:])
AC_DEFUN([gl_PREREQ_GETOPT],
[
AC_CHECK_DECLS_ONCE([getenv])
])
......
# getpass.m4 serial 6
dnl Copyright (C) 2002-2003, 2005 Free Software Foundation, Inc.
# getpass.m4 serial 7
dnl Copyright (C) 2002-2003, 2005-2006 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
dnl with or without modifications, as long as this notice is preserved.
......@@ -37,5 +37,9 @@ AC_DEFUN([gl_FUNC_GETPASS_GNU],
AC_DEFUN([gl_PREREQ_GETPASS], [
AC_CHECK_HEADERS_ONCE(stdio_ext.h termios.h)
AC_CHECK_FUNCS_ONCE(__fsetlocking tcgetattr tcsetattr)
AC_CHECK_DECLS_ONCE([fflush_unlocked flockfile fputs_unlocked funlockfile putc_unlocked])
AC_CHECK_DECLS_ONCE([fflush_unlocked])
AC_CHECK_DECLS_ONCE([flockfile])
AC_CHECK_DECLS_ONCE([fputs_unlocked])
AC_CHECK_DECLS_ONCE([funlockfile])
AC_CHECK_DECLS_ONCE([putc_unlocked])
])
......
# longdouble.m4 serial 1 (gettext-0.12)
dnl Copyright (C) 2002-2003 Free Software Foundation, Inc.
# longdouble.m4 serial 2 (gettext-0.15)
dnl Copyright (C) 2002-2003, 2006 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
dnl with or without modifications, as long as this notice is preserved.
......@@ -8,6 +8,9 @@ dnl From Bruno Haible.
dnl Test whether the compiler supports the 'long double' type.
dnl Prerequisite: AC_PROG_CC
dnl This file is only needed in autoconf <= 2.59. Newer versions of autoconf
dnl have a macro AC_TYPE_LONG_DOUBLE with identical semantics.
AC_DEFUN([gt_TYPE_LONGDOUBLE],
[
AC_CACHE_CHECK([for long double], gt_cv_c_long_double,
......
#serial 31
#serial 36
# Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2003, 2004, 2005 Free
# Software Foundation, Inc.
# Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2003, 2004, 2005,
# 2006 Free Software Foundation, Inc.
#
# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
......@@ -14,31 +14,6 @@ AC_PREREQ([2.50])
AC_DEFUN([gl_REGEX],
[
AC_REQUIRE([AC_SYS_LARGEFILE]) dnl for a sufficently-wide off_t
AC_CACHE_CHECK([whether off_t can be used in a switch statement],
[gl_cv_type_off_t_switch],
[AC_COMPILE_IFELSE(
[AC_LANG_PROGRAM(
[AC_INCLUDES_DEFAULT],
[[off_t o = -1;
switch (o)
{
case -2:
return 1;
case -1:
return 2;
default:
return 0;
}
]])],
[gl_cv_type_off_t_switch=yes],
[gl_cv_type_off_t_switch=no])])
if test $gl_cv_type_off_t_switch = yes; then
AC_DEFINE([_REGEX_LARGE_OFFSETS], 1,
[Define if you want regoff_t to be at least as wide POSIX requires.])
fi
MU_LIBSOURCES(
[regcomp.c, regex.c, regex.h,
regex_internal.c, regex_internal.h, regexec.c])
......@@ -49,7 +24,7 @@ AC_DEFUN([gl_REGEX],
systems with recent-enough versions of the GNU C
Library (use with caution on other systems)])])
case $with_included_regex in
case $with_included_regex in #(
yes|no) ac_use_included_regex=$with_included_regex
;;
'')
......@@ -59,20 +34,24 @@ AC_DEFUN([gl_REGEX],
# regex.c. The first failing regular expression is from `Spencer ere
# test #75' in grep-2.3.
AC_CACHE_CHECK([for working re_compile_pattern],
[gl_cv_func_re_compile_pattern_broken],
[gl_cv_func_re_compile_pattern_working],
[AC_RUN_IFELSE(
[AC_LANG_PROGRAM(
[AC_INCLUDES_DEFAULT
#include <regex.h>],
#include <limits.h>
#include <regex.h>
],
[[static struct re_pattern_buffer regex;
unsigned char folded_chars[UCHAR_MAX + 1];
int i;
const char *s;
struct re_registers regs;
/* Use the POSIX-compliant spelling with leading REG_,
rather than the traditional GNU spelling with leading RE_,
so that we reject older libc implementations. */
re_set_syntax (REG_SYNTAX_POSIX_EGREP);
re_set_syntax (RE_SYNTAX_POSIX_EGREP);
memset (&regex, 0, sizeof (regex));
s = re_compile_pattern ("a[:@:>@:]b\n", 9, &regex);
for (i = 0; i <= UCHAR_MAX; i++)
folded_chars[i] = i;
regex.translate = folded_chars;
s = re_compile_pattern ("a[[:@:>@:]]b\n", 11, &regex);
/* This should fail with _Invalid character class name_ error. */
if (!s)
exit (1);
......@@ -106,10 +85,9 @@ AC_DEFUN([gl_REGEX],
exit (1);
/* The version of regex.c in older versions of gnulib
ignored REG_IGNORE_CASE (which was then called RE_ICASE).
Detect that problem too. */
ignored RE_ICASE. Detect that problem too. */
memset (&regex, 0, sizeof (regex));
re_set_syntax (REG_SYNTAX_EMACS | REG_IGNORE_CASE);
re_set_syntax (RE_SYNTAX_EMACS | RE_ICASE);
s = re_compile_pattern ("x", 1, &regex);
if (s)
exit (1);
......@@ -123,24 +101,29 @@ AC_DEFUN([gl_REGEX],
exit (1);
/* Reject hosts whose regoff_t values are too narrow.
These include glibc 2.3.5 on hosts with 64-bit off_t
and 32-bit int, and Solaris 10 on hosts with 32-bit int
and _FILE_OFFSET_BITS=64. */
if (sizeof (regoff_t) < sizeof (off_t))
These include glibc 2.3.5 on hosts with 64-bit ptrdiff_t
and 32-bit int. */
if (sizeof (regoff_t) < sizeof (ptrdiff_t)
|| sizeof (regoff_t) < sizeof (ssize_t))
exit (1);
exit (0);]])],
[gl_cv_func_re_compile_pattern_broken=no],
[gl_cv_func_re_compile_pattern_broken=yes],
dnl When crosscompiling, assume it is broken.
[gl_cv_func_re_compile_pattern_broken=yes])])
ac_use_included_regex=$gl_cv_func_re_compile_pattern_broken
[gl_cv_func_re_compile_pattern_working=yes],
[gl_cv_func_re_compile_pattern_working=no],
dnl When crosscompiling, assume it is not working.
[gl_cv_func_re_compile_pattern_working=no])])
case $gl_cv_func_re_compile_pattern_working in #(
yes) ac_use_included_regex=no;; #(
no) ac_use_included_regex=yes;;
esac
;;
*) AC_MSG_ERROR([Invalid value for --with-included-regex: $with_included_regex])
;;
esac
if test $ac_use_included_regex = yes; then
AC_DEFINE([_REGEX_LARGE_OFFSETS], 1,
[Define if you want regoff_t to be at least as wide POSIX requires.])
AC_DEFINE([re_syntax_options], [rpl_re_syntax_options],
[Define to rpl_re_syntax_options if the replacement should be used.])
AC_DEFINE([re_set_syntax], [rpl_re_set_syntax],
......
# setenv.m4 serial 5
dnl Copyright (C) 2001-2004 Free Software Foundation, Inc.
# setenv.m4 serial 6
dnl Copyright (C) 2001-2004, 2006 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
dnl with or without modifications, as long as this notice is preserved.
......@@ -57,7 +57,6 @@ AC_DEFUN([gl_PREREQ_SETENV],
AC_CHECK_HEADERS_ONCE(unistd.h)
AC_CHECK_HEADERS(search.h)
AC_CHECK_FUNCS(tsearch)
gt_CHECK_VAR_DECL([#include <errno.h>], errno)
gt_CHECK_VAR_DECL([#include <unistd.h>], environ)
])
......@@ -65,6 +64,5 @@ AC_DEFUN([gl_PREREQ_SETENV],
AC_DEFUN([gl_PREREQ_UNSETENV],
[
AC_CHECK_HEADERS_ONCE(unistd.h)
gt_CHECK_VAR_DECL([#include <errno.h>], errno)
gt_CHECK_VAR_DECL([#include <unistd.h>], environ)
])
......
# size_max.m4 serial 3
dnl Copyright (C) 2003, 2005 Free Software Foundation, Inc.
# size_max.m4 serial 4
dnl Copyright (C) 2003, 2005-2006 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
dnl with or without modifications, as long as this notice is preserved.
......@@ -23,28 +23,29 @@ Found it
], result=yes)
if test -z "$result"; then
dnl Define it ourselves. Here we assume that the type 'size_t' is not wider
dnl than the type 'unsigned long'.
dnl The _AC_COMPUTE_INT macro works up to LONG_MAX, since it uses 'expr',
dnl which is guaranteed to work from LONG_MIN to LONG_MAX.
_AC_COMPUTE_INT([(size_t)~(size_t)0 / 10], res_hi,
[#include <stddef.h>], result=?)
_AC_COMPUTE_INT([(size_t)~(size_t)0 % 10], res_lo,
[#include <stddef.h>], result=?)
dnl than the type 'unsigned long'. Try hard to find a definition that can
dnl be used in a preprocessor #if, i.e. doesn't contain a cast.
_AC_COMPUTE_INT([sizeof (size_t) * CHAR_BIT - 1], size_t_bits_minus_1,
[#include <stddef.h>
#include <limits.h>], size_t_bits_minus_1=)
_AC_COMPUTE_INT([sizeof (size_t) <= sizeof (unsigned int)], fits_in_uint,
[#include <stddef.h>], result=?)
if test "$fits_in_uint" = 1; then
dnl Even though SIZE_MAX fits in an unsigned int, it must be of type
dnl 'unsigned long' if the type 'size_t' is the same as 'unsigned long'.
AC_TRY_COMPILE([#include <stddef.h>
extern size_t foo;
extern unsigned long foo;
], [], fits_in_uint=0)
fi
if test -z "$result"; then
if test "$fits_in_uint" = 1; then
result="$res_hi$res_lo"U
[#include <stddef.h>], fits_in_uint=)
if test -n "$size_t_bits_minus_1" && test -n "$fits_in_uint"; then
if test $fits_in_uint = 1; then
dnl Even though SIZE_MAX fits in an unsigned int, it must be of type
dnl 'unsigned long' if the type 'size_t' is the same as 'unsigned long'.
AC_TRY_COMPILE([#include <stddef.h>
extern size_t foo;
extern unsigned long foo;
], [], fits_in_uint=0)
fi
dnl We cannot use 'expr' to simplify this expression, because 'expr'
dnl works only with 'long' integers in the host environment, while we
dnl might be cross-compiling from a 32-bit platform to a 64-bit platform.
if test $fits_in_uint = 1; then
result="(((1U << $size_t_bits_minus_1) - 1) * 2 + 1)"
else
result="$res_hi$res_lo"UL
result="(((1UL << $size_t_bits_minus_1) - 1) * 2 + 1)"
fi
else
dnl Shouldn't happen, but who knows...
......
# ssize_t.m4 serial 3 (gettext-0.13)
dnl Copyright (C) 2001-2003 Free Software Foundation, Inc.
# ssize_t.m4 serial 4 (gettext-0.15)
dnl Copyright (C) 2001-2003, 2006 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
dnl with or without modifications, as long as this notice is preserved.
......@@ -9,12 +9,13 @@ dnl Test whether ssize_t is defined.
AC_DEFUN([gt_TYPE_SSIZE_T],
[
AC_CACHE_CHECK([for ssize_t], gt_cv_ssize_t,
AC_CACHE_CHECK([for ssize_t], [gt_cv_ssize_t],
[AC_TRY_COMPILE([#include <sys/types.h>],
[int x = sizeof (ssize_t *) + sizeof (ssize_t);],
gt_cv_ssize_t=yes, gt_cv_ssize_t=no)])
[int x = sizeof (ssize_t *) + sizeof (ssize_t);
return !x;],
[gt_cv_ssize_t=yes], [gt_cv_ssize_t=no])])
if test $gt_cv_ssize_t = no; then
AC_DEFINE(ssize_t, int,
AC_DEFINE([ssize_t], [int],
[Define as a signed type of the same size as size_t.])
fi
])
......
# Check for stdbool.h that conforms to C99.
dnl Copyright (C) 2002-2005 Free Software Foundation, Inc.
dnl Copyright (C) 2002-2006 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
dnl with or without modifications, as long as this notice is preserved.
......@@ -64,9 +64,9 @@ AC_DEFUN([AC_HEADER_STDBOOL],
char a[true == 1 ? 1 : -1];
char b[false == 0 ? 1 : -1];
char c[__bool_true_false_are_defined == 1 ? 1 : -1];
char d[(bool) -0.5 == true ? 1 : -1];
char d[(bool) 0.5 == true ? 1 : -1];
bool e = &s;
char f[(_Bool) -0.0 == false ? 1 : -1];
char f[(_Bool) 0.0 == false ? 1 : -1];
char g[true];
char h[sizeof (_Bool)];
char i[sizeof s.t];
......@@ -74,11 +74,38 @@ AC_DEFUN([AC_HEADER_STDBOOL],
_Bool n[m];
char o[sizeof n == m * sizeof n[0] ? 1 : -1];
char p[-1 - (_Bool) 0 < 0 && -1 - (bool) 0 < 0 ? 1 : -1];
#if defined __xlc__ || defined __GNUC__
/* Catch a bug in IBM AIX xlc compiler version 6.0.0.0
reported by James Lemley on 2005-10-05; see
http://lists.gnu.org/archive/html/bug-coreutils/2005-10/msg00086.html
This test is not quite right, since xlc is allowed to
reject this program, as the initializer for xlcbug is
not one of the forms that C requires support for.
However, doing the test right would require a run-time
test, and that would make cross-compilation harder.
Let us hope that IBM fixes the xlc bug, and also adds
support for this kind of constant expression. In the
meantime, this test will reject xlc, which is OK, since
our stdbool.h substitute should suffice. We also test
this with GCC, where it should work, to detect more
quickly whether someone messes up the test in the
future. */
char digs[] = "0123456789";
int xlcbug = 1 / (&(digs + 5)[-2 + (bool) 1] == &digs[4] ? 1 : -1);
#endif
/* Catch a bug in an HP-UX C compiler. See
http://gcc.gnu.org/ml/gcc-patches/2003-12/msg02303.html
http://lists.gnu.org/archive/html/bug-coreutils/2005-11/msg00161.html
*/
_Bool q = true;
_Bool *pq = &q;
],
[
*pq |= q;
*pq |= ! q;
/* Refer to every declared value, to avoid compiler optimizations. */
return (!a + !b + !c + !d + !e + !f + !g + !h + !i + !!j + !k + !!l
+ !m + !n + !o + !p);
+ !m + !n + !o + !p + !q + !pq);
],
[ac_cv_header_stdbool_h=yes],
[ac_cv_header_stdbool_h=no])])
......
# stdint.m4 serial 5
dnl Copyright (C) 2001-2002, 2004-2005 Free Software Foundation, Inc.
# stdint.m4 serial 10
dnl Copyright (C) 2001-2002, 2004-2006 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
dnl with or without modifications, as long as this notice is preserved.
......@@ -8,24 +8,59 @@ dnl From Bruno Haible.
dnl Test whether <stdint.h> is supported or must be substituted.
AC_DEFUN([gl_STDINT_H],
[dnl Check for <inttypes.h>.
AC_REQUIRE([gt_HEADER_INTTYPES_H])
dnl Check for <sys/inttypes.h>.
AC_CHECK_HEADERS([sys/inttypes.h])
dnl Check for <sys/bitypes.h> (used in Linux libc4 >= 4.6.7 and libc5).
AC_CHECK_HEADERS([sys/bitypes.h])
AC_MSG_CHECKING([for stdint.h])
AC_CACHE_VAL(gl_cv_header_stdint_h, [
AC_TRY_COMPILE([#include <stdint.h>], [],
gl_cv_header_stdint_h=yes, gl_cv_header_stdint_h=no)])
AC_MSG_RESULT([$gl_cv_header_stdint_h])
if test $gl_cv_header_stdint_h = yes; then
AC_DEFINE(HAVE_STDINT_H, 1,
[Define if you have a working <stdint.h> header file.])
STDINT_H=''
else
STDINT_H='stdint.h'
[
dnl Check for <wchar.h>.
AC_CHECK_HEADERS_ONCE([wchar.h])
if test $ac_cv_header_wchar_h = yes; then
HAVE_WCHAR_H=1
else
HAVE_WCHAR_H=0
fi
AC_SUBST([HAVE_WCHAR_H])
dnl Check for <stdint.h> that doesn't clash with <sys/types.h>.
gl_HEADER_STDINT_H
if test $gl_cv_header_stdint_h = yes; then
ac_cv_header_stdint_h=yes; dnl Hack for gl_FULL_HEADER_PATH.
gl_FULL_HEADER_PATH([stdint.h])
FULL_PATH_STDINT_H='<'$gl_cv_full_path_stdint_h'>'
AC_SUBST([FULL_PATH_STDINT_H])
HAVE_STDINT_H=1
else
HAVE_STDINT_H=0
fi
AC_SUBST([HAVE_STDINT_H])
dnl Check for <inttypes.h> that doesn't clash with <sys/types.h>.
gl_HEADER_INTTYPES_H
if test $gl_cv_header_inttypes_h = yes; then
ac_cv_header_inttypes_h=yes; dnl Hack for gl_FULL_HEADER_PATH.
gl_FULL_HEADER_PATH([inttypes.h])
FULL_PATH_INTTYPES_H='<'$gl_cv_full_path_inttypes_h'>'
AC_SUBST([FULL_PATH_INTTYPES_H])
HAVE_INTTYPES_H=1
else
HAVE_INTTYPES_H=0
fi
AC_SUBST([HAVE_INTTYPES_H])
dnl Check for <sys/inttypes.h>.
AC_CHECK_HEADERS([sys/inttypes.h])
if test $ac_cv_header_sys_inttypes_h = yes; then
HAVE_SYS_INTTYPES_H=1
else
HAVE_SYS_INTTYPES_H=0
fi
AC_SUBST([HAVE_SYS_INTTYPES_H])
dnl Check for <sys/bitypes.h> (used in Linux libc4 >= 4.6.7 and libc5).
AC_CHECK_HEADERS([sys/bitypes.h])
if test $ac_cv_header_sys_bitypes_h = yes; then
HAVE_SYS_BITYPES_H=1
else
HAVE_SYS_BITYPES_H=0
fi
AC_SUBST([HAVE_SYS_BITYPES_H])
dnl Is long == int64_t ?
AC_CACHE_CHECK([whether 'long' is 64 bit wide], gl_cv_long_bitsize_64, [
......@@ -55,6 +90,581 @@ typedef int array [2 * (POW63 != 0 && POW64 == 0) - 1];
fi
AC_SUBST(HAVE_LONG_LONG_64BIT)
fi
AC_SUBST(STDINT_H)
dnl Here we use FULL_PATH_INTTYPES_H and FULL_PATH_STDINT_H, not just
dnl <inttypes.h> and <stdint.h>, so that it also works during a
dnl "config.status --recheck" if an inttypes.h or stdint.h have been
dnl created in the build directory.
other_includes='
/* Get those types that are already defined in other system include files. */
#if defined(__FreeBSD__) && (__FreeBSD__ >= 3) && (__FreeBSD__ <= 4)
# include <sys/inttypes.h>
#endif
#if defined(__OpenBSD__) || defined(__bsdi__) || defined(__sgi)
# include <sys/types.h>
# if HAVE_INTTYPES_H
# include FULL_PATH_INTTYPES_H
# endif
#endif
#if defined(__linux__) && HAVE_SYS_BITYPES_H
# include <sys/bitypes.h>
#endif
#if defined(__sun) && HAVE_SYS_INTTYPES_H
# include <sys/inttypes.h>
#endif
#if (defined(__hpux) || defined(_AIX)) && HAVE_INTTYPES_H
# include FULL_PATH_INTTYPES_H
#endif
#if HAVE_STDINT_H && !(defined(__sgi) && HAVE_INTTYPES_H && !defined(__c99))
# include FULL_PATH_STDINT_H
#endif
'
gl_STDINT_CHECK_TYPES(
[int8_t int16_t int32_t int64_t \
uint8_t uint16_t uint32_t uint64_t \
int_least8_t int_least16_t int_least32_t int_least64_t \
uint_least8_t uint_least16_t uint_least32_t uint_least64_t \
int_fast8_t int_fast16_t int_fast32_t int_fast64_t \
uint_fast8_t uint_fast16_t uint_fast32_t uint_fast64_t \
intptr_t uintptr_t \
intmax_t uintmax_t],
[$other_includes],
[gl_cv_type_], [], [])
dnl Now see if we need a substitute <stdint.h>.
gl_cv_header_working_stdint_h=no
if test $gl_cv_header_stdint_h = yes; then
gl_STDINT_CHECK_TYPES(
[int64_t uint64_t \
int_least64_t uint_least64_t \
int_fast64_t uint_fast64_t],
[#include <stdint.h>],
[gl_cv_stdint_], [_IN_STDINT_H], [in <stdint.h>])
AC_COMPILE_IFELSE([
AC_LANG_PROGRAM([
#define __STDC_LIMIT_MACROS 1 /* to make it work also in C++ mode */
#include <stdint.h>
int8_t a1 = INT8_C (17);
int16_t a2 = INT16_C (17);
int32_t a3 = INT32_C (17);
#if HAVE_INT64_T_IN_STDINT_H
int64_t a4 = INT64_C (17);
#endif
uint8_t b1 = UINT8_C (17);
uint16_t b2 = UINT16_C (17);
uint32_t b3 = UINT32_C (17);
#if HAVE_UINT64_T_IN_STDINT_H
uint64_t b4 = UINT64_C (17);
#endif
int_least8_t c1 = 17;
int_least16_t c2 = 17;
int_least32_t c3 = 17;
#if HAVE_INT_LEAST64_T_IN_STDINT_H
int_least64_t c4 = 17;
#endif
uint_least8_t d1 = 17;
uint_least16_t d2 = 17;
uint_least32_t d3 = 17;
#if HAVE_UINT_LEAST64_T_IN_STDINT_H
uint_least64_t d4 = 17;
#endif
int_fast8_t e1 = 17;
int_fast16_t e2 = 17;
int_fast32_t e3 = 17;
#if HAVE_INT_FAST64_T_IN_STDINT_H
int_fast64_t e4 = 17;
#endif
uint_fast8_t f1 = 17;
uint_fast16_t f2 = 17;
uint_fast32_t f3 = 17;
#if HAVE_UINT_FAST64_T_IN_STDINT_H
uint_fast64_t f4 = 17;
#endif
intptr_t g = 17;
uintptr_t h = 17;
intmax_t i = INTMAX_C (17);
uintmax_t j = UINTMAX_C (17);
])],
[gl_cv_header_working_stdint_h=yes])
fi
if test $gl_cv_header_working_stdint_h = yes; then
dnl Use the existing <stdint.h>, adding missing macro definitions.
suff64=
suffu64=
if test $HAVE_LONG_64BIT = 1; then
suff64=L
suffu64=UL
else
if test $HAVE_LONG_LONG_64BIT = 1; then
suff64=LL
suffu64=ULL
else
AC_EGREP_CPP([msvc compiler], [
#ifdef _MSC_VER
msvc compiler
#endif
], [
suff64=i64
suffu64=ui64
])
fi
fi
dnl Here we assume a standard architecture where the hardware integer
dnl types have 8, 16, 32, optionally 64 bits.
gl_STDINT_MISSING_BOUND([INT8_MIN], [-128],
[Define if <stdint.h> doesn't define it.])
gl_STDINT_MISSING_BOUND([INT8_MAX], [127],
[Define if <stdint.h> doesn't define it.])
gl_STDINT_MISSING_BOUND([UINT8_MAX], [255],
[Define if <stdint.h> doesn't define it.])
gl_STDINT_MISSING_BOUND([INT16_MIN], [-32768],
[Define if <stdint.h> doesn't define it.])
gl_STDINT_MISSING_BOUND([INT16_MAX], [32767],
[Define if <stdint.h> doesn't define it.])
gl_STDINT_MISSING_BOUND([UINT16_MAX], [65535],
[Define if <stdint.h> doesn't define it.])
gl_STDINT_MISSING_BOUND([INT32_MIN], [(~INT32_MAX)],
[Define if <stdint.h> doesn't define it.])
gl_STDINT_MISSING_BOUND([INT32_MAX], [2147483647],
[Define if <stdint.h> doesn't define it.])
gl_STDINT_MISSING_BOUND([UINT32_MAX], [4294967295U],
[Define if <stdint.h> doesn't define it.])
if test $gl_cv_stdint_int64_t = yes; then
gl_STDINT_MISSING_BOUND([INT64_MIN], [(~INT64_MAX)],
[Define if <stdint.h> doesn't define it but has the int64_t type.])
gl_STDINT_MISSING_BOUND([INT64_MAX], [9223372036854775807${suff64}],
[Define if <stdint.h> doesn't define it but has the int64_t type.])
fi
if test $gl_cv_stdint_uint64_t = yes; then
gl_STDINT_MISSING_BOUND([UINT64_MAX], [18446744073709551615${suffu64}],
[Define if <stdint.h> doesn't define it but has the uint64_t type.])
fi
dnl Here we assume a standard architecture where the hardware integer
dnl types have 8, 16, 32, optionally 64 bits. Therefore the leastN_t types
dnl are the same as the corresponding N_t types.
gl_STDINT_MISSING_BOUND([INT_LEAST8_MIN], [INT8_MIN],
[Define if <stdint.h> doesn't define it.])
gl_STDINT_MISSING_BOUND([INT_LEAST8_MAX], [INT8_MAX],
[Define if <stdint.h> doesn't define it.])
gl_STDINT_MISSING_BOUND([UINT_LEAST8_MAX], [UINT8_MAX],
[Define if <stdint.h> doesn't define it.])
gl_STDINT_MISSING_BOUND([INT_LEAST16_MIN], [INT16_MIN],
[Define if <stdint.h> doesn't define it.])
gl_STDINT_MISSING_BOUND([INT_LEAST16_MAX], [INT16_MAX],
[Define if <stdint.h> doesn't define it.])
gl_STDINT_MISSING_BOUND([UINT_LEAST16_MAX], [UINT16_MAX],
[Define if <stdint.h> doesn't define it.])
gl_STDINT_MISSING_BOUND([INT_LEAST32_MIN], [INT32_MIN],
[Define if <stdint.h> doesn't define it.])
gl_STDINT_MISSING_BOUND([INT_LEAST32_MAX], [INT32_MAX],
[Define if <stdint.h> doesn't define it.])
gl_STDINT_MISSING_BOUND([UINT_LEAST32_MAX], [UINT32_MAX],
[Define if <stdint.h> doesn't define it.])
if test $gl_cv_stdint_int_least64_t = yes; then
gl_STDINT_MISSING_BOUND([INT_LEAST64_MIN], [INT64_MIN],
[Define if <stdint.h> doesn't define it but has the int_least64_t type.])
gl_STDINT_MISSING_BOUND([INT_LEAST64_MAX], [INT64_MAX],
[Define if <stdint.h> doesn't define it but has the int_least64_t type.])
fi
if test $gl_cv_stdint_uint_least64_t = yes; then
gl_STDINT_MISSING_BOUND([UINT_LEAST64_MAX], [UINT64_MAX],
[Define if <stdint.h> doesn't define it but has the uint_least64_t type.])
fi
dnl Here we assume a standard architecture where the hardware integer
dnl types have 8, 16, 32, optionally 64 bits. Therefore the fastN_t types
dnl are taken from the same list of types.
gl_STDINT_MISSING_BOUNDS([INT_FAST8_MIN INT_FAST8_MAX UINT_FAST8_MAX \
INT_FAST16_MIN INT_FAST16_MAX UINT_FAST16_MAX \
INT_FAST32_MIN INT_FAST32_MAX UINT_FAST32_MAX])
if test $gl_cv_stdint_uint_fast64_t = yes; then
gl_STDINT_MISSING_BOUNDS([INT_FAST64_MIN INT_FAST64_MAX])
fi
if test $gl_cv_stdint_uint_fast64_t = yes; then
gl_STDINT_MISSING_BOUNDS([UINT_FAST64_MAX])
fi
gl_STDINT_MISSING_BOUNDS([INTPTR_MIN INTPTR_MAX UINTPTR_MAX \
INTMAX_MIN INTMAX_MAX UINTMAX_MAX])
gl_STDINT_MISSING_BOUNDS([PTRDIFF_MIN PTRDIFF_MAX], [#include <stddef.h>])
gl_SIZE_MAX
gl_STDINT_MISSING_BOUNDS2([SIG_ATOMIC_MIN SIG_ATOMIC_MAX],
[#include <signal.h>])
dnl Don't bother defining WCHAR_MIN and WCHAR_MAX, since they should
dnl already be defined in <stddef.h> or <wchar.h>.
dnl For wint_t we need <wchar.h>.
dnl Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included
dnl before <wchar.h>.
dnl BSD/OS 4.1 has a bug: <stdio.h> and <time.h> must be included before
dnl <wchar.h>.
gl_STDINT_MISSING_BOUNDS2([WINT_MIN WINT_MAX], [
#include <stdio.h>
#include <time.h>
#include <wchar.h>
])
STDINT_H=''
else
gl_STDINT_BITSIZEOF(
[int8_t int16_t int32_t int64_t \
uint8_t uint16_t uint32_t uint64_t \
int_least8_t int_least16_t int_least32_t int_least64_t \
uint_least8_t uint_least16_t uint_least32_t uint_least64_t \
int_fast8_t int_fast16_t int_fast32_t int_fast64_t \
uint_fast8_t uint_fast16_t uint_fast32_t uint_fast64_t \
intptr_t uintptr_t \
intmax_t uintmax_t],
[$other_includes])
gl_cv_type_unsigned_int=yes
gl_cv_type_long=yes
gl_cv_type_unsigned_long=yes
gl_STDINT_BITSIZEOF([unsigned_int long unsigned_long],
[typedef unsigned int unsigned_int;
typedef unsigned long unsigned_long;])
AC_CHECK_TYPES([ptrdiff_t])
gl_cv_type_ptrdiff_t=$ac_cv_type_ptrdiff_t
AC_REQUIRE([AC_TYPE_SIZE_T])
gl_cv_type_size_t=yes
gl_STDINT_BITSIZEOF([ptrdiff_t size_t], [#include <stddef.h>])
gl_CHECK_TYPE_SAME([ptrdiff_t], [long], [#include <stddef.h>])
gl_CHECK_TYPE_SAME([size_t], [unsigned long], [#include <stddef.h>])
AC_CHECK_TYPES([sig_atomic_t], , , [#include <signal.h>])
gl_cv_type_sig_atomic_t=$ac_cv_type_sig_atomic_t
gl_STDINT_BITSIZEOF([sig_atomic_t], [#include <signal.h>])
gl_CHECK_TYPES_SIGNED([sig_atomic_t], [#include <signal.h>])
if test $HAVE_SIGNED_SIG_ATOMIC_T = 1; then
gl_CHECK_TYPE_SAME([sig_atomic_t], [long], [#include <signal.h>])
else
gl_CHECK_TYPE_SAME([sig_atomic_t], [unsigned long], [#include <signal.h>])
fi
AC_REQUIRE([gt_TYPE_WCHAR_T])
gl_cv_type_wchar_t=$gt_cv_c_wchar_t
gl_STDINT_BITSIZEOF([wchar_t], [#include <stddef.h>])
gl_CHECK_TYPES_SIGNED([wchar_t], [#include <stddef.h>])
if test $HAVE_SIGNED_WCHAR_T = 1; then
gl_CHECK_TYPE_SAME([wchar_t], [long], [#include <stddef.h>])
else
gl_CHECK_TYPE_SAME([wchar_t], [unsigned long], [#include <stddef.h>])
fi
dnl For wint_t we need <wchar.h>.
dnl Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included
dnl before <wchar.h>.
dnl BSD/OS 4.1 has a bug: <stdio.h> and <time.h> must be included before
dnl <wchar.h>.
AC_CHECK_TYPES([wint_t], , , [#include <stdio.h>
#include <time.h>
#include <wchar.h>
])
gl_cv_type_wint_t=$ac_cv_type_wint_t
gl_STDINT_BITSIZEOF([wint_t], [#include <stdio.h>
#include <time.h>
#include <wchar.h>
])
gl_CHECK_TYPES_SIGNED([wint_t], [#include <stdio.h>
#include <time.h>
#include <wchar.h>
])
if test $HAVE_SIGNED_WINT_T = 1; then
gl_CHECK_TYPE_SAME([wint_t], [long], [#include <stdio.h>
#include <time.h>
#include <wchar.h>
])
else
gl_CHECK_TYPE_SAME([wint_t], [unsigned long], [#include <stdio.h>
#include <time.h>
#include <wchar.h>
])
fi
STDINT_H='stdint.h'
fi
AC_SUBST(STDINT_H)
])
dnl Set gl_cv_header_stdint_h to yes and define HAVE_STDINT_H if
dnl <stdint.h> exists and doesn't clash with <sys/types.h>.
AC_DEFUN([gl_HEADER_STDINT_H],
[
dnl Check for <stdint.h> that doesn't clash with <sys/types.h>.
AC_CACHE_CHECK([for stdint.h], gl_cv_header_stdint_h, [
AC_TRY_COMPILE([
#include <sys/types.h>
#include <stdint.h>],
[], gl_cv_header_stdint_h=yes, gl_cv_header_stdint_h=no)
])
if test $gl_cv_header_stdint_h = yes; then
AC_DEFINE_UNQUOTED(HAVE_STDINT_H, 1,
[Define if <stdint.h> exists and doesn't clash with <sys/types.h>.])
fi
])
dnl Set gl_cv_header_inttypes_h to yes and define HAVE_INTTYPES_H if
dnl <inttypes.h> exists and doesn't clash with <sys/types.h>.
AC_DEFUN([gl_HEADER_INTTYPES_H],
[
dnl Check for <inttypes.h> that doesn't clash with <sys/types.h>.
dnl On IRIX 5.3, <inttypes.h> conflicts with <sys/types.h>.
AC_CACHE_CHECK([for inttypes.h], gl_cv_header_inttypes_h, [
AC_TRY_COMPILE([
#include <sys/types.h>
#include <inttypes.h>],
[], gl_cv_header_inttypes_h=yes, gl_cv_header_inttypes_h=no)
])
if test $gl_cv_header_inttypes_h = yes; then
AC_DEFINE_UNQUOTED(HAVE_INTTYPES_H, 1,
[Define if <inttypes.h> exists and doesn't clash with <sys/types.h>.])
fi
])
dnl gl_STDINT_CHECK_TYPES(TYPES, INCLUDES, CACHE_VAR_PREFIX, MACRO_SUFFIX, DESCRIPTION_SUFFIX)
dnl Check each of the given types, whether they are defined in the given
dnl include files.
AC_DEFUN([gl_STDINT_CHECK_TYPES],
[
dnl Use a shell loop, to avoid bloating configure, and
dnl - extra AH_TEMPLATE calls, so that autoheader knows what to put into
dnl config.h.in,
dnl - extra AC_SUBST calls, so that the right substitutions are made.
AC_FOREACH([gltype], [$1],
[AH_TEMPLATE([HAVE_]translit(gltype,[abcdefghijklmnopqrstuvwxyz],[ABCDEFGHIJKLMNOPQRSTUVWXYZ])[$4],
[Define to 1 if the type ']gltype[' is already defined$5.])])
for gltype in $1 ; do
AC_MSG_CHECKING([for $gltype])
AC_COMPILE_IFELSE([
AC_LANG_PROGRAM([$2
/* Test if the type exists. */
$gltype x = 17;
])],
result=yes, result=no)
eval $3${gltype}=\$result
AC_MSG_RESULT($result)
GLTYPE=`echo "$gltype" | tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ`
if test $result = yes; then
AC_DEFINE_UNQUOTED([HAVE_${GLTYPE}$4], 1)
eval HAVE_${GLTYPE}$4=1
else
eval HAVE_${GLTYPE}$4=0
fi
done
AC_FOREACH([gltype], [$1],
[AC_SUBST([HAVE_]translit(gltype,[abcdefghijklmnopqrstuvwxyz],[ABCDEFGHIJKLMNOPQRSTUVWXYZ])[$4])])
])
dnl gl_STDINT_MISSING_BOUND(TYPE_BOUND, DEFAULT, DESCRIPTION)
dnl assumes an otherwise complete <stdint.h> and defines TYPE_BOUND if
dnl <stdint.h> doesn't define it.
AC_DEFUN([gl_STDINT_MISSING_BOUND],
[
AC_CACHE_CHECK([for $1], [gl_cv_stdint_$1],
[AC_EGREP_CPP([found it], [#include <stdint.h>
#ifdef $1
found it
#endif
], [gl_cv_stdint_$1=yes], [gl_cv_stdint_$1="$2"])])
if test "$gl_cv_stdint_$1" != yes; then
AC_DEFINE_UNQUOTED([$1], [$2], [$3])
fi
])
dnl gl_STDINT_MISSING_BOUNDS(BOUNDS, INCLUDES)
dnl assumes an otherwise complete <stdint.h> and defines each element of BOUNDS
dnl if <stdint.h> doesn't define it.
dnl Use this for types whose signedness is determined by the first letter
dnl ('u' or not).
AC_DEFUN([gl_STDINT_MISSING_BOUNDS],
[
dnl Use a shell loop, to avoid bloating configure, and
dnl - extra AH_TEMPLATE calls, so that autoheader knows what to put into
dnl config.h.in.
AC_FOREACH([bound], [$1],
[AH_TEMPLATE(bound, [Define if <stdint.h> doesn't define it.])])
changequote(,)dnl
sed_unsigned='s,^\(U*\).*,\1,'
sed_limitkind='s,^.*\(_[^_]*\)$,\1,'
changequote([,])dnl
for bound in $1; do
type=`echo $bound | sed -e 's,_MAX,_t,' -e 's,_MIN,_t,' | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz`
unsigned=`echo $bound | sed -e "$sed_unsigned" | tr U u`
width=`echo $bound | sed -e 's,^U*INT,,' -e 's,_MIN,,' -e 's,_MAX,,'`
limitkind=`echo $bound | sed -e "$sed_limitkind"`
AC_CACHE_CHECK([for $bound], [gl_cv_stdint_$bound],
[AC_EGREP_CPP([found it], [#include <stdint.h>
#ifdef $bound
found it
#endif
], [eval gl_cv_stdint_$bound=yes],
[result=
case $width in
*8) widthlist="8 16 32 64" ;;
*16) widthlist="16 32 64" ;;
*32 | PTR | MAX | PTRDIFF) widthlist="32 64" ;;
*64) widthlist="64" ;;
esac
for w in $widthlist; do
if test -z "$result"; then
AC_COMPILE_IFELSE([[$2
#include <stdint.h>
int verify[2 * (sizeof ($type) == sizeof (${unsigned}int${w}_t)) - 1];
]], [result=`echo "$unsigned" | tr u U`INT${w}${limitkind}])
else
break
fi
done
if test -z "$result"; then
result=no
fi
eval gl_cv_stdint_$bound=\$result
])])
eval result=\$gl_cv_stdint_$bound
if test "$result" != yes && test "$result" != no; then
AC_DEFINE_UNQUOTED([$bound], [$result],
[Define if <stdint.h> doesn't define it.])
fi
done
])
dnl gl_STDINT_MISSING_BOUNDS2(BOUNDS, INCLUDES)
dnl assumes an otherwise complete <stdint.h> and defines each element of BOUNDS
dnl if <stdint.h> doesn't define it.
dnl Use this for types whose signedness is a priori unknown.
AC_DEFUN([gl_STDINT_MISSING_BOUNDS2],
[
dnl Use a shell loop, to avoid bloating configure, and
dnl - extra AH_TEMPLATE calls, so that autoheader knows what to put into
dnl config.h.in.
AC_FOREACH([bound], [$1],
[AH_TEMPLATE(bound, [Define if <stdint.h> doesn't define it.])])
changequote(,)dnl
sed_limitkind='s,^.*\(_[^_]*\)$,\1,'
changequote([,])dnl
for bound in $1; do
type=`echo $bound | sed -e 's,_MAX,_t,' -e 's,_MIN,_t,' | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz`
limitkind=`echo $bound | sed -e "$sed_limitkind"`
AC_CACHE_CHECK([for $bound], [gl_cv_stdint_$bound],
[AC_EGREP_CPP([found it], [#include <stdint.h>
#ifdef $bound
found it
#endif
], [eval gl_cv_stdint_$bound=yes],
[result=
AC_COMPILE_IFELSE([[$2
int verify[2 * (($type) -1 >= ($type) 0) - 1];
]],
[eval gl_cv_${type}_signed=no],
[eval gl_cv_${type}_signed=yes])
if eval test \$gl_cv_${type}_signed = yes; then
for w in 8 16 32 64; do
if test -z "$result"; then
AC_COMPILE_IFELSE([[$2
#include <stdint.h>
int verify[2 * (sizeof ($type) == sizeof (int${w}_t)) - 1];
]], [result=INT${w}${limitkind}])
else
break
fi
done
else
if test ${limitkind} = _MIN; then
result=0
else
for w in 8 16 32 64; do
if test -z "$result"; then
AC_COMPILE_IFELSE([[$2
#include <stdint.h>
int verify[2 * (sizeof ($type) == sizeof (uint${w}_t)) - 1];
]], [result=UINT${w}${limitkind}])
else
break
fi
done
fi
fi
if test -z "$result"; then
result=no
fi
eval gl_cv_stdint_$bound=\$result
])])
eval result=\$gl_cv_stdint_$bound
if test "$result" != yes && test "$result" != no; then
AC_DEFINE_UNQUOTED([$bound], [$result],
[Define if <stdint.h> doesn't define it.])
fi
done
])
dnl gl_STDINT_BITSIZEOF(TYPES, INCLUDES)
dnl Determine the size of each of the given types in bits.
AC_DEFUN([gl_STDINT_BITSIZEOF],
[
dnl Use a shell loop, to avoid bloating configure, and
dnl - extra AH_TEMPLATE calls, so that autoheader knows what to put into
dnl config.h.in,
dnl - extra AC_SUBST calls, so that the right substitutions are made.
AC_FOREACH([gltype], [$1],
[AH_TEMPLATE([BITSIZEOF_]translit(gltype,[abcdefghijklmnopqrstuvwxyz ],[ABCDEFGHIJKLMNOPQRSTUVWXYZ_]),
[Define to the number of bits in type ']gltype['.])])
for gltype in $1 ; do
if eval test \$gl_cv_type_${gltype} = yes; then
AC_CACHE_CHECK([for bit size of $gltype], [gl_cv_bitsizeof_${gltype}],
[_AC_COMPUTE_INT([sizeof ($gltype) * CHAR_BIT], result,
[$2
#include <limits.h>], result=unknown)
eval gl_cv_bitsizeof_${gltype}=\$result
])
eval result=\$gl_cv_bitsizeof_${gltype}
GLTYPE=`echo "$gltype" | tr 'abcdefghijklmnopqrstuvwxyz ' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ_'`
AC_DEFINE_UNQUOTED([BITSIZEOF_${GLTYPE}], [$result])
eval BITSIZEOF_${GLTYPE}=\$result
fi
done
AC_FOREACH([gltype], [$1],
[AC_SUBST([BITSIZEOF_]translit(gltype,[abcdefghijklmnopqrstuvwxyz ],[ABCDEFGHIJKLMNOPQRSTUVWXYZ_]))])
])
dnl gl_CHECK_TYPES_SIGNED(TYPES, INCLUDES)
dnl Determine the signedness of each of the given types.
dnl Define HAVE_SIGNED_TYPE if type is signed.
AC_DEFUN([gl_CHECK_TYPES_SIGNED],
[
dnl Use a shell loop, to avoid bloating configure, and
dnl - extra AH_TEMPLATE calls, so that autoheader knows what to put into
dnl config.h.in,
dnl - extra AC_SUBST calls, so that the right substitutions are made.
AC_FOREACH([gltype], [$1],
[AH_TEMPLATE([HAVE_SIGNED_]translit(gltype,[abcdefghijklmnopqrstuvwxyz ],[ABCDEFGHIJKLMNOPQRSTUVWXYZ_]),
[Define to 1 if ']gltype[' is a signed integer type.])])
for gltype in $1 ; do
AC_CACHE_CHECK([whether $gltype is signed], [gl_cv_type_${gltype}_signed],
[AC_COMPILE_IFELSE(
[AC_LANG_PROGRAM([[$2
int verify[2 * (($1) -1 < ($1) 0) - 1];
]])],
result=yes, result=no)
eval gl_cv_type_${gltype}_signed=\$result
])
eval result=\$gl_cv_type_${gltype}_signed
GLTYPE=`echo $gltype | tr 'abcdefghijklmnopqrstuvwxyz ' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ_'`
if test "$result" = yes; then
AC_DEFINE_UNQUOTED([HAVE_SIGNED_${GLTYPE}], 1)
eval HAVE_SIGNED_${GLTYPE}=1
else
eval HAVE_SIGNED_${GLTYPE}=0
fi
done
AC_FOREACH([gltype], [$1],
[AC_SUBST([HAVE_SIGNED_]translit(gltype,[abcdefghijklmnopqrstuvwxyz ],[ABCDEFGHIJKLMNOPQRSTUVWXYZ_]))])
])
dnl gl_CHECK_TYPE_SAME(TYPE, KNOWNTYPE, INCLUDES)
dnl Determines whether two types are the same.
AC_DEFUN([gl_CHECK_TYPE_SAME],
[
AC_TRY_COMPILE([$3
extern $1 foo;
extern $2 foo;], [],
[SAME_TYPE_]AS_TR_CPP([$1])[_]AS_TR_CPP([$2])[=1],
[SAME_TYPE_]AS_TR_CPP([$1])[_]AS_TR_CPP([$2])[=0])
AC_SUBST([SAME_TYPE_]AS_TR_CPP([$1])[_]AS_TR_CPP([$2]))
])
......
......@@ -25,6 +25,7 @@ AC_CACHE_CHECK([whether strerror_r returns char *],
char buf[100];
char x = *strerror_r (0, buf, sizeof buf);
char *p = strerror_r (0, buf, sizeof buf);
return !p || x;
]])],
ac_cv_func_strerror_r_char_p=yes)
else
......
# strndup.m4 serial 5
dnl Copyright (C) 2002, 2003, 2005 Free Software Foundation, Inc.
# strndup.m4 serial 6
dnl Copyright (C) 2002-2003, 2005-2006 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
dnl with or without modifications, as long as this notice is preserved.
......@@ -11,8 +11,36 @@ AC_DEFUN([gl_FUNC_STRNDUP],
dnl Persuade glibc <string.h> to declare strndup().
AC_REQUIRE([AC_GNU_SOURCE])
MU_REPLACE_FUNCS(strndup)
if test $ac_cv_func_strndup = no; then
AC_CHECK_DECLS_ONCE([strndup])
# AIX 4.3.3, AIX 5.1 have a function that fails to add the terminating '\0'.
AC_CACHE_CHECK([for working strndup], gl_cv_func_strndup,
[AC_RUN_IFELSE([
AC_LANG_PROGRAM([#include <string.h>], [[
#ifndef HAVE_DECL_STRNDUP
extern char *strndup (const char *, size_t);
#endif
char *s;
s = strndup ("some longer string", 15);
free (s);
s = strndup ("shorter string", 13);
return s[13] != '\0';]])],
[gl_cv_func_strndup=yes],
[gl_cv_func_strndup=no],
[AC_EGREP_CPP([too risky], [
#ifdef _AIX
too risky
#endif
],
[gl_cv_func_strndup=no],
[gl_cv_func_strndup=yes])])])
if test $gl_cv_func_strndup = yes; then
AC_DEFINE([HAVE_STRNDUP], 1,
[Define if you have the strndup() function and it works.])
else
MU_LIBOBJ([strndup])
AC_DEFINE(strndup, rpl_strndup,
[Define to rpl_strndup if the replacement function should be used,])
gl_PREREQ_STRNDUP
fi
])
......
/* Memory allocation on the stack.
Copyright (C) 1995, 1999, 2001, 2002, 2003, 2004 Free Software
Copyright (C) 1995, 1999, 2001, 2002, 2003, 2004, 2006 Free Software
Foundation, Inc.
This program is free software; you can redistribute it and/or modify it
......@@ -34,19 +34,21 @@
request, the program just crashes.
*/
#ifdef __GNUC__
# define alloca __builtin_alloca
#elif defined _AIX
# define alloca __alloca
#elif defined _MSC_VER
# include <malloc.h>
# define alloca _alloca
#else
# include <stddef.h>
# ifdef __cplusplus
#ifndef alloca
# ifdef __GNUC__
# define alloca __builtin_alloca
# elif defined _AIX
# define alloca __alloca
# elif defined _MSC_VER
# include <malloc.h>
# define alloca _alloca
# else
# include <stddef.h>
# ifdef __cplusplus
extern "C"
# endif
# endif
void *alloca (size_t);
# endif
#endif
#endif /* _GNULIB_ALLOCA_H */
......
......@@ -246,9 +246,10 @@ __argp_fmtstream_update (argp_fmtstream_t fs)
Oh well. Put it on an overlong line by itself. */
p = buf + (r + 1 - fs->point_col);
/* Find the end of the long word. */
do
++p;
while (p < nl && !isblank (*p));
if (p < nl)
do
++p;
while (p < nl && !isblank (*p));
if (p == nl)
{
/* It already ends a line. No fussing required. */
......
......@@ -146,7 +146,7 @@ validate_uparams (const struct argp_state *state, struct uparams *upptr)
__argp_failure (state, 0, 0,
dgettext (state->root_argp->argp_domain,
"\
ARGP_HELP_FMT: %s value is less then or equal to %s"),
ARGP_HELP_FMT: %s value is less than or equal to %s"),
"rmargin", up->name);
return;
}
......@@ -1304,7 +1304,7 @@ usage_long_opt (const struct argp_option *opt,
if (! arg)
arg = real->arg;
if (! (flags & OPTION_NO_USAGE))
if (! (flags & OPTION_NO_USAGE) && !odoc (opt))
{
if (arg)
{
......
......@@ -79,11 +79,11 @@ static volatile int _argp_hang;
static const struct argp_option argp_default_options[] =
{
{"help", '?', 0, 0, N_("Give this help list"), -1},
{"usage", OPT_USAGE, 0, 0, N_("Give a short usage message"), 0},
{"program-name",OPT_PROGNAME,N_("NAME"), OPTION_HIDDEN, N_("Set the program name"), 0},
{"help", '?', 0, 0, N_("give this help list"), -1},
{"usage", OPT_USAGE, 0, 0, N_("give a short usage message"), 0},
{"program-name",OPT_PROGNAME,N_("NAME"), OPTION_HIDDEN, N_("set the program name"), 0},
{"HANG", OPT_HANG, N_("SECS"), OPTION_ARG_OPTIONAL | OPTION_HIDDEN,
N_("Hang for SECS seconds (default 3600)"), 0},
N_("hang for SECS seconds (default 3600)"), 0},
{NULL, 0, 0, 0, NULL, 0}
};
......@@ -140,7 +140,7 @@ static const struct argp argp_default_argp =
static const struct argp_option argp_version_options[] =
{
{"version", 'V', 0, 0, N_("Print program version"), -1},
{"version", 'V', 0, 0, N_("print program version"), -1},
{NULL, 0, 0, 0, NULL, 0}
};
......
/* Copyright (C) 1991,1992,1993,1996,1997,1998,1999,2000,2001,2002,2003,2004,2005
/* Copyright (C) 1991,1992,1993,1996,1997,1998,1999,2000,2001,2002,2003,2004,2005,2006
Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
......@@ -180,7 +180,7 @@ static int posixly_correct;
# define FCT internal_fnmatch
# define EXT ext_match
# define END end_pattern
# define L(CS) CS
# define L_(CS) CS
# ifdef _LIBC
# define BTOWC(C) __btowc (C)
# else
......@@ -210,7 +210,7 @@ static int posixly_correct;
# define FCT internal_fnwmatch
# define EXT ext_wmatch
# define END end_wpattern
# define L(CS) L##CS
# define L_(CS) L##CS
# define BTOWC(C) (C)
# ifdef _LIBC
# define STRLEN(S) __wcslen (S)
......
/* Copyright (C) 1991,1992,1993,1996,1997,1998,1999,2000,2001,2002,2003,2004,2005
/* Copyright (C) 1991,1992,1993,1996,1997,1998,1999,2000,2001,2002,2003,2004,2005,2006
Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
......@@ -39,14 +39,14 @@ FCT (const CHAR *pattern, const CHAR *string, const CHAR *string_end,
# endif
#endif
while ((c = *p++) != L('\0'))
while ((c = *p++) != L_('\0'))
{
bool new_no_leading_period = false;
c = FOLD (c);
switch (c)
{
case L('?'):
case L_('?'):
if (__builtin_expect (flags & FNM_EXTMATCH, 0) && *p == '(')
{
int res;
......@@ -59,17 +59,17 @@ FCT (const CHAR *pattern, const CHAR *string, const CHAR *string_end,
if (n == string_end)
return FNM_NOMATCH;
else if (*n == L('/') && (flags & FNM_FILE_NAME))
else if (*n == L_('/') && (flags & FNM_FILE_NAME))
return FNM_NOMATCH;
else if (*n == L('.') && no_leading_period)
else if (*n == L_('.') && no_leading_period)
return FNM_NOMATCH;
break;
case L('\\'):
case L_('\\'):
if (!(flags & FNM_NOESCAPE))
{
c = *p++;
if (c == L('\0'))
if (c == L_('\0'))
/* Trailing \ loses. */
return FNM_NOMATCH;
c = FOLD (c);
......@@ -78,7 +78,7 @@ FCT (const CHAR *pattern, const CHAR *string, const CHAR *string_end,
return FNM_NOMATCH;
break;
case L('*'):
case L_('*'):
if (__builtin_expect (flags & FNM_EXTMATCH, 0) && *p == '(')
{
int res;
......@@ -89,12 +89,12 @@ FCT (const CHAR *pattern, const CHAR *string, const CHAR *string_end,
return res;
}
if (n != string_end && *n == L('.') && no_leading_period)
if (n != string_end && *n == L_('.') && no_leading_period)
return FNM_NOMATCH;
for (c = *p++; c == L('?') || c == L('*'); c = *p++)
for (c = *p++; c == L_('?') || c == L_('*'); c = *p++)
{
if (*p == L('(') && (flags & FNM_EXTMATCH) != 0)
if (*p == L_('(') && (flags & FNM_EXTMATCH) != 0)
{
const CHAR *endp = END (p);
if (endp != p)
......@@ -105,13 +105,13 @@ FCT (const CHAR *pattern, const CHAR *string, const CHAR *string_end,
}
}
if (c == L('?'))
if (c == L_('?'))
{
/* A ? needs to match one character. */
if (n == string_end)
/* There isn't another character; no match. */
return FNM_NOMATCH;
else if (*n == L('/')
else if (*n == L_('/')
&& __builtin_expect (flags & FNM_FILE_NAME, 0))
/* A slash does not match a wildcard under
FNM_FILE_NAME. */
......@@ -124,7 +124,7 @@ FCT (const CHAR *pattern, const CHAR *string, const CHAR *string_end,
}
}
if (c == L('\0'))
if (c == L_('\0'))
/* The wildcard(s) is/are the last element of the pattern.
If the name is a file name and contains another slash
this means it cannot match, unless the FNM_LEADING_DIR
......@@ -138,7 +138,7 @@ FCT (const CHAR *pattern, const CHAR *string, const CHAR *string_end,
result = 0;
else
{
if (MEMCHR (n, L('/'), string_end - n) == NULL)
if (MEMCHR (n, L_('/'), string_end - n) == NULL)
result = 0;
}
}
......@@ -149,15 +149,15 @@ FCT (const CHAR *pattern, const CHAR *string, const CHAR *string_end,
{
const CHAR *endp;
endp = MEMCHR (n, (flags & FNM_FILE_NAME) ? L('/') : L('\0'),
endp = MEMCHR (n, (flags & FNM_FILE_NAME) ? L_('/') : L_('\0'),
string_end - n);
if (endp == NULL)
endp = string_end;
if (c == L('[')
if (c == L_('[')
|| (__builtin_expect (flags & FNM_EXTMATCH, 0) != 0
&& (c == L('@') || c == L('+') || c == L('!'))
&& *p == L('(')))
&& (c == L_('@') || c == L_('+') || c == L_('!'))
&& *p == L_('(')))
{
int flags2 = ((flags & FNM_FILE_NAME)
? flags : (flags & ~FNM_PERIOD));
......@@ -168,11 +168,11 @@ FCT (const CHAR *pattern, const CHAR *string, const CHAR *string_end,
== 0)
return 0;
}
else if (c == L('/') && (flags & FNM_FILE_NAME))
else if (c == L_('/') && (flags & FNM_FILE_NAME))
{
while (n < string_end && *n != L('/'))
while (n < string_end && *n != L_('/'))
++n;
if (n < string_end && *n == L('/')
if (n < string_end && *n == L_('/')
&& (FCT (p, n + 1, string_end, flags & FNM_PERIOD, flags)
== 0))
return 0;
......@@ -183,7 +183,7 @@ FCT (const CHAR *pattern, const CHAR *string, const CHAR *string_end,
? flags : (flags & ~FNM_PERIOD));
int no_leading_period2 = no_leading_period;
if (c == L('\\') && !(flags & FNM_NOESCAPE))
if (c == L_('\\') && !(flags & FNM_NOESCAPE))
c = *p;
c = FOLD (c);
for (--p; n < endp; ++n, no_leading_period2 = false)
......@@ -197,7 +197,7 @@ FCT (const CHAR *pattern, const CHAR *string, const CHAR *string_end,
/* If we come here no match is possible with the wildcard. */
return FNM_NOMATCH;
case L('['):
case L_('['):
{
/* Nonzero if the sense of the character class is inverted. */
register bool not;
......@@ -210,14 +210,14 @@ FCT (const CHAR *pattern, const CHAR *string, const CHAR *string_end,
if (n == string_end)
return FNM_NOMATCH;
if (*n == L('.') && no_leading_period)
if (*n == L_('.') && no_leading_period)
return FNM_NOMATCH;
if (*n == L('/') && (flags & FNM_FILE_NAME))
if (*n == L_('/') && (flags & FNM_FILE_NAME))
/* `/' cannot be matched. */
return FNM_NOMATCH;
not = (*p == L('!') || (posixly_correct < 0 && *p == L('^')));
not = (*p == L_('!') || (posixly_correct < 0 && *p == L_('^')));
if (not)
++p;
......@@ -226,9 +226,9 @@ FCT (const CHAR *pattern, const CHAR *string, const CHAR *string_end,
c = *p++;
for (;;)
{
if (!(flags & FNM_NOESCAPE) && c == L('\\'))
if (!(flags & FNM_NOESCAPE) && c == L_('\\'))
{
if (*p == L('\0'))
if (*p == L_('\0'))
return FNM_NOMATCH;
c = FOLD ((UCHAR) *p);
++p;
......@@ -236,7 +236,7 @@ FCT (const CHAR *pattern, const CHAR *string, const CHAR *string_end,
if (c == fn)
goto matched;
}
else if (c == L('[') && *p == L(':'))
else if (c == L_('[') && *p == L_(':'))
{
/* Leave room for the null. */
CHAR str[CHAR_CLASS_MAX_LENGTH + 1];
......@@ -254,22 +254,22 @@ FCT (const CHAR *pattern, const CHAR *string, const CHAR *string_end,
return FNM_NOMATCH;
c = *++p;
if (c == L(':') && p[1] == L(']'))
if (c == L_(':') && p[1] == L_(']'))
{
p += 2;
break;
}
if (c < L('a') || c >= L('z'))
if (c < L_('a') || c >= L_('z'))
{
/* This cannot possibly be a character class name.
Match it as a normal range. */
p = startp;
c = L('[');
c = L_('[');
goto normal_bracket;
}
str[c1++] = c;
}
str[c1] = L('\0');
str[c1] = L_('\0');
#if defined _LIBC || WIDE_CHAR_SUPPORT
wt = IS_CHAR_CLASS (str);
......@@ -288,24 +288,24 @@ FCT (const CHAR *pattern, const CHAR *string, const CHAR *string_end,
goto matched;
# endif
#else
if ((STREQ (str, L("alnum")) && ISALNUM ((UCHAR) *n))
|| (STREQ (str, L("alpha")) && ISALPHA ((UCHAR) *n))
|| (STREQ (str, L("blank")) && ISBLANK ((UCHAR) *n))
|| (STREQ (str, L("cntrl")) && ISCNTRL ((UCHAR) *n))
|| (STREQ (str, L("digit")) && ISDIGIT ((UCHAR) *n))
|| (STREQ (str, L("graph")) && ISGRAPH ((UCHAR) *n))
|| (STREQ (str, L("lower")) && ISLOWER ((UCHAR) *n))
|| (STREQ (str, L("print")) && ISPRINT ((UCHAR) *n))
|| (STREQ (str, L("punct")) && ISPUNCT ((UCHAR) *n))
|| (STREQ (str, L("space")) && ISSPACE ((UCHAR) *n))
|| (STREQ (str, L("upper")) && ISUPPER ((UCHAR) *n))
|| (STREQ (str, L("xdigit")) && ISXDIGIT ((UCHAR) *n)))
if ((STREQ (str, L_("alnum")) && ISALNUM ((UCHAR) *n))
|| (STREQ (str, L_("alpha")) && ISALPHA ((UCHAR) *n))
|| (STREQ (str, L_("blank")) && ISBLANK ((UCHAR) *n))
|| (STREQ (str, L_("cntrl")) && ISCNTRL ((UCHAR) *n))
|| (STREQ (str, L_("digit")) && ISDIGIT ((UCHAR) *n))
|| (STREQ (str, L_("graph")) && ISGRAPH ((UCHAR) *n))
|| (STREQ (str, L_("lower")) && ISLOWER ((UCHAR) *n))
|| (STREQ (str, L_("print")) && ISPRINT ((UCHAR) *n))
|| (STREQ (str, L_("punct")) && ISPUNCT ((UCHAR) *n))
|| (STREQ (str, L_("space")) && ISSPACE ((UCHAR) *n))
|| (STREQ (str, L_("upper")) && ISUPPER ((UCHAR) *n))
|| (STREQ (str, L_("xdigit")) && ISXDIGIT ((UCHAR) *n)))
goto matched;
#endif
c = *p++;
}
#ifdef _LIBC
else if (c == L('[') && *p == L('='))
else if (c == L_('[') && *p == L_('='))
{
UCHAR str[1];
uint32_t nrules =
......@@ -313,19 +313,19 @@ FCT (const CHAR *pattern, const CHAR *string, const CHAR *string_end,
const CHAR *startp = p;
c = *++p;
if (c == L('\0'))
if (c == L_('\0'))
{
p = startp;
c = L('[');
c = L_('[');
goto normal_bracket;
}
str[0] = c;
c = *++p;
if (c != L('=') || p[1] != L(']'))
if (c != L_('=') || p[1] != L_(']'))
{
p = startp;
c = L('[');
c = L_('[');
goto normal_bracket;
}
p += 2;
......@@ -405,7 +405,7 @@ FCT (const CHAR *pattern, const CHAR *string, const CHAR *string_end,
c = *p++;
}
#endif
else if (c == L('\0'))
else if (c == L_('\0'))
/* [ (unterminated) loses. */
return FNM_NOMATCH;
else
......@@ -415,7 +415,7 @@ FCT (const CHAR *pattern, const CHAR *string, const CHAR *string_end,
#ifdef _LIBC
bool is_seqval = false;
if (c == L('[') && *p == L('.'))
if (c == L_('[') && *p == L_('.'))
{
uint32_t nrules =
_NL_CURRENT_WORD (LC_COLLATE, _NL_COLLATE_NRULES);
......@@ -425,7 +425,7 @@ FCT (const CHAR *pattern, const CHAR *string, const CHAR *string_end,
while (1)
{
c = *++p;
if (c == L('.') && p[1] == L(']'))
if (c == L_('.') && p[1] == L_(']'))
{
p += 2;
break;
......@@ -438,7 +438,7 @@ FCT (const CHAR *pattern, const CHAR *string, const CHAR *string_end,
/* We have to handling the symbols differently in
ranges since then the collation sequence is
important. */
is_range = *p == L('-') && p[1] != L('\0');
is_range = *p == L_('-') && p[1] != L_('\0');
if (nrules == 0)
{
......@@ -586,8 +586,8 @@ FCT (const CHAR *pattern, const CHAR *string, const CHAR *string_end,
/* We have to handling the symbols differently in
ranges since then the collation sequence is
important. */
is_range = (*p == L('-') && p[1] != L('\0')
&& p[1] != L(']'));
is_range = (*p == L_('-') && p[1] != L_('\0')
&& p[1] != L_(']'));
if (!is_range && c == fn)
goto matched;
......@@ -596,7 +596,7 @@ FCT (const CHAR *pattern, const CHAR *string, const CHAR *string_end,
c = *p++;
}
if (c == L('-') && *p != L(']'))
if (c == L_('-') && *p != L_(']'))
{
#if _LIBC
/* We have to find the collation sequence
......@@ -630,7 +630,7 @@ FCT (const CHAR *pattern, const CHAR *string, const CHAR *string_end,
# endif
is_seqval = false;
if (cend == L('[') && *p == L('.'))
if (cend == L_('[') && *p == L_('.'))
{
uint32_t nrules =
_NL_CURRENT_WORD (LC_COLLATE,
......@@ -641,7 +641,7 @@ FCT (const CHAR *pattern, const CHAR *string, const CHAR *string_end,
while (1)
{
c = *++p;
if (c == L('.') && p[1] == L(']'))
if (c == L_('.') && p[1] == L_(']'))
{
p += 2;
break;
......@@ -760,9 +760,9 @@ FCT (const CHAR *pattern, const CHAR *string, const CHAR *string_end,
}
else
{
if (!(flags & FNM_NOESCAPE) && cend == L('\\'))
if (!(flags & FNM_NOESCAPE) && cend == L_('\\'))
cend = *p++;
if (cend == L('\0'))
if (cend == L_('\0'))
return FNM_NOMATCH;
cend = FOLD (cend);
}
......@@ -814,9 +814,9 @@ FCT (const CHAR *pattern, const CHAR *string, const CHAR *string_end,
and sometimes fatal consequences. */
UCHAR cend = *p++;
if (!(flags & FNM_NOESCAPE) && cend == L('\\'))
if (!(flags & FNM_NOESCAPE) && cend == L_('\\'))
cend = *p++;
if (cend == L('\0'))
if (cend == L_('\0'))
return FNM_NOMATCH;
/* It is a range. */
......@@ -828,7 +828,7 @@ FCT (const CHAR *pattern, const CHAR *string, const CHAR *string_end,
}
}
if (c == L(']'))
if (c == L_(']'))
break;
}
......@@ -843,18 +843,18 @@ FCT (const CHAR *pattern, const CHAR *string, const CHAR *string_end,
ignore_next:
c = *p++;
if (c == L('\0'))
if (c == L_('\0'))
/* [... (unterminated) loses. */
return FNM_NOMATCH;
if (!(flags & FNM_NOESCAPE) && c == L('\\'))
if (!(flags & FNM_NOESCAPE) && c == L_('\\'))
{
if (*p == L('\0'))
if (*p == L_('\0'))
return FNM_NOMATCH;
/* XXX 1003.2d11 is unclear if this is right. */
++p;
}
else if (c == L('[') && *p == L(':'))
else if (c == L_('[') && *p == L_(':'))
{
int c1 = 0;
const CHAR *startp = p;
......@@ -865,10 +865,10 @@ FCT (const CHAR *pattern, const CHAR *string, const CHAR *string_end,
if (++c1 == CHAR_CLASS_MAX_LENGTH)
return FNM_NOMATCH;
if (*p == L(':') && p[1] == L(']'))
if (*p == L_(':') && p[1] == L_(']'))
break;
if (c < L('a') || c >= L('z'))
if (c < L_('a') || c >= L_('z'))
{
p = startp;
goto ignore_next;
......@@ -877,18 +877,18 @@ FCT (const CHAR *pattern, const CHAR *string, const CHAR *string_end,
p += 2;
c = *p++;
}
else if (c == L('[') && *p == L('='))
else if (c == L_('[') && *p == L_('='))
{
c = *++p;
if (c == L('\0'))
if (c == L_('\0'))
return FNM_NOMATCH;
c = *++p;
if (c != L('=') || p[1] != L(']'))
if (c != L_('=') || p[1] != L_(']'))
return FNM_NOMATCH;
p += 2;
c = *p++;
}
else if (c == L('[') && *p == L('.'))
else if (c == L_('[') && *p == L_('.'))
{
++p;
while (1)
......@@ -897,22 +897,22 @@ FCT (const CHAR *pattern, const CHAR *string, const CHAR *string_end,
if (c == '\0')
return FNM_NOMATCH;
if (*p == L('.') && p[1] == L(']'))
if (*p == L_('.') && p[1] == L_(']'))
break;
}
p += 2;
c = *p++;
}
}
while (c != L(']'));
while (c != L_(']'));
if (not)
return FNM_NOMATCH;
}
break;
case L('+'):
case L('@'):
case L('!'):
case L_('+'):
case L_('@'):
case L_('!'):
if (__builtin_expect (flags & FNM_EXTMATCH, 0) && *p == '(')
{
int res;
......@@ -923,7 +923,7 @@ FCT (const CHAR *pattern, const CHAR *string, const CHAR *string_end,
}
goto normal_match;
case L('/'):
case L_('/'):
if (NO_LEADING_PERIOD (flags))
{
if (n == string_end || c != (UCHAR) *n)
......@@ -946,7 +946,7 @@ FCT (const CHAR *pattern, const CHAR *string, const CHAR *string_end,
if (n == string_end)
return 0;
if ((flags & FNM_LEADING_DIR) && n != string_end && *n == L('/'))
if ((flags & FNM_LEADING_DIR) && n != string_end && *n == L_('/'))
/* The FNM_LEADING_DIR flag says that "foo*" matches "foobar/frobozz". */
return 0;
......@@ -961,10 +961,10 @@ END (const CHAR *pattern)
const CHAR *p = pattern;
while (1)
if (*++p == L('\0'))
if (*++p == L_('\0'))
/* This is an invalid pattern. */
return pattern;
else if (*p == L('['))
else if (*p == L_('['))
{
/* Handle brackets special. */
if (posixly_correct == 0)
......@@ -972,21 +972,21 @@ END (const CHAR *pattern)
/* Skip the not sign. We have to recognize it because of a possibly
following ']'. */
if (*++p == L('!') || (posixly_correct < 0 && *p == L('^')))
if (*++p == L_('!') || (posixly_correct < 0 && *p == L_('^')))
++p;
/* A leading ']' is recognized as such. */
if (*p == L(']'))
if (*p == L_(']'))
++p;
/* Skip over all characters of the list. */
while (*p != L(']'))
if (*p++ == L('\0'))
while (*p != L_(']'))
if (*p++ == L_('\0'))
/* This is no valid pattern. */
return pattern;
}
else if ((*p == L('?') || *p == L('*') || *p == L('+') || *p == L('@')
|| *p == L('!')) && p[1] == L('('))
else if ((*p == L_('?') || *p == L_('*') || *p == L_('+') || *p == L_('@')
|| *p == L_('!')) && p[1] == L_('('))
p = END (p + 1);
else if (*p == L(')'))
else if (*p == L_(')'))
break;
return p + 1;
......@@ -1014,10 +1014,10 @@ EXT (INT opt, const CHAR *pattern, const CHAR *string, const CHAR *string_end,
/* Parse the pattern. Store the individual parts in the list. */
level = 0;
for (startp = p = pattern + 1; ; ++p)
if (*p == L('\0'))
if (*p == L_('\0'))
/* This is an invalid pattern. */
return -1;
else if (*p == L('['))
else if (*p == L_('['))
{
/* Handle brackets special. */
if (posixly_correct == 0)
......@@ -1025,22 +1025,22 @@ EXT (INT opt, const CHAR *pattern, const CHAR *string, const CHAR *string_end,
/* Skip the not sign. We have to recognize it because of a possibly
following ']'. */
if (*++p == L('!') || (posixly_correct < 0 && *p == L('^')))
if (*++p == L_('!') || (posixly_correct < 0 && *p == L_('^')))
++p;
/* A leading ']' is recognized as such. */
if (*p == L(']'))
if (*p == L_(']'))
++p;
/* Skip over all characters of the list. */
while (*p != L(']'))
if (*p++ == L('\0'))
while (*p != L_(']'))
if (*p++ == L_('\0'))
/* This is no valid pattern. */
return -1;
}
else if ((*p == L('?') || *p == L('*') || *p == L('+') || *p == L('@')
|| *p == L('!')) && p[1] == L('('))
else if ((*p == L_('?') || *p == L_('*') || *p == L_('+') || *p == L_('@')
|| *p == L_('!')) && p[1] == L_('('))
/* Remember the nesting level. */
++level;
else if (*p == L(')'))
else if (*p == L_(')'))
{
if (level-- == 0)
{
......@@ -1051,7 +1051,7 @@ EXT (INT opt, const CHAR *pattern, const CHAR *string, const CHAR *string_end,
size_t plensize; \
size_t newpsize; \
\
plen = (opt == L('?') || opt == L('@') \
plen = (opt == L_('?') || opt == L_('@') \
? pattern_len \
: p - startp + 1); \
plensize = plen * sizeof (CHAR); \
......@@ -1061,7 +1061,7 @@ EXT (INT opt, const CHAR *pattern, const CHAR *string, const CHAR *string_end,
|| ALLOCA_LIMIT <= newpsize) \
return -1; \
newp = (struct patternlist *) alloca (newpsize); \
*((CHAR *) MEMPCPY (newp->str, startp, p - startp)) = L('\0'); \
*((CHAR *) MEMPCPY (newp->str, startp, p - startp)) = L_('\0'); \
newp->next = NULL; \
*lastp = newp; \
lastp = &newp->next
......@@ -1069,7 +1069,7 @@ EXT (INT opt, const CHAR *pattern, const CHAR *string, const CHAR *string_end,
break;
}
}
else if (*p == L('|'))
else if (*p == L_('|'))
{
if (level == 0)
{
......@@ -1078,17 +1078,17 @@ EXT (INT opt, const CHAR *pattern, const CHAR *string, const CHAR *string_end,
}
}
assert (list != NULL);
assert (p[-1] == L(')'));
assert (p[-1] == L_(')'));
#undef NEW_PATTERN
switch (opt)
{
case L('*'):
case L_('*'):
if (FCT (p, string, string_end, no_leading_period, flags) == 0)
return 0;
/* FALLTHROUGH */
case L('+'):
case L_('+'):
do
{
for (rs = string; rs <= string_end; ++rs)
......@@ -1120,12 +1120,12 @@ EXT (INT opt, const CHAR *pattern, const CHAR *string, const CHAR *string_end,
/* None of the patterns lead to a match. */
return FNM_NOMATCH;
case L('?'):
case L_('?'):
if (FCT (p, string, string_end, no_leading_period, flags) == 0)
return 0;
/* FALLTHROUGH */
case L('@'):
case L_('@'):
do
/* I cannot believe it but `strcat' is actually acceptable
here. Match the entire string with the prefix from the
......@@ -1141,7 +1141,7 @@ EXT (INT opt, const CHAR *pattern, const CHAR *string, const CHAR *string_end,
/* None of the patterns lead to a match. */
return FNM_NOMATCH;
case L('!'):
case L_('!'):
for (rs = string; rs <= string_end; ++rs)
{
struct patternlist *runp;
......@@ -1188,5 +1188,5 @@ EXT (INT opt, const CHAR *pattern, const CHAR *string, const CHAR *string_end,
#undef STRCOLL
#undef STRLEN
#undef STRCAT
#undef L
#undef L_
#undef BTOWC
......
......@@ -26,10 +26,7 @@
#include <errno.h>
#include <string.h>
#if HAVE_UNISTD_H
# include <unistd.h>
#endif
#include <unistd.h>
#if !HAVE_DECL_GETLOGIN
char *getlogin (void);
......
......@@ -19,10 +19,7 @@
/* Written by Paul Eggert and Derek Price. */
#include <stddef.h>
#if HAVE_UNISTD_H
# include <unistd.h>
#endif
#include <unistd.h>
/* Copies the user's login name to NAME.
The array pointed to by NAME has room for SIZE bytes.
......
......@@ -2,7 +2,7 @@
NOTE: getopt is now part of the C library, so if you don't know what
"Keep this file name-space clean" means, talk to drepper@gnu.org
before changing it!
Copyright (C) 1987,88,89,90,91,92,93,94,95,96,98,99,2000,2001,2002,2003,2004
Copyright (C) 1987,88,89,90,91,92,93,94,95,96,98,99,2000,2001,2002,2003,2004,2006
Free Software Foundation, Inc.
This file is part of the GNU C Library.
......@@ -20,28 +20,16 @@
with this program; if not, write to the Free Software Foundation,
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
/* This tells Alpha OSF/1 not to define a getopt prototype in <stdio.h>.
Ditto for AIX 3.2 and <stdlib.h>. */
#ifndef _NO_PROTO
# define _NO_PROTO
#endif
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <stdio.h>
/* This needs to come after some library #include
to get __GNU_LIBRARY__ defined. */
#ifdef __GNU_LIBRARY__
/* Don't include stdlib.h for non-GNU C libraries because some of them
contain conflicting prototypes for getopt. */
# include <stdlib.h>
# include <unistd.h>
#endif /* GNU C library. */
#include "getopt.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#ifdef VMS
# include <unixlib.h>
......@@ -76,7 +64,6 @@
GNU application programs can use a third alternative mode in which
they can distinguish the relative order of options and other arguments. */
#include "getopt.h"
#include "getopt_int.h"
/* For communication from `getopt' to the caller.
......@@ -118,16 +105,9 @@ int optopt = '?';
static struct _getopt_data getopt_data;
#ifndef __GNU_LIBRARY__
/* Avoid depending on library functions or files
whose names are inconsistent. */
#ifndef getenv
#if defined HAVE_DECL_GETENV && !HAVE_DECL_GETENV
extern char *getenv ();
#endif
#endif /* not __GNU_LIBRARY__ */
#ifdef _LIBC
/* Stored original parameters.
......@@ -556,10 +536,7 @@ _getopt_internal_r (int argc, char **argv, const char *optstring,
int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL;
if (_IO_fwide (stderr, 0) > 0)
__fwprintf (stderr, L"%s", buf);
else
fputs (buf, stderr);
__fxprintf (NULL, "%s", buf);
((_IO_FILE *) stderr)->_flags2 = old_flags2;
_IO_funlockfile (stderr);
......@@ -634,10 +611,7 @@ _getopt_internal_r (int argc, char **argv, const char *optstring,
((_IO_FILE *) stderr)->_flags2
|= _IO_FLAGS2_NOTCANCEL;
if (_IO_fwide (stderr, 0) > 0)
__fwprintf (stderr, L"%s", buf);
else
fputs (buf, stderr);
__fxprintf (NULL, "%s", buf);
((_IO_FILE *) stderr)->_flags2 = old_flags2;
_IO_funlockfile (stderr);
......@@ -674,10 +648,7 @@ _getopt_internal_r (int argc, char **argv, const char *optstring,
((_IO_FILE *) stderr)->_flags2
|= _IO_FLAGS2_NOTCANCEL;
if (_IO_fwide (stderr, 0) > 0)
__fwprintf (stderr, L"%s", buf);
else
fputs (buf, stderr);
__fxprintf (NULL, "%s", buf);
((_IO_FILE *) stderr)->_flags2 = old_flags2;
_IO_funlockfile (stderr);
......@@ -751,10 +722,7 @@ _getopt_internal_r (int argc, char **argv, const char *optstring,
int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL;
if (_IO_fwide (stderr, 0) > 0)
__fwprintf (stderr, L"%s", buf);
else
fputs (buf, stderr);
__fxprintf (NULL, "%s", buf);
((_IO_FILE *) stderr)->_flags2 = old_flags2;
_IO_funlockfile (stderr);
......@@ -817,10 +785,7 @@ _getopt_internal_r (int argc, char **argv, const char *optstring,
int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL;
if (_IO_fwide (stderr, 0) > 0)
__fwprintf (stderr, L"%s", buf);
else
fputs (buf, stderr);
__fxprintf (NULL, "%s", buf);
((_IO_FILE *) stderr)->_flags2 = old_flags2;
_IO_funlockfile (stderr);
......@@ -868,10 +833,7 @@ _getopt_internal_r (int argc, char **argv, const char *optstring,
int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL;
if (_IO_fwide (stderr, 0) > 0)
__fwprintf (stderr, L"%s", buf);
else
fputs (buf, stderr);
__fxprintf (NULL, "%s", buf);
((_IO_FILE *) stderr)->_flags2 = old_flags2;
_IO_funlockfile (stderr);
......@@ -940,10 +902,7 @@ _getopt_internal_r (int argc, char **argv, const char *optstring,
int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL;
if (_IO_fwide (stderr, 0) > 0)
__fwprintf (stderr, L"%s", buf);
else
fputs (buf, stderr);
__fxprintf (NULL, "%s", buf);
((_IO_FILE *) stderr)->_flags2 = old_flags2;
_IO_funlockfile (stderr);
......@@ -985,10 +944,7 @@ _getopt_internal_r (int argc, char **argv, const char *optstring,
((_IO_FILE *) stderr)->_flags2
|= _IO_FLAGS2_NOTCANCEL;
if (_IO_fwide (stderr, 0) > 0)
__fwprintf (stderr, L"%s", buf);
else
fputs (buf, stderr);
__fxprintf (NULL, "%s", buf);
((_IO_FILE *) stderr)->_flags2 = old_flags2;
_IO_funlockfile (stderr);
......@@ -1027,10 +983,7 @@ _getopt_internal_r (int argc, char **argv, const char *optstring,
((_IO_FILE *) stderr)->_flags2
|= _IO_FLAGS2_NOTCANCEL;
if (_IO_fwide (stderr, 0) > 0)
__fwprintf (stderr, L"%s", buf);
else
fputs (buf, stderr);
__fxprintf (NULL, "%s", buf);
((_IO_FILE *) stderr)->_flags2 = old_flags2;
_IO_funlockfile (stderr);
......@@ -1101,10 +1054,7 @@ _getopt_internal_r (int argc, char **argv, const char *optstring,
int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL;
if (_IO_fwide (stderr, 0) > 0)
__fwprintf (stderr, L"%s", buf);
else
fputs (buf, stderr);
__fxprintf (NULL, "%s", buf);
((_IO_FILE *) stderr)->_flags2 = old_flags2;
_IO_funlockfile (stderr);
......
/* Copyright (C) 1991-2002,2003,2004,2005 Free Software Foundation, Inc.
/* Copyright (C) 1991-2002,2003,2004,2005,2006 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
......@@ -34,13 +34,10 @@
#include <stdio.h> /* Needed on stupid SunOS for assert. */
#if !defined _LIBC || !defined GLOB_ONLY_P
#if defined HAVE_UNISTD_H || defined _LIBC
# include <unistd.h>
# ifndef POSIX
# ifdef _POSIX_VERSION
# define POSIX
# endif
# endif
#include <unistd.h>
#if !defined POSIX && defined _POSIX_VERSION
# define POSIX
#endif
#include <pwd.h>
......@@ -322,7 +319,7 @@ glob (pattern, flags, errfunc, pglob)
next = next_brace_sub (begin + 1, flags);
if (next == NULL)
{
/* It is an illegal expression. */
/* It is an invalid expression. */
#ifndef __GNUC__
free (onealt);
#endif
......@@ -336,7 +333,7 @@ glob (pattern, flags, errfunc, pglob)
rest = next_brace_sub (rest + 1, flags);
if (rest == NULL)
{
/* It is an illegal expression. */
/* It is an invalid expression. */
#ifndef __GNUC__
free (onealt);
#endif
......@@ -912,8 +909,8 @@ libc_hidden_def (globfree)
static int
collated_compare (const void *a, const void *b)
{
const char *const s1 = *(const char *const * const) a;
const char *const s2 = *(const char *const * const) b;
char *const *ps1 = a; char *s1 = *ps1;
char *const *ps2 = b; char *s2 = *ps2;
if (s1 == s2)
return 0;
......
/* Decomposed printf argument list.
Copyright (C) 1999, 2002-2003 Free Software Foundation, Inc.
Copyright (C) 1999, 2002-2003, 2006 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
......@@ -84,10 +84,29 @@ printf_fetchargs (va_list args, arguments *a)
#endif
case TYPE_STRING:
ap->a.a_string = va_arg (args, const char *);
/* A null pointer is an invalid argument for "%s", but in practice
it occurs quite frequently in printf statements that produce
debug output. Use a fallback in this case. */
if (ap->a.a_string == NULL)
ap->a.a_string = "(NULL)";
break;
#ifdef HAVE_WCHAR_T
case TYPE_WIDE_STRING:
ap->a.a_wide_string = va_arg (args, const wchar_t *);
/* A null pointer is an invalid argument for "%ls", but in practice
it occurs quite frequently in printf statements that produce
debug output. Use a fallback in this case. */
if (ap->a.a_wide_string == NULL)
{
static const wchar_t wide_null_string[] =
{
(wchar_t)'(',
(wchar_t)'N', (wchar_t)'U', (wchar_t)'L', (wchar_t)'L',
(wchar_t)')',
(wchar_t)0
};
ap->a.a_wide_string = wide_null_string;
}
break;
#endif
case TYPE_POINTER:
......
/* Extended regular expression matching and search library.
Copyright (C) 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
Copyright (C) 2002,2003,2004,2005,2006 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Isamu Hasegawa <isamu@yamato.ibm.com>.
......@@ -18,11 +18,11 @@
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
static reg_errcode_t re_compile_internal (regex_t *preg, const char * pattern,
Idx length, reg_syntax_t syntax);
size_t length, reg_syntax_t syntax);
static void re_compile_fastmap_iter (regex_t *bufp,
const re_dfastate_t *init_state,
char *fastmap);
static reg_errcode_t init_dfa (re_dfa_t *dfa, Idx pat_len);
static reg_errcode_t init_dfa (re_dfa_t *dfa, size_t pat_len);
#ifdef RE_ENABLE_I18N
static void free_charset (re_charset_t *cset);
#endif /* RE_ENABLE_I18N */
......@@ -55,7 +55,7 @@ static reg_errcode_t calc_inveclosure (re_dfa_t *dfa);
static Idx fetch_number (re_string_t *input, re_token_t *token,
reg_syntax_t syntax);
static int peek_token (re_token_t *token, re_string_t *input,
reg_syntax_t syntax);
reg_syntax_t syntax) internal_function;
static bin_tree_t *parse (re_string_t *regexp, regex_t *preg,
reg_syntax_t syntax, reg_errcode_t *err);
static bin_tree_t *parse_reg_exp (re_string_t *regexp, regex_t *preg,
......@@ -86,26 +86,26 @@ static reg_errcode_t parse_bracket_symbol (bracket_elem_t *elem,
re_string_t *regexp,
re_token_t *token);
#ifdef RE_ENABLE_I18N
static reg_errcode_t build_equiv_class (bitset sbcset,
static reg_errcode_t build_equiv_class (bitset_t sbcset,
re_charset_t *mbcset,
Idx *equiv_class_alloc,
const unsigned char *name);
static reg_errcode_t build_charclass (unsigned REG_TRANSLATE_TYPE trans,
bitset sbcset,
static reg_errcode_t build_charclass (RE_TRANSLATE_TYPE trans,
bitset_t sbcset,
re_charset_t *mbcset,
Idx *char_class_alloc,
const unsigned char *class_name,
reg_syntax_t syntax);
#else /* not RE_ENABLE_I18N */
static reg_errcode_t build_equiv_class (bitset sbcset,
static reg_errcode_t build_equiv_class (bitset_t sbcset,
const unsigned char *name);
static reg_errcode_t build_charclass (unsigned REG_TRANSLATE_TYPE trans,
bitset sbcset,
static reg_errcode_t build_charclass (RE_TRANSLATE_TYPE trans,
bitset_t sbcset,
const unsigned char *class_name,
reg_syntax_t syntax);
#endif /* not RE_ENABLE_I18N */
static bin_tree_t *build_charclass_op (re_dfa_t *dfa,
unsigned REG_TRANSLATE_TYPE trans,
RE_TRANSLATE_TYPE trans,
const unsigned char *class_name,
const unsigned char *extra,
bool non_match, reg_errcode_t *err);
......@@ -125,7 +125,7 @@ static reg_errcode_t mark_opt_subexp (void *extra, bin_tree_t *node);
POSIX doesn't require that we do anything for REG_NOERROR,
but why not be nice? */
const char __re_error_msgid[] attribute_hidden =
static const char __re_error_msgid[] =
{
#define REG_NOERROR_IDX 0
gettext_noop ("Success") /* REG_NOERROR */
......@@ -179,7 +179,7 @@ const char __re_error_msgid[] attribute_hidden =
gettext_noop ("Unmatched ) or \\)") /* REG_ERPAREN */
};
const size_t __re_error_msgid_idx[] attribute_hidden =
static const size_t __re_error_msgid_idx[] =
{
REG_NOERROR_IDX,
REG_NOMATCH_IDX,
......@@ -206,22 +206,30 @@ const size_t __re_error_msgid_idx[] attribute_hidden =
compiles PATTERN (of length LENGTH) and puts the result in BUFP.
Returns 0 if the pattern was valid, otherwise an error string.
Assumes the `re_allocated' (and perhaps `re_buffer') and `translate' fields
Assumes the `allocated' (and perhaps `buffer') and `translate' fields
are set in BUFP on entry. */
#ifdef _LIBC
const char *
re_compile_pattern (pattern, length, bufp)
const char *pattern;
size_t length;
struct re_pattern_buffer *bufp;
#else /* size_t might promote */
const char *
re_compile_pattern (const char *pattern, size_t length,
struct re_pattern_buffer *bufp)
#endif
{
reg_errcode_t ret;
/* And GNU code determines whether or not to get register information
by passing null for the REGS argument to re_match, etc., not by
setting re_no_sub, unless REG_NO_SUB is set. */
bufp->re_no_sub = !!(re_syntax_options & REG_NO_SUB);
setting no_sub, unless RE_NO_SUB is set. */
bufp->no_sub = !!(re_syntax_options & RE_NO_SUB);
/* Match anchors at newline. */
bufp->re_newline_anchor = 1;
bufp->newline_anchor = 1;
ret = re_compile_internal (bufp, pattern, length, re_syntax_options);
......@@ -249,7 +257,8 @@ reg_syntax_t re_syntax_options;
defined in regex.h. We return the old syntax. */
reg_syntax_t
re_set_syntax (reg_syntax_t syntax)
re_set_syntax (syntax)
reg_syntax_t syntax;
{
reg_syntax_t ret = re_syntax_options;
......@@ -261,10 +270,11 @@ weak_alias (__re_set_syntax, re_set_syntax)
#endif
int
re_compile_fastmap (struct re_pattern_buffer *bufp)
re_compile_fastmap (bufp)
struct re_pattern_buffer *bufp;
{
re_dfa_t *dfa = (re_dfa_t *) bufp->re_buffer;
char *fastmap = bufp->re_fastmap;
re_dfa_t *dfa = (re_dfa_t *) bufp->buffer;
char *fastmap = bufp->fastmap;
memset (fastmap, '\0', sizeof (char) * SBC_MAX);
re_compile_fastmap_iter (bufp, dfa->init_state, fastmap);
......@@ -274,7 +284,7 @@ re_compile_fastmap (struct re_pattern_buffer *bufp)
re_compile_fastmap_iter (bufp, dfa->init_state_nl, fastmap);
if (dfa->init_state != dfa->init_state_begbuf)
re_compile_fastmap_iter (bufp, dfa->init_state_begbuf, fastmap);
bufp->re_fastmap_accurate = 1;
bufp->fastmap_accurate = 1;
return 0;
}
#ifdef _LIBC
......@@ -297,9 +307,9 @@ static void
re_compile_fastmap_iter (regex_t *bufp, const re_dfastate_t *init_state,
char *fastmap)
{
re_dfa_t *dfa = (re_dfa_t *) bufp->re_buffer;
re_dfa_t *dfa = (re_dfa_t *) bufp->buffer;
Idx node_cnt;
bool icase = (dfa->mb_cur_max == 1 && (bufp->re_syntax & REG_IGNORE_CASE));
bool icase = (dfa->mb_cur_max == 1 && (bufp->syntax & RE_ICASE));
for (node_cnt = 0; node_cnt < init_state->nodes.nelem; ++node_cnt)
{
Idx node = init_state->nodes.elems[node_cnt];
......@@ -309,7 +319,7 @@ re_compile_fastmap_iter (regex_t *bufp, const re_dfastate_t *init_state,
{
re_set_fastmap (fastmap, icase, dfa->nodes[node].opr.c);
#ifdef RE_ENABLE_I18N
if ((bufp->re_syntax & REG_IGNORE_CASE) && dfa->mb_cur_max > 1)
if ((bufp->syntax & RE_ICASE) && dfa->mb_cur_max > 1)
{
unsigned char buf[MB_LEN_MAX];
unsigned char *p;
......@@ -322,7 +332,7 @@ re_compile_fastmap_iter (regex_t *bufp, const re_dfastate_t *init_state,
&& dfa->nodes[node].type == CHARACTER
&& dfa->nodes[node].mb_partial)
*p++ = dfa->nodes[node].opr.c;
memset (&state, 0, sizeof (state));
memset (&state, '\0', sizeof (state));
if (mbrtowc (&wc, (const char *) buf, p - buf,
&state) == p - buf
&& (__wcrtomb ((char *) buf, towlower (wc), &state)
......@@ -333,11 +343,15 @@ re_compile_fastmap_iter (regex_t *bufp, const re_dfastate_t *init_state,
}
else if (type == SIMPLE_BRACKET)
{
int i, j, ch;
int i, ch;
for (i = 0, ch = 0; i < BITSET_WORDS; ++i)
for (j = 0; j < BITSET_WORD_BITS; ++j, ++ch)
if (dfa->nodes[node].opr.sbcset[i] & ((bitset_word) 1 << j))
re_set_fastmap (fastmap, icase, ch);
{
int j;
bitset_word_t w = dfa->nodes[node].opr.sbcset[i];
for (j = 0; j < BITSET_WORD_BITS; ++j, ++ch)
if (w & ((bitset_word_t) 1 << j))
re_set_fastmap (fastmap, icase, ch);
}
}
#ifdef RE_ENABLE_I18N
else if (type == COMPLEX_BRACKET)
......@@ -376,7 +390,7 @@ re_compile_fastmap_iter (regex_t *bufp, const re_dfastate_t *init_state,
memset (&state, '\0', sizeof (state));
if (__wcrtomb (buf, cset->mbchars[i], &state) != (size_t) -1)
re_set_fastmap (fastmap, icase, *(unsigned char *) buf);
if ((bufp->re_syntax & REG_IGNORE_CASE) && dfa->mb_cur_max > 1)
if ((bufp->syntax & RE_ICASE) && dfa->mb_cur_max > 1)
{
if (__wcrtomb (buf, towlower (cset->mbchars[i]), &state)
!= (size_t) -1)
......@@ -393,7 +407,7 @@ re_compile_fastmap_iter (regex_t *bufp, const re_dfastate_t *init_state,
{
memset (fastmap, '\1', sizeof (char) * SBC_MAX);
if (type == END_OF_RE)
bufp->re_can_be_null = 1;
bufp->can_be_null = 1;
return;
}
}
......@@ -405,14 +419,14 @@ re_compile_fastmap_iter (regex_t *bufp, const re_dfastate_t *init_state,
PREG is a regex_t *. We do not expect any fields to be initialized,
since POSIX says we shouldn't. Thus, we set
`re_buffer' to the compiled pattern;
`re_used' to the length of the compiled pattern;
`re_syntax' to REG_SYNTAX_POSIX_EXTENDED if the
`buffer' to the compiled pattern;
`used' to the length of the compiled pattern;
`syntax' to RE_SYNTAX_POSIX_EXTENDED if the
REG_EXTENDED bit in CFLAGS is set; otherwise, to
REG_SYNTAX_POSIX_BASIC;
`re_newline_anchor' to REG_NEWLINE being set in CFLAGS;
`re_fastmap' to an allocated space for the fastmap;
`re_fastmap_accurate' to zero;
RE_SYNTAX_POSIX_BASIC;
`newline_anchor' to REG_NEWLINE being set in CFLAGS;
`fastmap' to an allocated space for the fastmap;
`fastmap_accurate' to zero;
`re_nsub' to the number of subexpressions in PATTERN.
PATTERN is the address of the pattern string.
......@@ -436,35 +450,38 @@ re_compile_fastmap_iter (regex_t *bufp, const re_dfastate_t *init_state,
the return codes and their meanings.) */
int
regcomp (regex_t *__restrict preg, const char *__restrict pattern, int cflags)
regcomp (preg, pattern, cflags)
regex_t *__restrict preg;
const char *__restrict pattern;
int cflags;
{
reg_errcode_t ret;
reg_syntax_t syntax = ((cflags & REG_EXTENDED) ? REG_SYNTAX_POSIX_EXTENDED
: REG_SYNTAX_POSIX_BASIC);
reg_syntax_t syntax = ((cflags & REG_EXTENDED) ? RE_SYNTAX_POSIX_EXTENDED
: RE_SYNTAX_POSIX_BASIC);
preg->re_buffer = NULL;
preg->re_allocated = 0;
preg->re_used = 0;
preg->buffer = NULL;
preg->allocated = 0;
preg->used = 0;
/* Try to allocate space for the fastmap. */
preg->re_fastmap = re_malloc (char, SBC_MAX);
if (BE (preg->re_fastmap == NULL, 0))
preg->fastmap = re_malloc (char, SBC_MAX);
if (BE (preg->fastmap == NULL, 0))
return REG_ESPACE;
syntax |= (cflags & REG_ICASE) ? REG_IGNORE_CASE : 0;
syntax |= (cflags & REG_ICASE) ? RE_ICASE : 0;
/* If REG_NEWLINE is set, newlines are treated differently. */
if (cflags & REG_NEWLINE)
{ /* REG_NEWLINE implies neither . nor [^...] match newline. */
syntax &= ~REG_DOT_NEWLINE;
syntax |= REG_HAT_LISTS_NOT_NEWLINE;
syntax &= ~RE_DOT_NEWLINE;
syntax |= RE_HAT_LISTS_NOT_NEWLINE;
/* It also changes the matching behavior. */
preg->re_newline_anchor = 1;
preg->newline_anchor = 1;
}
else
preg->re_newline_anchor = 0;
preg->re_no_sub = !!(cflags & REG_NOSUB);
preg->re_translate = NULL;
preg->newline_anchor = 0;
preg->no_sub = !!(cflags & REG_NOSUB);
preg->translate = NULL;
ret = re_compile_internal (preg, pattern, strlen (pattern), syntax);
......@@ -473,7 +490,7 @@ regcomp (regex_t *__restrict preg, const char *__restrict pattern, int cflags)
if (ret == REG_ERPAREN)
ret = REG_EPAREN;
/* We have already checked preg->re_fastmap != NULL. */
/* We have already checked preg->fastmap != NULL. */
if (BE (ret == REG_NOERROR, 1))
/* Compute the fastmap now, since regexec cannot modify the pattern
buffer. This function never fails in this implementation. */
......@@ -481,8 +498,8 @@ regcomp (regex_t *__restrict preg, const char *__restrict pattern, int cflags)
else
{
/* Some error occurred while compiling the expression. */
re_free (preg->re_fastmap);
preg->re_fastmap = NULL;
re_free (preg->fastmap);
preg->fastmap = NULL;
}
return (int) ret;
......@@ -494,9 +511,18 @@ weak_alias (__regcomp, regcomp)
/* Returns a message corresponding to an error code, ERRCODE, returned
from either regcomp or regexec. We don't use PREG here. */
#ifdef _LIBC
size_t
regerror (errcode, preg, errbuf, errbuf_size)
int errcode;
const regex_t *__restrict preg;
char *__restrict errbuf;
size_t errbuf_size;
#else /* size_t might promote */
size_t
regerror (int errcode, const regex_t *__restrict preg,
char *__restrict errbuf, size_t errbuf_size)
#endif
{
const char *msg;
size_t msg_size;
......@@ -541,21 +567,18 @@ weak_alias (__regerror, regerror)
UTF-8 is used. Otherwise we would allocate memory just to initialize
it the same all the time. UTF-8 is the preferred encoding so this is
a worthwhile optimization. */
static const bitset utf8_sb_map =
static const bitset_t utf8_sb_map =
{
/* Set the first 128 bits. */
# if 2 < BITSET_WORDS
BITSET_WORD_MAX,
# endif
# if 4 < BITSET_WORDS
BITSET_WORD_MAX,
# endif
# if 6 < BITSET_WORDS
# if 4 * BITSET_WORD_BITS < ASCII_CHARS
# error "bitset_word_t is narrower than 32 bits"
# elif 3 * BITSET_WORD_BITS < ASCII_CHARS
BITSET_WORD_MAX, BITSET_WORD_MAX, BITSET_WORD_MAX,
# elif 2 * BITSET_WORD_BITS < ASCII_CHARS
BITSET_WORD_MAX, BITSET_WORD_MAX,
# elif 1 * BITSET_WORD_BITS < ASCII_CHARS
BITSET_WORD_MAX,
# endif
# if 8 < BITSET_WORDS
# error "Invalid BITSET_WORDS"
# endif
(BITSET_WORD_MAX
>> (SBC_MAX % BITSET_WORD_BITS == 0
? 0
......@@ -615,19 +638,20 @@ free_dfa_content (re_dfa_t *dfa)
/* Free dynamically allocated space used by PREG. */
void
regfree (regex_t *preg)
regfree (preg)
regex_t *preg;
{
re_dfa_t *dfa = (re_dfa_t *) preg->re_buffer;
re_dfa_t *dfa = (re_dfa_t *) preg->buffer;
if (BE (dfa != NULL, 1))
free_dfa_content (dfa);
preg->re_buffer = NULL;
preg->re_allocated = 0;
preg->buffer = NULL;
preg->allocated = 0;
re_free (preg->re_fastmap);
preg->re_fastmap = NULL;
re_free (preg->fastmap);
preg->fastmap = NULL;
re_free (preg->re_translate);
preg->re_translate = NULL;
re_free (preg->translate);
preg->translate = NULL;
}
#ifdef _LIBC
weak_alias (__regfree, regfree)
......@@ -648,31 +672,32 @@ char *
regcomp/regexec above without link errors. */
weak_function
# endif
re_comp (const char *s)
re_comp (s)
const char *s;
{
reg_errcode_t ret;
char *fastmap;
if (!s)
{
if (!re_comp_buf.re_buffer)
if (!re_comp_buf.buffer)
return gettext ("No previous regular expression");
return 0;
}
if (re_comp_buf.re_buffer)
if (re_comp_buf.buffer)
{
fastmap = re_comp_buf.re_fastmap;
re_comp_buf.re_fastmap = NULL;
fastmap = re_comp_buf.fastmap;
re_comp_buf.fastmap = NULL;
__regfree (&re_comp_buf);
memset (&re_comp_buf, '\0', sizeof (re_comp_buf));
re_comp_buf.re_fastmap = fastmap;
re_comp_buf.fastmap = fastmap;
}
if (re_comp_buf.re_fastmap == NULL)
if (re_comp_buf.fastmap == NULL)
{
re_comp_buf.re_fastmap = (char *) malloc (SBC_MAX);
if (re_comp_buf.re_fastmap == NULL)
re_comp_buf.fastmap = (char *) malloc (SBC_MAX);
if (re_comp_buf.fastmap == NULL)
return (char *) gettext (__re_error_msgid
+ __re_error_msgid_idx[(int) REG_ESPACE]);
}
......@@ -681,7 +706,7 @@ re_comp (const char *s)
don't need to initialize the pattern buffer fields which affect it. */
/* Match anchors at newlines. */
re_comp_buf.re_newline_anchor = 1;
re_comp_buf.newline_anchor = 1;
ret = re_compile_internal (&re_comp_buf, s, strlen (s), re_syntax_options);
......@@ -706,7 +731,7 @@ libc_freeres_fn (free_mem)
SYNTAX indicate regular expression's syntax. */
static reg_errcode_t
re_compile_internal (regex_t *preg, const char *pattern, Idx length,
re_compile_internal (regex_t *preg, const char * pattern, size_t length,
reg_syntax_t syntax)
{
reg_errcode_t err = REG_NOERROR;
......@@ -714,55 +739,56 @@ re_compile_internal (regex_t *preg, const char *pattern, Idx length,
re_string_t regexp;
/* Initialize the pattern buffer. */
preg->re_fastmap_accurate = 0;
preg->re_syntax = syntax;
preg->re_not_bol = preg->re_not_eol = 0;
preg->re_used = 0;
preg->fastmap_accurate = 0;
preg->syntax = syntax;
preg->not_bol = preg->not_eol = 0;
preg->used = 0;
preg->re_nsub = 0;
preg->re_can_be_null = 0;
preg->re_regs_allocated = REG_UNALLOCATED;
preg->can_be_null = 0;
preg->regs_allocated = REGS_UNALLOCATED;
/* Initialize the dfa. */
dfa = (re_dfa_t *) preg->re_buffer;
if (BE (preg->re_allocated < sizeof (re_dfa_t), 0))
dfa = (re_dfa_t *) preg->buffer;
if (BE (preg->allocated < sizeof (re_dfa_t), 0))
{
/* If zero allocated, but buffer is non-null, try to realloc
enough space. This loses if buffer's address is bogus, but
that is the user's responsibility. If buffer is null this
that is the user's responsibility. If ->buffer is NULL this
is a simple allocation. */
dfa = re_realloc (preg->re_buffer, re_dfa_t, 1);
dfa = re_realloc (preg->buffer, re_dfa_t, 1);
if (dfa == NULL)
return REG_ESPACE;
preg->re_allocated = sizeof (re_dfa_t);
preg->re_buffer = (unsigned char *) dfa;
preg->allocated = sizeof (re_dfa_t);
preg->buffer = (unsigned char *) dfa;
}
preg->re_used = sizeof (re_dfa_t);
__libc_lock_init (dfa->lock);
preg->used = sizeof (re_dfa_t);
err = init_dfa (dfa, length);
if (BE (err != REG_NOERROR, 0))
{
free_dfa_content (dfa);
preg->re_buffer = NULL;
preg->re_allocated = 0;
preg->buffer = NULL;
preg->allocated = 0;
return err;
}
#ifdef DEBUG
/* Note: length+1 will not overflow since it is checked in init_dfa. */
dfa->re_str = re_malloc (char, length + 1);
strncpy (dfa->re_str, pattern, length + 1);
#endif
err = re_string_construct (&regexp, pattern, length, preg->re_translate,
syntax & REG_IGNORE_CASE, dfa);
__libc_lock_init (dfa->lock);
err = re_string_construct (&regexp, pattern, length, preg->translate,
syntax & RE_ICASE, dfa);
if (BE (err != REG_NOERROR, 0))
{
re_compile_internal_free_return:
free_workarea_compile (preg);
re_string_destruct (&regexp);
free_dfa_content (dfa);
preg->re_buffer = NULL;
preg->re_allocated = 0;
preg->buffer = NULL;
preg->allocated = 0;
return err;
}
......@@ -779,7 +805,7 @@ re_compile_internal (regex_t *preg, const char *pattern, Idx length,
#ifdef RE_ENABLE_I18N
/* If possible, do searching in single byte encoding to speed things up. */
if (dfa->is_utf8 && !(syntax & REG_IGNORE_CASE) && preg->re_translate == NULL)
if (dfa->is_utf8 && !(syntax & RE_ICASE) && preg->translate == NULL)
optimize_utf8 (dfa);
#endif
......@@ -793,8 +819,8 @@ re_compile_internal (regex_t *preg, const char *pattern, Idx length,
if (BE (err != REG_NOERROR, 0))
{
free_dfa_content (dfa);
preg->re_buffer = NULL;
preg->re_allocated = 0;
preg->buffer = NULL;
preg->allocated = 0;
}
return err;
......@@ -804,27 +830,45 @@ re_compile_internal (regex_t *preg, const char *pattern, Idx length,
as the initial length of some arrays. */
static reg_errcode_t
init_dfa (re_dfa_t *dfa, Idx pat_len)
init_dfa (re_dfa_t *dfa, size_t pat_len)
{
__re_size_t table_size;
#ifndef _LIBC
char *codeset_name;
#endif
#ifdef RE_ENABLE_I18N
size_t max_i18n_object_size = MAX (sizeof (wchar_t), sizeof (wctype_t));
#else
size_t max_i18n_object_size = 0;
#endif
size_t max_object_size =
MAX (sizeof (struct re_state_table_entry),
MAX (sizeof (re_token_t),
MAX (sizeof (re_node_set),
MAX (sizeof (regmatch_t),
max_i18n_object_size))));
memset (dfa, '\0', sizeof (re_dfa_t));
/* Force allocation of str_tree_storage the first time. */
dfa->str_tree_storage_idx = BIN_TREE_STORAGE_SIZE;
/* Avoid overflows. The extra "/ 2" is for the table_size doubling
calculation below, and for similar doubling calculations
elsewhere. And it's <= rather than <, because some of the
doubling calculations add 1 afterwards. */
if (BE (SIZE_MAX / max_object_size / 2 <= pat_len, 0))
return REG_ESPACE;
dfa->nodes_alloc = pat_len + 1;
dfa->nodes = re_xmalloc (re_token_t, dfa->nodes_alloc);
dfa->nodes = re_malloc (re_token_t, dfa->nodes_alloc);
/* table_size = 2 ^ ceil(log pat_len) */
for (table_size = 1; table_size <= pat_len; table_size <<= 1)
if (0 < (Idx) -1 && table_size == 0)
return REG_ESPACE;
for (table_size = 1; ; table_size <<= 1)
if (table_size > pat_len)
break;
dfa->state_table = re_calloc (struct re_state_table_entry, table_size);
dfa->state_table = calloc (sizeof (struct re_state_table_entry), table_size);
dfa->state_hash_mask = table_size - 1;
dfa->mb_cur_max = MB_CUR_MAX;
......@@ -867,7 +911,7 @@ init_dfa (re_dfa_t *dfa, Idx pat_len)
{
int i, j, ch;
dfa->sb_char = re_calloc (bitset_word, BITSET_WORDS);
dfa->sb_char = (re_bitset_ptr_t) calloc (sizeof (bitset_t), 1);
if (BE (dfa->sb_char == NULL, 0))
return REG_ESPACE;
......@@ -877,7 +921,7 @@ init_dfa (re_dfa_t *dfa, Idx pat_len)
{
wint_t wch = __btowc (ch);
if (wch != WEOF)
dfa->sb_char[i] |= (bitset_word) 1 << j;
dfa->sb_char[i] |= (bitset_word_t) 1 << j;
# ifndef _LIBC
if (isascii (ch) && wch != ch)
dfa->map_notascii = 1;
......@@ -897,6 +941,7 @@ init_dfa (re_dfa_t *dfa, Idx pat_len)
character used by some operators like "\<", "\>", etc. */
static void
internal_function
init_word_char (re_dfa_t *dfa)
{
int i, j, ch;
......@@ -904,7 +949,7 @@ init_word_char (re_dfa_t *dfa)
for (i = 0, ch = 0; i < BITSET_WORDS; ++i)
for (j = 0; j < BITSET_WORD_BITS; ++j, ++ch)
if (isalnum (ch) || ch == '_')
dfa->word_char[i] |= (bitset_word) 1 << j;
dfa->word_char[i] |= (bitset_word_t) 1 << j;
}
/* Free the work area which are only used while compiling. */
......@@ -912,7 +957,7 @@ init_word_char (re_dfa_t *dfa)
static void
free_workarea_compile (regex_t *preg)
{
re_dfa_t *dfa = (re_dfa_t *) preg->re_buffer;
re_dfa_t *dfa = (re_dfa_t *) preg->buffer;
bin_tree_storage_t *storage, *next;
for (storage = dfa->str_tree_storage; storage; storage = next)
{
......@@ -1022,7 +1067,7 @@ optimize_utf8 (re_dfa_t *dfa)
switch (dfa->nodes[node].type)
{
case CHARACTER:
if (dfa->nodes[node].opr.c >= 0x80)
if (dfa->nodes[node].opr.c >= ASCII_CHARS)
mb_chars = true;
break;
case ANCHOR:
......@@ -1053,11 +1098,10 @@ optimize_utf8 (re_dfa_t *dfa)
case SIMPLE_BRACKET:
/* Just double check. */
{
int rshift =
(SBC_MAX / 2 % BITSET_WORD_BITS == 0
? 0
: BITSET_WORD_BITS - SBC_MAX / 2 % BITSET_WORD_BITS);
for (i = SBC_MAX / 2 / BITSET_WORD_BITS; i < BITSET_WORDS; ++i)
int rshift = (ASCII_CHARS % BITSET_WORD_BITS == 0
? 0
: BITSET_WORD_BITS - ASCII_CHARS % BITSET_WORD_BITS);
for (i = ASCII_CHARS / BITSET_WORD_BITS; i < BITSET_WORDS; ++i)
{
if (dfa->nodes[node].opr.sbcset[i] >> rshift != 0)
return;
......@@ -1073,7 +1117,7 @@ optimize_utf8 (re_dfa_t *dfa)
for (node = 0; node < dfa->nodes_len; ++node)
{
if (dfa->nodes[node].type == CHARACTER
&& dfa->nodes[node].opr.c >= 0x80)
&& dfa->nodes[node].opr.c >= ASCII_CHARS)
dfa->nodes[node].mb_partial = 0;
else if (dfa->nodes[node].type == OP_PERIOD)
dfa->nodes[node].type = OP_UTF8_PERIOD;
......@@ -1092,19 +1136,19 @@ optimize_utf8 (re_dfa_t *dfa)
static reg_errcode_t
analyze (regex_t *preg)
{
re_dfa_t *dfa = (re_dfa_t *) preg->re_buffer;
re_dfa_t *dfa = (re_dfa_t *) preg->buffer;
reg_errcode_t ret;
/* Allocate arrays. */
dfa->nexts = re_malloc (Idx, dfa->nodes_alloc);
dfa->org_indices = re_malloc (Idx, dfa->nodes_alloc);
dfa->edests = re_xmalloc (re_node_set, dfa->nodes_alloc);
dfa->edests = re_malloc (re_node_set, dfa->nodes_alloc);
dfa->eclosures = re_malloc (re_node_set, dfa->nodes_alloc);
if (BE (dfa->nexts == NULL || dfa->org_indices == NULL || dfa->edests == NULL
|| dfa->eclosures == NULL, 0))
return REG_ESPACE;
dfa->subexp_map = re_xmalloc (Idx, preg->re_nsub);
dfa->subexp_map = re_malloc (Idx, preg->re_nsub);
if (dfa->subexp_map != NULL)
{
Idx i;
......@@ -1137,10 +1181,10 @@ analyze (regex_t *preg)
/* We only need this during the prune_impossible_nodes pass in regexec.c;
skip it if p_i_n will not run, as calc_inveclosure can be quadratic. */
if ((!preg->re_no_sub && preg->re_nsub > 0 && dfa->has_plural_match)
if ((!preg->no_sub && preg->re_nsub > 0 && dfa->has_plural_match)
|| dfa->nbackref)
{
dfa->inveclosures = re_xmalloc (re_node_set, dfa->nodes_len);
dfa->inveclosures = re_malloc (re_node_set, dfa->nodes_len);
if (BE (dfa->inveclosures == NULL, 0))
return REG_ESPACE;
ret = calc_inveclosure (dfa);
......@@ -1240,7 +1284,7 @@ optimize_subexps (void *extra, bin_tree_t *node)
dfa->subexp_map[other_idx] = dfa->subexp_map[node->token.opr.idx];
if (other_idx < BITSET_WORD_BITS)
dfa->used_bkref_map &= ~ ((bitset_word) 1 << other_idx);
dfa->used_bkref_map &= ~((bitset_word_t) 1 << other_idx);
}
return REG_NOERROR;
......@@ -1273,18 +1317,19 @@ lower_subexps (void *extra, bin_tree_t *node)
static bin_tree_t *
lower_subexp (reg_errcode_t *err, regex_t *preg, bin_tree_t *node)
{
re_dfa_t *dfa = (re_dfa_t *) preg->re_buffer;
re_dfa_t *dfa = (re_dfa_t *) preg->buffer;
bin_tree_t *body = node->left;
bin_tree_t *op, *cls, *tree1, *tree;
if (preg->re_no_sub
if (preg->no_sub
/* We do not optimize empty subexpressions, because otherwise we may
have bad CONCAT nodes with NULL children. This is obviously not
very common, so we do not lose much. An example that triggers
this case is the sed "script" /\(\)/x. */
&& node->left != NULL
&& ! (node->token.opr.idx < BITSET_WORD_BITS
&& dfa->used_bkref_map & ((bitset_word) 1 << node->token.opr.idx)))
&& (node->token.opr.idx >= BITSET_WORD_BITS
|| !(dfa->used_bkref_map
& ((bitset_word_t) 1 << node->token.opr.idx))))
return node->left;
/* Convert the SUBEXP node to the concatenation of an
......@@ -1410,9 +1455,9 @@ link_nfa_nodes (void *extra, bin_tree_t *node)
to their own constraint. */
static reg_errcode_t
duplicate_node_closure (re_dfa_t *dfa, Idx top_org_node,
Idx top_clone_node, Idx root_node,
unsigned int init_constraint)
internal_function
duplicate_node_closure (re_dfa_t *dfa, Idx top_org_node, Idx top_clone_node,
Idx root_node, unsigned int init_constraint)
{
Idx org_node, clone_node;
bool ok;
......@@ -1458,8 +1503,7 @@ duplicate_node_closure (re_dfa_t *dfa, Idx top_org_node,
/* ...but if the node is root_node itself, it means the
epsilon closure have a loop, then tie it to the
destination of the root_node. */
ok = re_node_set_insert (dfa->edests + clone_node,
org_dest);
ok = re_node_set_insert (dfa->edests + clone_node, org_dest);
if (BE (! ok, 0))
return REG_ESPACE;
break;
......@@ -1652,8 +1696,6 @@ calc_eclosure_iter (re_node_set *new_set, re_dfa_t *dfa, Idx node, bool root)
&& dfa->edests[node].nelem
&& !dfa->nodes[dfa->edests[node].elems[0]].duplicated)
{
Idx org_node, cur_node;
org_node = cur_node = node;
err = duplicate_node_closure (dfa, node, node, node, constraint);
if (BE (err != REG_NOERROR, 0))
return err;
......@@ -1711,6 +1753,7 @@ calc_eclosure_iter (re_node_set *new_set, re_dfa_t *dfa, Idx node, bool root)
We must not use this function inside bracket expressions. */
static void
internal_function
fetch_token (re_token_t *result, re_string_t *input, reg_syntax_t syntax)
{
re_string_skip_bytes (input, peek_token (result, input, syntax));
......@@ -1720,6 +1763,7 @@ fetch_token (re_token_t *result, re_string_t *input, reg_syntax_t syntax)
We must not use this function inside bracket expressions. */
static int
internal_function
peek_token (re_token_t *token, re_string_t *input, reg_syntax_t syntax)
{
unsigned char c;
......@@ -1770,97 +1814,97 @@ peek_token (re_token_t *token, re_string_t *input, reg_syntax_t syntax)
switch (c2)
{
case '|':
if (!(syntax & REG_LIMITED_OPS) && !(syntax & REG_NO_BK_VBAR))
if (!(syntax & RE_LIMITED_OPS) && !(syntax & RE_NO_BK_VBAR))
token->type = OP_ALT;
break;
case '1': case '2': case '3': case '4': case '5':
case '6': case '7': case '8': case '9':
if (!(syntax & REG_NO_BK_REFS))
if (!(syntax & RE_NO_BK_REFS))
{
token->type = OP_BACK_REF;
token->opr.idx = c2 - '1';
}
break;
case '<':
if (!(syntax & REG_NO_GNU_OPS))
if (!(syntax & RE_NO_GNU_OPS))
{
token->type = ANCHOR;
token->opr.ctx_type = WORD_FIRST;
}
break;
case '>':
if (!(syntax & REG_NO_GNU_OPS))
if (!(syntax & RE_NO_GNU_OPS))
{
token->type = ANCHOR;
token->opr.ctx_type = WORD_LAST;
}
break;
case 'b':
if (!(syntax & REG_NO_GNU_OPS))
if (!(syntax & RE_NO_GNU_OPS))
{
token->type = ANCHOR;
token->opr.ctx_type = WORD_DELIM;
}
break;
case 'B':
if (!(syntax & REG_NO_GNU_OPS))
if (!(syntax & RE_NO_GNU_OPS))
{
token->type = ANCHOR;
token->opr.ctx_type = NOT_WORD_DELIM;
}
break;
case 'w':
if (!(syntax & REG_NO_GNU_OPS))
if (!(syntax & RE_NO_GNU_OPS))
token->type = OP_WORD;
break;
case 'W':
if (!(syntax & REG_NO_GNU_OPS))
if (!(syntax & RE_NO_GNU_OPS))
token->type = OP_NOTWORD;
break;
case 's':
if (!(syntax & REG_NO_GNU_OPS))
if (!(syntax & RE_NO_GNU_OPS))
token->type = OP_SPACE;
break;
case 'S':
if (!(syntax & REG_NO_GNU_OPS))
if (!(syntax & RE_NO_GNU_OPS))
token->type = OP_NOTSPACE;
break;
case '`':
if (!(syntax & REG_NO_GNU_OPS))
if (!(syntax & RE_NO_GNU_OPS))
{
token->type = ANCHOR;
token->opr.ctx_type = BUF_FIRST;
}
break;
case '\'':
if (!(syntax & REG_NO_GNU_OPS))
if (!(syntax & RE_NO_GNU_OPS))
{
token->type = ANCHOR;
token->opr.ctx_type = BUF_LAST;
}
break;
case '(':
if (!(syntax & REG_NO_BK_PARENS))
if (!(syntax & RE_NO_BK_PARENS))
token->type = OP_OPEN_SUBEXP;
break;
case ')':
if (!(syntax & REG_NO_BK_PARENS))
if (!(syntax & RE_NO_BK_PARENS))
token->type = OP_CLOSE_SUBEXP;
break;
case '+':
if (!(syntax & REG_LIMITED_OPS) && (syntax & REG_BK_PLUS_QM))
if (!(syntax & RE_LIMITED_OPS) && (syntax & RE_BK_PLUS_QM))
token->type = OP_DUP_PLUS;
break;
case '?':
if (!(syntax & REG_LIMITED_OPS) && (syntax & REG_BK_PLUS_QM))
if (!(syntax & RE_LIMITED_OPS) && (syntax & RE_BK_PLUS_QM))
token->type = OP_DUP_QUESTION;
break;
case '{':
if ((syntax & REG_INTERVALS) && (!(syntax & REG_NO_BK_BRACES)))
if ((syntax & RE_INTERVALS) && (!(syntax & RE_NO_BK_BRACES)))
token->type = OP_OPEN_DUP_NUM;
break;
case '}':
if ((syntax & REG_INTERVALS) && (!(syntax & REG_NO_BK_BRACES)))
if ((syntax & RE_INTERVALS) && (!(syntax & RE_NO_BK_BRACES)))
token->type = OP_CLOSE_DUP_NUM;
break;
default:
......@@ -1883,38 +1927,38 @@ peek_token (re_token_t *token, re_string_t *input, reg_syntax_t syntax)
switch (c)
{
case '\n':
if (syntax & REG_NEWLINE_ALT)
if (syntax & RE_NEWLINE_ALT)
token->type = OP_ALT;
break;
case '|':
if (!(syntax & REG_LIMITED_OPS) && (syntax & REG_NO_BK_VBAR))
if (!(syntax & RE_LIMITED_OPS) && (syntax & RE_NO_BK_VBAR))
token->type = OP_ALT;
break;
case '*':
token->type = OP_DUP_ASTERISK;
break;
case '+':
if (!(syntax & REG_LIMITED_OPS) && !(syntax & REG_BK_PLUS_QM))
if (!(syntax & RE_LIMITED_OPS) && !(syntax & RE_BK_PLUS_QM))
token->type = OP_DUP_PLUS;
break;
case '?':
if (!(syntax & REG_LIMITED_OPS) && !(syntax & REG_BK_PLUS_QM))
if (!(syntax & RE_LIMITED_OPS) && !(syntax & RE_BK_PLUS_QM))
token->type = OP_DUP_QUESTION;
break;
case '{':
if ((syntax & REG_INTERVALS) && (syntax & REG_NO_BK_BRACES))
if ((syntax & RE_INTERVALS) && (syntax & RE_NO_BK_BRACES))
token->type = OP_OPEN_DUP_NUM;
break;
case '}':
if ((syntax & REG_INTERVALS) && (syntax & REG_NO_BK_BRACES))
if ((syntax & RE_INTERVALS) && (syntax & RE_NO_BK_BRACES))
token->type = OP_CLOSE_DUP_NUM;
break;
case '(':
if (syntax & REG_NO_BK_PARENS)
if (syntax & RE_NO_BK_PARENS)
token->type = OP_OPEN_SUBEXP;
break;
case ')':
if (syntax & REG_NO_BK_PARENS)
if (syntax & RE_NO_BK_PARENS)
token->type = OP_CLOSE_SUBEXP;
break;
case '[':
......@@ -1924,18 +1968,18 @@ peek_token (re_token_t *token, re_string_t *input, reg_syntax_t syntax)
token->type = OP_PERIOD;
break;
case '^':
if (!(syntax & (REG_CONTEXT_INDEP_ANCHORS | REG_CARET_ANCHORS_HERE)) &&
if (!(syntax & (RE_CONTEXT_INDEP_ANCHORS | RE_CARET_ANCHORS_HERE)) &&
re_string_cur_idx (input) != 0)
{
char prev = re_string_peek_byte (input, -1);
if (!(syntax & REG_NEWLINE_ALT) || prev != '\n')
if (!(syntax & RE_NEWLINE_ALT) || prev != '\n')
break;
}
token->type = ANCHOR;
token->opr.ctx_type = LINE_FIRST;
break;
case '$':
if (!(syntax & REG_CONTEXT_INDEP_ANCHORS) &&
if (!(syntax & RE_CONTEXT_INDEP_ANCHORS) &&
re_string_cur_idx (input) + 1 != re_string_length (input))
{
re_token_t next;
......@@ -1958,6 +2002,7 @@ peek_token (re_token_t *token, re_string_t *input, reg_syntax_t syntax)
We must not use this function out of bracket expressions. */
static int
internal_function
peek_token_bracket (re_token_t *token, re_string_t *input, reg_syntax_t syntax)
{
unsigned char c;
......@@ -1978,7 +2023,7 @@ peek_token_bracket (re_token_t *token, re_string_t *input, reg_syntax_t syntax)
}
#endif /* RE_ENABLE_I18N */
if (c == '\\' && (syntax & REG_BACKSLASH_ESCAPE_IN_LISTS)
if (c == '\\' && (syntax & RE_BACKSLASH_ESCAPE_IN_LISTS)
&& re_string_cur_idx (input) + 1 < re_string_length (input))
{
/* In this case, '\' escape a character. */
......@@ -2008,7 +2053,7 @@ peek_token_bracket (re_token_t *token, re_string_t *input, reg_syntax_t syntax)
token->type = OP_OPEN_EQUIV_CLASS;
break;
case ':':
if (syntax & REG_CHAR_CLASSES)
if (syntax & RE_CHAR_CLASSES)
{
token->type = OP_OPEN_CHAR_CLASS;
break;
......@@ -2057,11 +2102,11 @@ static bin_tree_t *
parse (re_string_t *regexp, regex_t *preg, reg_syntax_t syntax,
reg_errcode_t *err)
{
re_dfa_t *dfa = (re_dfa_t *) preg->re_buffer;
re_dfa_t *dfa = (re_dfa_t *) preg->buffer;
bin_tree_t *tree, *eor, *root;
re_token_t current_token;
dfa->syntax = syntax;
fetch_token (&current_token, regexp, syntax | REG_CARET_ANCHORS_HERE);
fetch_token (&current_token, regexp, syntax | RE_CARET_ANCHORS_HERE);
tree = parse_reg_exp (regexp, preg, &current_token, syntax, 0, err);
if (BE (*err != REG_NOERROR && tree == NULL, 0))
return NULL;
......@@ -2091,7 +2136,7 @@ static bin_tree_t *
parse_reg_exp (re_string_t *regexp, regex_t *preg, re_token_t *token,
reg_syntax_t syntax, Idx nest, reg_errcode_t *err)
{
re_dfa_t *dfa = (re_dfa_t *) preg->re_buffer;
re_dfa_t *dfa = (re_dfa_t *) preg->buffer;
bin_tree_t *tree, *branch = NULL;
tree = parse_branch (regexp, preg, token, syntax, nest, err);
if (BE (*err != REG_NOERROR && tree == NULL, 0))
......@@ -2099,7 +2144,7 @@ parse_reg_exp (re_string_t *regexp, regex_t *preg, re_token_t *token,
while (token->type == OP_ALT)
{
fetch_token (token, regexp, syntax | REG_CARET_ANCHORS_HERE);
fetch_token (token, regexp, syntax | RE_CARET_ANCHORS_HERE);
if (token->type != OP_ALT && token->type != END_OF_RE
&& (nest == 0 || token->type != OP_CLOSE_SUBEXP))
{
......@@ -2133,7 +2178,7 @@ parse_branch (re_string_t *regexp, regex_t *preg, re_token_t *token,
reg_syntax_t syntax, Idx nest, reg_errcode_t *err)
{
bin_tree_t *tree, *exp;
re_dfa_t *dfa = (re_dfa_t *) preg->re_buffer;
re_dfa_t *dfa = (re_dfa_t *) preg->buffer;
tree = parse_expression (regexp, preg, token, syntax, nest, err);
if (BE (*err != REG_NOERROR && tree == NULL, 0))
return NULL;
......@@ -2172,7 +2217,7 @@ static bin_tree_t *
parse_expression (re_string_t *regexp, regex_t *preg, re_token_t *token,
reg_syntax_t syntax, Idx nest, reg_errcode_t *err)
{
re_dfa_t *dfa = (re_dfa_t *) preg->re_buffer;
re_dfa_t *dfa = (re_dfa_t *) preg->buffer;
bin_tree_t *tree;
switch (token->type)
{
......@@ -2229,7 +2274,7 @@ parse_expression (re_string_t *regexp, regex_t *preg, re_token_t *token,
dfa->has_mb_node = 1;
break;
case OP_OPEN_DUP_NUM:
if (syntax & REG_CONTEXT_INVALID_DUP)
if (syntax & RE_CONTEXT_INVALID_DUP)
{
*err = REG_BADRPT;
return NULL;
......@@ -2238,12 +2283,12 @@ parse_expression (re_string_t *regexp, regex_t *preg, re_token_t *token,
case OP_DUP_ASTERISK:
case OP_DUP_PLUS:
case OP_DUP_QUESTION:
if (syntax & REG_CONTEXT_INVALID_OPS)
if (syntax & RE_CONTEXT_INVALID_OPS)
{
*err = REG_BADRPT;
return NULL;
}
else if (syntax & REG_CONTEXT_INDEP_OPS)
else if (syntax & RE_CONTEXT_INDEP_OPS)
{
fetch_token (token, regexp, syntax);
return parse_expression (regexp, preg, token, syntax, nest, err);
......@@ -2251,7 +2296,7 @@ parse_expression (re_string_t *regexp, regex_t *preg, re_token_t *token,
/* else fall through */
case OP_CLOSE_SUBEXP:
if ((token->type == OP_CLOSE_SUBEXP) &&
!(syntax & REG_UNMATCHED_RIGHT_PAREN_ORD))
!(syntax & RE_UNMATCHED_RIGHT_PAREN_ORD))
{
*err = REG_ERPAREN;
return NULL;
......@@ -2365,7 +2410,7 @@ parse_expression (re_string_t *regexp, regex_t *preg, re_token_t *token,
if (BE (*err != REG_NOERROR && tree == NULL, 0))
return NULL;
/* In BRE consecutive duplications are not allowed. */
if ((syntax & REG_CONTEXT_INVALID_DUP)
if ((syntax & RE_CONTEXT_INVALID_DUP)
&& (token->type == OP_DUP_ASTERISK
|| token->type == OP_OPEN_DUP_NUM))
{
......@@ -2388,12 +2433,12 @@ static bin_tree_t *
parse_sub_exp (re_string_t *regexp, regex_t *preg, re_token_t *token,
reg_syntax_t syntax, Idx nest, reg_errcode_t *err)
{
re_dfa_t *dfa = (re_dfa_t *) preg->re_buffer;
re_dfa_t *dfa = (re_dfa_t *) preg->buffer;
bin_tree_t *tree;
size_t cur_nsub;
cur_nsub = preg->re_nsub++;
fetch_token (token, regexp, syntax | REG_CARET_ANCHORS_HERE);
fetch_token (token, regexp, syntax | RE_CARET_ANCHORS_HERE);
/* The subexpression may be a null string. */
if (token->type == OP_CLOSE_SUBEXP)
......@@ -2454,7 +2499,7 @@ parse_dup_op (bin_tree_t *elem, re_string_t *regexp, re_dfa_t *dfa,
if (BE (start == REG_ERROR || end == REG_ERROR, 0))
{
/* Invalid sequence. */
if (BE (!(syntax & REG_INVALID_INTERVAL_ORD), 0))
if (BE (!(syntax & RE_INVALID_INTERVAL_ORD), 0))
{
if (token->type == END_OF_RE)
*err = REG_EBRACE;
......@@ -2565,11 +2610,14 @@ parse_dup_op (bin_tree_t *elem, re_string_t *regexp, re_dfa_t *dfa,
update it. */
static reg_errcode_t
build_range_exp (bitset sbcset,
internal_function
# ifdef RE_ENABLE_I18N
re_charset_t *mbcset, Idx *range_alloc,
# endif
build_range_exp (bitset_t sbcset, re_charset_t *mbcset, Idx *range_alloc,
bracket_elem_t *start_elem, bracket_elem_t *end_elem)
# else /* not RE_ENABLE_I18N */
build_range_exp (bitset_t sbcset, bracket_elem_t *start_elem,
bracket_elem_t *end_elem)
# endif /* not RE_ENABLE_I18N */
{
unsigned int start_ch, end_ch;
/* Equivalence Classes and Character Classes can't be a range start/end. */
......@@ -2589,7 +2637,8 @@ build_range_exp (bitset sbcset,
# ifdef RE_ENABLE_I18N
{
wchar_t wc;
wint_t start_wc, end_wc;
wint_t start_wc;
wint_t end_wc;
wchar_t cmp_buf[6] = {L'\0', L'\0', L'\0', L'\0', L'\0', L'\0'};
start_ch = ((start_elem->type == SB_CHAR) ? start_elem->opr.ch
......@@ -2623,11 +2672,12 @@ build_range_exp (bitset sbcset,
wchar_t *new_array_start, *new_array_end;
Idx new_nranges;
new_nranges = mbcset->nranges;
/* +1 in case of mbcset->nranges is 0. */
new_nranges = 2 * mbcset->nranges + 1;
/* Use realloc since mbcset->range_starts and mbcset->range_ends
are NULL if *range_alloc == 0. */
new_array_start = re_x2realloc (mbcset->range_starts, wchar_t,
&new_nranges);
new_array_start = re_realloc (mbcset->range_starts, wchar_t,
new_nranges);
new_array_end = re_realloc (mbcset->range_ends, wchar_t,
new_nranges);
......@@ -2681,7 +2731,8 @@ build_range_exp (bitset sbcset,
pointer argument since we may update it. */
static reg_errcode_t
build_collating_symbol (bitset sbcset,
internal_function
build_collating_symbol (bitset_t sbcset,
# ifdef RE_ENABLE_I18N
re_charset_t *mbcset, Idx *coll_sym_alloc,
# endif
......@@ -2719,27 +2770,34 @@ parse_bracket_exp (re_string_t *regexp, re_dfa_t *dfa, re_token_t *token,
auto inline int32_t
__attribute ((always_inline))
seek_collating_symbol_entry (const unsigned char *name, size_t name_len)
seek_collating_symbol_entry (name, name_len)
const unsigned char *name;
size_t name_len;
{
int32_t hash = elem_hash ((const char *) name, name_len);
int32_t elem = hash % table_size;
int32_t second = hash % (table_size - 2);
while (symb_table[2 * elem] != 0)
{
/* First compare the hashing value. */
if (symb_table[2 * elem] == hash
/* Compare the length of the name. */
&& name_len == extra[symb_table[2 * elem + 1]]
/* Compare the name. */
&& memcmp (name, &extra[symb_table[2 * elem + 1] + 1],
name_len) == 0)
if (symb_table[2 * elem] != 0)
{
int32_t second = hash % (table_size - 2) + 1;
do
{
/* Yep, this is the entry. */
break;
}
/* First compare the hashing value. */
if (symb_table[2 * elem] == hash
/* Compare the length of the name. */
&& name_len == extra[symb_table[2 * elem + 1]]
/* Compare the name. */
&& memcmp (name, &extra[symb_table[2 * elem + 1] + 1],
name_len) == 0)
{
/* Yep, this is the entry. */
break;
}
/* Next entry. */
elem += second;
/* Next entry. */
elem += second;
}
while (symb_table[2 * elem] != 0);
}
return elem;
}
......@@ -2750,7 +2808,8 @@ parse_bracket_exp (re_string_t *regexp, re_dfa_t *dfa, re_token_t *token,
auto inline unsigned int
__attribute ((always_inline))
lookup_collation_sequence_value (bracket_elem_t *br_elem)
lookup_collation_sequence_value (br_elem)
bracket_elem_t *br_elem;
{
if (br_elem->type == SB_CHAR)
{
......@@ -2817,9 +2876,11 @@ parse_bracket_exp (re_string_t *regexp, re_dfa_t *dfa, re_token_t *token,
auto inline reg_errcode_t
__attribute ((always_inline))
build_range_exp (bitset sbcset, re_charset_t *mbcset,
Idx *range_alloc,
bracket_elem_t *start_elem, bracket_elem_t *end_elem)
build_range_exp (sbcset, mbcset, range_alloc, start_elem, end_elem)
re_charset_t *mbcset;
Idx *range_alloc;
bitset_t sbcset;
bracket_elem_t *start_elem, *end_elem;
{
unsigned int ch;
uint32_t start_collseq;
......@@ -2837,7 +2898,7 @@ parse_bracket_exp (re_string_t *regexp, re_dfa_t *dfa, re_token_t *token,
/* Check start/end collation sequence values. */
if (BE (start_collseq == UINT_MAX || end_collseq == UINT_MAX, 0))
return REG_ECOLLATE;
if (BE ((syntax & REG_NO_EMPTY_RANGES) && start_collseq > end_collseq, 0))
if (BE ((syntax & RE_NO_EMPTY_RANGES) && start_collseq > end_collseq, 0))
return REG_ERANGE;
/* Got valid collation sequence values, add them as a new entry.
......@@ -2854,9 +2915,10 @@ parse_bracket_exp (re_string_t *regexp, re_dfa_t *dfa, re_token_t *token,
uint32_t *new_array_end;
Idx new_nranges;
new_nranges = mbcset->nranges;
new_array_start = re_x2realloc (mbcset->range_starts, uint32_t,
&new_nranges);
/* +1 in case of mbcset->nranges is 0. */
new_nranges = 2 * mbcset->nranges + 1;
new_array_start = re_realloc (mbcset->range_starts, uint32_t,
new_nranges);
new_array_end = re_realloc (mbcset->range_ends, uint32_t,
new_nranges);
......@@ -2897,8 +2959,11 @@ parse_bracket_exp (re_string_t *regexp, re_dfa_t *dfa, re_token_t *token,
auto inline reg_errcode_t
__attribute ((always_inline))
build_collating_symbol (bitset sbcset, re_charset_t *mbcset,
Idx *coll_sym_alloc, const unsigned char *name)
build_collating_symbol (sbcset, mbcset, coll_sym_alloc, name)
re_charset_t *mbcset;
Idx *coll_sym_alloc;
bitset_t sbcset;
const unsigned char *name;
{
int32_t elem, idx;
size_t name_len = strlen ((const char *) name);
......@@ -2927,11 +2992,12 @@ parse_bracket_exp (re_string_t *regexp, re_dfa_t *dfa, re_token_t *token,
if (BE (*coll_sym_alloc == mbcset->ncoll_syms, 0))
{
/* Not enough, realloc it. */
Idx new_coll_sym_alloc = mbcset->ncoll_syms;
/* +1 in case of mbcset->ncoll_syms is 0. */
Idx new_coll_sym_alloc = 2 * mbcset->ncoll_syms + 1;
/* Use realloc since mbcset->coll_syms is NULL
if *alloc == 0. */
int32_t *new_coll_syms = re_x2realloc (mbcset->coll_syms, int32_t,
&new_coll_sym_alloc);
int32_t *new_coll_syms = re_realloc (mbcset->coll_syms, int32_t,
new_coll_sym_alloc);
if (BE (new_coll_syms == NULL, 0))
return REG_ESPACE;
mbcset->coll_syms = new_coll_syms;
......@@ -2973,7 +3039,7 @@ parse_bracket_exp (re_string_t *regexp, re_dfa_t *dfa, re_token_t *token,
/*
if (MB_CUR_MAX > 1)
*/
collseqwc = _NL_CURRENT (LC_COLLATE, _NL_COLLATE_COLLSEQWC);
collseqwc = _NL_CURRENT (LC_COLLATE, _NL_COLLATE_COLLSEQWC);
table_size = _NL_CURRENT_WORD (LC_COLLATE, _NL_COLLATE_SYMB_HASH_SIZEMB);
symb_table = (const int32_t *) _NL_CURRENT (LC_COLLATE,
_NL_COLLATE_SYMB_TABLEMB);
......@@ -2981,9 +3047,9 @@ parse_bracket_exp (re_string_t *regexp, re_dfa_t *dfa, re_token_t *token,
_NL_COLLATE_SYMB_EXTRAMB);
}
#endif
sbcset = re_calloc (bitset_word, BITSET_WORDS);
sbcset = (re_bitset_ptr_t) calloc (sizeof (bitset_t), 1);
#ifdef RE_ENABLE_I18N
mbcset = re_calloc (re_charset_t, 1);
mbcset = (re_charset_t *) calloc (sizeof (re_charset_t), 1);
#endif /* RE_ENABLE_I18N */
#ifdef RE_ENABLE_I18N
if (BE (sbcset == NULL || mbcset == NULL, 0))
......@@ -3007,7 +3073,7 @@ parse_bracket_exp (re_string_t *regexp, re_dfa_t *dfa, re_token_t *token,
mbcset->non_match = 1;
#endif /* not RE_ENABLE_I18N */
non_match = true;
if (syntax & REG_HAT_LISTS_NOT_NEWLINE)
if (syntax & RE_HAT_LISTS_NOT_NEWLINE)
bitset_set (sbcset, '\0');
re_string_skip_bytes (regexp, token_len); /* Skip a token. */
token_len = peek_token_bracket (token, regexp, syntax);
......@@ -3115,10 +3181,11 @@ parse_bracket_exp (re_string_t *regexp, re_dfa_t *dfa, re_token_t *token,
{
wchar_t *new_mbchars;
/* Not enough, realloc it. */
mbchar_alloc = mbcset->nmbchars;
/* +1 in case of mbcset->nmbchars is 0. */
mbchar_alloc = 2 * mbcset->nmbchars + 1;
/* Use realloc since array is NULL if *alloc == 0. */
new_mbchars = re_x2realloc (mbcset->mbchars, wchar_t,
&mbchar_alloc);
new_mbchars = re_realloc (mbcset->mbchars, wchar_t,
mbchar_alloc);
if (BE (new_mbchars == NULL, 0))
goto parse_bracket_exp_espace;
mbcset->mbchars = new_mbchars;
......@@ -3331,13 +3398,14 @@ parse_bracket_symbol (bracket_elem_t *elem, re_string_t *regexp,
is a pointer argument sinse we may update it. */
static reg_errcode_t
build_equiv_class (bitset sbcset,
#ifdef RE_ENABLE_I18N
re_charset_t *mbcset, Idx *equiv_class_alloc,
#endif
const unsigned char *name)
build_equiv_class (bitset_t sbcset, re_charset_t *mbcset,
Idx *equiv_class_alloc, const unsigned char *name)
#else /* not RE_ENABLE_I18N */
build_equiv_class (bitset_t sbcset, const unsigned char *name)
#endif /* not RE_ENABLE_I18N */
{
#if defined _LIBC
#ifdef _LIBC
uint32_t nrules = _NL_CURRENT_WORD (LC_COLLATE, _NL_COLLATE_NRULES);
if (nrules != 0)
{
......@@ -3392,11 +3460,12 @@ build_equiv_class (bitset sbcset,
if (BE (*equiv_class_alloc == mbcset->nequiv_classes, 0))
{
/* Not enough, realloc it. */
Idx new_equiv_class_alloc = mbcset->nequiv_classes;
/* +1 in case of mbcset->nequiv_classes is 0. */
Idx new_equiv_class_alloc = 2 * mbcset->nequiv_classes + 1;
/* Use realloc since the array is NULL if *alloc == 0. */
int32_t *new_equiv_classes = re_x2realloc (mbcset->equiv_classes,
int32_t,
&new_equiv_class_alloc);
int32_t *new_equiv_classes = re_realloc (mbcset->equiv_classes,
int32_t,
new_equiv_class_alloc);
if (BE (new_equiv_classes == NULL, 0))
return REG_ESPACE;
mbcset->equiv_classes = new_equiv_classes;
......@@ -3421,18 +3490,21 @@ build_equiv_class (bitset sbcset,
is a pointer argument sinse we may update it. */
static reg_errcode_t
build_charclass (unsigned REG_TRANSLATE_TYPE trans, bitset sbcset,
#ifdef RE_ENABLE_I18N
build_charclass (RE_TRANSLATE_TYPE trans, bitset_t sbcset,
re_charset_t *mbcset, Idx *char_class_alloc,
#endif
const unsigned char *class_name, reg_syntax_t syntax)
#else /* not RE_ENABLE_I18N */
build_charclass (RE_TRANSLATE_TYPE trans, bitset_t sbcset,
const unsigned char *class_name, reg_syntax_t syntax)
#endif /* not RE_ENABLE_I18N */
{
int i;
const char *name = (const char *) class_name;
/* In case of REG_ICASE "upper" and "lower" match the both of
upper and lower cases. */
if ((syntax & REG_IGNORE_CASE)
if ((syntax & RE_ICASE)
&& (strcmp (name, "upper") == 0 || strcmp (name, "lower") == 0))
name = "alpha";
......@@ -3441,10 +3513,11 @@ build_charclass (unsigned REG_TRANSLATE_TYPE trans, bitset sbcset,
if (BE (*char_class_alloc == mbcset->nchar_classes, 0))
{
/* Not enough, realloc it. */
Idx new_char_class_alloc = mbcset->nchar_classes;
/* +1 in case of mbcset->nchar_classes is 0. */
Idx new_char_class_alloc = 2 * mbcset->nchar_classes + 1;
/* Use realloc since array is NULL if *alloc == 0. */
wctype_t *new_char_classes = re_x2realloc (mbcset->char_classes, wctype_t,
&new_char_class_alloc);
wctype_t *new_char_classes = re_realloc (mbcset->char_classes, wctype_t,
new_char_class_alloc);
if (BE (new_char_classes == NULL, 0))
return REG_ESPACE;
mbcset->char_classes = new_char_classes;
......@@ -3454,39 +3527,45 @@ build_charclass (unsigned REG_TRANSLATE_TYPE trans, bitset sbcset,
#endif /* RE_ENABLE_I18N */
#define BUILD_CHARCLASS_LOOP(ctype_func) \
for (i = 0; i < SBC_MAX; ++i) \
do { \
if (BE (trans != NULL, 0)) \
{ \
if (ctype_func (i)) \
{ \
int ch = trans ? trans[i] : i; \
bitset_set (sbcset, ch); \
} \
}
for (i = 0; i < SBC_MAX; ++i) \
if (ctype_func (i)) \
bitset_set (sbcset, trans[i]); \
} \
else \
{ \
for (i = 0; i < SBC_MAX; ++i) \
if (ctype_func (i)) \
bitset_set (sbcset, i); \
} \
} while (0)
if (strcmp (name, "alnum") == 0)
BUILD_CHARCLASS_LOOP (isalnum)
BUILD_CHARCLASS_LOOP (isalnum);
else if (strcmp (name, "cntrl") == 0)
BUILD_CHARCLASS_LOOP (iscntrl)
BUILD_CHARCLASS_LOOP (iscntrl);
else if (strcmp (name, "lower") == 0)
BUILD_CHARCLASS_LOOP (islower)
BUILD_CHARCLASS_LOOP (islower);
else if (strcmp (name, "space") == 0)
BUILD_CHARCLASS_LOOP (isspace)
BUILD_CHARCLASS_LOOP (isspace);
else if (strcmp (name, "alpha") == 0)
BUILD_CHARCLASS_LOOP (isalpha)
BUILD_CHARCLASS_LOOP (isalpha);
else if (strcmp (name, "digit") == 0)
BUILD_CHARCLASS_LOOP (isdigit)
BUILD_CHARCLASS_LOOP (isdigit);
else if (strcmp (name, "print") == 0)
BUILD_CHARCLASS_LOOP (isprint)
BUILD_CHARCLASS_LOOP (isprint);
else if (strcmp (name, "upper") == 0)
BUILD_CHARCLASS_LOOP (isupper)
BUILD_CHARCLASS_LOOP (isupper);
else if (strcmp (name, "blank") == 0)
BUILD_CHARCLASS_LOOP (isblank)
BUILD_CHARCLASS_LOOP (isblank);
else if (strcmp (name, "graph") == 0)
BUILD_CHARCLASS_LOOP (isgraph)
BUILD_CHARCLASS_LOOP (isgraph);
else if (strcmp (name, "punct") == 0)
BUILD_CHARCLASS_LOOP (ispunct)
BUILD_CHARCLASS_LOOP (ispunct);
else if (strcmp (name, "xdigit") == 0)
BUILD_CHARCLASS_LOOP (isxdigit)
BUILD_CHARCLASS_LOOP (isxdigit);
else
return REG_ECTYPE;
......@@ -3494,10 +3573,10 @@ build_charclass (unsigned REG_TRANSLATE_TYPE trans, bitset sbcset,
}
static bin_tree_t *
build_charclass_op (re_dfa_t *dfa, unsigned REG_TRANSLATE_TYPE trans,
build_charclass_op (re_dfa_t *dfa, RE_TRANSLATE_TYPE trans,
const unsigned char *class_name,
const unsigned char *extra,
bool non_match, reg_errcode_t *err)
const unsigned char *extra, bool non_match,
reg_errcode_t *err)
{
re_bitset_ptr_t sbcset;
#ifdef RE_ENABLE_I18N
......@@ -3508,9 +3587,9 @@ build_charclass_op (re_dfa_t *dfa, unsigned REG_TRANSLATE_TYPE trans,
re_token_t br_token;
bin_tree_t *tree;
sbcset = re_calloc (bitset_word, BITSET_WORDS);
sbcset = (re_bitset_ptr_t) calloc (sizeof (bitset_t), 1);
#ifdef RE_ENABLE_I18N
mbcset = re_calloc (re_charset_t, 1);
mbcset = (re_charset_t *) calloc (sizeof (re_charset_t), 1);
#endif /* RE_ENABLE_I18N */
#ifdef RE_ENABLE_I18N
......@@ -3527,7 +3606,7 @@ build_charclass_op (re_dfa_t *dfa, unsigned REG_TRANSLATE_TYPE trans,
{
#ifdef RE_ENABLE_I18N
/*
if (syntax & REG_HAT_LISTS_NOT_NEWLINE)
if (syntax & RE_HAT_LISTS_NOT_NEWLINE)
bitset_set(cset->sbcset, '\0');
*/
mbcset->non_match = 1;
......@@ -3627,7 +3706,7 @@ fetch_number (re_string_t *input, re_token_t *token, reg_syntax_t syntax)
|| num == REG_ERROR)
? REG_ERROR
: ((num == REG_MISSING) ? c - '0' : num * 10 + c - '0'));
num = (num > REG_DUP_MAX) ? REG_ERROR : num;
num = (num > RE_DUP_MAX) ? REG_ERROR : num;
}
return num;
}
......
/* Extended regular expression matching and search library.
Copyright (C) 2002, 2003 Free Software Foundation, Inc.
Copyright (C) 2002, 2003, 2005, 2006 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Isamu Hasegawa <isamu@yamato.ibm.com>.
......@@ -21,6 +21,11 @@
# include <config.h>
#endif
/* Make sure noone compiles this code with a C++ compiler. */
#if defined __cplusplus && defined _LIBC
# error "This is C code, use a C compiler"
#endif
#ifdef _LIBC
/* We have to keep the namespace clean. */
# define regfree(preg) __regfree (preg)
......
/* Definitions for data structures and routines for the regular
expression library.
Copyright (C) 1985,1989-93,1995-98,2000,2001,2002,2003,2005
Copyright (C) 1985,1989-93,1995-98,2000,2001,2002,2003,2005,2006
Free Software Foundation, Inc.
This file is part of the GNU C Library.
......@@ -28,16 +28,16 @@
extern "C" {
#endif
/* Define _REGEX_SOURCE to get definitions that are incompatible with
POSIX. */
#if (!defined _REGEX_SOURCE \
&& (defined _GNU_SOURCE \
|| (!defined _POSIX_C_SOURCE && !defined _POSIX_SOURCE \
&& !defined _XOPEN_SOURCE)))
# define _REGEX_SOURCE 1
/* Define __USE_GNU_REGEX to declare GNU extensions that violate the
POSIX name space rules. */
#undef __USE_GNU_REGEX
#if (defined _GNU_SOURCE \
|| (!defined _POSIX_C_SOURCE && !defined _POSIX_SOURCE \
&& !defined _XOPEN_SOURCE))
# define __USE_GNU_REGEX 1
#endif
#if defined _REGEX_SOURCE && defined VMS
#ifdef __VMS
/* VMS doesn't have `size_t' in <sys/types.h>, even though POSIX says it
should be there. */
# include <stddef.h>
......@@ -53,11 +53,13 @@ extern "C" {
/* The type of the offset of a byte within a string.
For historical reasons POSIX 1003.1-2004 requires that regoff_t be
at least as wide as off_t. This is a bit odd (and many common
POSIX platforms set it to the more-sensible ssize_t) but we might
as well conform. We don't know of any hosts where ssize_t is wider
than off_t, so off_t is safe. */
typedef off_t regoff_t;
at least as wide as off_t. However, many common POSIX platforms set
regoff_t to the more-sensible ssize_t and the Open Group has
signalled its intention to change the requirement to be that
regoff_t be at least as wide as ptrdiff_t and ssize_t; see XBD ERN
60 (2005-08-25). We don't know of any hosts where ssize_t or
ptrdiff_t is wider than ssize_t, so ssize_t is safe. */
typedef ssize_t regoff_t;
/* The type of nonnegative object indexes. Traditionally, GNU regex
uses 'int' for these. Code that uses __re_idx_t should work
......@@ -97,20 +99,22 @@ typedef unsigned long int active_reg_t;
add or remove a bit, only one other definition need change. */
typedef unsigned long int reg_syntax_t;
#ifdef __USE_GNU_REGEX
/* If this bit is not set, then \ inside a bracket expression is literal.
If set, then such a \ quotes the following character. */
#define REG_BACKSLASH_ESCAPE_IN_LISTS 1ul
# define RE_BACKSLASH_ESCAPE_IN_LISTS ((unsigned long int) 1)
/* If this bit is not set, then + and ? are operators, and \+ and \? are
literals.
If set, then \+ and \? are operators and + and ? are literals. */
#define REG_BK_PLUS_QM (1ul << 1)
# define RE_BK_PLUS_QM (RE_BACKSLASH_ESCAPE_IN_LISTS << 1)
/* If this bit is set, then character classes are supported. They are:
[:alpha:], [:upper:], [:lower:], [:digit:], [:alnum:], [:xdigit:],
[:space:], [:print:], [:punct:], [:graph:], and [:cntrl:].
If not set, then character classes are not supported. */
#define REG_CHAR_CLASSES (1ul << 2)
# define RE_CHAR_CLASSES (RE_BK_PLUS_QM << 1)
/* If this bit is set, then ^ and $ are always anchors (outside bracket
expressions, of course).
......@@ -120,11 +124,11 @@ typedef unsigned long int reg_syntax_t;
$ is an anchor if it is at the end of a regular expression, or
before a close-group or an alternation operator.
This bit could be (re)combined with REG_CONTEXT_INDEP_OPS, because
This bit could be (re)combined with RE_CONTEXT_INDEP_OPS, because
POSIX draft 11.2 says that * etc. in leading positions is undefined.
We already implemented a previous draft which made those constructs
invalid, though, so we haven't changed the code back. */
#define REG_CONTEXT_INDEP_ANCHORS (1ul << 3)
# define RE_CONTEXT_INDEP_ANCHORS (RE_CHAR_CLASSES << 1)
/* If this bit is set, then special characters are always special
regardless of where they are in the pattern.
......@@ -132,70 +136,71 @@ typedef unsigned long int reg_syntax_t;
some contexts; otherwise they are ordinary. Specifically,
* + ? and intervals are only special when not after the beginning,
open-group, or alternation operator. */
#define REG_CONTEXT_INDEP_OPS (1ul << 4)
# define RE_CONTEXT_INDEP_OPS (RE_CONTEXT_INDEP_ANCHORS << 1)
/* If this bit is set, then *, +, ?, and { cannot be first in an re or
immediately after an alternation or begin-group operator. */
#define REG_CONTEXT_INVALID_OPS (1ul << 5)
# define RE_CONTEXT_INVALID_OPS (RE_CONTEXT_INDEP_OPS << 1)
/* If this bit is set, then . matches newline.
If not set, then it doesn't. */
#define REG_DOT_NEWLINE (1ul << 6)
# define RE_DOT_NEWLINE (RE_CONTEXT_INVALID_OPS << 1)
/* If this bit is set, then . doesn't match NUL.
If not set, then it does. */
#define REG_DOT_NOT_NULL (1ul << 7)
# define RE_DOT_NOT_NULL (RE_DOT_NEWLINE << 1)
/* If this bit is set, nonmatching lists [^...] do not match newline.
If not set, they do. */
#define REG_HAT_LISTS_NOT_NEWLINE (1ul << 8)
# define RE_HAT_LISTS_NOT_NEWLINE (RE_DOT_NOT_NULL << 1)
/* If this bit is set, either \{...\} or {...} defines an
interval, depending on REG_NO_BK_BRACES.
interval, depending on RE_NO_BK_BRACES.
If not set, \{, \}, {, and } are literals. */
#define REG_INTERVALS (1ul << 9)
# define RE_INTERVALS (RE_HAT_LISTS_NOT_NEWLINE << 1)
/* If this bit is set, +, ? and | aren't recognized as operators.
If not set, they are. */
#define REG_LIMITED_OPS (1ul << 10)
# define RE_LIMITED_OPS (RE_INTERVALS << 1)
/* If this bit is set, newline is an alternation operator.
If not set, newline is literal. */
#define REG_NEWLINE_ALT (1ul << 11)
# define RE_NEWLINE_ALT (RE_LIMITED_OPS << 1)
/* If this bit is set, then `{...}' defines an interval, and \{ and \}
are literals.
If not set, then `\{...\}' defines an interval. */
#define REG_NO_BK_BRACES (1ul << 12)
# define RE_NO_BK_BRACES (RE_NEWLINE_ALT << 1)
/* If this bit is set, (...) defines a group, and \( and \) are literals.
If not set, \(...\) defines a group, and ( and ) are literals. */
#define REG_NO_BK_PARENS (1ul << 13)
# define RE_NO_BK_PARENS (RE_NO_BK_BRACES << 1)
/* If this bit is set, then \<digit> matches <digit>.
If not set, then \<digit> is a back-reference. */
#define REG_NO_BK_REFS (1ul << 14)
# define RE_NO_BK_REFS (RE_NO_BK_PARENS << 1)
/* If this bit is set, then | is an alternation operator, and \| is literal.
If not set, then \| is an alternation operator, and | is literal. */
#define REG_NO_BK_VBAR (1ul << 15)
# define RE_NO_BK_VBAR (RE_NO_BK_REFS << 1)
/* If this bit is set, then an ending range point collating higher
than the starting range point, as in [z-a], is invalid.
If not set, the containing range is empty and does not match any string. */
#define REG_NO_EMPTY_RANGES (1ul << 16)
If not set, then when ending range point collates higher than the
starting range point, the range is ignored. */
# define RE_NO_EMPTY_RANGES (RE_NO_BK_VBAR << 1)
/* If this bit is set, then an unmatched ) is ordinary.
If not set, then an unmatched ) is invalid. */
#define REG_UNMATCHED_RIGHT_PAREN_ORD (1ul << 17)
# define RE_UNMATCHED_RIGHT_PAREN_ORD (RE_NO_EMPTY_RANGES << 1)
/* If this bit is set, succeed as soon as we match the whole pattern,
without further backtracking. */
#define REG_NO_POSIX_BACKTRACKING (1ul << 18)
# define RE_NO_POSIX_BACKTRACKING (RE_UNMATCHED_RIGHT_PAREN_ORD << 1)
/* If this bit is set, do not process the GNU regex operators.
If not set, then the GNU regex operators are recognized. */
#define REG_NO_GNU_OPS (1ul << 19)
# define RE_NO_GNU_OPS (RE_NO_POSIX_BACKTRACKING << 1)
/* If this bit is set, turn on internal regex debugging.
If not set, and debugging was on, turn it off.
......@@ -203,29 +208,31 @@ typedef unsigned long int reg_syntax_t;
We define this bit always, so that all that's needed to turn on
debugging is to recompile regex.c; the calling code can always have
this bit set, and it won't affect anything in the normal case. */
#define REG_DEBUG (1ul << 20)
# define RE_DEBUG (RE_NO_GNU_OPS << 1)
/* If this bit is set, a syntactically invalid interval is treated as
a string of ordinary characters. For example, the ERE 'a{1' is
treated as 'a\{1'. */
#define REG_INVALID_INTERVAL_ORD (1ul << 21)
# define RE_INVALID_INTERVAL_ORD (RE_DEBUG << 1)
/* If this bit is set, then ignore case when matching.
If not set, then case is significant. */
#define REG_IGNORE_CASE (1ul << 22)
# define RE_ICASE (RE_INVALID_INTERVAL_ORD << 1)
/* This bit is used internally like REG_CONTEXT_INDEP_ANCHORS but only
/* This bit is used internally like RE_CONTEXT_INDEP_ANCHORS but only
for ^, because it is difficult to scan the regex backwards to find
whether ^ should be special. */
#define REG_CARET_ANCHORS_HERE (1ul << 23)
# define RE_CARET_ANCHORS_HERE (RE_ICASE << 1)
/* If this bit is set, then \{ cannot be first in an bre or
immediately after an alternation or begin-group operator. */
#define REG_CONTEXT_INVALID_DUP (1ul << 24)
# define RE_CONTEXT_INVALID_DUP (RE_CARET_ANCHORS_HERE << 1)
/* If this bit is set, then no_sub will be set to 1 during
re_compile_pattern. */
#define REG_NO_SUB (1ul << 25)
# define RE_NO_SUB (RE_CONTEXT_INVALID_DUP << 1)
#endif /* defined __USE_GNU_REGEX */
/* This global variable defines the particular regexp syntax to use (for
some interfaces). When a regexp is compiled, the syntax used is
......@@ -233,82 +240,99 @@ typedef unsigned long int reg_syntax_t;
already-compiled regexps. */
extern reg_syntax_t re_syntax_options;
#ifdef __USE_GNU_REGEX
/* Define combinations of the above bits for the standard possibilities.
(The [[[ comments delimit what gets put into the Texinfo file, so
don't delete them!) */
/* [[[begin syntaxes]]] */
#define REG_SYNTAX_EMACS 0
#define REG_SYNTAX_AWK \
(REG_BACKSLASH_ESCAPE_IN_LISTS | REG_DOT_NOT_NULL \
| REG_NO_BK_PARENS | REG_NO_BK_REFS \
| REG_NO_BK_VBAR | REG_NO_EMPTY_RANGES \
| REG_DOT_NEWLINE | REG_CONTEXT_INDEP_ANCHORS \
| REG_UNMATCHED_RIGHT_PAREN_ORD | REG_NO_GNU_OPS)
#define REG_SYNTAX_GNU_AWK \
((REG_SYNTAX_POSIX_EXTENDED | REG_BACKSLASH_ESCAPE_IN_LISTS \
| REG_DEBUG) \
& ~(REG_DOT_NOT_NULL | REG_INTERVALS | REG_CONTEXT_INDEP_OPS \
| REG_CONTEXT_INVALID_OPS ))
#define REG_SYNTAX_POSIX_AWK \
(REG_SYNTAX_POSIX_EXTENDED | REG_BACKSLASH_ESCAPE_IN_LISTS \
| REG_INTERVALS | REG_NO_GNU_OPS)
#define REG_SYNTAX_GREP \
(REG_BK_PLUS_QM | REG_CHAR_CLASSES \
| REG_HAT_LISTS_NOT_NEWLINE | REG_INTERVALS \
| REG_NEWLINE_ALT)
#define REG_SYNTAX_EGREP \
(REG_CHAR_CLASSES | REG_CONTEXT_INDEP_ANCHORS \
| REG_CONTEXT_INDEP_OPS | REG_HAT_LISTS_NOT_NEWLINE \
| REG_NEWLINE_ALT | REG_NO_BK_PARENS \
| REG_NO_BK_VBAR)
#define REG_SYNTAX_POSIX_EGREP \
(REG_SYNTAX_EGREP | REG_INTERVALS | REG_NO_BK_BRACES \
| REG_INVALID_INTERVAL_ORD)
# define RE_SYNTAX_EMACS 0
# define RE_SYNTAX_AWK \
(RE_BACKSLASH_ESCAPE_IN_LISTS | RE_DOT_NOT_NULL \
| RE_NO_BK_PARENS | RE_NO_BK_REFS \
| RE_NO_BK_VBAR | RE_NO_EMPTY_RANGES \
| RE_DOT_NEWLINE | RE_CONTEXT_INDEP_ANCHORS \
| RE_UNMATCHED_RIGHT_PAREN_ORD | RE_NO_GNU_OPS)
# define RE_SYNTAX_GNU_AWK \
((RE_SYNTAX_POSIX_EXTENDED | RE_BACKSLASH_ESCAPE_IN_LISTS | RE_DEBUG) \
& ~(RE_DOT_NOT_NULL | RE_INTERVALS | RE_CONTEXT_INDEP_OPS \
| RE_CONTEXT_INVALID_OPS ))
# define RE_SYNTAX_POSIX_AWK \
(RE_SYNTAX_POSIX_EXTENDED | RE_BACKSLASH_ESCAPE_IN_LISTS \
| RE_INTERVALS | RE_NO_GNU_OPS)
# define RE_SYNTAX_GREP \
(RE_BK_PLUS_QM | RE_CHAR_CLASSES \
| RE_HAT_LISTS_NOT_NEWLINE | RE_INTERVALS \
| RE_NEWLINE_ALT)
# define RE_SYNTAX_EGREP \
(RE_CHAR_CLASSES | RE_CONTEXT_INDEP_ANCHORS \
| RE_CONTEXT_INDEP_OPS | RE_HAT_LISTS_NOT_NEWLINE \
| RE_NEWLINE_ALT | RE_NO_BK_PARENS \
| RE_NO_BK_VBAR)
# define RE_SYNTAX_POSIX_EGREP \
(RE_SYNTAX_EGREP | RE_INTERVALS | RE_NO_BK_BRACES \
| RE_INVALID_INTERVAL_ORD)
/* P1003.2/D11.2, section 4.20.7.1, lines 5078ff. */
#define REG_SYNTAX_ED REG_SYNTAX_POSIX_BASIC
# define RE_SYNTAX_ED RE_SYNTAX_POSIX_BASIC
#define REG_SYNTAX_SED REG_SYNTAX_POSIX_BASIC
# define RE_SYNTAX_SED RE_SYNTAX_POSIX_BASIC
/* Syntax bits common to both basic and extended POSIX regex syntax. */
#define _REG_SYNTAX_POSIX_COMMON \
(REG_CHAR_CLASSES | REG_DOT_NEWLINE | REG_DOT_NOT_NULL \
| REG_INTERVALS | REG_NO_EMPTY_RANGES)
# define _RE_SYNTAX_POSIX_COMMON \
(RE_CHAR_CLASSES | RE_DOT_NEWLINE | RE_DOT_NOT_NULL \
| RE_INTERVALS | RE_NO_EMPTY_RANGES)
#define REG_SYNTAX_POSIX_BASIC \
(_REG_SYNTAX_POSIX_COMMON | REG_BK_PLUS_QM | REG_CONTEXT_INVALID_DUP)
# define RE_SYNTAX_POSIX_BASIC \
(_RE_SYNTAX_POSIX_COMMON | RE_BK_PLUS_QM | RE_CONTEXT_INVALID_DUP)
/* Differs from ..._POSIX_BASIC only in that REG_BK_PLUS_QM becomes
REG_LIMITED_OPS, i.e., \? \+ \| are not recognized. Actually, this
/* Differs from ..._POSIX_BASIC only in that RE_BK_PLUS_QM becomes
RE_LIMITED_OPS, i.e., \? \+ \| are not recognized. Actually, this
isn't minimal, since other operators, such as \`, aren't disabled. */
#define REG_SYNTAX_POSIX_MINIMAL_BASIC \
(_REG_SYNTAX_POSIX_COMMON | REG_LIMITED_OPS)
#define REG_SYNTAX_POSIX_EXTENDED \
(_REG_SYNTAX_POSIX_COMMON | REG_CONTEXT_INDEP_ANCHORS \
| REG_CONTEXT_INDEP_OPS | REG_NO_BK_BRACES \
| REG_NO_BK_PARENS | REG_NO_BK_VBAR \
| REG_CONTEXT_INVALID_OPS | REG_UNMATCHED_RIGHT_PAREN_ORD)
/* Differs from ..._POSIX_EXTENDED in that REG_CONTEXT_INDEP_OPS is
removed and REG_NO_BK_REFS is added. */
#define REG_SYNTAX_POSIX_MINIMAL_EXTENDED \
(_REG_SYNTAX_POSIX_COMMON | REG_CONTEXT_INDEP_ANCHORS \
| REG_CONTEXT_INVALID_OPS | REG_NO_BK_BRACES \
| REG_NO_BK_PARENS | REG_NO_BK_REFS \
| REG_NO_BK_VBAR | REG_UNMATCHED_RIGHT_PAREN_ORD)
# define RE_SYNTAX_POSIX_MINIMAL_BASIC \
(_RE_SYNTAX_POSIX_COMMON | RE_LIMITED_OPS)
# define RE_SYNTAX_POSIX_EXTENDED \
(_RE_SYNTAX_POSIX_COMMON | RE_CONTEXT_INDEP_ANCHORS \
| RE_CONTEXT_INDEP_OPS | RE_NO_BK_BRACES \
| RE_NO_BK_PARENS | RE_NO_BK_VBAR \
| RE_CONTEXT_INVALID_OPS | RE_UNMATCHED_RIGHT_PAREN_ORD)
/* Differs from ..._POSIX_EXTENDED in that RE_CONTEXT_INDEP_OPS is
removed and RE_NO_BK_REFS is added. */
# define RE_SYNTAX_POSIX_MINIMAL_EXTENDED \
(_RE_SYNTAX_POSIX_COMMON | RE_CONTEXT_INDEP_ANCHORS \
| RE_CONTEXT_INVALID_OPS | RE_NO_BK_BRACES \
| RE_NO_BK_PARENS | RE_NO_BK_REFS \
| RE_NO_BK_VBAR | RE_UNMATCHED_RIGHT_PAREN_ORD)
/* [[[end syntaxes]]] */
#endif /* defined __USE_GNU_REGEX */
/* Maximum number of duplicates an interval can allow. This is
distinct from RE_DUP_MAX, to conform to POSIX name space rules and
to avoid collisions with <limits.h>. */
#define REG_DUP_MAX 32767
#ifdef __USE_GNU_REGEX
/* Maximum number of duplicates an interval can allow. POSIX-conforming
systems might define this in <limits.h>, but we want our
value, so remove any previous define. */
# ifdef RE_DUP_MAX
# undef RE_DUP_MAX
# endif
/* RE_DUP_MAX is 2**15 - 1 because an earlier implementation stored
the counter as a 2-byte signed integer. This is no longer true, so
RE_DUP_MAX could be increased to (INT_MAX / 10 - 1), or to
((SIZE_MAX - 2) / 10 - 1) if _REGEX_LARGE_OFFSETS is defined.
However, there would be a huge performance problem if someone
actually used a pattern like a\{214748363\}, so RE_DUP_MAX retains
its historical value. */
# define RE_DUP_MAX (0x7fff)
#endif /* defined __USE_GNU_REGEX */
/* POSIX `cflags' bits (i.e., information for `regcomp'). */
......@@ -354,72 +378,55 @@ extern reg_syntax_t re_syntax_options;
typedef enum
{
_REG_ENOSYS = -1, /* This will never happen for this implementation. */
#define REG_ENOSYS _REG_ENOSYS
_REG_NOERROR, /* Success. */
#define REG_NOERROR _REG_NOERROR
_REG_NOERROR = 0, /* Success. */
_REG_NOMATCH, /* Didn't find a match (for regexec). */
#define REG_NOMATCH _REG_NOMATCH
/* POSIX regcomp return error codes. (In the order listed in the
standard.) */
_REG_BADPAT, /* Invalid pattern. */
#define REG_BADPAT _REG_BADPAT
_REG_ECOLLATE, /* Inalid collating element. */
#define REG_ECOLLATE _REG_ECOLLATE
_REG_ECOLLATE, /* Invalid collating element. */
_REG_ECTYPE, /* Invalid character class name. */
#define REG_ECTYPE _REG_ECTYPE
_REG_EESCAPE, /* Trailing backslash. */
#define REG_EESCAPE _REG_EESCAPE
_REG_ESUBREG, /* Invalid back reference. */
#define REG_ESUBREG _REG_ESUBREG
_REG_EBRACK, /* Unmatched left bracket. */
#define REG_EBRACK _REG_EBRACK
_REG_EPAREN, /* Parenthesis imbalance. */
#define REG_EPAREN _REG_EPAREN
_REG_EBRACE, /* Unmatched \{. */
#define REG_EBRACE _REG_EBRACE
_REG_BADBR, /* Invalid contents of \{\}. */
#define REG_BADBR _REG_BADBR
_REG_ERANGE, /* Invalid range end. */
#define REG_ERANGE _REG_ERANGE
_REG_ESPACE, /* Ran out of memory. */
#define REG_ESPACE _REG_ESPACE
_REG_BADRPT, /* No preceding re for repetition op. */
#define REG_BADRPT _REG_BADRPT
/* Error codes we've added. */
_REG_EEND, /* Premature end. */
#define REG_EEND _REG_EEND
_REG_ESIZE, /* Compiled pattern bigger than 2^16 bytes. */
#define REG_ESIZE _REG_ESIZE
_REG_ERPAREN /* Unmatched ) or \); not returned from regcomp. */
#define REG_ERPAREN _REG_ERPAREN
} reg_errcode_t;
#ifdef _XOPEN_SOURCE
# define REG_ENOSYS _REG_ENOSYS
#endif
#define REG_NOERROR _REG_NOERROR
#define REG_NOMATCH _REG_NOMATCH
#define REG_BADPAT _REG_BADPAT
#define REG_ECOLLATE _REG_ECOLLATE
#define REG_ECTYPE _REG_ECTYPE
#define REG_EESCAPE _REG_EESCAPE
#define REG_ESUBREG _REG_ESUBREG
#define REG_EBRACK _REG_EBRACK
#define REG_EPAREN _REG_EPAREN
#define REG_EBRACE _REG_EBRACE
#define REG_BADBR _REG_BADBR
#define REG_ERANGE _REG_ERANGE
#define REG_ESPACE _REG_ESPACE
#define REG_BADRPT _REG_BADRPT
#define REG_EEND _REG_EEND
#define REG_ESIZE _REG_ESIZE
#define REG_ERPAREN _REG_ERPAREN
/* In the traditional GNU implementation, regex.h defined member names
like `buffer' that POSIX does not allow. These members now have
names with leading `re_' (e.g., `re_buffer'). Support the old
names only if _REGEX_SOURCE is defined. New programs should use
the new names. */
#ifdef _REGEX_SOURCE
/* struct re_pattern_buffer normally uses member names like `buffer'
that POSIX does not allow. In POSIX mode these members have names
with leading `re_' (e.g., `re_buffer'). */
#ifdef __USE_GNU_REGEX
# define _REG_RE_NAME(id) id
# define _REG_RM_NAME(id) id
#else
......@@ -428,88 +435,87 @@ typedef enum
#endif
/* The user can specify the type of the re_translate member by
defining the macro REG_TRANSLATE_TYPE. In the traditional GNU
implementation, this macro was named RE_TRANSLATE_TYPE, but POSIX
does not allow this. Support the old name only if _REGEX_SOURCE
and if the new name is not defined. New programs should use the new
name. */
#ifndef REG_TRANSLATE_TYPE
# if defined _REGEX_SOURCE && defined RE_TRANSLATE_TYPE
# define REG_TRANSLATE_TYPE RE_TRANSLATE_TYPE
# else
# define REG_TRANSLATE_TYPE char *
defining the macro RE_TRANSLATE_TYPE, which defaults to unsigned
char *. This pollutes the POSIX name space, so in POSIX mode just
use unsigned char *. */
#ifdef __USE_GNU_REGEX
# ifndef RE_TRANSLATE_TYPE
# define RE_TRANSLATE_TYPE unsigned char *
# endif
# define REG_TRANSLATE_TYPE RE_TRANSLATE_TYPE
#else
# define REG_TRANSLATE_TYPE unsigned char *
#endif
/* This data structure represents a compiled pattern. Before calling
the pattern compiler), the fields `re_buffer', `re_allocated', `re_fastmap',
`re_translate', and `re_no_sub' can be set. After the pattern has been
the pattern compiler, the fields `buffer', `allocated', `fastmap',
`translate', and `no_sub' can be set. After the pattern has been
compiled, the `re_nsub' field is available. All other fields are
private to the regex routines. */
struct re_pattern_buffer
{
/* [[[begin pattern_buffer]]] */
/* Space that holds the compiled pattern. It is declared as
`unsigned char *' because its elements are
sometimes used as array indexes. */
/* Space that holds the compiled pattern. It is declared as
`unsigned char *' because its elements are sometimes used as
array indexes. */
unsigned char *_REG_RE_NAME (buffer);
/* Number of bytes to which `re_buffer' points. */
/* Number of bytes to which `buffer' points. */
__re_long_size_t _REG_RE_NAME (allocated);
/* Number of bytes actually used in `re_buffer'. */
/* Number of bytes actually used in `buffer'. */
__re_long_size_t _REG_RE_NAME (used);
/* Syntax setting with which the pattern was compiled. */
/* Syntax setting with which the pattern was compiled. */
reg_syntax_t _REG_RE_NAME (syntax);
/* Pointer to a fastmap, if any, otherwise zero. re_search uses
the fastmap, if there is one, to skip over impossible
starting points for matches. */
/* Pointer to a fastmap, if any, otherwise zero. re_search uses the
fastmap, if there is one, to skip over impossible starting points
for matches. */
char *_REG_RE_NAME (fastmap);
/* Either a translate table to apply to all characters before
comparing them, or zero for no translation. The translation
is applied to a pattern when it is compiled and to a string
when it is matched. */
/* Either a translate table to apply to all characters before
comparing them, or zero for no translation. The translation is
applied to a pattern when it is compiled and to a string when it
is matched. */
REG_TRANSLATE_TYPE _REG_RE_NAME (translate);
/* Number of subexpressions found by the compiler. */
/* Number of subexpressions found by the compiler. */
size_t re_nsub;
/* Zero if this pattern cannot match the empty string, one else.
Well, in truth it's used only in `re_search_2', to see
whether or not we should use the fastmap, so we don't set
this absolutely perfectly; see `re_compile_fastmap' (the
`duplicate' case). */
/* Zero if this pattern cannot match the empty string, one else.
Well, in truth it's used only in `re_search_2', to see whether or
not we should use the fastmap, so we don't set this absolutely
perfectly; see `re_compile_fastmap' (the `duplicate' case). */
unsigned int _REG_RE_NAME (can_be_null) : 1;
/* If REG_UNALLOCATED, allocate space in the `regs' structure
for `max (REG_NREGS, re_nsub + 1)' groups.
If REG_REALLOCATE, reallocate space if necessary.
If REG_FIXED, use what's there. */
#define REG_UNALLOCATED 0
#define REG_REALLOCATE 1
#define REG_FIXED 2
/* If REGS_UNALLOCATED, allocate space in the `regs' structure
for `max (RE_NREGS, re_nsub + 1)' groups.
If REGS_REALLOCATE, reallocate space if necessary.
If REGS_FIXED, use what's there. */
#ifdef __USE_GNU_REGEX
# define REGS_UNALLOCATED 0
# define REGS_REALLOCATE 1
# define REGS_FIXED 2
#endif
unsigned int _REG_RE_NAME (regs_allocated) : 2;
/* Set to zero when `regex_compile' compiles a pattern; set to one
by `re_compile_fastmap' if it updates the fastmap. */
/* Set to zero when `regex_compile' compiles a pattern; set to one
by `re_compile_fastmap' if it updates the fastmap. */
unsigned int _REG_RE_NAME (fastmap_accurate) : 1;
/* If set, `re_match_2' does not return information about
subexpressions. */
/* If set, `re_match_2' does not return information about
subexpressions. */
unsigned int _REG_RE_NAME (no_sub) : 1;
/* If set, a beginning-of-line anchor doesn't match at the
beginning of the string. */
/* If set, a beginning-of-line anchor doesn't match at the beginning
of the string. */
unsigned int _REG_RE_NAME (not_bol) : 1;
/* Similarly for an end-of-line anchor. */
/* Similarly for an end-of-line anchor. */
unsigned int _REG_RE_NAME (not_eol) : 1;
/* If true, an anchor at a newline matches. */
/* If true, an anchor at a newline matches. */
unsigned int _REG_RE_NAME (newline_anchor) : 1;
/* [[[end pattern_buffer]]] */
......@@ -527,11 +533,11 @@ struct re_registers
};
/* If `regs_allocated' is REG_UNALLOCATED in the pattern buffer,
/* If `regs_allocated' is REGS_UNALLOCATED in the pattern buffer,
`re_match_2' returns information about at least this many registers
the first time a `regs' structure is passed. */
#ifndef REG_NREGS
# define REG_NREGS 30
#if !defined RE_NREGS && defined __USE_GNU_REGEX
# define RE_NREGS 30
#endif
......@@ -567,7 +573,7 @@ extern int re_compile_fastmap (struct re_pattern_buffer *__buffer);
compiled into BUFFER. Start searching at position START, for RANGE
characters. Return the starting position of the match, -1 for no
match, or -2 for an internal error. Also return register
information in REGS (if REGS and BUFFER->re_no_sub are nonzero). */
information in REGS (if REGS and BUFFER->no_sub are nonzero). */
extern regoff_t re_search (struct re_pattern_buffer *__buffer,
const char *__string, __re_idx_t __length,
__re_idx_t __start, regoff_t __range,
......@@ -660,110 +666,8 @@ extern size_t regerror (int __errcode, const regex_t *__restrict __preg,
extern void regfree (regex_t *__preg);
#ifdef _REGEX_SOURCE
/* Define the POSIX-compatible member names in terms of the
incompatible (and deprecated) names established by _REG_RE_NAME.
New programs should use the re_* names. */
# define re_allocated allocated
# define re_buffer buffer
# define re_can_be_null can_be_null
# define re_fastmap fastmap
# define re_fastmap_accurate fastmap_accurate
# define re_newline_anchor newline_anchor
# define re_no_sub no_sub
# define re_not_bol not_bol
# define re_not_eol not_eol
# define re_regs_allocated regs_allocated
# define re_syntax syntax
# define re_translate translate
# define re_used used
/* Similarly for _REG_RM_NAME. */
# define rm_end end
# define rm_num_regs num_regs
# define rm_start start
/* Undef RE_DUP_MAX first, in case the user has already included a
<limits.h> with an incompatible definition.
On GNU systems, the most common spelling for RE_DUP_MAX's value in
<limits.h> is (0x7ffff), so define RE_DUP_MAX to that, not to
REG_DUP_MAX. This avoid some duplicate-macro-definition warnings
with programs that include <limits.h> after this file.
New programs should not assume that regex.h defines RE_DUP_MAX; to
get the value of RE_DUP_MAX, they should instead include <limits.h>
and possibly invoke the sysconf function. */
# undef RE_DUP_MAX
# define RE_DUP_MAX (0x7fff)
/* Define the following symbols for backward source compatibility.
These symbols violate the POSIX name space rules, and new programs
should avoid them. */
# define REGS_FIXED REG_FIXED
# define REGS_REALLOCATE REG_REALLOCATE
# define REGS_UNALLOCATED REG_UNALLOCATED
# define RE_BACKSLASH_ESCAPE_IN_LISTS REG_BACKSLASH_ESCAPE_IN_LISTS
# define RE_BK_PLUS_QM REG_BK_PLUS_QM
# define RE_CARET_ANCHORS_HERE REG_CARET_ANCHORS_HERE
# define RE_CHAR_CLASSES REG_CHAR_CLASSES
# define RE_CONTEXT_INDEP_ANCHORS REG_CONTEXT_INDEP_ANCHORS
# define RE_CONTEXT_INDEP_OPS REG_CONTEXT_INDEP_OPS
# define RE_CONTEXT_INVALID_DUP REG_CONTEXT_INVALID_DUP
# define RE_CONTEXT_INVALID_OPS REG_CONTEXT_INVALID_OPS
# define RE_DEBUG REG_DEBUG
# define RE_DOT_NEWLINE REG_DOT_NEWLINE
# define RE_DOT_NOT_NULL REG_DOT_NOT_NULL
# define RE_HAT_LISTS_NOT_NEWLINE REG_HAT_LISTS_NOT_NEWLINE
# define RE_ICASE REG_IGNORE_CASE /* avoid collision with REG_ICASE */
# define RE_INTERVALS REG_INTERVALS
# define RE_INVALID_INTERVAL_ORD REG_INVALID_INTERVAL_ORD
# define RE_LIMITED_OPS REG_LIMITED_OPS
# define RE_NEWLINE_ALT REG_NEWLINE_ALT
# define RE_NO_BK_BRACES REG_NO_BK_BRACES
# define RE_NO_BK_PARENS REG_NO_BK_PARENS
# define RE_NO_BK_REFS REG_NO_BK_REFS
# define RE_NO_BK_VBAR REG_NO_BK_VBAR
# define RE_NO_EMPTY_RANGES REG_NO_EMPTY_RANGES
# define RE_NO_GNU_OPS REG_NO_GNU_OPS
# define RE_NO_POSIX_BACKTRACKING REG_NO_POSIX_BACKTRACKING
# define RE_NO_SUB REG_NO_SUB
# define RE_NREGS REG_NREGS
# define RE_SYNTAX_AWK REG_SYNTAX_AWK
# define RE_SYNTAX_ED REG_SYNTAX_ED
# define RE_SYNTAX_EGREP REG_SYNTAX_EGREP
# define RE_SYNTAX_EMACS REG_SYNTAX_EMACS
# define RE_SYNTAX_GNU_AWK REG_SYNTAX_GNU_AWK
# define RE_SYNTAX_GREP REG_SYNTAX_GREP
# define RE_SYNTAX_POSIX_AWK REG_SYNTAX_POSIX_AWK
# define RE_SYNTAX_POSIX_BASIC REG_SYNTAX_POSIX_BASIC
# define RE_SYNTAX_POSIX_EGREP REG_SYNTAX_POSIX_EGREP
# define RE_SYNTAX_POSIX_EXTENDED REG_SYNTAX_POSIX_EXTENDED
# define RE_SYNTAX_POSIX_MINIMAL_BASIC REG_SYNTAX_POSIX_MINIMAL_BASIC
# define RE_SYNTAX_POSIX_MINIMAL_EXTENDED REG_SYNTAX_POSIX_MINIMAL_EXTENDED
# define RE_SYNTAX_SED REG_SYNTAX_SED
# define RE_UNMATCHED_RIGHT_PAREN_ORD REG_UNMATCHED_RIGHT_PAREN_ORD
# ifndef RE_TRANSLATE_TYPE
# define RE_TRANSLATE_TYPE REG_TRANSLATE_TYPE
# endif
#endif /* defined _REGEX_SOURCE */
#ifdef __cplusplus
}
#endif /* C++ */
#endif /* regex.h */
/*
Local variables:
make-backup-files: t
version-control: t
trim-versions-without-asking: nil
End:
*/
......
/* Extended regular expression matching and search library.
Copyright (C) 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
Copyright (C) 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Isamu Hasegawa <isamu@yamato.ibm.com>.
......@@ -19,7 +19,7 @@
static void re_string_construct_common (const char *str, Idx len,
re_string_t *pstr,
REG_TRANSLATE_TYPE trans, bool icase,
RE_TRANSLATE_TYPE trans, bool icase,
const re_dfa_t *dfa) internal_function;
static re_dfastate_t *create_ci_newstate (const re_dfa_t *dfa,
const re_node_set *nodes,
......@@ -37,7 +37,7 @@ static re_dfastate_t *create_cd_newstate (const re_dfa_t *dfa,
static reg_errcode_t
internal_function
re_string_allocate (re_string_t *pstr, const char *str, Idx len, Idx init_len,
REG_TRANSLATE_TYPE trans, bool icase, const re_dfa_t *dfa)
RE_TRANSLATE_TYPE trans, bool icase, const re_dfa_t *dfa)
{
reg_errcode_t ret;
Idx init_buf_len;
......@@ -65,7 +65,7 @@ re_string_allocate (re_string_t *pstr, const char *str, Idx len, Idx init_len,
static reg_errcode_t
internal_function
re_string_construct (re_string_t *pstr, const char *str, Idx len,
REG_TRANSLATE_TYPE trans, bool icase, const re_dfa_t *dfa)
RE_TRANSLATE_TYPE trans, bool icase, const re_dfa_t *dfa)
{
reg_errcode_t ret;
memset (pstr, '\0', sizeof (re_string_t));
......@@ -132,13 +132,20 @@ re_string_realloc_buffers (re_string_t *pstr, Idx new_buf_len)
#ifdef RE_ENABLE_I18N
if (pstr->mb_cur_max > 1)
{
wint_t *new_wcs = re_xrealloc (pstr->wcs, wint_t, new_buf_len);
wint_t *new_wcs;
/* Avoid overflow. */
size_t max_object_size = MAX (sizeof (wint_t), sizeof (Idx));
if (BE (SIZE_MAX / max_object_size < new_buf_len, 0))
return REG_ESPACE;
new_wcs = re_realloc (pstr->wcs, wint_t, new_buf_len);
if (BE (new_wcs == NULL, 0))
return REG_ESPACE;
pstr->wcs = new_wcs;
if (pstr->offsets != NULL)
{
Idx *new_offsets = re_xrealloc (pstr->offsets, Idx, new_buf_len);
Idx *new_offsets = re_realloc (pstr->offsets, Idx, new_buf_len);
if (BE (new_offsets == NULL, 0))
return REG_ESPACE;
pstr->offsets = new_offsets;
......@@ -161,13 +168,13 @@ re_string_realloc_buffers (re_string_t *pstr, Idx new_buf_len)
static void
internal_function
re_string_construct_common (const char *str, Idx len, re_string_t *pstr,
REG_TRANSLATE_TYPE trans, bool icase,
RE_TRANSLATE_TYPE trans, bool icase,
const re_dfa_t *dfa)
{
pstr->raw_mbs = (const unsigned char *) str;
pstr->len = len;
pstr->raw_len = len;
pstr->trans = (unsigned REG_TRANSLATE_TYPE) trans;
pstr->trans = trans;
pstr->icase = icase;
pstr->mbs_allocated = (trans != NULL || icase);
pstr->mb_cur_max = dfa->mb_cur_max;
......@@ -301,7 +308,7 @@ build_wcs_upper_buffer (re_string_t *pstr)
mbclen = mbrtowc (&wc,
((const char *) pstr->raw_mbs + pstr->raw_mbs_idx
+ byte_idx), remain_len, &pstr->cur_state);
if (BE ((size_t) (mbclen + 2) > 2, 1))
if (BE (mbclen < (size_t) -2, 1))
{
wchar_t wcu = wc;
if (iswlower (wc))
......@@ -369,7 +376,7 @@ build_wcs_upper_buffer (re_string_t *pstr)
else
p = (const char *) pstr->raw_mbs + pstr->raw_mbs_idx + src_idx;
mbclen = mbrtowc (&wc, p, remain_len, &pstr->cur_state);
if (BE ((size_t) (mbclen + 2) > 2, 1))
if (BE (mbclen < (size_t) -2, 1))
{
wchar_t wcu = wc;
if (iswlower (wc))
......@@ -392,7 +399,7 @@ build_wcs_upper_buffer (re_string_t *pstr)
if (pstr->offsets == NULL)
{
pstr->offsets = re_xmalloc (Idx, pstr->bufs_len);
pstr->offsets = re_malloc (Idx, pstr->bufs_len);
if (pstr->offsets == NULL)
return REG_ESPACE;
......@@ -635,37 +642,50 @@ re_string_reconstruct (re_string_t *pstr, Idx idx, int eflags)
byte other than 0x80 - 0xbf. */
raw = pstr->raw_mbs + pstr->raw_mbs_idx;
end = raw + (offset - pstr->mb_cur_max);
for (p = raw + offset - 1; p >= end; --p)
if ((*p & 0xc0) != 0x80)
{
mbstate_t cur_state;
wchar_t wc2;
Idx mlen = raw + pstr->len - p;
unsigned char buf[6];
size_t mbclen;
q = p;
if (BE (pstr->trans != NULL, 0))
{
int i = mlen < 6 ? mlen : 6;
while (--i >= 0)
buf[i] = pstr->trans[p[i]];
q = buf;
}
/* XXX Don't use mbrtowc, we know which conversion
to use (UTF-8 -> UCS4). */
memset (&cur_state, 0, sizeof (cur_state));
mbclen = mbrtowc (&wc2, (const char *) p, mlen,
&cur_state);
if (raw + offset - p <= mbclen && mbclen < (size_t) -2)
{
memset (&pstr->cur_state, '\0',
sizeof (mbstate_t));
pstr->valid_len = mbclen - (raw + offset - p);
wc = wc2;
}
break;
}
p = raw + offset - 1;
#ifdef _LIBC
/* We know the wchar_t encoding is UCS4, so for the simple
case, ASCII characters, skip the conversion step. */
if (isascii (*p) && BE (pstr->trans == NULL, 1))
{
memset (&pstr->cur_state, '\0', sizeof (mbstate_t));
pstr->valid_len = 0;
wc = (wchar_t) *p;
}
else
#endif
for (; p >= end; --p)
if ((*p & 0xc0) != 0x80)
{
mbstate_t cur_state;
wchar_t wc2;
Idx mlen = raw + pstr->len - p;
unsigned char buf[6];
size_t mbclen;
q = p;
if (BE (pstr->trans != NULL, 0))
{
int i = mlen < 6 ? mlen : 6;
while (--i >= 0)
buf[i] = pstr->trans[p[i]];
q = buf;
}
/* XXX Don't use mbrtowc, we know which conversion
to use (UTF-8 -> UCS4). */
memset (&cur_state, 0, sizeof (cur_state));
mbclen = mbrtowc (&wc2, (const char *) p, mlen,
&cur_state);
if (raw + offset - p <= mbclen
&& mbclen < (size_t) -2)
{
memset (&pstr->cur_state, '\0',
sizeof (mbstate_t));
pstr->valid_len = mbclen - (raw + offset - p);
wc = wc2;
}
break;
}
}
if (wc == WEOF)
......@@ -719,15 +739,15 @@ re_string_reconstruct (re_string_t *pstr, Idx idx, int eflags)
}
else
#endif /* RE_ENABLE_I18N */
if (BE (pstr->mbs_allocated, 0))
{
if (pstr->icase)
build_upper_buffer (pstr);
else if (pstr->trans != NULL)
re_string_translate_buffer (pstr);
}
else
pstr->valid_len = pstr->len;
if (BE (pstr->mbs_allocated, 0))
{
if (pstr->icase)
build_upper_buffer (pstr);
else if (pstr->trans != NULL)
re_string_translate_buffer (pstr);
}
else
pstr->valid_len = pstr->len;
pstr->cur_idx = 0;
return REG_NOERROR;
......@@ -873,7 +893,7 @@ re_node_set_alloc (re_node_set *set, Idx size)
{
set->alloc = size;
set->nelem = 0;
set->elems = re_xmalloc (Idx, size);
set->elems = re_malloc (Idx, size);
if (BE (set->elems == NULL, 0))
return REG_ESPACE;
return REG_NOERROR;
......@@ -939,7 +959,7 @@ re_node_set_init_copy (re_node_set *dest, const re_node_set *src)
dest->alloc = dest->nelem = 0;
return REG_ESPACE;
}
memcpy (dest->elems, src->elems, src->nelem * sizeof dest->elems[0]);
memcpy (dest->elems, src->elems, src->nelem * sizeof (Idx));
}
else
re_node_set_init_empty (dest);
......@@ -964,12 +984,7 @@ re_node_set_add_intersect (re_node_set *dest, const re_node_set *src1,
if (src1->nelem + src2->nelem + dest->nelem > dest->alloc)
{
Idx new_alloc = src1->nelem + src2->nelem + dest->alloc;
Idx *new_elems;
if (sizeof (Idx) < 3
&& (new_alloc < dest->alloc
|| ((Idx) (src1->nelem + src2->nelem) < src1->nelem)))
return REG_ESPACE;
new_elems = re_xrealloc (dest->elems, Idx, new_alloc);
Idx *new_elems = re_realloc (dest->elems, Idx, new_alloc);
if (BE (new_elems == NULL, 0))
return REG_ESPACE;
dest->elems = new_elems;
......@@ -1038,7 +1053,7 @@ re_node_set_add_intersect (re_node_set *dest, const re_node_set *src1,
}
/* Copy remaining SRC elements. */
memcpy (dest->elems, dest->elems + sbase, delta * sizeof dest->elems[0]);
memcpy (dest->elems, dest->elems + sbase, delta * sizeof (Idx));
return REG_NOERROR;
}
......@@ -1055,9 +1070,7 @@ re_node_set_init_union (re_node_set *dest, const re_node_set *src1,
if (src1 != NULL && src1->nelem > 0 && src2 != NULL && src2->nelem > 0)
{
dest->alloc = src1->nelem + src2->nelem;
if (sizeof (Idx) < 2 && dest->alloc < src1->nelem)
return REG_ESPACE;
dest->elems = re_xmalloc (Idx, dest->alloc);
dest->elems = re_malloc (Idx, dest->alloc);
if (BE (dest->elems == NULL, 0))
return REG_ESPACE;
}
......@@ -1085,13 +1098,13 @@ re_node_set_init_union (re_node_set *dest, const re_node_set *src1,
if (i1 < src1->nelem)
{
memcpy (dest->elems + id, src1->elems + i1,
(src1->nelem - i1) * sizeof dest->elems[0]);
(src1->nelem - i1) * sizeof (Idx));
id += src1->nelem - i1;
}
else if (i2 < src2->nelem)
{
memcpy (dest->elems + id, src2->elems + i2,
(src2->nelem - i2) * sizeof dest->elems[0]);
(src2->nelem - i2) * sizeof (Idx));
id += src2->nelem - i2;
}
dest->nelem = id;
......@@ -1108,17 +1121,10 @@ re_node_set_merge (re_node_set *dest, const re_node_set *src)
Idx is, id, sbase, delta;
if (src == NULL || src->nelem == 0)
return REG_NOERROR;
if (sizeof (Idx) < 3
&& ((Idx) (2 * src->nelem) < src->nelem
|| (Idx) (2 * src->nelem + dest->nelem) < dest->nelem))
return REG_ESPACE;
if (dest->alloc < 2 * src->nelem + dest->nelem)
{
Idx new_alloc = src->nelem + dest->alloc;
Idx *new_buffer;
if (sizeof (Idx) < 4 && new_alloc < dest->alloc)
return REG_ESPACE;
new_buffer = re_x2realloc (dest->elems, Idx, &new_alloc);
Idx new_alloc = 2 * (src->nelem + dest->alloc);
Idx *new_buffer = re_realloc (dest->elems, Idx, new_alloc);
if (BE (new_buffer == NULL, 0))
return REG_ESPACE;
dest->elems = new_buffer;
......@@ -1128,7 +1134,7 @@ re_node_set_merge (re_node_set *dest, const re_node_set *src)
if (BE (dest->nelem == 0, 0))
{
dest->nelem = src->nelem;
memcpy (dest->elems, src->elems, src->nelem * sizeof dest->elems[0]);
memcpy (dest->elems, src->elems, src->nelem * sizeof (Idx));
return REG_NOERROR;
}
......@@ -1150,8 +1156,7 @@ re_node_set_merge (re_node_set *dest, const re_node_set *src)
{
/* If DEST is exhausted, the remaining items of SRC must be unique. */
sbase -= is + 1;
memcpy (dest->elems + sbase, src->elems,
(is + 1) * sizeof dest->elems[0]);
memcpy (dest->elems + sbase, src->elems, (is + 1) * sizeof (Idx));
}
id = dest->nelem - 1;
......@@ -1180,7 +1185,7 @@ re_node_set_merge (re_node_set *dest, const re_node_set *src)
{
/* Copy remaining SRC elements. */
memcpy (dest->elems, dest->elems + sbase,
delta * sizeof dest->elems[0]);
delta * sizeof (Idx));
break;
}
}
......@@ -1200,7 +1205,7 @@ re_node_set_insert (re_node_set *set, Idx elem)
Idx idx;
/* In case the set is empty. */
if (set->alloc == 0)
return re_node_set_init_1 (set, elem) == REG_NOERROR;
return BE (re_node_set_init_1 (set, elem) == REG_NOERROR, 1);
if (BE (set->nelem, 0) == 0)
{
......@@ -1213,7 +1218,9 @@ re_node_set_insert (re_node_set *set, Idx elem)
/* Realloc if we need. */
if (set->alloc == set->nelem)
{
Idx *new_elems = re_x2realloc (set->elems, Idx, &set->alloc);
Idx *new_elems;
set->alloc = set->alloc * 2;
new_elems = re_realloc (set->elems, Idx, set->alloc);
if (BE (new_elems == NULL, 0))
return false;
set->elems = new_elems;
......@@ -1251,7 +1258,8 @@ re_node_set_insert_last (re_node_set *set, Idx elem)
if (set->alloc == set->nelem)
{
Idx *new_elems;
new_elems = re_x2realloc (set->elems, Idx, &set->alloc);
set->alloc = (set->alloc + 1) * 2;
new_elems = re_realloc (set->elems, Idx, set->alloc);
if (BE (new_elems == NULL, 0))
return false;
set->elems = new_elems;
......@@ -1324,18 +1332,26 @@ re_dfa_add_node (re_dfa_t *dfa, re_token_t token)
int type = token.type;
if (BE (dfa->nodes_len >= dfa->nodes_alloc, 0))
{
Idx new_nodes_alloc = dfa->nodes_alloc;
size_t new_nodes_alloc = dfa->nodes_alloc * 2;
Idx *new_nexts, *new_indices;
re_node_set *new_edests, *new_eclosures;
re_token_t *new_nodes;
size_t max_object_size =
MAX (sizeof (re_token_t),
MAX (sizeof (re_node_set),
sizeof (Idx)));
/* Avoid overflows. */
if (BE (SIZE_MAX / 2 / max_object_size < dfa->nodes_alloc, 0))
return REG_MISSING;
re_token_t *new_nodes = re_x2realloc (dfa->nodes, re_token_t,
&new_nodes_alloc);
new_nodes = re_realloc (dfa->nodes, re_token_t, new_nodes_alloc);
if (BE (new_nodes == NULL, 0))
return REG_MISSING;
dfa->nodes = new_nodes;
new_nexts = re_realloc (dfa->nexts, Idx, new_nodes_alloc);
new_indices = re_realloc (dfa->org_indices, Idx, new_nodes_alloc);
new_edests = re_xrealloc (dfa->edests, re_node_set, new_nodes_alloc);
new_edests = re_realloc (dfa->edests, re_node_set, new_nodes_alloc);
new_eclosures = re_realloc (dfa->eclosures, re_node_set, new_nodes_alloc);
if (BE (new_nexts == NULL || new_indices == NULL
|| new_edests == NULL || new_eclosures == NULL, 0))
......@@ -1378,9 +1394,10 @@ calc_state_hash (const re_node_set *nodes, unsigned int context)
- We never return non-NULL value in case of any errors, it is for
optimization. */
static re_dfastate_t*
static re_dfastate_t *
internal_function
re_acquire_state (reg_errcode_t *err, re_dfa_t *dfa, const re_node_set *nodes)
re_acquire_state (reg_errcode_t *err, const re_dfa_t *dfa,
const re_node_set *nodes)
{
re_hashval_t hash;
re_dfastate_t *new_state;
......@@ -1409,13 +1426,10 @@ re_acquire_state (reg_errcode_t *err, re_dfa_t *dfa, const re_node_set *nodes)
/* There are no appropriate state in the dfa, create the new one. */
new_state = create_ci_newstate (dfa, nodes, hash);
if (BE (new_state != NULL, 1))
return new_state;
else
{
*err = REG_ESPACE;
return NULL;
}
if (BE (new_state == NULL, 0))
*err = REG_ESPACE;
return new_state;
}
/* Search for the state whose node_set is equivalent to NODES and
......@@ -1428,9 +1442,9 @@ re_acquire_state (reg_errcode_t *err, re_dfa_t *dfa, const re_node_set *nodes)
- We never return non-NULL value in case of any errors, it is for
optimization. */
static re_dfastate_t*
static re_dfastate_t *
internal_function
re_acquire_state_context (reg_errcode_t *err, re_dfa_t *dfa,
re_acquire_state_context (reg_errcode_t *err, const re_dfa_t *dfa,
const re_node_set *nodes, unsigned int context)
{
re_hashval_t hash;
......@@ -1459,13 +1473,10 @@ re_acquire_state_context (reg_errcode_t *err, re_dfa_t *dfa,
}
/* There are no appropriate state in `dfa', create the new one. */
new_state = create_cd_newstate (dfa, nodes, context, hash);
if (BE (new_state != NULL, 1))
return new_state;
else
{
*err = REG_ESPACE;
return NULL;
}
if (BE (new_state == NULL, 0))
*err = REG_ESPACE;
return new_state;
}
/* Finish initialization of the new state NEWSTATE, and using its hash value
......@@ -1473,8 +1484,8 @@ re_acquire_state_context (reg_errcode_t *err, re_dfa_t *dfa,
indicates the error code if failed. */
static reg_errcode_t
internal_function
register_state (const re_dfa_t *dfa, re_dfastate_t *newstate, re_hashval_t hash)
register_state (const re_dfa_t *dfa, re_dfastate_t *newstate,
re_hashval_t hash)
{
struct re_state_table_entry *spot;
reg_errcode_t err;
......@@ -1488,19 +1499,16 @@ register_state (const re_dfa_t *dfa, re_dfastate_t *newstate, re_hashval_t hash)
{
Idx elem = newstate->nodes.elems[i];
if (!IS_EPSILON_NODE (dfa->nodes[elem].type))
{
bool ok = re_node_set_insert_last (&newstate->non_eps_nodes, elem);
if (BE (! ok, 0))
return REG_ESPACE;
}
if (BE (! re_node_set_insert_last (&newstate->non_eps_nodes, elem), 0))
return REG_ESPACE;
}
spot = dfa->state_table + (hash & dfa->state_hash_mask);
if (BE (spot->alloc <= spot->num, 0))
{
Idx new_alloc = spot->num;
re_dfastate_t **new_array = re_x2realloc (spot->array, re_dfastate_t *,
&new_alloc);
Idx new_alloc = 2 * spot->num + 2;
re_dfastate_t **new_array = re_realloc (spot->array, re_dfastate_t *,
new_alloc);
if (BE (new_array == NULL, 0))
return REG_ESPACE;
spot->array = new_array;
......@@ -1510,6 +1518,22 @@ register_state (const re_dfa_t *dfa, re_dfastate_t *newstate, re_hashval_t hash)
return REG_NOERROR;
}
static void
free_state (re_dfastate_t *state)
{
re_node_set_free (&state->non_eps_nodes);
re_node_set_free (&state->inveclosure);
if (state->entrance_nodes != &state->nodes)
{
re_node_set_free (state->entrance_nodes);
re_free (state->entrance_nodes);
}
re_node_set_free (&state->nodes);
re_free (state->word_trtable);
re_free (state->trtable);
re_free (state);
}
/* Create the new state which is independ of contexts.
Return the new state if succeeded, otherwise return NULL. */
......@@ -1522,7 +1546,7 @@ create_ci_newstate (const re_dfa_t *dfa, const re_node_set *nodes,
reg_errcode_t err;
re_dfastate_t *newstate;
newstate = re_calloc (re_dfastate_t, 1);
newstate = (re_dfastate_t *) calloc (sizeof (re_dfastate_t), 1);
if (BE (newstate == NULL, 0))
return NULL;
err = re_node_set_init_copy (&newstate->nodes, nodes);
......@@ -1572,7 +1596,7 @@ create_cd_newstate (const re_dfa_t *dfa, const re_node_set *nodes,
reg_errcode_t err;
re_dfastate_t *newstate;
newstate = re_calloc (re_dfastate_t, 1);
newstate = (re_dfastate_t *) calloc (sizeof (re_dfastate_t), 1);
if (BE (newstate == NULL, 0))
return NULL;
err = re_node_set_init_copy (&newstate->nodes, nodes);
......@@ -1637,20 +1661,3 @@ create_cd_newstate (const re_dfa_t *dfa, const re_node_set *nodes,
}
return newstate;
}
static void
internal_function
free_state (re_dfastate_t *state)
{
re_node_set_free (&state->non_eps_nodes);
re_node_set_free (&state->inveclosure);
if (state->entrance_nodes != &state->nodes)
{
re_node_set_free (state->entrance_nodes);
re_free (state->entrance_nodes);
}
re_node_set_free (&state->nodes);
re_free (state->word_trtable);
re_free (state->trtable);
re_free (state);
}
......
......@@ -43,6 +43,9 @@
#if defined HAVE_WCTYPE_H || defined _LIBC
# include <wctype.h>
#endif /* HAVE_WCTYPE_H || _LIBC */
#if defined HAVE_STDINT_H || defined _LIBC
# include <stdint.h>
#endif /* HAVE_STDINT_H || _LIBC */
#if defined _LIBC
# include <bits/libc-lock.h>
#else
......@@ -84,6 +87,11 @@
# define gettext_noop(String) String
#endif
/* For loser systems without the definition. */
#ifndef SIZE_MAX
# define SIZE_MAX ((size_t) -1)
#endif
#if (defined MB_CUR_MAX && HAVE_LOCALE_H && HAVE_WCTYPE_H && HAVE_WCHAR_H && HAVE_WCRTOMB && HAVE_MBRTOWC && HAVE_WCSCOLL) || _LIBC
# define RE_ENABLE_I18N
#endif
......@@ -92,10 +100,16 @@
# define BE(expr, val) __builtin_expect (expr, val)
#else
# define BE(expr, val) (expr)
# ifdef _LIBC
# define inline
# endif
#endif
/* Number of single byte character. */
#define SBC_MAX 256
/* Number of ASCII characters. */
#define ASCII_CHARS 0x80
/* Number of single byte characters. */
#define SBC_MAX (UCHAR_MAX + 1)
#define COLL_ELEM_LEN_MAX 8
......@@ -122,9 +136,6 @@
# define __attribute(arg)
#endif
extern const char __re_error_msgid[] attribute_hidden;
extern const size_t __re_error_msgid_idx[] attribute_hidden;
typedef __re_idx_t Idx;
/* Special return value for failure to match. */
......@@ -152,15 +163,15 @@ typedef __re_size_t re_hashval_t;
/* An integer used to represent a set of bits. It must be unsigned,
and must be at least as wide as unsigned int. */
typedef unsigned long int bitset_word;
/* Maximum value of a bitset word. It must be useful in preprocessor
contexts, and must be consistent with bitset_word. */
typedef unsigned long int bitset_word_t;
/* All bits set in a bitset_word_t. */
#define BITSET_WORD_MAX ULONG_MAX
/* Number of bits in a bitset word. Avoid greater-than-32-bit
integers and unconditional shifts by more than 31 bits, as they're
not portable. */
/* Number of bits in a bitset_word_t. For portability to hosts with
padding bits, do not use '(sizeof (bitset_word_t) * CHAR_BIT)';
instead, deduce it directly from BITSET_WORD_MAX. Avoid
greater-than-32-bit integers and unconditional shifts by more than
31 bits, as they're not portable. */
#if BITSET_WORD_MAX == 0xffffffff
# define BITSET_WORD_BITS 32
#elif BITSET_WORD_MAX >> 31 >> 5 == 1
......@@ -182,20 +193,20 @@ typedef unsigned long int bitset_word;
# if BITSET_WORD_BITS <= SBC_MAX
# error "Invalid SBC_MAX"
# endif
#elif BITSET_WORD_MAX == (0xffffffff + 2) * 0xffffffff
#elif BITSET_WORD_MAX == (0xffffffff + 2) * 0xffffffff
/* Work around a bug in 64-bit PGC (before version 6.1-2), where the
preprocessor mishandles large unsigned values as if they were signed. */
# define BITSET_WORD_BITS 64
#else
# error "Add case for new bitset_word size"
# error "Add case for new bitset_word_t size"
#endif
/* Number of bitset words in a bitset. */
/* Number of bitset_word_t values in a bitset_t. */
#define BITSET_WORDS ((SBC_MAX + BITSET_WORD_BITS - 1) / BITSET_WORD_BITS)
typedef bitset_word bitset[BITSET_WORDS];
typedef bitset_word *re_bitset_ptr_t;
typedef const bitset_word *re_const_bitset_ptr_t;
typedef bitset_word_t bitset_t[BITSET_WORDS];
typedef bitset_word_t *re_bitset_ptr_t;
typedef const bitset_word_t *re_const_bitset_ptr_t;
#define PREV_WORD_CONSTRAINT 0x0001
#define PREV_NOTWORD_CONSTRAINT 0x0002
......@@ -401,7 +412,7 @@ struct re_string_t
the beginning of the input string. */
unsigned int tip_context;
/* The translation passed as a part of an argument of re_compile_pattern. */
unsigned REG_TRANSLATE_TYPE trans;
RE_TRANSLATE_TYPE trans;
/* Copy of re_dfa_t's word_char. */
re_const_bitset_ptr_t word_char;
/* true if REG_ICASE. */
......@@ -438,10 +449,9 @@ static reg_errcode_t build_wcs_upper_buffer (re_string_t *pstr)
#endif /* RE_ENABLE_I18N */
static void build_upper_buffer (re_string_t *pstr) internal_function;
static void re_string_translate_buffer (re_string_t *pstr) internal_function;
static unsigned int re_string_context_at (const re_string_t *input,
Idx idx, int eflags)
static unsigned int re_string_context_at (const re_string_t *input, Idx idx,
int eflags)
internal_function __attribute ((pure));
#define re_string_peek_byte(pstr, offset) \
((pstr)->mbs[(pstr)->cur_idx + offset])
#define re_string_fetch_byte(pstr) \
......@@ -474,71 +484,14 @@ static unsigned int re_string_context_at (const re_string_t *input,
# endif
#endif
#ifndef MAX
# define MAX(a,b) ((a) < (b) ? (b) : (a))
#endif
#define re_malloc(t,n) ((t *) malloc ((n) * sizeof (t)))
#define re_xmalloc(t,n) ((t *) re_xnmalloc (n, sizeof (t)))
#define re_calloc(t,n) ((t *) calloc (n, sizeof (t)))
#define re_realloc(p,t,n) ((t *) realloc (p, (n) * sizeof (t)))
#define re_xrealloc(p,t,n) ((t *) re_xnrealloc (p, n, sizeof (t)))
#define re_x2realloc(p,t,pn) ((t *) re_x2nrealloc (p, pn, sizeof (t)))
#define re_free(p) free (p)
#ifndef SIZE_MAX
# define SIZE_MAX ((size_t) -1)
#endif
/* Return true if an array of N objects, each of size S, cannot exist
due to size arithmetic overflow. S must be nonzero. */
static inline bool
re_alloc_oversized (size_t n, size_t s)
{
return BE (SIZE_MAX / s < n, 0);
}
/* Return true if an array of (2 * N + 1) objects, each of size S,
cannot exist due to size arithmetic overflow. S must be nonzero. */
static inline bool
re_x2alloc_oversized (size_t n, size_t s)
{
return BE ((SIZE_MAX / s - 1) / 2 < n, 0);
}
/* Allocate an array of N objects, each with S bytes of memory,
dynamically, with error checking. S must be nonzero. */
static inline void *
re_xnmalloc (size_t n, size_t s)
{
return re_alloc_oversized (n, s) ? NULL : malloc (n * s);
}
/* Change the size of an allocated block of memory P to an array of N
objects each of S bytes, with error checking. S must be nonzero. */
static inline void *
re_xnrealloc (void *p, size_t n, size_t s)
{
return re_alloc_oversized (n, s) ? NULL : realloc (p, n * s);
}
/* Reallocate a block of memory P to an array of (2 * (*PN) + 1)
objects each of S bytes, with error checking. S must be nonzero.
If the allocation is successful, set *PN to the new allocation
count and return the resulting pointer. Otherwise, return
NULL. */
static inline void *
re_x2nrealloc (void *p, size_t *pn, size_t s)
{
if (re_x2alloc_oversized (*pn, s))
return NULL;
else
{
/* Add 1 in case *PN is zero. */
size_t n1 = 2 * *pn + 1;
p = realloc (p, n1 * s);
if (BE (p != NULL, 1))
*pn = n1;
return p;
}
}
struct bin_tree_t
{
struct bin_tree_t *parent;
......@@ -668,9 +621,9 @@ typedef struct
/* The string object corresponding to the input string. */
re_string_t input;
#if defined _LIBC || (defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L)
re_dfa_t *const dfa;
const re_dfa_t *const dfa;
#else
re_dfa_t *dfa;
const re_dfa_t *dfa;
#endif
/* EFLAGS of the argument of regexec. */
int eflags;
......@@ -717,8 +670,8 @@ struct re_fail_stack_t
struct re_dfa_t
{
re_token_t *nodes;
Idx nodes_alloc;
Idx nodes_len;
size_t nodes_alloc;
size_t nodes_len;
Idx *nexts;
Idx *org_indices;
re_node_set *edests;
......@@ -740,8 +693,8 @@ struct re_dfa_t
Idx nbackref; /* The number of backreference in this dfa. */
/* Bitmap expressing which backreference is used. */
bitset_word used_bkref_map;
bitset_word completed_bkref_map;
bitset_word_t used_bkref_map;
bitset_word_t completed_bkref_map;
unsigned int has_plural_match : 1;
/* If this dfa has "multibyte node", which is a backreference or
......@@ -752,7 +705,7 @@ struct re_dfa_t
unsigned int map_notascii : 1;
unsigned int word_ops_used : 1;
int mb_cur_max;
bitset word_char;
bitset_t word_char;
reg_syntax_t syntax;
Idx *subexp_map;
#ifdef DEBUG
......@@ -766,8 +719,6 @@ struct re_dfa_t
(re_node_set_remove_at (set, re_node_set_contains (set, id) - 1))
#define re_node_set_empty(p) ((p)->nelem = 0)
#define re_node_set_free(set) re_free ((set)->elems)
static void free_state (re_dfastate_t *state) internal_function;
typedef enum
......@@ -791,76 +742,76 @@ typedef struct
} bracket_elem_t;
/* Inline functions for bitset operation. */
/* Inline functions for bitset_t operation. */
static inline void
bitset_set (bitset set, Idx i)
bitset_set (bitset_t set, Idx i)
{
set[i / BITSET_WORD_BITS] |= (bitset_word) 1 << i % BITSET_WORD_BITS;
set[i / BITSET_WORD_BITS] |= (bitset_word_t) 1 << i % BITSET_WORD_BITS;
}
static inline void
bitset_clear (bitset set, Idx i)
bitset_clear (bitset_t set, Idx i)
{
set[i / BITSET_WORD_BITS] &= ~ ((bitset_word) 1 << i % BITSET_WORD_BITS);
set[i / BITSET_WORD_BITS] &= ~ ((bitset_word_t) 1 << i % BITSET_WORD_BITS);
}
static inline bool
bitset_contain (const bitset set, Idx i)
bitset_contain (const bitset_t set, Idx i)
{
return (set[i / BITSET_WORD_BITS] >> i % BITSET_WORD_BITS) & 1;
}
static inline void
bitset_empty (bitset set)
bitset_empty (bitset_t set)
{
memset (set, 0, sizeof (bitset));
memset (set, '\0', sizeof (bitset_t));
}
static inline void
bitset_set_all (bitset set)
bitset_set_all (bitset_t set)
{
memset (set, -1, sizeof (bitset_word) * (SBC_MAX / BITSET_WORD_BITS));
memset (set, -1, sizeof (bitset_word_t) * (SBC_MAX / BITSET_WORD_BITS));
if (SBC_MAX % BITSET_WORD_BITS != 0)
set[BITSET_WORDS - 1] =
((bitset_word) 1 << SBC_MAX % BITSET_WORD_BITS) - 1;
((bitset_word_t) 1 << SBC_MAX % BITSET_WORD_BITS) - 1;
}
static inline void
bitset_copy (bitset dest, const bitset src)
bitset_copy (bitset_t dest, const bitset_t src)
{
memcpy (dest, src, sizeof (bitset));
memcpy (dest, src, sizeof (bitset_t));
}
static inline void
bitset_not (bitset set)
bitset_not (bitset_t set)
{
int i;
for (i = 0; i < SBC_MAX / BITSET_WORD_BITS; ++i)
set[i] = ~set[i];
int bitset_i;
for (bitset_i = 0; bitset_i < SBC_MAX / BITSET_WORD_BITS; ++bitset_i)
set[bitset_i] = ~set[bitset_i];
if (SBC_MAX % BITSET_WORD_BITS != 0)
set[BITSET_WORDS - 1] =
((((bitset_word) 1 << SBC_MAX % BITSET_WORD_BITS) - 1)
((((bitset_word_t) 1 << SBC_MAX % BITSET_WORD_BITS) - 1)
& ~set[BITSET_WORDS - 1]);
}
static inline void
bitset_merge (bitset dest, const bitset src)
bitset_merge (bitset_t dest, const bitset_t src)
{
int i;
for (i = 0; i < BITSET_WORDS; ++i)
dest[i] |= src[i];
int bitset_i;
for (bitset_i = 0; bitset_i < BITSET_WORDS; ++bitset_i)
dest[bitset_i] |= src[bitset_i];
}
static inline void
bitset_mask (bitset dest, const bitset src)
bitset_mask (bitset_t dest, const bitset_t src)
{
int i;
for (i = 0; i < BITSET_WORDS; ++i)
dest[i] &= src[i];
int bitset_i;
for (bitset_i = 0; bitset_i < BITSET_WORDS; ++bitset_i)
dest[bitset_i] &= src[bitset_i];
}
#if defined RE_ENABLE_I18N
#ifdef RE_ENABLE_I18N
/* Inline functions for re_string. */
static inline int
internal_function __attribute ((pure))
......@@ -888,11 +839,11 @@ static int
internal_function __attribute ((pure))
re_string_elem_size_at (const re_string_t *pstr, Idx idx)
{
#ifdef _LIBC
# ifdef _LIBC
const unsigned char *p, *extra;
const int32_t *table, *indirect;
int32_t tmp;
# include <locale/weight.h>
# include <locale/weight.h>
uint_fast32_t nrules = _NL_CURRENT_WORD (LC_COLLATE, _NL_COLLATE_NRULES);
if (nrules != 0)
......@@ -907,7 +858,7 @@ re_string_elem_size_at (const re_string_t *pstr, Idx idx)
return p - pstr->mbs - idx;
}
else
#endif /* _LIBC */
# endif /* _LIBC */
return 1;
}
#endif /* RE_ENABLE_I18N */
......
/* Extended regular expression matching and search library.
Copyright (C) 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
Copyright (C) 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Isamu Hasegawa <isamu@yamato.ibm.com>.
......@@ -51,68 +51,79 @@ static regoff_t re_search_stub (struct re_pattern_buffer *bufp,
regoff_t range, Idx stop,
struct re_registers *regs,
bool ret_len) internal_function;
static unsigned re_copy_regs (struct re_registers *regs, regmatch_t *pmatch,
Idx nregs, int regs_allocated) internal_function;
static unsigned int re_copy_regs (struct re_registers *regs, regmatch_t *pmatch,
Idx nregs, int regs_allocated)
internal_function;
static reg_errcode_t prune_impossible_nodes (re_match_context_t *mctx)
internal_function;
static Idx check_matching (re_match_context_t *mctx, bool fl_longest_match,
Idx *p_match_first)
internal_function;
Idx *p_match_first) internal_function;
static Idx check_halt_state_context (const re_match_context_t *mctx,
const re_dfastate_t *state, Idx idx)
internal_function;
static void update_regs (re_dfa_t *dfa, regmatch_t *pmatch,
static void update_regs (const re_dfa_t *dfa, regmatch_t *pmatch,
regmatch_t *prev_idx_match, Idx cur_node,
Idx cur_idx, Idx nmatch) internal_function;
static reg_errcode_t push_fail_stack (struct re_fail_stack_t *fs,
Idx str_idx, Idx dest_node, Idx nregs,
regmatch_t *regs,
re_node_set *eps_via_nodes) internal_function;
re_node_set *eps_via_nodes)
internal_function;
static reg_errcode_t set_regs (const regex_t *preg,
const re_match_context_t *mctx,
size_t nmatch, regmatch_t *pmatch,
bool fl_backtrack) internal_function;
static reg_errcode_t free_fail_stack_return (struct re_fail_stack_t *fs) internal_function;
static reg_errcode_t free_fail_stack_return (struct re_fail_stack_t *fs)
internal_function;
#ifdef RE_ENABLE_I18N
static int sift_states_iter_mb (const re_match_context_t *mctx,
re_sift_context_t *sctx,
Idx node_idx, Idx str_idx, Idx max_str_idx) internal_function;
Idx node_idx, Idx str_idx, Idx max_str_idx)
internal_function;
#endif /* RE_ENABLE_I18N */
static reg_errcode_t sift_states_backward (re_match_context_t *mctx,
re_sift_context_t *sctx) internal_function;
static reg_errcode_t build_sifted_states (re_match_context_t *mctx,
static reg_errcode_t sift_states_backward (const re_match_context_t *mctx,
re_sift_context_t *sctx)
internal_function;
static reg_errcode_t build_sifted_states (const re_match_context_t *mctx,
re_sift_context_t *sctx, Idx str_idx,
re_node_set *cur_dest) internal_function;
static reg_errcode_t update_cur_sifted_state (re_match_context_t *mctx,
re_node_set *cur_dest)
internal_function;
static reg_errcode_t update_cur_sifted_state (const re_match_context_t *mctx,
re_sift_context_t *sctx,
Idx str_idx,
re_node_set *dest_nodes) internal_function;
static reg_errcode_t add_epsilon_src_nodes (re_dfa_t *dfa,
re_node_set *dest_nodes)
internal_function;
static reg_errcode_t add_epsilon_src_nodes (const re_dfa_t *dfa,
re_node_set *dest_nodes,
const re_node_set *candidates) internal_function;
const re_node_set *candidates)
internal_function;
static bool check_dst_limits (const re_match_context_t *mctx,
const re_node_set *limits,
Idx dst_node, Idx dst_idx, Idx src_node,
Idx src_idx) internal_function;
static int check_dst_limits_calc_pos_1 (const re_match_context_t *mctx,
int boundaries, Idx subexp_idx,
Idx from_node, Idx bkref_idx) internal_function;
Idx from_node, Idx bkref_idx)
internal_function;
static int check_dst_limits_calc_pos (const re_match_context_t *mctx,
Idx limit, Idx subexp_idx,
Idx node, Idx str_idx,
Idx bkref_idx) internal_function;
static reg_errcode_t check_subexp_limits (re_dfa_t *dfa,
static reg_errcode_t check_subexp_limits (const re_dfa_t *dfa,
re_node_set *dest_nodes,
const re_node_set *candidates,
re_node_set *limits,
struct re_backref_cache_entry *bkref_ents,
Idx str_idx) internal_function;
static reg_errcode_t sift_states_bkref (re_match_context_t *mctx,
static reg_errcode_t sift_states_bkref (const re_match_context_t *mctx,
re_sift_context_t *sctx,
Idx str_idx, const re_node_set *candidates) internal_function;
static reg_errcode_t merge_state_array (re_dfa_t *dfa, re_dfastate_t **dst,
re_dfastate_t **src, Idx num) internal_function;
Idx str_idx, const re_node_set *candidates)
internal_function;
static reg_errcode_t merge_state_array (const re_dfa_t *dfa,
re_dfastate_t **dst,
re_dfastate_t **src, Idx num)
internal_function;
static re_dfastate_t *find_recover_state (reg_errcode_t *err,
re_match_context_t *mctx) internal_function;
static re_dfastate_t *transit_state (reg_errcode_t *err,
......@@ -120,27 +131,33 @@ static re_dfastate_t *transit_state (reg_errcode_t *err,
re_dfastate_t *state) internal_function;
static re_dfastate_t *merge_state_with_log (reg_errcode_t *err,
re_match_context_t *mctx,
re_dfastate_t *next_state) internal_function;
re_dfastate_t *next_state)
internal_function;
static reg_errcode_t check_subexp_matching_top (re_match_context_t *mctx,
re_node_set *cur_nodes,
Idx str_idx) internal_function;
#if 0
static re_dfastate_t *transit_state_sb (reg_errcode_t *err,
re_match_context_t *mctx,
re_dfastate_t *pstate) internal_function;
re_dfastate_t *pstate)
internal_function;
#endif
#ifdef RE_ENABLE_I18N
static reg_errcode_t transit_state_mb (re_match_context_t *mctx,
re_dfastate_t *pstate) internal_function;
re_dfastate_t *pstate)
internal_function;
#endif /* RE_ENABLE_I18N */
static reg_errcode_t transit_state_bkref (re_match_context_t *mctx,
const re_node_set *nodes) internal_function;
const re_node_set *nodes)
internal_function;
static reg_errcode_t get_subexp (re_match_context_t *mctx,
Idx bkref_node, Idx bkref_str_idx) internal_function;
Idx bkref_node, Idx bkref_str_idx)
internal_function;
static reg_errcode_t get_subexp_sub (re_match_context_t *mctx,
const re_sub_match_top_t *sub_top,
re_sub_match_last_t *sub_last,
Idx bkref_node, Idx bkref_str) internal_function;
Idx bkref_node, Idx bkref_str)
internal_function;
static Idx find_subexp_node (const re_dfa_t *dfa, const re_node_set *nodes,
Idx subexp_idx, int type) internal_function;
static reg_errcode_t check_arrival (re_match_context_t *mctx,
......@@ -150,35 +167,41 @@ static reg_errcode_t check_arrival (re_match_context_t *mctx,
static reg_errcode_t check_arrival_add_next_nodes (re_match_context_t *mctx,
Idx str_idx,
re_node_set *cur_nodes,
re_node_set *next_nodes) internal_function;
static reg_errcode_t check_arrival_expand_ecl (re_dfa_t *dfa,
re_node_set *next_nodes)
internal_function;
static reg_errcode_t check_arrival_expand_ecl (const re_dfa_t *dfa,
re_node_set *cur_nodes,
Idx ex_subexp, int type) internal_function;
static reg_errcode_t check_arrival_expand_ecl_sub (re_dfa_t *dfa,
Idx ex_subexp, int type)
internal_function;
static reg_errcode_t check_arrival_expand_ecl_sub (const re_dfa_t *dfa,
re_node_set *dst_nodes,
Idx target, Idx ex_subexp,
int type) internal_function;
static reg_errcode_t expand_bkref_cache (re_match_context_t *mctx,
re_node_set *cur_nodes, Idx cur_str,
Idx subexp_num, int type) internal_function;
static bool build_trtable (re_dfa_t *dfa,
Idx subexp_num, int type)
internal_function;
static bool build_trtable (const re_dfa_t *dfa,
re_dfastate_t *state) internal_function;
#ifdef RE_ENABLE_I18N
static int check_node_accept_bytes (re_dfa_t *dfa, Idx node_idx,
const re_string_t *input, Idx idx) internal_function;
static int check_node_accept_bytes (const re_dfa_t *dfa, Idx node_idx,
const re_string_t *input, Idx idx)
internal_function;
# ifdef _LIBC
static unsigned int find_collation_sequence_value (const unsigned char *mbs,
size_t name_len) internal_function;
size_t name_len)
internal_function;
# endif /* _LIBC */
#endif /* RE_ENABLE_I18N */
static Idx group_nodes_into_DFAstates (const re_dfa_t *dfa,
const re_dfastate_t *state,
re_node_set *states_node,
bitset *states_ch) internal_function;
bitset_t *states_ch) internal_function;
static bool check_node_accept (const re_match_context_t *mctx,
const re_token_t *node, Idx idx)
internal_function;
static reg_errcode_t extend_buffers (re_match_context_t *mctx) internal_function;
static reg_errcode_t extend_buffers (re_match_context_t *mctx)
internal_function;
/* Entry point for POSIX code. */
......@@ -197,13 +220,17 @@ static reg_errcode_t extend_buffers (re_match_context_t *mctx) internal_function
We return 0 if we find a match and REG_NOMATCH if not. */
int
regexec (const regex_t *__restrict preg, const char *__restrict string,
size_t nmatch, regmatch_t pmatch[], int eflags)
regexec (preg, string, nmatch, pmatch, eflags)
const regex_t *__restrict preg;
const char *__restrict string;
size_t nmatch;
regmatch_t pmatch[];
int eflags;
{
reg_errcode_t err;
Idx start, length;
#ifdef _LIBC
re_dfa_t *dfa = (re_dfa_t *) preg->re_buffer;
re_dfa_t *dfa = (re_dfa_t *) preg->buffer;
#endif
if (eflags & ~(REG_NOTBOL | REG_NOTEOL | REG_STARTEND))
......@@ -221,7 +248,7 @@ regexec (const regex_t *__restrict preg, const char *__restrict string,
}
__libc_lock_lock (dfa->lock);
if (preg->re_no_sub)
if (preg->no_sub)
err = re_search_internal (preg, string, length, start, length,
length, 0, NULL, eflags);
else
......@@ -271,8 +298,8 @@ compat_symbol (libc, __compat_regexec, regexec, GLIBC_2_0);
the first STOP characters of the concatenation of the strings should be
concerned.
If REGS is not NULL, and BUFP->re_no_sub is not set, the offsets of the match
and all groups is stroed in REGS. (For the "_2" variants, the offsets are
If REGS is not NULL, and BUFP->no_sub is not set, the offsets of the match
and all groups is stored in REGS. (For the "_2" variants, the offsets are
computed relative to the concatenation, not relative to the individual
strings.)
......@@ -281,8 +308,11 @@ compat_symbol (libc, __compat_regexec, regexec, GLIBC_2_0);
match was found and -2 indicates an internal error. */
regoff_t
re_match (struct re_pattern_buffer *bufp, const char *string,
Idx length, Idx start, struct re_registers *regs)
re_match (bufp, string, length, start, regs)
struct re_pattern_buffer *bufp;
const char *string;
Idx length, start;
struct re_registers *regs;
{
return re_search_stub (bufp, string, length, start, 0, length, regs, true);
}
......@@ -291,8 +321,12 @@ weak_alias (__re_match, re_match)
#endif
regoff_t
re_search (struct re_pattern_buffer *bufp, const char *string,
Idx length, Idx start, regoff_t range, struct re_registers *regs)
re_search (bufp, string, length, start, range, regs)
struct re_pattern_buffer *bufp;
const char *string;
Idx length, start;
regoff_t range;
struct re_registers *regs;
{
return re_search_stub (bufp, string, length, start, range, length, regs,
false);
......@@ -302,10 +336,11 @@ weak_alias (__re_search, re_search)
#endif
regoff_t
re_match_2 (struct re_pattern_buffer *bufp,
const char *string1, Idx length1,
const char *string2, Idx length2,
Idx start, struct re_registers *regs, Idx stop)
re_match_2 (bufp, string1, length1, string2, length2, start, regs, stop)
struct re_pattern_buffer *bufp;
const char *string1, *string2;
Idx length1, length2, start, stop;
struct re_registers *regs;
{
return re_search_2_stub (bufp, string1, length1, string2, length2,
start, 0, regs, stop, true);
......@@ -315,10 +350,12 @@ weak_alias (__re_match_2, re_match_2)
#endif
regoff_t
re_search_2 (struct re_pattern_buffer *bufp,
const char *string1, Idx length1,
const char *string2, Idx length2,
Idx start, regoff_t range, struct re_registers *regs, Idx stop)
re_search_2 (bufp, string1, length1, string2, length2, start, range, regs, stop)
struct re_pattern_buffer *bufp;
const char *string1, *string2;
Idx length1, length2, start, stop;
regoff_t range;
struct re_registers *regs;
{
return re_search_2_stub (bufp, string1, length1, string2, length2,
start, range, regs, stop, false);
......@@ -351,8 +388,12 @@ re_search_2_stub (struct re_pattern_buffer *bufp,
if (BE (s == NULL, 0))
return -2;
#ifdef _LIBC
memcpy (__mempcpy (s, string1, length1), string2, length2);
#else
memcpy (s, string1, length1);
memcpy (s + length1, string2, length2);
#endif
str = s;
}
else
......@@ -384,59 +425,37 @@ re_search_stub (struct re_pattern_buffer *bufp,
regoff_t rval;
int eflags = 0;
#ifdef _LIBC
re_dfa_t *dfa = (re_dfa_t *) bufp->re_buffer;
re_dfa_t *dfa = (re_dfa_t *) bufp->buffer;
#endif
Idx last_start = start + range;
/* Check for out-of-range. */
if (BE (start < 0 || start > length, 0))
return -1;
if (sizeof start < sizeof range)
{
regoff_t length_offset = length;
regoff_t start_offset = start;
if (BE (length_offset - start_offset < range, 0))
last_start = length;
else if (BE (range < - start_offset, 0))
last_start = 0;
}
else
{
if (BE ((last_start < start) != (range < 0), 0))
{
/* Overflow occurred when computing last_start; substitute
the extreme value. */
last_start = range < 0 ? 0 : length;
}
else
{
if (BE (length < last_start, 0))
last_start = length;
else if (BE (last_start < 0, 0))
last_start = 0;
}
}
if (BE (length < last_start || (0 <= range && last_start < start), 0))
last_start = length;
else if (BE (last_start < 0 || (range < 0 && start <= last_start), 0))
last_start = 0;
__libc_lock_lock (dfa->lock);
eflags |= (bufp->re_not_bol) ? REG_NOTBOL : 0;
eflags |= (bufp->re_not_eol) ? REG_NOTEOL : 0;
eflags |= (bufp->not_bol) ? REG_NOTBOL : 0;
eflags |= (bufp->not_eol) ? REG_NOTEOL : 0;
/* Compile fastmap if we haven't yet. */
if (start < last_start && bufp->re_fastmap != NULL
&& !bufp->re_fastmap_accurate)
if (start < last_start && bufp->fastmap != NULL && !bufp->fastmap_accurate)
re_compile_fastmap (bufp);
if (BE (bufp->re_no_sub, 0))
if (BE (bufp->no_sub, 0))
regs = NULL;
/* We need at least 1 register. */
if (regs == NULL)
nregs = 1;
else if (BE (bufp->re_regs_allocated == REG_FIXED
&& regs->rm_num_regs <= bufp->re_nsub, 0))
else if (BE (bufp->regs_allocated == REGS_FIXED
&& regs->num_regs <= bufp->re_nsub, 0))
{
nregs = regs->rm_num_regs;
nregs = regs->num_regs;
if (BE (nregs < 1, 0))
{
/* Nothing can be copied to regs. */
......@@ -446,7 +465,7 @@ re_search_stub (struct re_pattern_buffer *bufp,
}
else
nregs = bufp->re_nsub + 1;
pmatch = re_xmalloc (regmatch_t, nregs);
pmatch = re_malloc (regmatch_t, nregs);
if (BE (pmatch == NULL, 0))
{
rval = -2;
......@@ -464,9 +483,9 @@ re_search_stub (struct re_pattern_buffer *bufp,
else if (regs != NULL)
{
/* If caller wants register contents data back, copy them. */
bufp->re_regs_allocated = re_copy_regs (regs, pmatch, nregs,
bufp->re_regs_allocated);
if (BE (bufp->re_regs_allocated == REG_UNALLOCATED, 0))
bufp->regs_allocated = re_copy_regs (regs, pmatch, nregs,
bufp->regs_allocated);
if (BE (bufp->regs_allocated == REGS_UNALLOCATED, 0))
rval = -2;
}
......@@ -486,58 +505,68 @@ re_search_stub (struct re_pattern_buffer *bufp,
return rval;
}
static unsigned
static unsigned int
internal_function
re_copy_regs (struct re_registers *regs, regmatch_t *pmatch, Idx nregs,
int regs_allocated)
{
int rval = REG_REALLOCATE;
int rval = REGS_REALLOCATE;
Idx i;
Idx need_regs = nregs + 1;
/* We need one extra element beyond `rm_num_regs' for the `-1' marker GNU code
/* We need one extra element beyond `num_regs' for the `-1' marker GNU code
uses. */
/* Have the register data arrays been allocated? */
if (regs_allocated == REG_UNALLOCATED)
if (regs_allocated == REGS_UNALLOCATED)
{ /* No. So allocate them with malloc. */
regs->rm_start = re_xmalloc (regoff_t, need_regs);
regs->rm_end = re_malloc (regoff_t, need_regs);
if (BE (regs->rm_start == NULL, 0) || BE (regs->rm_end == NULL, 0))
return REG_UNALLOCATED;
regs->rm_num_regs = need_regs;
regs->start = re_malloc (regoff_t, need_regs);
if (BE (regs->start == NULL, 0))
return REGS_UNALLOCATED;
regs->end = re_malloc (regoff_t, need_regs);
if (BE (regs->end == NULL, 0))
{
re_free (regs->start);
return REGS_UNALLOCATED;
}
regs->num_regs = need_regs;
}
else if (regs_allocated == REG_REALLOCATE)
else if (regs_allocated == REGS_REALLOCATE)
{ /* Yes. If we need more elements than were already
allocated, reallocate them. If we need fewer, just
leave it alone. */
if (BE (need_regs > regs->rm_num_regs, 0))
if (BE (need_regs > regs->num_regs, 0))
{
regoff_t *new_start =
re_xrealloc (regs->rm_start, regoff_t, need_regs);
regoff_t *new_end = re_realloc (regs->rm_end, regoff_t, need_regs);
if (BE (new_start == NULL, 0) || BE (new_end == NULL, 0))
return REG_UNALLOCATED;
regs->rm_start = new_start;
regs->rm_end = new_end;
regs->rm_num_regs = need_regs;
regoff_t *new_start = re_realloc (regs->start, regoff_t, need_regs);
regoff_t *new_end;
if (BE (new_start == NULL, 0))
return REGS_UNALLOCATED;
new_end = re_realloc (regs->end, regoff_t, need_regs);
if (BE (new_end == NULL, 0))
{
re_free (new_start);
return REGS_UNALLOCATED;
}
regs->start = new_start;
regs->end = new_end;
regs->num_regs = need_regs;
}
}
else
{
assert (regs_allocated == REG_FIXED);
/* This function may not be called with REG_FIXED and nregs too big. */
assert (regs->rm_num_regs >= nregs);
rval = REG_FIXED;
assert (regs_allocated == REGS_FIXED);
/* This function may not be called with REGS_FIXED and nregs too big. */
assert (regs->num_regs >= nregs);
rval = REGS_FIXED;
}
/* Copy the regs. */
for (i = 0; i < nregs; ++i)
{
regs->rm_start[i] = pmatch[i].rm_so;
regs->rm_end[i] = pmatch[i].rm_eo;
regs->start[i] = pmatch[i].rm_so;
regs->end[i] = pmatch[i].rm_eo;
}
for ( ; i < regs->rm_num_regs; ++i)
regs->rm_start[i] = regs->rm_end[i] = -1;
for ( ; i < regs->num_regs; ++i)
regs->start[i] = regs->end[i] = -1;
return rval;
}
......@@ -556,21 +585,24 @@ re_copy_regs (struct re_registers *regs, regmatch_t *pmatch, Idx nregs,
freeing the old data. */
void
re_set_registers (struct re_pattern_buffer *bufp, struct re_registers *regs,
__re_size_t num_regs, regoff_t *starts, regoff_t *ends)
re_set_registers (bufp, regs, num_regs, starts, ends)
struct re_pattern_buffer *bufp;
struct re_registers *regs;
__re_size_t num_regs;
regoff_t *starts, *ends;
{
if (num_regs)
{
bufp->re_regs_allocated = REG_REALLOCATE;
regs->rm_num_regs = num_regs;
regs->rm_start = starts;
regs->rm_end = ends;
bufp->regs_allocated = REGS_REALLOCATE;
regs->num_regs = num_regs;
regs->start = starts;
regs->end = ends;
}
else
{
bufp->re_regs_allocated = REG_UNALLOCATED;
regs->rm_num_regs = 0;
regs->rm_start = regs->rm_end = NULL;
bufp->regs_allocated = REGS_UNALLOCATED;
regs->num_regs = 0;
regs->start = regs->end = NULL;
}
}
#ifdef _LIBC
......@@ -585,7 +617,8 @@ int
# ifdef _LIBC
weak_function
# endif
re_exec (const char *s)
re_exec (s)
const char *s;
{
return 0 == regexec (&re_comp_buf, s, 0, NULL, 0);
}
......@@ -611,12 +644,13 @@ re_search_internal (const regex_t *preg,
int eflags)
{
reg_errcode_t err;
re_dfa_t *dfa = (re_dfa_t *) preg->re_buffer;
const re_dfa_t *dfa = (const re_dfa_t *) preg->buffer;
Idx left_lim, right_lim;
int incr;
bool fl_longest_match;
int match_kind;
Idx match_first, match_last = REG_MISSING;
Idx match_first;
Idx match_last = REG_MISSING;
Idx extra_nmatch;
bool sb;
int ch;
......@@ -625,11 +659,10 @@ re_search_internal (const regex_t *preg,
#else
re_match_context_t mctx;
#endif
char *fastmap = ((preg->re_fastmap != NULL && preg->re_fastmap_accurate
&& start != last_start && !preg->re_can_be_null)
? preg->re_fastmap : NULL);
unsigned REG_TRANSLATE_TYPE t =
(unsigned REG_TRANSLATE_TYPE) preg->re_translate;
char *fastmap = ((preg->fastmap != NULL && preg->fastmap_accurate
&& start != last_start && !preg->can_be_null)
? preg->fastmap : NULL);
RE_TRANSLATE_TYPE t = preg->translate;
#if !(defined _LIBC || (defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L))
memset (&mctx, '\0', sizeof (re_match_context_t));
......@@ -640,7 +673,7 @@ re_search_internal (const regex_t *preg,
nmatch -= extra_nmatch;
/* Check if the DFA haven't been compiled. */
if (BE (preg->re_used == 0 || dfa->init_state == NULL
if (BE (preg->used == 0 || dfa->init_state == NULL
|| dfa->init_state_word == NULL || dfa->init_state_nl == NULL
|| dfa->init_state_begbuf == NULL, 0))
return REG_NOMATCH;
......@@ -651,12 +684,12 @@ re_search_internal (const regex_t *preg,
#endif
/* If initial states with non-begbuf contexts have no elements,
the regex must be anchored. If preg->re_newline_anchor is set,
the regex must be anchored. If preg->newline_anchor is set,
we'll never use init_state_nl, so do not check it. */
if (dfa->init_state->nodes.nelem == 0
&& dfa->init_state_word->nodes.nelem == 0
&& (dfa->init_state_nl->nodes.nelem == 0
|| !preg->re_newline_anchor))
|| !preg->newline_anchor))
{
if (start != 0 && last_start != 0)
return REG_NOMATCH;
......@@ -667,13 +700,12 @@ re_search_internal (const regex_t *preg,
fl_longest_match = (nmatch != 0 || dfa->nbackref);
err = re_string_allocate (&mctx.input, string, length, dfa->nodes_len + 1,
preg->re_translate,
preg->re_syntax & REG_IGNORE_CASE, dfa);
preg->translate, preg->syntax & RE_ICASE, dfa);
if (BE (err != REG_NOERROR, 0))
goto free_return;
mctx.input.stop = stop;
mctx.input.raw_stop = stop;
mctx.input.newline_anchor = preg->re_newline_anchor;
mctx.input.newline_anchor = preg->newline_anchor;
err = match_ctx_init (&mctx, eflags, dfa->nbackref * 2);
if (BE (err != REG_NOERROR, 0))
......@@ -685,7 +717,14 @@ re_search_internal (const regex_t *preg,
multi character collating element. */
if (nmatch > 1 || dfa->has_mb_node)
{
mctx.state_log = re_xmalloc (re_dfastate_t *, mctx.input.bufs_len + 1);
/* Avoid overflow. */
if (BE (SIZE_MAX / sizeof (re_dfastate_t *) <= mctx.input.bufs_len, 0))
{
err = REG_ESPACE;
goto free_return;
}
mctx.state_log = re_malloc (re_dfastate_t *, mctx.input.bufs_len + 1);
if (BE (mctx.state_log == NULL, 0))
{
err = REG_ESPACE;
......@@ -706,7 +745,7 @@ re_search_internal (const regex_t *preg,
sb = dfa->mb_cur_max == 1;
match_kind =
(fastmap
? ((sb || !(preg->re_syntax & REG_IGNORE_CASE || t) ? 4 : 0)
? ((sb || !(preg->syntax & RE_ICASE || t) ? 4 : 0)
| (start <= last_start ? 2 : 0)
| (t != NULL ? 1 : 0))
: 8);
......@@ -828,13 +867,13 @@ re_search_internal (const regex_t *preg,
else
{
mctx.match_last = match_last;
if ((!preg->re_no_sub && nmatch > 1) || dfa->nbackref)
if ((!preg->no_sub && nmatch > 1) || dfa->nbackref)
{
re_dfastate_t *pstate = mctx.state_log[match_last];
mctx.last_node = check_halt_state_context (&mctx, pstate,
match_last);
}
if ((!preg->re_no_sub && nmatch > 1 && dfa->has_plural_match)
if ((!preg->no_sub && nmatch > 1 && dfa->has_plural_match)
|| dfa->nbackref)
{
err = prune_impossible_nodes (&mctx);
......@@ -873,7 +912,7 @@ re_search_internal (const regex_t *preg,
the maximum possible regoff_t value. We need a new error
code REG_OVERFLOW. */
if (!preg->re_no_sub && nmatch > 1)
if (!preg->no_sub && nmatch > 1)
{
err = set_regs (preg, &mctx, nmatch, pmatch,
dfa->has_plural_match && dfa->nbackref > 0);
......@@ -934,7 +973,7 @@ static reg_errcode_t
internal_function
prune_impossible_nodes (re_match_context_t *mctx)
{
re_dfa_t *const dfa = mctx->dfa;
const re_dfa_t *const dfa = mctx->dfa;
Idx halt_node, match_last;
reg_errcode_t ret;
re_dfastate_t **sifted_states;
......@@ -945,7 +984,12 @@ prune_impossible_nodes (re_match_context_t *mctx)
#endif
match_last = mctx->match_last;
halt_node = mctx->last_node;
sifted_states = re_xmalloc (re_dfastate_t *, match_last + 1);
/* Avoid overflow. */
if (BE (SIZE_MAX / sizeof (re_dfastate_t *) <= match_last, 0))
return REG_ESPACE;
sifted_states = re_malloc (re_dfastate_t *, match_last + 1);
if (BE (sifted_states == NULL, 0))
{
ret = REG_ESPACE;
......@@ -953,7 +997,7 @@ prune_impossible_nodes (re_match_context_t *mctx)
}
if (dfa->nbackref)
{
lim_states = re_xmalloc (re_dfastate_t *, match_last + 1);
lim_states = re_malloc (re_dfastate_t *, match_last + 1);
if (BE (lim_states == NULL, 0))
{
ret = REG_ESPACE;
......@@ -1021,7 +1065,7 @@ __attribute ((always_inline)) internal_function
acquire_init_state_context (reg_errcode_t *err, const re_match_context_t *mctx,
Idx idx)
{
re_dfa_t *const dfa = mctx->dfa;
const re_dfa_t *const dfa = mctx->dfa;
if (dfa->init_state->has_constraint)
{
unsigned int context;
......@@ -1063,7 +1107,7 @@ internal_function
check_matching (re_match_context_t *mctx, bool fl_longest_match,
Idx *p_match_first)
{
re_dfa_t *const dfa = mctx->dfa;
const re_dfa_t *const dfa = mctx->dfa;
reg_errcode_t err;
Idx match = 0;
Idx match_last = REG_MISSING;
......@@ -1233,11 +1277,11 @@ check_halt_state_context (const re_match_context_t *mctx,
static Idx
internal_function
proceed_next_node (const re_match_context_t *mctx,
Idx nregs, regmatch_t *regs, Idx *pidx, Idx node,
re_node_set *eps_via_nodes, struct re_fail_stack_t *fs)
proceed_next_node (const re_match_context_t *mctx, Idx nregs, regmatch_t *regs,
Idx *pidx, Idx node, re_node_set *eps_via_nodes,
struct re_fail_stack_t *fs)
{
re_dfa_t *const dfa = mctx->dfa;
const re_dfa_t *const dfa = mctx->dfa;
Idx i;
bool ok;
if (IS_EPSILON_NODE (dfa->nodes[node].type))
......@@ -1342,15 +1386,17 @@ push_fail_stack (struct re_fail_stack_t *fs, Idx str_idx, Idx dest_node,
Idx num = fs->num++;
if (fs->num == fs->alloc)
{
struct re_fail_stack_ent_t *new_array =
re_x2realloc (fs->stack, struct re_fail_stack_ent_t, &fs->alloc);
struct re_fail_stack_ent_t *new_array;
new_array = realloc (fs->stack, (sizeof (struct re_fail_stack_ent_t)
* fs->alloc * 2));
if (new_array == NULL)
return REG_ESPACE;
fs->alloc *= 2;
fs->stack = new_array;
}
fs->stack[num].idx = str_idx;
fs->stack[num].node = dest_node;
fs->stack[num].regs = re_xmalloc (regmatch_t, nregs);
fs->stack[num].regs = re_malloc (regmatch_t, nregs);
if (fs->stack[num].regs == NULL)
return REG_ESPACE;
memcpy (fs->stack[num].regs, regs, sizeof (regmatch_t) * nregs);
......@@ -1360,8 +1406,8 @@ push_fail_stack (struct re_fail_stack_t *fs, Idx str_idx, Idx dest_node,
static Idx
internal_function
pop_fail_stack (struct re_fail_stack_t *fs, Idx *pidx,
Idx nregs, regmatch_t *regs, re_node_set *eps_via_nodes)
pop_fail_stack (struct re_fail_stack_t *fs, Idx *pidx, Idx nregs,
regmatch_t *regs, re_node_set *eps_via_nodes)
{
Idx num = --fs->num;
assert (REG_VALID_INDEX (num));
......@@ -1380,10 +1426,10 @@ pop_fail_stack (struct re_fail_stack_t *fs, Idx *pidx,
static reg_errcode_t
internal_function
set_regs (const regex_t *preg, const re_match_context_t *mctx,
size_t nmatch, regmatch_t *pmatch, bool fl_backtrack)
set_regs (const regex_t *preg, const re_match_context_t *mctx, size_t nmatch,
regmatch_t *pmatch, bool fl_backtrack)
{
re_dfa_t *dfa = (re_dfa_t *) preg->re_buffer;
const re_dfa_t *dfa = (const re_dfa_t *) preg->buffer;
Idx idx, cur_node;
re_node_set eps_via_nodes;
struct re_fail_stack_t *fs;
......@@ -1398,7 +1444,7 @@ set_regs (const regex_t *preg, const re_match_context_t *mctx,
if (fl_backtrack)
{
fs = &fs_body;
fs->stack = re_xmalloc (struct re_fail_stack_ent_t, fs->alloc);
fs->stack = re_malloc (struct re_fail_stack_ent_t, fs->alloc);
if (fs->stack == NULL)
return REG_ESPACE;
}
......@@ -1408,11 +1454,6 @@ set_regs (const regex_t *preg, const re_match_context_t *mctx,
cur_node = dfa->init_node;
re_node_set_init_empty (&eps_via_nodes);
if (re_alloc_oversized (nmatch, sizeof (regmatch_t)))
{
free_fail_stack_return (fs);
return REG_ESPACE;
}
if (__libc_use_alloca (nmatch * sizeof (regmatch_t)))
prev_idx_match = (regmatch_t *) alloca (nmatch * sizeof (regmatch_t));
else
......@@ -1509,8 +1550,8 @@ free_fail_stack_return (struct re_fail_stack_t *fs)
static void
internal_function
update_regs (re_dfa_t *dfa, regmatch_t *pmatch, regmatch_t *prev_idx_match,
Idx cur_node, Idx cur_idx, Idx nmatch)
update_regs (const re_dfa_t *dfa, regmatch_t *pmatch,
regmatch_t *prev_idx_match, Idx cur_node, Idx cur_idx, Idx nmatch)
{
int type = dfa->nodes[cur_node].type;
if (type == OP_OPEN_SUBEXP)
......@@ -1581,7 +1622,7 @@ update_regs (re_dfa_t *dfa, regmatch_t *pmatch, regmatch_t *prev_idx_match,
static reg_errcode_t
internal_function
sift_states_backward (re_match_context_t *mctx, re_sift_context_t *sctx)
sift_states_backward (const re_match_context_t *mctx, re_sift_context_t *sctx)
{
reg_errcode_t err;
int null_cnt = 0;
......@@ -1639,11 +1680,11 @@ sift_states_backward (re_match_context_t *mctx, re_sift_context_t *sctx)
static reg_errcode_t
internal_function
build_sifted_states (re_match_context_t *mctx, re_sift_context_t *sctx,
build_sifted_states (const re_match_context_t *mctx, re_sift_context_t *sctx,
Idx str_idx, re_node_set *cur_dest)
{
re_dfa_t *const dfa = mctx->dfa;
re_node_set *cur_src = &mctx->state_log[str_idx]->non_eps_nodes;
const re_dfa_t *const dfa = mctx->dfa;
const re_node_set *cur_src = &mctx->state_log[str_idx]->non_eps_nodes;
Idx i;
/* Then build the next sifted state.
......@@ -1726,8 +1767,8 @@ clean_state_log_if_needed (re_match_context_t *mctx, Idx next_state_log_idx)
static reg_errcode_t
internal_function
merge_state_array (re_dfa_t *dfa, re_dfastate_t **dst, re_dfastate_t **src,
Idx num)
merge_state_array (const re_dfa_t *dfa, re_dfastate_t **dst,
re_dfastate_t **src, Idx num)
{
Idx st_idx;
reg_errcode_t err;
......@@ -1753,11 +1794,12 @@ merge_state_array (re_dfa_t *dfa, re_dfastate_t **dst, re_dfastate_t **src,
static reg_errcode_t
internal_function
update_cur_sifted_state (re_match_context_t *mctx, re_sift_context_t *sctx,
Idx str_idx, re_node_set *dest_nodes)
update_cur_sifted_state (const re_match_context_t *mctx,
re_sift_context_t *sctx, Idx str_idx,
re_node_set *dest_nodes)
{
re_dfa_t *const dfa = mctx->dfa;
reg_errcode_t err;
const re_dfa_t *const dfa = mctx->dfa;
reg_errcode_t err = REG_NOERROR;
const re_node_set *candidates;
candidates = ((mctx->state_log[str_idx] == NULL) ? NULL
: &mctx->state_log[str_idx]->nodes);
......@@ -1800,7 +1842,7 @@ update_cur_sifted_state (re_match_context_t *mctx, re_sift_context_t *sctx,
static reg_errcode_t
internal_function
add_epsilon_src_nodes (re_dfa_t *dfa, re_node_set *dest_nodes,
add_epsilon_src_nodes (const re_dfa_t *dfa, re_node_set *dest_nodes,
const re_node_set *candidates)
{
reg_errcode_t err = REG_NOERROR;
......@@ -1825,7 +1867,7 @@ add_epsilon_src_nodes (re_dfa_t *dfa, re_node_set *dest_nodes,
static reg_errcode_t
internal_function
sub_epsilon_src_nodes (re_dfa_t *dfa, Idx node, re_node_set *dest_nodes,
sub_epsilon_src_nodes (const re_dfa_t *dfa, Idx node, re_node_set *dest_nodes,
const re_node_set *candidates)
{
Idx ecl_idx;
......@@ -1877,7 +1919,7 @@ internal_function
check_dst_limits (const re_match_context_t *mctx, const re_node_set *limits,
Idx dst_node, Idx dst_idx, Idx src_node, Idx src_idx)
{
re_dfa_t *const dfa = mctx->dfa;
const re_dfa_t *const dfa = mctx->dfa;
Idx lim_idx, src_pos, dst_pos;
Idx dst_bkref_idx = search_cur_bkref_entry (mctx, dst_idx);
......@@ -1913,8 +1955,8 @@ internal_function
check_dst_limits_calc_pos_1 (const re_match_context_t *mctx, int boundaries,
Idx subexp_idx, Idx from_node, Idx bkref_idx)
{
re_dfa_t *const dfa = mctx->dfa;
re_node_set *eclosures = dfa->eclosures + from_node;
const re_dfa_t *const dfa = mctx->dfa;
const re_node_set *eclosures = dfa->eclosures + from_node;
Idx node_idx;
/* Else, we are on the boundary: examine the nodes on the epsilon
......@@ -1938,7 +1980,7 @@ check_dst_limits_calc_pos_1 (const re_match_context_t *mctx, int boundaries,
if (subexp_idx < BITSET_WORD_BITS
&& !(ent->eps_reachable_subexps_map
& ((bitset_word) 1 << subexp_idx)))
& ((bitset_word_t) 1 << subexp_idx)))
continue;
/* Recurse trying to reach the OP_OPEN_SUBEXP and
......@@ -1965,8 +2007,8 @@ check_dst_limits_calc_pos_1 (const re_match_context_t *mctx, int boundaries,
return 0;
if (subexp_idx < BITSET_WORD_BITS)
ent->eps_reachable_subexps_map &=
~ ((bitset_word) 1 << subexp_idx);
ent->eps_reachable_subexps_map
&= ~((bitset_word_t) 1 << subexp_idx);
}
while (ent++->more);
}
......@@ -1992,9 +2034,9 @@ check_dst_limits_calc_pos_1 (const re_match_context_t *mctx, int boundaries,
static int
internal_function
check_dst_limits_calc_pos (const re_match_context_t *mctx,
Idx limit, Idx subexp_idx,
Idx from_node, Idx str_idx, Idx bkref_idx)
check_dst_limits_calc_pos (const re_match_context_t *mctx, Idx limit,
Idx subexp_idx, Idx from_node, Idx str_idx,
Idx bkref_idx)
{
struct re_backref_cache_entry *lim = mctx->bkref_ents + limit;
int boundaries;
......@@ -2022,7 +2064,7 @@ check_dst_limits_calc_pos (const re_match_context_t *mctx,
static reg_errcode_t
internal_function
check_subexp_limits (re_dfa_t *dfa, re_node_set *dest_nodes,
check_subexp_limits (const re_dfa_t *dfa, re_node_set *dest_nodes,
const re_node_set *candidates, re_node_set *limits,
struct re_backref_cache_entry *bkref_ents, Idx str_idx)
{
......@@ -2110,10 +2152,10 @@ check_subexp_limits (re_dfa_t *dfa, re_node_set *dest_nodes,
static reg_errcode_t
internal_function
sift_states_bkref (re_match_context_t *mctx, re_sift_context_t *sctx,
sift_states_bkref (const re_match_context_t *mctx, re_sift_context_t *sctx,
Idx str_idx, const re_node_set *candidates)
{
re_dfa_t *const dfa = mctx->dfa;
const re_dfa_t *const dfa = mctx->dfa;
reg_errcode_t err;
Idx node_idx, node;
re_sift_context_t local_sctx;
......@@ -2141,8 +2183,10 @@ sift_states_bkref (re_match_context_t *mctx, re_sift_context_t *sctx,
enabled_idx = first_idx;
do
{
Idx subexp_len;
Idx to_idx;
Idx dst_node;
bool ok;
Idx subexp_len, to_idx, dst_node;
re_dfastate_t *cur_state;
if (entry->node != node)
......@@ -2211,7 +2255,7 @@ internal_function
sift_states_iter_mb (const re_match_context_t *mctx, re_sift_context_t *sctx,
Idx node_idx, Idx str_idx, Idx max_str_idx)
{
re_dfa_t *const dfa = mctx->dfa;
const re_dfa_t *const dfa = mctx->dfa;
int naccepted;
/* Check the node can accept `multi byte'. */
naccepted = check_node_accept_bytes (dfa, node_idx, &mctx->input, str_idx);
......@@ -2299,7 +2343,7 @@ internal_function
merge_state_with_log (reg_errcode_t *err, re_match_context_t *mctx,
re_dfastate_t *next_state)
{
re_dfa_t *const dfa = mctx->dfa;
const re_dfa_t *const dfa = mctx->dfa;
Idx cur_idx = re_string_cur_idx (&mctx->input);
if (cur_idx > mctx->state_log_top)
......@@ -2377,7 +2421,7 @@ static re_dfastate_t *
internal_function
find_recover_state (reg_errcode_t *err, re_match_context_t *mctx)
{
re_dfastate_t *cur_state = NULL;
re_dfastate_t *cur_state;
do
{
Idx max = mctx->state_log_top;
......@@ -2409,7 +2453,7 @@ internal_function
check_subexp_matching_top (re_match_context_t *mctx, re_node_set *cur_nodes,
Idx str_idx)
{
re_dfa_t *const dfa = mctx->dfa;
const re_dfa_t *const dfa = mctx->dfa;
Idx node_idx;
reg_errcode_t err;
......@@ -2424,7 +2468,7 @@ check_subexp_matching_top (re_match_context_t *mctx, re_node_set *cur_nodes,
if (dfa->nodes[node].type == OP_OPEN_SUBEXP
&& dfa->nodes[node].opr.idx < BITSET_WORD_BITS
&& (dfa->used_bkref_map
& ((bitset_word) 1 << dfa->nodes[node].opr.idx)))
& ((bitset_word_t) 1 << dfa->nodes[node].opr.idx)))
{
err = match_ctx_add_subtop (mctx, node, str_idx);
if (BE (err != REG_NOERROR, 0))
......@@ -2442,7 +2486,7 @@ static re_dfastate_t *
transit_state_sb (reg_errcode_t *err, re_match_context_t *mctx,
re_dfastate_t *state)
{
re_dfa_t *const dfa = mctx->dfa;
const re_dfa_t *const dfa = mctx->dfa;
re_node_set next_nodes;
re_dfastate_t *next_state;
Idx node_cnt, cur_str_idx = re_string_cur_idx (&mctx->input);
......@@ -2481,7 +2525,7 @@ static reg_errcode_t
internal_function
transit_state_mb (re_match_context_t *mctx, re_dfastate_t *pstate)
{
re_dfa_t *const dfa = mctx->dfa;
const re_dfa_t *const dfa = mctx->dfa;
reg_errcode_t err;
Idx i;
......@@ -2535,7 +2579,8 @@ transit_state_mb (re_match_context_t *mctx, re_dfastate_t *pstate)
if (BE (err != REG_NOERROR, 0))
return err;
}
context = re_string_context_at (&mctx->input, dest_idx - 1, mctx->eflags);
context = re_string_context_at (&mctx->input, dest_idx - 1,
mctx->eflags);
mctx->state_log[dest_idx]
= re_acquire_state_context (&err, dfa, &dest_nodes, context);
if (dest_state != NULL)
......@@ -2551,7 +2596,7 @@ static reg_errcode_t
internal_function
transit_state_bkref (re_match_context_t *mctx, const re_node_set *nodes)
{
re_dfa_t *const dfa = mctx->dfa;
const re_dfa_t *const dfa = mctx->dfa;
reg_errcode_t err;
Idx i;
Idx cur_str_idx = re_string_cur_idx (&mctx->input);
......@@ -2665,14 +2710,15 @@ static reg_errcode_t
internal_function
get_subexp (re_match_context_t *mctx, Idx bkref_node, Idx bkref_str_idx)
{
re_dfa_t *const dfa = mctx->dfa;
const re_dfa_t *const dfa = mctx->dfa;
Idx subexp_num, sub_top_idx;
const char *buf = (const char *) re_string_get_buffer (&mctx->input);
/* Return if we have already checked BKREF_NODE at BKREF_STR_IDX. */
Idx cache_idx = search_cur_bkref_entry (mctx, bkref_str_idx);
if (cache_idx != REG_MISSING)
{
const struct re_backref_cache_entry *entry = mctx->bkref_ents + cache_idx;
const struct re_backref_cache_entry *entry
= mctx->bkref_ents + cache_idx;
do
if (entry->node == bkref_node)
return REG_NOERROR; /* We already checked it. */
......@@ -2719,7 +2765,8 @@ get_subexp (re_match_context_t *mctx, Idx bkref_node, Idx bkref_str_idx)
buf = (const char *) re_string_get_buffer (&mctx->input);
}
if (memcmp (buf + bkref_str_off, buf + sl_str, sl_str_diff) != 0)
break; /* We don't need to search this sub expression any more. */
/* We don't need to search this sub expression any more. */
break;
}
bkref_str_off += sl_str_diff;
sl_str += sl_str_diff;
......@@ -2771,20 +2818,22 @@ get_subexp (re_match_context_t *mctx, Idx bkref_node, Idx bkref_str_idx)
continue;
/* Does this state have a ')' of the sub expression? */
nodes = &mctx->state_log[sl_str]->nodes;
cls_node = find_subexp_node (dfa, nodes, subexp_num, OP_CLOSE_SUBEXP);
cls_node = find_subexp_node (dfa, nodes, subexp_num,
OP_CLOSE_SUBEXP);
if (cls_node == REG_MISSING)
continue; /* No. */
if (sub_top->path == NULL)
{
sub_top->path = re_calloc (state_array_t,
sl_str - sub_top->str_idx + 1);
sub_top->path = calloc (sizeof (state_array_t),
sl_str - sub_top->str_idx + 1);
if (sub_top->path == NULL)
return REG_ESPACE;
}
/* Can the OP_OPEN_SUBEXP node arrive the OP_CLOSE_SUBEXP node
in the current context? */
err = check_arrival (mctx, sub_top->path, sub_top->node,
sub_top->str_idx, cls_node, sl_str, OP_CLOSE_SUBEXP);
sub_top->str_idx, cls_node, sl_str,
OP_CLOSE_SUBEXP);
if (err == REG_NOMATCH)
continue;
if (BE (err != REG_NOERROR, 0))
......@@ -2816,7 +2865,8 @@ get_subexp_sub (re_match_context_t *mctx, const re_sub_match_top_t *sub_top,
Idx to_idx;
/* Can the subexpression arrive the back reference? */
err = check_arrival (mctx, &sub_last->path, sub_last->node,
sub_last->str_idx, bkref_node, bkref_str, OP_OPEN_SUBEXP);
sub_last->str_idx, bkref_node, bkref_str,
OP_OPEN_SUBEXP);
if (err != REG_NOERROR)
return err;
err = match_ctx_add_entry (mctx, bkref_node, bkref_str, sub_top->str_idx,
......@@ -2859,12 +2909,11 @@ find_subexp_node (const re_dfa_t *dfa, const re_node_set *nodes,
static reg_errcode_t
internal_function
check_arrival (re_match_context_t *mctx, state_array_t *path,
Idx top_node, Idx top_str, Idx last_node, Idx last_str,
int type)
check_arrival (re_match_context_t *mctx, state_array_t *path, Idx top_node,
Idx top_str, Idx last_node, Idx last_str, int type)
{
re_dfa_t *const dfa = mctx->dfa;
reg_errcode_t err;
const re_dfa_t *const dfa = mctx->dfa;
reg_errcode_t err = REG_NOERROR;
Idx subexp_num, backup_cur_idx, str_idx, null_cnt;
re_dfastate_t *cur_state = NULL;
re_node_set *cur_nodes, next_nodes;
......@@ -2878,18 +2927,19 @@ check_arrival (re_match_context_t *mctx, state_array_t *path,
re_dfastate_t **new_array;
Idx old_alloc = path->alloc;
Idx new_alloc = old_alloc + last_str + mctx->max_mb_elem_len + 1;
if (BE (new_alloc < old_alloc, 0))
if (BE (new_alloc < old_alloc, 0)
|| BE (SIZE_MAX / sizeof (re_dfastate_t *) < new_alloc, 0))
return REG_ESPACE;
new_array = re_xrealloc (path->array, re_dfastate_t *, new_alloc);
new_array = re_realloc (path->array, re_dfastate_t *, new_alloc);
if (BE (new_array == NULL, 0))
return REG_ESPACE;
path->array = new_array;
path->alloc = new_alloc;
memset (new_array + old_alloc, '\0',
sizeof (re_dfastate_t *) * (new_alloc - old_alloc));
sizeof (re_dfastate_t *) * (path->alloc - old_alloc));
}
str_idx = path->next_idx == 0 ? top_str : path->next_idx;
str_idx = path->next_idx ? path->next_idx : top_str;
/* Temporary modify MCTX. */
backup_state_log = mctx->state_log;
......@@ -2917,7 +2967,7 @@ check_arrival (re_match_context_t *mctx, state_array_t *path,
if (cur_state && cur_state->has_backref)
{
err = re_node_set_init_copy (&next_nodes, &cur_state->nodes);
if (BE ( err != REG_NOERROR, 0))
if (BE (err != REG_NOERROR, 0))
return err;
}
else
......@@ -2929,7 +2979,7 @@ check_arrival (re_match_context_t *mctx, state_array_t *path,
{
err = expand_bkref_cache (mctx, &next_nodes, str_idx,
subexp_num, type);
if (BE ( err != REG_NOERROR, 0))
if (BE (err != REG_NOERROR, 0))
{
re_node_set_free (&next_nodes);
return err;
......@@ -2960,7 +3010,8 @@ check_arrival (re_match_context_t *mctx, state_array_t *path,
if (cur_state)
{
err = check_arrival_add_next_nodes (mctx, str_idx,
&cur_state->non_eps_nodes, &next_nodes);
&cur_state->non_eps_nodes,
&next_nodes);
if (BE (err != REG_NOERROR, 0))
{
re_node_set_free (&next_nodes);
......@@ -2978,7 +3029,7 @@ check_arrival (re_match_context_t *mctx, state_array_t *path,
}
err = expand_bkref_cache (mctx, &next_nodes, str_idx,
subexp_num, type);
if (BE ( err != REG_NOERROR, 0))
if (BE (err != REG_NOERROR, 0))
{
re_node_set_free (&next_nodes);
return err;
......@@ -3021,13 +3072,12 @@ check_arrival (re_match_context_t *mctx, state_array_t *path,
static reg_errcode_t
internal_function
check_arrival_add_next_nodes (re_match_context_t *mctx, Idx str_idx,
re_node_set *cur_nodes,
re_node_set *next_nodes)
re_node_set *cur_nodes, re_node_set *next_nodes)
{
re_dfa_t *const dfa = mctx->dfa;
const re_dfa_t *const dfa = mctx->dfa;
bool ok;
Idx cur_idx;
reg_errcode_t err;
reg_errcode_t err = REG_NOERROR;
re_node_set union_set;
re_node_set_init_empty (&union_set);
for (cur_idx = 0; cur_idx < cur_nodes->nelem; ++cur_idx)
......@@ -3100,7 +3150,7 @@ check_arrival_add_next_nodes (re_match_context_t *mctx, Idx str_idx,
static reg_errcode_t
internal_function
check_arrival_expand_ecl (re_dfa_t *dfa, re_node_set *cur_nodes,
check_arrival_expand_ecl (const re_dfa_t *dfa, re_node_set *cur_nodes,
Idx ex_subexp, int type)
{
reg_errcode_t err;
......@@ -3118,7 +3168,7 @@ check_arrival_expand_ecl (re_dfa_t *dfa, re_node_set *cur_nodes,
for (idx = 0; idx < cur_nodes->nelem; ++idx)
{
Idx cur_node = cur_nodes->elems[idx];
re_node_set *eclosure = dfa->eclosures + cur_node;
const re_node_set *eclosure = dfa->eclosures + cur_node;
outside_node = find_subexp_node (dfa, eclosure, ex_subexp, type);
if (outside_node == REG_MISSING)
{
......@@ -3153,7 +3203,7 @@ check_arrival_expand_ecl (re_dfa_t *dfa, re_node_set *cur_nodes,
static reg_errcode_t
internal_function
check_arrival_expand_ecl_sub (re_dfa_t *dfa, re_node_set *dst_nodes,
check_arrival_expand_ecl_sub (const re_dfa_t *dfa, re_node_set *dst_nodes,
Idx target, Idx ex_subexp, int type)
{
Idx cur_node;
......@@ -3179,12 +3229,12 @@ check_arrival_expand_ecl_sub (re_dfa_t *dfa, re_node_set *dst_nodes,
break;
if (dfa->edests[cur_node].nelem == 2)
{
reg_errcode_t ret =
check_arrival_expand_ecl_sub (dfa, dst_nodes,
dfa->edests[cur_node].elems[1],
ex_subexp, type);
if (BE (ret != REG_NOERROR, 0))
return ret;
reg_errcode_t err;
err = check_arrival_expand_ecl_sub (dfa, dst_nodes,
dfa->edests[cur_node].elems[1],
ex_subexp, type);
if (BE (err != REG_NOERROR, 0))
return err;
}
cur_node = dfa->edests[cur_node].elems[0];
}
......@@ -3201,7 +3251,7 @@ internal_function
expand_bkref_cache (re_match_context_t *mctx, re_node_set *cur_nodes,
Idx cur_str, Idx subexp_num, int type)
{
re_dfa_t *const dfa = mctx->dfa;
const re_dfa_t *const dfa = mctx->dfa;
reg_errcode_t err;
Idx cache_idx_start = search_cur_bkref_entry (mctx, cur_str);
struct re_backref_cache_entry *ent;
......@@ -3287,25 +3337,26 @@ expand_bkref_cache (re_match_context_t *mctx, re_node_set *cur_nodes,
static bool
internal_function
build_trtable (re_dfa_t *dfa, re_dfastate_t *state)
build_trtable (const re_dfa_t *dfa, re_dfastate_t *state)
{
reg_errcode_t err;
Idx i, j;
int ch;
bool need_word_trtable = false;
bitset_word elem, mask;
bool dests_node_malloced = false, dest_states_malloced = false;
bitset_word_t elem, mask;
bool dests_node_malloced = false;
bool dest_states_malloced = false;
Idx ndests; /* Number of the destination states from `state'. */
re_dfastate_t **trtable;
re_dfastate_t **dest_states = NULL, **dest_states_word, **dest_states_nl;
re_node_set follows, *dests_node;
bitset *dests_ch;
bitset acceptable;
bitset_t *dests_ch;
bitset_t acceptable;
struct dests_alloc
{
re_node_set dests_node[SBC_MAX];
bitset dests_ch[SBC_MAX];
bitset_t dests_ch[SBC_MAX];
} *dests_alloc;
/* We build DFA states which corresponds to the destination nodes
......@@ -3313,7 +3364,7 @@ build_trtable (re_dfa_t *dfa, re_dfastate_t *state)
destination state contains, and `dests_ch[i]' represents the
characters which i-th destination state accepts. */
if (__libc_use_alloca (sizeof (struct dests_alloc)))
dests_alloc = (struct dests_alloc *) alloca (sizeof dests_alloc[0]);
dests_alloc = (struct dests_alloc *) alloca (sizeof (struct dests_alloc));
else
{
dests_alloc = re_malloc (struct dests_alloc, 1);
......@@ -3336,7 +3387,8 @@ build_trtable (re_dfa_t *dfa, re_dfastate_t *state)
free (dests_alloc);
if (ndests == 0)
{
state->trtable = re_calloc (re_dfastate_t *, SBC_MAX);
state->trtable = (re_dfastate_t **)
calloc (sizeof (re_dfastate_t *), SBC_MAX);
return true;
}
return false;
......@@ -3347,12 +3399,13 @@ build_trtable (re_dfa_t *dfa, re_dfastate_t *state)
goto out_free;
/* Avoid arithmetic overflow in size calculation. */
if (BE (((SIZE_MAX - (sizeof (re_node_set) + sizeof (bitset)) * SBC_MAX)
/ (3 * sizeof (re_dfastate_t *)))
< ndests, 0))
if (BE ((((SIZE_MAX - (sizeof (re_node_set) + sizeof (bitset_t)) * SBC_MAX)
/ (3 * sizeof (re_dfastate_t *)))
< ndests),
0))
goto out_free;
if (__libc_use_alloca ((sizeof (re_node_set) + sizeof (bitset)) * SBC_MAX
if (__libc_use_alloca ((sizeof (re_node_set) + sizeof (bitset_t)) * SBC_MAX
+ ndests * 3 * sizeof (re_dfastate_t *)))
dest_states = (re_dfastate_t **)
alloca (ndests * 3 * sizeof (re_dfastate_t *));
......@@ -3428,7 +3481,8 @@ out_free:
character, or we are in a single-byte character set so we can
discern by looking at the character code: allocate a
256-entry transition table. */
trtable = state->trtable = re_calloc (re_dfastate_t *, SBC_MAX);
trtable = state->trtable =
(re_dfastate_t **) calloc (sizeof (re_dfastate_t *), SBC_MAX);
if (BE (trtable == NULL, 0))
goto out_free;
......@@ -3458,7 +3512,8 @@ out_free:
by looking at the character code: build two 256-entry
transition tables, one starting at trtable[0] and one
starting at trtable[SBC_MAX]. */
trtable = state->word_trtable = re_calloc (re_dfastate_t *, 2 * SBC_MAX);
trtable = state->word_trtable =
(re_dfastate_t **) calloc (sizeof (re_dfastate_t *), 2 * SBC_MAX);
if (BE (trtable == NULL, 0))
goto out_free;
......@@ -3518,13 +3573,13 @@ out_free:
static Idx
internal_function
group_nodes_into_DFAstates (const re_dfa_t *dfa, const re_dfastate_t *state,
re_node_set *dests_node, bitset *dests_ch)
re_node_set *dests_node, bitset_t *dests_ch)
{
reg_errcode_t err;
bool ok;
Idx i, j, k;
Idx ndests; /* Number of the destinations from `state'. */
bitset accepts; /* Characters a node can accept. */
bitset_t accepts; /* Characters a node can accept. */
const re_node_set *cur_nodes = &state->nodes;
bitset_empty (accepts);
ndests = 0;
......@@ -3551,21 +3606,21 @@ group_nodes_into_DFAstates (const re_dfa_t *dfa, const re_dfastate_t *state,
else
#endif
bitset_set_all (accepts);
if (!(dfa->syntax & REG_DOT_NEWLINE))
if (!(dfa->syntax & RE_DOT_NEWLINE))
bitset_clear (accepts, '\n');
if (dfa->syntax & REG_DOT_NOT_NULL)
if (dfa->syntax & RE_DOT_NOT_NULL)
bitset_clear (accepts, '\0');
}
#ifdef RE_ENABLE_I18N
else if (type == OP_UTF8_PERIOD)
{
if (SBC_MAX / 2 % BITSET_WORD_BITS == 0)
memset (accepts, -1, sizeof accepts / 2);
if (ASCII_CHARS % BITSET_WORD_BITS == 0)
memset (accepts, -1, ASCII_CHARS / CHAR_BIT);
else
bitset_merge (accepts, utf8_sb_map);
if (!(dfa->syntax & REG_DOT_NEWLINE))
if (!(dfa->syntax & RE_DOT_NEWLINE))
bitset_clear (accepts, '\n');
if (dfa->syntax & REG_DOT_NOT_NULL)
if (dfa->syntax & RE_DOT_NOT_NULL)
bitset_clear (accepts, '\0');
}
#endif
......@@ -3593,7 +3648,7 @@ group_nodes_into_DFAstates (const re_dfa_t *dfa, const re_dfastate_t *state,
if (constraint & NEXT_WORD_CONSTRAINT)
{
bitset_word any_set = 0;
bitset_word_t any_set = 0;
if (type == CHARACTER && !node->word_char)
{
bitset_empty (accepts);
......@@ -3612,7 +3667,7 @@ group_nodes_into_DFAstates (const re_dfa_t *dfa, const re_dfastate_t *state,
}
if (constraint & NEXT_NOTWORD_CONSTRAINT)
{
bitset_word any_set = 0;
bitset_word_t any_set = 0;
if (type == CHARACTER && node->word_char)
{
bitset_empty (accepts);
......@@ -3635,10 +3690,10 @@ group_nodes_into_DFAstates (const re_dfa_t *dfa, const re_dfastate_t *state,
state. Above, we make sure that accepts is not empty. */
for (j = 0; j < ndests; ++j)
{
bitset intersec; /* Intersection sets, see below. */
bitset remains;
bitset_t intersec; /* Intersection sets, see below. */
bitset_t remains;
/* Flags, see below. */
bitset_word has_intersec, not_subset, not_consumed;
bitset_word_t has_intersec, not_subset, not_consumed;
/* Optimization, skip if this state doesn't accept the character. */
if (type == CHARACTER && !bitset_contain (dests_ch[j], node->opr.c))
......@@ -3710,7 +3765,7 @@ group_nodes_into_DFAstates (const re_dfa_t *dfa, const re_dfastate_t *state,
static int
internal_function
check_node_accept_bytes (re_dfa_t *dfa, Idx node_idx,
check_node_accept_bytes (const re_dfa_t *dfa, Idx node_idx,
const re_string_t *input, Idx str_idx)
{
const re_token_t *node = dfa->nodes + node_idx;
......@@ -3776,9 +3831,9 @@ check_node_accept_bytes (re_dfa_t *dfa, Idx node_idx,
/* FIXME: I don't think this if is needed, as both '\n'
and '\0' are char_len == 1. */
/* '.' accepts any one character except the following two cases. */
if ((!(dfa->syntax & REG_DOT_NEWLINE) &&
if ((!(dfa->syntax & RE_DOT_NEWLINE) &&
re_string_byte_at (input, str_idx) == '\n') ||
((dfa->syntax & REG_DOT_NOT_NULL) &&
((dfa->syntax & RE_DOT_NOT_NULL) &&
re_string_byte_at (input, str_idx) == '\0'))
return 0;
return char_len;
......@@ -3945,6 +4000,7 @@ check_node_accept_bytes (re_dfa_t *dfa, Idx node_idx,
# ifdef _LIBC
static unsigned int
internal_function
find_collation_sequence_value (const unsigned char *mbs, size_t mbs_len)
{
uint32_t nrules = _NL_CURRENT_WORD (LC_COLLATE, _NL_COLLATE_NRULES);
......@@ -4028,13 +4084,13 @@ check_node_accept (const re_match_context_t *mctx, const re_token_t *node,
#ifdef RE_ENABLE_I18N
case OP_UTF8_PERIOD:
if (ch >= 0x80)
if (ch >= ASCII_CHARS)
return false;
/* FALLTHROUGH */
#endif
case OP_PERIOD:
if ((ch == '\n' && !(mctx->dfa->syntax & REG_DOT_NEWLINE))
|| (ch == '\0' && (mctx->dfa->syntax & REG_DOT_NOT_NULL)))
if ((ch == '\n' && !(mctx->dfa->syntax & RE_DOT_NEWLINE))
|| (ch == '\0' && (mctx->dfa->syntax & RE_DOT_NOT_NULL)))
return false;
break;
......@@ -4064,6 +4120,10 @@ extend_buffers (re_match_context_t *mctx)
reg_errcode_t ret;
re_string_t *pstr = &mctx->input;
/* Avoid overflow. */
if (BE (SIZE_MAX / 2 / sizeof (re_dfastate_t *) <= pstr->bufs_len, 0))
return REG_ESPACE;
/* Double the lengthes of the buffers. */
ret = re_string_realloc_buffers (pstr, pstr->bufs_len * 2);
if (BE (ret != REG_NOERROR, 0))
......@@ -4075,8 +4135,8 @@ extend_buffers (re_match_context_t *mctx)
/* XXX We have no indication of the size of this buffer. If this
allocation fail we have no indication that the state_log array
does not have the right size. */
re_dfastate_t **new_array = re_xrealloc (mctx->state_log, re_dfastate_t *,
pstr->bufs_len + 1);
re_dfastate_t **new_array = re_realloc (mctx->state_log, re_dfastate_t *,
pstr->bufs_len + 1);
if (BE (new_array == NULL, 0))
return REG_ESPACE;
mctx->state_log = new_array;
......@@ -4124,8 +4184,15 @@ match_ctx_init (re_match_context_t *mctx, int eflags, Idx n)
mctx->match_last = REG_MISSING;
if (n > 0)
{
mctx->bkref_ents = re_xmalloc (struct re_backref_cache_entry, n);
mctx->sub_tops = re_xmalloc (re_sub_match_top_t *, n);
/* Avoid overflow. */
size_t max_object_size =
MAX (sizeof (struct re_backref_cache_entry),
sizeof (re_sub_match_top_t *));
if (BE (SIZE_MAX / max_object_size < n, 0))
return REG_ESPACE;
mctx->bkref_ents = re_malloc (struct re_backref_cache_entry, n);
mctx->sub_tops = re_malloc (re_sub_match_top_t *, n);
if (BE (mctx->bkref_ents == NULL || mctx->sub_tops == NULL, 0))
return REG_ESPACE;
}
......@@ -4191,14 +4258,14 @@ match_ctx_free (re_match_context_t *mctx)
static reg_errcode_t
internal_function
match_ctx_add_entry (re_match_context_t *mctx, Idx node, Idx str_idx,
Idx from, Idx to)
match_ctx_add_entry (re_match_context_t *mctx, Idx node, Idx str_idx, Idx from,
Idx to)
{
if (mctx->nbkref_ents >= mctx->abkref_ents)
{
struct re_backref_cache_entry* new_entry;
new_entry = re_x2realloc (mctx->bkref_ents, struct re_backref_cache_entry,
&mctx->abkref_ents);
new_entry = re_realloc (mctx->bkref_ents, struct re_backref_cache_entry,
mctx->abkref_ents * 2);
if (BE (new_entry == NULL, 0))
{
re_free (mctx->bkref_ents);
......@@ -4206,8 +4273,8 @@ match_ctx_add_entry (re_match_context_t *mctx, Idx node, Idx str_idx,
}
mctx->bkref_ents = new_entry;
memset (mctx->bkref_ents + mctx->nbkref_ents, '\0',
(sizeof (struct re_backref_cache_entry)
* (mctx->abkref_ents - mctx->nbkref_ents)));
sizeof (struct re_backref_cache_entry) * mctx->abkref_ents);
mctx->abkref_ents *= 2;
}
if (mctx->nbkref_ents > 0
&& mctx->bkref_ents[mctx->nbkref_ents - 1].str_idx == str_idx)
......@@ -4271,16 +4338,16 @@ match_ctx_add_subtop (re_match_context_t *mctx, Idx node, Idx str_idx)
#endif
if (BE (mctx->nsub_tops == mctx->asub_tops, 0))
{
Idx new_asub_tops = mctx->asub_tops;
re_sub_match_top_t **new_array = re_x2realloc (mctx->sub_tops,
re_sub_match_top_t *,
&new_asub_tops);
Idx new_asub_tops = mctx->asub_tops * 2;
re_sub_match_top_t **new_array = re_realloc (mctx->sub_tops,
re_sub_match_top_t *,
new_asub_tops);
if (BE (new_array == NULL, 0))
return REG_ESPACE;
mctx->sub_tops = new_array;
mctx->asub_tops = new_asub_tops;
}
mctx->sub_tops[mctx->nsub_tops] = re_calloc (re_sub_match_top_t, 1);
mctx->sub_tops[mctx->nsub_tops] = calloc (1, sizeof (re_sub_match_top_t));
if (BE (mctx->sub_tops[mctx->nsub_tops] == NULL, 0))
return REG_ESPACE;
mctx->sub_tops[mctx->nsub_tops]->node = node;
......@@ -4298,16 +4365,16 @@ match_ctx_add_sublast (re_sub_match_top_t *subtop, Idx node, Idx str_idx)
re_sub_match_last_t *new_entry;
if (BE (subtop->nlasts == subtop->alasts, 0))
{
Idx new_alasts = subtop->alasts;
re_sub_match_last_t **new_array = re_x2realloc (subtop->lasts,
re_sub_match_last_t *,
&new_alasts);
Idx new_alasts = 2 * subtop->alasts + 1;
re_sub_match_last_t **new_array = re_realloc (subtop->lasts,
re_sub_match_last_t *,
new_alasts);
if (BE (new_array == NULL, 0))
return NULL;
subtop->lasts = new_array;
subtop->alasts = new_alasts;
}
new_entry = re_calloc (re_sub_match_last_t, 1);
new_entry = calloc (1, sizeof (re_sub_match_last_t));
if (BE (new_entry != NULL, 1))
{
subtop->lasts[subtop->nlasts] = new_entry;
......@@ -4320,10 +4387,8 @@ match_ctx_add_sublast (re_sub_match_top_t *subtop, Idx node, Idx str_idx)
static void
internal_function
sift_ctx_init (re_sift_context_t *sctx,
re_dfastate_t **sifted_sts,
re_dfastate_t **limited_sts,
Idx last_node, Idx last_str_idx)
sift_ctx_init (re_sift_context_t *sctx, re_dfastate_t **sifted_sts,
re_dfastate_t **limited_sts, Idx last_node, Idx last_str_idx)
{
sctx->sifted_states = sifted_sts;
sctx->limited_states = limited_sts;
......
/* size_max.h -- declare SIZE_MAX through system headers
Copyright (C) 2005 Free Software Foundation, Inc.
Copyright (C) 2005-2006 Free Software Foundation, Inc.
Written by Simon Josefsson.
This program is free software; you can redistribute it and/or modify
......@@ -19,9 +19,13 @@
#ifndef GNULIB_SIZE_MAX_H
#define GNULIB_SIZE_MAX_H
/* Get SIZE_MAX declaration on systems like Solaris 7/8/9. */
# include <limits.h>
/* Get SIZE_MAX declaration on systems like glibc 2. */
# if HAVE_STDINT_H
# include <stdint.h>
# endif
/* On systems where these include files don't define it, SIZE_MAX is defined
in config.h. */
#endif /* GNULIB_SIZE_MAX_H */
......
/* Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc.
/* Copyright (C) 2001, 2002, 2003, 2006 Free Software Foundation, Inc.
Written by Bruno Haible <haible@clisp.cons.org>, 2001.
This program is free software; you can redistribute it and/or modify
......@@ -70,18 +70,40 @@
(see ISO C 99 6.7.2.2.(4)); however, '_Bool' must promote to 'int'
(see ISO C 99 6.3.1.1.(2)). So we add a negative value to the
enum; this ensures that '_Bool' promotes to 'int'. */
#if !(defined __cplusplus || defined __BEOS__)
#if defined __cplusplus || defined __BEOS__
/* A compiler known to have 'bool'. */
/* If the compiler already has both 'bool' and '_Bool', we can assume they
are the same types. */
# if !@HAVE__BOOL@
# if defined __SUNPRO_C && (__SUNPRO_C < 0x550 || __STDC__ == 1)
/* Avoid stupid "warning: _Bool is a keyword in ISO C99". */
# define _Bool signed char
typedef bool _Bool;
# endif
#else
# if !defined __GNUC__
/* If @HAVE__BOOL@:
Some HP-UX cc and AIX IBM C compiler versions have compiler bugs when
the built-in _Bool type is used. See
http://gcc.gnu.org/ml/gcc-patches/2003-12/msg02303.html
http://lists.gnu.org/archive/html/bug-coreutils/2005-11/msg00161.html
http://lists.gnu.org/archive/html/bug-coreutils/2005-10/msg00086.html
Similar bugs are likely with other compilers as well; this file
wouldn't be used if <stdbool.h> was working.
So we override the _Bool type.
If !@HAVE__BOOL@:
Need to define _Bool ourselves. As 'signed char' or as an enum type?
Use of a typedef, with SunPRO C, leads to a stupid
"warning: _Bool is a keyword in ISO C99".
Use of an enum type, with IRIX cc, leads to a stupid
"warning(1185): enumerated type mixed with another type".
The only benefit of the enum type, debuggability, is not important
with these compilers. So use 'signed char' and no typedef. */
# define _Bool signed char
enum { false = 0, true = 1 };
# else
# else
/* With this compiler, trust the _Bool type if the compiler has it. */
# if !@HAVE__BOOL@
typedef enum { _Bool_must_promote_to_int = -1, false = 0, true = 1 } _Bool;
# endif
# endif
#else
typedef bool _Bool;
#endif
#define bool _Bool
......
......@@ -21,135 +21,256 @@
/*
* ISO C 99 <stdint.h> for platforms that lack it.
* <http://www.opengroup.org/onlinepubs/007904975/basedefs/stdint.h.html>
* <http://www.opengroup.org/susv3xbd/stdint.h.html>
*/
/* Get wchar_t, WCHAR_MIN, WCHAR_MAX. */
#include <stddef.h>
/* Get CHAR_BIT, LONG_MIN, LONG_MAX, ULONG_MAX. */
/* BSD/OS 4.2 defines WCHAR_MIN, WCHAR_MAX in <wchar.h>, not <stddef.h>. */
#if !(defined(WCHAR_MIN) && defined(WCHAR_MAX)) && @HAVE_WCHAR_H@
# include <wchar.h>
#endif
/* Get LONG_MIN, LONG_MAX, ULONG_MAX. */
#include <limits.h>
/* Get those types that are already defined in other system include files. */
#if defined(__FreeBSD__)
#if defined(__FreeBSD__) && (__FreeBSD__ >= 3) && (__FreeBSD__ <= 4)
# include <sys/inttypes.h>
#endif
#if defined(__linux__) && HAVE_SYS_BITYPES_H
#if defined(__OpenBSD__) || defined(__bsdi__) || defined(__sgi)
/* In OpenBSD 3.8, <sys/types.h> includes <machine/types.h>, which defines
int{8,16,32,64}_t, uint{8,16,32,64}_t and __BIT_TYPES_DEFINED__.
<inttypes.h> includes <machine/types.h> and also defines intptr_t and
uintptr_t. */
/* BSD/OS 4.2 is similar, but doesn't have <inttypes.h> */
/* IRIX 6.5 has <inttypes.h>, and <sys/types.h> defines some of these
types as well. */
# include <sys/types.h>
# if @HAVE_INTTYPES_H@
# include @FULL_PATH_INTTYPES_H@
# endif
#endif
#if defined(__linux__) && @HAVE_SYS_BITYPES_H@
/* Linux libc4 >= 4.6.7 and libc5 have a <sys/bitypes.h> that defines
int{8,16,32,64}_t and __BIT_TYPES_DEFINED__. In libc5 >= 5.2.2 it is
included by <sys/types.h>. */
# include <sys/bitypes.h>
#endif
#if defined(__sun) && HAVE_SYS_INTTYPES_H
# include <sys/inttypes.h>
#if defined(__sun) && @HAVE_SYS_INTTYPES_H@
/* Solaris 7 <sys/inttypes.h> has the types except the *_fast*_t types, and
the macros except for *_FAST*_*, INTPTR_MIN, PTRDIFF_MIN, PTRDIFF_MAX.
But note that <sys/int_types.h> contains only the type definitions! */
# define _STDINT_H_HAVE_SYSTEM_INTTYPES
# include <sys/inttypes.h>
#endif
#if (defined(__hpux) || defined(_AIX)) && HAVE_INTTYPES_H
# include <inttypes.h>
#if (defined(__hpux) || defined(_AIX)) && @HAVE_INTTYPES_H@
/* HP-UX 10 <inttypes.h> has nearly everything, except UINT_LEAST8_MAX,
UINT_FAST8_MAX, PTRDIFF_MIN, PTRDIFF_MAX. */
/* AIX 4 <inttypes.h> has nearly everything, except INTPTR_MIN, INTPTR_MAX,
UINTPTR_MAX, PTRDIFF_MIN, PTRDIFF_MAX. */
# define _STDINT_H_HAVE_SYSTEM_INTTYPES
# include @FULL_PATH_INTTYPES_H@
#endif
#if !((defined(UNIX_CYGWIN32) || defined(__linux__)) && defined(__BIT_TYPES_DEFINED__))
# define _STDINT_H_NEED_SIGNED_INT_TYPES
#if @HAVE_STDINT_H@
/* Other systems may have an incomplete <stdint.h>. */
/* On some versions of IRIX, the SGI C compiler comes with an <stdint.h>,
but
- in c99 mode, <inttypes.h> includes <stdint.h>,
- in c89 mode, <stdint.h> spews warnings and defines nothing.
<inttypes.h> defines only a subset of the types and macros that
<stdint.h> would define in c99 mode.
So we rely only on <inttypes.h> (included above). It means that in
c89 mode, we shadow the contents of warning-spewing <stdint.h>. */
# if !(defined(__sgi) && @HAVE_INTTYPES_H@ && !defined(__c99))
# include @FULL_PATH_STDINT_H@
# endif
#endif
#if !defined(_STDINT_H_HAVE_SYSTEM_INTTYPES)
/* 7.18.1.1. Exact-width integer types */
#if !defined(__FreeBSD__)
/* Here we assume a standard architecture where the hardware integer
types have 8, 16, 32, optionally 64 bits. */
#ifdef _STDINT_H_NEED_SIGNED_INT_TYPES
#if !@HAVE_INT8_T@
typedef signed char int8_t;
#endif
#if !@HAVE_UINT8_T@
typedef unsigned char uint8_t;
# define _UINT8_T /* avoid collision with Solaris 2.5.1 <pthread.h> */
#endif
#ifdef _STDINT_H_NEED_SIGNED_INT_TYPES
#if !@HAVE_INT16_T@
typedef short int16_t;
#endif
#if !@HAVE_UINT16_T@
typedef unsigned short uint16_t;
#endif
#ifdef _STDINT_H_NEED_SIGNED_INT_TYPES
#if !@HAVE_INT32_T@
typedef int int32_t;
#endif
#if !@HAVE_UINT32_T@
typedef unsigned int uint32_t;
# define _UINT32_T /* avoid collision with Solaris 2.5.1 <pthread.h> */
#endif
#if @HAVE_LONG_64BIT@
#ifdef _STDINT_H_NEED_SIGNED_INT_TYPES
#if @HAVE_INT64_T@
# define _STDINT_H_HAVE_INT64 1
#else
# if @HAVE_LONG_64BIT@
typedef long int64_t;
# define _STDINT_H_HAVE_INT64 1
# elif @HAVE_LONG_LONG_64BIT@
typedef long long int64_t;
# define _STDINT_H_HAVE_INT64 1
# elif defined _MSC_VER
typedef __int64 int64_t;
# define _STDINT_H_HAVE_INT64 1
# endif
#endif
typedef unsigned long uint64_t;
#define _STDINT_H_HAVE_INT64
#elif @HAVE_LONG_LONG_64BIT@
#ifdef _STDINT_H_NEED_SIGNED_INT_TYPES
typedef long long int64_t;
#endif
#if @HAVE_UINT64_T@
# define _STDINT_H_HAVE_UINT64 1
#else
# if @HAVE_LONG_64BIT@
typedef unsigned long uint64_t;
# define _STDINT_H_HAVE_UINT64 1
# elif @HAVE_LONG_LONG_64BIT@
typedef unsigned long long uint64_t;
#define _STDINT_H_HAVE_INT64
#elif defined(_MSC_VER)
typedef __int64 int64_t;
typedef unsigned __int64 uint64_t;
#define _STDINT_H_HAVE_INT64
# define _UINT64_T /* avoid collision with Solaris 2.5.1 <pthread.h> */
# define _STDINT_H_HAVE_UINT64 1
# elif defined _MSC_VER
typedef unsigned __int64 uint64_t;
# define _STDINT_H_HAVE_UINT64 1
# endif
#endif
#endif /* !FreeBSD */
/* 7.18.1.2. Minimum-width integer types */
/* Here we assume a standard architecture where the hardware integer
types have 8, 16, 32, optionally 64 bits. Therefore the leastN_t types
are the same as the corresponding N_t types. */
#if !@HAVE_INT_LEAST8_T@
typedef int8_t int_least8_t;
#endif
#if !@HAVE_UINT_LEAST8_T@
typedef uint8_t uint_least8_t;
#endif
#if !@HAVE_INT_LEAST16_T@
typedef int16_t int_least16_t;
#endif
#if !@HAVE_UINT_LEAST16_T@
typedef uint16_t uint_least16_t;
#endif
#if !@HAVE_INT_LEAST32_T@
typedef int32_t int_least32_t;
#endif
#if !@HAVE_UINT_LEAST32_T@
typedef uint32_t uint_least32_t;
#ifdef _STDINT_H_HAVE_INT64
#endif
#if !@HAVE_INT_LEAST64_T@ && _STDINT_H_HAVE_INT64
typedef int64_t int_least64_t;
#endif
#if !@HAVE_UINT_LEAST64_T@ && _STDINT_H_HAVE_UINT64
typedef uint64_t uint_least64_t;
#endif
/* 7.18.1.3. Fastest minimum-width integer types */
/* Note: Other <stdint.h> substitutes may define these types differently.
It is not recommended to use these types in public header files. */
/* Here we assume a standard architecture where the hardware integer
types have 8, 16, 32, optionally 64 bits. Therefore the fastN_t types
are taken from the same list of types. */
/* On alpha processors, int32_t variables are slower than int64_t variables,
due to the necessary zap instructions. */
#if defined __alpha
# define _STDINT_H_INT64_FASTER_THAN_INT32 1
#endif
#if !@HAVE_INT_FAST8_T@
# if _STDINT_H_INT64_FASTER_THAN_INT32
typedef int64_t int_fast8_t;
# else
typedef int32_t int_fast8_t;
# endif
#endif
#if !@HAVE_UINT_FAST8_T@
# if _STDINT_H_INT64_FASTER_THAN_INT32
typedef uint64_t uint_fast8_t;
# else
typedef uint32_t uint_fast8_t;
# endif
#endif
#if !@HAVE_INT_FAST16_T@
# if _STDINT_H_INT64_FASTER_THAN_INT32
typedef int64_t int_fast16_t;
# else
typedef int32_t int_fast16_t;
# endif
#endif
#if !@HAVE_UINT_FAST16_T@
# if _STDINT_H_INT64_FASTER_THAN_INT32
typedef uint64_t uint_fast16_t;
# else
typedef uint32_t uint_fast16_t;
# endif
#endif
#if !@HAVE_INT_FAST32_T@
# if _STDINT_H_INT64_FASTER_THAN_INT32
typedef int64_t int_fast32_t;
# else
typedef int32_t int_fast32_t;
# endif
#endif
#if !@HAVE_UINT_FAST32_T@
# if _STDINT_H_INT64_FASTER_THAN_INT32
typedef uint64_t uint_fast32_t;
# else
typedef uint32_t uint_fast32_t;
#ifdef _STDINT_H_HAVE_INT64
# endif
#endif
#if !@HAVE_INT_FAST64_T@ && _STDINT_H_HAVE_INT64
typedef int64_t int_fast64_t;
#endif
#if !@HAVE_UINT_FAST64_T@ && _STDINT_H_HAVE_UINT64
typedef uint64_t uint_fast64_t;
#endif
/* 7.18.1.4. Integer types capable of holding object pointers */
#if !defined(__FreeBSD__)
/* On some platforms (like IRIX6 MIPS with -n32) sizeof(void*) < sizeof(long),
but this doesn't matter here. */
#if !@HAVE_INTPTR_T@
typedef long intptr_t;
#endif
#if !@HAVE_UINTPTR_T@
typedef unsigned long uintptr_t;
#endif /* !FreeBSD */
#endif
/* 7.18.1.5. Greatest-width integer types */
#ifdef _STDINT_H_HAVE_INT64
# ifndef intmax_t
/* Note: These types are compiler dependent. It may be unwise to use them in
public header files. */
#if !@HAVE_INTMAX_T@
# ifdef _STDINT_H_HAVE_INT64
typedef int64_t intmax_t;
# endif
# ifndef uintmax_t
typedef uint64_t uintmax_t;
# endif
#else
# ifndef intmax_t
# else
typedef int32_t intmax_t;
# endif
# ifndef uintmax_t
#endif
#if !@HAVE_UINTMAX_T@
# ifdef _STDINT_H_HAVE_UINT64
typedef uint64_t uintmax_t;
# else
typedef uint32_t uintmax_t;
# endif
#endif
......@@ -160,96 +281,659 @@ typedef uint32_t uintmax_t;
/* 7.18.2.1. Limits of exact-width integer types */
#define INT8_MIN -128
#define INT8_MAX 127
#define UINT8_MAX 255U
#define INT16_MIN -32768
#define INT16_MAX 32767
#define UINT16_MAX 65535U
#define INT32_MIN (~INT32_MAX)
#define INT32_MAX 2147483647
#define UINT32_MAX 4294967295U
#ifdef _STDINT_H_HAVE_INT64
#define INT64_MIN (~INT64_MAX)
#if @HAVE_LONG_64BIT@
#define INT64_MAX 9223372036854775807L
#define UINT64_MAX 18446744073709551615UL
#elif @HAVE_LONG_LONG_64BIT@
#define INT64_MAX 9223372036854775807LL
#define UINT64_MAX 18446744073709551615ULL
#elif defined(_MSC_VER)
#define INT64_MAX 9223372036854775807i64
#define UINT64_MAX 18446744073709551615ui64
/* Here we assume a standard architecture where the hardware integer
types have 8, 16, 32, optionally 64 bits. */
#if @HAVE_INT8_T@
# ifndef INT8_MIN
# define INT8_MIN (-1 << (@BITSIZEOF_INT8_T@ - 1))
# endif
#else
# define INT8_MIN -128
#endif
#if @HAVE_INT8_T@
# ifndef INT8_MAX
# define INT8_MAX (~ (-1 << (@BITSIZEOF_INT8_T@ - 1)))
# endif
#else
# define INT8_MAX 127
#endif
#if @HAVE_UINT8_T@
# ifndef UINT8_MAX
# if @BITSIZEOF_UINT8_T@ < @BITSIZEOF_UNSIGNED_INT@
# define UINT8_MAX (((1 << (@BITSIZEOF_UINT8_T@ - 1)) - 1) * 2 + 1)
# else
# define UINT8_MAX (((1U << (@BITSIZEOF_UINT8_T@ - 1)) - 1) * 2 + 1)
# endif
# endif
#else
# define UINT8_MAX 255
#endif
#if @HAVE_INT16_T@
# ifndef INT16_MIN
# define INT16_MIN (-1 << (@BITSIZEOF_INT16_T@ - 1))
# endif
#else
# define INT16_MIN -32768
#endif
#if @HAVE_INT16_T@
# ifndef INT16_MAX
# define INT16_MAX (~ (-1 << (@BITSIZEOF_INT16_T@ - 1)))
# endif
#else
# define INT16_MAX 32767
#endif
#if @HAVE_UINT16_T@
# ifndef UINT16_MAX
# if @BITSIZEOF_UINT16_T@ < @BITSIZEOF_UNSIGNED_INT@
# define UINT16_MAX (((1 << (@BITSIZEOF_UINT16_T@ - 1)) - 1) * 2 + 1)
# else
# define UINT16_MAX (((1U << (@BITSIZEOF_UINT16_T@ - 1)) - 1) * 2 + 1)
# endif
# endif
#else
# define UINT16_MAX 65535
#endif
#if @HAVE_INT32_T@
# ifndef INT32_MIN
# define INT32_MIN (-1 << (@BITSIZEOF_INT32_T@ - 1))
# endif
#else
# define INT32_MIN (~INT32_MAX)
#endif
#if @HAVE_INT32_T@
# ifndef INT32_MAX
# define INT32_MAX (~ (-1 << (@BITSIZEOF_INT32_T@ - 1)))
# endif
#else
# define INT32_MAX 2147483647
#endif
#if @HAVE_UINT32_T@
# ifndef UINT32_MAX
# if @BITSIZEOF_UINT32_T@ < @BITSIZEOF_UNSIGNED_INT@
# define UINT32_MAX (((1 << (@BITSIZEOF_UINT32_T@ - 1)) - 1) * 2 + 1)
# else
# define UINT32_MAX (((1U << (@BITSIZEOF_UINT32_T@ - 1)) - 1) * 2 + 1)
# endif
# endif
#else
# define UINT32_MAX 4294967295U
#endif
#if @HAVE_INT64_T@
# ifndef INT64_MIN
# if @HAVE_LONG_64BIT@
# define INT64_MIN (-1L << (@BITSIZEOF_INT64_T@ - 1))
# elif @HAVE_LONG_LONG_64BIT@
# define INT64_MIN (-1LL << (@BITSIZEOF_INT64_T@ - 1))
# elif defined _MSC_VER
# define INT64_MIN (-1i64 << (@BITSIZEOF_INT64_T@ - 1))
# endif
# endif
#else
# ifdef _STDINT_H_HAVE_INT64
# define INT64_MIN (~INT64_MAX)
# endif
#endif
#if @HAVE_INT64_T@
# ifndef INT64_MAX
# if @HAVE_LONG_64BIT@
# define INT64_MAX (~ (-1L << (@BITSIZEOF_INT64_T@ - 1)))
# elif @HAVE_LONG_LONG_64BIT@
# define INT64_MAX (~ (-1LL << (@BITSIZEOF_INT64_T@ - 1)))
# elif defined _MSC_VER
# define INT64_MAX (~ (-1i64 << (@BITSIZEOF_INT64_T@ - 1)))
# endif
# endif
#else
# ifdef _STDINT_H_HAVE_INT64
# if @HAVE_LONG_64BIT@
# define INT64_MAX 9223372036854775807L
# elif @HAVE_LONG_LONG_64BIT@
# define INT64_MAX 9223372036854775807LL
# elif defined _MSC_VER
# define INT64_MAX 9223372036854775807i64
# endif
# endif
#endif
#if @HAVE_UINT64_T@
# ifndef UINT64_MAX
# if @HAVE_LONG_64BIT@
# define UINT64_MAX (((1UL << (@BITSIZEOF_UINT64_T@ - 1)) - 1) * 2 + 1)
# elif @HAVE_LONG_LONG_64BIT@
# define UINT64_MAX (((1ULL << (@BITSIZEOF_UINT64_T@ - 1)) - 1) * 2 + 1)
# elif defined _MSC_VER
# define UINT64_MAX (((1ui64 << (@BITSIZEOF_UINT64_T@ - 1)) - 1) * 2 + 1)
# endif
# endif
#else
# ifdef _STDINT_H_HAVE_UINT64
# if @HAVE_LONG_64BIT@
# define UINT64_MAX 18446744073709551615UL
# elif @HAVE_LONG_LONG_64BIT@
# define UINT64_MAX 18446744073709551615ULL
# elif defined _MSC_VER
# define UINT64_MAX 18446744073709551615ui64
# endif
# endif
#endif
/* 7.18.2.2. Limits of minimum-width integer types */
#define INT_LEAST8_MIN INT8_MIN
#define INT_LEAST8_MAX INT8_MAX
#define UINT_LEAST8_MAX UINT8_MAX
#define INT_LEAST16_MIN INT16_MIN
#define INT_LEAST16_MAX INT16_MAX
#define UINT_LEAST16_MAX UINT16_MAX
#define INT_LEAST32_MIN INT32_MIN
#define INT_LEAST32_MAX INT32_MAX
#define UINT_LEAST32_MAX UINT32_MAX
#ifdef _STDINT_H_HAVE_INT64
#define INT_LEAST64_MIN INT64_MIN
#define INT_LEAST64_MAX INT64_MAX
#define UINT_LEAST64_MAX UINT64_MAX
/* Here we assume a standard architecture where the hardware integer
types have 8, 16, 32, optionally 64 bits. Therefore the leastN_t types
are the same as the corresponding N_t types. */
#if @HAVE_INT_LEAST8_T@
# ifndef INT_LEAST8_MIN
# define INT_LEAST8_MIN (-1 << (@BITSIZEOF_INT_LEAST8_T@ - 1))
# endif
#else
# define INT_LEAST8_MIN INT8_MIN
#endif
#if @HAVE_INT_LEAST8_T@
# ifndef INT_LEAST8_MAX
# define INT_LEAST8_MAX (~ (-1 << (@BITSIZEOF_INT_LEAST8_T@ - 1)))
# endif
#else
# define INT_LEAST8_MAX INT8_MAX
#endif
#if @HAVE_UINT_LEAST8_T@
# ifndef UINT_LEAST8_MAX
# if @BITSIZEOF_UINT_LEAST8_T@ < @BITSIZEOF_UNSIGNED_INT@
# define UINT_LEAST8_MAX (((1 << (@BITSIZEOF_UINT_LEAST8_T@ - 1)) - 1) * 2 + 1)
# else
# define UINT_LEAST8_MAX (((1U << (@BITSIZEOF_UINT_LEAST8_T@ - 1)) - 1) * 2 + 1)
# endif
# endif
#else
# define UINT_LEAST8_MAX UINT8_MAX
#endif
#if @HAVE_INT_LEAST16_T@
# ifndef INT_LEAST16_MIN
# define INT_LEAST16_MIN (-1 << (@BITSIZEOF_INT_LEAST16_T@ - 1))
# endif
#else
# define INT_LEAST16_MIN INT16_MIN
#endif
#if @HAVE_INT_LEAST16_T@
# ifndef INT_LEAST16_MAX
# define INT_LEAST16_MAX (~ (-1 << (@BITSIZEOF_INT_LEAST16_T@ - 1)))
# endif
#else
# define INT_LEAST16_MAX INT16_MAX
#endif
#if @HAVE_UINT_LEAST16_T@
# ifndef UINT_LEAST16_MAX
# if @BITSIZEOF_UINT_LEAST16_T@ < @BITSIZEOF_UNSIGNED_INT@
# define UINT_LEAST16_MAX (((1 << (@BITSIZEOF_UINT_LEAST16_T@ - 1)) - 1) * 2 + 1)
# else
# define UINT_LEAST16_MAX (((1U << (@BITSIZEOF_UINT_LEAST16_T@ - 1)) - 1) * 2 + 1)
# endif
# endif
#else
# define UINT_LEAST16_MAX UINT16_MAX
#endif
#if @HAVE_INT_LEAST32_T@
# ifndef INT_LEAST32_MIN
# define INT_LEAST32_MIN (-1 << (@BITSIZEOF_INT_LEAST32_T@ - 1))
# endif
#else
# define INT_LEAST32_MIN INT32_MIN
#endif
#if @HAVE_INT_LEAST32_T@
# ifndef INT_LEAST32_MAX
# define INT_LEAST32_MAX (~ (-1 << (@BITSIZEOF_INT_LEAST32_T@ - 1)))
# endif
#else
# define INT_LEAST32_MAX INT32_MAX
#endif
#if @HAVE_UINT_LEAST32_T@
# ifndef UINT_LEAST32_MAX
# if @BITSIZEOF_UINT_LEAST32_T@ < @BITSIZEOF_UNSIGNED_INT@
# define UINT_LEAST32_MAX (((1 << (@BITSIZEOF_UINT_LEAST32_T@ - 1)) - 1) * 2 + 1)
# else
# define UINT_LEAST32_MAX (((1U << (@BITSIZEOF_UINT_LEAST32_T@ - 1)) - 1) * 2 + 1)
# endif
# endif
#else
# define UINT_LEAST32_MAX UINT32_MAX
#endif
#if @HAVE_INT_LEAST64_T@
# ifndef INT_LEAST64_MIN
# if @HAVE_LONG_64BIT@
# define INT_LEAST64_MIN (-1L << (@BITSIZEOF_INT_LEAST64_T@ - 1))
# elif @HAVE_LONG_LONG_64BIT@
# define INT_LEAST64_MIN (-1LL << (@BITSIZEOF_INT_LEAST64_T@ - 1))
# elif defined _MSC_VER
# define INT_LEAST64_MIN (-1i64 << (@BITSIZEOF_INT_LEAST64_T@ - 1))
# endif
# endif
#else
# ifdef _STDINT_H_HAVE_INT64
# define INT_LEAST64_MIN INT64_MIN
# endif
#endif
#if @HAVE_INT_LEAST64_T@
# ifndef INT_LEAST64_MAX
# if @HAVE_LONG_64BIT@
# define INT_LEAST64_MAX (~ (-1L << (@BITSIZEOF_INT_LEAST64_T@ - 1)))
# elif @HAVE_LONG_LONG_64BIT@
# define INT_LEAST64_MAX (~ (-1LL << (@BITSIZEOF_INT_LEAST64_T@ - 1)))
# elif defined _MSC_VER
# define INT_LEAST64_MAX (~ (-1i64 << (@BITSIZEOF_INT_LEAST64_T@ - 1)))
# endif
# endif
#else
# ifdef _STDINT_H_HAVE_INT64
# define INT_LEAST64_MAX INT64_MAX
# endif
#endif
#if @HAVE_UINT_LEAST64_T@
# ifndef UINT_LEAST64_MAX
# if @HAVE_LONG_64BIT@
# define UINT_LEAST64_MAX (((1UL << (@BITSIZEOF_UINT_LEAST64_T@ - 1)) - 1) * 2 + 1)
# elif @HAVE_LONG_LONG_64BIT@
# define UINT_LEAST64_MAX (((1ULL << (@BITSIZEOF_UINT_LEAST64_T@ - 1)) - 1) * 2 + 1)
# elif defined _MSC_VER
# define UINT_LEAST64_MAX (((1ui64 << (@BITSIZEOF_UINT_LEAST64_T@ - 1)) - 1) * 2 + 1)
# endif
# endif
#else
# ifdef _STDINT_H_HAVE_UINT64
# define UINT_LEAST64_MAX UINT64_MAX
# endif
#endif
/* 7.18.2.3. Limits of fastest minimum-width integer types */
#define INT_FAST8_MIN INT32_MIN
#define INT_FAST8_MAX INT32_MAX
#define UINT_FAST8_MAX UINT32_MAX
#define INT_FAST16_MIN INT32_MIN
#define INT_FAST16_MAX INT32_MAX
#define UINT_FAST16_MAX UINT32_MAX
#define INT_FAST32_MIN INT32_MIN
#define INT_FAST32_MAX INT32_MAX
#define UINT_FAST32_MAX UINT32_MAX
#ifdef _STDINT_H_HAVE_INT64
#define INT_FAST64_MIN INT64_MIN
#define INT_FAST64_MAX INT64_MAX
#define UINT_FAST64_MAX UINT64_MAX
/* Here we assume a standard architecture where the hardware integer
types have 8, 16, 32, optionally 64 bits. Therefore the fastN_t types
are taken from the same list of types. */
#if @HAVE_INT_FAST8_T@
# ifndef INT_FAST8_MIN
# define INT_FAST8_MIN (-1L << (@BITSIZEOF_INT_FAST8_T@ - 1))
# endif
#else
# if _STDINT_H_INT64_FASTER_THAN_INT32
# define INT_FAST8_MIN INT64_MIN
# else
# define INT_FAST8_MIN INT32_MIN
# endif
#endif
#if @HAVE_INT_FAST8_T@
# ifndef INT_FAST8_MAX
# define INT_FAST8_MAX (~ (-1L << (@BITSIZEOF_INT_FAST8_T@ - 1)))
# endif
#else
# if _STDINT_H_INT64_FASTER_THAN_INT32
# define INT_FAST8_MAX INT64_MAX
# else
# define INT_FAST8_MAX INT32_MAX
# endif
#endif
#if @HAVE_UINT_FAST8_T@
# ifndef UINT_FAST8_MAX
# if @BITSIZEOF_UINT_FAST8_T@ < @BITSIZEOF_UNSIGNED_INT@
# define UINT_FAST8_MAX (((1 << (@BITSIZEOF_UINT_FAST8_T@ - 1)) - 1) * 2 + 1)
# else
# define UINT_FAST8_MAX (((1UL << (@BITSIZEOF_UINT_FAST8_T@ - 1)) - 1) * 2 + 1)
# endif
# endif
#else
# if _STDINT_H_INT64_FASTER_THAN_INT32
# define UINT_FAST8_MAX UINT64_MAX
# else
# define UINT_FAST8_MAX UINT32_MAX
# endif
#endif
#if @HAVE_INT_FAST16_T@
# ifndef INT_FAST16_MIN
# define INT_FAST16_MIN (-1L << (@BITSIZEOF_INT_FAST16_T@ - 1))
# endif
#else
# if _STDINT_H_INT64_FASTER_THAN_INT32
# define INT_FAST16_MIN INT64_MIN
# else
# define INT_FAST16_MIN INT32_MIN
# endif
#endif
#if @HAVE_INT_FAST16_T@
# ifndef INT_FAST16_MAX
# define INT_FAST16_MAX (~ (-1L << (@BITSIZEOF_INT_FAST16_T@ - 1)))
# endif
#else
# if _STDINT_H_INT64_FASTER_THAN_INT32
# define INT_FAST16_MAX INT64_MAX
# else
# define INT_FAST16_MAX INT32_MAX
# endif
#endif
#if @HAVE_UINT_FAST16_T@
# ifndef UINT_FAST16_MAX
# if @BITSIZEOF_UINT_FAST16_T@ < @BITSIZEOF_UNSIGNED_INT@
# define UINT_FAST16_MAX (((1 << (@BITSIZEOF_UINT_FAST16_T@ - 1)) - 1) * 2 + 1)
# else
# define UINT_FAST16_MAX (((1UL << (@BITSIZEOF_UINT_FAST16_T@ - 1)) - 1) * 2 + 1)
# endif
# endif
#else
# if _STDINT_H_INT64_FASTER_THAN_INT32
# define UINT_FAST16_MAX UINT64_MAX
# else
# define UINT_FAST16_MAX UINT32_MAX
# endif
#endif
#if @HAVE_INT_FAST32_T@
# ifndef INT_FAST32_MIN
# define INT_FAST32_MIN (-1L << (@BITSIZEOF_INT_FAST32_T@ - 1))
# endif
#else
# if _STDINT_H_INT64_FASTER_THAN_INT32
# define INT_FAST32_MIN INT64_MIN
# else
# define INT_FAST32_MIN INT32_MIN
# endif
#endif
#if @HAVE_INT_FAST32_T@
# ifndef INT_FAST32_MAX
# define INT_FAST32_MAX (~ (-1L << (@BITSIZEOF_INT_FAST32_T@ - 1)))
# endif
#else
# if _STDINT_H_INT64_FASTER_THAN_INT32
# define INT_FAST32_MAX INT64_MAX
# else
# define INT_FAST32_MAX INT32_MAX
# endif
#endif
#if @HAVE_UINT_FAST32_T@
# ifndef UINT_FAST32_MAX
# if @BITSIZEOF_UINT_FAST32_T@ < @BITSIZEOF_UNSIGNED_INT@
# define UINT_FAST32_MAX (((1 << (@BITSIZEOF_UINT_FAST32_T@ - 1)) - 1) * 2 + 1)
# else
# define UINT_FAST32_MAX (((1UL << (@BITSIZEOF_UINT_FAST32_T@ - 1)) - 1) * 2 + 1)
# endif
# endif
#else
# if _STDINT_H_INT64_FASTER_THAN_INT32
# define UINT_FAST32_MAX UINT64_MAX
# else
# define UINT_FAST32_MAX UINT32_MAX
# endif
#endif
#if @HAVE_INT_FAST64_T@
# ifndef INT_FAST64_MIN
# if @HAVE_LONG_64BIT@
# define INT_FAST64_MIN (-1L << (@BITSIZEOF_INT_FAST64_T@ - 1))
# elif @HAVE_LONG_LONG_64BIT@
# define INT_FAST64_MIN (-1LL << (@BITSIZEOF_INT_FAST64_T@ - 1))
# elif defined _MSC_VER
# define INT_FAST64_MIN (-1i64 << (@BITSIZEOF_INT_FAST64_T@ - 1))
# endif
# endif
#else
# ifdef _STDINT_H_HAVE_INT64
# define INT_FAST64_MIN INT64_MIN
# endif
#endif
#if @HAVE_INT_FAST64_T@
# ifndef INT_FAST64_MAX
# if @HAVE_LONG_64BIT@
# define INT_FAST64_MAX (~ (-1L << (@BITSIZEOF_INT_FAST64_T@ - 1)))
# elif @HAVE_LONG_LONG_64BIT@
# define INT_FAST64_MAX (~ (-1LL << (@BITSIZEOF_INT_FAST64_T@ - 1)))
# elif defined _MSC_VER
# define INT_FAST64_MAX (~ (-1i64 << (@BITSIZEOF_INT_FAST64_T@ - 1)))
# endif
# endif
#else
# ifdef _STDINT_H_HAVE_INT64
# define INT_FAST64_MAX INT64_MAX
# endif
#endif
#if @HAVE_UINT_FAST64_T@
# ifndef UINT_FAST64_MAX
# if @HAVE_LONG_64BIT@
# define UINT_FAST64_MAX (((1UL << (@BITSIZEOF_UINT_FAST64_T@ - 1)) - 1) * 2 + 1)
# elif @HAVE_LONG_LONG_64BIT@
# define UINT_FAST64_MAX (((1ULL << (@BITSIZEOF_UINT_FAST64_T@ - 1)) - 1) * 2 + 1)
# elif defined _MSC_VER
# define UINT_FAST64_MAX (((1ui64 << (@BITSIZEOF_UINT_FAST64_T@ - 1)) - 1) * 2 + 1)
# endif
# endif
#else
# ifdef _STDINT_H_HAVE_UINT64
# define UINT_FAST64_MAX UINT64_MAX
# endif
#endif
/* 7.18.2.4. Limits of integer types capable of holding object pointers */
#define INTPTR_MIN LONG_MIN
#define INTPTR_MAX LONG_MAX
#define UINTPTR_MAX ULONG_MAX
#if @HAVE_INTPTR_T@
# ifndef INTPTR_MIN
# if @BITSIZEOF_INTPTR_T@ > @BITSIZEOF_LONG@
# define INTPTR_MIN (-1LL << (@BITSIZEOF_INTPTR_T@ - 1))
# else
# define INTPTR_MIN (-1L << (@BITSIZEOF_INTPTR_T@ - 1))
# endif
# endif
#else
# define INTPTR_MIN LONG_MIN
#endif
#if @HAVE_INTPTR_T@
# ifndef INTPTR_MAX
# if @BITSIZEOF_INTPTR_T@ > @BITSIZEOF_LONG@
# define INTPTR_MAX (~ (-1LL << (@BITSIZEOF_INTPTR_T@ - 1)))
# else
# define INTPTR_MAX (~ (-1L << (@BITSIZEOF_INTPTR_T@ - 1)))
# endif
# endif
#else
# define INTPTR_MAX LONG_MAX
#endif
#if @HAVE_UINTPTR_T@
# ifndef UINTPTR_MAX
# if @BITSIZEOF_UINTPTR_T@ > @BITSIZEOF_UNSIGNED_LONG@
# define UINTPTR_MAX (((1ULL << (@BITSIZEOF_UINTPTR_T@ - 1)) - 1) * 2 + 1)
# else
# define UINTPTR_MAX (((1UL << (@BITSIZEOF_UINTPTR_T@ - 1)) - 1) * 2 + 1)
# endif
# endif
#else
# define UINTPTR_MAX ULONG_MAX
#endif
/* 7.18.2.5. Limits of greatest-width integer types */
#ifdef _STDINT_H_HAVE_INT64
#define INTMAX_MIN INT64_MIN
#define INTMAX_MAX INT64_MAX
#define UINTMAX_MAX UINT64_MAX
#if @HAVE_INTMAX_T@
# ifndef INTMAX_MIN
# if @BITSIZEOF_INTMAX_T@ > @BITSIZEOF_LONG@
# define INTMAX_MIN (-1LL << (@BITSIZEOF_INTMAX_T@ - 1))
# else
# define INTMAX_MIN (-1L << (@BITSIZEOF_INTMAX_T@ - 1))
# endif
# endif
#else
#define INTMAX_MIN INT32_MIN
#define INTMAX_MAX INT32_MAX
#define UINTMAX_MAX UINT32_MAX
# ifdef _STDINT_H_HAVE_INT64
# define INTMAX_MIN INT64_MIN
# else
# define INTMAX_MIN INT32_MIN
# endif
#endif
#if @HAVE_INTMAX_T@
# ifndef INTMAX_MAX
# if @BITSIZEOF_INTMAX_T@ > @BITSIZEOF_LONG@
# define INTMAX_MAX (~ (-1LL << (@BITSIZEOF_INTMAX_T@ - 1)))
# else
# define INTMAX_MAX (~ (-1L << (@BITSIZEOF_INTMAX_T@ - 1)))
# endif
# endif
#else
# ifdef _STDINT_H_HAVE_INT64
# define INTMAX_MAX INT64_MAX
# else
# define INTMAX_MAX INT32_MAX
# endif
#endif
#if @HAVE_UINTMAX_T@
# ifndef UINTMAX_MAX
# if @BITSIZEOF_UINTMAX_T@ > @BITSIZEOF_UNSIGNED_LONG@
# define UINTMAX_MAX (((1ULL << (@BITSIZEOF_UINTMAX_T@ - 1)) - 1) * 2 + 1)
# else
# define UINTMAX_MAX (((1UL << (@BITSIZEOF_UINTMAX_T@ - 1)) - 1) * 2 + 1)
# endif
# endif
#else
# ifdef _STDINT_H_HAVE_INT64
# define UINTMAX_MAX UINT64_MAX
# else
# define UINTMAX_MAX UINT32_MAX
# endif
#endif
/* 7.18.3. Limits of other integer types */
#define PTRDIFF_MIN (~(ptrdiff_t)0 << (sizeof(ptrdiff_t)*CHAR_BIT-1))
#define PTRDIFF_MAX (~PTRDIFF_MIN)
/* ptrdiff_t limits */
#ifndef PTRDIFF_MIN
# if @BITSIZEOF_PTRDIFF_T@ > @BITSIZEOF_LONG@ || @SAME_TYPE_PTRDIFF_T_LONG@
# define PTRDIFF_MIN (-1L << (@BITSIZEOF_PTRDIFF_T@ - 1))
# else
# define PTRDIFF_MIN (-1 << (@BITSIZEOF_PTRDIFF_T@ - 1))
# endif
#endif
#ifndef PTRDIFF_MAX
# if @BITSIZEOF_PTRDIFF_T@ > @BITSIZEOF_LONG@ || @SAME_TYPE_PTRDIFF_T_LONG@
# define PTRDIFF_MAX (~ (-1L << (@BITSIZEOF_PTRDIFF_T@ - 1)))
# else
# define PTRDIFF_MAX (~ (-1 << (@BITSIZEOF_PTRDIFF_T@ - 1)))
# endif
#endif
/* This may be wrong... */
#define SIG_ATOMIC_MIN 0
#define SIG_ATOMIC_MAX 127
/* sig_atomic_t limits */
#ifndef SIG_ATOMIC_MIN
# if @HAVE_SIGNED_SIG_ATOMIC_T@
# if @BITSIZEOF_SIG_ATOMIC_T@ > @BITSIZEOF_LONG@ || @SAME_TYPE_SIG_ATOMIC_T_LONG@
# define SIG_ATOMIC_MIN (-1L << (@BITSIZEOF_SIG_ATOMIC_T@ - 1))
# else
# define SIG_ATOMIC_MIN (-1 << (@BITSIZEOF_SIG_ATOMIC_T@ - 1))
# endif
# else
# if @BITSIZEOF_SIG_ATOMIC_T@ > @BITSIZEOF_UNSIGNED_LONG@ || @SAME_TYPE_SIG_ATOMIC_T_UNSIGNED_LONG@
# define SIG_ATOMIC_MIN 0UL
# elif @BITSIZEOF_SIG_ATOMIC_T@ >= @BITSIZEOF_UNSIGNED_INT@
# define SIG_ATOMIC_MIN 0U
# else
# define SIG_ATOMIC_MIN 0
# endif
# endif
#endif
#ifndef SIG_ATOMIC_MAX
# if @HAVE_SIGNED_SIG_ATOMIC_T@
# if @BITSIZEOF_SIG_ATOMIC_T@ > @BITSIZEOF_LONG@ || @SAME_TYPE_SIG_ATOMIC_T_LONG@
# define SIG_ATOMIC_MAX (~ (-1L << (@BITSIZEOF_SIG_ATOMIC_T@ - 1)))
# else
# define SIG_ATOMIC_MAX (~ (-1 << (@BITSIZEOF_SIG_ATOMIC_T@ - 1)))
# endif
# else
# if @BITSIZEOF_SIG_ATOMIC_T@ > @BITSIZEOF_UNSIGNED_LONG@ || @SAME_TYPE_SIG_ATOMIC_T_UNSIGNED_LONG@
# define SIG_ATOMIC_MAX (((1UL << (@BITSIZEOF_SIG_ATOMIC_T@ - 1)) - 1) * 2 + 1)
# elif @BITSIZEOF_SIG_ATOMIC_T@ >= @BITSIZEOF_UNSIGNED_INT@
# define SIG_ATOMIC_MAX (((1U << (@BITSIZEOF_SIG_ATOMIC_T@ - 1)) - 1) * 2 + 1)
# else
# define SIG_ATOMIC_MAX (((1 << (@BITSIZEOF_SIG_ATOMIC_T@ - 1)) - 1) * 2 + 1)
# endif
# endif
#endif
/* size_t limit */
#ifndef SIZE_MAX /* SIZE_MAX may also be defined in config.h. */
# define SIZE_MAX ((size_t)~(size_t)0)
# if @BITSIZEOF_SIZE_T@ > @BITSIZEOF_UNSIGNED_LONG@ || @SAME_TYPE_SIZE_T_UNSIGNED_LONG@
# define SIZE_MAX (((1UL << (@BITSIZEOF_SIZE_T@ - 1)) - 1) * 2 + 1)
# else
# define SIZE_MAX (((1U << (@BITSIZEOF_SIZE_T@ - 1)) - 1) * 2 + 1)
# endif
#endif
/* wchar_t limits already defined in <stddef.h>. */
/* wint_t limits already defined in <wchar.h>. */
/* wchar_t limits may already be defined in <stddef.h>. */
#ifndef WCHAR_MIN
# if @HAVE_SIGNED_WCHAR_T@
# if @BITSIZEOF_WCHAR_T@ > @BITSIZEOF_LONG@ || @SAME_TYPE_WCHAR_T_LONG@
# define WCHAR_MIN (-1L << (@BITSIZEOF_WCHAR_T@ - 1))
# else
# define WCHAR_MIN (-1 << (@BITSIZEOF_WCHAR_T@ - 1))
# endif
# else
# if @BITSIZEOF_WCHAR_T@ > @BITSIZEOF_UNSIGNED_LONG@ || @SAME_TYPE_WCHAR_T_UNSIGNED_LONG@
# define WCHAR_MIN 0UL
# elif @BITSIZEOF_WCHAR_T@ >= @BITSIZEOF_UNSIGNED_INT@
# define WCHAR_MIN 0U
# else
# define WCHAR_MIN 0
# endif
# endif
#endif
#ifndef WCHAR_MAX
# if @HAVE_SIGNED_WCHAR_T@
# if @BITSIZEOF_WCHAR_T@ > @BITSIZEOF_LONG@ || @SAME_TYPE_WCHAR_T_LONG@
# define WCHAR_MAX (~ (-1L << (@BITSIZEOF_WCHAR_T@ - 1)))
# else
# define WCHAR_MAX (~ (-1 << (@BITSIZEOF_WCHAR_T@ - 1)))
# endif
# else
# if @BITSIZEOF_WCHAR_T@ > @BITSIZEOF_UNSIGNED_LONG@ || @SAME_TYPE_WCHAR_T_UNSIGNED_LONG@
# define WCHAR_MAX (((1UL << (@BITSIZEOF_WCHAR_T@ - 1)) - 1) * 2 + 1)
# elif @BITSIZEOF_WCHAR_T@ >= @BITSIZEOF_UNSIGNED_INT@
# define WCHAR_MAX (((1U << (@BITSIZEOF_WCHAR_T@ - 1)) - 1) * 2 + 1)
# else
# define WCHAR_MAX (((1 << (@BITSIZEOF_WCHAR_T@ - 1)) - 1) * 2 + 1)
# endif
# endif
#endif
/* wint_t limits */
#ifndef WINT_MIN
# if @HAVE_SIGNED_WINT_T@
# if @BITSIZEOF_WINT_T@ > @BITSIZEOF_LONG@ || @SAME_TYPE_WINT_T_LONG@
# define WINT_MIN (-1L << (@BITSIZEOF_WINT_T@ - 1))
# else
# define WINT_MIN (-1 << (@BITSIZEOF_WINT_T@ - 1))
# endif
# else
# if @BITSIZEOF_WINT_T@ > @BITSIZEOF_UNSIGNED_LONG@ || @SAME_TYPE_WINT_T_UNSIGNED_LONG@
# define WINT_MIN 0UL
# elif @BITSIZEOF_WINT_T@ >= @BITSIZEOF_UNSIGNED_INT@
# define WINT_MIN 0U
# else
# define WINT_MIN 0
# endif
# endif
#endif
#ifndef WINT_MAX
# if @HAVE_SIGNED_WINT_T@
# if @BITSIZEOF_WINT_T@ > @BITSIZEOF_LONG@ || @SAME_TYPE_WINT_T_LONG@
# define WINT_MAX (~ (-1L << (@BITSIZEOF_WINT_T@ - 1)))
# else
# define WINT_MAX (~ (-1 << (@BITSIZEOF_WINT_T@ - 1)))
# endif
# else
# if @BITSIZEOF_WINT_T@ > @BITSIZEOF_UNSIGNED_LONG@ || @SAME_TYPE_WINT_T_UNSIGNED_LONG@
# define WINT_MAX (((1UL << (@BITSIZEOF_WINT_T@ - 1)) - 1) * 2 + 1)
# elif @BITSIZEOF_WINT_T@ >= @BITSIZEOF_UNSIGNED_INT@
# define WINT_MAX (((1U << (@BITSIZEOF_WINT_T@ - 1)) - 1) * 2 + 1)
# else
# define WINT_MAX (((1 << (@BITSIZEOF_WINT_T@ - 1)) - 1) * 2 + 1)
# endif
# endif
#endif
#endif
......@@ -258,42 +942,78 @@ typedef uint32_t uintmax_t;
#if !defined(__cplusplus) || defined(__STDC_CONSTANT_MACROS)
/* 7.18.4.1. Macros for minimum-width integer constants */
/* According to ISO C 99 Technical Corrigendum 1 */
#undef INT8_C
#undef UINT8_C
#define INT8_C(x) x
#define UINT8_C(x) x##U
#if @HAVE_UINT8_T@
# if @BITSIZEOF_UINT8_T@ < @BITSIZEOF_UNSIGNED_INT@
# define UINT8_C(x) x
# else
# define UINT8_C(x) x##U
# endif
#else
# define UINT8_C(x) x
#endif
#undef INT16_C
#undef UINT16_C
#define INT16_C(x) x
#define UINT16_C(x) x##U
#if @HAVE_UINT16_T@
# if @BITSIZEOF_UINT16_T@ < @BITSIZEOF_UNSIGNED_INT@
# define UINT16_C(x) x
# else
# define UINT16_C(x) x##U
# endif
#else
# define UINT16_C(x) x
#endif
#undef INT32_C
#undef UINT32_C
#define INT32_C(x) x
#define UINT32_C(x) x##U
#if @HAVE_UINT32_T@
# if @BITSIZEOF_UINT32_T@ < @BITSIZEOF_UNSIGNED_INT@
# define UINT32_C(x) x
# else
# define UINT32_C(x) x##U
# endif
#else
# define UINT32_C(x) x
#endif
#undef INT64_C
#undef UINT64_C
#if @HAVE_LONG_64BIT@
#define INT64_C(x) x##L
#define UINT64_C(x) x##UL
# define INT64_C(x) x##L
# define UINT64_C(x) x##UL
#elif @HAVE_LONG_LONG_64BIT@
#define INT64_C(x) x##LL
#define UINT64_C(x) x##ULL
# define INT64_C(x) x##LL
# define UINT64_C(x) x##ULL
#elif defined(_MSC_VER)
#define INT64_C(x) x##i64
#define UINT64_C(x) x##ui64
# define INT64_C(x) x##i64
# define UINT64_C(x) x##ui64
#endif
/* 7.18.4.2. Macros for greatest-width integer constants */
#undef INTMAX_C
#undef UINTMAX_C
#if @HAVE_LONG_64BIT@
#define INTMAX_C(x) x##L
#define UINTMAX_C(x) x##UL
# define INTMAX_C(x) x##L
# define UINTMAX_C(x) x##UL
#elif @HAVE_LONG_LONG_64BIT@
#define INTMAX_C(x) x##LL
#define UINTMAX_C(x) x##ULL
# define INTMAX_C(x) x##LL
# define UINTMAX_C(x) x##ULL
#elif defined(_MSC_VER)
#define INTMAX_C(x) x##i64
#define UINTMAX_C(x) x##ui64
# define INTMAX_C(x) x##i64
# define UINTMAX_C(x) x##ui64
#else
#define INTMAX_C(x) x
#define UINTMAX_C(x) x##U
# define INTMAX_C(x) x
# define UINTMAX_C(x) x##U
#endif
#endif
#endif /* !_STDINT_H_HAVE_SYSTEM_INTTYPES */
#endif /* _STDINT_H */
......
/* Copyright (C) 1996, 1997, 1998, 2000, 2003, 2005 Free Software Foundation, Inc.
/* Copyright (C) 1996, 1997, 1998, 2001, 2002, 2003, 2005, 2006 Free
Software Foundation, Inc.
NOTE: The canonical source of this file is maintained with the GNU C Library.
Bugs can be reported to bug-glibc@prep.ai.mit.edu.
......@@ -20,24 +21,35 @@
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#if !_LIBC
# include "strndup.h"
#endif
#include <stdlib.h>
#include <string.h>
/* Get strnlen. */
#include "strnlen.h"
#if !_LIBC
# include "strnlen.h"
# ifndef __strnlen
# define __strnlen strnlen
# endif
#endif
#undef __strndup
#undef strndup
#if _LIBC
# undef strndup
#endif
#ifndef weak_alias
# define __strndup strndup
#endif
char *
__strndup (const char *s, size_t n)
__strndup (s, n)
const char *s;
size_t n;
{
size_t len = strnlen (s, n);
size_t len = __strnlen (s, n);
char *new = malloc (len + 1);
if (new == NULL)
......@@ -46,6 +58,9 @@ __strndup (const char *s, size_t n)
new[len] = '\0';
return memcpy (new, s, len);
}
#ifdef libc_hidden_def
libc_hidden_def (__strndup)
#endif
#ifdef weak_alias
weak_alias (__strndup, strndup)
#endif
......
/* Find the length of STRING, but scan at most MAXLEN characters.
Copyright (C) 1996, 1997, 1998, 2000-2003 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Copyright (C) 2005, 2006 Free Software Foundation, Inc.
Written by Simon Josefsson.
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
......@@ -12,37 +12,22 @@
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,
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. */
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#undef strnlen
#include <string.h>
#undef __strnlen
#undef strnlen
#ifndef _LIBC
# define strnlen rpl_strnlen
#endif
#ifndef weak_alias
# define __strnlen strnlen
#endif
#include "strnlen.h"
/* Find the length of STRING, but scan at most MAXLEN characters.
If no '\0' terminator is found in that many characters, return MAXLEN. */
size_t
__strnlen (const char *string, size_t maxlen)
strnlen (const char *string, size_t maxlen)
{
const char *end = memchr (string, '\0', maxlen);
return end ? (size_t) (end - string) : maxlen;
}
#ifdef weak_alias
weak_alias (__strnlen, strnlen)
#endif
......
/* vsprintf with automatic memory allocation.
Copyright (C) 1999, 2002-2005 Free Software Foundation, Inc.
Copyright (C) 1999, 2002-2006 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
......@@ -334,28 +334,28 @@ VASNPRINTF (CHAR_T *resultbuf, size_t *lengthp, const CHAR_T *format, va_list ar
tmp_length =
(unsigned int) (sizeof (unsigned long long) * CHAR_BIT
* 0.30103 /* binary -> decimal */
* 2 /* estimate for FLAG_GROUP */
)
+ 1 /* turn floor into ceil */
+ 1; /* account for leading sign */
+ 1; /* turn floor into ceil */
else
# endif
if (type == TYPE_LONGINT || type == TYPE_ULONGINT)
tmp_length =
(unsigned int) (sizeof (unsigned long) * CHAR_BIT
* 0.30103 /* binary -> decimal */
* 2 /* estimate for FLAG_GROUP */
)
+ 1 /* turn floor into ceil */
+ 1; /* account for leading sign */
+ 1; /* turn floor into ceil */
else
tmp_length =
(unsigned int) (sizeof (unsigned int) * CHAR_BIT
* 0.30103 /* binary -> decimal */
* 2 /* estimate for FLAG_GROUP */
)
+ 1 /* turn floor into ceil */
+ 1; /* account for leading sign */
+ 1; /* turn floor into ceil */
if (tmp_length < precision)
tmp_length = precision;
/* Multiply by 2, as an estimate for FLAG_GROUP. */
tmp_length = xsum (tmp_length, tmp_length);
/* Add 1, to account for a leading sign. */
tmp_length = xsum (tmp_length, 1);
break;
case 'o':
......@@ -365,8 +365,7 @@ VASNPRINTF (CHAR_T *resultbuf, size_t *lengthp, const CHAR_T *format, va_list ar
(unsigned int) (sizeof (unsigned long long) * CHAR_BIT
* 0.333334 /* binary -> octal */
)
+ 1 /* turn floor into ceil */
+ 1; /* account for leading sign */
+ 1; /* turn floor into ceil */
else
# endif
if (type == TYPE_LONGINT || type == TYPE_ULONGINT)
......@@ -374,15 +373,17 @@ VASNPRINTF (CHAR_T *resultbuf, size_t *lengthp, const CHAR_T *format, va_list ar
(unsigned int) (sizeof (unsigned long) * CHAR_BIT
* 0.333334 /* binary -> octal */
)
+ 1 /* turn floor into ceil */
+ 1; /* account for leading sign */
+ 1; /* turn floor into ceil */
else
tmp_length =
(unsigned int) (sizeof (unsigned int) * CHAR_BIT
* 0.333334 /* binary -> octal */
)
+ 1 /* turn floor into ceil */
+ 1; /* account for leading sign */
+ 1; /* turn floor into ceil */
if (tmp_length < precision)
tmp_length = precision;
/* Add 1, to account for a leading sign. */
tmp_length = xsum (tmp_length, 1);
break;
case 'x': case 'X':
......@@ -392,8 +393,7 @@ VASNPRINTF (CHAR_T *resultbuf, size_t *lengthp, const CHAR_T *format, va_list ar
(unsigned int) (sizeof (unsigned long long) * CHAR_BIT
* 0.25 /* binary -> hexadecimal */
)
+ 1 /* turn floor into ceil */
+ 2; /* account for leading sign or alternate form */
+ 1; /* turn floor into ceil */
else
# endif
if (type == TYPE_LONGINT || type == TYPE_ULONGINT)
......@@ -401,15 +401,17 @@ VASNPRINTF (CHAR_T *resultbuf, size_t *lengthp, const CHAR_T *format, va_list ar
(unsigned int) (sizeof (unsigned long) * CHAR_BIT
* 0.25 /* binary -> hexadecimal */
)
+ 1 /* turn floor into ceil */
+ 2; /* account for leading sign or alternate form */
+ 1; /* turn floor into ceil */
else
tmp_length =
(unsigned int) (sizeof (unsigned int) * CHAR_BIT
* 0.25 /* binary -> hexadecimal */
)
+ 1 /* turn floor into ceil */
+ 2; /* account for leading sign or alternate form */
+ 1; /* turn floor into ceil */
if (tmp_length < precision)
tmp_length = precision;
/* Add 2, to account for a leading sign or alternate form. */
tmp_length = xsum (tmp_length, 2);
break;
case 'f': case 'F':
......