/*******************************************************************************
* 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 34 and up                     *
* COMPONENT NAME   = odt.h                                                     *
* DESCRIPTIVE NAME = Define structures shared by ODT modules                   *
* DATE_WR          = 03/29/1988                                                *
* AUTHOR           = Pierre G. Richard - PETRUS at YKTVMX                      *
*                                                                              *
* FUNCTIONAL DESCRIPTION =                                                     *
* IMPLEMENTATION NOTES =                                                       *
* CHANGE HISTORY =                                                             *
*******************************************************************************/

typedef struct t_GI {           /* for each GI, pointed by ehsh_p->var_p */
   struct t_ENODE *enode_p;     /* ENODE */
   struct t_ANHDR *anhdr_p;     /* ANODE Header */
   struct t_SNODE *snode_p;     /* SNODE for shortref map */
   struct t_RKLN  *rkln_p;      /* Rank Node */
   uint   hash_ix;
   uchar *name_p;               /* GI name (ambiguities error msg) */
   uint   mdl_id      :15;      /* seq nbr, check dup GIs in a same model */
   uint   is_duplicate: 1;      /* duplicate GI (>= 2) for this mdl_id */
}GI;

typedef struct t_NB {           /* for each NB, pointed by ehsh_p->var_p */
   union {
      struct t_ANHDR *anhdr_p;  /* ANODE Header */
      int    atd_ix;            /* ix in ATD (temporary) */
   }u;
   union {
      EXID  *exid_p;            /* EXID pointer */
      int ncb_ix;               /* ix in NCB array (Temporary) */
   }v;
}NB;                            /* (Notation Block) */

typedef struct t_SNODE {        /* For each shortref map */
   uint ref_cnt;                /* count how many times this node referenced */
   union {
      SRM *srm_p;               /* array of sr_max SRM elements */
      int ix;                   /* index to the SRM in the SRM table */
   }u;
}SNODE;

typedef struct t_ENODE {
   ELT_FLAGS is;
   uint ref_cnt;                /* count how many times this node referenced */
   union {
      struct t_MNODE *mnode_p;  /* model node, and later (if solved) .... */
      uint  mdl_ix;             /* ...index in MDL array of the model */
      TK  dcl_tk;               /* exc if special: RCDATA, CDATA, EMPTY, ANY */
   }u;
   union {                      /* Minus exceptions: */
      struct t_EXCPT *p;        /* pointer, and later (when solved)...  */
      int ix;                   /* ...index in the EX array (-1 if none) */
   }mexcpt;
   union {                      /* Plus exceptions: */
      struct t_EXCPT *p;        /* pointer, and later (when solved)...  */
      int ix;                   /* ...index in the EX array (-1 if none) */
   }pexcpt;
}ENODE;

#define M_ltag(mnode_p) (mnode_p)->is.connector

typedef struct {
   uint rtag           :1;      /* tell rlink is right_link / thread */
   uint connector      :2;      /* also tell llink is left_link / elt */
   uint occurence      :2;      /* is_omittable, is_repeatable */
   uint target         :1;      /* is a target tag */
   uint pcdata         :1;      /* is pcdata */
   uint datatag        :1;      /* is a datatag */
   uint one_reqd       :1;      /* if one token in the subgroup is required */
   uint one_omit       :1;      /* if one token in the subgroup is omittable */
   uint ambig_found    :1;      /* a GI mnode and ambiguity found */
}MNODE_FLAGS;

typedef struct t_MNODE {
   MNODE_FLAGS     is;
   struct t_MNODE *rlink;       /* right link if rtag, or thread */
   union {
      struct t_MNODE *llink;    /* left link if ltag, or */
      struct t_GI    *gi_p;     /* *NOT* a thread / 0 for #PCDATA */
      OFS            *ofs_p;    /* Offset of datatag pattern / template(s) */
   }u;
}MNODE;

typedef struct t_EXCPT {        /* exception chain */
   struct t_GI    *gi_p;
   struct t_EXCPT *next;
}EXCPT;

typedef struct t_ANODE {
   struct t_ANODE *next_p;   /* circular list */
   ATD  atd;
}ANODE;

typedef struct {                /* Anode Flags */
   uint required      :1;       /* if TRUE, a REQUIRED attribute exists */
   uint current       :1;       /* if TRUE, a CURRENT  attribute exists */
   uint conref        :1;       /* if TRUE, a CONREF   attribute exists */
   uint notation      :1;       /* if TRUE, a NOTATION attribute exists */
   uint entity        :1;       /* if TRUE, one or more ENTITY(IES) attributes */
   uint id            :1;       /* if TRUE, an ID attribute exists */
   uint solved        :1;       /* if TRUE: u is atd_ix, or FALSE: first_p */
}ANHDR_FLAGS;

