Worked, thanks!

So I'm now using this line: gcc -o main.so -m64 -std=gnu99 -fPIC
-shared -export-dynamic main.c -lm -lpcre

It seems the version 3 number was not needed after all.

I've attached the C code for reference and this is what I use in PL:

(println
   (pipe (native "pcre/main.so" "pcre_match_all" NIL
"From:([\^@]+)@([\^\\.]+)\\.([\^ ]+)"
"From:regular.exÄpressi...@example.com From:ex...@43434.com
From:7853...@exgem.com")
      (make
         (while
            (let? R (line T)
               (link R)) ) ) ) )

I noted that ^ needs to be escaped otherwise the regex string won't be
OK on the C side. Are there any other characters which needs the same
treatment?

Result:

("From:regular.exÄpressi...@example.com" "regular.exÄpressions"
"example" "com" "From:ex...@43434.com" "exddd" "43434" "com"
"From:7853...@exgem.com" "7853456" "exgem" "com")




On Sun, May 13, 2012 at 12:06 AM, Alexander Burger <a...@software-lab.de> wrote:
> Hi Henrik,
>
>
>> 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.
>
> I'm always using a line like:
>
>   gcc -o <file>.so -m64 -fPIC -shared -export-dynamic <file>.c -lm
>
> so does this work if you append "-lpcre3"?
>
>
> Note (in general, not your problem here, I think) that <file>.so should
> either contain a slash (e.g. like "pcre/main.so" in your previous
> example), or it must be passed as "./file.so" to 'native', because
> otherwise it is searched for in the system libraries (e.g. via
> LD_LIBRARY_PATH).
>
> Cheers,
> - Alex
> --
> UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe
#include <string.h>
#include <stdio.h>
#include <pcre.h>

/*
 gcc main.c -std=gnu99 -lpcre -o main
 gcc -o main.so -m64 -std=gnu99 -fPIC -shared -export-dynamic main.c -lm -lpcre
 ./main "From:([^@]+)@([^\\.]+)\\.([^ ]+)" "From:regular.exÄpressi...@example.com From:ex...@43434.com From:7853...@exgem.com"
 ./main "[0-9]+" "hello777world99yew 8 I8909do23"
 ./main "From:([^ ]+)" "From:hej From:svejs From:apa"
 ./main "From:([a-z]+)" "From:hej From:svejs From:apa"
*/

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

    re = pcre_compile (regex,          
                       PCRE_MULTILINE,
                       &error,         
                       &erroffset,     
                       0);             
    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];
    }
    
}

void main (int argc, char *argv[])
{
	pcre_match_all(argv[1], argv[2]);
}

Reply via email to