/*****************************************************************************

	TECO-C Version 1.0

	Copyright 1983 by Pete Siemsen.  All this means is that nobody else
can claim they wrote TECO-C and sell it.  This code is in the public domain
and is free to anyone who wants it.

	This program is still under development.  See file PROBLEMS.TXT for
notes I've written to myself about things to do to the program. If you
modify this code to enhance it or fix a bug,  please communicate the changes
to me.  My address is

			Pete Siemsen
			645 Ohio Avenue #302
			Long Beach, Ca. 90814
			USA


	Version 1.0 of TECO-C is an almost-complete implementation of TECO-11.
All the code was written by one person,  so it is consistent, if nothing
else.  File PROBLEMS.TXT is a notes file listing ideas and known bugs.

	The file PG.MEM (programmer's guide) contains documentation explaining
algorithms used in TECOC.

	Global variable declarations for system-independent variables are
in this file.  Global variable definitions for system-dependent variables can
be found in file ZInit.c.  Global variable definitions for debugging
variables can be found in DbgDsp.c
*****************************************************************************/

#include "ZPort.h"		/* define portability identifiers */
#include "ZFiles.h"		/* define file data block structures */
#include "DefTeco.h"		/* define general identifiers */
#include "DefError.h"		/* define identifiers for error messages */
#include "DefScren.h"		/* define UNTERM */

extern	VOID	Init();		/* initialize TECO-C */
extern	VOID	ReadCS();	/* read command string */
extern	DEFAULT	ExeCSt();	/* execute command string */

/*****************************************************************************
	These pointers point to the first and last characters in an "area",
which is specified when an m,n argument pair preceeds a TECO command.  For
instance,  when the command 10,25T is executed,  the GetAra function is called
to set these pointers,  which are then used to display the text.
*****************************************************************************/

GLOBAL	char	*AraBeg;		/* start of m,n area */
GLOBAL	char	*AraEnd;		/* end of m,n area */

/*****************************************************************************
	ArgPtr points to the first character of the text argument associated
with a TECO-C command.  It is set by the FindES (find end-of-string) function.
When a command that has a text argument is executed,  FindES is called to
locate the end of the text argument.  FindES moves the command pointer to the
end of the text argument,  and remembers where the beginning was using ArgPtr.
*****************************************************************************/

GLOBAL	char	*ArgPtr;		/* start of text argument of a cmd */

/*****************************************************************************
	These variables point to the beginning and end of the command string
buffer.  Memory for the command string buffer is allocated in the MemIni
function.  CBfBeg always points to this buffer,  but CStBeg changes when an M
or EI command is executed.
*****************************************************************************/

GLOBAL	char	*CBfBeg;		/* beginning of cmd string buffer */
GLOBAL	char	*CBfEnd;		/* end of command string buffer */

/*****************************************************************************
	CBfPtr is the command string buffer pointer,  which moves across a
command string as it is executed.  CBfPtr usually points into the command
string buffer pointed to by CBfBeg,  but it points elsewhere when an M or EI
command is being executed.
*****************************************************************************/

GLOBAL	char	*CBfPtr;		/* command buffer pointer */

/*****************************************************************************
	When TECO-C is executing a command string,  it looks at each command
(1 or 2 characters) and calls a function to implement the command.  Some
commands can be modified by preceeding the command with a modifier character.
CmdMod contains bits which are set when a modifier character is "executed".
This variable is cleared by most commands before they successfully return.
The bits in CmdMod relate to the at-sign (@), colon (:), double-colon (::)
modifiers.  There is also a bit which indicates that a command has 2 numeric
arguments separated by a comma.
*****************************************************************************/

GLOBAL	BYTE	CmdMod;

/*****************************************************************************
	CRCnt maintains a count of the number of carriage returns that have
been typed by the user while entering a command string.  It is used to
recognize when the user executes a HELP command,  which is the only TECO
command that does not need to be terminated by double escapes.  When the very
first carriage return in the user's command string is struck,  TECO checks
if the text preceeding the carriage return is a valid HELP command.  This
checking is only performed when the first carriage return is struck.
*****************************************************************************/

GLOBAL	LONG	CRCnt;			/* carriage-return count */

/*****************************************************************************
	These variables point to the beginning and end of the executing
command string,  whether that command string is in the command buffer, a
q-register or the EI buffer.
*****************************************************************************/

