1 /************************************************************
2 Copyright (c) 1994 by Silicon Graphics Computer Systems, Inc.
4 Permission to use, copy, modify, and distribute this
5 software and its documentation for any purpose and without
6 fee is hereby granted, provided that the above copyright
7 notice appear in all copies and that both that copyright
8 notice and this permission notice appear in supporting
9 documentation, and that the name of Silicon Graphics not be
10 used in advertising or publicity pertaining to distribution
11 of the software without specific prior written permission.
12 Silicon Graphics makes no representation about the suitability
13 of this software for any purpose. It is provided "as is"
14 without any express or implied warranty.
16 SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
17 SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
18 AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
19 GRAPHICS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
20 DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
21 DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
22 OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH
23 THE USE OR PERFORMANCE OF THIS SOFTWARE.
25 ********************************************************/
32 #include <X11/extensions/XKB.h>
39 static char scanFileBuf[1024];
40 char * scanFile= scanFileBuf;
51 static int nInBuf = 0;
52 static char buf[BUFSIZE];
56 extern unsigned debugFlags;
64 case END_OF_FILE: sprintf(buf, "END_OF_FILE");break;
65 case ERROR: sprintf(buf, "ERROR"); break;
67 case BELL: sprintf(buf, "BELL"); break;
68 case ACCESSX: sprintf(buf, "ACCESSX"); break;
69 case MESSAGE: sprintf(buf, "MESSAGE"); break;
71 case NONE: sprintf(buf, "NONE"); break;
72 case IGNORE: sprintf(buf, "IGNORE"); break;
73 case ECHO: sprintf(buf, "ECHO"); break;
74 case PRINT_EV: sprintf(buf, "PRINT_EV"); break;
75 case SHELL: sprintf(buf, "SHELL"); break;
76 case SOUND: sprintf(buf, "SOUND"); break;
78 case EQUALS: sprintf(buf, "EQUALS"); break;
79 case PLUS: sprintf(buf, "PLUS"); break;
80 case MINUS: sprintf(buf, "MINUS"); break;
81 case DIVIDE: sprintf(buf, "DIVIDE"); break;
82 case TIMES: sprintf(buf, "TIMES"); break;
83 case OBRACE: sprintf(buf, "OBRACE"); break;
84 case CBRACE: sprintf(buf, "CBRACE"); break;
85 case OPAREN: sprintf(buf, "OPAREN"); break;
86 case CPAREN: sprintf(buf, "CPAREN"); break;
87 case OBRACKET: sprintf(buf, "OBRACKET");break;
88 case CBRACKET: sprintf(buf, "CBRACKET");break;
89 case DOT: sprintf(buf, "DOT"); break;
90 case COMMA: sprintf(buf, "COMMA"); break;
91 case SEMI: sprintf(buf, "SEMI"); break;
92 case EXCLAM: sprintf(buf, "EXCLAM"); break;
93 case INVERT: sprintf(buf, "INVERT"); break;
95 case STRING: sprintf(buf, "STRING (%s)",scanStr); break;
96 case INTEGER: sprintf(buf, "INTEGER (0x%x)",scanInt); break;
97 case FLOAT: sprintf(buf, "FLOAT (%d.%d)",
98 scanInt/XkbGeomPtsPerMM,
99 scanInt%XkbGeomPtsPerMM);break;
100 case IDENT: sprintf(buf, "IDENT (%s)",scanStr); break;
101 case KEYNAME: sprintf(buf, "KEYNAME (%s)",scanStr); break;
102 default: sprintf(buf, "UNKNOWN"); break;
109 setScanState(const char *file, int line)
112 strncpy(scanFile,file,1024);
124 while ( ((ch=getc(yyin))!=EOF) && (ch!='"') ) {
126 if ((ch = getc(yyin))!=EOF) {
127 if ( ch=='n' ) ch = '\n';
128 else if ( ch == 't' ) ch = '\t';
129 else if ( ch == 'v' ) ch = '\v';
130 else if ( ch == 'b' ) ch = '\b';
131 else if ( ch == 'r' ) ch = '\r';
132 else if ( ch == 'f' ) ch = '\f';
133 else if ( ch == 'e' ) ch = '\033';
134 else if ( ch == '0' ) {
137 if (((tmp=getc(yyin))!=EOF) && (isdigit(tmp)) &&
138 (tmp!='8') && (tmp!='9')) {
139 ch= (ch*8)+(tmp-'0');
145 if ((!stop) && ((tmp=getc(yyin))!=EOF) && (isdigit(tmp)) &&
146 (tmp!='8') && (tmp!='9')) {
147 ch= (ch*8)+(tmp-'0');
153 if ((!stop) && ((tmp=getc(yyin))!=EOF) && (isdigit(tmp)) &&
154 (tmp!='8') && (tmp!='9')) {
155 ch= (ch*8)+(tmp-'0');
166 if ( nInBuf < BUFSIZE-1 )
170 buf[nInBuf++] = '\0';
173 scanStr = uStringDup(buf);
174 scanStrLine = lineNum;
186 while ( ((ch=getc(yyin))!=EOF) && (ch!='>') ) {
188 if ((ch = getc(yyin))!=EOF) {
189 if ( ch=='n' ) ch = '\n';
190 else if ( ch == 't' ) ch = '\t';
191 else if ( ch == 'v' ) ch = '\v';
192 else if ( ch == 'b' ) ch = '\b';
193 else if ( ch == 'r' ) ch = '\r';
194 else if ( ch == 'f' ) ch = '\f';
195 else if ( ch == 'e' ) ch = '\033';
196 else if ( ch == '0' ) {
199 if (((tmp=getc(yyin))!=EOF) && (isdigit(tmp)) &&
200 (tmp!='8') && (tmp!='9')) {
201 ch= (ch*8)+(tmp-'0');
207 if ((!stop) && ((tmp=getc(yyin))!=EOF) && (isdigit(tmp)) &&
208 (tmp!='8') && (tmp!='9')) {
209 ch= (ch*8)+(tmp-'0');
215 if ((!stop) && ((tmp=getc(yyin))!=EOF) && (isdigit(tmp)) &&
216 (tmp!='8') && (tmp!='9')) {
217 ch= (ch*8)+(tmp-'0');
228 if ( nInBuf < BUFSIZE-1 )
231 if (( ch == '>' )&&(nInBuf<5)) {
232 buf[nInBuf++] = '\0';
235 scanStr = uStringDup(buf);
236 scanStrLine = lineNum;
242 static struct _Keyword {
247 { "accessx", ACCESSX },
248 { "message", MESSAGE },
250 { "ignore", IGNORE },
252 { "printevent", PRINT_EV },
256 static int numKeywords = sizeof(keywords)/sizeof(struct _Keyword);
259 yyGetIdent(int first)
264 buf[0] = first; nInBuf = 1;
265 while ( ((ch=getc(yyin))!=EOF) && (isalnum(ch)||(ch=='_')) ) {
266 if ( nInBuf < BUFSIZE - 1 )
269 buf[nInBuf++] = '\0';
272 for (i=0;(!found)&&(i<numKeywords);i++) {
273 if (uStrCaseCmp(buf,keywords[i].keyword)==0) {
274 rtrn= keywords[i].token;
281 scanStr = uStringDup(buf);
282 scanStrLine = lineNum;
286 if ( (ch!=EOF) && (!isspace(ch)) )
301 while (((ch=getc(yyin))!=EOF)&&(isxdigit(ch)||((nInBuf==1)&&(ch=='x')))) {
307 while (((ch=getc(yyin))!=EOF)&&(isxdigit(ch))) {
312 if ((ch!=EOF)&&(!isspace(ch)))
317 if (sscanf(buf,"%g",&tmp)==1) {
318 scanInt= tmp*XkbGeomPtsPerMM;
322 else if ( sscanf(buf,"%i",&scanInt)==1 )
324 fprintf(stderr,"Malformed number %s\n",buf);
339 else if ( ch=='/' ) { /* handle C++ style double-/ comments */
340 int newch= getc(yyin);
344 } while ((ch!='\n')&&(ch!=EOF));
347 else if (newch!=EOF) {
351 } while ((ch!=EOF)&&(isspace(ch)));
352 if ( ch == '=' ) rtrn = EQUALS;
353 else if ( ch == '+' ) rtrn = PLUS;
354 else if ( ch == '-' ) rtrn = MINUS;
355 else if ( ch == '/' ) rtrn = DIVIDE;
356 else if ( ch == '*' ) rtrn = TIMES;
357 else if ( ch == '{' ) rtrn = OBRACE;
358 else if ( ch == '}' ) rtrn = CBRACE;
359 else if ( ch == '(' ) rtrn = OPAREN;
360 else if ( ch == ')' ) rtrn = CPAREN;
361 else if ( ch == '[' ) rtrn = OBRACKET;
362 else if ( ch == ']' ) rtrn = CBRACKET;
363 else if ( ch == '.' ) rtrn = DOT;
364 else if ( ch == ',' ) rtrn = COMMA;
365 else if ( ch == ';' ) rtrn = SEMI;
366 else if ( ch == '!' ) rtrn = EXCLAM;
367 else if ( ch == '~' ) rtrn = INVERT;
368 else if ( ch == '"' ) rtrn = yyGetString();
369 else if ( ch == '<' ) rtrn = yyGetKeyName();
370 else if ( isalpha(ch) || (ch=='_')) rtrn = yyGetIdent(ch);
371 else if ( isdigit(ch) ) rtrn = yyGetNumber(ch);
372 else if ( ch == EOF ) rtrn = END_OF_FILE;
374 fprintf(stderr,"Unexpected character %c (%d) in input stream\n",ch,ch);
379 fprintf(stderr,"scan: %s\n",tokText(rtrn));