sfeed

simple feed reader - forked from git.codemadness.org/sfeed
git clone git://src.gearsix.net/sfeed
Log | Files | Refs | Atom | README | LICENSE

commit 1b14e601434435f48dfe1027a117c2af3dac325b
parent b4830a4a3a98874293e20b309e083a144c1b3609
Author: Hiltjo Posthuma <hiltjo@codemadness.org>
Date:   Sun, 21 Jun 2020 18:08:41 +0200

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.

Diffstat:
Msfeed_frames.c | 18+++++++-----------
Msfeed_html.c | 18+++++++-----------
2 files changed, 14 insertions(+), 22 deletions(-)

diff --git 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 @@ -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