HylaFAX The world's
most advanced open source fax server
|
|
[
Date Prev][
Date Next][
Thread Prev][
Thread Next]
[
Date Index]
[
Thread Index]
HylaFAX 4.0pl2: most platforms don't have REG_STARTEND
The file util/RegEx.c++ in HylaFAX 4.0pl2 uses the constant
REG_STARTEND in a call to regexec. Most platforms I checked don't
have this constant -- I checked Solaris, AIX, HP-UX, Linux, and
FreeBSD, and FreeBSD was the only one which had it.
I implemented the following fix. I haven't fully tested it, but it's
pretty straightforward and is pretty much verifiable by reading the
code. I used a static buffer to avoid lots of allocations and
deallocations when doing many regular expression matches.
--- RegEx.c++ 1998/11/30 20:48:17 1.1
+++ RegEx.c++ 1998/11/30 21:02:57 1.2
@@ -1,4 +1,4 @@
-/* $Id: RegEx.c++,v 1.1 1998/11/30 20:48:17 jik Exp $ */
+/* $Id: RegEx.c++,v 1.2 1998/11/30 21:02:57 jik Exp $ */
/*
* Copyright (c) 1994-1996 Sam Leffler
* Copyright (c) 1994-1996 Silicon Graphics, Inc.
@@ -74,10 +74,32 @@
if (off >= length || (off != 0 && _pattern[0] == '^'))
execResult = REG_NOMATCH;
else {
+#ifdef REG_STARTEND
matches[0].rm_so = off;
matches[0].rm_eo = length;
execResult = regexec(&c_pattern, text, c_pattern.re_nsub+1,
matches, REG_STARTEND);
+#else
+ static char *strbuf = 0;
+ static int bufsize = 0;
+ int size = length - off + 1;
+
+ /* XXX Should check malloc and realloc return values, but
+ none of the other HylaFax code does, so why should I be
+ any different? */
+ if (! strbuf) {
+ bufsize = size ? size : 1;
+ strbuf = (char *) malloc(bufsize);
+ }
+ else if (bufsize < size) {
+ bufsize = size;
+ strbuf = (char *) realloc(strbuf, bufsize);
+ }
+ strncpy(strbuf, text + off, length - off);
+ strbuf[length - off] = '\0';
+ execResult = regexec(&c_pattern, text, c_pattern.re_nsub+1,
+ matches, 0);
+#endif
}
}
return (execResult == 0);