GLOBAL	char	*CStBeg;		/* start of command string */
GLOBAL	char	*CStEnd;		/* end of command string */

/*****************************************************************************
	CurInp and CurOut are indices into the IFiles and OFiles arrays,
respectively.  They indicate the entries for the current input stream and
current output stream.
*****************************************************************************/

GLOBAL	DEFAULT	CurInp = PINPFL;
GLOBAL	DEFAULT	CurOut = POUTFL;

/*****************************************************************************
	DArg points to the text string that follows the "-d" switch on the
command line used to invoke TECOC.  It is used only during initialization.
*****************************************************************************/

GLOBAL char	*DArg;			/* data part of -d switch */

/*****************************************************************************
	These variables point to the digit buffer.  When TECO-C needs to
convert a binary number into an ASCII string,  the string is generated in this
buffer.  The buffer is large enough to hold the largest integer represented
by 32 bits,  plus an optional sign and maybe a carriage-return/line-feed pair.
*****************************************************************************/

GLOBAL	char	*DBfBeg= "             ";	/* digit buffer */
GLOBAL	char	*DBfPtr;		/* digit buffer pointer */

/*****************************************************************************
	These variables point to the first and last characters in the
edit buffer.  See file PG.MEM for a description of memory management.
*****************************************************************************/

GLOBAL	char	*EBfBeg;		/* first character in edit buffer */
GLOBAL	char	*EBfEnd;		/* last character in edit buffer */

/*****************************************************************************
	EBPtr1 is used when a search is being performed.  It is adjusted when
the edit buffer is being scanned for the first character of the search string.
When a search command succeeds,  this pointer is left pointing to the first
character of the found string.
*****************************************************************************/

GLOBAL	char	*EBPtr1;

/*****************************************************************************
	EBPtr2 is used when a search is being performed.  After a character
matching the first character of the search string is found,  this pointer is
adjusted as each remaining character of the search string is compared with
the edit buffer.  When a search command succeeds,  this pointer is left
pointing to the last character of the found string.
*****************************************************************************/

GLOBAL	char	*EBPtr2;

/*****************************************************************************
	Bits within EdFlag have the following meanings:

        1    Allow caret (^) in search strings
        2    Allow Y and _ commands to destroy edit buffer
        4    Don't arbitrarily expand memory
        16   preserve dot on failing searches
        64   only move dot by one on multiple occurrence searches
*****************************************************************************/

GLOBAL	WORD	EdFlag = 0;

/*****************************************************************************
	Bits within EhFlag have the following meanings:

        3    how much error message to display
        4    display failing command string after errors
*****************************************************************************/

GLOBAL	WORD	EhFlag = 0;

/*****************************************************************************
	EndSAr is used by search code to point to the end of the area to be
searched.
*****************************************************************************/

GLOBAL	char	*EndSAr;		/* end of search area */

/*****************************************************************************
	The ErrCod array contains the standard TECO three-letter abbreviations
for error messages.
*****************************************************************************/

GLOBAL	char	*ErrCod[] = {
/*  0*/ "ARG",    /*  1*/ "BNI",    /*  2*/ "CON",    /*  3*/ "DEV",
/*  4*/ "DTB",    /*  5*/ "FNF",    /*  6*/ "FUL",    /*  7*/ "ICE",
/*  8*/ "IEC",    /*  9*/ "IFC",    /* 10*/ "IFN",    /* 11*/ "IIA",
/* 12*/ "ILL",    /* 13*/ "ILN",    /* 14*/ "IPA",    /* 15*/ "IQC",
/* 16*/ "IQN",    /* 17*/ "IRA",    /* 18*/ "ISA",    /* 19*/ "ISS",
/* 20*/ "IUC",    /* 21*/ "MAP",    /* 22*/ "MEM",    /* 23*/ "MLA",
/* 24*/ "MLP",    /* 25*/ "MRA",    /* 26*/ "MRP",    /* 27*/ "MSC",
/* 28*/ "NAB",    /* 29*/ "NAC",    /* 30*/ "NAE",    /* 31*/ "NAP",
/* 32*/ "NAQ",    /* 33*/ "NAS",    /* 34*/ "NAU",    /* 35*/ "NCA",
/* 36*/ "NYA",    /* 37*/ "NFI",    /* 38*/ "NFO",    /* 39*/ "NPA",
/* 40*/ "NYI",    /* 41*/ "OFO",    /* 42*/ "PES",    /* 43*/ "PDO",
/* 44*/ "POP",    /* 45*/ "SNI",    /* 46*/ "SRH",    /* 47*/ "STL",
/* 48*/ "TAG",    /* 49*/ "UTC",    /* 50*/ "UTM",    /* 51*/ "XAB",
/* 52*/ "YCA",    /* 53*/ "NRO"
	};

