/*
 * CDE - Common Desktop Environment
 *
 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
 *
 * These libraries and programs are free software; you can
 * redistribute them and/or modify them under the terms of the GNU
 * Lesser General Public License as published by the Free Software
 * Foundation; either version 2 of the License, or (at your option)
 * any later version.
 *
 * These libraries and programs are distributed in the hope that
 * they will be useful, but WITHOUT ANY WARRANTY; without even the
 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
 * PURPOSE. See the GNU Lesser General Public License for more
 * details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with these libraries and programs; if not, write
 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
 * Floor, Boston, MA 02110-1301 USA
 */
/* A lexical scanner generated by flex */

/* scanner skeleton version:
 * $TOG: tokenStyle.C /main/6 1998/04/17 11:52:06 mgreess $
 */

#define FLEX_SCANNER

#include <stdio.h>


/* cfront 1.2 defines "c_plusplus" instead of "__cplusplus" */
#ifdef c_plusplus
#ifndef __cplusplus
#define __cplusplus
#endif
#endif


#ifdef __cplusplus

#include <stdlib.h>

#if !defined(__linux__) && !defined(CSRG_BASED) && !defined(sun)
#include <osfcn.h>
#endif

/* use prototypes in function declarations */
#define style_USE_PROTOS

/* the "const" storage-class-modifier is valid */
#define style_USE_CONST

#else	/* ! __cplusplus */

#ifdef __STDC__

#ifdef __GNUC__
#include <stddef.h>
void *malloc( size_t );
void free( void* );
#else
#include <stdlib.h>
#endif	/* __GNUC__ */

#define style_USE_PROTOS
#define style_USE_CONST

#endif	/* __STDC__ */
#endif	/* ! __cplusplus */


#ifdef __TURBOC__
#define style_USE_CONST
#endif


#ifndef style_USE_CONST
#define const
#endif


#ifdef style_USE_PROTOS
#define style_PROTO(proto) proto
#else
#define style_PROTO(proto) ()
/* we can't get here if it's an ANSI C compiler, or a C++ compiler,
 * so it's got to be a K&R compiler, and therefore there's no standard
 * place from which to include these definitions
 */
char *malloc();
int free();
int read();
#endif


/* amount of stuff to slurp up with each read */
#ifndef style_READ_BUF_SIZE
#define style_READ_BUF_SIZE 8192
#endif

/* returned upon end-of-file */
#define style_END_TOK 0

/* copy whatever the last rule matched to the standard output */

/* cast to (char *) is because for 8-bit chars, styletext is (unsigned char *) */
/* this used to be an fputs(), but since the string might contain NUL's,
 * we now use fwrite()
 */
#define ECHO (void) fwrite( (char *) styletext, styleleng, 1, styleout )

/* gets input and stuffs it into "buf".  number of characters read, or style_NULL,
 * is returned in "result".
 */
#define style_INPUT(buf,result,max_size) \
	if ( (result = read( fileno(stylein), (char *) buf, max_size )) < 0 ) \
	    style_FATAL_ERROR( "read() in flex scanner failed" );
#define style_NULL 0

/* no semi-colon after return; correct usage is to write "styleterminate();" -
 * we don't want an extra ';' after the "return" because that will cause
 * some compilers to complain about unreachable statements.
 */
#define styleterminate() return ( style_NULL )

/* report a fatal error */

/* The funky do-while is used to turn this macro definition into
 * a single C statement (which needs a semi-colon terminator).
 * This avoids problems with code like:
 *
 * 	if ( something_happens )
 *		style_FATAL_ERROR( "oops, the something happened" );
 *	else
 *		everything_okay();
 *
 * Prior to using the do-while the compiler would get upset at the
 * "else" because it interpreted the "if" statement as being all
 * done when it reached the ';' after the style_FATAL_ERROR() call.
 */

#define style_FATAL_ERROR(msg) \
	do \
		{ \
		(void) fputs( msg, stderr ); \
		(void) putc( '\n', stderr ); \
		exit( 1 ); \
		} \
	while ( 0 )

/* default stylewrap function - always treat EOF as an EOF */
#define stylewrap() 1

/* enter a start condition.  This macro really ought to take a parameter,
 * but we do it the disgusting crufty way forced on us by the ()-less
 * definition of BEGIN
 */
#define BEGIN style_start = 1 + 2 *

/* action number for EOF rule of a given start state */
#define style_STATE_EOF(state) (style_END_OF_BUFFER + state + 1)

/* special action meaning "start processing a new file" */
#define style_NEW_FILE \
	do \
		{ \
		style_init_buffer( style_current_buffer, stylein ); \
		style_load_buffer_state(); \
		} \
	while ( 0 )

/* default declaration of generated scanner - a define so the user can
 * easily add parameters
 */
#define style_DECL int stylelex style_PROTO(( void )) 

/* code executed at the end of each rule */
#define style_BREAK break;

#define style_END_OF_BUFFER_CHAR 0

#ifndef style_BUF_SIZE
#define style_BUF_SIZE (style_READ_BUF_SIZE * 2) /* size of default input buffer */
#endif

typedef struct style_buffer_state *style_BUFFER_STATE;

#define style_CHAR unsigned char
# line 1 "tokenStyle.l"
#define INITIAL 0
/*
* $TOG: tokenStyle.C /main/6 1998/04/17 11:52:06 mgreess $
*
* Copyright (c) 1993 HAL Computer Systems International, Ltd.
* All rights reserved.  Unpublished -- rights reserved under
* the Copyright Laws of the United States.  USE OF A COPYRIGHT
* NOTICE IS PRECAUTIONARY ONLY AND DOES NOT IMPLY PUBLICATION
* OR DISCLOSURE.
* 
* THIS SOFTWARE CONTAINS CONFIDENTIAL INFORMATION AND TRADE
* SECRETS OF HAL COMPUTER SYSTEMS INTERNATIONAL, LTD.  USE,
* DISCLOSURE, OR REPRODUCTION IS PROHIBITED WITHOUT THE
* PRIOR EXPRESS WRITTEN PERMISSION OF HAL COMPUTER SYSTEMS
* INTERNATIONAL, LTD.
* 
*                         RESTRICTED RIGHTS LEGEND
* Use, duplication, or disclosure by the Government is subject
* to the restrictions as set forth in subparagraph (c)(l)(ii)
* of the Rights in Technical Data and Computer Software clause
* at DFARS 252.227-7013.
*
*          HAL COMPUTER SYSTEMS INTERNATIONAL, LTD.
*                  1315 Dell Avenue
*                  Campbell, CA  95008
* 
*/
# line 37 "tokenStyle.l"
#include <string.h>
#include "ParserConst.h"
#include "Expression.h"
#include "FeatureValue.h"
#include "PathTable.h"
#include "SSPath.h"
#include "PathQualifier.h"
#include "StyleSheetExceptions.h"
#include "style.tab.h"
#include "Debug.h"
#include <iostream>
using namespace std;

