home *** CD-ROM | disk | FTP | other *** search
/ Gold Fish 3 / goldfish_volume_3.bin / files / dev / lang / sgmls / src / sgmlxtrn.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-07-10  |  11.6 KB  |  226 lines

  1. /*    Standard Generalized Markup Language Users' Group (SGMLUG)
  2.                  SGML Parser Materials (ARCSGML 1.0)
  3.  
  4. (C) 1983-1988 Charles F. Goldfarb (assigned to IBM Corporation)
  5. (C) 1988-1991 IBM Corporation
  6.  
  7. Licensed to the SGML Users' Group for distribution under the terms of
  8. the following license:                                                       */
  9.  
  10. char license[] =
  11. "SGMLUG hereby grants to any user: (1) an irrevocable royalty-free,\n\
  12. worldwide, non-exclusive license to use, execute, reproduce, display,\n\
  13. perform and distribute copies of, and to prepare derivative works\n\
  14. based upon these materials; and (2) the right to authorize others to\n\
  15. do any of the foregoing.\n";
  16.  
  17. #include "sgmlincl.h"
  18.  
  19. /* SGMLXTRN: Storage allocation and initialization for all public variables.
  20.              Exceptions: Constants lex????? and del????? are defined in
  21.              LEX?????.C modules; constants pcb????? are defined in PCB?????.c.
  22. */
  23. int badresw = 0;              /* 1=REF_ out of context; 0=valid. */
  24. int charmode = 0;             /* >0=in #CHARS; 0=not. */
  25. int conactsw = 0;             /* 1=return saved content action 0=get new one.*/
  26. int conrefsw = 0;             /* 1=content reference att specified; 0=no. */
  27. int contersv = 0;             /* Save contersw while processing pending REF. */
  28. int contersw = 0;             /* 1=element or #CHARS out of context; 0=valid. */
  29. int datarc = 0;               /* Return code for data: DAF_ or REF_. */
  30. int delmscsw = 0;             /* 1=DELMSC must be read on return to es==0. */
  31. int didreq = 0;               /* 1=required implied tag processed; 0=no. */
  32. int docelsw = 0;          /* 1=had document element; 0=no */
  33. int dostag = 0;               /* 1=retry newetd instead of parsing; 0=parse. */
  34. int dtdsw = 0;                /* DOCTYPE declaration found: 1=yes; 0=no. */
  35. int entdatsw = 0;             /* 2=CDATA entity; 4=SDATA; 8=NDATA; 0=none. */
  36. int entpisw = 0;              /* 4=PI entity occurred; 0=not. */
  37. int eodsw = 0;                /* 1=eod found in error; 0=not yet. */
  38. int eofsw = 0;                /* 1=eof found in body of document; 0=not yet. */
  39. int es = -1;                  /* Index of current source in stack. */
  40. int etagimct = 0;             /* Implicitly ended elements left on stack. */
  41. int etagimsw = 0;             /* 1=end-tag implied by other end-tag; 0=not. */
  42. int etagmin = MINNONE;        /* Minim: NONE NULL NET DATA; implied by S/ETAG*/
  43. int etictr = 0;               /* Number of "NET enabled" tags on stack. */
  44. int etisw = 0;                /* 1=tag ended with eti; 0=did not. */
  45. int indtdsw = 0;              /* Are we in the DTD? 1=yes; 0=no. */
  46. int mslevel = 0;              /* Nesting level of marked sections. */
  47. int msplevel = 0;             /* Nested MS levels subject to special parse. */
  48. int prologsw = 1;             /* 1=in prolog; 0=not. */
  49. int pss = 0;                  /* SGMLACT: scbsgml stack level. */
  50. int sgmlsw = 0;               /* SGML declaration found: 1=yes; 0=no. */
  51. int stagmin = MINNONE;        /* Minimization: NONE, NULL tag, implied by STAG*/
  52. int tagctr = 0;               /* Tag source chars read. */
  53. int tages = -1;              /* ES level at start of tag. */
  54. int ts = -1;                  /* Index of current tag in stack. */
  55. struct parse *propcb = &pcbpro; /* Current PCB for prolog parse. */
  56. int aentctr = 0;              /* Number of ENTITY tokens in this att list. */
  57. int conact = 0;               /* Return code from content parse. */
  58. int conrefsv = 0;             /* Save conrefsw when doing implied start-tag.*/
  59. int dtdrefsw = 0;             /* External DTD? 1=yes; 0=no. */
  60. int etiswsv = 0;              /* Save etisw when processing implied start-tag.*/
  61. int grplvl = 0;               /* Current level of nested grps in model. */
  62. int idrctr = 0;               /* Number of IDREF tokens in this att list. */
  63. int mdessv = 0;               /* ES level at start of markup declaration. */
  64. int notadn = 0;               /* Position of NOTATION attribute in list. */
  65. int parmno = 0;               /* Current markup declaration parameter number. */
  66. int pexsw = 0;                /* 1=tag valid solely because of plus exception.*/
  67. int rcessv = 0;               /* ES level at start of RCDATA content. */
  68. int tagdelsw = 0;             /* 1=tag ended with delimiter; 0=no delimiter. */
  69. int tokencnt = 0;             /* Number of tokens found in attribute value. */
  70. struct entity *ecbdeflt = 0;  /* #DEFAULT ecb (NULL if no default entity). */
  71. struct etd *docetd = 0;       /* The etd for the document as a whole. */
  72. struct etd *etagreal = 0;     /* Actual or dummy etd that implied this tag. */
  73. struct etd *newetd = 0;       /* The etd for a start- or end-tag recognized. */
  74. struct etd *nextetd = 0;      /* ETD that must come next (only one choice). */
  75. struct etd *lastetd = 0;      /* most recently ended ETD. */
  76. struct etd *stagreal = 0;     /* Actual or dummy etd that implied this tag. */
  77. struct parse *conpcb = 0;     /* Current PCB for content parse. */
  78. UNCH *data = 0;               /* Pointer to returned data in buffer. */
  79. UNCH *mdname = 0;             /* Name of current markup declaration. */
  80. UNCH *ptcon = 0;              /* Current pointer into tbuf. */
  81. UNCH *ptpro = 0;              /* Current pointer into tbuf. */
  82. UNCH *rbufs = 0;              /* DOS file read area: start position for read. */
  83. UNCH *subdcl = 0;             /* Subject of markup declaration (e.g., GI). */
  84. UNS conradn = 0;              /* 1=CONREF attribute in list (0=no). */
  85. UNS datalen = 0;              /* Length of returned data in buffer. */
  86. UNS entlen = 0;               /* Length of TAG or EXTERNAL entity text. */
  87. UNS idadn = 0;                /* Number of ID attribute (0 if none). */
  88. UNS noteadn = 0;              /* Number of NOTATION attribute (0 if none). */
  89. UNS reqadn = 0;               /* Num of atts with REQUIRED default (0=none). */
  90. int grplongs;              /* Number of longs for GRPCNT bitvector. */
  91.  
  92. /* Variable arrays and structures.
  93. */
  94. struct ad *al = 0;            /* Current attribute list work area. */
  95. struct dcncb *dcntab[1];      /* List of data content notation names. */
  96. struct entity *etab[ENTHASH]; /* Entity hash table. */
  97. struct etd *etdtab[ETDHASH];  /* Element type definition hash table. */
  98. struct fpi fpidf;             /* Fpi for #DEFAULT entity. */
  99. struct id *itab[IDHASH];      /* Unique identifier hash table. */
  100. struct etd **nmgrp = 0;          /* Element name group */
  101. PDCB *nnmgrp = 0;          /* Notation name group */
  102. struct restate *scbsgml = 0;  /* SGMLACT: return action state stack. */
  103. struct source *scbs = 0;      /* Stack of open sources ("SCB stack"). */
  104. struct srh *srhtab[1];        /* List of SHORTREF table headers. */
  105. struct sgmlstat ds;           /* Document statistics. */
  106. struct switches sw;           /* Parser control switches set by text proc. */
  107. struct tag *tags = 0;         /* Stack of open elements ("tag stack"). */
  108. struct thdr *gbuf = 0;        /* Buffer for creating group. */
  109. struct thdr prcon[3];         /* 0-2: Model for *DOC content. */
  110. struct thdr undechdr;         /* 0:Default model hdr for undeclared content.*/
  111. UNCH *dtype = 0;              /* Document type name. */
  112. UNCH *entbuf = 0;             /* Buffer for entity reference name. */
  113. UNCH fce[2];                  /* String form of FCE char.
  114.                                  (fce[1] must be EOS).*/
  115. /* Buffer for non-SGML character reference.*/
  116. UNCH nonchbuf[2] = { DELNONCH };
  117. UNCH *tbuf;              /* Work area for tokenization. */
  118. UNCH *lbuf = 0;              /* In tbuf: Literal parse area.*/
  119. UNCH *sysibuf = 0;          /* Buffer for system identifiers. */
  120. UNCH *pubibuf = 0;          /* Buffer for public identifiers. */
  121. UNCH *nmbuf = 0;          /* Name buffer used by mdentity. */
  122. struct mpos *savedpos;
  123.  
  124. /* Constants.
  125. */
  126. struct map dctab[] = {        /* Keywords for declared content parameter.*/
  127.      { key[KRCDATA],  MRCDATA+MPHRASE },
  128.      { key[KCDATA],   MCDATA+MPHRASE },
  129.      { key[KANY],     MANY+MCHARS+MGI },
  130.      { key[KEMPTY],   MNONE+MPHRASE },
  131.      { NULL,          0 }
  132. };
  133. struct map deftab[] = {       /* Default value keywords. */
  134.      { key[KIMPLIED],  DNULL },
  135.      { key[KREQUIRED], DREQ  },
  136.      { key[KCURRENT],  DCURR },
  137.      { key[KCONREF],   DCONR },
  138.      { key[KFIXED],    DFIXED},
  139.      { NULL,           0}
  140. };
  141. struct map dvtab[] = {        /* Declared value: keywords and type codes.*/
  142. /*                                TYPE      NUMBER   */
  143. /*   grp             ANMTGRP      Case 1 0  Grp size */
  144. /*   grp member      ANMTGRP      Case   0  Position */
  145. /*   grp             ANOTEGRP     Case 1 1  Grp size */
  146.      { key[KNOTATION], ANOTEGRP}, /* Case   1  Position */
  147.      { key[KCDATA],    ACHARS  }, /* Case   2  Always 0 */
  148.      { key[KENTITY],   AENTITY }, /* Case   3  Normal 1 */
  149.      { key[KID],       AID     }, /* Case   4  Normal 1 */
  150.      { key[KIDREF],    AIDREF  }, /* Case   5  Normal 1 */
  151.      { key[KNAME],     ANAME   }, /* Case   6  Normal 1 */
  152.      { key[KNMTOKEN],  ANMTOKE }, /* Case   7  Normal 1 */
  153.      { key[KNUMBER],   ANUMBER }, /* Case   8  Normal 1 */
  154.      { key[KNUTOKEN],  ANUTOKE }, /* Case   9  Normal 1 */
  155.      { key[KENTITIES], AENTITYS}, /* Case   A  Normal 1 */
  156.      { key[KIDREFS],   AIDREFS }, /* Case   B  # tokens */
  157.      { key[KNAMES],    ANAMES  }, /* Case   C  # tokens */
  158.      { key[KNMTOKENS], ANMTOKES}, /* Case   D  # tokens */
  159.      { key[KNUMBERS],  ANUMBERS}, /* Case   E  # tokens */
  160.      { key[KNUTOKENS], ANUTOKES}, /* Case   F  # tokens */
  161.      { NULL,           0 }         /* Case   0  ERROR    */
  162. };
  163. struct map enttab[] = {       /* Entity declaration second parameter. */
  164.      { key[KCDATA],     ESC },
  165.      { key[KSDATA],     ESX },
  166.      { key[KMS],        ESMS},
  167.      { key[KPI],        ESI },
  168.      { key[KSTARTTAG],  ESS },
  169.      { key[KENDTAG],    ESE },
  170.      { key[KMD],        ESMD},
  171.      { NULL,            0 }
  172. };
  173. struct map exttab[] = {       /* Keywords for external identifier. */
  174.      { key[KSYSTEM],    EDSYSTEM },
  175.      { key[KPUBLIC],    EDPUBLIC },
  176.      { NULL,            0 }
  177. };
  178. struct map extettab[] = {       /* Keywords for external entity type. */
  179.      { key[KCDATA],     ESNCDATA },
  180.      { key[KNDATA],     ESNNDATA },
  181.      { key[KSDATA],     ESNSDATA },
  182.      { key[KSUBDOC],    ESNSUB },
  183.      { NULL,            0 }
  184. };
  185. struct map funtab[] = {       /* Function character reference names. */
  186.      { key[KRE],       RECHAR },
  187.      { key[KRS],       RSCHAR },
  188.      { key[KSPACE],    SPCCHAR },
  189.      /* We should use an extra table for added functions. */
  190.      { (UNCH *)"TAB",  TABCHAR },
  191.      { NULL,           0 }
  192. };
  193. struct map mstab[] = {        /* Marked section keywords. */
  194.      { key[KTEMP],    MSTEMP  },
  195.      { key[KINCLUDE], MSTEMP  }, /* Treat INCLUDE like TEMP; both are NOPs.*/
  196.      { key[KRCDATA],  MSRCDATA},
  197.      { key[KCDATA],   MSCDATA },
  198.      { key[KIGNORE],  MSIGNORE},
  199.      { NULL,          0 }
  200. };
  201. struct map pubcltab[] = {     /* Names for public text class. */
  202.      { (UNCH *)"CAPACITY",  FPICAP  },
  203.      { (UNCH *)"CHARSET",   FPICHARS},
  204.      { (UNCH *)"DOCUMENT",  FPIDOC  },
  205.      { (UNCH *)"DTD",       FPIDTD  },
  206.      { (UNCH *)"ELEMENTS",  FPIELEM },
  207.      { (UNCH *)"ENTITIES",  FPIENT  },
  208.      { (UNCH *)"LPD",       FPILPD  },
  209.      { (UNCH *)"NONSGML",   FPINON  },
  210.      { (UNCH *)"NOTATION",  FPINOT  },
  211.      { (UNCH *)"SHORTREF",  FPISHORT},
  212.      { (UNCH *)"SUBDOC",    FPISUB  },
  213.      { (UNCH *)"SYNTAX",    FPISYN  },
  214.      { (UNCH *)"TEXT",      FPITEXT },
  215.      { NULL,            0 }
  216. };
  217. UNCH indefent[] = "\12#DEFAULT";   /* Internal name: default entity name. */
  218. UNCH indefetd[] = "\12*DOCTYPE";   /* Internal name: default document type. */
  219. UNCH indocent[] = "\12*SGMLDOC";   /* Internal name: SGML document entity. */
  220. UNCH indocetd[]  = "\6*DOC";       /* Internal name: document level etd. */
  221. UNCH indtdent[]  = "\11*DTDENT";   /* Internal name: external DTD entity. */
  222.  
  223. struct etd dumetd[3];
  224. struct entity *dumpecb;
  225. UNCH sgmlkey[] = "SGML";
  226.