/*****************************************************************************
	Several TECO error messages take an argument.  For instance,  the
"illegal command"  error message shows the user the illegal command.  When
these kinds of messages are required,  ErrTxt is used to send the text
of the argument to the error display function (ErrMsg).
*****************************************************************************/

GLOBAL	char	ErrTxt[6];		/* holds part of error message */

/*****************************************************************************
	The EsFlag flag controls what is displayed on the terminal after every
successful search command completes.  EsFlag has the following meanings:

        0         don't display anything
        -1        display the line containing the found string
        1-31      display the line containing the found string,
                  with a line feed at the character position
        32-126    display the line containing the found string,
                  with the character whose ASCII code is represented
                  by ES at the character position
        m*265+n   n has the meanings defined above.  m is the number
                  of lines above and below the found string to be
                  displayed.
*****************************************************************************/

GLOBAL	WORD	EsFlag = 0;

/*****************************************************************************
	The expression stack contains the components of TECO's numeric
expressions.  Each entry on the expression stack is either an OPERAND or
an OPERATOR (like +, -, /, *).
*****************************************************************************/

GLOBAL	struct	EStck EStack[EXS_SIZE]; /* expression stack */
GLOBAL	WORD	EStBot;			/* expression stack bottom */
GLOBAL	WORD	EStTop;			/* top of expression stack */

/*****************************************************************************
	Bits in EtFlag control TECO's handling of the terminal.  Definitions
of masks for each bit and the meaning of each bit can be found in file
"DefTeco.h".  This flag is initialized in function ZInit.
*****************************************************************************/

GLOBAL	WORD	EtFlag;

/*****************************************************************************
	The EuFlag is TECO's case mode control flag.  This flag allows TECO to
be used to input and output upper and lower case characters even if the
terminal being used is capable of displaying only uppercase characters.  If
the EU flag is 1, no case flagging is performed on type-out.  If the EU flag is
0,  lowercase characters are converted to uppercase on type-out,  and are
preceeded by a ' character.  If the EU flag is 1, then lowercase characters are
converted to uppercase on type-out,  but uppercase characters are preceeded by
a ' character.
*****************************************************************************/

GLOBAL	WORD	EuFlag = -1;		/* EU mode control flag */

/*****************************************************************************
	The EV mode control flag controls what is displayed on the terminal
after every successful command string completes.  By default, nothing is
displayed (EV is 0).  EV has the following meanings:

        0         don't display anything
        -1        display the line containing the character position
        1-31      display the line containing the character position,
                  with a line feed at the character position
        32-126    display the line containing the character position,
                  with the character whose ASCII code is represented
                  by ES at the character position
        m*265+n   n has the meanings defined above.  m is the number
                  of lines above and below the character position to be
                  displayed.
*****************************************************************************/

GLOBAL	WORD	EvFlag = 0;

/*****************************************************************************
	These variables point to the file specification buffer.  The buffer
itself (FBfBeg) is defined in system-dependent code because the size of the
buffer is system-dependent.
*****************************************************************************/

GLOBAL	char	*FBfEnd;		/* last chr (+1) of filespec buffer */
GLOBAL	char	*FBfPtr;		/* pointer into file spec buffer */

/*****************************************************************************
	FFPage is the value which is returned by the ^E command.  It is -1 if
the buffer currently contains a page of text that was terminated by a form
feed in the input file.  It is 0 if the buffer contains only part of a page
from the input file (because the input page filled the text buffer before it
was completely read in).  The FFPage flag is tested by the P command and
related operations to determine if a form feed should be appended to the
contents of the buffer when it is output.
*****************************************************************************/

GLOBAL	LONG	FFPage = 0L;		/* form feed flag (see ^E) */

/*****************************************************************************
	FileDf indicates whether a file specification was given on the
command line used to invoke TECO-C.  It is used during initialization,  when
the command line is being parsed.
*****************************************************************************/

