commit 7c99000c207c120d4094277b6ede56a36b929b46
parent 785a50c37c11c8e92387f8409d91bd77c41297b2
Author: Hiltjo Posthuma <hiltjo@codemadness.org>
Date: Wed, 1 Apr 2020 18:40:02 +0200
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.
Diffstat:
9 files changed, 17 insertions(+), 29 deletions(-)
diff --git 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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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 *);