Back to index

glibc  2.9
regexp.c
Go to the documentation of this file.
00001 /* Define function and variables for the obsolete <regexp.h> interface.
00002    Copyright (C) 1996, 2000 Free Software Foundation, Inc.
00003    This file is part of the GNU C Library.
00004    Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
00005 
00006    The GNU C Library is free software; you can redistribute it and/or
00007    modify it under the terms of the GNU Lesser General Public
00008    License as published by the Free Software Foundation; either
00009    version 2.1 of the License, or (at your option) any later version.
00010 
00011    The GNU C Library is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014    Lesser General Public License for more details.
00015 
00016    You should have received a copy of the GNU Lesser General Public
00017    License along with the GNU C Library; if not, write to the Free
00018    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00019    02111-1307 USA.  */
00020 
00021 #define __DO_NOT_DEFINE_COMPILE
00022 #include <regexp.h>
00023 
00024 /* Define the variables used for the interface.  */
00025 char *loc1;
00026 char *loc2;
00027 
00028 /* Although we do not support the use we define this variable as well.  */
00029 char *locs;
00030 
00031 
00032 /* Find the next match in STRING.  The compiled regular expression is
00033    found in the buffer starting at EXPBUF.  `loc1' will return the
00034    first character matched and `loc2' points to the next unmatched
00035    character.  */
00036 extern int __step (const char *string, const char *expbuf);
00037 int
00038 __step (const char *string, const char *expbuf)
00039 {
00040   regmatch_t match;  /* We only need info about the full match.  */
00041 
00042   expbuf += __alignof (regex_t *);
00043   expbuf -= (expbuf - ((const char *) 0)) % __alignof__ (regex_t *);
00044 
00045   if (__regexec ((const regex_t *) expbuf, string, 1, &match, REG_NOTEOL)
00046       == REG_NOMATCH)
00047     return 0;
00048 
00049   loc1 = (char *) string + match.rm_so;
00050   loc2 = (char *) string + match.rm_eo;
00051   return 1;
00052 }
00053 weak_alias (__step, step)
00054 
00055 
00056 /* Match the beginning of STRING with the compiled regular expression
00057    in EXPBUF.  If the match is successful `loc2' will contain the
00058    position of the first unmatched character.  */
00059 extern int __advance (const char *string, const char *expbuf);
00060 int
00061 __advance (const char *string, const char *expbuf)
00062 {
00063   regmatch_t match;  /* We only need info about the full match.  */
00064 
00065   expbuf += __alignof__ (regex_t *);
00066   expbuf -= (expbuf - ((const char *) 0)) % __alignof__ (regex_t *);
00067 
00068   if (__regexec ((const regex_t *) expbuf, string, 1, &match, REG_NOTEOL)
00069       == REG_NOMATCH
00070       /* We have to check whether the check is at the beginning of the
00071         buffer.  */
00072       || match.rm_so != 0)
00073     return 0;
00074 
00075   loc2 = (char *) string + match.rm_eo;
00076   return 1;
00077 }
00078 weak_alias (__advance, advance)