GLOBAL	BOOLEAN	FileDf;		/* was a file specification parsed? */

/*****************************************************************************
	These variables point to the first and last characters in the edit
buffer gap.  See file PG.MEM for a description of memory management.
*****************************************************************************/

GLOBAL	char	*GapBeg;		/* first char in edit buffer gap */
GLOBAL	char	*GapEnd;		/* last char in edit buffer gap */

/*****************************************************************************
	GotCtc indicates that the user has interrupted the normal execution
of TECO-C by typing a control-C.  This variable is set by the special
interrupt-handling routine executed when a control-C is struck,  and is
cleared before a command string is entered.  It is tested each time a command
terminates and when certain commands execute time-consuming loops.
*****************************************************************************/

GLOBAL	BOOLEAN	GotCtC = NO;

/*****************************************************************************
	IBfEnd is the end of the input buffer.  See file PG.MEM for adescription of memory management.

*****************************************************************************/

GLOBAL	char	*IBfEnd;

/*****************************************************************************
	IFiles holds the file data blocks for input files.  There are three
static input streams:   the primary input stream,  the secondary input stream,
and the input stream used by the EQq command.  To access these three files,
identifiers defined in file DefTeco.h are used to index into this array.
Other elements of this array are used to access input files for the EI
command.
*****************************************************************************/

GLOBAL	struct	IFDBST	IFiles[NIFDBS];

/*****************************************************************************
	EIIndx is an index into the IFiles array.  It is incremented each
time an EI command is executed and decremented each time an EI command
completes.  It is the index of the file data block of the currently open EI
input file.  When EIIndx equals EIFL-1,  no EI files are open.
*****************************************************************************/

GLOBAL	DEFAULT	EIIndx = EIFL-1;

/*****************************************************************************
	IniSrM is the initial search mode.  It is used when parsing search
strings and file specifications.  The value of this variable is set by ^V and
^W characters and is used to explicitly control the case (upper or lower) of
characters in a string.
*****************************************************************************/

GLOBAL	BYTE	IniSrM = NONE;

/*****************************************************************************
	IsOpnI and IsOpnO contain indicators about the status of the file
data blocks in the IFiles and OFiles arrays,  respectively.  An element has the
value YES when the corresponding file data block reflects an opened file.
IsEofI indicates that the corresponding element of IFiles reflects a file
that has reached the end.
*****************************************************************************/

GLOBAL	BOOLEAN	IsEofI[NIFDBS];
GLOBAL	BOOLEAN	IsOpnI[NIFDBS];
GLOBAL	BOOLEAN	IsOpnO[NOFDBS];

/*****************************************************************************
	LBfPtr points to the last-file-edited file specification buffer.  The
buffer itself (LStBeg) is define in ZInit,  because it's size is system
dependent.
*****************************************************************************/

GLOBAL	char	*LBfPtr;

/*****************************************************************************
	LstErr holds the code for the last error reported by TECO-C.  It is
set in the error display function (ErrMsg) and used when the user executes
the ? or / immediate mode commands,  to print out more information about the
last error that occurred.
*****************************************************************************/

GLOBAL	WORD	LstErr = ERR_XXX;	/* number of last error message */

/*****************************************************************************
	The loop stack maintains pointers to the first character of each loop
(the character following the "<").  LStTop is the element of LStack that
relates to the most recently executed "<" command.  LStBot is the index of
the bottom of the stack,  so that if (LStTop == LStBot),  we're not in a loop
in the current macro level.  When a macro is entered,  LStTop and LStBot are
saved on the macro stack,  and LStBot is set to LStTop,  so that LStBot
defines the bottom of the LStack frame for the new macro level.
*****************************************************************************/

GLOBAL	WORD	LStBot;			/* bottom of loop stack */
GLOBAL	struct	LStck LStack[LPS_SIZE]; /* loop stack */
GLOBAL	WORD	LStTop;			/* top of loop stack */

/*****************************************************************************
	MArgmt contains the m part of an m,n argument pair that preceeds a
TECO command.  For instance,  MArgmt would contain 10 when the command
10,45T is being executed.
*****************************************************************************/

GLOBAL	LONG	MArgmt;			/* m part of m,n numeric arguments */

/*****************************************************************************
	MAtchd is used to indicate that a match has been found for a search
string.  It is only used when a search command is being executed.
*****************************************************************************/