istream *g_stylein = 0;

#undef style_INPUT
#define style_INPUT(buf,result,max_size)\
  {\
     if (g_stylein -> eof()) {\
        result=0;\
     } else {\
        g_stylein -> read((char*)buf, max_size-1); \
        result = g_stylein -> gcount(); \
        buf[result] = 0; \
     }\
  }

unsigned char* qstring_buf = new unsigned char[1024];
int qstring_buf_size = 1024;
int qstring_buf_content_size = 0;

char* commentBuffer = new char [1024];
int commentBufferSize = 1024;
int commentBufferContentSize = 0;

int stylelineno=1;
		
void addToQstringBuf(const unsigned char* str, int size)
{
   if ( size <= 0 ) return;

   if ( qstring_buf_size - qstring_buf_content_size < size ) {
      qstring_buf_size = 2*(size+qstring_buf_content_size);
      unsigned char* x = new unsigned char[qstring_buf_size];
      memcpy(x, qstring_buf, qstring_buf_content_size);
      delete [] qstring_buf;
      qstring_buf = x;
   }

   memcpy(qstring_buf + qstring_buf_content_size, str, size);
   qstring_buf_content_size += size;
   qstring_buf[qstring_buf_content_size] = 0;
}


#define block 1
#define sgmlgimode 2
#define quoted_string 3
# line 95 "tokenStyle.l"

/* done after the current pattern has been matched and before the
 * corresponding action - sets up styletext
 */
#define style_DO_BEFORE_ACTION \
	styletext = style_bp; \
	styleleng = style_cp - style_bp; \
	style_hold_char = *style_cp; \
	*style_cp = '\0'; \
	style_c_buf_p = style_cp;

#define EOB_ACT_CONTINUE_SCAN 0
#define EOB_ACT_END_OF_FILE 1
#define EOB_ACT_LAST_MATCH 2

/* return all but the first 'n' matched characters back to the input stream */
#define styleless(n) \
	do \
		{ \
		/* undo effects of setting up styletext */ \
		*style_cp = style_hold_char; \
		style_c_buf_p = style_cp = style_bp + n; \
		style_DO_BEFORE_ACTION; /* set up styletext again */ \
		} \
	while ( 0 )

#define unput(c) styleunput( c, styletext )


struct style_buffer_state
    {
    FILE *style_input_file;

    style_CHAR *style_ch_buf;		/* input buffer */
    style_CHAR *style_buf_pos;	/* current position in input buffer */

    /* size of input buffer in bytes, not including room for EOB characters*/
    int style_buf_size;	

    /* number of characters read into style_ch_buf, not including EOB characters */
    int style_n_chars;

    int style_eof_status;		/* whether we've seen an EOF on this buffer */
#define EOF_NOT_SEEN 0
    /* "pending" happens when the EOF has been seen but there's still
     * some text process
     */
#define EOF_PENDING 1
#define EOF_DONE 2
    };

static style_BUFFER_STATE style_current_buffer;

/* we provide macros for accessing buffer states in case in the
 * future we want to put the buffer states in a more general
 * "scanner state"
 */
#define style_CURRENT_BUFFER style_current_buffer


/* style_hold_char holds the character lost when styletext is formed */
static style_CHAR style_hold_char;

static int style_n_chars;		/* number of characters read into style_ch_buf */



#ifndef style_USER_ACTION
#define style_USER_ACTION
#endif

#ifndef style_USER_INIT
#define style_USER_INIT
#endif

extern style_CHAR *styletext;
extern int styleleng;
extern FILE *stylein, *styleout;

style_CHAR *styletext;
int styleleng;

FILE *stylein = (FILE *) 0, *styleout = (FILE *) 0;

#define style_END_OF_BUFFER 48
typedef int style_state_type;
static const short int style_accept[134] =
    {   0,
        0,    0,    0,    0,    0,    0,   36,   36,   48,   39,
       41,   42,   43,   23,   33,   39,   39,   18,   19,    9,
        5,   13,    6,    8,    7,   31,   10,   24,    3,   24,
       11,    4,   39,   39,   39,   39,   39,   39,   39,   16,
       17,   12,   39,   39,   14,   39,   15,    2,   45,   46,
       45,   47,   40,   36,   36,   34,   35,   39,   22,    1,
       21,    0,   31,   39,   39,   39,   24,   38,   39,   39,
       38,   39,   28,   39,   39,   39,   20,    2,    2,    1,
       44,   40,   36,   32,   30,   30,   39,   39,   39,   39,
       39,   29,   39,   39,   39,   39,    0,    0,    0,   39,

       39,   39,   39,   39,   39,   39,   39,   26,   30,   30,
        0,    0,   39,   39,   27,   39,    0,    0,    0,    0,
       39,    0,    0,   39,   39,   39,   39,   39,   39,   39,
       39,   25,    0
    } ;

