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 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178
|
/*
* Add -ll in Makefile if you modify this file to convert to .c
*/
%x REGID
%x REGNAME
%x REGVAL
%{
#include <stdlib.h>
#include <string.h>
#include "header_mem_handler.h"
#include "fasta_header_handler.h"
#define MEMALLOCATED 10
#define BUFFER 5
#define YY_DECL int header_parser(int *nbf, int *memory_allocated, element_from_header **p_header)
%}
WORD [^>[:blank:]=;]+
WORDID [^>[:blank:]]+
SUP >
EOL \n
SEP ;
SPACE [[:blank:]]+
EQUAL =
%%
int i;
int size_needed;
int free_size;
char* field;
<INITIAL>{SUP} {
/*printf("\n<INITIAL>{SUP},%s",yytext);*/
BEGIN(REGID);
}
<INITIAL,REGID>{WORDID} {
i=0;
field = malloc_field(&free_size);
(*p_header)[*nbf].name = (char*) malloc(3*sizeof(char));
strcpy(((*p_header)[*nbf]).name,"id");
size_needed = strlen(yytext)+1;
(*p_header)[*nbf].value = (char*) malloc(sizeof(char)*size_needed);
strcpy(((*p_header)[*nbf]).value,yytext);
(*nbf)++;
}
<INITIAL,REGID>{SPACE} {
BEGIN(REGNAME);
}
<REGNAME>{WORD} {
/*fprintf(stderr,"\n<REGNAME>{WORD} **%s**",yytext);*/
field = store_in_field(field,yytext,&free_size,&i);
}
<REGNAME>{SPACE} {
/*fprintf(stderr,"\n<REGNAME>{SPACE} **%s**",yytext);*/
if (i != 0)
field = store_in_field(field,yytext,&free_size,&i);
}
<REGNAME>{EQUAL} {
/*fprintf(stderr,"\n<REGNAME>{EQUAL},%s",yytext);*/
field = store_in_header_table(field, &((*p_header)[*nbf].name), &free_size, &i);
BEGIN(REGVAL);
}
<REGNAME>{SEP} {
/*fprintf(stderr,"\n<REGNAME>{SEP},%s",yytext);*/
(*p_header)[*nbf].name = (char*) malloc(19*sizeof(char));
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);
BEGIN(REGNAME);
}
<REGVAL>{WORD} {
/*fprintf(stderr,"\n<REGVAL>{WORD} **%s**\n",yytext);*/
field = store_in_field(field,yytext,&free_size,&i);
}
<REGVAL>{SPACE} {
/*fprintf(stderr,"\n<REGVAL>{SPACE} **%s**\n",yytext);*/
field = store_in_field(field,yytext,&free_size,&i);
}
<REGVAL>{SEP} {
/*fprintf(stderr,"\n<REGVAL>{SEP},%s\n",yytext);*/
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);
BEGIN(REGNAME);
}
<REGVAL>{EQUAL} {
/*fprintf(stderr, "\nWarning : separator ';' probably missing in header after %s",(*p_header)[*nbf].name);*/
}
<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);
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");
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);
free(field);
BEGIN(INITIAL);
return 0;
}
%%
int header_yywrap()
{
return 1;
}
element_from_header* header_parser_main(char *h)
{
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));
memory_allocated=MEMALLOCATED;
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;
}
|