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