summaryrefslogtreecommitdiffstats
path: root/gnu
diff options
context:
space:
mode:
authorru <ru@FreeBSD.org>2000-01-31 13:26:10 +0000
committerru <ru@FreeBSD.org>2000-01-31 13:26:10 +0000
commit04530d99c149915b25cf02629930209d17d6aa1f (patch)
treefa1fe31f6ec3e4621cca438cd93200ad522dec7d /gnu
parent4c73bf82d8fca322d2dfcb1402ef91e9bc9639c6 (diff)
downloadFreeBSD-src-04530d99c149915b25cf02629930209d17d6aa1f.zip
FreeBSD-src-04530d99c149915b25cf02629930209d17d6aa1f.tar.gz
This is the stock GNU grep 2.4d file.
Diffstat (limited to 'gnu')
-rw-r--r--gnu/usr.bin/grep/getopt.c233
-rw-r--r--gnu/usr.bin/grep/getopt.h120
-rw-r--r--gnu/usr.bin/grep/getpagesize.h64
-rw-r--r--gnu/usr.bin/grep/kwset.c57
-rw-r--r--gnu/usr.bin/grep/obstack.c49
-rw-r--r--gnu/usr.bin/grep/obstack.h212
6 files changed, 391 insertions, 344 deletions
diff --git a/gnu/usr.bin/grep/getopt.c b/gnu/usr.bin/grep/getopt.c
index f919ed7..d176d3e 100644
--- a/gnu/usr.bin/grep/getopt.c
+++ b/gnu/usr.bin/grep/getopt.c
@@ -1,47 +1,40 @@
/* Getopt for GNU.
- 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 roland@gnu.ai.mit.edu
- before changing it!
+ NOTE: The canonical source of this file is maintained with the GNU
+ C Library. Bugs can be reported to bug-glibc@gnu.org.
- Copyright (C) 1987, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97
+ Copyright (C) 1987, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99
Free Software Foundation, Inc.
- This file is part of the GNU C Library. Its master source is NOT part of
- the C library, however. The master source lives in /gd/gnu/lib.
+ This program is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by the
+ Free Software Foundation; either version 2, or (at your option) any
+ later version.
- The GNU C Library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Library General Public License as
- published by the Free Software Foundation; either version 2 of the
- License, or (at your option) any later version.
-
- The GNU C Library is distributed in the hope that it will be useful,
+ This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Library General Public License for more details.
-
- You should have received a copy of the GNU Library General Public
- License along with the GNU C Library; see the file COPYING.LIB. If not,
- write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- Boston, MA 02111-1307, USA. */
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
-/* $FreeBSD$ */
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software Foundation,
+ Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
/* 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
+# define _NO_PROTO
#endif
#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#if !defined (__STDC__) || !__STDC__
+# include <config.h>
+#else
+# if !defined __STDC__ || !__STDC__
/* This is a separate conditional since some stdc systems
reject `defined (const)'. */
-#ifndef const
-#define const
-#endif
+# ifndef const
+# define const
+# endif
+# endif
#endif
#include <stdio.h>
@@ -55,11 +48,11 @@
it is simpler to just do this in the source for each such file. */
#define GETOPT_INTERFACE_VERSION 2
-#if !defined (_LIBC) && defined (__GLIBC__) && __GLIBC__ >= 2
-#include <gnu-versions.h>
-#if _GNU_GETOPT_INTERFACE_VERSION == GETOPT_INTERFACE_VERSION
-#define ELIDE_CODE
-#endif
+#if !defined _LIBC && defined __GLIBC__ && __GLIBC__ >= 2
+# include <gnu-versions.h>
+# if _GNU_GETOPT_INTERFACE_VERSION == GETOPT_INTERFACE_VERSION
+# define ELIDE_CODE
+# endif
#endif
#ifndef ELIDE_CODE
@@ -70,32 +63,26 @@
#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>
+# include <stdlib.h>
+# include <unistd.h>
#endif /* GNU C library. */
#ifdef VMS
-#include <unixlib.h>
-#if HAVE_STRING_H - 0
-#include <string.h>
-#endif
-#endif
-
-#if defined (WIN32) && !defined (__CYGWIN32__)
-/* It's not Unix, really. See? Capital letters. */
-#include <windows.h>
-#define getpid() GetCurrentProcessId()
+# include <unixlib.h>
+# if HAVE_STRING_H - 0
+# include <string.h>
+# endif
#endif
#ifndef _
/* This is for other GNU distributions with internationalized messages.
When compiling libc, the _ macro is predefined. */
-#ifdef HAVE_LIBINTL_H
-# include <libintl.h>
-# define _(msgid) gettext (msgid)
-#else
-# define _(msgid) (msgid)
-#endif
+# ifdef HAVE_LIBINTL_H
+# include <libintl.h>
+# define _(msgid) gettext (msgid)
+# else
+# define _(msgid) (msgid)
+# endif
#endif
/* This version of `getopt' appears to the caller like standard Unix `getopt'
@@ -120,7 +107,7 @@
Also, when `ordering' is RETURN_IN_ORDER,
each non-option ARGV-element is returned here. */
-char *optarg = NULL;
+char *optarg;
/* Index in ARGV of the next element to be scanned.
This is used for communication to and from the caller
@@ -141,7 +128,7 @@ int optind = 1;
causes problems with re-calling getopt as programs generally don't
know that. */
-int __getopt_initialized = 0;
+int __getopt_initialized;
/* The next char to be scanned in the option-element
in which the last option character we returned was found.
@@ -205,14 +192,22 @@ static char *posixly_correct;
because there are many ways it can cause trouble.
On some systems, it contains special magic macros that don't work
in GCC. */
-#include <string.h>
-#define my_index strchr
+# include <string.h>
+# define my_index strchr
#else
+# if HAVE_STRING_H
+# include <string.h>
+# else
+# include <strings.h>
+# endif
+
/* Avoid depending on library functions or files
whose names are inconsistent. */
-char *getenv ();
+#ifndef getenv
+extern char *getenv ();
+#endif
static char *
my_index (str, chr)
@@ -233,11 +228,11 @@ my_index (str, chr)
#ifdef __GNUC__
/* Note that Motorola Delta 68k R3V7 comes with GCC but not stddef.h.
That was relevant to code that was here before. */
-#if !defined (__STDC__) || !__STDC__
+# if (!defined __STDC__ || !__STDC__) && !defined strlen
/* gcc with -traditional declares the built-in strlen to return int,
and has done so at least since version 2.4.5. -- rms. */
extern int strlen (const char *);
-#endif /* not __STDC__ */
+# endif /* not __STDC__ */
#endif /* __GNUC__ */
#endif /* not __GNU_LIBRARY__ */
@@ -255,7 +250,10 @@ static int last_nonopt;
/* Bash 2.0 gives us an environment variable containing flags
indicating ARGV elements that should not be considered arguments. */
-static const char *nonoption_flags;
+/* Defined in getopt_init.c */
+extern char *__getopt_nonoption_flags;
+
+static int nonoption_flags_max_len;
static int nonoption_flags_len;
static int original_argc;
@@ -264,17 +262,29 @@ static char *const *original_argv;
/* Make sure the environment variable bash 2.0 puts in the environment
is valid for the getopt call we must make sure that the ARGV passed
to getopt is that one passed to the process. */
-static void store_args (int argc, char *const *argv) __attribute__ ((unused));
static void
-store_args (int argc, char *const *argv)
+__attribute__ ((unused))
+store_args_and_env (int argc, char *const *argv)
{
/* XXX This is no good solution. We should rather copy the args so
that we can compare them later. But we must not use malloc(3). */
original_argc = argc;
original_argv = argv;
}
-text_set_element (__libc_subinit, store_args);
-#endif
+# ifdef text_set_element
+text_set_element (__libc_subinit, store_args_and_env);
+# endif /* text_set_element */
+
+# define SWAP_FLAGS(ch1, ch2) \
+ if (nonoption_flags_len > 0) \
+ { \
+ char __tmp = __getopt_nonoption_flags[ch1]; \
+ __getopt_nonoption_flags[ch1] = __getopt_nonoption_flags[ch2]; \
+ __getopt_nonoption_flags[ch2] = __tmp; \
+ }
+#else /* !_LIBC */
+# define SWAP_FLAGS(ch1, ch2)
+#endif /* _LIBC */
/* Exchange two adjacent subsequences of ARGV.
One subsequence is elements [first_nonopt,last_nonopt)
@@ -285,7 +295,7 @@ text_set_element (__libc_subinit, store_args);
`first_nonopt' and `last_nonopt' are relocated so that they describe
the new indices of the non-options in ARGV after they are moved. */
-#if defined (__STDC__) && __STDC__
+#if defined __STDC__ && __STDC__
static void exchange (char **);
#endif
@@ -303,6 +313,28 @@ exchange (argv)
It leaves the longer segment in the right place overall,
but it consists of two parts that need to be swapped next. */
+#ifdef _LIBC
+ /* First make sure the handling of the `__getopt_nonoption_flags'
+ string can work normally. Our top argument must be in the range
+ of the string. */
+ if (nonoption_flags_len > 0 && top >= nonoption_flags_max_len)
+ {
+ /* We must extend the array. The user plays games with us and
+ presents new arguments. */
+ char *new_str = malloc (top + 1);
+ if (new_str == NULL)
+ nonoption_flags_len = nonoption_flags_max_len = 0;
+ else
+ {
+ memset (__mempcpy (new_str, __getopt_nonoption_flags,
+ nonoption_flags_max_len),
+ '\0', top + 1 - nonoption_flags_max_len);
+ nonoption_flags_max_len = top + 1;
+ __getopt_nonoption_flags = new_str;
+ }
+ }
+#endif
+
while (top > middle && middle > bottom)
{
if (top - middle > middle - bottom)
@@ -317,6 +349,7 @@ exchange (argv)
tem = argv[bottom + i];
argv[bottom + i] = argv[top - (middle - bottom) + i];
argv[top - (middle - bottom) + i] = tem;
+ SWAP_FLAGS (bottom + i, top - (middle - bottom) + i);
}
/* Exclude the moved bottom segment from further swapping. */
top -= len;
@@ -333,6 +366,7 @@ exchange (argv)
tem = argv[bottom + i];
argv[bottom + i] = argv[middle + i];
argv[middle + i] = tem;
+ SWAP_FLAGS (bottom + i, middle + i);
}
/* Exclude the moved top segment from further swapping. */
bottom += len;
@@ -347,7 +381,7 @@ exchange (argv)
/* Initialize the internal data when the first call is made. */
-#if defined (__STDC__) && __STDC__
+#if defined __STDC__ && __STDC__
static const char *_getopt_initialize (int, char *const *, const char *);
#endif
static const char *
@@ -360,7 +394,7 @@ _getopt_initialize (argc, argv, optstring)
is the program name); the sequence of previously skipped
non-option ARGV-elements is empty. */
- first_nonopt = last_nonopt = optind = 1;
+ first_nonopt = last_nonopt = optind;
nextchar = NULL;
@@ -387,17 +421,27 @@ _getopt_initialize (argc, argv, optstring)
if (posixly_correct == NULL
&& argc == original_argc && argv == original_argv)
{
- /* Bash 2.0 puts a special variable in the environment for each
- command it runs, specifying which ARGV elements are the results of
- file name wildcard expansion and therefore should not be
- considered as options. */
- char var[100];
- sprintf (var, "_%d_GNU_nonoption_argv_flags_", getpid ());
- nonoption_flags = getenv (var);
- if (nonoption_flags == NULL)
- nonoption_flags_len = 0;
- else
- nonoption_flags_len = strlen (nonoption_flags);
+ if (nonoption_flags_max_len == 0)
+ {
+ if (__getopt_nonoption_flags == NULL
+ || __getopt_nonoption_flags[0] == '\0')
+ nonoption_flags_max_len = -1;
+ else
+ {
+ const char *orig_str = __getopt_nonoption_flags;
+ int len = nonoption_flags_max_len = strlen (orig_str);
+ if (nonoption_flags_max_len < argc)
+ nonoption_flags_max_len = argc;
+ __getopt_nonoption_flags =
+ (char *) malloc (nonoption_flags_max_len);
+ if (__getopt_nonoption_flags == NULL)
+ nonoption_flags_max_len = -1;
+ else
+ memset (__mempcpy (__getopt_nonoption_flags, orig_str, len),
+ '\0', nonoption_flags_max_len - len);
+ }
+ }
+ nonoption_flags_len = nonoption_flags_max_len;
}
else
nonoption_flags_len = 0;
@@ -473,10 +517,11 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only)
{
optarg = NULL;
- if (!__getopt_initialized || optind == 0)
+ if (optind == 0 || !__getopt_initialized)
{
+ if (optind == 0)
+ optind = 1; /* Don't scan ARGV[0], the program name. */
optstring = _getopt_initialize (argc, argv, optstring);
- optind = 1; /* Don't scan ARGV[0], the program name. */
__getopt_initialized = 1;
}
@@ -485,11 +530,11 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only)
from the shell indicating it is not an option. The later information
is only used when the used in the GNU libc. */
#ifdef _LIBC
-#define NONOPTION_P (argv[optind][0] != '-' || argv[optind][1] == '\0' \
- || (optind < nonoption_flags_len \
- && nonoption_flags[optind] == '1'))
+# define NONOPTION_P (argv[optind][0] != '-' || argv[optind][1] == '\0' \
+ || (optind < nonoption_flags_len \
+ && __getopt_nonoption_flags[optind] == '1'))
#else
-#define NONOPTION_P (argv[optind][0] != '-' || argv[optind][1] == '\0')
+# define NONOPTION_P (argv[optind][0] != '-' || argv[optind][1] == '\0')
#endif
if (nextchar == NULL || *nextchar == '\0')
@@ -648,16 +693,18 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only)
else
{
if (opterr)
- if (argv[optind - 1][1] == '-')
- /* --option */
- fprintf (stderr,
- _("%s: option `--%s' doesn't allow an argument\n"),
- argv[0], pfound->name);
- else
- /* +option or -option */
- fprintf (stderr,
- _("%s: option `%c%s' doesn't allow an argument\n"),
- argv[0], argv[optind - 1][0], pfound->name);
+ {
+ if (argv[optind - 1][1] == '-')
+ /* --option */
+ fprintf (stderr,
+ _("%s: option `--%s' doesn't allow an argument\n"),
+ argv[0], pfound->name);
+ else
+ /* +option or -option */
+ fprintf (stderr,
+ _("%s: option `%c%s' doesn't allow an argument\n"),
+ argv[0], argv[optind - 1][0], pfound->name);
+ }
nextchar += strlen (nextchar);
diff --git a/gnu/usr.bin/grep/getopt.h b/gnu/usr.bin/grep/getopt.h
index 4209871..39f4a16 100644
--- a/gnu/usr.bin/grep/getopt.h
+++ b/gnu/usr.bin/grep/getopt.h
@@ -1,28 +1,27 @@
/* Declarations for getopt.
- Copyright (C) 1989,90,91,92,93,94,96,97, 98 Free Software Foundation, Inc.
-
- This file is part of the GNU C Library. Its master source is NOT part of
- the C library, however. The master source lives in /gd/gnu/lib.
-
- The GNU C Library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Library General Public License as
- published by the Free Software Foundation; either version 2 of the
- License, or (at your option) any later version.
-
- The GNU C Library is distributed in the hope that it will be useful,
+ Copyright (C) 1989,90,91,92,93,94,96,97,98 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@gnu.org.
+ This program is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by the
+ Free Software Foundation; either version 2, or (at your option) any
+ later version.
+
+ This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Library General Public License for more details.
-
- You should have received a copy of the GNU Library General Public
- License along with the GNU C Library; see the file COPYING.LIB. If not,
- write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- Boston, MA 02111-1307, USA. */
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
-/* $FreeBSD$ */
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+ USA. */
#ifndef _GETOPT_H
-#define _GETOPT_H 1
+
+#ifndef __need_getopt
+# define _GETOPT_H 1
+#endif
#ifdef __cplusplus
extern "C" {
@@ -59,6 +58,7 @@ extern int opterr;
extern int optopt;
+#ifndef __need_getopt
/* Describe the long-named options requested by the application.
The LONG_OPTIONS argument to getopt_long or getopt_long_only is a vector
of `struct option' terminated by an element containing a name which is
@@ -82,11 +82,11 @@ extern int optopt;
struct option
{
-#if defined (__STDC__) && __STDC__
+# if defined __STDC__ && __STDC__
const char *name;
-#else
+# else
char *name;
-#endif
+# endif
/* has_arg can't be an enum because some compilers complain about
type mismatches in all the code that assumes it is an int. */
int has_arg;
@@ -96,40 +96,74 @@ struct option
/* Names for the values of the `has_arg' field of `struct option'. */
-#define no_argument 0
-#define required_argument 1
-#define optional_argument 2
+# define no_argument 0
+# define required_argument 1
+# define optional_argument 2
+#endif /* need getopt */
+
-#if defined (__STDC__) && __STDC__
-#ifdef __GNU_LIBRARY__
+/* Get definitions and prototypes for functions to process the
+ arguments in ARGV (ARGC of them, minus the program name) for
+ options given in OPTS.
+
+ Return the option character from OPTS just read. Return -1 when
+ there are no more options. For unrecognized options, or options
+ missing arguments, `optopt' is set to the option letter, and '?' is
+ returned.
+
+ The OPTS string is a list of characters which are recognized option
+ letters, optionally followed by colons, specifying that that letter
+ takes an argument, to be placed in `optarg'.
+
+ If a letter in OPTS is followed by two colons, its argument is
+ optional. This behavior is specific to the GNU `getopt'.
+
+ The argument `--' causes premature termination of argument
+ scanning, explicitly telling `getopt' that there are no more
+ options.
+
+ If OPTS begins with `--', then non-option arguments are treated as
+ arguments to the option '\0'. This behavior is specific to the GNU
+ `getopt'. */
+
+#if (defined __STDC__ && __STDC__) || defined PROTOTYPES
+# ifdef __GNU_LIBRARY__
/* Many other libraries have conflicting prototypes for getopt, with
differences in the consts, in stdlib.h. To avoid compilation
errors, only prototype getopt for the GNU C library. */
-extern int getopt (int argc, char *const *argv, const char *shortopts);
-#else /* not __GNU_LIBRARY__ */
+extern int getopt (int __argc, char *const *__argv, const char *__shortopts);
+# else /* not __GNU_LIBRARY__ */
extern int getopt ();
-#endif /* __GNU_LIBRARY__ */
-extern int getopt_long (int argc, char *const *argv, const char *shortopts,
- const struct option *longopts, int *longind);
-extern int getopt_long_only (int argc, char *const *argv,
- const char *shortopts,
- const struct option *longopts, int *longind);
+# endif /* __GNU_LIBRARY__ */
+
+# ifndef __need_getopt
+extern int getopt_long (int __argc, char *const *__argv, const char *__shortopts,
+ const struct option *__longopts, int *__longind);
+extern int getopt_long_only (int __argc, char *const *__argv,
+ const char *__shortopts,
+ const struct option *__longopts, int *__longind);
/* Internal only. Users should not call this directly. */
-extern int _getopt_internal (int argc, char *const *argv,
- const char *shortopts,
- const struct option *longopts, int *longind,
- int long_only);
-#else /* not __STDC__ */
+extern int _getopt_internal (int __argc, char *const *__argv,
+ const char *__shortopts,
+ const struct option *__longopts, int *__longind,
+ int __long_only);
+# endif
+#else /* not ((defined __STDC__ && __STDC__) || defined PROTOTYPES) */
extern int getopt ();
+# ifndef __need_getopt
extern int getopt_long ();
extern int getopt_long_only ();
extern int _getopt_internal ();
-#endif /* __STDC__ */
+# endif
+#endif /* (defined __STDC__ && __STDC__) || defined PROTOTYPES */
#ifdef __cplusplus
}
#endif
-#endif /* _GETOPT_H */
+/* Make sure we later can get all the definitions and declarations. */
+#undef __need_getopt
+
+#endif /* getopt.h */
diff --git a/gnu/usr.bin/grep/getpagesize.h b/gnu/usr.bin/grep/getpagesize.h
index 4d562216..4e513c3 100644
--- a/gnu/usr.bin/grep/getpagesize.h
+++ b/gnu/usr.bin/grep/getpagesize.h
@@ -1,43 +1,35 @@
/* Emulate getpagesize on systems that lack it. */
-/* $FreeBSD$ */
-
#ifndef HAVE_GETPAGESIZE
-# ifdef VMS
-# define getpagesize() 512
-# endif
+#ifdef VMS
+#define getpagesize() 512
+#endif
+
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+
+#ifdef _SC_PAGESIZE
+#define getpagesize() sysconf(_SC_PAGESIZE)
+#else
-# ifdef HAVE_UNISTD_H
-# include <unistd.h>
-# endif
+#include <sys/param.h>
-# ifdef _SC_PAGESIZE
-# define getpagesize() sysconf(_SC_PAGESIZE)
-# else /* no _SC_PAGESIZE */
-# ifdef HAVE_SYS_PARAM_H
-# include <sys/param.h>
-# ifdef EXEC_PAGESIZE
-# define getpagesize() EXEC_PAGESIZE
-# else /* no EXEC_PAGESIZE */
-# ifdef NBPG
-# define getpagesize() NBPG * CLSIZE
-# ifndef CLSIZE
-# define CLSIZE 1
-# endif /* no CLSIZE */
-# else /* no NBPG */
-# ifdef NBPC
-# define getpagesize() NBPC
-# else /* no NBPC */
-# ifdef PAGESIZE
-# define getpagesize() PAGESIZE
-# endif /* PAGESIZE */
-# endif /* no NBPC */
-# endif /* no NBPG */
-# endif /* no EXEC_PAGESIZE */
-# else /* no HAVE_SYS_PARAM_H */
-# define getpagesize() 8192 /* punt totally */
-# endif /* no HAVE_SYS_PARAM_H */
-# endif /* no _SC_PAGESIZE */
+#ifdef EXEC_PAGESIZE
+#define getpagesize() EXEC_PAGESIZE
+#else
+#ifdef NBPG
+#define getpagesize() NBPG * CLSIZE
+#ifndef CLSIZE
+#define CLSIZE 1
+#endif /* no CLSIZE */
+#else /* no NBPG */
+#ifdef NBPC
+#define getpagesize() NBPC
+#endif /* NBPC */
+#endif /* no NBPG */
+#endif /* no EXEC_PAGESIZE */
+#endif /* no _SC_PAGESIZE */
-#endif /* no HAVE_GETPAGESIZE */
+#endif /* not HAVE_GETPAGESIZE */
diff --git a/gnu/usr.bin/grep/kwset.c b/gnu/usr.bin/grep/kwset.c
index adde8a7..92dbf09 100644
--- a/gnu/usr.bin/grep/kwset.c
+++ b/gnu/usr.bin/grep/kwset.c
@@ -20,8 +20,6 @@
The author may be reached (Email) at the address mike@ai.mit.edu,
or (US mail) as Mike Haertel c/o Free Software Foundation. */
-/* $FreeBSD$ */
-
/* The algorithm implemented by these routines bears a startling resemblence
to one discovered by Beate Commentz-Walter, although it is not identical.
See "A String Matching Algorithm Fast on the Average," Technical Report,
@@ -98,8 +96,7 @@ static char * cwexec PARAMS((kwset_t, char *, size_t, struct kwsmatch *));
/* Allocate and initialize a keyword set object, returning an opaque
pointer to it. Return NULL if memory is not available. */
kwset_t
-kwsalloc(trans)
- char *trans;
+kwsalloc (char *trans)
{
struct kwset *kwset;
@@ -134,10 +131,7 @@ kwsalloc(trans)
/* Add the given string to the contents of the keyword set. Return NULL
for success, an error message otherwise. */
char *
-kwsincr(kws, text, len)
- kwset_t kws;
- char *text;
- size_t len;
+kwsincr (kwset_t kws, char *text, size_t len)
{
struct kwset *kwset;
register struct trie *trie;
@@ -294,9 +288,7 @@ kwsincr(kws, text, len)
/* Enqueue the trie nodes referenced from the given tree in the
given queue. */
static void
-enqueue(tree, last)
- struct tree *tree;
- struct trie **last;
+enqueue (struct tree *tree, struct trie **last)
{
if (!tree)
return;
@@ -309,10 +301,7 @@ enqueue(tree, last)
from the given tree, given the failure function for their parent as
well as a last resort failure node. */
static void
-treefails(tree, fail, recourse)
- register struct tree *tree;
- struct trie *fail;
- struct trie *recourse;
+treefails (register struct tree *tree, struct trie *fail, struct trie *recourse)
{
register struct tree *link;
@@ -346,10 +335,9 @@ treefails(tree, fail, recourse)
/* Set delta entries for the links of the given tree such that
the preexisting delta value is larger than the current depth. */
static void
-treedelta(tree, depth, delta)
- register struct tree *tree;
- register unsigned int depth;
- unsigned char delta[];
+treedelta (register struct tree *tree,
+ register unsigned int depth,
+ unsigned char delta[])
{
if (!tree)
return;
@@ -361,9 +349,7 @@ treedelta(tree, depth, delta)
/* Return true if A has every label in B. */
static int
-hasevery(a, b)
- register struct tree *a;
- register struct tree *b;
+hasevery (register struct tree *a, register struct tree *b)
{
if (!b)
return 1;
@@ -382,9 +368,7 @@ hasevery(a, b)
/* Compute a vector, indexed by character code, of the trie nodes
referenced from the given tree. */
static void
-treenext(tree, next)
- struct tree *tree;
- struct trie *next[];
+treenext (struct tree *tree, struct trie *next[])
{
if (!tree)
return;
@@ -396,8 +380,7 @@ treenext(tree, next)
/* Compute the shift for each trie node, as well as the delta
table and next cache for the given keyword set. */
char *
-kwsprep(kws)
- kwset_t kws;
+kwsprep (kwset_t kws)
{
register struct kwset *kwset;
register int i;
@@ -515,10 +498,7 @@ kwsprep(kws)
/* Fast boyer-moore search. */
static char *
-bmexec(kws, text, size)
- kwset_t kws;
- char *text;
- size_t size;
+bmexec (kwset_t kws, char *text, size_t size)
{
struct kwset *kwset;
register unsigned char *d1;
@@ -601,11 +581,7 @@ bmexec(kws, text, size)
/* Hairy multiple string search. */
static char *
-cwexec(kws, text, len, kwsmatch)
- kwset_t kws;
- char *text;
- size_t len;
- struct kwsmatch *kwsmatch;
+cwexec (kwset_t kws, char *text, size_t len, struct kwsmatch *kwsmatch)
{
struct kwset *kwset;
struct trie **next, *trie, *accept;
@@ -766,11 +742,7 @@ cwexec(kws, text, len, kwsmatch)
in the referenced location the index number of the particular
keyword matched. */
char *
-kwsexec(kws, text, size, kwsmatch)
- kwset_t kws;
- char *text;
- size_t size;
- struct kwsmatch *kwsmatch;
+kwsexec (kwset_t kws, char *text, size_t size, struct kwsmatch *kwsmatch)
{
struct kwset *kwset;
char *ret;
@@ -793,8 +765,7 @@ kwsexec(kws, text, size, kwsmatch)
/* Free the components of the given keyword set. */
void
-kwsfree(kws)
- kwset_t kws;
+kwsfree (kwset_t kws)
{
struct kwset *kwset;
diff --git a/gnu/usr.bin/grep/obstack.c b/gnu/usr.bin/grep/obstack.c
index c77fdd4..17c6313 100644
--- a/gnu/usr.bin/grep/obstack.c
+++ b/gnu/usr.bin/grep/obstack.c
@@ -1,26 +1,23 @@
-/* obstack.h - object stack macros
- Copyright (C) 1988,89,90,91,92,93,94,96,97, 98 Free Software Foundation, Inc.
+/* obstack.c - subroutines used implicitly by object stack macros
+ Copyright (C) 1988-1994,96,97,98,99 Free Software Foundation, Inc.
+ This file is part of the GNU C Library. Its master source is NOT part of
the C library, however. The master source lives in /gd/gnu/lib.
-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.
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
-This program is free software; you can redistribute it and/or modify it
-under the terms of the GNU General Public License as published by the
-Free Software Foundation; either version 2, or (at your option) any
-later version.
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software Foundation,
-Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
-
-/* $FreeBSD$ */
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
#ifdef HAVE_CONFIG_H
#include <config.h>
@@ -81,7 +78,9 @@ union fooround {long x; double d;};
/* The functions allocating more room by calling `obstack_chunk_alloc'
jump to the handler pointed to by `obstack_alloc_failed_handler'.
- This variable by default points to the internal function
+ This can be set to a user defined function which should either
+ abort gracefully or use longjump - but shouldn't return. This
+ variable by default points to the internal function
`print_and_abort'. */
#if defined (__STDC__) && __STDC__
static void print_and_abort (void);
@@ -145,9 +144,8 @@ struct obstack *_obstack;
CHUNKFUN is the function to use to allocate chunks,
and FREEFUN the function to free them.
- Return nonzero if successful, zero if out of memory.
- To recover from an out of memory error,
- free up some memory, then call this again. */
+ Return nonzero if successful, calls obstack_alloc_failed_handler if
+ allocation fails. */
int
_obstack_begin (h, size, alignment, chunkfun, freefun)
@@ -462,11 +460,16 @@ _obstack_memory_used (h)
# define _(Str) (Str)
# endif
#endif
+#if defined _LIBC && defined USE_IN_LIBIO
+# include <libio/iolibio.h>
+# define fputs(s, f) _IO_fputs (s, f)
+#endif
static void
print_and_abort ()
{
- fputs (_("memory exhausted\n"), stderr);
+ fputs (_("memory exhausted"), stderr);
+ fputc ('\n', stderr);
exit (obstack_exit_failure);
}
diff --git a/gnu/usr.bin/grep/obstack.h b/gnu/usr.bin/grep/obstack.h
index df785c3..4d49ce0 100644
--- a/gnu/usr.bin/grep/obstack.h
+++ b/gnu/usr.bin/grep/obstack.h
@@ -1,26 +1,23 @@
/* obstack.h - object stack macros
- Copyright (C) 1988,89,90,91,92,93,94,96,97, 98 Free Software Foundation, Inc.
+ Copyright (C) 1988,89,90,91,92,93,94,96,97,98,99 Free Software Foundation, Inc.
+ This file is part of the GNU C Library. Its master source is NOT part of
the C library, however. The master source lives in /gd/gnu/lib.
-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.
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
-This program is free software; you can redistribute it and/or modify it
-under the terms of the GNU General Public License as published by the
-Free Software Foundation; either version 2, or (at your option) any
-later version.
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software Foundation,
-Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
-
-/* $FreeBSD$ */
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
/* Summary:
@@ -119,45 +116,39 @@ extern "C" {
may ignore the byte-within-word field of the pointer. */
#ifndef __PTR_TO_INT
-#define __PTR_TO_INT(P) ((P) - (char *) 0)
+# define __PTR_TO_INT(P) ((P) - (char *) 0)
#endif
#ifndef __INT_TO_PTR
-#define __INT_TO_PTR(P) ((P) + (char *) 0)
-#endif
-
-/* We need the type of the resulting object. In ANSI C it is ptrdiff_t
- but in traditional C it is usually long. If we are in ANSI C and
- don't already have ptrdiff_t get it. */
-
-#if defined (__STDC__) && __STDC__ && ! defined (offsetof)
-#if defined (__GNUC__) && defined (IN_GCC)
-/* On Next machine, the system's stddef.h screws up if included
- after we have defined just ptrdiff_t, so include all of stddef.h.
- Otherwise, define just ptrdiff_t, which is all we need. */
-#ifndef __NeXT__
-#define __need_ptrdiff_t
-#endif
+# define __INT_TO_PTR(P) ((P) + (char *) 0)
#endif
-#include <stddef.h>
-#endif
+/* We need the type of the resulting object. If __PTRDIFF_TYPE__ is
+ defined, as with GNU C, use that; that way we don't pollute the
+ namespace with <stddef.h>'s symbols. Otherwise, if <stddef.h> is
+ available, include it and use ptrdiff_t. In traditional C, long is
+ the best that we can do. */
-#if defined (__STDC__) && __STDC__
-#define PTR_INT_TYPE ptrdiff_t
+#ifdef __PTRDIFF_TYPE__
+# define PTR_INT_TYPE __PTRDIFF_TYPE__
#else
-#define PTR_INT_TYPE long
+# ifdef HAVE_STDDEF_H
+# include <stddef.h>
+# define PTR_INT_TYPE ptrdiff_t
+# else
+# define PTR_INT_TYPE long
+# endif
#endif
-#if defined (_LIBC) || defined (HAVE_STRING_H)
-#include <string.h>
-#define _obstack_memcpy(To, From, N) memcpy ((To), (From), (N))
+#if defined _LIBC || defined HAVE_STRING_H
+# include <string.h>
+# define _obstack_memcpy(To, From, N) memcpy ((To), (From), (N))
#else
-#ifdef memcpy
-#define _obstack_memcpy(To, From, N) memcpy ((To), (From), (N))
-#else
-#define _obstack_memcpy(To, From, N) bcopy ((From), (To), (N))
-#endif
+# ifdef memcpy
+# define _obstack_memcpy(To, From, N) memcpy ((To), (From), (N))
+# else
+# define _obstack_memcpy(To, From, N) bcopy ((From), (To), (N))
+# endif
#endif
struct _obstack_chunk /* Lives at front of each chunk. */
@@ -176,7 +167,7 @@ struct obstack /* control current object in current chunk */
char *chunk_limit; /* address of char after current chunk */
PTR_INT_TYPE temp; /* Temporary for some macros. */
int alignment_mask; /* Mask of alignment for each object. */
-#if defined (__STDC__) && __STDC__
+#if defined __STDC__ && __STDC__
/* These prototypes vary based on `use_extra_arg', and we use
casts to the prototypeless function type in all assignments,
but having prototypes here quiets -Wstrict-prototypes. */
@@ -200,7 +191,7 @@ struct obstack /* control current object in current chunk */
/* Declare the external functions we use; they are in obstack.c. */
-#if defined (__STDC__) && __STDC__
+#if defined __STDC__ && __STDC__
extern void _obstack_newchunk (struct obstack *, int);
extern void _obstack_free (struct obstack *, void *);
extern int _obstack_begin (struct obstack *, int, int,
@@ -217,7 +208,7 @@ extern int _obstack_begin_1 ();
extern int _obstack_memory_used ();
#endif
-#if defined (__STDC__) && __STDC__
+#if defined __STDC__ && __STDC__
/* Do the function-declarations after the structs
but before defining the macros. */
@@ -263,9 +254,10 @@ int obstack_memory_used (struct obstack *obstack);
so we do not declare them. */
/* Error handler called when `obstack_chunk_alloc' failed to allocate
- more memory. This can be set to a user defined function. The
- default action is to print a message and abort. */
-#if defined (__STDC__) && __STDC__
+ more memory. This can be set to a user defined function which
+ should either abort gracefully or use longjump - but shouldn't
+ return. The default action is to print a message and abort. */
+#if defined __STDC__ && __STDC__
extern void (*obstack_alloc_failed_handler) (void);
#else
extern void (*obstack_alloc_failed_handler) ();
@@ -294,53 +286,53 @@ extern int obstack_exit_failure;
/* To prevent prototype warnings provide complete argument list in
standard C version. */
-#if defined (__STDC__) && __STDC__
+#if defined __STDC__ && __STDC__
-#define obstack_init(h) \
+# define obstack_init(h) \
_obstack_begin ((h), 0, 0, \
(void *(*) (long)) obstack_chunk_alloc, (void (*) (void *)) obstack_chunk_free)
-#define obstack_begin(h, size) \
+# define obstack_begin(h, size) \
_obstack_begin ((h), (size), 0, \
(void *(*) (long)) obstack_chunk_alloc, (void (*) (void *)) obstack_chunk_free)
-#define obstack_specify_allocation(h, size, alignment, chunkfun, freefun) \
+# define obstack_specify_allocation(h, size, alignment, chunkfun, freefun) \
_obstack_begin ((h), (size), (alignment), \
(void *(*) (long)) (chunkfun), (void (*) (void *)) (freefun))
-#define obstack_specify_allocation_with_arg(h, size, alignment, chunkfun, freefun, arg) \
+# define obstack_specify_allocation_with_arg(h, size, alignment, chunkfun, freefun, arg) \
_obstack_begin_1 ((h), (size), (alignment), \
(void *(*) (void *, long)) (chunkfun), \
(void (*) (void *, void *)) (freefun), (arg))
-#define obstack_chunkfun(h, newchunkfun) \
+# define obstack_chunkfun(h, newchunkfun) \
((h) -> chunkfun = (struct _obstack_chunk *(*)(void *, long)) (newchunkfun))
-#define obstack_freefun(h, newfreefun) \
+# define obstack_freefun(h, newfreefun) \
((h) -> freefun = (void (*)(void *, struct _obstack_chunk *)) (newfreefun))
#else
-#define obstack_init(h) \
+# define obstack_init(h) \
_obstack_begin ((h), 0, 0, \
(void *(*) ()) obstack_chunk_alloc, (void (*) ()) obstack_chunk_free)
-#define obstack_begin(h, size) \
+# define obstack_begin(h, size) \
_obstack_begin ((h), (size), 0, \
(void *(*) ()) obstack_chunk_alloc, (void (*) ()) obstack_chunk_free)
-#define obstack_specify_allocation(h, size, alignment, chunkfun, freefun) \
+# define obstack_specify_allocation(h, size, alignment, chunkfun, freefun) \
_obstack_begin ((h), (size), (alignment), \
(void *(*) ()) (chunkfun), (void (*) ()) (freefun))
-#define obstack_specify_allocation_with_arg(h, size, alignment, chunkfun, freefun, arg) \
+# define obstack_specify_allocation_with_arg(h, size, alignment, chunkfun, freefun, arg) \
_obstack_begin_1 ((h), (size), (alignment), \
(void *(*) ()) (chunkfun), (void (*) ()) (freefun), (arg))
-#define obstack_chunkfun(h, newchunkfun) \
+# define obstack_chunkfun(h, newchunkfun) \
((h) -> chunkfun = (struct _obstack_chunk *(*)()) (newchunkfun))
-#define obstack_freefun(h, newfreefun) \
+# define obstack_freefun(h, newfreefun) \
((h) -> freefun = (void (*)()) (newfreefun))
#endif
@@ -351,30 +343,30 @@ extern int obstack_exit_failure;
#define obstack_memory_used(h) _obstack_memory_used (h)
-#if defined (__GNUC__) && defined (__STDC__) && __STDC__
+#if defined __GNUC__ && defined __STDC__ && __STDC__
/* NextStep 2.0 cc is really gcc 1.93 but it defines __GNUC__ = 2 and
does not implement __extension__. But that compiler doesn't define
__GNUC_MINOR__. */
-#if __GNUC__ < 2 || (__NeXT__ && !__GNUC_MINOR__)
-#define __extension__
-#endif
+# if __GNUC__ < 2 || (__NeXT__ && !__GNUC_MINOR__)
+# define __extension__
+# endif
/* For GNU C, if not -traditional,
we can define these macros to compute all args only once
without using a global variable.
Also, we can avoid using the `temp' slot, to make faster code. */
-#define obstack_object_size(OBSTACK) \
+# define obstack_object_size(OBSTACK) \
__extension__ \
({ struct obstack *__o = (OBSTACK); \
(unsigned) (__o->next_free - __o->object_base); })
-#define obstack_room(OBSTACK) \
+# define obstack_room(OBSTACK) \
__extension__ \
({ struct obstack *__o = (OBSTACK); \
(unsigned) (__o->chunk_limit - __o->next_free); })
-#define obstack_make_room(OBSTACK,length) \
+# define obstack_make_room(OBSTACK,length) \
__extension__ \
({ struct obstack *__o = (OBSTACK); \
int __len = (length); \
@@ -382,7 +374,12 @@ __extension__ \
_obstack_newchunk (__o, __len); \
(void) 0; })
-#define obstack_grow(OBSTACK,where,length) \
+# define obstack_empty_p(OBSTACK) \
+ __extension__ \
+ ({ struct obstack *__o = (OBSTACK); \
+ (__o->chunk->prev == 0 && __o->next_free - __o->chunk->contents == 0); })
+
+# define obstack_grow(OBSTACK,where,length) \
__extension__ \
({ struct obstack *__o = (OBSTACK); \
int __len = (length); \
@@ -392,7 +389,7 @@ __extension__ \
__o->next_free += __len; \
(void) 0; })
-#define obstack_grow0(OBSTACK,where,length) \
+# define obstack_grow0(OBSTACK,where,length) \
__extension__ \
({ struct obstack *__o = (OBSTACK); \
int __len = (length); \
@@ -403,7 +400,7 @@ __extension__ \
*(__o->next_free)++ = 0; \
(void) 0; })
-#define obstack_1grow(OBSTACK,datum) \
+# define obstack_1grow(OBSTACK,datum) \
__extension__ \
({ struct obstack *__o = (OBSTACK); \
if (__o->next_free + 1 > __o->chunk_limit) \
@@ -415,7 +412,7 @@ __extension__ \
and that the data added so far to the current object
shares that much alignment. */
-#define obstack_ptr_grow(OBSTACK,datum) \
+# define obstack_ptr_grow(OBSTACK,datum) \
__extension__ \
({ struct obstack *__o = (OBSTACK); \
if (__o->next_free + sizeof (void *) > __o->chunk_limit) \
@@ -423,7 +420,7 @@ __extension__ \
*((void **)__o->next_free)++ = ((void *)datum); \
(void) 0; })
-#define obstack_int_grow(OBSTACK,datum) \
+# define obstack_int_grow(OBSTACK,datum) \
__extension__ \
({ struct obstack *__o = (OBSTACK); \
if (__o->next_free + sizeof (int) > __o->chunk_limit) \
@@ -431,10 +428,10 @@ __extension__ \
*((int *)__o->next_free)++ = ((int)datum); \
(void) 0; })
-#define obstack_ptr_grow_fast(h,aptr) (*((void **) (h)->next_free)++ = (void *)aptr)
-#define obstack_int_grow_fast(h,aint) (*((int *) (h)->next_free)++ = (int) aint)
+# define obstack_ptr_grow_fast(h,aptr) (*((void **) (h)->next_free)++ = (void *)aptr)
+# define obstack_int_grow_fast(h,aint) (*((int *) (h)->next_free)++ = (int) aint)
-#define obstack_blank(OBSTACK,length) \
+# define obstack_blank(OBSTACK,length) \
__extension__ \
({ struct obstack *__o = (OBSTACK); \
int __len = (length); \
@@ -443,19 +440,19 @@ __extension__ \
__o->next_free += __len; \
(void) 0; })
-#define obstack_alloc(OBSTACK,length) \
+# define obstack_alloc(OBSTACK,length) \
__extension__ \
({ struct obstack *__h = (OBSTACK); \
obstack_blank (__h, (length)); \
obstack_finish (__h); })
-#define obstack_copy(OBSTACK,where,length) \
+# define obstack_copy(OBSTACK,where,length) \
__extension__ \
({ struct obstack *__h = (OBSTACK); \
obstack_grow (__h, (where), (length)); \
obstack_finish (__h); })
-#define obstack_copy0(OBSTACK,where,length) \
+# define obstack_copy0(OBSTACK,where,length) \
__extension__ \
({ struct obstack *__h = (OBSTACK); \
obstack_grow0 (__h, (where), (length)); \
@@ -463,7 +460,7 @@ __extension__ \
/* The local variable is named __o1 to avoid a name conflict
when obstack_blank is called. */
-#define obstack_finish(OBSTACK) \
+# define obstack_finish(OBSTACK) \
__extension__ \
({ struct obstack *__o1 = (OBSTACK); \
void *value; \
@@ -479,41 +476,44 @@ __extension__ \
__o1->object_base = __o1->next_free; \
value; })
-#define obstack_free(OBSTACK, OBJ) \
+# define obstack_free(OBSTACK, OBJ) \
__extension__ \
({ struct obstack *__o = (OBSTACK); \
void *__obj = (OBJ); \
if (__obj > (void *)__o->chunk && __obj < (void *)__o->chunk_limit) \
- __o->next_free = __o->object_base = __obj; \
+ __o->next_free = __o->object_base = (char *)__obj; \
else (obstack_free) (__o, __obj); })
#else /* not __GNUC__ or not __STDC__ */
-#define obstack_object_size(h) \
+# define obstack_object_size(h) \
(unsigned) ((h)->next_free - (h)->object_base)
-#define obstack_room(h) \
+# define obstack_room(h) \
(unsigned) ((h)->chunk_limit - (h)->next_free)
+# define obstack_empty_p(h) \
+ ((h)->chunk->prev == 0 && (h)->next_free - (h)->chunk->contents == 0)
+
/* Note that the call to _obstack_newchunk is enclosed in (..., 0)
so that we can avoid having void expressions
in the arms of the conditional expression.
Casting the third operand to void was tried before,
but some compilers won't accept it. */
-#define obstack_make_room(h,length) \
+# define obstack_make_room(h,length) \
( (h)->temp = (length), \
(((h)->next_free + (h)->temp > (h)->chunk_limit) \
? (_obstack_newchunk ((h), (h)->temp), 0) : 0))
-#define obstack_grow(h,where,length) \
+# define obstack_grow(h,where,length) \
( (h)->temp = (length), \
(((h)->next_free + (h)->temp > (h)->chunk_limit) \
? (_obstack_newchunk ((h), (h)->temp), 0) : 0), \
_obstack_memcpy ((h)->next_free, (char *) (where), (h)->temp), \
(h)->next_free += (h)->temp)
-#define obstack_grow0(h,where,length) \
+# define obstack_grow0(h,where,length) \
( (h)->temp = (length), \
(((h)->next_free + (h)->temp + 1 > (h)->chunk_limit) \
? (_obstack_newchunk ((h), (h)->temp + 1), 0) : 0), \
@@ -521,40 +521,40 @@ __extension__ \
(h)->next_free += (h)->temp, \
*((h)->next_free)++ = 0)
-#define obstack_1grow(h,datum) \
+# define obstack_1grow(h,datum) \
( (((h)->next_free + 1 > (h)->chunk_limit) \
? (_obstack_newchunk ((h), 1), 0) : 0), \
(*((h)->next_free)++ = (datum)))
-#define obstack_ptr_grow(h,datum) \
+# define obstack_ptr_grow(h,datum) \
( (((h)->next_free + sizeof (char *) > (h)->chunk_limit) \
? (_obstack_newchunk ((h), sizeof (char *)), 0) : 0), \
(*((char **) (((h)->next_free+=sizeof(char *))-sizeof(char *))) = ((char *) datum)))
-#define obstack_int_grow(h,datum) \
+# define obstack_int_grow(h,datum) \
( (((h)->next_free + sizeof (int) > (h)->chunk_limit) \
? (_obstack_newchunk ((h), sizeof (int)), 0) : 0), \
(*((int *) (((h)->next_free+=sizeof(int))-sizeof(int))) = ((int) datum)))
-#define obstack_ptr_grow_fast(h,aptr) (*((char **) (h)->next_free)++ = (char *) aptr)
-#define obstack_int_grow_fast(h,aint) (*((int *) (h)->next_free)++ = (int) aint)
+# define obstack_ptr_grow_fast(h,aptr) (*((char **) (h)->next_free)++ = (char *) aptr)
+# define obstack_int_grow_fast(h,aint) (*((int *) (h)->next_free)++ = (int) aint)
-#define obstack_blank(h,length) \
+# define obstack_blank(h,length) \
( (h)->temp = (length), \
(((h)->chunk_limit - (h)->next_free < (h)->temp) \
? (_obstack_newchunk ((h), (h)->temp), 0) : 0), \
((h)->next_free += (h)->temp))
-#define obstack_alloc(h,length) \
+# define obstack_alloc(h,length) \
(obstack_blank ((h), (length)), obstack_finish ((h)))
-#define obstack_copy(h,where,length) \
+# define obstack_copy(h,where,length) \
(obstack_grow ((h), (where), (length)), obstack_finish ((h)))
-#define obstack_copy0(h,where,length) \
+# define obstack_copy0(h,where,length) \
(obstack_grow0 ((h), (where), (length)), obstack_finish ((h)))
-#define obstack_finish(h) \
+# define obstack_finish(h) \
( ((h)->next_free == (h)->object_base \
? (((h)->maybe_empty_object = 1), 0) \
: 0), \
@@ -568,21 +568,21 @@ __extension__ \
(h)->object_base = (h)->next_free, \
__INT_TO_PTR ((h)->temp))
-#if defined (__STDC__) && __STDC__
-#define obstack_free(h,obj) \
+# if defined __STDC__ && __STDC__
+# define obstack_free(h,obj) \
( (h)->temp = (char *) (obj) - (char *) (h)->chunk, \
(((h)->temp > 0 && (h)->temp < (h)->chunk_limit - (char *) (h)->chunk)\
? (int) ((h)->next_free = (h)->object_base \
= (h)->temp + (char *) (h)->chunk) \
: (((obstack_free) ((h), (h)->temp + (char *) (h)->chunk), 0), 0)))
-#else
-#define obstack_free(h,obj) \
+# else
+# define obstack_free(h,obj) \
( (h)->temp = (char *) (obj) - (char *) (h)->chunk, \
(((h)->temp > 0 && (h)->temp < (h)->chunk_limit - (char *) (h)->chunk)\
? (int) ((h)->next_free = (h)->object_base \
= (h)->temp + (char *) (h)->chunk) \
: (_obstack_free ((h), (h)->temp + (char *) (h)->chunk), 0)))
-#endif
+# endif
#endif /* not __GNUC__ or not __STDC__ */
OpenPOWER on IntegriCloud