3 * Copyright 2002 Red Hat Inc., Durham, North Carolina.
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:
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.
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
31 * Rickard E. (Rik) Faith <faith@redhat.com>
36 #ifdef HAVE_DMX_CONFIG_H
37 #include <dmx-config.h>
45 static int getdimension(int token, const char *text, int leng);
46 static int getstring(int token, const char *text, int leng);
47 static int gettoken(int token, const char *text, int leng);
48 static int getcomment(int token, const char *text, int leng);
49 static int lineno = 1;
53 word ([[:alpha:]_/:\-\+\.\*][[:alnum:]_/:\-\+\.\*]+)
54 string \"(([^\"\n])|\"\")*\"
55 badstring \"(([^\"\n])|\"\")*
57 dimension [[:digit:]]+[[:blank:]]*x[[:blank:]]*[[:digit:]]+
58 offset [+-][[:digit:]]+[[:blank:]]*[+-][[:blank:]]*[[:digit:]]+
59 origin @[[:blank:]]*[[:digit:]]+[[:blank:]]*[[:blank:]]*x[[:digit:]]+
63 virtual return gettoken(T_VIRTUAL, yytext, yyleng);
64 display return gettoken(T_DISPLAY, yytext, yyleng);
65 wall return gettoken(T_WALL, yytext, yyleng);
66 option return gettoken(T_OPTION, yytext, yyleng);
67 param return gettoken(T_PARAM, yytext, yyleng);
68 {dimension} return getdimension(T_DIMENSION, yytext, yyleng);
69 {offset} return getdimension(T_OFFSET, yytext+1, yyleng-1);
70 {origin} return getdimension(T_ORIGIN, yytext+1, yyleng-1);
71 {word} return getstring(T_STRING, yytext, yyleng);
72 {string} return getstring(T_STRING, yytext+1, yyleng-2);
75 \{ return gettoken(yytext[0], yytext, yyleng);
76 \} return gettoken(yytext[0], yytext, yyleng);
77 \; return gettoken(yytext[0], yytext, yyleng);
78 \/ return gettoken(yytext[0], yytext, yyleng);
79 ^{comment} return getcomment(T_LINE_COMMENT, yytext, yyleng);
80 {comment} return getcomment(T_COMMENT, yytext, yyleng);
81 . return getstring(T_STRING, yytext, yyleng);
89 void yyerror(const char *message)
96 { "T_VIRTUAL", "\"virtual\"" },
97 { "T_DISPLAY", "\"display\"" },
98 { "T_WALL", "\"wall\"" },
99 { "T_OPTION", "\"option\"" },
100 { "T_PARAM", "\"param\"" },
101 { "T_DIMENSION", "dimension (e.g., 2x2 or 1024x768)" },
102 { "T_OFFSET", "display offset (e.g., +10-10)" },
103 { "T_ORIGIN", "tile origin (e.g., @1280x1024)" },
104 { "T_STRING", "string" },
105 { "T_COMMENT", "comment (e.g., #...)" },
106 { "T_LINE_COMMENT", "comment (e.g., #...)" },
110 fprintf(stderr, "parse error on line %d at token \"%*.*s\"\n",
111 lineno, yyleng, yyleng, yytext);
112 end = message + strlen(message);
113 for (pt = message; *pt; pt++) {
114 if (pt[0] == 'T' && pt[1] == '_') {
115 const char *next = strchr(pt, ' ');
116 if (!next || !*next) next = strchr(pt, '\0');
117 if (!next) goto bail;
119 if (next-pt == 1 && next[1]
120 && next[2] == '\'' && next[3] == '\'') {
121 fprintf(stderr, "\"%c\"", next[1]);
125 for (entry = list; entry->from; ++entry) {
126 if (!strncmp(entry->from, pt, strlen(entry->from))) {
127 fprintf(stderr, "%s", entry->to);
132 } else if (end-pt >= 5 && pt[0] == '\'' && pt[1] == '\'' && pt[3]
133 && pt[4] == '\'' && pt[5] == '\'') {
134 fprintf(stderr, "\"%c\"", pt[3]);
136 } else if (end-pt >= 3 && pt[0] == '\'' && pt[1] && pt[2] == '\'') {
137 fprintf(stderr, "\"%c\"", pt[1]);
145 fprintf(stderr, "\n");
149 static int getdimension(int token, const char *text, int leng)
152 char *tmp = dmxConfigAlloc(leng+1);
155 strncpy(tmp, text, leng);
156 x = strtol(tmp, &endptr, 10);
157 while (*endptr && !isdigit(*endptr)) ++endptr;
158 y = strtol(endptr, NULL, 10);
160 yylval.pair = dmxConfigCreatePair(token, lineno, NULL, x, y, 1, 1);
164 static int getstring(int token, const char *text, int leng)
166 yylval.string = dmxConfigCreateString(token, lineno, NULL,
167 dmxConfigCopyString(leng ? text : "",
172 static int gettoken(int token, const char *text, int leng)
174 yylval.token = dmxConfigCreateToken(token, lineno, NULL);
178 static int getcomment(int token, const char *text, int leng)
180 yylval.comment = dmxConfigCreateComment(token, lineno,
181 dmxConfigCopyString(text + 1,