GLOBAL	BOOLEAN	Matchd;			/* used by search code */

/*****************************************************************************
	MemDf indicates whether filename memory was used to provide the name
of the file name on the command line used to invoke TECOC.  This variable is
used only during initialization.
*****************************************************************************/

GLOBAL	BOOLEAN	MemDf;

/*****************************************************************************
	These variables implement the macro stack.  When TECO executes a
macro,  it must first save the current state,  so that the state can be
restored when the macro has finished executing.  Each entry in the macro
stack preserves the critical variables for one macro call.
*****************************************************************************/

GLOBAL	struct	MStck MStack[MCS_SIZE]; /* macro stack */
GLOBAL	WORD	MStTop = -1;		/* top of macro stack */

/*****************************************************************************
	Tells ZChIn whether to wait until the user types a character or to
return immediately.  This variable is set by ExeCtT depending on the NOWAIT
bit in EtFlag.
*****************************************************************************/

GLOBAL	BOOLEAN	NoWait = NO;		/* no wait for input character flag

/*****************************************************************************
	NArgmt holds the numeric argument that preceeds a command.  It is set
by a call to the GetNmA function.  When the command is preceeded by an m,n
argument pair,  NArgmt holds the value of the n argument.
*****************************************************************************/

GLOBAL	LONG	NArgmt;			/* n argument (n part of m,n) */

/*****************************************************************************
	OFiles holds the file data blocks for the output files.  There are
three output streams:   the primary output stream,  the secondary output
stream and the output stream used by the E%q command.  The array is indexed
using identifiers defined in file DefTeco.h.
*****************************************************************************/

GLOBAL	struct	OFDBST	OFiles[NOFDBS];

/*****************************************************************************
	QBfBeg,  QBfPtr and QNumbr are variables used to access q-registers.
They are set by calling the FindQR function.  Whenever a command that uses a
q-register is executed,  FindQR is called to set these variables,  and then
they are used to access the text in the q-register (QBfBeg and QBfEnd) and/or
the numeric value of the q-register (QNumbr).  These are pointers which point
to the elements in the QRgstr array.
*****************************************************************************/

GLOBAL	char	*(*QBfBeg);		/* start of q-register text area */
GLOBAL	char	*(*QBfPtr);		/* end of q-register text, plus 1 */
GLOBAL	LONG	*QNumbr;		/* numeric part of q-register */

/*****************************************************************************
	The structures in the QRgstr array represent the global and main-level
local q-registers.  The 0-9 elements are for global digit q-registers (0-9),
the 10-35 elements are for global alphabetic q-registers (a-z or A-Z),  the
36-45 elements are for main-level local digit q-registers (.0-.9) and the
46-71 elements are for main-level local alphabetic q-registers (.a-.z or
.A-.Z).  Local q-registers at macro levels other than the main level are
allocated dynamically.
*****************************************************************************/

GLOBAL	struct	QReg QRgstr[72] = {
	{NULL,NULL,0L}, {NULL,NULL,0L}, {NULL,NULL,0L}, {NULL,NULL,0L},
	{NULL,NULL,0L}, {NULL,NULL,0L}, {NULL,NULL,0L}, {NULL,NULL,0L},
	{NULL,NULL,0L}, {NULL,NULL,0L}, {NULL,NULL,0L}, {NULL,NULL,0L},
	{NULL,NULL,0L}, {NULL,NULL,0L}, {NULL,NULL,0L}, {NULL,NULL,0L},
	{NULL,NULL,0L}, {NULL,NULL,0L}, {NULL,NULL,0L}, {NULL,NULL,0L},
	{NULL,NULL,0L}, {NULL,NULL,0L}, {NULL,NULL,0L}, {NULL,NULL,0L},
	{NULL,NULL,0L}, {NULL,NULL,0L}, {NULL,NULL,0L}, {NULL,NULL,0L},
	{NULL,NULL,0L}, {NULL,NULL,0L}, {NULL,NULL,0L}, {NULL,NULL,0L},
	{NULL,NULL,0L}, {NULL,NULL,0L}, {NULL,NULL,0L}, {NULL,NULL,0L},
	{NULL,NULL,0L}, {NULL,NULL,0L}, {NULL,NULL,0L}, {NULL,NULL,0L},
	{NULL,NULL,0L}, {NULL,NULL,0L}, {NULL,NULL,0L}, {NULL,NULL,0L},
	{NULL,NULL,0L}, {NULL,NULL,0L}, {NULL,NULL,0L}, {NULL,NULL,0L},
	{NULL,NULL,0L}, {NULL,NULL,0L}, {NULL,NULL,0L}, {NULL,NULL,0L},
	{NULL,NULL,0L}, {NULL,NULL,0L}, {NULL,NULL,0L}, {NULL,NULL,0L},
	{NULL,NULL,0L}, {NULL,NULL,0L}, {NULL,NULL,0L}, {NULL,NULL,0L},
	{NULL,NULL,0L}, {NULL,NULL,0L}, {NULL,NULL,0L}, {NULL,NULL,0L},
	{NULL,NULL,0L}, {NULL,NULL,0L}, {NULL,NULL,0L}, {NULL,NULL,0L},
	{NULL,NULL,0L}, {NULL,NULL,0L}, {NULL,NULL,0L}, {NULL,NULL,0L}
};