static const style_CHAR style_ec[256] =
    {   0,
        1,    1,    1,    1,    1,    1,    1,    1,    2,    3,
        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
        1,    4,    5,    6,    7,    1,    1,    8,    1,    9,
       10,   11,   12,   13,   14,   15,   16,   17,   17,   17,
       17,   17,   17,   17,   17,   17,   17,   18,    1,   19,
       20,   21,   22,   23,   24,   25,   26,   25,   27,   28,
       29,   30,   31,   25,   25,   32,   33,   34,   35,   36,
       25,   37,   38,   39,   40,   25,   25,   41,   25,   25,
       42,   43,   44,   45,    1,    1,   46,   25,   47,   25,

       48,   28,   25,   30,   49,   25,   25,   32,   33,   50,
       51,   36,   25,   37,   52,   53,   40,   54,   25,   41,
       25,   25,   55,   56,   57,    1,    1,    1,    1,    1,
        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,

        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
        1,    1,    1,    1,    1
    } ;

static const style_CHAR style_meta[58] =
    {   0,
        1,    2,    3,    2,    2,    4,    1,    1,    2,    2,
        2,    2,    2,    5,    6,    2,    5,    2,    1,    2,
        1,    2,    2,    5,    5,    5,    5,    5,    5,    5,
        5,    5,    5,    5,    5,    5,    5,    5,    5,    5,
        5,    2,    7,    2,    2,    5,    5,    5,    5,    5,
        5,    5,    5,    5,    2,    1,    2
    } ;

static const short int style_base[141] =
    {   0,
        0,  341,   55,   56,  112,    0,   57,   58,  347,    0,
      349,  349,  349,  326,  349,  289,  336,  349,  349,  349,
      349,  349,    0,  349,  349,   50,  349,  323,  322,  321,
      349,  349,  303,   38,  300,   32,   40,   57,  284,  349,
      349,  349,   35,  289,  349,  259,  349,  168,  349,  349,
      307,  349,    0,    0,    0,  349,  349,    0,  349,    0,
        0,  296,  170,  262,   37,  169,  349,    0,  262,  267,
       44,  264,    0,  156,   44,  251,    0,  224,    0,    0,
      349,    0,    0,  224,    0,   47,  168,   46,   51,  244,
      259,    0,   56,  144,  155,  166,  255,  177,  223,  257,

      152,  204,  198,  211,  234,  253,  168,    0,  349,  217,
      237,  226,  250,  212,    0,  213,  223,  221,  229,  246,
      164,  167,  244,  127,   59,   55,   56,   45,   30,   24,
       24,    0,  349,  297,  304,  311,  318,  321,  327,  333
    } ;

static const short int style_def[141] =
    {   0,
      133,    1,  134,  134,  133,    5,  135,  135,  133,  136,
      133,  133,  133,  133,  133,  136,  136,  133,  133,  133,
      133,  133,  136,  133,  133,  136,  133,  136,  133,  136,
      133,  133,  136,  136,  136,  136,  136,  136,  136,  133,
      133,  133,  136,  136,  133,  136,  133,  137,  133,  133,
      133,  133,  138,  139,  139,  133,  133,  136,  133,  136,
      136,  133,  136,  136,  136,  136,  133,  136,  136,  136,
      136,  136,  136,  136,  136,  136,  136,  137,  140,   78,
      133,  138,  139,  133,  136,  136,  136,  136,  136,  136,
      136,  136,  136,  136,  136,  136,  133,  133,  133,  136,

      136,  136,  136,  136,  136,  136,  136,  136,  133,  133,
      133,  133,  136,  136,  136,  136,  133,  133,  133,  133,
      136,  133,  133,  136,  136,  136,  136,  136,  136,  136,
      136,  136,    0,  133,  133,  133,  133,  133,  133,  133
    } ;

static const short int style_nxt[407] =
    {   0,
       10,   11,   12,   13,   14,   15,   16,   17,   18,   19,
       20,   21,   22,   23,   24,   25,   26,   27,   28,   29,
       30,   31,   32,   10,   10,   33,   10,   34,   35,   10,
       36,   10,   10,   10,   37,   38,   10,   10,   39,   10,
       10,   40,   10,   41,   42,   10,   33,   10,   36,   43,
       44,   10,   39,   10,   45,   46,   47,   50,   50,   55,
       55,   69,   56,   56,   62,   71,   63,   72,   73,   91,
       86,  132,  100,   73,   95,   64,  103,  131,  130,   68,
       65,   71,   68,   69,   73,   66,   86,   74,  104,   73,
       91,   75,   95,  100,  103,   68,   64,  129,   65,   57,

       57,   68,  104,   68,  128,   74,  127,   75,  126,   68,
       51,   51,   52,   52,   52,   52,   52,   52,   52,   52,
       52,   52,   52,   52,   52,   53,   53,   52,   53,   52,
       52,   52,   52,   52,   52,   53,   53,   53,   53,   53,
       53,   53,   53,   53,   53,   53,   53,   53,   53,   53,
       53,   53,   53,   52,   52,   52,   52,   53,   53,   53,
       53,   53,   53,   53,   53,   53,   52,   52,   52,   79,
      106,   79,   79,   79,  125,   85,   79,   79,   79,   79,
       79,   93,   79,   79,   62,   79,   63,   79,  107,   79,
       79,  106,  108,  101,   85,   64,   94,   85,  109,   87,

       65,  124,   93,   88,  107,   66,   68,   85,  102,   79,
      110,   79,   79,  108,  101,   85,   64,   87,   65,   88,
       68,   85,   79,   80,   79,   79,  110,   79,   79,   79,
      113,  114,   79,   79,   79,   79,   79,  115,   79,   79,
       84,   79,  117,   79,  109,   79,   79,  114,  109,   97,
       85,  113,  109,  111,   98,  122,  120,  112,  115,   99,
      121,  109,  118,  117,   85,   79,  109,   79,   79,  109,
       97,  111,   98,  112,  120,  109,  122,  119,   79,  123,
       79,   85,  109,  118,   68,  116,   85,  109,   68,  105,
       96,   92,   90,   89,   85,  123,  109,   49,   49,   49,

       49,   49,   49,   49,   54,   54,   54,   54,   54,   54,
       54,   58,   84,   81,   77,   58,   72,   58,   78,   78,
       76,   78,   78,   78,   78,   82,   82,   83,   83,   83,
       70,   83,   83,   79,   79,   68,   79,   79,   79,   79,
       67,   59,   67,   61,   60,   59,  133,   48,    9,  133,
      133,  133,  133,  133,  133,  133,  133,  133,  133,  133,
      133,  133,  133,  133,  133,  133,  133,  133,  133,  133,
      133,  133,  133,  133,  133,  133,  133,  133,  133,  133,
      133,  133,  133,  133,  133,  133,  133,  133,  133,  133,
      133,  133,  133,  133,  133,  133,  133,  133,  133,  133,

      133,  133,  133,  133,  133,  133
    } ;

