/*******************************************************************************
* 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 + Application / Header file                          *
* STATUS           = Version 0, Release 1, Level 36 and up                     *
* COMPONENT NAME   = yaspapi.h                                                 *
* DESCRIPTIVE NAME = Parser Application Interface Definitions                  *
* DATE_WR          = 01/08/1988                                                *
* AUTHOR           = Pierre G. Richard - PETRUS at YKTVMX                      *
*                                                                              *
* FUNCTIONAL DESCRIPTION =                                                     *
* H file to establish PARSER <-> APPLICATION Interface conventions             *
*                                                                              *
* IMPLEMENTATION NOTES =                                                       *
* All Parser function calls use C conventions: the C_FCT #defined constant     *
* can be used to insure that the C compiler uses the correct call convention   *
* (if it can handle several: pascal, C, fortran...).  In such a case,          *
* add a "#define C_FCT cdecl" in an H file (like gendef.h) included            *
* prior to this one.  By default, the C_FCT is voided.                         *
*                                                                              *
* CHANGE HISTORY =                                                             *
* Number Date     Inits    Change & reason (brief)                             *
*      1 01/05/90 GPD      Packaging (only one file)                           *
*      2 02/20/90 GPD      PAC005: new messages                                *
*      3 06/14/90 PETRUS   PAC006 - Parser Services                            *
*      4 10/19/90 PETRUS   Same file for the Parser and the Application        *
*      5 12/11/90 PETRUS   Isolating S/CDATA entities in CDATA AVL             *
*      6 01/06/91 PETRUS   PAC007 - More PFC codes                             *
*      7 01/20/91 PETRUS   PAC008 - To report start/end entities               *
*      8 03/01/91 DUROT    PAC009 - Skipped Data Notif, PAC "position" field   *
*      9 06/06/91 GPD/PGR  PAC011                                              *
*     10 08/24/91 PETRUS   PAC012 - Field for Application Private Use          *
*     11 08/27/91 PETRUS   DED and ATD changes.  What implied a tag?           *
*     12 12/20/91 PETRUS   PAC013 - Opened Entity Block                        *
*     13 12/20/91 PETRUS   PAC014 - UTSYNR (for SCOPE INSTANCE)                *
*     14 09/28/92 PETRUS   Added getpos/setpos services                        *
*     15 05/13/93 PETRUS   Added OMITNAME_AF                                   *
*     16 08/09/93 GLS/PGR  Enabled to C++                                      *
*     17 03/31/95 ESPERT   Added new ahlid for character sets                  *
*     18 06/13/95 ESPERT   SUBMAIN in yasp.c for SUBDOC                        *
*     19 04/01/97 ESPERT   Added new PFCs for markup declarations              *
*******************************************************************************/
#ifndef INCL_NO_YASP_PSE   /* Include PSE.H, except if user don't want it */
#include "pse.h"
#endif  /* INCL_NO_YASP_PSE */
#ifndef YASP_API_INCLUDED  /* protect against multiple include */
#define YASP_API_INCLUDED

#ifndef C_FCT
#define C_FCT
#endif

#ifdef __cplusplus         /* crissXcrossed references */
typedef struct t_ELT ELT;
typedef struct t_ATD ATD;
#endif

/*-----------------------------------------------------------------------------+
|OFS: string offset within stringbuf (for YASP internal use)                   |
+-----------------------------------------------------------------------------*/
typedef unsigned int OFS;

/*-----------------------------------------------------------------------------+
|AHL: Application Handle                                                       |
+-----------------------------------------------------------------------------*/
typedef union {           /* to pass any kind of file handle */
   void *p;               /* either pointer */
   int   i;               /* or identifier */
}AHL;

/*-----------------------------------------------------------------------------+
| OFLEN: Standard Offset/Length descriptor                                     |
+-----------------------------------------------------------------------------*/
typedef struct {           /* to access to a subfield */
   unsigned int rel;       /* Relative offset of the subfield within adlen.p */
   unsigned int len;       /* Subfield length */
}OFLEN;

/*-----------------------------------------------------------------------------+
|ADLEN: Standard Address/Length descriptor                                     |
+-----------------------------------------------------------------------------*/
#ifndef YASP_PARSER_CODE

/* simplified version for an application */
typedef struct {           /* to pass any lengthed chunk */
   void * p;               /* address */
   int    len;             /* length */
}ADLEN;

#else
/* The ADLEN is modified to allow string relocation */
typedef struct {           /* to pass any lengthed chunk */
   union {
     void  *p;
     OFS   ofs;
     int   ix;
   }_;
   int    len;
}ADLEN;

#endif

