Add GNU LGPL headers to all .c .C and .h files
[oweals/cde.git] / cde / programs / dtinfo / DtMmdb / StyleSheet / tokenStyle.C
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
6  * These libraries and programs are free software; you can
7  * redistribute them and/or modify them under the terms of the GNU
8  * Lesser General Public License as published by the Free Software
9  * Foundation; either version 2 of the License, or (at your option)
10  * any later version.
11  *
12  * These libraries and programs are distributed in the hope that
13  * they will be useful, but WITHOUT ANY WARRANTY; without even the
14  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  * PURPOSE. See the GNU Lesser General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with these librararies and programs; if not, write
20  * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21  * Floor, Boston, MA 02110-1301 USA
22  */
23 /* A lexical scanner generated by flex */
24
25 /* scanner skeleton version:
26  * $TOG: tokenStyle.C /main/6 1998/04/17 11:52:06 mgreess $
27  */
28
29 #define FLEX_SCANNER
30
31 #include <stdio.h>
32
33
34 /* cfront 1.2 defines "c_plusplus" instead of "__cplusplus" */
35 #ifdef c_plusplus
36 #ifndef __cplusplus
37 #define __cplusplus
38 #endif
39 #endif
40
41
42 #ifdef __cplusplus
43
44 #include <stdlib.h>
45
46 #if !defined(__osf__) && !defined(USL)
47 #include <osfcn.h>
48 #endif
49
50 /* use prototypes in function declarations */
51 #define style_USE_PROTOS
52
53 /* the "const" storage-class-modifier is valid */
54 #define style_USE_CONST
55
56 #else   /* ! __cplusplus */
57
58 #ifdef __STDC__
59
60 #ifdef __GNUC__
61 #include <stddef.h>
62 void *malloc( size_t );
63 void free( void* );
64 #else
65 #include <stdlib.h>
66 #endif  /* __GNUC__ */
67
68 #define style_USE_PROTOS
69 #define style_USE_CONST
70
71 #endif  /* __STDC__ */
72 #endif  /* ! __cplusplus */
73
74
75 #ifdef __TURBOC__
76 #define style_USE_CONST
77 #endif
78
79
80 #ifndef style_USE_CONST
81 #define const
82 #endif
83
84
85 #ifdef style_USE_PROTOS
86 #define style_PROTO(proto) proto
87 #else
88 #define style_PROTO(proto) ()
89 /* we can't get here if it's an ANSI C compiler, or a C++ compiler,
90  * so it's got to be a K&R compiler, and therefore there's no standard
91  * place from which to include these definitions
92  */
93 char *malloc();
94 int free();
95 int read();
96 #endif
97
98
99 /* amount of stuff to slurp up with each read */
100 #ifndef style_READ_BUF_SIZE
101 #define style_READ_BUF_SIZE 8192
102 #endif
103
104 /* returned upon end-of-file */
105 #define style_END_TOK 0
106
107 /* copy whatever the last rule matched to the standard output */
108
109 /* cast to (char *) is because for 8-bit chars, styletext is (unsigned char *) */
110 /* this used to be an fputs(), but since the string might contain NUL's,
111  * we now use fwrite()
112  */
113 #define ECHO (void) fwrite( (char *) styletext, styleleng, 1, styleout )
114
115 /* gets input and stuffs it into "buf".  number of characters read, or style_NULL,
116  * is returned in "result".
117  */
118 #define style_INPUT(buf,result,max_size) \
119         if ( (result = read( fileno(stylein), (char *) buf, max_size )) < 0 ) \
120             style_FATAL_ERROR( "read() in flex scanner failed" );
121 #define style_NULL 0
122
123 /* no semi-colon after return; correct usage is to write "styleterminate();" -
124  * we don't want an extra ';' after the "return" because that will cause
125  * some compilers to complain about unreachable statements.
126  */
127 #define styleterminate() return ( style_NULL )
128
129 /* report a fatal error */
130
131 /* The funky do-while is used to turn this macro definition into
132  * a single C statement (which needs a semi-colon terminator).
133  * This avoids problems with code like:
134  *
135  *      if ( something_happens )
136  *              style_FATAL_ERROR( "oops, the something happened" );
137  *      else
138  *              everything_okay();
139  *
140  * Prior to using the do-while the compiler would get upset at the
141  * "else" because it interpreted the "if" statement as being all
142  * done when it reached the ';' after the style_FATAL_ERROR() call.
143  */
144
145 #define style_FATAL_ERROR(msg) \
146         do \
147                 { \
148                 (void) fputs( msg, stderr ); \
149                 (void) putc( '\n', stderr ); \
150                 exit( 1 ); \
151                 } \
152         while ( 0 )
153
154 /* default stylewrap function - always treat EOF as an EOF */
155 #define stylewrap() 1
156
157 /* enter a start condition.  This macro really ought to take a parameter,
158  * but we do it the disgusting crufty way forced on us by the ()-less
159  * definition of BEGIN
160  */
161 #define BEGIN style_start = 1 + 2 *
162
163 /* action number for EOF rule of a given start state */
164 #define style_STATE_EOF(state) (style_END_OF_BUFFER + state + 1)
165
166 /* special action meaning "start processing a new file" */
167 #define style_NEW_FILE \
168         do \
169                 { \
170                 style_init_buffer( style_current_buffer, stylein ); \
171                 style_load_buffer_state(); \
172                 } \
173         while ( 0 )
174
175 /* default declaration of generated scanner - a define so the user can
176  * easily add parameters
177  */
178 #define style_DECL int stylelex style_PROTO(( void )) 
179
180 /* code executed at the end of each rule */
181 #define style_BREAK break;
182
183 #define style_END_OF_BUFFER_CHAR 0
184
185 #ifndef style_BUF_SIZE
186 #define style_BUF_SIZE (style_READ_BUF_SIZE * 2) /* size of default input buffer */
187 #endif
188
189 typedef struct style_buffer_state *style_BUFFER_STATE;
190
191 #define style_CHAR unsigned char
192 # line 1 "tokenStyle.l"
193 #define INITIAL 0
194 /*
195 * $TOG: tokenStyle.C /main/6 1998/04/17 11:52:06 mgreess $
196 *
197 * Copyright (c) 1993 HAL Computer Systems International, Ltd.
198 * All rights reserved.  Unpublished -- rights reserved under
199 * the Copyright Laws of the United States.  USE OF A COPYRIGHT
200 * NOTICE IS PRECAUTIONARY ONLY AND DOES NOT IMPLY PUBLICATION
201 * OR DISCLOSURE.
202
203 * THIS SOFTWARE CONTAINS CONFIDENTIAL INFORMATION AND TRADE
204 * SECRETS OF HAL COMPUTER SYSTEMS INTERNATIONAL, LTD.  USE,
205 * DISCLOSURE, OR REPRODUCTION IS PROHIBITED WITHOUT THE
206 * PRIOR EXPRESS WRITTEN PERMISSION OF HAL COMPUTER SYSTEMS
207 * INTERNATIONAL, LTD.
208
209 *                         RESTRICTED RIGHTS LEGEND
210 * Use, duplication, or disclosure by the Government is subject
211 * to the restrictions as set forth in subparagraph (c)(l)(ii)
212 * of the Rights in Technical Data and Computer Software clause
213 * at DFARS 252.227-7013.
214 *
215 *          HAL COMPUTER SYSTEMS INTERNATIONAL, LTD.
216 *                  1315 Dell Avenue
217 *                  Campbell, CA  95008
218
219 */
220 # line 37 "tokenStyle.l"
221 #include <string.h>
222 #include "ParserConst.h"
223 #include "Expression.h"
224 #include "FeatureValue.h"
225 #include "PathTable.h"
226 #include "SSPath.h"
227 #include "PathQualifier.h"
228 #include "StyleSheetExceptions.h"
229 #include "style.tab.h"
230 #include "Debug.h"
231 #include <iostream.h>
232
233 istream *g_stylein = 0;
234
235 #undef style_INPUT
236 #define style_INPUT(buf,result,max_size)\
237   {\
238      if (g_stylein -> eof()) {\
239         result=0;\
240      } else {\
241         g_stylein -> read((char*)buf, max_size-1); \
242         result = g_stylein -> gcount(); \
243         buf[result] = 0; \
244      }\
245   }
246
247 unsigned char* qstring_buf = new unsigned char[1024];
248 int qstring_buf_size = 1024;
249 int qstring_buf_content_size = 0;
250
251 char* commentBuffer = new char [1024];
252 int commentBufferSize = 1024;
253 int commentBufferContentSize = 0;
254
255 int stylelineno=1;
256                 
257 void addToQstringBuf(const unsigned char* str, int size)
258 {
259    if ( size <= 0 ) return;
260
261    if ( qstring_buf_size - qstring_buf_content_size < size ) {
262       qstring_buf_size = 2*(size+qstring_buf_content_size);
263       unsigned char* x = new unsigned char[qstring_buf_size];
264       memcpy(x, qstring_buf, qstring_buf_content_size);
265       delete qstring_buf;
266       qstring_buf = x;
267    }
268
269    memcpy(qstring_buf + qstring_buf_content_size, str, size);
270    qstring_buf_content_size += size;
271    qstring_buf[qstring_buf_content_size] = 0;
272 }
273
274
275 #define block 1
276 #define sgmlgimode 2
277 #define quoted_string 3
278 # line 95 "tokenStyle.l"
279
280 /* done after the current pattern has been matched and before the
281  * corresponding action - sets up styletext
282  */
283 #define style_DO_BEFORE_ACTION \
284         styletext = style_bp; \
285         styleleng = style_cp - style_bp; \
286         style_hold_char = *style_cp; \
287         *style_cp = '\0'; \
288         style_c_buf_p = style_cp;
289
290 #define EOB_ACT_CONTINUE_SCAN 0
291 #define EOB_ACT_END_OF_FILE 1
292 #define EOB_ACT_LAST_MATCH 2
293
294 /* return all but the first 'n' matched characters back to the input stream */
295 #define styleless(n) \
296         do \
297                 { \
298                 /* undo effects of setting up styletext */ \
299                 *style_cp = style_hold_char; \
300                 style_c_buf_p = style_cp = style_bp + n; \
301                 style_DO_BEFORE_ACTION; /* set up styletext again */ \
302                 } \
303         while ( 0 )
304
305 #define unput(c) styleunput( c, styletext )
306
307
308 struct style_buffer_state
309     {
310     FILE *style_input_file;
311
312     style_CHAR *style_ch_buf;           /* input buffer */
313     style_CHAR *style_buf_pos;  /* current position in input buffer */
314
315     /* size of input buffer in bytes, not including room for EOB characters*/
316     int style_buf_size; 
317
318     /* number of characters read into style_ch_buf, not including EOB characters */
319     int style_n_chars;
320
321     int style_eof_status;               /* whether we've seen an EOF on this buffer */
322 #define EOF_NOT_SEEN 0
323     /* "pending" happens when the EOF has been seen but there's still
324      * some text process
325      */
326 #define EOF_PENDING 1
327 #define EOF_DONE 2
328     };
329
330 static style_BUFFER_STATE style_current_buffer;
331
332 /* we provide macros for accessing buffer states in case in the
333  * future we want to put the buffer states in a more general
334  * "scanner state"
335  */
336 #define style_CURRENT_BUFFER style_current_buffer
337
338
339 /* style_hold_char holds the character lost when styletext is formed */
340 static style_CHAR style_hold_char;
341
342 static int style_n_chars;               /* number of characters read into style_ch_buf */
343
344
345
346 #ifndef style_USER_ACTION
347 #define style_USER_ACTION
348 #endif
349
350 #ifndef style_USER_INIT
351 #define style_USER_INIT
352 #endif
353
354 extern style_CHAR *styletext;
355 extern int styleleng;
356 extern FILE *stylein, *styleout;
357
358 style_CHAR *styletext;
359 int styleleng;
360
361 FILE *stylein = (FILE *) 0, *styleout = (FILE *) 0;
362
363 #define style_END_OF_BUFFER 48
364 typedef int style_state_type;
365 static const short int style_accept[134] =
366     {   0,
367         0,    0,    0,    0,    0,    0,   36,   36,   48,   39,
368        41,   42,   43,   23,   33,   39,   39,   18,   19,    9,
369         5,   13,    6,    8,    7,   31,   10,   24,    3,   24,
370        11,    4,   39,   39,   39,   39,   39,   39,   39,   16,
371        17,   12,   39,   39,   14,   39,   15,    2,   45,   46,
372        45,   47,   40,   36,   36,   34,   35,   39,   22,    1,
373        21,    0,   31,   39,   39,   39,   24,   38,   39,   39,
374        38,   39,   28,   39,   39,   39,   20,    2,    2,    1,
375        44,   40,   36,   32,   30,   30,   39,   39,   39,   39,
376        39,   29,   39,   39,   39,   39,    0,    0,    0,   39,
377
378        39,   39,   39,   39,   39,   39,   39,   26,   30,   30,
379         0,    0,   39,   39,   27,   39,    0,    0,    0,    0,
380        39,    0,    0,   39,   39,   39,   39,   39,   39,   39,
381        39,   25,    0
382     } ;
383
384 static const style_CHAR style_ec[256] =
385     {   0,
386         1,    1,    1,    1,    1,    1,    1,    1,    2,    3,
387         1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
388         1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
389         1,    4,    5,    6,    7,    1,    1,    8,    1,    9,
390        10,   11,   12,   13,   14,   15,   16,   17,   17,   17,
391        17,   17,   17,   17,   17,   17,   17,   18,    1,   19,
392        20,   21,   22,   23,   24,   25,   26,   25,   27,   28,
393        29,   30,   31,   25,   25,   32,   33,   34,   35,   36,
394        25,   37,   38,   39,   40,   25,   25,   41,   25,   25,
395        42,   43,   44,   45,    1,    1,   46,   25,   47,   25,
396
397        48,   28,   25,   30,   49,   25,   25,   32,   33,   50,
398        51,   36,   25,   37,   52,   53,   40,   54,   25,   41,
399        25,   25,   55,   56,   57,    1,    1,    1,    1,    1,
400         1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
401         1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
402         1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
403         1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
404         1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
405         1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
406         1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
407
408         1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
409         1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
410         1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
411         1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
412         1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
413         1,    1,    1,    1,    1
414     } ;
415
416 static const style_CHAR style_meta[58] =
417     {   0,
418         1,    2,    3,    2,    2,    4,    1,    1,    2,    2,
419         2,    2,    2,    5,    6,    2,    5,    2,    1,    2,
420         1,    2,    2,    5,    5,    5,    5,    5,    5,    5,
421         5,    5,    5,    5,    5,    5,    5,    5,    5,    5,
422         5,    2,    7,    2,    2,    5,    5,    5,    5,    5,
423         5,    5,    5,    5,    2,    1,    2
424     } ;
425
426 static const short int style_base[141] =
427     {   0,
428         0,  341,   55,   56,  112,    0,   57,   58,  347,    0,
429       349,  349,  349,  326,  349,  289,  336,  349,  349,  349,
430       349,  349,    0,  349,  349,   50,  349,  323,  322,  321,
431       349,  349,  303,   38,  300,   32,   40,   57,  284,  349,
432       349,  349,   35,  289,  349,  259,  349,  168,  349,  349,
433       307,  349,    0,    0,    0,  349,  349,    0,  349,    0,
434         0,  296,  170,  262,   37,  169,  349,    0,  262,  267,
435        44,  264,    0,  156,   44,  251,    0,  224,    0,    0,
436       349,    0,    0,  224,    0,   47,  168,   46,   51,  244,
437       259,    0,   56,  144,  155,  166,  255,  177,  223,  257,
438
439       152,  204,  198,  211,  234,  253,  168,    0,  349,  217,
440       237,  226,  250,  212,    0,  213,  223,  221,  229,  246,
441       164,  167,  244,  127,   59,   55,   56,   45,   30,   24,
442        24,    0,  349,  297,  304,  311,  318,  321,  327,  333
443     } ;
444
445 static const short int style_def[141] =
446     {   0,
447       133,    1,  134,  134,  133,    5,  135,  135,  133,  136,
448       133,  133,  133,  133,  133,  136,  136,  133,  133,  133,
449       133,  133,  136,  133,  133,  136,  133,  136,  133,  136,
450       133,  133,  136,  136,  136,  136,  136,  136,  136,  133,
451       133,  133,  136,  136,  133,  136,  133,  137,  133,  133,
452       133,  133,  138,  139,  139,  133,  133,  136,  133,  136,
453       136,  133,  136,  136,  136,  136,  133,  136,  136,  136,
454       136,  136,  136,  136,  136,  136,  136,  137,  140,   78,
455       133,  138,  139,  133,  136,  136,  136,  136,  136,  136,
456       136,  136,  136,  136,  136,  136,  133,  133,  133,  136,
457
458       136,  136,  136,  136,  136,  136,  136,  136,  133,  133,
459       133,  133,  136,  136,  136,  136,  133,  133,  133,  133,
460       136,  133,  133,  136,  136,  136,  136,  136,  136,  136,
461       136,  136,    0,  133,  133,  133,  133,  133,  133,  133
462     } ;
463
464 static const short int style_nxt[407] =
465     {   0,
466        10,   11,   12,   13,   14,   15,   16,   17,   18,   19,
467        20,   21,   22,   23,   24,   25,   26,   27,   28,   29,
468        30,   31,   32,   10,   10,   33,   10,   34,   35,   10,
469        36,   10,   10,   10,   37,   38,   10,   10,   39,   10,
470        10,   40,   10,   41,   42,   10,   33,   10,   36,   43,
471        44,   10,   39,   10,   45,   46,   47,   50,   50,   55,
472        55,   69,   56,   56,   62,   71,   63,   72,   73,   91,
473        86,  132,  100,   73,   95,   64,  103,  131,  130,   68,
474        65,   71,   68,   69,   73,   66,   86,   74,  104,   73,
475        91,   75,   95,  100,  103,   68,   64,  129,   65,   57,
476
477        57,   68,  104,   68,  128,   74,  127,   75,  126,   68,
478        51,   51,   52,   52,   52,   52,   52,   52,   52,   52,
479        52,   52,   52,   52,   52,   53,   53,   52,   53,   52,
480        52,   52,   52,   52,   52,   53,   53,   53,   53,   53,
481        53,   53,   53,   53,   53,   53,   53,   53,   53,   53,
482        53,   53,   53,   52,   52,   52,   52,   53,   53,   53,
483        53,   53,   53,   53,   53,   53,   52,   52,   52,   79,
484       106,   79,   79,   79,  125,   85,   79,   79,   79,   79,
485        79,   93,   79,   79,   62,   79,   63,   79,  107,   79,
486        79,  106,  108,  101,   85,   64,   94,   85,  109,   87,
487
488        65,  124,   93,   88,  107,   66,   68,   85,  102,   79,
489       110,   79,   79,  108,  101,   85,   64,   87,   65,   88,
490        68,   85,   79,   80,   79,   79,  110,   79,   79,   79,
491       113,  114,   79,   79,   79,   79,   79,  115,   79,   79,
492        84,   79,  117,   79,  109,   79,   79,  114,  109,   97,
493        85,  113,  109,  111,   98,  122,  120,  112,  115,   99,
494       121,  109,  118,  117,   85,   79,  109,   79,   79,  109,
495        97,  111,   98,  112,  120,  109,  122,  119,   79,  123,
496        79,   85,  109,  118,   68,  116,   85,  109,   68,  105,
497        96,   92,   90,   89,   85,  123,  109,   49,   49,   49,
498
499        49,   49,   49,   49,   54,   54,   54,   54,   54,   54,
500        54,   58,   84,   81,   77,   58,   72,   58,   78,   78,
501        76,   78,   78,   78,   78,   82,   82,   83,   83,   83,
502        70,   83,   83,   79,   79,   68,   79,   79,   79,   79,
503        67,   59,   67,   61,   60,   59,  133,   48,    9,  133,
504       133,  133,  133,  133,  133,  133,  133,  133,  133,  133,
505       133,  133,  133,  133,  133,  133,  133,  133,  133,  133,
506       133,  133,  133,  133,  133,  133,  133,  133,  133,  133,
507       133,  133,  133,  133,  133,  133,  133,  133,  133,  133,
508       133,  133,  133,  133,  133,  133,  133,  133,  133,  133,
509
510       133,  133,  133,  133,  133,  133
511     } ;
512
513 static const short int style_chk[407] =
514     {   0,
515         1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
516         1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
517         1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
518         1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
519         1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
520         1,    1,    1,    1,    1,    1,    1,    3,    4,    7,
521         8,   34,    7,    8,   26,   36,   26,   37,   43,   71,
522        65,  131,   86,   37,   75,   26,   88,  130,  129,   93,
523        26,   36,   38,   34,   43,   26,   65,   38,   89,   37,
524        71,   38,   75,   86,   88,   38,   26,  128,   26,    7,
525
526         8,   93,   89,   38,  127,   38,  126,   38,  125,   38,
527         3,    4,    5,    5,    5,    5,    5,    5,    5,    5,
528         5,    5,    5,    5,    5,    5,    5,    5,    5,    5,
529         5,    5,    5,    5,    5,    5,    5,    5,    5,    5,
530         5,    5,    5,    5,    5,    5,    5,    5,    5,    5,
531         5,    5,    5,    5,    5,    5,    5,    5,    5,    5,
532         5,    5,    5,    5,    5,    5,    5,    5,    5,   48,
533        94,   48,   48,   48,  124,  101,   48,   48,   48,   48,
534        48,   74,   48,   48,   63,   48,   63,   48,   95,   48,
535        48,   94,   96,   87,   66,   63,   74,  101,  122,   66,
536
537        63,  121,   74,   66,   95,   63,  107,   66,   87,   48,
538        98,   48,   48,   96,   87,   66,   63,   66,   63,   66,
539       107,   66,   48,   48,   48,   78,   98,   78,   78,   78,
540       102,  103,   78,   78,   78,   78,   78,  104,   78,   78,
541        84,   78,  110,   78,  118,   78,   78,  103,   99,   84,
542       114,  102,  117,   99,   84,  119,  112,   99,  104,   84,
543       116,   99,  111,  110,  114,   78,  118,   78,   78,   99,
544        84,   99,   84,   99,  112,   99,  119,  111,   78,  120,
545        78,  113,  123,  111,  106,  105,  100,   97,   91,   90,
546        76,   72,   70,   69,   64,  120,  123,  134,  134,  134,
547
548       134,  134,  134,  134,  135,  135,  135,  135,  135,  135,
549       135,  136,   62,   51,   46,  136,   44,  136,  137,  137,
550        39,  137,  137,  137,  137,  138,  138,  139,  139,  139,
551        35,  139,  139,  140,  140,   33,  140,  140,  140,  140,
552        30,   29,   28,   17,   16,   14,    9,    2,  133,  133,
553       133,  133,  133,  133,  133,  133,  133,  133,  133,  133,
554       133,  133,  133,  133,  133,  133,  133,  133,  133,  133,
555       133,  133,  133,  133,  133,  133,  133,  133,  133,  133,
556       133,  133,  133,  133,  133,  133,  133,  133,  133,  133,
557       133,  133,  133,  133,  133,  133,  133,  133,  133,  133,
558
559       133,  133,  133,  133,  133,  133
560     } ;
561
562 static style_state_type style_last_accepting_state;
563 static style_CHAR *style_last_accepting_cpos;
564
565 /* the intent behind this definition is that it'll catch
566  * any uses of REJECT which flex missed
567  */
568 #define REJECT reject_used_but_not_detected
569 #define stylemore() stylemore_used_but_not_detected
570 #define style_MORE_ADJ 0
571
572 /* these variables are all declared out here so that section 3 code can
573  * manipulate them
574  */
575 /* points to current character in buffer */
576 static style_CHAR *style_c_buf_p = (style_CHAR *) 0;
577 static int style_init = 1;              /* whether we need to initialize */
578 static int style_start = 0;     /* start state number */
579
580 /* flag which is used to allow stylewrap()'s to do buffer switches
581  * instead of setting up a fresh stylein.  A bit of a hack ...
582  */
583 static int style_did_buffer_switch_on_eof;
584
585 static style_state_type style_get_previous_state style_PROTO(( void ));
586 static style_state_type style_try_NUL_trans style_PROTO(( style_state_type current_state ));
587 static int style_get_next_buffer style_PROTO(( void ));
588 static void styleunput style_PROTO(( style_CHAR c, style_CHAR *buf_ptr ));
589 void stylerestart style_PROTO(( FILE *input_file ));
590 void style_switch_to_buffer style_PROTO(( style_BUFFER_STATE new_buffer ));
591 void style_load_buffer_state style_PROTO(( void ));
592 style_BUFFER_STATE style_create_buffer style_PROTO(( FILE *file, int size ));
593 void style_delete_buffer style_PROTO(( style_BUFFER_STATE b ));
594 void style_init_buffer style_PROTO(( style_BUFFER_STATE b, FILE *file ));
595
596 #define style_new_buffer style_create_buffer
597
598 #ifdef __cplusplus
599 static int styleinput style_PROTO(( void ));
600 #else
601 static int input style_PROTO(( void ));
602 #endif
603
604 style_DECL
605     {
606     register style_state_type style_current_state;
607     register style_CHAR *style_cp, *style_bp;
608     register int style_act;
609
610
611
612
613     if ( style_init )
614         {
615         style_USER_INIT;
616
617         if ( ! style_start )
618             style_start = 1;    /* first start state */
619
620         if ( ! stylein )
621             stylein = stdin;
622
623         if ( ! styleout )
624             styleout = stdout;
625
626         if ( style_current_buffer )
627             style_init_buffer( style_current_buffer, stylein );
628         else
629             style_current_buffer = style_create_buffer( stylein, style_BUF_SIZE );
630
631         style_load_buffer_state();
632
633         style_init = 0;
634         }
635
636     while ( 1 )         /* loops until end-of-file is reached */
637         {
638         style_cp = style_c_buf_p;
639
640         /* support of styletext */
641         *style_cp = style_hold_char;
642
643         /* style_bp points to the position in style_ch_buf of the start of the
644          * current run.
645          */
646         style_bp = style_cp;
647
648         style_current_state = style_start;
649         if ( style_bp[-1] == '\n' )
650             ++style_current_state;
651 style_match:
652         do
653             {
654             register style_CHAR style_c = style_ec[*style_cp];
655             if ( style_accept[style_current_state] )
656                 {
657                 style_last_accepting_state = style_current_state;
658                 style_last_accepting_cpos = style_cp;
659                 }
660             while ( style_chk[style_base[style_current_state] + style_c] != style_current_state )
661                 {
662                 style_current_state = style_def[style_current_state];
663                 if ( style_current_state >= 134 )
664                     style_c = style_meta[style_c];
665                 }
666             style_current_state = style_nxt[style_base[style_current_state] + style_c];
667             ++style_cp;
668             }
669         while ( style_current_state != 133 );
670         style_cp = style_last_accepting_cpos;
671         style_current_state = style_last_accepting_state;
672
673 style_find_action:
674         style_act = style_accept[style_current_state];
675
676         style_DO_BEFORE_ACTION;
677         style_USER_ACTION;
678
679 do_action:      /* this label is used only to access EOF actions */
680
681
682         switch ( style_act )
683             {
684             case 0: /* must backtrack */
685             /* undo the effects of style_DO_BEFORE_ACTION */
686             *style_cp = style_hold_char;
687             style_cp = style_last_accepting_cpos;
688             style_current_state = style_last_accepting_state;
689             goto style_find_action;
690
691 case 1:
692 # line 97 "tokenStyle.l"
693 BEGIN(block);
694         style_BREAK
695 case 2:
696 # line 99 "tokenStyle.l"
697 {
698            if ( commentBufferSize < styleleng ) {
699               delete commentBuffer;
700               commentBufferSize = 2 * styleleng ;
701               commentBuffer = new char [commentBufferSize];
702            } 
703
704            commentBufferContentSize = styleleng-1;
705            memcpy(commentBuffer, styletext+1, commentBufferContentSize); // copy everything except the #
706            commentBuffer[commentBufferContentSize] = 0;
707         }
708         style_BREAK
709 case 3:
710 # line 111 "tokenStyle.l"
711 {
712            return(OPER_assign);
713         }
714         style_BREAK
715 case 4:
716 # line 115 "tokenStyle.l"
717 {
718            return(OPER_attr);
719         }
720         style_BREAK
721 case 5:
722 # line 119 "tokenStyle.l"
723 {
724            stylelval.charData = styletext[0];
725            return(OPER_plus);
726         }
727         style_BREAK
728 case 6:
729 # line 124 "tokenStyle.l"
730 {
731            stylelval.charData = styletext[0];
732            return(OPER_minus);
733         }
734         style_BREAK
735 case 7:
736 # line 129 "tokenStyle.l"
737 {
738            stylelval.charData = styletext[0];
739            return(OPER_div);
740         }
741         style_BREAK
742 case 8:
743 # line 134 "tokenStyle.l"
744 {
745            return(OPER_period);
746         }
747         style_BREAK
748 case 9:
749 # line 138 "tokenStyle.l"
750 {
751            stylelval.charData = styletext[0];
752            return(OPER_star);
753         }
754         style_BREAK
755 case 10:
756 # line 143 "tokenStyle.l"
757 {
758            return(OPER_modify);
759         }
760         style_BREAK
761 case 11:
762 # line 147 "tokenStyle.l"
763 {
764            return(OPER_oneof);
765         }
766         style_BREAK
767 case 12:
768 # line 151 "tokenStyle.l"
769 {
770            return(OPER_parent);
771         }
772         style_BREAK
773 case 13:
774 # line 155 "tokenStyle.l"
775 {
776            return(SEPARATOR);
777         }
778         style_BREAK
779 case 14:
780 # line 159 "tokenStyle.l"
781 {
782            return(FSOPEN);
783         }
784         style_BREAK
785 case 15:
786 # line 163 "tokenStyle.l"
787 {
788            return(FSCLOSE);
789         }
790         style_BREAK
791 case 16:
792 # line 167 "tokenStyle.l"
793 {
794            return(ARRAYOPEN);
795         }
796         style_BREAK
797 case 17:
798 # line 171 "tokenStyle.l"
799 {
800            return(ARRAYCLOSE);
801         }
802         style_BREAK
803 case 18:
804 # line 175 "tokenStyle.l"
805 {
806            return(OPER_parenopen);
807         }
808         style_BREAK
809 case 19:
810 # line 179 "tokenStyle.l"
811 {
812            return(OPER_parenclose);
813         }
814         style_BREAK
815 case 20:
816 # line 183 "tokenStyle.l"
817 {
818            return(OPER_or);
819         }
820         style_BREAK
821 case 21:
822 # line 187 "tokenStyle.l"
823 {
824            return(OPER_and);
825         }
826         style_BREAK
827 case 22:
828 # line 191 "tokenStyle.l"
829 {
830            if ( strcmp((const char*)styletext, "==") == 0 )
831               stylelval.intData = EQUAL;
832            else
833               stylelval.intData = NOT_EQUAL;
834
835            return(OPER_equality);
836         }
837         style_BREAK
838 case 23:
839 # line 200 "tokenStyle.l"
840 {
841            return(OPER_logicalnegate);
842         }
843         style_BREAK
844 case 24:
845 # line 204 "tokenStyle.l"
846 {
847            if ( strcmp((const char*)styletext, "<=") == 0 )
848               stylelval.intData = LESS_OR_EQUAL;
849            else
850            if ( strcmp((const char*)styletext, "<") == 0 )
851               stylelval.intData = LESS;
852            else
853            if ( strcmp((const char*)styletext, ">=") == 0 )
854               stylelval.intData = GREATER_OR_EQUAL;
855            else
856               stylelval.intData = GREATER;
857
858            return(OPER_relational);
859         }
860         style_BREAK
861 case 25:
862 # line 219 "tokenStyle.l"
863 {
864                 return(GI_CASE_SENSITIVE);
865                         }
866         style_BREAK
867 case 26:
868 # line 223 "tokenStyle.l"
869 {
870                 stylelval.boolData = true;
871                 return(BOOLVAL);
872                         }
873         style_BREAK
874 case 27:
875 # line 228 "tokenStyle.l"
876 {
877                 stylelval.boolData = false;
878                 return(BOOLVAL);
879                         }
880         style_BREAK
881 case 28:
882 # line 233 "tokenStyle.l"
883 {
884                 stylelval.boolData = true;
885                 return(BOOLVAL);
886                 }
887         style_BREAK
888 case 29:
889 # line 238 "tokenStyle.l"
890 {
891                 stylelval.boolData = false;
892                 return(BOOLVAL);
893                 }
894         style_BREAK
895 case 30:
896 # line 243 "tokenStyle.l"
897 {
898                 stylelval.charPtrData = 
899                   (unsigned char*)strdup((const char*)styletext);
900                 return(DIMENSION);
901                 }
902         style_BREAK
903 case 31:
904 # line 249 "tokenStyle.l"
905 {
906                 stylelval.intData = atoi((char*)styletext);
907                 return(INTEGER);
908                 }
909         style_BREAK
910 case 32:
911 # line 254 "tokenStyle.l"
912 {
913                 stylelval.realData = atof((char*)styletext);
914                 return(REAL);
915                 }
916         style_BREAK
917 case 33:
918 # line 259 "tokenStyle.l"
919 {
920                 BEGIN quoted_string;
921                 }
922         style_BREAK
923 case 34:
924 # line 263 "tokenStyle.l"
925 {
926
927                 stylelval.charPtrData = 
928                         new unsigned char[qstring_buf_content_size+1];
929                 memcpy( stylelval.charPtrData, 
930                         qstring_buf, 
931                         qstring_buf_content_size+1
932                       );
933
934                 qstring_buf_content_size = 0;
935                 BEGIN 0;
936
937                 return(QUOTED_STRING);
938                 }
939         style_BREAK
940 case 35:
941 # line 278 "tokenStyle.l"
942 {
943                 int c = styleinput();
944                 switch (c) {
945                    case '"':
946                      addToQstringBuf((unsigned char*)"\"", 1);
947                      break;
948                    case '\\':
949                      addToQstringBuf((unsigned char*)"\\", 1);
950                      break;
951                    default:
952                      throw(CASTSSEXCEPT StyleSheetException());
953                 }
954                 }
955         style_BREAK
956 case 36:
957 # line 292 "tokenStyle.l"
958 {
959                 addToQstringBuf((const unsigned char *)styletext, styleleng);
960                 }
961         style_BREAK
962 case 37:
963 # line 296 "tokenStyle.l"
964 {
965                 addToQstringBuf((const unsigned char *)styletext, styleleng);
966                 }
967         style_BREAK
968 case 38:
969 # line 300 "tokenStyle.l"
970 {
971                 stylelval.charPtrData = 
972                   (unsigned char*)strdup((const char*)styletext);
973                   return(UNIT_STRING);
974                 }
975         style_BREAK
976 case 39:
977 # line 306 "tokenStyle.l"
978 {
979                 stylelval.charPtrData = 
980                   (unsigned char*)strdup((const char*)styletext);
981                 return(NORMAL_STRING);
982                 }
983         style_BREAK
984 case 40:
985 # line 312 "tokenStyle.l"
986 {
987                 stylelval.charPtrData = 
988                   (unsigned char*)strdup((const char*)styletext);
989                 BEGIN 0;
990                 return(SGMLGI_STRING);
991         }
992         style_BREAK
993 case 41:
994 # line 319 "tokenStyle.l"
995 {
996         }
997         style_BREAK
998 case 42:
999 # line 322 "tokenStyle.l"
1000 {
1001            stylelineno++;
1002         }
1003         style_BREAK
1004 case 43:
1005 # line 326 "tokenStyle.l"
1006 {
1007         }
1008         style_BREAK
1009 case 44:
1010 # line 331 "tokenStyle.l"
1011 { BEGIN(0); }
1012         style_BREAK
1013 case 45:
1014 # line 332 "tokenStyle.l"
1015 ;
1016         style_BREAK
1017 case 46:
1018 # line 333 "tokenStyle.l"
1019 ;
1020         style_BREAK
1021 case 47:
1022 # line 334 "tokenStyle.l"
1023 style_FATAL_ERROR( "flex scanner jammed" );
1024         style_BREAK
1025 case style_STATE_EOF(INITIAL):
1026 case style_STATE_EOF(block):
1027 case style_STATE_EOF(sgmlgimode):
1028 case style_STATE_EOF(quoted_string):
1029     styleterminate();
1030
1031             case style_END_OF_BUFFER:
1032                 {
1033                 /* amount of text matched not including the EOB char */
1034                 int style_amount_of_matched_text = style_cp - styletext - 1;
1035
1036                 /* undo the effects of style_DO_BEFORE_ACTION */
1037                 *style_cp = style_hold_char;
1038
1039                 /* note that here we test for style_c_buf_p "<=" to the position
1040                  * of the first EOB in the buffer, since style_c_buf_p will
1041                  * already have been incremented past the NUL character
1042                  * (since all states make transitions on EOB to the end-
1043                  * of-buffer state).  Contrast this with the test in styleinput().
1044                  */
1045                 if ( style_c_buf_p <= &style_current_buffer->style_ch_buf[style_n_chars] )
1046                     /* this was really a NUL */
1047                     {
1048                     style_state_type style_next_state;
1049
1050                     style_c_buf_p = styletext + style_amount_of_matched_text;
1051
1052                     style_current_state = style_get_previous_state();
1053
1054                     /* okay, we're now positioned to make the
1055                      * NUL transition.  We couldn't have
1056                      * style_get_previous_state() go ahead and do it
1057                      * for us because it doesn't know how to deal
1058                      * with the possibility of jamming (and we
1059                      * don't want to build jamming into it because
1060                      * then it will run more slowly)
1061                      */
1062
1063                     style_next_state = style_try_NUL_trans( style_current_state );
1064
1065                     style_bp = styletext + style_MORE_ADJ;
1066
1067                     if ( style_next_state )
1068                         {
1069                         /* consume the NUL */
1070                         style_cp = ++style_c_buf_p;
1071                         style_current_state = style_next_state;
1072                         goto style_match;
1073                         }
1074
1075                     else
1076                         {
1077                             style_cp = style_last_accepting_cpos;
1078                             style_current_state = style_last_accepting_state;
1079                         goto style_find_action;
1080                         }
1081                     }
1082
1083                 else switch ( style_get_next_buffer() )
1084                     {
1085                     case EOB_ACT_END_OF_FILE:
1086                         {
1087                         style_did_buffer_switch_on_eof = 0;
1088
1089                         if ( stylewrap() )
1090                             {
1091                             /* note: because we've taken care in
1092                              * style_get_next_buffer() to have set up styletext,
1093                              * we can now set up style_c_buf_p so that if some
1094                              * total hoser (like flex itself) wants
1095                              * to call the scanner after we return the
1096                              * style_NULL, it'll still work - another style_NULL
1097                              * will get returned.
1098                              */
1099                             style_c_buf_p = styletext + style_MORE_ADJ;
1100
1101                             style_act = style_STATE_EOF((style_start - 1) / 2);
1102                             goto do_action;
1103                             }
1104
1105                         else
1106                             {
1107                             if ( ! style_did_buffer_switch_on_eof )
1108                                 style_NEW_FILE;
1109                             }
1110                         }
1111                         break;
1112
1113                     case EOB_ACT_CONTINUE_SCAN:
1114                         style_c_buf_p = styletext + style_amount_of_matched_text;
1115
1116                         style_current_state = style_get_previous_state();
1117
1118                         style_cp = style_c_buf_p;
1119                         style_bp = styletext + style_MORE_ADJ;
1120                         goto style_match;
1121
1122                     case EOB_ACT_LAST_MATCH:
1123                         style_c_buf_p =
1124                             &style_current_buffer->style_ch_buf[style_n_chars];
1125
1126                         style_current_state = style_get_previous_state();
1127
1128                         style_cp = style_c_buf_p;
1129                         style_bp = styletext + style_MORE_ADJ;
1130                         goto style_find_action;
1131                     }
1132                 break;
1133                 }
1134
1135             default:
1136 #ifdef FLEX_DEBUG
1137                 printf( "action # %d\n", style_act );
1138 #endif
1139                 style_FATAL_ERROR(
1140                         "fatal flex scanner internal error--no action found" );
1141             }
1142         }
1143     }
1144
1145
1146 /* style_get_next_buffer - try to read in a new buffer
1147  *
1148  * synopsis
1149  *     int style_get_next_buffer();
1150  *     
1151  * returns a code representing an action
1152  *     EOB_ACT_LAST_MATCH - 
1153  *     EOB_ACT_CONTINUE_SCAN - continue scanning from current position
1154  *     EOB_ACT_END_OF_FILE - end of file
1155  */
1156
1157 static int style_get_next_buffer()
1158
1159     {
1160     register style_CHAR *dest = style_current_buffer->style_ch_buf;
1161     register style_CHAR *source = styletext - 1; /* copy prev. char, too */
1162     register int number_to_move, i;
1163     int ret_val;
1164
1165     if ( style_c_buf_p > &style_current_buffer->style_ch_buf[style_n_chars + 1] )
1166         style_FATAL_ERROR(
1167                 "fatal flex scanner internal error--end of buffer missed" );
1168
1169     /* try to read more data */
1170
1171     /* first move last chars to start of buffer */
1172     number_to_move = style_c_buf_p - styletext;
1173
1174     for ( i = 0; i < number_to_move; ++i )
1175         *(dest++) = *(source++);
1176
1177     if ( style_current_buffer->style_eof_status != EOF_NOT_SEEN )
1178         /* don't do the read, it's not guaranteed to return an EOF,
1179          * just force an EOF
1180          */
1181         style_n_chars = 0;
1182
1183     else
1184         {
1185         int num_to_read = style_current_buffer->style_buf_size - number_to_move - 1;
1186
1187         if ( num_to_read > style_READ_BUF_SIZE )
1188             num_to_read = style_READ_BUF_SIZE;
1189
1190         else if ( num_to_read <= 0 )
1191             style_FATAL_ERROR( "fatal error - scanner input buffer overflow" );
1192
1193         /* read in more data */
1194         style_INPUT( (&style_current_buffer->style_ch_buf[number_to_move]),
1195                   style_n_chars, num_to_read );
1196         }
1197
1198     if ( style_n_chars == 0 )
1199         {
1200         if ( number_to_move == 1 )
1201             {
1202             ret_val = EOB_ACT_END_OF_FILE;
1203             style_current_buffer->style_eof_status = EOF_DONE;
1204             }
1205
1206         else
1207             {
1208             ret_val = EOB_ACT_LAST_MATCH;
1209             style_current_buffer->style_eof_status = EOF_PENDING;
1210             }
1211         }
1212
1213     else
1214         ret_val = EOB_ACT_CONTINUE_SCAN;
1215
1216     style_n_chars += number_to_move;
1217     style_current_buffer->style_ch_buf[style_n_chars] = style_END_OF_BUFFER_CHAR;
1218     style_current_buffer->style_ch_buf[style_n_chars + 1] = style_END_OF_BUFFER_CHAR;
1219
1220     /* styletext begins at the second character in style_ch_buf; the first
1221      * character is the one which preceded it before reading in the latest
1222      * buffer; it needs to be kept around in case it's a newline, so
1223      * style_get_previous_state() will have with '^' rules active
1224      */
1225
1226     styletext = &style_current_buffer->style_ch_buf[1];
1227
1228     return ( ret_val );
1229     }
1230
1231
1232 /* style_get_previous_state - get the state just before the EOB char was reached
1233  *
1234  * synopsis
1235  *     style_state_type style_get_previous_state();
1236  */
1237
1238 static style_state_type style_get_previous_state()
1239
1240     {
1241     register style_state_type style_current_state;
1242     register style_CHAR *style_cp;
1243
1244     register style_CHAR *style_bp = styletext;
1245
1246     style_current_state = style_start;
1247     if ( style_bp[-1] == '\n' )
1248         ++style_current_state;
1249
1250     for ( style_cp = styletext + style_MORE_ADJ; style_cp < style_c_buf_p; ++style_cp )
1251         {
1252         register style_CHAR style_c = (*style_cp ? style_ec[*style_cp] : 1);
1253         if ( style_accept[style_current_state] )
1254             {
1255             style_last_accepting_state = style_current_state;
1256             style_last_accepting_cpos = style_cp;
1257             }
1258         while ( style_chk[style_base[style_current_state] + style_c] != style_current_state )
1259             {
1260             style_current_state = style_def[style_current_state];
1261             if ( style_current_state >= 134 )
1262                 style_c = style_meta[style_c];
1263             }
1264         style_current_state = style_nxt[style_base[style_current_state] + style_c];
1265         }
1266
1267     return ( style_current_state );
1268     }
1269
1270
1271 /* style_try_NUL_trans - try to make a transition on the NUL character
1272  *
1273  * synopsis
1274  *     next_state = style_try_NUL_trans( current_state );
1275  */
1276
1277 #ifdef style_USE_PROTOS
1278 static style_state_type style_try_NUL_trans( register style_state_type style_current_state )
1279 #else
1280 static style_state_type style_try_NUL_trans( style_current_state )
1281 register style_state_type style_current_state;
1282 #endif
1283
1284     {
1285     register int style_is_jam;
1286     register style_CHAR *style_cp = style_c_buf_p;
1287
1288     register style_CHAR style_c = 1;
1289     if ( style_accept[style_current_state] )
1290         {
1291         style_last_accepting_state = style_current_state;
1292         style_last_accepting_cpos = style_cp;
1293         }
1294     while ( style_chk[style_base[style_current_state] + style_c] != style_current_state )
1295         {
1296         style_current_state = style_def[style_current_state];
1297         if ( style_current_state >= 134 )
1298             style_c = style_meta[style_c];
1299         }
1300     style_current_state = style_nxt[style_base[style_current_state] + style_c];
1301     style_is_jam = (style_current_state == 133);
1302
1303     return ( style_is_jam ? 0 : style_current_state );
1304     }
1305
1306
1307 #ifdef style_USE_PROTOS
1308 static void styleunput( style_CHAR c, register style_CHAR *style_bp )
1309 #else
1310 static void styleunput( c, style_bp )
1311 style_CHAR c;
1312 register style_CHAR *style_bp;
1313 #endif
1314
1315     {
1316     register style_CHAR *style_cp = style_c_buf_p;
1317
1318     /* undo effects of setting up styletext */
1319     *style_cp = style_hold_char;
1320
1321     if ( style_cp < style_current_buffer->style_ch_buf + 2 )
1322         { /* need to shift things up to make room */
1323         register int number_to_move = style_n_chars + 2; /* +2 for EOB chars */
1324         register style_CHAR *dest =
1325             &style_current_buffer->style_ch_buf[style_current_buffer->style_buf_size + 2];
1326         register style_CHAR *source =
1327             &style_current_buffer->style_ch_buf[number_to_move];
1328
1329         while ( source > style_current_buffer->style_ch_buf )
1330             *--dest = *--source;
1331
1332         style_cp += dest - source;
1333         style_bp += dest - source;
1334         style_n_chars = style_current_buffer->style_buf_size;
1335
1336         if ( style_cp < style_current_buffer->style_ch_buf + 2 )
1337             style_FATAL_ERROR( "flex scanner push-back overflow" );
1338         }
1339
1340     if ( style_cp > style_bp && style_cp[-1] == '\n' )
1341         style_cp[-2] = '\n';
1342
1343     *--style_cp = c;
1344
1345     /* note: the formal parameter *must* be called "style_bp" for this
1346      *       macro to now work correctly
1347      */
1348     style_DO_BEFORE_ACTION; /* set up styletext again */
1349     }
1350
1351
1352 #ifdef __cplusplus
1353 static int styleinput()
1354 #else
1355 static int input()
1356 #endif
1357
1358     {
1359     int c;
1360     style_CHAR *style_cp = style_c_buf_p;
1361
1362     *style_cp = style_hold_char;
1363
1364     if ( *style_c_buf_p == style_END_OF_BUFFER_CHAR )
1365         {
1366         /* style_c_buf_p now points to the character we want to return.
1367          * If this occurs *before* the EOB characters, then it's a
1368          * valid NUL; if not, then we've hit the end of the buffer.
1369          */
1370         if ( style_c_buf_p < &style_current_buffer->style_ch_buf[style_n_chars] )
1371             /* this was really a NUL */
1372             *style_c_buf_p = '\0';
1373
1374         else
1375             { /* need more input */
1376             styletext = style_c_buf_p;
1377             ++style_c_buf_p;
1378
1379             switch ( style_get_next_buffer() )
1380                 {
1381                 case EOB_ACT_END_OF_FILE:
1382                     {
1383                     if ( stylewrap() )
1384                         {
1385                         style_c_buf_p = styletext + style_MORE_ADJ;
1386                         return ( EOF );
1387                         }
1388
1389                     style_NEW_FILE;
1390
1391 #ifdef __cplusplus
1392                     return ( styleinput() );
1393 #else
1394                     return ( input() );
1395 #endif
1396                     }
1397                     break;
1398
1399                 case EOB_ACT_CONTINUE_SCAN:
1400                     style_c_buf_p = styletext + style_MORE_ADJ;
1401                     break;
1402
1403                 case EOB_ACT_LAST_MATCH:
1404 #ifdef __cplusplus
1405                     style_FATAL_ERROR( "unexpected last match in styleinput()" );
1406 #else
1407                     style_FATAL_ERROR( "unexpected last match in input()" );
1408 #endif
1409                 }
1410             }
1411         }
1412
1413     c = *style_c_buf_p;
1414     style_hold_char = *++style_c_buf_p;
1415
1416     return ( c );
1417     }
1418
1419
1420 #ifdef style_USE_PROTOS
1421 void stylerestart( FILE *input_file )
1422 #else
1423 void stylerestart( input_file )
1424 FILE *input_file;
1425 #endif
1426
1427     {
1428     style_init_buffer( style_current_buffer, input_file );
1429     style_load_buffer_state();
1430     }
1431
1432
1433 #ifdef style_USE_PROTOS
1434 void style_switch_to_buffer( style_BUFFER_STATE new_buffer )
1435 #else
1436 void style_switch_to_buffer( new_buffer )
1437 style_BUFFER_STATE new_buffer;
1438 #endif
1439
1440     {
1441     if ( style_current_buffer == new_buffer )
1442         return;
1443
1444     if ( style_current_buffer )
1445         {
1446         /* flush out information for old buffer */
1447         *style_c_buf_p = style_hold_char;
1448         style_current_buffer->style_buf_pos = style_c_buf_p;
1449         style_current_buffer->style_n_chars = style_n_chars;
1450         }
1451
1452     style_current_buffer = new_buffer;
1453     style_load_buffer_state();
1454
1455     /* we don't actually know whether we did this switch during
1456      * EOF (stylewrap()) processing, but the only time this flag
1457      * is looked at is after stylewrap() is called, so it's safe
1458      * to go ahead and always set it.
1459      */
1460     style_did_buffer_switch_on_eof = 1;
1461     }
1462
1463
1464 #ifdef style_USE_PROTOS
1465 void style_load_buffer_state( void )
1466 #else
1467 void style_load_buffer_state()
1468 #endif
1469
1470     {
1471     style_n_chars = style_current_buffer->style_n_chars;
1472     styletext = style_c_buf_p = style_current_buffer->style_buf_pos;
1473     stylein = style_current_buffer->style_input_file;
1474     style_hold_char = *style_c_buf_p;
1475     }
1476
1477
1478 #ifdef style_USE_PROTOS
1479 style_BUFFER_STATE style_create_buffer( FILE *file, int size )
1480 #else
1481 style_BUFFER_STATE style_create_buffer( file, size )
1482 FILE *file;
1483 int size;
1484 #endif
1485
1486     {
1487     style_BUFFER_STATE b;
1488
1489     b = (style_BUFFER_STATE) malloc( sizeof( struct style_buffer_state ) );
1490
1491     if ( ! b )
1492         style_FATAL_ERROR( "out of dynamic memory in style_create_buffer()" );
1493
1494     b->style_buf_size = size;
1495
1496     /* style_ch_buf has to be 2 characters longer than the size given because
1497      * we need to put in 2 end-of-buffer characters.
1498      */
1499     b->style_ch_buf = (style_CHAR *) malloc( (unsigned) (b->style_buf_size + 2) );
1500
1501     if ( ! b->style_ch_buf )
1502         style_FATAL_ERROR( "out of dynamic memory in style_create_buffer()" );
1503
1504     style_init_buffer( b, file );
1505
1506     return ( b );
1507     }
1508
1509
1510 #ifdef style_USE_PROTOS
1511 void style_delete_buffer( style_BUFFER_STATE b )
1512 #else
1513 void style_delete_buffer( b )
1514 style_BUFFER_STATE b;
1515 #endif
1516
1517     {
1518     if ( b == style_current_buffer )
1519         style_current_buffer = (style_BUFFER_STATE) 0;
1520
1521     free( (char *) b->style_ch_buf );
1522     free( (char *) b );
1523     }
1524
1525
1526 #ifdef style_USE_PROTOS
1527 void style_init_buffer( style_BUFFER_STATE b, FILE *file )
1528 #else
1529 void style_init_buffer( b, file )
1530 style_BUFFER_STATE b;
1531 FILE *file;
1532 #endif
1533
1534     {
1535     b->style_input_file = file;
1536
1537     /* we put in the '\n' and start reading from [1] so that an
1538      * initial match-at-newline will be true.
1539      */
1540
1541     b->style_ch_buf[0] = '\n';
1542     b->style_n_chars = 1;
1543
1544     /* we always need two end-of-buffer characters.  The first causes
1545      * a transition to the end-of-buffer state.  The second causes
1546      * a jam in that state.
1547      */
1548     b->style_ch_buf[1] = style_END_OF_BUFFER_CHAR;
1549     b->style_ch_buf[2] = style_END_OF_BUFFER_CHAR;
1550
1551     b->style_buf_pos = &b->style_ch_buf[1];
1552
1553     b->style_eof_status = EOF_NOT_SEEN;
1554     }
1555 # line 334 "tokenStyle.l"
1556
1557
1558 void enter_sgmlgi_context()
1559 {
1560    BEGIN sgmlgimode;
1561 }
1562
1563
1564 void report_error_location()
1565 {
1566    if ( commentBufferContentSize > 0 ) {
1567       cerr << commentBuffer << "\n";
1568    }
1569 }
1570
1571 void styleerror(char* msg)
1572 {
1573 #ifdef DEBUG
1574    cerr << "line " << stylelineno << ": " << msg << "\n";
1575 #endif
1576    throw(CASTSSEXCEPT StyleSheetSyntaxError());
1577 }
1578