#ifdef YY_USE_PROTOS
#define YY_PROTO(proto) proto
#else
#define YY_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 YY_READ_BUF_SIZE
#define YY_READ_BUF_SIZE 8192
#endif
/* returned upon end-of-file */
#define YY_END_TOK 0
/* copy whatever the last rule matched to the standard output */
/* cast to (char *) is because for 8-bit chars, yytext 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 *) yytext, yyleng, 1, yyout )
/* gets input and stuffs it into "buf". number of characters read, or YY_NULL,
* is returned in "result".
*/
#define YY_INPUT(buf,result,max_size) \
if ( (result = read( fileno(yyin), (char *) buf, max_size )) < 0 ) \
YY_FATAL_ERROR( "read() in flex scanner failed" );
#define YY_NULL 0
/* no semi-colon after return; correct usage is to write "yyterminate();" -
* we don't want an extra ';' after the "return" because that will cause
* some compilers to complain about unreachable statements.
*/
#define yyterminate() return ( YY_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 )
* YY_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 YY_FATAL_ERROR() call.
*/
/* default yywrap function - always treat EOF as an EOF */
#define yywrap() 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 yy_start = 1 + 2 *
/* action number for EOF rule of a given start state */
#define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1)
/* special action meaning "start processing a new file" */
#define YY_NEW_FILE \
do \
{ \
yy_init_buffer( yy_current_buffer, yyin ); \
yy_load_buffer_state(); \
} \
while ( 0 )
/* default declaration of generated scanner - a define so the user can
* easily add parameters
*/
#define YY_DECL int yylex YY_PROTO(( void ))
/* code executed at the end of each rule */
#define YY_BREAK break;
#define YY_CHAR char
# line 1 "l2x.l"
#define INITIAL 0
# line 2 "l2x.l"
/*
* l2x.l --- (flex) lexer for converting a LaTeX file to X
* Written by Peter Wilson (Catholic University and NIST)
* Version 0.2, January 1995
* Revised July 1996
* -- replace myprint(tag) by tag_print(tag)
* -- added verb(atim) like capability
*/
/* Development of this software was funded by the United States Government,
* and is not subject to copyright.
*/
#include <string.h>
#ifndef STRTYPES_H
#include "strtypes.h"
#endif
#ifndef L2XCOM_H
#include "l2xcom.h"
#endif
#include "l2xytab.h" /* token codes from parser */
#include "l2xlib.h" /* functions and global variables */
#include "l2xusrlb.h" /* possibly useful strings and user-defined functions */
extern int opt_param;
extern int all_opt;
extern int opt_coord;
int got_opt_item = FALSE;
int got_a_dollar = FALSE;
int got_opt_param = FALSE;
int got_all_opt = FALSE;
int got_opt_coord = FALSE;
char verb_char; /* delimeter for \verb command */
int result;
int kind;
int special_kind;
PSENTRY ptr; /* pointer to sym entry */
int nl_count = 0; /* number of consecutive new lines */
char a_newline[] = "\n";
char a_space[] = " ";
char vlenv[80]; /* name of verbatim-like environment */
int nopen_vbrace = 0; /* no of unmatched open braces after verb-like command */
int nopen_noop = 0; /* no of unmatched openers for no_op argument */
#define NOOPLBRAK 1
#define NOOPRBRAK 1
#define NOOPLBRACE 2
#define NOOPRBRACE 2
int noop_openc; /* noop argument opening character ( [ or { )*/
#define LDA -1
#define LD0 0
#define LD1 1
#define LD2 2
#define LD3 3
#define LD4 4
#define LD5 5
#define LD6 6
/*
* LDEBUG > LDA: error prints:
* > LD0: names not in command table
* > LD1: newlines, returned useful tokens
* > LD2: general tokens
* > LD3: text dealt with in lexer
* > LD4: comments
* > LD5: stuff within verbatims
* > LD6:
*
*/
/* whitespace and comments */
/* TeX comments from % through eol + any following whitespace */
/* general REs */
/* (La)TeX literals */
/* general LaTeX commands */
/* list items */
#define VERBATIM_STATE 1
#define VERB_STATE 2
#define VERBATIM_LIKE 3
#define VERB_LIKE 4
#define NOOP 5
# line 122 "l2x.l"
/* done after the current pattern has been matched and before the
* corresponding action - sets up yytext
*/
#define YY_DO_BEFORE_ACTION \
yytext = yy_bp; \
yyleng = yy_cp - yy_bp; \
yy_hold_char = *yy_cp; \
*yy_cp = '\0'; \
yy_c_buf_p = yy_cp;
/* return all but the first 'n' matched characters back to the input stream */
#define yyless(n) \
do \
{ \
/* undo effects of setting up yytext */ \
*yy_cp = yy_hold_char; \
yy_c_buf_p = yy_cp = yy_bp + n; \
YY_DO_BEFORE_ACTION; /* set up yytext again */ \
} \
while ( 0 )
#define unput(c) yyunput( c, yytext )
struct yy_buffer_state
{
FILE *yy_input_file;
YY_CHAR *yy_ch_buf; /* input buffer */
YY_CHAR *yy_buf_pos; /* current position in input buffer */
/* size of input buffer in bytes, not including room for EOB characters*/
int yy_buf_size;
/* number of characters read into yy_ch_buf, not including EOB characters */
int yy_n_chars;
int yy_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 YY_BUFFER_STATE yy_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 YY_CURRENT_BUFFER yy_current_buffer
/* yy_hold_char holds the character lost when yytext is formed */
static YY_CHAR yy_hold_char;
static int yy_n_chars; /* number of characters read into yy_ch_buf */
/* 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 yymore() yymore_used_but_not_detected
#define YY_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 YY_CHAR *yy_c_buf_p = (YY_CHAR *) 0;
static int yy_init = 1; /* whether we need to initialize */
static int yy_start = 0; /* start state number */
/* flag which is used to allow yywrap()'s to do buffer switches
* instead of setting up a fresh yyin. A bit of a hack ...
*/
static int yy_did_buffer_switch_on_eof;
do_action: /* this label is used only to access EOF actions */
switch ( yy_act )
{
case 0: /* must backtrack */
/* undo the effects of YY_DO_BEFORE_ACTION */
*yy_cp = yy_hold_char;
yy_cp = yy_last_accepting_cpos;
yy_current_state = yy_last_accepting_state;
goto yy_find_action;
case 1:
# line 126 "l2x.l"
{
if (LDEBUG > LD4) {
print_debug_2s("(tex_comment):", yytext);
}
catl(yyleng, yytext);
do_newline();
if (leave_comments) { /* leave in comments */
myprint(yytext);
}
}
YY_BREAK
/* \begin{document} */
case 2:
# line 139 "l2x.l"
{ catl(yyleng, yytext);
nl_count = 0;
if (LDEBUG > LD1) {
print_debug_2s("(t_BEGIN_DOCUMENT):", yytext);
}
yylval.pos = get_mode_sym(pos_bdoc);
return(BEGIN_DOCUMENT);
}
YY_BREAK
/* end of document \end{document} */
case 3:
# line 149 "l2x.l"
{ catl(yyleng, yytext);
nl_count = 0;
if (LDEBUG > LD1) {
print_debug_2s("(t_END_DOCUMENT):", yytext);
}
yylval.pos = get_mode_sym(pos_edoc);
return(END_DOCUMENT);
}
YY_BREAK
/*----------------- verbatims -----------------------------------------*/
/* Do most of the processing in the lexer */
/* but pass token back to parser anyway */
/* \begin{verbatim} */
case 4:
# line 166 "l2x.l"
{ catl(yyleng, yytext);
nl_count = 0;
if (LDEBUG > LD1) {
print_debug_2s("(begin{verbatim}):", yytext);
}
BEGIN VERBATIM_STATE;
yylval.pos = get_mode_sym(pos_bvbm);
bverb = TRUE;
return(BEGIN_VERBATIM);
}
YY_BREAK
/* newline */
case 5:
# line 177 "l2x.l"
{ catl(yyleng, yytext);
do_newline();
if (LDEBUG > LD3) {
print_debug_2s("(newline in verbatim):", yytext);
}
verbatim_print(yytext);
}
YY_BREAK
/* backslash */
case 6:
# line 185 "l2x.l"
{ catl(yyleng, yytext);
if (LDEBUG > LD5) {
print_to_err(yytext);
}
verbatim_print(yytext);
}
YY_BREAK
/* any characters other than newline and backslash */
case 7:
# line 192 "l2x.l"
{ catl(yyleng, yytext);
if (LDEBUG > LD5) {
print_to_err(yytext);
}
verbatim_print(yytext);
}
YY_BREAK
/* \end{verbatim} */
case 8:
# line 199 "l2x.l"
{ catl(yyleng, yytext);
nl_count = 0;
if (LDEBUG > LD1) {
print_debug_2s("(end{verbatim}):", yytext);
}
BEGIN 0;
yylval.pos = get_mode_sym(pos_evbm);
return(END_VERBATIM);
}
YY_BREAK
/* \verb (and its trailing character) */
case 9:
# line 210 "l2x.l"
{ catl(yyleng, yytext);
nl_count = 0;
if (LDEBUG > LD1) {
print_debug_2s("(verb):", yytext);
}
BEGIN VERB_STATE;
verb_char = yytext[yyleng-1];
yylval.pos = get_mode_sym(pos_bv);
return(BEGIN_VERB);
}
YY_BREAK
/* chars inside \verb */
case 10:
# line 222 "l2x.l"
{ catl(yyleng, yytext);
if (LDEBUG > LD5) {
print_to_err(yytext);
}
if (verb_char != yytext[0] ) {
myprint(yytext);
}
else { /* end of verb environment */
BEGIN 0;
yylval.pos = get_mode_sym(pos_ev);
return(END_VERB);
}
}
YY_BREAK
/* newlines not allowed within verb */
case 11:
# line 237 "l2x.l"
{ catl(yyleng, yytext);
nl_count++;
if (LDEBUG > LD5) {
print_to_err(yytext);
}
BEGIN 0;
yyerror("Error: \"verb\" ended by a newline");
do_newline();
myprint(a_newline);
yylval.pos = get_mode_sym(pos_ev);
return(END_VERB);
}
YY_BREAK
/* VERB LIKE command stuff */
/* { (open brace) */
case 12:
# line 252 "l2x.l"
{ catl(yyleng, yytext);
nopen_vbrace++;
if (LDEBUG > LD5) {
print_to_err(yytext);
}
if (nopen_vbrace == 1) { /* start of argument */
yylval.pos = get_mode_sym(pos_lbrace);
return(LBRACE);
}
else { /* part of argument */
verbatim_print(yytext);
}
}
YY_BREAK
/* } (close brace) */
case 13:
# line 267 "l2x.l"
{ catl(yyleng, yytext);
nopen_vbrace--;
if (LDEBUG > LD5) {
print_to_err(yytext);
}
if (nopen_vbrace == 0) { /* end of argument */
BEGIN 0; /* change state */
yylval.pos = get_mode_sym(pos_rbrace);
return(RBRACE);
}
else { /* part of argument */
verbatim_print(yytext);
}
}
YY_BREAK
/* newline */
case 14:
# line 283 "l2x.l"
{ catl(yyleng, yytext);
do_newline();
if (LDEBUG > LD3) {
print_debug_2s("(newline in verb-like):", yytext);
}
verbatim_print(yytext);
}
YY_BREAK
/* any other character */
case 15:
# line 292 "l2x.l"
{ catl(yyleng, yytext);
if (LDEBUG > LD5) {
print_to_err(yytext);
}
verbatim_print(yytext);
}
YY_BREAK
/* VERBATIM LIKE environment stuff */
/* \end{something} */
case 16:
# line 303 "l2x.l"
{ catl (yyleng, yytext);
nl_count = 0;
get_env_name(yytext);
if (strcmp(vlenv, env_name) == 0) { /* close verbatim like */
if (LDEBUG > LD1) {
print_debug_2s("(end):", yytext);
print_debug_2s("env_name= ", env_name);
}
result = lookup_entry(env_name, END_VENV);
if (result > 0) { /* found it */
ptr = get_mode_sym(result);
yylval.pos = ptr;
kind = command_type(ptr);
BEGIN 0;
return(kind);
}
else { /* got problems, end env name not in table */
warning_3s("END_VENV",env_name,"not in command table. Expect input/output errors from now on");
BEGIN 0;
verbatim_print(yytext);
}
}
else { /* not end of verbatim-like env */
verbatim_print(yytext);
}
}
YY_BREAK
/* newline */
case 17:
# line 331 "l2x.l"
{ catl(yyleng, yytext);
do_newline();
if (LDEBUG > LD3) {
print_debug_2s("(newline in verbatim-like):", yytext);
}
verbatim_print(yytext);
}
YY_BREAK
/* any other character */
case 18:
# line 340 "l2x.l"
{ catl(yyleng, yytext);
if (LDEBUG > LD5) {
print_to_err(yytext);
}
verbatim_print(yytext);
}
YY_BREAK
/*---------------------------No Op processing---------------------------*/
/* open brace */
case 19:
# line 350 "l2x.l"
{ catl(yyleng, yytext);
if (LDEBUG > LD5) {
print_to_err(yytext);
}
if (noop_openc == NOOPLBRACE) {
nopen_noop++;
}
}
YY_BREAK
/* open bracket */
case 20:
# line 360 "l2x.l"
{ catl(yyleng, yytext);
if (LDEBUG > LD5) {
print_to_err(yytext);
}
if (noop_openc == NOOPLBRAK) {
nopen_noop++;
}
}
YY_BREAK
/* close brace */
case 21:
# line 370 "l2x.l"
{ catl(yyleng, yytext);
if (LDEBUG > LD5) {
print_to_err(yytext);
}
if (noop_openc == NOOPLBRACE) {
nopen_noop--;
if (nopen_noop <= 0) {
if (LDEBUG > LD3) {
print_to_err("(Closing NO_OP on brace)");
}
nopen_noop = 0;
in_noop = FALSE;
start_noop = FALSE;
BEGIN 0;
yylval.pos = get_mode_sym(pos_rbrace);
return(RBRACE);
}
}
}
YY_BREAK
/* close bracket */
case 22:
# line 391 "l2x.l"
{ catl(yyleng, yytext);
if (LDEBUG > LD5) {
print_to_err(yytext);
}
if (noop_openc == NOOPLBRAK) {
nopen_noop--;
if (nopen_noop <= 0) {
if (LDEBUG > LD3) {
print_to_err("(Closing NO_OP on bracket)");
}
nopen_noop = 0;
in_noop = FALSE;
start_noop = FALSE;
BEGIN 0;
got_opt_param = FALSE;
return(END_ANOPT);
}
}
}
YY_BREAK
/* newline */
case 23:
# line 413 "l2x.l"
{ catl(yyleng, yytext);
do_newline();
if (LDEBUG > LD3) {
print_debug_2s("(newline in a no op):", yytext);
}
}
YY_BREAK
/* any other character */
case 24:
# line 421 "l2x.l"
{ catl(yyleng, yytext);
if (LDEBUG > LD5) {
print_to_err(yytext);
}
}
YY_BREAK
/*----------------------------Default processing------------------------*/
/*----------------------- list items ---------------------------*/
/* item */
case 25:
# line 432 "l2x.l"
{ catl(yyleng, yytext);
nl_count = 0;
if (LDEBUG > LD1) {
print_debug_2s("(t_ITEM):", yytext);
}
return(ITEM);
}
YY_BREAK
/* item[ */
case 26:
# line 441 "l2x.l"
{ catl(yyleng, yytext);
nl_count = 0;
if (LDEBUG > LD1) {
print_debug_2s("(t_ITEM_AND_BRAK):", yytext);
}
got_opt_item = TRUE;
return(ITEM_AND_BRAK);
}
YY_BREAK
/*------------------------------ commands ------------------------------*/
/* (La)TeX backslash followed by a single space */
case 27:
# line 454 "l2x.l"
{ catl(yyleng, yytext);
nl_count = 0;
if (LDEBUG > LD4) {
print_debug_2s("(slashspace):", yytext);
} /* 6/96 change myprint to tag_print */
ptr = get_mode_sym(pos_bss);
tag_print(get_t(ptr));
tag_print(get_et(ptr));
}
YY_BREAK
/* (La)TeX backslash followed by a newline */
case 28:
# line 465 "l2x.l"
{ catl(yyleng, yytext);
nl_count++;
yylval.string = strsave(yytext);
do_newline();
if (LDEBUG > LD1) {
fprintf(filerr, "\n LD(slashnewline): next line is %d\n", lineno);
fflush(filerr);
}
ptr = get_mode_sym(pos_bss);
tag_print(get_t(ptr));
tag_print(get_et(ptr));
if (!pretty_print) {
myprint(a_newline);
}
}
YY_BREAK
/* \one non-alphabetic character */
case 29:
# line 482 "l2x.l"
{catl(yyleng, yytext);
nl_count = 0;
if (LDEBUG > LD1) {
print_debug_2s("(char_command):", yytext);
}
result = lookup_entry(yytext, CHAR_COMMAND);
if (result >= 0) { /* found it */
ptr = get_mode_sym(result);
kind = command_type(ptr);
yylval.pos = ptr;
return(kind);
}
else {
yylval.string = strsave(yytext);
if (LDEBUG > LD1) {
print_debug_1s("(as t_OTHER_COMMAND)");
}
if (LDEBUG > LD0) {
print_debug_undef(yylval.string, " (as CHAR_COMMAND)");
}
return(OTHER_COMMAND);
}
}
YY_BREAK
/* special processing for \\* command */
case 30:
# line 507 "l2x.l"
{ catl(yyleng, yytext);
nl_count = 0;
if (LDEBUG > LD1) {
print_debug_2s("(char_command):", yytext);
}
result = lookup_entry("\\\\", CHAR_COMMAND);
if (result >= 0) { /* found it */
ptr = get_mode_sym(result);
kind = command_type(ptr);
yylval.pos = ptr;
return(kind);
}
else {
yylval.string = strsave(yytext);
if (LDEBUG > LD1) {
print_debug_1s("(as t_OTHER_COMMAND)");
}
if (LDEBUG > LD0) {
print_debug_undef(yylval.string, " (as CHAR_COMMAND)");
}
return(OTHER_COMMAND);
}
}
YY_BREAK
/* a command \something or \something* */
case 31:
# line 534 "l2x.l"
{ catl(yyleng, yytext);
nl_count = 0;
if (LDEBUG > LD1) {
print_debug_2s("(command):", yytext);
}
result = lookup_entry(yytext, DONT_CARE);
if (result >= 0) { /* found it */
ptr = get_mode_sym(result);
kind = command_type(ptr);
yylval.pos = ptr;
switch (get_user_type(ptr)) {
case SPECIAL_COMMAND: {
special_kind = get_special_token(ptr);
if (special_kind == COMMAND) {
warning_3s("SPECIAL_COMMAND",yytext,"not yet implemented");
}
if (special_kind >= MIN_CODE_SPECIAL) {
return(kind);
}
else {
return(special_kind);
}
break;
}
case SPECIAL_SECTIONING: {
special_kind = get_special_token(ptr);
if (special_kind == COMMAND) {
warning_3s("SPECIAL_SECTIONING",yytext,"not yet implemented");
}
if (special_kind >= MIN_CODE_SPECIAL) {
return(kind);
}
else {
return(special_kind);
}
break;
}
case VCOMMAND: { /* verb-like */
BEGIN VERB_LIKE;
nopen_vbrace = 0;
break;
}
} /* end switch */
return(kind);
}
else {
yylval.string = strsave(yytext);
if (LDEBUG > LD1) {
print_debug_1s("(as t_OTHER_COMMAND)");
}
if (LDEBUG > LD0) {
print_debug_undef(yylval.string, " (as a command type)");
}
return(OTHER_COMMAND);
}
}
YY_BREAK
/*-------------------- Environments ---------------------------*/
/* \begin{something} */
case 32:
# line 595 "l2x.l"
{ catl(yyleng, yytext);
nl_count = 0;
if (LDEBUG > LD1) {
print_debug_2s("(begin):", yytext);
}
get_env_name(yytext);
if (LDEBUG > LD1) {
print_debug_2s("env_name= ", env_name);
}
result = lookup_entry(env_name, BEGIN_ENV);
if (result >= 0) { /* found it */
ptr = get_mode_sym(result);
yylval.pos = ptr;
kind = command_type(ptr);
return(kind);
}
result = lookup_entry(env_name, BEGIN_LIST_ENV);
if (result >= 0) { /* found it */
ptr = get_mode_sym(result);
yylval.pos = ptr;
kind = command_type(ptr);
return(kind);
}
result = lookup_entry(env_name, BEGIN_PICTURE_CC);
if (result >= 0) { /* found it */
ptr = get_mode_sym(result);
yylval.pos = ptr;
kind = command_type(ptr);
return(kind);
}
result = lookup_entry(env_name, BEGIN_VENV);
if (result >= 0) { /* found it */
BEGIN VERBATIM_LIKE; /* switch into verbatim-like mode */
bverb = TRUE;
strcpy(vlenv, env_name); /* remember environment name */
ptr = get_mode_sym(result);
yylval.pos = ptr;
kind = command_type(ptr);
return(kind);
}
result = lookup_entry(env_name, SPECIAL_BEGIN_ENV);
if (result >= 0) { /* found it */
ptr = get_mode_sym(result);
yylval.pos = ptr;
special_kind = get_special_token(ptr);
if (special_kind == COMMAND) {
warning_3s("SPECIAL_BEGIN_ENV",env_name,"not yet implemented");
}
if (special_kind >= MIN_CODE_SPECIAL) {
return(command_type(ptr));
}
else {
return(special_kind);
}
}
result = lookup_entry(env_name, SPECIAL_BEGIN_LIST);
if (result >= 0) { /* found it */
ptr = get_mode_sym(result);
yylval.pos = ptr;
special_kind = get_special_token(ptr);
if (special_kind == COMMAND) {
warning_3s("SPECIAL_BEGIN_LIST",env_name,"not yet implemented");
}
if (special_kind >= MIN_CODE_SPECIAL) {
return(command_type(ptr));
}
else {
return(special_kind);
}
}
yylval.string = strsave(yytext);
if (LDEBUG > LD1) {
print_debug_1s("(as t_OTHER_BEGIN)");
}
if (LDEBUG > LD0) {
print_debug_undef(yylval.string, " (as begin something)");
}
return(OTHER_BEGIN);
}
YY_BREAK
/* \end{something} */
case 33:
# line 676 "l2x.l"
{ catl(yyleng, yytext);
nl_count = 0;
if (LDEBUG > LD1) {
print_debug_2s("(end):", yytext);
}
get_env_name(yytext);
if (LDEBUG > LD1) {
print_debug_2s("env_name= ", env_name);
}
result = lookup_entry(env_name, END_ENV);
if (result >= 0) { /* found it */
ptr = get_mode_sym(result);
yylval.pos = ptr;
kind = command_type(ptr);
return(kind);
}
result = lookup_entry(env_name, END_LIST_ENV);
if (result >= 0) { /* found it */
ptr = get_mode_sym(result);
yylval.pos = ptr;
kind = command_type(ptr);
return(kind);
}
result = lookup_entry(env_name, END_PICTURE);
if (result >= 0) { /* found it */
ptr = get_mode_sym(result);
yylval.pos = ptr;
kind = command_type(ptr);
return(kind);
}
result = lookup_entry(env_name, SPECIAL_END_ENV);
if (result >= 0) { /* found it */
ptr = get_mode_sym(result);
yylval.pos = ptr;
special_kind = get_special_token(ptr);
if (special_kind == COMMAND) {
warning_3s("SPECIAL_END_ENV",env_name,"not yet implemented");
}
if (special_kind >= MIN_CODE_SPECIAL) {
return(command_type(ptr));
}
else {
return(special_kind);
}
}
result = lookup_entry(env_name, SPECIAL_END_LIST);
if (result >= 0) { /* found it */
ptr = get_mode_sym(result);
yylval.pos = ptr;
special_kind = get_special_token(ptr);
if (special_kind == COMMAND) {
warning_3s("SPECIAL_END_ENV",env_name,"not yet implemented");
}
if (special_kind >= MIN_CODE_SPECIAL) {
return(command_type(ptr));
}
else {
return(special_kind);
}
}
yylval.string = strsave(yytext);
if (LDEBUG > LD1) {
print_debug_1s("(as t_OTHER_END)");
}
if (LDEBUG > LD0) {
print_debug_undef(yylval.string, " (as end something)");
}
return(OTHER_END);
}
YY_BREAK
/*--------------------- Miscellaneous stuff -----------------------*/
/* an open brace { */
case 34:
# line 751 "l2x.l"
{ catl(yyleng, yytext);
nl_count = 0;
if (LDEBUG > LD1) {
print_debug_2s("(t_LBRACE):", yytext);
}
if (start_noop) {
if (LDEBUG > LD3) {
print_to_err("(Starting NO_OP on brace)");
}
start_noop = FALSE;
in_noop = TRUE;
nopen_noop = 1;
noop_openc = NOOPLBRACE;
BEGIN NOOP;
}
yylval.pos = get_mode_sym(pos_lbrace);
return(LBRACE);
}
YY_BREAK
/* a close brace } */
case 35:
# line 771 "l2x.l"
{ catl(yyleng, yytext);
nl_count = 0;
if (LDEBUG > LD1) {
print_debug_2s("(t_RBRACE):", yytext);
}
yylval.pos = get_mode_sym(pos_rbrace);
return(RBRACE);
}
YY_BREAK
/* an open bracket [ */
case 36:
# line 781 "l2x.l"
{ catl(yyleng, yytext);
nl_count = 0;
if (LDEBUG > LD1) {
print_debug_2s("(t_LBRAK):", yytext);
}
if (opt_param) {
got_opt_param = TRUE;
opt_param = FALSE;
if (start_noop) {
if (LDEBUG > LD3) {
print_to_err("(Starting NO_OP on bracket)");
}
start_noop = FALSE;
in_noop = TRUE;
noop_openc = NOOPLBRAK;
BEGIN NOOP;
}
return(START_ANOPT);
}
else if (all_opt) {
got_all_opt = TRUE;
all_opt = FALSE;
return(START_ALLOPT);
}
else {
return(LBRAK);
}
}
YY_BREAK
/* a close bracket ] */
case 37:
# line 811 "l2x.l"
{ catl(yyleng, yytext);
nl_count = 0;
if (LDEBUG > LD1) {
print_debug_2s("(t_RBRAK):", yytext);
}
if (got_opt_item) {
got_opt_item = FALSE;
return(END_ITEM_BRAK);
}
else if (got_opt_param) {
got_opt_param = FALSE;
return(END_ANOPT);
}
else if (got_all_opt) {
got_all_opt = FALSE;
return(END_ALLOPT);
}
else {
return(RBRAK);
}
}
YY_BREAK
/*------------------- Special characters ----------------------*/
/* a naked hash # */
case 38:
# line 836 "l2x.l"
{ catl(yyleng, yytext);
nl_count = 0;
if (LDEBUG > LD1) {
print_debug_2s("(hash):", yytext);
}
result = lookup_entry(yytext, TEX_CHAR);
if (result >= 0) { /* found it */
ptr = get_mode_sym(result);
kind = command_type(ptr);
yylval.pos = ptr;
return(kind);
}
else {
yylval.string = strsave(yytext);
if (LDEBUG > LD1) {
print_debug_1s("(as t_OTHER)");
}
if (LDEBUG > LD0) {
print_debug_undef(yylval.string, " (as a special character)");
}
return(OTHER);
}
}
YY_BREAK
/* a naked dollar $ */
case 39:
# line 861 "l2x.l"
{ catl(yyleng, yytext);
nl_count = 0;
if (LDEBUG > LD1) {
print_debug_2s("(dollar):", yytext);
if (got_a_dollar) { print_debug_1s("(as t_END_DOLLAR)"); }
else { print_debug_1s("(as t_BEGIN_DOLLAR)"); }
}
if (got_a_dollar) { /* a 'closing' $ */
got_a_dollar = FALSE;
yylval.pos = get_mode_sym(pos_edol);
return(END_DOLLAR);
}
else { /* an 'opening' $ */
got_a_dollar = TRUE;
yylval.pos = get_mode_sym(pos_bdol);
return(BEGIN_DOLLAR);
}
}
YY_BREAK
/* a naked ampersand & */
case 40:
# line 881 "l2x.l"
{ catl(yyleng, yytext);
nl_count = 0;
if (LDEBUG > LD1) {
print_debug_2s("(ampersand):", yytext);
}
result = lookup_entry(yytext, TEX_CHAR);
if (result >= 0) { /* found it */
ptr = get_mode_sym(result);
kind = command_type(ptr);
yylval.pos = ptr;
return(kind);
}
else {
yylval.string = strsave(yytext);
if (LDEBUG > LD1) {
print_debug_1s("(as t_OTHER)");
}
if (LDEBUG > LD0) {
print_debug_undef(yylval.string, " (as a special character)");
}
return(OTHER);
}
}
YY_BREAK
/* a naked twiddle ~ */
case 41:
# line 907 "l2x.l"
{ catl(yyleng, yytext);
nl_count = 0;
if (LDEBUG > LD1) {
print_debug_2s("(twiddle):", yytext);
}
result = lookup_entry(yytext, TEX_CHAR);
if (result >= 0) { /* found it */
ptr = get_mode_sym(result);
yylval.pos = ptr;
kind = command_type(ptr);
return(kind);
}
else {
yylval.string = strsave(yytext);
if (LDEBUG > LD1) {
print_debug_1s("(as t_OTHER)");
}
if (LDEBUG > LD0) {
print_debug_undef(yylval.string, " (as a special character)");
}
return(OTHER);
}
}
YY_BREAK
/* a naked underscore _ */
case 42:
# line 932 "l2x.l"
{ catl(yyleng, yytext);
nl_count = 0;
if (LDEBUG > LD1) {
print_debug_2s("(underscore):", yytext);
}
result = lookup_entry(yytext, TEX_CHAR);
if (result >= 0) { /* found it */
ptr = get_mode_sym(result);
yylval.pos = ptr;
kind = command_type(ptr);
return(kind);
}
else {
yylval.string = strsave(yytext);
if (LDEBUG > LD1) {
print_debug_1s("(as t_OTHER)");
}
if (LDEBUG > LD0) {
print_debug_undef(yylval.string, " (as a special character)");
}
return(OTHER);
}
}
YY_BREAK
/* a naked caret ^ */
case 43:
# line 957 "l2x.l"
{ catl(yyleng, yytext);
nl_count = 0;
if (LDEBUG > LD1) {
print_debug_2s("(caret):", yytext);
}
result = lookup_entry(yytext, TEX_CHAR);
if (result >= 0) { /* found it */
ptr = get_mode_sym(result);
yylval.pos = ptr;
kind = command_type(ptr);
return(kind);
}
else {
yylval.string = strsave(yytext);
if (LDEBUG > LD1) {
print_debug_1s("(as t_OTHER)");
}
if (LDEBUG > LD0) {
print_debug_undef(yylval.string, " (as a special character)");
}
return(OTHER);
}
}
YY_BREAK
/* a naked percent % */
case 44:
# line 982 "l2x.l"
{ catl(yyleng, yytext);
nl_count = 0;
if (LDEBUG > LD1) {
print_debug_2s("(percent):", yytext);
}
result = lookup_entry(yytext, TEX_CHAR);
if (result >= 0) { /* found it */
ptr = get_mode_sym(result);
yylval.pos = ptr;
kind = command_type(ptr);
return(kind);
}
else {
yylval.string = strsave(yytext);
if (LDEBUG > LD1) {
print_debug_1s("(as t_OTHER)");
}
if (LDEBUG > LD0) {
print_debug_undef(yylval.string, " (as a special character)");
}
return(OTHER);
}
}
YY_BREAK
/* a naked at @ */
case 45:
# line 1007 "l2x.l"
{ catl(yyleng, yytext);
nl_count = 0;
if (LDEBUG > LD1) {
print_debug_2s("(at):", yytext);
}
result = lookup_entry(yytext, TEX_CHAR);
if (result >= 0) { /* found it */
ptr = get_mode_sym(result);
yylval.pos = ptr;
kind = command_type(ptr);
return(kind);
}
else {
yylval.string = strsave(yytext);
if (LDEBUG > LD1) {
print_debug_1s("(as t_OTHER)");
}
if (LDEBUG > LD0) {
print_debug_undef(yylval.string, " (as a special character)");
}
return(OTHER);
}
}
YY_BREAK
/* name (alphabetic string(*) ) */
case 46:
# line 1034 "l2x.l"
{ catl(yyleng, yytext);
nl_count = 0;
yylval.string = strsave(yytext);
if (LDEBUG > LD1) {
print_debug_2s("(t_NAME):", yytext);
}
return(NAME);
}
YY_BREAK
/* integer (digit string) */
case 47:
# line 1044 "l2x.l"
{ catl(yyleng, yytext);
nl_count = 0;
yylval.string = strsave(yytext);
if (LDEBUG > LD2) {
print_debug_2s("(t_INTEGER):", yytext);
}
return(INTEGER);
}
YY_BREAK
/* real (digits with one period) */
case 48:
# line 1054 "l2x.l"
{ catl(yyleng, yytext);
nl_count = 0;
yylval.string = strsave(yytext);
if (LDEBUG > LD2) {
print_debug_2s("(t_REAL):", yytext);
}
return(REAL);
}
YY_BREAK
/* a comma */
case 49:
# line 1065 "l2x.l"
{ catl(yyleng, yytext);
nl_count = 0;
if (LDEBUG > LD2) {
print_debug_2s("(t_COMMA):", yytext);
}
return(COMMA);
}
YY_BREAK
/* left parenthesis */
case 50:
# line 1074 "l2x.l"
{ catl(yyleng, yytext);
nl_count = 0;
if (LDEBUG > LD2) {
print_debug_2s("(t_LPAREN):", yytext);
}
if (opt_coord) {
got_opt_coord = TRUE;
opt_coord = FALSE;
return(START_COORD);
}
else {
return(LPAREN);
}
}
YY_BREAK
/* right parenthesis */
case 51:
# line 1090 "l2x.l"
{ catl(yyleng, yytext);
nl_count = 0;
if (LDEBUG > LD2) {
print_debug_2s("(t_RPAREN):", yytext);
}
if (got_opt_coord) {
got_opt_coord = FALSE;
return(END_COORD);
}
else {
return(RPAREN);
}
}
YY_BREAK
/* whitespace (except newline) print it out */
case 52:
# line 1107 "l2x.l"
{ catl(yyleng, yytext);
if (LDEBUG > LD4) {
print_debug_2s("(ws):", yytext);
}
if (collapse_ws) { /* collapse whitespace */
myprint(a_space);
}
else {
myprint(yytext);
}
}
YY_BREAK
/* newline with leading and trailing spaces */
/* 7/96 changed to enable paragraphs outside pretty mode */
case 53:
# line 1121 "l2x.l"
{ catl(yyleng, yytext);
nl_count++;
/* yylval.string = strsave(yytext); */
do_newline();
if (LDEBUG > LD1) {
fprintf(filerr, "\n LD(newline): next line is %d\n", lineno);
fflush(filerr);
}
if (!pretty_print) { /* not pretty printing */
myprint(yytext);
if (nl_count == 2) { /* 6/96 added this */
yylval.pos = get_mode_sym(pos_para);
return(PARAGRAPH);
}
}
else {
if (nl_count == 2) { /* (6/96 changed from >= 2 to == 2) a paragraph break */
yylval.pos = get_mode_sym(pos_para);
return(PARAGRAPH);
}
else { /* treat as space */
myprint(a_space);
}
}
}
YY_BREAK
/*----------- WHEN ALL ELSE FAILS --------------------*/
/* end of file */
case YY_STATE_EOF(INITIAL):
case YY_STATE_EOF(VERBATIM_STATE):
case YY_STATE_EOF(VERB_STATE):
case YY_STATE_EOF(VERBATIM_LIKE):
case YY_STATE_EOF(VERB_LIKE):
case YY_STATE_EOF(NOOP):
# line 1152 "l2x.l"
{ catl(yyleng, yytext);
if (LDEBUG > LD1) {
print_debug_1s("(end of file):\n");
}
yyerror("Lexer: Unexpected end of file");
return(END_OF_FILE);
}
YY_BREAK
/* anything else */
case 55:
# line 1161 "l2x.l"
{ catl(yyleng, yytext);
nl_count = 0;
result = lookup_entry(yytext, TEX_CHAR);
if (result >= 0) { /* found it */
if (LDEBUG > LD1) {
print_debug_2s("(tex_char):", yytext);
}
ptr = get_mode_sym(result);
yylval.pos = ptr;
kind = command_type(ptr);
return(kind);
}
else {
yylval.string = strsave(yytext);
if (LDEBUG > LD4) {
print_debug_2s("(catch_all):", yytext);
}
return(OTHER);
}
}
YY_BREAK
case 56:
# line 1182 "l2x.l"
ECHO;
YY_BREAK
case YY_END_OF_BUFFER:
{
/* amount of text matched not including the EOB char */
int yy_amount_of_matched_text = yy_cp - yytext - 1;
/* undo the effects of YY_DO_BEFORE_ACTION */
*yy_cp = yy_hold_char;
/* note that here we test for yy_c_buf_p "<=" to the position
* of the first EOB in the buffer, since yy_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 yyinput().
*/
if ( yy_c_buf_p <= &yy_current_buffer->yy_ch_buf[yy_n_chars] )
/* this was really a NUL */
{
yy_state_type yy_next_state;
yy_c_buf_p = yytext + yy_amount_of_matched_text;
yy_current_state = yy_get_previous_state();
/* okay, we're now positioned to make the
* NUL transition. We couldn't have
* yy_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)
*/
if ( yywrap() )
{
/* note: because we've taken care in
* yy_get_next_buffer() to have set up yytext,
* we can now set up yy_c_buf_p so that if some
* total hoser (like flex itself) wants
* to call the scanner after we return the
* YY_NULL, it'll still work - another YY_NULL
* will get returned.
*/
yy_c_buf_p = yytext + YY_MORE_ADJ;
/* yy_get_next_buffer - try to read in a new buffer
*
* synopsis
* int yy_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 yy_get_next_buffer()
{
register YY_CHAR *dest = yy_current_buffer->yy_ch_buf;
register YY_CHAR *source = yytext - 1; /* copy prev. char, too */
register int number_to_move, i;
int ret_val;
if ( yy_c_buf_p > &yy_current_buffer->yy_ch_buf[yy_n_chars + 1] )
YY_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 = yy_c_buf_p - yytext;
for ( i = 0; i < number_to_move; ++i )
*(dest++) = *(source++);
if ( yy_current_buffer->yy_eof_status != EOF_NOT_SEEN )
/* don't do the read, it's not guaranteed to return an EOF,
* just force an EOF
*/
yy_n_chars = 0;
else
{
int num_to_read = yy_current_buffer->yy_buf_size - number_to_move - 1;
if ( num_to_read > YY_READ_BUF_SIZE )
num_to_read = YY_READ_BUF_SIZE;
/* yytext begins at the second character in yy_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
* yy_get_previous_state() will have with '^' rules active
*/
yytext = &yy_current_buffer->yy_ch_buf[1];
return ( ret_val );
}
/* yy_get_previous_state - get the state just before the EOB char was reached
*
* synopsis
* yy_state_type yy_get_previous_state();
*/
/* undo effects of setting up yytext */
*yy_cp = yy_hold_char;
if ( yy_cp < yy_current_buffer->yy_ch_buf + 2 )
{ /* need to shift things up to make room */
register int number_to_move = yy_n_chars + 2; /* +2 for EOB chars */
register YY_CHAR *dest =
&yy_current_buffer->yy_ch_buf[yy_current_buffer->yy_buf_size + 2];
register YY_CHAR *source =
&yy_current_buffer->yy_ch_buf[number_to_move];
while ( source > yy_current_buffer->yy_ch_buf )
*--dest = *--source;
yy_cp += dest - source;
yy_bp += dest - source;
yy_n_chars = yy_current_buffer->yy_buf_size;
/* note: the formal parameter *must* be called "yy_bp" for this
* macro to now work correctly
*/
YY_DO_BEFORE_ACTION; /* set up yytext again */
}
#ifdef __cplusplus
static int yyinput()
#else
static int input()
#endif
{
int c;
YY_CHAR *yy_cp = yy_c_buf_p;
*yy_cp = yy_hold_char;
if ( *yy_c_buf_p == YY_END_OF_BUFFER_CHAR )
{
/* yy_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 ( yy_c_buf_p < &yy_current_buffer->yy_ch_buf[yy_n_chars] )
/* this was really a NUL */
*yy_c_buf_p = '\0';
else
{ /* need more input */
yytext = yy_c_buf_p;
++yy_c_buf_p;
case EOB_ACT_CONTINUE_SCAN:
yy_c_buf_p = yytext + YY_MORE_ADJ;
break;
case EOB_ACT_LAST_MATCH:
#ifdef __cplusplus
YY_FATAL_ERROR( "unexpected last match in yyinput()" );
#else
YY_FATAL_ERROR( "unexpected last match in input()" );
#endif
}
}
}
if ( yy_current_buffer )
{
/* flush out information for old buffer */
*yy_c_buf_p = yy_hold_char;
yy_current_buffer->yy_buf_pos = yy_c_buf_p;
yy_current_buffer->yy_n_chars = yy_n_chars;
}
/* we don't actually know whether we did this switch during
* EOF (yywrap()) processing, but the only time this flag
* is looked at is after yywrap() is called, so it's safe
* to go ahead and always set it.
*/
yy_did_buffer_switch_on_eof = 1;
}
#ifdef YY_USE_PROTOS
YY_BUFFER_STATE yy_create_buffer( FILE *file, int size )
#else
YY_BUFFER_STATE yy_create_buffer( file, size )
FILE *file;
int size;
#endif
{
YY_BUFFER_STATE b;
b = (YY_BUFFER_STATE) malloc( sizeof( struct yy_buffer_state ) );
if ( ! b )
YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" );
b->yy_buf_size = size;
/* yy_ch_buf has to be 2 characters longer than the size given because
* we need to put in 2 end-of-buffer characters.
*/
b->yy_ch_buf = (YY_CHAR *) malloc( (unsigned) (b->yy_buf_size + 2) );
if ( ! b->yy_ch_buf )
YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" );
yy_init_buffer( b, file );
return ( b );
}
#ifdef YY_USE_PROTOS
void yy_delete_buffer( YY_BUFFER_STATE b )
#else
void yy_delete_buffer( b )
YY_BUFFER_STATE b;
#endif
{
if ( b == yy_current_buffer )
yy_current_buffer = (YY_BUFFER_STATE) 0;
/* we put in the '\n' and start reading from [1] so that an
* initial match-at-newline will be true.
*/
b->yy_ch_buf[0] = '\n';
b->yy_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->yy_ch_buf[1] = YY_END_OF_BUFFER_CHAR;
b->yy_ch_buf[2] = YY_END_OF_BUFFER_CHAR;
b->yy_buf_pos = &b->yy_ch_buf[1];
b->yy_eof_status = EOF_NOT_SEEN;
}
# line 1182 "l2x.l"