gnu: remove gnugrep and libgnuregex
Differential Revision: https://reviews.freebsd.org/D27732
This commit is contained in:
parent
d1c965f143
commit
47d1ad2413
@ -1,32 +0,0 @@
|
||||
# $FreeBSD$
|
||||
|
||||
LIB= gnuregex
|
||||
SHLIB_MAJOR= 5
|
||||
|
||||
REGEXDIR= ${SRCTOP}/contrib/libgnuregex
|
||||
.PATH: ${REGEXDIR}
|
||||
|
||||
WARNS?= 1
|
||||
|
||||
SRCS= gnuregex.c
|
||||
INCSGROUPS= INCS WRINCS PXINCS
|
||||
INCS= regex.h.patched
|
||||
INCSNAME= regex.h
|
||||
INCSDIR= ${INCLUDEDIR}/gnu
|
||||
WRINCS= gnuregex.h
|
||||
PXINCS= ${REGEXDIR}/regex.h
|
||||
PXINCSDIR= ${INCSDIR}/posix
|
||||
|
||||
CFLAGS+= -D__attribute_warn_unused_result__=""
|
||||
CFLAGS+= -DHAVE_CONFIG_H -I${.CURDIR} -I${REGEXDIR}
|
||||
|
||||
CLEANFILES= regex.h.patched gnuregex.c
|
||||
regex.h.patched: regex.h
|
||||
sed 's=<posix/regex\.h>=<gnu/posix/regex.h>=g' \
|
||||
< ${.ALLSRC} > ${.TARGET}
|
||||
|
||||
gnuregex.c: regex.c
|
||||
sed 's=<regex\.h>=<gnu/regex.h>=g' \
|
||||
< ${.ALLSRC} > ${.TARGET}
|
||||
|
||||
.include <bsd.lib.mk>
|
@ -1,16 +0,0 @@
|
||||
# $FreeBSD$
|
||||
# Autogenerated - do NOT edit!
|
||||
|
||||
DIRDEPS = \
|
||||
include \
|
||||
include/xlocale \
|
||||
lib/${CSU_DIR} \
|
||||
lib/libc \
|
||||
lib/libcompiler_rt \
|
||||
|
||||
|
||||
.include <dirdeps.mk>
|
||||
|
||||
.if ${DEP_RELDIR} == ${_DEP_RELDIR}
|
||||
# local dependencies - needed for -jN in clean tree
|
||||
.endif
|
@ -1,15 +0,0 @@
|
||||
/* $FreeBSD$ */
|
||||
|
||||
#define _REGEX_RE_COMP 1
|
||||
#define HAVE_LANGINFO_H 1
|
||||
#define HAVE_LANGINFO_CODESET 1
|
||||
#define HAVE_LOCALE_H 1
|
||||
#define HAVE_WCHAR_H 1
|
||||
#define HAVE_WCTYPE_H 1
|
||||
#define HAVE_ISBLANK 1
|
||||
#define HAVE_WCRTOMB 1
|
||||
#define HAVE_MBRTOWC 1
|
||||
#define HAVE_WCSCOLL 1
|
||||
#define HAVE_ALLOCA 1
|
||||
#define HAVE_STDBOOL_H 1
|
||||
#define HAVE_STDINT_H 1
|
@ -1,33 +0,0 @@
|
||||
/*-
|
||||
* Copyright (c) 2004 David E. O'Brien
|
||||
* Copyright (c) 2004 Andrey A. Chernov
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
#ifdef __GNUC__
|
||||
#warning "Use -I/usr/include/gnu and <regex.h> instead of <gnuregex.h>"
|
||||
#endif
|
||||
#include <gnu/regex.h>
|
@ -1,54 +0,0 @@
|
||||
/* $FreeBSD$ */
|
||||
#ifndef _REGEX_H
|
||||
|
||||
#ifndef __USE_GNU
|
||||
#define __USE_GNU
|
||||
#endif
|
||||
|
||||
#include <posix/regex.h>
|
||||
|
||||
/* Document internal interfaces. */
|
||||
extern reg_syntax_t __re_set_syntax (reg_syntax_t __syntax);
|
||||
|
||||
extern const char *__re_compile_pattern (const char *__pattern, size_t __length,
|
||||
struct re_pattern_buffer *__buffer);
|
||||
|
||||
extern int __re_compile_fastmap (struct re_pattern_buffer *__buffer);
|
||||
|
||||
extern int __re_search (struct re_pattern_buffer *__buffer, const char *__string,
|
||||
int __length, int __start, int __range,
|
||||
struct re_registers *__regs);
|
||||
|
||||
extern int __re_search_2 (struct re_pattern_buffer *__buffer,
|
||||
const char *__string1, int __length1,
|
||||
const char *__string2, int __length2, int __start,
|
||||
int __range, struct re_registers *__regs, int __stop);
|
||||
|
||||
extern int __re_match (struct re_pattern_buffer *__buffer, const char *__string,
|
||||
int __length, int __start, struct re_registers *__regs);
|
||||
|
||||
extern int __re_match_2 (struct re_pattern_buffer *__buffer,
|
||||
const char *__string1, int __length1,
|
||||
const char *__string2, int __length2, int __start,
|
||||
struct re_registers *__regs, int __stop);
|
||||
|
||||
extern void __re_set_registers (struct re_pattern_buffer *__buffer,
|
||||
struct re_registers *__regs,
|
||||
unsigned int __num_regs,
|
||||
regoff_t *__starts, regoff_t *__ends);
|
||||
|
||||
extern int __regcomp (regex_t *__restrict __preg,
|
||||
const char *__restrict __pattern,
|
||||
int __cflags);
|
||||
|
||||
extern int __regexec (const regex_t *__restrict __preg,
|
||||
const char *__restrict __string, size_t __nmatch,
|
||||
regmatch_t __pmatch[__restrict_arr],
|
||||
int __eflags);
|
||||
|
||||
extern size_t __regerror (int __errcode, const regex_t *__restrict __preg,
|
||||
char *__restrict __errbuf, size_t __errbuf_size);
|
||||
|
||||
extern void __regfree (regex_t *__preg);
|
||||
|
||||
#endif /* _REGEX_H */
|
@ -1,44 +0,0 @@
|
||||
Mike Haertel wrote the main program and the dfa and kwset matchers.
|
||||
|
||||
Arthur David Olson contributed the heuristics for finding fixed substrings
|
||||
at the end of dfa.c.
|
||||
|
||||
Richard Stallman and Karl Berry wrote the regex backtracking matcher.
|
||||
|
||||
Henry Spencer wrote the original test suite from which grep's was derived.
|
||||
|
||||
Scott Anderson invented the Khadafy test.
|
||||
|
||||
David MacKenzie wrote the automatic configuration software use to
|
||||
produce the configure script.
|
||||
|
||||
Authors of the replacements for standard library routines are identified
|
||||
in the corresponding source files.
|
||||
|
||||
The idea of using Boyer-Moore type algorithms to quickly filter out
|
||||
non-matching text before calling the regexp matcher was originally due
|
||||
to James Woods. He also contributed some code to early versions of
|
||||
GNU grep.
|
||||
|
||||
Mike Haertel would like to thank Andrew Hume for many fascinating discussions
|
||||
of string searching issues over the years. Hume & Sunday's excellent
|
||||
paper on fast string searching (AT&T Bell Laboratories CSTR #156)
|
||||
describes some of the history of the subject, as well as providing
|
||||
exhaustive performance analysis of various implementation alternatives.
|
||||
The inner loop of GNU grep is similar to Hume & Sunday's recommended
|
||||
"Tuned Boyer Moore" inner loop.
|
||||
|
||||
More work was done on regex.[ch] by Ulrich Drepper and Arnold
|
||||
Robbins. Regex is now part of GNU C library, see this package
|
||||
for complete details and credits.
|
||||
|
||||
Arnold Robbins contributed to improve dfa.[ch]. In fact
|
||||
it came straight from gawk-3.0.3 with small editing and fixes.
|
||||
|
||||
Many folks contributed see THANKS, if I omited someone please
|
||||
send me email.
|
||||
|
||||
Alain Magloire maintained GNU grep until version 2.5e.
|
||||
|
||||
Bernhard "Bero" Rosenkränzer <bero@redhat.com> is the current maintainer.
|
||||
|
@ -1,340 +0,0 @@
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 2, June 1991
|
||||
|
||||
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
|
||||
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The licenses for most software are designed to take away your
|
||||
freedom to share and change it. By contrast, the GNU General Public
|
||||
License is intended to guarantee your freedom to share and change free
|
||||
software--to make sure the software is free for all its users. This
|
||||
General Public License applies to most of the Free Software
|
||||
Foundation's software and to any other program whose authors commit to
|
||||
using it. (Some other Free Software Foundation software is covered by
|
||||
the GNU Library General Public License instead.) You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
this service if you wish), that you receive source code or can get it
|
||||
if you want it, that you can change the software or use pieces of it
|
||||
in new free programs; and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to make restrictions that forbid
|
||||
anyone to deny you these rights or to ask you to surrender the rights.
|
||||
These restrictions translate to certain responsibilities for you if you
|
||||
distribute copies of the software, or if you modify it.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must give the recipients all the rights that
|
||||
you have. You must make sure that they, too, receive or can get the
|
||||
source code. And you must show them these terms so they know their
|
||||
rights.
|
||||
|
||||
We protect your rights with two steps: (1) copyright the software, and
|
||||
(2) offer you this license which gives you legal permission to copy,
|
||||
distribute and/or modify the software.
|
||||
|
||||
Also, for each author's protection and ours, we want to make certain
|
||||
that everyone understands that there is no warranty for this free
|
||||
software. If the software is modified by someone else and passed on, we
|
||||
want its recipients to know that what they have is not the original, so
|
||||
that any problems introduced by others will not reflect on the original
|
||||
authors' reputations.
|
||||
|
||||
Finally, any free program is threatened constantly by software
|
||||
patents. We wish to avoid the danger that redistributors of a free
|
||||
program will individually obtain patent licenses, in effect making the
|
||||
program proprietary. To prevent this, we have made it clear that any
|
||||
patent must be licensed for everyone's free use or not licensed at all.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. This License applies to any program or other work which contains
|
||||
a notice placed by the copyright holder saying it may be distributed
|
||||
under the terms of this General Public License. The "Program", below,
|
||||
refers to any such program or work, and a "work based on the Program"
|
||||
means either the Program or any derivative work under copyright law:
|
||||
that is to say, a work containing the Program or a portion of it,
|
||||
either verbatim or with modifications and/or translated into another
|
||||
language. (Hereinafter, translation is included without limitation in
|
||||
the term "modification".) Each licensee is addressed as "you".
|
||||
|
||||
Activities other than copying, distribution and modification are not
|
||||
covered by this License; they are outside its scope. The act of
|
||||
running the Program is not restricted, and the output from the Program
|
||||
is covered only if its contents constitute a work based on the
|
||||
Program (independent of having been made by running the Program).
|
||||
Whether that is true depends on what the Program does.
|
||||
|
||||
1. You may copy and distribute verbatim copies of the Program's
|
||||
source code as you receive it, in any medium, provided that you
|
||||
conspicuously and appropriately publish on each copy an appropriate
|
||||
copyright notice and disclaimer of warranty; keep intact all the
|
||||
notices that refer to this License and to the absence of any warranty;
|
||||
and give any other recipients of the Program a copy of this License
|
||||
along with the Program.
|
||||
|
||||
You may charge a fee for the physical act of transferring a copy, and
|
||||
you may at your option offer warranty protection in exchange for a fee.
|
||||
|
||||
2. You may modify your copy or copies of the Program or any portion
|
||||
of it, thus forming a work based on the Program, and copy and
|
||||
distribute such modifications or work under the terms of Section 1
|
||||
above, provided that you also meet all of these conditions:
|
||||
|
||||
a) You must cause the modified files to carry prominent notices
|
||||
stating that you changed the files and the date of any change.
|
||||
|
||||
b) You must cause any work that you distribute or publish, that in
|
||||
whole or in part contains or is derived from the Program or any
|
||||
part thereof, to be licensed as a whole at no charge to all third
|
||||
parties under the terms of this License.
|
||||
|
||||
c) If the modified program normally reads commands interactively
|
||||
when run, you must cause it, when started running for such
|
||||
interactive use in the most ordinary way, to print or display an
|
||||
announcement including an appropriate copyright notice and a
|
||||
notice that there is no warranty (or else, saying that you provide
|
||||
a warranty) and that users may redistribute the program under
|
||||
these conditions, and telling the user how to view a copy of this
|
||||
License. (Exception: if the Program itself is interactive but
|
||||
does not normally print such an announcement, your work based on
|
||||
the Program is not required to print an announcement.)
|
||||
|
||||
These requirements apply to the modified work as a whole. If
|
||||
identifiable sections of that work are not derived from the Program,
|
||||
and can be reasonably considered independent and separate works in
|
||||
themselves, then this License, and its terms, do not apply to those
|
||||
sections when you distribute them as separate works. But when you
|
||||
distribute the same sections as part of a whole which is a work based
|
||||
on the Program, the distribution of the whole must be on the terms of
|
||||
this License, whose permissions for other licensees extend to the
|
||||
entire whole, and thus to each and every part regardless of who wrote it.
|
||||
|
||||
Thus, it is not the intent of this section to claim rights or contest
|
||||
your rights to work written entirely by you; rather, the intent is to
|
||||
exercise the right to control the distribution of derivative or
|
||||
collective works based on the Program.
|
||||
|
||||
In addition, mere aggregation of another work not based on the Program
|
||||
with the Program (or with a work based on the Program) on a volume of
|
||||
a storage or distribution medium does not bring the other work under
|
||||
the scope of this License.
|
||||
|
||||
3. You may copy and distribute the Program (or a work based on it,
|
||||
under Section 2) in object code or executable form under the terms of
|
||||
Sections 1 and 2 above provided that you also do one of the following:
|
||||
|
||||
a) Accompany it with the complete corresponding machine-readable
|
||||
source code, which must be distributed under the terms of Sections
|
||||
1 and 2 above on a medium customarily used for software interchange; or,
|
||||
|
||||
b) Accompany it with a written offer, valid for at least three
|
||||
years, to give any third party, for a charge no more than your
|
||||
cost of physically performing source distribution, a complete
|
||||
machine-readable copy of the corresponding source code, to be
|
||||
distributed under the terms of Sections 1 and 2 above on a medium
|
||||
customarily used for software interchange; or,
|
||||
|
||||
c) Accompany it with the information you received as to the offer
|
||||
to distribute corresponding source code. (This alternative is
|
||||
allowed only for noncommercial distribution and only if you
|
||||
received the program in object code or executable form with such
|
||||
an offer, in accord with Subsection b above.)
|
||||
|
||||
The source code for a work means the preferred form of the work for
|
||||
making modifications to it. For an executable work, complete source
|
||||
code means all the source code for all modules it contains, plus any
|
||||
associated interface definition files, plus the scripts used to
|
||||
control compilation and installation of the executable. However, as a
|
||||
special exception, the source code distributed need not include
|
||||
anything that is normally distributed (in either source or binary
|
||||
form) with the major components (compiler, kernel, and so on) of the
|
||||
operating system on which the executable runs, unless that component
|
||||
itself accompanies the executable.
|
||||
|
||||
If distribution of executable or object code is made by offering
|
||||
access to copy from a designated place, then offering equivalent
|
||||
access to copy the source code from the same place counts as
|
||||
distribution of the source code, even though third parties are not
|
||||
compelled to copy the source along with the object code.
|
||||
|
||||
4. You may not copy, modify, sublicense, or distribute the Program
|
||||
except as expressly provided under this License. Any attempt
|
||||
otherwise to copy, modify, sublicense or distribute the Program is
|
||||
void, and will automatically terminate your rights under this License.
|
||||
However, parties who have received copies, or rights, from you under
|
||||
this License will not have their licenses terminated so long as such
|
||||
parties remain in full compliance.
|
||||
|
||||
5. You are not required to accept this License, since you have not
|
||||
signed it. However, nothing else grants you permission to modify or
|
||||
distribute the Program or its derivative works. These actions are
|
||||
prohibited by law if you do not accept this License. Therefore, by
|
||||
modifying or distributing the Program (or any work based on the
|
||||
Program), you indicate your acceptance of this License to do so, and
|
||||
all its terms and conditions for copying, distributing or modifying
|
||||
the Program or works based on it.
|
||||
|
||||
6. Each time you redistribute the Program (or any work based on the
|
||||
Program), the recipient automatically receives a license from the
|
||||
original licensor to copy, distribute or modify the Program subject to
|
||||
these terms and conditions. You may not impose any further
|
||||
restrictions on the recipients' exercise of the rights granted herein.
|
||||
You are not responsible for enforcing compliance by third parties to
|
||||
this License.
|
||||
|
||||
7. If, as a consequence of a court judgment or allegation of patent
|
||||
infringement or for any other reason (not limited to patent issues),
|
||||
conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot
|
||||
distribute so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you
|
||||
may not distribute the Program at all. For example, if a patent
|
||||
license would not permit royalty-free redistribution of the Program by
|
||||
all those who receive copies directly or indirectly through you, then
|
||||
the only way you could satisfy both it and this License would be to
|
||||
refrain entirely from distribution of the Program.
|
||||
|
||||
If any portion of this section is held invalid or unenforceable under
|
||||
any particular circumstance, the balance of the section is intended to
|
||||
apply and the section as a whole is intended to apply in other
|
||||
circumstances.
|
||||
|
||||
It is not the purpose of this section to induce you to infringe any
|
||||
patents or other property right claims or to contest validity of any
|
||||
such claims; this section has the sole purpose of protecting the
|
||||
integrity of the free software distribution system, which is
|
||||
implemented by public license practices. Many people have made
|
||||
generous contributions to the wide range of software distributed
|
||||
through that system in reliance on consistent application of that
|
||||
system; it is up to the author/donor to decide if he or she is willing
|
||||
to distribute software through any other system and a licensee cannot
|
||||
impose that choice.
|
||||
|
||||
This section is intended to make thoroughly clear what is believed to
|
||||
be a consequence of the rest of this License.
|
||||
|
||||
8. If the distribution and/or use of the Program is restricted in
|
||||
certain countries either by patents or by copyrighted interfaces, the
|
||||
original copyright holder who places the Program under this License
|
||||
may add an explicit geographical distribution limitation excluding
|
||||
those countries, so that distribution is permitted only in or among
|
||||
countries not thus excluded. In such case, this License incorporates
|
||||
the limitation as if written in the body of this License.
|
||||
|
||||
9. The Free Software Foundation may publish revised and/or new versions
|
||||
of the General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the Program
|
||||
specifies a version number of this License which applies to it and "any
|
||||
later version", you have the option of following the terms and conditions
|
||||
either of that version or of any later version published by the Free
|
||||
Software Foundation. If the Program does not specify a version number of
|
||||
this License, you may choose any version ever published by the Free Software
|
||||
Foundation.
|
||||
|
||||
10. If you wish to incorporate parts of the Program into other free
|
||||
programs whose distribution conditions are different, write to the author
|
||||
to ask for permission. For software which is copyrighted by the Free
|
||||
Software Foundation, write to the Free Software Foundation; we sometimes
|
||||
make exceptions for this. Our decision will be guided by the two goals
|
||||
of preserving the free status of all derivatives of our free software and
|
||||
of promoting the sharing and reuse of software generally.
|
||||
|
||||
NO WARRANTY
|
||||
|
||||
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
|
||||
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
|
||||
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
|
||||
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
|
||||
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
|
||||
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
|
||||
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
|
||||
REPAIR OR CORRECTION.
|
||||
|
||||
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
|
||||
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
|
||||
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
|
||||
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
|
||||
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
|
||||
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
|
||||
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGES.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
convey the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) 19yy <name of author>
|
||||
|
||||
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 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program is interactive, make it output a short notice like this
|
||||
when it starts in an interactive mode:
|
||||
|
||||
Gnomovision version 69, Copyright (C) 19yy name of author
|
||||
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, the commands you use may
|
||||
be called something other than `show w' and `show c'; they could even be
|
||||
mouse-clicks or menu items--whatever suits your program.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or your
|
||||
school, if any, to sign a "copyright disclaimer" for the program, if
|
||||
necessary. Here is a sample; alter the names:
|
||||
|
||||
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
|
||||
`Gnomovision' (which makes passes at compilers) written by James Hacker.
|
||||
|
||||
<signature of Ty Coon>, 1 April 1989
|
||||
Ty Coon, President of Vice
|
||||
|
||||
This General Public License does not permit incorporating your program into
|
||||
proprietary programs. If your program is a subroutine library, you may
|
||||
consider it more useful to permit linking proprietary applications with the
|
||||
library. If this is what you want to do, use the GNU Library General
|
||||
Public License instead of this License.
|
File diff suppressed because it is too large
Load Diff
@ -1,37 +0,0 @@
|
||||
$FreeBSD$
|
||||
|
||||
GNU grep
|
||||
|
||||
Original source distribution can be found at:
|
||||
http://ftp.gnu.org/pub/gnu/grep/
|
||||
|
||||
Due to an unfortunate number of bugs and performance problems in
|
||||
GNU grep 2.5.1, various patches from The Fedora Project have been applied.
|
||||
These patches can be extracted from the SRPM package available at:
|
||||
|
||||
http://download.fedora.redhat.com/pub/fedora/linux/core/test/
|
||||
3.92/SRPMS/grep-2.5.1-48.src.rpm
|
||||
|
||||
The following patches have been applied:
|
||||
|
||||
grep-2.5-i18n.patch
|
||||
grep-2.5.1-bracket.patch
|
||||
grep-2.5.1-color.patch
|
||||
grep-2.5.1-dfa-optional.patch
|
||||
grep-2.5.1-egf-speedup.patch
|
||||
grep-2.5.1-fgrep.patch
|
||||
grep-2.5.1-icolor.patch
|
||||
grep-2.5.1-oi.patch
|
||||
grep-2.5.1-w.patch
|
||||
|
||||
In addition to these, some FreeBSD-specific changes have been made
|
||||
to add bzip2 support, etc.
|
||||
|
||||
Due to the large number of patches applied, conflicts are likely with
|
||||
future releases. However, most of the patches are either (a) small bug
|
||||
fixes that have been fed upstream, or (b) performance improvements that
|
||||
could be reverted without loss of functionality.
|
||||
|
||||
It is suggested that those planning to import a newer release of GNU grep
|
||||
should revert all local changes since the 2.5.1 import before proceeding
|
||||
with the newer import.
|
@ -1,58 +0,0 @@
|
||||
# $FreeBSD$
|
||||
|
||||
.include <src.opts.mk>
|
||||
|
||||
GREP_LIBZ=YES
|
||||
|
||||
.if ${MK_BSD_GREP} != "yes"
|
||||
PROG= grep
|
||||
.else
|
||||
PROG= gnugrep
|
||||
.endif
|
||||
SRCS= closeout.c dfa.c error.c exclude.c grep.c grepmat.c hard-locale.c \
|
||||
isdir.c kwset.c obstack.c quotearg.c savedir.c search.c xmalloc.c \
|
||||
xstrtoumax.c
|
||||
CLEANFILES+= gnugrep.1
|
||||
|
||||
WARNS?= 0
|
||||
|
||||
CFLAGS+=-I${.CURDIR} -I${SYSROOT:U${DESTDIR}}/usr/include/gnu -DHAVE_CONFIG_H
|
||||
|
||||
.if ${MK_BSD_GREP} != "yes"
|
||||
LINKS+= ${BINDIR}/grep ${BINDIR}/egrep \
|
||||
${BINDIR}/grep ${BINDIR}/fgrep
|
||||
MLINKS= grep.1 egrep.1 grep.1 fgrep.1
|
||||
.endif
|
||||
|
||||
LIBADD= gnuregex bz2
|
||||
|
||||
.if defined(GREP_LIBZ) && !empty(GREP_LIBZ)
|
||||
LIBADD+= z
|
||||
CFLAGS+=-DHAVE_LIBZ=1
|
||||
.endif
|
||||
|
||||
gnugrep.1: grep.1
|
||||
${CP} ${.ALLSRC} ${.TARGET}
|
||||
|
||||
check: all
|
||||
@failed=0; total=0; \
|
||||
for tst in ${TESTS}; do \
|
||||
total=$$(($$total+1)); \
|
||||
if GREP=${.OBJDIR}/${PROG} srcdir=${.CURDIR}/tests \
|
||||
${.CURDIR}/tests/$$tst; then \
|
||||
echo "PASS: $$tst"; \
|
||||
else \
|
||||
failed=$$(($$failed+1)); \
|
||||
echo "FAIL: $$tst"; \
|
||||
fi; \
|
||||
done; \
|
||||
if [ "$$failed" -eq 0 ]; then \
|
||||
echo "All $$total tests passed"; \
|
||||
else \
|
||||
echo "$$failed of $$total tests failed"; \
|
||||
fi
|
||||
|
||||
TESTS= warning.sh khadafy.sh spencer1.sh bre.sh ere.sh status.sh empty.sh \
|
||||
options.sh backref.sh file.sh
|
||||
|
||||
.include <bsd.prog.mk>
|
@ -1,20 +0,0 @@
|
||||
# $FreeBSD$
|
||||
# Autogenerated - do NOT edit!
|
||||
|
||||
DIRDEPS = \
|
||||
gnu/lib/csu \
|
||||
gnu/lib/libregex \
|
||||
include \
|
||||
include/xlocale \
|
||||
lib/${CSU_DIR} \
|
||||
lib/libbz2 \
|
||||
lib/libc \
|
||||
lib/libcompiler_rt \
|
||||
lib/libz \
|
||||
|
||||
|
||||
.include <dirdeps.mk>
|
||||
|
||||
.if ${DEP_RELDIR} == ${_DEP_RELDIR}
|
||||
# local dependencies - needed for -jN in clean tree
|
||||
.endif
|
@ -1,238 +0,0 @@
|
||||
Version 2.5.1
|
||||
- This is a bugfix release. No new features.
|
||||
|
||||
Version 2.5
|
||||
- The new option --label allows to specify a different name for input
|
||||
from stdin. See the man or info pages for details.
|
||||
|
||||
- The internal lib/getopt* files are no longer used on systems providing
|
||||
getopt functionality in their libc (e.g. glibc 2.2.x).
|
||||
If you need the old getopt files, use --with-included-getopt.
|
||||
|
||||
- The new option --only-matching (-o) will print only the part of matching
|
||||
lines that matches the pattern. This is useful, for example, to extract
|
||||
IP addresses from log files.
|
||||
|
||||
- i18n bug fixed ([A-Z0-9] wouldn't match A in locales other than C on
|
||||
systems using recent glibc builds
|
||||
|
||||
- GNU grep can now be built with autoconf 2.52.
|
||||
|
||||
- The new option --devices controls how grep handles device files. Its usage
|
||||
is analogous to --directories.
|
||||
|
||||
- The new option --line-buffered fflush on everyline. There is a noticeable
|
||||
slow down when forcing line buffering.
|
||||
|
||||
- Back references are now local to the regex.
|
||||
grep -e '\(a\)\1' -e '\(b\)\1'
|
||||
The last backref \1 in the second expression refer to \(b\)
|
||||
|
||||
- The new option --include=PATTERN will only search matching files
|
||||
when recursing in directories
|
||||
|
||||
- The new option --exclude=PATTERN will skip matching files when
|
||||
recursing in directories.
|
||||
|
||||
- The new option --color will use the environment variable GREP_COLOR
|
||||
(default is red) to highlight the matching string.
|
||||
--color takes an optional argument specifying when to colorize a line:
|
||||
--color=always, --color=tty, --color=never
|
||||
|
||||
- The following changes are for POSIX.2 conformance:
|
||||
|
||||
. The -q or --quiet or --silent option now causes grep to exit
|
||||
with zero status when a input line is selected, even if an error
|
||||
also occurs.
|
||||
|
||||
. The -s or --no-messages option no longer affects the exit status.
|
||||
|
||||
. Bracket regular expressions like [a-z] are now locale-dependent.
|
||||
For example, many locales sort characters in dictionary order,
|
||||
and in these locales the regular expression [a-d] is not
|
||||
equivalent to [abcd]; it might be equivalent to [aBbCcDd], for
|
||||
example. To obtain the traditional interpretation of bracket
|
||||
expressions, you can use the C locale by setting the LC_ALL
|
||||
environment variable to the value "C".
|
||||
|
||||
- The -C or --context option now requires an argument, partly for
|
||||
consistency, and partly because POSIX.2 recommends against
|
||||
optional arguments.
|
||||
|
||||
- The new -P or --perl-regexp option tells grep to interpert the pattern as
|
||||
a Perl regular expression.
|
||||
|
||||
- The new option --max-count=num makes grep stop reading a file after num
|
||||
matching lines.
|
||||
New option -m; equivalent to --max-count.
|
||||
|
||||
- Translations for bg, ca, da, nb and tr have been added.
|
||||
|
||||
Version 2.4.2
|
||||
|
||||
- Added more check in configure to default the grep-${version}/src/regex.c
|
||||
instead of the one in GNU Lib C.
|
||||
|
||||
Version 2.4.1
|
||||
|
||||
- If the final byte of an input file is not a newline, grep now silently
|
||||
supplies one.
|
||||
|
||||
- The new option --binary-files=TYPE makes grep assume that a binary input
|
||||
file is of type TYPE.
|
||||
--binary-files='binary' (the default) outputs a 1-line summary of matches.
|
||||
--binary-files='without-match' assumes binary files do not match.
|
||||
--binary-files='text' treats binary files as text
|
||||
(equivalent to the -a or --text option).
|
||||
|
||||
- New option -I; equivalent to --binary-files='without-match'.
|
||||
|
||||
Version 2.4:
|
||||
|
||||
- egrep is now equivalent to `grep -E' as required by POSIX,
|
||||
removing a longstanding source of confusion and incompatibility.
|
||||
`grep' is now more forgiving about stray `{'s, for backward
|
||||
compatibility with traditional egrep.
|
||||
|
||||
- The lower bound of an interval is not optional.
|
||||
You must use an explicit zero, e.g. `x{0,10}' instead of `x{,10}'.
|
||||
(The old documentation incorrectly claimed that it was optional.)
|
||||
|
||||
- The --revert-match option has been renamed to --invert-match.
|
||||
|
||||
- The --fixed-regexp option has been renamed to --fixed-string.
|
||||
|
||||
- New option -H or --with-filename.
|
||||
|
||||
- New option --mmap. By default, GNU grep now uses read instead of mmap.
|
||||
This is faster on some hosts, and is safer on all.
|
||||
|
||||
- The new option -z or --null-data causes `grep' to treat a zero byte
|
||||
(the ASCII NUL character) as a line terminator in input data, and
|
||||
to treat newlines as ordinary data.
|
||||
|
||||
- The new option -Z or --null causes `grep' to output a zero byte
|
||||
instead of the normal separator after a file name.
|
||||
|
||||
- These two options can be used with commands like `find -print0',
|
||||
`perl -0', `sort -z', and `xargs -0' to process arbitrary file names,
|
||||
even those that contain newlines.
|
||||
|
||||
- The environment variable GREP_OPTIONS specifies default options;
|
||||
e.g. GREP_OPTIONS='--directories=skip' reestablishes grep 2.1's
|
||||
behavior of silently skipping directories.
|
||||
|
||||
- You can specify a matcher multiple times without error, e.g.
|
||||
`grep -E -E' or `fgrep -F'. It is still an error to specify
|
||||
conflicting matchers.
|
||||
|
||||
- -u and -U are now allowed on non-DOS hosts, and have no effect.
|
||||
|
||||
- Modifications of the tests scripts to go around the "Broken Pipe"
|
||||
errors from bash. See Bash FAQ.
|
||||
|
||||
- New option -r or --recursive or --directories=recurse.
|
||||
(This option was also in grep 2.3, but wasn't announced here.)
|
||||
|
||||
- --without-included-regex disable, was causing bogus reports .i.e
|
||||
doing more harm then good.
|
||||
|
||||
Version 2.3:
|
||||
|
||||
- When searching a binary file FOO, grep now just reports
|
||||
`Binary file FOO matches' instead of outputting binary data.
|
||||
This is typically more useful than the old behavior,
|
||||
and it is also more consistent with other utilities like `diff'.
|
||||
A file is considered to be binary if it contains a NUL (i.e. zero) byte.
|
||||
|
||||
The new -a or --text option causes `grep' to assume that all
|
||||
input is text. (This option has the same meaning as with `diff'.)
|
||||
Use it if you want binary data in your output.
|
||||
|
||||
- `grep' now searches directories just like ordinary files; it no longer
|
||||
silently skips directories. This is the traditional behavior of
|
||||
Unix text utilities (in particular, of traditional `grep').
|
||||
Hence `grep PATTERN DIRECTORY' should report
|
||||
`grep: DIRECTORY: Is a directory' on hosts where the operating system
|
||||
does not permit programs to read directories directly, and
|
||||
`grep: DIRECTORY: Binary file matches' (or nothing) otherwise.
|
||||
|
||||
The new -d ACTION or --directories=ACTION option affects directory handling.
|
||||
`-d skip' causes `grep' to silently skip directories, as in grep 2.1;
|
||||
`-d read' (the default) causes `grep' to read directories if possible,
|
||||
as in earlier versions of grep.
|
||||
|
||||
- The MS-DOS and Microsoft Windows ports now behave identically to the
|
||||
GNU and Unix ports with respect to binary files and directories.
|
||||
|
||||
Version 2.2:
|
||||
|
||||
Bug fix release.
|
||||
|
||||
- Status error number fix.
|
||||
- Skipping directories removed.
|
||||
- Many typos fix.
|
||||
- -f /dev/null fix(not to consider as an empty pattern).
|
||||
- Checks for wctype/wchar.
|
||||
- -E was using the wrong matcher fix.
|
||||
- bug in regex char class fix
|
||||
- Fixes for DJGPP
|
||||
|
||||
Version 2.1:
|
||||
|
||||
This is a bug fix release(see Changelog) i.e. no new features.
|
||||
|
||||
- More compliance to GNU standard.
|
||||
- Long options.
|
||||
- Internationalisation.
|
||||
- Use automake/autoconf.
|
||||
- Directory hierarchy change.
|
||||
- Sigvec with -e on Linux corrected.
|
||||
- Sigvec with -f on Linux corrected.
|
||||
- Sigvec with the mmap() corrected.
|
||||
- Bug in kwset corrected.
|
||||
- -q, -L and -l stop on first match.
|
||||
- New and improve regex.[ch] from Ulrich Drepper.
|
||||
- New and improve dfa.[ch] from Arnold Robbins.
|
||||
- Prototypes for over zealous C compiler.
|
||||
- Not scanning a file, if it's a directory
|
||||
(cause problems on Sun).
|
||||
- Ported to MS-DOS/MS-Windows with DJGPP tools.
|
||||
|
||||
See Changelog for the full story and proper credits.
|
||||
|
||||
Version 2.0:
|
||||
|
||||
The most important user visible change is that egrep and fgrep have
|
||||
disappeared as separate programs into the single grep program mandated
|
||||
by POSIX 1003.2. New options -G, -E, and -F have been added,
|
||||
selecting grep, egrep, and fgrep behavior respectively. For
|
||||
compatibility with historical practice, hard links named egrep and
|
||||
fgrep are also provided. See the manual page for details.
|
||||
|
||||
In addition, the regular expression facilities described in Posix
|
||||
draft 11.2 are now supported, except for internationalization features
|
||||
related to locale-dependent collating sequence information.
|
||||
|
||||
There is a new option, -L, which is like -l except it lists
|
||||
files which don't contain matches. The reason this option was
|
||||
added is because '-l -v' doesn't do what you expect.
|
||||
|
||||
Performance has been improved; the amount of improvement is platform
|
||||
dependent, but (for example) grep 2.0 typically runs at least 30% faster
|
||||
than grep 1.6 on a DECstation using the MIPS compiler. Where possible,
|
||||
grep now uses mmap() for file input; on a Sun 4 running SunOS 4.1 this
|
||||
may cut system time by as much as half, for a total reduction in running
|
||||
time by nearly 50%. On machines that don't use mmap(), the buffering
|
||||
code has been rewritten to choose more favorable alignments and buffer
|
||||
sizes for read().
|
||||
|
||||
Portability has been substantially cleaned up, and an automatic
|
||||
configure script is now provided.
|
||||
|
||||
The internals have changed in ways too numerous to mention.
|
||||
People brave enough to reuse the DFA matcher in other programs
|
||||
will now have their bravery amply "rewarded", for the interface
|
||||
to that file has been completely changed. Some changes were
|
||||
necessary to track the evolution of the regex package, and since
|
||||
I was changing it anyway I decided to do a general cleanup.
|
@ -1,26 +0,0 @@
|
||||
This is GNU grep, the "fastest grep in the west" (we hope). All
|
||||
bugs reported in previous releases have been fixed. Many exciting new
|
||||
bugs have probably been introduced in this revision.
|
||||
|
||||
GNU grep is provided "as is" with no warranty. The exact terms
|
||||
under which you may use and (re)distribute this program are detailed
|
||||
in the GNU General Public License, in the file COPYING.
|
||||
|
||||
GNU grep is based on a fast lazy-state deterministic matcher (about
|
||||
twice as fast as stock Unix egrep) hybridized with a Boyer-Moore-Gosper
|
||||
search for a fixed string that eliminates impossible text from being
|
||||
considered by the full regexp matcher without necessarily having to
|
||||
look at every character. The result is typically many times faster
|
||||
than Unix grep or egrep. (Regular expressions containing backreferencing
|
||||
will run more slowly, however.)
|
||||
|
||||
See the files AUTHORS and THANKS for a list of authors and other contributors.
|
||||
|
||||
See the file INSTALL for compilation and installation instructions.
|
||||
|
||||
See the file NEWS for a description of major changes in this release.
|
||||
|
||||
See the file TODO for ideas on how you could help us improve grep.
|
||||
|
||||
Send bug reports to bug-gnu-utils@gnu.org. Be sure to
|
||||
include the word "grep" in your Subject: header field.
|
@ -1,72 +0,0 @@
|
||||
Aharon Robbins <arnold@gnu.org>
|
||||
Akim Demaille <akim@epita.fr>
|
||||
Alain Magloire <alainm@gnu.org>
|
||||
Andreas Schwab <schwab@suse.de>
|
||||
Andreas Ley <andy@rz.uni-karlsruhe.de>
|
||||
Bastiaan "Darquan" Stougie <darquan@zonnet.nl>
|
||||
Ben Elliston <bje@cygnus.com>
|
||||
Bernd Strieder <strieder@student.uni-kl.de>
|
||||
Bernhard Rosenkraenzer <bero@redhat.com>
|
||||
Bob Proulx <rwp@hprwp.fc.hp.com>
|
||||
Brian Youmans <3diff@gnu.org>
|
||||
Bruno Haible <haible@ilog.fr>
|
||||
Christian Groessler <cpg@aladdin.de>
|
||||
David Clissold <cliss@austin.ibm.com>
|
||||
David J MacKenzie <djm@catapult.va.pubnix.com>
|
||||
David O'Brien <obrien@freebsd.org>
|
||||
Eli Zaretskii <eliz@is.elta.co.il>
|
||||
Florian La Roche <laroche@redhat.com>
|
||||
Franc,ois Pinard <pinard@IRO.UMontreal.CA>
|
||||
Gerald Stoller <gerald_stoller@hotmail.com>
|
||||
Grant McDorman <grant@isgtec.com>
|
||||
Greg Louis <glouis@dynamicro.on.ca>
|
||||
Guglielmo 'bond' Bondioni <g.bondioni@libero.it>
|
||||
H. Merijn Brand <h.m.brand@hccnet.nl>
|
||||
Harald Hanche-Olsen <hanche@math.ntnu.no>
|
||||
Hans-Bernhard Broeker <broeker@physik.rwth-aachen.de>
|
||||
Heikki Korpela <heko@iki.fi>
|
||||
Isamu Hasegawa <isamu@yamato.ibm.com>
|
||||
Jeff Bailey <jbailey@nisa.net>
|
||||
Jim Hand <jhand@austx.tandem.com>
|
||||
Jim Meyering <meyering@asic.sc.ti.com>
|
||||
Jochen Hein <jochen.hein@delphi.central.de>
|
||||
Joel N. Weber II <devnull@gnu.org>
|
||||
John Hughes <john@nitelite.calvacom.fr>
|
||||
Jorge Stolfi <stolfi@dcc.unicamp.br>
|
||||
Juan Manuel Guerrero <ST001906@HRZ1.HRZ.TU-Darmstadt.De>
|
||||
Karl Berry <karl@cs.umb.edu>
|
||||
Karl Heuer <kwzh@gnu.org>
|
||||
Kaveh R. Ghazi <ghazi@caip.rutgers.edu>
|
||||
Kazuro Furukawa <furukawa@apricot.kek.jp>
|
||||
Keith Bostic <bostic@bsdi.com>
|
||||
Krishna Sethuraman <krishna@sgihub.corp.sgi.com>
|
||||
Kurt D Schwehr <kdschweh@insci14.ucsd.edu>
|
||||
Mark Waite <markw@mddmew.fc.hp.com>
|
||||
Martin P.J. Zinser <zinser@decus.de>
|
||||
Martin Rex <martin.rex@sap-ag.de>
|
||||
Michael Aichlmayr <mikla@nx.com>
|
||||
Miles Bader <miles@ccs.mt.nec.co.jp>
|
||||
Olaf Kirch <okir@ns.lst.de>
|
||||
Paul Eggert <eggert@twinsun.com>
|
||||
Paul Kimoto <kimoto@spacenet.tn.cornell.edu>
|
||||
Phillip C. Brisco <phillip.craig.brisco@ccmail.census.gov>
|
||||
Philippe Defert <Philippe.Defert@cern.ch>
|
||||
Philippe De Muyter <phdm@info.ucl.ac.be>
|
||||
Philip Hazel <ph10@cus.cam.ac.uk>
|
||||
Roland Roberts <rroberts@muller.com>
|
||||
Ruslan Ermilov <ru@freebsd.org>
|
||||
Santiago Vila <sanvila@unex.es>
|
||||
Shannon Hill <hill@synnet.com>
|
||||
Sotiris Vassilopoulos <Sotiris.Vassilopoulos@betatech.gr>
|
||||
Stewart Levin <stew@sep.stanford.edu>
|
||||
Sydoruk Stepan <step@unitex.kiev.ua>
|
||||
Tapani Tarvainen <tt@mit.jyu.fi>
|
||||
Tom 'moof' Spindler <dogcow@ccs.neu.edu>
|
||||
Tom Tromey <tromey@creche.cygnus.com>
|
||||
Ulrich Drepper <drepper@cygnus.com>
|
||||
UEBAYASHI Masao <masao@nf.enveng.titech.ac.jp>
|
||||
Uwe H. Steinfeld <usteinfeld@gmx.net>
|
||||
Volker Borchert <bt@teknon.de>
|
||||
Wichert Akkerman <wichert@cistron.nl>
|
||||
William Bader <william@nscs.fast.net>
|
||||
Wolfgang Schludi <schludi@syscomp.de>
|
@ -1,121 +0,0 @@
|
||||
/* closeout.c - close standard output
|
||||
Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software Foundation,
|
||||
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
||||
|
||||
#if HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#if ENABLE_NLS
|
||||
# include <libintl.h>
|
||||
# define _(Text) gettext (Text)
|
||||
#else
|
||||
# define _(Text) Text
|
||||
#endif
|
||||
|
||||
#if HAVE_STDLIB_H
|
||||
# include <stdlib.h>
|
||||
#endif
|
||||
#ifndef EXIT_FAILURE
|
||||
# define EXIT_FAILURE 1
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include <errno.h>
|
||||
#ifndef errno
|
||||
extern int errno;
|
||||
#endif
|
||||
|
||||
#include "closeout.h"
|
||||
#include "error.h"
|
||||
#include "quotearg.h"
|
||||
#if 0
|
||||
#include "__fpending.h"
|
||||
#endif
|
||||
|
||||
static int default_exit_status = EXIT_FAILURE;
|
||||
static const char *file_name;
|
||||
|
||||
/* Set the value to be used for the exit status when close_stdout is called.
|
||||
This is useful when it is not convenient to call close_stdout_status,
|
||||
e.g., when close_stdout is called via atexit. */
|
||||
void
|
||||
close_stdout_set_status (int status)
|
||||
{
|
||||
default_exit_status = status;
|
||||
}
|
||||
|
||||
/* Set the file name to be reported in the event an error is detected
|
||||
by close_stdout_status. */
|
||||
void
|
||||
close_stdout_set_file_name (const char *file)
|
||||
{
|
||||
file_name = file;
|
||||
}
|
||||
|
||||
/* Close standard output, exiting with status STATUS on failure.
|
||||
If a program writes *anything* to stdout, that program should `fflush'
|
||||
stdout and make sure that it succeeds before exiting. Otherwise,
|
||||
suppose that you go to the extreme of checking the return status
|
||||
of every function that does an explicit write to stdout. The last
|
||||
printf can succeed in writing to the internal stream buffer, and yet
|
||||
the fclose(stdout) could still fail (due e.g., to a disk full error)
|
||||
when it tries to write out that buffered data. Thus, you would be
|
||||
left with an incomplete output file and the offending program would
|
||||
exit successfully.
|
||||
|
||||
FIXME: note the fflush suggested above is implicit in the fclose
|
||||
we actually do below. Consider doing only the fflush and/or using
|
||||
setvbuf to inhibit buffering.
|
||||
|
||||
Besides, it's wasteful to check the return value from every call
|
||||
that writes to stdout -- just let the internal stream state record
|
||||
the failure. That's what the ferror test is checking below.
|
||||
|
||||
It's important to detect such failures and exit nonzero because many
|
||||
tools (most notably `make' and other build-management systems) depend
|
||||
on being able to detect failure in other tools via their exit status. */
|
||||
|
||||
void
|
||||
close_stdout_status (int status)
|
||||
{
|
||||
int e = ferror (stdout) ? 0 : -1;
|
||||
|
||||
#if 0
|
||||
if (__fpending (stdout) == 0)
|
||||
return;
|
||||
#endif
|
||||
|
||||
if (fclose (stdout) != 0)
|
||||
e = errno;
|
||||
|
||||
if (0 < e)
|
||||
{
|
||||
char const *write_error = _("write error");
|
||||
if (file_name)
|
||||
error (status, e, "%s: %s", quotearg_colon (file_name), write_error);
|
||||
else
|
||||
error (status, e, "%s", write_error);
|
||||
}
|
||||
}
|
||||
|
||||
/* Close standard output, exiting with status EXIT_FAILURE on failure. */
|
||||
void
|
||||
close_stdout (void)
|
||||
{
|
||||
close_stdout_status (default_exit_status);
|
||||
}
|
@ -1,17 +0,0 @@
|
||||
#ifndef CLOSEOUT_H
|
||||
# define CLOSEOUT_H 1
|
||||
|
||||
# ifndef PARAMS
|
||||
# if defined PROTOTYPES || (defined __STDC__ && __STDC__)
|
||||
# define PARAMS(Args) Args
|
||||
# else
|
||||
# define PARAMS(Args) ()
|
||||
# endif
|
||||
# endif
|
||||
|
||||
void close_stdout_set_status PARAMS ((int status));
|
||||
void close_stdout_set_file_name PARAMS ((const char *file));
|
||||
void close_stdout PARAMS ((void));
|
||||
void close_stdout_status PARAMS ((int status));
|
||||
|
||||
#endif
|
@ -1,342 +0,0 @@
|
||||
/* $FreeBSD$ */
|
||||
/* config.h. Generated by configure. */
|
||||
/* config.hin. Generated from configure.in by autoheader. */
|
||||
|
||||
/* Define to 1 if the `closedir' function returns void instead of `int'. */
|
||||
/* #undef CLOSEDIR_VOID */
|
||||
|
||||
/* Define to one of `_getb67', `GETB67', `getb67' for Cray-2 and Cray-YMP
|
||||
systems. This function is required for `alloca.c' support on those systems.
|
||||
*/
|
||||
/* #undef CRAY_STACKSEG_END */
|
||||
|
||||
/* Define to 1 if using `alloca.c'. */
|
||||
/* #undef C_ALLOCA */
|
||||
|
||||
/* Define to 1 if translation of program messages to the user's native
|
||||
language is requested. */
|
||||
/* #undef ENABLE_NLS */
|
||||
|
||||
/* We are building grep */
|
||||
#define GREP 1
|
||||
|
||||
/* Define to 1 if you have `alloca', as a function or macro. */
|
||||
#define HAVE_ALLOCA 1
|
||||
|
||||
/* Define to 1 if you have <alloca.h> and it should be used (not on Ultrix).
|
||||
*/
|
||||
/* #undef HAVE_ALLOCA_H */
|
||||
|
||||
/* Define to 1 if you have the <argz.h> header file. */
|
||||
/* #undef HAVE_ARGZ_H */
|
||||
|
||||
/* Define to 1 if you have the `atexit' function. */
|
||||
#define HAVE_ATEXIT 1
|
||||
|
||||
/* Define to 1 if you have the `btowc' function. */
|
||||
#define HAVE_BTOWC 1
|
||||
|
||||
/* Define to 1 if you have the `dcgettext' function. */
|
||||
/* #undef HAVE_DCGETTEXT */
|
||||
|
||||
/* Define to 1 if strerror_r is declared. */
|
||||
#define HAVE_DECL_STRERROR_R 1
|
||||
|
||||
/* Define if <stdlib.h> declares strtoul. */
|
||||
#define HAVE_DECL_STRTOUL 1
|
||||
|
||||
/* Define if <stdlib.h> declares strtoull. */
|
||||
#define HAVE_DECL_STRTOULL 1
|
||||
|
||||
/* Define to 1 if you have the <dirent.h> header file, and it defines `DIR'.
|
||||
*/
|
||||
#define HAVE_DIRENT_H 1
|
||||
|
||||
/* Define if the malloc check has been performed. */
|
||||
#define HAVE_DONE_WORKING_MALLOC_CHECK 1
|
||||
|
||||
/* Define if the realloc check has been performed. */
|
||||
#define HAVE_DONE_WORKING_REALLOC_CHECK 1
|
||||
|
||||
/* Define to 1 if you have the `doprnt' function. */
|
||||
/* #undef HAVE_DOPRNT */
|
||||
|
||||
/* Define if text file lines end in CRLF. */
|
||||
/* #undef HAVE_DOS_FILE_CONTENTS */
|
||||
|
||||
/* Define if your OS uses backslashes as directory separators */
|
||||
/* #undef HAVE_DOS_FILE_NAMES */
|
||||
|
||||
/* Define to 1 if you have the `feof_unlocked' function. */
|
||||
#define HAVE_FEOF_UNLOCKED 1
|
||||
|
||||
/* Define to 1 if you have the `fgets_unlocked' function. */
|
||||
/* #undef HAVE_FGETS_UNLOCKED */
|
||||
|
||||
/* Define to 1 if you have the `fnmatch' function. */
|
||||
#define HAVE_FNMATCH 1
|
||||
|
||||
/* Define to 1 if you have the `getcwd' function. */
|
||||
#define HAVE_GETCWD 1
|
||||
|
||||
/* Define to 1 if you have the `getegid' function. */
|
||||
#define HAVE_GETEGID 1
|
||||
|
||||
/* Define to 1 if you have the `geteuid' function. */
|
||||
#define HAVE_GETEUID 1
|
||||
|
||||
/* Define to 1 if you have the `getgid' function. */
|
||||
#define HAVE_GETGID 1
|
||||
|
||||
/* Define to 1 if you have the `getpagesize' function. */
|
||||
#define HAVE_GETPAGESIZE 1
|
||||
|
||||
/* Define if the GNU gettext() function is already present or preinstalled. */
|
||||
/* #undef HAVE_GETTEXT */
|
||||
|
||||
/* Define to 1 if you have the `getuid' function. */
|
||||
#define HAVE_GETUID 1
|
||||
|
||||
/* Define if you have the iconv() function. */
|
||||
#define HAVE_ICONV 1
|
||||
|
||||
/* Define if <inttypes.h> exists, doesn't clash with <sys/types.h>, and
|
||||
declares uintmax_t. */
|
||||
#define HAVE_INTTYPES_H 1
|
||||
|
||||
/* Define to 1 if you have the `isascii' function. */
|
||||
#define HAVE_ISASCII 1
|
||||
|
||||
/* Define if you have <langinfo.h> and nl_langinfo(CODESET). */
|
||||
#define HAVE_LANGINFO_CODESET 1
|
||||
|
||||
/* Define if your <locale.h> file defines LC_MESSAGES. */
|
||||
#define HAVE_LC_MESSAGES 1
|
||||
|
||||
/* Define to 1 if you have the <libintl.h> header file. */
|
||||
/* #undef HAVE_LIBINTL_H */
|
||||
|
||||
/* Define to 1 if you have the `pcre' library (-lpcre). */
|
||||
/* #undef HAVE_LIBPCRE */
|
||||
|
||||
/* Define to 1 if you have the <limits.h> header file. */
|
||||
#define HAVE_LIMITS_H 1
|
||||
|
||||
/* Define to 1 if you have the <locale.h> header file. */
|
||||
#define HAVE_LOCALE_H 1
|
||||
|
||||
/* Define to 1 if you have the <malloc.h> header file. */
|
||||
/* #undef HAVE_MALLOC_H */
|
||||
|
||||
/* Define to 1 if you have the `mbrtowc' function. */
|
||||
#define HAVE_MBRTOWC 1
|
||||
|
||||
/* Define to 1 if you have the `memchr' function. */
|
||||
#define HAVE_MEMCHR 1
|
||||
|
||||
/* Define to 1 if you have the `memmove' function. */
|
||||
#define HAVE_MEMMOVE 1
|
||||
|
||||
/* Define to 1 if you have the <memory.h> header file. */
|
||||
#define HAVE_MEMORY_H 1
|
||||
|
||||
/* Define to 1 if you have the `mempcpy' function. */
|
||||
/* #undef HAVE_MEMPCPY */
|
||||
|
||||
/* Define to 1 if you have a working `mmap' system call. */
|
||||
#define HAVE_MMAP 1
|
||||
|
||||
/* Define to 1 if you have the `munmap' function. */
|
||||
#define HAVE_MUNMAP 1
|
||||
|
||||
/* Define to 1 if you have the <ndir.h> header file, and it defines `DIR'. */
|
||||
/* #undef HAVE_NDIR_H */
|
||||
|
||||
/* Define to 1 if you have the <nl_types.h> header file. */
|
||||
#define HAVE_NL_TYPES_H 1
|
||||
|
||||
/* Define to 1 if you have the `putenv' function. */
|
||||
#define HAVE_PUTENV 1
|
||||
|
||||
/* Define to 1 if you have the `setenv' function. */
|
||||
#define HAVE_SETENV 1
|
||||
|
||||
/* Define to 1 if you have the `setlocale' function. */
|
||||
#define HAVE_SETLOCALE 1
|
||||
|
||||
/* Define to 1 if you have the `setmode' function. */
|
||||
#define HAVE_SETMODE 1
|
||||
|
||||
/* Define to 1 if you have the <stddef.h> header file. */
|
||||
#define HAVE_STDDEF_H 1
|
||||
|
||||
/* Define to 1 if you have the <stdint.h> header file. */
|
||||
#define HAVE_STDINT_H 1
|
||||
|
||||
/* Define to 1 if you have the <stdlib.h> header file. */
|
||||
#define HAVE_STDLIB_H 1
|
||||
|
||||
/* Define to 1 if you have the `stpcpy' function. */
|
||||
#define HAVE_STPCPY 1
|
||||
|
||||
/* Define to 1 if you have the `strcasecmp' function. */
|
||||
#define HAVE_STRCASECMP 1
|
||||
|
||||
/* Define to 1 if you have the `strchr' function. */
|
||||
#define HAVE_STRCHR 1
|
||||
|
||||
/* Define to 1 if you have the `strdup' function. */
|
||||
#define HAVE_STRDUP 1
|
||||
|
||||
/* Define to 1 if you have the `strerror' function. */
|
||||
#define HAVE_STRERROR 1
|
||||
|
||||
/* Define to 1 if you have the `strerror_r' function. */
|
||||
#define HAVE_STRERROR_R 1
|
||||
|
||||
/* Define to 1 if you have the <strings.h> header file. */
|
||||
#define HAVE_STRINGS_H 1
|
||||
|
||||
/* Define to 1 if you have the <string.h> header file. */
|
||||
#define HAVE_STRING_H 1
|
||||
|
||||
/* Define to 1 if you have the `strtoul' function. */
|
||||
#define HAVE_STRTOUL 1
|
||||
|
||||
/* Define to 1 if you have the `strtoull' function. */
|
||||
/* #undef HAVE_STRTOULL */
|
||||
|
||||
/* Define to 1 if you have the `strtoumax' function. */
|
||||
#define HAVE_STRTOUMAX 1
|
||||
|
||||
/* Define to 1 if you have the <sys/dir.h> header file, and it defines `DIR'.
|
||||
*/
|
||||
/* #undef HAVE_SYS_DIR_H */
|
||||
|
||||
/* Define to 1 if you have the <sys/ndir.h> header file, and it defines `DIR'.
|
||||
*/
|
||||
/* #undef HAVE_SYS_NDIR_H */
|
||||
|
||||
/* Define to 1 if you have the <sys/param.h> header file. */
|
||||
#define HAVE_SYS_PARAM_H 1
|
||||
|
||||
/* Define to 1 if you have the <sys/stat.h> header file. */
|
||||
#define HAVE_SYS_STAT_H 1
|
||||
|
||||
/* Define to 1 if you have the <sys/types.h> header file. */
|
||||
#define HAVE_SYS_TYPES_H 1
|
||||
|
||||
/* Define to 1 if you have the `tsearch' function. */
|
||||
#define HAVE_TSEARCH 1
|
||||
|
||||
/* Define to 1 if you have the <unistd.h> header file. */
|
||||
#define HAVE_UNISTD_H 1
|
||||
|
||||
/* Define if you have the unsigned long long type. */
|
||||
#define HAVE_UNSIGNED_LONG_LONG 1
|
||||
|
||||
/* Define to 1 if you have the `vprintf' function. */
|
||||
#define HAVE_VPRINTF 1
|
||||
|
||||
/* Define to 1 if you have the <wchar.h> header file. */
|
||||
#define HAVE_WCHAR_H 1
|
||||
|
||||
/* Define to 1 if you have the `wctype' function. */
|
||||
#define HAVE_WCTYPE 1
|
||||
|
||||
/* Define to 1 if you have the <wctype.h> header file. */
|
||||
#define HAVE_WCTYPE_H 1
|
||||
|
||||
/* Define to 1 if strerror_r returns a string. */
|
||||
/* #undef HAVE_WORKING_STRERROR_R */
|
||||
|
||||
/* Define to 1 if you have the `__argz_count' function. */
|
||||
/* #undef HAVE___ARGZ_COUNT */
|
||||
|
||||
/* Define to 1 if you have the `__argz_next' function. */
|
||||
/* #undef HAVE___ARGZ_NEXT */
|
||||
|
||||
/* Define to 1 if you have the `__argz_stringify' function. */
|
||||
/* #undef HAVE___ARGZ_STRINGIFY */
|
||||
|
||||
/* Define as const if the declaration of iconv() needs const. */
|
||||
#define ICONV_CONST
|
||||
|
||||
/* Name of package */
|
||||
#define PACKAGE "grep"
|
||||
|
||||
/* Define to the address where bug reports for this package should be sent. */
|
||||
#define PACKAGE_BUGREPORT ""
|
||||
|
||||
/* Define to the full name of this package. */
|
||||
#define PACKAGE_NAME ""
|
||||
|
||||
/* Define to the full name and version of this package. */
|
||||
#define PACKAGE_STRING ""
|
||||
|
||||
/* Define to the one symbol short name of this package. */
|
||||
#define PACKAGE_TARNAME ""
|
||||
|
||||
/* Define to the version of this package. */
|
||||
#define PACKAGE_VERSION ""
|
||||
|
||||
/* Define if compiler has function prototypes */
|
||||
#define PROTOTYPES 1
|
||||
|
||||
/* If using the C implementation of alloca, define if you know the
|
||||
direction of stack growth for your system; otherwise it will be
|
||||
automatically deduced at run-time.
|
||||
STACK_DIRECTION > 0 => grows toward higher addresses
|
||||
STACK_DIRECTION < 0 => grows toward lower addresses
|
||||
STACK_DIRECTION = 0 => direction of growth unknown */
|
||||
/* #undef STACK_DIRECTION */
|
||||
|
||||
/* Define to 1 if the `S_IS*' macros in <sys/stat.h> do not work properly. */
|
||||
/* #undef STAT_MACROS_BROKEN */
|
||||
|
||||
/* Define to 1 if you have the ANSI C header files. */
|
||||
#define STDC_HEADERS 1
|
||||
|
||||
/* Version number of package */
|
||||
#define VERSION "2.5.1-FreeBSD"
|
||||
|
||||
/* Number of bits in a file offset, on hosts where this is settable. */
|
||||
/* #undef _FILE_OFFSET_BITS */
|
||||
|
||||
/* Define to make fseeko etc. visible, on some hosts. */
|
||||
/* #undef _LARGEFILE_SOURCE */
|
||||
|
||||
/* Define for large files, on AIX-style hosts. */
|
||||
/* #undef _LARGE_FILES */
|
||||
|
||||
/* Define if your compiler is broken */
|
||||
/* #undef alloca */
|
||||
|
||||
/* Define to empty if `const' does not conform to ANSI C. */
|
||||
/* #undef const */
|
||||
|
||||
/* Define as `__inline' if that's what the C compiler calls it, or to nothing
|
||||
if it is not supported. */
|
||||
/* #undef inline */
|
||||
|
||||
/* Define to rpl_malloc if the replacement function should be used. */
|
||||
/* #undef malloc */
|
||||
|
||||
/* Define to a type if <wchar.h> does not define. */
|
||||
/* #undef mbstate_t */
|
||||
|
||||
/* Define to `long' if <sys/types.h> does not define. */
|
||||
/* #undef off_t */
|
||||
|
||||
/* Define to rpl_realloc if the replacement function should be used. */
|
||||
/* #undef realloc */
|
||||
|
||||
/* Define to `unsigned' if <sys/types.h> does not define. */
|
||||
/* #undef size_t */
|
||||
|
||||
/* Define to `int' if <sys/types.h> does not define. */
|
||||
/* #undef ssize_t */
|
||||
|
||||
/* Define to unsigned long or unsigned long long if <inttypes.h> doesn't
|
||||
define. */
|
||||
/* #undef uintmax_t */
|
File diff suppressed because it is too large
Load Diff
@ -1,434 +0,0 @@
|
||||
/* dfa.h - declarations for GNU deterministic regexp compiler
|
||||
Copyright (C) 1988, 1998 Free Software Foundation, Inc.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */
|
||||
|
||||
/* Written June, 1988 by Mike Haertel */
|
||||
|
||||
/* $FreeBSD$ */
|
||||
|
||||
/* FIXME:
|
||||
2. We should not export so much of the DFA internals.
|
||||
In addition to clobbering modularity, we eat up valuable
|
||||
name space. */
|
||||
|
||||
#ifdef __STDC__
|
||||
# ifndef _PTR_T
|
||||
# define _PTR_T
|
||||
typedef void * ptr_t;
|
||||
# endif
|
||||
#else
|
||||
# ifndef _PTR_T
|
||||
# define _PTR_T
|
||||
typedef char * ptr_t;
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifdef PARAMS
|
||||
# undef PARAMS
|
||||
#endif
|
||||
#if PROTOTYPES
|
||||
# define PARAMS(x) x
|
||||
#else
|
||||
# define PARAMS(x) ()
|
||||
#endif
|
||||
|
||||
/* Number of bits in an unsigned char. */
|
||||
#ifndef CHARBITS
|
||||
#define CHARBITS 8
|
||||
#endif
|
||||
|
||||
/* First integer value that is greater than any character code. */
|
||||
#define NOTCHAR (1 << CHARBITS)
|
||||
|
||||
/* INTBITS need not be exact, just a lower bound. */
|
||||
#ifndef INTBITS
|
||||
#define INTBITS (CHARBITS * sizeof (int))
|
||||
#endif
|
||||
|
||||
/* Number of ints required to hold a bit for every character. */
|
||||
#define CHARCLASS_INTS ((NOTCHAR + INTBITS - 1) / INTBITS)
|
||||
|
||||
/* Sets of unsigned characters are stored as bit vectors in arrays of ints. */
|
||||
typedef int charclass[CHARCLASS_INTS];
|
||||
|
||||
/* The regexp is parsed into an array of tokens in postfix form. Some tokens
|
||||
are operators and others are terminal symbols. Most (but not all) of these
|
||||
codes are returned by the lexical analyzer. */
|
||||
|
||||
typedef enum
|
||||
{
|
||||
END = -1, /* END is a terminal symbol that matches the
|
||||
end of input; any value of END or less in
|
||||
the parse tree is such a symbol. Accepting
|
||||
states of the DFA are those that would have
|
||||
a transition on END. */
|
||||
|
||||
/* Ordinary character values are terminal symbols that match themselves. */
|
||||
|
||||
EMPTY = NOTCHAR, /* EMPTY is a terminal symbol that matches
|
||||
the empty string. */
|
||||
|
||||
BACKREF, /* BACKREF is generated by \<digit>; it
|
||||
it not completely handled. If the scanner
|
||||
detects a transition on backref, it returns
|
||||
a kind of "semi-success" indicating that
|
||||
the match will have to be verified with
|
||||
a backtracking matcher. */
|
||||
|
||||
BEGLINE, /* BEGLINE is a terminal symbol that matches
|
||||
the empty string if it is at the beginning
|
||||
of a line. */
|
||||
|
||||
ENDLINE, /* ENDLINE is a terminal symbol that matches
|
||||
the empty string if it is at the end of
|
||||
a line. */
|
||||
|
||||
BEGWORD, /* BEGWORD is a terminal symbol that matches
|
||||
the empty string if it is at the beginning
|
||||
of a word. */
|
||||
|
||||
ENDWORD, /* ENDWORD is a terminal symbol that matches
|
||||
the empty string if it is at the end of
|
||||
a word. */
|
||||
|
||||
LIMWORD, /* LIMWORD is a terminal symbol that matches
|
||||
the empty string if it is at the beginning
|
||||
or the end of a word. */
|
||||
|
||||
NOTLIMWORD, /* NOTLIMWORD is a terminal symbol that
|
||||
matches the empty string if it is not at
|
||||
the beginning or end of a word. */
|
||||
|
||||
QMARK, /* QMARK is an operator of one argument that
|
||||
matches zero or one occurences of its
|
||||
argument. */
|
||||
|
||||
STAR, /* STAR is an operator of one argument that
|
||||
matches the Kleene closure (zero or more
|
||||
occurrences) of its argument. */
|
||||
|
||||
PLUS, /* PLUS is an operator of one argument that
|
||||
matches the positive closure (one or more
|
||||
occurrences) of its argument. */
|
||||
|
||||
REPMN, /* REPMN is a lexical token corresponding
|
||||
to the {m,n} construct. REPMN never
|
||||
appears in the compiled token vector. */
|
||||
|
||||
CAT, /* CAT is an operator of two arguments that
|
||||
matches the concatenation of its
|
||||
arguments. CAT is never returned by the
|
||||
lexical analyzer. */
|
||||
|
||||
OR, /* OR is an operator of two arguments that
|
||||
matches either of its arguments. */
|
||||
|
||||
ORTOP, /* OR at the toplevel in the parse tree.
|
||||
This is used for a boyer-moore heuristic. */
|
||||
|
||||
LPAREN, /* LPAREN never appears in the parse tree,
|
||||
it is only a lexeme. */
|
||||
|
||||
RPAREN, /* RPAREN never appears in the parse tree. */
|
||||
|
||||
CRANGE, /* CRANGE never appears in the parse tree.
|
||||
It stands for a character range that can
|
||||
match a string of one or more characters.
|
||||
For example, [a-z] can match "ch" in
|
||||
a Spanish locale. */
|
||||
|
||||
#ifdef MBS_SUPPORT
|
||||
ANYCHAR, /* ANYCHAR is a terminal symbol that matches
|
||||
any multibyte(or singlebyte) characters.
|
||||
It is used only if MB_CUR_MAX > 1. */
|
||||
|
||||
MBCSET, /* MBCSET is similar to CSET, but for
|
||||
multibyte characters. */
|
||||
#endif /* MBS_SUPPORT */
|
||||
|
||||
CSET /* CSET and (and any value greater) is a
|
||||
terminal symbol that matches any of a
|
||||
class of characters. */
|
||||
} token;
|
||||
|
||||
/* Sets are stored in an array in the compiled dfa; the index of the
|
||||
array corresponding to a given set token is given by SET_INDEX(t). */
|
||||
#define SET_INDEX(t) ((t) - CSET)
|
||||
|
||||
/* Sometimes characters can only be matched depending on the surrounding
|
||||
context. Such context decisions depend on what the previous character
|
||||
was, and the value of the current (lookahead) character. Context
|
||||
dependent constraints are encoded as 8 bit integers. Each bit that
|
||||
is set indicates that the constraint succeeds in the corresponding
|
||||
context.
|
||||
|
||||
bit 7 - previous and current are newlines
|
||||
bit 6 - previous was newline, current isn't
|
||||
bit 5 - previous wasn't newline, current is
|
||||
bit 4 - neither previous nor current is a newline
|
||||
bit 3 - previous and current are word-constituents
|
||||
bit 2 - previous was word-constituent, current isn't
|
||||
bit 1 - previous wasn't word-constituent, current is
|
||||
bit 0 - neither previous nor current is word-constituent
|
||||
|
||||
Word-constituent characters are those that satisfy isalnum().
|
||||
|
||||
The macro SUCCEEDS_IN_CONTEXT determines whether a a given constraint
|
||||
succeeds in a particular context. Prevn is true if the previous character
|
||||
was a newline, currn is true if the lookahead character is a newline.
|
||||
Prevl and currl similarly depend upon whether the previous and current
|
||||
characters are word-constituent letters. */
|
||||
#define MATCHES_NEWLINE_CONTEXT(constraint, prevn, currn) \
|
||||
((constraint) & 1 << (((prevn) ? 2 : 0) + ((currn) ? 1 : 0) + 4))
|
||||
#define MATCHES_LETTER_CONTEXT(constraint, prevl, currl) \
|
||||
((constraint) & 1 << (((prevl) ? 2 : 0) + ((currl) ? 1 : 0)))
|
||||
#define SUCCEEDS_IN_CONTEXT(constraint, prevn, currn, prevl, currl) \
|
||||
(MATCHES_NEWLINE_CONTEXT(constraint, prevn, currn) \
|
||||
&& MATCHES_LETTER_CONTEXT(constraint, prevl, currl))
|
||||
|
||||
/* The following macros give information about what a constraint depends on. */
|
||||
#define PREV_NEWLINE_DEPENDENT(constraint) \
|
||||
(((constraint) & 0xc0) >> 2 != ((constraint) & 0x30))
|
||||
#define PREV_LETTER_DEPENDENT(constraint) \
|
||||
(((constraint) & 0x0c) >> 2 != ((constraint) & 0x03))
|
||||
|
||||
/* Tokens that match the empty string subject to some constraint actually
|
||||
work by applying that constraint to determine what may follow them,
|
||||
taking into account what has gone before. The following values are
|
||||
the constraints corresponding to the special tokens previously defined. */
|
||||
#define NO_CONSTRAINT 0xff
|
||||
#define BEGLINE_CONSTRAINT 0xcf
|
||||
#define ENDLINE_CONSTRAINT 0xaf
|
||||
#define BEGWORD_CONSTRAINT 0xf2
|
||||
#define ENDWORD_CONSTRAINT 0xf4
|
||||
#define LIMWORD_CONSTRAINT 0xf6
|
||||
#define NOTLIMWORD_CONSTRAINT 0xf9
|
||||
|
||||
/* States of the recognizer correspond to sets of positions in the parse
|
||||
tree, together with the constraints under which they may be matched.
|
||||
So a position is encoded as an index into the parse tree together with
|
||||
a constraint. */
|
||||
typedef struct
|
||||
{
|
||||
unsigned index; /* Index into the parse array. */
|
||||
unsigned constraint; /* Constraint for matching this position. */
|
||||
} position;
|
||||
|
||||
/* Sets of positions are stored as arrays. */
|
||||
typedef struct
|
||||
{
|
||||
position *elems; /* Elements of this position set. */
|
||||
int nelem; /* Number of elements in this set. */
|
||||
} position_set;
|
||||
|
||||
/* A state of the dfa consists of a set of positions, some flags,
|
||||
and the token value of the lowest-numbered position of the state that
|
||||
contains an END token. */
|
||||
typedef struct
|
||||
{
|
||||
int hash; /* Hash of the positions of this state. */
|
||||
position_set elems; /* Positions this state could match. */
|
||||
char newline; /* True if previous state matched newline. */
|
||||
char letter; /* True if previous state matched a letter. */
|
||||
char backref; /* True if this state matches a \<digit>. */
|
||||
unsigned char constraint; /* Constraint for this state to accept. */
|
||||
int first_end; /* Token value of the first END in elems. */
|
||||
#ifdef MBS_SUPPORT
|
||||
position_set mbps; /* Positions which can match multibyte
|
||||
characters. e.g. period.
|
||||
These staff are used only if
|
||||
MB_CUR_MAX > 1. */
|
||||
#endif
|
||||
} dfa_state;
|
||||
|
||||
/* Element of a list of strings, at least one of which is known to
|
||||
appear in any R.E. matching the DFA. */
|
||||
struct dfamust
|
||||
{
|
||||
int exact;
|
||||
char *must;
|
||||
struct dfamust *next;
|
||||
};
|
||||
|
||||
#ifdef MBS_SUPPORT
|
||||
/* A bracket operator.
|
||||
e.g. [a-c], [[:alpha:]], etc. */
|
||||
struct mb_char_classes
|
||||
{
|
||||
int invert;
|
||||
wchar_t *chars; /* Normal characters. */
|
||||
int nchars;
|
||||
wctype_t *ch_classes; /* Character classes. */
|
||||
int nch_classes;
|
||||
wchar_t *range_sts; /* Range characters (start of the range). */
|
||||
wchar_t *range_ends; /* Range characters (end of the range). */
|
||||
int nranges;
|
||||
char **equivs; /* Equivalent classes. */
|
||||
int nequivs;
|
||||
char **coll_elems;
|
||||
int ncoll_elems; /* Collating elements. */
|
||||
};
|
||||
#endif
|
||||
|
||||
/* A compiled regular expression. */
|
||||
struct dfa
|
||||
{
|
||||
/* Stuff built by the scanner. */
|
||||
charclass *charclasses; /* Array of character sets for CSET tokens. */
|
||||
int cindex; /* Index for adding new charclasses. */
|
||||
int calloc; /* Number of charclasses currently allocated. */
|
||||
|
||||
/* Stuff built by the parser. */
|
||||
token *tokens; /* Postfix parse array. */
|
||||
int tindex; /* Index for adding new tokens. */
|
||||
int talloc; /* Number of tokens currently allocated. */
|
||||
int depth; /* Depth required of an evaluation stack
|
||||
used for depth-first traversal of the
|
||||
parse tree. */
|
||||
int nleaves; /* Number of leaves on the parse tree. */
|
||||
int nregexps; /* Count of parallel regexps being built
|
||||
with dfaparse(). */
|
||||
#ifdef MBS_SUPPORT
|
||||
/* These stuff are used only if MB_CUR_MAX > 1 or multibyte environments. */
|
||||
int nmultibyte_prop;
|
||||
int *multibyte_prop;
|
||||
/* The value of multibyte_prop[i] is defined by following rule.
|
||||
if tokens[i] < NOTCHAR
|
||||
bit 1 : tokens[i] is a singlebyte character, or the last-byte of
|
||||
a multibyte character.
|
||||
bit 0 : tokens[i] is a singlebyte character, or the 1st-byte of
|
||||
a multibyte character.
|
||||
if tokens[i] = MBCSET
|
||||
("the index of mbcsets correspnd to this operator" << 2) + 3
|
||||
|
||||
e.g.
|
||||
tokens
|
||||
= 'single_byte_a', 'multi_byte_A', single_byte_b'
|
||||
= 'sb_a', 'mb_A(1st byte)', 'mb_A(2nd byte)', 'mb_A(3rd byte)', 'sb_b'
|
||||
multibyte_prop
|
||||
= 3 , 1 , 0 , 2 , 3
|
||||
*/
|
||||
|
||||
/* Array of the bracket expressoin in the DFA. */
|
||||
struct mb_char_classes *mbcsets;
|
||||
int nmbcsets;
|
||||
int mbcsets_alloc;
|
||||
#endif
|
||||
|
||||
/* Stuff owned by the state builder. */
|
||||
dfa_state *states; /* States of the dfa. */
|
||||
int sindex; /* Index for adding new states. */
|
||||
int salloc; /* Number of states currently allocated. */
|
||||
|
||||
/* Stuff built by the structure analyzer. */
|
||||
position_set *follows; /* Array of follow sets, indexed by position
|
||||
index. The follow of a position is the set
|
||||
of positions containing characters that
|
||||
could conceivably follow a character
|
||||
matching the given position in a string
|
||||
matching the regexp. Allocated to the
|
||||
maximum possible position index. */
|
||||
int searchflag; /* True if we are supposed to build a searching
|
||||
as opposed to an exact matcher. A searching
|
||||
matcher finds the first and shortest string
|
||||
matching a regexp anywhere in the buffer,
|
||||
whereas an exact matcher finds the longest
|
||||
string matching, but anchored to the
|
||||
beginning of the buffer. */
|
||||
|
||||
/* Stuff owned by the executor. */
|
||||
int tralloc; /* Number of transition tables that have
|
||||
slots so far. */
|
||||
int trcount; /* Number of transition tables that have
|
||||
actually been built. */
|
||||
int **trans; /* Transition tables for states that can
|
||||
never accept. If the transitions for a
|
||||
state have not yet been computed, or the
|
||||
state could possibly accept, its entry in
|
||||
this table is NULL. */
|
||||
int **realtrans; /* Trans always points to realtrans + 1; this
|
||||
is so trans[-1] can contain NULL. */
|
||||
int **fails; /* Transition tables after failing to accept
|
||||
on a state that potentially could do so. */
|
||||
int *success; /* Table of acceptance conditions used in
|
||||
dfaexec and computed in build_state. */
|
||||
struct dfamust *musts; /* List of strings, at least one of which
|
||||
is known to appear in any r.e. matching
|
||||
the dfa. */
|
||||
};
|
||||
|
||||
/* Some macros for user access to dfa internals. */
|
||||
|
||||
/* ACCEPTING returns true if s could possibly be an accepting state of r. */
|
||||
#define ACCEPTING(s, r) ((r).states[s].constraint)
|
||||
|
||||
/* ACCEPTS_IN_CONTEXT returns true if the given state accepts in the
|
||||
specified context. */
|
||||
#define ACCEPTS_IN_CONTEXT(prevn, currn, prevl, currl, state, dfa) \
|
||||
SUCCEEDS_IN_CONTEXT((dfa).states[state].constraint, \
|
||||
prevn, currn, prevl, currl)
|
||||
|
||||
/* FIRST_MATCHING_REGEXP returns the index number of the first of parallel
|
||||
regexps that a given state could accept. Parallel regexps are numbered
|
||||
starting at 1. */
|
||||
#define FIRST_MATCHING_REGEXP(state, dfa) (-(dfa).states[state].first_end)
|
||||
|
||||
/* Entry points. */
|
||||
|
||||
/* dfasyntax() takes three arguments; the first sets the syntax bits described
|
||||
earlier in this file, the second sets the case-folding flag, and the
|
||||
third specifies the line terminator. */
|
||||
extern void dfasyntax PARAMS ((reg_syntax_t, int, unsigned char));
|
||||
|
||||
/* Compile the given string of the given length into the given struct dfa.
|
||||
Final argument is a flag specifying whether to build a searching or an
|
||||
exact matcher. */
|
||||
extern void dfacomp PARAMS ((char const *, size_t, struct dfa *, int));
|
||||
|
||||
/* Execute the given struct dfa on the buffer of characters. The
|
||||
last byte of the buffer must equal the end-of-line byte.
|
||||
The final argument points to a flag that will
|
||||
be set if further examination by a backtracking matcher is needed in
|
||||
order to verify backreferencing; otherwise the flag will be cleared.
|
||||
Returns (size_t) -1 if no match is found, or the offset of the first
|
||||
character after the first & shortest matching string in the buffer. */
|
||||
extern size_t dfaexec PARAMS ((struct dfa *, char const *, size_t, int *));
|
||||
|
||||
/* Free the storage held by the components of a struct dfa. */
|
||||
extern void dfafree PARAMS ((struct dfa *));
|
||||
|
||||
/* Entry points for people who know what they're doing. */
|
||||
|
||||
/* Initialize the components of a struct dfa. */
|
||||
extern void dfainit PARAMS ((struct dfa *));
|
||||
|
||||
/* Incrementally parse a string of given length into a struct dfa. */
|
||||
extern void dfaparse PARAMS ((char const *, size_t, struct dfa *));
|
||||
|
||||
/* Analyze a parsed regexp; second argument tells whether to build a searching
|
||||
or an exact matcher. */
|
||||
extern void dfaanalyze PARAMS ((struct dfa *, int));
|
||||
|
||||
/* Compute, for each possible character, the transitions out of a given
|
||||
state, storing them in an array of integers. */
|
||||
extern void dfastate PARAMS ((int, struct dfa *, int []));
|
||||
|
||||
/* Error handling. */
|
||||
|
||||
/* dfaerror() is called by the regexp routines whenever an error occurs. It
|
||||
takes a single argument, a NUL-terminated string describing the error.
|
||||
The user must supply a dfaerror. */
|
||||
extern void dfaerror PARAMS ((const char *));
|
@ -1,276 +0,0 @@
|
||||
/* Error handler for noninteractive utilities
|
||||
Copyright (C) 1990-1998, 2000 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,
|
||||
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. */
|
||||
|
||||
/* Written by David MacKenzie <djm@gnu.ai.mit.edu>. */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#if HAVE_LIBINTL_H
|
||||
# include <libintl.h>
|
||||
#endif
|
||||
|
||||
#if HAVE_VPRINTF || HAVE_DOPRNT || _LIBC
|
||||
# if __STDC__
|
||||
# include <stdarg.h>
|
||||
# define VA_START(args, lastarg) va_start(args, lastarg)
|
||||
# else
|
||||
# include <varargs.h>
|
||||
# define VA_START(args, lastarg) va_start(args)
|
||||
# endif
|
||||
#else
|
||||
# define va_alist a1, a2, a3, a4, a5, a6, a7, a8
|
||||
# define va_dcl char *a1, *a2, *a3, *a4, *a5, *a6, *a7, *a8;
|
||||
#endif
|
||||
|
||||
#if STDC_HEADERS || _LIBC
|
||||
# include <stdlib.h>
|
||||
# include <string.h>
|
||||
#else
|
||||
void exit ();
|
||||
#endif
|
||||
|
||||
#include "error.h"
|
||||
|
||||
#ifndef HAVE_DECL_STRERROR_R
|
||||
"this configure-time declaration test was not run"
|
||||
#endif
|
||||
#if !HAVE_DECL_STRERROR_R
|
||||
char *strerror_r ();
|
||||
#endif
|
||||
|
||||
#ifndef _
|
||||
# define _(String) String
|
||||
#endif
|
||||
|
||||
/* If NULL, error will flush stdout, then print on stderr the program
|
||||
name, a colon and a space. Otherwise, error will call this
|
||||
function without parameters instead. */
|
||||
void (*error_print_progname) (
|
||||
#if __STDC__ - 0
|
||||
void
|
||||
#endif
|
||||
);
|
||||
|
||||
/* This variable is incremented each time `error' is called. */
|
||||
unsigned int error_message_count;
|
||||
|
||||
#ifdef _LIBC
|
||||
/* In the GNU C library, there is a predefined variable for this. */
|
||||
|
||||
# define program_name program_invocation_name
|
||||
# include <errno.h>
|
||||
|
||||
/* In GNU libc we want do not want to use the common name `error' directly.
|
||||
Instead make it a weak alias. */
|
||||
# define error __error
|
||||
# define error_at_line __error_at_line
|
||||
|
||||
# ifdef USE_IN_LIBIO
|
||||
# include <libio/iolibio.h>
|
||||
# define fflush(s) _IO_fflush (s)
|
||||
# endif
|
||||
|
||||
#else /* not _LIBC */
|
||||
|
||||
/* The calling program should define program_name and set it to the
|
||||
name of the executing program. */
|
||||
extern char *program_name;
|
||||
|
||||
# ifdef HAVE_STRERROR_R
|
||||
# define __strerror_r strerror_r
|
||||
# else
|
||||
# if HAVE_STRERROR
|
||||
# ifndef strerror /* On some systems, strerror is a macro */
|
||||
char *strerror ();
|
||||
# endif
|
||||
# else
|
||||
static char *
|
||||
private_strerror (errnum)
|
||||
int errnum;
|
||||
{
|
||||
extern char *sys_errlist[];
|
||||
extern int sys_nerr;
|
||||
|
||||
if (errnum > 0 && errnum <= sys_nerr)
|
||||
return _(sys_errlist[errnum]);
|
||||
return _("Unknown system error");
|
||||
}
|
||||
# define strerror private_strerror
|
||||
# endif /* HAVE_STRERROR */
|
||||
# endif /* HAVE_STRERROR_R */
|
||||
#endif /* not _LIBC */
|
||||
|
||||
/* Print the program name and error message MESSAGE, which is a printf-style
|
||||
format string with optional args.
|
||||
If ERRNUM is nonzero, print its corresponding system error message.
|
||||
Exit with status STATUS if it is nonzero. */
|
||||
/* VARARGS */
|
||||
|
||||
void
|
||||
#if defined VA_START && __STDC__
|
||||
error (int status, int errnum, const char *message, ...)
|
||||
#else
|
||||
error (status, errnum, message, va_alist)
|
||||
int status;
|
||||
int errnum;
|
||||
char *message;
|
||||
va_dcl
|
||||
#endif
|
||||
{
|
||||
#ifdef VA_START
|
||||
va_list args;
|
||||
#endif
|
||||
|
||||
if (error_print_progname)
|
||||
(*error_print_progname) ();
|
||||
else
|
||||
{
|
||||
fflush (stdout);
|
||||
fprintf (stderr, "%s: ", program_name);
|
||||
}
|
||||
|
||||
#ifdef VA_START
|
||||
VA_START (args, message);
|
||||
# if HAVE_VPRINTF || _LIBC
|
||||
vfprintf (stderr, message, args);
|
||||
# else
|
||||
_doprnt (message, args, stderr);
|
||||
# endif
|
||||
va_end (args);
|
||||
#else
|
||||
fprintf (stderr, message, a1, a2, a3, a4, a5, a6, a7, a8);
|
||||
#endif
|
||||
|
||||
++error_message_count;
|
||||
if (errnum)
|
||||
{
|
||||
#if defined HAVE_STRERROR_R || _LIBC
|
||||
char errbuf[1024];
|
||||
# if HAVE_WORKING_STRERROR_R || _LIBC
|
||||
fprintf (stderr, ": %s", __strerror_r (errnum, errbuf, sizeof errbuf));
|
||||
# else
|
||||
/* Don't use __strerror_r's return value because on some systems
|
||||
(at least DEC UNIX 4.0[A-D]) strerror_r returns `int'. */
|
||||
__strerror_r (errnum, errbuf, sizeof errbuf);
|
||||
fprintf (stderr, ": %s", errbuf);
|
||||
# endif
|
||||
#else
|
||||
fprintf (stderr, ": %s", strerror (errnum));
|
||||
#endif
|
||||
}
|
||||
putc ('\n', stderr);
|
||||
fflush (stderr);
|
||||
if (status)
|
||||
exit (status);
|
||||
}
|
||||
|
||||
/* Sometimes we want to have at most one error per line. This
|
||||
variable controls whether this mode is selected or not. */
|
||||
int error_one_per_line;
|
||||
|
||||
void
|
||||
#if defined VA_START && __STDC__
|
||||
error_at_line (int status, int errnum, const char *file_name,
|
||||
unsigned int line_number, const char *message, ...)
|
||||
#else
|
||||
error_at_line (status, errnum, file_name, line_number, message, va_alist)
|
||||
int status;
|
||||
int errnum;
|
||||
const char *file_name;
|
||||
unsigned int line_number;
|
||||
char *message;
|
||||
va_dcl
|
||||
#endif
|
||||
{
|
||||
#ifdef VA_START
|
||||
va_list args;
|
||||
#endif
|
||||
|
||||
if (error_one_per_line)
|
||||
{
|
||||
static const char *old_file_name;
|
||||
static unsigned int old_line_number;
|
||||
|
||||
if (old_line_number == line_number &&
|
||||
(file_name == old_file_name || !strcmp (old_file_name, file_name)))
|
||||
/* Simply return and print nothing. */
|
||||
return;
|
||||
|
||||
old_file_name = file_name;
|
||||
old_line_number = line_number;
|
||||
}
|
||||
|
||||
if (error_print_progname)
|
||||
(*error_print_progname) ();
|
||||
else
|
||||
{
|
||||
fflush (stdout);
|
||||
fprintf (stderr, "%s:", program_name);
|
||||
}
|
||||
|
||||
if (file_name != NULL)
|
||||
fprintf (stderr, "%s:%d: ", file_name, line_number);
|
||||
|
||||
#ifdef VA_START
|
||||
VA_START (args, message);
|
||||
# if HAVE_VPRINTF || _LIBC
|
||||
vfprintf (stderr, message, args);
|
||||
# else
|
||||
_doprnt (message, args, stderr);
|
||||
# endif
|
||||
va_end (args);
|
||||
#else
|
||||
fprintf (stderr, message, a1, a2, a3, a4, a5, a6, a7, a8);
|
||||
#endif
|
||||
|
||||
++error_message_count;
|
||||
if (errnum)
|
||||
{
|
||||
#if defined HAVE_STRERROR_R || _LIBC
|
||||
char errbuf[1024];
|
||||
# if HAVE_WORKING_STRERROR_R || _LIBC
|
||||
fprintf (stderr, ": %s", __strerror_r (errnum, errbuf, sizeof errbuf));
|
||||
# else
|
||||
/* Don't use __strerror_r's return value because on some systems
|
||||
(at least DEC UNIX 4.0[A-D]) strerror_r returns `int'. */
|
||||
__strerror_r (errnum, errbuf, sizeof errbuf);
|
||||
fprintf (stderr, ": %s", errbuf);
|
||||
# endif
|
||||
#else
|
||||
fprintf (stderr, ": %s", strerror (errnum));
|
||||
#endif
|
||||
}
|
||||
putc ('\n', stderr);
|
||||
fflush (stderr);
|
||||
if (status)
|
||||
exit (status);
|
||||
}
|
||||
|
||||
#ifdef _LIBC
|
||||
/* Make the weak alias. */
|
||||
# undef error
|
||||
# undef error_at_line
|
||||
weak_alias (__error, error)
|
||||
weak_alias (__error_at_line, error_at_line)
|
||||
#endif
|
@ -1,78 +0,0 @@
|
||||
/* Declaration for error-reporting function
|
||||
Copyright (C) 1995, 1996, 1997 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.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by the
|
||||
Free Software Foundation; either version 2, or (at your option) any
|
||||
later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
||||
USA. */
|
||||
|
||||
#ifndef _ERROR_H
|
||||
#define _ERROR_H 1
|
||||
|
||||
#ifndef __attribute__
|
||||
/* This feature is available in gcc versions 2.5 and later. */
|
||||
# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || __STRICT_ANSI__
|
||||
# define __attribute__(Spec) /* empty */
|
||||
# endif
|
||||
/* The __-protected variants of `format' and `printf' attributes
|
||||
are accepted by gcc versions 2.6.4 (effectively 2.7) and later. */
|
||||
# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7)
|
||||
# define __format__ format
|
||||
# define __printf__ printf
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#if defined (__STDC__) && __STDC__
|
||||
|
||||
/* Print a message with `fprintf (stderr, FORMAT, ...)';
|
||||
if ERRNUM is nonzero, follow it with ": " and strerror (ERRNUM).
|
||||
If STATUS is nonzero, terminate the program with `exit (STATUS)'. */
|
||||
|
||||
extern void error (int status, int errnum, const char *format, ...)
|
||||
__attribute__ ((__format__ (__printf__, 3, 4)));
|
||||
|
||||
extern void error_at_line (int status, int errnum, const char *fname,
|
||||
unsigned int lineno, const char *format, ...)
|
||||
__attribute__ ((__format__ (__printf__, 5, 6)));
|
||||
|
||||
/* If NULL, error will flush stdout, then print on stderr the program
|
||||
name, a colon and a space. Otherwise, error will call this
|
||||
function without parameters instead. */
|
||||
extern void (*error_print_progname) (void);
|
||||
|
||||
#else
|
||||
void error ();
|
||||
void error_at_line ();
|
||||
extern void (*error_print_progname) ();
|
||||
#endif
|
||||
|
||||
/* This variable is incremented each time `error' is called. */
|
||||
extern unsigned int error_message_count;
|
||||
|
||||
/* Sometimes we want to have at most one error per line. This
|
||||
variable controls whether this mode is selected or not. */
|
||||
extern int error_one_per_line;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* error.h */
|
@ -1,128 +0,0 @@
|
||||
/* exclude.c -- exclude file names
|
||||
Copyright 1992, 1993, 1994, 1997, 1999, 2000 Free Software Foundation, Inc.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; see the file COPYING.
|
||||
If not, write to the Free Software Foundation,
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
||||
|
||||
/* Written by Paul Eggert <eggert@twinsun.com> */
|
||||
|
||||
#if HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#include <errno.h>
|
||||
#ifndef errno
|
||||
extern int errno;
|
||||
#endif
|
||||
#include <exclude.h>
|
||||
#include <fnmatch.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
void *xmalloc PARAMS ((size_t));
|
||||
void *xrealloc PARAMS ((void *, size_t));
|
||||
|
||||
/* Keep track of excluded file name patterns. */
|
||||
|
||||
struct exclude
|
||||
{
|
||||
char const **exclude;
|
||||
int exclude_alloc;
|
||||
int exclude_count;
|
||||
};
|
||||
|
||||
struct exclude *
|
||||
new_exclude (void)
|
||||
{
|
||||
struct exclude *ex = (struct exclude *) xmalloc (sizeof (struct exclude));
|
||||
ex->exclude_count = 0;
|
||||
ex->exclude_alloc = 64;
|
||||
ex->exclude = (char const **) xmalloc (ex->exclude_alloc * sizeof (char *));
|
||||
return ex;
|
||||
}
|
||||
|
||||
int
|
||||
excluded_filename (struct exclude const *ex, char const *f, int options)
|
||||
{
|
||||
char const * const *exclude = ex->exclude;
|
||||
int exclude_count = ex->exclude_count;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < exclude_count; i++)
|
||||
if (fnmatch (exclude[i], f, options) == 0)
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
add_exclude (struct exclude *ex, char const *pattern)
|
||||
{
|
||||
if (ex->exclude_alloc <= ex->exclude_count)
|
||||
ex->exclude = (char const **) xrealloc (ex->exclude,
|
||||
((ex->exclude_alloc *= 2)
|
||||
* sizeof (char *)));
|
||||
|
||||
ex->exclude[ex->exclude_count++] = pattern;
|
||||
}
|
||||
|
||||
int
|
||||
add_exclude_file (void (*add_func) PARAMS ((struct exclude *, char const *)),
|
||||
struct exclude *ex, char const *filename, char line_end)
|
||||
{
|
||||
int use_stdin = filename[0] == '-' && !filename[1];
|
||||
FILE *in;
|
||||
char *buf;
|
||||
char *p;
|
||||
char const *pattern;
|
||||
char const *lim;
|
||||
size_t buf_alloc = 1024;
|
||||
size_t buf_count = 0;
|
||||
int c;
|
||||
int e = 0;
|
||||
|
||||
if (use_stdin)
|
||||
in = stdin;
|
||||
else if (! (in = fopen (filename, "r")))
|
||||
return -1;
|
||||
|
||||
buf = xmalloc (buf_alloc);
|
||||
|
||||
while ((c = getc (in)) != EOF)
|
||||
{
|
||||
buf[buf_count++] = c;
|
||||
if (buf_count == buf_alloc)
|
||||
buf = xrealloc (buf, buf_alloc *= 2);
|
||||
}
|
||||
|
||||
buf = xrealloc (buf, buf_count + 1);
|
||||
|
||||
if (ferror (in))
|
||||
e = errno;
|
||||
|
||||
if (!use_stdin && fclose (in) != 0)
|
||||
e = errno;
|
||||
|
||||
for (pattern = p = buf, lim = buf + buf_count; p <= lim; p++)
|
||||
if (p < lim ? *p == line_end : buf < p && p[-1])
|
||||
{
|
||||
*p = '\0';
|
||||
(*add_func) (ex, pattern);
|
||||
pattern = p + 1;
|
||||
}
|
||||
|
||||
errno = e;
|
||||
return e ? -1 : 0;
|
||||
}
|
@ -1,35 +0,0 @@
|
||||
/* exclude.h -- declarations for excluding file names
|
||||
Copyright 1992, 1993, 1994, 1997, 1999 Free Software Foundation, Inc.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; see the file COPYING.
|
||||
If not, write to the Free Software Foundation,
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
||||
|
||||
/* Written by Paul Eggert <eggert@twinsun.com> */
|
||||
|
||||
#ifndef PARAMS
|
||||
# if defined PROTOTYPES || (defined __STDC__ && __STDC__)
|
||||
# define PARAMS(Args) Args
|
||||
# else
|
||||
# define PARAMS(Args) ()
|
||||
# endif
|
||||
#endif
|
||||
|
||||
struct exclude;
|
||||
|
||||
struct exclude *new_exclude PARAMS ((void));
|
||||
void add_exclude PARAMS ((struct exclude *, char const *));
|
||||
int add_exclude_file PARAMS ((void (*) (struct exclude *, char const *),
|
||||
struct exclude *, char const *, char));
|
||||
int excluded_filename PARAMS ((struct exclude const *, char const *, int));
|
@ -1,48 +0,0 @@
|
||||
/* Emulate getpagesize on systems that lack it. */
|
||||
|
||||
/* $FreeBSD$ */
|
||||
|
||||
#ifndef HAVE_GETPAGESIZE
|
||||
|
||||
#if !defined getpagesize && defined __BEOS__
|
||||
# include <OS.h>
|
||||
# define getpagesize() B_PAGE_SIZE
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_UNISTD_H
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
|
||||
#if !defined getpagesize && defined _SC_PAGESIZE
|
||||
# if !(defined VMS && __VMS_VER < 70000000)
|
||||
# define getpagesize() sysconf (_SC_PAGESIZE)
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if !defined getpagesize && defined VMS
|
||||
# ifdef __ALPHA
|
||||
# define getpagesize() 8192
|
||||
# else
|
||||
# define getpagesize() 512
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef getpagesize
|
||||
# include <sys/param.h>
|
||||
# ifdef EXEC_PAGESIZE
|
||||
# define getpagesize() EXEC_PAGESIZE
|
||||
# else
|
||||
# ifdef NBPG
|
||||
# ifndef CLSIZE
|
||||
# define CLSIZE 1
|
||||
# endif
|
||||
# define getpagesize() (NBPG * CLSIZE)
|
||||
# else
|
||||
# ifdef NBPC
|
||||
# define getpagesize() NBPC
|
||||
# endif
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#endif /* not HAVE_GETPAGESIZE */
|
@ -1,780 +0,0 @@
|
||||
.\" grep man page
|
||||
.\" $FreeBSD$
|
||||
.if !\n(.g \{\
|
||||
. if !\w|\*(lq| \{\
|
||||
. ds lq ``
|
||||
. if \w'\(lq' .ds lq "\(lq
|
||||
. \}
|
||||
. if !\w|\*(rq| \{\
|
||||
. ds rq ''
|
||||
. if \w'\(rq' .ds rq "\(rq
|
||||
. \}
|
||||
.\}
|
||||
.de Id
|
||||
.ds Dt \\$4
|
||||
..
|
||||
.Id $Id: grep.1,v 1.23 2002/01/22 13:20:04 bero Exp $
|
||||
.TH GREP 1 \*(Dt "GNU Project"
|
||||
.SH NAME
|
||||
grep, egrep, fgrep, zgrep, zegrep, zfgrep,
|
||||
bzgrep, bzegrep, bzfgrep \- print lines matching a pattern
|
||||
.SH SYNOPSIS
|
||||
.B grep
|
||||
.RI [ options ]
|
||||
.I PATTERN
|
||||
.RI [ FILE .\|.\|.]
|
||||
.br
|
||||
.B grep
|
||||
.RI [ options ]
|
||||
.RB [ \-e
|
||||
.I PATTERN
|
||||
|
|
||||
.B \-f
|
||||
.IR FILE ]
|
||||
.RI [ FILE .\|.\|.]
|
||||
.SH DESCRIPTION
|
||||
.B grep
|
||||
searches the named input
|
||||
.IR FILE s
|
||||
(or standard input if no files are named, or
|
||||
the file name
|
||||
.B \-
|
||||
is given)
|
||||
for lines containing a match to the given
|
||||
.IR PATTERN .
|
||||
By default,
|
||||
.B grep
|
||||
prints the matching lines.
|
||||
.PP
|
||||
In addition, two variant programs
|
||||
.B egrep
|
||||
and
|
||||
.B fgrep
|
||||
are available.
|
||||
.B egrep
|
||||
is the same as
|
||||
.BR "grep\ \-E" .
|
||||
.B fgrep
|
||||
is the same as
|
||||
.BR "grep\ \-F" .
|
||||
.B zgrep
|
||||
is the same as
|
||||
.BR "grep\ \-Z" .
|
||||
.B zegrep
|
||||
is the same as
|
||||
.BR "grep\ \-EZ" .
|
||||
.B zfgrep
|
||||
is the same as
|
||||
.BR "grep\ \-FZ" .
|
||||
.SH OPTIONS
|
||||
.TP
|
||||
.BI \-A " NUM" "\fR,\fP \-\^\-after-context=" NUM
|
||||
Print
|
||||
.I NUM
|
||||
lines of trailing context after matching lines.
|
||||
Places a line containing
|
||||
.B \-\^\-
|
||||
between contiguous groups of matches.
|
||||
.TP
|
||||
.BR \-a ", " \-\^\-text
|
||||
Process a binary file as if it were text; this is equivalent to the
|
||||
.B \-\^\-binary-files=text
|
||||
option.
|
||||
.TP
|
||||
.BI \-B " NUM" "\fR,\fP \-\^\-before-context=" NUM
|
||||
Print
|
||||
.I NUM
|
||||
lines of leading context before matching lines.
|
||||
Places a line containing
|
||||
.B \-\^\-
|
||||
between contiguous groups of matches.
|
||||
.TP
|
||||
.BI \-C " NUM" "\fR,\fP \-\^\-context=" NUM
|
||||
Print
|
||||
.I NUM
|
||||
lines of output context.
|
||||
Places a line containing
|
||||
.B \-\^\-
|
||||
between contiguous groups of matches.
|
||||
.TP
|
||||
.BR \-b ", " \-\^\-byte-offset
|
||||
Print the byte offset within the input file before
|
||||
each line of output.
|
||||
.TP
|
||||
.BI \-\^\-binary-files= TYPE
|
||||
If the first few bytes of a file indicate that the file contains binary
|
||||
data, assume that the file is of type
|
||||
.IR TYPE .
|
||||
By default,
|
||||
.I TYPE
|
||||
is
|
||||
.BR binary ,
|
||||
and
|
||||
.B grep
|
||||
normally outputs either
|
||||
a one-line message saying that a binary file matches, or no message if
|
||||
there is no match.
|
||||
If
|
||||
.I TYPE
|
||||
is
|
||||
.BR without-match ,
|
||||
.B grep
|
||||
assumes that a binary file does not match; this is equivalent to the
|
||||
.B \-I
|
||||
option.
|
||||
If
|
||||
.I TYPE
|
||||
is
|
||||
.BR text ,
|
||||
.B grep
|
||||
processes a binary file as if it were text; this is equivalent to the
|
||||
.B \-a
|
||||
option.
|
||||
.I Warning:
|
||||
.B "grep \-\^\-binary-files=text"
|
||||
might output binary garbage,
|
||||
which can have nasty side effects if the output is a terminal and if the
|
||||
terminal driver interprets some of it as commands.
|
||||
.TP
|
||||
.BI \-\^\-colour[=\fIWHEN\fR] ", " \-\^\-color[=\fIWHEN\fR]
|
||||
Surround the matching string with the marker find in
|
||||
.B GREP_COLOR
|
||||
environment variable. WHEN may be `never', `always', or `auto'
|
||||
.TP
|
||||
.BR \-c ", " \-\^\-count
|
||||
Suppress normal output; instead print a count of
|
||||
matching lines for each input file.
|
||||
With the
|
||||
.BR \-v ", " \-\^\-invert-match
|
||||
option (see below), count non-matching lines.
|
||||
.TP
|
||||
.BI \-D " ACTION" "\fR,\fP \-\^\-devices=" ACTION
|
||||
If an input file is a device, FIFO or socket, use
|
||||
.I ACTION
|
||||
to process it. By default,
|
||||
.I ACTION
|
||||
is
|
||||
.BR read ,
|
||||
which means that devices are read just as if they were ordinary files.
|
||||
If
|
||||
.I ACTION
|
||||
is
|
||||
.BR skip ,
|
||||
devices are silently skipped.
|
||||
.TP
|
||||
.BI \-d " ACTION" "\fR,\fP \-\^\-directories=" ACTION
|
||||
If an input file is a directory, use
|
||||
.I ACTION
|
||||
to process it. By default,
|
||||
.I ACTION
|
||||
is
|
||||
.BR read ,
|
||||
which means that directories are read just as if they were ordinary files.
|
||||
If
|
||||
.I ACTION
|
||||
is
|
||||
.BR skip ,
|
||||
directories are silently skipped.
|
||||
If
|
||||
.I ACTION
|
||||
is
|
||||
.BR recurse ,
|
||||
.B grep
|
||||
reads all files under each directory, recursively;
|
||||
this is equivalent to the
|
||||
.B \-r
|
||||
option.
|
||||
.TP
|
||||
.BR \-E ", " \-\^\-extended-regexp
|
||||
Interpret
|
||||
.I PATTERN
|
||||
as an extended regular expression (see below).
|
||||
.TP
|
||||
.BI \-e " PATTERN" "\fR,\fP \-\^\-regexp=" PATTERN
|
||||
Use
|
||||
.I PATTERN
|
||||
as the pattern; useful to protect patterns beginning with
|
||||
.BR \- .
|
||||
.TP
|
||||
.BR \-F ", " \-\^\-fixed-strings
|
||||
Interpret
|
||||
.I PATTERN
|
||||
as a list of fixed strings, separated by newlines,
|
||||
any of which is to be matched.
|
||||
.TP
|
||||
.BR \-P ", " \-\^\-perl-regexp
|
||||
Interpret
|
||||
.I PATTERN
|
||||
as a Perl regular expression.
|
||||
This option is not supported in FreeBSD.
|
||||
.TP
|
||||
.BI \-f " FILE" "\fR,\fP \-\^\-file=" FILE
|
||||
Obtain patterns from
|
||||
.IR FILE ,
|
||||
one per line.
|
||||
The empty file contains zero patterns, and therefore matches nothing.
|
||||
.TP
|
||||
.BR \-G ", " \-\^\-basic-regexp
|
||||
Interpret
|
||||
.I PATTERN
|
||||
as a basic regular expression (see below). This is the default.
|
||||
.TP
|
||||
.BR \-H ", " \-\^\-with-filename
|
||||
Print the filename for each match.
|
||||
.TP
|
||||
.BR \-h ", " \-\^\-no-filename
|
||||
Suppress the prefixing of filenames on output
|
||||
when multiple files are searched.
|
||||
.TP
|
||||
.B \-\^\-help
|
||||
Output a brief help message.
|
||||
.TP
|
||||
.BR \-I
|
||||
Process a binary file as if it did not contain matching data; this is
|
||||
equivalent to the
|
||||
.B \-\^\-binary-files=without-match
|
||||
option.
|
||||
.TP
|
||||
.BR \-i ", " \-\^\-ignore-case
|
||||
Ignore case distinctions in both the
|
||||
.I PATTERN
|
||||
and the input files.
|
||||
.TP
|
||||
.BR \-L ", " \-\^\-files-without-match
|
||||
Suppress normal output; instead print the name
|
||||
of each input file from which no output would
|
||||
normally have been printed. The scanning will stop
|
||||
on the first match.
|
||||
.TP
|
||||
.BR \-l ", " \-\^\-files-with-matches
|
||||
Suppress normal output; instead print
|
||||
the name of each input file from which output
|
||||
would normally have been printed. The scanning will
|
||||
stop on the first match.
|
||||
.TP
|
||||
.BI \-m " NUM" "\fR,\fP \-\^\-max-count=" NUM
|
||||
Stop reading a file after
|
||||
.I NUM
|
||||
matching lines. If the input is standard input from a regular file,
|
||||
and
|
||||
.I NUM
|
||||
matching lines are output,
|
||||
.B grep
|
||||
ensures that the standard input is positioned to just after the last
|
||||
matching line before exiting, regardless of the presence of trailing
|
||||
context lines. This enables a calling process to resume a search.
|
||||
When
|
||||
.B grep
|
||||
stops after
|
||||
.I NUM
|
||||
matching lines, it outputs any trailing context lines. When the
|
||||
.B \-c
|
||||
or
|
||||
.B \-\^\-count
|
||||
option is also used,
|
||||
.B grep
|
||||
does not output a count greater than
|
||||
.IR NUM .
|
||||
When the
|
||||
.B \-v
|
||||
or
|
||||
.B \-\^\-invert-match
|
||||
option is also used,
|
||||
.B grep
|
||||
stops after outputting
|
||||
.I NUM
|
||||
non-matching lines.
|
||||
.TP
|
||||
.B \-\^\-mmap
|
||||
If possible, use the
|
||||
.BR mmap (2)
|
||||
system call to read input, instead of
|
||||
the default
|
||||
.BR read (2)
|
||||
system call. In some situations,
|
||||
.B \-\^\-mmap
|
||||
yields better performance. However,
|
||||
.B \-\^\-mmap
|
||||
can cause undefined behavior (including core dumps)
|
||||
if an input file shrinks while
|
||||
.B grep
|
||||
is operating, or if an I/O error occurs.
|
||||
.TP
|
||||
.BR \-n ", " \-\^\-line-number
|
||||
Prefix each line of output with the line number
|
||||
within its input file.
|
||||
.TP
|
||||
.BR \-o ", " \-\^\-only-matching
|
||||
Show only the part of a matching line that matches
|
||||
.I PATTERN.
|
||||
.TP
|
||||
.BI \-\^\-label= LABEL
|
||||
Displays input actually coming from standard input as input coming from file
|
||||
.I LABEL.
|
||||
This is especially useful for tools like zgrep, e.g.
|
||||
.B "gzip -cd foo.gz |grep --label=foo something"
|
||||
.TP
|
||||
.BR \-\^\-line-buffered
|
||||
Flush output on every line.
|
||||
Note that this incurs a performance penalty.
|
||||
.TP
|
||||
.BR \-q ", " \-\^\-quiet ", " \-\^\-silent
|
||||
Quiet; do not write anything to standard output.
|
||||
Exit immediately with zero status if any match is found,
|
||||
even if an error was detected.
|
||||
Also see the
|
||||
.B \-s
|
||||
or
|
||||
.B \-\^\-no-messages
|
||||
option.
|
||||
.TP
|
||||
.BR \-R ", " \-r ", " \-\^\-recursive
|
||||
Read all files under each directory, recursively;
|
||||
this is equivalent to the
|
||||
.B "\-d recurse"
|
||||
option.
|
||||
.TP
|
||||
.BR "\fR \fP \-\^\-include=" PATTERN
|
||||
Recurse in directories only searching file matching
|
||||
.I PATTERN.
|
||||
.TP
|
||||
.BR "\fR \fP \-\^\-exclude=" PATTERN
|
||||
Recurse in directories skip file matching
|
||||
.I PATTERN.
|
||||
.TP
|
||||
.BR \-s ", " \-\^\-no-messages
|
||||
Suppress error messages about nonexistent or unreadable files.
|
||||
Portability note: unlike \s-1GNU\s0
|
||||
.BR grep ,
|
||||
traditional
|
||||
.B grep
|
||||
did not conform to \s-1POSIX.2\s0, because traditional
|
||||
.B grep
|
||||
lacked a
|
||||
.B \-q
|
||||
option and its
|
||||
.B \-s
|
||||
option behaved like \s-1GNU\s0
|
||||
.BR grep 's
|
||||
.B \-q
|
||||
option.
|
||||
Shell scripts intended to be portable to traditional
|
||||
.B grep
|
||||
should avoid both
|
||||
.B \-q
|
||||
and
|
||||
.B \-s
|
||||
and should redirect output to /dev/null instead.
|
||||
.TP
|
||||
.BR \-U ", " \-\^\-binary
|
||||
Treat the file(s) as binary. By default, under MS-DOS and MS-Windows,
|
||||
.BR grep
|
||||
guesses the file type by looking at the contents of the first 32KB
|
||||
read from the file. If
|
||||
.BR grep
|
||||
decides the file is a text file, it strips the CR characters from the
|
||||
original file contents (to make regular expressions with
|
||||
.B ^
|
||||
and
|
||||
.B $
|
||||
work correctly). Specifying
|
||||
.B \-U
|
||||
overrules this guesswork, causing all files to be read and passed to the
|
||||
matching mechanism verbatim; if the file is a text file with CR/LF
|
||||
pairs at the end of each line, this will cause some regular
|
||||
expressions to fail.
|
||||
This option has no effect on platforms other than MS-DOS and
|
||||
MS-Windows.
|
||||
.TP
|
||||
.BR \-u ", " \-\^\-unix-byte-offsets
|
||||
Report Unix-style byte offsets. This switch causes
|
||||
.B grep
|
||||
to report byte offsets as if the file were Unix-style text file, i.e. with
|
||||
CR characters stripped off. This will produce results identical to running
|
||||
.B grep
|
||||
on a Unix machine. This option has no effect unless
|
||||
.B \-b
|
||||
option is also used;
|
||||
it has no effect on platforms other than MS-DOS and MS-Windows.
|
||||
.TP
|
||||
.BR \-V ", " \-\^\-version
|
||||
Print the version number of
|
||||
.B grep
|
||||
to standard error. This version number should
|
||||
be included in all bug reports (see below).
|
||||
.TP
|
||||
.BR \-v ", " \-\^\-invert-match
|
||||
Invert the sense of matching, to select non-matching lines.
|
||||
.TP
|
||||
.BR \-w ", " \-\^\-word-regexp
|
||||
Select only those lines containing matches that form whole words.
|
||||
The test is that the matching substring must either be at the
|
||||
beginning of the line, or preceded by a non-word constituent
|
||||
character. Similarly, it must be either at the end of the line
|
||||
or followed by a non-word constituent character. Word-constituent
|
||||
characters are letters, digits, and the underscore.
|
||||
.TP
|
||||
.BR \-x ", " \-\^\-line-regexp
|
||||
Select only those matches that exactly match the whole line.
|
||||
.TP
|
||||
.B \-y
|
||||
Obsolete synonym for
|
||||
.BR \-i .
|
||||
.TP
|
||||
.B \-\^\-null
|
||||
Output a zero byte (the \s-1ASCII\s0
|
||||
.B NUL
|
||||
character) instead of the character that normally follows a file name.
|
||||
For example,
|
||||
.B "grep \-l \-\^\-null"
|
||||
outputs a zero byte after each file name instead of the usual newline.
|
||||
This option makes the output unambiguous, even in the presence of file
|
||||
names containing unusual characters like newlines. This option can be
|
||||
used with commands like
|
||||
.BR "find \-print0" ,
|
||||
.BR "perl \-0" ,
|
||||
.BR "sort \-z" ,
|
||||
and
|
||||
.B "xargs \-0"
|
||||
to process arbitrary file names,
|
||||
even those that contain newline characters.
|
||||
.TP
|
||||
.BR \-Z ", " \-\^\-decompress
|
||||
Decompress the input data before searching.
|
||||
This option is only available if compiled with
|
||||
.BR zlib (3)
|
||||
library.
|
||||
.TP
|
||||
.BR \-J ", " \-\^\-bz2decompress
|
||||
Decompress the
|
||||
.BR bzip2 (1)
|
||||
compressed input data before searching.
|
||||
.SH "REGULAR EXPRESSIONS"
|
||||
A regular expression is a pattern that describes a set of strings.
|
||||
Regular expressions are constructed analogously to arithmetic
|
||||
expressions, by using various operators to combine smaller expressions.
|
||||
.PP
|
||||
.B grep
|
||||
understands two different versions of regular expression syntax:
|
||||
\*(lqbasic\*(rq and \*(lqextended.\*(rq In
|
||||
.RB "\s-1GNU\s0\ " grep ,
|
||||
there is no difference in available functionality using either syntax.
|
||||
In other implementations, basic regular expressions are less powerful.
|
||||
The following description applies to extended regular expressions;
|
||||
differences for basic regular expressions are summarized afterwards.
|
||||
.PP
|
||||
The fundamental building blocks are the regular expressions that match
|
||||
a single character. Most characters, including all letters and digits,
|
||||
are regular expressions that match themselves. Any metacharacter with
|
||||
special meaning may be quoted by preceding it with a backslash.
|
||||
.PP
|
||||
A
|
||||
.I "bracket expression"
|
||||
is a list of characters enclosed by
|
||||
.B [
|
||||
and
|
||||
.BR ] .
|
||||
It matches any single
|
||||
character in that list; if the first character of the list
|
||||
is the caret
|
||||
.B ^
|
||||
then it matches any character
|
||||
.I not
|
||||
in the list.
|
||||
For example, the regular expression
|
||||
.B [0123456789]
|
||||
matches any single digit.
|
||||
.PP
|
||||
Within a bracket expression, a
|
||||
.I "range expression"
|
||||
consists of two characters separated by a hyphen.
|
||||
It matches any single character that sorts between the two characters,
|
||||
inclusive, using the locale's collating sequence and character set.
|
||||
For example, in the default C locale,
|
||||
.B [a\-d]
|
||||
is equivalent to
|
||||
.BR [abcd] .
|
||||
Many locales sort characters in dictionary order, and in these locales
|
||||
.B [a\-d]
|
||||
is typically not equivalent to
|
||||
.BR [abcd] ;
|
||||
it might be equivalent to
|
||||
.BR [aBbCcDd] ,
|
||||
for example.
|
||||
To obtain the traditional interpretation of bracket expressions,
|
||||
you can use the C locale by setting the
|
||||
.B LC_ALL
|
||||
environment variable to the value
|
||||
.BR C .
|
||||
.PP
|
||||
Finally, certain named classes of characters are predefined within
|
||||
bracket expressions, as follows.
|
||||
Their names are self explanatory, and they are
|
||||
.BR [:alnum:] ,
|
||||
.BR [:alpha:] ,
|
||||
.BR [:blank:] ,
|
||||
.BR [:cntrl:] ,
|
||||
.BR [:digit:] ,
|
||||
.BR [:graph:] ,
|
||||
.BR [:lower:] ,
|
||||
.BR [:print:] ,
|
||||
.BR [:punct:] ,
|
||||
.BR [:space:] ,
|
||||
.BR [:upper:] ,
|
||||
and
|
||||
.BR [:xdigit:].
|
||||
For example,
|
||||
.B [[:alnum:]]
|
||||
means
|
||||
.BR [0\-9A\-Za\-z] ,
|
||||
except the latter form depends upon the C locale and the
|
||||
\s-1ASCII\s0 character encoding, whereas the former is independent
|
||||
of locale and character set.
|
||||
(Note that the brackets in these class names are part of the symbolic
|
||||
names, and must be included in addition to the brackets delimiting
|
||||
the bracket list.) Most metacharacters lose their special meaning
|
||||
inside lists. To include a literal
|
||||
.B ]
|
||||
place it first in the list. Similarly, to include a literal
|
||||
.B ^
|
||||
place it anywhere but first. Finally, to include a literal
|
||||
.B \-
|
||||
place it last.
|
||||
.PP
|
||||
The period
|
||||
.B .
|
||||
matches any single character.
|
||||
The symbol
|
||||
.B \ew
|
||||
is a synonym for
|
||||
.B [[:alnum:]]
|
||||
and
|
||||
.B \eW
|
||||
is a synonym for
|
||||
.BR [^[:alnum:]] .
|
||||
.PP
|
||||
The caret
|
||||
.B ^
|
||||
and the dollar sign
|
||||
.B $
|
||||
are metacharacters that respectively match the empty string at the
|
||||
beginning and end of a line.
|
||||
The symbols
|
||||
.B \e<
|
||||
and
|
||||
.B \e>
|
||||
respectively match the empty string at the beginning and end of a word.
|
||||
The symbol
|
||||
.B \eb
|
||||
matches the empty string at the edge of a word,
|
||||
and
|
||||
.B \eB
|
||||
matches the empty string provided it's
|
||||
.I not
|
||||
at the edge of a word.
|
||||
.PP
|
||||
A regular expression may be followed by one of several repetition operators:
|
||||
.PD 0
|
||||
.TP
|
||||
.B ?
|
||||
The preceding item is optional and matched at most once.
|
||||
.TP
|
||||
.B *
|
||||
The preceding item will be matched zero or more times.
|
||||
.TP
|
||||
.B +
|
||||
The preceding item will be matched one or more times.
|
||||
.TP
|
||||
.BI { n }
|
||||
The preceding item is matched exactly
|
||||
.I n
|
||||
times.
|
||||
.TP
|
||||
.BI { n ,}
|
||||
The preceding item is matched
|
||||
.I n
|
||||
or more times.
|
||||
.TP
|
||||
.BI { n , m }
|
||||
The preceding item is matched at least
|
||||
.I n
|
||||
times, but not more than
|
||||
.I m
|
||||
times.
|
||||
.PD
|
||||
.PP
|
||||
Two regular expressions may be concatenated; the resulting
|
||||
regular expression matches any string formed by concatenating
|
||||
two substrings that respectively match the concatenated
|
||||
subexpressions.
|
||||
.PP
|
||||
Two regular expressions may be joined by the infix operator
|
||||
.BR | ;
|
||||
the resulting regular expression matches any string matching
|
||||
either subexpression.
|
||||
.PP
|
||||
Repetition takes precedence over concatenation, which in turn
|
||||
takes precedence over alternation. A whole subexpression may be
|
||||
enclosed in parentheses to override these precedence rules.
|
||||
.PP
|
||||
The backreference
|
||||
.BI \e n\c
|
||||
\&, where
|
||||
.I n
|
||||
is a single digit, matches the substring
|
||||
previously matched by the
|
||||
.IR n th
|
||||
parenthesized subexpression of the regular expression.
|
||||
.PP
|
||||
In basic regular expressions the metacharacters
|
||||
.BR ? ,
|
||||
.BR + ,
|
||||
.BR { ,
|
||||
.BR | ,
|
||||
.BR ( ,
|
||||
and
|
||||
.BR )
|
||||
lose their special meaning; instead use the backslashed
|
||||
versions
|
||||
.BR \e? ,
|
||||
.BR \e+ ,
|
||||
.BR \e{ ,
|
||||
.BR \e| ,
|
||||
.BR \e( ,
|
||||
and
|
||||
.BR \e) .
|
||||
.PP
|
||||
Traditional
|
||||
.B egrep
|
||||
did not support the
|
||||
.B {
|
||||
metacharacter, and some
|
||||
.B egrep
|
||||
implementations support
|
||||
.B \e{
|
||||
instead, so portable scripts should avoid
|
||||
.B {
|
||||
in
|
||||
.B egrep
|
||||
patterns and should use
|
||||
.B [{]
|
||||
to match a literal
|
||||
.BR { .
|
||||
.PP
|
||||
\s-1GNU\s0
|
||||
.B egrep
|
||||
attempts to support traditional usage by assuming that
|
||||
.B {
|
||||
is not special if it would be the start of an invalid interval
|
||||
specification. For example, the shell command
|
||||
.B "egrep '{1'"
|
||||
searches for the two-character string
|
||||
.B {1
|
||||
instead of reporting a syntax error in the regular expression.
|
||||
\s-1POSIX.2\s0 allows this behavior as an extension, but portable scripts
|
||||
should avoid it.
|
||||
.SH "ENVIRONMENT VARIABLES"
|
||||
Grep's behavior is affected by the following environment variables.
|
||||
.PP
|
||||
A locale
|
||||
.BI LC_ foo
|
||||
is specified by examining the three environment variables
|
||||
.BR LC_ALL ,
|
||||
.BR LC_\fIfoo\fP ,
|
||||
.BR LANG ,
|
||||
in that order.
|
||||
The first of these variables that is set specifies the locale.
|
||||
For example, if
|
||||
.B LC_ALL
|
||||
is not set, but
|
||||
.B LC_MESSAGES
|
||||
is set to
|
||||
.BR pt_BR ,
|
||||
then Brazilian Portuguese is used for the
|
||||
.B LC_MESSAGES
|
||||
locale.
|
||||
The C locale is used if none of these environment variables are set,
|
||||
or if the locale catalog is not installed, or if
|
||||
.B grep
|
||||
was not compiled with national language support (\s-1NLS\s0).
|
||||
.TP
|
||||
.B GREP_OPTIONS
|
||||
This variable specifies default options to be placed in front of any
|
||||
explicit options. For example, if
|
||||
.B GREP_OPTIONS
|
||||
is
|
||||
.BR "'\-\^\-binary-files=without-match \-\^\-directories=skip'" ,
|
||||
.B grep
|
||||
behaves as if the two options
|
||||
.B \-\^\-binary-files=without-match
|
||||
and
|
||||
.B \-\^\-directories=skip
|
||||
had been specified before any explicit options.
|
||||
Option specifications are separated by whitespace.
|
||||
A backslash escapes the next character,
|
||||
so it can be used to specify an option containing whitespace or a backslash.
|
||||
.TP
|
||||
.B GREP_COLOR
|
||||
Specifies the marker for highlighting.
|
||||
.TP
|
||||
\fBLC_ALL\fP, \fBLC_COLLATE\fP, \fBLANG\fP
|
||||
These variables specify the
|
||||
.B LC_COLLATE
|
||||
locale, which determines the collating sequence used to interpret
|
||||
range expressions like
|
||||
.BR [a\-z] .
|
||||
.TP
|
||||
\fBLC_ALL\fP, \fBLC_CTYPE\fP, \fBLANG\fP
|
||||
These variables specify the
|
||||
.B LC_CTYPE
|
||||
locale, which determines the type of characters, e.g., which
|
||||
characters are whitespace.
|
||||
.TP
|
||||
\fBLC_ALL\fP, \fBLC_MESSAGES\fP, \fBLANG\fP
|
||||
These variables specify the
|
||||
.B LC_MESSAGES
|
||||
locale, which determines the language that
|
||||
.B grep
|
||||
uses for messages.
|
||||
The default C locale uses American English messages.
|
||||
.TP
|
||||
.B POSIXLY_CORRECT
|
||||
If set,
|
||||
.B grep
|
||||
behaves as \s-1POSIX.2\s0 requires; otherwise,
|
||||
.B grep
|
||||
behaves more like other \s-1GNU\s0 programs.
|
||||
\s-1POSIX.2\s0 requires that options that follow file names must be
|
||||
treated as file names; by default, such options are permuted to the
|
||||
front of the operand list and are treated as options.
|
||||
Also, \s-1POSIX.2\s0 requires that unrecognized options be diagnosed as
|
||||
\*(lqillegal\*(rq, but since they are not really against the law the default
|
||||
is to diagnose them as \*(lqinvalid\*(rq.
|
||||
.SH DIAGNOSTICS
|
||||
.PP
|
||||
Normally, exit status is 0 if selected lines are found and 1 otherwise.
|
||||
But the exit status is 2 if an error occurred, unless the
|
||||
.B \-q
|
||||
or
|
||||
.B \-\^\-quiet
|
||||
or
|
||||
.B \-\^\-silent
|
||||
option is used and a selected line is found.
|
||||
.SH BUGS
|
||||
Email bug reports to
|
||||
.BR bug-gnu-utils@gnu.org .
|
||||
Be sure to include the word \*(lqgrep\*(rq somewhere in the
|
||||
\*(lqSubject:\*(rq field.
|
||||
.PP
|
||||
Large repetition counts in the
|
||||
.BI { n , m }
|
||||
construct may cause grep to use lots of memory.
|
||||
In addition,
|
||||
certain other obscure regular expressions require exponential time
|
||||
and space, and may cause
|
||||
.B grep
|
||||
to run out of memory.
|
||||
.PP
|
||||
Backreferences are very slow, and may require exponential time.
|
||||
.\" Work around problems with some troff -man implementations.
|
||||
.br
|
File diff suppressed because it is too large
Load Diff
@ -1,44 +0,0 @@
|
||||
/* grep.h - interface to grep driver for searching subroutines.
|
||||
Copyright (C) 1992, 1998, 2001 Free Software Foundation, Inc.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
||||
02111-1307, USA. */
|
||||
|
||||
/* $FreeBSD$ */
|
||||
|
||||
#if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 6) || __STRICT_ANSI__
|
||||
# define __attribute__(x)
|
||||
#endif
|
||||
|
||||
/* Grep.c expects the matchers vector to be terminated
|
||||
by an entry with a NULL compile, and to contain at least
|
||||
an entry named "default". */
|
||||
|
||||
extern struct matcher
|
||||
{
|
||||
char name[8];
|
||||
void (*compile) PARAMS ((char const *, size_t));
|
||||
size_t (*execute) PARAMS ((char const *, size_t, size_t *, int));
|
||||
} const matchers[];
|
||||
|
||||
/* Exported from fgrepmat.c, egrepmat.c, grepmat.c. */
|
||||
extern char const *matcher;
|
||||
|
||||
/* The following flags are exported from grep for the matchers
|
||||
to look at. */
|
||||
extern int match_icase; /* -i */
|
||||
extern int match_words; /* -w */
|
||||
extern int match_lines; /* -x */
|
||||
extern unsigned char eolbyte; /* -z */
|
@ -1,6 +0,0 @@
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
#include "system.h"
|
||||
#include "grep.h"
|
||||
char const *matcher;
|
@ -1,87 +0,0 @@
|
||||
/* hard-locale.c -- Determine whether a locale is hard.
|
||||
Copyright 1997, 1998, 1999 Free Software Foundation, Inc.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software Foundation,
|
||||
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
||||
|
||||
/* $FreeBSD$ */
|
||||
|
||||
#if HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#ifndef __GNUC__
|
||||
# ifdef HAVE_ALLOCA_H
|
||||
# include <alloca.h>
|
||||
# else
|
||||
# ifdef _AIX
|
||||
# pragma alloca
|
||||
# else
|
||||
# ifdef _WIN32
|
||||
# include <malloc.h>
|
||||
# include <io.h>
|
||||
# else
|
||||
# ifndef alloca
|
||||
char *alloca ();
|
||||
# endif
|
||||
# endif
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if HAVE_LOCALE_H
|
||||
# include <locale.h>
|
||||
#endif
|
||||
|
||||
#if HAVE_STRING_H
|
||||
# include <string.h>
|
||||
#endif
|
||||
|
||||
/* Return nonzero if the current CATEGORY locale is hard, i.e. if you
|
||||
can't get away with assuming traditional C or POSIX behavior. */
|
||||
int
|
||||
hard_locale (int category)
|
||||
{
|
||||
#if ! HAVE_SETLOCALE
|
||||
return 0;
|
||||
#else
|
||||
|
||||
int hard = 1;
|
||||
char const *p = setlocale (category, 0);
|
||||
|
||||
if (p)
|
||||
{
|
||||
# if defined(__FreeBSD__) || (defined __GLIBC__ && __GLIBC__ >= 2)
|
||||
if (strcmp (p, "C") == 0 || strcmp (p, "POSIX") == 0)
|
||||
hard = 0;
|
||||
# else
|
||||
char *locale = alloca (strlen (p) + 1);
|
||||
strcpy (locale, p);
|
||||
|
||||
/* Temporarily set the locale to the "C" and "POSIX" locales to
|
||||
find their names, so that we can determine whether one or the
|
||||
other is the caller's locale. */
|
||||
if (((p = setlocale (category, "C")) && strcmp (p, locale) == 0)
|
||||
|| ((p = setlocale (category, "POSIX")) && strcmp (p, locale) == 0))
|
||||
hard = 0;
|
||||
|
||||
/* Restore the caller's locale. */
|
||||
setlocale (category, locale);
|
||||
# endif
|
||||
}
|
||||
|
||||
return hard;
|
||||
|
||||
#endif
|
||||
}
|
@ -1,18 +0,0 @@
|
||||
#ifndef HARD_LOCALE_H_
|
||||
# define HARD_LOCALE_H_ 1
|
||||
|
||||
# if HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
# endif
|
||||
|
||||
# ifndef PARAMS
|
||||
# if defined PROTOTYPES || (defined __STDC__ && __STDC__)
|
||||
# define PARAMS(Args) Args
|
||||
# else
|
||||
# define PARAMS(Args) ()
|
||||
# endif
|
||||
# endif
|
||||
|
||||
int hard_locale PARAMS ((int));
|
||||
|
||||
#endif /* HARD_LOCALE_H_ */
|
@ -1,42 +0,0 @@
|
||||
/* isdir.c -- determine whether a directory exists
|
||||
Copyright (C) 1990, 1998 Free Software Foundation, Inc.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software Foundation,
|
||||
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
||||
|
||||
#if HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#if STAT_MACROS_BROKEN
|
||||
# undef S_ISDIR
|
||||
#endif
|
||||
|
||||
#if !defined S_ISDIR && defined S_IFDIR
|
||||
# define S_ISDIR(Mode) (((Mode) & S_IFMT) == S_IFDIR)
|
||||
#endif
|
||||
|
||||
/* If PATH is an existing directory or symbolic link to a directory,
|
||||
return nonzero, else 0. */
|
||||
|
||||
int
|
||||
isdir (const char *path)
|
||||
{
|
||||
struct stat stats;
|
||||
|
||||
return stat (path, &stats) == 0 && S_ISDIR (stats.st_mode);
|
||||
}
|
@ -1,773 +0,0 @@
|
||||
/* kwset.c - search for any of a set of keywords.
|
||||
Copyright 1989, 1998, 2000 Free Software Foundation, Inc.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
||||
02111-1307, USA. */
|
||||
|
||||
/* $FreeBSD$ */
|
||||
|
||||
/* Written August 1989 by Mike Haertel.
|
||||
The author may be reached (Email) at the address mike@ai.mit.edu,
|
||||
or (US mail) as Mike Haertel c/o Free Software Foundation. */
|
||||
|
||||
/* 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,
|
||||
IBM-Germany, Scientific Center Heidelberg, Tiergartenstrasse 15, D-6900
|
||||
Heidelberg, Germany. See also Aho, A.V., and M. Corasick, "Efficient
|
||||
String Matching: An Aid to Bibliographic Search," CACM June 1975,
|
||||
Vol. 18, No. 6, which describes the failure function used below. */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
#include <sys/types.h>
|
||||
#include "system.h"
|
||||
#include "kwset.h"
|
||||
#include "obstack.h"
|
||||
|
||||
#ifdef GREP
|
||||
extern char *xmalloc();
|
||||
# undef malloc
|
||||
# define malloc xmalloc
|
||||
#endif
|
||||
|
||||
#define NCHAR (UCHAR_MAX + 1)
|
||||
#define obstack_chunk_alloc malloc
|
||||
#define obstack_chunk_free free
|
||||
|
||||
/* Balanced tree of edges and labels leaving a given trie node. */
|
||||
struct tree
|
||||
{
|
||||
struct tree *llink; /* Left link; MUST be first field. */
|
||||
struct tree *rlink; /* Right link (to larger labels). */
|
||||
struct trie *trie; /* Trie node pointed to by this edge. */
|
||||
unsigned char label; /* Label on this edge. */
|
||||
char balance; /* Difference in depths of subtrees. */
|
||||
};
|
||||
|
||||
/* Node of a trie representing a set of reversed keywords. */
|
||||
struct trie
|
||||
{
|
||||
unsigned int accepting; /* Word index of accepted word, or zero. */
|
||||
struct tree *links; /* Tree of edges leaving this node. */
|
||||
struct trie *parent; /* Parent of this node. */
|
||||
struct trie *next; /* List of all trie nodes in level order. */
|
||||
struct trie *fail; /* Aho-Corasick failure function. */
|
||||
int depth; /* Depth of this node from the root. */
|
||||
int shift; /* Shift function for search failures. */
|
||||
int maxshift; /* Max shift of self and descendents. */
|
||||
};
|
||||
|
||||
/* Structure returned opaquely to the caller, containing everything. */
|
||||
struct kwset
|
||||
{
|
||||
struct obstack obstack; /* Obstack for node allocation. */
|
||||
int words; /* Number of words in the trie. */
|
||||
struct trie *trie; /* The trie itself. */
|
||||
int mind; /* Minimum depth of an accepting node. */
|
||||
int maxd; /* Maximum depth of any node. */
|
||||
unsigned char delta[NCHAR]; /* Delta table for rapid search. */
|
||||
struct trie *next[NCHAR]; /* Table of children of the root. */
|
||||
char *target; /* Target string if there's only one. */
|
||||
int mind2; /* Used in Boyer-Moore search for one string. */
|
||||
char const *trans; /* Character translation table. */
|
||||
};
|
||||
|
||||
/* Allocate and initialize a keyword set object, returning an opaque
|
||||
pointer to it. Return NULL if memory is not available. */
|
||||
kwset_t
|
||||
kwsalloc (char const *trans)
|
||||
{
|
||||
struct kwset *kwset;
|
||||
|
||||
kwset = (struct kwset *) malloc(sizeof (struct kwset));
|
||||
if (!kwset)
|
||||
return 0;
|
||||
|
||||
obstack_init(&kwset->obstack);
|
||||
kwset->words = 0;
|
||||
kwset->trie
|
||||
= (struct trie *) obstack_alloc(&kwset->obstack, sizeof (struct trie));
|
||||
if (!kwset->trie)
|
||||
{
|
||||
kwsfree((kwset_t) kwset);
|
||||
return 0;
|
||||
}
|
||||
kwset->trie->accepting = 0;
|
||||
kwset->trie->links = 0;
|
||||
kwset->trie->parent = 0;
|
||||
kwset->trie->next = 0;
|
||||
kwset->trie->fail = 0;
|
||||
kwset->trie->depth = 0;
|
||||
kwset->trie->shift = 0;
|
||||
kwset->mind = INT_MAX;
|
||||
kwset->maxd = -1;
|
||||
kwset->target = 0;
|
||||
kwset->trans = trans;
|
||||
|
||||
return (kwset_t) kwset;
|
||||
}
|
||||
|
||||
/* Add the given string to the contents of the keyword set. Return NULL
|
||||
for success, an error message otherwise. */
|
||||
char *
|
||||
kwsincr (kwset_t kws, char const *text, size_t len)
|
||||
{
|
||||
struct kwset *kwset;
|
||||
register struct trie *trie;
|
||||
register unsigned char label;
|
||||
register struct tree *link;
|
||||
register int depth;
|
||||
struct tree *links[12];
|
||||
enum { L, R } dirs[12];
|
||||
struct tree *t, *r, *l, *rl, *lr;
|
||||
|
||||
kwset = (struct kwset *) kws;
|
||||
trie = kwset->trie;
|
||||
text += len;
|
||||
|
||||
/* Descend the trie (built of reversed keywords) character-by-character,
|
||||
installing new nodes when necessary. */
|
||||
while (len--)
|
||||
{
|
||||
label = kwset->trans ? kwset->trans[(unsigned char) *--text] : *--text;
|
||||
|
||||
/* Descend the tree of outgoing links for this trie node,
|
||||
looking for the current character and keeping track
|
||||
of the path followed. */
|
||||
link = trie->links;
|
||||
links[0] = (struct tree *) &trie->links;
|
||||
dirs[0] = L;
|
||||
depth = 1;
|
||||
|
||||
while (link && label != link->label)
|
||||
{
|
||||
links[depth] = link;
|
||||
if (label < link->label)
|
||||
dirs[depth++] = L, link = link->llink;
|
||||
else
|
||||
dirs[depth++] = R, link = link->rlink;
|
||||
}
|
||||
|
||||
/* The current character doesn't have an outgoing link at
|
||||
this trie node, so build a new trie node and install
|
||||
a link in the current trie node's tree. */
|
||||
if (!link)
|
||||
{
|
||||
link = (struct tree *) obstack_alloc(&kwset->obstack,
|
||||
sizeof (struct tree));
|
||||
if (!link)
|
||||
return _("memory exhausted");
|
||||
link->llink = 0;
|
||||
link->rlink = 0;
|
||||
link->trie = (struct trie *) obstack_alloc(&kwset->obstack,
|
||||
sizeof (struct trie));
|
||||
if (!link->trie)
|
||||
return _("memory exhausted");
|
||||
link->trie->accepting = 0;
|
||||
link->trie->links = 0;
|
||||
link->trie->parent = trie;
|
||||
link->trie->next = 0;
|
||||
link->trie->fail = 0;
|
||||
link->trie->depth = trie->depth + 1;
|
||||
link->trie->shift = 0;
|
||||
link->label = label;
|
||||
link->balance = 0;
|
||||
|
||||
/* Install the new tree node in its parent. */
|
||||
if (dirs[--depth] == L)
|
||||
links[depth]->llink = link;
|
||||
else
|
||||
links[depth]->rlink = link;
|
||||
|
||||
/* Back up the tree fixing the balance flags. */
|
||||
while (depth && !links[depth]->balance)
|
||||
{
|
||||
if (dirs[depth] == L)
|
||||
--links[depth]->balance;
|
||||
else
|
||||
++links[depth]->balance;
|
||||
--depth;
|
||||
}
|
||||
|
||||
/* Rebalance the tree by pointer rotations if necessary. */
|
||||
if (depth && ((dirs[depth] == L && --links[depth]->balance)
|
||||
|| (dirs[depth] == R && ++links[depth]->balance)))
|
||||
{
|
||||
switch (links[depth]->balance)
|
||||
{
|
||||
case (char) -2:
|
||||
switch (dirs[depth + 1])
|
||||
{
|
||||
case L:
|
||||
r = links[depth], t = r->llink, rl = t->rlink;
|
||||
t->rlink = r, r->llink = rl;
|
||||
t->balance = r->balance = 0;
|
||||
break;
|
||||
case R:
|
||||
r = links[depth], l = r->llink, t = l->rlink;
|
||||
rl = t->rlink, lr = t->llink;
|
||||
t->llink = l, l->rlink = lr, t->rlink = r, r->llink = rl;
|
||||
l->balance = t->balance != 1 ? 0 : -1;
|
||||
r->balance = t->balance != (char) -1 ? 0 : 1;
|
||||
t->balance = 0;
|
||||
break;
|
||||
default:
|
||||
abort ();
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
switch (dirs[depth + 1])
|
||||
{
|
||||
case R:
|
||||
l = links[depth], t = l->rlink, lr = t->llink;
|
||||
t->llink = l, l->rlink = lr;
|
||||
t->balance = l->balance = 0;
|
||||
break;
|
||||
case L:
|
||||
l = links[depth], r = l->rlink, t = r->llink;
|
||||
lr = t->llink, rl = t->rlink;
|
||||
t->llink = l, l->rlink = lr, t->rlink = r, r->llink = rl;
|
||||
l->balance = t->balance != 1 ? 0 : -1;
|
||||
r->balance = t->balance != (char) -1 ? 0 : 1;
|
||||
t->balance = 0;
|
||||
break;
|
||||
default:
|
||||
abort ();
|
||||
}
|
||||
break;
|
||||
default:
|
||||
abort ();
|
||||
}
|
||||
|
||||
if (dirs[depth - 1] == L)
|
||||
links[depth - 1]->llink = t;
|
||||
else
|
||||
links[depth - 1]->rlink = t;
|
||||
}
|
||||
}
|
||||
|
||||
trie = link->trie;
|
||||
}
|
||||
|
||||
/* Mark the node we finally reached as accepting, encoding the
|
||||
index number of this word in the keyword set so far. */
|
||||
if (!trie->accepting)
|
||||
trie->accepting = 1 + 2 * kwset->words;
|
||||
++kwset->words;
|
||||
|
||||
/* Keep track of the longest and shortest string of the keyword set. */
|
||||
if (trie->depth < kwset->mind)
|
||||
kwset->mind = trie->depth;
|
||||
if (trie->depth > kwset->maxd)
|
||||
kwset->maxd = trie->depth;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Enqueue the trie nodes referenced from the given tree in the
|
||||
given queue. */
|
||||
static void
|
||||
enqueue (struct tree *tree, struct trie **last)
|
||||
{
|
||||
if (!tree)
|
||||
return;
|
||||
enqueue(tree->llink, last);
|
||||
enqueue(tree->rlink, last);
|
||||
(*last) = (*last)->next = tree->trie;
|
||||
}
|
||||
|
||||
/* Compute the Aho-Corasick failure function for the trie nodes referenced
|
||||
from the given tree, given the failure function for their parent as
|
||||
well as a last resort failure node. */
|
||||
static void
|
||||
treefails (register struct tree const *tree, struct trie const *fail,
|
||||
struct trie *recourse)
|
||||
{
|
||||
register struct tree *link;
|
||||
|
||||
if (!tree)
|
||||
return;
|
||||
|
||||
treefails(tree->llink, fail, recourse);
|
||||
treefails(tree->rlink, fail, recourse);
|
||||
|
||||
/* Find, in the chain of fails going back to the root, the first
|
||||
node that has a descendent on the current label. */
|
||||
while (fail)
|
||||
{
|
||||
link = fail->links;
|
||||
while (link && tree->label != link->label)
|
||||
if (tree->label < link->label)
|
||||
link = link->llink;
|
||||
else
|
||||
link = link->rlink;
|
||||
if (link)
|
||||
{
|
||||
tree->trie->fail = link->trie;
|
||||
return;
|
||||
}
|
||||
fail = fail->fail;
|
||||
}
|
||||
|
||||
tree->trie->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 (register struct tree const *tree,
|
||||
register unsigned int depth,
|
||||
unsigned char delta[])
|
||||
{
|
||||
if (!tree)
|
||||
return;
|
||||
treedelta(tree->llink, depth, delta);
|
||||
treedelta(tree->rlink, depth, delta);
|
||||
if (depth < delta[tree->label])
|
||||
delta[tree->label] = depth;
|
||||
}
|
||||
|
||||
/* Return true if A has every label in B. */
|
||||
static int
|
||||
hasevery (register struct tree const *a, register struct tree const *b)
|
||||
{
|
||||
if (!b)
|
||||
return 1;
|
||||
if (!hasevery(a, b->llink))
|
||||
return 0;
|
||||
if (!hasevery(a, b->rlink))
|
||||
return 0;
|
||||
while (a && b->label != a->label)
|
||||
if (b->label < a->label)
|
||||
a = a->llink;
|
||||
else
|
||||
a = a->rlink;
|
||||
return !!a;
|
||||
}
|
||||
|
||||
/* Compute a vector, indexed by character code, of the trie nodes
|
||||
referenced from the given tree. */
|
||||
static void
|
||||
treenext (struct tree const *tree, struct trie *next[])
|
||||
{
|
||||
if (!tree)
|
||||
return;
|
||||
treenext(tree->llink, next);
|
||||
treenext(tree->rlink, next);
|
||||
next[tree->label] = tree->trie;
|
||||
}
|
||||
|
||||
/* Compute the shift for each trie node, as well as the delta
|
||||
table and next cache for the given keyword set. */
|
||||
char *
|
||||
kwsprep (kwset_t kws)
|
||||
{
|
||||
register struct kwset *kwset;
|
||||
register int i;
|
||||
register struct trie *curr, *fail;
|
||||
register char const *trans;
|
||||
unsigned char delta[NCHAR];
|
||||
struct trie *last, *next[NCHAR];
|
||||
|
||||
kwset = (struct kwset *) kws;
|
||||
|
||||
/* Initial values for the delta table; will be changed later. The
|
||||
delta entry for a given character is the smallest depth of any
|
||||
node at which an outgoing edge is labeled by that character. */
|
||||
if (kwset->mind < 256)
|
||||
for (i = 0; i < NCHAR; ++i)
|
||||
delta[i] = kwset->mind;
|
||||
else
|
||||
for (i = 0; i < NCHAR; ++i)
|
||||
delta[i] = 255;
|
||||
|
||||
/* Check if we can use the simple boyer-moore algorithm, instead
|
||||
of the hairy commentz-walter algorithm. */
|
||||
if (kwset->words == 1 && kwset->trans == 0)
|
||||
{
|
||||
/* Looking for just one string. Extract it from the trie. */
|
||||
kwset->target = obstack_alloc(&kwset->obstack, kwset->mind);
|
||||
for (i = kwset->mind - 1, curr = kwset->trie; i >= 0; --i)
|
||||
{
|
||||
kwset->target[i] = curr->links->label;
|
||||
curr = curr->links->trie;
|
||||
}
|
||||
/* Build the Boyer Moore delta. Boy that's easy compared to CW. */
|
||||
for (i = 0; i < kwset->mind; ++i)
|
||||
delta[(unsigned char) kwset->target[i]] = kwset->mind - (i + 1);
|
||||
kwset->mind2 = kwset->mind;
|
||||
/* Find the minimal delta2 shift that we might make after
|
||||
a backwards match has failed. */
|
||||
for (i = 0; i < kwset->mind - 1; ++i)
|
||||
if (kwset->target[i] == kwset->target[kwset->mind - 1])
|
||||
kwset->mind2 = kwset->mind - (i + 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Traverse the nodes of the trie in level order, simultaneously
|
||||
computing the delta table, failure function, and shift function. */
|
||||
for (curr = last = kwset->trie; curr; curr = curr->next)
|
||||
{
|
||||
/* Enqueue the immediate descendents in the level order queue. */
|
||||
enqueue(curr->links, &last);
|
||||
|
||||
curr->shift = kwset->mind;
|
||||
curr->maxshift = kwset->mind;
|
||||
|
||||
/* Update the delta table for the descendents of this node. */
|
||||
treedelta(curr->links, curr->depth, delta);
|
||||
|
||||
/* Compute the failure function for the decendents of this node. */
|
||||
treefails(curr->links, curr->fail, kwset->trie);
|
||||
|
||||
/* Update the shifts at each node in the current node's chain
|
||||
of fails back to the root. */
|
||||
for (fail = curr->fail; fail; fail = fail->fail)
|
||||
{
|
||||
/* If the current node has some outgoing edge that the fail
|
||||
doesn't, then the shift at the fail should be no larger
|
||||
than the difference of their depths. */
|
||||
if (!hasevery(fail->links, curr->links))
|
||||
if (curr->depth - fail->depth < fail->shift)
|
||||
fail->shift = curr->depth - fail->depth;
|
||||
|
||||
/* If the current node is accepting then the shift at the
|
||||
fail and its descendents should be no larger than the
|
||||
difference of their depths. */
|
||||
if (curr->accepting && fail->maxshift > curr->depth - fail->depth)
|
||||
fail->maxshift = curr->depth - fail->depth;
|
||||
}
|
||||
}
|
||||
|
||||
/* Traverse the trie in level order again, fixing up all nodes whose
|
||||
shift exceeds their inherited maxshift. */
|
||||
for (curr = kwset->trie->next; curr; curr = curr->next)
|
||||
{
|
||||
if (curr->maxshift > curr->parent->maxshift)
|
||||
curr->maxshift = curr->parent->maxshift;
|
||||
if (curr->shift > curr->maxshift)
|
||||
curr->shift = curr->maxshift;
|
||||
}
|
||||
|
||||
/* Create a vector, indexed by character code, of the outgoing links
|
||||
from the root node. */
|
||||
for (i = 0; i < NCHAR; ++i)
|
||||
next[i] = 0;
|
||||
treenext(kwset->trie->links, next);
|
||||
|
||||
if ((trans = kwset->trans) != 0)
|
||||
for (i = 0; i < NCHAR; ++i)
|
||||
kwset->next[i] = next[(unsigned char) trans[i]];
|
||||
else
|
||||
for (i = 0; i < NCHAR; ++i)
|
||||
kwset->next[i] = next[i];
|
||||
}
|
||||
|
||||
/* Fix things up for any translation table. */
|
||||
if ((trans = kwset->trans) != 0)
|
||||
for (i = 0; i < NCHAR; ++i)
|
||||
kwset->delta[i] = delta[(unsigned char) trans[i]];
|
||||
else
|
||||
for (i = 0; i < NCHAR; ++i)
|
||||
kwset->delta[i] = delta[i];
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#define U(C) ((unsigned char) (C))
|
||||
|
||||
/* Fast boyer-moore search. */
|
||||
static size_t
|
||||
bmexec (kwset_t kws, char const *text, size_t size)
|
||||
{
|
||||
struct kwset const *kwset;
|
||||
register unsigned char const *d1;
|
||||
register char const *ep, *sp, *tp;
|
||||
register int d, gc, i, len, md2;
|
||||
|
||||
kwset = (struct kwset const *) kws;
|
||||
len = kwset->mind;
|
||||
|
||||
if (len == 0)
|
||||
return 0;
|
||||
if (len > size)
|
||||
return -1;
|
||||
if (len == 1)
|
||||
{
|
||||
tp = memchr (text, kwset->target[0], size);
|
||||
return tp ? tp - text : -1;
|
||||
}
|
||||
|
||||
d1 = kwset->delta;
|
||||
sp = kwset->target + len;
|
||||
gc = U(sp[-2]);
|
||||
md2 = kwset->mind2;
|
||||
tp = text + len;
|
||||
|
||||
/* Significance of 12: 1 (initial offset) + 10 (skip loop) + 1 (md2). */
|
||||
if (size > 12 * len)
|
||||
/* 11 is not a bug, the initial offset happens only once. */
|
||||
for (ep = text + size - 11 * len;;)
|
||||
{
|
||||
while (tp <= ep)
|
||||
{
|
||||
d = d1[U(tp[-1])], tp += d;
|
||||
d = d1[U(tp[-1])], tp += d;
|
||||
if (d == 0)
|
||||
goto found;
|
||||
d = d1[U(tp[-1])], tp += d;
|
||||
d = d1[U(tp[-1])], tp += d;
|
||||
d = d1[U(tp[-1])], tp += d;
|
||||
if (d == 0)
|
||||
goto found;
|
||||
d = d1[U(tp[-1])], tp += d;
|
||||
d = d1[U(tp[-1])], tp += d;
|
||||
d = d1[U(tp[-1])], tp += d;
|
||||
if (d == 0)
|
||||
goto found;
|
||||
d = d1[U(tp[-1])], tp += d;
|
||||
d = d1[U(tp[-1])], tp += d;
|
||||
}
|
||||
break;
|
||||
found:
|
||||
if (U(tp[-2]) == gc)
|
||||
{
|
||||
for (i = 3; i <= len && U(tp[-i]) == U(sp[-i]); ++i)
|
||||
;
|
||||
if (i > len)
|
||||
return tp - len - text;
|
||||
}
|
||||
tp += md2;
|
||||
}
|
||||
|
||||
/* Now we have only a few characters left to search. We
|
||||
carefully avoid ever producing an out-of-bounds pointer. */
|
||||
ep = text + size;
|
||||
d = d1[U(tp[-1])];
|
||||
while (d <= ep - tp)
|
||||
{
|
||||
d = d1[U((tp += d)[-1])];
|
||||
if (d != 0)
|
||||
continue;
|
||||
if (U(tp[-2]) == gc)
|
||||
{
|
||||
for (i = 3; i <= len && U(tp[-i]) == U(sp[-i]); ++i)
|
||||
;
|
||||
if (i > len)
|
||||
return tp - len - text;
|
||||
}
|
||||
d = md2;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Hairy multiple string search. */
|
||||
static size_t
|
||||
cwexec (kwset_t kws, char const *text, size_t len, struct kwsmatch *kwsmatch)
|
||||
{
|
||||
struct kwset const *kwset;
|
||||
struct trie * const *next;
|
||||
struct trie const *trie;
|
||||
struct trie const *accept;
|
||||
char const *beg, *lim, *mch, *lmch;
|
||||
register unsigned char c;
|
||||
register unsigned char const *delta;
|
||||
register int d;
|
||||
register char const *end, *qlim;
|
||||
register struct tree const *tree;
|
||||
register char const *trans;
|
||||
|
||||
#ifdef lint
|
||||
accept = NULL;
|
||||
#endif
|
||||
|
||||
/* Initialize register copies and look for easy ways out. */
|
||||
kwset = (struct kwset *) kws;
|
||||
if (len < kwset->mind)
|
||||
return -1;
|
||||
next = kwset->next;
|
||||
delta = kwset->delta;
|
||||
trans = kwset->trans;
|
||||
lim = text + len;
|
||||
end = text;
|
||||
if ((d = kwset->mind) != 0)
|
||||
mch = 0;
|
||||
else
|
||||
{
|
||||
mch = text, accept = kwset->trie;
|
||||
goto match;
|
||||
}
|
||||
|
||||
if (len >= 4 * kwset->mind)
|
||||
qlim = lim - 4 * kwset->mind;
|
||||
else
|
||||
qlim = 0;
|
||||
|
||||
while (lim - end >= d)
|
||||
{
|
||||
if (qlim && end <= qlim)
|
||||
{
|
||||
end += d - 1;
|
||||
while ((d = delta[c = *end]) && end < qlim)
|
||||
{
|
||||
end += d;
|
||||
end += delta[(unsigned char) *end];
|
||||
end += delta[(unsigned char) *end];
|
||||
}
|
||||
++end;
|
||||
}
|
||||
else
|
||||
d = delta[c = (end += d)[-1]];
|
||||
if (d)
|
||||
continue;
|
||||
beg = end - 1;
|
||||
trie = next[c];
|
||||
if (trie->accepting)
|
||||
{
|
||||
mch = beg;
|
||||
accept = trie;
|
||||
}
|
||||
d = trie->shift;
|
||||
while (beg > text)
|
||||
{
|
||||
c = trans ? trans[(unsigned char) *--beg] : *--beg;
|
||||
tree = trie->links;
|
||||
while (tree && c != tree->label)
|
||||
if (c < tree->label)
|
||||
tree = tree->llink;
|
||||
else
|
||||
tree = tree->rlink;
|
||||
if (tree)
|
||||
{
|
||||
trie = tree->trie;
|
||||
if (trie->accepting)
|
||||
{
|
||||
mch = beg;
|
||||
accept = trie;
|
||||
}
|
||||
}
|
||||
else
|
||||
break;
|
||||
d = trie->shift;
|
||||
}
|
||||
if (mch)
|
||||
goto match;
|
||||
}
|
||||
return -1;
|
||||
|
||||
match:
|
||||
/* Given a known match, find the longest possible match anchored
|
||||
at or before its starting point. This is nearly a verbatim
|
||||
copy of the preceding main search loops. */
|
||||
if (lim - mch > kwset->maxd)
|
||||
lim = mch + kwset->maxd;
|
||||
lmch = 0;
|
||||
d = 1;
|
||||
while (lim - end >= d)
|
||||
{
|
||||
if ((d = delta[c = (end += d)[-1]]) != 0)
|
||||
continue;
|
||||
beg = end - 1;
|
||||
if (!(trie = next[c]))
|
||||
{
|
||||
d = 1;
|
||||
continue;
|
||||
}
|
||||
if (trie->accepting && beg <= mch)
|
||||
{
|
||||
lmch = beg;
|
||||
accept = trie;
|
||||
}
|
||||
d = trie->shift;
|
||||
while (beg > text)
|
||||
{
|
||||
c = trans ? trans[(unsigned char) *--beg] : *--beg;
|
||||
tree = trie->links;
|
||||
while (tree && c != tree->label)
|
||||
if (c < tree->label)
|
||||
tree = tree->llink;
|
||||
else
|
||||
tree = tree->rlink;
|
||||
if (tree)
|
||||
{
|
||||
trie = tree->trie;
|
||||
if (trie->accepting && beg <= mch)
|
||||
{
|
||||
lmch = beg;
|
||||
accept = trie;
|
||||
}
|
||||
}
|
||||
else
|
||||
break;
|
||||
d = trie->shift;
|
||||
}
|
||||
if (lmch)
|
||||
{
|
||||
mch = lmch;
|
||||
goto match;
|
||||
}
|
||||
if (!d)
|
||||
d = 1;
|
||||
}
|
||||
|
||||
if (kwsmatch)
|
||||
{
|
||||
kwsmatch->index = accept->accepting / 2;
|
||||
kwsmatch->offset[0] = mch - text;
|
||||
kwsmatch->size[0] = accept->depth;
|
||||
}
|
||||
return mch - text;
|
||||
}
|
||||
|
||||
/* Search through the given text for a match of any member of the
|
||||
given keyword set. Return a pointer to the first character of
|
||||
the matching substring, or NULL if no match is found. If FOUNDLEN
|
||||
is non-NULL store in the referenced location the length of the
|
||||
matching substring. Similarly, if FOUNDIDX is non-NULL, store
|
||||
in the referenced location the index number of the particular
|
||||
keyword matched. */
|
||||
size_t
|
||||
kwsexec (kwset_t kws, char const *text, size_t size,
|
||||
struct kwsmatch *kwsmatch)
|
||||
{
|
||||
struct kwset const *kwset = (struct kwset *) kws;
|
||||
if (kwset->words == 1 && kwset->trans == 0)
|
||||
{
|
||||
size_t ret = bmexec (kws, text, size);
|
||||
if (kwsmatch != 0 && ret != (size_t) -1)
|
||||
{
|
||||
kwsmatch->index = 0;
|
||||
kwsmatch->offset[0] = ret;
|
||||
kwsmatch->size[0] = kwset->mind;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
else
|
||||
return cwexec(kws, text, size, kwsmatch);
|
||||
}
|
||||
|
||||
/* Free the components of the given keyword set. */
|
||||
void
|
||||
kwsfree (kwset_t kws)
|
||||
{
|
||||
struct kwset *kwset;
|
||||
|
||||
kwset = (struct kwset *) kws;
|
||||
obstack_free(&kwset->obstack, 0);
|
||||
free(kws);
|
||||
}
|
@ -1,59 +0,0 @@
|
||||
/* kwset.h - header declaring the keyword set library.
|
||||
Copyright (C) 1989, 1998 Free Software Foundation, Inc.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
||||
02111-1307, USA. */
|
||||
|
||||
/* Written August 1989 by Mike Haertel.
|
||||
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$ */
|
||||
|
||||
struct kwsmatch
|
||||
{
|
||||
int index; /* Index number of matching keyword. */
|
||||
size_t offset[1]; /* Offset of each submatch. */
|
||||
size_t size[1]; /* Length of each submatch. */
|
||||
};
|
||||
|
||||
typedef ptr_t kwset_t;
|
||||
|
||||
/* Return an opaque pointer to a newly allocated keyword set, or NULL
|
||||
if enough memory cannot be obtained. The argument if non-NULL
|
||||
specifies a table of character translations to be applied to all
|
||||
pattern and search text. */
|
||||
extern kwset_t kwsalloc PARAMS((char const *));
|
||||
|
||||
/* Incrementally extend the keyword set to include the given string.
|
||||
Return NULL for success, or an error message. Remember an index
|
||||
number for each keyword included in the set. */
|
||||
extern char *kwsincr PARAMS((kwset_t, char const *, size_t));
|
||||
|
||||
/* When the keyword set has been completely built, prepare it for
|
||||
use. Return NULL for success, or an error message. */
|
||||
extern char *kwsprep PARAMS((kwset_t));
|
||||
|
||||
/* Search through the given buffer for a member of the keyword set.
|
||||
Return a pointer to the leftmost longest match found, or NULL if
|
||||
no match is found. If foundlen is non-NULL, store the length of
|
||||
the matching substring in the integer it points to. Similarly,
|
||||
if foundindex is non-NULL, store the index of the particular
|
||||
keyword found therein. */
|
||||
extern size_t kwsexec PARAMS((kwset_t, char const *, size_t, struct kwsmatch *));
|
||||
|
||||
/* Deallocate the given keyword set and all its associated storage. */
|
||||
extern void kwsfree PARAMS((kwset_t));
|
||||
|
@ -1,598 +0,0 @@
|
||||
/* 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.
|
||||
|
||||
The GNU C Library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public License as
|
||||
published by the Free Software Foundation; either version 2 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
The GNU C Library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with the GNU C Library; see the file COPYING.LIB. If not,
|
||||
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
Boston, MA 02111-1307, USA. */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include "obstack.h"
|
||||
|
||||
/* NOTE BEFORE MODIFYING THIS FILE: This version number must be
|
||||
incremented whenever callers compiled using an old obstack.h can no
|
||||
longer properly call the functions in this obstack.c. */
|
||||
#define OBSTACK_INTERFACE_VERSION 1
|
||||
|
||||
/* Comment out all this code if we are using the GNU C Library, and are not
|
||||
actually compiling the library itself, and the installed library
|
||||
supports the same library interface we do. This code is part of the GNU
|
||||
C Library, but also included in many other GNU distributions. Compiling
|
||||
and linking in this code is a waste when using the GNU C library
|
||||
(especially if it is a shared library). Rather than having every GNU
|
||||
program understand `configure --with-gnu-libc' and omit the object
|
||||
files, it is simpler to just do this in the source for each such file. */
|
||||
|
||||
#include <stdio.h> /* Random thing to get __GNU_LIBRARY__. */
|
||||
#if !defined (_LIBC) && defined (__GNU_LIBRARY__) && __GNU_LIBRARY__ > 1
|
||||
#include <gnu-versions.h>
|
||||
#if _GNU_OBSTACK_INTERFACE_VERSION == OBSTACK_INTERFACE_VERSION
|
||||
#define ELIDE_CODE
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef ELIDE_CODE
|
||||
|
||||
|
||||
#if defined (__STDC__) && __STDC__
|
||||
#define POINTER void *
|
||||
#else
|
||||
#define POINTER char *
|
||||
#endif
|
||||
|
||||
/* Determine default alignment. */
|
||||
struct fooalign {char x; double d;};
|
||||
#define DEFAULT_ALIGNMENT \
|
||||
((PTR_INT_TYPE) ((char *) &((struct fooalign *) 0)->d - (char *) 0))
|
||||
/* If malloc were really smart, it would round addresses to DEFAULT_ALIGNMENT.
|
||||
But in fact it might be less smart and round addresses to as much as
|
||||
DEFAULT_ROUNDING. So we prepare for it to do that. */
|
||||
union fooround {long x; double d;};
|
||||
#define DEFAULT_ROUNDING (sizeof (union fooround))
|
||||
|
||||
/* When we copy a long block of data, this is the unit to do it with.
|
||||
On some machines, copying successive ints does not work;
|
||||
in such a case, redefine COPYING_UNIT to `long' (if that works)
|
||||
or `char' as a last resort. */
|
||||
#ifndef COPYING_UNIT
|
||||
#define COPYING_UNIT int
|
||||
#endif
|
||||
|
||||
|
||||
/* The functions allocating more room by calling `obstack_chunk_alloc'
|
||||
jump to the handler pointed to by `obstack_alloc_failed_handler'.
|
||||
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);
|
||||
void (*obstack_alloc_failed_handler) (void) = print_and_abort;
|
||||
#else
|
||||
static void print_and_abort ();
|
||||
void (*obstack_alloc_failed_handler) () = print_and_abort;
|
||||
#endif
|
||||
|
||||
/* Exit value used when `print_and_abort' is used. */
|
||||
#if defined __GNU_LIBRARY__ || defined HAVE_STDLIB_H
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
#ifndef EXIT_FAILURE
|
||||
#define EXIT_FAILURE 1
|
||||
#endif
|
||||
int obstack_exit_failure = EXIT_FAILURE;
|
||||
|
||||
/* The non-GNU-C macros copy the obstack into this global variable
|
||||
to avoid multiple evaluation. */
|
||||
|
||||
struct obstack *_obstack;
|
||||
|
||||
/* Define a macro that either calls functions with the traditional malloc/free
|
||||
calling interface, or calls functions with the mmalloc/mfree interface
|
||||
(that adds an extra first argument), based on the state of use_extra_arg.
|
||||
For free, do not use ?:, since some compilers, like the MIPS compilers,
|
||||
do not allow (expr) ? void : void. */
|
||||
|
||||
#if defined (__STDC__) && __STDC__
|
||||
#define CALL_CHUNKFUN(h, size) \
|
||||
(((h) -> use_extra_arg) \
|
||||
? (*(h)->chunkfun) ((h)->extra_arg, (size)) \
|
||||
: (*(struct _obstack_chunk *(*) (long)) (h)->chunkfun) ((size)))
|
||||
|
||||
#define CALL_FREEFUN(h, old_chunk) \
|
||||
do { \
|
||||
if ((h) -> use_extra_arg) \
|
||||
(*(h)->freefun) ((h)->extra_arg, (old_chunk)); \
|
||||
else \
|
||||
(*(void (*) (void *)) (h)->freefun) ((old_chunk)); \
|
||||
} while (0)
|
||||
#else
|
||||
#define CALL_CHUNKFUN(h, size) \
|
||||
(((h) -> use_extra_arg) \
|
||||
? (*(h)->chunkfun) ((h)->extra_arg, (size)) \
|
||||
: (*(struct _obstack_chunk *(*) ()) (h)->chunkfun) ((size)))
|
||||
|
||||
#define CALL_FREEFUN(h, old_chunk) \
|
||||
do { \
|
||||
if ((h) -> use_extra_arg) \
|
||||
(*(h)->freefun) ((h)->extra_arg, (old_chunk)); \
|
||||
else \
|
||||
(*(void (*) ()) (h)->freefun) ((old_chunk)); \
|
||||
} while (0)
|
||||
#endif
|
||||
|
||||
|
||||
/* Initialize an obstack H for use. Specify chunk size SIZE (0 means default).
|
||||
Objects start on multiples of ALIGNMENT (0 means use default).
|
||||
CHUNKFUN is the function to use to allocate chunks,
|
||||
and FREEFUN the function to free them.
|
||||
|
||||
Return nonzero if successful, calls obstack_alloc_failed_handler if
|
||||
allocation fails. */
|
||||
|
||||
int
|
||||
_obstack_begin (h, size, alignment, chunkfun, freefun)
|
||||
struct obstack *h;
|
||||
int size;
|
||||
int alignment;
|
||||
#if defined (__STDC__) && __STDC__
|
||||
POINTER (*chunkfun) (long);
|
||||
void (*freefun) (void *);
|
||||
#else
|
||||
POINTER (*chunkfun) ();
|
||||
void (*freefun) ();
|
||||
#endif
|
||||
{
|
||||
register struct _obstack_chunk *chunk; /* points to new chunk */
|
||||
|
||||
if (alignment == 0)
|
||||
alignment = (int) DEFAULT_ALIGNMENT;
|
||||
if (size == 0)
|
||||
/* Default size is what GNU malloc can fit in a 4096-byte block. */
|
||||
{
|
||||
/* 12 is sizeof (mhead) and 4 is EXTRA from GNU malloc.
|
||||
Use the values for range checking, because if range checking is off,
|
||||
the extra bytes won't be missed terribly, but if range checking is on
|
||||
and we used a larger request, a whole extra 4096 bytes would be
|
||||
allocated.
|
||||
|
||||
These number are irrelevant to the new GNU malloc. I suspect it is
|
||||
less sensitive to the size of the request. */
|
||||
int extra = ((((12 + DEFAULT_ROUNDING - 1) & ~(DEFAULT_ROUNDING - 1))
|
||||
+ 4 + DEFAULT_ROUNDING - 1)
|
||||
& ~(DEFAULT_ROUNDING - 1));
|
||||
size = 4096 - extra;
|
||||
}
|
||||
|
||||
#if defined (__STDC__) && __STDC__
|
||||
h->chunkfun = (struct _obstack_chunk * (*)(void *, long)) chunkfun;
|
||||
h->freefun = (void (*) (void *, struct _obstack_chunk *)) freefun;
|
||||
#else
|
||||
h->chunkfun = (struct _obstack_chunk * (*)()) chunkfun;
|
||||
h->freefun = freefun;
|
||||
#endif
|
||||
h->chunk_size = size;
|
||||
h->alignment_mask = alignment - 1;
|
||||
h->use_extra_arg = 0;
|
||||
|
||||
chunk = h->chunk = CALL_CHUNKFUN (h, h -> chunk_size);
|
||||
if (!chunk)
|
||||
(*obstack_alloc_failed_handler) ();
|
||||
h->next_free = h->object_base = chunk->contents;
|
||||
h->chunk_limit = chunk->limit
|
||||
= (char *) chunk + h->chunk_size;
|
||||
chunk->prev = 0;
|
||||
/* The initial chunk now contains no empty object. */
|
||||
h->maybe_empty_object = 0;
|
||||
h->alloc_failed = 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int
|
||||
_obstack_begin_1 (h, size, alignment, chunkfun, freefun, arg)
|
||||
struct obstack *h;
|
||||
int size;
|
||||
int alignment;
|
||||
#if defined (__STDC__) && __STDC__
|
||||
POINTER (*chunkfun) (POINTER, long);
|
||||
void (*freefun) (POINTER, POINTER);
|
||||
#else
|
||||
POINTER (*chunkfun) ();
|
||||
void (*freefun) ();
|
||||
#endif
|
||||
POINTER arg;
|
||||
{
|
||||
register struct _obstack_chunk *chunk; /* points to new chunk */
|
||||
|
||||
if (alignment == 0)
|
||||
alignment = (int) DEFAULT_ALIGNMENT;
|
||||
if (size == 0)
|
||||
/* Default size is what GNU malloc can fit in a 4096-byte block. */
|
||||
{
|
||||
/* 12 is sizeof (mhead) and 4 is EXTRA from GNU malloc.
|
||||
Use the values for range checking, because if range checking is off,
|
||||
the extra bytes won't be missed terribly, but if range checking is on
|
||||
and we used a larger request, a whole extra 4096 bytes would be
|
||||
allocated.
|
||||
|
||||
These number are irrelevant to the new GNU malloc. I suspect it is
|
||||
less sensitive to the size of the request. */
|
||||
int extra = ((((12 + DEFAULT_ROUNDING - 1) & ~(DEFAULT_ROUNDING - 1))
|
||||
+ 4 + DEFAULT_ROUNDING - 1)
|
||||
& ~(DEFAULT_ROUNDING - 1));
|
||||
size = 4096 - extra;
|
||||
}
|
||||
|
||||
#if defined(__STDC__) && __STDC__
|
||||
h->chunkfun = (struct _obstack_chunk * (*)(void *,long)) chunkfun;
|
||||
h->freefun = (void (*) (void *, struct _obstack_chunk *)) freefun;
|
||||
#else
|
||||
h->chunkfun = (struct _obstack_chunk * (*)()) chunkfun;
|
||||
h->freefun = freefun;
|
||||
#endif
|
||||
h->chunk_size = size;
|
||||
h->alignment_mask = alignment - 1;
|
||||
h->extra_arg = arg;
|
||||
h->use_extra_arg = 1;
|
||||
|
||||
chunk = h->chunk = CALL_CHUNKFUN (h, h -> chunk_size);
|
||||
if (!chunk)
|
||||
(*obstack_alloc_failed_handler) ();
|
||||
h->next_free = h->object_base = chunk->contents;
|
||||
h->chunk_limit = chunk->limit
|
||||
= (char *) chunk + h->chunk_size;
|
||||
chunk->prev = 0;
|
||||
/* The initial chunk now contains no empty object. */
|
||||
h->maybe_empty_object = 0;
|
||||
h->alloc_failed = 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Allocate a new current chunk for the obstack *H
|
||||
on the assumption that LENGTH bytes need to be added
|
||||
to the current object, or a new object of length LENGTH allocated.
|
||||
Copies any partial object from the end of the old chunk
|
||||
to the beginning of the new one. */
|
||||
|
||||
void
|
||||
_obstack_newchunk (h, length)
|
||||
struct obstack *h;
|
||||
int length;
|
||||
{
|
||||
register struct _obstack_chunk *old_chunk = h->chunk;
|
||||
register struct _obstack_chunk *new_chunk;
|
||||
register long new_size;
|
||||
register long obj_size = h->next_free - h->object_base;
|
||||
register long i;
|
||||
long already;
|
||||
|
||||
/* Compute size for new chunk. */
|
||||
new_size = (obj_size + length) + (obj_size >> 3) + 100;
|
||||
if (new_size < h->chunk_size)
|
||||
new_size = h->chunk_size;
|
||||
|
||||
/* Allocate and initialize the new chunk. */
|
||||
new_chunk = CALL_CHUNKFUN (h, new_size);
|
||||
if (!new_chunk)
|
||||
(*obstack_alloc_failed_handler) ();
|
||||
h->chunk = new_chunk;
|
||||
new_chunk->prev = old_chunk;
|
||||
new_chunk->limit = h->chunk_limit = (char *) new_chunk + new_size;
|
||||
|
||||
/* Move the existing object to the new chunk.
|
||||
Word at a time is fast and is safe if the object
|
||||
is sufficiently aligned. */
|
||||
if (h->alignment_mask + 1 >= DEFAULT_ALIGNMENT)
|
||||
{
|
||||
for (i = obj_size / sizeof (COPYING_UNIT) - 1;
|
||||
i >= 0; i--)
|
||||
((COPYING_UNIT *)new_chunk->contents)[i]
|
||||
= ((COPYING_UNIT *)h->object_base)[i];
|
||||
/* We used to copy the odd few remaining bytes as one extra COPYING_UNIT,
|
||||
but that can cross a page boundary on a machine
|
||||
which does not do strict alignment for COPYING_UNITS. */
|
||||
already = obj_size / sizeof (COPYING_UNIT) * sizeof (COPYING_UNIT);
|
||||
}
|
||||
else
|
||||
already = 0;
|
||||
/* Copy remaining bytes one by one. */
|
||||
for (i = already; i < obj_size; i++)
|
||||
new_chunk->contents[i] = h->object_base[i];
|
||||
|
||||
/* If the object just copied was the only data in OLD_CHUNK,
|
||||
free that chunk and remove it from the chain.
|
||||
But not if that chunk might contain an empty object. */
|
||||
if (h->object_base == old_chunk->contents && ! h->maybe_empty_object)
|
||||
{
|
||||
new_chunk->prev = old_chunk->prev;
|
||||
CALL_FREEFUN (h, old_chunk);
|
||||
}
|
||||
|
||||
h->object_base = new_chunk->contents;
|
||||
h->next_free = h->object_base + obj_size;
|
||||
/* The new chunk certainly contains no empty object yet. */
|
||||
h->maybe_empty_object = 0;
|
||||
}
|
||||
|
||||
/* Return nonzero if object OBJ has been allocated from obstack H.
|
||||
This is here for debugging.
|
||||
If you use it in a program, you are probably losing. */
|
||||
|
||||
#if defined (__STDC__) && __STDC__
|
||||
/* Suppress -Wmissing-prototypes warning. We don't want to declare this in
|
||||
obstack.h because it is just for debugging. */
|
||||
int _obstack_allocated_p (struct obstack *h, POINTER obj);
|
||||
#endif
|
||||
|
||||
int
|
||||
_obstack_allocated_p (h, obj)
|
||||
struct obstack *h;
|
||||
POINTER obj;
|
||||
{
|
||||
register struct _obstack_chunk *lp; /* below addr of any objects in this chunk */
|
||||
register struct _obstack_chunk *plp; /* point to previous chunk if any */
|
||||
|
||||
lp = (h)->chunk;
|
||||
/* We use >= rather than > since the object cannot be exactly at
|
||||
the beginning of the chunk but might be an empty object exactly
|
||||
at the end of an adjacent chunk. */
|
||||
while (lp != 0 && ((POINTER) lp >= obj || (POINTER) (lp)->limit < obj))
|
||||
{
|
||||
plp = lp->prev;
|
||||
lp = plp;
|
||||
}
|
||||
return lp != 0;
|
||||
}
|
||||
|
||||
/* Free objects in obstack H, including OBJ and everything allocate
|
||||
more recently than OBJ. If OBJ is zero, free everything in H. */
|
||||
|
||||
#undef obstack_free
|
||||
|
||||
/* This function has two names with identical definitions.
|
||||
This is the first one, called from non-ANSI code. */
|
||||
|
||||
void
|
||||
_obstack_free (h, obj)
|
||||
struct obstack *h;
|
||||
POINTER obj;
|
||||
{
|
||||
register struct _obstack_chunk *lp; /* below addr of any objects in this chunk */
|
||||
register struct _obstack_chunk *plp; /* point to previous chunk if any */
|
||||
|
||||
lp = h->chunk;
|
||||
/* We use >= because there cannot be an object at the beginning of a chunk.
|
||||
But there can be an empty object at that address
|
||||
at the end of another chunk. */
|
||||
while (lp != 0 && ((POINTER) lp >= obj || (POINTER) (lp)->limit < obj))
|
||||
{
|
||||
plp = lp->prev;
|
||||
CALL_FREEFUN (h, lp);
|
||||
lp = plp;
|
||||
/* If we switch chunks, we can't tell whether the new current
|
||||
chunk contains an empty object, so assume that it may. */
|
||||
h->maybe_empty_object = 1;
|
||||
}
|
||||
if (lp)
|
||||
{
|
||||
h->object_base = h->next_free = (char *) (obj);
|
||||
h->chunk_limit = lp->limit;
|
||||
h->chunk = lp;
|
||||
}
|
||||
else if (obj != 0)
|
||||
/* obj is not in any of the chunks! */
|
||||
abort ();
|
||||
}
|
||||
|
||||
/* This function is used from ANSI code. */
|
||||
|
||||
void
|
||||
obstack_free (h, obj)
|
||||
struct obstack *h;
|
||||
POINTER obj;
|
||||
{
|
||||
register struct _obstack_chunk *lp; /* below addr of any objects in this chunk */
|
||||
register struct _obstack_chunk *plp; /* point to previous chunk if any */
|
||||
|
||||
lp = h->chunk;
|
||||
/* We use >= because there cannot be an object at the beginning of a chunk.
|
||||
But there can be an empty object at that address
|
||||
at the end of another chunk. */
|
||||
while (lp != 0 && ((POINTER) lp >= obj || (POINTER) (lp)->limit < obj))
|
||||
{
|
||||
plp = lp->prev;
|
||||
CALL_FREEFUN (h, lp);
|
||||
lp = plp;
|
||||
/* If we switch chunks, we can't tell whether the new current
|
||||
chunk contains an empty object, so assume that it may. */
|
||||
h->maybe_empty_object = 1;
|
||||
}
|
||||
if (lp)
|
||||
{
|
||||
h->object_base = h->next_free = (char *) (obj);
|
||||
h->chunk_limit = lp->limit;
|
||||
h->chunk = lp;
|
||||
}
|
||||
else if (obj != 0)
|
||||
/* obj is not in any of the chunks! */
|
||||
abort ();
|
||||
}
|
||||
|
||||
int
|
||||
_obstack_memory_used (h)
|
||||
struct obstack *h;
|
||||
{
|
||||
register struct _obstack_chunk* lp;
|
||||
register int nbytes = 0;
|
||||
|
||||
for (lp = h->chunk; lp != 0; lp = lp->prev)
|
||||
{
|
||||
nbytes += lp->limit - (char *) lp;
|
||||
}
|
||||
return nbytes;
|
||||
}
|
||||
|
||||
/* Define the error handler. */
|
||||
#ifndef _
|
||||
# ifdef HAVE_LIBINTL_H
|
||||
# include <libintl.h>
|
||||
# ifndef _
|
||||
# define _(Str) gettext (Str)
|
||||
# endif
|
||||
# else
|
||||
# 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"), stderr);
|
||||
fputc ('\n', stderr);
|
||||
exit (obstack_exit_failure);
|
||||
}
|
||||
|
||||
#if 0
|
||||
/* These are now turned off because the applications do not use it
|
||||
and it uses bcopy via obstack_grow, which causes trouble on sysV. */
|
||||
|
||||
/* Now define the functional versions of the obstack macros.
|
||||
Define them to simply use the corresponding macros to do the job. */
|
||||
|
||||
#if defined (__STDC__) && __STDC__
|
||||
/* These function definitions do not work with non-ANSI preprocessors;
|
||||
they won't pass through the macro names in parentheses. */
|
||||
|
||||
/* The function names appear in parentheses in order to prevent
|
||||
the macro-definitions of the names from being expanded there. */
|
||||
|
||||
POINTER (obstack_base) (obstack)
|
||||
struct obstack *obstack;
|
||||
{
|
||||
return obstack_base (obstack);
|
||||
}
|
||||
|
||||
POINTER (obstack_next_free) (obstack)
|
||||
struct obstack *obstack;
|
||||
{
|
||||
return obstack_next_free (obstack);
|
||||
}
|
||||
|
||||
int (obstack_object_size) (obstack)
|
||||
struct obstack *obstack;
|
||||
{
|
||||
return obstack_object_size (obstack);
|
||||
}
|
||||
|
||||
int (obstack_room) (obstack)
|
||||
struct obstack *obstack;
|
||||
{
|
||||
return obstack_room (obstack);
|
||||
}
|
||||
|
||||
int (obstack_make_room) (obstack, length)
|
||||
struct obstack *obstack;
|
||||
int length;
|
||||
{
|
||||
return obstack_make_room (obstack, length);
|
||||
}
|
||||
|
||||
void (obstack_grow) (obstack, pointer, length)
|
||||
struct obstack *obstack;
|
||||
POINTER pointer;
|
||||
int length;
|
||||
{
|
||||
obstack_grow (obstack, pointer, length);
|
||||
}
|
||||
|
||||
void (obstack_grow0) (obstack, pointer, length)
|
||||
struct obstack *obstack;
|
||||
POINTER pointer;
|
||||
int length;
|
||||
{
|
||||
obstack_grow0 (obstack, pointer, length);
|
||||
}
|
||||
|
||||
void (obstack_1grow) (obstack, character)
|
||||
struct obstack *obstack;
|
||||
int character;
|
||||
{
|
||||
obstack_1grow (obstack, character);
|
||||
}
|
||||
|
||||
void (obstack_blank) (obstack, length)
|
||||
struct obstack *obstack;
|
||||
int length;
|
||||
{
|
||||
obstack_blank (obstack, length);
|
||||
}
|
||||
|
||||
void (obstack_1grow_fast) (obstack, character)
|
||||
struct obstack *obstack;
|
||||
int character;
|
||||
{
|
||||
obstack_1grow_fast (obstack, character);
|
||||
}
|
||||
|
||||
void (obstack_blank_fast) (obstack, length)
|
||||
struct obstack *obstack;
|
||||
int length;
|
||||
{
|
||||
obstack_blank_fast (obstack, length);
|
||||
}
|
||||
|
||||
POINTER (obstack_finish) (obstack)
|
||||
struct obstack *obstack;
|
||||
{
|
||||
return obstack_finish (obstack);
|
||||
}
|
||||
|
||||
POINTER (obstack_alloc) (obstack, length)
|
||||
struct obstack *obstack;
|
||||
int length;
|
||||
{
|
||||
return obstack_alloc (obstack, length);
|
||||
}
|
||||
|
||||
POINTER (obstack_copy) (obstack, pointer, length)
|
||||
struct obstack *obstack;
|
||||
POINTER pointer;
|
||||
int length;
|
||||
{
|
||||
return obstack_copy (obstack, pointer, length);
|
||||
}
|
||||
|
||||
POINTER (obstack_copy0) (obstack, pointer, length)
|
||||
struct obstack *obstack;
|
||||
POINTER pointer;
|
||||
int length;
|
||||
{
|
||||
return obstack_copy0 (obstack, pointer, length);
|
||||
}
|
||||
|
||||
#endif /* __STDC__ */
|
||||
|
||||
#endif /* 0 */
|
||||
|
||||
#endif /* !ELIDE_CODE */
|
@ -1,593 +0,0 @@
|
||||
/* obstack.h - object stack macros
|
||||
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.
|
||||
|
||||
The GNU C Library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public License as
|
||||
published by the Free Software Foundation; either version 2 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
The GNU C Library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with the GNU C Library; see the file COPYING.LIB. If not,
|
||||
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
Boston, MA 02111-1307, USA. */
|
||||
|
||||
/* Summary:
|
||||
|
||||
All the apparent functions defined here are macros. The idea
|
||||
is that you would use these pre-tested macros to solve a
|
||||
very specific set of problems, and they would run fast.
|
||||
Caution: no side-effects in arguments please!! They may be
|
||||
evaluated MANY times!!
|
||||
|
||||
These macros operate a stack of objects. Each object starts life
|
||||
small, and may grow to maturity. (Consider building a word syllable
|
||||
by syllable.) An object can move while it is growing. Once it has
|
||||
been "finished" it never changes address again. So the "top of the
|
||||
stack" is typically an immature growing object, while the rest of the
|
||||
stack is of mature, fixed size and fixed address objects.
|
||||
|
||||
These routines grab large chunks of memory, using a function you
|
||||
supply, called `obstack_chunk_alloc'. On occasion, they free chunks,
|
||||
by calling `obstack_chunk_free'. You must define them and declare
|
||||
them before using any obstack macros.
|
||||
|
||||
Each independent stack is represented by a `struct obstack'.
|
||||
Each of the obstack macros expects a pointer to such a structure
|
||||
as the first argument.
|
||||
|
||||
One motivation for this package is the problem of growing char strings
|
||||
in symbol tables. Unless you are "fascist pig with a read-only mind"
|
||||
--Gosper's immortal quote from HAKMEM item 154, out of context--you
|
||||
would not like to put any arbitrary upper limit on the length of your
|
||||
symbols.
|
||||
|
||||
In practice this often means you will build many short symbols and a
|
||||
few long symbols. At the time you are reading a symbol you don't know
|
||||
how long it is. One traditional method is to read a symbol into a
|
||||
buffer, realloc()ating the buffer every time you try to read a symbol
|
||||
that is longer than the buffer. This is beaut, but you still will
|
||||
want to copy the symbol from the buffer to a more permanent
|
||||
symbol-table entry say about half the time.
|
||||
|
||||
With obstacks, you can work differently. Use one obstack for all symbol
|
||||
names. As you read a symbol, grow the name in the obstack gradually.
|
||||
When the name is complete, finalize it. Then, if the symbol exists already,
|
||||
free the newly read name.
|
||||
|
||||
The way we do this is to take a large chunk, allocating memory from
|
||||
low addresses. When you want to build a symbol in the chunk you just
|
||||
add chars above the current "high water mark" in the chunk. When you
|
||||
have finished adding chars, because you got to the end of the symbol,
|
||||
you know how long the chars are, and you can create a new object.
|
||||
Mostly the chars will not burst over the highest address of the chunk,
|
||||
because you would typically expect a chunk to be (say) 100 times as
|
||||
long as an average object.
|
||||
|
||||
In case that isn't clear, when we have enough chars to make up
|
||||
the object, THEY ARE ALREADY CONTIGUOUS IN THE CHUNK (guaranteed)
|
||||
so we just point to it where it lies. No moving of chars is
|
||||
needed and this is the second win: potentially long strings need
|
||||
never be explicitly shuffled. Once an object is formed, it does not
|
||||
change its address during its lifetime.
|
||||
|
||||
When the chars burst over a chunk boundary, we allocate a larger
|
||||
chunk, and then copy the partly formed object from the end of the old
|
||||
chunk to the beginning of the new larger chunk. We then carry on
|
||||
accreting characters to the end of the object as we normally would.
|
||||
|
||||
A special macro is provided to add a single char at a time to a
|
||||
growing object. This allows the use of register variables, which
|
||||
break the ordinary 'growth' macro.
|
||||
|
||||
Summary:
|
||||
We allocate large chunks.
|
||||
We carve out one object at a time from the current chunk.
|
||||
Once carved, an object never moves.
|
||||
We are free to append data of any size to the currently
|
||||
growing object.
|
||||
Exactly one object is growing in an obstack at any one time.
|
||||
You can run one obstack per control block.
|
||||
You may have as many control blocks as you dare.
|
||||
Because of the way we do it, you can `unwind' an obstack
|
||||
back to a previous state. (You may remove objects much
|
||||
as you would with a stack.)
|
||||
*/
|
||||
|
||||
|
||||
/* Don't do the contents of this file more than once. */
|
||||
|
||||
#ifndef _OBSTACK_H
|
||||
#define _OBSTACK_H 1
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* We use subtraction of (char *) 0 instead of casting to int
|
||||
because on word-addressable machines a simple cast to int
|
||||
may ignore the byte-within-word field of the pointer. */
|
||||
|
||||
#ifndef __PTR_TO_INT
|
||||
# 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. 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. */
|
||||
|
||||
#ifdef __PTRDIFF_TYPE__
|
||||
# define PTR_INT_TYPE __PTRDIFF_TYPE__
|
||||
#else
|
||||
# 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))
|
||||
#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
|
||||
#endif
|
||||
|
||||
struct _obstack_chunk /* Lives at front of each chunk. */
|
||||
{
|
||||
char *limit; /* 1 past end of this chunk */
|
||||
struct _obstack_chunk *prev; /* address of prior chunk or NULL */
|
||||
char contents[4]; /* objects begin here */
|
||||
};
|
||||
|
||||
struct obstack /* control current object in current chunk */
|
||||
{
|
||||
long chunk_size; /* preferred size to allocate chunks in */
|
||||
struct _obstack_chunk *chunk; /* address of current struct obstack_chunk */
|
||||
char *object_base; /* address of object we are building */
|
||||
char *next_free; /* where to add next char to current object */
|
||||
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__
|
||||
/* 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. */
|
||||
struct _obstack_chunk *(*chunkfun) (void *, long);
|
||||
void (*freefun) (void *, struct _obstack_chunk *);
|
||||
void *extra_arg; /* first arg for chunk alloc/dealloc funcs */
|
||||
#else
|
||||
struct _obstack_chunk *(*chunkfun) (); /* User's fcn to allocate a chunk. */
|
||||
void (*freefun) (); /* User's function to free a chunk. */
|
||||
char *extra_arg; /* first arg for chunk alloc/dealloc funcs */
|
||||
#endif
|
||||
unsigned use_extra_arg:1; /* chunk alloc/dealloc funcs take extra arg */
|
||||
unsigned maybe_empty_object:1;/* There is a possibility that the current
|
||||
chunk contains a zero-length object. This
|
||||
prevents freeing the chunk if we allocate
|
||||
a bigger chunk to replace it. */
|
||||
unsigned alloc_failed:1; /* No longer used, as we now call the failed
|
||||
handler on error, but retained for binary
|
||||
compatibility. */
|
||||
};
|
||||
|
||||
/* Declare the external functions we use; they are in obstack.c. */
|
||||
|
||||
#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,
|
||||
void *(*) (long), void (*) (void *));
|
||||
extern int _obstack_begin_1 (struct obstack *, int, int,
|
||||
void *(*) (void *, long),
|
||||
void (*) (void *, void *), void *);
|
||||
extern int _obstack_memory_used (struct obstack *);
|
||||
#else
|
||||
extern void _obstack_newchunk ();
|
||||
extern void _obstack_free ();
|
||||
extern int _obstack_begin ();
|
||||
extern int _obstack_begin_1 ();
|
||||
extern int _obstack_memory_used ();
|
||||
#endif
|
||||
|
||||
#if defined __STDC__ && __STDC__
|
||||
|
||||
/* Do the function-declarations after the structs
|
||||
but before defining the macros. */
|
||||
|
||||
void obstack_init (struct obstack *obstack);
|
||||
|
||||
void * obstack_alloc (struct obstack *obstack, int size);
|
||||
|
||||
void * obstack_copy (struct obstack *obstack, void *address, int size);
|
||||
void * obstack_copy0 (struct obstack *obstack, void *address, int size);
|
||||
|
||||
void obstack_free (struct obstack *obstack, void *block);
|
||||
|
||||
void obstack_blank (struct obstack *obstack, int size);
|
||||
|
||||
void obstack_grow (struct obstack *obstack, void *data, int size);
|
||||
void obstack_grow0 (struct obstack *obstack, void *data, int size);
|
||||
|
||||
void obstack_1grow (struct obstack *obstack, int data_char);
|
||||
void obstack_ptr_grow (struct obstack *obstack, void *data);
|
||||
void obstack_int_grow (struct obstack *obstack, int data);
|
||||
|
||||
void * obstack_finish (struct obstack *obstack);
|
||||
|
||||
int obstack_object_size (struct obstack *obstack);
|
||||
|
||||
int obstack_room (struct obstack *obstack);
|
||||
void obstack_make_room (struct obstack *obstack, int size);
|
||||
void obstack_1grow_fast (struct obstack *obstack, int data_char);
|
||||
void obstack_ptr_grow_fast (struct obstack *obstack, void *data);
|
||||
void obstack_int_grow_fast (struct obstack *obstack, int data);
|
||||
void obstack_blank_fast (struct obstack *obstack, int size);
|
||||
|
||||
void * obstack_base (struct obstack *obstack);
|
||||
void * obstack_next_free (struct obstack *obstack);
|
||||
int obstack_alignment_mask (struct obstack *obstack);
|
||||
int obstack_chunk_size (struct obstack *obstack);
|
||||
int obstack_memory_used (struct obstack *obstack);
|
||||
|
||||
#endif /* __STDC__ */
|
||||
|
||||
/* Non-ANSI C cannot really support alternative functions for these macros,
|
||||
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 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) ();
|
||||
#endif
|
||||
|
||||
/* Exit value used when `print_and_abort' is used. */
|
||||
extern int obstack_exit_failure;
|
||||
|
||||
/* Pointer to beginning of object being allocated or to be allocated next.
|
||||
Note that this might not be the final address of the object
|
||||
because a new chunk might be needed to hold the final size. */
|
||||
|
||||
#define obstack_base(h) ((h)->object_base)
|
||||
|
||||
/* Size for allocating ordinary chunks. */
|
||||
|
||||
#define obstack_chunk_size(h) ((h)->chunk_size)
|
||||
|
||||
/* Pointer to next byte not yet allocated in current chunk. */
|
||||
|
||||
#define obstack_next_free(h) ((h)->next_free)
|
||||
|
||||
/* Mask specifying low bits that should be clear in address of an object. */
|
||||
|
||||
#define obstack_alignment_mask(h) ((h)->alignment_mask)
|
||||
|
||||
/* To prevent prototype warnings provide complete argument list in
|
||||
standard C version. */
|
||||
#if defined __STDC__ && __STDC__
|
||||
|
||||
# define obstack_init(h) \
|
||||
_obstack_begin ((h), 0, 0, \
|
||||
(void *(*) (long)) obstack_chunk_alloc, (void (*) (void *)) obstack_chunk_free)
|
||||
|
||||
# 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) \
|
||||
_obstack_begin ((h), (size), (alignment), \
|
||||
(void *(*) (long)) (chunkfun), (void (*) (void *)) (freefun))
|
||||
|
||||
# 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) \
|
||||
((h) -> chunkfun = (struct _obstack_chunk *(*)(void *, long)) (newchunkfun))
|
||||
|
||||
# define obstack_freefun(h, newfreefun) \
|
||||
((h) -> freefun = (void (*)(void *, struct _obstack_chunk *)) (newfreefun))
|
||||
|
||||
#else
|
||||
|
||||
# define obstack_init(h) \
|
||||
_obstack_begin ((h), 0, 0, \
|
||||
(void *(*) ()) obstack_chunk_alloc, (void (*) ()) obstack_chunk_free)
|
||||
|
||||
# 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) \
|
||||
_obstack_begin ((h), (size), (alignment), \
|
||||
(void *(*) ()) (chunkfun), (void (*) ()) (freefun))
|
||||
|
||||
# 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) \
|
||||
((h) -> chunkfun = (struct _obstack_chunk *(*)()) (newchunkfun))
|
||||
|
||||
# define obstack_freefun(h, newfreefun) \
|
||||
((h) -> freefun = (void (*)()) (newfreefun))
|
||||
|
||||
#endif
|
||||
|
||||
#define obstack_1grow_fast(h,achar) (*((h)->next_free)++ = achar)
|
||||
|
||||
#define obstack_blank_fast(h,n) ((h)->next_free += (n))
|
||||
|
||||
#define obstack_memory_used(h) _obstack_memory_used (h)
|
||||
|
||||
#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
|
||||
|
||||
/* 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) \
|
||||
__extension__ \
|
||||
({ struct obstack *__o = (OBSTACK); \
|
||||
(unsigned) (__o->next_free - __o->object_base); })
|
||||
|
||||
# define obstack_room(OBSTACK) \
|
||||
__extension__ \
|
||||
({ struct obstack *__o = (OBSTACK); \
|
||||
(unsigned) (__o->chunk_limit - __o->next_free); })
|
||||
|
||||
# define obstack_make_room(OBSTACK,length) \
|
||||
__extension__ \
|
||||
({ struct obstack *__o = (OBSTACK); \
|
||||
int __len = (length); \
|
||||
if (__o->chunk_limit - __o->next_free < __len) \
|
||||
_obstack_newchunk (__o, __len); \
|
||||
(void) 0; })
|
||||
|
||||
# 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); \
|
||||
if (__o->next_free + __len > __o->chunk_limit) \
|
||||
_obstack_newchunk (__o, __len); \
|
||||
_obstack_memcpy (__o->next_free, (char *) (where), __len); \
|
||||
__o->next_free += __len; \
|
||||
(void) 0; })
|
||||
|
||||
# define obstack_grow0(OBSTACK,where,length) \
|
||||
__extension__ \
|
||||
({ struct obstack *__o = (OBSTACK); \
|
||||
int __len = (length); \
|
||||
if (__o->next_free + __len + 1 > __o->chunk_limit) \
|
||||
_obstack_newchunk (__o, __len + 1); \
|
||||
_obstack_memcpy (__o->next_free, (char *) (where), __len); \
|
||||
__o->next_free += __len; \
|
||||
*(__o->next_free)++ = 0; \
|
||||
(void) 0; })
|
||||
|
||||
# define obstack_1grow(OBSTACK,datum) \
|
||||
__extension__ \
|
||||
({ struct obstack *__o = (OBSTACK); \
|
||||
if (__o->next_free + 1 > __o->chunk_limit) \
|
||||
_obstack_newchunk (__o, 1); \
|
||||
*(__o->next_free)++ = (datum); \
|
||||
(void) 0; })
|
||||
|
||||
/* These assume that the obstack alignment is good enough for pointers or ints,
|
||||
and that the data added so far to the current object
|
||||
shares that much alignment. */
|
||||
|
||||
# define obstack_ptr_grow(OBSTACK,datum) \
|
||||
__extension__ \
|
||||
({ struct obstack *__o = (OBSTACK); \
|
||||
if (__o->next_free + sizeof (void *) > __o->chunk_limit) \
|
||||
_obstack_newchunk (__o, sizeof (void *)); \
|
||||
*((void **)__o->next_free)++ = ((void *)datum); \
|
||||
(void) 0; })
|
||||
|
||||
# define obstack_int_grow(OBSTACK,datum) \
|
||||
__extension__ \
|
||||
({ struct obstack *__o = (OBSTACK); \
|
||||
if (__o->next_free + sizeof (int) > __o->chunk_limit) \
|
||||
_obstack_newchunk (__o, sizeof (int)); \
|
||||
*((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_blank(OBSTACK,length) \
|
||||
__extension__ \
|
||||
({ struct obstack *__o = (OBSTACK); \
|
||||
int __len = (length); \
|
||||
if (__o->chunk_limit - __o->next_free < __len) \
|
||||
_obstack_newchunk (__o, __len); \
|
||||
__o->next_free += __len; \
|
||||
(void) 0; })
|
||||
|
||||
# define obstack_alloc(OBSTACK,length) \
|
||||
__extension__ \
|
||||
({ struct obstack *__h = (OBSTACK); \
|
||||
obstack_blank (__h, (length)); \
|
||||
obstack_finish (__h); })
|
||||
|
||||
# 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) \
|
||||
__extension__ \
|
||||
({ struct obstack *__h = (OBSTACK); \
|
||||
obstack_grow0 (__h, (where), (length)); \
|
||||
obstack_finish (__h); })
|
||||
|
||||
/* The local variable is named __o1 to avoid a name conflict
|
||||
when obstack_blank is called. */
|
||||
# define obstack_finish(OBSTACK) \
|
||||
__extension__ \
|
||||
({ struct obstack *__o1 = (OBSTACK); \
|
||||
void *value; \
|
||||
value = (void *) __o1->object_base; \
|
||||
if (__o1->next_free == value) \
|
||||
__o1->maybe_empty_object = 1; \
|
||||
__o1->next_free \
|
||||
= __INT_TO_PTR ((__PTR_TO_INT (__o1->next_free)+__o1->alignment_mask)\
|
||||
& ~ (__o1->alignment_mask)); \
|
||||
if (__o1->next_free - (char *)__o1->chunk \
|
||||
> __o1->chunk_limit - (char *)__o1->chunk) \
|
||||
__o1->next_free = __o1->chunk_limit; \
|
||||
__o1->object_base = __o1->next_free; \
|
||||
value; })
|
||||
|
||||
# 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 = (char *)__obj; \
|
||||
else (obstack_free) (__o, __obj); })
|
||||
|
||||
#else /* not __GNUC__ or not __STDC__ */
|
||||
|
||||
# define obstack_object_size(h) \
|
||||
(unsigned) ((h)->next_free - (h)->object_base)
|
||||
|
||||
# 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) \
|
||||
( (h)->temp = (length), \
|
||||
(((h)->next_free + (h)->temp > (h)->chunk_limit) \
|
||||
? (_obstack_newchunk ((h), (h)->temp), 0) : 0))
|
||||
|
||||
# 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) \
|
||||
( (h)->temp = (length), \
|
||||
(((h)->next_free + (h)->temp + 1 > (h)->chunk_limit) \
|
||||
? (_obstack_newchunk ((h), (h)->temp + 1), 0) : 0), \
|
||||
_obstack_memcpy ((h)->next_free, (char *) (where), (h)->temp), \
|
||||
(h)->next_free += (h)->temp, \
|
||||
*((h)->next_free)++ = 0)
|
||||
|
||||
# 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) \
|
||||
( (((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) \
|
||||
( (((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_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) \
|
||||
(obstack_blank ((h), (length)), obstack_finish ((h)))
|
||||
|
||||
# define obstack_copy(h,where,length) \
|
||||
(obstack_grow ((h), (where), (length)), obstack_finish ((h)))
|
||||
|
||||
# define obstack_copy0(h,where,length) \
|
||||
(obstack_grow0 ((h), (where), (length)), obstack_finish ((h)))
|
||||
|
||||
# define obstack_finish(h) \
|
||||
( ((h)->next_free == (h)->object_base \
|
||||
? (((h)->maybe_empty_object = 1), 0) \
|
||||
: 0), \
|
||||
(h)->temp = __PTR_TO_INT ((h)->object_base), \
|
||||
(h)->next_free \
|
||||
= __INT_TO_PTR ((__PTR_TO_INT ((h)->next_free)+(h)->alignment_mask) \
|
||||
& ~ ((h)->alignment_mask)), \
|
||||
(((h)->next_free - (char *) (h)->chunk \
|
||||
> (h)->chunk_limit - (char *) (h)->chunk) \
|
||||
? ((h)->next_free = (h)->chunk_limit) : 0), \
|
||||
(h)->object_base = (h)->next_free, \
|
||||
__INT_TO_PTR ((h)->temp))
|
||||
|
||||
# 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) \
|
||||
( (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 /* not __GNUC__ or not __STDC__ */
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* C++ */
|
||||
#endif
|
||||
|
||||
#endif /* obstack.h */
|
@ -1,613 +0,0 @@
|
||||
/* quotearg.c - quote arguments for output
|
||||
Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software Foundation,
|
||||
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
||||
|
||||
/* Written by Paul Eggert <eggert@twinsun.com> */
|
||||
|
||||
#if HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#if HAVE_STDDEF_H
|
||||
# include <stddef.h> /* For the definition of size_t on windows w/MSVC. */
|
||||
#endif
|
||||
#include <sys/types.h>
|
||||
#include <quotearg.h>
|
||||
#include <xalloc.h>
|
||||
|
||||
#include <ctype.h>
|
||||
|
||||
#if ENABLE_NLS
|
||||
# include <libintl.h>
|
||||
# define _(text) gettext (text)
|
||||
#else
|
||||
# define _(text) text
|
||||
#endif
|
||||
#define N_(text) text
|
||||
|
||||
#if HAVE_LIMITS_H
|
||||
# include <limits.h>
|
||||
#endif
|
||||
#ifndef CHAR_BIT
|
||||
# define CHAR_BIT 8
|
||||
#endif
|
||||
#ifndef UCHAR_MAX
|
||||
# define UCHAR_MAX ((unsigned char) -1)
|
||||
#endif
|
||||
|
||||
#if HAVE_C_BACKSLASH_A
|
||||
# define ALERT_CHAR '\a'
|
||||
#else
|
||||
# define ALERT_CHAR '\7'
|
||||
#endif
|
||||
|
||||
#if HAVE_STDLIB_H
|
||||
# include <stdlib.h>
|
||||
#endif
|
||||
|
||||
#if HAVE_STRING_H
|
||||
# include <string.h>
|
||||
#endif
|
||||
|
||||
#if HAVE_WCHAR_H
|
||||
# include <wchar.h>
|
||||
#endif
|
||||
|
||||
#if !HAVE_MBRTOWC
|
||||
/* Disable multibyte processing entirely. Since MB_CUR_MAX is 1, the
|
||||
other macros are defined only for documentation and to satisfy C
|
||||
syntax. */
|
||||
# undef MB_CUR_MAX
|
||||
# define MB_CUR_MAX 1
|
||||
# define mbrtowc(pwc, s, n, ps) ((*(pwc) = *(s)) != 0)
|
||||
# define mbsinit(ps) 1
|
||||
# define iswprint(wc) ISPRINT ((unsigned char) (wc))
|
||||
#endif
|
||||
|
||||
#ifndef iswprint
|
||||
# if HAVE_WCTYPE_H
|
||||
# include <wctype.h>
|
||||
# endif
|
||||
# if !defined iswprint && !HAVE_ISWPRINT
|
||||
# define iswprint(wc) 1
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#define INT_BITS (sizeof (int) * CHAR_BIT)
|
||||
|
||||
#if defined (STDC_HEADERS) || (!defined (isascii) && !defined (HAVE_ISASCII))
|
||||
# define IN_CTYPE_DOMAIN(c) 1
|
||||
#else
|
||||
# define IN_CTYPE_DOMAIN(c) isascii(c)
|
||||
#endif
|
||||
|
||||
/* Undefine to protect against the definition in wctype.h of solaris2.6. */
|
||||
#undef ISPRINT
|
||||
#define ISPRINT(c) (IN_CTYPE_DOMAIN (c) && isprint (c))
|
||||
|
||||
struct quoting_options
|
||||
{
|
||||
/* Basic quoting style. */
|
||||
enum quoting_style style;
|
||||
|
||||
/* Quote the characters indicated by this bit vector even if the
|
||||
quoting style would not normally require them to be quoted. */
|
||||
int quote_these_too[(UCHAR_MAX / INT_BITS) + 1];
|
||||
};
|
||||
|
||||
/* Names of quoting styles. */
|
||||
char const *const quoting_style_args[] =
|
||||
{
|
||||
"literal",
|
||||
"shell",
|
||||
"shell-always",
|
||||
"c",
|
||||
"escape",
|
||||
"locale",
|
||||
"clocale",
|
||||
0
|
||||
};
|
||||
|
||||
/* Correspondences to quoting style names. */
|
||||
enum quoting_style const quoting_style_vals[] =
|
||||
{
|
||||
literal_quoting_style,
|
||||
shell_quoting_style,
|
||||
shell_always_quoting_style,
|
||||
c_quoting_style,
|
||||
escape_quoting_style,
|
||||
locale_quoting_style,
|
||||
clocale_quoting_style
|
||||
};
|
||||
|
||||
/* The default quoting options. */
|
||||
static struct quoting_options default_quoting_options;
|
||||
|
||||
/* Allocate a new set of quoting options, with contents initially identical
|
||||
to O if O is not null, or to the default if O is null.
|
||||
It is the caller's responsibility to free the result. */
|
||||
struct quoting_options *
|
||||
clone_quoting_options (struct quoting_options *o)
|
||||
{
|
||||
struct quoting_options *p
|
||||
= (struct quoting_options *) xmalloc (sizeof (struct quoting_options));
|
||||
*p = *(o ? o : &default_quoting_options);
|
||||
return p;
|
||||
}
|
||||
|
||||
/* Get the value of O's quoting style. If O is null, use the default. */
|
||||
enum quoting_style
|
||||
get_quoting_style (struct quoting_options *o)
|
||||
{
|
||||
return (o ? o : &default_quoting_options)->style;
|
||||
}
|
||||
|
||||
/* In O (or in the default if O is null),
|
||||
set the value of the quoting style to S. */
|
||||
void
|
||||
set_quoting_style (struct quoting_options *o, enum quoting_style s)
|
||||
{
|
||||
(o ? o : &default_quoting_options)->style = s;
|
||||
}
|
||||
|
||||
/* In O (or in the default if O is null),
|
||||
set the value of the quoting options for character C to I.
|
||||
Return the old value. Currently, the only values defined for I are
|
||||
0 (the default) and 1 (which means to quote the character even if
|
||||
it would not otherwise be quoted). */
|
||||
int
|
||||
set_char_quoting (struct quoting_options *o, char c, int i)
|
||||
{
|
||||
unsigned char uc = c;
|
||||
int *p = (o ? o : &default_quoting_options)->quote_these_too + uc / INT_BITS;
|
||||
int shift = uc % INT_BITS;
|
||||
int r = (*p >> shift) & 1;
|
||||
*p ^= ((i & 1) ^ r) << shift;
|
||||
return r;
|
||||
}
|
||||
|
||||
/* MSGID approximates a quotation mark. Return its translation if it
|
||||
has one; otherwise, return either it or "\"", depending on S. */
|
||||
static char const *
|
||||
gettext_quote (char const *msgid, enum quoting_style s)
|
||||
{
|
||||
char const *translation = _(msgid);
|
||||
if (translation == msgid && s == clocale_quoting_style)
|
||||
translation = "\"";
|
||||
return translation;
|
||||
}
|
||||
|
||||
/* Place into buffer BUFFER (of size BUFFERSIZE) a quoted version of
|
||||
argument ARG (of size ARGSIZE), using QUOTING_STYLE and the
|
||||
non-quoting-style part of O to control quoting.
|
||||
Terminate the output with a null character, and return the written
|
||||
size of the output, not counting the terminating null.
|
||||
If BUFFERSIZE is too small to store the output string, return the
|
||||
value that would have been returned had BUFFERSIZE been large enough.
|
||||
If ARGSIZE is -1, use the string length of the argument for ARGSIZE.
|
||||
|
||||
This function acts like quotearg_buffer (BUFFER, BUFFERSIZE, ARG,
|
||||
ARGSIZE, O), except it uses QUOTING_STYLE instead of the quoting
|
||||
style specified by O, and O may not be null. */
|
||||
|
||||
static size_t
|
||||
quotearg_buffer_restyled (char *buffer, size_t buffersize,
|
||||
char const *arg, size_t argsize,
|
||||
enum quoting_style quoting_style,
|
||||
struct quoting_options const *o)
|
||||
{
|
||||
size_t i;
|
||||
size_t len = 0;
|
||||
char const *quote_string = 0;
|
||||
size_t quote_string_len = 0;
|
||||
int backslash_escapes = 0;
|
||||
int unibyte_locale = MB_CUR_MAX == 1;
|
||||
|
||||
#define STORE(c) \
|
||||
do \
|
||||
{ \
|
||||
if (len < buffersize) \
|
||||
buffer[len] = (c); \
|
||||
len++; \
|
||||
} \
|
||||
while (0)
|
||||
|
||||
switch (quoting_style)
|
||||
{
|
||||
case c_quoting_style:
|
||||
STORE ('"');
|
||||
backslash_escapes = 1;
|
||||
quote_string = "\"";
|
||||
quote_string_len = 1;
|
||||
break;
|
||||
|
||||
case escape_quoting_style:
|
||||
backslash_escapes = 1;
|
||||
break;
|
||||
|
||||
case locale_quoting_style:
|
||||
case clocale_quoting_style:
|
||||
{
|
||||
/* Get translations for open and closing quotation marks.
|
||||
|
||||
The message catalog should translate "`" to a left
|
||||
quotation mark suitable for the locale, and similarly for
|
||||
"'". If the catalog has no translation,
|
||||
locale_quoting_style quotes `like this', and
|
||||
clocale_quoting_style quotes "like this".
|
||||
|
||||
For example, an American English Unicode locale should
|
||||
translate "`" to U+201C (LEFT DOUBLE QUOTATION MARK), and
|
||||
should translate "'" to U+201D (RIGHT DOUBLE QUOTATION
|
||||
MARK). A British English Unicode locale should instead
|
||||
translate these to U+2018 (LEFT SINGLE QUOTATION MARK) and
|
||||
U+2019 (RIGHT SINGLE QUOTATION MARK), respectively. */
|
||||
|
||||
char const *left = gettext_quote (N_("`"), quoting_style);
|
||||
char const *right = gettext_quote (N_("'"), quoting_style);
|
||||
for (quote_string = left; *quote_string; quote_string++)
|
||||
STORE (*quote_string);
|
||||
backslash_escapes = 1;
|
||||
quote_string = right;
|
||||
quote_string_len = strlen (quote_string);
|
||||
}
|
||||
break;
|
||||
|
||||
case shell_always_quoting_style:
|
||||
STORE ('\'');
|
||||
quote_string = "'";
|
||||
quote_string_len = 1;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
for (i = 0; ! (argsize == (size_t) -1 ? arg[i] == '\0' : i == argsize); i++)
|
||||
{
|
||||
unsigned char c;
|
||||
unsigned char esc;
|
||||
|
||||
if (backslash_escapes
|
||||
&& quote_string_len
|
||||
&& i + quote_string_len <= argsize
|
||||
&& memcmp (arg + i, quote_string, quote_string_len) == 0)
|
||||
STORE ('\\');
|
||||
|
||||
c = arg[i];
|
||||
switch (c)
|
||||
{
|
||||
case '?':
|
||||
switch (quoting_style)
|
||||
{
|
||||
case shell_quoting_style:
|
||||
goto use_shell_always_quoting_style;
|
||||
|
||||
case c_quoting_style:
|
||||
if (i + 2 < argsize && arg[i + 1] == '?')
|
||||
switch (arg[i + 2])
|
||||
{
|
||||
case '!': case '\'':
|
||||
case '(': case ')': case '-': case '/':
|
||||
case '<': case '=': case '>':
|
||||
/* Escape the second '?' in what would otherwise be
|
||||
a trigraph. */
|
||||
i += 2;
|
||||
c = arg[i + 2];
|
||||
STORE ('?');
|
||||
STORE ('\\');
|
||||
STORE ('?');
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case ALERT_CHAR: esc = 'a'; goto c_escape;
|
||||
case '\b': esc = 'b'; goto c_escape;
|
||||
case '\f': esc = 'f'; goto c_escape;
|
||||
case '\n': esc = 'n'; goto c_and_shell_escape;
|
||||
case '\r': esc = 'r'; goto c_and_shell_escape;
|
||||
case '\t': esc = 't'; goto c_and_shell_escape;
|
||||
case '\v': esc = 'v'; goto c_escape;
|
||||
case '\\': esc = c; goto c_and_shell_escape;
|
||||
|
||||
c_and_shell_escape:
|
||||
if (quoting_style == shell_quoting_style)
|
||||
goto use_shell_always_quoting_style;
|
||||
c_escape:
|
||||
if (backslash_escapes)
|
||||
{
|
||||
c = esc;
|
||||
goto store_escape;
|
||||
}
|
||||
break;
|
||||
|
||||
case '#': case '~':
|
||||
if (i != 0)
|
||||
break;
|
||||
/* Fall through. */
|
||||
case ' ':
|
||||
case '!': /* special in bash */
|
||||
case '"': case '$': case '&':
|
||||
case '(': case ')': case '*': case ';':
|
||||
case '<': case '>': case '[':
|
||||
case '^': /* special in old /bin/sh, e.g. SunOS 4.1.4 */
|
||||
case '`': case '|':
|
||||
/* A shell special character. In theory, '$' and '`' could
|
||||
be the first bytes of multibyte characters, which means
|
||||
we should check them with mbrtowc, but in practice this
|
||||
doesn't happen so it's not worth worrying about. */
|
||||
if (quoting_style == shell_quoting_style)
|
||||
goto use_shell_always_quoting_style;
|
||||
break;
|
||||
|
||||
case '\'':
|
||||
switch (quoting_style)
|
||||
{
|
||||
case shell_quoting_style:
|
||||
goto use_shell_always_quoting_style;
|
||||
|
||||
case shell_always_quoting_style:
|
||||
STORE ('\'');
|
||||
STORE ('\\');
|
||||
STORE ('\'');
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case '%': case '+': case ',': case '-': case '.': case '/':
|
||||
case '0': case '1': case '2': case '3': case '4': case '5':
|
||||
case '6': case '7': case '8': case '9': case ':': case '=':
|
||||
case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
|
||||
case 'G': case 'H': case 'I': case 'J': case 'K': case 'L':
|
||||
case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R':
|
||||
case 'S': case 'T': case 'U': case 'V': case 'W': case 'X':
|
||||
case 'Y': case 'Z': case ']': case '_': case 'a': case 'b':
|
||||
case 'c': case 'd': case 'e': case 'f': case 'g': case 'h':
|
||||
case 'i': case 'j': case 'k': case 'l': case 'm': case 'n':
|
||||
case 'o': case 'p': case 'q': case 'r': case 's': case 't':
|
||||
case 'u': case 'v': case 'w': case 'x': case 'y': case 'z':
|
||||
case '{': case '}':
|
||||
/* These characters don't cause problems, no matter what the
|
||||
quoting style is. They cannot start multibyte sequences. */
|
||||
break;
|
||||
|
||||
default:
|
||||
/* If we have a multibyte sequence, copy it until we reach
|
||||
its end, find an error, or come back to the initial shift
|
||||
state. For C-like styles, if the sequence has
|
||||
unprintable characters, escape the whole sequence, since
|
||||
we can't easily escape single characters within it. */
|
||||
{
|
||||
/* Length of multibyte sequence found so far. */
|
||||
size_t m;
|
||||
|
||||
int printable;
|
||||
|
||||
if (unibyte_locale)
|
||||
{
|
||||
m = 1;
|
||||
printable = ISPRINT (c);
|
||||
}
|
||||
else
|
||||
{
|
||||
mbstate_t mbstate;
|
||||
memset (&mbstate, 0, sizeof mbstate);
|
||||
|
||||
m = 0;
|
||||
printable = 1;
|
||||
if (argsize == (size_t) -1)
|
||||
argsize = strlen (arg);
|
||||
|
||||
do
|
||||
{
|
||||
wchar_t w;
|
||||
size_t bytes = mbrtowc (&w, &arg[i + m],
|
||||
argsize - (i + m), &mbstate);
|
||||
if (bytes == 0)
|
||||
break;
|
||||
else if (bytes == (size_t) -1)
|
||||
{
|
||||
printable = 0;
|
||||
break;
|
||||
}
|
||||
else if (bytes == (size_t) -2)
|
||||
{
|
||||
printable = 0;
|
||||
while (i + m < argsize && arg[i + m])
|
||||
m++;
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (! iswprint (w))
|
||||
printable = 0;
|
||||
m += bytes;
|
||||
}
|
||||
}
|
||||
while (! mbsinit (&mbstate));
|
||||
}
|
||||
|
||||
if (1 < m || (backslash_escapes && ! printable))
|
||||
{
|
||||
/* Output a multibyte sequence, or an escaped
|
||||
unprintable unibyte character. */
|
||||
size_t ilim = i + m;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
if (backslash_escapes && ! printable)
|
||||
{
|
||||
STORE ('\\');
|
||||
STORE ('0' + (c >> 6));
|
||||
STORE ('0' + ((c >> 3) & 7));
|
||||
c = '0' + (c & 7);
|
||||
}
|
||||
if (ilim <= i + 1)
|
||||
break;
|
||||
STORE (c);
|
||||
c = arg[++i];
|
||||
}
|
||||
|
||||
goto store_c;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (! (backslash_escapes
|
||||
&& o->quote_these_too[c / INT_BITS] & (1 << (c % INT_BITS))))
|
||||
goto store_c;
|
||||
|
||||
store_escape:
|
||||
STORE ('\\');
|
||||
|
||||
store_c:
|
||||
STORE (c);
|
||||
}
|
||||
|
||||
if (quote_string)
|
||||
for (; *quote_string; quote_string++)
|
||||
STORE (*quote_string);
|
||||
|
||||
if (len < buffersize)
|
||||
buffer[len] = '\0';
|
||||
return len;
|
||||
|
||||
use_shell_always_quoting_style:
|
||||
return quotearg_buffer_restyled (buffer, buffersize, arg, argsize,
|
||||
shell_always_quoting_style, o);
|
||||
}
|
||||
|
||||
/* Place into buffer BUFFER (of size BUFFERSIZE) a quoted version of
|
||||
argument ARG (of size ARGSIZE), using O to control quoting.
|
||||
If O is null, use the default.
|
||||
Terminate the output with a null character, and return the written
|
||||
size of the output, not counting the terminating null.
|
||||
If BUFFERSIZE is too small to store the output string, return the
|
||||
value that would have been returned had BUFFERSIZE been large enough.
|
||||
If ARGSIZE is -1, use the string length of the argument for ARGSIZE. */
|
||||
size_t
|
||||
quotearg_buffer (char *buffer, size_t buffersize,
|
||||
char const *arg, size_t argsize,
|
||||
struct quoting_options const *o)
|
||||
{
|
||||
struct quoting_options const *p = o ? o : &default_quoting_options;
|
||||
return quotearg_buffer_restyled (buffer, buffersize, arg, argsize,
|
||||
p->style, p);
|
||||
}
|
||||
|
||||
/* Use storage slot N to return a quoted version of the string ARG.
|
||||
OPTIONS specifies the quoting options.
|
||||
The returned value points to static storage that can be
|
||||
reused by the next call to this function with the same value of N.
|
||||
N must be nonnegative. N is deliberately declared with type "int"
|
||||
to allow for future extensions (using negative values). */
|
||||
static char *
|
||||
quotearg_n_options (int n, char const *arg,
|
||||
struct quoting_options const *options)
|
||||
{
|
||||
/* Preallocate a slot 0 buffer, so that the caller can always quote
|
||||
one small component of a "memory exhausted" message in slot 0. */
|
||||
static char slot0[256];
|
||||
static unsigned int nslots = 1;
|
||||
struct slotvec
|
||||
{
|
||||
size_t size;
|
||||
char *val;
|
||||
};
|
||||
static struct slotvec slotvec0 = {sizeof slot0, slot0};
|
||||
static struct slotvec *slotvec = &slotvec0;
|
||||
|
||||
if (nslots <= n)
|
||||
{
|
||||
int n1 = n + 1;
|
||||
size_t s = n1 * sizeof (struct slotvec);
|
||||
if (! (0 < n1 && n1 == s / sizeof (struct slotvec)))
|
||||
abort ();
|
||||
if (slotvec == &slotvec0)
|
||||
{
|
||||
slotvec = (struct slotvec *) xmalloc (sizeof (struct slotvec));
|
||||
*slotvec = slotvec0;
|
||||
}
|
||||
slotvec = (struct slotvec *) xrealloc (slotvec, s);
|
||||
memset (slotvec + nslots, 0, (n1 - nslots) * sizeof (struct slotvec));
|
||||
nslots = n;
|
||||
}
|
||||
|
||||
{
|
||||
size_t size = slotvec[n].size;
|
||||
char *val = slotvec[n].val;
|
||||
size_t qsize = quotearg_buffer (val, size, arg, (size_t) -1, options);
|
||||
|
||||
if (size <= qsize)
|
||||
{
|
||||
slotvec[n].size = size = qsize + 1;
|
||||
slotvec[n].val = val = xrealloc (val == slot0 ? 0 : val, size);
|
||||
quotearg_buffer (val, size, arg, (size_t) -1, options);
|
||||
}
|
||||
|
||||
return val;
|
||||
}
|
||||
}
|
||||
|
||||
char *
|
||||
quotearg_n (unsigned int n, char const *arg)
|
||||
{
|
||||
return quotearg_n_options (n, arg, &default_quoting_options);
|
||||
}
|
||||
|
||||
char *
|
||||
quotearg (char const *arg)
|
||||
{
|
||||
return quotearg_n (0, arg);
|
||||
}
|
||||
|
||||
char *
|
||||
quotearg_n_style (unsigned int n, enum quoting_style s, char const *arg)
|
||||
{
|
||||
struct quoting_options o;
|
||||
o.style = s;
|
||||
memset (o.quote_these_too, 0, sizeof o.quote_these_too);
|
||||
return quotearg_n_options (n, arg, &o);
|
||||
}
|
||||
|
||||
char *
|
||||
quotearg_style (enum quoting_style s, char const *arg)
|
||||
{
|
||||
return quotearg_n_style (0, s, arg);
|
||||
}
|
||||
|
||||
char *
|
||||
quotearg_char (char const *arg, char ch)
|
||||
{
|
||||
struct quoting_options options;
|
||||
options = default_quoting_options;
|
||||
set_char_quoting (&options, ch, 1);
|
||||
return quotearg_n_options (0, arg, &options);
|
||||
}
|
||||
|
||||
char *
|
||||
quotearg_colon (char const *arg)
|
||||
{
|
||||
return quotearg_char (arg, ':');
|
||||
}
|
@ -1,110 +0,0 @@
|
||||
/* quotearg.h - quote arguments for output
|
||||
Copyright (C) 1998, 1999, 2000 Free Software Foundation, Inc.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software Foundation,
|
||||
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
||||
|
||||
/* Written by Paul Eggert <eggert@twinsun.com> */
|
||||
|
||||
/* Basic quoting styles. */
|
||||
enum quoting_style
|
||||
{
|
||||
literal_quoting_style, /* --quoting-style=literal */
|
||||
shell_quoting_style, /* --quoting-style=shell */
|
||||
shell_always_quoting_style, /* --quoting-style=shell-always */
|
||||
c_quoting_style, /* --quoting-style=c */
|
||||
escape_quoting_style, /* --quoting-style=escape */
|
||||
locale_quoting_style, /* --quoting-style=locale */
|
||||
clocale_quoting_style /* --quoting-style=clocale */
|
||||
};
|
||||
|
||||
/* For now, --quoting-style=literal is the default, but this may change. */
|
||||
#ifndef DEFAULT_QUOTING_STYLE
|
||||
# define DEFAULT_QUOTING_STYLE literal_quoting_style
|
||||
#endif
|
||||
|
||||
/* Names of quoting styles and their corresponding values. */
|
||||
extern char const *const quoting_style_args[];
|
||||
extern enum quoting_style const quoting_style_vals[];
|
||||
|
||||
struct quoting_options;
|
||||
|
||||
#ifndef PARAMS
|
||||
# if defined PROTOTYPES || defined __STDC__
|
||||
# define PARAMS(Args) Args
|
||||
# else
|
||||
# define PARAMS(Args) ()
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* The functions listed below set and use a hidden variable
|
||||
that contains the default quoting style options. */
|
||||
|
||||
/* Allocate a new set of quoting options, with contents initially identical
|
||||
to O if O is not null, or to the default if O is null.
|
||||
It is the caller's responsibility to free the result. */
|
||||
struct quoting_options *clone_quoting_options
|
||||
PARAMS ((struct quoting_options *o));
|
||||
|
||||
/* Get the value of O's quoting style. If O is null, use the default. */
|
||||
enum quoting_style get_quoting_style PARAMS ((struct quoting_options *o));
|
||||
|
||||
/* In O (or in the default if O is null),
|
||||
set the value of the quoting style to S. */
|
||||
void set_quoting_style PARAMS ((struct quoting_options *o,
|
||||
enum quoting_style s));
|
||||
|
||||
/* In O (or in the default if O is null),
|
||||
set the value of the quoting options for character C to I.
|
||||
Return the old value. Currently, the only values defined for I are
|
||||
0 (the default) and 1 (which means to quote the character even if
|
||||
it would not otherwise be quoted). */
|
||||
int set_char_quoting PARAMS ((struct quoting_options *o, char c, int i));
|
||||
|
||||
/* Place into buffer BUFFER (of size BUFFERSIZE) a quoted version of
|
||||
argument ARG (of size ARGSIZE), using O to control quoting.
|
||||
If O is null, use the default.
|
||||
Terminate the output with a null character, and return the written
|
||||
size of the output, not counting the terminating null.
|
||||
If BUFFERSIZE is too small to store the output string, return the
|
||||
value that would have been returned had BUFFERSIZE been large enough.
|
||||
If ARGSIZE is -1, use the string length of the argument for ARGSIZE. */
|
||||
size_t quotearg_buffer PARAMS ((char *buffer, size_t buffersize,
|
||||
char const *arg, size_t argsize,
|
||||
struct quoting_options const *o));
|
||||
|
||||
/* Use storage slot N to return a quoted version of the string ARG.
|
||||
Use the default quoting options.
|
||||
The returned value points to static storage that can be
|
||||
reused by the next call to this function with the same value of N.
|
||||
N must be nonnegative. */
|
||||
char *quotearg_n PARAMS ((unsigned int n, char const *arg));
|
||||
|
||||
/* Equivalent to quotearg_n (0, ARG). */
|
||||
char *quotearg PARAMS ((char const *arg));
|
||||
|
||||
/* Use style S and storage slot N to return a quoted version of the string ARG.
|
||||
This is like quotearg_n (N, ARG), except that it uses S with no other
|
||||
options to specify the quoting method. */
|
||||
char *quotearg_n_style PARAMS ((unsigned int n, enum quoting_style s,
|
||||
char const *arg));
|
||||
|
||||
/* Equivalent to quotearg_n_style (0, S, ARG). */
|
||||
char *quotearg_style PARAMS ((enum quoting_style s, char const *arg));
|
||||
|
||||
/* Like quotearg (ARG), except also quote any instances of CH. */
|
||||
char *quotearg_char PARAMS ((char const *arg, char ch));
|
||||
|
||||
/* Equivalent to quotearg_char (ARG, ':'). */
|
||||
char *quotearg_colon PARAMS ((char const *arg));
|
@ -1,183 +0,0 @@
|
||||
/* savedir.c -- save the list of files in a directory in a string
|
||||
Copyright (C) 1990, 1997, 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software Foundation,
|
||||
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
||||
|
||||
/* Written by David MacKenzie <djm@gnu.ai.mit.edu>. */
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#if HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#if HAVE_UNISTD_H
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
|
||||
#if HAVE_DIRENT_H
|
||||
# include <dirent.h>
|
||||
# define NAMLEN(dirent) strlen((dirent)->d_name)
|
||||
#else
|
||||
# define dirent direct
|
||||
# define NAMLEN(dirent) (dirent)->d_namlen
|
||||
# if HAVE_SYS_NDIR_H
|
||||
# include <sys/ndir.h>
|
||||
# endif
|
||||
# if HAVE_SYS_DIR_H
|
||||
# include <sys/dir.h>
|
||||
# endif
|
||||
# if HAVE_NDIR_H
|
||||
# include <ndir.h>
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifdef CLOSEDIR_VOID
|
||||
/* Fake a return value. */
|
||||
# define CLOSEDIR(d) (closedir (d), 0)
|
||||
#else
|
||||
# define CLOSEDIR(d) closedir (d)
|
||||
#endif
|
||||
|
||||
#ifdef STDC_HEADERS
|
||||
# include <stdlib.h>
|
||||
# include <string.h>
|
||||
#else
|
||||
char *malloc ();
|
||||
char *realloc ();
|
||||
#endif
|
||||
#ifndef NULL
|
||||
# define NULL 0
|
||||
#endif
|
||||
|
||||
#ifndef stpcpy
|
||||
char *stpcpy ();
|
||||
#endif
|
||||
|
||||
#include <fnmatch.h>
|
||||
#include "savedir.h"
|
||||
#include "system.h"
|
||||
|
||||
char *path;
|
||||
size_t pathlen;
|
||||
|
||||
static int
|
||||
isdir1 (const char *dir, const char *file)
|
||||
{
|
||||
int status;
|
||||
int slash;
|
||||
size_t dirlen = strlen (dir);
|
||||
size_t filelen = strlen (file);
|
||||
if ((dirlen + filelen + 2) > pathlen)
|
||||
{
|
||||
path = calloc (dirlen + 1 + filelen + 1, sizeof (*path));
|
||||
pathlen = dirlen + filelen + 2;
|
||||
}
|
||||
strcpy (path, dir);
|
||||
slash = (path[dirlen] != '/');
|
||||
path[dirlen] = '/';
|
||||
strcpy (path + dirlen + slash , file);
|
||||
status = isdir (path);
|
||||
return status;
|
||||
}
|
||||
|
||||
/* Return a freshly allocated string containing the filenames
|
||||
in directory DIR, separated by '\0' characters;
|
||||
the end is marked by two '\0' characters in a row.
|
||||
NAME_SIZE is the number of bytes to initially allocate
|
||||
for the string; it will be enlarged as needed.
|
||||
Return NULL if DIR cannot be opened or if out of memory. */
|
||||
char *
|
||||
savedir (const char *dir, off_t name_size, struct exclude *included_patterns,
|
||||
struct exclude *excluded_patterns)
|
||||
{
|
||||
DIR *dirp;
|
||||
struct dirent *dp;
|
||||
char *name_space;
|
||||
char *namep;
|
||||
|
||||
dirp = opendir (dir);
|
||||
if (dirp == NULL)
|
||||
return NULL;
|
||||
|
||||
/* Be sure name_size is at least `1' so there's room for
|
||||
the final NUL byte. */
|
||||
if (name_size <= 0)
|
||||
name_size = 1;
|
||||
|
||||
name_space = (char *) malloc (name_size);
|
||||
if (name_space == NULL)
|
||||
{
|
||||
closedir (dirp);
|
||||
return NULL;
|
||||
}
|
||||
namep = name_space;
|
||||
|
||||
while ((dp = readdir (dirp)) != NULL)
|
||||
{
|
||||
/* Skip "." and ".." (some NFS filesystems' directories lack them). */
|
||||
if (dp->d_name[0] != '.'
|
||||
|| (dp->d_name[1] != '\0'
|
||||
&& (dp->d_name[1] != '.' || dp->d_name[2] != '\0')))
|
||||
{
|
||||
off_t size_needed = (namep - name_space) + NAMLEN (dp) + 2;
|
||||
|
||||
if ((included_patterns || excluded_patterns)
|
||||
&& !isdir1 (dir, dp->d_name))
|
||||
{
|
||||
if (included_patterns
|
||||
&& !excluded_filename (included_patterns, path, 0))
|
||||
continue;
|
||||
if (excluded_patterns
|
||||
&& excluded_filename (excluded_patterns, path, 0))
|
||||
continue;
|
||||
}
|
||||
|
||||
if (size_needed > name_size)
|
||||
{
|
||||
char *new_name_space;
|
||||
|
||||
while (size_needed > name_size)
|
||||
name_size += 1024;
|
||||
|
||||
new_name_space = realloc (name_space, name_size);
|
||||
if (new_name_space == NULL)
|
||||
{
|
||||
closedir (dirp);
|
||||
return NULL;
|
||||
}
|
||||
namep += new_name_space - name_space;
|
||||
name_space = new_name_space;
|
||||
}
|
||||
namep = stpcpy (namep, dp->d_name) + 1;
|
||||
}
|
||||
}
|
||||
*namep = '\0';
|
||||
if (CLOSEDIR (dirp))
|
||||
{
|
||||
free (name_space);
|
||||
return NULL;
|
||||
}
|
||||
if (path)
|
||||
{
|
||||
free (path);
|
||||
path = NULL;
|
||||
pathlen = 0;
|
||||
}
|
||||
return name_space;
|
||||
}
|
@ -1,18 +0,0 @@
|
||||
#if !defined SAVEDIR_H_
|
||||
# define SAVEDIR_H_
|
||||
|
||||
#include "exclude.h"
|
||||
|
||||
# ifndef PARAMS
|
||||
# if defined PROTOTYPES || (defined __STDC__ && __STDC__)
|
||||
# define PARAMS(Args) Args
|
||||
# else
|
||||
# define PARAMS(Args) ()
|
||||
# endif
|
||||
# endif
|
||||
|
||||
extern char *
|
||||
savedir PARAMS ((const char *dir, off_t name_size,
|
||||
struct exclude *, struct exclude *));
|
||||
|
||||
#endif
|
File diff suppressed because it is too large
Load Diff
@ -1,206 +0,0 @@
|
||||
/* Portability cruft. Include after config.h and sys/types.h.
|
||||
Copyright 1996, 1998, 1999, 2000 Free Software Foundation, Inc.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
||||
02111-1307, USA. */
|
||||
|
||||
#undef PARAMS
|
||||
#if defined (__STDC__) && __STDC__
|
||||
# ifndef _PTR_T
|
||||
# define _PTR_T
|
||||
typedef void * ptr_t;
|
||||
# endif
|
||||
# define PARAMS(x) x
|
||||
#else
|
||||
# ifndef _PTR_T
|
||||
# define _PTR_T
|
||||
typedef char * ptr_t;
|
||||
# endif
|
||||
# define PARAMS(x) ()
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_UNISTD_H
|
||||
# include <fcntl.h>
|
||||
# include <unistd.h>
|
||||
#else
|
||||
# define O_RDONLY 0
|
||||
# define SEEK_SET 0
|
||||
# define SEEK_CUR 1
|
||||
int open(), read(), close();
|
||||
#endif
|
||||
|
||||
#include <errno.h>
|
||||
#ifndef errno
|
||||
extern int errno;
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_STRERROR
|
||||
extern int sys_nerr;
|
||||
extern char *sys_errlist[];
|
||||
# define strerror(E) (0 <= (E) && (E) < sys_nerr ? _(sys_errlist[E]) : _("Unknown system error"))
|
||||
#endif
|
||||
|
||||
/* Some operating systems treat text and binary files differently. */
|
||||
#ifdef __BEOS__
|
||||
# undef O_BINARY /* BeOS 5 has O_BINARY and O_TEXT, but they have no effect. */
|
||||
#endif
|
||||
#ifdef HAVE_DOS_FILE_CONTENTS
|
||||
# include <io.h>
|
||||
# ifdef HAVE_SETMODE
|
||||
# define SET_BINARY(fd) setmode (fd, O_BINARY)
|
||||
# else
|
||||
# define SET_BINARY(fd) _setmode (fd, O_BINARY)
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_DOS_FILE_NAMES
|
||||
# define IS_SLASH(c) ((c) == '/' || (c) == '\\')
|
||||
# define FILESYSTEM_PREFIX_LEN(f) ((f)[0] && (f)[1] == ':' ? 2 : 0)
|
||||
#endif
|
||||
|
||||
#ifndef IS_SLASH
|
||||
# define IS_SLASH(c) ((c) == '/')
|
||||
#endif
|
||||
|
||||
#ifndef FILESYSTEM_PREFIX_LEN
|
||||
# define FILESYSTEM_PREFIX_LEN(f) 0
|
||||
#endif
|
||||
|
||||
int isdir PARAMS ((char const *));
|
||||
|
||||
#ifdef HAVE_DIR_EACCES_BUG
|
||||
# ifdef EISDIR
|
||||
# define is_EISDIR(e, f) \
|
||||
((e) == EISDIR \
|
||||
|| ((e) == EACCES && isdir (f) && ((e) = EISDIR, 1)))
|
||||
# else
|
||||
# define is_EISDIR(e, f) ((e) == EACCES && isdir (f))
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef is_EISDIR
|
||||
# ifdef EISDIR
|
||||
# define is_EISDIR(e, f) ((e) == EISDIR)
|
||||
# else
|
||||
# define is_EISDIR(e, f) 0
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if STAT_MACROS_BROKEN
|
||||
# undef S_ISDIR
|
||||
# undef S_ISREG
|
||||
#endif
|
||||
#if !defined(S_ISDIR) && defined(S_IFDIR)
|
||||
# define S_ISDIR(Mode) (((Mode) & S_IFMT) == S_IFDIR)
|
||||
#endif
|
||||
#if !defined(S_ISREG) && defined(S_IFREG)
|
||||
# define S_ISREG(Mode) (((Mode) & S_IFMT) == S_IFREG)
|
||||
#endif
|
||||
|
||||
#ifdef STDC_HEADERS
|
||||
# include <stdlib.h>
|
||||
#else
|
||||
char *getenv ();
|
||||
ptr_t malloc(), realloc(), calloc();
|
||||
void free();
|
||||
#endif
|
||||
|
||||
#if __STDC__
|
||||
# include <stddef.h>
|
||||
#endif
|
||||
#ifdef STDC_HEADERS
|
||||
# include <limits.h>
|
||||
#endif
|
||||
#ifndef CHAR_BIT
|
||||
# define CHAR_BIT 8
|
||||
#endif
|
||||
/* The extra casts work around common compiler bugs. */
|
||||
#define TYPE_SIGNED(t) (! ((t) 0 < (t) -1))
|
||||
#define TYPE_MINIMUM(t) ((t) (TYPE_SIGNED (t) \
|
||||
? ~ (t) 0 << (sizeof (t) * CHAR_BIT - 1) \
|
||||
: (t) 0))
|
||||
#define TYPE_MAXIMUM(t) ((t) (~ (t) 0 - TYPE_MINIMUM (t)))
|
||||
#ifndef CHAR_MAX
|
||||
# define CHAR_MAX TYPE_MAXIMUM (char)
|
||||
#endif
|
||||
#ifndef INT_MAX
|
||||
# define INT_MAX TYPE_MAXIMUM (int)
|
||||
#endif
|
||||
#ifndef UCHAR_MAX
|
||||
# define UCHAR_MAX TYPE_MAXIMUM (unsigned char)
|
||||
#endif
|
||||
|
||||
#if !defined(STDC_HEADERS) && defined(HAVE_STRING_H) && defined(HAVE_MEMORY_H)
|
||||
# include <memory.h>
|
||||
#endif
|
||||
#if defined(STDC_HEADERS) || defined(HAVE_STRING_H)
|
||||
# include <string.h>
|
||||
#else
|
||||
# include <strings.h>
|
||||
# undef strchr
|
||||
# define strchr index
|
||||
# undef strrchr
|
||||
# define strrchr rindex
|
||||
# undef memcpy
|
||||
# define memcpy(d, s, n) bcopy (s, d, n)
|
||||
#endif
|
||||
#ifndef HAVE_MEMCHR
|
||||
ptr_t memchr();
|
||||
#endif
|
||||
#if ! defined HAVE_MEMMOVE && ! defined memmove
|
||||
# define memmove(d, s, n) bcopy (s, d, n)
|
||||
#endif
|
||||
|
||||
#include <ctype.h>
|
||||
|
||||
#ifndef isgraph
|
||||
# define isgraph(C) (isprint(C) && !isspace(C))
|
||||
#endif
|
||||
|
||||
#if defined (STDC_HEADERS) || (!defined (isascii) && !defined (HAVE_ISASCII))
|
||||
# define IN_CTYPE_DOMAIN(c) 1
|
||||
#else
|
||||
# define IN_CTYPE_DOMAIN(c) isascii(c)
|
||||
#endif
|
||||
|
||||
#define ISALPHA(C) (IN_CTYPE_DOMAIN (C) && isalpha (C))
|
||||
#define ISUPPER(C) (IN_CTYPE_DOMAIN (C) && isupper (C))
|
||||
#define ISLOWER(C) (IN_CTYPE_DOMAIN (C) && islower (C))
|
||||
#define ISDIGIT(C) (IN_CTYPE_DOMAIN (C) && isdigit (C))
|
||||
#define ISXDIGIT(C) (IN_CTYPE_DOMAIN (C) && isxdigit (C))
|
||||
#define ISSPACE(C) (IN_CTYPE_DOMAIN (C) && isspace (C))
|
||||
#define ISPUNCT(C) (IN_CTYPE_DOMAIN (C) && ispunct (C))
|
||||
#define ISALNUM(C) (IN_CTYPE_DOMAIN (C) && isalnum (C))
|
||||
#define ISPRINT(C) (IN_CTYPE_DOMAIN (C) && isprint (C))
|
||||
#define ISGRAPH(C) (IN_CTYPE_DOMAIN (C) && isgraph (C))
|
||||
#define ISCNTRL(C) (IN_CTYPE_DOMAIN (C) && iscntrl (C))
|
||||
|
||||
#define TOLOWER(C) (ISUPPER(C) ? tolower(C) : (C))
|
||||
|
||||
#if ENABLE_NLS
|
||||
# include <libintl.h>
|
||||
# define _(String) gettext (String)
|
||||
#else
|
||||
# define _(String) String
|
||||
#endif
|
||||
#define N_(String) String
|
||||
|
||||
#if HAVE_SETLOCALE
|
||||
# include <locale.h>
|
||||
#endif
|
||||
|
||||
#ifndef initialize_main
|
||||
#define initialize_main(argcp, argvp)
|
||||
#endif
|
@ -1,38 +0,0 @@
|
||||
#!/bin/sh
|
||||
# Test that backrefs are local to regex.
|
||||
#
|
||||
#
|
||||
|
||||
: ${srcdir=.}
|
||||
|
||||
failures=0
|
||||
|
||||
# checking for a palindrome
|
||||
echo "radar" | ${GREP} -e '\(.\)\(.\).\2\1' > /dev/null 2>&1
|
||||
if test $? -ne 0 ; then
|
||||
echo "backref: palindrome, test \#1 failed"
|
||||
failures=1
|
||||
fi
|
||||
|
||||
# hit hard with the `Bond' tests
|
||||
echo "civic" | ${GREP} -E -e '^(.?)(.?)(.?)(.?)(.?)(.?)(.?)(.?)(.?).?\9\8\7\6\5\4\3\2\1$' > /dev/null 2>&1
|
||||
if test $? -ne 0 ; then
|
||||
echo "Options: Bond, test \#2 failed"
|
||||
failures=1
|
||||
fi
|
||||
|
||||
# backref are local should be error
|
||||
echo "123" | ${GREP} -e 'a\(.\)' -e 'b\1' > /dev/null 2>&1
|
||||
if test $? -ne 2 ; then
|
||||
echo "Options: Backref not local, test \#3 failed"
|
||||
failures=1
|
||||
fi
|
||||
|
||||
# Pattern should faile
|
||||
echo "123" | ${GREP} -e '[' -e ']' > /dev/null 2>&1
|
||||
if test $? -ne 2 ; then
|
||||
echo "Options: Compiled not local, test \#3 failed"
|
||||
failures=1
|
||||
fi
|
||||
|
||||
exit $failures
|
@ -1,27 +0,0 @@
|
||||
BEGIN {
|
||||
FS="@";
|
||||
n = 0;
|
||||
printf ("# Generated Spencer BRE Test\n");
|
||||
printf ("failures=0\n");
|
||||
}
|
||||
|
||||
$0 ~ /^#/ { next; }
|
||||
|
||||
NF == 3 {
|
||||
# printf ("status=`echo '%s' | { ${GREP} -e '%s' > /dev/null 2>&1; echo $?; cat >/dev/null; }`\n",$3, $2);
|
||||
printf ("status=`echo '%s' | { ${GREP} -e '%s' > /dev/null 2>&1; echo $? ; }`\n",$3, $2);
|
||||
printf ("if test $status -ne %s ; then\n", $1);
|
||||
printf ("\techo Spencer bre test \\#%d failed\n", ++n);
|
||||
printf ("\tfailures=1\n");
|
||||
printf ("fi\n");
|
||||
}
|
||||
|
||||
NF == 4 {
|
||||
#don't alarm users
|
||||
# printf ("echo '%s' | ${GREP} -e '%s' > /dev/null 2>&1\n",$3, $2);
|
||||
# printf ("if test $? -ne %s ; then\n", $1);
|
||||
# printf ("\techo Expected non conformance \\#%d ... continuing\n", ++n);
|
||||
# printf ("fi\n");
|
||||
}
|
||||
|
||||
END { printf ("exit $failures\n"); }
|
@ -1,13 +0,0 @@
|
||||
#!/bin/sh
|
||||
# Regression test for GNU grep.
|
||||
|
||||
: ${srcdir=.}
|
||||
|
||||
failures=0
|
||||
|
||||
# . . . and the following by Henry Spencer.
|
||||
|
||||
${AWK-awk} -f $srcdir/bre.awk $srcdir/bre.tests > bre.script
|
||||
|
||||
sh bre.script && exit $failures
|
||||
exit 1
|
@ -1,62 +0,0 @@
|
||||
0@a\(b\)c@abc
|
||||
0@a(@a(
|
||||
2@a\(@EPAREN
|
||||
2@a\(b@EPAREN
|
||||
0@a(b@a(b
|
||||
0@a)@a)
|
||||
2@a\)@EPAREN
|
||||
2@\)@EPAREN
|
||||
0@a\(\)b@ab
|
||||
0@a^b@a^b@TO CORRECT
|
||||
0@a$b@a$b
|
||||
0@\($\)\(^\)@@
|
||||
0@a*\(^b$\)c*@b
|
||||
0@|@|
|
||||
0@*@*
|
||||
0@\(\)@abc
|
||||
2@\(\{1\}a\)@BADRPT@TO CORRECT
|
||||
0@^*@*
|
||||
2@^\{1\}@BADRPT@TO CORRECT
|
||||
0@{@{
|
||||
1@a\(b*\)c\1d@abbcbd
|
||||
1@a\(b*\)c\1d@abbcbbbd
|
||||
1@^\(.\)\1@abc
|
||||
0@a\(\([bc]\)\2\)*d@abbccd
|
||||
1@a\(\([bc]\)\2\)*d@abbcbd
|
||||
0@a\(\(b\)*\2\)*d@abbbd
|
||||
0@\(a\)\1bcd@aabcd
|
||||
0@\(a\)\1bc*d@aabcd
|
||||
0@\(a\)\1bc*d@aabd
|
||||
0@\(a\)\1bc*d@aabcccd
|
||||
0@\(a\)\1bc*[ce]d@aabcccd@TO CORRECT
|
||||
0@^\(a\)\1b\(c\)*cd$@aabcccd
|
||||
0@a\(*\)b@a*b
|
||||
0@a\(**\)b@ab
|
||||
2@a\(***\)b@BADRPT@TO CORRECT
|
||||
0@*a@*a
|
||||
0@**a@a
|
||||
2@***a@BADRPT@TO CORRECT
|
||||
0@a\{1\}b@ab
|
||||
0@a\{1,\}b@ab
|
||||
0@a\{1,2\}b@aab
|
||||
2@a\{1@EBRACE
|
||||
2@a\{1a@EBRACE
|
||||
2@a\{1a\}@BADBR
|
||||
2@a\{,2\}@BADBR
|
||||
2@a\{,\}@BADBR
|
||||
2@a\{1,x\}@BADBR
|
||||
2@a\{1,x@EBRACE
|
||||
2@a\{32768\}@BADBR
|
||||
2@a\{1,0\}@BADBR
|
||||
0@ab\{0,0\}c@abcac
|
||||
0@ab\{0,1\}c@abcac
|
||||
0@ab\{0,3\}c@abbcac
|
||||
0@ab\{1,1\}c@acabc
|
||||
0@ab\{1,3\}c@acabc
|
||||
0@ab\{2,2\}c@abcabbc
|
||||
0@ab\{2,4\}c@abcabbc
|
||||
2@a\{1\}\{1\}@BADRPT@TO CORRECT
|
||||
2@a*\{1\}@BADRPT@TO CORRECT
|
||||
2@a\{1\}*@BADRPT@TO CORRECT
|
||||
1@a\(b\)?c\1d@acd
|
||||
0@-\{0,1\}[0-9]*$@-5
|
@ -1,33 +0,0 @@
|
||||
#!/bin/sh
|
||||
# test that the empty file means no pattern
|
||||
# and an empty pattern means match all.
|
||||
|
||||
: ${srcdir=.}
|
||||
|
||||
failures=0
|
||||
|
||||
for options in '-E' '-E -w' '-F -x' '-G -w -x'; do
|
||||
|
||||
# should return 0 found a match
|
||||
echo "" | ${GREP} $options -e '' > /dev/null 2>&1
|
||||
if test $? -ne 0 ; then
|
||||
echo "Status: Wrong status code, test \#1 failed ($options)"
|
||||
failures=1
|
||||
fi
|
||||
|
||||
# should return 1 found no match
|
||||
echo "abcd" | ${GREP} $options -f /dev/null > /dev/null 2>&1
|
||||
if test $? -ne 1 ; then
|
||||
echo "Status: Wrong status code, test \#2 failed ($options)"
|
||||
failures=1
|
||||
fi
|
||||
|
||||
# should return 0 found a match
|
||||
echo "abcd" | ${GREP} $options -f /dev/null -e "abcd" > /dev/null 2>&1
|
||||
if test $? -ne 0 ; then
|
||||
echo "Status: Wrong status code, test \#3 failed ($options)"
|
||||
failures=1
|
||||
fi
|
||||
done
|
||||
|
||||
exit $failures
|
@ -1,32 +0,0 @@
|
||||
BEGIN {
|
||||
FS="@";
|
||||
n = 0;
|
||||
printf ("# Generated Spencer ERE Test\n");
|
||||
printf ("failures=0\n");
|
||||
}
|
||||
|
||||
$0 ~ /^#/ { next; }
|
||||
|
||||
NF == 3 {
|
||||
# printf ("status=`echo '%s' | { ${GREP} -E -e '%s' > /dev/null 2>&1; echo $?; cat >/dev/null; }`\n",$3, $2);
|
||||
printf ("status=`echo '%s' | { ${GREP} -E -e '%s' > /dev/null 2>&1; echo $?; }`\n",$3, $2);
|
||||
printf ("if test $status -ne %s ; then\n", $1);
|
||||
printf ("\techo Spencer ere test \\#%d failed\n", ++n);
|
||||
printf ("\tfailures=1\n");
|
||||
printf ("fi\n");
|
||||
}
|
||||
|
||||
NF == 4 {
|
||||
# don't alarm the user for now
|
||||
# printf ("echo '%s'|${GREP} -E -e '%s' > /dev/null 2>&1\n",$3, $2);
|
||||
# printf ("if test $? -ne %s ; then\n", $1);
|
||||
# printf ("\techo Expected non conformance \\#%d ... continuing\n", ++n);
|
||||
# printf ("fi\n");
|
||||
}
|
||||
|
||||
NF == 5 {
|
||||
# don't alarm the user for now
|
||||
next;
|
||||
}
|
||||
|
||||
END { printf ("exit $failures\n"); }
|
@ -1,13 +0,0 @@
|
||||
#!/bin/sh
|
||||
# Regression test for GNU grep.
|
||||
|
||||
: ${srcdir=.}
|
||||
|
||||
failures=0
|
||||
|
||||
# . . . and the following by Henry Spencer.
|
||||
|
||||
${AWK-awk} -f $srcdir/ere.awk $srcdir/ere.tests > ere.script
|
||||
|
||||
sh ere.script && exit $failures
|
||||
exit 1
|
@ -1,215 +0,0 @@
|
||||
0@a@a
|
||||
0@abc@abc
|
||||
0@abc|de@abc
|
||||
0@a|b|c@abc
|
||||
0@a(b)c@abc
|
||||
2@a(@EPAREN
|
||||
0@a\(@a(
|
||||
2@a(b@EPAREN
|
||||
0@a)@a)@POSIX BOTCH
|
||||
0@)@)@POSIX BOTCH
|
||||
0@a()b@ab
|
||||
0@^abc$@abc
|
||||
1@a^b@a^b
|
||||
1@a$b@a$b
|
||||
0@^@abc
|
||||
0@$@abc
|
||||
0@^$@@
|
||||
0@$^@@
|
||||
0@^^@@
|
||||
0@$$@@
|
||||
0@a*(^b$)c*@b
|
||||
2@|@EMPTY@NO ALTERNATION
|
||||
2@*@BADRPT@TO CORRECT
|
||||
2@+@BADRPT@TO CORRECT
|
||||
2@?@BADRPT@TO CORRECT
|
||||
1@&C@PASS
|
||||
0@()@abc
|
||||
2@a||b@EMPTY@NO ALTERNATION
|
||||
2@|ab@EMPTY@NO ALTERNATION
|
||||
2@ab|@EMPTY@NO ALTERNATION
|
||||
2@(|a)b@EMPTY@NO ALTERNATION
|
||||
2@(a|)b@EMPTY@NO ALTERNATION
|
||||
2@(*a)@BADRPT@TO CORRECT
|
||||
2@(+a)@BADRPT@TO CORRECT
|
||||
2@(?a)@BADRPT@TO CORRECT
|
||||
2@({1}a)@BADRPT@TO CORRECT
|
||||
2@(a|*b)@BADRPT@NO ALTERNATION
|
||||
2@(a|+b)@BADRPT@NO ALTERNATION
|
||||
2@(a|?b)@BADRPT@NO ALTERNATION
|
||||
2@(a|{1}b)@BADRPT@NO ALTERNATION
|
||||
2@^*@BADRPT@TO CORRECT
|
||||
2@^+@BADRPT@TO CORRECT
|
||||
2@^?@BADRPT@TO CORRECT
|
||||
2@^{1}@BADRPT@TO CORRECT
|
||||
0@a.c@abc
|
||||
0@a[bc]d@abd
|
||||
0@a\*c@a*c
|
||||
0@a\\b@a\b@TO CORRECT
|
||||
0@a\\\*b@a\*b@SHELL TROUBLE
|
||||
0@a\bc@abc@TO CORRECT
|
||||
2@a\@EESCAPE@SHELL TROUBLE
|
||||
0@a\\bc@a\bc@TO CORRECT
|
||||
0@a\[b@a[b
|
||||
2@a[b@EBRACK
|
||||
0@a$@a
|
||||
1@a$@a$
|
||||
1@a\$@a@SHELL TROUBLE
|
||||
0@a\$@a$@SHELL TROUBLE
|
||||
1@a\\$@a
|
||||
1@a\\$@a$@SHELL TROUBLE
|
||||
1@a\\$@a\$@SHELL TROUBLE
|
||||
0@a\\$@a\@SHEL TROUBLE
|
||||
0@ab*c@abc
|
||||
0@ab+c@abc
|
||||
0@ab?c@abc
|
||||
0@{@{@TO CORRECT
|
||||
0@{abc@{abc@TO CORRECT
|
||||
0@{1@{1
|
||||
2@{1}@BADRPT@TO CORRECT
|
||||
0@a{b@a{b@TO CORRECT
|
||||
0@a{1}b@ab
|
||||
0@a{1,}b@ab
|
||||
0@a{1,2}b@aab
|
||||
0@a{1@a{1
|
||||
1@a{1a@aa
|
||||
0@a{1a}@a{1a}
|
||||
0@a{,2}@a{,2}
|
||||
0@a{,}@a{,}
|
||||
0@a{1,*}@a{1,,,}
|
||||
2@a{1,x@EBRACE@TO CORRECT
|
||||
2@a{300}@BADBR@TO CORRECT
|
||||
2@a{1,0}@BADBR@TO CORRECT
|
||||
0@ab{0,0}c@abcac
|
||||
0@ab{0,1}c@abcac
|
||||
0@ab{0,3}c@abbcac
|
||||
0@ab{1,1}c@acabc
|
||||
0@ab{1,3}c@acabc
|
||||
0@ab{2,2}c@abcabbc
|
||||
0@ab{2,4}c@abcabbc
|
||||
2@a**@BADRPT@TO CORRECT
|
||||
2@a++@BADRPT@TO CORRECT
|
||||
2@a??@BADRPT@TO CORRECT
|
||||
2@a*+@BADRPT@TO CORRECT
|
||||
2@a*?@BADRPT@TO CORRECT
|
||||
2@a+*@BADRPT@TO CORRECT
|
||||
2@a+?@BADRPT@TO CORRECT
|
||||
2@a?*@BADRPT@TO CORRECT
|
||||
2@a?+@BADRPT@TO CORRECT
|
||||
2@a{1}{1}@BADRPT@TO CORRECT
|
||||
2@a*{1}@BADRPT@TO CORRECT
|
||||
2@a+{1}@BADRPT@TO CORRECT
|
||||
2@a?{1}@BADRPT@TO CORRECT
|
||||
2@a{1}*@BADRPT@TO CORRECT
|
||||
2@a{1}+@BADRPT@TO CORRECT
|
||||
2@a{1}?@BADRPT@TO CORRECT
|
||||
0@a*{b}@a{b}@TO CORRECT
|
||||
0@a[b]c@abc
|
||||
0@a[ab]c@abc
|
||||
0@a[^ab]c@adc
|
||||
0@a[]b]c@a]c
|
||||
0@a[[b]c@a[c
|
||||
0@a[-b]c@a-c
|
||||
0@a[^]b]c@adc
|
||||
0@a[^-b]c@adc
|
||||
0@a[b-]c@a-c
|
||||
2@a[b@EBRACK
|
||||
2@a[]@EBRACK
|
||||
0@a[1-3]c@a2c
|
||||
2@a[3-1]c@ERANGE@TO CORRECT
|
||||
2@a[1-3-5]c@ERANGE@TO CORRECT
|
||||
0@a[[.-.]--]c@a-c@TO CORRECT
|
||||
2@a[1-@ERANGE
|
||||
2@a[[.@EBRACK
|
||||
2@a[[.x@EBRACK
|
||||
2@a[[.x.@EBRACK
|
||||
2@a[[.x.]@EBRACK@TO CORRECT
|
||||
0@a[[.x.]]@ax@TO CORRECT
|
||||
2@a[[.x,.]]@ECOLLATE@TO CORRECT
|
||||
0@a[[.one.]]b@a1b@TO CORRECT
|
||||
2@a[[.notdef.]]b@ECOLLATE@TO CORRECT
|
||||
0@a[[.].]]b@a]b@TO CORRECT
|
||||
0@a[[:alpha:]]c@abc
|
||||
2@a[[:notdef:]]c@ECTYPE
|
||||
2@a[[:@EBRACK
|
||||
2@a[[:alpha@EBRACK
|
||||
2@a[[:alpha:]@EBRACK
|
||||
2@a[[:alpha,:]@ECTYPE
|
||||
2@a[[:]:]]b@ECTYPE
|
||||
2@a[[:-:]]b@ECTYPE
|
||||
2@a[[:alph:]]@ECTYPE
|
||||
2@a[[:alphabet:]]@ECTYPE
|
||||
0@[[:digit:]]+@a019b
|
||||
0@[[:lower:]]+@AabC
|
||||
0@[[:upper:]]+@aBCd
|
||||
0@[[:xdigit:]]+@p0f3Cq
|
||||
0@a[[=b=]]c@abc@TO CORRECT
|
||||
2@a[[=@EBRACK
|
||||
2@a[[=b@EBRACK
|
||||
2@a[[=b=@EBRACK
|
||||
2@a[[=b=]@EBRACK@TO CORRECT
|
||||
2@a[[=b,=]]@ECOLLATE@TO CORRECT
|
||||
0@a[[=one=]]b@a1b@TO CORRECT
|
||||
0@a(((b)))c@abc
|
||||
0@a(b|(c))d@abd
|
||||
0@a(b*|c)d@abbd
|
||||
0@a[ab]{20}@aaaaabaaaabaaaabaaaab
|
||||
0@a[ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab]@aaaaabaaaabaaaabaaaab
|
||||
0@a[ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab](wee|week)(knights|night)@aaaaabaaaabaaaabaaaabweeknights
|
||||
0@12345678901234567890123456789@a12345678901234567890123456789b
|
||||
0@123456789012345678901234567890@a123456789012345678901234567890b
|
||||
0@1234567890123456789012345678901@a1234567890123456789012345678901b
|
||||
0@12345678901234567890123456789012@a12345678901234567890123456789012b
|
||||
0@123456789012345678901234567890123@a123456789012345678901234567890123b
|
||||
0@1234567890123456789012345678901234567890123456789012345678901234567890@a1234567890123456789012345678901234567890123456789012345678901234567890b
|
||||
0@[ab][cd][ef][gh][ij][kl][mn]@xacegikmoq
|
||||
0@[ab][cd][ef][gh][ij][kl][mn][op]@xacegikmoq
|
||||
0@[ab][cd][ef][gh][ij][kl][mn][op][qr]@xacegikmoqy
|
||||
0@[ab][cd][ef][gh][ij][kl][mn][op][q]@xacegikmoqy
|
||||
0@abc@xabcy
|
||||
0@aBc@Abc@TO CORRECT
|
||||
0@a[Bc]*d@abBCcd@TO CORRECT
|
||||
0@0[[:upper:]]1@0a1@TO CORRECT
|
||||
0@0[[:lower:]]1@0A1@TO CORRECT
|
||||
1@a[^b]c@abc
|
||||
1@a[^b]c@aBc@TO CORRECT
|
||||
0@a[^b]c@adc
|
||||
0@[a]b[c]@abc
|
||||
0@[a]b[a]@aba
|
||||
0@[abc]b[abc]@abc
|
||||
0@[abc]b[abd]@abd
|
||||
0@a(b?c)+d@accd
|
||||
0@(wee|week)(knights|night)@weeknights
|
||||
0@(we|wee|week|frob)(knights|night|day)@weeknights
|
||||
0@a[bc]d@xyzaaabcaababdacd
|
||||
0@a[ab]c@aaabc
|
||||
0@a*@b
|
||||
0@/\*.*\*/@/*x*/
|
||||
0@/\*.*\*/@/*x*/y/*z*/
|
||||
0@/\*([^*]|\*[^/])*\*/@/*x*/
|
||||
0@/\*([^*]|\*[^/])*\*/@/*x*/y/*z*/
|
||||
0@/\*([^*]|\*[^/])*\*/@/*x**/y/*z*/
|
||||
0@/\*([^*]|\*+[^*/])*\*+/@/*x*/
|
||||
0@/\*([^*]|\*+[^*/])*\*+/@/*x*/y/*z*/
|
||||
0@/\*([^*]|\*+[^*/])*\*+/@/*x**/y/*z*/
|
||||
0@/\*([^*]|\*+[^*/])*\*+/@/*x****/y/*z*/
|
||||
0@/\*([^*]|\*+[^*/])*\*+/@/*x**x*/y/*z*/
|
||||
0@/\*([^*]|\*+[^*/])*\*+/@/*x***x/y/*z*/
|
||||
0@aZb@a@TO CORRECT
|
||||
0@[[:<:]]a@a@TO CORRECT
|
||||
1@[[:<:]]a@ba@TO CORRECT
|
||||
0@[[:<:]]a@-a@TO CORRECT
|
||||
0@a[[:>:]]@a@TO CORRECT
|
||||
1@a[[:>:]]@ab@TO CORRECT
|
||||
0@a[[:>:]]@a-@TO CORRECT
|
||||
0@[[:<:]]a.c[[:>:]]@axcd-dayc-dazce-abc@TO CORRECT
|
||||
0@[[:<:]]a.c[[:>:]]@axcd-dayc-dazce-abc-q@TO CORRECT
|
||||
0@[[:<:]]a.c[[:>:]]@axc-dayc-dazce-abc@TO CORRECT
|
||||
0@[[:<:]]b.c[[:>:]]@a_bxc-byc_d-bzc-q@TO CORRECT
|
||||
0@[[:<:]].x..[[:>:]]@y_xa_-_xb_y-_xc_-axdc@TO CORRECT
|
||||
1@[[:<:]]a_b[[:>:]]@x_a_b@TO CORRECT
|
||||
0@(A[1])|(A[2])|(A[3])|(A[4])|(A[5])|(A[6])|(A[7])|(A[8])|(A[9])|(A[A])@A1
|
||||
0@abcdefghijklmnop@abcdefghijklmnop
|
||||
0@abcdefghijklmnopqrstuv@abcdefghijklmnopqrstuv
|
||||
0@CC[13]1|a{21}[23][EO][123][Es][12]a{15}aa[34][EW]aaaaaaa[X]a@CC11
|
||||
0@a?b@ab
|
@ -1,59 +0,0 @@
|
||||
#!/bin/sh
|
||||
# Test for POSIX.2 options for grep
|
||||
#
|
||||
# grep -E -f pattern_file file
|
||||
# grep -F -f pattern_file file
|
||||
# grep -G -f pattern_file file
|
||||
#
|
||||
|
||||
: ${srcdir=.}
|
||||
|
||||
failures=0
|
||||
|
||||
cat <<EOF >patfile
|
||||
radar
|
||||
MILES
|
||||
GNU
|
||||
EOF
|
||||
|
||||
# match
|
||||
echo "miles" | ${GREP} -i -E -f patfile > /dev/null 2>&1
|
||||
if test $? -ne 0 ; then
|
||||
echo "File_pattern: Wrong status code, test \#1 failed"
|
||||
failures=1
|
||||
fi
|
||||
|
||||
# match
|
||||
echo "GNU" | ${GREP} -G -f patfile > /dev/null 2>&1
|
||||
if test $? -ne 0 ; then
|
||||
echo "File_pattern: Wrong status code, test \#2 failed"
|
||||
failures=1
|
||||
fi
|
||||
|
||||
# checking for no match
|
||||
echo "ridar" | ${GREP} -F -f patfile > /dev/null 2>&1
|
||||
if test $? -ne 1 ; then
|
||||
echo "File_pattern: Wrong status code, test \#3 failed"
|
||||
failures=1
|
||||
fi
|
||||
|
||||
cat <<EOF >patfile
|
||||
|
||||
EOF
|
||||
# empty pattern : every match
|
||||
echo "abbcd" | ${GREP} -F -f patfile > /dev/null 2>&1
|
||||
if test $? -ne 0 ; then
|
||||
echo "File_pattern: Wrong status code, test \#4 failed"
|
||||
failures=1
|
||||
fi
|
||||
|
||||
cp /dev/null patfile
|
||||
|
||||
# null pattern : no match
|
||||
echo "abbcd" | ${GREP} -F -f patfile > /dev/null 2>&1
|
||||
if test $? -ne 1 ; then
|
||||
echo "File_pattern: Wrong status code, test \#5 failed"
|
||||
failures=1
|
||||
fi
|
||||
|
||||
exit $failures
|
@ -1,55 +0,0 @@
|
||||
#
|
||||
# Basic Regular Expression
|
||||
|
||||
# kip comments
|
||||
$0 ~ /^#/ { next; }
|
||||
|
||||
# skip those option specific to regexec/regcomp
|
||||
$2 ~ /[msnr$#p^]/ { next; }
|
||||
|
||||
# skip empty lines
|
||||
$0 ~ /^$/ { next; }
|
||||
|
||||
# debug
|
||||
#{ printf ("<%s> <%s> <%s> <%s>\n", $1, $2, $3, $4); }
|
||||
|
||||
# subreg expresion
|
||||
NF >= 5 { next; }
|
||||
|
||||
# errors
|
||||
NF == 3 {
|
||||
# gsub (/@/, ",");
|
||||
# it means empty lines
|
||||
gsub (/\"\"/, "");
|
||||
# escapes
|
||||
gsub (/\\\'/, "\\\'\'");
|
||||
# error in regex
|
||||
if (index ($2, "C") != 0)
|
||||
{
|
||||
if (index ($2, "b") != 0)
|
||||
printf ("2@%s@%s\n", $1, $3);
|
||||
}
|
||||
# erro no match
|
||||
else
|
||||
{
|
||||
if (index ($2, "b") != 0)
|
||||
printf ("1@%s@%s\n", $1, $3);
|
||||
}
|
||||
next;
|
||||
}
|
||||
|
||||
# ok
|
||||
NF == 4 {
|
||||
# skip those magic cookies can't rely on echo to gnerate them
|
||||
if (match($3, /[NSTZ]/))
|
||||
next;
|
||||
|
||||
# gsub (/@/, ",");
|
||||
# it means empty lines
|
||||
gsub (/\"\"/, "");
|
||||
# escape escapes
|
||||
gsub (/\\\'/, "\\\'\'");
|
||||
|
||||
if (index ($2, "b") != 0)
|
||||
printf ("0@%s@%s\n", $1, $3);
|
||||
}
|
@ -1,60 +0,0 @@
|
||||
#
|
||||
# Extended Regular Expression
|
||||
|
||||
# skip comments
|
||||
$0 ~ /^#/ { next; }
|
||||
|
||||
# skip specifics to regcomp/regexec
|
||||
$2 ~ /[msnr$#p^]/ { next; }
|
||||
|
||||
# jump empty lines
|
||||
$0 ~ /^$/ { next; }
|
||||
|
||||
# subreg skip
|
||||
NF >= 5 { next; }
|
||||
|
||||
# debug
|
||||
#{ printf ("<%s> <%s> <%s> <%s>\n", $1, $2, $3, $4); }
|
||||
|
||||
# errors
|
||||
NF == 3 {
|
||||
# nuke any remaining '@'
|
||||
# gsub (/@/, ",");
|
||||
# it means empty lines
|
||||
gsub (/\"\"/, "");
|
||||
# escapes
|
||||
gsub (/\\\'/, "\\\'\'");
|
||||
# error in regex
|
||||
if (index ($2, "C") != 0)
|
||||
{
|
||||
if (index ($2, "b") == 0)
|
||||
printf ("2@%s@%s\n", $1, $3);
|
||||
}
|
||||
# error not matching
|
||||
else
|
||||
{
|
||||
if (index ($2, "b") == 0)
|
||||
printf ("1@%s@%s\n", $1, $3);
|
||||
}
|
||||
next;
|
||||
}
|
||||
|
||||
# ok
|
||||
NF == 4 {
|
||||
# skip those magic cookies can't rely on echo to gnerate them
|
||||
if (match($3, /[NSTZ]/))
|
||||
next;
|
||||
|
||||
# nuke any remaining '@'
|
||||
# gsub (/@/, ",");
|
||||
# it means empty lines
|
||||
gsub (/\"\"/, "");
|
||||
# escape escapes
|
||||
gsub (/\\\'/, "\\\'\'");
|
||||
|
||||
if (index ($2, "b") == 0)
|
||||
{
|
||||
printf ("0@%s@%s\n", $1, $3);
|
||||
}
|
||||
next;
|
||||
}
|
@ -1,32 +0,0 @@
|
||||
1) Muammar Qaddafi
|
||||
2) Mo'ammar Gadhafi
|
||||
3) Muammar Kaddafi
|
||||
4) Muammar Qadhafi
|
||||
5) Moammar El Kadhafi
|
||||
6) Muammar Gadafi
|
||||
7) Mu'ammar al-Qadafi
|
||||
8) Moamer El Kazzafi
|
||||
9) Moamar al-Gaddafi
|
||||
10) Mu'ammar Al Qathafi
|
||||
11) Muammar Al Qathafi
|
||||
12) Mo'ammar el-Gadhafi
|
||||
13) Moamar El Kadhafi
|
||||
14) Muammar al-Qadhafi
|
||||
15) Mu'ammar al-Qadhdhafi
|
||||
16) Mu'ammar Qadafi
|
||||
17) Moamar Gaddafi
|
||||
18) Mu'ammar Qadhdhafi
|
||||
19) Muammar Khaddafi
|
||||
20) Muammar al-Khaddafi
|
||||
21) Mu'amar al-Kadafi
|
||||
22) Muammar Ghaddafy
|
||||
23) Muammar Ghadafi
|
||||
24) Muammar Ghaddafi
|
||||
25) Muamar Kaddafi
|
||||
26) Muammar Quathafi
|
||||
27) Muammar Gheddafi
|
||||
28) Muamar Al-Kaddafi
|
||||
29) Moammar Khadafy
|
||||
30) Moammar Qudhafi
|
||||
31) Mu'ammar al-Qaddafi
|
||||
32) Mulazim Awwal Mu'ammar Muhammad Abu Minyar al-Qadhafi
|
@ -1 +0,0 @@
|
||||
M[ou]'?am+[ae]r .*([AEae]l[- ])?[GKQ]h?[aeu]+([dtz][dhz]?)+af[iy]
|
@ -1,20 +0,0 @@
|
||||
#!/bin/sh
|
||||
# Regression test for GNU grep.
|
||||
|
||||
: ${srcdir=.}
|
||||
: ${GREP=../src/grep}
|
||||
|
||||
failures=0
|
||||
|
||||
# The Khadafy test is brought to you by Scott Anderson . . .
|
||||
|
||||
${GREP} -E -f $srcdir/khadafy.regexp $srcdir/khadafy.lines > khadafy.out
|
||||
if cmp $srcdir/khadafy.lines khadafy.out
|
||||
then
|
||||
:
|
||||
else
|
||||
echo Khadafy test failed -- output left on khadafy.out
|
||||
failures=1
|
||||
fi
|
||||
|
||||
exit $failures
|
@ -1,36 +0,0 @@
|
||||
#!/bin/sh
|
||||
# Test for POSIX.2 options for grep
|
||||
#
|
||||
# grep [ -E| -F][ -c| -l| -q ][-insvx] -e pattern_list
|
||||
# [-f pattern_file] ... [file. ..]
|
||||
# grep [ -E| -F][ -c| -l| -q ][-insvx][-e pattern_list]
|
||||
# -f pattern_file ... [file ...]
|
||||
# grep [ -E| -F][ -c| -l| -q ][-insvx] pattern_list [file...]
|
||||
#
|
||||
|
||||
: ${srcdir=.}
|
||||
|
||||
failures=0
|
||||
|
||||
# checking for -E extended regex
|
||||
echo "abababccccccd" | ${GREP} -E -e 'c{3}' > /dev/null 2>&1
|
||||
if test $? -ne 0 ; then
|
||||
echo "Options: Wrong status code, test \#1 failed"
|
||||
failures=1
|
||||
fi
|
||||
|
||||
# checking for basic regex
|
||||
echo "abababccccccd" | ${GREP} -G -e 'c\{3\}' > /dev/null 2>&1
|
||||
if test $? -ne 0 ; then
|
||||
echo "Options: Wrong status code, test \#2 failed"
|
||||
failures=1
|
||||
fi
|
||||
|
||||
# checking for fixed string
|
||||
echo "abababccccccd" | ${GREP} -F -e 'c\{3\}' > /dev/null 2>&1
|
||||
if test $? -ne 1 ; then
|
||||
echo "Options: Wrong status code, test \#3 failed"
|
||||
failures=1
|
||||
fi
|
||||
|
||||
exit $failures
|
@ -1,15 +0,0 @@
|
||||
BEGIN {
|
||||
FS = "@";
|
||||
printf ("failures=0\n");
|
||||
}
|
||||
|
||||
$0 !~ /^#/ && NF = 3 {
|
||||
# printf ("status=`echo '%s'| { ${GREP} -E -e '%s' > /dev/null 2>&1; echo $?; cat >/dev/null; }`\n",$3, $2);
|
||||
printf ("status=`echo '%s'| { ${GREP} -E -e '%s' >/dev/null 2>&1 ; echo $?; }`\n",$3, $2);
|
||||
printf ("if test $status -ne %s ; then\n", $1);
|
||||
printf ("\techo Spencer test \\#%d failed\n", ++n);
|
||||
printf ("\tfailures=1\n");
|
||||
printf ("fi\n");
|
||||
}
|
||||
|
||||
END { printf ("exit $failures\n"); }
|
@ -1,13 +0,0 @@
|
||||
#!/bin/sh
|
||||
# Regression test for GNU grep.
|
||||
|
||||
: ${srcdir=.}
|
||||
|
||||
failures=0
|
||||
|
||||
# . . . and the following by Henry Spencer.
|
||||
|
||||
${AWK-awk} -f $srcdir/spencer1.awk $srcdir/spencer1.tests > spencer1.script
|
||||
|
||||
sh spencer1.script && exit $failures
|
||||
exit 1
|
@ -1,122 +0,0 @@
|
||||
0@abc@abc
|
||||
1@abc@xbc
|
||||
1@abc@axc
|
||||
1@abc@abx
|
||||
0@abc@xabcy
|
||||
0@abc@ababc
|
||||
0@ab*c@abc
|
||||
0@ab*bc@abc
|
||||
0@ab*bc@abbc
|
||||
0@ab*bc@abbbbc
|
||||
0@ab+bc@abbc
|
||||
1@ab+bc@abc
|
||||
1@ab+bc@abq
|
||||
0@ab+bc@abbbbc
|
||||
0@ab?bc@abbc
|
||||
0@ab?bc@abc
|
||||
1@ab?bc@abbbbc
|
||||
0@ab?c@abc
|
||||
0@^abc$@abc
|
||||
1@^abc$@abcc
|
||||
0@^abc@abcc
|
||||
1@^abc$@aabc
|
||||
0@abc$@aabc
|
||||
0@^@abc
|
||||
0@$@abc
|
||||
0@a.c@abc
|
||||
0@a.c@axc
|
||||
0@a.*c@axyzc
|
||||
1@a.*c@axyzd
|
||||
1@a[bc]d@abc
|
||||
0@a[bc]d@abd
|
||||
1@a[b-d]e@abd
|
||||
0@a[b-d]e@ace
|
||||
0@a[b-d]@aac
|
||||
0@a[-b]@a-
|
||||
0@a[b-]@a-
|
||||
1@a[b-a]@-
|
||||
2@a[]b@-
|
||||
2@a[@-
|
||||
0@a]@a]
|
||||
0@a[]]b@a]b
|
||||
0@a[^bc]d@aed
|
||||
1@a[^bc]d@abd
|
||||
0@a[^-b]c@adc
|
||||
1@a[^-b]c@a-c
|
||||
1@a[^]b]c@a]c
|
||||
0@a[^]b]c@adc
|
||||
0@ab|cd@abc
|
||||
0@ab|cd@abcd
|
||||
0@()ef@def
|
||||
0@()*@-
|
||||
1@*a@-
|
||||
0@^*@-
|
||||
0@$*@-
|
||||
1@(*)b@-
|
||||
1@$b@b
|
||||
2@a\@-
|
||||
0@a\(b@a(b
|
||||
0@a\(*b@ab
|
||||
0@a\(*b@a((b
|
||||
1@a\x@a\x
|
||||
2@abc)@-
|
||||
2@(abc@-
|
||||
0@((a))@abc
|
||||
0@(a)b(c)@abc
|
||||
0@a+b+c@aabbabc
|
||||
0@a**@-
|
||||
0@a*?@-
|
||||
0@(a*)*@-
|
||||
0@(a*)+@-
|
||||
0@(a|)*@-
|
||||
0@(a*|b)*@-
|
||||
0@(a+|b)*@ab
|
||||
0@(a+|b)+@ab
|
||||
0@(a+|b)?@ab
|
||||
0@[^ab]*@cde
|
||||
0@(^)*@-
|
||||
0@(ab|)*@-
|
||||
2@)(@-
|
||||
1@abc@
|
||||
1@abc@
|
||||
0@a*@
|
||||
0@([abc])*d@abbbcd
|
||||
0@([abc])*bcd@abcd
|
||||
0@a|b|c|d|e@e
|
||||
0@(a|b|c|d|e)f@ef
|
||||
0@((a*|b))*@-
|
||||
0@abcd*efg@abcdefg
|
||||
0@ab*@xabyabbbz
|
||||
0@ab*@xayabbbz
|
||||
0@(ab|cd)e@abcde
|
||||
0@[abhgefdc]ij@hij
|
||||
1@^(ab|cd)e@abcde
|
||||
0@(abc|)ef@abcdef
|
||||
0@(a|b)c*d@abcd
|
||||
0@(ab|ab*)bc@abc
|
||||
0@a([bc]*)c*@abc
|
||||
0@a([bc]*)(c*d)@abcd
|
||||
0@a([bc]+)(c*d)@abcd
|
||||
0@a([bc]*)(c+d)@abcd
|
||||
0@a[bcd]*dcdcde@adcdcde
|
||||
1@a[bcd]+dcdcde@adcdcde
|
||||
0@(ab|a)b*c@abc
|
||||
0@((a)(b)c)(d)@abcd
|
||||
0@[A-Za-z_][A-Za-z0-9_]*@alpha
|
||||
0@^a(bc+|b[eh])g|.h$@abh
|
||||
0@(bc+d$|ef*g.|h?i(j|k))@effgz
|
||||
0@(bc+d$|ef*g.|h?i(j|k))@ij
|
||||
1@(bc+d$|ef*g.|h?i(j|k))@effg
|
||||
1@(bc+d$|ef*g.|h?i(j|k))@bcdd
|
||||
0@(bc+d$|ef*g.|h?i(j|k))@reffgz
|
||||
1@((((((((((a))))))))))@-
|
||||
0@(((((((((a)))))))))@a
|
||||
1@multiple words of text@uh-uh
|
||||
0@multiple words@multiple words, yeah
|
||||
0@(.*)c(.*)@abcde
|
||||
1@\((.*),@(.*)\)
|
||||
1@[k]@ab
|
||||
0@abcd@abcd
|
||||
0@a(bc)d@abcd
|
||||
0@a[-]?c@ac
|
||||
0@(....).*\1@beriberi
|
@ -1,13 +0,0 @@
|
||||
#!/bin/sh
|
||||
# Regression test for GNU grep.
|
||||
|
||||
: ${srcdir=.}
|
||||
|
||||
failures=0
|
||||
|
||||
# . . . and the following by Henry Spencer.
|
||||
|
||||
${AWK-awk} -f $srcdir/scriptgen.awk $srcdir/spencer2.tests > tmp2.script
|
||||
|
||||
sh tmp2.script && exit $failures
|
||||
exit 1
|
@ -1,317 +0,0 @@
|
||||
0@a@a
|
||||
0@abc@abc
|
||||
0@abc|de@abc
|
||||
0@a|b|c@abc
|
||||
0@a(b)c@abc
|
||||
1@a\(b\)c@abc
|
||||
2@a(@EPAREN
|
||||
2@a(@a(
|
||||
0@a\(@a(
|
||||
1@a\(@EPAREN
|
||||
1@a\(b@EPAREN
|
||||
2@a(b@EPAREN
|
||||
2@a(b@a(b
|
||||
2@a)@a)
|
||||
2@)@)
|
||||
2@a)@a)
|
||||
1@a\)@EPAREN
|
||||
1@\)@EPAREN
|
||||
0@a()b@ab
|
||||
1@a\(\)b@ab
|
||||
0@^abc$@abc
|
||||
1@a^b@a^b
|
||||
1@a^b@a^b
|
||||
1@a$b@a$b
|
||||
1@a$b@a$b
|
||||
0@^@abc
|
||||
0@$@abc
|
||||
1@^$@""
|
||||
1@$^@""
|
||||
1@\($\)\(^\)@""
|
||||
0@^^@""
|
||||
0@$$@""
|
||||
1@b$@abNc
|
||||
1@b$@abNc
|
||||
1@^b$@aNbNc
|
||||
1@^b$@aNbNc
|
||||
1@^$@aNNb
|
||||
1@^$@abc
|
||||
1@^$@abcN
|
||||
1@$^@aNNb
|
||||
1@\($\)\(^\)@aNNb
|
||||
0@^^@aNNb
|
||||
0@$$@aNNb
|
||||
0@^a@a
|
||||
0@a$@a
|
||||
0@^a@aNb
|
||||
1@^b@aNb
|
||||
0@a$@bNa
|
||||
1@b$@bNa
|
||||
0@a*(^b$)c*@b
|
||||
1@a*\(^b$\)c*@b
|
||||
0@|@EMPTY
|
||||
0@|@|
|
||||
0@*@BADRPT
|
||||
0@*@*
|
||||
0@+@BADRPT
|
||||
0@?@BADRPT
|
||||
1@""@EMPTY
|
||||
0@()@abc
|
||||
1@\(\)@abc
|
||||
0@a||b@EMPTY
|
||||
0@|ab@EMPTY
|
||||
0@ab|@EMPTY
|
||||
1@(|a)b@EMPTY
|
||||
1@(a|)b@EMPTY
|
||||
1@(*a)@BADRPT
|
||||
1@(+a)@BADRPT
|
||||
1@(?a)@BADRPT
|
||||
1@({1}a)@BADRPT
|
||||
1@\(\{1\}a\)@BADRPT
|
||||
1@(a|*b)@BADRPT
|
||||
1@(a|+b)@BADRPT
|
||||
1@(a|?b)@BADRPT
|
||||
1@(a|{1}b)@BADRPT
|
||||
0@^*@BADRPT
|
||||
0@^*@*
|
||||
0@^+@BADRPT
|
||||
0@^?@BADRPT
|
||||
0@^{1}@BADRPT
|
||||
1@^\{1\}@BADRPT
|
||||
0@a.c@abc
|
||||
0@a[bc]d@abd
|
||||
0@a\*c@a*c
|
||||
1@ac@abc
|
||||
1@a\bc@ac
|
||||
1@\{@BADRPT
|
||||
0@a\[b@a[b
|
||||
2@a[b@EBRACK
|
||||
0@a$@a
|
||||
1@a$@a$
|
||||
1@a\$@a
|
||||
0@a\$@a$
|
||||
1@a\$@a
|
||||
1@a\$@a\$
|
||||
2@a\(b\)\2c@ESUBREG
|
||||
2@a\(b\1\)c@ESUBREG
|
||||
2@a\(b*\)c\1d@abbcbd
|
||||
2@a\(b*\)c\1d@abbcbbbd
|
||||
2@^\(.\)\1@abc
|
||||
2@a\(\([bc]\)\2\)*d@abbccd
|
||||
2@a\(\([bc]\)\2\)*d@abbcbd
|
||||
2@a\(\(b\)*\2\)*d@abbbd
|
||||
2@\(a\)\1bcd@aabcd
|
||||
2@\(a\)\1bc*d@aabcd
|
||||
2@\(a\)\1bc*d@aabd
|
||||
2@\(a\)\1bc*d@aabcccd
|
||||
2@\(a\)\1bc*[ce]d@aabcccd
|
||||
2@^\(a\)\1b\(c\)*cd$@aabcccd
|
||||
0@ab*c@abc
|
||||
0@ab+c@abc
|
||||
0@ab?c@abc
|
||||
1@a\(*\)b@a*b
|
||||
1@a\(**\)b@ab
|
||||
1@a\(***\)b@BADRPT
|
||||
0@*a@*a
|
||||
0@**a@a
|
||||
1@***a@BADRPT
|
||||
2@{@{
|
||||
2@{abc@{abc
|
||||
2@{1@BADRPT
|
||||
0@{1}@BADRPT
|
||||
2@a{b@a{b
|
||||
0@a{1}b@ab
|
||||
1@a\{1\}b@ab
|
||||
0@a{1,}b@ab
|
||||
1@a\{1,\}b@ab
|
||||
0@a{1,2}b@aab
|
||||
1@a\{1,2\}b@aab
|
||||
2@a{1@EBRACE
|
||||
1@a\{1@EBRACE
|
||||
2@a{1a@EBRACE
|
||||
1@a\{1a@EBRACE
|
||||
2@a{1a}@BADBR
|
||||
1@a\{1a\}@BADBR
|
||||
0@a{,2}@a{,2}
|
||||
1@a\{,2\}@BADBR
|
||||
0@a{,}@a{,}
|
||||
1@a\{,\}@BADBR
|
||||
2@a{1,x}@BADBR
|
||||
1@a\{1,x\}@BADBR
|
||||
2@a{1,x@EBRACE
|
||||
1@a\{1,x@EBRACE
|
||||
1@a{300}@BADBR
|
||||
1@a\{300\}@BADBR
|
||||
1@a{1,0}@BADBR
|
||||
1@a\{1,0\}@BADBR
|
||||
0@ab{0,0}c@abcac
|
||||
1@ab\{0,0\}c@abcac
|
||||
0@ab{0,1}c@abcac
|
||||
1@ab\{0,1\}c@abcac
|
||||
0@ab{0,3}c@abbcac
|
||||
1@ab\{0,3\}c@abbcac
|
||||
0@ab{1,1}c@acabc
|
||||
1@ab\{1,1\}c@acabc
|
||||
0@ab{1,3}c@acabc
|
||||
1@ab\{1,3\}c@acabc
|
||||
0@ab{2,2}c@abcabbc
|
||||
1@ab\{2,2\}c@abcabbc
|
||||
0@ab{2,4}c@abcabbc
|
||||
1@ab\{2,4\}c@abcabbc
|
||||
0@a**@BADRPT
|
||||
1@a++@BADRPT
|
||||
0@a??@BADRPT
|
||||
0@a*+@BADRPT
|
||||
0@a*?@BADRPT
|
||||
0@a+*@BADRPT
|
||||
0@a+?@BADRPT
|
||||
0@a?*@BADRPT
|
||||
0@a?+@BADRPT
|
||||
1@a{1}{1}@BADRPT
|
||||
0@a*{1}@BADRPT
|
||||
1@a+{1}@BADRPT
|
||||
0@a?{1}@BADRPT
|
||||
0@a{1}*@BADRPT
|
||||
1@a{1}+@BADRPT
|
||||
0@a{1}?@BADRPT
|
||||
2@a*{b}@a{b}
|
||||
1@a\{1\}\{1\}@BADRPT
|
||||
1@a*\{1\}@BADRPT
|
||||
1@a\{1\}*@BADRPT
|
||||
0@a[b]c@abc
|
||||
0@a[ab]c@abc
|
||||
0@a[^ab]c@adc
|
||||
0@a[]b]c@a]c
|
||||
0@a[[b]c@a[c
|
||||
0@a[-b]c@a-c
|
||||
0@a[^]b]c@adc
|
||||
0@a[^-b]c@adc
|
||||
0@a[b-]c@a-c
|
||||
2@a[b@EBRACK
|
||||
2@a[]@EBRACK
|
||||
0@a[1-3]c@a2c
|
||||
1@a[3-1]c@ERANGE
|
||||
1@a[1-3-5]c@ERANGE
|
||||
1@a[[.-.]--]c@a-c
|
||||
2@a[1-@ERANGE
|
||||
2@a[[.@EBRACK
|
||||
2@a[[.x@EBRACK
|
||||
2@a[[.x.@EBRACK
|
||||
1@a[[.x.]@EBRACK
|
||||
1@a[[.x.]]@ax
|
||||
1@a[[.x,.]]@ECOLLATE
|
||||
1@a[[.one.]]b@a1b
|
||||
1@a[[.notdef.]]b@ECOLLATE
|
||||
1@a[[.].]]b@a]b
|
||||
0@a[[:alpha:]]c@abc
|
||||
2@a[[:notdef:]]c@ECTYPE
|
||||
2@a[[:@EBRACK
|
||||
2@a[[:alpha@EBRACK
|
||||
2@a[[:alpha:]@EBRACK
|
||||
2@a[[:alpha,:]@ECTYPE
|
||||
2@a[[:]:]]b@ECTYPE
|
||||
2@a[[:-:]]b@ECTYPE
|
||||
2@a[[:alph:]]@ECTYPE
|
||||
2@a[[:alphabet:]]@ECTYPE
|
||||
1@[[:blank:]]+@aSSTb
|
||||
1@[[:cntrl:]]+@aNTb
|
||||
0@[[:digit:]]+@a019b
|
||||
0@[[:graph:]]+@Sa%bS
|
||||
0@[[:lower:]]+@AabC
|
||||
0@[[:print:]]+@NaSbN
|
||||
0@[[:punct:]]+@S%-&T
|
||||
1@[[:space:]]+@aSNTb
|
||||
0@[[:upper:]]+@aBCd
|
||||
0@[[:xdigit:]]+@p0f3Cq
|
||||
1@a[[=b=]]c@abc
|
||||
2@a[[=@EBRACK
|
||||
2@a[[=b@EBRACK
|
||||
2@a[[=b=@EBRACK
|
||||
1@a[[=b=]@EBRACK
|
||||
1@a[[=b,=]]@ECOLLATE
|
||||
1@a[[=one=]]b@a1b
|
||||
0@a(((b)))c@abc
|
||||
0@a(b|(c))d@abd
|
||||
0@a(b*|c)d@abbd
|
||||
0@a[ab]{20}@aaaaabaaaabaaaabaaaab
|
||||
0@a[ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab]@aaaaabaaaabaaaabaaaab
|
||||
0@a[ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab](wee|week)(knights|night)@aaaaabaaaabaaaabaaaabweeknights
|
||||
0@12345678901234567890123456789@a12345678901234567890123456789b
|
||||
0@123456789012345678901234567890@a123456789012345678901234567890b
|
||||
0@1234567890123456789012345678901@a1234567890123456789012345678901b
|
||||
0@12345678901234567890123456789012@a12345678901234567890123456789012b
|
||||
0@123456789012345678901234567890123@a123456789012345678901234567890123b
|
||||
0@1234567890123456789012345678901234567890123456789012345678901234567890@a1234567890123456789012345678901234567890123456789012345678901234567890b
|
||||
0@[ab][cd][ef][gh][ij][kl][mn]@xacegikmoq
|
||||
0@[ab][cd][ef][gh][ij][kl][mn][op]@xacegikmoq
|
||||
0@[ab][cd][ef][gh][ij][kl][mn][op][qr]@xacegikmoqy
|
||||
0@[ab][cd][ef][gh][ij][kl][mn][op][q]@xacegikmoqy
|
||||
0@abc@xabcy
|
||||
2@a\(b\)?c\1d@acd
|
||||
1@aBc@Abc
|
||||
1@a[Bc]*d@abBCcd
|
||||
1@0[[:upper:]]1@0a1
|
||||
1@0[[:lower:]]1@0A1
|
||||
1@a[^b]c@abc
|
||||
0@a[^b]c@aBc
|
||||
0@a[^b]c@adc
|
||||
0@[a]b[c]@abc
|
||||
0@[a]b[a]@aba
|
||||
0@[abc]b[abc]@abc
|
||||
0@[abc]b[abd]@abd
|
||||
0@a(b?c)+d@accd
|
||||
0@(wee|week)(knights|night)@weeknights
|
||||
0@(we|wee|week|frob)(knights|night|day)@weeknights
|
||||
0@a[bc]d@xyzaaabcaababdacd
|
||||
0@a[ab]c@aaabc
|
||||
0@abc@abc
|
||||
0@a*@b
|
||||
0@/\*.*\*/@/*x*/
|
||||
0@/\*.*\*/@/*x*/y/*z*/
|
||||
0@/\*([^*]|\*[^/])*\*/@/*x*/
|
||||
0@/\*([^*]|\*[^/])*\*/@/*x*/y/*z*/
|
||||
0@/\*([^*]|\*[^/])*\*/@/*x**/y/*z*/
|
||||
0@/\*([^*]|\*+[^*/])*\*+/@/*x*/
|
||||
0@/\*([^*]|\*+[^*/])*\*+/@/*x*/y/*z*/
|
||||
0@/\*([^*]|\*+[^*/])*\*+/@/*x**/y/*z*/
|
||||
0@/\*([^*]|\*+[^*/])*\*+/@/*x****/y/*z*/
|
||||
0@/\*([^*]|\*+[^*/])*\*+/@/*x**x*/y/*z*/
|
||||
0@/\*([^*]|\*+[^*/])*\*+/@/*x***x/y/*z*/
|
||||
0@[abc]@a(b)c
|
||||
0@[abc]@a(d)c
|
||||
0@[abc]@a(bc)d
|
||||
0@[abc]@a(dc)d
|
||||
0@.@a()c
|
||||
0@b.*c@b(bc)c
|
||||
0@b.*@b(bc)c
|
||||
0@.*c@b(bc)c
|
||||
0@abc@abc
|
||||
0@abc@xabcy
|
||||
1@abc@xyz
|
||||
0@a*b@aba*b
|
||||
0@a*b@ab
|
||||
1@""@EMPTY
|
||||
1@aZb@a
|
||||
1@aZb@a
|
||||
0@aZb@(aZb)
|
||||
0@aZ*b@(ab)
|
||||
0@a.b@(aZb)
|
||||
0@a.*@(aZb)c
|
||||
2@[[:<:]]a@a
|
||||
2@[[:<:]]a@ba
|
||||
2@[[:<:]]a@-a
|
||||
2@a[[:>:]]@a
|
||||
2@a[[:>:]]@ab
|
||||
2@a[[:>:]]@a-
|
||||
2@[[:<:]]a.c[[:>:]]@axcd-dayc-dazce-abc
|
||||
2@[[:<:]]a.c[[:>:]]@axcd-dayc-dazce-abc-q
|
||||
2@[[:<:]]a.c[[:>:]]@axc-dayc-dazce-abc
|
||||
2@[[:<:]]b.c[[:>:]]@a_bxc-byc_d-bzc-q
|
||||
2@[[:<:]].x..[[:>:]]@y_xa_-_xb_y-_xc_-axdc
|
||||
2@[[:<:]]a_b[[:>:]]@x_a_b
|
||||
0@(A[1])|(A[2])|(A[3])|(A[4])|(A[5])|(A[6])|(A[7])|(A[8])|(A[9])|(A[A])@A1
|
||||
0@abcdefghijklmnop@abcdefghijklmnop
|
||||
0@abcdefghijklmnopqrstuv@abcdefghijklmnopqrstuv
|
||||
0@CC[13]1|a{21}[23][EO][123][Es][12]a{15}aa[34][EW]aaaaaaa[X]a@CC11
|
||||
0@a?b@ab
|
||||
1@-\{0,1\}[0-9]*$@-5
|
@ -1,52 +0,0 @@
|
||||
#!/bin/sh
|
||||
# Test for status code for GNU grep.
|
||||
# status code
|
||||
# 0 match found
|
||||
# 1 no match
|
||||
# 2 file not found
|
||||
|
||||
: ${srcdir=.}
|
||||
|
||||
failures=0
|
||||
|
||||
# should return 0 found a match
|
||||
echo "abcd" | ${GREP} -E -e 'abc' > /dev/null 2>&1
|
||||
if test $? -ne 0 ; then
|
||||
echo "Status: Wrong status code, test \#1 failed"
|
||||
failures=1
|
||||
fi
|
||||
|
||||
# should return 1 found no match
|
||||
echo "abcd" | ${GREP} -E -e 'zbc' > /dev/null 2>&1
|
||||
if test $? -ne 1 ; then
|
||||
echo "Status: Wrong status code, test \#2 failed"
|
||||
failures=1
|
||||
fi
|
||||
|
||||
# the filename MMMMMMMM.MMM should not exist hopefully
|
||||
if test -r MMMMMMMM.MMM; then
|
||||
echo "Please remove MMMMMMMM.MMM to run check"
|
||||
else
|
||||
# should return 2 file not found
|
||||
${GREP} -E -e 'abc' MMMMMMMM.MMM > /dev/null 2>&1
|
||||
if test $? -ne 2 ; then
|
||||
echo "Status: Wrong status code, test \#3 failed"
|
||||
failures=1
|
||||
fi
|
||||
|
||||
# should return 2 file not found
|
||||
${GREP} -E -s -e 'abc' MMMMMMMM.MMM > /dev/null 2>&1
|
||||
if test $? -ne 2 ; then
|
||||
echo "Status: Wrong status code, test \#4 failed"
|
||||
failures=1
|
||||
fi
|
||||
|
||||
# should return 0 found a match
|
||||
echo "abcd" | ${GREP} -E -q -s 'abc' MMMMMMMM.MMM - > /dev/null 2>&1
|
||||
if test $? -ne 0 ; then
|
||||
echo "Status: Wrong status code, test \#5 failed"
|
||||
failures=1
|
||||
fi
|
||||
fi
|
||||
|
||||
exit $failures
|
@ -1,475 +0,0 @@
|
||||
# regular expression test set
|
||||
# Lines are at least three fields, separated by one or more tabs. "" stands
|
||||
# for an empty field. First field is an RE. Second field is flags. If
|
||||
# C flag given, regcomp() is expected to fail, and the third field is the
|
||||
# error name (minus the leading REG_).
|
||||
#
|
||||
# Otherwise it is expected to succeed, and the third field is the string to
|
||||
# try matching it against. If there is no fourth field, the match is
|
||||
# expected to fail. If there is a fourth field, it is the substring that
|
||||
# the RE is expected to match. If there is a fifth field, it is a comma-
|
||||
# separated list of what the subexpressions should match, with - indicating
|
||||
# no match for that one. In both the fourth and fifth fields, a (sub)field
|
||||
# starting with @ indicates that the (sub)expression is expected to match
|
||||
# a null string followed by the stuff after the @; this provides a way to
|
||||
# test where null strings match. The character `N' in REs and strings
|
||||
# is newline, `S' is space, `T' is tab, `Z' is NUL.
|
||||
#
|
||||
# The full list of flags:
|
||||
# - placeholder, does nothing
|
||||
# b RE is a BRE, not an ERE
|
||||
# & try it as both an ERE and a BRE
|
||||
# C regcomp() error expected, third field is error name
|
||||
# i REG_ICASE
|
||||
# m ("mundane") REG_NOSPEC
|
||||
# s REG_NOSUB (not really testable)
|
||||
# n REG_NEWLINE
|
||||
# ^ REG_NOTBOL
|
||||
# $ REG_NOTEOL
|
||||
# # REG_STARTEND (see below)
|
||||
# p REG_PEND
|
||||
#
|
||||
# For REG_STARTEND, the start/end offsets are those of the substring
|
||||
# enclosed in ().
|
||||
|
||||
# basics
|
||||
a & a a
|
||||
abc & abc abc
|
||||
abc|de - abc abc
|
||||
a|b|c - abc a
|
||||
|
||||
# parentheses and perversions thereof
|
||||
a(b)c - abc abc
|
||||
a\(b\)c b abc abc
|
||||
a( C EPAREN
|
||||
a( b a( a(
|
||||
a\( - a( a(
|
||||
a\( bC EPAREN
|
||||
a\(b bC EPAREN
|
||||
a(b C EPAREN
|
||||
a(b b a(b a(b
|
||||
# gag me with a right parenthesis -- 1003.2 goofed here (my fault, partly)
|
||||
a) - a) a)
|
||||
) - ) )
|
||||
# end gagging (in a just world, those *should* give EPAREN)
|
||||
a) b a) a)
|
||||
a\) bC EPAREN
|
||||
\) bC EPAREN
|
||||
a()b - ab ab
|
||||
a\(\)b b ab ab
|
||||
|
||||
# anchoring and REG_NEWLINE
|
||||
^abc$ & abc abc
|
||||
a^b - a^b
|
||||
a^b b a^b a^b
|
||||
a$b - a$b
|
||||
a$b b a$b a$b
|
||||
^ & abc @abc
|
||||
$ & abc @
|
||||
^$ & "" @
|
||||
$^ - "" @
|
||||
\($\)\(^\) b "" @
|
||||
# stop retching, those are legitimate (although disgusting)
|
||||
^^ - "" @
|
||||
$$ - "" @
|
||||
##b$ & abNc
|
||||
##b$ &n abNc b
|
||||
##^b$ & aNbNc
|
||||
##^b$ &n aNbNc b
|
||||
##^$ &n aNNb @Nb
|
||||
^$ n abc
|
||||
##^$ n abcN @
|
||||
##$^ n aNNb @Nb
|
||||
##\($\)\(^\) bn aNNb @Nb
|
||||
##^^ n^ aNNb @Nb
|
||||
##$$ n aNNb @NN
|
||||
^a ^ a
|
||||
a$ $ a
|
||||
##^a ^n aNb
|
||||
##^b ^n aNb b
|
||||
##a$ $n bNa
|
||||
##b$ $n bNa b
|
||||
a*(^b$)c* - b b
|
||||
a*\(^b$\)c* b b b
|
||||
|
||||
# certain syntax errors and non-errors
|
||||
| C EMPTY
|
||||
| b | |
|
||||
* C BADRPT
|
||||
* b * *
|
||||
+ C BADRPT
|
||||
? C BADRPT
|
||||
"" &C EMPTY
|
||||
() - abc @abc
|
||||
\(\) b abc @abc
|
||||
a||b C EMPTY
|
||||
|ab C EMPTY
|
||||
ab| C EMPTY
|
||||
(|a)b C EMPTY
|
||||
(a|)b C EMPTY
|
||||
(*a) C BADRPT
|
||||
(+a) C BADRPT
|
||||
(?a) C BADRPT
|
||||
({1}a) C BADRPT
|
||||
\(\{1\}a\) bC BADRPT
|
||||
(a|*b) C BADRPT
|
||||
(a|+b) C BADRPT
|
||||
(a|?b) C BADRPT
|
||||
(a|{1}b) C BADRPT
|
||||
^* C BADRPT
|
||||
^* b * *
|
||||
^+ C BADRPT
|
||||
^? C BADRPT
|
||||
^{1} C BADRPT
|
||||
^\{1\} bC BADRPT
|
||||
|
||||
# metacharacters, backslashes
|
||||
a.c & abc abc
|
||||
a[bc]d & abd abd
|
||||
a\*c & a*c a*c
|
||||
a\\b & a\b a\b
|
||||
a\\\*b & a\*b a\*b
|
||||
a\bc & abc abc
|
||||
a\ &C EESCAPE
|
||||
a\\bc & a\bc a\bc
|
||||
\{ bC BADRPT
|
||||
a\[b & a[b a[b
|
||||
a[b &C EBRACK
|
||||
# trailing $ is a peculiar special case for the BRE code
|
||||
a$ & a a
|
||||
a$ & a$
|
||||
a\$ & a
|
||||
a\$ & a$ a$
|
||||
a\\$ & a
|
||||
a\\$ & a$
|
||||
a\\$ & a\$
|
||||
a\\$ & a\ a\
|
||||
|
||||
# back references, ugh
|
||||
##a\(b\)\2c bC ESUBREG
|
||||
##a\(b\1\)c bC ESUBREG
|
||||
a\(b*\)c\1d b abbcbbd abbcbbd bb
|
||||
a\(b*\)c\1d b abbcbd
|
||||
a\(b*\)c\1d b abbcbbbd
|
||||
^\(.\)\1 b abc
|
||||
a\([bc]\)\1d b abcdabbd abbd b
|
||||
a\(\([bc]\)\2\)*d b abbccd abbccd
|
||||
a\(\([bc]\)\2\)*d b abbcbd
|
||||
# actually, this next one probably ought to fail, but the spec is unclear
|
||||
a\(\(b\)*\2\)*d b abbbd abbbd
|
||||
# here is a case that no NFA implementation does right
|
||||
\(ab*\)[ab]*\1 b ababaaa ababaaa a
|
||||
# check out normal matching in the presence of back refs
|
||||
\(a\)\1bcd b aabcd aabcd
|
||||
\(a\)\1bc*d b aabcd aabcd
|
||||
\(a\)\1bc*d b aabd aabd
|
||||
\(a\)\1bc*d b aabcccd aabcccd
|
||||
\(a\)\1bc*[ce]d b aabcccd aabcccd
|
||||
^\(a\)\1b\(c\)*cd$ b aabcccd aabcccd
|
||||
|
||||
# ordinary repetitions
|
||||
ab*c & abc abc
|
||||
ab+c - abc abc
|
||||
ab?c - abc abc
|
||||
a\(*\)b b a*b a*b
|
||||
a\(**\)b b ab ab
|
||||
a\(***\)b bC BADRPT
|
||||
*a b *a *a
|
||||
**a b a a
|
||||
***a bC BADRPT
|
||||
|
||||
# the dreaded bounded repetitions
|
||||
{ & { {
|
||||
{abc & {abc {abc
|
||||
{1 C BADRPT
|
||||
{1} C BADRPT
|
||||
a{b & a{b a{b
|
||||
a{1}b - ab ab
|
||||
a\{1\}b b ab ab
|
||||
a{1,}b - ab ab
|
||||
a\{1,\}b b ab ab
|
||||
a{1,2}b - aab aab
|
||||
a\{1,2\}b b aab aab
|
||||
a{1 C EBRACE
|
||||
a\{1 bC EBRACE
|
||||
a{1a C EBRACE
|
||||
a\{1a bC EBRACE
|
||||
a{1a} C BADBR
|
||||
a\{1a\} bC BADBR
|
||||
a{,2} - a{,2} a{,2}
|
||||
a\{,2\} bC BADBR
|
||||
a{,} - a{,} a{,}
|
||||
a\{,\} bC BADBR
|
||||
a{1,x} C BADBR
|
||||
a\{1,x\} bC BADBR
|
||||
a{1,x C EBRACE
|
||||
a\{1,x bC EBRACE
|
||||
a{300} C BADBR
|
||||
a\{300\} bC BADBR
|
||||
a{1,0} C BADBR
|
||||
a\{1,0\} bC BADBR
|
||||
ab{0,0}c - abcac ac
|
||||
ab\{0,0\}c b abcac ac
|
||||
ab{0,1}c - abcac abc
|
||||
ab\{0,1\}c b abcac abc
|
||||
ab{0,3}c - abbcac abbc
|
||||
ab\{0,3\}c b abbcac abbc
|
||||
ab{1,1}c - acabc abc
|
||||
ab\{1,1\}c b acabc abc
|
||||
ab{1,3}c - acabc abc
|
||||
ab\{1,3\}c b acabc abc
|
||||
ab{2,2}c - abcabbc abbc
|
||||
ab\{2,2\}c b abcabbc abbc
|
||||
ab{2,4}c - abcabbc abbc
|
||||
ab\{2,4\}c b abcabbc abbc
|
||||
((a{1,10}){1,10}){1,10} - a a a,a
|
||||
|
||||
# multiple repetitions
|
||||
a** &C BADRPT
|
||||
a++ C BADRPT
|
||||
a?? C BADRPT
|
||||
a*+ C BADRPT
|
||||
a*? C BADRPT
|
||||
a+* C BADRPT
|
||||
a+? C BADRPT
|
||||
a?* C BADRPT
|
||||
a?+ C BADRPT
|
||||
a{1}{1} C BADRPT
|
||||
a*{1} C BADRPT
|
||||
a+{1} C BADRPT
|
||||
a?{1} C BADRPT
|
||||
a{1}* C BADRPT
|
||||
a{1}+ C BADRPT
|
||||
a{1}? C BADRPT
|
||||
a*{b} - a{b} a{b}
|
||||
a\{1\}\{1\} bC BADRPT
|
||||
a*\{1\} bC BADRPT
|
||||
a\{1\}* bC BADRPT
|
||||
|
||||
# brackets, and numerous perversions thereof
|
||||
a[b]c & abc abc
|
||||
a[ab]c & abc abc
|
||||
a[^ab]c & adc adc
|
||||
a[]b]c & a]c a]c
|
||||
a[[b]c & a[c a[c
|
||||
a[-b]c & a-c a-c
|
||||
a[^]b]c & adc adc
|
||||
a[^-b]c & adc adc
|
||||
a[b-]c & a-c a-c
|
||||
a[b &C EBRACK
|
||||
a[] &C EBRACK
|
||||
a[1-3]c & a2c a2c
|
||||
a[3-1]c &C ERANGE
|
||||
a[1-3-5]c &C ERANGE
|
||||
a[[.-.]--]c & a-c a-c
|
||||
a[1- &C ERANGE
|
||||
a[[. &C EBRACK
|
||||
a[[.x &C EBRACK
|
||||
a[[.x. &C EBRACK
|
||||
a[[.x.] &C EBRACK
|
||||
a[[.x.]] & ax ax
|
||||
a[[.x,.]] &C ECOLLATE
|
||||
a[[.one.]]b & a1b a1b
|
||||
a[[.notdef.]]b &C ECOLLATE
|
||||
a[[.].]]b & a]b a]b
|
||||
a[[:alpha:]]c & abc abc
|
||||
a[[:notdef:]]c &C ECTYPE
|
||||
a[[: &C EBRACK
|
||||
a[[:alpha &C EBRACK
|
||||
a[[:alpha:] &C EBRACK
|
||||
a[[:alpha,:] &C ECTYPE
|
||||
a[[:]:]]b &C ECTYPE
|
||||
a[[:-:]]b &C ECTYPE
|
||||
a[[:alph:]] &C ECTYPE
|
||||
a[[:alphabet:]] &C ECTYPE
|
||||
##[[:alnum:]]+ - -%@a0X- a0X
|
||||
##[[:alpha:]]+ - -%@aX0- aX
|
||||
[[:blank:]]+ - aSSTb SST
|
||||
##[[:cntrl:]]+ - aNTb NT
|
||||
[[:digit:]]+ - a019b 019
|
||||
##[[:graph:]]+ - Sa%bS a%b
|
||||
[[:lower:]]+ - AabC ab
|
||||
##[[:print:]]+ - NaSbN aSb
|
||||
##[[:punct:]]+ - S%-&T %-&
|
||||
[[:space:]]+ - aSNTb SNT
|
||||
[[:upper:]]+ - aBCd BC
|
||||
[[:xdigit:]]+ - p0f3Cq 0f3C
|
||||
a[[=b=]]c & abc abc
|
||||
a[[= &C EBRACK
|
||||
a[[=b &C EBRACK
|
||||
a[[=b= &C EBRACK
|
||||
a[[=b=] &C EBRACK
|
||||
a[[=b,=]] &C ECOLLATE
|
||||
a[[=one=]]b & a1b a1b
|
||||
|
||||
# complexities
|
||||
a(((b)))c - abc abc
|
||||
a(b|(c))d - abd abd
|
||||
a(b*|c)d - abbd abbd
|
||||
# just gotta have one DFA-buster, of course
|
||||
a[ab]{20} - aaaaabaaaabaaaabaaaab aaaaabaaaabaaaabaaaab
|
||||
# and an inline expansion in case somebody gets tricky
|
||||
a[ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab] - aaaaabaaaabaaaabaaaab aaaaabaaaabaaaabaaaab
|
||||
# and in case somebody just slips in an NFA...
|
||||
a[ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab](wee|week)(knights|night) - aaaaabaaaabaaaabaaaabweeknights aaaaabaaaabaaaabaaaabweeknights
|
||||
# fish for anomalies as the number of states passes 32
|
||||
12345678901234567890123456789 - a12345678901234567890123456789b 12345678901234567890123456789
|
||||
123456789012345678901234567890 - a123456789012345678901234567890b 123456789012345678901234567890
|
||||
1234567890123456789012345678901 - a1234567890123456789012345678901b 1234567890123456789012345678901
|
||||
12345678901234567890123456789012 - a12345678901234567890123456789012b 12345678901234567890123456789012
|
||||
123456789012345678901234567890123 - a123456789012345678901234567890123b 123456789012345678901234567890123
|
||||
# and one really big one, beyond any plausible word width
|
||||
1234567890123456789012345678901234567890123456789012345678901234567890 - a1234567890123456789012345678901234567890123456789012345678901234567890b 1234567890123456789012345678901234567890123456789012345678901234567890
|
||||
# fish for problems as brackets go past 8
|
||||
[ab][cd][ef][gh][ij][kl][mn] - xacegikmoq acegikm
|
||||
[ab][cd][ef][gh][ij][kl][mn][op] - xacegikmoq acegikmo
|
||||
[ab][cd][ef][gh][ij][kl][mn][op][qr] - xacegikmoqy acegikmoq
|
||||
[ab][cd][ef][gh][ij][kl][mn][op][q] - xacegikmoqy acegikmoq
|
||||
|
||||
# subtleties of matching
|
||||
abc & xabcy abc
|
||||
a\(b\)?c\1d b acd
|
||||
aBc i Abc Abc
|
||||
a[Bc]*d i abBCcd abBCcd
|
||||
0[[:upper:]]1 &i 0a1 0a1
|
||||
0[[:lower:]]1 &i 0A1 0A1
|
||||
a[^b]c &i abc
|
||||
a[^b]c &i aBc
|
||||
a[^b]c &i adc adc
|
||||
[a]b[c] - abc abc
|
||||
[a]b[a] - aba aba
|
||||
[abc]b[abc] - abc abc
|
||||
[abc]b[abd] - abd abd
|
||||
a(b?c)+d - accd accd
|
||||
(wee|week)(knights|night) - weeknights weeknights
|
||||
(we|wee|week|frob)(knights|night|day) - weeknights weeknights
|
||||
a[bc]d - xyzaaabcaababdacd abd
|
||||
a[ab]c - aaabc abc
|
||||
abc s abc abc
|
||||
a* & b @b
|
||||
|
||||
# Let's have some fun -- try to match a C comment.
|
||||
# first the obvious, which looks okay at first glance...
|
||||
/\*.*\*/ - /*x*/ /*x*/
|
||||
# but...
|
||||
/\*.*\*/ - /*x*/y/*z*/ /*x*/y/*z*/
|
||||
# okay, we must not match */ inside; try to do that...
|
||||
/\*([^*]|\*[^/])*\*/ - /*x*/ /*x*/
|
||||
/\*([^*]|\*[^/])*\*/ - /*x*/y/*z*/ /*x*/
|
||||
# but...
|
||||
/\*([^*]|\*[^/])*\*/ - /*x**/y/*z*/ /*x**/y/*z*/
|
||||
# and a still fancier version, which does it right (I think)...
|
||||
/\*([^*]|\*+[^*/])*\*+/ - /*x*/ /*x*/
|
||||
/\*([^*]|\*+[^*/])*\*+/ - /*x*/y/*z*/ /*x*/
|
||||
/\*([^*]|\*+[^*/])*\*+/ - /*x**/y/*z*/ /*x**/
|
||||
/\*([^*]|\*+[^*/])*\*+/ - /*x****/y/*z*/ /*x****/
|
||||
/\*([^*]|\*+[^*/])*\*+/ - /*x**x*/y/*z*/ /*x**x*/
|
||||
/\*([^*]|\*+[^*/])*\*+/ - /*x***x/y/*z*/ /*x***x/y/*z*/
|
||||
|
||||
# subexpressions
|
||||
a(b)(c)d - abcd abcd b,c
|
||||
a(((b)))c - abc abc b,b,b
|
||||
a(b|(c))d - abd abd b,-
|
||||
a(b*|c|e)d - abbd abbd bb
|
||||
a(b*|c|e)d - acd acd c
|
||||
a(b*|c|e)d - ad ad @d
|
||||
a(b?)c - abc abc b
|
||||
a(b?)c - ac ac @c
|
||||
a(b+)c - abc abc b
|
||||
a(b+)c - abbbc abbbc bbb
|
||||
a(b*)c - ac ac @c
|
||||
(a|ab)(bc([de]+)f|cde) - abcdef abcdef a,bcdef,de
|
||||
# the regression tester only asks for 9 subexpressions
|
||||
a(b)(c)(d)(e)(f)(g)(h)(i)(j)k - abcdefghijk abcdefghijk b,c,d,e,f,g,h,i,j
|
||||
a(b)(c)(d)(e)(f)(g)(h)(i)(j)(k)l - abcdefghijkl abcdefghijkl b,c,d,e,f,g,h,i,j,k
|
||||
a([bc]?)c - abc abc b
|
||||
a([bc]?)c - ac ac @c
|
||||
a([bc]+)c - abc abc b
|
||||
a([bc]+)c - abcc abcc bc
|
||||
a([bc]+)bc - abcbc abcbc bc
|
||||
a(bb+|b)b - abb abb b
|
||||
a(bbb+|bb+|b)b - abb abb b
|
||||
a(bbb+|bb+|b)b - abbb abbb bb
|
||||
a(bbb+|bb+|b)bb - abbb abbb b
|
||||
(.*).* - abcdef abcdef abcdef
|
||||
##(a*)* - bc @b @b
|
||||
|
||||
# do we get the right subexpression when it is used more than once?
|
||||
a(b|c)*d - ad ad -
|
||||
a(b|c)*d - abcd abcd c
|
||||
a(b|c)+d - abd abd b
|
||||
a(b|c)+d - abcd abcd c
|
||||
a(b|c?)+d - ad ad @d
|
||||
a(b|c?)+d - abcd abcd @d
|
||||
a(b|c){0,0}d - ad ad -
|
||||
a(b|c){0,1}d - ad ad -
|
||||
a(b|c){0,1}d - abd abd b
|
||||
a(b|c){0,2}d - ad ad -
|
||||
a(b|c){0,2}d - abcd abcd c
|
||||
a(b|c){0,}d - ad ad -
|
||||
a(b|c){0,}d - abcd abcd c
|
||||
a(b|c){1,1}d - abd abd b
|
||||
a(b|c){1,1}d - acd acd c
|
||||
a(b|c){1,2}d - abd abd b
|
||||
a(b|c){1,2}d - abcd abcd c
|
||||
a(b|c){1,}d - abd abd b
|
||||
a(b|c){1,}d - abcd abcd c
|
||||
a(b|c){2,2}d - acbd acbd b
|
||||
a(b|c){2,2}d - abcd abcd c
|
||||
a(b|c){2,4}d - abcd abcd c
|
||||
a(b|c){2,4}d - abcbd abcbd b
|
||||
a(b|c){2,4}d - abcbcd abcbcd c
|
||||
a(b|c){2,}d - abcd abcd c
|
||||
a(b|c){2,}d - abcbd abcbd b
|
||||
##a(b+|((c)*))+d - abd abd @d,@d,-
|
||||
##a(b+|((c)*))+d - abcd abcd @d,@d,-
|
||||
|
||||
# check out the STARTEND option
|
||||
[abc] &# a(b)c b
|
||||
[abc] &# a(d)c
|
||||
[abc] &# a(bc)d b
|
||||
[abc] &# a(dc)d c
|
||||
. &# a()c
|
||||
b.*c &# b(bc)c bc
|
||||
b.* &# b(bc)c bc
|
||||
.*c &# b(bc)c bc
|
||||
|
||||
# plain strings, with the NOSPEC flag
|
||||
abc m abc abc
|
||||
abc m xabcy abc
|
||||
abc m xyz
|
||||
a*b m aba*b a*b
|
||||
a*b m ab
|
||||
"" mC EMPTY
|
||||
|
||||
# cases involving NULs
|
||||
aZb & a a
|
||||
aZb &p a
|
||||
#aZb &p# (aZb) aZb
|
||||
aZ*b &p# (ab) ab
|
||||
#a.b &# (aZb) aZb
|
||||
#a.* &# (aZb)c aZb
|
||||
|
||||
# word boundaries (ick)
|
||||
[[:<:]]a & a a
|
||||
[[:<:]]a & ba
|
||||
[[:<:]]a & -a a
|
||||
a[[:>:]] & a a
|
||||
a[[:>:]] & ab
|
||||
a[[:>:]] & a- a
|
||||
[[:<:]]a.c[[:>:]] & axcd-dayc-dazce-abc abc
|
||||
[[:<:]]a.c[[:>:]] & axcd-dayc-dazce-abc-q abc
|
||||
[[:<:]]a.c[[:>:]] & axc-dayc-dazce-abc axc
|
||||
[[:<:]]b.c[[:>:]] & a_bxc-byc_d-bzc-q bzc
|
||||
[[:<:]].x..[[:>:]] & y_xa_-_xb_y-_xc_-axdc _xc_
|
||||
[[:<:]]a_b[[:>:]] & x_a_b
|
||||
|
||||
# past problems, and suspected problems
|
||||
(A[1])|(A[2])|(A[3])|(A[4])|(A[5])|(A[6])|(A[7])|(A[8])|(A[9])|(A[A]) - A1 A1
|
||||
abcdefghijklmnop i abcdefghijklmnop abcdefghijklmnop
|
||||
abcdefghijklmnopqrstuv i abcdefghijklmnopqrstuv abcdefghijklmnopqrstuv
|
||||
(ALAK)|(ALT[AB])|(CC[123]1)|(CM[123]1)|(GAMC)|(LC[23][EO ])|(SEM[1234])|(SL[ES][12])|(SLWW)|(SLF )|(SLDT)|(VWH[12])|(WH[34][EW])|(WP1[ESN]) - CC11 CC11
|
||||
CC[13]1|a{21}[23][EO][123][Es][12]a{15}aa[34][EW]aaaaaaa[X]a - CC11 CC11
|
||||
Char \([a-z0-9_]*\)\[.* b Char xyz[k Char xyz[k xyz
|
||||
a?b - ab ab
|
||||
-\{0,1\}[0-9]*$ b -5 -5
|
@ -1,19 +0,0 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# Tell them not to be alarmed.
|
||||
|
||||
: ${srcdir=.}
|
||||
|
||||
failures=0
|
||||
|
||||
#
|
||||
cat <<\EOF
|
||||
|
||||
Please, do not be alarmed if some of the tests failed.
|
||||
Report them to <bug-gnu-utils@gnu.org>,
|
||||
with the line number, the name of the file,
|
||||
and grep version number 'grep --version'.
|
||||
Make sure you have the word grep in the subject.
|
||||
Thank You.
|
||||
|
||||
EOF
|
@ -1,87 +0,0 @@
|
||||
/* xalloc.h -- malloc with out-of-memory checking
|
||||
Copyright (C) 1990-1998, 1999, 2000 Free Software Foundation, Inc.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software Foundation,
|
||||
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
||||
|
||||
#ifndef XALLOC_H_
|
||||
# define XALLOC_H_
|
||||
|
||||
# ifndef PARAMS
|
||||
# if defined PROTOTYPES || (defined __STDC__ && __STDC__)
|
||||
# define PARAMS(Args) Args
|
||||
# else
|
||||
# define PARAMS(Args) ()
|
||||
# endif
|
||||
# endif
|
||||
|
||||
# ifndef __attribute__
|
||||
# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 8) || __STRICT_ANSI__
|
||||
# define __attribute__(x)
|
||||
# endif
|
||||
# endif
|
||||
|
||||
# ifndef ATTRIBUTE_NORETURN
|
||||
# define ATTRIBUTE_NORETURN __attribute__ ((__noreturn__))
|
||||
# endif
|
||||
|
||||
/* Exit value when the requested amount of memory is not available.
|
||||
It is initialized to EXIT_FAILURE, but the caller may set it to
|
||||
some other value. */
|
||||
extern int xalloc_exit_failure;
|
||||
|
||||
/* If this pointer is non-zero, run the specified function upon each
|
||||
allocation failure. It is initialized to zero. */
|
||||
extern void (*xalloc_fail_func) PARAMS ((void));
|
||||
|
||||
/* If XALLOC_FAIL_FUNC is undefined or a function that returns, this
|
||||
message is output. It is translated via gettext.
|
||||
Its value is "memory exhausted". */
|
||||
extern char const xalloc_msg_memory_exhausted[];
|
||||
|
||||
/* This function is always triggered when memory is exhausted. It is
|
||||
in charge of honoring the three previous items. This is the
|
||||
function to call when one wants the program to die because of a
|
||||
memory allocation failure. */
|
||||
extern void xalloc_die PARAMS ((void)) ATTRIBUTE_NORETURN;
|
||||
|
||||
void *xmalloc PARAMS ((size_t n));
|
||||
void *xcalloc PARAMS ((size_t n, size_t s));
|
||||
void *xrealloc PARAMS ((void *p, size_t n));
|
||||
char *xstrdup PARAMS ((const char *str));
|
||||
|
||||
# define XMALLOC(Type, N_items) ((Type *) xmalloc (sizeof (Type) * (N_items)))
|
||||
# define XCALLOC(Type, N_items) ((Type *) xcalloc (sizeof (Type), (N_items)))
|
||||
# define XREALLOC(Ptr, Type, N_items) \
|
||||
((Type *) xrealloc ((void *) (Ptr), sizeof (Type) * (N_items)))
|
||||
|
||||
/* Declare and alloc memory for VAR of type TYPE. */
|
||||
# define NEW(Type, Var) Type *(Var) = XMALLOC (Type, 1)
|
||||
|
||||
/* Free VAR only if non NULL. */
|
||||
# define XFREE(Var) \
|
||||
do { \
|
||||
if (Var) \
|
||||
free (Var); \
|
||||
} while (0)
|
||||
|
||||
/* Return a pointer to a malloc'ed copy of the array SRC of NUM elements. */
|
||||
# define CCLONE(Src, Num) \
|
||||
(memcpy (xmalloc (sizeof (*Src) * (Num)), (Src), sizeof (*Src) * (Num)))
|
||||
|
||||
/* Return a malloc'ed copy of SRC. */
|
||||
# define CLONE(Src) CCLONE (Src, 1)
|
||||
|
||||
|
||||
#endif /* !XALLOC_H_ */
|
@ -1,116 +0,0 @@
|
||||
/* xmalloc.c -- malloc with out of memory checking
|
||||
Copyright (C) 1990-1999, 2000 Free Software Foundation, Inc.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software Foundation,
|
||||
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
||||
|
||||
#if HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#if STDC_HEADERS
|
||||
# include <stdlib.h>
|
||||
#else
|
||||
void *calloc ();
|
||||
void *malloc ();
|
||||
void *realloc ();
|
||||
void free ();
|
||||
#endif
|
||||
|
||||
#if ENABLE_NLS
|
||||
# include <libintl.h>
|
||||
# define _(Text) gettext (Text)
|
||||
#else
|
||||
# define textdomain(Domain)
|
||||
# define _(Text) Text
|
||||
#endif
|
||||
#define N_(Text) Text
|
||||
|
||||
#include "error.h"
|
||||
#include "xalloc.h"
|
||||
|
||||
#ifndef EXIT_FAILURE
|
||||
# define EXIT_FAILURE 1
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_DONE_WORKING_MALLOC_CHECK
|
||||
"you must run the autoconf test for a properly working malloc -- see malloc.m4"
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_DONE_WORKING_REALLOC_CHECK
|
||||
"you must run the autoconf test for a properly working realloc --see realloc.m4"
|
||||
#endif
|
||||
|
||||
/* Exit value when the requested amount of memory is not available.
|
||||
The caller may set it to some other value. */
|
||||
int xalloc_exit_failure = EXIT_FAILURE;
|
||||
|
||||
/* If non NULL, call this function when memory is exhausted. */
|
||||
void (*xalloc_fail_func) PARAMS ((void)) = 0;
|
||||
|
||||
/* If XALLOC_FAIL_FUNC is NULL, or does return, display this message
|
||||
before exiting when memory is exhausted. Goes through gettext. */
|
||||
char const xalloc_msg_memory_exhausted[] = N_("memory exhausted");
|
||||
|
||||
void
|
||||
xalloc_die (void)
|
||||
{
|
||||
if (xalloc_fail_func)
|
||||
(*xalloc_fail_func) ();
|
||||
error (xalloc_exit_failure, 0, "%s", _(xalloc_msg_memory_exhausted));
|
||||
/* The `noreturn' cannot be given to error, since it may return if
|
||||
its first argument is 0. To help compilers understand the
|
||||
xalloc_die does terminate, call exit. */
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
|
||||
/* Allocate N bytes of memory dynamically, with error checking. */
|
||||
|
||||
void *
|
||||
xmalloc (size_t n)
|
||||
{
|
||||
void *p;
|
||||
|
||||
p = malloc (n);
|
||||
if (p == 0)
|
||||
xalloc_die ();
|
||||
return p;
|
||||
}
|
||||
|
||||
/* Change the size of an allocated block of memory P to N bytes,
|
||||
with error checking. */
|
||||
|
||||
void *
|
||||
xrealloc (void *p, size_t n)
|
||||
{
|
||||
p = realloc (p, n);
|
||||
if (p == 0)
|
||||
xalloc_die ();
|
||||
return p;
|
||||
}
|
||||
|
||||
/* Allocate memory for N elements of S bytes, with error checking. */
|
||||
|
||||
void *
|
||||
xcalloc (size_t n, size_t s)
|
||||
{
|
||||
void *p;
|
||||
|
||||
p = calloc (n, s);
|
||||
if (p == 0)
|
||||
xalloc_die ();
|
||||
return p;
|
||||
}
|
@ -1,282 +0,0 @@
|
||||
/* A more useful interface to strtol.
|
||||
Copyright (C) 1995, 1996, 1998-2000 Free Software Foundation, Inc.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software Foundation,
|
||||
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
||||
|
||||
/* Written by Jim Meyering. */
|
||||
|
||||
#if HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#ifndef __strtol
|
||||
# define __strtol strtol
|
||||
# define __strtol_t long int
|
||||
# define __xstrtol xstrtol
|
||||
#endif
|
||||
|
||||
/* Some pre-ANSI implementations (e.g. SunOS 4)
|
||||
need stderr defined if assertion checking is enabled. */
|
||||
#include <stdio.h>
|
||||
|
||||
#if STDC_HEADERS
|
||||
# include <stdlib.h>
|
||||
#endif
|
||||
|
||||
#if HAVE_STRING_H
|
||||
# include <string.h>
|
||||
#else
|
||||
# include <strings.h>
|
||||
# ifndef strchr
|
||||
# define strchr index
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#include <assert.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#include <errno.h>
|
||||
#ifndef errno
|
||||
extern int errno;
|
||||
#endif
|
||||
|
||||
#if HAVE_LIMITS_H
|
||||
# include <limits.h>
|
||||
#endif
|
||||
|
||||
#ifndef CHAR_BIT
|
||||
# define CHAR_BIT 8
|
||||
#endif
|
||||
|
||||
/* The extra casts work around common compiler bugs. */
|
||||
#define TYPE_SIGNED(t) (! ((t) 0 < (t) -1))
|
||||
/* The outer cast is needed to work around a bug in Cray C 5.0.3.0.
|
||||
It is necessary at least when t == time_t. */
|
||||
#define TYPE_MINIMUM(t) ((t) (TYPE_SIGNED (t) \
|
||||
? ~ (t) 0 << (sizeof (t) * CHAR_BIT - 1) : (t) 0))
|
||||
#define TYPE_MAXIMUM(t) (~ (t) 0 - TYPE_MINIMUM (t))
|
||||
|
||||
#if defined (STDC_HEADERS) || (!defined (isascii) && !defined (HAVE_ISASCII))
|
||||
# define IN_CTYPE_DOMAIN(c) 1
|
||||
#else
|
||||
# define IN_CTYPE_DOMAIN(c) isascii(c)
|
||||
#endif
|
||||
|
||||
#define ISSPACE(c) (IN_CTYPE_DOMAIN (c) && isspace (c))
|
||||
|
||||
#include "xstrtol.h"
|
||||
|
||||
#ifndef strtol
|
||||
long int strtol ();
|
||||
#endif
|
||||
|
||||
#ifndef strtoul
|
||||
unsigned long int strtoul ();
|
||||
#endif
|
||||
|
||||
#ifndef strtoumax
|
||||
uintmax_t strtoumax ();
|
||||
#endif
|
||||
|
||||
static int
|
||||
bkm_scale (__strtol_t *x, int scale_factor)
|
||||
{
|
||||
__strtol_t product = *x * scale_factor;
|
||||
if (*x != product / scale_factor)
|
||||
return 1;
|
||||
*x = product;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
bkm_scale_by_power (__strtol_t *x, int base, int power)
|
||||
{
|
||||
while (power--)
|
||||
if (bkm_scale (x, base))
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* FIXME: comment. */
|
||||
|
||||
strtol_error
|
||||
__xstrtol (const char *s, char **ptr, int strtol_base,
|
||||
__strtol_t *val, const char *valid_suffixes)
|
||||
{
|
||||
char *t_ptr;
|
||||
char **p;
|
||||
__strtol_t tmp;
|
||||
|
||||
assert (0 <= strtol_base && strtol_base <= 36);
|
||||
|
||||
p = (ptr ? ptr : &t_ptr);
|
||||
|
||||
if (! TYPE_SIGNED (__strtol_t))
|
||||
{
|
||||
const char *q = s;
|
||||
while (ISSPACE ((unsigned char) *q))
|
||||
++q;
|
||||
if (*q == '-')
|
||||
return LONGINT_INVALID;
|
||||
}
|
||||
|
||||
errno = 0;
|
||||
tmp = __strtol (s, p, strtol_base);
|
||||
if (errno != 0)
|
||||
return LONGINT_OVERFLOW;
|
||||
if (*p == s)
|
||||
return LONGINT_INVALID;
|
||||
|
||||
/* Let valid_suffixes == NULL mean `allow any suffix'. */
|
||||
/* FIXME: update all callers except the ones that allow suffixes
|
||||
after the number, changing last parameter NULL to `""'. */
|
||||
if (!valid_suffixes)
|
||||
{
|
||||
*val = tmp;
|
||||
return LONGINT_OK;
|
||||
}
|
||||
|
||||
if (**p != '\0')
|
||||
{
|
||||
int base = 1024;
|
||||
int suffixes = 1;
|
||||
int overflow;
|
||||
|
||||
if (!strchr (valid_suffixes, **p))
|
||||
{
|
||||
*val = tmp;
|
||||
return LONGINT_INVALID_SUFFIX_CHAR;
|
||||
}
|
||||
|
||||
if (strchr (valid_suffixes, '0'))
|
||||
{
|
||||
/* The ``valid suffix'' '0' is a special flag meaning that
|
||||
an optional second suffix is allowed, which can change
|
||||
the base, e.g. "100MD" for 100 megabytes decimal. */
|
||||
|
||||
switch (p[0][1])
|
||||
{
|
||||
case 'B':
|
||||
suffixes++;
|
||||
break;
|
||||
|
||||
case 'D':
|
||||
base = 1000;
|
||||
suffixes++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
switch (**p)
|
||||
{
|
||||
case 'b':
|
||||
overflow = bkm_scale (&tmp, 512);
|
||||
break;
|
||||
|
||||
case 'B':
|
||||
overflow = bkm_scale (&tmp, 1024);
|
||||
break;
|
||||
|
||||
case 'c':
|
||||
overflow = 0;
|
||||
break;
|
||||
|
||||
case 'E': /* Exa */
|
||||
overflow = bkm_scale_by_power (&tmp, base, 6);
|
||||
break;
|
||||
|
||||
case 'G': /* Giga */
|
||||
overflow = bkm_scale_by_power (&tmp, base, 3);
|
||||
break;
|
||||
|
||||
case 'k': /* kilo */
|
||||
overflow = bkm_scale_by_power (&tmp, base, 1);
|
||||
break;
|
||||
|
||||
case 'M': /* Mega */
|
||||
case 'm': /* 'm' is undocumented; for backward compatibility only */
|
||||
overflow = bkm_scale_by_power (&tmp, base, 2);
|
||||
break;
|
||||
|
||||
case 'P': /* Peta */
|
||||
overflow = bkm_scale_by_power (&tmp, base, 5);
|
||||
break;
|
||||
|
||||
case 'T': /* Tera */
|
||||
overflow = bkm_scale_by_power (&tmp, base, 4);
|
||||
break;
|
||||
|
||||
case 'w':
|
||||
overflow = bkm_scale (&tmp, 2);
|
||||
break;
|
||||
|
||||
case 'Y': /* Yotta */
|
||||
overflow = bkm_scale_by_power (&tmp, base, 8);
|
||||
break;
|
||||
|
||||
case 'Z': /* Zetta */
|
||||
overflow = bkm_scale_by_power (&tmp, base, 7);
|
||||
break;
|
||||
|
||||
default:
|
||||
*val = tmp;
|
||||
return LONGINT_INVALID_SUFFIX_CHAR;
|
||||
break;
|
||||
}
|
||||
|
||||
if (overflow)
|
||||
return LONGINT_OVERFLOW;
|
||||
|
||||
(*p) += suffixes;
|
||||
}
|
||||
|
||||
*val = tmp;
|
||||
return LONGINT_OK;
|
||||
}
|
||||
|
||||
#ifdef TESTING_XSTRTO
|
||||
|
||||
# include <stdio.h>
|
||||
# include "error.h"
|
||||
|
||||
char *program_name;
|
||||
|
||||
int
|
||||
main (int argc, char** argv)
|
||||
{
|
||||
strtol_error s_err;
|
||||
int i;
|
||||
|
||||
program_name = argv[0];
|
||||
for (i=1; i<argc; i++)
|
||||
{
|
||||
char *p;
|
||||
__strtol_t val;
|
||||
|
||||
s_err = __xstrtol (argv[i], &p, 0, &val, "bckmw");
|
||||
if (s_err == LONGINT_OK)
|
||||
{
|
||||
printf ("%s->%lu (%s)\n", argv[i], val, p);
|
||||
}
|
||||
else
|
||||
{
|
||||
STRTOL_FATAL_ERROR (argv[i], "arg", s_err);
|
||||
}
|
||||
}
|
||||
exit (0);
|
||||
}
|
||||
|
||||
#endif /* TESTING_XSTRTO */
|
@ -1,64 +0,0 @@
|
||||
#ifndef XSTRTOL_H_
|
||||
# define XSTRTOL_H_ 1
|
||||
|
||||
# if HAVE_INTTYPES_H
|
||||
# include <inttypes.h> /* for uintmax_t */
|
||||
# endif
|
||||
|
||||
# ifndef PARAMS
|
||||
# if defined PROTOTYPES || (defined __STDC__ && __STDC__)
|
||||
# define PARAMS(Args) Args
|
||||
# else
|
||||
# define PARAMS(Args) ()
|
||||
# endif
|
||||
# endif
|
||||
|
||||
# ifndef _STRTOL_ERROR
|
||||
enum strtol_error
|
||||
{
|
||||
LONGINT_OK, LONGINT_INVALID, LONGINT_INVALID_SUFFIX_CHAR, LONGINT_OVERFLOW
|
||||
};
|
||||
typedef enum strtol_error strtol_error;
|
||||
# endif
|
||||
|
||||
# define _DECLARE_XSTRTOL(name, type) \
|
||||
strtol_error \
|
||||
name PARAMS ((const char *s, char **ptr, int base, \
|
||||
type *val, const char *valid_suffixes));
|
||||
_DECLARE_XSTRTOL (xstrtol, long int)
|
||||
_DECLARE_XSTRTOL (xstrtoul, unsigned long int)
|
||||
_DECLARE_XSTRTOL (xstrtoumax, uintmax_t)
|
||||
|
||||
# define _STRTOL_ERROR(Exit_code, Str, Argument_type_string, Err) \
|
||||
do \
|
||||
{ \
|
||||
switch ((Err)) \
|
||||
{ \
|
||||
case LONGINT_OK: \
|
||||
abort (); \
|
||||
\
|
||||
case LONGINT_INVALID: \
|
||||
error ((Exit_code), 0, "invalid %s `%s'", \
|
||||
(Argument_type_string), (Str)); \
|
||||
break; \
|
||||
\
|
||||
case LONGINT_INVALID_SUFFIX_CHAR: \
|
||||
error ((Exit_code), 0, "invalid character following %s `%s'", \
|
||||
(Argument_type_string), (Str)); \
|
||||
break; \
|
||||
\
|
||||
case LONGINT_OVERFLOW: \
|
||||
error ((Exit_code), 0, "%s `%s' too large", \
|
||||
(Argument_type_string), (Str)); \
|
||||
break; \
|
||||
} \
|
||||
} \
|
||||
while (0)
|
||||
|
||||
# define STRTOL_FATAL_ERROR(Str, Argument_type_string, Err) \
|
||||
_STRTOL_ERROR (2, Str, Argument_type_string, Err)
|
||||
|
||||
# define STRTOL_FAIL_WARN(Str, Argument_type_string, Err) \
|
||||
_STRTOL_ERROR (0, Str, Argument_type_string, Err)
|
||||
|
||||
#endif /* not XSTRTOL_H_ */
|
@ -1,31 +0,0 @@
|
||||
/* xstrtoumax.c -- A more useful interface to strtoumax.
|
||||
Copyright 1999 Free Software Foundation, Inc.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software Foundation,
|
||||
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
||||
|
||||
/* Written by Paul Eggert. */
|
||||
|
||||
#if HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#if HAVE_INTTYPES_H
|
||||
# include <inttypes.h>
|
||||
#endif
|
||||
|
||||
#define __strtol strtoumax
|
||||
#define __strtol_t uintmax_t
|
||||
#define __xstrtol xstrtoumax
|
||||
#include "xstrtol.c"
|
Loading…
Reference in New Issue
Block a user