Broke freeglut.h into glut.h and freeglut_ext.h
[freeglut] / genfonts / lex.l
1 %{
2 /* $XConsortium: lex.l,v 5.9 95/01/05 19:18:40 kaleb Exp $ */
3 /* $XFree86: xc/fonts/PEX/lex.l,v 3.9 1996/10/17 15:10:45 dawes Exp $ */
4
5 /*****************************************************************
6
7 Copyright (c) 1989,1990, 1991  X Consortium
8
9 Permission is hereby granted, free of charge, to any person obtaining a copy
10 of this software and associated documentation files (the "Software"), to deal
11 in the Software without restriction, including without limitation the rights
12 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 copies of the Software, and to permit persons to whom the Software is
14 furnished to do so, subject to the following conditions:
15
16 The above copyright notice and this permission notice shall be included in
17 all copies or substantial portions of the Software.
18
19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
22 X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
23 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25
26 Except as contained in this notice, the name of the X Consortium shall not be
27 used in advertising or otherwise to promote the sale, use or other dealings
28 in this Software without prior written authorization from the X Consortium.
29
30 Copyright (c) 1989,1990, 1991 by Sun Microsystems, Inc.
31
32                         All Rights Reserved
33
34 Permission to use, copy, modify, and distribute this software and its 
35 documentation for any purpose and without fee is hereby granted, 
36 provided that the above copyright notice appear in all copies and that
37 both that copyright notice and this permission notice appear in 
38 supporting documentation, and that the names of Sun Microsystems,
39 and the X Consortium, not be used in advertising or publicity 
40 pertaining to distribution of the software without specific, written 
41 prior permission.  
42
43 SUN MICROSYSTEMS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, 
44 INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT 
45 SHALL SUN MICROSYSTEMS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL 
46 DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
47 WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
48 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
49 SOFTWARE.
50
51 ******************************************************************/
52
53 #include <ctype.h>
54 #include <math.h>
55 #include <stdlib.h>
56
57 int string(char *, int), res_words(char *);
58
59 %}
60 %%
61 \'[^']*\' |
62 \"[^"]*\"               return string(yytext, yyleng);
63 #.*                     ;
64 [ ,;\t\n\r]*              /* natural dilimters */ ;
65
66 [a-zA-Z][a-zA-Z0-9_.]*  {
67                                 int     token;
68                                 if ( (token = res_words(yytext)) )
69                                         return token;
70                                 return string(yytext, yyleng);
71                         }
72
73 [+-]?[0-9]+\.?[0-9]*[eE][+-]?[0-9]+ |
74 [+-]?[0-9]+\.[0-9]*     |
75 \.[0-9]+                {
76                                 yylval.dval = atof((char *)yytext);
77                                 return REAL;
78                         }
79 [+-]?[0-9]+#[0-9]+      {
80                                 return INTEGER;
81                         }
82 [+-]?[0-9]+             {
83                                 yylval.ival = atoi((char *)yytext);
84                                 return INTEGER;
85                         }
86 [()]                    ;
87 %%
88
89 int res_words(char *str)
90 {
91         static  struct  res_strct {
92                 char    *word;
93                 int     token;
94         } res_table[] = {
95                 {"BOTTOM",              BOTTOM},
96                 {"CENTER",              CENTER},
97                 {"PROPERTIES",          PROPERTIES},
98                 {"CLOSE",               CLOSE},
99                 {"FONTNAME",            FONTNAME},
100                 {"INDEX",               INDEX},
101                 {"MAGIC",               MAGIC},
102                 {"OPEN",                OPEN},
103                 {"RIGHT",               RIGHT},
104                 {"STROKE",              STROKE},
105                 {"TOP",                 TOP},
106                 {"VERTICES",            VERTICES},
107                 {"BEARING",             BEARING},
108                 {"L_SPACE",             L_SPACE},
109                 {"WIDTH",               WIDTH},
110                 {"R_SPACE",             R_SPACE},
111                 {"NUM_CH",              NUM_CH},
112                 {0, 0}
113         };
114
115         {
116                 register struct res_strct *reserved;
117
118                 reserved = res_table;
119
120                 do
121                         if (!strcmp(str, reserved->word))
122                                 break;
123                 while ((++reserved)->word != 0);
124                 return reserved->token;
125         }
126 }
127
128 int string(char *str, int n)
129 {
130         if (*str == '\"' || *str == '\'')
131         {
132                 str++;
133                 n -= 2; /* one for EOL, one for end quote */
134         }
135         if ((yylval.cval = (char *)malloc(n + 1)) != NULL)
136         {
137                 strncpy(yylval.cval, str, n);
138                 yylval.cval[n] = '\0';
139                 return STRING;
140         }
141         else
142                 return 0;
143 }