Bonjour

Je voudrais réaliser un programme en c qui me permet de rechercher tous les fichiers qui suivent le motif d'une expression régulière dans un dossier et tous ses sous-dossier je les stocke ensuite leur nom et chemin dans une liste.
j'utilise la librairie regex.h pour utiliser les expressions régulières et dirent.h pour naviguer dans les dossier.
Le debugage au printf m'a permit de voir que l'erreur se trouve dans ma fonction parcours_directory. Voici mon code
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include <stdio.h>
#include <stdlib.h>
#include <regex.h>
#include <dirent.h>
#include "projet.h"
#include <link.h>
#include <string.h>
 
 
int isDir(struct dirent* currentFile)
{
    if ((strchr(currentFile->d_name, '.')) == NULL) /* Si le nom du fichier n'a pas de point (une extension). */
        return 1;
    else
        return 0;
}
 
char* concatpath(char *s1,char *s2)
	{
     char *s3=NULL;
     s3=(char *)malloc((strlen(s1)+strlen(s2))*sizeof(char));
     strcpy(s3,s1);
	 strcat(s3,"\\");
     strcat(s3,s2);
     return s3;
	}
 
 
int parcours_directory (DIR* rep, regex_t exp, char* path, struct link* l )
{	int cpt = 0; //compteur pour debugger
	struct dirent* currentFile;
	int match;
	while ((currentFile = readdir(rep)) != NULL)
		{
		++cpt;
		printf("toto parcours 1\n %d\n", cpt);
		if (isDir(currentFile))
			{
			printf("toto parcours 2\n %d\n", cpt);
			path=concatpath(path, currentFile->d_name); // on met à jour le path
			rep = opendir(path);
			parcours_directory(rep, exp, path, l);
			closedir(rep);
			}
		if ((match = regexec (&exp, currentFile->d_name,0, NULL, 0)) == 1)
			{
			struct lelement* e;
			printf("toto parcours 3\n %d\n", cpt);
			e = create_lelement(currentFile->d_name, path);
			lnk__add_head(l,e); // on stock dans la  link
			display_lnk(l);
			}
		}
	return 0;	
}
 
int main (int argc, char *argv[]) // argument 1 = chemin racine, argument 2 = expression régulière à chercher
{
 
    DIR* rep;
    regex_t exp;
    const char* str_regex = argv[2];
    char* path = argv[1];
    struct link* l = lnk__empty();
	printf("%d", argc);
    if (argc != 3)
    {
            printf(" les arguments doivent etre valides : argument 1 = chemin racin, argument = expression reguliere a chercher.");
                return 0;
    }
 
	rep = opendir(path);
	printf("toto\n");
	regcomp (&exp, str_regex, REG_NOSUB | REG_EXTENDED); // compilation de l'expression régulière
	parcours_directory(rep, exp, path, l);
	printf("tot1");
	display_lnk(l);
	regfree (&exp);
	lnk_free(l);
	free(path);
    return 0;
}
voici mon tad de liste, c'est peu être qui pose problème, mais je ne pense pas.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include "link.h"
 
 
 
 
struct lelement *create_lelement( char* name, char* path)
{
	struct lelement* e = malloc (sizeof(struct lelement));
	e->name = name;
	e->path = path;
	e->next = NULL;
        return e;
}
 
struct link* lnk__empty()
{
	struct link* l = malloc (sizeof(struct link));
	l->head = NULL;
	return l; 
}
 
 
int lnk__is_end_mark(struct lelement *e)
{
  return (e == NULL);
}
 
void lnk__add_head(struct link *l, struct lelement *e)
{
  e->next = l->head;
  l->head = e;
}
 
struct lelement *lnk__remove_head(struct link *l)
{
  struct lelement *tmp = l->head;
  l->head = l->head->next;
  return tmp;
}
 
 
void display_lnk (struct link* l)
{
	struct lelement *tmp;
	for(tmp = l->head; !lnk__is_end_mark(tmp->next); tmp = tmp->next)
	{
		printf("%s à pour chemin %s\n", tmp->name, tmp->path);
	}
} 
 
void lnk_free(struct link* l)
{
        struct lelement* tmp;
	for(tmp = l->head; !lnk__is_end_mark(tmp->next); tmp = tmp->next)
		free(tmp);
	free(l);
}

Merci pour votre futur aide
Amicalement Psykomusic.