Commit Graph

157 Commits

Author SHA1 Message Date
Pedro F. Giffuni
eab20bceca regex: Remove some unreachable breaks.
This is based on a much bigger cleanup done in Illumos.

Reference:
https://www.illumos.org/issues/2077

MFC after:	1 week
2014-05-01 23:34:14 +00:00
Marcel Moolenaar
8876613dc5 Replace use of ${.CURDIR} by ${LIBC_SRCTOP} and define ${LIBC_SRCTOP}
if not already defined. This allows building libc from outside of
lib/libc using a reach-over makefile.

A typical use-case is to build a standard ILP32 version and a COMPAT32
version in a single iteration by building the COMPAT32 version using a
reach-over makefile.

Obtained from:	Juniper Networks, Inc.
2014-03-04 02:19:39 +00:00
Xin LI
d0ebccde13 Fix assignment of maximum bounadary.
Submitted by:	Sascha Wildner <saw online de>
Obtained from:	DragonFly rev fd39c81ba220f7ad6e4dc9b30d45e828cf58a1ad
MFC after:	2 weeks
2013-03-01 23:26:13 +00:00
David Chisnall
7dfd88318b Remove some duplicated copyright notices.
Approved by:	dim (mentor)
2012-03-06 12:53:44 +00:00
David Chisnall
3c87aa1d3d Implement xlocale APIs from Darwin, mainly for use by libc++. This adds a
load of _l suffixed versions of various standard library functions that use
the global locale, making them take an explicit locale parameter.  Also
adds support for per-thread locales.  This work was funded by the FreeBSD
Foundation.

Please test any code you have that uses the C standard locale functions!

Reviewed by:    das (gdtoa changes)
Approved by:    dim (mentor)
2011-11-20 14:45:42 +00:00
Kevin Lo
5249ac8610 Converting int to wint_t leads to broekn comparison of raw char
and encoded wint_t.

Spotted by:	ache
2011-11-11 01:35:07 +00:00
Kevin Lo
2bf213eb6c - Don't handle out-of-memory condition
- Fix types of function arguments match their declaration

Reviewed by:	delphij
Obtained from:	NetBSD
2011-11-10 01:44:05 +00:00
Ulrich Spörlein
0d9deed52c mdoc: drop redundant .Pp and .LP calls
They have no effect when coming in pairs, or before .Bl/.Bd
2010-10-08 12:40:16 +00:00
Diomidis Spinellis
e7cbc6ee95 Fix an off-by-one error in the marking of the O_CH operator
following an OOR2 operator.

PR:		130504
MFC after:	2 weeks
2009-09-16 06:32:23 +00:00
Diomidis Spinellis
bca3476acd Add a couple of debugging statements. 2009-09-16 06:29:23 +00:00
Diomidis Spinellis
b7bb894067 Add two test cases from PR 130504.
An additional one coming from http://www.research.att.com/~gsf/testregex/
was not added; at some point the entire AT&T regression test harness
should be imported here.
But that would also mean commitment to fix the uncovered errors.

PR:		130504
Submitted by:	Chris Kuklewicz
2009-09-15 21:15:29 +00:00
Giorgos Keramidas
0efdfdee5f Add two example regexps: (1) one for matching all the characters
that belong in a character class, and (2) one for matching all
the characters *not* in a character class.

Submitted by:	Mark B, mkbucc at gmail.com
MFC after:	3 days
2008-09-05 17:41:20 +00:00
Kevin Lo
8f9872ccb3 getopt(3) returns -1, not EOF. 2008-02-18 03:19:25 +00:00
Xin LI
54a648d1e5 Diff reduction against other *BSDs: ANSIfy function
prototypes.  No function changes.
2007-06-11 03:05:54 +00:00
Xin LI
eb2b3d109a Const'ify and ANSIfy the internal interfaces of regex(3).
This is the final change that makes libc to compile with
WERROR on my amd64 crashbox.
2007-05-25 12:44:58 +00:00
Daniel Eischen
5f864214bb Use C comments since we now preprocess these files with CPP. 2007-04-29 14:05:22 +00:00
Xin LI
2f1b6e8bb5 Test cases for back references.
Obtained from:	OpenBSD
2007-03-05 09:44:41 +00:00
Xin LI
082063a051 Only stop evaluation of a back reference if the match length is
zero and the recursion level is too deep.