/*****************************************************************************
	QStack is the q-register stack,  accessed via the [ and ] commands.
*****************************************************************************/

GLOBAL	struct	QReg QStack[QRS_SIZE];	/* q-register stack */
GLOBAL	WORD	QStTop = -1;		/* top of q-register stack */

/*****************************************************************************
	RefLen is the length of the last inserted string or found search
string.  It is accessed by the ^S command.
*****************************************************************************/

GLOBAL	LONG	RefLen = 0L;		/* returned by ^S */

/*****************************************************************************
	Radix is TECO's radix,  usually 10.  It is set by the ^D, ^O and ^R
commands.
*****************************************************************************/

GLOBAL	DEFAULT	Radix = 10;		/* TECO's current radix */

/*****************************************************************************
	When searching,  this pointer points to the farthest-right character
in the area to be searched.  It is used after the first character of a string
has been found,  to indicate the limit of the area in the edit buffer that
should be checked against the remaining characters in the search string.
*****************************************************************************/

GLOBAL	char	*RhtSid;

/*****************************************************************************
	These variables point to the search string buffer.  The search buffer
is allocated by function MemIni.
*****************************************************************************/

GLOBAL	char	*SBfBeg = NULL;		/* start of search buffer */
GLOBAL	char	*SBfEnd;		/* end search buffer */
GLOBAL	char	*SBfPtr;		/* end of search string buffer */

/*****************************************************************************
	SIncrm is the value added to the search pointer when the edit buffer
is being searched.  If SIncrm is 1,  then the search proceeds in a forward
direction.  If SIncrm is -1,  then the search proceeds in a backward
direction.  By using this variable,  the rather complex code that implements
searching can easily be used to search in either direction.
*****************************************************************************/

GLOBAL	LONG	SIncrm;			/* search increment */

/*****************************************************************************
	SMFlag is TECOC's search mode flag,  and controls case sensitivity
during searches.  This variable holds the value of the ^X command.
*****************************************************************************/

GLOBAL	WORD	SMFlag;			/* search mode flag (^X) */

/*****************************************************************************
	SrcTyp is used to "remember" the kind of search command that we're
working on.  The same search code is used by all the search commands,  but
each search command is slightly different than the others.  The common
search code tests this variable to implement the differences.
*****************************************************************************/

GLOBAL	WORD	SrcTyp;			/* type of search (E_SEARCH, etc) */

/*****************************************************************************
	SStPtr points into the search buffer,  and is used only by the search
code.
*****************************************************************************/

GLOBAL	char	*SStPtr;		/* search string pointer */

/*****************************************************************************
	These variables are set to YES or NO based on whether the command
line used to invoke TECO-C contained optional arguments.  For instance, if
the command line contained the -r switch,  then Swit_R would be YES.
*****************************************************************************/

GLOBAL	BOOLEAN	Swit_C;		/* was a C command line switch parsed? */
GLOBAL	BOOLEAN	Swit_D;		/* was a D command line switch parsed? */
GLOBAL	BOOLEAN	Swit_M;		/* was an M command line switch parsed? */
GLOBAL	BOOLEAN	Swit_P;		/* was a P command line switch parsed? */
GLOBAL	BOOLEAN	Swit_R;		/* was an R command line switch parsed? */

