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