xref: /freebsd/lib/libcompat/4.3/re_comp.3 (revision afe61c15161c324a7af299a9b8457aba5afc92db)
1.\" Copyright (c) 1980, 1991, 1993
2.\"	The Regents of the University of California.  All rights reserved.
3.\"
4.\" Redistribution and use in source and binary forms, with or without
5.\" modification, are permitted provided that the following conditions
6.\" are met:
7.\" 1. Redistributions of source code must retain the above copyright
8.\"    notice, this list of conditions and the following disclaimer.
9.\" 2. Redistributions in binary form must reproduce the above copyright
10.\"    notice, this list of conditions and the following disclaimer in the
11.\"    documentation and/or other materials provided with the distribution.
12.\" 3. All advertising materials mentioning features or use of this software
13.\"    must display the following acknowledgement:
14.\"	This product includes software developed by the University of
15.\"	California, Berkeley and its contributors.
16.\" 4. Neither the name of the University nor the names of its contributors
17.\"    may be used to endorse or promote products derived from this software
18.\"    without specific prior written permission.
19.\"
20.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30.\" SUCH DAMAGE.
31.\"
32.\"     @(#)re_comp.3	8.1 (Berkeley) 6/4/93
33.\"
34.Dd June 4, 1993
35.Dt RE_COMP 3
36.Os
37.Sh NAME
38.Nm re_comp ,
39.Nm re_exec
40.Nd regular expression handler
41.Sh SYNOPSIS
42.Fd #include <unistd.h>
43.Ft char *
44.Fn re_comp "const char *s"
45.Ft int
46.Fn re_exec "const char *s"
47.Sh DESCRIPTION
48This interface is made obsolete by
49.Xr regex 3 .
50.Pp
51The
52.Fn re_comp
53function
54compiles a string into an internal form suitable for pattern matching.
55The
56.Fn re_exec
57function
58checks the argument string against the last string passed to
59.Fn re_comp .
60.Pp
61The
62.Fn re_comp
63function
64returns 0 if the string
65.Fa s
66was compiled successfully; otherwise a string containing an
67error message is returned. If
68.Fn re_comp
69is passed 0 or a null string, it returns without changing the currently
70compiled regular expression.
71.Pp
72The
73.Fn re_exec
74function
75returns 1 if the string
76.Fa s
77matches the last compiled regular expression, 0 if the string
78.Fa s
79failed to match the last compiled regular expression, and \-1 if the compiled
80regular expression was invalid (indicating an internal error).
81.Pp
82The strings passed to both
83.Fn re_comp
84and
85.Fn re_exec
86may have trailing or embedded newline characters;
87they are terminated by
88.Dv NUL Ns s.
89The regular expressions recognized are described in the manual entry for
90.Xr ed 1 ,
91given the above difference.
92.Sh DIAGNOSTICS
93The
94.Fn re_exec
95function
96returns \-1 for an internal error.
97.Pp
98The
99.Fn re_comp
100function
101returns one of the following strings if an error occurs:
102.Bd -unfilled -offset indent
103No previous regular expression,
104Regular expression too long,
105unmatched \e(,
106missing ],
107too many \e(\e) pairs,
108unmatched \e).
109.Ed
110.Sh SEE ALSO
111.Xr ed 1 ,
112.Xr ex 1 ,
113.Xr egrep 1 ,
114.Xr fgrep 1 ,
115.Xr grep 1 ,
116.Xr regex 3
117.Sh HISTORY
118The
119.Fn re_comp
120and
121.Fn re_exec
122functions appeared in
123.Bx 4.0 .
124