Question sur le string matching
Bonjour à tous,
Je souhaite parcourir les fichiers d'un répertoire donné par l'utilisateur et ne charger que les fichiers avec une extension spéciale (exemple .flv).
j'ai fait cette petite fonction de test (avec ce que j'ai trouvé sur le net) mais le résultat n'est pas bon soit tout match soit rien ne match:
Code:
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 32 33
|
# define INPUT_FILE_FILTER_PATTERN "flv$"
if(strcmp(".",ep->d_name) != 0 && strcmp("..",ep->d_name) !=0 ){
err = regcomp (&preg, INPUT_FILE_FILTER_PATTERN, REG_NOSUB | REG_EXTENDED | REG_NEWLINE | REG_ICASE);
if (err == 0) // compilation ok
{
match = regexec (&preg, INPUT_FILE_FILTER_PATTERN, 0, NULL, 0);
regfree (&preg); // free memory
if (match == 0)
{
printf("-> %s\n",ep->d_name);
}else if (match == REG_NOMATCH){ // not match
printf("not match -> %s\n",ep->d_name);
}
}else{
char *text;
size_t size;
size = regerror (err, &preg, NULL, 0);
text = malloc (sizeof (*text) * size);
if (text)
{
regerror (err, &preg, text, size);
fprintf (stderr, "%s\n", text);
free (text);
}else {
fprintf (stderr, "Memoire insuffisante\n");
exit (EXIT_FAILURE);
}
} |
j'ai aussi fait cette autre fonction ;
Code:
1 2 3 4 5 6
|
if(fnmatch(INPUT_FILE_FILTER_PATTERN, ep->d_name, FNM_NOESCAPE | FNM_CASEFOLD) == 0){
printf("match -> %s\n",ep->d_name);
}else{
printf("not match -> %s\n",ep->d_name);
} |
mais à la compilation j'ai cette erreur :
Citation:
error: ‘FNM_CASEFOLD’ undeclared (first use in this function)
Merci beaucoup pour votre aide