HylaFAX The world's most advanced open source fax server

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

RegEx.c++ not compiling under linux (REG_STARTEND) (patch included)



I looked through the archives and saw that other people had the same
problem as I did.

Namely compilation of RegEx.c++ under a linux box (or at least a linux
box for me) generated errors because of an Undefined reference to
REG_STARTEND.

In specific:

  /usr/bin/g++      -I/usr/include                          -D__ANSI_CPP__ \
     -I. -I.. -I.././util -I.././util -I/usr/include -I/usr/include -g -O  -c \
     RegEx.c++
  RegEx.c++: In method `unsigned char RegEx::Find(const char *, unsigned int, \
     unsigned int = 0)':
  RegEx.c++:80: `REG_STARTEND' undeclared (first use this function)
  RegEx.c++:80: (Each undeclared identifier is reported only once
  RegEx.c++:80: for each function it appears in.)
  make: *** [RegEx.o] Error 1

Now it is true that some people noticed that the regex.h that comes with
hylafax does define this and your problems are solved so long as
./regex appears before /usr/include in your $CC include list.

However.  I don't think this is the most elegant, nor correct solution.
My C libraries (linux) have regexec built in to them and I think hylafax
should compile correctly with the default system libraries when they are
present and not horribly broken or some other problem that would warrant
forcing the compilation and use of the support libraries that come with
Hylafax.

i.e. I have regexec built-in and I want to use it (correctly) and not fool
the compiler with an inappropriate header file.

So: I've included a patch that should eliminate the necessity of REG_STARTEND
in the call to regexec on line 80.

essentially REG_STARTEND is used to pattern match against a substring
of the original string.  This patch copies the substring to a temporary
string, runs regexec() on that substring (without the use of REG_STARTEND)
and then corrects the data returned in the pmatch array to compensate
for the substring starting at zero instead of the offset byte.

I haven't tested whether or not this works 100% the way REG_STARTEND does
because I don't have a lot of knowledge or practice with dialrules but it
does allow for the compilation to succeed.

Please let me know if there is anything wrong with this and I'll try to
fix it in a way which is correct yet still portable.

- Jeff Wiegley

Oh God... This is probably soooo wrong (but well documented)...

*** hylafax-v4.0pl2/util/RegEx.c++.orig Mon Mar  8 19:46:43 1999
--- hylafax-v4.0pl2/util/RegEx.c++      Mon Mar  8 20:15:28 1999
***************
*** 76,83 ****
        else {
            matches[0].rm_so = off;
            matches[0].rm_eo = length;
!           execResult = regexec(&c_pattern, text, c_pattern.re_nsub+1,
!                           matches, REG_STARTEND);
        }
      }
      return (execResult == 0);
--- 76,120 ----
        else {
            matches[0].rm_so = off;
            matches[0].rm_eo = length;
! 
!             /* REG_STARTEND is not specified by POSIX 1003.2 but rather
!                an extension. It should not be used in software which is
!                intended to be portable to other systems. (The man page
!                version which documents REG_STARTEND even says so */
! 
!           //      execResult = regexec(&c_pattern, text, c_pattern.re_nsub+1,
!           //                      matches, REG_STARTEND);
! 
!             /* so we create a temporary string and copy the dsired
!                substring bounded by text[off] and text[length] to this
!                location.  Using this substring eliminates the need for
!                REG_STARTEND */
! 
!           /* create temporary space of sufficient size */
!           char newtext[length-off+1];
!           strncpy(newtext,&text[off],length-off);
!           newtext[length-off]='\0';
! 
!           /* run regexec on that temporary string instead */
!           execResult = regexec(&c_pattern, newtext, c_pattern.re_nsub+1,
!                                matches, 0x0);
! 
!           /* in order to fully emulate the behavior of REG_STARTEND
!                we need to add back the offset of the beginning to any
!                matches found. We allow the index 'j' to run through
!                all the possible elements of matches (instead of stopping
!                at the first rm_so==-1 since the manual pages provide
!                no documentation that you are guaranteed to have no
!                further matches described after the first rm_so==1 is
!                encountered. */
!           for (int j=0;j<c_pattern.re_nsub+1;j++)
!             matches[j].rm_so+=off, matches[j].rm_eo+=off;
!           
!           /* further note: when building the regexec library you can
!                define REG_NOSUB or not and get similar behavior to
!                REG_STARTEND automatically. however I don't test for this
!                and the above code should be portable in all instances
!                and work correctly. I hope.*/
        }
      }
      return (execResult == 0);




Project hosted by iFAX Solutions