1 
2 /*
3  *  Linux Frame Buffer Device Configuration
4  *
5  *  � Copyright 1995-1998 by Geert Uytterhoeven
6  *		       (Geert.Uytterhoeven@cs.kuleuven.ac.be)
7  *
8  *  --------------------------------------------------------------------------
9  *
10  *  This file is subject to the terms and conditions of the GNU General Public
11  *  License. See the file COPYING in the main directory of the Linux
12  *  distribution for more details.
13  */
14 
15 
16 %{
17 
18 #include <string.h>
19 #include <stdlib.h>
20 
21 #define Die Sys_Error
22 
23 #include "fbset.h"
24 #include "fbset_modes_y.h"
25 
26 #ifndef YY_PROTO
27 # define YY_PROTO(x) x
28 #else
29 # define YY_FLEX_REALLOC_HACK
30 #endif
31 int yyget_lineno  (void);
32 FILE *yyget_in  (void);
33 FILE *yyget_out  (void);
34 int yyget_leng  (void);
35 char *yyget_text  (void);
36 void yyset_lineno (int  line_number);
37 void yyset_in (FILE *  in_str);
38 void yyset_out (FILE *  out_str);
39 int yyget_debug  (void);
40 void yyset_debug (int  bdebug);
41 int yylex_destroy (void);
42 
43 #define YY_NO_UNPUT
44 #define YY_DECL int yylex YY_PROTO(( void ))
45 YY_DECL;
46 
47 struct keyword {
48 	const char *name;
49 	int token;
50 	int value;
51 };
52 
53 static struct keyword keywords[] = {
54 	{ "mode", MODE, 0 },
55 	{ "geometry", GEOMETRY, 0 },
56 	{ "timings", TIMINGS, 0 },
57 	{ "hsync", HSYNC, 0 },
58 	{ "vsync", VSYNC, 0 },
59 	{ "csync", CSYNC, 0 },
60 	{ "gsync", GSYNC, 0 },
61 	{ "extsync", EXTSYNC, 0 },
62 	{ "bcast", BCAST, 0 },
63 	{ "laced", LACED, 0 },
64 	{ "double", DOUBLE, 0 },
65 	{ "rgba", RGBA, 0 },
66 	{ "nonstd", NONSTD, 0 },
67 	{ "accel", ACCEL, 0 },
68 	{ "grayscale", GRAYSCALE, 0 },
69 	{ "endmode", ENDMODE, 0 },
70 	{ "low", POLARITY, LOW },
71 	{ "high", POLARITY, HIGH },
72 	{ "false", BOOLEAN, FALSE },
73 	{ "true", BOOLEAN, TRUE },
74 	{ "", -1, 0 }
75 };
76 
77 int line = 1;
78 
79 
80 void yyerror(const char *s);
yyerror(const char * s)81 void yyerror(const char *s)
82 {
83 	Die("%s:%d: %s", Opt_modedb, line, s);
84 }
85 
86 
yywrap(void)87 static int yywrap(void)
88 {
89 	return 1;
90 }
91 
92 
FindToken(const char * s)93 static int FindToken(const char *s)
94 {
95 	int i;
96 
97 	for (i = 0; keywords[i].token > 0; i++)
98 	if (!strcasecmp(s, keywords[i].name)) {
99 		yylval.int_val = keywords[i].value;
100 		return keywords[i].token;
101 	}
102 	Die("%s:%d: Unknown keyword `%s'", Opt_modedb, line, s);
103 }
104 
105 
CopyString(const char * s)106 static const char *CopyString(const char *s)
107 {
108 	int len;
109 	char *s2;
110 
111 	len = strlen(s)-2;
112 	if (!(s2 = malloc(len+1)))
113 	Die("No memory");
114 	strncpy(s2, s+1, len);
115 	s2[len] = '\0';
116 	return s2;
117 }
118 
119 
120 %}
121 
122 keyword	[a-zA-Z][a-zA-Z0-9]*
123 number	[0-9]*
124 string	\"[^\"\n]*\"
125 comment	\#([^\n]*)
126 space	[ \t]+
127 junk	.
128 
129 %%
130 
131 {keyword}   {
132 		return FindToken(yytext);
133 		}
134 
135 {number}    {
136 		yylval.int_val = strtoul(yytext, NULL, 0);
137 		return NUMBER;
138 		}
139 
140 {string}    {
141 		yylval.string = CopyString(yytext);
142 		return STRING;
143 		}
144 
145 {comment}$  break;
146 
147 {space}	    break;
148 
149 \n	    {
150 		line++;
151 		break;
152 		}
153 
154 {junk}	    {
155 		Die("%s:%d: Invalid token `%s'", Opt_modedb, line, yytext);
156 		}
157 
158 %%
159 
160 #ifdef YY_FLEX_REALLOC_HACK
161 #else
162 static __attribute__ ((used)) void (*yyunput_hack)(int, char*) = yyunput;
163 static __attribute__ ((used)) int (*input_hack)(void) = input;
164 #endif
165