/*****************************************************************************
	This table serves two functions.  It is used by the character macros
defined in file ChrMacs.h.  It is also used by the command line input code
in function ReadCS.
	The top four bits of each mask are used by the functions in ChrMacs.h.
The top four bits are masks used to represent "uppercase", "lowercase",
"digit" and "line terminator.
	The bottom four bits of each mask are used by function ReadCS.  They
are treated as a number and are used in a SWITCH statement.  In ReadCS,  the
top four bits of each mask are not used.
*****************************************************************************/

char ChrMsk[128] =
		{
		RCS_DEF,		/* null */
		RCS_CCH,		/* ^A */
		RCS_CCH,		/* ^B */
		RCS_CCH,		/* ^C */
		RCS_CCH,		/* ^D */
		RCS_CCH,		/* ^E */
		RCS_CCH,		/* ^F */
		RCS_CTG,		/* ^G (bell) */
		RCS_BS,			/* ^H (bs) */
		RCS_DEF,		/* ^I (tab) */
		RCS_LF | CM_LINE_TERM,	/* ^J (lf) */
		RCS_VF | CM_LINE_TERM,	/* ^K (vt) */
		RCS_VF | CM_LINE_TERM,	/* ^L (ff) */
		RCS_CR,			/* ^M (cr) */
		RCS_CCH,		/* ^N */
		RCS_CCH,		/* ^O */
		RCS_CCH,		/* ^P */
		RCS_CCH,		/* ^Q */
		RCS_CCH,		/* ^R */
		RCS_CCH,		/* ^S */
		RCS_CCH,		/* ^T */
		RCS_CTU,		/* ^U */
		RCS_CCH,		/* ^V */
		RCS_CCH,		/* ^W */
		RCS_CCH,		/* ^X */
		RCS_CCH,		/* ^Y */
		RCS_CTZ,		/* ^Z */
		0,			/* escape */
		RCS_DEF,		/* FS */
		RCS_DEF,		/* GS */
		RCS_DEF,		/* RS */
		RCS_DEF,		/* US */
		RCS_SP,			/* space */
		RCS_DEF,		/* ! */
		RCS_DEF,		/* " */
		RCS_DEF,		/* # */
		RCS_DEF,		/* $ */
		RCS_DEF,		/* % */
		RCS_DEF,		/* | */
		RCS_DEF,		/* ' */
		RCS_DEF,		/* ( */
		RCS_DEF,		/* ) */
		RCS_AST,		/* * */
		RCS_DEF,		/* + */
		RCS_DEF,		/* , */
		RCS_DEF,		/* - */
		RCS_DEF,		/* . */
		RCS_DEF,		/* / */
		RCS_DEF | CM_DIGIT,	/* 0 */
		RCS_DEF | CM_DIGIT,	/* 1 */
		RCS_DEF | CM_DIGIT,	/* 2 */
		RCS_DEF | CM_DIGIT,	/* 3 */
		RCS_DEF | CM_DIGIT,	/* 4 */
		RCS_DEF | CM_DIGIT,	/* 5 */
		RCS_DEF | CM_DIGIT,	/* 6 */
		RCS_DEF | CM_DIGIT,	/* 7 */
		RCS_DEF | CM_DIGIT,	/* 8 */
		RCS_DEF | CM_DIGIT,	/* 9 */
		RCS_DEF,		/* : */
		RCS_DEF,		/* ; */
		RCS_DEF,		/* < */
		RCS_DEF,		/* = */
		RCS_DEF,		/* > */
		RCS_DEF,		/* ? */
		RCS_DEF,		/* @ */
		RCS_DEF | CM_UPPER,	/* A */
		RCS_DEF | CM_UPPER,	/* B */
		RCS_DEF | CM_UPPER,	/* C */
		RCS_DEF | CM_UPPER,	/* D */
		RCS_DEF | CM_UPPER,	/* E */
		RCS_DEF | CM_UPPER,	/* F */
		RCS_DEF | CM_UPPER,	/* G */
		RCS_DEF | CM_UPPER,	/* H */
		RCS_DEF | CM_UPPER,	/* I */
		RCS_DEF | CM_UPPER,	/* J */
		RCS_DEF | CM_UPPER,	/* K */
		RCS_DEF | CM_UPPER,	/* L */
		RCS_DEF | CM_UPPER,	/* M */
		RCS_DEF | CM_UPPER,	/* N */
		RCS_DEF | CM_UPPER,	/* O */
		RCS_DEF | CM_UPPER,	/* P */
		RCS_DEF | CM_UPPER,	/* Q */
		RCS_DEF | CM_UPPER,	/* R */
		RCS_DEF | CM_UPPER,	/* S */
		RCS_DEF | CM_UPPER,	/* T */
		RCS_DEF | CM_UPPER,	/* U */
		RCS_DEF | CM_UPPER,	/* V */
		RCS_DEF | CM_UPPER,	/* W */
		RCS_DEF | CM_UPPER,	/* X */
		RCS_DEF | CM_UPPER,	/* Y */
		RCS_DEF | CM_UPPER,	/* Z */
		RCS_DEF,		/* [ */
		RCS_DEF,		/* \ */
		RCS_DEF,		/* ] */
		RCS_DEF,		/* ^ */
		RCS_DEF,		/* _ */
		RCS_GRV,		/* ` */
		RCS_LWR | CM_LOWER,	/* a */
		RCS_LWR | CM_LOWER,	/* b */
		RCS_LWR | CM_LOWER,	/* c */
		RCS_LWR | CM_LOWER,	/* d */
		RCS_LWR | CM_LOWER,	/* e */
		RCS_LWR | CM_LOWER,	/* f */
		RCS_LWR | CM_LOWER,	/* g */
		RCS_LWR | CM_LOWER,	/* h */
		RCS_LWR | CM_LOWER,	/* i */
		RCS_LWR | CM_LOWER,	/* j */
		RCS_LWR | CM_LOWER,	/* k */
		RCS_LWR | CM_LOWER,	/* l */
		RCS_LWR | CM_LOWER,	/* m */
		RCS_LWR | CM_LOWER,	/* n */
		RCS_LWR | CM_LOWER,	/* o */
		RCS_LWR | CM_LOWER,	/* p */
		RCS_LWR | CM_LOWER,	/* q */
		RCS_LWR | CM_LOWER,	/* r */
		RCS_LWR | CM_LOWER,	/* s */
		RCS_LWR | CM_LOWER,	/* t */
		RCS_LWR | CM_LOWER,	/* u */
		RCS_LWR | CM_LOWER,	/* v */
		RCS_LWR | CM_LOWER,	/* w */
		RCS_LWR | CM_LOWER,	/* x */
		RCS_LWR | CM_LOWER,	/* y */
		RCS_LWR | CM_LOWER,	/* z */
		RCS_DEF,		/* { */
		RCS_DEF,		/* | */
		RCS_DEF,		/* } */
		RCS_DEF,		/* ~ */
		RCS_DEL			/* delete */
	};