Obtained from:	OpenBSD
2007-03-05 09:43:55 +00:00
Xin LI
0f4481c5e4 Avoid infinite recursion on:
echo "foo foo bar bar bar baz" | sed 's/\([^ ]*\)\( *\1\)*/\1/g'

Obtained from:	OpenBSD via NetBSD (rev. 1.18)
2007-03-05 03:07:36 +00:00
Warner Losh
c879ae3536 Per Regents of the University of Calfornia letter, remove advertising
clause.

# If I've done so improperly on a file, please let me know.
2007-01-09 00:28:16 +00:00
Daniel Eischen
6fad3aaf15 Add each directory's symbol map file to SYM_MAPS. 2006-03-13 01:15:01 +00:00
Daniel Eischen
cce72e8860 Add symbol maps and initial symbol version definitions to libc.
Reviewed by:	davidxu
2006-03-13 00:53:21 +00:00
Stefan Farfeleder
69053d669e Use prototypes for CHIN1() and CHIN(). 2005-09-12 16:02:54 +00:00
Tim J. Robbins
1ee0dbee57 Fix a boundary condition error in slow() and fast() in multibyte locales:
we must allow the character beginning at "p" to be converted to a wide
character for the purposes of EOL processing and word-boundary matching.
2005-08-17 11:37:38 +00:00
Tim J. Robbins
0eac054729 Document the fact that word-boundary matching does not work
properly in multibyte locales.
2005-08-17 11:21:15 +00:00
Tim J. Robbins
0853006ff1 Change OUT from -2 to CHAR_MIN-1, making it impossible for it to
inadvertently match a negative char in the RE being compiled.

This fixes compilation of "\376" (as an ERE) and "\376\376" (as a BRE).

PR:		84740
MFC after:	1 week
2005-08-13 02:30:15 +00:00
Xin LI
b49627d7a7 Remove unused file.
Confirmed by:	tjr [1]

[1] PERFORCE CHANGESET 57044:
	http://perforce.freebsd.org/changeView.cgi?CH=57044
2005-04-25 02:29:03 +00:00
Ruslan Ermilov
0227791b40 Expand *n't contractions. 2005-02-13 22:25:33 +00:00
Ruslan Ermilov
24a0682c64 Sort sections. 2005-01-20 09:17:07 +00:00
Diomidis Spinellis
c7ce9e21f8 Plug memory leak.
PR:		bin/75656
MFC after:	2 weeks
2004-12-30 14:27:57 +00:00
Tim J. Robbins
bd9643b135 Fix computation of the 'n' argument to mbrtowc (through XMBRTOWC) to avoid
reading past 'stop' in various places when converting multibyte characters.
Reading too far caused truncation to not be detected when it should have
been, eventually causing regexec() to loop infinitely in with certain
combinations of patterns and strings in multibyte locales.

PR:		74020
MFC after:	4 weeks
2004-11-21 03:14:32 +00:00
Stefan Farfeleder
4e8c80e977 Directly include <runetype.h> for _CurrentRuneLocale, <_ctype.h> doesn't
include it in all cases.
2004-10-03 15:42:59 +00:00
Tim J. Robbins
33176f1755 Fix two problems with REG_ICASE that were introduced with the addition of
multibyte character support:
- In CHadd(), avoid writing past the end of the character set bitmap when
  the opposite-case counterpart of wide characters with values less than
  NC have values greater than or equal to NC.
- In CHaddtype(), fix a braino that caused alphabetic characters to be
  added to all character classes! (but only with REG_ICASE)

