#include <stdio.h>
#include <stdlib.h>
-#ifdef HAVE_STRING_H
-# include <string.h>
-#else
-# include <strings.h>
-#endif
+#include <string.h>
#include <assert.h>
#include "wget.h"
if (ga_newsize != (sizevar)) \
{ \
if (resized) \
- basevar = (type *)xrealloc (basevar, ga_newsize * sizeof (type)); \
+ basevar = xrealloc (basevar, ga_newsize * sizeof (type)); \
else \
{ \
void *ga_new = xmalloc (ga_newsize * sizeof (type)); \
#undef ENT1
#undef ENT2
#undef ENT3
+#undef FITS
+#undef SKIP_SEMI
enum {
AP_DOWNCASE = 1,
the ASCII range when copying the string.
* AP_TRIM_BLANKS -- ignore blanks at the beginning and at the end
- of text. */
+ of text, as well as embedded newlines. */
static void
convert_and_copy (struct pool *pool, const char *beg, const char *end, int flags)
{
int old_tail = pool->tail;
- int size;
- /* First, skip blanks if required. We must do this before entities
- are processed, so that blanks can still be inserted as, for
- instance, ` '. */
+ /* Skip blanks if required. We must do this before entities are
+ processed, so that blanks can still be inserted as, for instance,
+ ` '. */
if (flags & AP_TRIM_BLANKS)
{
while (beg < end && ISSPACE (*beg))
while (end > beg && ISSPACE (end[-1]))
--end;
}
- size = end - beg;
if (flags & AP_DECODE_ENTITIES)
{
never lengthen it. */
const char *from = beg;
char *to;
+ int squash_newlines = flags & AP_TRIM_BLANKS;
POOL_GROW (pool, end - beg);
to = pool->contents + pool->tail;
while (from < end)
{
- if (*from != '&')
- *to++ = *from++;
- else
+ if (*from == '&')
{
int entity = decode_entity (&from, end);
if (entity != -1)
else
*to++ = *from++;
}
+ else if ((*from == '\n' || *from == '\r') && squash_newlines)
+ ++from;
+ else
+ *to++ = *from++;
}
/* Verify that we haven't exceeded the original size. (It
shouldn't happen, hence the assert.) */
MAPFUN will be called with two arguments: pointer to an initialized
struct taginfo, and MAPARG.
- ALLOWED_TAG_NAMES should be a NULL-terminated array of tag names to
- be processed by this function. If it is NULL, all the tags are
- allowed. The same goes for attributes and ALLOWED_ATTRIBUTE_NAMES.
+ ALLOWED_TAGS and ALLOWED_ATTRIBUTES are hash tables the keys of
+ which are the tags and attribute names that this function should
+ use. If ALLOWED_TAGS is NULL, all tags are processed; if
+ ALLOWED_ATTRIBUTES is NULL, all attributes are returned.
(Obviously, the caller can filter out unwanted tags and attributes
just as well, but this is just an optimization designed to avoid
- unnecessary copying for tags/attributes which the caller doesn't
- want to know about. These lists are searched linearly; therefore,
- if you're interested in a large number of tags or attributes, you'd
- better set these to NULL and filter them out yourself with a
- hashing process most appropriate for your application.) */
+ unnecessary copying of tags/attributes which the caller doesn't
+ care about.) */
void
map_html_tags (const char *text, int size,
taginfo.attrs = pairs;
taginfo.start_position = tag_start_position;
taginfo.end_position = p + 1;
- /* Ta-dam! */
- (*mapfun) (&taginfo, maparg);
+ mapfun (&taginfo, maparg);
ADVANCE (p);
}
goto look_for_tag;
int main ()
{
int size = 256;
- char *x = (char *)xmalloc (size);
+ char *x = xmalloc (size);
int length = 0;
int read_count;
int tag_counter = 0;
{
length += read_count;
size <<= 1;
- x = (char *)xrealloc (x, size);
+ x = xrealloc (x, size);
}
map_html_tags (x, length, test_mapper, &tag_counter, 0, NULL, NULL);