/*
- * Sherlock Library -- Interface to Regular Expression Libraries
+ * UCW Library -- Interface to Regular Expression Libraries
*
* (c) 1997--2004 Martin Mares <mj@ucw.cz>
* (c) 2001 Robert Spalek <robert@ucw.cz>
#include <stdio.h>
#include <string.h>
-#include <stdlib.h>
#if defined(CONFIG_OWN_REGEX) || defined(CONFIG_POSIX_REGEX)
};
regex *
-rx_compile(byte *p, int icase)
+rx_compile(const char *p, int icase)
{
regex *r = xmalloc_zero(sizeof(regex));
int err = regcomp(&r->rx, p, REG_EXTENDED | (icase ? REG_ICASE : 0));
if (err)
{
- byte msg[256];
+ char msg[256];
regerror(err, &r->rx, msg, sizeof(msg)-1);
/* regfree(&r->rx) not needed */
die("Error parsing regular expression `%s': %s", p, msg);
}
int
-rx_match(regex *r, byte *s)
+rx_match(regex *r, const char *s)
{
int err = regexec(&r->rx, s, 10, r->matches, 0);
if (!err)
}
int
-rx_subst(regex *r, byte *by, byte *src, byte *dest, uns destlen)
+rx_subst(regex *r, const char *by, const char *src, char *dest, uns destlen)
{
- byte *end = dest + destlen - 1;
+ char *end = dest + destlen - 1;
if (!rx_match(r, src))
return 0;
uns j = *by++ - '0';
if (j <= r->rx.re_nsub && r->matches[j].rm_so >= 0)
{
- byte *s = src + r->matches[j].rm_so;
+ const char *s = src + r->matches[j].rm_so;
uns i = r->matches[j].rm_eo - r->matches[j].rm_so;
if (dest + i >= end)
return -1;
};
regex *
-rx_compile(byte *p, int icase)
+rx_compile(const char *p, int icase)
{
const char *err;
int errpos, match_array_size, eno;
}
int
-rx_match(regex *r, byte *s)
+rx_match(regex *r, const char *s)
{
int len = str_len(s);
int err = pcre_exec(r->rx, r->extra, s, len, 0, 0, r->matches, r->match_array_size);
}
int
-rx_subst(regex *r, byte *by, byte *src, byte *dest, uns destlen)
+rx_subst(regex *r, const char *by, const char *src, char *dest, uns destlen)
{
- byte *end = dest + destlen - 1;
+ char *end = dest + destlen - 1;
if (!rx_match(r, src))
return 0;
uns j = *by++ - '0';
if (j < r->real_matches && r->matches[2*j] >= 0)
{
- byte *s = src + r->matches[2*j];
+ char *s = src + r->matches[2*j];
uns i = r->matches[2*j+1] - r->matches[2*j];
if (dest + i >= end)
return -1;
};
regex *
-rx_compile(byte *p, int icase)
+rx_compile(const char *p, int icase)
{
regex *r = xmalloc_zero(sizeof(regex));
const char *msg;
}
int
-rx_match(regex *r, byte *s)
+rx_match(regex *r, const char *s)
{
int len = strlen(s);
}
int
-rx_subst(regex *r, byte *by, byte *src, byte *dest, uns destlen)
+rx_subst(regex *r, const char *by, const char *src, char *dest, uns destlen)
{
- byte *end = dest + destlen - 1;
+ char *end = dest + destlen - 1;
if (!rx_match(r, src))
return 0;
uns j = *by++ - '0';
if (j < r->regs.num_regs)
{
- byte *s = src + r->regs.start[j];
+ const char *s = src + r->regs.start[j];
uns i = r->regs.end[j] - r->regs.start[j];
if (r->regs.start[j] > r->len_cache || r->regs.end[j] > r->len_cache)
return -1;
int main(int argc, char **argv)
{
regex *r;
- byte buf1[4096], buf2[4096];
+ char buf1[4096], buf2[4096];
int opt_i = 0;
if (!strcmp(argv[1], "-i"))