static const short int style_chk[407] =
    {   0,
        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
        1,    1,    1,    1,    1,    1,    1,    3,    4,    7,
        8,   34,    7,    8,   26,   36,   26,   37,   43,   71,
       65,  131,   86,   37,   75,   26,   88,  130,  129,   93,
       26,   36,   38,   34,   43,   26,   65,   38,   89,   37,
       71,   38,   75,   86,   88,   38,   26,  128,   26,    7,

        8,   93,   89,   38,  127,   38,  126,   38,  125,   38,
        3,    4,    5,    5,    5,    5,    5,    5,    5,    5,
        5,    5,    5,    5,    5,    5,    5,    5,    5,    5,
        5,    5,    5,    5,    5,    5,    5,    5,    5,    5,
        5,    5,    5,    5,    5,    5,    5,    5,    5,    5,
        5,    5,    5,    5,    5,    5,    5,    5,    5,    5,
        5,    5,    5,    5,    5,    5,    5,    5,    5,   48,
       94,   48,   48,   48,  124,  101,   48,   48,   48,   48,
       48,   74,   48,   48,   63,   48,   63,   48,   95,   48,
       48,   94,   96,   87,   66,   63,   74,  101,  122,   66,

       63,  121,   74,   66,   95,   63,  107,   66,   87,   48,
       98,   48,   48,   96,   87,   66,   63,   66,   63,   66,
      107,   66,   48,   48,   48,   78,   98,   78,   78,   78,
      102,  103,   78,   78,   78,   78,   78,  104,   78,   78,
       84,   78,  110,   78,  118,   78,   78,  103,   99,   84,
      114,  102,  117,   99,   84,  119,  112,   99,  104,   84,
      116,   99,  111,  110,  114,   78,  118,   78,   78,   99,
       84,   99,   84,   99,  112,   99,  119,  111,   78,  120,
       78,  113,  123,  111,  106,  105,  100,   97,   91,   90,
       76,   72,   70,   69,   64,  120,  123,  134,  134,  134,

      134,  134,  134,  134,  135,  135,  135,  135,  135,  135,
      135,  136,   62,   51,   46,  136,   44,  136,  137,  137,
       39,  137,  137,  137,  137,  138,  138,  139,  139,  139,
       35,  139,  139,  140,  140,   33,  140,  140,  140,  140,
       30,   29,   28,   17,   16,   14,    9,    2,  133,  133,
      133,  133,  133,  133,  133,  133,  133,  133,  133,  133,
      133,  133,  133,  133,  133,  133,  133,  133,  133,  133,
      133,  133,  133,  133,  133,  133,  133,  133,  133,  133,
      133,  133,  133,  133,  133,  133,  133,  133,  133,  133,
      133,  133,  133,  133,  133,  133,  133,  133,  133,  133,

      133,  133,  133,  133,  133,  133
    } ;

static style_state_type style_last_accepting_state;
static style_CHAR *style_last_accepting_cpos;

/* the intent behind this definition is that it'll catch
 * any uses of REJECT which flex missed
 */
#define REJECT reject_used_but_not_detected
#define stylemore() stylemore_used_but_not_detected
#define style_MORE_ADJ 0

/* these variables are all declared out here so that section 3 code can
 * manipulate them
 */
/* points to current character in buffer */
static style_CHAR *style_c_buf_p = (style_CHAR *) 0;
static int style_init = 1;		/* whether we need to initialize */
static int style_start = 0;	/* start state number */

/* flag which is used to allow stylewrap()'s to do buffer switches
 * instead of setting up a fresh stylein.  A bit of a hack ...
 */
static int style_did_buffer_switch_on_eof;

static style_state_type style_get_previous_state style_PROTO(( void ));
static style_state_type style_try_NUL_trans style_PROTO(( style_state_type current_state ));
static int style_get_next_buffer style_PROTO(( void ));
#if 0
static void styleunput style_PROTO(( style_CHAR c, style_CHAR *buf_ptr ));
#endif
void stylerestart style_PROTO(( FILE *input_file ));
void style_switch_to_buffer style_PROTO(( style_BUFFER_STATE new_buffer ));
void style_load_buffer_state style_PROTO(( void ));
style_BUFFER_STATE style_create_buffer style_PROTO(( FILE *file, int size ));
void style_delete_buffer style_PROTO(( style_BUFFER_STATE b ));
void style_init_buffer style_PROTO(( style_BUFFER_STATE b, FILE *file ));

#define style_new_buffer style_create_buffer

#ifdef __cplusplus
static int styleinput style_PROTO(( void ));
#else
static int input style_PROTO(( void ));
#endif

