cdesktopenv/cde/programs/dtinfo/DtMmdb/compression/sgml.C

1084 lines
28 KiB
C

/*
* 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:
* $XConsortium: sgml.cc /main/5 1996/08/05 17:05:53 drk $
*/
#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 <unistd.h>
#else
#include <osfcn.h>
#endif
/* use prototypes in function declarations */
#define sgml_USE_PROTOS
/* the "const" storage-class-modifier is valid */
#define sgml_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 sgml_USE_PROTOS
#define sgml_USE_CONST
#endif /* __STDC__ */
#endif /* ! __cplusplus */
#ifdef __TURBOC__
#define sgml_USE_CONST
#endif
#ifndef sgml_USE_CONST
#define const
#endif
#ifdef sgml_USE_PROTOS
#define sgml_PROTO(proto) proto
#else
#define sgml_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 sgml_READ_BUF_SIZE
#define sgml_READ_BUF_SIZE 8192
#endif
/* returned upon end-of-file */
#define sgml_END_TOK 0
/* copy whatever the last rule matched to the standard output */
/* cast to (char *) is because for 8-bit chars, sgmltext 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 *) sgmltext, sgmlleng, 1, sgmlout )
/* gets input and stuffs it into "buf". number of characters read, or sgml_NULL,
* is returned in "result".
*/
#define sgml_INPUT(buf,result,max_size) \
if ( (result = read( fileno(sgmlin), (char *) buf, max_size )) < 0 ) \
sgml_FATAL_ERROR( "read() in flex scanner failed" );
#define sgml_NULL 0
/* no semi-colon after return; correct usage is to write "sgmlterminate();" -
* we don't want an extra ';' after the "return" because that will cause
* some compilers to complain about unreachable statements.
*/
#define sgmlterminate() return ( sgml_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 )
* sgml_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 sgml_FATAL_ERROR() call.
*/
#define sgml_FATAL_ERROR(msg) \
do \
{ \
(void) fputs( msg, stderr ); \
(void) putc( '\n', stderr ); \
exit( 1 ); \
} \
while ( 0 )
/* default sgmlwrap function - always treat EOF as an EOF */
#define sgmlwrap() 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 sgml_start = 1 + 2 *
/* action number for EOF rule of a given start state */
#define sgml_STATE_EOF(state) (sgml_END_OF_BUFFER + state + 1)
/* special action meaning "start processing a new file" */
#define sgml_NEW_FILE \
do \
{ \
sgml_init_buffer( sgml_current_buffer, sgmlin ); \
sgml_load_buffer_state(); \
} \
while ( 0 )
/* default declaration of generated scanner - a define so the user can
* easily add parameters
*/
#define sgml_DECL int sgmllex sgml_PROTO(( void ))
/* code executed at the end of each rule */
#define sgml_BREAK break;
#define sgml_END_OF_BUFFER_CHAR 0
#ifndef sgml_BUF_SIZE
#define sgml_BUF_SIZE (sgml_READ_BUF_SIZE * 2) /* size of default input buffer */
#endif
typedef struct sgml_buffer_state *sgml_BUFFER_STATE;
#define sgml_CHAR unsigned char
# line 1 "sgml.l"
#define INITIAL 0
/*
* $XConsortium: sgml.cc /main/5 1996/08/05 17:05:53 drk $
*
* 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 "sgml.l"
#include "compression/trie.h"
#include "compression/abs_agent.h"
static unsigned char sgmlbuf[LBUFSIZ];
static int sgmlbuf_sz = LBUFSIZ;
static int sgmlbuffed = 0;
#undef sgmlwrap
int sgmlwrap();
#undef sgml_INPUT
#define sgml_INPUT(buf,result,max_size) \
{ \
result = (*fill_buf_func)((unsigned char*)buf,max_size); \
}
# line 59 "sgml.l"
/* done after the current pattern has been matched and before the
* corresponding action - sets up sgmltext
*/
#define sgml_DO_BEFORE_ACTION \
sgmltext = sgml_bp; \
sgmlleng = sgml_cp - sgml_bp; \
sgml_hold_char = *sgml_cp; \
*sgml_cp = '\0'; \
sgml_c_buf_p = sgml_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 sgmlless(n) \
do \
{ \
/* undo effects of setting up sgmltext */ \
*sgml_cp = sgml_hold_char; \
sgml_c_buf_p = sgml_cp = sgml_bp + n; \
sgml_DO_BEFORE_ACTION; /* set up sgmltext again */ \
} \
while ( 0 )
#define unput(c) sgmlunput( c, sgmltext )
struct sgml_buffer_state
{
FILE *sgml_input_file;
sgml_CHAR *sgml_ch_buf; /* input buffer */
sgml_CHAR *sgml_buf_pos; /* current position in input buffer */
/* size of input buffer in bytes, not including room for EOB characters*/
int sgml_buf_size;
/* number of characters read into sgml_ch_buf, not including EOB characters */
int sgml_n_chars;
int sgml_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 sgml_BUFFER_STATE sgml_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 sgml_CURRENT_BUFFER sgml_current_buffer
/* sgml_hold_char holds the character lost when sgmltext is formed */
static sgml_CHAR sgml_hold_char;
static int sgml_n_chars; /* number of characters read into sgml_ch_buf */
#ifndef sgml_USER_ACTION
#define sgml_USER_ACTION
#endif
#ifndef sgml_USER_INIT
#define sgml_USER_INIT
#endif
extern sgml_CHAR *sgmltext;
extern int sgmlleng;
extern FILE *sgmlin, *sgmlout;
sgml_CHAR *sgmltext;
int sgmlleng;
FILE *sgmlin = (FILE *) 0, *sgmlout = (FILE *) 0;
#define sgml_END_OF_BUFFER 4
typedef int sgml_state_type;
static const short int sgml_accept[11] =
{ 0,
0, 0, 4, 2, 2, 0, 0, 1, 0, 0
} ;
static const sgml_CHAR sgml_ec[256] =
{ 0,
1, 1, 1, 1, 1, 1, 1, 1, 1, 2,
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, 3, 3, 3,
3, 3, 3, 3, 3, 3, 3, 1, 1, 5,
1, 6, 1, 1, 3, 3, 3, 3, 3, 3,
3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
1, 1, 1, 1, 3, 1, 3, 3, 3, 3,
3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
3, 3, 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, 1, 1, 1
} ;
static const sgml_CHAR sgml_meta[7] =
{ 0,
1, 1, 2, 1, 1, 1
} ;
static const short int sgml_base[13] =
{ 0,
7, 6, 7, 13, 0, 2, 0, 13, 0, 13,
8, 0
} ;
static const short int sgml_def[13] =
{ 0,
11, 11, 10, 10, 10, 10, 12, 10, 12, 0,
10, 10
} ;
static const short int sgml_nxt[20] =
{ 0,
10, 9, 6, 7, 6, 8, 10, 8, 4, 4,
5, 5, 3, 10, 10, 10, 10, 10, 10
} ;
static const short int sgml_chk[20] =
{ 0,
0, 12, 5, 5, 6, 9, 3, 6, 11, 11,
2, 1, 10, 10, 10, 10, 10, 10, 10
} ;
static sgml_state_type sgml_last_accepting_state;
static sgml_CHAR *sgml_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 sgmlmore() sgmlmore_used_but_not_detected
#define sgml_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 sgml_CHAR *sgml_c_buf_p = (sgml_CHAR *) 0;
static int sgml_init = 1; /* whether we need to initialize */
static int sgml_start = 0; /* start state number */
/* flag which is used to allow sgmlwrap()'s to do buffer switches
* instead of setting up a fresh sgmlin. A bit of a hack ...
*/
static int sgml_did_buffer_switch_on_eof;
static sgml_state_type sgml_get_previous_state sgml_PROTO(( void ));
static sgml_state_type sgml_try_NUL_trans sgml_PROTO(( sgml_state_type current_state ));
static int sgml_get_next_buffer sgml_PROTO(( void ));
#if 0
static void sgmlunput sgml_PROTO(( sgml_CHAR c, sgml_CHAR *buf_ptr ));
#endif
void sgmlrestart sgml_PROTO(( FILE *input_file ));
void sgml_switch_to_buffer sgml_PROTO(( sgml_BUFFER_STATE new_buffer ));
void sgml_load_buffer_state sgml_PROTO(( void ));
sgml_BUFFER_STATE sgml_create_buffer sgml_PROTO(( FILE *file, int size ));
void sgml_delete_buffer sgml_PROTO(( sgml_BUFFER_STATE b ));
void sgml_init_buffer sgml_PROTO(( sgml_BUFFER_STATE b, FILE *file ));
#define sgml_new_buffer sgml_create_buffer
#if 0
#ifdef __cplusplus
static int sgmlinput sgml_PROTO(( void ));
#else
static int input sgml_PROTO(( void ));
#endif
#endif
sgml_DECL
{
sgml_state_type sgml_current_state;
sgml_CHAR *sgml_cp, *sgml_bp;
int sgml_act;
if ( sgml_init )
{
sgml_USER_INIT;
if ( ! sgml_start )
sgml_start = 1; /* first start state */
if ( ! sgmlin )
sgmlin = stdin;
if ( ! sgmlout )
sgmlout = stdout;
if ( sgml_current_buffer )
sgml_init_buffer( sgml_current_buffer, sgmlin );
else
sgml_current_buffer = sgml_create_buffer( sgmlin, sgml_BUF_SIZE );
sgml_load_buffer_state();
sgml_init = 0;
}
while ( 1 ) /* loops until end-of-file is reached */
{
sgml_cp = sgml_c_buf_p;
/* support of sgmltext */
*sgml_cp = sgml_hold_char;
/* sgml_bp points to the position in sgml_ch_buf of the start of the
* current run.
*/
sgml_bp = sgml_cp;
sgml_current_state = sgml_start;
sgml_match:
do
{
sgml_CHAR sgml_c = sgml_ec[*sgml_cp];
if ( sgml_accept[sgml_current_state] )
{
sgml_last_accepting_state = sgml_current_state;
sgml_last_accepting_cpos = sgml_cp;
}
while ( sgml_chk[sgml_base[sgml_current_state] + sgml_c] != sgml_current_state )
{
sgml_current_state = sgml_def[sgml_current_state];
if ( sgml_current_state >= 11 )
sgml_c = sgml_meta[sgml_c];
}
sgml_current_state = sgml_nxt[sgml_base[sgml_current_state] + sgml_c];
++sgml_cp;
}
while ( sgml_current_state != 10 );
sgml_cp = sgml_last_accepting_cpos;
sgml_current_state = sgml_last_accepting_state;
sgml_find_action:
sgml_act = sgml_accept[sgml_current_state];
sgml_DO_BEFORE_ACTION;
sgml_USER_ACTION;
do_action: /* this label is used only to access EOF actions */
switch ( sgml_act )
{
case 0: /* must backtrack */
/* undo the effects of sgml_DO_BEFORE_ACTION */
*sgml_cp = sgml_hold_char;
sgml_cp = sgml_last_accepting_cpos;
sgml_current_state = sgml_last_accepting_state;
goto sgml_find_action;
case 1:
# line 61 "sgml.l"
{
(*lex_action_func)((unsigned char*)(sgmltext), sgmlleng, 1);
}
sgml_BREAK
case 2:
# line 65 "sgml.l"
{
if ( sgmlbuffed >= sgmlbuf_sz ) {
(*lex_action_func)(sgmlbuf, sgmlbuf_sz, 2);
sgmlbuffed = 0;
}
sgmlbuf[sgmlbuffed++] = sgmltext[0];
}
sgml_BREAK
case 3:
# line 75 "sgml.l"
sgml_FATAL_ERROR( "flex scanner jammed" );
sgml_BREAK
case sgml_STATE_EOF(INITIAL):
sgmlterminate();
case sgml_END_OF_BUFFER:
{
/* amount of text matched not including the EOB char */
int sgml_amount_of_matched_text = sgml_cp - sgmltext - 1;
/* undo the effects of sgml_DO_BEFORE_ACTION */
*sgml_cp = sgml_hold_char;
/* note that here we test for sgml_c_buf_p "<=" to the position
* of the first EOB in the buffer, since sgml_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 sgmlinput().
*/
if ( sgml_c_buf_p <= &sgml_current_buffer->sgml_ch_buf[sgml_n_chars] )
/* this was really a NUL */
{
sgml_state_type sgml_next_state;
sgml_c_buf_p = sgmltext + sgml_amount_of_matched_text;
sgml_current_state = sgml_get_previous_state();
/* okay, we're now positioned to make the
* NUL transition. We couldn't have
* sgml_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)
*/
sgml_next_state = sgml_try_NUL_trans( sgml_current_state );
sgml_bp = sgmltext + sgml_MORE_ADJ;
if ( sgml_next_state )
{
/* consume the NUL */
sgml_cp = ++sgml_c_buf_p;
sgml_current_state = sgml_next_state;
goto sgml_match;
}
else
{
sgml_cp = sgml_last_accepting_cpos;
sgml_current_state = sgml_last_accepting_state;
goto sgml_find_action;
}
}
else switch ( sgml_get_next_buffer() )
{
case EOB_ACT_END_OF_FILE:
{
sgml_did_buffer_switch_on_eof = 0;
if ( sgmlwrap() )
{
/* note: because we've taken care in
* sgml_get_next_buffer() to have set up sgmltext,
* we can now set up sgml_c_buf_p so that if some
* total hoser (like flex itself) wants
* to call the scanner after we return the
* sgml_NULL, it'll still work - another sgml_NULL
* will get returned.
*/
sgml_c_buf_p = sgmltext + sgml_MORE_ADJ;
sgml_act = sgml_STATE_EOF((sgml_start - 1) / 2);
goto do_action;
}
else
{
if ( ! sgml_did_buffer_switch_on_eof )
sgml_NEW_FILE;
}
}
break;
case EOB_ACT_CONTINUE_SCAN:
sgml_c_buf_p = sgmltext + sgml_amount_of_matched_text;
sgml_current_state = sgml_get_previous_state();
sgml_cp = sgml_c_buf_p;
sgml_bp = sgmltext + sgml_MORE_ADJ;
goto sgml_match;
case EOB_ACT_LAST_MATCH:
sgml_c_buf_p =
&sgml_current_buffer->sgml_ch_buf[sgml_n_chars];
sgml_current_state = sgml_get_previous_state();
sgml_cp = sgml_c_buf_p;
sgml_bp = sgmltext + sgml_MORE_ADJ;
goto sgml_find_action;
}
break;
}
default:
#ifdef FLEX_DEBUG
printf( "action # %d\n", sgml_act );
#endif
sgml_FATAL_ERROR(
"fatal flex scanner internal error--no action found" );
}
}
}
/* sgml_get_next_buffer - try to read in a new buffer
*
* synopsis
* int sgml_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 sgml_get_next_buffer()
{
sgml_CHAR *dest = sgml_current_buffer->sgml_ch_buf;
sgml_CHAR *source = sgmltext - 1; /* copy prev. char, too */
int number_to_move, i;
int ret_val;
if ( sgml_c_buf_p > &sgml_current_buffer->sgml_ch_buf[sgml_n_chars + 1] )
sgml_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 = sgml_c_buf_p - sgmltext;
for ( i = 0; i < number_to_move; ++i )
*(dest++) = *(source++);
if ( sgml_current_buffer->sgml_eof_status != EOF_NOT_SEEN )
/* don't do the read, it's not guaranteed to return an EOF,
* just force an EOF
*/
sgml_n_chars = 0;
else
{
int num_to_read = sgml_current_buffer->sgml_buf_size - number_to_move - 1;
if ( num_to_read > sgml_READ_BUF_SIZE )
num_to_read = sgml_READ_BUF_SIZE;
else if ( num_to_read <= 0 )
sgml_FATAL_ERROR( "fatal error - scanner input buffer overflow" );
/* read in more data */
sgml_INPUT( (&sgml_current_buffer->sgml_ch_buf[number_to_move]),
sgml_n_chars, num_to_read );
}
if ( sgml_n_chars == 0 )
{
if ( number_to_move == 1 )
{
ret_val = EOB_ACT_END_OF_FILE;
sgml_current_buffer->sgml_eof_status = EOF_DONE;
}
else
{
ret_val = EOB_ACT_LAST_MATCH;
sgml_current_buffer->sgml_eof_status = EOF_PENDING;
}
}
else
ret_val = EOB_ACT_CONTINUE_SCAN;
sgml_n_chars += number_to_move;
sgml_current_buffer->sgml_ch_buf[sgml_n_chars] = sgml_END_OF_BUFFER_CHAR;
sgml_current_buffer->sgml_ch_buf[sgml_n_chars + 1] = sgml_END_OF_BUFFER_CHAR;
/* sgmltext begins at the second character in sgml_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
* sgml_get_previous_state() will have with '^' rules active
*/
sgmltext = &sgml_current_buffer->sgml_ch_buf[1];
return ( ret_val );
}
/* sgml_get_previous_state - get the state just before the EOB char was reached
*
* synopsis
* sgml_state_type sgml_get_previous_state();
*/
static sgml_state_type sgml_get_previous_state()
{
sgml_state_type sgml_current_state;
sgml_CHAR *sgml_cp;
sgml_current_state = sgml_start;
for ( sgml_cp = sgmltext + sgml_MORE_ADJ; sgml_cp < sgml_c_buf_p; ++sgml_cp )
{
sgml_CHAR sgml_c = (*sgml_cp ? sgml_ec[*sgml_cp] : 1);
if ( sgml_accept[sgml_current_state] )
{
sgml_last_accepting_state = sgml_current_state;
sgml_last_accepting_cpos = sgml_cp;
}
while ( sgml_chk[sgml_base[sgml_current_state] + sgml_c] != sgml_current_state )
{
sgml_current_state = sgml_def[sgml_current_state];
if ( sgml_current_state >= 11 )
sgml_c = sgml_meta[sgml_c];
}
sgml_current_state = sgml_nxt[sgml_base[sgml_current_state] + sgml_c];
}
return ( sgml_current_state );
}
/* sgml_try_NUL_trans - try to make a transition on the NUL character
*
* synopsis
* next_state = sgml_try_NUL_trans( current_state );
*/
#ifdef sgml_USE_PROTOS
static sgml_state_type sgml_try_NUL_trans( sgml_state_type sgml_current_state )
#else
static sgml_state_type sgml_try_NUL_trans( sgml_current_state )
sgml_state_type sgml_current_state;
#endif
{
int sgml_is_jam;
sgml_CHAR *sgml_cp = sgml_c_buf_p;
sgml_CHAR sgml_c = 1;
if ( sgml_accept[sgml_current_state] )
{
sgml_last_accepting_state = sgml_current_state;
sgml_last_accepting_cpos = sgml_cp;
}
while ( sgml_chk[sgml_base[sgml_current_state] + sgml_c] != sgml_current_state )
{
sgml_current_state = sgml_def[sgml_current_state];
if ( sgml_current_state >= 11 )
sgml_c = sgml_meta[sgml_c];
}
sgml_current_state = sgml_nxt[sgml_base[sgml_current_state] + sgml_c];
sgml_is_jam = (sgml_current_state == 10);
return ( sgml_is_jam ? 0 : sgml_current_state );
}
#if 0
#ifdef sgml_USE_PROTOS
static void sgmlunput( sgml_CHAR c, sgml_CHAR *sgml_bp )
#else
static void sgmlunput( c, sgml_bp )
sgml_CHAR c;
sgml_CHAR *sgml_bp;
#endif
{
sgml_CHAR *sgml_cp = sgml_c_buf_p;
/* undo effects of setting up sgmltext */
*sgml_cp = sgml_hold_char;
if ( sgml_cp < sgml_current_buffer->sgml_ch_buf + 2 )
{ /* need to shift things up to make room */
int number_to_move = sgml_n_chars + 2; /* +2 for EOB chars */
sgml_CHAR *dest =
&sgml_current_buffer->sgml_ch_buf[sgml_current_buffer->sgml_buf_size + 2];
sgml_CHAR *source =
&sgml_current_buffer->sgml_ch_buf[number_to_move];
while ( source > sgml_current_buffer->sgml_ch_buf )
*--dest = *--source;
sgml_cp += dest - source;
sgml_bp += dest - source;
sgml_n_chars = sgml_current_buffer->sgml_buf_size;
if ( sgml_cp < sgml_current_buffer->sgml_ch_buf + 2 )
sgml_FATAL_ERROR( "flex scanner push-back overflow" );
}
if ( sgml_cp > sgml_bp && sgml_cp[-1] == '\n' )
sgml_cp[-2] = '\n';
*--sgml_cp = c;
/* note: the formal parameter *must* be called "sgml_bp" for this
* macro to now work correctly
*/
sgml_DO_BEFORE_ACTION; /* set up sgmltext again */
}
#endif
#if 0
#ifdef __cplusplus
static int sgmlinput()
#else
static int input()
#endif
{
int c;
sgml_CHAR *sgml_cp = sgml_c_buf_p;
*sgml_cp = sgml_hold_char;
if ( *sgml_c_buf_p == sgml_END_OF_BUFFER_CHAR )
{
/* sgml_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 ( sgml_c_buf_p < &sgml_current_buffer->sgml_ch_buf[sgml_n_chars] )
/* this was really a NUL */
*sgml_c_buf_p = '\0';
else
{ /* need more input */
sgmltext = sgml_c_buf_p;
++sgml_c_buf_p;
switch ( sgml_get_next_buffer() )
{
case EOB_ACT_END_OF_FILE:
{
if ( sgmlwrap() )
{
sgml_c_buf_p = sgmltext + sgml_MORE_ADJ;
return ( EOF );
}
sgml_NEW_FILE;
#ifdef __cplusplus
return ( sgmlinput() );
#else
return ( input() );
#endif
}
break;
case EOB_ACT_CONTINUE_SCAN:
sgml_c_buf_p = sgmltext + sgml_MORE_ADJ;
break;
case EOB_ACT_LAST_MATCH:
#ifdef __cplusplus
sgml_FATAL_ERROR( "unexpected last match in sgmlinput()" );
#else
sgml_FATAL_ERROR( "unexpected last match in input()" );
#endif
}
}
}
c = *sgml_c_buf_p;
sgml_hold_char = *++sgml_c_buf_p;
return ( c );
}
#endif
#ifdef sgml_USE_PROTOS
void sgmlrestart( FILE *input_file )
#else
void sgmlrestart( input_file )
FILE *input_file;
#endif
{
sgml_init_buffer( sgml_current_buffer, input_file );
sgml_load_buffer_state();
}
#ifdef sgml_USE_PROTOS
void sgml_switch_to_buffer( sgml_BUFFER_STATE new_buffer )
#else
void sgml_switch_to_buffer( new_buffer )
sgml_BUFFER_STATE new_buffer;
#endif
{
if ( sgml_current_buffer == new_buffer )
return;
if ( sgml_current_buffer )
{
/* flush out information for old buffer */
*sgml_c_buf_p = sgml_hold_char;
sgml_current_buffer->sgml_buf_pos = sgml_c_buf_p;
sgml_current_buffer->sgml_n_chars = sgml_n_chars;
}
sgml_current_buffer = new_buffer;
sgml_load_buffer_state();
/* we don't actually know whether we did this switch during
* EOF (sgmlwrap()) processing, but the only time this flag
* is looked at is after sgmlwrap() is called, so it's safe
* to go ahead and always set it.
*/
sgml_did_buffer_switch_on_eof = 1;
}
#ifdef sgml_USE_PROTOS
void sgml_load_buffer_state( void )
#else
void sgml_load_buffer_state()
#endif
{
sgml_n_chars = sgml_current_buffer->sgml_n_chars;
sgmltext = sgml_c_buf_p = sgml_current_buffer->sgml_buf_pos;
sgmlin = sgml_current_buffer->sgml_input_file;
sgml_hold_char = *sgml_c_buf_p;
}
#ifdef sgml_USE_PROTOS
sgml_BUFFER_STATE sgml_create_buffer( FILE *file, int size )
#else
sgml_BUFFER_STATE sgml_create_buffer( file, size )
FILE *file;
int size;
#endif
{
sgml_BUFFER_STATE b;
b = (sgml_BUFFER_STATE) malloc( sizeof( struct sgml_buffer_state ) );
if ( ! b )
sgml_FATAL_ERROR( "out of dynamic memory in sgml_create_buffer()" );
b->sgml_buf_size = size;
/* sgml_ch_buf has to be 2 characters longer than the size given because
* we need to put in 2 end-of-buffer characters.
*/
b->sgml_ch_buf = (sgml_CHAR *) malloc( (unsigned) (b->sgml_buf_size + 2) );
if ( ! b->sgml_ch_buf )
sgml_FATAL_ERROR( "out of dynamic memory in sgml_create_buffer()" );
sgml_init_buffer( b, file );
return ( b );
}
#ifdef sgml_USE_PROTOS
void sgml_delete_buffer( sgml_BUFFER_STATE b )
#else
void sgml_delete_buffer( b )
sgml_BUFFER_STATE b;
#endif
{
if ( b == sgml_current_buffer )
sgml_current_buffer = (sgml_BUFFER_STATE) 0;
free( (char *) b->sgml_ch_buf );
free( (char *) b );
}
#ifdef sgml_USE_PROTOS
void sgml_init_buffer( sgml_BUFFER_STATE b, FILE *file )
#else
void sgml_init_buffer( b, file )
sgml_BUFFER_STATE b;
FILE *file;
#endif
{
b->sgml_input_file = file;
/* we put in the '\n' and start reading from [1] so that an
* initial match-at-newline will be true.
*/
b->sgml_ch_buf[0] = '\n';
b->sgml_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->sgml_ch_buf[1] = sgml_END_OF_BUFFER_CHAR;
b->sgml_ch_buf[2] = sgml_END_OF_BUFFER_CHAR;
b->sgml_buf_pos = &b->sgml_ch_buf[1];
b->sgml_eof_status = EOF_NOT_SEEN;
}
# line 75 "sgml.l"
int sgmlwrap()
{
(*lex_action_func)(sgmlbuf, sgmlbuffed, 2);
return 1;
}