/*-----------------------------------------------------------------------------+
|PFC:  Application function request codes                                      |
|                                                                              |
|pac.dad.p -> structure: means the length is immaterial                        |
|pac.dad means the entire ADLEN describes data                                 |
+-----------------------------------------------------------------------------*/
typedef enum {
   RES_PFC=0,       /*  0 is Reserved */
   ELTST_PFC,       /*  1 Start element: pac.dad.p -> DED */
   ELTND_PFC,       /*  2 End element: pac.dad.p -> DED */
   RE_PFC,          /*  3 Relevant record end (No data) */
   TEXT_PFC,        /*  4 Text data: pac.dad */
   PI_PFC,          /*  5 Processing instruction: pac.dad */
   NSGML_PFC,       /*  6 Report Non SGML characters */
   ETY_PFC,         /*  7 Data Entity: pac.dad.p -> ETY */
   MSG_PFC,         /*  8 Message: pac.dad, pac.errc */

   SGET_PFC,        /*  9 Get storage: pac.stg.len; returns pac.stg.p */
   SFRE_PFC,        /* 10 Free storage: pac.stg */

   /* This function takes an External Identifier, returns a Fileid-AHL */
   FIND_PFC,        /* 11 Get a FileId-AHL: pac.dad.p -> EXID */

   /* The following functions take a FileId-AHL, returns an Access-AHL */
   XENOP_PFC,       /* 12 Open External Entity */
   UTOPR_PFC,       /* 13 Open Utility File for Reading */
   UTOPW_PFC,       /* 14 Open Utility File for Writing */

   /* The following functions use an Access-AHL */
   UTWRT_PFC,       /* 15 Write Utility File record: pac.dad */
   UTRD_PFC,        /* 16 Read utility file record: returns pac.dad */
   UTCL_PFC,        /* 17 Close an Utility File */

   XENRD_PFC,       /* 18 Read Data from an External Entity: returns pac.dad */
   XENCL_PFC,       /* 19 Close an External Entity */

   /* Miscellaneous Notifications */
   PROST_PFC,       /* 20 Begin Prolog */
   PROND_PFC,       /* 21 End of Prolog found */
   DOCND_PFC,       /* 22 End of DOC found - Parse Ended */

   ETYST_PFC,       /* 23 Report start parsing an Entity: pac.dad.p -> ETY */
   ETYND_PFC,       /* 24 Report end of an Entity */

   SR_PFC,          /* 25 A mapped shortref has been found */
   MAP_PFC,         /* 26 USEMAP declaration in the instance */
   SKIP_PFC,        /* 27 Skipped data: pac.sdc has the SDC */

   DECST_PFC,       /* 28 Start of SGML Declaration */
   DTDST_PFC,       /* 29 Start of DTD */
   DTDND_PFC,       /* 30 End of DTD */

   DAPND_PFC,       /* 31 End of DOC right After Prolog - Parse continues */
   UNUSED32_PFC,    /* 32 -- no more used -- */

   LTDST_PFC,       /* 33 Start of LTD */
   LTDND_PFC,       /* 34 End of LTD */

   /* GETPOS / SETPOS (only used for LINK) */
   XENGP_PFC,       /* 35 Get position: returns pac.dad=block,length of block */
   XENSP_PFC,       /* 36 Set position: passed pac.dad=block,length of block */

   /* Markup declarations */
   ETYDCLST_PFC,    /* 37 ENTITY declaration start */
   ETYDCLND_PFC,    /* 38 ENTITY declaration end */
   NOTDCLST_PFC,    /* 39 NOTATION declaration start */
   NOTDCLND_PFC,    /* 40 NOTATION declaration end */
   ELTDCLST_PFC,    /* 41 ELEMENT declaration start */
   ELTDCLND_PFC,    /* 42 ELEMENT declaration end */
   ATLELTDCLST_PFC, /* 43 ATTLIST declaration start for element(s) */
   ATLELTDCLND_PFC, /* 44 ATTLIST declaration end for element(s) */
   ATLNOTDCLST_PFC, /* 45 ATTLIST declaration start for notation(s) */
   ATLNOTDCLND_PFC, /* 46 ATTLIST declaration end for notation(s) */

   USER_PFC = 200   /* 200 and higher are reserved for Application own's use */
}PFC;

/*-----------------------------------------------------------------------------+
|PSF:  Parser services request codes                                           |
+-----------------------------------------------------------------------------*/
typedef enum {
   RES_PSF=0,       /*  0 is Reserved */
   UNUSED01_PSF,    /*  1 -- no more used -- */
   QELT_PSF,        /*  2 Query for an element: pac.dad.p -> ELT */
   QLELT_PSF,       /*  3 List all elmts: pac.dad.p->ELT array, len = count */
   QGETY_PSF,       /*  4 Query for a gen entity: pac.dad.p -> ETY */
   QLGETY_PSF,      /*  5 List all geties: pac.dad.p->ETY array, len=count */
   QPETY_PSF,       /*  6 Query for a prm entity: pac.dad.p -> ETY */
   QLPETY_PSF,      /*  7 List all peties: pac.dad.p->ETY array, len=count */
   QDLM_PSF,        /*  8 Returns the Delimiter Table (dstab) */
   QCAPA_PSF,       /*  9 Returns the capacities tables */
   QETY_PSF,        /* 10 Query the current entity */
   UNUSED11_PSF,    /* 11 -- no more used -- */
   UNUSED12_PSF,    /* 12 -- no more used -- */
   UNUSED13_PSF,    /* 13 -- no more used -- */
   QSR_PSF,         /* 14 Query ShortRef delimiter table */
   QQTY_PSF,        /* 15 Query the declared quantities */
   QOPT_PSF,        /* 16 Query the enabled features/options */
   QFCT_PSF,        /* 17 Query the functions characters */
   QNOTA_PSF,       /* 18 Query a given notation: pac.dad.p -> NCB */
   QLNOTA_PSF,      /* 19 List all notations: pac.dad.p->NCB array, len=count */
   FGETY_PSF,       /* 20 Get access to a gen entity: pac.dad.p -> ETY */        /*@GP0012*/
   ALINK_PSF,       /* 21 Activate a linktype */
   ACONC_PSF        /* 22 Activate a concurrent DTD */
}PSF;