typedef struct t_ANHDR {        /* Anode Header */
   union {
      struct t_ANODE *anode_p;  /* first of a circular list */
      uint atd_ix;              /* used when unloading ...*/
   }u;
   uint ref_cnt;                /* count how many times this node referenced */
   uint atdsize;                /* size of the ATD array */
   ANHDR_FLAGS is;
}ANHDR;

typedef struct t_RKLN {         /* Rank Nodes */
   union {
      uint   rkl_ix;            /* temporary: index in RKL array */
      struct t_RKLN *stem_p;    /* Same stem link */
   }s;
   union {
      uint   stem_cnt;          /* For the STEM, count RKL with same stem */
      struct t_RKLN *group_p;   /* Same group link */
   }g;
}RKLN;

/*-----------------------------------------------------------------+
|This structure is a common data area used when compiling the DTD  |
+-----------------------------------------------------------------*/
typedef struct {
   GA_P gbla_p;
   MNODE  **link;
   ENODE   *enode_p;
   void   **patch_pp;
   ANODE   *anode_p;
   SNODE   *snode_p;
   EXCPT  **excpt_pp;
   GI      *doc_elmt_gi_p;     /* see ISO 8879-1986 4.99 p 10 */
   uint     occurence, connector, kind_of_mnode;
   void    *elt_scope;
   void    *srm_scope;
   void    *nota_scope;
   void    *stem_scope;
   boolean  is_notation_adl;
   boolean  must_check_ambiguities;
   boolean  is_PCDATA_duplicate;
   uint     erh_action;
   uint     mdl_id;
   uint     nbr_of_model, nbr_of_useless_model, nbr_of_elt,
            nbr_of_exceptions, nbr_of_excptnames,
            nbr_of_rkl, nbr_of_sts,
            nbr_of_attributes,
            nbr_of_att_dclv, nbr_of_dclv_text, nbr_of_attdesc,
            nbr_of_p_entities,
            nbr_of_g_text, nbr_of_p_text,
            nbr_of_srmap,
            nbr_of_dtp, nbr_of_datatag, nbr_of_datatag_text,
            nbr_of_nad, nbr_of_ncb, nbr_of_nxid_text,
            nbr_of_exid_text,
            grplvl, grpgtc, attcnt, ety_ix;
   uchar    name[NAMELEN_MAX+1], idname[NAMELEN_MAX+1], *names_p, *c_p;
   OFS      dflety_exid_val_ofs, dflety_val_lit_ofs;
   int      dflety_val_nad_ix;
   OFS     *ofs_p;                    /* for datatag pattern / template(s) */
   MDL     *mdl_p, *mdl_orig;
   ELT     *elt_orig;
   EX      *ex_p, *ex_orig;           /* array of index to ELT array */
   ATD     *atd_p, *atd_orig;
   ADLEN   *desc_p, *desc_orig;
   EXID    *exid_p, *exid_orig;
   ETY     *ety_p;
   SRM     *srm_p, *srm_orig;         /* ptr to an array of SRM */
   DTP     *dtp_p, *dtp_orig;
   NAD     *nad_p, *nad_orig;
   NCB     *ncb_p, *ncb_orig;
   RKL     *rkl_p, *rkl_orig;
   STS     *sts_p, *sts_orig;
}COMMON_ODT_AREA;

/* Common area is on the stack (in the nearby) */
typedef COMMON_ODT_AREA STACK_BASED * COMMON_P;

extern void P_FCT odt_uatd  (COMMON_P, ATD *);
extern void P_FCT elm_deco  (COMMON_P);
extern void P_FCT elm_mdbl  (COMMON_P, MNODE *, ushort *);
extern void P_FCT elm_exbl  (COMMON_P, EXCPT *);
extern void P_FCT adl_deco  (COMMON_P);
extern int  P_FCT adl_ulad  (COMMON_P, ANHDR *);
extern void P_FCT ety_deco  (COMMON_P);
extern void P_FCT ety_bld   (void STACK_BASED *, EHSH *);
extern void P_FCT srf_mpty  (COMMON_P);
extern void P_FCT srf_sdec  (COMMON_P);
extern void P_FCT srf_udec  (COMMON_P);
extern void P_FCT srf_bld   (void STACK_BASED *, EHSH *);
extern void P_FCT nta_deco  (COMMON_P);
extern void P_FCT nta_bld   (void STACK_BASED *, EHSH *);
extern void P_FCT abg_chk   (COMMON_P, MNODE *);
/******************************************************************************/
