(MSG_*): Also define as macros.
[glibc.git] / misc / regexp.c
blob34019aeb1a33f9de84b8a1c016bcf2ffa190e4fd
1 /* Define function and variables for the obsolete <regexp.h> interface.
2 Copyright (C) 1996 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4 Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public License as
8 published by the Free Software Foundation; either version 2 of the
9 License, or (at your option) any later version.
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details.
16 You should have received a copy of the GNU Library General Public
17 License along with the GNU C Library; see the file COPYING.LIB. If not,
18 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
21 #define __DO_NOT_DEFINE_COMPILE
22 #include <regexp.h>
24 /* Define the variables used for the interface. */
25 char *loc1;
26 char *loc2;
28 /* Although we do not support the use we define this variable as well. */
29 char *locs;
32 /* Find the next match in STRING. The compiled regular expression is
33 found in the buffer starting at EXPBUF. `loc1' will return the
34 first character matched and `loc2' points to the next unmatched
35 character. */
36 int
37 __step (const char *string, const char *expbuf)
39 regmatch_t match; /* We only need info about the full match. */
41 expbuf += __alignof (regex_t *);
42 expbuf -= (expbuf - ((const char *) 0)) % __alignof__ (regex_t *);
44 if (regexec ((regex_t *) expbuf, string, 1, &match, REG_NOTEOL)
45 == REG_NOMATCH)
46 return 0;
48 loc1 = (char *) string + match.rm_so;
49 loc2 = (char *) string + match.rm_eo;
50 return 1;
52 weak_alias (__step, step)
55 /* Match the beginning of STRING with the compiled regular expression
56 in EXPBUF. If the match is successful `loc2' will contain the
57 position of the first unmatched character. */
58 int
59 __advance (const char *string, const char *expbuf)
61 regmatch_t match; /* We only need info about the full match. */
63 expbuf += __alignof__ (regex_t *);
64 expbuf -= (expbuf - ((const char *) 0)) % __alignof__ (regex_t *);
66 if (regexec ((regex_t *) expbuf, string, 1, &match, REG_NOTEOL)
67 == REG_NOMATCH
68 /* We have to check whether the check is at the beginning of the
69 buffer. */
70 || match.rm_so != 0)
71 return 0;
73 loc2 = (char *) string + match.rm_eo;
74 return 1;
76 weak_alias (__advance, advance)