/*-----------------------------------------------------------------------------+
| SDC: Skipped Data Codes                                                      |
+-----------------------------------------------------------------------------*/
typedef enum {
   NULL_SDC=0,      /*  0 is reserved */
   COMMENT_SDC,     /*  1 SGML Comment */
   ERROR_SDC,       /*  2 SGML Error: text ignored */
   MSINCL_SDC,      /*  3 Marked Section INCLUDE or TEMP */
   MSIGN_SDC,       /*  4 Marked Section IGNORE <![IGNORE [data]]> */
   MSCDATA_SDC,     /*  5 Marked Section CDATA  <![CDATA [ */
   MSRCDATA_SDC,    /*  6 Marked Section RCDATA <![RCDATA [ */
   MSC_SDC,         /*  7 Marked Section Close: ]]> */
   MDOMDC_SDC       /*  8 Found <!> */
}SDC;

/*-----------------------------------------------------------------------------+
|External Identifier Descriptor                                                |
+-----------------------------------------------------------------------------*/
                              /* EXID Bits Flag */
#define SOLVED_XF      0x0001 /* FIND_PFC has been issued for this XID */
#define INVALID_XF     0x0002 /* FIND_PFC was unable to get a FileId-AHL */
#define VALIDFPI_XF    0x0004 /* PID has a formal structure */
#define AVAILPTEXT_XF  0x0008 /* available public text */
#define PROVPTDV_XF    0x0010 /* System must provide Pub.Text Disp.Vers.*/
#define PTDS_XF        0x0020 /* Pub.Text Design. Sequence vs. Language */
#define ALTERN_XF      0x0040 /* Take alternate system spec if any */
#define DEFLT_XF       0x0080 /* Default entity */
#define REGISTERED_XF  0x0100 /* Owner is registered */
#define ISOREG_XF      0x0200 /* Registration is ISO */
#define PUBLIC_XF      0x0400 /* A Public Identifier was furnished */
#define SYSTEM_XF      0x0800 /* A System Identifier was furnished */

                              /* Class Field */
#define INVALID_XFC       0   /* Invalid */
#define CAPACITY_XFC      1   /* capacity set */
#define CHARSET_XFC       2   /* character data */
#define DOCUMENT_XFC      3   /* sgml document */
#define DTD_XFC           4   /* document type declaration subset */
#define ELEMENTS_XFC      5   /* element set */
#define ENTITIES_XFC      6   /* entity set */
#define LPD_XFC           7   /* link type declaration subset */
#define NONSGML_XFC       8   /* non sgml data entity */
#define NOTATION_XFC      9   /* character data */
#define SHORTREF_XFC     10   /* short reference set */
#define SUBDOC_XFC       11   /* sgml subdocument entity */
#define SYNTAX_XFC       12   /* concrete syntax */
#define TEXT_XFC         13   /* sgml text entity */
                              /* Parser Specific */
#define UTODTR_XFC       14   /* utility dtd to read (odt) */
#define UTODTW_XFC       15   /* utility dtd to write (odt) */
#define UTSYNU_XFC       16   /* utility user-modified ocs */
#define UTSYNL_XFC       17   /* utility local-system ocs */
#define UTSYNR_XFC       18   /* utility refcon-system ocs */
#define PRIMARY_XFC      19   /* primary entity */
#define UTOLTR_XFC       21   /* utility ltd to read (olt) */
#define UTOLTW_XFC       22   /* utility ltd to write (olt) */

typedef struct {              /* external resource identifier descriptor */
   ADLEN name;                /* Entity name */
   /*----------------------------------------------+
   |The System Identifier is optional for PUBLIC   |
   |The Public identifier doesn't exist for SYSTEM |
   +----------------------------------------------*/
   ADLEN val;                 /* Identifier */
                              /* Identifier Subfields related to "val" */
   OFLEN sid;                 /* System Identifier */
   OFLEN pid;                 /* Public Identifier */
   /* iff is.VALIDFPI, redefine FPI fields of "pid" (still related to "val") */
   OFLEN ownid;               /* Owner identifier */
   OFLEN txtdesc;             /* Public text description */
   OFLEN lang;                /* lang, or designating seq */
   OFLEN ptdv;                /* Public Text Display Version */
                              /* Flags */
   unsigned short is;         /* Bits Flag */
   unsigned char asgn_cls;    /* Class Field assigned by the Parser */
   unsigned char spec_cls;    /* Class Field specified */
   AHL idhl;                  /* FileId-AHL (when solved) */
}EXID;

