1 /* HTML parser for Wget.
2 Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
3 2007 Free Software Foundation, Inc.
5 This file is part of GNU Wget.
7 GNU Wget is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or (at
10 your option) any later version.
12 GNU Wget is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with Wget. If not, see <http://www.gnu.org/licenses/>.
20 In addition, as a special exception, the Free Software Foundation
21 gives permission to link the code of its release of Wget with the
22 OpenSSL project's "OpenSSL" library (or with modified versions of it
23 that use the same license as the "OpenSSL" library), and distribute
24 the linked executables. You must obey the GNU General Public License
25 in all respects for all of the code used other than "OpenSSL". If you
26 modify this file, you may extend this exception to your version of the
27 file, but you are not obligated to do so. If you do not wish to do
28 so, delete this exception statement from your version. */
30 /* The only entry point to this module is map_html_tags(), which see. */
34 - Allow hooks for callers to process contents outside tags. This
35 is needed to implement handling <style> and <script>. The
36 taginfo structure already carries the information about where the
37 tags are, but this is not enough, because one would also want to
38 skip the comments. (The funny thing is that for <style> and
39 <script> you *don't* want to skip comments!)
41 - Create a test suite for regression testing. */
45 This is the third HTML parser written for Wget. The first one was
46 written some time during the Geturl 1.0 beta cycle, and was very
47 inefficient and buggy. It also contained some very complex code to
48 remember a list of parser states, because it was supposed to be
51 The second HTML parser was written for Wget 1.4 (the first version
52 by the name `Wget'), and was a complete rewrite. Although the new
53 parser behaved much better and made no claims of reentrancy, it
54 still shared many of the fundamental flaws of the old version -- it
55 only regarded HTML in terms tag-attribute pairs, where the
56 attribute's value was a URL to be returned. Any other property of
57 HTML, such as <base href=...>, or strange way to specify a URL,
58 such as <meta http-equiv=Refresh content="0; URL=..."> had to be
59 crudely hacked in -- and the caller had to be aware of these hacks.
60 Like its predecessor, this parser did not support HTML comments.
62 After Wget 1.5.1 was released, I set out to write a third HTML
63 parser. The objectives of the new parser were to: (1) provide a
64 clean way to analyze HTML lexically, (2) separate interpretation of
65 the markup from the parsing process, (3) be as correct as possible,
66 e.g. correctly skipping comments and other SGML declarations, (4)
67 understand the most common errors in markup and skip them or be
68 relaxed towrds them, and (5) be reasonably efficient (no regexps,
69 minimum copying and minimum or no heap allocation).
71 I believe this parser meets all of the above goals. It is
72 reasonably well structured, and could be relatively easily
73 separated from Wget and used elsewhere. While some of its
74 intrinsic properties limit its value as a general-purpose HTML
75 parser, I believe that, with minimum modifications, it could serve
78 Due to time and other constraints, this parser was not integrated
79 into Wget until the version 1.7. */
83 The single entry point of this parser is map_html_tags(), which
84 works by calling a function you specify for each tag. The function
85 gets called with the pointer to a structure describing the tag and
88 /* To test as standalone, compile with `-DSTANDALONE -I.'. You'll
89 still need Wget headers to compile. */
94 # define I_REALLY_WANT_CTYPE_MACROS
102 #include "html-parse.h"
108 # define xmalloc malloc
109 # define xrealloc realloc
120 # define c_isspace(x) isspace (x)
121 # define c_isdigit(x) isdigit (x)
122 # define c_isxdigit(x) isxdigit (x)
123 # define c_isalpha(x) isalpha (x)
124 # define c_isalnum(x) isalnum (x)
125 # define c_tolower(x) tolower (x)
126 # define c_toupper(x) toupper (x)
132 hash_table_get (const struct hash_table *ht, void *ptr)
136 #else /* not STANDALONE */
140 /* Pool support. A pool is a resizable chunk of memory. It is first
141 allocated on the stack, and moved to the heap if it needs to be
142 larger than originally expected. map_html_tags() uses it to store
143 the zero-terminated names and values of tags and attributes.
145 Thus taginfo->name, and attr->name and attr->value for each
146 attribute, do not point into separately allocated areas, but into
147 different parts of the pool, separated only by terminating zeros.
148 This ensures minimum amount of allocation and, for most tags, no
149 allocation because the entire pool is kept on the stack. */
152 char *contents; /* pointer to the contents. */
153 int size; /* size of the pool. */
154 int tail; /* next available position index. */
155 bool resized; /* whether the pool has been resized
158 char *orig_contents; /* original pool contents, usually
159 stack-allocated. used by POOL_FREE
160 to restore the pool to the initial
165 /* Initialize the pool to hold INITIAL_SIZE bytes of storage. */
167 #define POOL_INIT(p, initial_storage, initial_size) do { \
168 struct pool *P = (p); \
169 P->contents = (initial_storage); \
170 P->size = (initial_size); \
172 P->resized = false; \
173 P->orig_contents = P->contents; \
174 P->orig_size = P->size; \
177 /* Grow the pool to accomodate at least SIZE new bytes. If the pool
178 already has room to accomodate SIZE bytes of data, this is a no-op. */
180 #define POOL_GROW(p, increase) \
181 GROW_ARRAY ((p)->contents, (p)->size, (p)->tail + (increase), \
184 /* Append text in the range [beg, end) to POOL. No zero-termination
187 #define POOL_APPEND(p, beg, end) do { \
188 const char *PA_beg = (beg); \
189 int PA_size = (end) - PA_beg; \
190 POOL_GROW (p, PA_size); \
191 memcpy ((p)->contents + (p)->tail, PA_beg, PA_size); \
192 (p)->tail += PA_size; \
195 /* Append one character to the pool. Can be used to zero-terminate
198 #define POOL_APPEND_CHR(p, ch) do { \
199 char PAC_char = (ch); \
201 (p)->contents[(p)->tail++] = PAC_char; \
204 /* Forget old pool contents. The allocated memory is not freed. */
205 #define POOL_REWIND(p) (p)->tail = 0
207 /* Free heap-allocated memory for contents of POOL. This calls
208 xfree() if the memory was allocated through malloc. It also
209 restores `contents' and `size' to their original, pre-malloc
210 values. That way after POOL_FREE, the pool is fully usable, just
211 as if it were freshly initialized with POOL_INIT. */
213 #define POOL_FREE(p) do { \
214 struct pool *P = p; \
216 xfree (P->contents); \
217 P->contents = P->orig_contents; \
218 P->size = P->orig_size; \
220 P->resized = false; \
223 /* Used for small stack-allocated memory chunks that might grow. Like
224 DO_REALLOC, this macro grows BASEVAR as necessary to take
225 NEEDED_SIZE items of TYPE.
227 The difference is that on the first resize, it will use
228 malloc+memcpy rather than realloc. That way you can stack-allocate
229 the initial chunk, and only resort to heap allocation if you
230 stumble upon large data.
232 After the first resize, subsequent ones are performed with realloc,
233 just like DO_REALLOC. */
235 #define GROW_ARRAY(basevar, sizevar, needed_size, resized, type) do { \
236 long ga_needed_size = (needed_size); \
237 long ga_newsize = (sizevar); \
238 while (ga_newsize < ga_needed_size) \
240 if (ga_newsize != (sizevar)) \
243 basevar = xrealloc (basevar, ga_newsize * sizeof (type)); \
246 void *ga_new = xmalloc (ga_newsize * sizeof (type)); \
247 memcpy (ga_new, basevar, (sizevar) * sizeof (type)); \
248 (basevar) = ga_new; \
251 (sizevar) = ga_newsize; \
255 /* Test whether n+1-sized entity name fits in P. We don't support
256 IE-style non-terminated entities, e.g. "<foo" -> "<foo".
257 However, "<foo" will work, as will "<!foo", "<", etc. In
258 other words an entity needs to be terminated by either a
259 non-alphanumeric or the end of string. */
260 #define FITS(p, n) (p + n == end || (p + n < end && !c_isalnum (p[n])))
262 /* Macros that test entity names by returning true if P is followed by
263 the specified characters. */
264 #define ENT1(p, c0) (FITS (p, 1) && p[0] == c0)
265 #define ENT2(p, c0, c1) (FITS (p, 2) && p[0] == c0 && p[1] == c1)
266 #define ENT3(p, c0, c1, c2) (FITS (p, 3) && p[0]==c0 && p[1]==c1 && p[2]==c2)
268 /* Increment P by INC chars. If P lands at a semicolon, increment it
269 past the semicolon. This ensures that e.g. "<foo" is converted
270 to "<foo", but "<,foo" to "<,foo". */
271 #define SKIP_SEMI(p, inc) (p += inc, p < end && *p == ';' ? ++p : p)
273 /* Decode the HTML character entity at *PTR, considering END to be end
274 of buffer. It is assumed that the "&" character that marks the
275 beginning of the entity has been seen at *PTR-1. If a recognized
276 ASCII entity is seen, it is returned, and *PTR is moved to the end
277 of the entity. Otherwise, -1 is returned and *PTR left unmodified.
279 The recognized entities are: <, >, &, &apos, and ". */
282 decode_entity (const char **ptr, const char *end)
284 const char *p = *ptr;
293 /* Process numeric entities "&#DDD;" and "&#xHH;". */
298 for (++p; value < 256 && p < end && c_isxdigit (*p); p++, digits++)
299 value = (value << 4) + XDIGIT_TO_NUM (*p);
301 for (; value < 256 && p < end && c_isdigit (*p); p++, digits++)
302 value = (value * 10) + (*p - '0');
305 /* Don't interpret 128+ codes and NUL because we cannot
306 portably reinserted them into HTML. */
307 if (!value || (value & ~0x7f))
309 *ptr = SKIP_SEMI (p, 0);
312 /* Process named ASCII entities. */
315 value = '>', *ptr = SKIP_SEMI (p, 1);
319 value = '<', *ptr = SKIP_SEMI (p, 1);
322 if (ENT2 (p, 'm', 'p'))
323 value = '&', *ptr = SKIP_SEMI (p, 2);
324 else if (ENT3 (p, 'p', 'o', 's'))
325 /* handle &apos for the sake of the XML/XHTML crowd. */
326 value = '\'', *ptr = SKIP_SEMI (p, 3);
329 if (ENT3 (p, 'u', 'o', 't'))
330 value = '\"', *ptr = SKIP_SEMI (p, 3);
343 AP_DECODE_ENTITIES = 2,
347 /* Copy the text in the range [BEG, END) to POOL, optionally
348 performing operations specified by FLAGS. FLAGS may be any
349 combination of AP_DOWNCASE, AP_DECODE_ENTITIES and AP_TRIM_BLANKS
350 with the following meaning:
352 * AP_DOWNCASE -- downcase all the letters;
354 * AP_DECODE_ENTITIES -- decode the named and numeric entities in
355 the ASCII range when copying the string.
357 * AP_TRIM_BLANKS -- ignore blanks at the beginning and at the end
358 of text, as well as embedded newlines. */
361 convert_and_copy (struct pool *pool, const char *beg, const char *end, int flags)
363 int old_tail = pool->tail;
365 /* Skip blanks if required. We must do this before entities are
366 processed, so that blanks can still be inserted as, for instance,
368 if (flags & AP_TRIM_BLANKS)
370 while (beg < end && c_isspace (*beg))
372 while (end > beg && c_isspace (end[-1]))
376 if (flags & AP_DECODE_ENTITIES)
378 /* Grow the pool, then copy the text to the pool character by
379 character, processing the encountered entities as we go
382 It's safe (and necessary) to grow the pool in advance because
383 processing the entities can only *shorten* the string, it can
384 never lengthen it. */
385 const char *from = beg;
387 bool squash_newlines = !!(flags & AP_TRIM_BLANKS);
389 POOL_GROW (pool, end - beg);
390 to = pool->contents + pool->tail;
396 int entity = decode_entity (&from, end);
402 else if ((*from == '\n' || *from == '\r') && squash_newlines)
407 /* Verify that we haven't exceeded the original size. (It
408 shouldn't happen, hence the assert.) */
409 assert (to - (pool->contents + pool->tail) <= end - beg);
411 /* Make POOL's tail point to the position following the string
413 pool->tail = to - pool->contents;
414 POOL_APPEND_CHR (pool, '\0');
418 /* Just copy the text to the pool. */
419 POOL_APPEND (pool, beg, end);
420 POOL_APPEND_CHR (pool, '\0');
423 if (flags & AP_DOWNCASE)
425 char *p = pool->contents + old_tail;
431 /* Originally we used to adhere to rfc 1866 here, and allowed only
432 letters, digits, periods, and hyphens as names (of tags or
433 attributes). However, this broke too many pages which used
434 proprietary or strange attributes, e.g. <img src="a.gif"
435 v:shapes="whatever">.
437 So now we allow any character except:
439 * 8-bit and control chars
440 * characters that clearly cannot be part of name:
443 This only affects attribute and tag names; attribute values allow
444 an even greater variety of characters. */
446 #define NAME_CHAR_P(x) ((x) > 32 && (x) < 127 \
447 && (x) != '=' && (x) != '>' && (x) != '/')
450 static int comment_backout_count;
453 /* Advance over an SGML declaration, such as <!DOCTYPE ...>. In
454 strict comments mode, this is used for skipping over comments as
457 To recap: any SGML declaration may have comments associated with
459 <!MY-DECL -- isn't this fun? -- foo bar>
461 An HTML comment is merely an empty declaration (<!>) with a comment
463 <!-- some stuff here -->
465 Several comments may be embedded in one comment declaration:
466 <!-- have -- -- fun -->
468 Whitespace is allowed between and after the comments, but not
469 before the first comment. Additionally, this function attempts to
470 handle double quotes in SGML declarations correctly. */
473 advance_declaration (const char *beg, const char *end)
476 char quote_char = '\0'; /* shut up, gcc! */
499 /* It looked like a good idea to write this as a state machine, but
502 while (state != AC_S_DONE && state != AC_S_BACKOUT)
505 state = AC_S_BACKOUT;
515 state = AC_S_DEFAULT;
518 state = AC_S_BACKOUT;
540 if (NAME_CHAR_P (ch))
541 state = AC_S_DCLNAME;
543 state = AC_S_BACKOUT;
550 else if (NAME_CHAR_P (ch))
553 state = AC_S_DEFAULT;
556 /* We must use 0x22 because broken assert macros choke on
558 assert (ch == '\'' || ch == 0x22);
559 quote_char = ch; /* cheating -- I really don't feel like
560 introducing more different states for
561 different quote characters. */
563 state = AC_S_IN_QUOTE;
566 if (ch == quote_char)
572 assert (ch == quote_char);
574 state = AC_S_DEFAULT;
586 state = AC_S_COMMENT;
589 state = AC_S_BACKOUT;
613 state = AC_S_DEFAULT;
616 state = AC_S_COMMENT;
623 if (state == AC_S_BACKOUT)
626 ++comment_backout_count;
633 /* Find the first occurrence of the substring "-->" in [BEG, END) and
634 return the pointer to the character after the substring. If the
635 substring is not found, return NULL. */
638 find_comment_end (const char *beg, const char *end)
640 /* Open-coded Boyer-Moore search for "-->". Examine the third char;
641 if it's not '>' or '-', advance by three characters. Otherwise,
642 look at the preceding characters and try to find a match. */
644 const char *p = beg - 1;
646 while ((p += 3) < end)
650 if (p[-1] == '-' && p[-2] == '-')
658 if (++p == end) return NULL;
661 case '>': return p + 1;
662 case '-': goto at_dash_dash;
667 if ((p += 2) >= end) return NULL;
682 /* Return true if the string containing of characters inside [b, e) is
683 present in hash table HT. */
686 name_allowed (const struct hash_table *ht, const char *b, const char *e)
691 BOUNDED_TO_ALLOCA (b, e, copy);
692 return hash_table_get (ht, copy) != NULL;
695 /* Advance P (a char pointer), with the explicit intent of being able
696 to read the next character. If this is not possible, go to finish. */
698 #define ADVANCE(p) do { \
704 /* Skip whitespace, if any. */
706 #define SKIP_WS(p) do { \
707 while (c_isspace (*p)) { \
712 /* Skip non-whitespace, if any. */
714 #define SKIP_NON_WS(p) do { \
715 while (!c_isspace (*p)) { \
721 static int tag_backout_count;
724 /* Map MAPFUN over HTML tags in TEXT, which is SIZE characters long.
725 MAPFUN will be called with two arguments: pointer to an initialized
726 struct taginfo, and MAPARG.
728 ALLOWED_TAGS and ALLOWED_ATTRIBUTES are hash tables the keys of
729 which are the tags and attribute names that this function should
730 use. If ALLOWED_TAGS is NULL, all tags are processed; if
731 ALLOWED_ATTRIBUTES is NULL, all attributes are returned.
733 (Obviously, the caller can filter out unwanted tags and attributes
734 just as well, but this is just an optimization designed to avoid
735 unnecessary copying of tags/attributes which the caller doesn't
739 map_html_tags (const char *text, int size,
740 void (*mapfun) (struct taginfo *, void *), void *maparg,
742 const struct hash_table *allowed_tags,
743 const struct hash_table *allowed_attributes)
745 /* storage for strings passed to MAPFUN callback; if 256 bytes is
746 too little, POOL_APPEND allocates more with malloc. */
747 char pool_initial_storage[256];
750 const char *p = text;
751 const char *end = text + size;
753 struct attr_pair attr_pair_initial_storage[8];
754 int attr_pair_size = countof (attr_pair_initial_storage);
755 bool attr_pair_resized = false;
756 struct attr_pair *pairs = attr_pair_initial_storage;
761 POOL_INIT (&pool, pool_initial_storage, countof (pool_initial_storage));
765 const char *tag_name_begin, *tag_name_end;
766 const char *tag_start_position;
767 bool uninteresting_tag;
775 /* Find beginning of tag. We use memchr() instead of the usual
776 looping with ADVANCE() for speed. */
777 p = memchr (p, '<', end - p);
781 tag_start_position = p;
784 /* Establish the type of the tag (start-tag, end-tag or
788 if (!(flags & MHT_STRICT_COMMENTS)
789 && p < end + 3 && p[1] == '-' && p[2] == '-')
791 /* If strict comments are not enforced and if we know
792 we're looking at a comment, simply look for the
793 terminating "-->". Non-strict is the default because
794 it works in other browsers and most HTML writers can't
795 be bothered with getting the comments right. */
796 const char *comment_end = find_comment_end (p + 3, end);
802 /* Either in strict comment mode or looking at a non-empty
803 declaration. Real declarations are much less likely to
804 be misused the way comments are, so advance over them
805 properly regardless of strictness. */
806 p = advance_declaration (p, end);
818 while (NAME_CHAR_P (*p))
820 if (p == tag_name_begin)
824 if (end_tag && *p != '>')
827 if (!name_allowed (allowed_tags, tag_name_begin, tag_name_end))
828 /* We can't just say "goto look_for_tag" here because we need
829 the loop below to properly advance over the tag's attributes. */
830 uninteresting_tag = true;
833 uninteresting_tag = false;
834 convert_and_copy (&pool, tag_name_begin, tag_name_end, AP_DOWNCASE);
837 /* Find the attributes. */
840 const char *attr_name_begin, *attr_name_end;
841 const char *attr_value_begin, *attr_value_end;
842 const char *attr_raw_value_begin, *attr_raw_value_end;
843 int operation = AP_DOWNCASE; /* stupid compiler. */
849 /* A slash at this point means the tag is about to be
850 closed. This is legal in XML and has been popularized
851 in HTML via XHTML. */
852 /* <foo a=b c=d /> */
860 /* Check for end of tag definition. */
864 /* Establish bounds of attribute name. */
865 attr_name_begin = p; /* <foo bar ...> */
867 while (NAME_CHAR_P (*p))
869 attr_name_end = p; /* <foo bar ...> */
871 if (attr_name_begin == attr_name_end)
874 /* Establish bounds of attribute value. */
876 if (NAME_CHAR_P (*p) || *p == '/' || *p == '>')
878 /* Minimized attribute syntax allows `=' to be omitted.
879 For example, <UL COMPACT> is a valid shorthand for <UL
880 COMPACT="compact">. Even if such attributes are not
881 useful to Wget, we need to support them, so that the
882 tags containing them can be parsed correctly. */
883 attr_raw_value_begin = attr_value_begin = attr_name_begin;
884 attr_raw_value_end = attr_value_end = attr_name_end;
890 if (*p == '\"' || *p == '\'')
892 bool newline_seen = false;
893 char quote_char = *p;
894 attr_raw_value_begin = p;
896 attr_value_begin = p; /* <foo bar="baz"> */
898 while (*p != quote_char)
900 if (!newline_seen && *p == '\n')
902 /* If a newline is seen within the quotes, it
903 is most likely that someone forgot to close
904 the quote. In that case, we back out to
905 the value beginning, and terminate the tag
906 at either `>' or the delimiter, whichever
907 comes first. Such a tag terminated at `>'
909 p = attr_value_begin;
913 else if (newline_seen && *p == '>')
917 attr_value_end = p; /* <foo bar="baz"> */
919 if (*p == quote_char)
923 attr_raw_value_end = p; /* <foo bar="baz"> */
925 operation = AP_DECODE_ENTITIES;
926 if (flags & MHT_TRIM_VALUES)
927 operation |= AP_TRIM_BLANKS;
931 attr_value_begin = p; /* <foo bar=baz> */
933 /* According to SGML, a name token should consist only
934 of alphanumerics, . and -. However, this is often
935 violated by, for instance, `%' in `width=75%'.
936 We'll be liberal and allow just about anything as
937 an attribute value. */
938 while (!c_isspace (*p) && *p != '>')
940 attr_value_end = p; /* <foo bar=baz qux=quix> */
942 if (attr_value_begin == attr_value_end)
946 attr_raw_value_begin = attr_value_begin;
947 attr_raw_value_end = attr_value_end;
948 operation = AP_DECODE_ENTITIES;
953 /* We skipped the whitespace and found something that is
954 neither `=' nor the beginning of the next attribute's
956 goto backout_tag; /* <foo bar [... */
960 /* If we're not interested in the tag, don't bother with any
961 of the attributes. */
962 if (uninteresting_tag)
965 /* If we aren't interested in the attribute, skip it. We
966 cannot do this test any sooner, because our text pointer
967 needs to correctly advance over the attribute. */
968 if (!name_allowed (allowed_attributes, attr_name_begin, attr_name_end))
971 GROW_ARRAY (pairs, attr_pair_size, nattrs + 1, attr_pair_resized,
974 pairs[nattrs].name_pool_index = pool.tail;
975 convert_and_copy (&pool, attr_name_begin, attr_name_end, AP_DOWNCASE);
977 pairs[nattrs].value_pool_index = pool.tail;
978 convert_and_copy (&pool, attr_value_begin, attr_value_end, operation);
979 pairs[nattrs].value_raw_beginning = attr_raw_value_begin;
980 pairs[nattrs].value_raw_size = (attr_raw_value_end
981 - attr_raw_value_begin);
985 if (uninteresting_tag)
991 /* By now, we have a valid tag with a name and zero or more
992 attributes. Fill in the data and call the mapper function. */
995 struct taginfo taginfo;
997 taginfo.name = pool.contents;
998 taginfo.end_tag_p = end_tag;
999 taginfo.nattrs = nattrs;
1000 /* We fill in the char pointers only now, when pool can no
1001 longer get realloc'ed. If we did that above, we could get
1002 hosed by reallocation. Obviously, after this point, the pool
1003 may no longer be grown. */
1004 for (i = 0; i < nattrs; i++)
1006 pairs[i].name = pool.contents + pairs[i].name_pool_index;
1007 pairs[i].value = pool.contents + pairs[i].value_pool_index;
1009 taginfo.attrs = pairs;
1010 taginfo.start_position = tag_start_position;
1011 taginfo.end_position = p + 1;
1012 mapfun (&taginfo, maparg);
1019 ++tag_backout_count;
1021 /* The tag wasn't really a tag. Treat its contents as ordinary
1023 p = tag_start_position + 1;
1029 if (attr_pair_resized)
1039 test_mapper (struct taginfo *taginfo, void *arg)
1043 printf ("%s%s", taginfo->end_tag_p ? "/" : "", taginfo->name);
1044 for (i = 0; i < taginfo->nattrs; i++)
1045 printf (" %s=%s", taginfo->attrs[i].name, taginfo->attrs[i].value);
1053 char *x = xmalloc (size);
1056 int tag_counter = 0;
1058 while ((read_count = fread (x + length, 1, size - length, stdin)))
1060 length += read_count;
1062 x = xrealloc (x, size);
1065 map_html_tags (x, length, test_mapper, &tag_counter, 0, NULL, NULL);
1066 printf ("TAGS: %d\n", tag_counter);
1067 printf ("Tag backouts: %d\n", tag_backout_count);
1068 printf ("Comment backouts: %d\n", comment_backout_count);
1071 #endif /* STANDALONE */