File: modes.l

package info (click to toggle)
fbset 1.0-2
  • links: PTS
  • area: main
  • in suites: hamm
  • size: 132 kB
  • ctags: 141
  • sloc: ansic: 837; lex: 114; makefile: 106; yacc: 95; sh: 56
file content (129 lines) | stat: -rw-r--r-- 2,177 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129

/*
 *  Linux/m68k Frame Buffer Device Configuration
 *
 *   Copyright 1995 by Geert Uytterhoeven
 *		       (Geert.Uytterhoeven@cs.kuleuven.ac.be)
 *
 *  --------------------------------------------------------------------------
 *
 *  This file is subject to the terms and conditions of the GNU General Public
 *  License. See the file COPYING in the main directory of the Linux
 *  distribution for more details.
 */


%{

#include <string.h>
#include <stdlib.h>

#include "fbset.h"
#include "modes.tab.h"

struct keyword {
    const char *name;
    int token;
    int value;
};

static struct keyword keywords[] = {
    { "mode", MODE, 0 },
    { "geometry", GEOMETRY, 0 },
    { "timings", TIMINGS, 0 },
    { "hsync", HSYNC, 0 },
    { "vsync", VSYNC, 0 },
    { "csync", CSYNC, 0 },
    { "extsync", EXTSYNC, 0 },
    { "bcast", BCAST, 0 },
    { "laced", LACED, 0 },
    { "double", DOUBLE, 0 },
    { "endmode", ENDMODE, 0 },
    { "low", POLARITY, LOW },
    { "high", POLARITY, HIGH },
    { "false", BOOLEAN, FALSE },
    { "true", BOOLEAN, TRUE },
    { "", -1, 0 }
};

int line = 1;


void yyerror(const char *s)
{
    Die("%s:%d: %s\n", Opt_modedb, line, s);
}


int yywrap(void)
{
    return(1);
}


static int FindToken(const char *s)
{
    int i;

    for (i = 0; keywords[i].token > 0; i++)
	if (!strcasecmp(s, keywords[i].name)) {
	    yylval = keywords[i].value;
	    return(keywords[i].token);
	}
    Die("%s:%d: Unknown keyword `%s'\n", Opt_modedb, line, s);
}


static char *CopyString(const char *s)
{
    int len;
    char *s2;

    len = strlen(s)-2;
    if (!(s2 = malloc(len+1)))
	Die("No memory\n");
    strncpy(s2, s+1, len);
    s2[len] = '\0';
    return(s2);
}


%}

keyword	[a-zA-Z][a-zA-Z0-9]*
number	[0-9]*
string	\"[^\"\n]*\"
comment	\#([^\n]*)
space	[ \t]+
junk	.

%%

{keyword}   {
		return(FindToken(yytext));
	    }

{number}    {
		yylval = strtoul(yytext, NULL, 0);
		return(NUMBER);
	    }

{string}    {
		yylval = (int)CopyString(yytext);
		return(STRING);
	    }

{comment}$  break;

{space}	    break;

\n	    {
		line++;
		break;
	    }

{junk}	    {
		Die("%s:%d: Invalid token `%s'\n", Opt_modedb, line, yytext);
	    }

%%