%{ /* cfg.l - switch configuration language */ /* Written 1998 by Werner Almesberger, EPFL ICA */ #if HAVE_CONFIG_H #include #endif #include #include #include #include "atm.h" #include "cfg_y.h" static int lineno = 1; static int token; /* f@#%ing flex doesn't grok return after BEGIN */ void yyerror(const char *s); %} %s N %s P %% BEGIN(N); option { BEGIN(P); token = TOK_OPTION; } control { BEGIN(P); token = TOK_CONTROL; } command return TOK_COMMAND; socket { BEGIN(P); token = TOK_SOCKET; } vpci return TOK_VPCI; itf return TOK_ITF; route { BEGIN(P); token = TOK_ROUTE; } default return TOK_DEFAULT; \"[^"\t\n]*\" { yylval.str = strdup(yytext+1); *strrchr(yylval.str,'"') = 0; return TOK_STR; } [0-9]+ { char *end; yylval.num = strtoul(yytext,&end,10); if (*end) yyerror("invalid number"); return TOK_NUM; } [0-9]+\.[0-9]+(\.[0-9]+)? { if (text2atm(yytext,(struct sockaddr *) &yylval.pvc, sizeof(yylval.pvc),T2A_PVC) < 0) yyerror("invalid VC"); return TOK_PVC; }

[^\t\n ]+ { BEGIN(N); yylval.str = strdup(yytext); if (!yylval.str) { perror("strdup"); exit(1); } return token; } \n?[\t ]* lineno += *yytext == '\n'; #[^\n]*\n lineno++; . return *yytext; %% void yyerror(const char *s) { fprintf(stderr,"line %d: %s near \"%s\"\n",lineno,s,yytext); exit(1); }