/* Collection of code snippets by Arne Vajhøj */
/* (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) */
#include <stdio.h>
#include <string.h>
#include <pcre.h>

void parse(char *s)
{
    int i;
    pcre *re;
    int rc;
    int erroffset;
    int ovector[300];
    const char *error;
    const char *p;
    const char label[][20] = { "func", "stringsep", "string", "stringsep", "statementsep" };
    printf("%s\n",s);
    re = pcre_compile("([a-zA-Z_][a-zA-Z_0-9]*)(?: )(\")([^\"]*)(\")(;)",0,&error,&erroffset,NULL);
    rc = pcre_exec(re,NULL,s,strlen(s),0,0,ovector,sizeof(ovector)/sizeof(int));
    pcre_get_substring(s,ovector,rc,1,&p);
    printf("func = %s\n",p);
    pcre_get_substring(s,ovector,rc,2,&p);
    printf("stringsep = %s\n",p);
    pcre_get_substring(s,ovector,rc,3,&p);
    printf("string = %s\n",p);
    pcre_get_substring(s,ovector,rc,4,&p);
    printf("stringsep = %s\n",p);
    pcre_get_substring(s,ovector,rc,5,&p);
    printf("statementsep = %s\n",p);
}

int main()
{
    parse("a \"aa\";");
    parse("b \"bb bb\";");
    return 0;
}