style_DECL
    {
    register style_state_type style_current_state;
    register style_CHAR *style_cp, *style_bp;
    register int style_act;




    if ( style_init )
	{
	style_USER_INIT;

	if ( ! style_start )
	    style_start = 1;	/* first start state */

	if ( ! stylein )
	    stylein = stdin;

	if ( ! styleout )
	    styleout = stdout;

	if ( style_current_buffer )
	    style_init_buffer( style_current_buffer, stylein );
	else
	    style_current_buffer = style_create_buffer( stylein, style_BUF_SIZE );

	style_load_buffer_state();

	style_init = 0;
	}

    while ( 1 )		/* loops until end-of-file is reached */
	{
	style_cp = style_c_buf_p;

	/* support of styletext */
	*style_cp = style_hold_char;

	/* style_bp points to the position in style_ch_buf of the start of the
	 * current run.
	 */
	style_bp = style_cp;

	style_current_state = style_start;
	if ( style_bp[-1] == '\n' )
	    ++style_current_state;
style_match:
	do
	    {
	    register style_CHAR style_c = style_ec[*style_cp];
	    if ( style_accept[style_current_state] )
		{
		style_last_accepting_state = style_current_state;
		style_last_accepting_cpos = style_cp;
		}
	    while ( style_chk[style_base[style_current_state] + style_c] != style_current_state )
		{
		style_current_state = style_def[style_current_state];
		if ( style_current_state >= 134 )
		    style_c = style_meta[style_c];
		}
	    style_current_state = style_nxt[style_base[style_current_state] + style_c];
	    ++style_cp;
	    }
	while ( style_current_state != 133 );
	style_cp = style_last_accepting_cpos;
	style_current_state = style_last_accepting_state;

style_find_action:
	style_act = style_accept[style_current_state];

	style_DO_BEFORE_ACTION;
	style_USER_ACTION;

do_action:	/* this label is used only to access EOF actions */


	switch ( style_act )
	    {
	    case 0: /* must backtrack */
	    /* undo the effects of style_DO_BEFORE_ACTION */
	    *style_cp = style_hold_char;
	    style_cp = style_last_accepting_cpos;
	    style_current_state = style_last_accepting_state;
	    goto style_find_action;

case 1:
# line 97 "tokenStyle.l"
BEGIN(block);
	style_BREAK
case 2:
# line 99 "tokenStyle.l"
{
	   if ( commentBufferSize < styleleng ) {
              delete [] commentBuffer;
              commentBufferSize = 2 * styleleng ;
              commentBuffer = new char [commentBufferSize];
           } 

	   commentBufferContentSize = styleleng-1;
           memcpy(commentBuffer, styletext+1, commentBufferContentSize); // copy everything except the #
           commentBuffer[commentBufferContentSize] = 0;
	}
	style_BREAK
case 3:
# line 111 "tokenStyle.l"
{
	   return(OPER_assign);
	}
	style_BREAK
case 4:
# line 115 "tokenStyle.l"
{
	   return(OPER_attr);
	}
	style_BREAK
case 5:
# line 119 "tokenStyle.l"
{
           stylelval.charData = styletext[0];
	   return(OPER_plus);
	}
	style_BREAK
case 6:
# line 124 "tokenStyle.l"
{
           stylelval.charData = styletext[0];
	   return(OPER_minus);
	}
	style_BREAK
case 7:
# line 129 "tokenStyle.l"
{
           stylelval.charData = styletext[0];
	   return(OPER_div);
	}
	style_BREAK
case 8:
# line 134 "tokenStyle.l"
{
	   return(OPER_period);
	}
	style_BREAK
case 9:
# line 138 "tokenStyle.l"
{
           stylelval.charData = styletext[0];
	   return(OPER_star);
	}
	style_BREAK
case 10:
# line 143 "tokenStyle.l"
{
	   return(OPER_modify);
	}
	style_BREAK
case 11:
# line 147 "tokenStyle.l"
{
	   return(OPER_oneof);
	}
	style_BREAK
case 12:
# line 151 "tokenStyle.l"
{
	   return(OPER_parent);
	}
	style_BREAK
case 13:
# line 155 "tokenStyle.l"
{
	   return(SEPARATOR);
	}
	style_BREAK
case 14:
# line 159 "tokenStyle.l"
{
	   return(FSOPEN);
	}
	style_BREAK
case 15:
# line 163 "tokenStyle.l"
{
	   return(FSCLOSE);
	}
	style_BREAK
case 16:
# line 167 "tokenStyle.l"
{
	   return(ARRAYOPEN);
	}
	style_BREAK
case 17:
# line 171 "tokenStyle.l"
{
	   return(ARRAYCLOSE);
	}
	style_BREAK
case 18:
# line 175 "tokenStyle.l"
{
	   return(OPER_parenopen);
	}
	style_BREAK
case 19:
# line 179 "tokenStyle.l"
{
	   return(OPER_parenclose);
	}
	style_BREAK
case 20:
# line 183 "tokenStyle.l"
{
	   return(OPER_or);
	}
	style_BREAK
case 21:
# line 187 "tokenStyle.l"
{
	   return(OPER_and);
	}
	style_BREAK
case 22:
# line 191 "tokenStyle.l"
{
           if ( strcmp((const char*)styletext, "==") == 0 )
              stylelval.intData = EQUAL;
 	   else
              stylelval.intData = NOT_EQUAL;

	   return(OPER_equality);
	}
	style_BREAK
case 23:
# line 200 "tokenStyle.l"
{
	   return(OPER_logicalnegate);
	}
	style_BREAK
case 24:
# line 204 "tokenStyle.l"
{
           if ( strcmp((const char*)styletext, "<=") == 0 )
              stylelval.intData = LESS_OR_EQUAL;
 	   else
           if ( strcmp((const char*)styletext, "<") == 0 )
              stylelval.intData = LESS;
 	   else
           if ( strcmp((const char*)styletext, ">=") == 0 )
              stylelval.intData = GREATER_OR_EQUAL;
 	   else
              stylelval.intData = GREATER;

	   return(OPER_relational);
	}
	style_BREAK
case 25:
# line 219 "tokenStyle.l"
{
		return(GI_CASE_SENSITIVE);
			}
	style_BREAK
case 26:
# line 223 "tokenStyle.l"
{
                stylelval.boolData = true;
		return(BOOLVAL);
			}
	style_BREAK
case 27:
# line 228 "tokenStyle.l"
{
                stylelval.boolData = false;
		return(BOOLVAL);
			}
	style_BREAK
case 28:
# line 233 "tokenStyle.l"
{
                stylelval.boolData = true;
		return(BOOLVAL);
		}
	style_BREAK
case 29:
# line 238 "tokenStyle.l"
{
                stylelval.boolData = false;
		return(BOOLVAL);
		}
	style_BREAK
case 30:
# line 243 "tokenStyle.l"
{
		stylelval.charPtrData = 
                  (unsigned char*)strdup((const char*)styletext);
		return(DIMENSION);
		}
	style_BREAK
case 31:
# line 249 "tokenStyle.l"
{
		stylelval.intData = atoi((char*)styletext);
		return(INTEGER);
		}
	style_BREAK
case 32:
# line 254 "tokenStyle.l"
{
		stylelval.realData = atof((char*)styletext);
		return(REAL);
		}
	style_BREAK
case 33:
# line 259 "tokenStyle.l"
{
		BEGIN quoted_string;
		}
	style_BREAK
case 34:
# line 263 "tokenStyle.l"
{

		stylelval.charPtrData = 
			new unsigned char[qstring_buf_content_size+1];
		memcpy( stylelval.charPtrData, 
			qstring_buf, 
			qstring_buf_content_size+1
		      );

   		qstring_buf_content_size = 0;
		BEGIN 0;

		return(QUOTED_STRING);
		}
	style_BREAK
case 35:
# line 278 "tokenStyle.l"
{
		int c = styleinput();
		switch (c) {
		   case '"':
		     addToQstringBuf((unsigned char*)"\"", 1);
		     break;
		   case '\\':
		     addToQstringBuf((unsigned char*)"\\", 1);
		     break;
		   default:
                     throw(CASTSSEXCEPT StyleSheetException());
		}
		}
	style_BREAK
case 36:
# line 292 "tokenStyle.l"
{
		addToQstringBuf((const unsigned char *)styletext, styleleng);
		}
	style_BREAK
case 37:
# line 296 "tokenStyle.l"
{
		addToQstringBuf((const unsigned char *)styletext, styleleng);
		}
	style_BREAK
case 38:
# line 300 "tokenStyle.l"
{
		stylelval.charPtrData = 
                  (unsigned char*)strdup((const char*)styletext);
		  return(UNIT_STRING);
		}
	style_BREAK
case 39:
# line 306 "tokenStyle.l"
{
		stylelval.charPtrData = 
                  (unsigned char*)strdup((const char*)styletext);
		return(NORMAL_STRING);
		}
	style_BREAK
case 40:
# line 312 "tokenStyle.l"
{
		stylelval.charPtrData = 
                  (unsigned char*)strdup((const char*)styletext);
		BEGIN 0;
		return(SGMLGI_STRING);
	}
	style_BREAK
case 41:
# line 319 "tokenStyle.l"
{
	}
	style_BREAK
case 42:
# line 322 "tokenStyle.l"
{
	   stylelineno++;
	}
	style_BREAK
case 43:
# line 326 "tokenStyle.l"
{
	}
	style_BREAK
case 44:
# line 331 "tokenStyle.l"
{ BEGIN(0); }
	style_BREAK
case 45:
# line 332 "tokenStyle.l"
;
	style_BREAK
case 46:
# line 333 "tokenStyle.l"
;
	style_BREAK
case 47:
# line 334 "tokenStyle.l"
style_FATAL_ERROR( "flex scanner jammed" );
	style_BREAK
case style_STATE_EOF(INITIAL):
case style_STATE_EOF(block):
case style_STATE_EOF(sgmlgimode):
case style_STATE_EOF(quoted_string):
    styleterminate();

	    case style_END_OF_BUFFER:
		{
		/* amount of text matched not including the EOB char */
		int style_amount_of_matched_text = style_cp - styletext - 1;

		/* undo the effects of style_DO_BEFORE_ACTION */
		*style_cp = style_hold_char;

		/* note that here we test for style_c_buf_p "<=" to the position
		 * of the first EOB in the buffer, since style_c_buf_p will
		 * already have been incremented past the NUL character
		 * (since all states make transitions on EOB to the end-
		 * of-buffer state).  Contrast this with the test in styleinput().
		 */
		if ( style_c_buf_p <= &style_current_buffer->style_ch_buf[style_n_chars] )
		    /* this was really a NUL */
		    {
		    style_state_type style_next_state;

		    style_c_buf_p = styletext + style_amount_of_matched_text;

		    style_current_state = style_get_previous_state();

		    /* okay, we're now positioned to make the
		     * NUL transition.  We couldn't have
		     * style_get_previous_state() go ahead and do it
		     * for us because it doesn't know how to deal
		     * with the possibility of jamming (and we
		     * don't want to build jamming into it because
		     * then it will run more slowly)
		     */

		    style_next_state = style_try_NUL_trans( style_current_state );

		    style_bp = styletext + style_MORE_ADJ;

		    if ( style_next_state )
			{
			/* consume the NUL */
			style_cp = ++style_c_buf_p;
			style_current_state = style_next_state;
			goto style_match;
			}

		    else
			{
			    style_cp = style_last_accepting_cpos;
			    style_current_state = style_last_accepting_state;
			goto style_find_action;
			}
		    }

		else switch ( style_get_next_buffer() )
		    {
		    case EOB_ACT_END_OF_FILE:
			{
			style_did_buffer_switch_on_eof = 0;

			if ( stylewrap() )
			    {
			    /* note: because we've taken care in
			     * style_get_next_buffer() to have set up styletext,
			     * we can now set up style_c_buf_p so that if some
			     * total hoser (like flex itself) wants
			     * to call the scanner after we return the
			     * style_NULL, it'll still work - another style_NULL
			     * will get returned.
			     */
			    style_c_buf_p = styletext + style_MORE_ADJ;

			    style_act = style_STATE_EOF((style_start - 1) / 2);
			    goto do_action;
			    }

			else
			    {
			    if ( ! style_did_buffer_switch_on_eof )
				style_NEW_FILE;
			    }
			}
			break;

		    case EOB_ACT_CONTINUE_SCAN:
			style_c_buf_p = styletext + style_amount_of_matched_text;

			style_current_state = style_get_previous_state();

			style_cp = style_c_buf_p;
			style_bp = styletext + style_MORE_ADJ;
			goto style_match;

		    case EOB_ACT_LAST_MATCH:
			style_c_buf_p =
			    &style_current_buffer->style_ch_buf[style_n_chars];

			style_current_state = style_get_previous_state();

			style_cp = style_c_buf_p;
			style_bp = styletext + style_MORE_ADJ;
			goto style_find_action;
		    }
		break;
		}

	    default:
#ifdef FLEX_DEBUG
		printf( "action # %d\n", style_act );
#endif
		style_FATAL_ERROR(
			"fatal flex scanner internal error--no action found" );
	    }
	}
    }


