/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
.TYPE 		Header
.NAME 		tex.h
.LANGUAGE 	C
.AUTHOR		Francois Ochsenbein [ESO]
.CATEGORY	TeX-like scan
.COMMENTS 	Definition of structures for scanning
		a ``TeX-like'' text.
.ENVIRONMENT	
.VERSION 1.0	20-Apr-1988: Creation
.VERSION 1.1	20-Nov-1990: Added obeylines / obeyspaces
.VERSION 1.2	10-Sep-1991: New routines tex_new tex_kill tex_setact
.VERSION 1.3	08-Feb-1994: Added end_mode
.VERSION 1.4	20-Oct-1994: Modified obey codes
------------------------------------------------------------*/

#ifndef TEX_DEF

#define TEX_DEF		0

#include <hash.h>	/* Hash table is used	*/

#ifdef __STDC__
#define _ARGS(A)        A /* ANSI */
#else
#define _ARGS(A)        ()  /* non-ansi */
#endif

/*===========================================================================
 *             Structures
 *===========================================================================*/

#define TeX_BUF	40			/* Normally, only one word... 	*/

typedef struct {
	H_TABLE *macros;		/* Stored macros		*/
	int	(*output)();		/* Output function		*/
	int	(*action)();		/* Action function		*/
	char	*ap;			/* Parameter address		*/
	char	*end_mode;		/* String marking end of mode	*/
	char	mode;			/* Verbatim mode flag		*/
#define _TeX_BEGIN_	'\001'		/* New Environment		*/
#define _TeX_END_	'\002'		/* End Environment		*/
#define _TeX_ACTION_	'\003'		/* Triggers action = next byte	*/
#define _TeX_ENDACTION_	'\004'		/* End-of-action byte		*/
#define _TeX_VERBATIM_	'\005'		/* Inhibate substitutions	*/
#define _TeX_DEF_	'\006'		/* Definition flag		*/
#define _TeX_INCLUDE_	'\007'		/* Include a file		*/
#define _TeX_IF_	'\021'		/* Basic tests			*/
#define _TeX_LEN_	'\022'		/* Length of a text		*/
#define _TeX_TIME_	'\023'		/* Date / Time editions		*/
#define _TeX_setchar_	'\033'		/* Redefine class of char	*/
#define _TeX_obeylines	'\110'		/* Keep original line breaks	*/
#define _TeX_obeyspaces	'\150'		/* Keep original tabs / spaces	*/
#define _TeX_obey_	0100
	unsigned char	flags;		/* Defined by user		*/
	short int nbuf;			/* Number of chars in out_buf	*/
	char	out_buf[TeX_BUF];
	} TeX;

/*===========================================================================
 *		Function Templates
 *===========================================================================*/
int 	tex_exec	_ARGS((TeX *htex, char *str, int len));
int 	tex_mexec	_ARGS((TeX *htex, char **str, int nstrings));
int 	tex_tell	_ARGS((void));
int 	tex_getvparm	_ARGS((int param_no));		/* Verbatim parameter	*/
int 	tex_getparm	_ARGS((int param_no));		/* Processed parameter	*/
int 	tex_unit	_ARGS((char *str, int len));	/* Length of {....}	*/
int 	tex_input	_ARGS((TeX *htex, char *filename, int opt));
int 	tex_load	_ARGS((TeX *htex, int fid, int len, int opt));
int 	tex_list	_ARGS((TeX *htex));		/* List Macros		*/
char	*tex_symbol	_ARGS((char *str));		/* Conversion of a Symbol */
TeX	*tex_new	_ARGS((int (*out)(), int (*act)(), int symbols));
int 	tex_kill	_ARGS((TeX *htex));		/* Terminate		*/
int 	tex_setact	_ARGS((TeX *htex, char *name, char *(*act)())); 

/*===========================================================================
 *             Related functions and macros
 *===========================================================================*/

#define TeX_Execute(hTeX,s,l)		tex_exec(hTeX,s,l)
#define TeX_Continue(hTeX)		tex_exec(hTeX,(char *)0, 0)

#define TeX_ExecuteArray(hTeX,ss,n)	tex_mexec(hTeX,ss,n)
#define TeX_ExecuteString(hTeX,s)	tex_exec(hTeX,s,strlen(s))

#define TeX_Load(hTeX,fid,bytes)	tex_load(hTeX,fid, bytes,0)
#define TeX_Include(hTeX,fname)		tex_input(hTeX,fname,0)

#define TeX_SetAction(hTeX,name,act)	tex_setact(hTeX,name,act)
#define TeX_Create(out,act,n)		tex_new(out,act,n)
#define TeX_Kill(hTeX)			tex_kill(hTeX)

#endif
