2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
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)
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
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these librararies and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
23 /* A lexical scanner generated by flex */
25 /* scanner skeleton version:
26 * $XConsortium: sgml.cc /main/5 1996/08/05 17:05:53 drk $
34 /* cfront 1.2 defines "c_plusplus" instead of "__cplusplus" */
46 #if defined(__osf__) || defined(linux) || defined(CSRG_BASED)
49 #if !defined(__uxp__) && !defined(USL)
54 /* use prototypes in function declarations */
55 #define sgml_USE_PROTOS
57 /* the "const" storage-class-modifier is valid */
58 #define sgml_USE_CONST
60 #else /* ! __cplusplus */
66 void *malloc( size_t );
72 #define sgml_USE_PROTOS
73 #define sgml_USE_CONST
76 #endif /* ! __cplusplus */
80 #define sgml_USE_CONST
84 #ifndef sgml_USE_CONST
89 #ifdef sgml_USE_PROTOS
90 #define sgml_PROTO(proto) proto
92 #define sgml_PROTO(proto) ()
93 /* we can't get here if it's an ANSI C compiler, or a C++ compiler,
94 * so it's got to be a K&R compiler, and therefore there's no standard
95 * place from which to include these definitions
103 /* amount of stuff to slurp up with each read */
104 #ifndef sgml_READ_BUF_SIZE
105 #define sgml_READ_BUF_SIZE 8192
108 /* returned upon end-of-file */
109 #define sgml_END_TOK 0
111 /* copy whatever the last rule matched to the standard output */
113 /* cast to (char *) is because for 8-bit chars, sgmltext is (unsigned char *) */
114 /* this used to be an fputs(), but since the string might contain NUL's,
115 * we now use fwrite()
117 #define ECHO (void) fwrite( (char *) sgmltext, sgmlleng, 1, sgmlout )
119 /* gets input and stuffs it into "buf". number of characters read, or sgml_NULL,
120 * is returned in "result".
122 #define sgml_INPUT(buf,result,max_size) \
123 if ( (result = read( fileno(sgmlin), (char *) buf, max_size )) < 0 ) \
124 sgml_FATAL_ERROR( "read() in flex scanner failed" );
127 /* no semi-colon after return; correct usage is to write "sgmlterminate();" -
128 * we don't want an extra ';' after the "return" because that will cause
129 * some compilers to complain about unreachable statements.
131 #define sgmlterminate() return ( sgml_NULL )
133 /* report a fatal error */
135 /* The funky do-while is used to turn this macro definition into
136 * a single C statement (which needs a semi-colon terminator).
137 * This avoids problems with code like:
139 * if ( something_happens )
140 * sgml_FATAL_ERROR( "oops, the something happened" );
144 * Prior to using the do-while the compiler would get upset at the
145 * "else" because it interpreted the "if" statement as being all
146 * done when it reached the ';' after the sgml_FATAL_ERROR() call.
149 #define sgml_FATAL_ERROR(msg) \
152 (void) fputs( msg, stderr ); \
153 (void) putc( '\n', stderr ); \
158 /* default sgmlwrap function - always treat EOF as an EOF */
161 /* enter a start condition. This macro really ought to take a parameter,
162 * but we do it the disgusting crufty way forced on us by the ()-less
163 * definition of BEGIN
165 #define BEGIN sgml_start = 1 + 2 *
167 /* action number for EOF rule of a given start state */
168 #define sgml_STATE_EOF(state) (sgml_END_OF_BUFFER + state + 1)
170 /* special action meaning "start processing a new file" */
171 #define sgml_NEW_FILE \
174 sgml_init_buffer( sgml_current_buffer, sgmlin ); \
175 sgml_load_buffer_state(); \
179 /* default declaration of generated scanner - a define so the user can
180 * easily add parameters
182 #define sgml_DECL int sgmllex sgml_PROTO(( void ))
184 /* code executed at the end of each rule */
185 #define sgml_BREAK break;
187 #define sgml_END_OF_BUFFER_CHAR 0
189 #ifndef sgml_BUF_SIZE
190 #define sgml_BUF_SIZE (sgml_READ_BUF_SIZE * 2) /* size of default input buffer */
193 typedef struct sgml_buffer_state *sgml_BUFFER_STATE;
195 #define sgml_CHAR unsigned char
199 * $XConsortium: sgml.cc /main/5 1996/08/05 17:05:53 drk $
201 * Copyright (c) 1993 HAL Computer Systems International, Ltd.
202 * All rights reserved. Unpublished -- rights reserved under
203 * the Copyright Laws of the United States. USE OF A COPYRIGHT
204 * NOTICE IS PRECAUTIONARY ONLY AND DOES NOT IMPLY PUBLICATION
207 * THIS SOFTWARE CONTAINS CONFIDENTIAL INFORMATION AND TRADE
208 * SECRETS OF HAL COMPUTER SYSTEMS INTERNATIONAL, LTD. USE,
209 * DISCLOSURE, OR REPRODUCTION IS PROHIBITED WITHOUT THE
210 * PRIOR EXPRESS WRITTEN PERMISSION OF HAL COMPUTER SYSTEMS
211 * INTERNATIONAL, LTD.
213 * RESTRICTED RIGHTS LEGEND
214 * Use, duplication, or disclosure by the Government is subject
215 * to the restrictions as set forth in subparagraph (c)(l)(ii)
216 * of the Rights in Technical Data and Computer Software clause
217 * at DFARS 252.227-7013.
219 * HAL COMPUTER SYSTEMS INTERNATIONAL, LTD.
226 #include "compression/trie.h"
227 #include "compression/abs_agent.h"
230 static unsigned char sgmlbuf[LBUFSIZ];
231 static int sgmlbuf_sz = LBUFSIZ;
232 static int sgmlbuffed = 0;
239 #define sgml_INPUT(buf,result,max_size) \
241 result = (*fill_buf_func)((unsigned char*)buf,max_size); \
247 /* done after the current pattern has been matched and before the
248 * corresponding action - sets up sgmltext
250 #define sgml_DO_BEFORE_ACTION \
251 sgmltext = sgml_bp; \
252 sgmlleng = sgml_cp - sgml_bp; \
253 sgml_hold_char = *sgml_cp; \
255 sgml_c_buf_p = sgml_cp;
257 #define EOB_ACT_CONTINUE_SCAN 0
258 #define EOB_ACT_END_OF_FILE 1
259 #define EOB_ACT_LAST_MATCH 2
261 /* return all but the first 'n' matched characters back to the input stream */
262 #define sgmlless(n) \
265 /* undo effects of setting up sgmltext */ \
266 *sgml_cp = sgml_hold_char; \
267 sgml_c_buf_p = sgml_cp = sgml_bp + n; \
268 sgml_DO_BEFORE_ACTION; /* set up sgmltext again */ \
272 #define unput(c) sgmlunput( c, sgmltext )
275 struct sgml_buffer_state
277 FILE *sgml_input_file;
279 sgml_CHAR *sgml_ch_buf; /* input buffer */
280 sgml_CHAR *sgml_buf_pos; /* current position in input buffer */
282 /* size of input buffer in bytes, not including room for EOB characters*/
285 /* number of characters read into sgml_ch_buf, not including EOB characters */
288 int sgml_eof_status; /* whether we've seen an EOF on this buffer */
289 #define EOF_NOT_SEEN 0
290 /* "pending" happens when the EOF has been seen but there's still
293 #define EOF_PENDING 1
297 static sgml_BUFFER_STATE sgml_current_buffer;
299 /* we provide macros for accessing buffer states in case in the
300 * future we want to put the buffer states in a more general
303 #define sgml_CURRENT_BUFFER sgml_current_buffer
306 /* sgml_hold_char holds the character lost when sgmltext is formed */
307 static sgml_CHAR sgml_hold_char;
309 static int sgml_n_chars; /* number of characters read into sgml_ch_buf */
313 #ifndef sgml_USER_ACTION
314 #define sgml_USER_ACTION
317 #ifndef sgml_USER_INIT
318 #define sgml_USER_INIT
321 extern sgml_CHAR *sgmltext;
323 extern FILE *sgmlin, *sgmlout;
328 FILE *sgmlin = (FILE *) 0, *sgmlout = (FILE *) 0;
330 #define sgml_END_OF_BUFFER 4
331 typedef int sgml_state_type;
332 static const short int sgml_accept[11] =
334 0, 0, 4, 2, 2, 0, 0, 1, 0, 0
337 static const sgml_CHAR sgml_ec[256] =
339 1, 1, 1, 1, 1, 1, 1, 1, 1, 2,
340 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
341 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
342 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
343 1, 1, 1, 1, 1, 3, 4, 3, 3, 3,
344 3, 3, 3, 3, 3, 3, 3, 1, 1, 5,
345 1, 6, 1, 1, 3, 3, 3, 3, 3, 3,
346 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
347 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
348 1, 1, 1, 1, 3, 1, 3, 3, 3, 3,
350 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
351 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
352 3, 3, 1, 1, 1, 1, 1, 1, 1, 1,
353 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
354 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
355 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
356 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
357 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
358 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
359 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
361 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
362 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
363 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
364 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
365 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
369 static const sgml_CHAR sgml_meta[7] =
374 static const short int sgml_base[13] =
376 7, 6, 7, 13, 0, 2, 0, 13, 0, 13,
380 static const short int sgml_def[13] =
382 11, 11, 10, 10, 10, 10, 12, 10, 12, 0,
386 static const short int sgml_nxt[20] =
388 10, 9, 6, 7, 6, 8, 10, 8, 4, 4,
389 5, 5, 3, 10, 10, 10, 10, 10, 10
392 static const short int sgml_chk[20] =
394 0, 12, 5, 5, 6, 9, 3, 6, 11, 11,
395 2, 1, 10, 10, 10, 10, 10, 10, 10
398 static sgml_state_type sgml_last_accepting_state;
399 static sgml_CHAR *sgml_last_accepting_cpos;
401 /* the intent behind this definition is that it'll catch
402 * any uses of REJECT which flex missed
404 #define REJECT reject_used_but_not_detected
405 #define sgmlmore() sgmlmore_used_but_not_detected
406 #define sgml_MORE_ADJ 0
408 /* these variables are all declared out here so that section 3 code can
411 /* points to current character in buffer */
412 static sgml_CHAR *sgml_c_buf_p = (sgml_CHAR *) 0;
413 static int sgml_init = 1; /* whether we need to initialize */
414 static int sgml_start = 0; /* start state number */
416 /* flag which is used to allow sgmlwrap()'s to do buffer switches
417 * instead of setting up a fresh sgmlin. A bit of a hack ...
419 static int sgml_did_buffer_switch_on_eof;
421 static sgml_state_type sgml_get_previous_state sgml_PROTO(( void ));
422 static sgml_state_type sgml_try_NUL_trans sgml_PROTO(( sgml_state_type current_state ));
423 static int sgml_get_next_buffer sgml_PROTO(( void ));
425 static void sgmlunput sgml_PROTO(( sgml_CHAR c, sgml_CHAR *buf_ptr ));
427 void sgmlrestart sgml_PROTO(( FILE *input_file ));
428 void sgml_switch_to_buffer sgml_PROTO(( sgml_BUFFER_STATE new_buffer ));
429 void sgml_load_buffer_state sgml_PROTO(( void ));
430 sgml_BUFFER_STATE sgml_create_buffer sgml_PROTO(( FILE *file, int size ));
431 void sgml_delete_buffer sgml_PROTO(( sgml_BUFFER_STATE b ));
432 void sgml_init_buffer sgml_PROTO(( sgml_BUFFER_STATE b, FILE *file ));
434 #define sgml_new_buffer sgml_create_buffer
438 static int sgmlinput sgml_PROTO(( void ));
440 static int input sgml_PROTO(( void ));
446 register sgml_state_type sgml_current_state;
447 register sgml_CHAR *sgml_cp, *sgml_bp;
448 register int sgml_act;
458 sgml_start = 1; /* first start state */
466 if ( sgml_current_buffer )
467 sgml_init_buffer( sgml_current_buffer, sgmlin );
469 sgml_current_buffer = sgml_create_buffer( sgmlin, sgml_BUF_SIZE );
471 sgml_load_buffer_state();
476 while ( 1 ) /* loops until end-of-file is reached */
478 sgml_cp = sgml_c_buf_p;
480 /* support of sgmltext */
481 *sgml_cp = sgml_hold_char;
483 /* sgml_bp points to the position in sgml_ch_buf of the start of the
488 sgml_current_state = sgml_start;
492 register sgml_CHAR sgml_c = sgml_ec[*sgml_cp];
493 if ( sgml_accept[sgml_current_state] )
495 sgml_last_accepting_state = sgml_current_state;
496 sgml_last_accepting_cpos = sgml_cp;
498 while ( sgml_chk[sgml_base[sgml_current_state] + sgml_c] != sgml_current_state )
500 sgml_current_state = sgml_def[sgml_current_state];
501 if ( sgml_current_state >= 11 )
502 sgml_c = sgml_meta[sgml_c];
504 sgml_current_state = sgml_nxt[sgml_base[sgml_current_state] + sgml_c];
507 while ( sgml_current_state != 10 );
508 sgml_cp = sgml_last_accepting_cpos;
509 sgml_current_state = sgml_last_accepting_state;
512 sgml_act = sgml_accept[sgml_current_state];
514 sgml_DO_BEFORE_ACTION;
517 do_action: /* this label is used only to access EOF actions */
522 case 0: /* must backtrack */
523 /* undo the effects of sgml_DO_BEFORE_ACTION */
524 *sgml_cp = sgml_hold_char;
525 sgml_cp = sgml_last_accepting_cpos;
526 sgml_current_state = sgml_last_accepting_state;
527 goto sgml_find_action;
532 (*lex_action_func)((unsigned char*)(sgmltext), sgmlleng, 1);
538 if ( sgmlbuffed >= sgmlbuf_sz ) {
539 (*lex_action_func)(sgmlbuf, sgmlbuf_sz, 2);
543 sgmlbuf[sgmlbuffed++] = sgmltext[0];
548 sgml_FATAL_ERROR( "flex scanner jammed" );
550 case sgml_STATE_EOF(INITIAL):
553 case sgml_END_OF_BUFFER:
555 /* amount of text matched not including the EOB char */
556 int sgml_amount_of_matched_text = sgml_cp - sgmltext - 1;
558 /* undo the effects of sgml_DO_BEFORE_ACTION */
559 *sgml_cp = sgml_hold_char;
561 /* note that here we test for sgml_c_buf_p "<=" to the position
562 * of the first EOB in the buffer, since sgml_c_buf_p will
563 * already have been incremented past the NUL character
564 * (since all states make transitions on EOB to the end-
565 * of-buffer state). Contrast this with the test in sgmlinput().
567 if ( sgml_c_buf_p <= &sgml_current_buffer->sgml_ch_buf[sgml_n_chars] )
568 /* this was really a NUL */
570 sgml_state_type sgml_next_state;
572 sgml_c_buf_p = sgmltext + sgml_amount_of_matched_text;
574 sgml_current_state = sgml_get_previous_state();
576 /* okay, we're now positioned to make the
577 * NUL transition. We couldn't have
578 * sgml_get_previous_state() go ahead and do it
579 * for us because it doesn't know how to deal
580 * with the possibility of jamming (and we
581 * don't want to build jamming into it because
582 * then it will run more slowly)
585 sgml_next_state = sgml_try_NUL_trans( sgml_current_state );
587 sgml_bp = sgmltext + sgml_MORE_ADJ;
589 if ( sgml_next_state )
591 /* consume the NUL */
592 sgml_cp = ++sgml_c_buf_p;
593 sgml_current_state = sgml_next_state;
599 sgml_cp = sgml_last_accepting_cpos;
600 sgml_current_state = sgml_last_accepting_state;
601 goto sgml_find_action;
605 else switch ( sgml_get_next_buffer() )
607 case EOB_ACT_END_OF_FILE:
609 sgml_did_buffer_switch_on_eof = 0;
613 /* note: because we've taken care in
614 * sgml_get_next_buffer() to have set up sgmltext,
615 * we can now set up sgml_c_buf_p so that if some
616 * total hoser (like flex itself) wants
617 * to call the scanner after we return the
618 * sgml_NULL, it'll still work - another sgml_NULL
621 sgml_c_buf_p = sgmltext + sgml_MORE_ADJ;
623 sgml_act = sgml_STATE_EOF((sgml_start - 1) / 2);
629 if ( ! sgml_did_buffer_switch_on_eof )
635 case EOB_ACT_CONTINUE_SCAN:
636 sgml_c_buf_p = sgmltext + sgml_amount_of_matched_text;
638 sgml_current_state = sgml_get_previous_state();
640 sgml_cp = sgml_c_buf_p;
641 sgml_bp = sgmltext + sgml_MORE_ADJ;
644 case EOB_ACT_LAST_MATCH:
646 &sgml_current_buffer->sgml_ch_buf[sgml_n_chars];
648 sgml_current_state = sgml_get_previous_state();
650 sgml_cp = sgml_c_buf_p;
651 sgml_bp = sgmltext + sgml_MORE_ADJ;
652 goto sgml_find_action;
659 printf( "action # %d\n", sgml_act );
662 "fatal flex scanner internal error--no action found" );
668 /* sgml_get_next_buffer - try to read in a new buffer
671 * int sgml_get_next_buffer();
673 * returns a code representing an action
674 * EOB_ACT_LAST_MATCH -
675 * EOB_ACT_CONTINUE_SCAN - continue scanning from current position
676 * EOB_ACT_END_OF_FILE - end of file
679 static int sgml_get_next_buffer()
682 register sgml_CHAR *dest = sgml_current_buffer->sgml_ch_buf;
683 register sgml_CHAR *source = sgmltext - 1; /* copy prev. char, too */
684 register int number_to_move, i;
687 if ( sgml_c_buf_p > &sgml_current_buffer->sgml_ch_buf[sgml_n_chars + 1] )
689 "fatal flex scanner internal error--end of buffer missed" );
691 /* try to read more data */
693 /* first move last chars to start of buffer */
694 number_to_move = sgml_c_buf_p - sgmltext;
696 for ( i = 0; i < number_to_move; ++i )
697 *(dest++) = *(source++);
699 if ( sgml_current_buffer->sgml_eof_status != EOF_NOT_SEEN )
700 /* don't do the read, it's not guaranteed to return an EOF,
707 int num_to_read = sgml_current_buffer->sgml_buf_size - number_to_move - 1;
709 if ( num_to_read > sgml_READ_BUF_SIZE )
710 num_to_read = sgml_READ_BUF_SIZE;
712 else if ( num_to_read <= 0 )
713 sgml_FATAL_ERROR( "fatal error - scanner input buffer overflow" );
715 /* read in more data */
716 sgml_INPUT( (&sgml_current_buffer->sgml_ch_buf[number_to_move]),
717 sgml_n_chars, num_to_read );
720 if ( sgml_n_chars == 0 )
722 if ( number_to_move == 1 )
724 ret_val = EOB_ACT_END_OF_FILE;
725 sgml_current_buffer->sgml_eof_status = EOF_DONE;
730 ret_val = EOB_ACT_LAST_MATCH;
731 sgml_current_buffer->sgml_eof_status = EOF_PENDING;
736 ret_val = EOB_ACT_CONTINUE_SCAN;
738 sgml_n_chars += number_to_move;
739 sgml_current_buffer->sgml_ch_buf[sgml_n_chars] = sgml_END_OF_BUFFER_CHAR;
740 sgml_current_buffer->sgml_ch_buf[sgml_n_chars + 1] = sgml_END_OF_BUFFER_CHAR;
742 /* sgmltext begins at the second character in sgml_ch_buf; the first
743 * character is the one which preceded it before reading in the latest
744 * buffer; it needs to be kept around in case it's a newline, so
745 * sgml_get_previous_state() will have with '^' rules active
748 sgmltext = &sgml_current_buffer->sgml_ch_buf[1];
754 /* sgml_get_previous_state - get the state just before the EOB char was reached
757 * sgml_state_type sgml_get_previous_state();
760 static sgml_state_type sgml_get_previous_state()
763 register sgml_state_type sgml_current_state;
764 register sgml_CHAR *sgml_cp;
766 sgml_current_state = sgml_start;
768 for ( sgml_cp = sgmltext + sgml_MORE_ADJ; sgml_cp < sgml_c_buf_p; ++sgml_cp )
770 register sgml_CHAR sgml_c = (*sgml_cp ? sgml_ec[*sgml_cp] : 1);
771 if ( sgml_accept[sgml_current_state] )
773 sgml_last_accepting_state = sgml_current_state;
774 sgml_last_accepting_cpos = sgml_cp;
776 while ( sgml_chk[sgml_base[sgml_current_state] + sgml_c] != sgml_current_state )
778 sgml_current_state = sgml_def[sgml_current_state];
779 if ( sgml_current_state >= 11 )
780 sgml_c = sgml_meta[sgml_c];
782 sgml_current_state = sgml_nxt[sgml_base[sgml_current_state] + sgml_c];
785 return ( sgml_current_state );
789 /* sgml_try_NUL_trans - try to make a transition on the NUL character
792 * next_state = sgml_try_NUL_trans( current_state );
795 #ifdef sgml_USE_PROTOS
796 static sgml_state_type sgml_try_NUL_trans( register sgml_state_type sgml_current_state )
798 static sgml_state_type sgml_try_NUL_trans( sgml_current_state )
799 register sgml_state_type sgml_current_state;
803 register int sgml_is_jam;
804 register sgml_CHAR *sgml_cp = sgml_c_buf_p;
806 register sgml_CHAR sgml_c = 1;
807 if ( sgml_accept[sgml_current_state] )
809 sgml_last_accepting_state = sgml_current_state;
810 sgml_last_accepting_cpos = sgml_cp;
812 while ( sgml_chk[sgml_base[sgml_current_state] + sgml_c] != sgml_current_state )
814 sgml_current_state = sgml_def[sgml_current_state];
815 if ( sgml_current_state >= 11 )
816 sgml_c = sgml_meta[sgml_c];
818 sgml_current_state = sgml_nxt[sgml_base[sgml_current_state] + sgml_c];
819 sgml_is_jam = (sgml_current_state == 10);
821 return ( sgml_is_jam ? 0 : sgml_current_state );
826 #ifdef sgml_USE_PROTOS
827 static void sgmlunput( sgml_CHAR c, register sgml_CHAR *sgml_bp )
829 static void sgmlunput( c, sgml_bp )
831 register sgml_CHAR *sgml_bp;
835 register sgml_CHAR *sgml_cp = sgml_c_buf_p;
837 /* undo effects of setting up sgmltext */
838 *sgml_cp = sgml_hold_char;
840 if ( sgml_cp < sgml_current_buffer->sgml_ch_buf + 2 )
841 { /* need to shift things up to make room */
842 register int number_to_move = sgml_n_chars + 2; /* +2 for EOB chars */
843 register sgml_CHAR *dest =
844 &sgml_current_buffer->sgml_ch_buf[sgml_current_buffer->sgml_buf_size + 2];
845 register sgml_CHAR *source =
846 &sgml_current_buffer->sgml_ch_buf[number_to_move];
848 while ( source > sgml_current_buffer->sgml_ch_buf )
851 sgml_cp += dest - source;
852 sgml_bp += dest - source;
853 sgml_n_chars = sgml_current_buffer->sgml_buf_size;
855 if ( sgml_cp < sgml_current_buffer->sgml_ch_buf + 2 )
856 sgml_FATAL_ERROR( "flex scanner push-back overflow" );
859 if ( sgml_cp > sgml_bp && sgml_cp[-1] == '\n' )
864 /* note: the formal parameter *must* be called "sgml_bp" for this
865 * macro to now work correctly
867 sgml_DO_BEFORE_ACTION; /* set up sgmltext again */
874 static int sgmlinput()
881 sgml_CHAR *sgml_cp = sgml_c_buf_p;
883 *sgml_cp = sgml_hold_char;
885 if ( *sgml_c_buf_p == sgml_END_OF_BUFFER_CHAR )
887 /* sgml_c_buf_p now points to the character we want to return.
888 * If this occurs *before* the EOB characters, then it's a
889 * valid NUL; if not, then we've hit the end of the buffer.
891 if ( sgml_c_buf_p < &sgml_current_buffer->sgml_ch_buf[sgml_n_chars] )
892 /* this was really a NUL */
893 *sgml_c_buf_p = '\0';
896 { /* need more input */
897 sgmltext = sgml_c_buf_p;
900 switch ( sgml_get_next_buffer() )
902 case EOB_ACT_END_OF_FILE:
906 sgml_c_buf_p = sgmltext + sgml_MORE_ADJ;
913 return ( sgmlinput() );
920 case EOB_ACT_CONTINUE_SCAN:
921 sgml_c_buf_p = sgmltext + sgml_MORE_ADJ;
924 case EOB_ACT_LAST_MATCH:
926 sgml_FATAL_ERROR( "unexpected last match in sgmlinput()" );
928 sgml_FATAL_ERROR( "unexpected last match in input()" );
935 sgml_hold_char = *++sgml_c_buf_p;
942 #ifdef sgml_USE_PROTOS
943 void sgmlrestart( FILE *input_file )
945 void sgmlrestart( input_file )
950 sgml_init_buffer( sgml_current_buffer, input_file );
951 sgml_load_buffer_state();
955 #ifdef sgml_USE_PROTOS
956 void sgml_switch_to_buffer( sgml_BUFFER_STATE new_buffer )
958 void sgml_switch_to_buffer( new_buffer )
959 sgml_BUFFER_STATE new_buffer;
963 if ( sgml_current_buffer == new_buffer )
966 if ( sgml_current_buffer )
968 /* flush out information for old buffer */
969 *sgml_c_buf_p = sgml_hold_char;
970 sgml_current_buffer->sgml_buf_pos = sgml_c_buf_p;
971 sgml_current_buffer->sgml_n_chars = sgml_n_chars;
974 sgml_current_buffer = new_buffer;
975 sgml_load_buffer_state();
977 /* we don't actually know whether we did this switch during
978 * EOF (sgmlwrap()) processing, but the only time this flag
979 * is looked at is after sgmlwrap() is called, so it's safe
980 * to go ahead and always set it.
982 sgml_did_buffer_switch_on_eof = 1;
986 #ifdef sgml_USE_PROTOS
987 void sgml_load_buffer_state( void )
989 void sgml_load_buffer_state()
993 sgml_n_chars = sgml_current_buffer->sgml_n_chars;
994 sgmltext = sgml_c_buf_p = sgml_current_buffer->sgml_buf_pos;
995 sgmlin = sgml_current_buffer->sgml_input_file;
996 sgml_hold_char = *sgml_c_buf_p;
1000 #ifdef sgml_USE_PROTOS
1001 sgml_BUFFER_STATE sgml_create_buffer( FILE *file, int size )
1003 sgml_BUFFER_STATE sgml_create_buffer( file, size )
1009 sgml_BUFFER_STATE b;
1011 b = (sgml_BUFFER_STATE) malloc( sizeof( struct sgml_buffer_state ) );
1014 sgml_FATAL_ERROR( "out of dynamic memory in sgml_create_buffer()" );
1016 b->sgml_buf_size = size;
1018 /* sgml_ch_buf has to be 2 characters longer than the size given because
1019 * we need to put in 2 end-of-buffer characters.
1021 b->sgml_ch_buf = (sgml_CHAR *) malloc( (unsigned) (b->sgml_buf_size + 2) );
1023 if ( ! b->sgml_ch_buf )
1024 sgml_FATAL_ERROR( "out of dynamic memory in sgml_create_buffer()" );
1026 sgml_init_buffer( b, file );
1032 #ifdef sgml_USE_PROTOS
1033 void sgml_delete_buffer( sgml_BUFFER_STATE b )
1035 void sgml_delete_buffer( b )
1036 sgml_BUFFER_STATE b;
1040 if ( b == sgml_current_buffer )
1041 sgml_current_buffer = (sgml_BUFFER_STATE) 0;
1043 free( (char *) b->sgml_ch_buf );
1048 #ifdef sgml_USE_PROTOS
1049 void sgml_init_buffer( sgml_BUFFER_STATE b, FILE *file )
1051 void sgml_init_buffer( b, file )
1052 sgml_BUFFER_STATE b;
1057 b->sgml_input_file = file;
1059 /* we put in the '\n' and start reading from [1] so that an
1060 * initial match-at-newline will be true.
1063 b->sgml_ch_buf[0] = '\n';
1064 b->sgml_n_chars = 1;
1066 /* we always need two end-of-buffer characters. The first causes
1067 * a transition to the end-of-buffer state. The second causes
1068 * a jam in that state.
1070 b->sgml_ch_buf[1] = sgml_END_OF_BUFFER_CHAR;
1071 b->sgml_ch_buf[2] = sgml_END_OF_BUFFER_CHAR;
1073 b->sgml_buf_pos = &b->sgml_ch_buf[1];
1075 b->sgml_eof_status = EOF_NOT_SEEN;
1082 (*lex_action_func)(sgmlbuf, sgmlbuffed, 2);