/*-----------------------------------------------------------------------------+
| Rank double link list                                                        |
+-----------------------------------------------------------------------------*/
typedef struct {           /* Stem structure */
   union {                 /* Item HEADER (SHSH_HDR for shsh hashing) */
      OFS ofs;             /* offset of the rank name */
      unsigned char *p;    /* ...then relocated (when loaded) */
   }name;
   int suffix;             /* current suffix value (-1 if not set) */
   int count;              /* count of elements having this stem */
}STS;

typedef struct t_RKL {     /* for a ranked element */
   union {
      int    ix;           /* index in the STS array */
      STS   *p;            /* pointer when loaded */
   }sts;
   union {                 /* to other ranked of which the elt is a member */
      int    ix;           /* index in the RKL array */
      struct t_RKL *p;     /* pointer when loaded */
   }grp;
}RKL;

/*-----------------------------------------------------------------------------+
| Data Tag Pattern                                                             |
+-----------------------------------------------------------------------------*/
typedef union {            /* Data Tag Pattern - array is 3 entries at least:*/
   OFS    ofs;             /* 1st is the padding (or Null Pointer if none) */
   unsigned char *c_p;     /* 2nd is the first template */
}DTP;                      /* last is a Null Pointer */

/*-----------------------------------------------------------------------------+
| Model structure                                                              |
+-----------------------------------------------------------------------------*/
#define NULL_CONN 0
#define AND_CONN  1
#define SEQ_CONN  2
#define OR_CONN   3

#define OMITTABLE   0x01
#define REPEATABLE  0x02

#define NULL_OCCUR  0
#define OPT_OCCUR   OMITTABLE
#define PLUS_OCCUR  REPEATABLE
#define REP_OCCUR   OMITTABLE + REPEATABLE


typedef struct {
   unsigned int connector  :2; /* also tell "l" has elt/dtp, or tok */
   unsigned int occurence  :2; /* is_omittable, is_repeatable */
   unsigned int is_target  :1; /* Target (l.elt_p, next brother is a Datatag) */
   unsigned int is_datatag :1; /* Datatag (l.dtp.p) */
   unsigned int is_pcdata  :1; /* Pcdata  (neither l.dtp.p, nor l.elt.p) */
   unsigned int unused     :9; /* for future use... */
   union {
      struct {                 /* if ltag (i.e. connector) */
         unsigned short num;   /* number of tokens in subgroup (1) */
         unsigned short rx;    /* relative index of 1st token of subgroup (2) */
      }mdl;                    /* no ltag: */
      union {
         int    ix;        /* index in ELT array of the element (-1: PCDATA) */
         struct t_ELT *p;  /* when loaded: pointer to elt (0: PCDATA) */
      }elt;                /* Note PCDATA without any data-tag, otherwise: */
      union {
         int    ix;        /* index in DTP array of the data-tag pattern */
         DTP    *p;        /* when loaded: pointer to dtp */
      }dtp;
   }l;
}MDL;

/* (1) - At most, GRPCNT */
/* (2) - i.e. how many MDL to jump from here to the 1st subgroup token. */
/*       At most, GRPGTCNT */

/*-----------------------------------------------------------------------------+
| Exceptions                                                                   |
+-----------------------------------------------------------------------------*/
typedef union {
   int    ix;              /* index in elt array */
   struct t_ELT *p;        /* when loaded, point exception elt */
}EX;

/*-----------------------------------------------------------------------------+
| Notation Control Block                                                       |
|                                                                              |
| The NOTATION Control Block is an extended EXID.                              |
| This is in fact the EXID of a notation.                                      |
+-----------------------------------------------------------------------------*/
typedef struct {           /* Notation Control Block */
   EXID exid;
   union {
      int    ix;           /* index in ATD table */
      struct t_ATD *p;     /* or Attribute Value Specification */
   }atd;
}NCB;

/*-----------------------------------------------------------------------------+
| Notation Interpreter structure                                               |
|                                                                              |
|  A Notation Interpreter structure (NAD) describes the notation and           |
|  data attributes associated to external C/N/S DATA entities.                 |
+-----------------------------------------------------------------------------*/
typedef struct {           /* Notation Interpreter Structure */
   union {
      int    ix;           /* index in ATD table */
      struct t_ATD *p;     /* or Attribute Value Specification */
   }atd;
   union {
      int   ix;            /* Index in the NCB array when unloaded or - 1 */
      NCB   *p;            /* After relocation ptr to NCB or 0 if no notation */
   }ncb;
}NAD;                      /* External N/S/CDATA Notation and Attributes */

/*-----------------------------------------------------------------------------+
| Entity Descriptor Structure                                                  |
+-----------------------------------------------------------------------------*/
                              /* ETY Bits Flag */
