%{ #include "CLISupport.h" #include "CLIParser.hpp" #include "ParserCommon.h" #include int CLICurrentLine = 1, CLICurrentColumn = 0; #define TRACKLINE() CLICurrentLine++; CLICurrentColumn = 0; #define TRACKCOLUMN() CLICurrentColumn += yyleng; extern "C" int yywrap(void) { return 1; } /* * We do our own YY_INPUT so we can handle requests to shut down. */ #define YY_INPUT(buf,result,max_size) CLIRead(buf,result,max_size) %} %array %option outfile="CLIScanner.cpp" %option always-interactive %option prefix="cli" DIGIT [0-9] STRING \"([^\"]|\\\")*\" HEX_VAL 0x[0-9a-fA-F]{1,8} MACADDR1 0x[0-9a-fA-F]{12} MACADDR2 [0-9a-fA-F]{2}[:-][0-9a-fA-F]{2}[:-][0-9a-fA-F]{2}[:-][0-9a-fA-F]{2}[:-][0-9a-fA-F]{2}[:-][0-9a-fA-F]{2} OUI_VAL1 0x[0-9a-fA-F]{6} OUI_VAL2 [0-9a-fA-F]{2}[:-][0-9a-fA-F]{2}[:-][0-9a-fA-F]{2} IPv4_ADDR [0-9]+\.[0-9]+\.[0-9]+\.[0-9]+ COMMAND [a-zA-Z_][a-zA-Z0-9_]* %% \n { TRACKCOLUMN(); return '\n'; } {DIGIT}+ { TRACKCOLUMN(); clilval.IntVal = atoi(yytext); return NUMBER; } {STRING} { /* get the string minus the surrounding quotes */ yytext[yyleng - 1] = '\0'; clilval.StrVal = strdup(yytext + 1); TRACKCOLUMN(); return STRING; } {IPv4_ADDR} { TRACKCOLUMN(); clilval.IPVal = new TIPAddress(yytext); return IPADDR; } ({MACADDR1})|({MACADDR2}) { TRACKCOLUMN(); clilval.MacVal = new TMacAddress(yytext); return MACADDR; } {OUI_VAL1} { TRACKCOLUMN(); char *str; int Pos; for(str = yytext + 2, Pos = 0; *str; str += 2) { clilval.OuiVal[Pos++] = ParseHex(str); } return OUI_VAL; } {HEX_VAL} { TRACKCOLUMN(); clilval.IntVal = strtoul(yytext, NULL, 16); return NUMBER; } "debug" { TRACKCOLUMN(); return CMD_DEBUG; } "device" { TRACKCOLUMN(); return CMD_DEVICE; } "list" { TRACKCOLUMN(); return CMD_LIST; } "size" { TRACKCOLUMN(); return CMD_SIZE; } "detail" { TRACKCOLUMN(); return CMD_DETAIL; } "queue" { TRACKCOLUMN(); return CMD_QUEUE; } "scan" { TRACKCOLUMN(); return CMD_SCAN; } "thread" { TRACKCOLUMN(); return CMD_THREAD; } "status" { TRACKCOLUMN(); return CMD_STATUS; } "config" { TRACKCOLUMN(); return CMD_CONFIG; } "classify" { TRACKCOLUMN(); return CMD_CLASSIFY; } "quit"|"exit" { TRACKCOLUMN(); return CMD_QUIT; } "help"|"?" { TRACKCOLUMN(); return CMD_HELP; } "sniffer" { TRACKCOLUMN(); return CMD_SNIFFER; } "deferred" { TRACKCOLUMN(); return CMD_DEFERRED; } "packet" { TRACKCOLUMN(); return CMD_PACKET; } "submit" { TRACKCOLUMN(); return CMD_SUBMIT; } {COMMAND} { TRACKCOLUMN(); clilval.StrVal = strdup(yytext); return COMMAND; } [\ \t]+ { TRACKCOLUMN(); } . { printf("\nUnknown token: %s (line %d, column %d)\n", yytext, CLICurrentLine, CLICurrentColumn); TRACKCOLUMN(); } %%