Thanks a lot but it seems I can't try it out because apparently I'm
not able to create a shared library.

I get symbol lookup error: pcre/main.so: undefined symbol:
pcre_compile even though my compile lines look like this:

 gcc main.c -c -std=gnu99 -fPIC -I/usr/local/include -I/usr/include
-L/usr/local/lib -L/usr/lib -lpcre3
 gcc -shared -rdynamic -o main.so main.o

In the first line I've also tried -lpcre, -llibpcre and -llibpcre3 to no avail.

The point here was to create something like PHPs preg_match_all in (
http://php.net/manual/en/function.preg-match-all.php ) order to
capture all matches, I quickly found a good example I could almost
copy paste straight for PCRE but if you have any ideas of how to do
this with regexec I'll go for that instead due to the linking
problems.

The code:

void pcre_match_all (char *regex, char *str)
{
    const char *error;
    int   erroffset;
    pcre *re;
    int   rc;
    int   i;
    int   ovector[1000];

    re = pcre_compile (regex,          /* the pattern */
                       PCRE_MULTILINE,
                       &error,         /* for error message */
                       &erroffset,     /* for error offset */
                       0);             /* use default character tables */
    if (!re)
    {
        printf("pcre_compile failed (offset: %d), %s\n", erroffset, error);
    }

    unsigned int offset = 0;
    unsigned int len    = strlen(str);
    while (offset < len && (rc = pcre_exec(re, 0, str, len, offset, 0,
ovector, sizeof(ovector))) >= 0)
    {
        for(int i = 0; i < rc; ++i)
        {
            printf("%.*s\n", ovector[2*i+1] - ovector[2*i], str + ovector[2*i]);
        }
        offset = ovector[1];
    }
}



On Fri, May 11, 2012 at 10:00 PM, Alexander Burger <a...@software-lab.de> wrote:
> Oops, forgot one answer.
>
> On Fri, May 11, 2012 at 08:48:15PM +0700, Henrik Sarvell wrote:
>> Maybe it's just easier to print the results and capture that? If so
>> then maybe it's even easier/more efficient to skip this completely and
>> simply call an executable or does native have lower overhead?
>
> I would estimate that calling an executable has at least a 1000-fold
> overhead:
>
>   : (bench (do 1000 (call "/bin/true")))
>   0.616 sec
>   -> T
>
>   : (bench (do 1000000 (native "pcre/main.so" "tst" NIL '(X (16 S S)))))
>   0.157 sec
>   -> NIL
>
> Cheers,
> - Alex
> --
> UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe
--
UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe

Reply via email to