2012-02-07 15:37:11 +01:00
|
|
|
%{
|
|
|
|
#include<string.h>
|
|
|
|
int n=0;
|
|
|
|
%}
|
|
|
|
|
|
|
|
%%
|
|
|
|
|
|
|
|
PATTERN {
|
|
|
|
int start, end, len;
|
|
|
|
char *lastseg, *tmp;
|
|
|
|
if(yytext[yyleng-1]!='\n')
|
|
|
|
{fprintf(stderr,"ser: pattern matches incomplete line\n"); exit(1);}
|
|
|
|
n++;
|
2016-12-05 20:13:07 +01:00
|
|
|
if( sscanf(yytext,"%d %d",&start,&len) != 2 ) {start=-1; len=-1;};
|
|
|
|
yytext[yyleng-1]='\0';
|
2012-02-07 15:37:11 +01:00
|
|
|
if(tmp=strrchr(yytext,'\n'))
|
|
|
|
{
|
|
|
|
lastseg=tmp+1;
|
2016-12-05 20:13:07 +01:00
|
|
|
if( sscanf(lastseg,"%d %d",&end,&len) != 2 ) {start=-1; len=-1;};
|
2012-02-07 15:37:11 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
end=start;
|
|
|
|
yytext[yyleng-1]='\n';
|
2016-12-05 20:13:07 +01:00
|
|
|
if(start >= 0 && end >=0)
|
|
|
|
printf("%04d 00 BOM * ser:%d\n",start,n);
|
|
|
|
else
|
|
|
|
printf("BOM * ser:%d\n",n);
|
2012-02-07 15:37:11 +01:00
|
|
|
ECHO;
|
2016-12-05 20:13:07 +01:00
|
|
|
if(start>=0 && end >=0)
|
|
|
|
printf("%04d 00 EOM * ser:%d\n",end+len,n);
|
|
|
|
else
|
|
|
|
printf("EOM * ser:%d\n",n);
|
2012-02-07 15:37:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.*\n DEFAULTACTION;
|