#ifndef AZTEC_C

#include <stdio.h>
#include <sys/types.h>
#include <ctype.h>
#include <time.h>
#include <string.h>
#include <fcntl.h>

#endif

/**** Definitions des constantes ***/

#define LGMAXNDF 255
#define LGMAXBUF 512
#define LGMAXSTR 255

#define IM_FILLING 0x01 	/* filling on */
#define IM_RDMACRO 0x02 	/* defining macro */
#define IM_EXMACRO 0x04 	/* executing macro */
#define IM_RDARGS  0x08 	/* reading args. of request */
#define IM_TRANSP  0x10 	/* transparent mode */
#define IM_STRING  0x20 	/* inserting string */

#define AM_BOTH    1		/* mode d'ajustement */
#define AM_RIGHT   2
#define AM_LEFT    3
#define AM_CENTER  4

#define DEF_LINLEN 80		/* valeurs par defaut */
#define DEF_PAGLEN 66
#define DEF_TITLEN 80
#define DEF_INDENT 0
#define DEF_PAGNUM 1
#define DEF_LINSPC 1
#define DEF_PAGOFS 0
#define DEF_TABLEN 8
#define DEF_TABCHR ' '
#define DEF_LINNUM 1
#define DEF_PILE   256
#define DEF_TITSEQ 6

#define F_WASBS    0x0001	/* prev. char. was '\'   */
#define F_WASNL    0x0002	/* prev. char. was '\n'  */
#define F_SKIPEOL  0x0004	/* ignore until EOL	 */
#define F_NOBRK    0x0008	/* desactive do_br()     */
#define F_NEWPAR   0x0010	/* new section (2 \n)    */
#define F_NOTI	   0x0020	/* derniere req != "ti"  */
#define F_BREAKED  0x0040	/* ligne "cassee" (.br)  */
#define F_NUMBER   0x0080	/* numerote les lignes	 */
#define F_MACREQ   0x0100	/* exec requete/macro	 */
#define F_TRAP	   0x0200	/* trappe declanchee	 */
#define F_SORTIE   0x0400	/* au moins 1 lig sortie */
#define F_CONTINUE 0x0800	/* continue et non break */
#define F_WASIF    0x1000	/* derniere req == 'if'  */
#define F_WASFALSE 0x2000	/* dernier 'if' faux     */
#define F_IFNOT    0x4000	/* .if ! <reste>	 */
#define F_LOADED   0x8000	/* option -l indiquee	 */

#define SC_IGNORE  '\001'
#define SC_FIXSPC  '\002'
#define SC_EXPAND  '\003'

#define ERR_INTERNAL	0	/* erreur interne....  */
#define ERR_PILEV	1	/* pile vide	       */
#define ERR_PILEP	2	/* pile pleine	       */
#define ERR_SYNTAX	3	/* erreur de syntaxe   */
#define ERR_OVERFLOW	4	/* debordement table   */
#define ERR_OPEN	5	/* err. ouverture fic. */
#define ERR_ARGS	6	/* args. incorrects    */
#define ERR_WRITE	7	/* erreur en ecriture  */
#define ERR_MEMORY	8	/* plus de memoire     */
#define ERR_IFELSE	9	/* else sans if        */
#define ERR_SEEK       10	/* lseek() a echoue    */
#define ERR_READ       11	/* erreur de lecture   */
#define ERR_EMPTY      12	/* fichier vide        */

#define BSET( f , b ) f |= b
#define BCLR( f , b ) f &= ~b
#define Fatal( c ) FatalError( c , __LINE__ , __FILE__ )

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

struct Noeud
{
  struct Noeud *el_Suivant ;
  struct Noeud *el_Precedant ;
} ;

struct TeteListe
{
  struct Noeud *tl_Premier ;
  struct Noeud *tl_Dernier ;
  long		tl_NbrElem ;
} ;

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

struct MLine
{
  struct Noeud	ml_Node ;		/* ptr ligne suiv. */
  long		ml_Len ;		/* taille ligne    */
  unsigned char ml_Text[LGMAXSTR] ;	/* ligne elle-meme */
} ;

struct Macro
{
  struct Noeud	   m_Node ;	/* ptr macro suivante */
  char		   m_Name[3] ;	/* nom de cette macro */
  long		   m_Flag ;	/* indicateurs divers */
  struct TeteListe m_Def ;	/* tete liste lignes  */
  struct MLine	  *m_NextL ;	/* ptr ligne a lire   */
  long		   m_NextC ;	/* ptr caract. a lire */
  long		   m_NbArg ;	/* nombre d'arguments */
  unsigned char   *m_Arg[10] ;	/* args. */
} ;

#define MF_TRAP 0x01	/* appele par une trappe */
#define MF_WAIT 0x02	/* a une ligne en attente */

struct InputFile
{
  struct Noeud	if_Node ;	/* ptr fichier suivant */
  char		*if_Name ;	/* nom de ce fichier   */
  int		if_Desc ;	/* retourne par open() */
  unsigned char *if_Buf ;	/* tampon de lecture   */
  long		if_BufLen ;	/* nb de car. ds ifBuf */
  long		if_NextC ;	/* ptr caract. a lire  */
  long		if_Line ;	/* no ligne courante   */
  long		if_Flag ;	/* indicateurs	       */
} ;

#define IFF_STDIN  0x01  /* fichier = entree standard */
#define IFF_LOADED 0x02  /* fichier charge en memoire */

struct Command
{
  char *c_name ;
  void (*c_func)() ;
} ;

struct String
{
  long	s_pos ;
  long	s_len ;
  char	s_val[LGMAXSTR+1] ;
} ;

struct Contexte
{
  union
  {
    struct InputFile c_file ;
    struct Macro     c_macro ;
    struct String    c_string ;
  } src ;
  long		   c_ptr  ;
  long		   c_len  ;
  long		   c_olen ;
  char		   c_obuf[LGMAXBUF] ;
  char		   c_ibuf[LGMAXBUF] ;
  long		   c_seek ;
  long		   c_imod ;
  long		   c_flag ;
} ;

