4f462928e0f3fb1aea9a6209d9f3d4c91b2b01f6 chinhli Wed Nov 13 10:21:56 2013 -0800 Added new function findNextMatchingTag() to htmlPage.c struct htmlTag *findNextMatchingTag(struct htmlTag *list, char *name); /* Return first tag in list that is of type name or NULL if not found. * */ diff --git src/lib/htmlPage.c src/lib/htmlPage.c index 9bcafe1..74f9cf9 100644 --- src/lib/htmlPage.c +++ src/lib/htmlPage.c @@ -252,30 +252,42 @@ } static int findLineNumber(char *start, char *pos) /* Figure out line number of given position relative to start. */ { char *s; int line = 1; for (s = start; s <= pos; ++s) { if (s[0] == '\n') ++line; } return line; } +struct htmlTag *findNextMatchingTag(struct htmlTag *list, char *name) +/* Return first tag in list that is of type name or NULL if not found*/ +{ +struct htmlTag *tag; +for (tag = list; tag != NULL; tag = tag->next) + { + if (sameWord(name, tag->name)) + return tag; + } +return NULL; +} + static void tagVaWarn(struct htmlPage *page, struct htmlTag *tag, char *format, va_list args) /* Print warning message and some context of tag. */ { char context[80]; strncpy(context, tag->start, sizeof(context)); context[sizeof(context)-1] = 0; warn("Error near line %d of %s:\n %s", findLineNumber(page->htmlText, tag->start), page->url, context); vaWarn(format, args); } static void tagWarn(struct htmlPage *page, struct htmlTag *tag, char *format, ...) /* Print warning message and some context of tag. */ {