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 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
| MotCompact * LireToutesTablesFichBinaire(const char* seq, size_t const *pcTailles, struct char_fbtAllocator *pAllocCaracs, struct int_fbtAllocator *pAllocLignes)
{
if(seq==NULL||pcTailles==NULL || pAllocCaracs==NULL || pAllocLignes==NULL)
return NULL;
{
/*Allocation*/
size_t nbMots = SommeTailles(pcTailles);
MotCompact *pMots = CreerTableauMotsCompacts(nbMots);
printf("Chargement des sequences pour langue");
if(pMots != NULL)
{
size_t iMot = 0;
int iSeq=2;
// for(iSeq=2 ; iSeq<=m ; iSeq++)
// {
// assert(iMot < nbMots || (iSeq==maxSequence && pcTailles[maxSequence]==0));
if(LireTableFichBinaire2fr(seq,pcTailles[iSeq], pAllocCaracs, pAllocLignes, pMots, &iMot, nbMots)<0)
{
free(pMots);
return NULL;
}
//}
return pMots;
}
else
perror("LireToutesTablesFichBinaire/malloc");
}
return NULL;
}
size_t SommeTailles(size_t const *pcTailles)
{
size_t ret = 0;
size_t nouvRet = ret + pcTailles[1];
if(nouvRet < ret)
{
fprintf(stderr, "Les tailles des differents fichiers binaires font un depassement!\n");
exit(EXIT_FAILURE);
}
ret = nouvRet;
return ret;
}
MotCompact * CreerTableauMotsCompacts(size_t n)
{
MotCompact *pRet = malloc(n*sizeof *pRet);
if(pRet!=NULL)
{
size_t i;
for(i=0 ; i<n ; i++)
{
static const struct st_motCompact defMot = {0, 0, NULL, NULL};
pRet[i] = defMot;
}
assert(i==n);
}
return pRet;
}
static int LireTableFichBinaire2fr(const char*seq,size_t verifTaille, struct char_fbtAllocator *pAllocCaracs, struct int_fbtAllocator *pAllocLignes, MotCompact *pMots, size_t *piMot, size_t nbMots)
{
int retour = -1;
FILE *pfIn;
pfIn = fopen(seq, LECTURE_SEQUENTIELLE_BINAIRE);
if(pfIn != NULL)
{
retour = LireTableFichierOuvert(pfIn, verifTaille, pAllocCaracs, pAllocLignes, pMots, piMot, nbMots);
fclose(pfIn);
}
return retour;
}
static int LireTableFichierOuvert(FILE *pfIn, size_t verifTaille, struct char_fbtAllocator *pAllocCaracs, struct int_fbtAllocator *pAllocLignes, MotCompact *pMots, size_t *piMot, size_t nbMots)
{
unsigned int magic;
unsigned int taille;
unsigned int iMotTableCourante;
if(LireInt32(pfIn, &magic)<0 || magic!=0x68617368/*'hash'*/)
return -1;
/*AfficherInt32(magic, WHITE);*/
if(LireInt32(pfIn, &taille)<0)
return -1;
/*AfficherInt32(taille, RED);*/
if(taille!=verifTaille)
return -1;
printf("\tLecture de sequences...\n");
for(iMotTableCourante=0 ; iMotTableCourante<taille ; iMotTableCourante++)
{
MotCompact *pMot = &pMots[*piMot];
assert(GetMotCompact(pMot)==NULL);
(void)nbMots;
assert(*piMot < nbMots);
(*piMot)++;
if(LireMot(pfIn, pAllocCaracs, pAllocLignes, pMot)<0)
return -1;
}
return 0;
}
int LireInt32(FILE *pfIn, unsigned int *pI32)
{
unsigned char bytes[4];
size_t nLus;
nLus = fread(bytes, 1, 4, pfIn);
if(nLus==4)
{
if(pI32!=NULL)
{
unsigned int i32 = 0;
size_t i;
for(i=0 ; i<4 ; i++)
{
i32 <<= 8;
i32 |= bytes[i];
}
*pI32 = i32;
}
return 0;
}
else
return -1;
} |
Partager