From 3dbdf1ccfa5f109f8d7489f913ed57aa8e9b5f11 Mon Sep 17 00:00:00 2001 From: Hiltjo Posthuma Date: Mon, 7 Mar 2022 12:13:15 +0100 Subject: bump version to 1.3 --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Makefile') diff --git a/Makefile b/Makefile index de4d489..7d35bb1 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ .POSIX: NAME = sfeed -VERSION = 1.2 +VERSION = 1.3 # curses theme, see themes/ directory. SFEED_THEME = mono -- cgit v1.2.3 From 49d22d1256498c449b44a80901887bc58b67148c Mon Sep 17 00:00:00 2001 From: NRK Date: Sat, 19 Mar 2022 16:45:02 +0600 Subject: rebuild sfeed_curses if the same theme changes --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Makefile') diff --git a/Makefile b/Makefile index 7d35bb1..349bbf2 100644 --- a/Makefile +++ b/Makefile @@ -112,7 +112,7 @@ ${OBJ}: ${HDR} .c.o: ${CC} -o $@ -c $< ${SFEED_CFLAGS} ${SFEED_CPPFLAGS} -sfeed_curses.o: sfeed_curses.c +sfeed_curses.o: sfeed_curses.c themes/${SFEED_THEME}.h ${CC} -o $@ -c sfeed_curses.c ${SFEED_CURSES_CFLAGS} ${SFEED_CURSES_CPPFLAGS} sfeed_curses: ${LIB} sfeed_curses.o -- cgit v1.2.3 From 7225f6f9274173e65d002c886789c0f24d2045a6 Mon Sep 17 00:00:00 2001 From: Hiltjo Posthuma Date: Sat, 2 Apr 2022 17:35:31 +0200 Subject: bump version to 1.4 --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Makefile') diff --git a/Makefile b/Makefile index 349bbf2..5098ee6 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ .POSIX: NAME = sfeed -VERSION = 1.3 +VERSION = 1.4 # curses theme, see themes/ directory. SFEED_THEME = mono -- cgit v1.2.3 From 41b46d04521618d33bb159cc963b1d8e6b6e173f Mon Sep 17 00:00:00 2001 From: Hiltjo Posthuma Date: Sat, 21 May 2022 11:34:58 +0200 Subject: bump version to 1.5 --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Makefile') diff --git a/Makefile b/Makefile index 5098ee6..0772230 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ .POSIX: NAME = sfeed -VERSION = 1.4 +VERSION = 1.5 # curses theme, see themes/ directory. SFEED_THEME = mono -- cgit v1.2.3 From 411f5e83c38da298175b69c572485a421f44fb28 Mon Sep 17 00:00:00 2001 From: Hiltjo Posthuma Date: Wed, 17 Aug 2022 16:47:52 +0200 Subject: bump version to 1.6 --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Makefile') diff --git a/Makefile b/Makefile index 0772230..9958954 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ .POSIX: NAME = sfeed -VERSION = 1.5 +VERSION = 1.6 # curses theme, see themes/ directory. SFEED_THEME = mono -- cgit v1.2.3 From 19a4c010f95ad17e02ca59e9949524e801ad22f2 Mon Sep 17 00:00:00 2001 From: Hiltjo Posthuma Date: Sat, 25 Feb 2023 14:40:11 +0100 Subject: bump version to 1.7 --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Makefile') diff --git a/Makefile b/Makefile index 9958954..d24de84 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ .POSIX: NAME = sfeed -VERSION = 1.6 +VERSION = 1.7 # curses theme, see themes/ directory. SFEED_THEME = mono -- cgit v1.2.3 From daf56f2cb0a6994c4be8f1b57f1eb4b4cb8c91ba Mon Sep 17 00:00:00 2001 From: Hiltjo Posthuma Date: Tue, 14 Mar 2023 18:30:47 +0100 Subject: Makefile: remove duplicate CPPFLAGS for sfeed_curses --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Makefile') diff --git a/Makefile b/Makefile index d24de84..c167614 100644 --- a/Makefile +++ b/Makefile @@ -26,7 +26,7 @@ SFEED_CPPFLAGS = -D_DEFAULT_SOURCE -D_XOPEN_SOURCE=700 -D_BSD_SOURCE SFEED_CURSES = sfeed_curses SFEED_CURSES_CFLAGS = ${CFLAGS} SFEED_CURSES_CPPFLAGS = -D_DEFAULT_SOURCE -D_XOPEN_SOURCE=700 -D_BSD_SOURCE \ - -DSFEED_THEME=\"themes/${SFEED_THEME}.h\" ${SFEED_CPPFLAGS} + -DSFEED_THEME=\"themes/${SFEED_THEME}.h\" SFEED_CURSES_LDFLAGS = ${LDFLAGS} -lcurses # Linux: some distros use ncurses and require -lncurses. -- cgit v1.2.3 From ced0dd7f8a01dedad3ba16c4cf209aea673c3e82 Mon Sep 17 00:00:00 2001 From: Hiltjo Posthuma Date: Mon, 10 Apr 2023 17:03:57 +0200 Subject: sfeed_json: add JSON output format tool This outputs the TSV data to JSON. It uses a subset of JSON Feed 1.1: https://www.jsonfeed.org/version/1.1/ --- Makefile | 1 + README | 1 + sfeed_json.1 | 48 +++++++++++++++++ sfeed_json.c | 171 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 221 insertions(+) create mode 100644 sfeed_json.1 create mode 100644 sfeed_json.c (limited to 'Makefile') diff --git a/Makefile b/Makefile index c167614..a8493ba 100644 --- a/Makefile +++ b/Makefile @@ -51,6 +51,7 @@ BIN = \ sfeed_frames\ sfeed_gopher\ sfeed_html\ + sfeed_json\ sfeed_mbox\ sfeed_opml_import\ sfeed_plain\ diff --git a/README b/README index e633a80..a0a4815 100644 --- a/README +++ b/README @@ -186,6 +186,7 @@ sfeed_curses - Format feed data (TSV) to a curses interface. sfeed_frames - Format feed data (TSV) to HTML file(s) with frames. sfeed_gopher - Format feed data (TSV) to Gopher files. sfeed_html - Format feed data (TSV) to HTML. +sfeed_json - Format feed data (TSV) to JSON Feed. sfeed_opml_export - Generate an OPML XML file from a sfeedrc config file. sfeed_opml_import - Generate a sfeedrc config file from an OPML XML file. sfeed_markread - Mark items as read/unread, for use with sfeed_curses. diff --git a/sfeed_json.1 b/sfeed_json.1 new file mode 100644 index 0000000..8bd6ab0 --- /dev/null +++ b/sfeed_json.1 @@ -0,0 +1,48 @@ +.Dd March 8, 2023 +.Dt SFEED_JSON 1 +.Os +.Sh NAME +.Nm sfeed_json +.Nd format feed data to JSON Feed +.Sh SYNOPSIS +.Nm +.Op Ar +.Sh DESCRIPTION +.Nm +formats feed data (TSV) from +.Xr sfeed 1 +from stdin or for each +.Ar file +to stdout as JSON Feed data. +If one or more +.Ar file +arguments are specified then the basename of the +.Ar file +is used as the feed name in the output. +If no +.Ar file +arguments are specified and so the data is read from stdin then the feed name +is empty. +If +.Nm +is reading from one or more +.Ar file +arguments it will prefix the entry title with "[feed name] ". +.Sh EXIT STATUS +.Ex -std +.Sh EXAMPLES +.Bd -literal +curl -s 'https://codemadness.org/atom.xml' | sfeed | sfeed_json +.Ed +.Sh SEE ALSO +.Xr sfeed 1 , +.Xr sfeed_atom 1 , +.Xr sfeed 5 +.Sh STANDARDS +.Rs +.%T JSON Feed Version 1.1 +.%U https://www.jsonfeed.org/version/1.1/ +.%D Nov, 2022 +.Re +.Sh AUTHORS +.An Hiltjo Posthuma Aq Mt hiltjo@codemadness.org diff --git a/sfeed_json.c b/sfeed_json.c new file mode 100644 index 0000000..f6bb904 --- /dev/null +++ b/sfeed_json.c @@ -0,0 +1,171 @@ +#include +#include +#include +#include + +#include "util.h" + +static char *line; +static size_t linesize; +static int firstitem = 1; + +/* Unescape / decode fields printed by string_print_encoded() */ +static void +printcontent(const char *s) +{ + for (; *s; s++) { + switch (*s) { + case '\\': + s++; + switch (*s) { + case 'n': fputs("\\n", stdout); break; + case '\\': fputs("\\\\", stdout); break; + case 't': fputs("\\t", stdout); break; + } + break; /* ignore invalid escape sequence */ + case '"': fputs("\\\"", stdout); break; + default: + putchar(*s); + break; + } + } +} + +static void +printfield(const char *s) +{ + for (; *s; s++) { + if (*s == '\\') + fputs("\\\\", stdout); + else if (*s == '"') + fputs("\\\"", stdout); + else + putchar(*s); + } +} + +static void +printfeed(FILE *fp, const char *feedname) +{ + char *fields[FieldLast], timebuf[32]; + struct tm parsedtm, *tm; + time_t parsedtime; + ssize_t linelen; + int ch; + char *p, *s; + + while ((linelen = getline(&line, &linesize, fp)) > 0 && + !ferror(stdout)) { + if (line[linelen - 1] == '\n') + line[--linelen] = '\0'; + parseline(line, fields); + + if (!firstitem) + fputs(",\n", stdout); + firstitem = 0; + + fputs("{\n\t\"id\": \"", stdout); + printfield(fields[FieldId]); + fputs("\"", stdout); + + parsedtime = 0; + if (!strtotime(fields[FieldUnixTimestamp], &parsedtime) && + (tm = gmtime_r(&parsedtime, &parsedtm)) && + strftime(timebuf, sizeof(timebuf), "%Y-%m-%dT%H:%M:%SZ", tm)) { + fputs(",\n\t\"date_published\": \"", stdout); + fputs(timebuf, stdout); + fputs("\"", stdout); + } + + fputs(",\n\t\"title\": \"", stdout); + if (feedname[0]) { + fputs("[", stdout); + printfield(feedname); + fputs("] ", stdout); + } + printfield(fields[FieldTitle]); + fputs("\"", stdout); + + if (fields[FieldLink][0]) { + fputs(",\n\t\"url\": \"", stdout); + printfield(fields[FieldLink]); + fputs("\"", stdout); + } + + if (fields[FieldAuthor][0]) { + fputs(",\n\t\"authors\": [{\"name\": \"", stdout); + printfield(fields[FieldAuthor]); + fputs("\"}]", stdout); + } + + if (fields[FieldCategory][0]) { + fputs(",\n\t\"tags\": [", stdout); + + for (p = s = fields[FieldCategory]; ; s++) { + if (*s == '|' || *s == '\0') { + if (p != fields[FieldCategory]) + fputs(", ", stdout); + ch = *s; + *s = '\0'; /* temporary NUL terminate */ + fputs("\"", stdout); + printfield(p); + fputs("\"", stdout); + *s = ch; /* restore */ + p = s + 1; + } + if (*s == '\0') + break; + } + fputs("]", stdout); + } + + if (fields[FieldEnclosure][0]) { + fputs(",\n\t\"attachments\": [{\"url:\": \"", stdout); + printfield(fields[FieldEnclosure]); + fputs("\"}]", stdout); + } + + if (!strcmp(fields[FieldContentType], "html")) + fputs(",\n\t\"content_html\": \"", stdout); + else + fputs(",\n\t\"content_text\": \"", stdout); + printcontent(fields[FieldContent]); + fputs("\"\n}", stdout); + } +} + +int +main(int argc, char *argv[]) +{ + FILE *fp; + char *name; + int i; + + if (pledge(argc == 1 ? "stdio" : "stdio rpath", NULL) == -1) + err(1, "pledge"); + + fputs("{\n" + "\"version\": \"https://jsonfeed.org/version/1.1\",\n" + "\"title\": \"Newsfeed\",\n" + "\"items\": [\n", stdout); + + if (argc == 1) { + printfeed(stdin, ""); + checkfileerror(stdin, "", 'r'); + } else { + for (i = 1; i < argc; i++) { + if (!(fp = fopen(argv[i], "r"))) + err(1, "fopen: %s", argv[i]); + name = ((name = strrchr(argv[i], '/'))) ? name + 1 : argv[i]; + printfeed(fp, name); + checkfileerror(fp, argv[i], 'r'); + checkfileerror(stdout, "", 'w'); + fclose(fp); + } + } + fputs("]\n}\n", stdout); + + checkfileerror(stdout, "", 'w'); + + return 0; +} -- cgit v1.2.3 From aed47142611e23b363298bbb534c5cc4bd11a86b Mon Sep 17 00:00:00 2001 From: Hiltjo Posthuma Date: Sun, 23 Apr 2023 14:03:55 +0200 Subject: bump version to 1.8 --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Makefile') diff --git a/Makefile b/Makefile index a8493ba..fbe2aa1 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ .POSIX: NAME = sfeed -VERSION = 1.7 +VERSION = 1.8 # curses theme, see themes/ directory. SFEED_THEME = mono -- cgit v1.2.3 From ea04ae0101ae0607295ebea0a23364d31d1d37aa Mon Sep 17 00:00:00 2001 From: Hiltjo Posthuma Date: Wed, 9 Aug 2023 23:04:21 +0200 Subject: Makefile: change -lcurses to -lncurses for Gentoo in the comment Reported by commodorian, thanks! --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Makefile') diff --git a/Makefile b/Makefile index fbe2aa1..9a02987 100644 --- a/Makefile +++ b/Makefile @@ -34,7 +34,7 @@ SFEED_CURSES_LDFLAGS = ${LDFLAGS} -lcurses # Gentoo Linux: some distros might also require -ltinfo and -D_DEFAULT_SOURCE # to prevent warnings about feature test macros. -#SFEED_CURSES_LDFLAGS = ${LDFLAGS} -lcurses -ltinfo +#SFEED_CURSES_LDFLAGS = ${LDFLAGS} -lncurses -ltinfo # FreeBSD: unset feature test macros for SIGWINCH etc. #SFEED_CURSES_CPPFLAGS = -- cgit v1.2.3 From c43e677d80f5eae1e05bcb71d88008fb8ded8cab Mon Sep 17 00:00:00 2001 From: Hiltjo Posthuma Date: Fri, 18 Aug 2023 18:40:05 +0200 Subject: bump version to 1.9 --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Makefile') diff --git a/Makefile b/Makefile index 9a02987..b8f6f64 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ .POSIX: NAME = sfeed -VERSION = 1.8 +VERSION = 1.9 # curses theme, see themes/ directory. SFEED_THEME = mono -- cgit v1.2.3 From 1f76c85ab88f0a1a36c7769a0b8ac13b9072105b Mon Sep 17 00:00:00 2001 From: Hiltjo Posthuma Date: Fri, 29 Dec 2023 14:29:04 +0100 Subject: bump version to 2.0 --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Makefile') diff --git a/Makefile b/Makefile index b8f6f64..3acea14 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ .POSIX: NAME = sfeed -VERSION = 1.9 +VERSION = 2.0 # curses theme, see themes/ directory. SFEED_THEME = mono -- cgit v1.2.3