/*******************************************************************************
* YORKTOWN ADVANCED SGML PARSER (YASP)                                         *
*         An SGML Parser conforming to International Standard ISO 8879 --      *
*         Standard Generalized Markup Language                                 *
*------------------------------------------------------------------------------*
* Written 1987 - 1993 by                                                       *
*         Pierre G. Richard                                                    *
*         IBM T.J. Watson Research Center                                      *
*         Yorktown Heights, New York                                           *
*         petrus@watson.ibm.com                                                *
*------------------------------------------------------------------------------*
* FUNCTION NAME    = YASP / Header File                                        *
* STATUS           = Version 0, Release 1, Level 25 and up                     *
* COMPONENT NAME   = modele.h                                                  *
* DESCRIPTIVE NAME = modele: block and functions                               *
* DATE_WR          = 02/23/1988                                                *
* AUTHOR           = Pierre G. Richard - PETRUS at YKTVMX                      *
*                                                                              *
* FUNCTIONAL DESCRIPTION =                                                     *
* IMPLEMENTATION NOTES =                                                       *
* CHANGE HISTORY =                                                             *
*******************************************************************************/

#if (GRPCNT_MAX <= 32)
typedef unsigned long HITS;
#else
typedef uchar HITS[(GRPCNT_MAX+7)/8];
#endif

typedef enum t_MS {        /* Modele status, some values saved in TCB */
   MATCH_MS   = 1, /*TCB*/ /* GI is the one expected next */
   FINISH_MS  = 2, /*TCB*/ /* All token have been checked */
   INVALID_MS = 3, /*TCB*/ /* GI invalid: not element end; no required GI */
   MATCHX_MS,              /* Current GI was an invalid exclusion */
   REQRD_MS,               /* Required GI must precede proposed GI */
   REQRDX_MS,              /* A required GI was an invalid exclusion */
   EXCLUS_MS,              /* GI is invalid: exclusion (minus exception) */
   INCLUS_MS,              /* GI is valid as an inclusion (plus exclusion) */
   REPARSE_MS,             /* Need to reparse current char (stow_dtcb) */
   OOCDATA_MS,             /* Out-of-context data */
   OOCSTG_MS               /* Out-of-context start_tag */
}MS;

typedef struct {
   MDL *mdl_p;             /* Group node in the model */
   uint   ix;              /* Index of the current token in this group */
   HITS hits;              /* Hit bits of this group's tokens */
}GRP;

/* TCB's are on the stack (in the nearby), so are GRP */
typedef GRP STACK_BASED * GRP_P;

typedef union {
   struct {
      uint ms          :2; /* MATCH, INVALID, FINISHED (temporary: NONE) */
      uint zero        :1; /* This is the first TCB in the array */
      uint net_enabling:1; /* Tag enables NET */
      uint net_enabled :1; /* NET enabled now and/or before */
      uint pex         :1; /* Tag was plus exception */
      uint mhit        :1; /* Header model group was hit */
      uint dtag_enabled:1; /* DATATAG enabled now and/or before */
      uint bad_empty   :1; /* If tag has been omitted and empty content */
      uint unused      :7;
   }b;
   uint all_bits;          /* also used to save the mex level */
}TCB_FLAGS;

typedef struct t_TCB {     /* Tag control block */
   ELT *elt_p;             /* Element type for this tag */
   SRM *srm_p;             /* Shortref map (could be inherited, or modified) */
   DTP *dtp_p;             /* Data tag pattern (if any) */
   TCB_FLAGS is;           /* If mdl_goto return MEX, tcb_p+1->is == mex lvl */
                           /* Directions taken in model road map: */
   GRP_P grp_p;            /* Last entry in grp array (current group) */
   GRP   grp_p0[GRPLVL+1]; /* Array of traversed group nodes */
}TCB;                      /* Last entry + 1 is current token */

/* TCB's are on the stack (in the nearby) */
typedef TCB STACK_BASED * TCB_P;

extern MS      P_FCT mdl_goto  (TCB_P, ELT *);
extern MS      P_FCT mdl_fini  (TCB_P);
extern void    P_FCT mdl_edtg  (TCB_P);
/******************************************************************************/
