From ff283804e0dc61f2e6e7ad3de072f354df74effe Mon Sep 17 00:00:00 2001 From: Hiltjo Posthuma Date: Sun, 20 Mar 2016 13:07:53 +0100 Subject: code cleanup: put table of parsed tagid at top (near reverse table) --- sfeed.c | 64 ++++++++++++++++++++++++++++++++++------------------------------ 1 file changed, 34 insertions(+), 30 deletions(-) diff --git a/sfeed.c b/sfeed.c index 7b5d08a..421bab5 100644 --- a/sfeed.c +++ b/sfeed.c @@ -110,7 +110,38 @@ static void xml_handler_start_el(XMLParser *, const char *, size_t); static void xml_handler_start_el_parsed(XMLParser *, const char *, size_t, int); -/* map tag type to field */ +/* map tag name to tagid */ +/* RSS, alphabetical order */ +static FeedTag rsstags[] = { + { STRP("author"), RSSTagAuthor }, + { STRP("content:encoded"), RSSTagContentEncoded }, + { STRP("dc:creator"), RSSTagDccreator }, + { STRP("dc:date"), RSSTagDcdate }, + { STRP("description"), RSSTagDescription }, + { STRP("guid"), RSSTagGuid }, + { STRP("link"), RSSTagLink }, + { STRP("media:description"), RSSTagMediaDescription }, + { STRP("pubdate"), RSSTagPubdate }, + { STRP("title"), RSSTagTitle }, + { NULL, 0, -1 } +}; +/* Atom, alphabetical order */ +static FeedTag atomtags[] = { + /* */ + { STRP("author"), AtomTagAuthor }, + { STRP("content"), AtomTagContent }, + { STRP("id"), AtomTagId }, + /* */ + { STRP("link"), AtomTagLink }, + { STRP("media:description"), AtomTagMediaDescription }, + { STRP("published"), AtomTagPublished }, + { STRP("summary"), AtomTagSummary }, + { STRP("title"), AtomTagTitle }, + { STRP("updated"), AtomTagUpdated }, + { NULL, 0, -1 } +}; + +/* map tagid type to RSS/Atom field */ static int fieldmap[TagLast] = { /* RSS */ [RSSTagDcdate] = FeedFieldTime, @@ -141,39 +172,12 @@ static const char *baseurl = ""; static FeedContext ctx; static XMLParser parser; /* XML parser state */ -/* Unique id for parsed tag. */ +/* Unique tagid for parsed tag name. */ static enum TagId gettag(enum FeedType feedtype, const char *name, size_t namelen) { - /* RSS, alphabetical order */ - static FeedTag rsstags[] = { - { STRP("author"), RSSTagAuthor }, - { STRP("content:encoded"), RSSTagContentEncoded }, - { STRP("dc:creator"), RSSTagDccreator }, - { STRP("dc:date"), RSSTagDcdate }, - { STRP("description"), RSSTagDescription }, - { STRP("guid"), RSSTagGuid }, - { STRP("link"), RSSTagLink }, - { STRP("media:description"), RSSTagMediaDescription }, - { STRP("pubdate"), RSSTagPubdate }, - { STRP("title"), RSSTagTitle }, - { NULL, 0, -1 } - }; - /* Atom, alphabetical order */ - static FeedTag atomtags[] = { - { STRP("author"), AtomTagAuthor }, - { STRP("content"), AtomTagContent }, - { STRP("id"), AtomTagId }, - { STRP("link"), AtomTagLink }, - { STRP("media:description"), AtomTagMediaDescription }, - { STRP("published"), AtomTagPublished }, - { STRP("summary"), AtomTagSummary }, - { STRP("title"), AtomTagTitle }, - { STRP("updated"), AtomTagUpdated }, - { NULL, 0, -1 } - }; const FeedTag *tags; - int i; + size_t i; /* optimization: these are always non-matching */ if (namelen < 2 || namelen > 17) -- cgit v1.2.3