|
@@ -24,8 +24,8 @@ int wildcard_result(const char* seq) {
|
|
|
//Recup la liste des fichiers dans le dossier courant
|
|
|
nbFile = scandir(".", &namelist, 0, alphasort);
|
|
|
if (nbFile < 0) {
|
|
|
- perror("scandir");
|
|
|
- return -1;
|
|
|
+ perror("scandir() : ");
|
|
|
+ return ERR;
|
|
|
}
|
|
|
//Parcours chaque fichier pour compter le nombre de resultat
|
|
|
while (nbFile--) {
|
|
@@ -47,19 +47,20 @@ int wildcard_result(const char* seq) {
|
|
|
}
|
|
|
|
|
|
//Sequence + taille du tableau result + tableau de retour vide
|
|
|
+
|
|
|
int wildcard(const char* seq, int size, char** result) {
|
|
|
//Declaration variable
|
|
|
struct dirent **namelist;
|
|
|
int nbFile, nbRes = 0;
|
|
|
//Verification parametre
|
|
|
if (size < 1) {
|
|
|
- return -1;
|
|
|
+ return ERR;
|
|
|
}
|
|
|
//Recup la liste des fichiers dans le dossier courant
|
|
|
nbFile = scandir(".", &namelist, 0, alphasort);
|
|
|
if (nbFile < 0) {
|
|
|
- perror("scandir");
|
|
|
- return -1;
|
|
|
+ perror("scandir() : ");
|
|
|
+ return ERR;
|
|
|
}
|
|
|
//Parcours chaque fichier pour ajouter les resultats à result
|
|
|
int i = 0;
|
|
@@ -86,11 +87,12 @@ int wildcard(const char* seq, int size, char** result) {
|
|
|
}
|
|
|
|
|
|
//La position de la valeur à remplacer, le tableau dans lequel il faut remplacer, sa taille, le tableau à insérer, sa taille, la nouvelle taille
|
|
|
+
|
|
|
char** insert_array(int pos, char** array, int arraysize, char** insert, int insertsize, int* newsize) {
|
|
|
//Erreur parametre
|
|
|
if (pos < 0 || arraysize < 1 || insertsize < 1 || pos >= arraysize) {
|
|
|
if (newsize != NULL) {
|
|
|
- *newsize = -1;
|
|
|
+ *newsize = ERR;
|
|
|
}
|
|
|
return NULL;
|
|
|
}
|
|
@@ -116,21 +118,42 @@ char** insert_array(int pos, char** array, int arraysize, char** insert, int ins
|
|
|
newarray = malloc(sizeof (char*) * size);
|
|
|
//Ajout des elements avant la postion
|
|
|
for (i = 0; i < pos; i++) {
|
|
|
- newarray[i] = malloc(strlen(array[i]) * sizeof (char));
|
|
|
- strcpy(newarray[i], array[i]);
|
|
|
- free(array[i]);
|
|
|
+ //Si l'element est null
|
|
|
+ if (array[i] == NULL) {
|
|
|
+ newarray[i] = NULL;
|
|
|
+ }
|
|
|
+ //Sinon on le copie
|
|
|
+ else {
|
|
|
+ newarray[i] = malloc(strlen(array[i]) * sizeof (char));
|
|
|
+ strcpy(newarray[i], array[i]);
|
|
|
+ free(array[i]);
|
|
|
+ }
|
|
|
}
|
|
|
//Ajout des nouveaux elements
|
|
|
for (int j = 0; j < insertsize; j++, i++) {
|
|
|
- newarray[i] = malloc(strlen(insert[j]) * sizeof (char));
|
|
|
- strcpy(newarray[i], insert[j]);
|
|
|
- free(insert[j]);
|
|
|
+ //Si l'element est null
|
|
|
+ if (insert[j] == NULL) {
|
|
|
+ newarray[i] = NULL;
|
|
|
+ }
|
|
|
+ //Sinon on le copie
|
|
|
+ else {
|
|
|
+ newarray[i] = malloc(strlen(insert[j]) * sizeof (char));
|
|
|
+ strcpy(newarray[i], insert[j]);
|
|
|
+ free(insert[j]);
|
|
|
+ }
|
|
|
}
|
|
|
//Ajout fin
|
|
|
for (int j = pos + 1; j < arraysize; j++, i++) {
|
|
|
- newarray[i] = malloc(strlen(array[j]) * sizeof (char));
|
|
|
- strcpy(newarray[i], array[j]);
|
|
|
- free(array[j]);
|
|
|
+ //Si l'element est null
|
|
|
+ if (array[j] == NULL) {
|
|
|
+ newarray[i] = NULL;
|
|
|
+ }
|
|
|
+ //Sinon on le copie
|
|
|
+ else {
|
|
|
+ newarray[i] = malloc(strlen(array[j]) * sizeof (char));
|
|
|
+ strcpy(newarray[i], array[j]);
|
|
|
+ free(array[j]);
|
|
|
+ }
|
|
|
}
|
|
|
//Nettoyage et changement tableau
|
|
|
free(array[pos]);
|