#define NOTATION_EF       1   /* a notation block is associated */
#define BRACKETED_EF      2   /* must put stuff around it */
#define RCDATA_EF         4   /* RCDATA vs. CDATA/SDATA/NDATA/PI or SUBDOC */
#define EXTERNAL_EF       8   /* external entity vs. memory entity */
#define DEFLT_EF         16   /* it's the default entity */
#define PARAMETER_EF     32   /* it's a parameter entity */
#define USER_EF          64   /* User flag - Init value is "off" */

                              /* Kind: */
#define INVALID_EFK       0   /* Invalid */
#define CDATA_EFK         1   /* not_rcdata|Ext/Int|notation iff Ext */
#define SDATA_EFK         2   /* not_rcdata|Ext/Int|notation iff Ext */
#define MD_EFK            3   /*   rcdata  |  Int  |   bracketed     */
#define PI_EFK            4   /* not_rcdata|  Int  |   bracketed     */
#define STARTTAG_EFK      5   /*   rcdata  |  Int  |   bracketed     */
#define ENDTAG_EFK        6   /*   rcdata  |  Int  |   bracketed     */
#define MS_EFK            7   /*   rcdata  |  Int  |   bracketed     */
#define NDATA_EFK         8   /* not_rcdata|  Ext  |   notation      */
#define TEXT_EFK          9   /*   rcdata  |  Int  |                 */
#define SGML_EFK         10   /*   rcdata  |  Ext  |                 */
#define SUBDOC_EFK       11   /* not_rcdata|  Ext  |                 */

typedef struct {              /* Entity Descriptor Structure */
   ADLEN name;                /* Item HEADER (SHSH_HDR for shsh hashing) */
   union {
      ADLEN lit;              /* Internal Entity: ADLEN of the literal */
      struct {                /* External entity: */
         union {
            union {           /* 1)- Address of the EXID: */
               int  ix;       /*     - Index in the EXID array */
               EXID *p;       /*     - Pointer (after relocation) */
            }exid;
            int ety_ix;       /* 1)- Index in the ETY array (temporary use) */
         }_;
         union {              /* 2)- External (non reparseable), NAD address: */
            int  ix;          /*     - Index in the NAD array */
            NAD *p;           /*     - Pointer (after relocation) */
         }nad;
      }ext;
   }val;
   unsigned char is;          /* Bits Flag */
   unsigned char kind;        /* value field */
}ETY;

/*-----------------------------------------------------------------------------+
| Attribute Descriptor Structure                                               |
+-----------------------------------------------------------------------------*/
                              /* ATD Bits Flag */
#define LAST_AF            1  /* last in chain */
#define LISTED_AF          2  /* belongs to a name (token?) group */
#define BAD_AF             4  /* Bad attribute specified (run time) */
#define EXM_AF             8  /* attribute has been examined (run time) */
#define DESC_AF           16  /* Lit is described by ADLEN 0 (run time) */
#define OMITNAME_AF      512  /* Attribute name was omitted */
#define LINK_AF         1024  /* Is a link attribute */

                              /* Kind field: an odd number mean "plurality" */
#define INVALID_AFK        0  /* None = Invalid (for unsolved NADs) */
#define CDATA_AFK          2  /* character data */
#define ENTITY_AFK         4  /* general entity name */
#define ENTITIES_AFK       5  /* general entity name list */
#define ID_AFK             6  /* an ID */
#define IDREF_AFK          8  /* an ID reference */
#define IDREFS_AFK         9  /* an ID reference list */
#define NAME_AFK          10  /* a name */
#define NAMES_AFK         11  /* a name list */
#define NMTOKEN_AFK       12  /* a name token */
#define NMTOKENS_AFK      13  /* a name token list */
#define NOTATION_AFK      14  /* notation or solved NAD */
#define NUMBER_AFK        16  /* a number */
#define NUMBERS_AFK       17  /* a number list */
#define NUTOKEN_AFK       18  /* a number token */
#define NUTOKENS_AFK      19  /* a number token list */
#define GROUP_AFK         20  /* one of a fixed group */

                              /* Value field: */
#define INVALID_AFV        0  /* None = Invalid */
#define IMPLIED_AFV        1  /* Impliable attribute */
#define REQUIRED_AFV       2  /* This attribute is REQUIRED  <= 1 => ID */
#define CURRENT_AFV        3  /* Default attribute is CURRENT value */
#define CONREF_AFV         4  /* Content Reference Attribute */
#define DEFLT_AFV          5  /* >= A default value has been specified */
#define FIXED_AFV          6  /* This default value is fixed */

typedef struct t_ATD {        /* Attribute Descriptor Structure */
   union {
      OFS ofs;                /* offset of the attribute name */
      unsigned char *p;       /* ...then relocated (when loaded) */
   }name;
   unsigned short is;         /* Bits Flag */
   unsigned char kind;        /* see AFK list */
   unsigned char defv;        /* Default Value: see AFV list */
   union {
      ADLEN lit;              /* For regular attributes: literal ADLEN */
      ADLEN desc;             /* or literal descriptor if DESC_AF */
      NCB *ncb_p;             /* For  a Notation attribute: NCB pointer */
      struct {                /* For ENTITY or ENTITIES attributes: */
         ETY **pp;            /* 1)- pointer to an array of pointers to ETY */
         unsigned int count;  /* 2)- count of ETY(s) in the array */
      }ety;
   }val;
}ATD;

