Home | History | Annotate | Download | only in tools
      1 %{
      2 /*
      3  *
      4  *  BlueZ - Bluetooth protocol stack for Linux
      5  *
      6  *  Copyright (C) 2002-2010  Marcel Holtmann <marcel (at) holtmann.org>
      7  *
      8  *
      9  *  This program is free software; you can redistribute it and/or modify
     10  *  it under the terms of the GNU General Public License as published by
     11  *  the Free Software Foundation; either version 2 of the License, or
     12  *  (at your option) any later version.
     13  *
     14  *  This program is distributed in the hope that it will be useful,
     15  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
     16  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     17  *  GNU General Public License for more details.
     18  *
     19  *  You should have received a copy of the GNU General Public License
     20  *  along with this program; if not, write to the Free Software
     21  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
     22  *
     23  */
     24 
     25 #ifdef HAVE_CONFIG_H
     26 #include <config.h>
     27 #endif
     28 
     29 /* Nasty workaround, but flex defines isatty() twice */
     30 #define _UNISTD_H
     31 
     32 #include <stdio.h>
     33 #include <errno.h>
     34 #include <sys/socket.h>
     35 
     36 #include <bluetooth/bluetooth.h>
     37 #include <bluetooth/rfcomm.h>
     38 
     39 #include "kword.h"
     40 #include "parser.h"
     41 
     42 int yylex(void);
     43 
     44 #define YY_NO_INPUT
     45 
     46 #define ECHO {;}
     47 #define YY_DECL int yylex(void)
     48 
     49 int yyerror(char *str);
     50 
     51 %}
     52 
     53 %option nounput
     54 
     55 space		[ \t]
     56 linebreak	\n
     57 comment		\#.*\n
     58 keyword		[A-Za-z0-9\_\-]+
     59 
     60 number		[0-9]+
     61 string		\".*\"
     62 bdaddr		[A-Za-z0-9]{2}:[A-Za-z0-9]{2}:[A-Za-z0-9]{2}:[A-Za-z0-9]{2}:[A-Za-z0-9]{2}:[A-Za-z0-9]{2}
     63 
     64 %%
     65 
     66 {space}		{
     67 			/* Skip spaces and tabs */
     68 			;
     69 		}
     70 
     71 {comment}	{
     72 			/* Skip comments */
     73 			lineno++;
     74 		}
     75 
     76 {number}	{
     77 			yylval.number = atoi(yytext);
     78 			return NUMBER;
     79 		}
     80 
     81 {string}	{
     82 			yylval.string = yytext;
     83 			return STRING;
     84 		}
     85 
     86 {bdaddr}	{
     87 			bdaddr_t *ba = malloc(sizeof(bdaddr_t));
     88 			str2ba(yytext, ba);
     89 			yylval.bdaddr = ba;
     90 			return BDADDR;
     91 		}
     92 
     93 {keyword}	{
     94 			int keyword = rfcomm_find_keyword(rfcomm_keyword, yytext);
     95 			if (keyword != -1)
     96 				return keyword;
     97 
     98 			if (strncmp(yytext, "rfcomm", 6) == 0) {
     99 				yylval.number = atoi(yytext + 6);
    100 				return RFCOMM;
    101 			}
    102 
    103 			yylval.string = yytext;
    104 			return WORD;
    105 		}
    106 
    107 {linebreak}	{
    108 			lineno++;
    109 		}
    110 
    111 .		{
    112 			return *yytext;
    113 		}
    114 
    115 %%
    116 
    117 int yywrap(void)
    118 {
    119 	return 1;
    120 }
    121