Annotation of Amaya/amaya/XHTMLbuilder.c, revision 1.60
1.1 cvs 1: /*
2: *
1.59 quint 3: * (c) COPYRIGHT MIT and INRIA, 1996-2002.
1.1 cvs 4: * Please first read the full copyright statement in file COPYRIGHT.
5: *
6: */
7:
8: /*
1.30 cvs 9: * XHTMLbuilder.c
1.23 cvs 10: * Builds the corresponding abstract tree for a Thot document of type HTML.
1.1 cvs 11: *
1.20 cvs 12: * Authors: L. Carcone
13: * V. Quint
1.1 cvs 14: */
15:
16: #define THOT_EXPORT extern
17: #include "amaya.h"
18: #include "css.h"
1.2 cvs 19: #include "parser.h"
20: #include "HTML.h"
1.30 cvs 21: #include "fetchHTMLname.h"
1.2 cvs 22:
1.13 cvs 23: #include "css_f.h"
24: #include "fetchXMLname_f.h"
1.30 cvs 25: #include "fetchHTMLname_f.h"
1.22 cvs 26: #include "html2thot_f.h"
1.1 cvs 27: #include "HTMLactions_f.h"
28: #include "HTMLedit_f.h"
1.22 cvs 29: #include "HTMLform_f.h"
1.1 cvs 30: #include "HTMLimage_f.h"
31: #include "HTMLtable_f.h"
32: #include "HTMLimage_f.h"
33: #include "UIcss_f.h"
1.13 cvs 34: #include "styleparser_f.h"
1.2 cvs 35: #include "XHTMLbuilder_f.h"
1.13 cvs 36: #include "Xml2thot_f.h"
1.1 cvs 37:
38: /* maximum length of a Thot structure schema name */
39: #define MAX_SS_NAME_LENGTH 32
40:
1.30 cvs 41: #define MaxMsgLength 200
42:
1.47 cvs 43: /* Elements that cannot contain text as immediate children.
44: When some text is present in the HTML file it must be
45: surrounded by a Pseudo_paragraph element */
46: static int NoTextChild[] =
47: {
48: HTML_EL_Document, HTML_EL_HTML, HTML_EL_HEAD, HTML_EL_BODY,
49: HTML_EL_Definition_List, HTML_EL_Block_Quote, HTML_EL_Directory,
50: HTML_EL_Form, HTML_EL_Menu, HTML_EL_FIELDSET,
51: HTML_EL_Numbered_List, HTML_EL_Option_Menu,
52: HTML_EL_Unnumbered_List, HTML_EL_Definition, HTML_EL_List_Item,
53: HTML_EL_MAP, HTML_EL_map, HTML_EL_Applet,
54: HTML_EL_Object, HTML_EL_IFRAME, HTML_EL_NOFRAMES,
55: HTML_EL_Division, HTML_EL_Center, HTML_EL_NOSCRIPT,
56: HTML_EL_Data_cell, HTML_EL_Heading_cell,
57: 0};
58:
1.14 cvs 59: /* Mapping table of HTML attribute values */
60: AttrValueMapping XhtmlAttrValueMappingTable[] =
1.1 cvs 61: {
1.59 quint 62: {HTML_ATTR_dir, "ltr", HTML_ATTR_dir_VAL_ltr_},
63: {HTML_ATTR_dir, "rtl", HTML_ATTR_dir_VAL_rtl_},
1.1 cvs 64:
1.36 cvs 65: {HTML_ATTR_TextAlign, "left", HTML_ATTR_TextAlign_VAL_left_},
66: {HTML_ATTR_TextAlign, "center", HTML_ATTR_TextAlign_VAL_center_},
67: {HTML_ATTR_TextAlign, "right", HTML_ATTR_TextAlign_VAL_right_},
68: {HTML_ATTR_TextAlign, "justify", HTML_ATTR_TextAlign_VAL_justify_},
69:
70: {HTML_ATTR_Align, "left", HTML_ATTR_Align_VAL_left_},
71: {HTML_ATTR_Align, "center", HTML_ATTR_Align_VAL_center_},
72: {HTML_ATTR_Align, "right", HTML_ATTR_Align_VAL_right_},
73:
74: {HTML_ATTR_LAlign, "top", HTML_ATTR_LAlign_VAL_Top_},
75: {HTML_ATTR_LAlign, "bottom", HTML_ATTR_LAlign_VAL_Bottom_},
76: {HTML_ATTR_LAlign, "left", HTML_ATTR_LAlign_VAL_Left_},
77: {HTML_ATTR_LAlign, "right", HTML_ATTR_LAlign_VAL_Right_},
78:
79: {HTML_ATTR_Clear, "left", HTML_ATTR_Clear_VAL_Left_},
80: {HTML_ATTR_Clear, "right", HTML_ATTR_Clear_VAL_Right_},
81: {HTML_ATTR_Clear, "all", HTML_ATTR_Clear_VAL_All_},
82: {HTML_ATTR_Clear, "none", HTML_ATTR_Clear_VAL_None_},
83:
84: {HTML_ATTR_NumberStyle, "1", HTML_ATTR_NumberStyle_VAL_Arabic_},
85: {HTML_ATTR_NumberStyle, "a", HTML_ATTR_NumberStyle_VAL_LowerAlpha},
86: {HTML_ATTR_NumberStyle, "A", HTML_ATTR_NumberStyle_VAL_UpperAlpha},
87: {HTML_ATTR_NumberStyle, "i", HTML_ATTR_NumberStyle_VAL_LowerRoman},
88: {HTML_ATTR_NumberStyle, "I", HTML_ATTR_NumberStyle_VAL_UpperRoman},
89:
90: {HTML_ATTR_BulletStyle, "disc", HTML_ATTR_BulletStyle_VAL_disc},
91: {HTML_ATTR_BulletStyle, "square", HTML_ATTR_BulletStyle_VAL_square},
92: {HTML_ATTR_BulletStyle, "circle", HTML_ATTR_BulletStyle_VAL_circle},
93:
94: {HTML_ATTR_ItemStyle, "1", HTML_ATTR_ItemStyle_VAL_Arabic_},
95: {HTML_ATTR_ItemStyle, "a", HTML_ATTR_ItemStyle_VAL_LowerAlpha},
96: {HTML_ATTR_ItemStyle, "A", HTML_ATTR_ItemStyle_VAL_UpperAlpha},
97: {HTML_ATTR_ItemStyle, "i", HTML_ATTR_ItemStyle_VAL_LowerRoman},
98: {HTML_ATTR_ItemStyle, "I", HTML_ATTR_ItemStyle_VAL_UpperRoman},
99: {HTML_ATTR_ItemStyle, "disc", HTML_ATTR_ItemStyle_VAL_disc},
100: {HTML_ATTR_ItemStyle, "square", HTML_ATTR_ItemStyle_VAL_square},
101: {HTML_ATTR_ItemStyle, "circle", HTML_ATTR_ItemStyle_VAL_circle},
102:
103: {HTML_ATTR_Button_type, "button", HTML_ATTR_Button_type_VAL_button},
104: {HTML_ATTR_Button_type, "submit", HTML_ATTR_Button_type_VAL_submit},
105: {HTML_ATTR_Button_type, "reset", HTML_ATTR_Button_type_VAL_reset},
106:
107: {HTML_ATTR_frame, "void", HTML_ATTR_frame_VAL_void},
108: {HTML_ATTR_frame, "above", HTML_ATTR_frame_VAL_above},
109: {HTML_ATTR_frame, "below", HTML_ATTR_frame_VAL_below},
110: {HTML_ATTR_frame, "hsides", HTML_ATTR_frame_VAL_hsides},
111: {HTML_ATTR_frame, "lhs", HTML_ATTR_frame_VAL_lhs},
112: {HTML_ATTR_frame, "rhs", HTML_ATTR_frame_VAL_rhs},
113: {HTML_ATTR_frame, "vsides", HTML_ATTR_frame_VAL_vsides},
114: {HTML_ATTR_frame, "box", HTML_ATTR_frame_VAL_box},
115: {HTML_ATTR_frame, "border", HTML_ATTR_frame_VAL_border},
116:
117: {HTML_ATTR_frameborder, "0", HTML_ATTR_frameborder_VAL_Border0},
118: {HTML_ATTR_frameborder, "1", HTML_ATTR_frameborder_VAL_Border1},
119:
120: {HTML_ATTR_scrolling, "yes", HTML_ATTR_scrolling_VAL_Yes_},
121: {HTML_ATTR_scrolling, "no", HTML_ATTR_scrolling_VAL_No_},
122: {HTML_ATTR_scrolling, "auto", HTML_ATTR_scrolling_VAL_auto_},
123:
124: {HTML_ATTR_rules_, "none", HTML_ATTR_rules__VAL_none_},
125: {HTML_ATTR_rules_, "groups", HTML_ATTR_rules__VAL_groups},
126: {HTML_ATTR_rules_, "rows", HTML_ATTR_rules__VAL_rows},
127: {HTML_ATTR_rules_, "cols", HTML_ATTR_rules__VAL_cols},
128: {HTML_ATTR_rules_, "all", HTML_ATTR_rules__VAL_all},
129:
130: {HTML_ATTR_Cell_align, "left", HTML_ATTR_Cell_align_VAL_Cell_left},
131: {HTML_ATTR_Cell_align, "center", HTML_ATTR_Cell_align_VAL_Cell_center},
132: {HTML_ATTR_Cell_align, "right", HTML_ATTR_Cell_align_VAL_Cell_right},
133: {HTML_ATTR_Cell_align, "justify", HTML_ATTR_Cell_align_VAL_Cell_justify},
134: {HTML_ATTR_Cell_align, "char", HTML_ATTR_Cell_align_VAL_Cell_char},
135:
136: {HTML_ATTR_Alignment, "top", HTML_ATTR_Alignment_VAL_Top_},
137: {HTML_ATTR_Alignment, "middle", HTML_ATTR_Alignment_VAL_Middle_},
138: {HTML_ATTR_Alignment, "bottom", HTML_ATTR_Alignment_VAL_Bottom_},
139: {HTML_ATTR_Alignment, "left", HTML_ATTR_Alignment_VAL_Left_},
140: {HTML_ATTR_Alignment, "right", HTML_ATTR_Alignment_VAL_Right_},
141:
142: {HTML_ATTR_METHOD, "get", HTML_ATTR_METHOD_VAL_Get_},
143: {HTML_ATTR_METHOD, "post", HTML_ATTR_METHOD_VAL_Post_},
144:
145: {HTML_ATTR_Position, "top", HTML_ATTR_Position_VAL_Position_top},
146: {HTML_ATTR_Position, "bottom", HTML_ATTR_Position_VAL_Position_bottom},
147: {HTML_ATTR_Position, "left", HTML_ATTR_Position_VAL_Position_left},
148: {HTML_ATTR_Position, "right", HTML_ATTR_Position_VAL_Position_right},
149:
150: {HTML_ATTR_Row_valign, "top", HTML_ATTR_Row_valign_VAL_Row_top},
151: {HTML_ATTR_Row_valign, "middle", HTML_ATTR_Row_valign_VAL_Row_middle},
152: {HTML_ATTR_Row_valign, "bottom", HTML_ATTR_Row_valign_VAL_Row_bottom},
153: {HTML_ATTR_Row_valign, "baseline", HTML_ATTR_Row_valign_VAL_Row_baseline},
154:
155: {HTML_ATTR_Cell_valign, "top", HTML_ATTR_Cell_valign_VAL_Cell_top},
156: {HTML_ATTR_Cell_valign, "middle", HTML_ATTR_Cell_valign_VAL_Cell_middle},
157: {HTML_ATTR_Cell_valign, "bottom", HTML_ATTR_Cell_valign_VAL_Cell_bottom},
158: {HTML_ATTR_Cell_valign, "baseline", HTML_ATTR_Cell_valign_VAL_Cell_baseline},
159:
160: {HTML_ATTR_shape, "rect", HTML_ATTR_shape_VAL_rectangle},
161: {HTML_ATTR_shape, "circle", HTML_ATTR_shape_VAL_circle},
162: {HTML_ATTR_shape, "poly", HTML_ATTR_shape_VAL_polygon},
163:
164: {HTML_ATTR_valuetype, "data", HTML_ATTR_valuetype_VAL_data_},
165: {HTML_ATTR_valuetype, "ref", HTML_ATTR_valuetype_VAL_ref},
166: {HTML_ATTR_valuetype, "object", HTML_ATTR_valuetype_VAL_object_},
1.1 cvs 167:
1.57 cvs 168: {HTML_ATTR_EmbedHidden, "yes", HTML_ATTR_EmbedHidden_VAL_Yes_},
169: {HTML_ATTR_EmbedHidden, "no", HTML_ATTR_EmbedHidden_VAL_No_},
170:
1.1 cvs 171: /* HTML attribute TYPE generates a Thot element */
1.36 cvs 172: {DummyAttribute, "button", HTML_EL_Button_Input},
173: {DummyAttribute, "checkbox", HTML_EL_Checkbox_Input},
174: {DummyAttribute, "file", HTML_EL_File_Input},
175: {DummyAttribute, "hidden", HTML_EL_Hidden_Input},
176: {DummyAttribute, "image", HTML_EL_PICTURE_UNIT},
177: {DummyAttribute, "password", HTML_EL_Password_Input},
178: {DummyAttribute, "radio", HTML_EL_Radio_Input},
179: {DummyAttribute, "reset", HTML_EL_Reset_Input},
180: {DummyAttribute, "submit", HTML_EL_Submit_Input},
181: {DummyAttribute, "text", HTML_EL_Text_Input},
1.1 cvs 182:
183: /* The following declarations allow the parser to accept boolean attributes */
184: /* written "checked=CHECKED"), for instance */
1.36 cvs 185: {HTML_ATTR_ISMAP, "ismap", HTML_ATTR_ISMAP_VAL_Yes_},
186: {HTML_ATTR_nohref, "nohref", HTML_ATTR_nohref_VAL_Yes_},
187: {HTML_ATTR_COMPACT, "compact", HTML_ATTR_COMPACT_VAL_Yes_},
188: {HTML_ATTR_Multiple, "multiple", HTML_ATTR_Multiple_VAL_Yes_},
189: {HTML_ATTR_Selected, "selected", HTML_ATTR_Selected_VAL_Yes_},
190: {HTML_ATTR_Checked, "checked", HTML_ATTR_Checked_VAL_Yes_},
191: {HTML_ATTR_No_wrap, "nowrap", HTML_ATTR_No_wrap_VAL_no_wrap},
192: {HTML_ATTR_NoShade, "noshade", HTML_ATTR_NoShade_VAL_NoShade_},
193: {HTML_ATTR_declare, "declare", HTML_ATTR_declare_VAL_Yes_},
194: {HTML_ATTR_defer, "defer", HTML_ATTR_defer_VAL_Yes_},
195: {HTML_ATTR_disabled, "disabled", HTML_ATTR_disabled_VAL_Yes_},
196: {HTML_ATTR_readonly, "readonly", HTML_ATTR_readonly_VAL_Yes_},
197: {HTML_ATTR_no_resize, "noresize", HTML_ATTR_no_resize_VAL_Yes_},
1.21 cvs 198:
199: /* XML attribute xml:space */
1.36 cvs 200: {HTML_ATTR_xml_space, "default", HTML_ATTR_xml_space_VAL_xml_space_default},
201: {HTML_ATTR_xml_space, "preserve", HTML_ATTR_xml_space_VAL_xml_space_preserve},
1.21 cvs 202:
1.36 cvs 203: {0, "", 0} /* Last entry. Mandatory */
1.1 cvs 204: };
1.6 cvs 205:
1.28 cvs 206: /* Define a pointer to let parser functions access the HTML entity table */
207: extern XmlEntity *pXhtmlEntityTable;
1.6 cvs 208:
1.30 cvs 209: /* maximum size of error messages */
210: #define MaxMsgLength 200
211:
1.6 cvs 212: /*----------------------------------------------------------------------
1.15 cvs 213: ParseCharset:
1.6 cvs 214: Parses the element HTTP-EQUIV and looks for the charset value.
215: ----------------------------------------------------------------------*/
1.30 cvs 216: void ParseCharset (Element el, Document doc)
217:
1.6 cvs 218: {
1.15 cvs 219: AttributeType attrType;
220: Attribute attr;
221: SSchema docSSchema;
222: CHARSET charset;
1.39 cvs 223: char *text, *text2, *ptrText, *str;
224: char charsetname[MAX_LENGTH];
1.15 cvs 225: int length;
1.6 cvs 226: int pos, index = 0;
227:
1.15 cvs 228: charset = TtaGetDocumentCharset (doc);
229: if (charset != UNDEFINED_CHARSET)
230: /* the charset was already defined by the http header */
231: return;
1.6 cvs 232:
233: docSSchema = TtaGetDocumentSSchema (doc);
234: attrType.AttrSSchema = docSSchema;
235: attrType.AttrTypeNum = HTML_ATTR_http_equiv;
236: attr = TtaGetAttribute (el, attrType);
237: if (attr != NULL)
238: {
239: /* There is a HTTP-EQUIV attribute */
240: length = TtaGetTextAttributeLength (attr);
241: if (length > 0)
242: {
1.37 cvs 243: text = TtaGetMemory (length + 1);
1.6 cvs 244: TtaGiveTextAttributeValue (attr, text, &length);
1.37 cvs 245: if (!strcasecmp (text, "content-type"))
1.6 cvs 246: {
247: attrType.AttrTypeNum = HTML_ATTR_meta_content;
248: attr = TtaGetAttribute (el, attrType);
249: if (attr != NULL)
250: {
251: length = TtaGetTextAttributeLength (attr);
252: if (length > 0)
253: {
1.37 cvs 254: text2 = TtaGetMemory (length + 1);
1.6 cvs 255: TtaGiveTextAttributeValue (attr, text2, &length);
256: ptrText = text2;
257: while (*ptrText)
258: {
1.53 vatton 259: *ptrText = tolower (*ptrText);
1.6 cvs 260: ptrText++;
261: }
262:
1.37 cvs 263: str = strstr (text2, "charset=");
1.6 cvs 264: if (str)
265: {
266: pos = str - text2 + 8;
1.37 cvs 267: while (text2[pos] != SPACE &&
268: text2[pos] != TAB && text2[pos] != EOS)
1.6 cvs 269: charsetname[index++] = text2[pos++];
1.37 cvs 270: charsetname[index] = EOS;
1.15 cvs 271: charset = TtaGetCharset (charsetname);
272: if (charset != UNDEFINED_CHARSET)
273: TtaSetDocumentCharset (doc, charset);
1.6 cvs 274: }
275: TtaFreeMemory (text2);
276: }
277: }
278: }
279: TtaFreeMemory (text);
280: }
281: }
282: }
283:
1.23 cvs 284: /*----------------------------------------------------------------------
1.47 cvs 285: XhtmlCannotContainText
286: Return TRUE if element el is a block element.
287: ----------------------------------------------------------------------*/
288: ThotBool XhtmlCannotContainText (ElementType elType)
289:
290: {
291: int i;
292: ThotBool ret;
293:
294: if (strcmp (TtaGetSSchemaName (elType.ElSSchema), "HTML"))
295: /* not an HTML element */
296: ret = TRUE;
297: else
298: {
299: ret = FALSE;
300: i = 0;
301: while (NoTextChild[i] > 0 && NoTextChild[i] != elType.ElTypeNum)
302: i++;
303: if (NoTextChild[i] == elType.ElTypeNum)
304: ret = TRUE;
305: }
306: return ret;
1.23 cvs 307: }
308:
1.6 cvs 309: /*----------------------------------------------------------------------
310: XhtmlElementComplete
1.20 cvs 311: Complete Xhtml elements.
1.6 cvs 312: Check its attributes and its contents.
313: ----------------------------------------------------------------------*/
1.51 cvs 314: void XhtmlElementComplete (Element el, Document doc, int *error)
1.30 cvs 315:
316: {
317: ElementType elType, newElType, childType;
318: Element constElem, child, desc, leaf, prev, next, last,
1.41 cvs 319: elFrames, lastFrame, lastChild, parent;
1.30 cvs 320: Attribute attr;
321: AttributeType attrType;
322: Language lang;
1.41 cvs 323: char *text;
1.39 cvs 324: char lastChar[2];
325: char *name1;
1.30 cvs 326: int length;
327: SSchema docSSchema;
1.6 cvs 328:
329: *error = 0;
330: docSSchema = TtaGetDocumentSSchema (doc);
331:
332: elType = TtaGetElementType (el);
333: /* is this a block-level element in a character-level element? */
1.56 cvs 334: if (!IsXMLElementInline (elType, doc) &&
1.24 cvs 335: elType.ElTypeNum != HTML_EL_Comment_ &&
336: elType.ElTypeNum != HTML_EL_XMLPI)
1.6 cvs 337: BlockInCharLevelElem (el);
338:
339: newElType.ElSSchema = elType.ElSSchema;
340: switch (elType.ElTypeNum)
341: {
342: case HTML_EL_Object: /* it's an object */
343: /* create Object_Content */
344: child = TtaGetFirstChild (el);
345: if (child != NULL)
346: elType = TtaGetElementType (child);
347:
348: /* is it the PICTURE element ? */
349: if (child == NULL || elType.ElTypeNum != HTML_EL_PICTURE_UNIT)
350: {
351: desc = child;
352: /* create the PICTURE element */
353: elType.ElTypeNum = HTML_EL_PICTURE_UNIT;
354: child = TtaNewTree (doc, elType, "");
355: if (desc == NULL)
356: TtaInsertFirstChild (&child, el, doc);
357: else
358: TtaInsertSibling (child, desc, TRUE, doc);
359: }
360:
361: /* copy attribute data into SRC attribute of Object_Image */
362: attrType.AttrSSchema = docSSchema;
363: attrType.AttrTypeNum = HTML_ATTR_data;
364: attr = TtaGetAttribute (el, attrType);
365: if (attr != NULL)
366: {
367: length = TtaGetTextAttributeLength (attr);
368: if (length > 0)
369: {
1.37 cvs 370: name1 = TtaGetMemory (length + 1);
1.6 cvs 371: TtaGiveTextAttributeValue (attr, name1, &length);
372: attrType.AttrTypeNum = HTML_ATTR_SRC;
373: attr = TtaGetAttribute (child, attrType);
374: if (attr == NULL)
375: {
376: attr = TtaNewAttribute (attrType);
377: TtaAttachAttribute (child, attr, doc);
378: }
379: TtaSetAttributeText (attr, name1, child, doc);
380: TtaFreeMemory (name1);
381: }
382: }
383:
384: /* is the Object_Content element already created ? */
385: desc = child;
386: TtaNextSibling(&desc);
387: if (desc != NULL)
388: elType = TtaGetElementType (desc);
389:
390: /* is it the Object_Content element ? */
391: if (desc == NULL || elType.ElTypeNum != HTML_EL_Object_Content)
392: {
393: /* create Object_Content */
394: elType.ElTypeNum = HTML_EL_Object_Content;
395: desc = TtaNewTree (doc, elType, "");
396: TtaInsertSibling (desc, child, FALSE, doc);
397: /* move previous existing children into Object_Content */
398: child = TtaGetLastChild(el);
399: while (child != desc)
400: {
401: TtaRemoveTree (child, doc);
402: TtaInsertFirstChild (&child, desc, doc);
403: child = TtaGetLastChild(el);
404: }
405: }
406: break;
407:
408: case HTML_EL_Unnumbered_List:
409: case HTML_EL_Numbered_List:
410: case HTML_EL_Menu:
411: case HTML_EL_Directory:
412: /* It's a List element. It should only have List_Item children.
413: If it has List element chidren, move these List elements
414: within their previous List_Item sibling. This is to fix
415: a bug in document generated by Mozilla. */
416: prev = NULL;
417: next = NULL;
418: child = TtaGetFirstChild (el);
419: while (child != NULL)
420: {
421: next = child;
422: TtaNextSibling (&next);
423: elType = TtaGetElementType (child);
424: if (elType.ElTypeNum == HTML_EL_Unnumbered_List ||
425: elType.ElTypeNum == HTML_EL_Numbered_List ||
426: elType.ElTypeNum == HTML_EL_Menu ||
427: elType.ElTypeNum == HTML_EL_Directory)
428: /* this list element is a child of another list element */
429: if (prev)
430: {
431: elType = TtaGetElementType (prev);
432: if (elType.ElTypeNum == HTML_EL_List_Item)
433: {
434: /* get the last child of the previous List_Item */
435: desc = TtaGetFirstChild (prev);
436: last = NULL;
437: while (desc)
438: {
439: last = desc;
440: TtaNextSibling (&desc);
441: }
442: /* move the list element after the last child of the
443: previous List_Item */
444: TtaRemoveTree (child, doc);
445: if (last)
446: TtaInsertSibling (child, last, FALSE, doc);
447: else
448: TtaInsertFirstChild (&child, prev, doc);
449: child = prev;
450: }
451: }
452: prev = child;
453: child = next;
454: }
455: break;
456:
457: case HTML_EL_FRAMESET:
458: /* The FRAMESET element is now complete. Gather all its FRAMESET
459: and FRAME children and wrap them up in a Frames element */
460: elFrames = NULL; lastFrame = NULL;
461: lastChild = NULL;
462: child = TtaGetFirstChild (el);
463: while (child != NULL)
464: {
465: next = child;
466: TtaNextSibling (&next);
467: elType = TtaGetElementType (child);
468: if (elType.ElTypeNum == HTML_EL_FRAMESET ||
469: elType.ElTypeNum == HTML_EL_FRAME ||
470: elType.ElTypeNum == HTML_EL_Comment_)
471: {
472: /* create the Frames element if it does not exist */
473: if (elFrames == NULL)
474: {
475: newElType.ElSSchema = docSSchema;
476: newElType.ElTypeNum = HTML_EL_Frames;
477: elFrames = TtaNewElement (doc, newElType);
478: XmlSetElemLineNumber (elFrames);
479: TtaInsertSibling (elFrames, child, TRUE, doc);
480: }
481: /* move the element as the last child of the Frames element */
482: TtaRemoveTree (child, doc);
483: if (lastFrame == NULL)
484: TtaInsertFirstChild (&child, elFrames, doc);
485: else
486: TtaInsertSibling (child, lastFrame, FALSE, doc);
487: lastFrame = child;
488: }
489: child = next;
490: }
491: break;
492:
493: case HTML_EL_Input: /* it's an INPUT without any TYPE attribute */
494: /* Create a child of type Text_Input */
495: elType.ElTypeNum = HTML_EL_Text_Input;
496: child = TtaNewTree (doc, elType, "");
497: XmlSetElemLineNumber (child);
498: TtaInsertFirstChild (&child, el, doc);
499: /* now, process it like a Text_Input element */
500:
501: case HTML_EL_Text_Input:
502: case HTML_EL_Password_Input:
503: case HTML_EL_File_Input:
504: /* get element Inserted_Text */
505: child = TtaGetFirstChild (el);
506: if (child != NULL)
507: {
508: attrType.AttrSSchema = docSSchema;
509: attrType.AttrTypeNum = HTML_ATTR_Value_;
510: attr = TtaGetAttribute (el, attrType);
511: if (attr != NULL)
512: {
513: /* copy the value of attribute "value" into the first text
514: leaf of element */
515: length = TtaGetTextAttributeLength (attr);
516: if (length > 0)
517: {
518: /* get the text leaf */
519: leaf = TtaGetFirstChild (child);
520: if (leaf != NULL)
521: {
522: childType = TtaGetElementType (leaf);
523: if (childType.ElTypeNum == HTML_EL_TEXT_UNIT)
524: {
525: /* copy attribute value into the text leaf */
1.37 cvs 526: text = TtaGetMemory (length + 1);
1.6 cvs 527: TtaGiveTextAttributeValue (attr, text, &length);
528: TtaSetTextContent (leaf, text,
529: TtaGetDefaultLanguage (), doc);
530: TtaFreeMemory (text);
531: }
532: }
533: }
534: }
535: }
536: break;
537:
538: case HTML_EL_META:
1.15 cvs 539: ParseCharset (el, doc);
1.6 cvs 540: break;
541:
542: case HTML_EL_STYLE_: /* it's a STYLE element */
1.60 ! vatton 543: case HTML_EL_SCRIPT_: /* it's a SCRIPT element */
1.6 cvs 544: case HTML_EL_Preformatted: /* it's a PRE */
545: /* if the last line of the Preformatted is empty, remove it */
546: leaf = XmlLastLeafInElement (el);
547: if (leaf != NULL)
548: {
549: elType = TtaGetElementType (leaf);
550: if (elType.ElTypeNum == HTML_EL_TEXT_UNIT)
551: /* the last leaf is a TEXT element */
552: {
553: length = TtaGetTextLength (leaf);
554: if (length > 0)
555: {
556: TtaGiveSubString (leaf, lastChar, length, 1);
557: if (lastChar[0] == EOL)
558: /* last character is new line, delete it */
559: {
560: if (length == 1)
561: /* empty TEXT element */
562: TtaDeleteTree (leaf, doc);
563: else
564: /* remove the last character */
565: TtaDeleteTextContent (leaf, length, 1, doc);
566: }
567: }
568: }
569: }
570: if (IsParsingCSS ())
571: {
572: text = GetStyleContents (el);
573: if (text)
574: {
1.42 cvs 575: ReadCSSRules (doc, NULL, text,
576: TtaGetElementLineNumber (el), FALSE);
1.6 cvs 577: TtaFreeMemory (text);
578: }
579: SetParsingCSS (FALSE);
580: }
581: /* and continue as if it were a Preformatted or a Script */
582: break;
583:
584: case HTML_EL_Text_Area: /* it's a Text_Area */
585: SetParsingTextArea (FALSE);
586: child = TtaGetFirstChild (el);
587: if (child == NULL)
588: /* it's an empty Text_Area */
589: /* insert a Inserted_Text element in the element */
590: {
591: newElType.ElTypeNum = HTML_EL_Inserted_Text;
592: child = TtaNewTree (doc, newElType, "");
593: TtaInsertFirstChild (&child, el, doc);
594: }
595: else
596: {
597: /* save the text into Default_Value attribute */
598: attrType.AttrSSchema = docSSchema;
599: attrType.AttrTypeNum = HTML_ATTR_Default_Value;
600: if (TtaGetAttribute (el, attrType) == NULL)
601: /* attribute Default_Value is missing */
602: {
603: attr = TtaNewAttribute (attrType);
604: TtaAttachAttribute (el, attr, doc);
605: desc = TtaGetFirstChild (child);
606: length = TtaGetTextLength (desc) + 1;
1.37 cvs 607: text = TtaGetMemory (length);
1.6 cvs 608: TtaGiveTextContent (desc, text, &length, &lang);
609: TtaSetAttributeText (attr, text, el, doc);
610: TtaFreeMemory (text);
611: }
612: }
613: /* insert a Frame element */
614: newElType.ElTypeNum = HTML_EL_Frame;
615: constElem = TtaNewTree (doc, newElType, "");
616: TtaInsertSibling (constElem, child, FALSE, doc);
617: break;
618:
619: case HTML_EL_Radio_Input:
620: case HTML_EL_Checkbox_Input:
621: /* put an attribute Checked if it is missing */
622: attrType.AttrSSchema = docSSchema;
623: attrType.AttrTypeNum = HTML_ATTR_Checked;
624: if (TtaGetAttribute (el, attrType) == NULL)
625: /* attribute Checked is missing */
626: {
627: attr = TtaNewAttribute (attrType);
628: TtaAttachAttribute (el, attr, doc);
629: TtaSetAttributeValue (attr, HTML_ATTR_Checked_VAL_No_, el, doc);
630: }
631: break;
632:
633: case HTML_EL_Option_Menu:
634: /* Check that at least one option has a SELECTED attribute */
635: OnlyOneOptionSelected (el, doc, TRUE);
636: break;
637:
638: case HTML_EL_PICTURE_UNIT:
639: break;
640:
641: case HTML_EL_LINK:
642: CheckCSSLink (el, doc, docSSchema);
643: break;
644:
645: case HTML_EL_Data_cell:
646: case HTML_EL_Heading_cell:
647: /* insert a pseudo paragraph into empty cells */
648: child = TtaGetFirstChild (el);
649: if (child == NULL)
650: {
651: elType.ElTypeNum = HTML_EL_Pseudo_paragraph;
652: child = TtaNewTree (doc, elType, "");
653: if (child != NULL)
654: TtaInsertFirstChild (&child, el, doc);
655: }
656:
657: /* detect whether we're parsing a whole table or just a cell */
658: if (IsWithinTable ())
659: NewCell (el, doc, FALSE);
660: break;
661:
662: case HTML_EL_Table:
663: CheckTable (el, doc);
664: SubWithinTable ();
665: break;
666:
667: case HTML_EL_TITLE:
668: /* show the TITLE in the main window */
669: UpdateTitle (el, doc);
670: break;
1.41 cvs 671:
672: case HTML_EL_rbc:
673: /* an rbc element has been read. Its parent should be a complex_ruby.
674: Change the type of the parent, as simple_ruby are created by
675: default */
676: parent = TtaGetParent (el);
677: if (parent)
678: {
679: newElType = TtaGetElementType (parent);
680: if (newElType.ElSSchema == elType.ElSSchema &&
681: newElType.ElTypeNum == HTML_EL_simple_ruby)
682: ChangeElementType (parent, HTML_EL_complex_ruby);
683: }
684: break;
685:
686: case HTML_EL_rtc1:
687: /* an rtc element has been parsed. If it has already a rtc1 sibling,
688: change its type to rtc2 */
689: prev = el;
690: do
691: {
692: TtaPreviousSibling(&prev);
693: if (prev)
694: {
695: newElType = TtaGetElementType (prev);
696: if (newElType.ElSSchema == elType.ElSSchema &&
697: newElType.ElTypeNum == HTML_EL_rtc1)
698: {
699: ChangeElementType (el, HTML_EL_rtc2);
700: prev = NULL;
701: }
702: }
703: }
704: while (prev);
705: break;
706:
1.6 cvs 707: default:
708: break;
709: }
710: }
1.1 cvs 711:
712: /*----------------------------------------------------------------------
1.30 cvs 713: PutInContent
714: Put the string ChrString in the leaf of current element.
715: ----------------------------------------------------------------------*/
1.39 cvs 716: Element PutInContent (char *ChrString, ParserData *context)
1.30 cvs 717:
718: {
719: Element el, child;
720: ElementType elType;
721: int length;
722:
723: el = NULL;
724: if (context->lastElement != NULL)
725: {
726: /* search first leaf of current element */
727: el = context->lastElement;
728: do
729: {
730: child = TtaGetFirstChild (el);
731: if (child != NULL)
732: el = child;
733: }
734: while (child != NULL);
735: elType = TtaGetElementType (el);
736: length = 0;
737: if (elType.ElTypeNum == 1)
738: length = TtaGetTextLength (el);
739: if (length == 0)
740: TtaSetTextContent (el, ChrString, context->language, context->doc);
741: else
742: TtaAppendTextContent (el, ChrString, context->doc);
743: }
744: return el;
745: }
746:
747: /*----------------------------------------------------------------------
1.51 cvs 748: UnknownXhtmlNameSpace
749: Create an element that belongs to a non-supported namespace
750: ----------------------------------------------------------------------*/
751: void UnknownXhtmlNameSpace (ParserData *context, char* content)
752: {
753: ElementType elType;
754: Element elInv, elText;
755:
756: /* Create a new Invalid_element */
757: elType.ElSSchema = GetXMLSSchema (XHTML_TYPE, context->doc);
758: elType.ElTypeNum = HTML_EL_Unknown_namespace;
759: elInv = TtaNewElement (context->doc, elType);
760: if (elInv != NULL)
761: {
762: XmlSetElemLineNumber (elInv);
763: InsertXmlElement (&elInv);
764: context->lastElementClosed = TRUE;
765: elType.ElTypeNum = HTML_EL_TEXT_UNIT;
766: elText = TtaNewElement (context->doc, elType);
767: XmlSetElemLineNumber (elText);
768: TtaInsertFirstChild (&elText, elInv, context->doc);
769: TtaSetTextContent (elText, content, context->language, context->doc);
770: TtaSetAccessRight (elText, ReadOnly, context->doc);
771: }
772: }
773:
774: /*----------------------------------------------------------------------
1.30 cvs 775: CreateHTMLAttribute
776: create an attribute of type attrType for the element el.
777: ----------------------------------------------------------------------*/
778: void CreateHTMLAttribute (Element el,
779: AttributeType attrType,
1.46 cvs 780: char* text,
1.30 cvs 781: ThotBool isInvalid,
782: Document doc,
783: Attribute *lastAttribute,
784: Element *lastAttrElement)
785:
786: {
787: int attrKind;
788: int length;
1.39 cvs 789: char *buffer;
1.30 cvs 790: Attribute attr, oldAttr;
791:
792: if (attrType.AttrTypeNum != 0)
793: {
794: oldAttr = TtaGetAttribute (el, attrType);
795: if (oldAttr != NULL)
796: /* this attribute already exists */
797: attr = oldAttr;
798: else
799: /* create a new attribute and attach it to the element */
800: {
801: attr = TtaNewAttribute (attrType);
802: TtaAttachAttribute (el, attr, doc);
803: }
804: *lastAttribute = attr;
805: *lastAttrElement = el;
806:
807: TtaGiveAttributeType (attr, &attrType, &attrKind);
808: if (attrKind == 0) /* enumerate */
809: TtaSetAttributeValue (attr, 1, el, doc);
810:
811: /* attribute BORDER without any value (ThotBool attribute) is */
812: /* considered as BORDER=1 */
813: if (attrType.AttrTypeNum == HTML_ATTR_Border)
814: TtaSetAttributeValue (attr, 1, el, doc);
815:
816: if (isInvalid)
817: /* Copy the name of the invalid attribute as the content */
818: /* of the Invalid_attribute attribute. */
819: {
1.37 cvs 820: length = strlen (text) + 2;
1.30 cvs 821: length += TtaGetTextAttributeLength (attr);
1.37 cvs 822: buffer = TtaGetMemory (length + 1);
1.30 cvs 823: TtaGiveTextAttributeValue (attr, buffer, &length);
1.37 cvs 824: strcat (buffer, " ");
825: strcat (buffer, text);
1.30 cvs 826: TtaSetAttributeText (attr, buffer, el, doc);
827: TtaFreeMemory (buffer);
828: }
829: }
830: }
831:
832: /*----------------------------------------------------------------------
833: HTMLTypeAttrValue
834: Value val has been read for the HTML attribute TYPE.
835: Create a child for the current Thot element INPUT accordingly.
836: ----------------------------------------------------------------------*/
1.46 cvs 837: void HTMLTypeAttrValue (char *val,
1.30 cvs 838: Attribute lastAttribute,
839: Element lastAttrElement,
840: ParserData *context)
841:
842: {
843: ElementType elType;
844: Element newChild;
845: AttributeType attrType;
846: Attribute attr;
1.39 cvs 847: char msgBuffer[MaxMsgLength];
1.30 cvs 848: int value;
849: int numberOfLinesRead;
850:
851: value = MapAttrValue (DummyAttribute, val);
852: if (value < 0)
853: {
1.37 cvs 854: if (strlen (val) > MaxMsgLength - 40)
855: val[MaxMsgLength - 40] = EOS;
856: sprintf (msgBuffer, "Unknown attribute value \"type = %s\"", val);
1.42 cvs 857: HTMLParseError (context->doc, msgBuffer);
1.30 cvs 858: attrType.AttrSSchema = TtaGetDocumentSSchema (context->doc);
859: attrType.AttrTypeNum = pHTMLAttributeMapping[0].ThotAttribute;
1.37 cvs 860: sprintf (msgBuffer, "type=%s", val);
1.30 cvs 861: CreateHTMLAttribute (context->lastElement, attrType, msgBuffer, TRUE,
862: context->doc, &lastAttribute, &lastAttrElement);
863: }
864: else
865: {
866: elType = TtaGetElementType (context->lastElement);
867: if (elType.ElTypeNum != HTML_EL_Input)
868: {
1.37 cvs 869: if (strlen (val) > MaxMsgLength - 40)
870: val[MaxMsgLength - 40] = EOS;
871: sprintf (msgBuffer, "Duplicate attribute \"type = %s\"", val);
1.30 cvs 872: }
873: else
874: {
875: elType.ElSSchema = TtaGetDocumentSSchema (context->doc);
876: elType.ElTypeNum = value;
877: newChild = TtaNewTree (context->doc, elType, "");
878: numberOfLinesRead = 0;
879: TtaSetElementLineNumber (newChild, numberOfLinesRead);
880: TtaInsertFirstChild (&newChild, context->lastElement, context->doc);
881: if (value == HTML_EL_PICTURE_UNIT)
882: {
883: /* add the attribute IsInput to input pictures */
884: attrType.AttrSSchema = elType.ElSSchema;
885: attrType.AttrTypeNum = HTML_ATTR_IsInput;
886: attr = TtaNewAttribute (attrType);
887: TtaAttachAttribute (newChild, attr, context->doc);
888: }
889: }
890: }
891: }
892:
893: /*----------------------------------------------------------------------
894: XhtmlTypeAttrValue
895: Value val has been read for the HTML attribute TYPE.
896: Create a child for the current Thot element INPUT accordingly.
897: ----------------------------------------------------------------------*/
1.46 cvs 898: void XhtmlTypeAttrValue (char *val,
1.30 cvs 899: Attribute currentAttribute,
900: Element lastAttrElement,
901: ParserData *context)
902:
903: {
904: ElementType elType;
905: Element newChild;
906: AttributeType attrType;
907: Attribute attr;
1.39 cvs 908: char msgBuffer[MaxMsgLength];
1.30 cvs 909: int value;
910: ThotBool level;
911:
912: attrType.AttrTypeNum = DummyAttribute;
913: MapHTMLAttributeValue (val, attrType, &value);
914: if (value < 0)
915: {
1.37 cvs 916: sprintf (msgBuffer, "Unknown attribute value \"type=%s\"", val);
1.30 cvs 917: XmlParseError (errorParsing, msgBuffer, 0);
1.36 cvs 918: MapHTMLAttribute ("unknown_attr", &attrType, NULL,
1.30 cvs 919: &level, context->doc);
1.37 cvs 920: sprintf (msgBuffer, "type=%s", val);
1.30 cvs 921: CreateHTMLAttribute (context->lastElement, attrType, msgBuffer, TRUE,
922: context->doc, ¤tAttribute, &lastAttrElement);
923: }
924: else
925: {
926: elType = TtaGetElementType (context->lastElement);
927: if (elType.ElTypeNum != HTML_EL_Input)
928: {
1.37 cvs 929: sprintf (msgBuffer, "Duplicate attribute \"type = %s\"", val);
1.30 cvs 930: XmlParseError (errorParsing, msgBuffer, 0);
931: }
932: else
933: {
934: elType.ElTypeNum = value;
935: newChild = TtaNewTree (context->doc, elType, "");
936: XmlSetElemLineNumber (newChild);
937: TtaInsertFirstChild (&newChild, context->lastElement, context->doc);
938: if (value == HTML_EL_PICTURE_UNIT)
939: {
940: /* add the attribute IsInput to input pictures */
941: attrType.AttrSSchema = elType.ElSSchema;
942: attrType.AttrTypeNum = HTML_ATTR_IsInput;
943: attr = TtaNewAttribute (attrType);
944: TtaAttachAttribute (newChild, attr, context->doc);
945: }
946: }
947: }
948: }
949:
950: /*----------------------------------------------------------------------
951: CreateAttrWidthPercentPxl
952: an HTML attribute "width" has been created for a Table of a HR.
953: Create the corresponding attribute IntWidthPercent or IntWidthPxl.
954: oldWidth is -1 or the old image width.
955: ----------------------------------------------------------------------*/
1.58 vatton 956: void CreateAttrWidthPercentPxl (char *buffer, Element el,
957: Document doc, int oldWidth)
1.30 cvs 958: {
959: AttributeType attrTypePxl, attrTypePercent;
960: Attribute attrOld, attrNew;
961: int length, val;
1.39 cvs 962: char msgBuffer[MaxMsgLength];
1.30 cvs 963: ElementType elType;
964: int w, h;
965: ThotBool isImage;
966:
967: elType = TtaGetElementType (el);
968: isImage = (elType.ElTypeNum == HTML_EL_PICTURE_UNIT ||
969: elType.ElTypeNum == HTML_EL_Data_cell ||
970: elType.ElTypeNum == HTML_EL_Heading_cell);
971:
972: /* remove trailing spaces */
1.37 cvs 973: length = strlen (buffer) - 1;
1.30 cvs 974: while (length > 0 && buffer[length] <= SPACE)
975: length--;
976: attrTypePxl.AttrSSchema = TtaGetDocumentSSchema (doc);
977: attrTypePercent.AttrSSchema = TtaGetDocumentSSchema (doc);
978: attrTypePxl.AttrTypeNum = HTML_ATTR_IntWidthPxl;
979: attrTypePercent.AttrTypeNum = HTML_ATTR_IntWidthPercent;
980: /* is the last character a '%' ? */
981: if (buffer[length] == '%')
982: {
983: /* remove IntWidthPxl */
984: attrOld = TtaGetAttribute (el, attrTypePxl);
985: /* update IntWidthPercent */
986: attrNew = TtaGetAttribute (el, attrTypePercent);
987: if (attrNew == NULL)
988: {
989: attrNew = TtaNewAttribute (attrTypePercent);
990: TtaAttachAttribute (el, attrNew, doc);
991: }
992: else if (isImage && oldWidth == -1)
993: {
994: if (attrOld == NULL)
995: oldWidth = TtaGetAttributeValue (attrNew);
996: else
997: oldWidth = TtaGetAttributeValue (attrOld);
998: }
999: }
1000: else
1001: {
1002: /* remove IntWidthPercent */
1003: attrOld = TtaGetAttribute (el, attrTypePercent);
1004: /* update IntWidthPxl */
1005: attrNew = TtaGetAttribute (el, attrTypePxl);
1006: if (attrNew == NULL)
1007: {
1008: attrNew = TtaNewAttribute (attrTypePxl);
1009: TtaAttachAttribute (el, attrNew, doc);
1010: }
1011: else if (isImage && oldWidth == -1)
1012: {
1013: TtaGiveBoxSize (el, doc, 1, UnPixel, &w, &h);
1014: if (attrOld == NULL)
1015: oldWidth = w * TtaGetAttributeValue (attrNew) / 100;
1016: else
1017: oldWidth = w * TtaGetAttributeValue (attrOld) / 100;
1018: }
1019: }
1020:
1021: if (attrOld != NULL)
1022: TtaRemoveAttribute (el, attrOld, doc);
1.43 cvs 1023: if (sscanf (buffer, "%d", &val))
1.30 cvs 1024: TtaSetAttributeValue (attrNew, val, el, doc);
1025: else
1026: /* its not a number. Delete attribute and send an error message */
1027: {
1028: TtaRemoveAttribute (el, attrNew, doc);
1.37 cvs 1029: if (strlen (buffer) > MaxMsgLength - 30)
1.30 cvs 1030: buffer[MaxMsgLength - 30] = EOS;
1.37 cvs 1031: sprintf (msgBuffer, "Invalid attribute value \"%s\"", buffer);
1.42 cvs 1032: HTMLParseError (doc, msgBuffer);
1.30 cvs 1033: }
1034: if (isImage)
1035: UpdateImageMap (el, doc, oldWidth, -1);
1036: }
1037:
1038: /*----------------------------------------------------------------------
1.58 vatton 1039: CreateAttrHeightPercentPxl
1040: an HTML attribute "width" has been created for a Table of a HR.
1041: Create the corresponding attribute IntHeightPercent or IntHeightPxl.
1042: oldHeight is -1 or the old image width.
1043: ----------------------------------------------------------------------*/
1044: void CreateAttrHeightPercentPxl (char *buffer, Element el,
1045: Document doc, int oldHeight)
1046: {
1047: AttributeType attrTypePxl, attrTypePercent;
1048: Attribute attrOld, attrNew;
1049: int length, val;
1050: char msgBuffer[MaxMsgLength];
1051: ElementType elType;
1052: int w, h;
1053: ThotBool isImage;
1054:
1055: elType = TtaGetElementType (el);
1056: isImage = (elType.ElTypeNum == HTML_EL_PICTURE_UNIT ||
1057: elType.ElTypeNum == HTML_EL_Data_cell ||
1058: elType.ElTypeNum == HTML_EL_Heading_cell);
1059:
1060: /* remove trailing spaces */
1061: length = strlen (buffer) - 1;
1062: while (length > 0 && buffer[length] <= SPACE)
1063: length--;
1064: attrTypePxl.AttrSSchema = TtaGetDocumentSSchema (doc);
1065: attrTypePercent.AttrSSchema = TtaGetDocumentSSchema (doc);
1066: attrTypePxl.AttrTypeNum = HTML_ATTR_IntHeightPxl;
1067: attrTypePercent.AttrTypeNum = HTML_ATTR_IntHeightPercent;
1068: /* is the last character a '%' ? */
1069: if (buffer[length] == '%')
1070: {
1071: /* remove IntHeightPxl */
1072: attrOld = TtaGetAttribute (el, attrTypePxl);
1073: /* update IntHeightPercent */
1074: attrNew = TtaGetAttribute (el, attrTypePercent);
1075: if (attrNew == NULL)
1076: {
1077: attrNew = TtaNewAttribute (attrTypePercent);
1078: TtaAttachAttribute (el, attrNew, doc);
1079: }
1080: else if (isImage && oldHeight == -1)
1081: {
1082: if (attrOld == NULL)
1083: oldHeight = TtaGetAttributeValue (attrNew);
1084: else
1085: oldHeight = TtaGetAttributeValue (attrOld);
1086: }
1087: }
1088: else
1089: {
1090: /* remove IntHeightPercent */
1091: attrOld = TtaGetAttribute (el, attrTypePercent);
1092: /* update IntHeightPxl */
1093: attrNew = TtaGetAttribute (el, attrTypePxl);
1094: if (attrNew == NULL)
1095: {
1096: attrNew = TtaNewAttribute (attrTypePxl);
1097: TtaAttachAttribute (el, attrNew, doc);
1098: }
1099: else if (isImage && oldHeight == -1)
1100: {
1101: TtaGiveBoxSize (el, doc, 1, UnPixel, &w, &h);
1102: if (attrOld == NULL)
1103: oldHeight = w * TtaGetAttributeValue (attrNew) / 100;
1104: else
1105: oldHeight = w * TtaGetAttributeValue (attrOld) / 100;
1106: }
1107: }
1108:
1109: if (attrOld != NULL)
1110: TtaRemoveAttribute (el, attrOld, doc);
1111: if (sscanf (buffer, "%d", &val))
1112: TtaSetAttributeValue (attrNew, val, el, doc);
1113: else
1114: /* its not a number. Delete attribute and send an error message */
1115: {
1116: TtaRemoveAttribute (el, attrNew, doc);
1117: if (strlen (buffer) > MaxMsgLength - 30)
1118: buffer[MaxMsgLength - 30] = EOS;
1119: sprintf (msgBuffer, "Invalid attribute value \"%s\"", buffer);
1120: HTMLParseError (doc, msgBuffer);
1121: }
1122: if (isImage)
1123: UpdateImageMap (el, doc, oldHeight, -1);
1124: }
1125:
1126: /*----------------------------------------------------------------------
1.30 cvs 1127: CreateAttrIntSize
1128: an HTML attribute "size" has been created for a Font element.
1129: Create the corresponding internal attribute.
1130: ----------------------------------------------------------------------*/
1.46 cvs 1131: void CreateAttrIntSize (char *buffer, Element el, Document doc)
1.30 cvs 1132:
1133: {
1134: AttributeType attrType;
1135: int val, ind, factor, delta;
1136: Attribute attr;
1.37 cvs 1137: char msgBuffer[MaxMsgLength];
1.30 cvs 1138:
1139: /* is the first character a '+' or a '-' ? */
1140: ind = 0;
1141: factor = 1;
1142: delta = 0;
1143: if (buffer[0] == '+')
1144: {
1145: attrType.AttrTypeNum = HTML_ATTR_IntSizeIncr;
1146: ind++;
1147: factor = 2;
1148: }
1149: else if (buffer[0] == '-')
1150: {
1151: attrType.AttrTypeNum = HTML_ATTR_IntSizeDecr;
1152: ind++;
1153: factor = 2;
1154: }
1155: else
1156: {
1157: attrType.AttrTypeNum = HTML_ATTR_IntSizeRel;
1158: delta = 1;
1159: }
1160: attrType.AttrSSchema = TtaGetDocumentSSchema (doc);
1161: attr = TtaGetAttribute (el, attrType);
1.43 cvs 1162: if (sscanf (&buffer[ind], "%d", &val))
1.30 cvs 1163: {
1164: val = val * factor + delta;
1165: if (attr == NULL)
1166: {
1167: /* this attribute doesn't exist, create it */
1168: attr = TtaNewAttribute (attrType);
1169: TtaAttachAttribute (el, attr, doc);
1170: }
1171: TtaSetAttributeValue (attr, val, el, doc);
1172: }
1173: else
1174: /* its not a number. Delete attribute and send an error message */
1175: {
1176: if (attr)
1177: TtaRemoveAttribute (el, attr, doc);
1.37 cvs 1178: if (strlen (buffer) > MaxMsgLength - 30)
1.30 cvs 1179: buffer[MaxMsgLength - 30] = EOS;
1.37 cvs 1180: sprintf (msgBuffer, "Invalid attribute value \"%s\"", buffer);
1.42 cvs 1181: HTMLParseError (doc, msgBuffer);
1.30 cvs 1182: }
1183: }
1184: /*----------------------------------------------------------------------
1185: EndOfHTMLAttributeValue
1186: Filling of an HTML attribute value
1187: ----------------------------------------------------------------------*/
1.48 vatton 1188: void EndOfHTMLAttributeValue (char *attrValue,
1189: AttributeMapping *lastMappedAttr,
1190: Attribute currentAttribute,
1191: Element lastAttrElement,
1192: ThotBool UnknownAttr,
1193: ParserData *context,
1194: ThotBool isXML)
1.30 cvs 1195: {
1.48 vatton 1196: AttributeType attrType, attrType1;
1197: Attribute attr;
1198: ElementType elType;
1199: Element child, root;
1200: Language lang;
1201: char translation;
1202: char shape;
1203: char *buffer;
1204: char *attrName;
1205: char msgBuffer[MaxMsgLength];
1206: int val;
1207: int length;
1208: int attrKind;
1209: ThotBool done = FALSE;
1.30 cvs 1210:
1.48 vatton 1211: /* treatments of some particular HTML attributes */
1212: if (!strcmp (lastMappedAttr->XMLattribute, "style"))
1213: {
1214: TtaSetAttributeText (currentAttribute, attrValue,
1215: lastAttrElement, context->doc);
1216: ParseHTMLSpecificStyle (context->lastElement, attrValue,
1217: context->doc, 1, FALSE);
1218: done = TRUE;
1219: }
1220: else
1221: {
1222: if (!strcmp (lastMappedAttr->XMLattribute, "link"))
1223: HTMLSetAlinkColor (context->doc, attrValue);
1224: else if (!strcmp (lastMappedAttr->XMLattribute, "alink"))
1225: HTMLSetAactiveColor (context->doc, attrValue);
1226: else if (!strcmp (lastMappedAttr->XMLattribute, "vlink"))
1227: HTMLSetAvisitedColor (context->doc, attrValue);
1228: }
1.30 cvs 1229:
1.48 vatton 1230: if (!done)
1231: {
1232: val = 0;
1233: translation = lastMappedAttr->AttrOrContent;
1234: switch (translation)
1235: {
1236: case 'C': /* Content */
1237: child = PutInContent (attrValue, context);
1238: if (child != NULL)
1239: TtaAppendTextContent (child, "\" ", context->doc);
1240: break;
1241:
1242: case 'A':
1243: if (currentAttribute != NULL)
1244: {
1245: TtaGiveAttributeType (currentAttribute, &attrType, &attrKind);
1246: switch (attrKind)
1247: {
1248: case 0: /* enumerate */
1249: if (isXML)
1250: MapHTMLAttributeValue (attrValue, attrType, &val);
1251: else
1252: val = MapAttrValue (lastMappedAttr->ThotAttribute,
1.40 cvs 1253: attrValue);
1.48 vatton 1254: if (val < 0)
1255: {
1256: TtaGiveAttributeType (currentAttribute,
1257: &attrType, &attrKind);
1258: attrName = TtaGetAttributeName (attrType);
1259: sprintf (msgBuffer,
1.51 cvs 1260: "Invalid attribute value \"%s = %s\"",
1.48 vatton 1261: attrName, attrValue);
1262: if (isXML)
1263: XmlParseError (errorParsing, msgBuffer, 0);
1264: else
1.51 cvs 1265: {
1266: HTMLParseError (context->doc, msgBuffer);
1.48 vatton 1267: /* remove the attribute and replace it by an */
1.51 cvs 1268: /* Invalid_attribute (not for XHTML) */
1269: TtaRemoveAttribute (lastAttrElement,
1270: currentAttribute, context->doc);
1.48 vatton 1271: attrType.AttrSSchema =
1272: TtaGetDocumentSSchema (context->doc);
1273: attrType.AttrTypeNum =
1274: pHTMLAttributeMapping[0].ThotAttribute;
1.51 cvs 1275: sprintf (msgBuffer, "%s=%s", attrName, attrValue);
1276: CreateHTMLAttribute (lastAttrElement, attrType,
1277: msgBuffer, TRUE, context->doc,
1278: ¤tAttribute,
1279: &lastAttrElement);
1.48 vatton 1280: }
1281: }
1282: else
1283: TtaSetAttributeValue (currentAttribute, val,
1284: lastAttrElement, context->doc);
1285: break;
1286: case 1: /* integer */
1287: if (attrType.AttrTypeNum == HTML_ATTR_Border &&
1288: !strcasecmp (attrValue, "border"))
1289: {
1290: /* border="border" for a table */
1291: val = 1;
1292: TtaSetAttributeValue (currentAttribute, val,
1.30 cvs 1293: lastAttrElement, context->doc);
1.48 vatton 1294: }
1295: else if (sscanf (attrValue, "%d", &val))
1296: TtaSetAttributeValue (currentAttribute, val,
1297: lastAttrElement, context->doc);
1298: else
1299: {
1300: TtaRemoveAttribute (lastAttrElement, currentAttribute,
1301: context->doc);
1302: sprintf (msgBuffer,
1303: "Unknown attribute value \"%s\"",
1304: attrValue);
1305: if (isXML)
1306: XmlParseError (errorParsing, msgBuffer, 0);
1307: else
1308: HTMLParseError (context->doc, msgBuffer);
1309: }
1310: break;
1311: case 2: /* text */
1312: if (!UnknownAttr)
1313: {
1314: TtaSetAttributeText (currentAttribute, attrValue,
1315: lastAttrElement, context->doc);
1.55 cvs 1316: if (attrType.AttrTypeNum == HTML_ATTR_Language)
1.48 vatton 1317: {
1318: /* it's a LANG attribute value */
1319: lang = TtaGetLanguageIdFromName (attrValue);
1320: if (lang == 0)
1321: {
1322: sprintf (msgBuffer,
1323: "warning - unsupported language: %s",
1324: attrValue);
1325: if (isXML)
1326: XmlParseError (errorParsing, msgBuffer, 0);
1327: else
1328: HTMLParseError (context->doc, msgBuffer);
1329: }
1330: else
1331: {
1332: /* change current language */
1333: context->language = lang;
1334: if (isXML)
1335: SetLanguagInXmlStack (lang);
1336: else
1337: SetLanguagInHTMLStack (lang);
1338: }
1339: root = TtaGetRootElement (context->doc);
1340: if (lastAttrElement == root)
1341: /* it's a LANG attribute on the root element */
1342: /* set the RealLang attribute */
1343: {
1344: attrType1.AttrSSchema = TtaGetDocumentSSchema (context->doc);
1345: attrType1.AttrTypeNum = HTML_ATTR_RealLang;
1346: /* this attribute could be already present,
1347: (lang and xml:lang attributes) */
1348: if (!TtaGetAttribute (lastAttrElement,
1349: attrType1))
1350: /* it's not present. Add it */
1351: {
1352: attr = TtaNewAttribute (attrType1);
1353: TtaAttachAttribute (lastAttrElement,
1354: attr, context->doc);
1355: TtaSetAttributeValue (attr,
1356: HTML_ATTR_RealLang_VAL_Yes_,
1357: lastAttrElement,
1358: context->doc);
1359: }
1360: }
1361: }
1362: else if (attrType.AttrTypeNum == HTML_ATTR_accesskey)
1363: TtaAddAccessKey (context->doc, (unsigned int)attrValue[0],
1364: lastAttrElement);
1365: }
1366: else
1367: {
1.51 cvs 1368: /* this is the content of an invalid attribute */
1369: /* append it to the current Invalid_attribute */
1370: if (!isXML)
1371: {
1372: length = strlen (attrValue) + 2;
1373: length += TtaGetTextAttributeLength (currentAttribute);
1374: buffer = TtaGetMemory (length + 1);
1375: TtaGiveTextAttributeValue (currentAttribute,
1376: buffer, &length);
1377: strcat (buffer, "=");
1378: strcat (buffer, attrValue);
1379: TtaSetAttributeText (currentAttribute, buffer,
1380: lastAttrElement, context->doc);
1381: TtaFreeMemory (buffer);
1382: }
1.48 vatton 1383: }
1384: break;
1385: case 3: /* reference */
1386: break;
1387: }
1388: }
1389: break;
1390:
1391: case SPACE:
1392: if (isXML)
1393: XhtmlTypeAttrValue (attrValue, currentAttribute,
1.30 cvs 1394: lastAttrElement, context);
1.48 vatton 1395: else
1396: HTMLTypeAttrValue (attrValue, currentAttribute,
1397: lastAttrElement, context);
1398: break;
1399:
1.30 cvs 1400: default:
1401: break;
1.48 vatton 1402: }
1.30 cvs 1403:
1404: if (lastMappedAttr->ThotAttribute == HTML_ATTR_Width__)
1.48 vatton 1405: /* HTML attribute "width" for a table or a hr */
1406: /* create the corresponding attribute IntWidthPercent or */
1407: /* IntWidthPxl */
1408: CreateAttrWidthPercentPxl (attrValue, lastAttrElement, context->doc, -1);
1.58 vatton 1409: else if (lastMappedAttr->ThotAttribute == HTML_ATTR_Height_)
1410: /* HTML attribute "width" for a table or a hr */
1411: /* create the corresponding attribute IntHeightPercent or */
1412: /* IntHeightPxl */
1413: CreateAttrHeightPercentPxl (attrValue, lastAttrElement, context->doc, -1);
1.48 vatton 1414: else if (!strcmp (lastMappedAttr->XMLattribute, "size"))
1415: {
1416: TtaGiveAttributeType (currentAttribute, &attrType, &attrKind);
1417: if (attrType.AttrTypeNum == HTML_ATTR_Font_size)
1418: CreateAttrIntSize (attrValue, lastAttrElement, context->doc);
1419: }
1420: else if (!strcmp (lastMappedAttr->XMLattribute, "shape"))
1421: {
1422: child = TtaGetFirstChild (lastAttrElement);
1423: if (child != NULL)
1424: {
1425: switch (val)
1426: {
1427: case HTML_ATTR_shape_VAL_rectangle:
1428: shape = 'R';
1429: break;
1430: case HTML_ATTR_shape_VAL_circle:
1431: shape = 'a';
1432: break;
1433: case HTML_ATTR_shape_VAL_polygon:
1434: shape = 'p';
1435: break;
1436: default:
1437: shape = SPACE;
1438: break;
1439: }
1440: TtaSetGraphicsShape (child, shape, context->doc);
1441: }
1442: }
1443: else if (!strcmp (lastMappedAttr->XMLattribute, "value"))
1444: {
1445: elType = TtaGetElementType (lastAttrElement);
1446: if (elType.ElTypeNum == HTML_EL_Text_Input ||
1447: elType.ElTypeNum == HTML_EL_Password_Input ||
1448: elType.ElTypeNum == HTML_EL_File_Input ||
1449: elType.ElTypeNum == HTML_EL_Input)
1450: /* create a Default_Value attribute with the same content */
1451: {
1452: attrType1.AttrSSchema = attrType.AttrSSchema;
1453: attrType1.AttrTypeNum = HTML_ATTR_Default_Value;
1454: attr = TtaNewAttribute (attrType1);
1455: TtaAttachAttribute (lastAttrElement, attr, context->doc);
1456: TtaSetAttributeText (attr, attrValue,
1457: lastAttrElement, context->doc);
1458: }
1459: }
1.30 cvs 1460: else
1.48 vatton 1461: {
1462: /* Some HTML attributes are equivalent to a CSS property: */
1463: /* background -> background */
1464: /* bgcolor -> background */
1465: /* text -> color */
1466: /* color -> color */
1467: if (!strcmp (lastMappedAttr->XMLattribute, "background"))
1468: {
1469: if (strlen (attrValue) > MaxMsgLength - 30)
1470: attrValue[MaxMsgLength - 30] = EOS;
1471: HTMLSetBackgroundImage (context->doc,
1472: context->lastElement, STYLE_REPEAT, attrValue);
1473: }
1474: else if (!strcmp (lastMappedAttr->XMLattribute, "bgcolor"))
1475: HTMLSetBackgroundColor (context->doc,
1476: context->lastElement, attrValue);
1477: else if (!strcmp (lastMappedAttr->XMLattribute, "text") ||
1478: !strcmp (lastMappedAttr->XMLattribute, "color"))
1479: HTMLSetForegroundColor (context->doc,
1480: context->lastElement, attrValue);
1481: }
1482: }
1.30 cvs 1483: }
1484:
1485: /*----------------------------------------------------------------------
1.16 cvs 1486: MapHTMLAttributeValue
1.2 cvs 1487: Search in the Attribute Value Mapping Table the entry for the attribute
1488: ThotAtt and its value AttrVal. Returns the corresponding Thot value.
1.1 cvs 1489: ----------------------------------------------------------------------*/
1.39 cvs 1490: void MapHTMLAttributeValue (char *AttrVal,
1.30 cvs 1491: AttributeType attrType,
1492: int *value)
1.1 cvs 1493: {
1.45 cvs 1494: int i;
1.2 cvs 1495:
1.45 cvs 1496: *value = 0;
1497: i = 0;
1498: while (XhtmlAttrValueMappingTable[i].ThotAttr != attrType.AttrTypeNum &&
1499: XhtmlAttrValueMappingTable[i].ThotAttr != 0)
1500: i++;
1501: if (XhtmlAttrValueMappingTable[i].ThotAttr == attrType.AttrTypeNum)
1502: do
1503: if (!strcmp (XhtmlAttrValueMappingTable[i].XMLattrValue, AttrVal))
1504: *value = XhtmlAttrValueMappingTable[i].ThotAttrValue;
1505: else
1506: i++;
1507: while (*value <= 0 &&
1508: XhtmlAttrValueMappingTable[i].ThotAttr == attrType.AttrTypeNum);
1.1 cvs 1509: }
Webmaster