diff options
-rw-r--r-- | sfeed.c | 169 | ||||
-rw-r--r-- | sfeed_frames.c | 74 | ||||
-rw-r--r-- | sfeed_html.c | 40 | ||||
-rw-r--r-- | sfeed_opml_import.c | 12 | ||||
-rw-r--r-- | sfeed_plain.c | 14 | ||||
-rw-r--r-- | sfeed_web.c | 32 | ||||
-rw-r--r-- | sfeed_xmlenc.c | 8 | ||||
-rw-r--r-- | util.c | 34 | ||||
-rw-r--r-- | xml.c | 228 |
9 files changed, 306 insertions, 305 deletions
@@ -135,23 +135,23 @@ gettag(int feedtype, const char *name, size_t namelen) int i, n; /* optimization: these are always non-matching */ - if(namelen < 2 || namelen > 15) + if (namelen < 2 || namelen > 15) return TagUnknown; - if(feedtype == FeedTypeRSS) { - for(i = 0; rsstag[i].name; i++) { - if(!(n = strncasecmp(rsstag[i].name, name, rsstag[i].namelen))) + if (feedtype == FeedTypeRSS) { + for (i = 0; rsstag[i].name; i++) { + if (!(n = strncasecmp(rsstag[i].name, name, rsstag[i].namelen))) return rsstag[i].id; /* optimization: it's sorted so nothing after it matches. */ - if(n > 0) + if (n > 0) return TagUnknown; } - } else if(feedtype == FeedTypeAtom) { - for(i = 0; atomtag[i].name; i++) { - if(!(n = strncasecmp(atomtag[i].name, name, atomtag[i].namelen))) + } else if (feedtype == FeedTypeAtom) { + for (i = 0; atomtag[i].name; i++) { + if (!(n = strncasecmp(atomtag[i].name, name, atomtag[i].namelen))) return atomtag[i].id; /* optimization: it's sorted so nothing after it matches. */ - if(n > 0) + if (n > 0) return TagUnknown; } } @@ -162,7 +162,7 @@ gettag(int feedtype, const char *name, size_t namelen) static void string_clear(String *s) { - if(s->data) + if (s->data) s->data[0] = '\0'; s->len = 0; } @@ -170,7 +170,7 @@ string_clear(String *s) static void string_buffer_init(String *s, size_t len) { - if(!(s->data = malloc(len))) + if (!(s->data = malloc(len))) err(1, "malloc"); s->bufsiz = len; string_clear(s); @@ -182,9 +182,9 @@ string_buffer_realloc(String *s, size_t newlen) char *p; size_t alloclen; - for(alloclen = 16; alloclen <= newlen; alloclen *= 2) + for (alloclen = 16; alloclen <= newlen; alloclen *= 2) ; - if(!(p = realloc(s->data, alloclen))) + if (!(p = realloc(s->data, alloclen))) err(1, "realloc"); s->bufsiz = alloclen; s->data = p; @@ -193,11 +193,11 @@ string_buffer_realloc(String *s, size_t newlen) static void string_append(String *s, const char *data, size_t len) { - if(!len || *data == '\0') + if (!len || *data == '\0') return; /* check if allocation is necesary, don't shrink buffer should be more than bufsiz ofcourse */ - if(s->len + len >= s->bufsiz) + if (s->len + len >= s->bufsiz) string_buffer_realloc(s, s->len + len + 1); memcpy(s->data + s->len, data, len); s->len += len; @@ -229,25 +229,25 @@ gettimetz(const char *s, char *buf, size_t bufsiz, int *tzoffset) char c = '+'; size_t i; - for(; *s && !isalpha(*s) && *s != '-' && *s != '+'; s++) + for (; *s && !isalpha(*s) && *s != '-' && *s != '+'; s++) ; - if(!*s || *s == 'Z' || *s == 'z') + if (!*s || *s == 'Z' || *s == 'z') goto time_ok; /* look until some common timezone delimiters are found */ - for(i = 0; s[i] && isalpha((int)s[i]); i++) + for (i = 0; s[i] && isalpha((int)s[i]); i++) ; /* copy tz name */ - if(i >= sizeof(tzbuf)) + if (i >= sizeof(tzbuf)) i = sizeof(tzbuf) - 1; memcpy(tzbuf, s, i); tzbuf[i] = '\0'; - if((sscanf(s, "%c%02d:%02d", &c, &tzhour, &tzmin)) == 3) { + if ((sscanf(s, "%c%02d:%02d", &c, &tzhour, &tzmin)) == 3) { ; - } else if(sscanf(s, "%c%02d%02d", &c, &tzhour, &tzmin) == 3) { + } else if (sscanf(s, "%c%02d%02d", &c, &tzhour, &tzmin) == 3) { ; - } else if(sscanf(s, "%c%d", &c, &tzhour) == 2) { + } else if (sscanf(s, "%c%d", &c, &tzhour) == 2) { tzmin = 0; } else { c = '+'; @@ -270,9 +270,9 @@ gettimetz(const char *s, char *buf, size_t bufsiz, int *tzoffset) time_ok: r = snprintf(buf, bufsiz, "%s%c%02d%02d", tz, c, tzhour, tzmin); - if(r < 0 || (size_t)r >= bufsiz) + if (r < 0 || (size_t)r >= bufsiz) return -1; /* truncation or error */ - if(tzoffset) + if (tzoffset) *tzoffset = (tzhour * 3600) + (tzmin * 60) * (c == '-' ? -1 : 1); return 0; } @@ -294,23 +294,23 @@ parsetime(const char *s, char *buf, size_t bufsiz, time_t *tp) int tzoffset, r; memset(&tm, 0, sizeof(tm)); - for(i = 0; formats[i]; i++) { - if(!(p = strptime(s, formats[i], &tm))) + for (i = 0; formats[i]; i++) { + if (!(p = strptime(s, formats[i], &tm))) continue; tm.tm_isdst = -1; /* don't use DST */ - if((t = timegm(&tm)) == -1) /* error */ + if ((t = timegm(&tm)) == -1) /* error */ return -1; - if(gettimetz(p, tz, sizeof(tz), &tzoffset) != -1) + if (gettimetz(p, tz, sizeof(tz), &tzoffset) != -1) t -= tzoffset; - if(buf) { + if (buf) { r = snprintf(buf, bufsiz, "%04d-%02d-%02d %02d:%02d:%02d %s", tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec, tz); - if(r == -1 || (size_t)r >= bufsiz) + if (r == -1 || (size_t)r >= bufsiz) return -1; /* truncation */ } - if(tp) + if (tp) *tp = t; return 0; } @@ -327,16 +327,16 @@ string_print(String *s) p = trimstart(s->data); e = trimend(p); - for(; *p && p != e; p++) { + for (; *p && p != e; p++) { /* isspace(c) && c != ' '. */ - if(((unsigned)*p - '\t') < 5) { + if (((unsigned)*p - '\t') < 5) { switch(*p) { case '\n': fputs("\\n", stdout); break; case '\\': fputs("\\\\", stdout); break; case '\t': fputs("\\t", stdout); break; default: break; /* ignore other whitespace chars */ } - } else if(!iscntrl((int)*p)) { /* ignore control chars */ + } else if (!iscntrl((int)*p)) { /* ignore control chars */ putchar(*p); } } @@ -353,10 +353,10 @@ printfields(void) * if the parsed time is invalid */ r = parsetime((&ctx.item.timestamp)->data, timebuf, sizeof(timebuf), &t); - if(r != -1) + if (r != -1) printf("%ld", (long)t); putchar(FieldSeparator); - if(r != -1) + if (r != -1) fputs(timebuf, stdout); putchar(FieldSeparator); string_print(&ctx.item.title); @@ -384,7 +384,8 @@ istag(const char *name, size_t len, const char *name2, size_t len2) } static int -isattr(const char *name, size_t len, const char *name2, size_t len2) { +isattr(const char *name, size_t len, const char *name2, size_t len2) +{ return (len == len2 && !strcasecmp(name, name2)); } @@ -393,10 +394,10 @@ isattr(const char *name, size_t len, const char *name2, size_t len2) { static void xml_handler_data(XMLParser *p, const char *s, size_t len) { - if(ctx.field) { + if (ctx.field) { /* add only data from <name> inside <author> tag * or any other non-<author> tag */ - if(ctx.tagid != AtomTagAuthor || !strcmp(p->tag, "name")) + if (ctx.tagid != AtomTagAuthor || !strcmp(p->tag, "name")) string_append(ctx.field, s, len); } } @@ -406,7 +407,7 @@ xml_handler_cdata(XMLParser *p, const char *s, size_t len) { (void)p; - if(ctx.field) + if (ctx.field) string_append(ctx.field, s, len); } @@ -417,11 +418,11 @@ xml_handler_attr_start(XMLParser *p, const char *tag, size_t taglen, (void)tag; (void)taglen; - if(!ISINCONTENT(ctx)) + if (!ISINCONTENT(ctx)) return; /* handles transforming inline XML to data */ - if(!ctx.attrcount) + if (!ctx.attrcount) xml_handler_data(p, " ", 1); ctx.attrcount++; xml_handler_data(p, name, namelen); @@ -437,7 +438,7 @@ xml_handler_attr_end(struct xmlparser *p, const char *tag, size_t taglen, (void)name; (void)namelen; - if(!ISINCONTENT(ctx)) + if (!ISINCONTENT(ctx)) return; /* handles transforming inline XML to data */ @@ -452,10 +453,10 @@ xml_handler_start_element_parsed(XMLParser *p, const char *tag, size_t taglen, (void)tag; (void)taglen; - if(!ISINCONTENT(ctx)) + if (!ISINCONTENT(ctx)) return; - if(isshort) + if (isshort) xml_handler_data(p, "/>", 2); else xml_handler_data(p, ">", 1); @@ -470,14 +471,14 @@ xml_handler_attr(XMLParser *p, const char *tag, size_t taglen, (void)taglen; /* handles transforming inline XML to data */ - if(ISINCONTENT(ctx)) { + if (ISINCONTENT(ctx)) { xml_handler_data(p, value, valuelen); return; } - if(ctx.item.feedtype == FeedTypeAtom) { - if(ISCONTENTTAG(ctx)) { - if(isattr(name, namelen, STRP("type")) && + if (ctx.item.feedtype == FeedTypeAtom) { + if (ISCONTENTTAG(ctx)) { + if (isattr(name, namelen, STRP("type")) && (isattr(value, valuelen, STRP("xhtml")) || isattr(value, valuelen, STRP("text/xhtml")) || isattr(value, valuelen, STRP("html")) || @@ -490,7 +491,7 @@ xml_handler_attr(XMLParser *p, const char *tag, size_t taglen, p->xmlattrend = xml_handler_attr_end; p->xmltagstartparsed = xml_handler_start_element_parsed; } - } else if(ctx.tagid == AtomTagLink && + } else if (ctx.tagid == AtomTagLink && isattr(name, namelen, STRP("href"))) { /* link href attribute */ @@ -504,11 +505,11 @@ xml_handler_start_element(XMLParser *p, const char *name, size_t namelen) { /* starts with div, handle as XML, don't convert entities * (set handler to NULL) */ - if(ISCONTENTTAG(ctx) && ctx.item.feedtype == FeedTypeAtom && + if (ISCONTENTTAG(ctx) && ctx.item.feedtype == FeedTypeAtom && namelen == STRSIZ("div") && !strncmp(name, STRP("div"))) { p->xmldataentity = NULL; } - if(ctx.iscontent) { + if (ctx.iscontent) { ctx.attrcount = 0; ctx.iscontenttag = 0; xml_handler_data(p, "<", 1); @@ -517,14 +518,14 @@ xml_handler_start_element(XMLParser *p, const char *name, size_t namelen) } /* start of RSS or Atom item / entry */ - if(ctx.item.feedtype == FeedTypeNone) { - if(istag(name, namelen, STRP("entry"))) { + if (ctx.item.feedtype == FeedTypeNone) { + if (istag(name, namelen, STRP("entry"))) { /* Atom */ ctx.item.feedtype = FeedTypeAtom; /* default content type for Atom */ ctx.item.contenttype = ContentTypePlain; ctx.field = NULL; /* XXX: optimization */ - } else if(istag(name, namelen, STRP("item"))) { + } else if (istag(name, namelen, STRP("item"))) { /* RSS */ ctx.item.feedtype = FeedTypeRSS; /* default content type for RSS */ @@ -535,58 +536,58 @@ xml_handler_start_element(XMLParser *p, const char *name, size_t namelen) } /* tag already set: return */ - if(ctx.tag[0] != '\0') + if (ctx.tag[0] != '\0') return; /* in item */ strlcpy(ctx.tag, name, sizeof(ctx.tag)); /* NOTE: truncation ignored */ ctx.taglen = namelen; ctx.tagid = gettag(ctx.item.feedtype, ctx.tag, ctx.taglen); - if(ctx.tagid == TagUnknown) + if (ctx.tagid == TagUnknown) ctx.field = NULL; - if(ctx.item.feedtype == FeedTypeRSS) { - if(ctx.tagid == RSSTagPubdate || ctx.tagid == RSSTagDcdate) + if (ctx.item.feedtype == FeedTypeRSS) { + if (ctx.tagid == RSSTagPubdate || ctx.tagid == RSSTagDcdate) ctx.field = &ctx.item.timestamp; - else if(ctx.tagid == RSSTagTitle) + else if (ctx.tagid == RSSTagTitle) ctx.field = &ctx.item.title; - else if(ctx.tagid == RSSTagLink) + else if (ctx.tagid == RSSTagLink) ctx.field = &ctx.item.link; - else if(ctx.tagid == RSSTagDescription || + else if (ctx.tagid == RSSTagDescription || ctx.tagid == RSSTagContentencoded) { /* ignore, prefer content:encoded over description */ - if(ctx.tagid != RSSTagDescription || !ctx.item.content.len) { + if (ctx.tagid != RSSTagDescription || !ctx.item.content.len) { ctx.iscontenttag = 1; ctx.field = &ctx.item.content; } - } else if(ctx.tagid == RSSTagGuid) { + } else if (ctx.tagid == RSSTagGuid) { ctx.field = &ctx.item.id; - } else if(ctx.tagid == RSSTagAuthor || ctx.tagid == RSSTagDccreator) { + } else if (ctx.tagid == RSSTagAuthor || ctx.tagid == RSSTagDccreator) { ctx.field = &ctx.item.author; } - } else if(ctx.item.feedtype == FeedTypeAtom) { - if(ctx.tagid == AtomTagPublished || ctx.tagid == AtomTagUpdated) { + } else if (ctx.item.feedtype == FeedTypeAtom) { + if (ctx.tagid == AtomTagPublished || ctx.tagid == AtomTagUpdated) { /* ignore, prefer updated over published */ - if(ctx.tagid != AtomTagPublished || !ctx.item.timestamp.len) { + if (ctx.tagid != AtomTagPublished || !ctx.item.timestamp.len) { ctx.field = &ctx.item.timestamp; } - } else if(ctx.tagid == AtomTagTitle) { + } else if (ctx.tagid == AtomTagTitle) { ctx.field = &ctx.item.title; - } else if(ctx.tagid == AtomTagSummary || ctx.tagid == AtomTagContent) { + } else if (ctx.tagid == AtomTagSummary || ctx.tagid == AtomTagContent) { /* ignore, prefer content:encoded over description */ - if(ctx.tagid != AtomTagSummary || !ctx.item.content.len) { + if (ctx.tagid != AtomTagSummary || !ctx.item.content.len) { ctx.iscontenttag = 1; ctx.field = &ctx.item.content; } - } else if(ctx.tagid == AtomTagId) { + } else if (ctx.tagid == AtomTagId) { ctx.field = &ctx.item.id; - } else if(ctx.tagid == AtomTagLink) { + } else if (ctx.tagid == AtomTagLink) { ctx.field = &ctx.item.link; - } else if(ctx.tagid == AtomTagAuthor) { + } else if (ctx.tagid == AtomTagAuthor) { ctx.field = &ctx.item.author; } } /* clear field */ - if(ctx.field) + if (ctx.field) string_clear(ctx.field); } @@ -600,10 +601,10 @@ xml_handler_data_entity(XMLParser *p, const char *data, size_t datalen) * xml_data_handler */ len = xml_entitytostr(data, buffer, sizeof(buffer)); /* this should never happen (buffer too small) */ - if(len < 0) + if (len < 0) return; - if(len > 0) + if (len > 0) xml_handler_data(p, buffer, (size_t)len); else xml_handler_data(p, data, datalen); @@ -614,11 +615,11 @@ xml_handler_end_element(XMLParser *p, const char *name, size_t namelen, int issh { int tagid; - if(ctx.iscontent) { + if (ctx.iscontent) { ctx.attrcount = 0; tagid = gettag(ctx.item.feedtype, name, namelen); /* close content */ - if(ctx.tagid == tagid) { + if (ctx.tagid == tagid) { ctx.iscontent = 0; ctx.iscontenttag = 0; ctx.tag[0] = '\0'; @@ -632,17 +633,17 @@ xml_handler_end_element(XMLParser *p, const char *name, size_t namelen, int issh return; } - if(!isshort) { + if (!isshort) { xml_handler_data(p, "</", 2); xml_handler_data(p, name, namelen); xml_handler_data(p, ">", 1); } return; } - if(ctx.item.feedtype == FeedTypeNone) + if (ctx.item.feedtype == FeedTypeNone) return; /* end of RSS or Atom entry / item */ - if((ctx.item.feedtype == FeedTypeAtom && + if ((ctx.item.feedtype == FeedTypeAtom && istag(name, namelen, STRP("entry"))) || /* Atom */ (ctx.item.feedtype == FeedTypeRSS && istag(name, namelen, STRP("item")))) /* RSS */ @@ -665,7 +666,7 @@ xml_handler_end_element(XMLParser *p, const char *name, size_t namelen, int issh /* not sure if needed */ ctx.iscontenttag = 0; ctx.iscontent = 0; - } else if(ctx.taglen == namelen && !strcmp(ctx.tag, name)) { + } else if (ctx.taglen == namelen && !strcmp(ctx.tag, name)) { /* clear */ /* XXX: optimize ? */ ctx.field = NULL; @@ -682,7 +683,7 @@ xml_handler_end_element(XMLParser *p, const char *name, size_t namelen, int issh int main(int argc, char *argv[]) { - if(argc > 1) + if (argc > 1) baseurl = argv[1]; /* init strings and initial memory pool size */ diff --git a/sfeed_frames.c b/sfeed_frames.c index da06b8b..9689e66 100644 --- a/sfeed_frames.c +++ b/sfeed_frames.c @@ -30,22 +30,22 @@ normalizepath(const char *path, char *buf, size_t bufsiz) { size_t i = 0, r = 0; - for(; *path && i < bufsiz; path++) { - if(isalpha((int)*path) || isdigit((int)*path)) { + for (; *path && i < bufsiz; path++) { + if (isalpha((int)*path) || isdigit((int)*path)) { buf[i++] = tolower((int)*path); r = 0; } else { /* don't repeat '-' */ - if(!r) + if (!r) buf[i++] = '-'; r++; } } /* remove trailing '-' */ - for(; i > 0 && (buf[i - 1] == '-'); i--) + for (; i > 0 && (buf[i - 1] == '-'); i--) ; - if(bufsiz > 0) + if (bufsiz > 0) buf[i] = '\0'; return i; @@ -64,23 +64,23 @@ printfeed(FILE *fpitems, FILE *fpin, struct feed *f) time_t parsedtime; int r; - if(f->name[0]) + if (f->name[0]) feedname = f->name; else feedname = "unnamed"; /* make directory for feedname */ - if(!(namelen = normalizepath(feedname, name, sizeof(name)))) + if (!(namelen = normalizepath(feedname, name, sizeof(name)))) return; - - if(strlcpy(dirpath, name, sizeof(dirpath)) >= sizeof(dirpath)) + + if (strlcpy(dirpath, name, sizeof(dirpath)) >= sizeof(dirpath)) errx(1, "strlcpy: path truncation"); /* directory doesn't exist: try to create it. */ - if(stat(dirpath, &st) == -1 && mkdir(dirpath, S_IRWXU) == -1) + if (stat(dirpath, &st) == -1 && mkdir(dirpath, S_IRWXU) == -1) err(1, "mkdir: %s", dirpath); - + /* menu if not unnamed */ - if(f->name[0]) { + if (f->name[0]) { fputs("<h2 id=\"", fpitems); printxmlencoded(f->name, fpitems); fputs("\"><a href=\"#", fpitems); @@ -91,17 +91,17 @@ printfeed(FILE *fpitems, FILE *fpin, struct feed *f) } fputs("<table cellpadding=\"0\" cellspacing=\"0\">\n", fpitems); - while(parseline(&line, &linesize, fields, FieldLast, '\t', fpin) > 0) { + while (parseline(&line, &linesize, fields, FieldLast, '\t', fpin) > 0) { /* write content */ - if(!(namelen = normalizepath(fields[FieldTitle], name, sizeof(name)))) + if (!(namelen = normalizepath(fields[FieldTitle], name, sizeof(name)))) continue; r = snprintf(filepath, sizeof(filepath), "%s/%s.html", dirpath, name); - if(r == -1 || (size_t)r >= sizeof(filepath)) + if (r == -1 || (size_t)r >= sizeof(filepath)) errx(1, "snprintf: path truncation"); /* file doesn't exist yet and has write access */ - if(access(filepath, F_OK) != 0) { - if(!(fpcontent = fopen(filepath, "w+b"))) + if (access(filepath, F_OK) != 0) { + if (!(fpcontent = fopen(filepath, "w+b"))) err(1, "fopen: %s", filepath); fputs("<html><head><link rel=\"stylesheet\" type=\"text/css\" href=\"../../style.css\" />" "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" /></head>\n" @@ -118,7 +118,7 @@ printfeed(FILE *fpitems, FILE *fpin, struct feed *f) /* set modified and access time of file to time of item. */ r = strtotime(fields[FieldUnixTimestamp], &parsedtime); - if(r != -1) { + if (r != -1) { contenttime.actime = parsedtime; contenttime.modtime = parsedtime; utime(filepath, &contenttime); @@ -128,21 +128,21 @@ printfeed(FILE *fpitems, FILE *fpin, struct feed *f) totalnew += isnew; f->totalnew += isnew; f->total++; - if(isnew) + if (isnew) fputs("<tr class=\"n\">", fpitems); else fputs("<tr>", fpitems); fputs("<td nowrap valign=\"top\">", fpitems); fputs(fields[FieldTimeFormatted], fpitems); fputs("</td><td nowrap valign=\"top\">", fpitems); - if(isnew) + if (isnew) fputs("<b><u>", fpitems); fputs("<a href=\"", fpitems); fputs(filepath, fpitems); fputs("\" target=\"content\">", fpitems); printxmlencoded(fields[FieldTitle], fpitems); fputs("</a>", fpitems); - if(isnew) + if (isnew) fputs("</u></b>", fpitems); fputs("</td></tr>\n", fpitems); } @@ -157,63 +157,63 @@ main(int argc, char *argv[]) int i; struct feed *f; - if(!(feeds = calloc(argc, sizeof(struct feed *)))) + if (!(feeds = calloc(argc, sizeof(struct feed *)))) err(1, "calloc"); /* 1 day is old news */ comparetime = time(NULL) - 86400; /* write main index page */ - if(!(fpindex = fopen("index.html", "w+b"))) + if (!(fpindex = fopen("index.html", "w+b"))) err(1, "fopen: index.html"); - if(!(fpmenu = fopen("menu.html", "w+b"))) + if (!(fpmenu = fopen("menu.html", "w+b"))) err(1, "fopen: menu.html"); - if(!(fpitems = fopen("items.html", "w+b"))) + if (!(fpitems = fopen("items.html", "w+b"))) err(1, "fopen: items.html"); fputs("<html><head><link rel=\"stylesheet\" type=\"text/css\" href=\"../style.css\" />" "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" /></head>" "<body class=\"frame\"><div id=\"items\">", fpitems); - if(argc == 1) { - if(!(feeds[0] = calloc(1, sizeof(struct feed)))) + if (argc == 1) { + if (!(feeds[0] = calloc(1, sizeof(struct feed)))) err(1, "calloc"); feeds[0]->name = ""; printfeed(fpitems, stdin, feeds[0]); } else { - for(i = 1; i < argc; i++) { - if(!(feeds[i - 1] = calloc(1, sizeof(struct feed)))) + for (i = 1; i < argc; i++) { + if (!(feeds[i - 1] = calloc(1, sizeof(struct feed)))) err(1, "calloc"); feeds[i - 1]->name = xbasename(argv[i]); - if(!(fp = fopen(argv[i], "r"))) + if (!(fp = fopen(argv[i], "r"))) err(1, "fopen: %s", argv[i]); printfeed(fpitems, fp, feeds[i - 1]); - if(ferror(fp)) + if (ferror(fp)) err(1, "ferror: %s", argv[i]); fclose(fp); } } fputs("\n</div></body>\n</html>", fpitems); /* div items */ - if(showsidebar) { + if (showsidebar) { fputs("<html><head>" "<link rel=\"stylesheet\" type=\"text/css\" href=\"../style.css\" />\n" "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />\n" "</head><body class=\"frame\"><div id=\"sidebar\">", fpmenu); - for(i = 1; i < argc; i++) { + for (i = 1; i < argc; i++) { f = feeds[i - 1]; - if(f->totalnew) + if (f->totalnew) fputs("<a class=\"n\" href=\"items.html#", fpmenu); else fputs("<a href=\"items.html#", fpmenu); printxmlencoded(f->name, fpmenu); fputs("\" target=\"items\">", fpmenu); - if(f->totalnew > 0) + if (f->totalnew > 0) fputs("<b><u>", fpmenu); printxmlencoded(f->name, fpmenu); fprintf(fpmenu, "(%lu)", f->totalnew); - if(f->totalnew > 0) + if (f->totalnew > 0) fputs("</u></b>", fpmenu); fputs("</a><br/>\n", fpmenu); } @@ -224,7 +224,7 @@ main(int argc, char *argv[]) fputs(")</title>\n\t<link rel=\"stylesheet\" type=\"text/css\" href=\"../style.css\" />\n" "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />\n" "</head>\n", fpindex); - if(showsidebar) { + if (showsidebar) { fputs("<frameset framespacing=\"0\" cols=\"200,*\" frameborder=\"1\">\n" " <frame name=\"menu\" src=\"menu.html\" target=\"menu\">\n", fpindex); } else { diff --git a/sfeed_html.c b/sfeed_html.c index e81e6c4..771f849 100644 --- a/sfeed_html.c +++ b/sfeed_html.c @@ -22,7 +22,7 @@ printfeed(FILE *fp, struct feed *f) unsigned int islink, isnew; int r; - if(f->name[0] != '\0') { + if (f->name[0] != '\0') { fputs("<h2 id=\"", stdout); printxmlencoded(f->name, stdout); fputs("\"><a href=\"#", stdout); @@ -33,7 +33,7 @@ printfeed(FILE *fp, struct feed *f) } fputs("<table cellpadding=\"0\" cellspacing=\"0\">\n", stdout); - while(parseline(&line, &linesize, fields, FieldLast, '\t', fp) > 0) { + while (parseline(&line, &linesize, fields, FieldLast, '\t', fp) > 0) { r = strtotime(fields[FieldUnixTimestamp], &parsedtime); isnew = (r != -1 && parsedtime >= comparetime) ? 1 : 0; islink = (fields[FieldLink][0] != '\0') ? 1 : 0; @@ -42,24 +42,24 @@ printfeed(FILE *fp, struct feed *f) f->totalnew += isnew; f->total++; - if(isnew) + if (isnew) fputs("<tr class=\"n\">", stdout); else fputs("<tr>", stdout); fputs("<td nowrap valign=\"top\">", stdout); fputs(fields[FieldTimeFormatted], stdout); fputs("</td><td nowrap valign=\"top\">", stdout); - if(isnew) + if (isnew) fputs("<b><u>", stdout); - if(islink) { + if (islink) { fputs("<a href=\"", stdout); printxmlencoded(fields[FieldLink], stdout); fputs("\">", stdout); } printxmlencoded(fields[FieldTitle], stdout); - if(islink) + if (islink) fputs("</a>", stdout); - if(isnew) + if (isnew) fputs("</u></b>", stdout); fputs("</td></tr>\n", stdout); } @@ -73,7 +73,7 @@ main(int argc, char *argv[]) FILE *fp; int i; - if(!(feeds = calloc(argc, sizeof(struct feed *)))) + if (!(feeds = calloc(argc, sizeof(struct feed *)))) err(1, "calloc"); /* 1 day old is old news */ @@ -88,50 +88,50 @@ main(int argc, char *argv[]) "\t<body class=\"noframe\">\n", stdout); showsidebar = (argc > 1); - if(showsidebar) + if (showsidebar) fputs("\t\t<div id=\"items\">\n", stdout); else fputs("\t\t<div id=\"items\" class=\"nosidebar\">\n", stdout); - if(argc == 1) { - if(!(feeds[0] = calloc(1, sizeof(struct feed)))) + if (argc == 1) { + if (!(feeds[0] = calloc(1, sizeof(struct feed)))) err(1, "calloc"); feeds[0]->name = ""; printfeed(stdin, feeds[0]); - if(ferror(stdin)) + if (ferror(stdin)) err(1, "ferror: <stdin>:"); } else { - for(i = 1; i < argc; i++) { - if(!(feeds[i - 1] = calloc(1, sizeof(struct feed)))) + for (i = 1; i < argc; i++) { + if (!(feeds[i - 1] = calloc(1, sizeof(struct feed)))) err(1, "calloc"); feeds[i - 1]->name = xbasename(argv[i]); - if(!(fp = fopen(argv[i], "r"))) + if (!(fp = fopen(argv[i], "r"))) err(1, "fopen: %s", argv[i]); printfeed(fp, feeds[i - 1]); - if(ferror(fp)) + if (ferror(fp)) err(1, "ferror: %s", argv[i]); fclose(fp); } } fputs("</div>\n", stdout); /* div items */ - if(showsidebar) { + if (showsidebar) { fputs("\t<div id=\"sidebar\">\n\t\t<ul>\n", stdout); for (i = 1; i < argc; i++) { f = feeds[i - 1]; - if(f->totalnew > 0) + if (f->totalnew > 0) fputs("<li class=\"n\"><a href=\"#", stdout); else fputs("<li><a href=\"#", stdout); printxmlencoded(f->name, stdout); fputs("\">", stdout); - if(f->totalnew > 0) + if (f->totalnew > 0) fputs("<b><u>", stdout); printxmlencoded(f->name, stdout); fprintf(stdout, "(%lu)", f->totalnew); - if(f->totalnew > 0) + if (f->totalnew > 0) fputs("</u></b>", stdout); fputs("</a></li>\n", stdout); } diff --git a/sfeed_opml_import.c b/sfeed_opml_import.c index e79a2ef..db10ea7 100644 --- a/sfeed_opml_import.c +++ b/sfeed_opml_import.c @@ -28,7 +28,7 @@ xml_handler_start_element(XMLParser *p, const char *tag, size_t taglen) (void)p; (void)taglen; - if(istag(tag, "outline")) { + if (istag(tag, "outline")) { feedurl[0] = '\0'; feedname[0] = '\0'; basesiteurl[0] = '\0'; @@ -43,7 +43,7 @@ xml_handler_end_element(XMLParser *p, const char *tag, size_t taglen, (void)taglen; (void)isshort; - if(istag(tag, "outline")) { + if (istag(tag, "outline")) { printf("\tfeed \"%s\" \"%s\" \"%s\"\n", feedname[0] ? feedname : "unnamed", feedurl[0] ? feedurl : "", @@ -60,12 +60,12 @@ xml_handler_attr(XMLParser *p, const char *tag, size_t taglen, (void)namelen; (void)valuelen; - if(istag(tag, "outline")) { - if(isattr(name, "text") || isattr(name, "title")) + if (istag(tag, "outline")) { + if (isattr(name, "text") || isattr(name, "title")) strlcpy(feedname, value, sizeof(feedname)); - else if(isattr(name, "htmlurl")) + else if (isattr(name, "htmlurl")) strlcpy(basesiteurl, value, sizeof(basesiteurl)); - else if(isattr(name, "xmlurl")) + else if (isattr(name, "xmlurl")) strlcpy(feedurl, value, sizeof(feedurl)); } } diff --git a/sfeed_plain.c b/sfeed_plain.c index 9b5a793..f3ffcf7 100644 --- a/sfeed_plain.c +++ b/sfeed_plain.c @@ -16,14 +16,14 @@ printfeed(FILE *fp, const char *feedname) char *fields[FieldLast]; time_t parsedtime; - while(parseline(&line, &size, fields, FieldLast, '\t', fp) > 0) { - if(strtotime(fields[FieldUnixTimestamp], &parsedtime) != -1 && + while (parseline(&line, &size, fields, FieldLast, '\t', fp) > 0) { + if (strtotime(fields[FieldUnixTimestamp], &parsedtime) != -1 && parsedtime >= comparetime) fputs(" N ", stdout); else fputs(" ", stdout); - if(feedname[0]) + if (feedname[0]) printf("%-15.15s ", feedname); printf(" %-30.30s ", fields[FieldTimeFormatted]); printutf8pad(stdout, fields[FieldTitle], 70, ' '); @@ -43,16 +43,16 @@ main(int argc, char *argv[]) /* 1 day is old news */ comparetime = time(NULL) - (3600 * 24); - if(argc == 1) { + if (argc == 1) { printfeed(stdin, ""); } else { - for(i = 1; i < argc; i++) { - if(!(fp = fopen(argv[i], "r"))) + for (i = 1; i < argc; i++) { + if (!(fp = fopen(argv[i], "r"))) err(1, "fopen: %s", argv[i]); name = xbasename(argv[i]); printfeed(fp, name); free(name); - if(ferror(fp)) + if (ferror(fp)) err(1, "ferror: %s", argv[i]); fclose(fp); } diff --git a/sfeed_web.c b/sfeed_web.c index 4e7a8d5..5ad6449 100644 --- a/sfeed_web.c +++ b/sfeed_web.c @@ -13,8 +13,8 @@ static char abslink[4096], feedlink[4096], basehref[4096], feedtype[256]; static void printfeedtype(const char *s, FILE *fp) { - for(; *s; s++) { - if(!isspace((int)*s)) + for (; *s; s++) { + if (!isspace((int)*s)) fputc(*s, fp); } } @@ -25,10 +25,10 @@ xmltagstart(XMLParser *p, const char *tag, size_t taglen) (void)p; isbase = islink = isfeedlink = 0; - if(taglen == 4) { /* optimization */ - if(!strncasecmp(tag, "base", taglen)) + if (taglen == 4) { /* optimization */ + if (!strncasecmp(tag, "base", taglen)) isbase = 1; - else if(!strncasecmp(tag, "link", taglen)) + else if (!strncasecmp(tag, "link", taglen)) islink = 1; } } @@ -41,12 +41,12 @@ xmltagstartparsed(XMLParser *p, const char *tag, size_t taglen, int isshort) (void)taglen; (void)isshort; - if(isfeedlink) { - if(*feedtype) { + if (isfeedlink) { + if (*feedtype) { printfeedtype(feedtype, stdout); putchar(' '); } - if(absuri(feedlink, basehref, abslink, sizeof(abslink)) != -1) + if (absuri(feedlink, basehref, abslink, sizeof(abslink)) != -1) fputs(abslink, stdout); putchar('\n'); found++; @@ -62,20 +62,20 @@ xmlattr(XMLParser *p, const char *tag, size_t taglen, const char *name, (void)taglen; (void)valuelen; - if(namelen != 4) /* optimization */ + if (namelen != 4) /* optimization */ return; - if(isbase) { - if(!strncasecmp(name, "href", namelen)) + if (isbase) { + if (!strncasecmp(name, "href", namelen)) strlcpy(basehref, value, sizeof(basehref)); - } else if(islink) { - if(!strncasecmp(name, "type", namelen)) { - if(!strncasecmp(value, "application/atom", strlen("application/atom")) || + } else if (islink) { + if (!strncasecmp(name, "type", namelen)) { + if (!strncasecmp(value, "application/atom", strlen("application/atom")) || !strncasecmp(value, "application/xml", strlen("application/xml")) || !strncasecmp(value, "application/rss", strlen("application/rss"))) { isfeedlink = 1; strlcpy(feedtype, value, sizeof(feedtype)); } - } else if(!strncasecmp(name, "href", namelen)) { + } else if (!strncasecmp(name, "href", namelen)) { strlcpy(feedlink, value, sizeof(feedlink)); } } @@ -86,7 +86,7 @@ main(int argc, char *argv[]) { XMLParser parser; - if(argc > 1) + if (argc > 1) strlcpy(basehref, argv[1], sizeof(basehref)); memset(&parser, 0, sizeof(parser)); diff --git a/sfeed_xmlenc.c b/sfeed_xmlenc.c index 7bd54a6..e08099d 100644 --- a/sfeed_xmlenc.c +++ b/sfeed_xmlenc.c @@ -14,7 +14,7 @@ xmltagstart(XMLParser *p, const char *tag, size_t taglen) (void)p; /* optimization: try to find processing instruction at start */ - if(tags > 3) + if (tags > 3) exit(1); isxmlpi = (!strncasecmp(tag, "?xml", taglen)) ? 1 : 0; tags++; @@ -40,10 +40,10 @@ xmlattr(XMLParser *p, const char *tag, size_t taglen, const char *name, (void)taglen; (void)valuelen; - if(isxmlpi && (!strncasecmp(name, "encoding", namelen))) { - if(*value) { + if (isxmlpi && (!strncasecmp(name, "encoding", namelen))) { + if (*value) { /* output lowercase */ - for(; *value; value++) + for (; *value; value++) putc(tolower((int)*value), stdout); putchar('\n'); } @@ -167,10 +167,10 @@ parseline(char **line, size_t *size, char **fields, char *prev, *s; unsigned int i; - if(getline(line, size, fp) <= 0) + if (getline(line, size, fp) <= 0) return -1; - for(prev = *line, i = 0; + for (prev = *line, i = 0; (s = strchr(prev, separator)) && i < maxfields - 1; i++) { *s = '\0'; @@ -179,7 +179,7 @@ parseline(char **line, size_t *size, char **fields, } fields[i++] = prev; /* make non-parsed fields empty. */ - for(; i < maxfields; i++) + for (; i < maxfields; i++) fields[i] = ""; return (int)i; @@ -190,7 +190,7 @@ trimend(const char *s) { size_t len = strlen(s); - for(; len > 0 && isspace((int)s[len - 1]); len--) + for (; len > 0 && isspace((int)s[len - 1]); len--) ; return (char*)&s[len]; } @@ -198,7 +198,7 @@ trimend(const char *s) char * trimstart(const char *s) { - for(; *s && isspace((int)*s); s++) + for (; *s && isspace((int)*s); s++) ; return (char *)s; } @@ -206,7 +206,7 @@ trimstart(const char *s) void printxmlencoded(const char *s, FILE *fp) { - for(; *s; s++) { + for (; *s; s++) { switch(*s) { case '<': fputs("<", fp); break; case '>': fputs(">", fp); break; @@ -228,17 +228,17 @@ printutf8pad(FILE *fp, const char *s, size_t len, int pad) size_t n = 0, i; int r; - for(i = 0; *s && n < len; i++, s++) { - if(ISUTF8(*s)) { - if((r = mbtowc(&w, s, 4)) == -1) + for (i = 0; *s && n < len; i++, s++) { + if (ISUTF8(*s)) { + if ((r = mbtowc(&w, s, 4)) == -1) break; - if((r = wcwidth(w)) == -1) + if ((r = wcwidth(w)) == -1) r = 1; n += (size_t)r; } putc(*s, fp); } - for(; n < len; n++) + for (; n < len; n++) putc(pad, fp); } @@ -250,7 +250,7 @@ strtotime(const char *s, time_t *t) errno = 0; l = strtol(s, NULL, 10); - if(errno != 0) + if (errno != 0) return -1; *t = (time_t)l; @@ -264,8 +264,8 @@ printcontent(const char *s, FILE *fp) { const char *p; - for(p = s; *p; p++) { - if(*p == '\\') { + for (p = s; *p; p++) { + if (*p == '\\') { switch (*(++p)) { case '\\': fputc('\\', fp); break; case 't': fputc('\t', fp); break; @@ -289,11 +289,11 @@ xbasename(const char *path) { char *p, *b; - if(!(p = strdup(path))) + if (!(p = strdup(path))) err(1, "strdup"); - if(!(b = basename(p))) + if (!(b = basename(p))) err(1, "basename"); - if(!(b = strdup(b))) + if (!(b = strdup(b))) err(1, "strdup"); free(p); return b; @@ -33,20 +33,20 @@ xmlparser_fd_getnext(XMLParser *x) ssize_t r; /* previous read error was set */ - if(x->readerrno) + if (x->readerrno) return EOF; - if(x->readoffset >= x->readlastbytes) { + if (x->readoffset >= x->readlastbytes) { x->readoffset = 0; again: r = read(x->fd, x->readbuf, sizeof(x->readbuf)); - if(r == -1) { - if(errno == EINTR) + if (r == -1) { + if (errno == EINTR) goto again; x->readerrno = errno; x->readlastbytes = 0; return EOF; - } else if(!r) { + } else if (!r) { return EOF; } x->readlastbytes = r; @@ -66,90 +66,90 @@ xmlparser_parseattrs(XMLParser *x) size_t namelen = 0, valuelen; int c, endsep, endname = 0; - while((c = xmlparser_getnext(x)) != EOF) { - if(isspace(c)) { /* TODO: simplify endname ? */ - if(namelen) + while ((c = xmlparser_getnext(x)) != EOF) { + if (isspace(c)) { /* TODO: simplify endname ? */ + if (namelen) endname = 1; continue; } - if(c == '?') + if (c == '?') ; /* ignore */ - else if(c == '=') { + else if (c == '=') { x->name[namelen] = '\0'; - } else if(namelen && ((endname && isalpha(c)) || (c == '>' || c == '/'))) { + } else if (namelen && ((endname && isalpha(c)) || (c == '>' || c == '/'))) { /* attribute without value */ x->name[namelen] = '\0'; - if(x->xmlattrstart) + if (x->xmlattrstart) x->xmlattrstart(x, x->tag, x->taglen, x->name, namelen); - if(x->xmlattr) + if (x->xmlattr) x->xmlattr(x, x->tag, x->taglen, x->name, namelen, "", 0); - if(x->xmlattrend) + if (x->xmlattrend) x->xmlattrend(x, x->tag, x->taglen, x->name, namelen); endname = 0; x->name[0] = c; namelen = 1; - } else if(namelen && (c == '\'' || c == '"')) { + } else if (namelen && (c == '\'' || c == '"')) { /* attribute with value */ endsep = c; /* c is end separator */ - if(x->xmlattrstart) + if (x->xmlattrstart) x->xmlattrstart(x, x->tag, x->taglen, x->name, namelen); - for(valuelen = 0; (c = xmlparser_getnext(x)) != EOF;) { - if(c == '&') { /* entities */ + for (valuelen = 0; (c = xmlparser_getnext(x)) != EOF;) { + if (c == '&') { /* entities */ x->data[valuelen] = '\0'; /* call data function with data before entity if there is data */ - if(valuelen && x->xmlattr) + if (valuelen && x->xmlattr) x->xmlattr(x, x->tag, x->taglen, x->name, namelen, x->data, valuelen); x->data[0] = c; valuelen = 1; - while((c = xmlparser_getnext(x)) != EOF) { - if(c == endsep) + while ((c = xmlparser_getnext(x)) != EOF) { + if (c == endsep) break; - if(valuelen < sizeof(x->data) - 1) + if (valuelen < sizeof(x->data) - 1) x->data[valuelen++] = c; else { /* TODO: entity too long? this should be very strange. */ x->data[valuelen] = '\0'; - if(x->xmlattr) + if (x->xmlattr) x->xmlattr(x, x->tag, x->taglen, x->name, namelen, x->data, valuelen); valuelen = 0; break; } - if(c == ';') { + if (c == ';') { x->data[valuelen] = '\0'; - if(x->xmlattrentity) + if (x->xmlattrentity) x->xmlattrentity(x, x->tag, x->taglen, x->name, namelen, x->data, valuelen); valuelen = 0; break; } } - } else if(c != endsep) { - if(valuelen < sizeof(x->data) - 1) { + } else if (c != endsep) { + if (valuelen < sizeof(x->data) - 1) { x->data[valuelen++] = c; } else { x->data[valuelen] = '\0'; - if(x->xmlattr) + if (x->xmlattr) x->xmlattr(x, x->tag, x->taglen, x->name, namelen, x->data, valuelen); x->data[0] = c; valuelen = 1; } } - if(c == endsep) { + if (c == endsep) { x->data[valuelen] = '\0'; - if(x->xmlattr) + if (x->xmlattr) x->xmlattr(x, x->tag, x->taglen, x->name, namelen, x->data, valuelen); - if(x->xmlattrend) + if (x->xmlattrend) x->xmlattrend(x, x->tag, x->taglen, x->name, namelen); break; } } namelen = 0; endname = 0; - } else if(namelen < sizeof(x->name) - 1) { + } else if (namelen < sizeof(x->name) - 1) { x->name[namelen++] = c; } - if(c == '>') { + if (c == '>') { break; - } else if(c == '/') { + } else if (c == '/') { x->isshorttag = 1; namelen = 0; x->name[0] = '\0'; @@ -165,22 +165,22 @@ xmlparser_parsecomment(XMLParser *x) char tmp[4]; int c; - if(x->xmlcommentstart) + if (x->xmlcommentstart) x->xmlcommentstart(x); - while((c = xmlparser_getnext(x)) != EOF) { - if(c == end[i]) { - if(end[++i] == '\0') { /* end */ + while ((c = xmlparser_getnext(x)) != EOF) { + if (c == end[i]) { + if (end[++i] == '\0') { /* end */ x->data[datalen] = '\0'; - if(x->xmlcomment) + if (x->xmlcomment) x->xmlcomment(x, x->data, datalen); - if(x->xmlcommentend) + if (x->xmlcommentend) x->xmlcommentend(x); return; } - } else if(i) { - if(x->xmlcomment) { + } else if (i) { + if (x->xmlcomment) { x->data[datalen] = '\0'; - if(datalen) + if (datalen) x->xmlcomment(x, x->data, datalen); memcpy(tmp, end, i); tmp[i] = '\0'; @@ -189,11 +189,11 @@ xmlparser_parsecomment(XMLParser *x) i = 0; x->data[0] = c; datalen = 1; - } else if(datalen < sizeof(x->data) - 1) { + } else if (datalen < sizeof(x->data) - 1) { x->data[datalen++] = c; } else { x->data[datalen] = '\0'; - if(x->xmlcomment) + if (x->xmlcomment) x->xmlcomment(x, x->data, datalen); x->data[0] = c; datalen = 1; @@ -209,22 +209,22 @@ xmlparser_parsecdata(XMLParser *x) char tmp[4]; int c; - if(x->xmlcdatastart) + if (x->xmlcdatastart) x->xmlcdatastart(x); - while((c = xmlparser_getnext(x)) != EOF) { - if(c == end[i]) { - if(end[++i] == '\0') { /* end */ + while ((c = xmlparser_getnext(x)) != EOF) { + if (c == end[i]) { + if (end[++i] == '\0') { /* end */ x->data[datalen] = '\0'; - if(x->xmlcdata) + if (x->xmlcdata) x->xmlcdata(x, x->data, datalen); - if(x->xmlcdataend) + if (x->xmlcdataend) x->xmlcdataend(x); return; } - } else if(i) { + } else if (i) { x->data[datalen] = '\0'; - if(x->xmlcdata) { - if(datalen) + if (x->xmlcdata) { + if (datalen) x->xmlcdata(x, x->data, datalen); memcpy(tmp, end, i); tmp[i] = '\0'; @@ -233,11 +233,11 @@ xmlparser_parsecdata(XMLParser *x) i = 0; x->data[0] = c; datalen = 1; - } else if(datalen < sizeof(x->data) - 1) { + } else if (datalen < sizeof(x->data) - 1) { x->data[datalen++] = c; } else { x->data[datalen] = '\0'; - if(x->xmlcdata) + if (x->xmlcdata) x->xmlcdata(x, x->data, datalen); x->data[0] = c; datalen = 1; @@ -248,19 +248,19 @@ xmlparser_parsecdata(XMLParser *x) int xml_codepointtoutf8(uint32_t cp, uint32_t *utf) { - if(cp >= 0x10000) { + if (cp >= 0x10000) { /* 4 bytes */ *utf = 0xf0808080 | ((cp & 0xfc0000) << 6) | ((cp & 0x3f000) << 4) | ((cp & 0xfc0) << 2) | (cp & 0x3f); return 4; - } else if(cp >= 0x00800) { + } else if (cp >= 0x00800) { /* 3 bytes */ *utf = 0xe08080 | ((cp & 0x3f000) << 4) | ((cp & 0xfc0) << 2) | (cp & 0x3f); return 3; - } else if(cp >= 0x80) { + } else if (cp >= 0x80) { /* 2 bytes */ *utf = 0xc080 | ((cp & 0xfc0) << 2) | (cp & 0x3f); @@ -276,16 +276,16 @@ xml_namedentitytostr(const char *e, char *buf, size_t bufsiz) size_t i; /* buffer is too small */ - if(bufsiz < 2) + if (bufsiz < 2) return -1; /* doesn't start with &: can't match */ - if(*e != '&') + if (*e != '&') return 0; - for(i = 0; sizeof(entities) / sizeof(*entities); i++) { + for (i = 0; sizeof(entities) / sizeof(*entities); i++) { /* NOTE: compares max 6 chars */ - if(!strncasecmp(e, entities[i].entity, 6)) { + if (!strncasecmp(e, entities[i].entity, 6)) { buf[0] = entities[i].c; buf[1] = '\0'; return 1; @@ -302,28 +302,28 @@ xml_numericentitytostr(const char *e, char *buf, size_t bufsiz) char *end; /* buffer is too small */ - if(bufsiz < 5) + if (bufsiz < 5) return -1; /* not a numeric entity */ - if(!(e[0] == '&' && e[1] == '#')) + if (!(e[0] == '&' && e[1] == '#')) return 0; /* e[1] == '#', numeric / hexadecimal entity */ e += 2; /* skip "&#" */ errno = 0; /* hex (16) or decimal (10) */ - if(*e == 'x') + if (*e == 'x') l = strtoul(e + 1, &end, 16); else l = strtoul(e, &end, 10); /* invalid value or not a well-formed entity */ - if(errno != 0 || (*end != '\0' && *end != ';')) + if (errno != 0 || (*end != '\0' && *end != ';')) return 0; - if(!(len = xml_codepointtoutf8(l, &cp))) + if (!(len = xml_codepointtoutf8(l, &cp))) return 0; /* make string */ - for(b = 0; b < len; b++) + for (b = 0; b < len; b++) buf[b] = (cp >> (8 * (len - 1 - b))) & 0xff; buf[len] = '\0'; return (ssize_t)len; @@ -335,13 +335,13 @@ ssize_t xml_entitytostr(const char *e, char *buf, size_t bufsiz) { /* buffer is too small */ - if(bufsiz < 5) + if (bufsiz < 5) return -1; /* doesn't start with & */ - if(e[0] != '&') + if (e[0] != '&') return 0; /* named entity */ - if(e[1] != '#') + if (e[1] != '#') return xml_namedentitytostr(e, buf, bufsiz); else /* numeric entity */ return xml_numericentitytostr(e, buf, bufsiz); @@ -353,26 +353,26 @@ xmlparser_parse(XMLParser *x) int c, ispi; size_t datalen, tagdatalen, taglen; - while((c = xmlparser_getnext(x)) != EOF && c != '<'); /* skip until < */ + while ((c = xmlparser_getnext(x)) != EOF && c != '<'); /* skip until < */ - while(c != EOF) { - if(c == '<') { /* parse tag */ - if((c = xmlparser_getnext(x)) == EOF) + while (c != EOF) { + if (c == '<') { /* parse tag */ + if ((c = xmlparser_getnext(x)) == EOF) return; x->tag[0] = '\0'; x->taglen = 0; - if(c == '!') { /* cdata and comments */ - for(tagdatalen = 0; (c = xmlparser_getnext(x)) != EOF;) { - if(tagdatalen <= strlen("[CDATA[")) /* if(d < sizeof(x->data)) */ + if (c == '!') { /* cdata and comments */ + for (tagdatalen = 0; (c = xmlparser_getnext(x)) != EOF;) { + if (tagdatalen <= strlen("[CDATA[")) /* if (d < sizeof(x->data)) */ x->data[tagdatalen++] = c; /* TODO: prevent overflow */ - if(c == '>') + if (c == '>') break; - else if(c == '-' && tagdatalen == strlen("--") && + else if (c == '-' && tagdatalen == strlen("--") && (x->data[0] == '-')) { /* comment */ xmlparser_parsecomment(x); break; - } else if(c == '[') { - if(tagdatalen == strlen("[CDATA[") && + } else if (c == '[') { + if (tagdatalen == strlen("[CDATA[") && x->data[1] == 'C' && x->data[2] == 'D' && x->data[3] == 'A' && x->data[4] == 'T' && x->data[5] == 'A' && x->data[6] == '[') { /* CDATA */ @@ -382,92 +382,92 @@ xmlparser_parse(XMLParser *x) } else { /* TODO ? */ /* markup declaration section */ - while((c = xmlparser_getnext(x)) != EOF && c != ']'); + while ((c = xmlparser_getnext(x)) != EOF && c != ']'); #endif } } } } else { /* normal tag (open, short open, close), processing instruction. */ - if(isspace(c)) - while((c = xmlparser_getnext(x)) != EOF && isspace(c)); - if(c == EOF) + if (isspace(c)) + while ((c = xmlparser_getnext(x)) != EOF && isspace(c)); + if (c == EOF) return; x->tag[0] = c; ispi = (c == '?') ? 1 : 0; x->isshorttag = ispi; taglen = 1; - while((c = xmlparser_getnext(x)) != EOF) { - if(c == '/') /* TODO: simplify short tag? */ + while ((c = xmlparser_getnext(x)) != EOF) { + if (c == '/') /* TODO: simplify short tag? */ x->isshorttag = 1; /* short tag */ - else if(c == '>' || isspace(c)) { + else if (c == '>' || isspace(c)) { x->tag[taglen] = '\0'; - if(x->tag[0] == '/') { /* end tag, starts with </ */ + if (x->tag[0] == '/') { /* end tag, starts with </ */ x->taglen = --taglen; /* len -1 because of / */ - if(taglen && x->xmltagend) + if (taglen && x->xmltagend) x->xmltagend(x, &(x->tag)[1], x->taglen, 0); } else { x->taglen = taglen; /* start tag */ - if(x->xmltagstart) + if (x->xmltagstart) x->xmltagstart(x, x->tag, x->taglen); - if(isspace(c)) + if (isspace(c)) xmlparser_parseattrs(x); - if(x->xmltagstartparsed) + if (x->xmltagstartparsed) x->xmltagstartparsed(x, x->tag, x->taglen, x->isshorttag); } /* call tagend for shortform or processing instruction */ - if((x->isshorttag || ispi) && x->xmltagend) + if ((x->isshorttag || ispi) && x->xmltagend) x->xmltagend(x, x->tag, x->taglen, 1); break; - } else if(taglen < sizeof(x->tag) - 1) + } else if (taglen < sizeof(x->tag) - 1) x->tag[taglen++] = c; } } } else { /* parse tag data */ datalen = 0; - if(x->xmldatastart) + if (x->xmldatastart) x->xmldatastart(x); - while((c = xmlparser_getnext(x)) != EOF) { - if(c == '&') { - if(datalen) { + while ((c = xmlparser_getnext(x)) != EOF) { + if (c == '&') { + if (datalen) { x->data[datalen] = '\0'; - if(x->xmldata) + if (x->xmldata) x->xmldata(x, x->data, datalen); } x->data[0] = c; datalen = 1; - while((c = xmlparser_getnext(x)) != EOF) { - if(c == '<') + while ((c = xmlparser_getnext(x)) != EOF) { + if (c == '<') break; - if(datalen < sizeof(x->data) - 1) + if (datalen < sizeof(x->data) - 1) x->data[datalen++] = c; - if(isspace(c)) + if (isspace(c)) break; - else if(c == ';') { + else if (c == ';') { x->data[datalen] = '\0'; - if(x->xmldataentity) + if (x->xmldataentity) x->xmldataentity(x, x->data, datalen); datalen = 0; break; } } - } else if(c != '<') { - if(datalen < sizeof(x->data) - 1) { + } else if (c != '<') { + if (datalen < sizeof(x->data) - 1) { x->data[datalen++] = c; } else { x->data[datalen] = '\0'; - if(x->xmldata) + if (x->xmldata) x->xmldata(x, x->data, datalen); x->data[0] = c; datalen = 1; } } - if(c == '<') { + if (c == '<') { x->data[datalen] = '\0'; - if(x->xmldata && datalen) + if (x->xmldata && datalen) x->xmldata(x, x->data, datalen); - if(x->xmldataend) + if (x->xmldataend) x->xmldataend(x); break; } |