~ubuntu-branches/ubuntu/trusty/librep/trusty

« back to all changes in this revision

Viewing changes to src/README.regexp

  • Committer: Bazaar Package Importer
  • Author(s): Christian Marillat
  • Date: 2001-11-13 15:06:22 UTC
  • Revision ID: james.westby@ubuntu.com-20011113150622-vgmgmk6srj3kldr3
Tags: upstream-0.15.2
ImportĀ upstreamĀ versionĀ 0.15.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
This is a version of Henry Spencer's famous regexp implementation. I've
 
3
modified it to meet my needs, this is what I've done:
 
4
 
 
5
    2) added a new function regsublen(), this performs a dry run of the
 
6
       regsub() function returning the length of the string needed to hold
 
7
       the output from regsub().
 
8
    3) changed regexec(prog,str) to regexec2(prog,str,eflags) with macro for
 
9
       regexec(). This is so I can have the flag REG_NOTBOL which signifies
 
10
       that the string passed to regexec[2]() is not actually the start of a
 
11
       line.
 
12
    4) support for case-insignificant matching (with the flag REG_NOCASE)
 
13
    5) split the definition of a compiled regexp from regexp.c into
 
14
       a new file regprog.h
 
15
    6) created a new file regjade.c which uses the regexec() structure to
 
16
       match regexp against editor buffers in place.
 
17
    7) Altered the regexp structure to allow storing of subexpressions as
 
18
       positions in a Jade buffer. Also altered calling conventions of
 
19
       regsub() and regsublen() to support this.
 
20
    8) support \w, \W, \s, \S, \d, \D, \b, \B, *?, +?, ?? syntax (as in Perl)
 
21
 
 
22
And probably some other things as well. Obviously all errors are my
 
23
responsibility. The original README follows,
 
24
 
 
25
John
 
26
 
 
27
-- 
 
28
 
 
29
This is a nearly-public-domain reimplementation of the V8 regexp(3) package.
 
30
It gives C programs the ability to use egrep-style regular expressions, and
 
31
does it in a much cleaner fashion than the analogous routines in SysV.
 
32
 
 
33
        Copyright (c) 1986 by University of Toronto.
 
34
        Written by Henry Spencer.  Not derived from licensed software.
 
35
 
 
36
        Permission is granted to anyone to use this software for any
 
37
        purpose on any computer system, and to redistribute it freely,
 
38
        subject to the following restrictions:
 
39
 
 
40
        1. The author is not responsible for the consequences of use of
 
41
                this software, no matter how awful, even if they arise
 
42
                from defects in it.
 
43
 
 
44
        2. The origin of this software must not be misrepresented, either
 
45
                by explicit claim or by omission.
 
46
 
 
47
        3. Altered versions must be plainly marked as such, and must not
 
48
                be misrepresented as being the original software.
 
49
 
 
50
Barring a couple of small items in the BUGS list, this implementation is
 
51
believed 100% compatible with V8.  It should even be binary-compatible,
 
52
sort of, since the only fields in a "struct regexp" that other people have
 
53
any business touching are declared in exactly the same way at the same
 
54
location in the struct (the beginning).
 
55
 
 
56
This implementation is *NOT* AT&T/Bell code, and is not derived from licensed
 
57
software.  Even though U of T is a V8 licensee.  This software is based on
 
58
a V8 manual page sent to me by Dennis Ritchie (the manual page enclosed
 
59
here is a complete rewrite and hence is not covered by AT&T copyright).
 
60
The software was nearly complete at the time of arrival of our V8 tape.
 
61
I haven't even looked at V8 yet, although a friend elsewhere at U of T has
 
62
been kind enough to run a few test programs using the V8 regexp(3) to resolve
 
63
a few fine points.  I admit to some familiarity with regular-expression
 
64
implementations of the past, but the only one that this code traces any
 
65
ancestry to is the one published in Kernighan & Plauger (from which this
 
66
one draws ideas but not code).
 
67
 
 
68
Simplistically:  put this stuff into a source directory, copy regexp.h into
 
69
/usr/include, inspect Makefile for compilation options that need changing
 
70
to suit your local environment, and then do "make r".  This compiles the
 
71
regexp(3) functions, compiles a test program, and runs a large set of
 
72
regression tests.  If there are no complaints, then put regexp.o, regsub.o,
 
73
and regerror.o into your C library, and regexp.3 into your manual-pages
 
74
directory.
 
75
 
 
76
Note that if you don't put regexp.h into /usr/include *before* compiling,
 
77
you'll have to add "-I." to CFLAGS before compiling.
 
78
 
 
79
The files are:
 
80
 
 
81
Makefile        instructions to make everything
 
82
regexp.3        manual page
 
83
regexp.h        header file, for /usr/include
 
84
regexp.c        source for regcomp() and regexec()
 
85
regsub.c        source for regsub()
 
86
regerror.c      source for default regerror()
 
87
regmagic.h      internal header file
 
88
try.c           source for test program
 
89
timer.c         source for timing program
 
90
tests           test list for try and timer
 
91
 
 
92
This implementation uses nondeterministic automata rather than the
 
93
deterministic ones found in some other implementations, which makes it
 
94
simpler, smaller, and faster at compiling regular expressions, but slower
 
95
at executing them.  In theory, anyway.  This implementation does employ
 
96
some special-case optimizations to make the simpler cases (which do make
 
97
up the bulk of regular expressions actually used) run quickly.  In general,
 
98
if you want blazing speed you're in the wrong place.  Replacing the insides
 
99
of egrep with this stuff is probably a mistake; if you want your own egrep
 
100
you're going to have to do a lot more work.  But if you want to use regular
 
101
expressions a little bit in something else, you're in luck.  Note that many
 
102
existing text editors use nondeterministic regular-expression implementations,
 
103
so you're in good company.
 
104
 
 
105
This stuff should be pretty portable, given appropriate option settings.
 
106
If your chars have less than 8 bits, you're going to have to change the
 
107
internal representation of the automaton, although knowledge of the details
 
108
of this is fairly localized.  There are no "reserved" char values except for
 
109
NUL, and no special significance is attached to the top bit of chars.
 
110
The string(3) functions are used a fair bit, on the grounds that they are
 
111
probably faster than coding the operations in line.  Some attempts at code
 
112
tuning have been made, but this is invariably a bit machine-specific.