From 7c99000c207c120d4094277b6ede56a36b929b46 Mon Sep 17 00:00:00 2001 From: Hiltjo Posthuma Date: Wed, 1 Apr 2020 18:40:02 +0200 Subject: util: improve/cleanup parseline() - remove a check that has no use/can never happen. - remove the return value as it's unused and the input size is known. - fix an old comment that doesn't reflect what the function does anymore. --- sfeed_atom.c | 3 +-- sfeed_frames.c | 3 +-- sfeed_gopher.c | 3 +-- sfeed_html.c | 3 +-- sfeed_mbox.c | 3 +-- sfeed_plain.c | 3 +-- sfeed_twtxt.c | 3 +-- util.c | 13 ++++--------- util.h | 12 ++++++------ 9 files changed, 17 insertions(+), 29 deletions(-) diff --git a/sfeed_atom.c b/sfeed_atom.c index 844bd2e..33bd9a7 100644 --- a/sfeed_atom.c +++ b/sfeed_atom.c @@ -44,8 +44,7 @@ printfeed(FILE *fp, const char *feedname) while ((linelen = getline(&line, &linesize, fp)) > 0) { if (line[linelen - 1] == '\n') line[--linelen] = '\0'; - if (!parseline(line, fields)) - break; + parseline(line, fields); parsedtime = 0; if (strtotime(fields[FieldUnixTimestamp], &parsedtime)) diff --git a/sfeed_frames.c b/sfeed_frames.c index 84116b0..dd50de1 100644 --- a/sfeed_frames.c +++ b/sfeed_frames.c @@ -38,8 +38,7 @@ printfeed(FILE *fpitems, FILE *fpin, struct feed *f) while ((linelen = getline(&line, &linesize, fpin)) > 0) { if (line[linelen - 1] == '\n') line[--linelen] = '\0'; - if (!parseline(line, fields)) - break; + parseline(line, fields); parsedtime = 0; if (strtotime(fields[FieldUnixTimestamp], &parsedtime)) diff --git a/sfeed_gopher.c b/sfeed_gopher.c index 27f23ef..7362716 100644 --- a/sfeed_gopher.c +++ b/sfeed_gopher.c @@ -51,8 +51,7 @@ printfeed(FILE *fpitems, FILE *fpin, struct feed *f) while ((linelen = getline(&line, &linesize, fpin)) > 0) { if (line[linelen - 1] == '\n') line[--linelen] = '\0'; - if (!parseline(line, fields)) - break; + parseline(line, fields); parsedtime = 0; if (strtotime(fields[FieldUnixTimestamp], &parsedtime)) diff --git a/sfeed_html.c b/sfeed_html.c index ac75db0..caac47e 100644 --- a/sfeed_html.c +++ b/sfeed_html.c @@ -38,8 +38,7 @@ printfeed(FILE *fp, struct feed *f) while ((linelen = getline(&line, &linesize, fp)) > 0) { if (line[linelen - 1] == '\n') line[--linelen] = '\0'; - if (!parseline(line, fields)) - break; + parseline(line, fields); parsedtime = 0; if (strtotime(fields[FieldUnixTimestamp], &parsedtime)) diff --git a/sfeed_mbox.c b/sfeed_mbox.c index 1aab49b..587429b 100644 --- a/sfeed_mbox.c +++ b/sfeed_mbox.c @@ -34,8 +34,7 @@ printfeed(FILE *fp, const char *feedname) if (line[linelen - 1] == '\n') line[--linelen] = '\0'; hash = djb2((unsigned char *)line, 5381UL); - if (!parseline(line, fields)) - break; + parseline(line, fields); parsedtime = 0; if (strtotime(fields[FieldUnixTimestamp], &parsedtime)) diff --git a/sfeed_plain.c b/sfeed_plain.c index e08e466..6dd3d5e 100644 --- a/sfeed_plain.c +++ b/sfeed_plain.c @@ -23,8 +23,7 @@ printfeed(FILE *fp, const char *feedname) while ((linelen = getline(&line, &linesize, fp)) > 0) { if (line[linelen - 1] == '\n') line[--linelen] = '\0'; - if (!parseline(line, fields)) - break; + parseline(line, fields); parsedtime = 0; if (strtotime(fields[FieldUnixTimestamp], &parsedtime)) diff --git a/sfeed_twtxt.c b/sfeed_twtxt.c index ef80e2d..52281d2 100644 --- a/sfeed_twtxt.c +++ b/sfeed_twtxt.c @@ -21,8 +21,7 @@ printfeed(FILE *fp, const char *feedname) while ((linelen = getline(&line, &linesize, fp)) > 0) { if (line[linelen - 1] == '\n') line[--linelen] = '\0'; - if (!parseline(line, fields)) - break; + parseline(line, fields); parsedtime = 0; if (strtotime(fields[FieldUnixTimestamp], &parsedtime)) diff --git a/util.c b/util.c index 51f7bd8..24f38b5 100644 --- a/util.c +++ b/util.c @@ -171,13 +171,10 @@ absuri(char *buf, size_t bufsiz, const char *link, const char *base) return encodeuri(buf, bufsiz, tmp); } -/* Read a field-separated line from 'fp', - * separated by a character 'separator', - * '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. */ -size_t +/* Splits fields in the line buffer by replacing TAB separators with NUL ('\0') + * terminators and assign these fields as pointers. If there are less fields + * than expected then the field is an empty string constant. */ +void parseline(char *line, char *fields[FieldLast]) { char *prev, *s; @@ -194,8 +191,6 @@ parseline(char *line, char *fields[FieldLast]) /* make non-parsed fields empty. */ for (; i < FieldLast; i++) fields[i] = ""; - - return i; } /* Parse time to time_t, assumes time_t is signed, ignores fractions. */ diff --git a/util.h b/util.h index 6d0d58d..cf250ec 100644 --- a/util.h +++ b/util.h @@ -33,9 +33,9 @@ enum { FieldContentType, FieldId, FieldAuthor, FieldEnclosure, FieldLast }; -int absuri(char *, size_t, const char *, const char *); -size_t parseline(char *, char *[FieldLast]); -int parseuri(const char *, struct uri *, int); -void printutf8pad(FILE *, const char *, size_t, int); -int strtotime(const char *, time_t *); -void xmlencode(const char *, FILE *); +int absuri(char *, size_t, const char *, const char *); +void parseline(char *, char *[FieldLast]); +int parseuri(const char *, struct uri *, int); +void printutf8pad(FILE *, const char *, size_t, int); +int strtotime(const char *, time_t *); +void xmlencode(const char *, FILE *); -- cgit v1.2.3