/*-----------------------------------------------------------------------------+
| Short Reference Mapping                                                      |
| The Shortref Maps is an array of (map_count)*(sr_max+1) t_SRM elements:      |
| - the first one is the SHSH_HDR to hash the mapname, (shsh_fnd)              |
| - the sr_max others points to the ETY related (or 0 if none)                 |
|   (sr_max == count of shortrefs, srm_p+n points ETY related to the SR #n)    |
+-----------------------------------------------------------------------------*/
typedef union {            /* element of a (sr_max+1) array of: */
   union {                 /* Item HEADER (SHSH_HDR for shsh hashing) */
      OFS ofs;             /* offset of the map name */
      unsigned char *p;    /* ...then relocated (when loaded) */
   }mapname;
   unsigned char *name_p;  /* while building it: entity name pointer */
   int  ix;                /* unloaded: indeces to an array of ETY */
   ETY  *ety_p;            /* final: ETY pointers */
}SRM;

/*-----------------------------------------------------------------------------+
| Element                                                                      |
|                                                                              |
| Note: An element that has a CONREF attribute can *not* have a dcl-content    |
|       of EMPTY.  However, when there is an explicit content reference,       |
|       the "empty" bit is turned ON for the time of the notification.  This   |
|       serves as a reminder the element's content is EMPTY.                   |
+-----------------------------------------------------------------------------*/
                           /* Values taken by the elt.is.dcdata field: */
#define DENY_DCDATA 0x00   /* Is *not* Declared Character Data */
#define NONR_DCDATA 0x01   /* Non Replaceable Character Data (i.e.: CDATA) */
#define RPLC_DCDATA 0x02   /* Replaceable Character Data (i.e.: RCDATA) */

typedef struct {
   unsigned int reqd_open_tag :1;  /* Minimization */
   unsigned int reqd_end_tag  :1;  /* Minimization */
   unsigned int any           :1;  /* No mdl_p: model content: ANY */
   unsigned int empty         :1;  /* No mdl_p: dcl content EMPTY (see Note) */
   unsigned int dcdata        :2;  /* No mdl_p: dcl content DCDATA (see above)*/
   unsigned int pcdata        :1;  /* Mixed content and data-char allowed */
   unsigned int required      :1;  /* An attribute in the list is REQUIRED */
   unsigned int current       :1;  /* An attribute in the list is CURRENT */
   unsigned int conref        :1;  /* An attribute in the list is CONREF */
   unsigned int notation      :1;  /* An attribute in the list is NOTATION */
   unsigned int entity        :1;  /* An attribute in the list is ENTITY(IES) */
   unsigned int solved        :1;  /* Internal use */
   unsigned int unused        :3;  /* for future use... */
}ELT_FLAGS;


typedef struct t_ELT {     /* Element Type Definition */
   union {                 /* Item HEADER (SHSH_HDR for shsh hashing) */
      OFS ofs;             /* offset of the elt name */
      unsigned char *p;    /* ...then relocated (when loaded) */
   }name;
   ELT_FLAGS is;
   union {                 /* -1 if: ANY, EMPTY, DCDATA (RCDATA || CDATA) */
      int  ix;             /* or index in MDL array of the model */
      MDL *p;              /* when loaded, pointer to the model header */
   }mdl;
   union {
      int  ix;             /* index in an ATD array of first attribute value */
      ATD *p;              /* when loaded, points an AD array */
   }atd;                   /* Attribute Definition */
   unsigned int atdsize;   /* size of the ad array */
   union {
      int  ix;             /* index in an EX array */
      EX  *p;              /* when loaded, points an EX array */
   }mex;                   /* minus exceptions */
   union {
      int  ix;            /* index in an EX array */
      EX  *p;              /* when loaded, points an EX array */
   }pex;                   /* plus exceptions */
   union {
      int  ix;             /* point an array of indeces to ETY array */
      SRM *p;              /* when loaded, points an array of ETY ptrs */
   }srm;                   /* short ref map */
   union {
      int  ix;             /* index in an RKL array (-1 if not ranked) */
      RKL *p;              /* when loaded, points an RKL */
   }rkl;
}ELT;

/*-----------------------------------------------------------------------------+
|Document Element Descriptor                                                   |
+-----------------------------------------------------------------------------*/
                                      /* DED Bits Flag */
#define RE_LF  (unsigned char)0x00    /* A Record End */
#define STG_LF (unsigned char)0x01    /* Start Tag */
#define ETG_LF (unsigned char)0x02    /* End Tag */
#define IMP_LF (unsigned char)0x04    /* Implied (vs. User Initiated) */
#define PEX_LF (unsigned char)0x08    /* Plus Exception (vs. Proper Element) */
#define PMT_LF (unsigned char)0x10    /* Premature End Tag */
#define EMP_LF (unsigned char)0x20    /* End tag with invalid empty content */
#define ECR_LF (unsigned char)0x40    /* Explicit Content Ref: empty content */

                              /* Minimization field: */
