http://gimel.esc.cam.ac.uk/james/rpld/src/rpld-1.3.tar.gz
[rpld.git] / rpld_conf.lex
1 /*************************************************
2 *     rpld - an IBM style RIPL server            *
3 *************************************************/
4
5 /* Copyright (c) 1999, James McKenzie.
6  *                      All rights reserved
7  * Copyright (c) 1998, Christopher Lightfoot.
8  *                      All rights reserved
9  *
10  * By using this file, you agree to the terms and conditions set
11  * forth in the LICENCE file which can be found at the top level of
12  * the rpld distribution.
13  *
14  * IBM is a trademark of IBM corp.
15  *
16  */
17
18 /*
19  *  Lexer for RPLD conf files
20  *
21  *  $Log: rpld_conf.lex,v $
22  *  Revision 1.4  1999/09/26 10:46:56  root
23  *  #
24  *
25  *  Revision 1.3  1999/09/13 11:17:35  root
26  *  \#
27  *
28  *  Revision 1.2  1999/09/13 11:08:34  root
29  *  \#
30  *
31  *  Revision 1.1  1999/09/13 11:04:13  root
32  *  \#
33  *
34  *  
35  */
36
37 %x      COMMENT
38
39 %{
40 static char rcsid[]="$Id: rpld_conf.lex,v 1.4 1999/09/26 10:46:56 root Exp root $";
41
42 #include <stdio.h>
43 #include <string.h>
44 #include <stdlib.h>
45 #include "rpld_conf.tab.h"
46
47
48 // line number
49 int lineno = 1;
50
51 // function to convert hex digits to a MAC address
52 void strtomac(char *s, char *mac);
53
54 void strtomac(char *s, char *mac)
55 {
56         // mac address *must* be in form 00:11:22:33:44:55
57         int i;
58
59         for (i = 0; i < 6; i++) *(mac + i) = (unsigned char)strtol(s + i * 3, NULL, 16);
60 }
61
62
63 %}
64 ws      [ \t]+
65 nl      \n
66 hb      [0-9A-Fa-f][0-9A-Fa-f]
67
68 %%
69
70 {ws}                    ;
71 {nl}                    { lineno++; }
72
73 \/\/.*                  ;
74
75 "/*"                    BEGIN COMMENT;
76 <COMMENT>.      |
77 <COMMENT>\n             ;
78 <COMMENT>"*/"           BEGIN INITIAL;
79
80 [{]                     { return BLOCK_START; }
81
82 [}]                     { return BLOCK_END; }
83
84 {hb}:{hb}:{hb}:{hb}:{hb}:{hb}   {
85                                 strtomac(yytext, (yylval.mac_address));
86                                 return MACADDR;
87                         }
88
89 {hb}:{hb}:{hb}:{hb}:{hb}:{hb}/[1-6]     {
90                                 strtomac(yytext, (yylval.pm.mac_address));
91                                 yylval.pm.mac_len = yytext[13] - '0';
92                                 return MACADDR_PARTIAL;
93                         }
94
95 0x[0-9A-Fa-f]+ {
96                                 yylval.number = strtol(yytext + 2, NULL, 16);
97                                 return NUMBER;
98                         }
99
100 [0-9]+                  {
101                                 int i; i = strtol(yytext, NULL, 10);
102                                 yylval.number = i; return NUMBER;
103                         }
104
105 [A-Za-z\-_]+            { yylval.name = strdup(yytext); return NAME; }
106
107 \"[A-Za-z0-9.:/\-_ ]*\" { yylval.text = strdup(yytext + 1); *(yylval.text + strlen(yylval.text) - 1) = 0; return TEXT;}
108
109 .                       { return yytext[0]; }
110
111 %%
112
113
114 int yywrap()
115 {
116         return 1;
117 }
118