/* style_get_next_buffer - try to read in a new buffer
 *
 * synopsis
 *     int style_get_next_buffer();
 *     
 * returns a code representing an action
 *     EOB_ACT_LAST_MATCH - 
 *     EOB_ACT_CONTINUE_SCAN - continue scanning from current position
 *     EOB_ACT_END_OF_FILE - end of file
 */

static int style_get_next_buffer()

    {
    register style_CHAR *dest = style_current_buffer->style_ch_buf;
    register style_CHAR *source = styletext - 1; /* copy prev. char, too */
    register int number_to_move, i;
    int ret_val;

    if ( style_c_buf_p > &style_current_buffer->style_ch_buf[style_n_chars + 1] )
	style_FATAL_ERROR(
		"fatal flex scanner internal error--end of buffer missed" );

    /* try to read more data */

    /* first move last chars to start of buffer */
    number_to_move = style_c_buf_p - styletext;

    for ( i = 0; i < number_to_move; ++i )
	*(dest++) = *(source++);

    if ( style_current_buffer->style_eof_status != EOF_NOT_SEEN )
	/* don't do the read, it's not guaranteed to return an EOF,
	 * just force an EOF
	 */
	style_n_chars = 0;

    else
	{
	int num_to_read = style_current_buffer->style_buf_size - number_to_move - 1;

	if ( num_to_read > style_READ_BUF_SIZE )
	    num_to_read = style_READ_BUF_SIZE;

	else if ( num_to_read <= 0 )
	    style_FATAL_ERROR( "fatal error - scanner input buffer overflow" );

	/* read in more data */
	style_INPUT( (&style_current_buffer->style_ch_buf[number_to_move]),
		  style_n_chars, num_to_read );
	}

    if ( style_n_chars == 0 )
	{
	if ( number_to_move == 1 )
	    {
	    ret_val = EOB_ACT_END_OF_FILE;
	    style_current_buffer->style_eof_status = EOF_DONE;
	    }

	else
	    {
	    ret_val = EOB_ACT_LAST_MATCH;
	    style_current_buffer->style_eof_status = EOF_PENDING;
	    }
	}

    else
	ret_val = EOB_ACT_CONTINUE_SCAN;

    style_n_chars += number_to_move;
    style_current_buffer->style_ch_buf[style_n_chars] = style_END_OF_BUFFER_CHAR;
    style_current_buffer->style_ch_buf[style_n_chars + 1] = style_END_OF_BUFFER_CHAR;

    /* styletext begins at the second character in style_ch_buf; the first
     * character is the one which preceded it before reading in the latest
     * buffer; it needs to be kept around in case it's a newline, so
     * style_get_previous_state() will have with '^' rules active
     */

    styletext = &style_current_buffer->style_ch_buf[1];

    return ( ret_val );
    }


