diff options
author | Hiltjo Posthuma <hiltjo@codemadness.org> | 2020-04-01 18:40:02 +0200 |
---|---|---|
committer | Hiltjo Posthuma <hiltjo@codemadness.org> | 2020-04-01 18:49:24 +0200 |
commit | 7c99000c207c120d4094277b6ede56a36b929b46 (patch) | |
tree | 7fc5304ca7ec4f437c1c21f6e7b640cf83b601f0 | |
parent | 785a50c37c11c8e92387f8409d91bd77c41297b2 (diff) |
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.
-rw-r--r-- | sfeed_atom.c | 3 | ||||
-rw-r--r-- | sfeed_frames.c | 3 | ||||
-rw-r--r-- | sfeed_gopher.c | 3 | ||||
-rw-r--r-- | sfeed_html.c | 3 | ||||
-rw-r--r-- | sfeed_mbox.c | 3 | ||||
-rw-r--r-- | sfeed_plain.c | 3 | ||||
-rw-r--r-- | sfeed_twtxt.c | 3 | ||||
-rw-r--r-- | util.c | 13 | ||||
-rw-r--r-- | 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)) @@ -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. */ @@ -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 *); |