changeset 496:8f420eb7c20d

strdup() id and style strings
author Johannes Hofmann <Johannes.Hofmann@gmx.de>
date Thu, 23 Oct 2008 20:30:38 +0200
parents 7224de9c34b7
children 96713a0f5d8b
files src/css.cc src/html.cc
diffstat 2 files changed, 32 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/css.cc	Thu Oct 23 20:03:33 2008 +0200
+++ b/src/css.cc	Thu Oct 23 20:30:38 2008 +0200
@@ -9,6 +9,7 @@
  * (at your option) any later version.
  */
 
+#include <stdio.h>
 #include "css.hh"
 
 StyleEngine::StyleEngine () {
@@ -16,3 +17,13 @@
 
 StyleEngine::~StyleEngine () {
 }
+
+void
+StyleEngine::startElement (int tag, const char *id, const char *style) {
+   fprintf(stderr, "===> START %d %s %s\n", tag, id, style);
+}
+
+void
+StyleEngine::endElement (int tag) {
+   fprintf(stderr, "===> END %d\n", tag);
+}
--- a/src/html.cc	Thu Oct 23 20:03:33 2008 +0200
+++ b/src/html.cc	Thu Oct 23 20:30:38 2008 +0200
@@ -3445,6 +3445,7 @@
 {
    int ci, ni;           /* current and new tag indexes */
    const char *attrbuf;
+   char *id = NULL, *style = NULL;
    char *start = tag + 1; /* discard the '<' */
    int IsCloseTag = (*start == '/');
 
@@ -3497,12 +3498,14 @@
           * spec states in Sec. 7.5.2 that anchor ids are case-sensitive.
           * So we don't do it and hope for better specs in the future ...
           */
-         Html_check_name_val(html, attrbuf, "id");
+         if (attrbuf)
+            id = strdup (attrbuf);
+         Html_check_name_val(html, id, "id");
          /* We compare the "id" value with the url-decoded "name" value */
-         if (!html->NameVal || strcmp(html->NameVal, attrbuf)) {
+         if (!html->NameVal || strcmp(html->NameVal, id)) {
             if (html->NameVal)
                BUG_MSG("'id' and 'name' attribute of <a> tag differ\n");
-            Html_add_anchor(html, attrbuf);
+            Html_add_anchor(html, id);
          }
       }
 
@@ -3512,6 +3515,20 @@
          html->NameVal = NULL;
       }
 
+      if (tagsize >= 11) {       /* length of "<t style=i>" */
+          attrbuf = Html_get_attr2(html, tag, tagsize, "style",
+                                   HTML_LeftTrim | HTML_RightTrim);
+          if (attrbuf)
+            style = strdup (attrbuf);
+      }
+
+      html->styleEngine->startElement (ni, id, style);
+
+      if (id)
+         free (id);
+      if (style)
+         free (style);
+
       /* let the parser know this was an open tag */
       html->PrevWasOpenTag = true;
 
@@ -3534,6 +3551,7 @@
             (size_t)tagsize == strlen(Tags[ni].name) + 3))) {   /*  <x/>   */
    
          Tags[ni].close (html, ni);
+         html->styleEngine->endElement (ni);
          /* This was a close tag */
          html->PrevWasOpenTag = false;
          html->ReqTagClose = false;