%{ /* This lexer parses INI format output by rc-status ( rc-status -f ini --all ) */ #include #include #include "Service.hpp" static std::string runlevel; extern std::vector services; void yyerror(char* str); %} %option noyywrap %option nodefault %x STATUS SWALLOW identifier [[:alnum:]]([[:alnum:]]|[-_ /])*[[:alnum:]] %% "["{identifier}"]" { //printf("new runlevel: %s\n", yytext); runlevel = yytext; } ^{identifier} { //printf("service found: %s", yytext); services.push_back(new Service); services.back()->name = yytext; services.back()->runlevel = runlevel; } = { BEGIN STATUS; } \n { ; } [[:alpha:]]+ { BEGIN SWALLOW; //printf(" whichs status is: %s\n", yytext); services.back()->status = yytext; services.back()->status = '[' + services.back()->status + ']'; } . { ; } \n { BEGIN INITIAL; } [ \t]* { ; } . { yyerror(yytext); } %%