sfeed

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

commit 02f91017fdfa8c90a25991bf1cb4b6efcb0bc7c6
parent 5c8840493f8cd52ba2224db6ed644f4933ac2212
Author: Hiltjo Posthuma <hiltjo@codemadness.org>
Date:   Sat, 16 May 2015 15:56:00 +0200

util: parseline can return error, unsigned int -> int

Diffstat:
Mutil.c | 30+++++++++++++++++-------------
Mutil.h | 2+-
2 files changed, 18 insertions(+), 14 deletions(-)

diff --git a/util.c b/util.c @@ -56,26 +56,30 @@ printlink(const char *link, const char *baseurl, FILE *fp) * 'fields' is a list of pointer with a maximum size of 'maxfields'. * 'line' buffer is allocated using malloc, 'size' will contain the * allocated buffer size. - * returns: amount of fields read. */ -unsigned int + * returns: amount of fields read or -1 on error. */ +int parseline(char **line, size_t *size, char **fields, unsigned int maxfields, int separator, FILE *fp) { - unsigned int i = 0; char *prev, *s; + unsigned int i; - if(getline(line, size, fp) > 0) { - for(prev = *line; (s = strchr(prev, separator)) && i <= maxfields; i++) { - *s = '\0'; - fields[i] = prev; - prev = s + 1; - } + if(getline(line, size, fp) <= 0) + return -1; + + for(prev = *line, i = 0; + (s = strchr(prev, separator)) && i <= maxfields; + i++) { + *s = '\0'; fields[i] = prev; - /* make non-parsed fields empty. */ - for(i++; i < maxfields; i++) - fields[i] = ""; + prev = s + 1; } - return i; + fields[i++] = prev; + /* make non-parsed fields empty. */ + for(; i < maxfields; i++) + fields[i] = ""; + + return (int)i; } const char * diff --git a/util.h b/util.h @@ -23,7 +23,7 @@ enum { FieldUnixTimestamp = 0, FieldTimeFormatted, FieldTitle, FieldLink, FieldContent, FieldContentType, FieldId, FieldAuthor, FieldFeedType, FieldFeedName, FieldFeedUrl, FieldBaseSiteUrl, FieldLast }; -unsigned int parseline(char **, size_t *, char **, unsigned int, int, FILE *); +int parseline(char **, size_t *, char **, unsigned int, int, FILE *); void printfeednameid(const char *, FILE *); void printhtmlencoded(const char *, FILE *); void printlink(const char *, const char *, FILE *);