]> sjero.net Git - wget/blobdiff - src/html-parse.c
[svn] Various IPv6 fixes.
[wget] / src / html-parse.c
index f9a5b0f5379129fcf7fe3e54baf65dee1a48293e..4ad331d52458852843a1c1759650146ed31d7926 100644 (file)
@@ -83,6 +83,10 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
 
 #include <config.h>
 
+#ifdef STANDALONE
+# define I_REALLY_WANT_CTYPE_MACROS
+#endif
+
 #include <stdio.h>
 #include <stdlib.h>
 #ifdef HAVE_STRING_H
@@ -99,12 +103,24 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
 # define xmalloc malloc
 # define xrealloc realloc
 # define xfree free
+
+# define ISSPACE(x) isspace (x)
+# define ISDIGIT(x) isdigit (x)
+# define ISALPHA(x) isalpha (x)
+# define ISALNUM(x) isalnum (x)
+# define TOLOWER(x) tolower (x)
 #endif /* STANDALONE */
 
-/* Pool support.  For efficiency, map_html_tags() stores temporary
-   string data to a single stack-allocated pool.  If the pool proves
-   too small, additional memory is allocated/resized with
-   malloc()/realloc().  */
+/* Pool support.  A pool is a resizable chunk of memory.  It is first
+   allocated on the stack, and moved to the heap if it needs to be
+   larger than originally expected.  map_html_tags() uses it to store
+   the zero-terminated names and values of tags and attributes.
+
+   Thus taginfo->name, and attr->name and attr->value for each
+   attribute, do not point into separately allocated areas, but into
+   different parts of the pool, separated only by terminating zeros.
+   This ensures minimum amount of allocation and, for most tags, no
+   allocation because the entire pool is kept on the stack.  */
 
 struct pool {
   char *contents;              /* pointer to the contents. */
@@ -432,7 +448,9 @@ advance_declaration (const char *beg, const char *end)
            state = AC_S_DEFAULT;
          break;
        case AC_S_QUOTE1:
-         assert (ch == '\'' || ch == '"');
+         /* We must use 0x22 because broken assert macros choke on
+            '"' and '\"'.  */
+         assert (ch == '\'' || ch == 0x22);
          quote_char = ch;      /* cheating -- I really don't feel like
                                   introducing more different states for
                                   different quote characters. */
@@ -638,6 +656,19 @@ map_html_tags (const char *text, int size,
 
        SKIP_WS (p);
 
+       if (*p == '/')
+         {
+           /* A slash at this point means the tag is about to be
+              closed.  This is legal in XML and has been popularized
+              in HTML via XHTML.  */
+           /* <foo a=b c=d /> */
+           /*              ^  */
+           ADVANCE (p);
+           SKIP_WS (p);
+           if (*p != '>')
+             goto backout_tag;
+         }
+
        /* Check for end of tag definition. */
        if (*p == '>')
          break;
@@ -654,7 +685,7 @@ map_html_tags (const char *text, int size,
 
        /* Establish bounds of attribute value. */
        SKIP_WS (p);
-       if (NAME_CHAR_P (*p) || *p == '>')
+       if (NAME_CHAR_P (*p) || *p == '/' || *p == '>')
          {
            /* Minimized attribute syntax allows `=' to be omitted.
                For example, <UL COMPACT> is a valid shorthand for <UL
@@ -735,7 +766,7 @@ map_html_tags (const char *text, int size,
            /* We skipped the whitespace and found something that is
               neither `=' nor the beginning of the next attribute's
               name.  Back out.  */
-           goto backout_tag;   /* <foo bar /... */
+           goto backout_tag;   /* <foo bar [... */
                                /*          ^    */
          }