1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
|
void regCompile(regex_t *reg, int *nmatch, const char *maRegexp){
if (regcomp (reg, maRegexp, REG_EXTENDED) != 0){
exit(-1);
}
*nmatch = reg->re_nsub;
}
void extractLinks(Page *page){
regex_t reg;
const char *maRegexp = "href *= *\"?([^\" >]*)";
int nmatch;
int size;
regCompile (®, &nmatch, maRegexp);
regmatch_t *pmatch = (regmatch_t *)malloc (sizeof(regmatch_t *) *nmatch);
if (pmatch == NULL){
fprintf(stderr, "Probleme d'allocation memeoire\n");
}
while(regexec (®, page->page, nmatch, pmatch, 0) == 0){
size = pmatch[0].rm_eo - pmatch[0].rm_so;
appendToList(page->listURL, strndup(&(page->page[pmatch[0].rm_so]) ,size)); /* ce que je récupère */
page->page+=pmatch[0].rm_eo;
BUG
}
} |
Partager