Fixes for OpenBSD
[oweals/cde.git] / cde / programs / dtinfo / DtMmdb / StyleSheet / tokenStyle.l
1  /*
2   * $TOG: tokenStyle.l /main/6 1998/04/17 11:50:07 mgreess $
3   *
4   * Copyright (c) 1993 HAL Computer Systems International, Ltd.
5   * All rights reserved.  Unpublished -- rights reserved under
6   * the Copyright Laws of the United States.  USE OF A COPYRIGHT
7   * NOTICE IS PRECAUTIONARY ONLY AND DOES NOT IMPLY PUBLICATION
8   * OR DISCLOSURE.
9   * 
10   * THIS SOFTWARE CONTAINS CONFIDENTIAL INFORMATION AND TRADE
11   * SECRETS OF HAL COMPUTER SYSTEMS INTERNATIONAL, LTD.  USE,
12   * DISCLOSURE, OR REPRODUCTION IS PROHIBITED WITHOUT THE
13   * PRIOR EXPRESS WRITTEN PERMISSION OF HAL COMPUTER SYSTEMS
14   * INTERNATIONAL, LTD.
15   * 
16   *                         RESTRICTED RIGHTS LEGEND
17   * Use, duplication, or disclosure by the Government is subject
18   * to the restrictions as set forth in subparagraph (c)(l)(ii)
19   * of the Rights in Technical Data and Computer Software clause
20   * at DFARS 252.227-7013.
21   *
22   *          HAL COMPUTER SYSTEMS INTERNATIONAL, LTD.
23   *                  1315 Dell Avenue
24   *                  Campbell, CA  95008
25   * 
26   */
27
28
29 %a 30000
30 %e 10000
31 %k 10000
32 %n 10000
33 %o 40000
34 %p 20000
35
36 %{
37 #include <string.h>
38 #include "ParserConst.h"
39 #include "Expression.h"
40 #include "FeatureValue.h"
41 #include "PathTable.h"
42 #include "SSPath.h"
43 #include "PathQualifier.h"
44 #include "StyleSheetExceptions.h"
45 #include "style.tab.h"
46 #include "Debug.h"
47 #include <iostream.h>
48
49 extern istream *g_stylein ;
50
51 #define YY_INPUT(buf,result,max_size)\
52   {\
53      if (g_stylein -> eof()) {\
54         result=0;\
55      } else {\
56         g_stylein -> read((char*)buf, max_size-1); \
57         result = g_stylein -> gcount(); \
58         buf[result] = 0; \
59      }\
60   }
61
62 unsigned char* qstring_buf = new unsigned char[1024];
63 int qstring_buf_size = 1024;
64 int qstring_buf_content_size = 0;
65
66 char* commentBuffer = new char [1024];
67 int commentBufferSize = 1024;
68 int commentBufferContentSize = 0;
69
70 int yylineno=1;
71                 
72 void addToQstringBuf(const unsigned char* str, int size)
73 {
74    if ( size <= 0 ) return;
75
76    if ( qstring_buf_size - qstring_buf_content_size < size ) {
77       qstring_buf_size = 2*(size+qstring_buf_content_size);
78       unsigned char* x = new unsigned char[qstring_buf_size];
79       memcpy(x, qstring_buf, qstring_buf_content_size);
80       delete qstring_buf;
81       qstring_buf = x;
82    }
83
84    memcpy(qstring_buf + qstring_buf_content_size, str, size);
85    qstring_buf_content_size += size;
86    qstring_buf[qstring_buf_content_size] = 0;
87 }
88
89
90 %}
91 unit ([Ii][Nn]|[Ii][Nn][Cc][Hh]|[Pp][Cc]|[Pp][Ii][Cc][Aa]|[Pp][Tt]|[Pp][Oo][Ii][Nn][Tt]|[Pp][Ii][Xx][Ee][Ll]|[Cc][Mm])
92
93 %x block sgmlgimode quoted_string
94
95 %%
96
97 "#|"    BEGIN(block);
98
99 ^"#".*  {
100            if ( commentBufferSize < yyleng ) {
101               delete commentBuffer;
102               commentBufferSize = 2 * yyleng ;
103               commentBuffer = new char [commentBufferSize];
104            } 
105
106            commentBufferContentSize = yyleng-1;
107            memcpy(commentBuffer, yytext+1, commentBufferContentSize); // copy everything except the #
108            commentBuffer[commentBufferContentSize] = 0;
109         }
110
111 "="     {
112            return(OPER_assign);
113         }
114
115 "@"     {
116            return(OPER_attr);
117         }
118
119 [+]     {
120            yylval.charData = yytext[0];
121            return(OPER_plus);
122         }
123
124 [-]     {
125            yylval.charData = yytext[0];
126            return(OPER_minus);
127         }
128
129 "/"     {
130            yylval.charData = yytext[0];
131            return(OPER_div);
132         }
133
134 "."     {
135            return(OPER_period);
136         }
137
138 "*"     {
139            yylval.charData = yytext[0];
140            return(OPER_star);
141         }
142
143 ":"     {
144            return(OPER_modify);
145         }
146
147 "?"     {
148            return(OPER_oneof);
149         }
150
151 "^"     {
152            return(OPER_parent);
153         }
154
155 ","     {
156            return(SEPARATOR);
157         }
158
159 "{"     {
160            return(FSOPEN);
161         }
162
163 "}"     {
164            return(FSCLOSE);
165         }
166
167 "["     {
168            return(ARRAYOPEN);
169         }
170
171 "]"     {
172            return(ARRAYCLOSE);
173         }
174
175 "("     {
176            return(OPER_parenopen);
177         }
178
179 ")"     {
180            return(OPER_parenclose);
181         }
182
183 "||"    {
184            return(OPER_or);
185         }
186
187 "&&"    {
188            return(OPER_and);
189         }
190
191 "=="|"!="       {
192            if ( strcmp((const char*)yytext, "==") == 0 )
193               yylval.intData = EQUAL;
194            else
195               yylval.intData = NOT_EQUAL;
196
197            return(OPER_equality);
198         }
199
200 "!"     {
201            return(OPER_logicalnegate);
202         }
203
204 "<="|"<"|">="|">"       {
205            if ( strcmp((const char*)yytext, "<=") == 0 )
206               yylval.intData = LESS_OR_EQUAL;
207            else
208            if ( strcmp((const char*)yytext, "<") == 0 )
209               yylval.intData = LESS;
210            else
211            if ( strcmp((const char*)yytext, ">=") == 0 )
212               yylval.intData = GREATER_OR_EQUAL;
213            else
214               yylval.intData = GREATER;
215
216            return(OPER_relational);
217         }
218
219 "GICaseSensitive"       {
220                 return(GI_CASE_SENSITIVE);
221                         }
222
223 [Tt][Rr][Uu][Ee]        {
224                 yylval.boolData = true;
225                 return(BOOLVAL);
226                         }
227
228 [Ff][Aa][Ll][Ss][Ee]    {
229                 yylval.boolData = false;
230                 return(BOOLVAL);
231                         }
232
233 [On][Nn]        {
234                 yylval.boolData = true;
235                 return(BOOLVAL);
236                 }
237
238 [Oo][Ff][Ff]    {
239                 yylval.boolData = false;
240                 return(BOOLVAL);
241                 }
242
243 [0-9]+("."[0-9]+)?{unit}        {
244                 yylval.charPtrData = 
245                   (unsigned char*)strdup((const char*)yytext);
246                 return(DIMENSION);
247                 }
248
249 [0-9]+          {
250                 yylval.intData = atoi((char*)yytext);
251                 return(INTEGER);
252                 }
253
254 [0-9]+"."[0-9]+ {
255                 yylval.realData = atof((char*)yytext);
256                 return(REAL);
257                 }
258
259 \"              {
260                 BEGIN quoted_string;
261                 }
262
263 <quoted_string>\"       {
264
265                 yylval.charPtrData = 
266                         new unsigned char[qstring_buf_content_size+1];
267                 memcpy( yylval.charPtrData, 
268                         qstring_buf, 
269                         qstring_buf_content_size+1
270                       );
271
272                 qstring_buf_content_size = 0;
273                 BEGIN 0;
274
275                 return(QUOTED_STRING);
276                 }
277
278 <quoted_string>\\       {
279                 int c = styleinput();
280                 switch (c) {
281                    case '"':
282                      addToQstringBuf((unsigned char*)"\"", 1);
283                      break;
284                    case '\\':
285                      addToQstringBuf((unsigned char*)"\\", 1);
286                      break;
287                    default:
288                      throw(CASTSSEXCEPT StyleSheetException());
289                 }
290                 }
291
292 <quoted_string>[^\\\"]* {
293                 addToQstringBuf((unsigned char*)yytext, yyleng);
294                 }
295
296 <quoted_string>.        {
297                 addToQstringBuf((unsigned char*)yytext, yyleng);
298                 }
299
300 {unit}          {
301                 yylval.charPtrData = 
302                   (unsigned char*)strdup((const char*)yytext);
303                   return(UNIT_STRING);
304                 }
305
306 [^ \t\n\".=@+*\/\.\*:?\^,{}\[\]()!]+    {
307                 yylval.charPtrData = 
308                   (unsigned char*)strdup((const char*)yytext);
309                 return(NORMAL_STRING);
310                 }
311
312 <sgmlgimode>[0-9a-zA-Z\.\-]+ {
313                 yylval.charPtrData = 
314                   (unsigned char*)strdup((const char*)yytext);
315                 BEGIN 0;
316                 return(SGMLGI_STRING);
317         }
318
319 [\t]    {
320         }
321
322 [\n]    {
323            yylineno++;
324         }
325
326 .       {
327         }
328
329
330
331 <block>"|#"     { BEGIN(0); }
332 <block>.        ;
333 <block>\n       ;
334 %%
335
336 void enter_sgmlgi_context()
337 {
338    BEGIN sgmlgimode;
339 }
340
341
342 void report_error_location()
343 {
344    if ( commentBufferContentSize > 0 ) {
345       cerr << commentBuffer << "\n";
346    }
347 }
348
349 void yyerror(char* msg)
350 {
351 #ifdef DEBUG
352    cerr << "line " << yylineno << ": " << msg << "\n";
353 #endif
354    throw(CASTSSSEEXCEPT StyleSheetSyntaxError());
355 }
356