I am trying to write a simple program that finds all txt files in HTML web page.
I am using C with libcurl(in order to download the page from the internet) and PCRE for scanning the page.
I am using the next pattern - /\w+.txt/g and the next code -
if(htmlContent == NULL) return;
char pattern[] = "/\\w+.txt/g";
const char *error;
int erroffset, ovector[OVECCOUNT], htmlLength = (int)(sizeof(htmlContent) / sizeof(char));
pcre *re = pcre_compile(pattern,0,&error,&erroffset,NULL);
if (re == NULL) {
printf("PCRE compilation failed at offset %d: %s\n", erroffset, error);
return;
}
int rc = pcre_exec(re,NULL,htmlContent,htmlLength,0,0,ovector,OVECCOUNT);
if(rc < 0) {
pcre_free(re);
return;
}
if (rc == 0)
{
rc = OVECCOUNT/3;
printf("ovector only has room for %d captured substrings\n", rc - 1);
}
int i;
for (i = 0; i < rc; i++)
{
char *substring_start = htmlContent + ovector[2*i];
int substring_length = ovector[2*i+1] - ovector[2*i];
printf("%2d: %.*s\n", i, substring_length, substring_start);
}
I get zero results while running the code (btw this code is just from the curl callback)