sfeed

Simple RSS and Atom feed parser
git clone https://git.sinitax.com/codemadness/sfeed
Log | Files | Refs | README | LICENSE | Upstream | sfeed.txt

commit 9a52f59fc546d509dc1a859c6cce92f99e31f46d
parent a855f803fd27af9ec1d19c5d7444ef0ad3d91b0b
Author: Hiltjo Posthuma <hiltjo@codemadness.org>
Date:   Tue, 11 Nov 2014 19:56:05 +0100

code style, use actual column width of char

Diffstat:
Msfeed.c | 6+++---
Msfeed_frames.c | 27++++++++++++++++-----------
Msfeed_html.c | 15+++++++++------
Msfeed_opml_import.c | 12++++++++----
Msfeed_plain.c | 7++++---
Msfeed_stats.c | 15+++++++++------
Msfeed_web.c | 16++++++++++------
Msfeed_xmlenc.c | 13++++++++-----
Mutil.c | 38+++++++++++++++++++++++++-------------
Mutil.h | 2++
10 files changed, 94 insertions(+), 57 deletions(-)

diff --git a/sfeed.c b/sfeed.c @@ -1,11 +1,11 @@ +#include <ctype.h> +#include <errno.h> +#include <stdint.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <strings.h> #include <time.h> -#include <ctype.h> -#include <stdint.h> -#include <errno.h> #include "util.h" #include "xml.h" diff --git a/sfeed_frames.c b/sfeed_frames.c @@ -1,14 +1,14 @@ +#include <ctype.h> +#include <errno.h> +#include <limits.h> #include <stdio.h> -#include <string.h> #include <stdlib.h> +#include <string.h> +#include <sys/stat.h> +#include <sys/types.h> #include <time.h> -#include <ctype.h> #include <unistd.h> -#include <sys/types.h> -#include <sys/stat.h> #include <utime.h> -#include <limits.h> -#include <errno.h> #include "util.h" @@ -20,13 +20,15 @@ static struct feed *feeds = NULL; /* print error message to stderr */ static void -die(const char *s) { +die(const char *s) +{ fprintf(stderr, "sfeed_frames: %s\n", s); exit(EXIT_FAILURE); } static void -cleanup(void) { +cleanup(void) +{ if(fpmenu) { fclose(fpmenu); fpmenu = NULL; @@ -51,7 +53,8 @@ cleanup(void) { /* print text, ignore tabs, newline and carriage return etc * print some HTML 2.0 / XML 1.0 as normal text */ static void -printcontent(const char *s, FILE *fp) { +printcontent(const char *s, FILE *fp) +{ const char *p; for(p = s; *p; p++) { @@ -73,7 +76,8 @@ printcontent(const char *s, FILE *fp) { /* TODO: bufsiz - 1 ? */ static size_t -makepathname(const char *path, char *buffer, size_t bufsiz) { +makepathname(const char *path, char *buffer, size_t bufsiz) +{ size_t i = 0, r = 0; for(; *path && i < bufsiz - 1; path++) { @@ -94,7 +98,8 @@ makepathname(const char *path, char *buffer, size_t bufsiz) { } int -main(int argc, char **argv) { +main(int argc, char *argv[]) +{ struct feed *f, *fcur = NULL; char *fields[FieldLast]; char name[64]; /* TODO: bigger size? */ diff --git a/sfeed_html.c b/sfeed_html.c @@ -1,9 +1,9 @@ +#include <ctype.h> +#include <errno.h> #include <stdio.h> -#include <string.h> #include <stdlib.h> +#include <string.h> #include <time.h> -#include <ctype.h> -#include <errno.h> #include "util.h" @@ -12,7 +12,8 @@ static struct feed *feeds = NULL; /* start of feeds linked-list. */ static char *line = NULL; static void -cleanup(void) { +cleanup(void) +{ free(line); /* free line */ line = NULL; feedsfree(feeds); /* free feeds linked-list */ @@ -20,13 +21,15 @@ cleanup(void) { /* print error message to stderr */ static void -die(const char *s) { +die(const char *s) +{ fprintf(stderr, "sfeed_html: %s\n", s); exit(EXIT_FAILURE); } int -main(void) { +main(void) +{ char *fields[FieldLast]; unsigned long totalfeeds = 0, totalnew = 0; unsigned int islink, isnew; diff --git a/sfeed_opml_import.c b/sfeed_opml_import.c @@ -11,17 +11,20 @@ static XMLParser parser; /* XML parser state */ static char feedurl[2048], feedname[2048], basesiteurl[2048]; static int -istag(const char *s1, const char *s2) { +istag(const char *s1, const char *s2) +{ return !strcasecmp(s1, s2); } static int -isattr(const char *s1, const char *s2) { +isattr(const char *s1, const char *s2) +{ return !strcasecmp(s1, s2); } static void -xml_handler_start_element(XMLParser *p, const char *tag, size_t taglen) { +xml_handler_start_element(XMLParser *p, const char *tag, size_t taglen) +{ (void)p; (void)taglen; @@ -68,7 +71,8 @@ xml_handler_attr(XMLParser *p, const char *tag, size_t taglen, } int -main(void) { +main(void) +{ xmlparser_init(&parser, stdin); parser.xmltagstart = xml_handler_start_element; diff --git a/sfeed_plain.c b/sfeed_plain.c @@ -1,13 +1,14 @@ +#include <errno.h> #include <stdio.h> -#include <string.h> #include <stdlib.h> +#include <string.h> #include <time.h> -#include <errno.h> #include "util.h" int -main(void) { +main(void) +{ char *line = NULL, *fields[FieldLast]; time_t parsedtime, comparetime; size_t size = 0; diff --git a/sfeed_stats.c b/sfeed_stats.c @@ -1,9 +1,9 @@ +#include <ctype.h> +#include <errno.h> #include <stdio.h> -#include <string.h> #include <stdlib.h> +#include <string.h> #include <time.h> -#include <ctype.h> -#include <errno.h> #include "util.h" @@ -11,7 +11,8 @@ static struct feed *feeds = NULL; /* start of feeds linked-list. */ static char *line = NULL; static void -cleanup(void) { +cleanup(void) +{ free(line); /* free line */ line = NULL; feedsfree(feeds); /* free feeds linked-list */ @@ -19,13 +20,15 @@ cleanup(void) { /* print error message to stderr */ static void -die(const char *s) { +die(const char *s) +{ fprintf(stderr, "sfeed_stats: %s\n", s); exit(EXIT_FAILURE); } int -main(void) { +main(void) +{ char *fields[FieldLast], timenewestformat[64] = ""; unsigned long totalfeeds = 0, totalnew = 0, totalitems = 0; unsigned int isnew; diff --git a/sfeed_web.c b/sfeed_web.c @@ -1,8 +1,8 @@ +#include <ctype.h> #include <stdio.h> +#include <stdlib.h> #include <string.h> #include <strings.h> -#include <stdlib.h> -#include <ctype.h> #include "util.h" #include "xml.h" @@ -11,7 +11,8 @@ static unsigned int isbase = 0, islink = 0, isfeedlink = 0, found = 0; static char feedlink[4096] = "", basehref[4096] = "", feedtype[256] = ""; static void -xmltagstart(XMLParser *p, const char *tag, size_t taglen) { +xmltagstart(XMLParser *p, const char *tag, size_t taglen) +{ (void)p; isbase = islink = isfeedlink = 0; @@ -24,7 +25,8 @@ xmltagstart(XMLParser *p, const char *tag, size_t taglen) { } static void -xmltagstartparsed(XMLParser *p, const char *tag, size_t taglen, int isshort) { +xmltagstartparsed(XMLParser *p, const char *tag, size_t taglen, int isshort) +{ (void)p; (void)tag; (void)taglen; @@ -43,7 +45,8 @@ xmltagstartparsed(XMLParser *p, const char *tag, size_t taglen, int isshort) { static void xmlattr(XMLParser *p, const char *tag, size_t taglen, const char *name, - size_t namelen, const char *value, size_t valuelen) { + size_t namelen, const char *value, size_t valuelen) +{ (void)p; (void)tag; (void)taglen; @@ -67,7 +70,8 @@ xmlattr(XMLParser *p, const char *tag, size_t taglen, const char *name, } int -main(int argc, char **argv) { +main(int argc, char *argv[]) +{ XMLParser x; /* base href */ diff --git a/sfeed_xmlenc.c b/sfeed_xmlenc.c @@ -1,15 +1,16 @@ +#include <ctype.h> #include <stdio.h> +#include <stdlib.h> #include <string.h> #include <strings.h> -#include <stdlib.h> -#include <ctype.h> #include "xml.h" static int isxmlpi = 0, tags = 0; static void -xmltagstart(XMLParser *p, const char *tag, size_t taglen) { +xmltagstart(XMLParser *p, const char *tag, size_t taglen) +{ (void)p; /* optimization: try to find processing instruction at start */ @@ -20,7 +21,8 @@ xmltagstart(XMLParser *p, const char *tag, size_t taglen) { } static void -xmltagend(XMLParser *p, const char *tag, size_t taglen, int isshort) { +xmltagend(XMLParser *p, const char *tag, size_t taglen, int isshort) +{ (void)p; (void)tag; (void)taglen; @@ -50,7 +52,8 @@ xmlattr(XMLParser *p, const char *tag, size_t taglen, const char *name, } int -main(void) { +main(void) +{ XMLParser x; xmlparser_init(&x, stdin); diff --git a/util.c b/util.c @@ -1,9 +1,10 @@ +#include <ctype.h> #include <stdio.h> -#include <string.h> #include <stdlib.h> -#include <time.h> -#include <ctype.h> +#include <string.h> #include <sys/types.h> +#include <time.h> +#include <wchar.h> #include "util.h" @@ -14,7 +15,8 @@ * Returns strlen(src); if retval >= siz, truncation occurred. */ size_t -strlcpy(char *dst, const char *src, size_t siz) { +strlcpy(char *dst, const char *src, size_t siz) +{ char *d = dst; const char *s = src; size_t n = siz; @@ -38,7 +40,8 @@ strlcpy(char *dst, const char *src, size_t siz) { /* print link; if link is relative use baseurl to make it absolute */ void -printlink(const char *link, const char *baseurl, FILE *fp) { +printlink(const char *link, const char *baseurl, FILE *fp) +{ const char *ebaseproto, *ebasedomain, *p; int isrelative; @@ -105,7 +108,8 @@ parseline(char **line, size_t *size, char **fields, /* print feed name for id; spaces and tabs in string as "-" * (spaces in anchors are not valid). */ void -printfeednameid(const char *s, FILE *fp) { +printfeednameid(const char *s, FILE *fp) +{ for(; *s; s++) fputc(isspace((int)*s) ? '-' : tolower((int)*s), fp); } @@ -124,7 +128,8 @@ printhtmlencoded(const char *s, FILE *fp) { } void -feedsfree(struct feed *f) { +feedsfree(struct feed *f) +{ struct feed *next = NULL; for(; f; f = next) { @@ -137,14 +142,21 @@ feedsfree(struct feed *f) { } void -printutf8pad(FILE *fp, const char *s, size_t len, int pad) { +printutf8pad(FILE *fp, const char *s, size_t len, int pad) +{ + wchar_t w; size_t n = 0, i; + int r; - for(i = 0; s[i] && n < len; i++) { - /* start of character */ - if((s[i] & 0xc0) != 0x80) - n++; - putc(s[i], fp); + for(i = 0; *s && n < len; i++, s++) { + if(ISUTF8(*s)) { + if((r = mbtowc(&w, s, 4)) == -1) + break; + if((r = wcwidth(w)) == -1) + r = 1; + n += (size_t)r; + } + putc(*s, fp); } for(; n < len; n++) putc(pad, fp); diff --git a/util.h b/util.h @@ -1,5 +1,7 @@ #include <time.h> +#define ISUTF8(c) (((c) & 0xc0) != 0x80) + /* feed info */ struct feed { char *name; /* feed name */