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 103 104 105 106 107 108 109 110 111 112 113 114
|
static struct temp *
PerlPower(char * arg[], int taille/*,int *nb_retours, int *nbligne, int *nbchamp*/)
{
dSP; // initialise le pointeur de pile
int count = 0, i = 0, j=0, k=0;
int *nbligne = NULL, *nbchamp = NULL, nb_retours;
struct temp *ret = NULL;
char ****tableau = NULL;
SV *tmp;
SV *ligne_tmp;
SV *champ;
AV *liste_retour;
AV *table;
AV *ligne;
ENTER; // tout ce qui est cree a partir d'ici
SAVETMPS; // ... est une variable temporaire
PUSHMARK(SP); // sauvegarde du pointeur de pile
while( i < taille )
XPUSHs(sv_2mortal(newSVpv(arg[i++],0))); // depose la base dans la pile
PUTBACK; // rend global le pointeur local de pile
count = perl_call_pv("lance", G_ARRAY); // appelle la fonction
SPAGAIN; // rafraichit le pointeur de pile
if(count != 0) {
printf("Nombre de retour = %d\n",count);
liste_retour = (AV *) SvRV(POPs);
nb_retours = av_len(liste_retour)+1;
printf("taille liste retour = %d\n",(nb_retours));
tableau = malloc( (nb_retours) * sizeof( ***tableau) );
nbligne = malloc( (nb_retours) * sizeof( int ) );
nbchamp = malloc( (nb_retours) * sizeof( int ) );
for(i=0; i<(nb_retours); i++){
printf("\nRetour %d\n",i+1);
tmp = *av_fetch(liste_retour, i, 0);
if( SvTYPE(SvRV(tmp)) == SVt_NV ){
printf("Entier de taille %d\n",SvLEN(tmp));
}
else if( SvTYPE(SvRV(tmp)) == SVt_PVAV ){
printf("tableau\n");
table = (AV *) SvRV(tmp);
//nbligne[i] = malloc( sizeof( int ) );
//nbchamp[i] = malloc( sizeof( int ) );
nbligne[i] = av_len(table)+1;
tableau[i] = malloc((nbligne[i]) * sizeof( **tableau ));
printf("Nombre de lignes pour ce retour = %d\n",(nbligne[i]));
for(j=0; j<(nbligne[i]); j++){
printf("\tLigne %d retour %d :\n",j+1,i+1);
ligne_tmp = *av_fetch(table,j,0);
ligne = (AV *) SvRV(ligne_tmp);
if(j==0)
nbchamp[i] = av_len(ligne)+1;
printf("par la\n");
tableau[i][j] = malloc( (nbchamp[i]) * sizeof(*tableau) );
printf("\tNombre de champ pour cette ligne = %d\n",(nbchamp[i]));
for(k=0; k<(nbchamp[i]); k++){
printf("\t\tChamp %d de la ligne %d du retour %d :\n",k+1,j+1,i+1);
champ = *av_fetch(ligne,k,0);
tableau[i][j][k] = malloc( sizeof( SvLEN(champ) ) );
printf("\t\t\tValeur du champ : %s, taille = %d\n",(char *)SvRV(champ),SvLEN(champ));
strcpy( tableau[i][j][k], (char *)SvRV(champ) );
}
printf("\tFin ligne %d\n",j+1);
}
printf("\nFin retour %d\n",i+1);
}
}
/* printf("ecriture des valeur de ligne et champ :\n");
for(i=0;i<(nb_retours);i++){
printf("nbligne = %d, nbchamp = %d\n",nbligne[i],nbchamp[i]);
}*/
}
PUTBACK; // retire la valeur de retour de la pile
FREETMPS; // libere la valeur de retour
LEAVE; // ...et retire les arguments empiles
printf("retour de la fonction\n");
if(nb_retours > 0){
printf("la !\n");
ret = (struct temp *) malloc ( sizeof(struct temp));
ret->tableau = tableau;
ret->nb_retours = nb_retours;
ret->nbligne = nbligne;
ret->nbchamp = nbchamp;
}
return ret;
} |
Partager