PR:		71367
2004-09-05 08:30:42 +00:00
Tim J. Robbins
2ff3ba336e Update paths to reg*.c and regex2.h. Add a target to build regex.h. 2004-07-19 08:48:17 +00:00
Tim J. Robbins
405033831e Update for removal of cclass.h. Trim some useless targets. Invoke mkh
with "sh mkh" so it works if the script is not executable.
2004-07-19 08:41:11 +00:00
Tim J. Robbins
ec8b0411f1 Update for recent changes to struct re_guts. Disable printing the contents
of OANYOF sets for the moment.
2004-07-19 08:28:53 +00:00
Tim J. Robbins
f420a25887 Remove unused files. 2004-07-19 08:24:21 +00:00
Tim J. Robbins
ee5d8a1b0a Remove an entry from the BUGS section: we have multibyte character
support now.
2004-07-12 11:03:42 +00:00
Tim J. Robbins
e5996857ad Make regular expression matching aware of multibyte characters. The general
idea is that we perform multibyte->wide character conversion while parsing
and compiling, then convert byte sequences to wide characters when they're
needed for comparison and stepping through the string during execution.

As with tr(1), the main complication is to efficiently represent sets of
characters in bracket expressions. The old bitmap representation is replaced
by a bitmap for the first 256 characters combined with a vector of individual
wide characters, a vector of character ranges (for [A-Z] etc.), and a vector
of character classes (for [[:alpha:]] etc.).

One other point of interest is that although the Boyer-Moore algorithm had
to be disabled in the general multibyte case, it is still enabled for UTF-8
because of its self-synchronizing nature. This greatly speeds up matching
by reducing the number of multibyte conversions that need to be done.
2004-07-12 07:35:59 +00:00
Tim J. Robbins
67aff1896c Add a new error code, REG_ILLSEQ, to indicate that a regular expression
contains an illegal multibyte character sequence.
2004-07-12 06:07:26 +00:00
Tim J. Robbins
80f363668e Remove incomplete support for multi-character collating elements. Remove
unused character category calculations.
2004-07-11 05:58:31 +00:00
Tim J. Robbins
65b2e19ef7 Document incorrect handling of multibyte characters. 2004-07-06 09:20:51 +00:00
Ruslan Ermilov
1a0a934547 Mechanically kill hard sentence breaks. 2004-07-02 23:52:20 +00:00
Ruslan Ermilov
fe08efe680 mdoc(7): Use the new feature of the .In macro. 2003-09-08 19:57:22 +00:00
Jacques Vidrine
e0554a531f Eliminate 61 warnings emitted at WARNS=2 (leaving 53 to go).
Only warnings that could be fixed without changing the generated object
code and without restructuring the source code have been handled.

Reviewed by:	/sbin/md5
2003-02-16 17:29:11 +00:00
Ruslan Ermilov
2efeeba554 mdoc(7) police: "The .Fa argument.". 2002-12-19 09:40:28 +00:00
Ruslan Ermilov
1fae73b137 mdoc(7) police: "The .Fn function". 2002-12-18 12:45:11 +00:00
Ruslan Ermilov
c51d717f0c libc_r wasn't so tied to libc for 22 months. 2002-11-18 09:50:57 +00:00
Mike Barcroft
4047df8d24 Add restrict type-qualifier. 2002-10-02 07:49:35 +00:00
Philippe Charnier
7fed38d0a0 Replace various spelling with FALLTHROUGH which is lint()able 2002-08-25 13:10:45 +00:00
David E. O'Brien
1114a754ed Fix the style of the SCM ID's.
I believe have made all of libc .h's as consistent as possible.
2002-03-22 23:42:05 +00:00
David E. O'Brien
333fc21e3c Fix the style of the SCM ID's.
I believe have made all of libc .c's as consistent as possible.
2002-03-22 21:53:29 +00:00
David E. O'Brien
4b74b09895 Back out last commit (rev 1.2). I thought I caught this file in time
when deP'ing.  But I guess not.
2002-03-22 19:45:43 +00:00
David E. O'Brien
c05ac53b8b Remove __P() usage. 2002-03-21 22:49:10 +00:00
David E. O'Brien
8fb3f3f682 Remove 'register' keyword. 2002-03-21 18:49:23 +00:00
Ruslan Ermilov
0c7f152b7b Fix a typo I made in revision 1.5.
Submitted by:	trevor
2002-01-22 12:38:43 +00:00
Daniel C. Sobral
8e2f75b833 The algorithm that computes the tables used in the BM search algorithm sometimes
access an array beyond it's length. This only happens in the last iteration of
a loop, and the value fetched is not used then, so the bug is a relatively
innocent one. Fix this by not fetching any value on the last iteration of said
loop.

