Add patch that contain Mali fixes.
[deb_xorg-server.git] / hw / dmx / config / scanner.l
... / ...
CommitLineData
1/* $XFree86$ */
2/*
3 * Copyright 2002 Red Hat Inc., Durham, North Carolina.
4 *
5 * All Rights Reserved.
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining
8 * a copy of this software and associated documentation files (the
9 * "Software"), to deal in the Software without restriction, including
10 * without limitation on the rights to use, copy, modify, merge,
11 * publish, distribute, sublicense, and/or sell copies of the Software,
12 * and to permit persons to whom the Software is furnished to do so,
13 * subject to the following conditions:
14 *
15 * The above copyright notice and this permission notice (including the
16 * next paragraph) shall be included in all copies or substantial
17 * portions of the Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
22 * NON-INFRINGEMENT. IN NO EVENT SHALL RED HAT AND/OR THEIR SUPPLIERS
23 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
24 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
25 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26 * SOFTWARE.
27 */
28
29/*
30 * Authors:
31 * Rickard E. (Rik) Faith <faith@redhat.com>
32 *
33 */
34
35%{
36#ifdef HAVE_DMX_CONFIG_H
37#include <dmx-config.h>
38#endif
39
40#include "dmxparse.h"
41#include "parser.h"
42#include "os.h"
43#include <string.h>
44#include <stdlib.h>
45#include <ctype.h>
46static int getdimension(int token, const char *text, int leng);
47static int getstring(int token, const char *text, int leng);
48static int gettoken(int token, const char *text, int leng);
49static int getcomment(int token, const char *text, int leng);
50static int lineno = 1;
51%}
52%s OTHER
53comment #.*
54word ([[:alpha:]_/:\-\+\.\*][[:alnum:]_/:\-\+\.\*]+)
55string \"(([^\"\n])|\"\")*\"
56badstring \"(([^\"\n])|\"\")*
57number [[:digit:]x]+
58dimension [[:digit:]]+[[:blank:]]*x[[:blank:]]*[[:digit:]]+
59offset [+-][[:digit:]]+[[:blank:]]*[+-][[:blank:]]*[[:digit:]]+
60origin @[[:blank:]]*[[:digit:]]+[[:blank:]]*[[:blank:]]*x[[:digit:]]+
61NL \n
62WS [[:blank:]]+
63%%
64virtual return gettoken(T_VIRTUAL, yytext, yyleng);
65display return gettoken(T_DISPLAY, yytext, yyleng);
66wall return gettoken(T_WALL, yytext, yyleng);
67option return gettoken(T_OPTION, yytext, yyleng);
68param return gettoken(T_PARAM, yytext, yyleng);
69{dimension} return getdimension(T_DIMENSION, yytext, yyleng);
70{offset} return getdimension(T_OFFSET, yytext+1, yyleng-1);
71{origin} return getdimension(T_ORIGIN, yytext+1, yyleng-1);
72{word} return getstring(T_STRING, yytext, yyleng);
73{string} return getstring(T_STRING, yytext+1, yyleng-2);
74{NL} ++lineno;
75{WS}
76\{ return gettoken(yytext[0], yytext, yyleng);
77\} return gettoken(yytext[0], yytext, yyleng);
78\; return gettoken(yytext[0], yytext, yyleng);
79\/ return gettoken(yytext[0], yytext, yyleng);
80^{comment} return getcomment(T_LINE_COMMENT, yytext, yyleng);
81{comment} return getcomment(T_COMMENT, yytext, yyleng);
82. return getstring(T_STRING, yytext, yyleng);
83<<EOF>> return 0;
84%%
85int yywrap(void)
86{
87 return 1;
88}
89
90void yyerror(const char *message)
91{
92 const char *pt, *end;
93 struct _entry {
94 const char *from;
95 const char *to;
96 } *entry, list[] = {
97 { "T_VIRTUAL", "\"virtual\"" },
98 { "T_DISPLAY", "\"display\"" },
99 { "T_WALL", "\"wall\"" },
100 { "T_OPTION", "\"option\"" },
101 { "T_PARAM", "\"param\"" },
102 { "T_DIMENSION", "dimension (e.g., 2x2 or 1024x768)" },
103 { "T_OFFSET", "display offset (e.g., +10-10)" },
104 { "T_ORIGIN", "tile origin (e.g., @1280x1024)" },
105 { "T_STRING", "string" },
106 { "T_COMMENT", "comment (e.g., #...)" },
107 { "T_LINE_COMMENT", "comment (e.g., #...)" },
108 { NULL, NULL }
109 };
110
111 fprintf(stderr, "parse error on line %d at token \"%*.*s\"\n",
112 lineno, yyleng, yyleng, yytext);
113 end = message + strlen(message);
114 for (pt = message; *pt; pt++) {
115 if (pt[0] == 'T' && pt[1] == '_') {
116 const char *next = strchr(pt, ' ');
117 if (!next || !*next) next = strchr(pt, '\0');
118 if (!next) goto bail;
119 --next;
120 if (next-pt == 1 && next[1]
121 && next[2] == '\'' && next[3] == '\'') {
122 fprintf(stderr, "\"%c\"", next[1]);
123 pt += 4;
124 goto cnt;
125 }
126 for (entry = list; entry->from; ++entry) {
127 if (!strncmp(entry->from, pt, strlen(entry->from))) {
128 fprintf(stderr, "%s", entry->to);
129 pt = next;
130 goto cnt;
131 }
132 }
133 } else if (end-pt >= 5 && pt[0] == '\'' && pt[1] == '\'' && pt[3]
134 && pt[4] == '\'' && pt[5] == '\'') {
135 fprintf(stderr, "\"%c\"", pt[3]);
136 pt += 5;
137 } else if (end-pt >= 3 && pt[0] == '\'' && pt[1] && pt[2] == '\'') {
138 fprintf(stderr, "\"%c\"", pt[1]);
139 pt += 3;
140 }
141 bail:
142 putc(*pt, stderr);
143 cnt:
144 ;
145 }
146 fprintf(stderr, "\n");
147 exit( 1 );
148}
149
150static int getdimension(int token, const char *text, int leng)
151{
152 char *endptr;
153 char *tmp = dmxConfigAlloc(leng+1);
154 int x, y;
155
156 strlcpy(tmp, text, leng+1);
157 x = strtol(tmp, &endptr, 10);
158 while (*endptr && !isdigit(*endptr)) ++endptr;
159 y = strtol(endptr, NULL, 10);
160 dmxConfigFree(tmp);
161 yylval.pair = dmxConfigCreatePair(token, lineno, NULL, x, y, 1, 1);
162 return token;
163}
164
165static int getstring(int token, const char *text, int leng)
166{
167 yylval.string = dmxConfigCreateString(token, lineno, NULL,
168 dmxConfigCopyString(leng ? text : "",
169 leng));
170 return token;
171}
172
173static int gettoken(int token, const char *text, int leng)
174{
175 yylval.token = dmxConfigCreateToken(token, lineno, NULL);
176 return token;
177}
178
179static int getcomment(int token, const char *text, int leng)
180{
181 yylval.comment = dmxConfigCreateComment(token, lineno,
182 dmxConfigCopyString(text + 1,
183 leng - 1));
184 return token;
185}