Edinburgh Speech Tools  2.4-release
 All Classes Functions Variables Typedefs Enumerations Enumerator Friends Pages
dtd.h
1 /*************************************************************************/
2 /* */
3 /* Copyright (c) 1997-98 Richard Tobin, Language Technology Group, HCRC, */
4 /* University of Edinburgh. */
5 /* */
6 /* THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, */
7 /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
8 /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
9 /* IN NO EVENT SHALL THE AUTHOR OR THE UNIVERSITY OF EDINBURGH BE LIABLE */
10 /* FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF */
11 /* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION */
12 /* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
13 /* */
14 /*************************************************************************/
15 #ifndef DTD_H
16 #define DTD_H
17 
18 #ifndef FOR_LT
19 #define XML_API
20 #endif
21 
22 #include "charset.h"
23 
24 /* Typedefs */
25 
26 typedef struct dtd *Dtd;
27 
28 typedef struct entity *Entity;
29 
30 typedef struct element_definition *ElementDefinition;
31 
32 typedef struct attribute_definition *AttributeDefinition;
33 AttributeDefinition NextAttributeDefinition(ElementDefinition element,
34  AttributeDefinition previous);
35 
36 typedef struct notation_definition *NotationDefinition;
37 
38 /* DTDs */
39 
40 struct dtd {
41  const Char *name; /* The doctype name */
42  Entity internal_part, external_part;
43  Entity entities;
44  Entity parameter_entities;
45  Entity predefined_entities;
46 #ifdef FOR_LT
47  NSL_Doctype_I *doctype;
48 #else
49  ElementDefinition elements;
50 #endif
51  NotationDefinition notations;
52 };
53 
54 /* Entities */
55 
56 enum entity_type {ET_external, ET_internal};
57 typedef enum entity_type EntityType;
58 
59 enum markup_language {ML_xml, ML_nsl, ML_unspecified};
60 typedef enum markup_language MarkupLanguage;
61 
62 enum standalone_declaration {
63  /* NB must match NSL's rmdCode */
64  SDD_unspecified, SDD_no, SDD_yes, SDD_enum_count
65 };
66 typedef enum standalone_declaration StandaloneDeclaration;
67 
68 extern const char8 *StandaloneDeclarationName[SDD_enum_count];
69 
70 
71 struct entity {
72  /* All entities */
73 
74  const Char *name; /* The name in the entity declaration */
75  EntityType type; /* ET_external or ET_internal */
76  const char8 *base_url; /* If different from expected */
77  struct entity *next; /* For chaining a document's entity defns */
78  CharacterEncoding encoding; /* The character encoding of the entity */
79  Entity parent; /* The entity in which it is defined */
80  const char8 *url; /* URL of entity */
81 
82  /* Internal entities */
83 
84  const Char *text; /* Text of the entity */
85  int line_offset; /* Line offset of definition */
86  int line1_char_offset; /* Char offset on first line */
87  int matches_parent_text; /* False if might contain expanded PEs */
88 
89  /* External entities */
90 
91  const char8 *systemid; /* Declared public ID */
92  const char8 *publicid; /* Declared public ID */
93  NotationDefinition notation; /* Binary entity's declared notation */
94  MarkupLanguage ml_decl; /* XML, NSL or not specified */
95  const char8 *version_decl; /* XML declarations found in entity, if any */
96  CharacterEncoding encoding_decl;
97  StandaloneDeclaration standalone_decl;
98  const char8 *ddb_filename; /* filename in NSL declaration */
99 };
100 
101 /* Elements */
102 
103 enum content_type {
104  /* NB this must match NSL's ctVals */
105  CT_mixed, CT_any, CT_bogus1, CT_bogus2, CT_empty, CT_element, CT_enum_count
106 };
107 typedef enum content_type ContentType;
108 
109 extern XML_API const char8 *ContentTypeName[CT_enum_count];
110 
112  const Char *name; /* The element name */
113  int namelen;
114  int tentative;
115 #ifdef FOR_LT
116  NSL_Doctype_I *doctype;
117  NSL_ElementSummary_I *elsum;
118 #else
119  ContentType type; /* The declared content */
120  Char *content; /* Element content */
121  AttributeDefinition attributes;
122  struct element_definition *next;
123 #endif
124 };
125 
126 /* Attributes */
127 
128 enum default_type {
129  /* NB this must match NSL's NSL_ADefType */
130  DT_required, DT_bogus1, DT_implied,
131  DT_bogus2, DT_none, DT_fixed, DT_enum_count
132 };
133 typedef enum default_type DefaultType;
134 
135 extern XML_API const char8 *DefaultTypeName[DT_enum_count];
136 
137 enum attribute_type {
138  /* NB this must match NSL's NSL_Attr_Dec_Value */
139  AT_cdata, AT_bogus1, AT_bogus2, AT_nmtoken, AT_bogus3, AT_entity,
140  AT_idref, AT_bogus4, AT_bogus5, AT_nmtokens, AT_bogus6, AT_entities,
141  AT_idrefs, AT_id, AT_notation, AT_enumeration, AT_enum_count
142 };
143 typedef enum attribute_type AttributeType;
144 
145 extern XML_API const char8 *AttributeTypeName[AT_enum_count];
146 
148 #ifdef FOR_LT
149  /* NB this must match NSL's AttributeSummary */
150  /* We never really have one of these structures; only an AttributeSummary
151  cast to this type. We need to be able to access the type, so that
152  we can normalise if appropriate. We need to be able to refer to
153  the default_type and default_value, but these don't need to work
154  since we will never have ReturnDefaultedAttributes true in NSL. */
155  int a, b, c;
156  short d;
157  char type, default_type;
158  /* This had better never be accessed! */
159  Char *default_value;
160 #else
161  const Char *name; /* The attribute name */
162  int namelen;
163  AttributeType type; /* The declared type */
164  Char **allowed_values; /* List of allowed values, argv style */
165  DefaultType default_type; /* The type of the declared default */
166  const Char *default_value; /* The declared default value */
167  struct attribute_definition *next;
168 #endif
169 };
170 
171 /* Notations */
172 
174  const Char *name; /* The notation name */
175  int tentative;
176  const char8 *systemid; /* System identifier */
177  const char8 *publicid; /* Public identifier */
178  struct notation_definition *next;
179 };
180 
181 /* Public functions */
182 
183 XML_API Dtd NewDtd(void);
184 XML_API void FreeDtd(Dtd dtd);
185 
186 XML_API Entity NewExternalEntityN(const Char *name, int namelen,
187  const char8 *publicid, const char8 *systemid,
188  NotationDefinition notation,
189  Entity parent);
190 XML_API Entity NewInternalEntityN(const Char *name, int namelen,
191  const Char *text, Entity parent,
192  int line_offset, int line1_char_offset,
193  int matches_parent_text);
194 XML_API void FreeEntity(Entity e);
195 
196 XML_API const char8 *EntityURL(Entity e);
197 XML_API const char8 *EntityDescription(Entity e);
198 XML_API void EntitySetBaseURL(Entity e, const char8 *url);
199 XML_API const char8 *EntityBaseURL(Entity e);
200 
201 XML_API Entity DefineEntity(Dtd dtd, Entity entity, int pe);
202 XML_API Entity FindEntityN(Dtd dtd, const Char *name, int namelen, int pe);
203 
204 #define NewExternalEntity(name, pub, sys, nnot, parent) \
205  NewExternalEntityN(name, name ? Strlen(name) : 0, pub, sys, nnot, parent)
206 #define NewInternalEntity(name, test, parent, l, l1, mat) \
207  NewInternalEntityN(name, name ? Strlen(name) : 0, test, parent, l, l1, mat)
208 #define FindEntity(dtd, name, pe) FindEntityN(dtd, name, Strlen(name), pe)
209 
210 XML_API ElementDefinition DefineElementN(Dtd dtd, const Char *name, int namelen,
211  ContentType type, Char *content);
212 XML_API ElementDefinition TentativelyDefineElementN(Dtd dtd,
213  const Char *name, int namelen);
214 XML_API ElementDefinition RedefineElement(ElementDefinition e, ContentType type,
215  Char *content);
216 XML_API ElementDefinition FindElementN(Dtd dtd, const Char *name, int namelen);
217 XML_API void FreeElementDefinition(ElementDefinition e);
218 
219 #define DefineElement(dtd, name, type, content) \
220  DefineElementN(dtd, name, Strlen(name), type, content)
221 #define TentativelyDefineElement(dtd, name) \
222  TentativelyDefineElementN(dtd, name, Strlen(name))
223 #define FindElement(dtd, name) FindElementN(dtd, name, Strlen(name))
224 
225 XML_API AttributeDefinition DefineAttributeN(ElementDefinition element,
226  const Char *name, int namelen,
227  AttributeType type, Char **allowed_values,
228  DefaultType default_type,
229  const Char *default_value);
230 XML_API AttributeDefinition FindAttributeN(ElementDefinition element,
231  const Char *name, int namelen);
232 XML_API void FreeAttributeDefinition(AttributeDefinition a);
233 
234 #define DefineAttribute(element, name, type, all, dt, dv) \
235  DefineAttributeN(element, name, Strlen(name), type, all, dt, dv)
236 #define FindAttribute(element, name) \
237  FindAttributeN(element, name, Strlen(name))
238 
239 XML_API NotationDefinition DefineNotationN(Dtd dtd, const Char *name, int namelen,
240  const char8 *publicid, const char8 *systemid);
241 XML_API NotationDefinition TentativelyDefineNotationN(Dtd dtd,
242  const Char *name, int namelen);
243 XML_API NotationDefinition RedefineNotation(NotationDefinition n,
244  const char8 *publicid, const char8 *systemid);
245 XML_API NotationDefinition FindNotationN(Dtd dtd, const Char *name, int namelen);
246 XML_API void FreeNotationDefinition(NotationDefinition n);
247 
248 #define DefineNotation(dtd, name, pub, sys) \
249  DefineNotationN(dtd, name, Strlen(name), pub, sys)
250 #define TentativelyDefineNotation(dtd, name) \
251  TentativelyDefineNotationN(dtd, name, Strlen(name))
252 #define FindNotation(dtd, name) FindNotationN(dtd, name, Strlen(name))
253 
254 #endif /* DTD_H */