#define NO_MNF            0   /* No minimization */
#define EMPTY_ST_MNF      1   /* EMPTY start-tag (STAGO-TAGC) */
#define UNCL_ST_MNF       2   /* Unclosed start-tag */
#define NET_ST_MNF        3   /* NET-enabling start-tag */
#define EMPTY_ET_MNF      4   /* EMPTY end-tag (ETAGO-TAGC) */
#define UNCL_ET_MNF       5   /* Unclosed end-tag */
#define NULL_ET_MNF       6   /* NULL end-tag (NET) */
#define DATA_ET_MNF       7   /* DATATAG end-tag */

                              /* "impldby" field - markup implied by: */
#define NO_IMF            0   /* (reserved) */
#define DOC_IMF           1   /* Start of document instance set */
#define DATA_IMF          2   /* Data */
#define STG_IMF           3   /* Start-tag (by_elt_p) */
#define ETG_IMF           4   /* End-tag (by_elt_p) */
#define EDTG_IMF          5   /* End-DataTag (by_elt_p) */
#define EOF_IMF           6   /* End of File */

typedef struct {
   ELT *elt_p;                /* Element pointer */
   ATD *atd_p;                /* Address of the first ATD or 0 */
   ELT *by_elt_p;             /* If this tag was implied by another tag */
   SRM *srm_p;                /* Current shortref map */
   unsigned short is;         /* Bits Flag */
   unsigned char tagmin;      /* Minimization */
   unsigned char impldby;     /* What implied the tag */
}DED;
#define DEDSIZE  sizeof(DED)


/*-----------------------------------------------------------------------------+
|POS: Position in input stream                                                 |
+-----------------------------------------------------------------------------*/
typedef struct {          /* to describe position in input stream */
   int row;               /* RE count: line number */
   int col;               /* Offset within last row */
   long ofs;              /* Offset from the beginning */
   ETY *ety_p;            /* ETY pointer */
}POS;

/*-----------------------------------------------------------------------------+
|OEB: Opened Entity Block                                                      |
+-----------------------------------------------------------------------------*/
typedef struct {             /* Opened Entity Block */
   ETY *ety_p;               /* entity structure ** READ ONLY ** */
   AHL achl;                 /* Access AHL */
   long offset;              /* offset within entity */
   int col;                  /* col == offset within current record */
   int row;                  /* RS counts */
   unsigned char *appl_info; /* Appl. provides for msgs ER_LOC0 and ER_LOC1 */
}OEB;

/*-----------------------------------------------------------------------------+
|ShortRef Table Entry (for application only)                                   |
|Note: This structure has to have the same layout as the EQTK internal YASP    |
|      structure, but is simplified here.                                      |
+-----------------------------------------------------------------------------*/
typedef struct {
   unsigned char *p;      /* Actual ShortRef string */
   unsigned int reserved; /* Reserved field */
}SRTBE;

/*-----------------------------------------------------------------------------+
|FNCR table: Mapping of function characters.                                   |
+-----------------------------------------------------------------------------*/
typedef enum {
   NULL_FCTCLS = 0, /*  0 is Reserved */
   RE_FCTCLS,
   RS_FCTCLS,
   SPACE_FCTCLS,
   FUNCHAR_FCTCLS,
   MSICHAR_FCTCLS,
   MSOCHAR_FCTCLS,
   MSSCHAR_FCTCLS,
   SEPCHAR_FCTCLS
}FCTCLS;

typedef struct {              /* to map : */
   union {                    /* a function name (ex: "TAB") */
     OFS ofs;                 /* offset... */
     unsigned char *p;        /* ...then relocated (when loaded) */
   }s;
   unsigned int ch_nb;        /* to a corresponding char number (ex: 9) */
   FCTCLS fctcls;             /* Function Class (ex: SEPCHAR_FCTCLS) */
}FNCR;

/*-----------------------------------------------------------------------------+
|YES/NO table, for options/features/scope                                      |
|                                                                              |
|Not really an EQU, but checked as is: if (t.opt.ft.b.rank)                    |
|see SGML [196],[197],[198],[203], B.14.1.1 also: scope [181]                  |
|                                                                              |
|Note: this gives the class code (G1, p149)                                    |
+-----------------------------------------------------------------------------*/
                              /* opt.ft Bits Flags (Feature Code) */
#define FORMAL_FT         1   /* formal public identifiers */
#define CONCUR_FT         2   /* concurrent document instances */
#define EXPLICIT_FT       4   /* explicit link process */
#define IMPLICIT_FT       8   /* implicit link process */
#define SIMPLE_FT        16   /* simple link process */
#define SUBDOC_FT        32   /* nested subdocuments */
#define RANK_FT          64   /* omitted rank suffix minimization */
#define DATATAG_FT      128   /* datatag minimization */
#define OMITTAG_FT      256   /* omitted tag minimization */
#define SHORTTAG_FT     512   /* short tag minimization */

                              /* opt.ot Bits Flags (others) */