/*****************************************************************************
	This variable is set to YES when TECO's trace mode is on.  When it is
set,  commands are echoed to the terminal as they are executed.  This mode is
used to aid in debugging TECO macros,  and is toggled by the ? command.
*****************************************************************************/

GLOBAL	BOOLEAN	TraceM = NO;		/* trace mode flag */

/*****************************************************************************
	TrmTyp is the terminal type.  It is used by the ScrnOp function to
drive the few screen capabilities of TECOC.
*****************************************************************************/

GLOBAL	LONG	TrmTyp = UNTERM;	/* terminal type */

/*****************************************************************************
	These variables point to the wildcard file specification buffer.  The
buffer itself (FBfBeg) is defined in system-dependent code because the size of
the buffer is system-dependent.
*****************************************************************************/

GLOBAL	char	*WBfEnd;		/* last chr (+1) of filespec buffer */
GLOBAL	char	*WBfPtr;		/* pointer into file spec buffer */



main(argc,argv)
int argc;
char *argv[];
{

	Init(argc, argv);			/* initialize TECO */

/*****************************************************************************
	read a command string and then execute it.  This loop is infinite.
	TECO-C is exited explicitly when a lower-level function calls ZAbort.
*****************************************************************************/

	CStBeg = CStEnd = CBfBeg;
	CStEnd--;
	FOREVER					/* loop forever */
		{
		ReadCS();			/* read command string */
		CBfPtr = CBfBeg;		/* command string pointers */
		CmdMod = '\0';			/* clear modifiers flags */
		EStTop = EStBot =		/* clear expression stack */
		LStTop = LStBot =		/* clear loop stack */
		MStTop = -1;			/* clear macro stack */
		ExeCSt();			/* execute command string */
		}
}
