utt/lib/ser.l.template

37 lines
815 B
Plaintext

%{
#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++;
if( sscanf(yytext,"%d %d",&start,&len) != 2 ) {start=-1; len=-1;};
yytext[yyleng-1]='\0';
if(tmp=strrchr(yytext,'\n'))
{
lastseg=tmp+1;
if( sscanf(lastseg,"%d %d",&end,&len) != 2 ) {start=-1; len=-1;};
}
else
end=start;
yytext[yyleng-1]='\n';
if(start >= 0 && end >=0)
printf("%04d 00 BOM * ser:%d\n",start,n);
else
printf("BOM * ser:%d\n",n);
ECHO;
if(start>=0 && end >=0)
printf("%04d 00 EOM * ser:%d\n",end+len,n);
else
printf("EOM * ser:%d\n",n);
}
.*\n DEFAULTACTION;