Bonjour,

j'ai un problème avec cette fonction. Je dois l'utiliser pour recoder un dictionnaire (7000 appels). Il semble qu'il y ait une perte de mémoire mais je ne suis pas assez calé pour trouver où ?

Est-ce la façon d'appeler la fonction ou l'appel des fonctions regex (j'ai été obligé de modifier une ligne) ?

Soyez indulgent avec moi... je programme un peu comme un bourrin, j'en suis pleinement conscient.

Si une bonne âme pouvait me remettre sur la bonne voie ...

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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
 
Fonction appelante :
 
...
...
strcpy(tempCode,codePhone(tempCible));	
...
...
 
 
/**************************************************************
*****************        CODEPHONE         ********************
**************************************************************/
char *codePhone(char *source){					
	// Déclaration
	int longSource;
	int numLin=0;
	int k; // compteur de boucle		
	int decal;
	char *reg_exp;
	int spos, epos;
	int err,match;
	int maxLine;
 
	phoneComment[0]=0;
 
	maxLine=codePhon[nivPhone].maxlinePhon;
 
	for(numLin=0;numLin<maxLine;numLin++){
		if(strstr(listeVolumePhon,codePhon[nivPhone].listePhon[numLin].volume)!=0){    // test du volume Phonétique
 
			reg_exp=codePhon[nivPhone].listePhon[numLin].ciblePhon;
 
			match=0;
			while(match==0){ 
				regex_t preg;
 
 
				err = regcomp (&preg,reg_exp, REG_EXTENDED); // compilation du motif avec recherche d'erreur 
 
				if (err == 0) // pas d'erreur dans le motif
				{
					size_t nmatch=0;	 
					regmatch_t *pmatch = NULL; 
					nmatch = preg.re_nsub; // Nombre d'occurence du motif trouvé
 
					// Ligne originale:
					//pmatch = malloc (sizeof(*pmatch) * nmatch); 
 
					// Remplacée par:
					pmatch =(regmatch_t*) malloc (sizeof(*pmatch) * nmatch);	
 
 
					match = regexec (&preg,source, nmatch, pmatch, 0); // Lancer la recherche
					regfree (&preg); // libérer la mémoire
 
					/********************************************/
					/*           le motif a été trouvé          */
					/********************************************/
					if (match == 0){ 
 
						spos = pmatch[0].rm_so;
						epos = pmatch[0].rm_eo;
 
						spos=spos+codePhon[nivPhone].listePhon[numLin].startCible;
						epos=spos+codePhon[nivPhone].listePhon[numLin].longCible;		
 
 
						longSource=strlen(source);
						char *newPhon=codePhon[nivPhone].listePhon[numLin].newPhon;
 
						// Suppression des caractères inutiles par décalage à gauche
						// remplacer boucle par stcpy (+rapide)??
						decal=epos-spos-strlen(newPhon);
						for(k=epos;k<longSource;k++) source[k-decal]=source[k];
						source[longSource-decal]=0;
 
						// recopie de newPhon
						for(k=0;k<strlen(newPhon);k++) source[spos+k]=newPhon[k];
 
						// Saut de lignes
						numLin=numLin+codePhon[nivPhone].listePhon[numLin].sautPhon;                
						// Commentaires
						strncat(phoneComment,codePhon[nivPhone].listePhon[numLin].commentPhon,strlen(codePhon[nivPhone].listePhon[numLin].commentPhon));
 
 
					}else  { 
					# include "nomatch.cpp"
					}
 
					free(pmatch);
				} // if (match==0)
 
			} // fin test err==0	
		} // fin test Volume	
	} // fin boucle numlin
 
 
 
 
	return source;
}