diff options
-rw-r--r-- | sfeed_frames.c | 2 | ||||
-rw-r--r-- | sfeed_html.c | 2 | ||||
-rw-r--r-- | sfeed_mbox.c | 2 | ||||
-rw-r--r-- | sfeed_plain.c | 2 | ||||
-rw-r--r-- | util.c | 25 | ||||
-rw-r--r-- | util.h | 14 |
6 files changed, 23 insertions, 24 deletions
diff --git a/sfeed_frames.c b/sfeed_frames.c index b333f04..4ac9f29 100644 --- a/sfeed_frames.c +++ b/sfeed_frames.c @@ -112,7 +112,7 @@ 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, fpin) > 0) { /* write content */ if (!(namelen = normalizepath(fields[FieldTitle], name, sizeof(name)))) continue; diff --git a/sfeed_html.c b/sfeed_html.c index 36113c0..fb4ed8b 100644 --- a/sfeed_html.c +++ b/sfeed_html.c @@ -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, fp) > 0) { r = strtotime(fields[FieldUnixTimestamp], &parsedtime); isnew = (r != -1 && parsedtime >= comparetime) ? 1 : 0; islink = (fields[FieldLink][0] != '\0') ? 1 : 0; diff --git a/sfeed_mbox.c b/sfeed_mbox.c index 10b31c8..6e171cb 100644 --- a/sfeed_mbox.c +++ b/sfeed_mbox.c @@ -76,7 +76,7 @@ printfeed(FILE *fp, const char *feedname) if (!strftime(mtimebuf, sizeof(mtimebuf), "%a %b %d %H:%M:%S %Y", &tm)) errx(1, "can't format current time"); - while (parseline(&line, &linesize, fields, FieldLast, '\t', fp) > 0) { + while (parseline(&line, &linesize, fields, fp) > 0) { if ((r = strtotime(fields[FieldUnixTimestamp], &parsedtime)) == -1) continue; /* invalid date */ if (!gmtime_r(&parsedtime, &tm)) diff --git a/sfeed_plain.c b/sfeed_plain.c index ff54df5..6bd93a3 100644 --- a/sfeed_plain.c +++ b/sfeed_plain.c @@ -44,7 +44,7 @@ printfeed(FILE *fp, const char *feedname) char *fields[FieldLast]; time_t parsedtime; - while (parseline(&line, &size, fields, FieldLast, '\t', fp) > 0) { + while (parseline(&line, &size, fields, fp) > 0) { if (strtotime(fields[FieldUnixTimestamp], &parsedtime) != -1 && parsedtime >= comparetime) fputs(" N ", stdout); @@ -155,23 +155,21 @@ encodeuri(const char *s, char *buf, size_t bufsiz) /* Read a field-separated line from 'fp', * separated by a character 'separator', - * 'fields' is a list of pointer with a maximum size of 'maxfields'. - * 'maxfields' must be > 0. - * 'line' buffer is allocated using malloc, 'size' will contain the - * allocated buffer size. - * 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) + * 'fields' is a list of pointers with a size of FieldLast (must be >0). + * 'line' buffer is allocated using malloc, 'size' will contain the allocated + * buffer size. + * returns: amount of fields read (>0) or -1 on error. */ +ssize_t +parseline(char **line, size_t *size, char *fields[FieldLast], FILE *fp) { char *prev, *s; - unsigned int i; + size_t i; if (getline(line, size, fp) <= 0) return -1; for (prev = *line, i = 0; - (s = strchr(prev, separator)) && i < maxfields - 1; + (s = strchr(prev, '\t')) && i < FieldLast - 1; i++) { *s = '\0'; fields[i] = prev; @@ -179,10 +177,10 @@ parseline(char **line, size_t *size, char **fields, } fields[i++] = prev; /* make non-parsed fields empty. */ - for (; i < maxfields; i++) + for (; i < FieldLast; i++) fields[i] = ""; - return (int)i; + return (ssize_t)i; } /* Parse time to time_t, assumes time_t is signed. */ @@ -195,7 +193,8 @@ strtotime(const char *s, time_t *t) l = strtol(s, NULL, 10); if (errno != 0) return -1; - *t = (time_t)l; + if (t) + *t = (time_t)l; return 0; } @@ -25,12 +25,12 @@ enum { FieldUnixTimestamp = 0, FieldTimeFormatted, FieldTitle, FieldLink, FieldContent, FieldContentType, FieldId, FieldAuthor, FieldFeedType, FieldLast }; -int absuri(const char *, const char *, char *, size_t); -int encodeuri(const char *, char *, size_t); -int parseline(char **, size_t *, char **, unsigned int, int, FILE *); -int parseuri(const char *, struct uri *, int); -int strtotime(const char *, time_t *); -char * xbasename(const char *); -void xmlencode(const char *, FILE *); +int absuri(const char *, const char *, char *, size_t); +int encodeuri(const char *, char *, size_t); +ssize_t parseline(char **, size_t *, char *[FieldLast], FILE *); +int parseuri(const char *, struct uri *, int); +int strtotime(const char *, time_t *); +char * xbasename(const char *); +void xmlencode(const char *, FILE *); |