Submitted by:	MKI <mki@mozone.net>
MFC after:	1 week
2001-11-09 10:17:44 +00:00
Ruslan Ermilov
32eef9aeb1 mdoc(7) police: Use the new .In macro for #include statements. 2001-10-01 16:09:29 +00:00
Ruslan Ermilov
57e4378bf6 mdoc(7) police: protect trailing full stops of abbreviations
with a trailing zero-width space: `e.g.\&'.
2001-08-10 13:45:36 +00:00
Ruslan Ermilov
c4d9468ea0 mdoc(7) police:
Avoid using parenthesis enclosure macros (.Pq and .Po/.Pc) with plain text.
Not only this slows down the mdoc(7) processing significantly, but it also
has an undesired (in this case) effect of disabling hyphenation within the
entire enclosed block.
2001-08-07 15:48:51 +00:00
Dima Dorfman
7ebcc426ef Remove whitespace at EOL. 2001-07-15 07:53:42 +00:00
Ruslan Ermilov
4a558355e5 MAN[1-9] -> MAN. 2001-03-27 17:27:19 +00:00
Ruslan Ermilov
3fe5c3c9aa mdoc(7) police: fixed the weird construct. 2001-02-09 09:08:53 +00:00
Ruslan Ermilov
794b517fa4 man(7) -> mdoc(7). 2001-01-12 13:35:17 +00:00
Ruslan Ermilov
4263595653 Prepare for mdoc(7)NG. 2000-12-29 14:08:20 +00:00
Ruslan Ermilov
55d8033fb4 Replace a dagger' sign with a double dagger' one.
The former looks ugly on grotty(1) devices.
2000-11-16 11:22:42 +00:00
Ruslan Ermilov
855ac919f1 Convert this from -man to -mdoc. 2000-11-14 16:47:54 +00:00
Brian Feldman
c98c98a822 Actually make it so this Makefile can build grot. 2000-07-10 06:10:47 +00:00
Daniel C. Sobral
beea813ee4 Add a test case for one of the bugs found on the new additions to
regex(3).
2000-07-09 18:14:39 +00:00
Daniel C. Sobral
8ca5c256cb Spencer's regex(3) test code.
Obtained from: BSD/OS
2000-07-09 18:13:35 +00:00
Daniel C. Sobral
8f9e434f46 altoffset() always returned whenever it recursed, because at the end
of the processing of the recursion, "scan" would be pointing to O_CH
(or O_QUEST), which would then be interpreted as being the end character
for altoffset().

We avoid this by properly increasing scan before leaving the switch.

Without this, something like (a?b?)?cc would result in a g->moffset of
1 instead of 2.

I added a case to the soon-to-be-imported regex(3) test code to catch
this error.
2000-07-09 17:45:30 +00:00
Daniel C. Sobral
b6c1a56180 Since g->moffset points to the _maximum_ offset at which the must
string may be found (from the beginning of the pattern), the point
at which must is found minus that offset may actually point to some
place before the start of the text.

In that case, make start = start.

Alternatively, this could be tested for in the preceding if, but it
did not occur to me. :-)

Caught by: regex(3) test code
2000-07-09 17:36:53 +00:00
Daniel C. Sobral
517bffca1b Add some casts here and there. 2000-07-09 15:12:28 +00:00
Daniel C. Sobral
6d902efe43 Since we have modified charjump to be CHAR_MIN-based, we have to
correct the offset when we free it.

Caught by: phkmalloc
2000-07-08 09:45:17 +00:00
Daniel C. Sobral
4d41cae8f8 Do not free NULL pointers. 2000-07-07 07:47:39 +00:00
Daniel C. Sobral
c5e125bbbf Deal with the signed/unsigned chars issue in a more proper manner. We
use a CHAR_MIN-based array, like elsewhere in the code.

Remove a number of unused variables (some due to the above change, one
that was left after a number of optimizing steps through the source).

Brucified by: bde
2000-07-07 07:46:36 +00:00
Daniel C. Sobral
f943749dcd I hate signed chars.^W^W^W^W^WCast to unsigned char before using signed
chars as array indices.
2000-07-06 06:37:30 +00:00
Daniel C. Sobral
9868274b74 Correct comment to work with test code.
Prevent out of bounds array access in some specific cases.
2000-07-06 06:34:15 +00:00
Daniel C. Sobral
03b59f2038 Use UCHAR_MAX consistently. 2000-07-06 05:19:29 +00:00
Daniel C. Sobral
a5378e623a Fix memory leak introduced with regcomp.c rev 1.14. 2000-07-02 15:58:54 +00:00
Daniel C. Sobral
e6a886d8db Enhance the optimization provided by pre-matching. Fix style bugs with
previous commits.

At the time we search the pattern for the "must" string, we now compute
the longest offset from the beginning of the pattern at which the must
string might be found. If that offset is found to be infinite (through
use of "+" or "*"), we set it to -1 to disable the heuristics applied
later.

After we are done with pre-matching, we use that offset and the point in
the text at which the must string was found to compute the earliest
point at which the pattern might be found.

Special care should be taken here. The variable "start" is passed to the
automata-processing functions fast() and slow() to indicate the point in
the text at which they should start working from. The real beginning of
the text is passed in a struct match variable m, which is used to check
for anchors. That variable, though, is initialized with "start", so we
must not adjust "start" before "m" is properly initialized.

Simple tests showed a speed increase from 100% to 400%, but they were
biased in that regexec() was called for the whole file instead of line
by line, and parenthized subexpressions were not searched for.

This change adds a single integer to the size of the "guts" structure,
and does not change the ABI.

Further improvements possible:

Since the speed increase observed here is so huge, one intuitive
optimization would be to introduce a bias in the function that computes
the "must" string so as to prefer a smaller string with a finite offset
over a larger one with an infinite offset. Tests have shown this to be a
bad idea, though, as the cost of false pre-matches far outweights the
benefits of a must offset, even in biased situations.

A number of other improvements suggest themselves, though:

	* identify the cases where the pattern is identical to the must
	string, and avoid entering fast() and slow() in these cases.

	* compute the maximum offset from the must string to the end of
	the pattern, and use that to set the point at which fast() and
	slow() should give up trying to find a match, and return then
	return to pre-matching.

	* return all the way to pre-matching if a "match" was found and
	later invalidated by back reference processing. Since back
	references are evil and should be avoided anyway, this is of
	little use.
2000-07-02 10:58:07 +00:00
Daniel C. Sobral
5ead635430 Remove from the notes a bug that it's said to have been fixed.
PR: 15561
Submitted by: Martin Kammerhofer <mkamm@gmx.net>
Confirmed by: ache
2000-07-02 10:34:25 +00:00
Daniel C. Sobral
6b709b74ae Initialize variables used by the Boyer-Moore algorithm.
This should fix core dumps when the must pattern is of length
three or less.

Bug found by: knu
2000-06-29 18:53:55 +00:00
Daniel C. Sobral
6049d9f0eb Add Boyler-Moore algorithm to pre-matching test.
The BM algorithm works by scanning the pattern from right to left,
and jumping as many characters as viable based on the text's mismatched
character and the pattern's already matched suffix.

This typically enable us to test only a fraction of the text's characters,
but has a worse performance than the straight-forward method for small
patterns. Because of this, the BM algorithm will only be used if the
pattern size is at least 4 characters.

Notice that this pre-matching is done on the largest substring of the
regular expression that _must_ be present on the text for a succesful
match to be possible at all.

For instance, "(xyzzy|grues)" will yield a null "must" substring, and,
therefore, not benefit from the BM algorithm at all. Because of the
lack of intelligence of the algorithm that finds the "must" string,
things like "charjump|matchjump" will also yield a null string. To
optimize that, "(char|match)jump" should be used.

The setup time (at regcomp()) for the BM algorithm will most likely
outweight any benefits for one-time matches. Given the slow regex(3)
we have, this is unlikely to be even perceptible, though.

The size of a regex_t structure is increased by 2*sizeof(char*) +
256*sizeof(int) + strlen(must)*sizeof(int). This is all inside the
regex_t's "guts", which is allocated dynamically by regcomp(). If
allocation of either of the two tables fail, the other one is freed.
In this case, the straight-forward algorithm is used for pre-matching.

Tests exercising the code path affected have shown a speed increase of
50% for "must" strings of length four or five.

API and ABI remain unchanged by this commit.

The patch submitted on the PR was not used, as it was non-functional.

PR: 14342
2000-06-29 04:48:34 +00:00
Peter Wemm
7f3dea244c $Id$ -> $FreeBSD$ 1999-08-28 00:22:10 +00:00
Andrey A. Chernov
77eb0fc601 remove <ctype.h> - not needed 1999-07-26 05:50:43 +00:00
Andrey A. Chernov
89b86d020c unsigned char cleanup
fix wrong index from p_simp_re()

PR: 8790
Submitted by: Alexander Viro <viro@math.psu.edu> (partially)
1999-07-26 01:33:38 +00:00
Nik Clayton
fbc400a67a Add $Id$, to make it simpler for members of the translation teams to
track.

The $Id$ line is normally at the bottom of the main comment block in the
man page, separated from the rest of the manpage by an empty comment,
like so;

     .\"    $Id$
     .\"

If the immediately preceding comment is a @(#) format ID marker than the
the $Id$ will line up underneath it with no intervening blank lines.
Otherwise, an additional blank line is inserted.

Approved by:            bde
1999-07-12 20:50:10 +00:00
Warner Losh
e8420087b0 Replace memory leaking instances of realloc with non-leaking reallocf.
In some cases replace if (a == null) a = malloc(x); else a =
realloc(a, x); with simple reallocf(a, x).  Per ANSI-C, this is
guaranteed to be the same thing.

I've been running these on my system here w/o ill effects for some
time.  However, the CTM-express is at part 6 of 34 for the CAM
changes, so I've not been able to do a build world with the CAM in the
tree with these changes.  Shouldn't impact anything, but...
1998-09-16 04:17:47 +00:00
John Birrell
cfc1614a48 int -> long changes that reduce the diffs with the NetBSD version to
work in a 64-bit environment.
1998-05-14 21:45:18 +00:00
Steve Price
0f4b8423e1 Note that '+' and '?' are not special characters in basic REs but they
can be simulated using bounds.

PR:		5708
Submitted by:	Oliver Fromme <oliver.fromme@heim3.tu-clausthal.de>
1998-02-14 18:26:29 +00:00
Bruce Evans
2bc3b4d735 Removed the subdirectory paths from the definitions of MAN[1-9]. They
were a workaround for limitations in bsd.man.mk that were fixed about
2 years ago.
1997-10-15 16:16:41 +00:00
John Birrell
870039320f Changed all paths to be relative to src/lib instead of src/lib/libc
so that all these makefiles can be used to build libc_r too.

Added .if ${LIB} == "c" tests to restrict man page builds to libc
to avoid needlessly building them with libc_r too.

Split libc Makefile into Makefile and Makefile.inc to allow the
libc_r Makefile to include Makefile.inc too.
1997-05-03 03:50:06 +00:00
Andrey A. Chernov
b5a6eb1833 Speedup in case locale not used 1997-04-04 19:40:49 +00:00
Andrey A. Chernov
c61cea7272 collate_range_cmp -> __collate_range_cmp 1996-10-31 04:38:21 +00:00
Mike Pritchard
7bdf80e571 Correctly use .Fn instead of .Nm to reference function names
in a bunch of man pages.

Use the correct .Bx  (BSD UNIX) or .At (AT&T UNIX) macros
instead of explicitly specifying the version in the text
in a bunch of man pages.
1996-08-22 23:31:07 +00:00
Andrey A. Chernov
79deb12410 Convert to newly aded collate compare function 1996-08-12 18:49:54 +00:00
Andrey A. Chernov
c73ac73fb4 Remove static collcmp, use new internal function now 1996-08-12 03:51:16 +00:00
Andrey A. Chernov
5c551438ec Use collate data for national alpha character ranges like [a-z] 1996-08-11 16:08:17 +00:00
Andrey A. Chernov
3073507540 Short value is better for hash due to easy overflow in 8bit characters 1996-08-11 11:49:23 +00:00