int Fawk(char *ligne, char *chaine, int posligne, char *sep1, char *sep2, char *commentaire, int *nbmot)
{
int poslgn;
int cidx,idx,goodcar;
int lenlgn;
int nmot;
char findsep1;
lenlgn = strlen( ligne );
if( *posligne >= lenlgn ) //Si le positionnement est en dehors de ligne
{
*posligne = 0;
*nbmot = 0;
return( 0 );
}
if( !lenlgn ) //Si ligne est de longueur 0
{
*posligne = 0;
*nbmot = 0;
chaine[ 0 ] = '\0';
return (0);
}
poslgn = *posligne;
nmot = *nbmot;
cidx=0;
//Retourne 1 si ligne[poslgn] appartient a sep2 et si findsep1 est
//different du 1ier caractere de commentaire
for(idx=0;idx<strlen(sep2);idx++)
{
if( ligne[poslgn] == sep2[ idx ] && findsep1 != commentaire[0] )
{
chaine[0] = ligne[poslgn];
chaine[1] = '\0';
*nbmot = ++nmot;
*posligne += 1 ;
return( 1 );
}
}
//Un premier separateur a ete trouve
findsep1='\001';
//Parcours de ligne
while( ligne[ poslgn ] )
{
for(;poslgn<strlen(ligne);poslgn++)
{
goodcar = 1;
if( ligne[poslgn] == commentaire[0] )
if( findsep1 != commentaire[0] )
findsep1=commentaire[0];
else
findsep1='\001';
if( commentaire[0] != '\0' || findsep1 != commentaire[0] )
{
//Parcours de sep1
for(idx=0;idx<strlen(sep1);idx++)
{
if( ligne[poslgn] == sep1[ idx ] && findsep1 != commentaire[0] )
{
chaine[ cidx ] = '\0';
if( cidx && ligne[poslgn] )
{
*posligne = poslgn + 1 ;
*nbmot = ++nmot;
return( strlen( chaine ) );
}
else
{
goodcar = 0;
break;
}
}
}
//Parcours de sep2
for(idx=0;idx<strlen(sep2);idx++)
{
if( ligne[poslgn] == sep2[ idx ] )
{
chaine[ cidx ] = '\0';
if( cidx && ligne[poslgn] )
{
*posligne = poslgn ;
*nbmot = ++nmot;
return( strlen( chaine ) );
}
else
break;
}
}
}
if( goodcar )
{
chaine[ cidx ] = ligne[ poslgn ];
cidx++;
}
}
}
*posligne = poslgn;
*nbmot = ++nmot;
chaine[ cidx ] = '\0';
if( !strlen( chaine ) )
*posligne = 0;
return( strlen( chaine ) );
}
Oui je sais j'abuse ... mais si vous pouviez jetter un coup d'oeil, je comprends rien à cette fonction et elle est appelée partout
Il doit s'agir d'une manipulation de chaine avec des separateurs ... mais je coince !!
Merci