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 <string.h> 43#include <stdlib.h> 44#include <ctype.h> 45static int getdimension(int token, const char *text, int leng); 46static int getstring(int token, const char *text, int leng); 47static int gettoken(int token, const char *text, int leng); 48static int getcomment(int token, const char *text, int leng); 49static int lineno = 1; 50%} 51%s OTHER 52comment #.* 53word ([[:alpha:]_/:\-\+\.\*][[:alnum:]_/:\-\+\.\*]+) 54string \"(([^\"\n])|\"\")*\" 55badstring \"(([^\"\n])|\"\")* 56number [[:digit:]x]+ 57dimension [[:digit:]]+[[:blank:]]*x[[:blank:]]*[[:digit:]]+ 58offset [+-][[:digit:]]+[[:blank:]]*[+-][[:blank:]]*[[:digit:]]+ 59origin @[[:blank:]]*[[:digit:]]+[[:blank:]]*[[:blank:]]*x[[:digit:]]+ 60NL \n 61WS [[:blank:]]+ 62%% 63virtual return gettoken(T_VIRTUAL, yytext, yyleng); 64display return gettoken(T_DISPLAY, yytext, yyleng); 65wall return gettoken(T_WALL, yytext, yyleng); 66option return gettoken(T_OPTION, yytext, yyleng); 67param 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); 73{NL} ++lineno; 74{WS} 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); 82<<EOF>> return 0; 83%% 84int yywrap(void) 85{ 86 return 1; 87} 88 89void yyerror(const char *message) 90{ 91 const char *pt, *end; 92 struct _entry { 93 const char *from; 94 const char *to; 95 } *entry, list[] = { 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., #...)" }, 107 { NULL, NULL } 108 }; 109 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; 118 --next; 119 if (next-pt == 1 && next[1] 120 && next[2] == '\'' && next[3] == '\'') { 121 fprintf(stderr, "\"%c\"", next[1]); 122 pt += 4; 123 goto cnt; 124 } 125 for (entry = list; entry->from; ++entry) { 126 if (!strncmp(entry->from, pt, strlen(entry->from))) { 127 fprintf(stderr, "%s", entry->to); 128 pt = next; 129 goto cnt; 130 } 131 } 132 } else if (end-pt >= 5 && pt[0] == '\'' && pt[1] == '\'' && pt[3] 133 && pt[4] == '\'' && pt[5] == '\'') { 134 fprintf(stderr, "\"%c\"", pt[3]); 135 pt += 5; 136 } else if (end-pt >= 3 && pt[0] == '\'' && pt[1] && pt[2] == '\'') { 137 fprintf(stderr, "\"%c\"", pt[1]); 138 pt += 3; 139 } 140 bail: 141 putc(*pt, stderr); 142 cnt: 143 ; 144 } 145 fprintf(stderr, "\n"); 146 exit( 1 ); 147} 148 149static int getdimension(int token, const char *text, int leng) 150{ 151 char *endptr; 152 char *tmp = dmxConfigAlloc(leng+1); 153 int x, y; 154 155 strncpy(tmp, text, leng); 156 x = strtol(tmp, &endptr, 10); 157 while (*endptr && !isdigit(*endptr)) ++endptr; 158 y = strtol(endptr, NULL, 10); 159 dmxConfigFree(tmp); 160 yylval.pair = dmxConfigCreatePair(token, lineno, NULL, x, y, 1, 1); 161 return token; 162} 163 164static int getstring(int token, const char *text, int leng) 165{ 166 yylval.string = dmxConfigCreateString(token, lineno, NULL, 167 dmxConfigCopyString(leng ? text : "", 168 leng)); 169 return token; 170} 171 172static int gettoken(int token, const char *text, int leng) 173{ 174 yylval.token = dmxConfigCreateToken(token, lineno, NULL); 175 return token; 176} 177 178static int getcomment(int token, const char *text, int leng) 179{ 180 yylval.comment = dmxConfigCreateComment(token, lineno, 181 dmxConfigCopyString(text + 1, 182 leng - 1)); 183 return token; 184} 185