Back to index

glibc  2.9
bug-regex8.c
Go to the documentation of this file.
00001 /* Test for the STOP parameter of re_match_2 and re_search_2.
00002    Copyright (C) 2002 Free Software Foundation, Inc.
00003    This file is part of the GNU C Library.
00004    Contributed by Stepan Kasal <kasal@math.cas.cz>, 2002.
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 #include <locale.h>
00022 #include <stdio.h>
00023 #include <stdlib.h>
00024 #include <string.h>
00025 #include <sys/types.h>
00026 #include <regex.h>
00027 
00028 
00029 int
00030 main (void)
00031 {
00032   struct re_pattern_buffer regex;
00033   const char *s;
00034   int match[4];
00035 
00036   memset (&regex, '\0', sizeof (regex));
00037 
00038   s = re_compile_pattern ("xy$", 3, &regex);
00039   if (s != NULL)
00040     {
00041       puts ("failed to compile pattern \"xy$\"");
00042       return 1;
00043     }
00044   else
00045     match[0] = re_match_2(&regex,"xyz",3,NULL,0,0,NULL,2);
00046 
00047   free (regex.buffer);
00048   memset (&regex, '\0', sizeof (regex));
00049 
00050   s = re_compile_pattern ("xy\\>", 4, &regex);
00051   if (s != NULL)
00052     {
00053       puts ("failed to compile pattern \"xy\\>\"");
00054       return 1;
00055     }
00056   else
00057     match[1] = re_search_2(&regex,"xyz",3,NULL,0,0,2,NULL,2);
00058 
00059   free (regex.buffer);
00060   memset (&regex, '\0', sizeof (regex));
00061 
00062   s = re_compile_pattern ("xy \\<", 5, &regex);
00063   if (s != NULL)
00064     {
00065       puts ("failed to compile pattern \"xy \\<\"");
00066       return 1;
00067     }
00068   else
00069     {
00070       match[2] = re_match_2(&regex,"xy  ",4,NULL,0,0,NULL,3);
00071       match[3] = re_match_2(&regex,"xy z",4,NULL,0,0,NULL,3);
00072     }
00073 
00074   if (match[0] != -1 || match[1] != -1 || match[2] != -1 || match[3] != 3)
00075     {
00076       printf ("re_{match,search}_2 returned %d,%d,%d,%d, expected -1,-1,-1,3\n",
00077               match[0], match[1], match[2], match[3]);
00078       return 1;
00079     }
00080 
00081   puts (" -> OK");
00082 
00083   return 0;
00084 }