/* style_get_previous_state - get the state just before the EOB char was reached
 *
 * synopsis
 *     style_state_type style_get_previous_state();
 */

static style_state_type style_get_previous_state()

    {
    register style_state_type style_current_state;
    register style_CHAR *style_cp;

    register style_CHAR *style_bp = styletext;

    style_current_state = style_start;
    if ( style_bp[-1] == '\n' )
	++style_current_state;

    for ( style_cp = styletext + style_MORE_ADJ; style_cp < style_c_buf_p; ++style_cp )
	{
	register style_CHAR style_c = (*style_cp ? style_ec[*style_cp] : 1);
	if ( style_accept[style_current_state] )
	    {
	    style_last_accepting_state = style_current_state;
	    style_last_accepting_cpos = style_cp;
	    }
	while ( style_chk[style_base[style_current_state] + style_c] != style_current_state )
	    {
	    style_current_state = style_def[style_current_state];
	    if ( style_current_state >= 134 )
		style_c = style_meta[style_c];
	    }
	style_current_state = style_nxt[style_base[style_current_state] + style_c];
	}

    return ( style_current_state );
    }


/* style_try_NUL_trans - try to make a transition on the NUL character
 *
 * synopsis
 *     next_state = style_try_NUL_trans( current_state );
 */

#ifdef style_USE_PROTOS
static style_state_type style_try_NUL_trans( register style_state_type style_current_state )
#else
static style_state_type style_try_NUL_trans( style_current_state )
register style_state_type style_current_state;
#endif

    {
    register int style_is_jam;
    register style_CHAR *style_cp = style_c_buf_p;

    register style_CHAR style_c = 1;
    if ( style_accept[style_current_state] )
	{
	style_last_accepting_state = style_current_state;
	style_last_accepting_cpos = style_cp;
	}
    while ( style_chk[style_base[style_current_state] + style_c] != style_current_state )
	{
	style_current_state = style_def[style_current_state];
	if ( style_current_state >= 134 )
	    style_c = style_meta[style_c];
	}
    style_current_state = style_nxt[style_base[style_current_state] + style_c];
    style_is_jam = (style_current_state == 133);

    return ( style_is_jam ? 0 : style_current_state );
    }


#if 0
#ifdef style_USE_PROTOS
static void styleunput( style_CHAR c, register style_CHAR *style_bp )
#else
static void styleunput( c, style_bp )
style_CHAR c;
register style_CHAR *style_bp;
#endif

    {
    register style_CHAR *style_cp = style_c_buf_p;

    /* undo effects of setting up styletext */
    *style_cp = style_hold_char;

    if ( style_cp < style_current_buffer->style_ch_buf + 2 )
	{ /* need to shift things up to make room */
	register int number_to_move = style_n_chars + 2; /* +2 for EOB chars */
	register style_CHAR *dest =
	    &style_current_buffer->style_ch_buf[style_current_buffer->style_buf_size + 2];
	register style_CHAR *source =
	    &style_current_buffer->style_ch_buf[number_to_move];

	while ( source > style_current_buffer->style_ch_buf )
	    *--dest = *--source;

	style_cp += dest - source;
	style_bp += dest - source;
	style_n_chars = style_current_buffer->style_buf_size;

	if ( style_cp < style_current_buffer->style_ch_buf + 2 )
	    style_FATAL_ERROR( "flex scanner push-back overflow" );
	}

    if ( style_cp > style_bp && style_cp[-1] == '\n' )
	style_cp[-2] = '\n';

    *--style_cp = c;

    /* note: the formal parameter *must* be called "style_bp" for this
     *       macro to now work correctly
     */
    style_DO_BEFORE_ACTION; /* set up styletext again */
    }
