SGML.h
上传用户:zlh9724
上传日期:2007-01-04
资源大小:1991k
文件大小:4k
源码类别:

浏览器

开发平台:

Unix_Linux

  1. /*                                                                      SGML Parse Definition
  2.                                   SGML PARSE DEFINITION
  3.                                              
  4.  */
  5. /*
  6. **      (c) COPYRIGHT MIT 1995.
  7. **      Please first read the full copyright statement in the file COPYRIGH.
  8. */
  9. /*
  10.    The SGML parser is a state machine.  It is called for every character of the input
  11.    stream. The DTD data structure contains pointers to functions which are called to
  12.    implement the actual effect of the text read. When these functions are called, the
  13.    attribute structures pointed to by the DTD are valid, and the function is parsed a
  14.    pointer to the curent tag structure, and an "element stack" which represents the state
  15.    of nesting within SGML elements. See also the the generic Stream definition
  16.    
  17.    The following aspects are from Dan Connolly's suggestions: Binary search, Strcutured
  18.    object scheme basically, SGML content enum type.
  19.    
  20.    This module is implemented by SGML.c, and it is a part of the W3C Reference Library.
  21.    
  22.  */
  23. #ifndef SGML_H
  24. #define SGML_H
  25. #include "HTStream.h"
  26. #include "HTStruct.h"
  27. /*
  28. SGML content types
  29.  */
  30. typedef enum _SGMLContent{
  31.   SGML_EMPTY,    /* no content */
  32.   SGML_LITERAL, /* character data. Recognized exact close tag only.
  33.                     Old www server compatibility only! Not SGML */
  34.   SGML_CDATA,    /* character data. recognize </ only */
  35.   SGML_RCDATA,   /* replaceable character data. recognize </ and &ref; */
  36.   SGML_MIXED,    /* elements and parsed character data. recognize all markup */
  37.   SGML_ELEMENT   /* any data found will be returned as an error*/
  38.   } SGMLContent;
  39. typedef struct {
  40.     char *      name;           /* The (constant) name of the attribute */
  41.                                 /* Could put type info in here */
  42. } attr;
  43. /*              A tag structure describes an SGML element.
  44. **              -----------------------------------------
  45. **
  46. **
  47. **      name            is the string which comes after the tag opener "<".
  48. **
  49. **      attributes      points to a zero-terminated array
  50. **                      of attribute names.
  51. **
  52. **      litteral        determines how the SGML engine parses the charaters
  53. **                      within the element. If set, tag openers are ignored
  54. **                      except for that which opens a matching closing tag.
  55. **
  56. */
  57. typedef struct _tag HTTag;
  58. struct _tag{
  59.     char *      name;                   /* The name of the tag */
  60.     attr *      attributes;             /* The list of acceptable attributes */
  61.     int         number_of_attributes;   /* Number of possible attributes */
  62.     SGMLContent contents;               /* End only on end tag @@ */
  63. };
  64. /*              DTD Information
  65. **              ---------------
  66. **
  67. ** Not the whole DTD, but all this parser usues of it.
  68. */
  69. typedef struct {
  70.     HTTag *             tags;           /* Must be in strcmp order by name */
  71.     int                 number_of_tags;
  72.     CONST char **       entity_names;   /* Must be in strcmp order by name */
  73.     int                 number_of_entities;
  74. } SGML_dtd;
  75. #define MAX_ATTRIBUTES 20            /* Max number of attributes per element */
  76. /*      SGML context passed to parsers */
  77. typedef struct _HTSGMLContext *HTSGMLContext;   /* Hidden */
  78. /*
  79. Find a Tag by Name
  80.    Returns a pointer to the tag within the DTD.
  81.    
  82.  */
  83. extern HTTag * SGMLFindTag (CONST SGML_dtd* dtd, CONST char * string);
  84. /*
  85. Find a Attribute by Name
  86.    Returns the number of the atribute or -1 if failure.
  87.    
  88.  */
  89. extern int SGMLFindAttribute (HTTag* tag, CONST char * string);
  90. /*
  91. Create an SGML parser
  92.  */
  93. /*
  94. ** On entry,
  95. **      dtd             must point to a DTD structure as defined above
  96. **      callbacks       must point to user routines.
  97. **      callData        is returned in callbacks transparently.
  98. ** On exit,
  99. **              The default tag starter has been processed.
  100. */
  101. extern HTStream* SGML_new (
  102.         CONST SGML_dtd *                dtd,
  103.         HTStructured *          target);
  104. #if 0
  105. extern CONST HTStreamClass SGMLParser;
  106. #endif
  107. #endif  /* SGML_H */
  108. /*
  109.     */