#define GENERAL_CASE_OT   1   /* upper case general */
#define ENTITY_CASE_OT    2   /* upper case entities */
#define INSTANCE_SCOPE_OT 4   /* is_DOCUMENT 0, is_INSTANCE 1 */

typedef struct {              /* Options */
   unsigned int ft;           /* Feature Code (Bits Flag) */
   unsigned int ot;           /* Others Bits Flag */
   unsigned int max_simple;
   unsigned int max_explicit;
   unsigned int max_concur;
   unsigned int max_subdoc;
   ADLEN    appinfo;          /* appinfo.p is also ASCIIZ */
}OPT;

/*-----------------------------------------------------------------------------+
|Error Severities                                                              |
+-----------------------------------------------------------------------------*/
#define ERH_I_SEV   0    /* Informational message  (Never exceeds AutoQuit) */
#define ERH_W_SEV   4    /* Warning */
#define ERH_E_SEV   8    /* Error (something is bad, but Parser can recover) */
#define ERH_S_SEV  12    /* Severe error (probably can't recover) */
#define ERH_T_SEV  16    /* Terminating error (MUST get RC 10 back) */

/*-----------------------------------------------------------------------------+
|AHL Identifier (AHL.i) the Application returns for FIND_PFC of a CHARSET      |
+-----------------------------------------------------------------------------*/
#define UNKNOWN_AHLID         0  /* Unknown CHARSET */
#define ISO_646_1983_AHLID   16  /* ISO 646-1983 (IRV) */
#define ISO_8859_AHLID       17  /* ISO 8859-1 Latin alphabet No.1 */
#define ANSI_X3_4_1986_AHLID 18  /* ANSI X3.4-1986 (ASCII) */
#define IBM_395_AHLID        19  /* IBM codepage 395 */
#define IBM_850_AHLID        20  /* IBM codepage 850 */
#define ISO_100_ECMA_AHLID   21  /* ISO registration 100 ECMA Nr. 1 */

/*-----------------------------------------------------------------------------+
|Global Return codes from the application                                      |
+-----------------------------------------------------------------------------*/
#define END_PARSE_RC   10 /* "Abandon Ship" code */
#define END_RESUME_RC  11 /* End reparsing session */

/*-----------------------------------------------------------------------------+
|PAC: Parser/Application Communication block                                   |
+-----------------------------------------------------------------------------*/
#define PAC_IDENTIFIER "PAC015"
typedef struct t_PAC {
   char  id[8];       /* <PAC015>, I'm a PAC */
   short resv;        /* (Reserved, must be zero) */
   short argc;        /* (Reserved, must be zero) */
   char **argv;       /* (Reserved, must be zero) */
   int   (C_FCT *ase)(struct t_PAC *);  /* E.P. Addr for Application services */
   int   (C_FCT *pse)(struct t_PAC *);  /* E.P. Addr for Parser services */
   PFC   func;        /* PFC code (See equates) */
   PSF   psf;         /* PSF code (See equates) */
   OEB  *oeb_p;       /* Opened Entity Block (of current entity) */
   AHL   ahl;         /* Application Handle (Identifier or Access) */
   ADLEN dad;         /* Adlen for passed data */
   ADLEN stg;         /* Adlen for storage allocation */

   /* Other Fields */
   POS   pos;         /* Position of the most recently reported event */
   SDC   sdc;         /* SDC code for SKIP_PFC (see equates) */
   int   errcod;      /* Error Code for these series of messages */
   int   msgcod;      /* Message code of this message in the series */
   short errsev;      /* Error Severity of the series of messages */
   short msglast;     /* last message in the series or not (0 or 1) */

   /* Fields for private System (interface Parser <-> Appl) use */
   int   syssa;       /* System private use save word */
   int   syssy;       /* System private use sync. word */
   int   syssv[16];   /* System private save area */
   void *stack_p;     /* Usually: address of parser stack storage */
   void *swork_p;     /* Usually: copy of ase(), when trapping ase's */

   /* Fields for private Parser use */
   void *gwork_p;     /* Work area for use of parser */

   /* Fields for private Application use */
   void *user_p;      /* Usually: regain a reentrancy anchor in services */
}PAC;
#define PACSIZE   sizeof(PAC)

/*-----------------------------------------------------------------------------+
|YASP exported functions and data                                              |
+-----------------------------------------------------------------------------*/
extern YASP_API char const * const C_FCT PACID;     /* PAC identifier */
extern YASP_API char const * const C_FCT PARSID;    /* YASP identifier */
extern YASP_API unsigned int C_FCT PRSMAIN (PAC *); /* YASP main entry point */
extern YASP_API unsigned int C_FCT SUBMAIN (PAC *, ETY *); /* Entry point for SUBDOC */
/******************************************************************************/

#endif  /* YASP_API_INCLUDED */