#endif


#ifdef __cplusplus
static int styleinput()
#else
static int input()
#endif

    {
    int c;
    style_CHAR *style_cp = style_c_buf_p;

    *style_cp = style_hold_char;

    if ( *style_c_buf_p == style_END_OF_BUFFER_CHAR )
	{
	/* style_c_buf_p now points to the character we want to return.
	 * If this occurs *before* the EOB characters, then it's a
	 * valid NUL; if not, then we've hit the end of the buffer.
	 */
	if ( style_c_buf_p < &style_current_buffer->style_ch_buf[style_n_chars] )
	    /* this was really a NUL */
	    *style_c_buf_p = '\0';

	else
	    { /* need more input */
	    styletext = style_c_buf_p;
	    ++style_c_buf_p;

	    switch ( style_get_next_buffer() )
		{
		case EOB_ACT_END_OF_FILE:
		    {
		    if ( stylewrap() )
			{
			style_c_buf_p = styletext + style_MORE_ADJ;
			return ( EOF );
			}

		    style_NEW_FILE;

#ifdef __cplusplus
		    return ( styleinput() );
#else
		    return ( input() );
#endif
		    }
		    break;

		case EOB_ACT_CONTINUE_SCAN:
		    style_c_buf_p = styletext + style_MORE_ADJ;
		    break;

		case EOB_ACT_LAST_MATCH:
#ifdef __cplusplus
		    style_FATAL_ERROR( "unexpected last match in styleinput()" );
#else
		    style_FATAL_ERROR( "unexpected last match in input()" );
#endif
		}
	    }
	}

    c = *style_c_buf_p;
    style_hold_char = *++style_c_buf_p;

    return ( c );
    }


#ifdef style_USE_PROTOS
void stylerestart( FILE *input_file )
#else
void stylerestart( input_file )
FILE *input_file;
#endif

    {
    style_init_buffer( style_current_buffer, input_file );
    style_load_buffer_state();
    }


#ifdef style_USE_PROTOS
void style_switch_to_buffer( style_BUFFER_STATE new_buffer )
#else
void style_switch_to_buffer( new_buffer )
style_BUFFER_STATE new_buffer;
#endif

    {
    if ( style_current_buffer == new_buffer )
	return;

    if ( style_current_buffer )
	{
	/* flush out information for old buffer */
	*style_c_buf_p = style_hold_char;
	style_current_buffer->style_buf_pos = style_c_buf_p;
	style_current_buffer->style_n_chars = style_n_chars;
	}

    style_current_buffer = new_buffer;
    style_load_buffer_state();

    /* we don't actually know whether we did this switch during
     * EOF (stylewrap()) processing, but the only time this flag
     * is looked at is after stylewrap() is called, so it's safe
     * to go ahead and always set it.
     */
    style_did_buffer_switch_on_eof = 1;
    }


#ifdef style_USE_PROTOS
void style_load_buffer_state( void )
#else
void style_load_buffer_state()
#endif

    {
    style_n_chars = style_current_buffer->style_n_chars;
    styletext = style_c_buf_p = style_current_buffer->style_buf_pos;
    stylein = style_current_buffer->style_input_file;
    style_hold_char = *style_c_buf_p;
    }


#ifdef style_USE_PROTOS
style_BUFFER_STATE style_create_buffer( FILE *file, int size )
#else
style_BUFFER_STATE style_create_buffer( file, size )
FILE *file;
int size;
#endif

    {
    style_BUFFER_STATE b;

    b = (style_BUFFER_STATE) malloc( sizeof( struct style_buffer_state ) );

    if ( ! b )
	style_FATAL_ERROR( "out of dynamic memory in style_create_buffer()" );

    b->style_buf_size = size;

    /* style_ch_buf has to be 2 characters longer than the size given because
     * we need to put in 2 end-of-buffer characters.
     */
    b->style_ch_buf = (style_CHAR *) malloc( (unsigned) (b->style_buf_size + 2) );

    if ( ! b->style_ch_buf )
	style_FATAL_ERROR( "out of dynamic memory in style_create_buffer()" );

    style_init_buffer( b, file );

    return ( b );
    }


#ifdef style_USE_PROTOS
void style_delete_buffer( style_BUFFER_STATE b )
#else
void style_delete_buffer( b )
style_BUFFER_STATE b;
#endif

    {
    if ( b == style_current_buffer )
	style_current_buffer = (style_BUFFER_STATE) 0;

    free( (char *) b->style_ch_buf );
    free( (char *) b );
    }


#ifdef style_USE_PROTOS
void style_init_buffer( style_BUFFER_STATE b, FILE *file )
#else
void style_init_buffer( b, file )
style_BUFFER_STATE b;
FILE *file;
#endif

    {
    b->style_input_file = file;

    /* we put in the '\n' and start reading from [1] so that an
     * initial match-at-newline will be true.
     */

    b->style_ch_buf[0] = '\n';
    b->style_n_chars = 1;

    /* we always need two end-of-buffer characters.  The first causes
     * a transition to the end-of-buffer state.  The second causes
     * a jam in that state.
     */
    b->style_ch_buf[1] = style_END_OF_BUFFER_CHAR;
    b->style_ch_buf[2] = style_END_OF_BUFFER_CHAR;

    b->style_buf_pos = &b->style_ch_buf[1];

    b->style_eof_status = EOF_NOT_SEEN;
    }
# line 334 "tokenStyle.l"


void enter_sgmlgi_context()
{
   BEGIN sgmlgimode;
}


void report_error_location()
{
   if ( commentBufferContentSize > 0 ) {
      cerr << commentBuffer << "\n";
   }
}

void styleerror(char* msg)
{
#ifdef DEBUG
   cerr << "line " << stylelineno << ": " << msg << "\n";
#endif
   throw(CASTSSEXCEPT StyleSheetSyntaxError());
}

