Improved the fasta parser for better memory handling and better parsing
of the last parts of fasta headers (definitions)
This commit is contained in:
@ -53,7 +53,7 @@ EQUAL =
|
||||
(*p_header)[*nbf].value = (char*) malloc(sizeof(char)*size_needed);
|
||||
strcpy(((*p_header)[*nbf]).value,yytext);
|
||||
|
||||
(*nbf)++;
|
||||
p_header = check_and_realloc_mem_in_header_table(p_header, nbf, memory_allocated);
|
||||
}
|
||||
|
||||
|
||||
@ -66,7 +66,7 @@ EQUAL =
|
||||
field = store_in_field(field,yytext,&free_size,&i);
|
||||
}
|
||||
|
||||
<REGNAME>{SPACE} {
|
||||
<REGNAME>{SPACE} { // TODO
|
||||
/*fprintf(stderr,"\n<REGNAME>{SPACE} **%s**",yytext);*/
|
||||
if (i != 0)
|
||||
field = store_in_field(field,yytext,&free_size,&i);
|
||||
@ -112,22 +112,19 @@ EQUAL =
|
||||
|
||||
<REGVAL><<EOF>> {
|
||||
field = store_in_header_table(field, &((*p_header)[*nbf].value), &free_size, &i);
|
||||
p_header = check_and_realloc_mem_in_header_table(p_header, nbf, memory_allocated);
|
||||
(*nbf)++;
|
||||
end_header_table(p_header, *nbf);
|
||||
|
||||
free(field);
|
||||
BEGIN(INITIAL);
|
||||
return 0;
|
||||
}
|
||||
|
||||
<REGNAME><<EOF>> {
|
||||
/*(*p_header)[*nbf].name = (char*) malloc(sizeof(char)*19);
|
||||
strcpy((*p_header)[*nbf].name,"other_informations");
|
||||
(*p_header)[*nbf].name = (char*) malloc(sizeof(char)*19);
|
||||
strcpy((*p_header)[*nbf].name,"definition");
|
||||
field = store_in_header_table(field, &((*p_header)[*nbf].value), &free_size, &i);
|
||||
p_header = check_and_realloc_mem_in_header_table(p_header, nbf, memory_allocated);
|
||||
*/
|
||||
end_header_table(p_header, *nbf);
|
||||
|
||||
(*nbf)++;
|
||||
end_header_table(p_header, nbf);
|
||||
free(field);
|
||||
BEGIN(INITIAL);
|
||||
return 0;
|
||||
@ -142,37 +139,31 @@ int header_yywrap()
|
||||
|
||||
element_from_header* header_parser_main(char *h)
|
||||
{
|
||||
int nbfields,memory_allocated;
|
||||
int nbfields, memory_allocated;
|
||||
element_from_header* header;
|
||||
char* nbfields_n;
|
||||
char* nbfields_v;
|
||||
|
||||
nbfields_n = (char*) malloc(9*sizeof(char));
|
||||
nbfields_v = (char*) malloc(5*sizeof(char));
|
||||
YY_BUFFER_STATE state;
|
||||
|
||||
state=yy_scan_string(h);
|
||||
|
||||
memory_allocated=MEMALLOCATED;
|
||||
|
||||
header = (element_from_header*) malloc(memory_allocated * sizeof(element_from_header));
|
||||
|
||||
nbfields_n = (char*) malloc(9*sizeof(char));
|
||||
strcpy(nbfields_n, "nbfields");
|
||||
header[0].name = nbfields_n;
|
||||
|
||||
// Initialize memory to store the number of fields
|
||||
header[0].value = (char*) malloc(10*sizeof(char));
|
||||
|
||||
nbfields=1;
|
||||
|
||||
strcpy(nbfields_n, "nbfields");
|
||||
strcpy(nbfields_v, "1");
|
||||
|
||||
header = (element_from_header*) malloc(memory_allocated * sizeof(element_from_header));
|
||||
|
||||
header[0].name = nbfields_n;
|
||||
header[0].value = nbfields_v;
|
||||
|
||||
YY_BUFFER_STATE state;
|
||||
|
||||
state=yy_scan_string(h);
|
||||
|
||||
header_parser(&nbfields, &memory_allocated, &header);
|
||||
|
||||
|
||||
yy_delete_buffer(state);
|
||||
|
||||
|
||||
return header;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user