1706f2543Smrg/* $XFree86$ */ 2706f2543Smrg/* 3706f2543Smrg * Copyright 2002 Red Hat Inc., Durham, North Carolina. 4706f2543Smrg * 5706f2543Smrg * All Rights Reserved. 6706f2543Smrg * 7706f2543Smrg * Permission is hereby granted, free of charge, to any person obtaining 8706f2543Smrg * a copy of this software and associated documentation files (the 9706f2543Smrg * "Software"), to deal in the Software without restriction, including 10706f2543Smrg * without limitation on the rights to use, copy, modify, merge, 11706f2543Smrg * publish, distribute, sublicense, and/or sell copies of the Software, 12706f2543Smrg * and to permit persons to whom the Software is furnished to do so, 13706f2543Smrg * subject to the following conditions: 14706f2543Smrg * 15706f2543Smrg * The above copyright notice and this permission notice (including the 16706f2543Smrg * next paragraph) shall be included in all copies or substantial 17706f2543Smrg * portions of the Software. 18706f2543Smrg * 19706f2543Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 20706f2543Smrg * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 21706f2543Smrg * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 22706f2543Smrg * NON-INFRINGEMENT. IN NO EVENT SHALL RED HAT AND/OR THEIR SUPPLIERS 23706f2543Smrg * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 24706f2543Smrg * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 25706f2543Smrg * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 26706f2543Smrg * SOFTWARE. 27706f2543Smrg */ 28706f2543Smrg 29706f2543Smrg/* 30706f2543Smrg * Authors: 31706f2543Smrg * Rickard E. (Rik) Faith <faith@redhat.com> 32706f2543Smrg * 33706f2543Smrg */ 34706f2543Smrg 35706f2543Smrg%{ 36706f2543Smrg#ifdef HAVE_DMX_CONFIG_H 37706f2543Smrg#include <dmx-config.h> 38706f2543Smrg#endif 39706f2543Smrg 40706f2543Smrg#include "dmxparse.h" 41706f2543Smrg#include "parser.h" 42706f2543Smrg#include <string.h> 43706f2543Smrg#include <stdlib.h> 44706f2543Smrg#include <ctype.h> 45706f2543Smrgstatic int getdimension(int token, const char *text, int leng); 46706f2543Smrgstatic int getstring(int token, const char *text, int leng); 47706f2543Smrgstatic int gettoken(int token, const char *text, int leng); 48706f2543Smrgstatic int getcomment(int token, const char *text, int leng); 49706f2543Smrgstatic int lineno = 1; 50706f2543Smrg%} 51706f2543Smrg%s OTHER 52706f2543Smrgcomment #.* 53706f2543Smrgword ([[:alpha:]_/:\-\+\.\*][[:alnum:]_/:\-\+\.\*]+) 54706f2543Smrgstring \"(([^\"\n])|\"\")*\" 55706f2543Smrgbadstring \"(([^\"\n])|\"\")* 56706f2543Smrgnumber [[:digit:]x]+ 57706f2543Smrgdimension [[:digit:]]+[[:blank:]]*x[[:blank:]]*[[:digit:]]+ 58706f2543Smrgoffset [+-][[:digit:]]+[[:blank:]]*[+-][[:blank:]]*[[:digit:]]+ 59706f2543Smrgorigin @[[:blank:]]*[[:digit:]]+[[:blank:]]*[[:blank:]]*x[[:digit:]]+ 60706f2543SmrgNL \n 61706f2543SmrgWS [[:blank:]]+ 62706f2543Smrg%% 63706f2543Smrgvirtual return gettoken(T_VIRTUAL, yytext, yyleng); 64706f2543Smrgdisplay return gettoken(T_DISPLAY, yytext, yyleng); 65706f2543Smrgwall return gettoken(T_WALL, yytext, yyleng); 66706f2543Smrgoption return gettoken(T_OPTION, yytext, yyleng); 67706f2543Smrgparam return gettoken(T_PARAM, yytext, yyleng); 68706f2543Smrg{dimension} return getdimension(T_DIMENSION, yytext, yyleng); 69706f2543Smrg{offset} return getdimension(T_OFFSET, yytext+1, yyleng-1); 70706f2543Smrg{origin} return getdimension(T_ORIGIN, yytext+1, yyleng-1); 71706f2543Smrg{word} return getstring(T_STRING, yytext, yyleng); 72706f2543Smrg{string} return getstring(T_STRING, yytext+1, yyleng-2); 73706f2543Smrg{NL} ++lineno; 74706f2543Smrg{WS} 75706f2543Smrg\{ return gettoken(yytext[0], yytext, yyleng); 76706f2543Smrg\} return gettoken(yytext[0], yytext, yyleng); 77706f2543Smrg\; return gettoken(yytext[0], yytext, yyleng); 78706f2543Smrg\/ return gettoken(yytext[0], yytext, yyleng); 79706f2543Smrg^{comment} return getcomment(T_LINE_COMMENT, yytext, yyleng); 80706f2543Smrg{comment} return getcomment(T_COMMENT, yytext, yyleng); 81706f2543Smrg. return getstring(T_STRING, yytext, yyleng); 82706f2543Smrg<<EOF>> return 0; 83706f2543Smrg%% 84706f2543Smrgint yywrap(void) 85706f2543Smrg{ 86706f2543Smrg return 1; 87706f2543Smrg} 88706f2543Smrg 89706f2543Smrgvoid yyerror(const char *message) 90706f2543Smrg{ 91706f2543Smrg const char *pt, *end; 92706f2543Smrg struct _entry { 93706f2543Smrg const char *from; 94706f2543Smrg const char *to; 95706f2543Smrg } *entry, list[] = { 96706f2543Smrg { "T_VIRTUAL", "\"virtual\"" }, 97706f2543Smrg { "T_DISPLAY", "\"display\"" }, 98706f2543Smrg { "T_WALL", "\"wall\"" }, 99706f2543Smrg { "T_OPTION", "\"option\"" }, 100706f2543Smrg { "T_PARAM", "\"param\"" }, 101706f2543Smrg { "T_DIMENSION", "dimension (e.g., 2x2 or 1024x768)" }, 102706f2543Smrg { "T_OFFSET", "display offset (e.g., +10-10)" }, 103706f2543Smrg { "T_ORIGIN", "tile origin (e.g., @1280x1024)" }, 104706f2543Smrg { "T_STRING", "string" }, 105706f2543Smrg { "T_COMMENT", "comment (e.g., #...)" }, 106706f2543Smrg { "T_LINE_COMMENT", "comment (e.g., #...)" }, 107706f2543Smrg { NULL, NULL } 108706f2543Smrg }; 109706f2543Smrg 110706f2543Smrg fprintf(stderr, "parse error on line %d at token \"%*.*s\"\n", 111706f2543Smrg lineno, yyleng, yyleng, yytext); 112706f2543Smrg end = message + strlen(message); 113706f2543Smrg for (pt = message; *pt; pt++) { 114706f2543Smrg if (pt[0] == 'T' && pt[1] == '_') { 115706f2543Smrg const char *next = strchr(pt, ' '); 116706f2543Smrg if (!next || !*next) next = strchr(pt, '\0'); 117706f2543Smrg if (!next) goto bail; 118706f2543Smrg --next; 119706f2543Smrg if (next-pt == 1 && next[1] 120706f2543Smrg && next[2] == '\'' && next[3] == '\'') { 121706f2543Smrg fprintf(stderr, "\"%c\"", next[1]); 122706f2543Smrg pt += 4; 123706f2543Smrg goto cnt; 124706f2543Smrg } 125706f2543Smrg for (entry = list; entry->from; ++entry) { 126706f2543Smrg if (!strncmp(entry->from, pt, strlen(entry->from))) { 127706f2543Smrg fprintf(stderr, "%s", entry->to); 128706f2543Smrg pt = next; 129706f2543Smrg goto cnt; 130706f2543Smrg } 131706f2543Smrg } 132706f2543Smrg } else if (end-pt >= 5 && pt[0] == '\'' && pt[1] == '\'' && pt[3] 133706f2543Smrg && pt[4] == '\'' && pt[5] == '\'') { 134706f2543Smrg fprintf(stderr, "\"%c\"", pt[3]); 135706f2543Smrg pt += 5; 136706f2543Smrg } else if (end-pt >= 3 && pt[0] == '\'' && pt[1] && pt[2] == '\'') { 137706f2543Smrg fprintf(stderr, "\"%c\"", pt[1]); 138706f2543Smrg pt += 3; 139706f2543Smrg } 140706f2543Smrg bail: 141706f2543Smrg putc(*pt, stderr); 142706f2543Smrg cnt: 143706f2543Smrg ; 144706f2543Smrg } 145706f2543Smrg fprintf(stderr, "\n"); 146706f2543Smrg exit( 1 ); 147706f2543Smrg} 148706f2543Smrg 149706f2543Smrgstatic int getdimension(int token, const char *text, int leng) 150706f2543Smrg{ 151706f2543Smrg char *endptr; 152706f2543Smrg char *tmp = dmxConfigAlloc(leng+1); 153706f2543Smrg int x, y; 154706f2543Smrg 155706f2543Smrg strncpy(tmp, text, leng); 156706f2543Smrg x = strtol(tmp, &endptr, 10); 157706f2543Smrg while (*endptr && !isdigit(*endptr)) ++endptr; 158706f2543Smrg y = strtol(endptr, NULL, 10); 159706f2543Smrg dmxConfigFree(tmp); 160706f2543Smrg yylval.pair = dmxConfigCreatePair(token, lineno, NULL, x, y, 1, 1); 161706f2543Smrg return token; 162706f2543Smrg} 163706f2543Smrg 164706f2543Smrgstatic int getstring(int token, const char *text, int leng) 165706f2543Smrg{ 166706f2543Smrg yylval.string = dmxConfigCreateString(token, lineno, NULL, 167706f2543Smrg dmxConfigCopyString(leng ? text : "", 168706f2543Smrg leng)); 169706f2543Smrg return token; 170706f2543Smrg} 171706f2543Smrg 172706f2543Smrgstatic int gettoken(int token, const char *text, int leng) 173706f2543Smrg{ 174706f2543Smrg yylval.token = dmxConfigCreateToken(token, lineno, NULL); 175706f2543Smrg return token; 176706f2543Smrg} 177706f2543Smrg 178706f2543Smrgstatic int getcomment(int token, const char *text, int leng) 179706f2543Smrg{ 180706f2543Smrg yylval.comment = dmxConfigCreateComment(token, lineno, 181706f2543Smrg dmxConfigCopyString(text + 1, 182706f2543Smrg leng - 1)); 183706f2543Smrg return token; 184706f2543Smrg} 185