1 /* Test for re_match with non-zero start.
2 Copyright (C) 2002 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4 Contributed by Jakub Jelinek <jakub@redhat.com>, 2002.
5
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
10
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 Lesser General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, write to the Free
18 Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 02110-1301 USA. */
20
21 #ifdef HAVE_CONFIG_H
22 #include "config.h"
23 #endif
24
25 #include <locale.h>
26 #include <stdio.h>
27 #include <string.h>
28 #include <regex.h>
29
30 int
main(void)31 main (void)
32 {
33 struct re_pattern_buffer regex;
34 struct re_registers regs;
35 const char *s;
36 int match;
37 int result = 0;
38
39 regs.num_regs = 1;
40 memset (®ex, '\0', sizeof (regex));
41 s = re_compile_pattern ("[abc]*d", 7, ®ex);
42 if (s != NULL)
43 {
44 puts ("re_compile_pattern return non-NULL value");
45 result = 1;
46 }
47 else
48 {
49 match = re_match (®ex, "foacabdxy", 9, 2, ®s);
50 if (match != 5)
51 {
52 printf ("re_match returned %d, expected 5\n", match);
53 result = 1;
54 }
55 else if (regs.start[0] != 2 || regs.end[0] != 7)
56 {
57 printf ("re_match returned %d..%d, expected 2..7\n",
58 regs.start[0], regs.end[0]);
59 result = 1;
60 }
61 puts (" -> OK");
62 }
63
64 return result;
65 }
66