summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHiltjo Posthuma <hiltjo@codemadness.org>2020-06-21 18:08:41 +0200
committerHiltjo Posthuma <hiltjo@codemadness.org>2020-06-21 18:08:41 +0200
commit1b14e601434435f48dfe1027a117c2af3dac325b (patch)
tree77d1446dd002f67c48567cac224b22260ae96355
parentb4830a4a3a98874293e20b309e083a144c1b3609 (diff)
sfeed_html/sfeed_frames: simplify struct feed allocation
There's no need for a dynamic struct feed **. The required size is known (argc). Just allocate it in one go.
-rw-r--r--sfeed_frames.c18
-rw-r--r--sfeed_html.c18
2 files changed, 14 insertions, 22 deletions
diff --git a/sfeed_frames.c b/sfeed_frames.c
index dd50de1..972f9ce 100644
--- a/sfeed_frames.c
+++ b/sfeed_frames.c
@@ -8,7 +8,7 @@
#include "util.h"
-static struct feed **feeds;
+static struct feed *feeds;
static char *line;
static size_t linesize;
static time_t comparetime;
@@ -82,7 +82,7 @@ main(int argc, char *argv[])
if (pledge("stdio rpath wpath cpath", NULL) == -1)
err(1, "pledge");
- if (!(feeds = calloc(argc, sizeof(struct feed *))))
+ if (!(feeds = calloc(argc, sizeof(struct feed))))
err(1, "calloc");
if ((comparetime = time(NULL)) == -1)
@@ -111,20 +111,16 @@ main(int argc, char *argv[])
"<body class=\"frame\"><div id=\"items\">", fpitems);
if (argc == 1) {
- if (!(feeds[0] = calloc(1, sizeof(struct feed))))
- err(1, "calloc");
- feeds[0]->name = "";
- printfeed(fpitems, stdin, feeds[0]);
+ feeds[0].name = "";
+ printfeed(fpitems, stdin, &feeds[0]);
} else {
for (i = 1; i < argc; i++) {
- if (!(feeds[i - 1] = calloc(1, sizeof(struct feed))))
- err(1, "calloc");
name = ((name = strrchr(argv[i], '/'))) ? name + 1 : argv[i];
- feeds[i - 1]->name = name;
+ feeds[i - 1].name = name;
if (!(fp = fopen(argv[i], "r")))
err(1, "fopen: %s", argv[i]);
- printfeed(fpitems, fp, feeds[i - 1]);
+ printfeed(fpitems, fp, &feeds[i - 1]);
if (ferror(fp))
err(1, "ferror: %s", argv[i]);
fclose(fp);
@@ -142,7 +138,7 @@ main(int argc, char *argv[])
"<body class=\"frame\">\n<div id=\"sidebar\">\n", fpmenu);
for (i = 1; i < argc; i++) {
- f = feeds[i - 1];
+ f = &feeds[i - 1];
if (f->totalnew)
fputs("<a class=\"n\" href=\"items.html#", fpmenu);
else
diff --git a/sfeed_html.c b/sfeed_html.c
index caac47e..97318af 100644
--- a/sfeed_html.c
+++ b/sfeed_html.c
@@ -8,7 +8,7 @@
#include "util.h"
-static struct feed **feeds;
+static struct feed *feeds;
static int showsidebar;
static char *line;
static size_t linesize;
@@ -83,7 +83,7 @@ main(int argc, char *argv[])
if (pledge(argc == 1 ? "stdio" : "stdio rpath", NULL) == -1)
err(1, "pledge");
- if (!(feeds = calloc(argc, sizeof(struct feed *))))
+ if (!(feeds = calloc(argc, sizeof(struct feed))))
err(1, "calloc");
if ((comparetime = time(NULL)) == -1)
err(1, "time");
@@ -106,21 +106,17 @@ main(int argc, char *argv[])
fputs("\t\t<div id=\"items\" class=\"nosidebar\">\n", stdout);
if (argc == 1) {
- if (!(feeds[0] = calloc(1, sizeof(struct feed))))
- err(1, "calloc");
- feeds[0]->name = "";
- printfeed(stdin, feeds[0]);
+ feeds[0].name = "";
+ printfeed(stdin, &feeds[0]);
if (ferror(stdin))
err(1, "ferror: <stdin>:");
} else {
for (i = 1; i < argc; i++) {
- if (!(feeds[i - 1] = calloc(1, sizeof(struct feed))))
- err(1, "calloc");
name = ((name = strrchr(argv[i], '/'))) ? name + 1 : argv[i];
- feeds[i - 1]->name = name;
+ feeds[i - 1].name = name;
if (!(fp = fopen(argv[i], "r")))
err(1, "fopen: %s", argv[i]);
- printfeed(fp, feeds[i - 1]);
+ printfeed(fp, &feeds[i - 1]);
if (ferror(fp))
err(1, "ferror: %s", argv[i]);
fclose(fp);
@@ -132,7 +128,7 @@ main(int argc, char *argv[])
fputs("\t<div id=\"sidebar\">\n\t\t<ul>\n", stdout);
for (i = 1; i < argc; i++) {
- f = feeds[i - 1];
+ f = &feeds[i - 1];
if (f->totalnew > 0)
fputs("<li class=\"n\"><a href=\"#", stdout);
else