11 main (int argc
, char *argv
[])
14 static const char *pat
[] = {
16 "(.?)(.?)(.?)(.?)(.?)(.?)(.?)argc",
17 "((((((((((.?))))))))))((((((((((.?))))))))))((((((((((.?))))))))))"
18 "((((((((((.?))))))))))((((((((((.?))))))))))((((((((((.?))))))))))"
19 "((((((((((.?))))))))))argc" };
23 int testno
, i
, j
, k
, l
;
30 fd
= open (argv
[1], O_RDONLY
);
33 printf ("Couldn't open %s: %s\n", argv
[1], strerror (errno
));
37 if (fstat (fd
, &st
) < 0)
39 printf ("Couldn't fstat %s: %s\n", argv
[1], strerror (errno
));
43 buf
= malloc (st
.st_size
+ 1);
46 printf ("Couldn't allocate buffer: %s\n", strerror (errno
));
50 if (read (fd
, buf
, st
.st_size
) != (ssize_t
) st
.st_size
)
52 printf ("Couldn't read %s", argv
[1]);
57 buf
[st
.st_size
] = '\0';
62 for (testno
= 0; testno
< 4; ++testno
)
63 for (i
= 0; i
< sizeof (pat
) / sizeof (pat
[0]); ++i
)
66 struct re_pattern_buffer rpbuf
;
69 printf ("test %d pattern %d", testno
, i
);
72 err
= regcomp (&rbuf
, pat
[i
],
73 REG_EXTENDED
| (testno
? REG_NOSUB
: 0));
78 regerror (err
, &rbuf
, errstr
, sizeof (errstr
));
86 re_set_syntax (RE_SYNTAX_POSIX_EGREP
87 | (testno
== 3 ? RE_NO_SUB
: 0));
89 memset (&rpbuf
, 0, sizeof (rpbuf
));
90 s
= re_compile_pattern (pat
[i
], strlen (pat
[i
]), &rpbuf
);
97 /* Just so that this can be tested with earlier glibc as well. */
104 regmatch_t pmatch
[71];
105 err
= regexec (&rbuf
, string
, 71, pmatch
, 0);
106 if (err
== REG_NOMATCH
)
108 puts ("\nregexec failed");
114 if (pmatch
[0].rm_eo
!= pmatch
[0].rm_so
+ 11
115 || pmatch
[0].rm_eo
> len
116 || string
+ pmatch
[0].rm_so
>= strchr (string
, 'R')
117 || strncmp (string
+ pmatch
[0].rm_so
,
119 sizeof "n (int argc" - 1)
122 puts ("\nregexec without REG_NOSUB did not find the correct match");
127 for (j
= 0, l
= 1; j
< 7; ++j
)
128 for (k
= 0; k
< (i
== 1 ? 1 : 10); ++k
, ++l
)
129 if (pmatch
[l
].rm_so
!= pmatch
[0].rm_so
+ j
130 || pmatch
[l
].rm_eo
!= pmatch
[l
].rm_so
+ 1)
132 printf ("\npmatch[%d] incorrect\n", l
);
139 struct re_registers regs
;
142 memset (®s
, 0, sizeof (regs
));
143 match
= re_search (&rpbuf
, string
, len
, 0, len
,
147 puts ("\nre_search failed");
152 || string
+ match
>= strchr (string
, 'R')
153 || strncmp (string
+ match
,
155 sizeof "n (int argc" - 1)
158 puts ("\nre_search did not find the correct match");
164 if (regs
.num_regs
!= 2 + (i
== 0 ? 0 : i
== 1 ? 7 : 70))
166 printf ("\nincorrect num_regs %d\n", regs
.num_regs
);
170 if (regs
.start
[0] != match
|| regs
.end
[0] != match
+ 11)
172 printf ("\nincorrect regs.{start,end}[0] = { %d, %d}\n",
173 regs
.start
[0], regs
.end
[0]);
177 if (regs
.start
[regs
.num_regs
- 1] != -1
178 || regs
.end
[regs
.num_regs
- 1] != -1)
180 puts ("\nincorrect regs.{start,end}[num_regs - 1]");
185 for (j
= 0, l
= 1; j
< 7; ++j
)
186 for (k
= 0; k
< (i
== 1 ? 1 : 10); ++k
, ++l
)
187 if (regs
.start
[l
] != match
+ j
188 || regs
.end
[l
] != regs
.start
[l
] + 1)
190 printf ("\nregs.{start,end}[%d] incorrect\n", l
);