From 13d7a0cd875bf24a5fe5bf3df8aa0d7f52ab1102 Mon Sep 17 00:00:00 2001 From: Hiltjo Posthuma Date: Thu, 24 Feb 2022 00:24:20 +0100 Subject: sfeed_curses: add keybinds for home key and home and end key in urxvt \x1b[1~ home (putty and some terminals). \x1b[7~ urxvt home. \x1b[8~ urxvt end. Refactor repeated code also. --- sfeed_curses.c | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) (limited to 'sfeed_curses.c') diff --git a/sfeed_curses.c b/sfeed_curses.c index d12f170..299baaa 100644 --- a/sfeed_curses.c +++ b/sfeed_curses.c @@ -2112,23 +2112,25 @@ main(int argc, char *argv[]) case 'D': goto keyleft; /* arrow right */ case 'F': goto endpos; /* end */ case 'H': goto startpos; /* home */ + case '1': /* home */ case '4': /* end */ - if ((ch = readch()) < 0) - goto event; - if (ch == '~') - goto endpos; - continue; case '5': /* page up */ - if ((ch = readch()) < 0) - goto event; - if (ch == '~') - goto prevpage; - continue; case '6': /* page down */ + case '7': /* home: urxvt */ + case '8': /* end: urxvt */ + i = ch; if ((ch = readch()) < 0) goto event; - if (ch == '~') - goto nextpage; + if (ch == '~') { + switch (i) { + case '1': goto startpos; + case '4': goto endpos; + case '5': goto prevpage; + case '6': goto nextpage; + case '7': goto startpos; + case '8': goto endpos; + } + } continue; } break; -- cgit v1.2.3 From 3c2de33c958405c282a0d27d4bdddda434dbfa99 Mon Sep 17 00:00:00 2001 From: Hiltjo Posthuma Date: Thu, 24 Feb 2022 00:37:32 +0100 Subject: sfeed_curses: fix a wrong comment about the arrow left and right keys Add autocmd comment. --- sfeed_curses.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'sfeed_curses.c') diff --git a/sfeed_curses.c b/sfeed_curses.c index 299baaa..4072fdd 100644 --- a/sfeed_curses.c +++ b/sfeed_curses.c @@ -952,7 +952,7 @@ readch(void) struct timeval tv; if (cmdenv && *cmdenv) - return *(cmdenv++); + return *(cmdenv++); /* $SFEED_AUTOCMD */ for (;;) { FD_ZERO(&readfds); @@ -2108,8 +2108,8 @@ main(int argc, char *argv[]) break; case 'A': goto keyup; /* arrow up */ case 'B': goto keydown; /* arrow down */ - case 'C': goto keyright; /* arrow left */ - case 'D': goto keyleft; /* arrow right */ + case 'C': goto keyright; /* arrow right */ + case 'D': goto keyleft; /* arrow left */ case 'F': goto endpos; /* end */ case 'H': goto startpos; /* home */ case '1': /* home */ -- cgit v1.2.3 From 23736959669760b02644d3042ff67950d1d61a9e Mon Sep 17 00:00:00 2001 From: Hiltjo Posthuma Date: Thu, 24 Feb 2022 00:39:30 +0100 Subject: sfeed_curses: die(): use stdio buffered function/macro vdprintf() was changed back to vfprintf() in commit 06bb4583, but the write was not changed. Change it to be more consistent and use the stdio buffered functions/macro. --- sfeed_curses.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'sfeed_curses.c') diff --git a/sfeed_curses.c b/sfeed_curses.c index 4072fdd..4be111f 100644 --- a/sfeed_curses.c +++ b/sfeed_curses.c @@ -229,8 +229,8 @@ die(const char *fmt, ...) if (saved_errno) fprintf(stderr, ": %s", strerror(saved_errno)); + putc('\n', stderr); fflush(stderr); - write(2, "\n", 1); _exit(1); } -- cgit v1.2.3 From 43a4e46c50ab81bd82b856e244d9b186dfd0cdf9 Mon Sep 17 00:00:00 2001 From: Hiltjo Posthuma Date: Thu, 24 Feb 2022 00:50:08 +0100 Subject: sfeed_curses: fix a redraw when reloading a file when reading from stdin When reading data from stdin and changing the URL file externally in some way and then pressing 'R' would not redraw (and highlight/unhighlight) the marked items. --- sfeed_curses.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'sfeed_curses.c') diff --git a/sfeed_curses.c b/sfeed_curses.c index 4be111f..c911f67 100644 --- a/sfeed_curses.c +++ b/sfeed_curses.c @@ -1205,6 +1205,7 @@ updatenewitems(struct feed *f) size_t i; p = &panes[PaneItems]; + p->dirty = 1; f->totalnew = 0; for (i = 0; i < p->nrows; i++) { row = &(p->rows[i]); /* do not use pane_row_get() */ @@ -1238,8 +1239,6 @@ feed_load(struct feed *f, FILE *fp) p->rows[i].data = &(items.items[i]); /* do not use pane_row_get() */ updatenewitems(f); - - p->dirty = 1; } void -- cgit v1.2.3 From 4a9456848a45edbc097770df20dec216f44ca0f5 Mon Sep 17 00:00:00 2001 From: Hiltjo Posthuma Date: Thu, 24 Feb 2022 19:25:06 +0100 Subject: sfeed_curses: remove continue in application key handling On an unknown or invalid sequence just use the key handling like the other keys do. --- sfeed_curses.c | 1 - 1 file changed, 1 deletion(-) (limited to 'sfeed_curses.c') diff --git a/sfeed_curses.c b/sfeed_curses.c index c911f67..da0b0a9 100644 --- a/sfeed_curses.c +++ b/sfeed_curses.c @@ -2130,7 +2130,6 @@ main(int argc, char *argv[]) case '8': goto endpos; } } - continue; } break; keyup: -- cgit v1.2.3 From c1d2ebe8cac049808be400221c3ed4bda780cab7 Mon Sep 17 00:00:00 2001 From: Hiltjo Posthuma Date: Fri, 25 Feb 2022 00:27:22 +0100 Subject: sfeed_curses: cast character for SFEED_AUTOCMD to unsigned char Otherwise a character like \xa0 (160) would be negative and goto the event, since a negative return value in readch() is used for errors or reserved for signal handling. Noticed while testing mouse X10 encoding with extended buttons, like button 7: SFEED_AUTOCMD="l$(printf '\x1b[M\xa0!!')j" ./sfeed_curses ~/.sfeed/feeds/* --- sfeed_curses.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'sfeed_curses.c') diff --git a/sfeed_curses.c b/sfeed_curses.c index da0b0a9..4d77504 100644 --- a/sfeed_curses.c +++ b/sfeed_curses.c @@ -951,8 +951,10 @@ readch(void) fd_set readfds; struct timeval tv; - if (cmdenv && *cmdenv) - return *(cmdenv++); /* $SFEED_AUTOCMD */ + if (cmdenv && *cmdenv) { + b = *(cmdenv++); /* $SFEED_AUTOCMD */ + return (int)b; + } for (;;) { FD_ZERO(&readfds); -- cgit v1.2.3 From b6f7a3fe15f2f253a1653454f514b467aa20f821 Mon Sep 17 00:00:00 2001 From: Hiltjo Posthuma Date: Mon, 14 Mar 2022 13:25:52 +0100 Subject: improve time(NULL) error checking Use errx, time(NULL) does not set errno. For sfeed_curses reset errno so it doesn't print a random error if it failed. POSIX recommends checking against (time_t)-1 on failure. Note that some implementation, like the OpenBSD man page says time() cannot fail. --- sfeed_atom.c | 4 ++-- sfeed_curses.c | 3 ++- sfeed_frames.c | 4 ++-- sfeed_gopher.c | 4 ++-- sfeed_html.c | 4 ++-- sfeed_mbox.c | 4 ++-- sfeed_plain.c | 4 ++-- 7 files changed, 14 insertions(+), 13 deletions(-) (limited to 'sfeed_curses.c') diff --git a/sfeed_atom.c b/sfeed_atom.c index 1dff75b..2aea54e 100644 --- a/sfeed_atom.c +++ b/sfeed_atom.c @@ -124,8 +124,8 @@ main(int argc, char *argv[]) if (pledge(argc == 1 ? "stdio" : "stdio rpath", NULL) == -1) err(1, "pledge"); - if ((now = time(NULL)) == -1) - err(1, "time"); + if ((now = time(NULL)) == (time_t)-1) + errx(1, "time"); if (!(tm = gmtime_r(&now, &tmnow))) err(1, "gmtime_r"); diff --git a/sfeed_curses.c b/sfeed_curses.c index 4d77504..1c6bc24 100644 --- a/sfeed_curses.c +++ b/sfeed_curses.c @@ -1308,7 +1308,8 @@ feeds_load(struct feed *feeds, size_t nfeeds) struct feed *f; size_t i; - if ((comparetime = time(NULL)) == -1) + errno = 0; + if ((comparetime = time(NULL)) == (time_t)-1) die("time"); /* 1 day is old news */ comparetime -= 86400; diff --git a/sfeed_frames.c b/sfeed_frames.c index 89838cc..d345c60 100644 --- a/sfeed_frames.c +++ b/sfeed_frames.c @@ -86,8 +86,8 @@ main(int argc, char *argv[]) if (!(feeds = calloc(argc, sizeof(struct feed)))) err(1, "calloc"); - if ((comparetime = time(NULL)) == -1) - err(1, "time"); + if ((comparetime = time(NULL)) == (time_t)-1) + errx(1, "time"); /* 1 day is old news */ comparetime -= 86400; diff --git a/sfeed_gopher.c b/sfeed_gopher.c index 9e8e10a..0b95b3d 100644 --- a/sfeed_gopher.c +++ b/sfeed_gopher.c @@ -137,8 +137,8 @@ main(int argc, char *argv[]) err(1, "pledge"); } - if ((comparetime = time(NULL)) == -1) - err(1, "time"); + if ((comparetime = time(NULL)) == (time_t)-1) + errx(1, "time"); /* 1 day is old news */ comparetime -= 86400; diff --git a/sfeed_html.c b/sfeed_html.c index d8abda7..240ea66 100644 --- a/sfeed_html.c +++ b/sfeed_html.c @@ -86,8 +86,8 @@ main(int argc, char *argv[]) if (!(feeds = calloc(argc, sizeof(struct feed)))) err(1, "calloc"); - if ((comparetime = time(NULL)) == -1) - err(1, "time"); + if ((comparetime = time(NULL)) == (time_t)-1) + errx(1, "time"); /* 1 day is old news */ comparetime -= 86400; diff --git a/sfeed_mbox.c b/sfeed_mbox.c index 6419d16..c2827d4 100644 --- a/sfeed_mbox.c +++ b/sfeed_mbox.c @@ -152,8 +152,8 @@ main(int argc, char *argv[]) user = "you"; if (gethostname(host, sizeof(host)) == -1) err(1, "gethostname"); - if ((now = time(NULL)) == -1) - err(1, "time"); + if ((now = time(NULL)) == (time_t)-1) + errx(1, "time"); if (!gmtime_r(&now, &tmnow)) err(1, "gmtime_r: can't get current time"); if (!strftime(mtimebuf, sizeof(mtimebuf), "%a %b %d %H:%M:%S %Y", &tmnow)) diff --git a/sfeed_plain.c b/sfeed_plain.c index df93a5a..45785e7 100644 --- a/sfeed_plain.c +++ b/sfeed_plain.c @@ -62,8 +62,8 @@ main(int argc, char *argv[]) if (pledge(argc == 1 ? "stdio" : "stdio rpath", NULL) == -1) err(1, "pledge"); - if ((comparetime = time(NULL)) == -1) - err(1, "time"); + if ((comparetime = time(NULL)) == (time_t)-1) + errx(1, "time"); /* 1 day is old news */ comparetime -= 86400; -- cgit v1.2.3 From 813a96b517ae96716fb018ff93ab2d6a4bbcda95 Mon Sep 17 00:00:00 2001 From: Hiltjo Posthuma Date: Mon, 14 Mar 2022 14:07:20 +0100 Subject: sfeed_curses: use ttywrite() for writing to the tty consistently This should also suppress a compiler warning of an unchecked write() return value. --- sfeed_curses.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'sfeed_curses.c') diff --git a/sfeed_curses.c b/sfeed_curses.c index 1c6bc24..d0ca7dd 100644 --- a/sfeed_curses.c +++ b/sfeed_curses.c @@ -986,7 +986,7 @@ lineeditor(void) int ch; for (;;) { - if (nchars + 1 >= cap) { + if (nchars + 2 >= cap) { cap = cap ? cap * 2 : 32; input = erealloc(input, cap); } @@ -999,11 +999,11 @@ lineeditor(void) if (!nchars) continue; input[--nchars] = '\0'; - write(1, "\b \b", 3); /* back, blank, back */ - continue; + ttywrite("\b \b"); /* back, blank, back */ } else if (ch >= ' ') { input[nchars] = ch; - write(1, &input[nchars], 1); + input[nchars + 1] = '\0'; + ttywrite(&input[nchars]); nchars++; } else if (ch < 0) { switch (sigstate) { -- cgit v1.2.3 From cae75cf30a64158f2120f28df0a02475fb970bcc Mon Sep 17 00:00:00 2001 From: Hiltjo Posthuma Date: Wed, 16 Mar 2022 18:57:02 +0100 Subject: sfeed_curses: refactor DEC function key parsing First it expected a single digit number, but this way it makes it more easy and logical to add Sun function keys: ESC [ num z For archive/reference Sun function keys relevant to sfeed_curses: num = 214: home 216: page up 220: end 222: page down Noticed on OpenIndiana/Illumos. --- sfeed_curses.c | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) (limited to 'sfeed_curses.c') diff --git a/sfeed_curses.c b/sfeed_curses.c index d0ca7dd..484593b 100644 --- a/sfeed_curses.c +++ b/sfeed_curses.c @@ -2114,24 +2114,26 @@ main(int argc, char *argv[]) case 'D': goto keyleft; /* arrow left */ case 'F': goto endpos; /* end */ case 'H': goto startpos; /* home */ - case '1': /* home */ - case '4': /* end */ - case '5': /* page up */ - case '6': /* page down */ - case '7': /* home: urxvt */ - case '8': /* end: urxvt */ - i = ch; - if ((ch = readch()) < 0) - goto event; - if (ch == '~') { - switch (i) { - case '1': goto startpos; - case '4': goto endpos; - case '5': goto prevpage; - case '6': goto nextpage; - case '7': goto startpos; - case '8': goto endpos; + default: + if (!(ch >= '0' && ch <= '9')) + break; + for (i = ch - '0'; ;) { + if ((ch = readch()) < 0) { + goto event; + } else if (ch >= '0' && ch <= '9') { + i = (i * 10) + (ch - '0'); + continue; + } else if (ch == '~') { /* DEC: ESC [ num ~ */ + switch (i) { + case 1: goto startpos; /* home */ + case 4: goto endpos; /* end */ + case 5: goto prevpage; /* page up */ + case 6: goto nextpage; /* page down */ + case 7: goto startpos; /* home: urxvt */ + case 8: goto endpos; /* end: urxvt */ + } } + break; } } break; -- cgit v1.2.3 From db1dcafd03997127f2cbc82376e2cc8df9b77356 Mon Sep 17 00:00:00 2001 From: Hiltjo Posthuma Date: Fri, 25 Mar 2022 23:18:58 +0100 Subject: rm sys/types.h include and improve portability This include is not needed. It was intended for ssize_t but this is already defined by stdio.h for getline(). --- sfeed_atom.c | 2 -- sfeed_curses.c | 1 - sfeed_frames.c | 2 -- sfeed_gopher.c | 2 -- sfeed_html.c | 2 -- sfeed_plain.c | 2 -- sfeed_twtxt.c | 2 -- 7 files changed, 13 deletions(-) (limited to 'sfeed_curses.c') diff --git a/sfeed_atom.c b/sfeed_atom.c index 3ce5cf0..c74e5fa 100644 --- a/sfeed_atom.c +++ b/sfeed_atom.c @@ -1,5 +1,3 @@ -#include - #include #include #include diff --git a/sfeed_curses.c b/sfeed_curses.c index 484593b..0d878f7 100644 --- a/sfeed_curses.c +++ b/sfeed_curses.c @@ -4,7 +4,6 @@ #include #include -#include #include #include #include diff --git a/sfeed_frames.c b/sfeed_frames.c index 178a4a2..7fcf3ee 100644 --- a/sfeed_frames.c +++ b/sfeed_frames.c @@ -1,5 +1,3 @@ -#include - #include #include #include diff --git a/sfeed_gopher.c b/sfeed_gopher.c index 7da41f6..0d3ea38 100644 --- a/sfeed_gopher.c +++ b/sfeed_gopher.c @@ -1,5 +1,3 @@ -#include - #include #include #include diff --git a/sfeed_html.c b/sfeed_html.c index ce96687..ebc9acd 100644 --- a/sfeed_html.c +++ b/sfeed_html.c @@ -1,5 +1,3 @@ -#include - #include #include #include diff --git a/sfeed_plain.c b/sfeed_plain.c index 8b1f00f..732eb04 100644 --- a/sfeed_plain.c +++ b/sfeed_plain.c @@ -1,5 +1,3 @@ -#include - #include #include #include diff --git a/sfeed_twtxt.c b/sfeed_twtxt.c index 1d8ab36..1bb9d3b 100644 --- a/sfeed_twtxt.c +++ b/sfeed_twtxt.c @@ -1,5 +1,3 @@ -#include - #include #include #include -- cgit v1.2.3 From 33ae34357f371f45ecb5f988bcdd961372130565 Mon Sep 17 00:00:00 2001 From: Hiltjo Posthuma Date: Sun, 27 Mar 2022 12:32:31 +0200 Subject: sfeed_curses: avoid non-interactive plumb process becoming a zombie From POSIX: Consequences of Process Termination: https://pubs.opengroup.org/onlinepubs/9699919799/functions/_Exit.html#tag_16_01_03_01 " [XSI] [Option Start] If the parent process of the calling process has set its SA_NOCLDWAIT flag or has set the action for the SIGCHLD signal to SIG_IGN: The process' status information (see Status Information), if any, shall be discarded. The lifetime of the calling process shall end immediately. If SA_NOCLDWAIT is set, it is implementation-defined whether a SIGCHLD signal is sent to the parent process. If a thread in the parent process of the calling process is blocked in wait(), waitpid(), or waitid(), and the parent process has no remaining child processes in the set of waited-for children, the wait(), waitid(), or waitpid() function shall fail and set errno to [ECHILD]. " Noticed on Linux (but not on OpenBSD). To reproduce: - SFEED_PLUMBER_INTERACTIVE=0 SFEED_PLUMBER="less" sfeed_curses ~/.sfeed/feeds/* - Then open and close the child program. - Notice it becoming a zombie or "" in the process table. --- sfeed_curses.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'sfeed_curses.c') diff --git a/sfeed_curses.c b/sfeed_curses.c index 0d878f7..6f151d4 100644 --- a/sfeed_curses.c +++ b/sfeed_curses.c @@ -558,6 +558,9 @@ init(void) sigaction(SIGINT, &sa, NULL); sigaction(SIGTERM, &sa, NULL); sigaction(SIGWINCH, &sa, NULL); + /* ignore SIGCHLD: for non-interactive programs: don't become a zombie */ + sa.sa_handler = SIG_IGN; + sigaction(SIGCHLD, &sa, NULL); } void -- cgit v1.2.3 From b2264d5892343e61594d703330b85c33172ce00a Mon Sep 17 00:00:00 2001 From: Hiltjo Posthuma Date: Sun, 27 Mar 2022 12:40:07 +0200 Subject: sfeed_curses: processexit: do not set and reset SIGINT for non-interactive plumbing Only set/override it in the interactive case. Also add some comments. No functional change intended. --- sfeed_curses.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) (limited to 'sfeed_curses.c') diff --git a/sfeed_curses.c b/sfeed_curses.c index 6f151d4..86a6f11 100644 --- a/sfeed_curses.c +++ b/sfeed_curses.c @@ -569,22 +569,20 @@ processexit(pid_t pid, int interactive) pid_t wpid; struct sigaction sa; - memset(&sa, 0, sizeof(sa)); - sigemptyset(&sa.sa_mask); - sa.sa_flags = SA_RESTART; /* require BSD signal semantics */ - sa.sa_handler = SIG_IGN; - sigaction(SIGINT, &sa, NULL); - if (interactive) { + /* ignore SIGINT (^C) in parent in interactive applications */ + memset(&sa, 0, sizeof(sa)); + sigemptyset(&sa.sa_mask); + sa.sa_flags = SA_RESTART; /* require BSD signal semantics */ + sa.sa_handler = SIG_IGN; + sigaction(SIGINT, &sa, NULL); + /* wait for process to change state */ while ((wpid = wait(NULL)) >= 0 && wpid != pid) ; init(); updatesidebar(); updategeom(); updatetitle(); - } else { - sa.sa_handler = sighandler; - sigaction(SIGINT, &sa, NULL); } } -- cgit v1.2.3 From b75648df800e43cf32492c204d21663f013cff40 Mon Sep 17 00:00:00 2001 From: Hiltjo Posthuma Date: Sun, 27 Mar 2022 12:50:49 +0200 Subject: sfeed_curses: tiny rewording in comment --- sfeed_curses.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'sfeed_curses.c') diff --git a/sfeed_curses.c b/sfeed_curses.c index 86a6f11..b5d1901 100644 --- a/sfeed_curses.c +++ b/sfeed_curses.c @@ -570,7 +570,7 @@ processexit(pid_t pid, int interactive) struct sigaction sa; if (interactive) { - /* ignore SIGINT (^C) in parent in interactive applications */ + /* ignore SIGINT (^C) in parent for interactive applications */ memset(&sa, 0, sizeof(sa)); sigemptyset(&sa.sa_mask); sa.sa_flags = SA_RESTART; /* require BSD signal semantics */ -- cgit v1.2.3 From ebc33326e1da17131171a76a9136c1f1af4f0c55 Mon Sep 17 00:00:00 2001 From: Hiltjo Posthuma Date: Sun, 27 Mar 2022 14:57:05 +0200 Subject: Revert "rm sys/types.h include and improve portability" This reverts commit db1dcafd03997127f2cbc82376e2cc8df9b77356. This is needed. Tested on an (old) Slackware 11 install. --- sfeed_atom.c | 2 ++ sfeed_curses.c | 1 + sfeed_frames.c | 2 ++ sfeed_gopher.c | 2 ++ sfeed_html.c | 2 ++ sfeed_plain.c | 2 ++ sfeed_twtxt.c | 2 ++ 7 files changed, 13 insertions(+) (limited to 'sfeed_curses.c') diff --git a/sfeed_atom.c b/sfeed_atom.c index c74e5fa..3ce5cf0 100644 --- a/sfeed_atom.c +++ b/sfeed_atom.c @@ -1,3 +1,5 @@ +#include + #include #include #include diff --git a/sfeed_curses.c b/sfeed_curses.c index b5d1901..7d16b05 100644 --- a/sfeed_curses.c +++ b/sfeed_curses.c @@ -4,6 +4,7 @@ #include #include +#include #include #include #include diff --git a/sfeed_frames.c b/sfeed_frames.c index 7fcf3ee..178a4a2 100644 --- a/sfeed_frames.c +++ b/sfeed_frames.c @@ -1,3 +1,5 @@ +#include + #include #include #include diff --git a/sfeed_gopher.c b/sfeed_gopher.c index 0d3ea38..7da41f6 100644 --- a/sfeed_gopher.c +++ b/sfeed_gopher.c @@ -1,3 +1,5 @@ +#include + #include #include #include diff --git a/sfeed_html.c b/sfeed_html.c index ebc9acd..ce96687 100644 --- a/sfeed_html.c +++ b/sfeed_html.c @@ -1,3 +1,5 @@ +#include + #include #include #include diff --git a/sfeed_plain.c b/sfeed_plain.c index 732eb04..8b1f00f 100644 --- a/sfeed_plain.c +++ b/sfeed_plain.c @@ -1,3 +1,5 @@ +#include + #include #include #include diff --git a/sfeed_twtxt.c b/sfeed_twtxt.c index 1bb9d3b..1d8ab36 100644 --- a/sfeed_twtxt.c +++ b/sfeed_twtxt.c @@ -1,3 +1,5 @@ +#include + #include #include #include -- cgit v1.2.3 From ab0c25faa0f5378aaeb0f7b219ecdfb649c043f9 Mon Sep 17 00:00:00 2001 From: Hiltjo Posthuma Date: Sun, 27 Mar 2022 14:57:36 +0200 Subject: sfeed_curses: remove unneeded ctype.h include --- sfeed_curses.c | 1 - 1 file changed, 1 deletion(-) (limited to 'sfeed_curses.c') diff --git a/sfeed_curses.c b/sfeed_curses.c index 7d16b05..b5d1901 100644 --- a/sfeed_curses.c +++ b/sfeed_curses.c @@ -4,7 +4,6 @@ #include #include -#include #include #include #include -- cgit v1.2.3 From 30a70fa2dab1925b0eaea04f67e3f86b360386dd Mon Sep 17 00:00:00 2001 From: Hiltjo Posthuma Date: Mon, 28 Mar 2022 15:54:03 +0200 Subject: sfeed_curses: ignore SIGCHLD only for non-interactive programs This is a regression from the introduced change. Else wait(&status) returned -1 and status was uninitialized. The status of the returned program in the markread() function is used to visually show it as read/unread. If the program failed it is assumed the program could not mark it and so it is visually unchanged. Just to be sure also initialize status to -1 (which can never happen normally) since the exitstatus range is 0-255. https://man.openbsd.org/wait#ERRORS [ECHILD]: "No status from the terminated child process is available because the calling process has asked the system to discard such status by ignoring the signal SIGCHLD or setting the flag SA_NOCLDWAIT for that signal." --- sfeed_curses.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'sfeed_curses.c') diff --git a/sfeed_curses.c b/sfeed_curses.c index b5d1901..00189a0 100644 --- a/sfeed_curses.c +++ b/sfeed_curses.c @@ -558,9 +558,6 @@ init(void) sigaction(SIGINT, &sa, NULL); sigaction(SIGTERM, &sa, NULL); sigaction(SIGWINCH, &sa, NULL); - /* ignore SIGCHLD: for non-interactive programs: don't become a zombie */ - sa.sa_handler = SIG_IGN; - sigaction(SIGCHLD, &sa, NULL); } void @@ -583,6 +580,10 @@ processexit(pid_t pid, int interactive) updatesidebar(); updategeom(); updatetitle(); + } else { + /* ignore SIGCHLD: for non-interactive programs: don't become a zombie */ + sa.sa_handler = SIG_IGN; + sigaction(SIGCHLD, &sa, NULL); } } @@ -1836,7 +1837,7 @@ markread(struct pane *p, off_t from, off_t to, int isread) FILE *fp; off_t i; const char *cmd; - int isnew = !isread, pid, wpid, status, visstart; + int isnew = !isread, pid, wpid, status = -1, visstart; if (!urlfile || !p->nrows) return; -- cgit v1.2.3 From a58fa45f25da4f18d7b8c1a815884f67b965406f Mon Sep 17 00:00:00 2001 From: Hiltjo Posthuma Date: Mon, 28 Mar 2022 18:01:22 +0200 Subject: sfeed_curses: fix-up from previous commit: properly initialize struct sigaction --- sfeed_curses.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'sfeed_curses.c') diff --git a/sfeed_curses.c b/sfeed_curses.c index 00189a0..abd6740 100644 --- a/sfeed_curses.c +++ b/sfeed_curses.c @@ -566,11 +566,12 @@ processexit(pid_t pid, int interactive) pid_t wpid; struct sigaction sa; + memset(&sa, 0, sizeof(sa)); + sigemptyset(&sa.sa_mask); + sa.sa_flags = SA_RESTART; /* require BSD signal semantics */ + if (interactive) { /* ignore SIGINT (^C) in parent for interactive applications */ - memset(&sa, 0, sizeof(sa)); - sigemptyset(&sa.sa_mask); - sa.sa_flags = SA_RESTART; /* require BSD signal semantics */ sa.sa_handler = SIG_IGN; sigaction(SIGINT, &sa, NULL); /* wait for process to change state */ -- cgit v1.2.3 From a6a8f296664be3d652015dd26bdaf3e2101e7f04 Mon Sep 17 00:00:00 2001 From: Hiltjo Posthuma Date: Thu, 31 Mar 2022 22:54:48 +0200 Subject: sfeed_curses: improve waiting on processes and reaping them - Wait on the exact process id and get its status. - Handle SIGCHLD explicitly and reap zombie children: ignoring them by using sigaction(SIGCHLD, &sa, NULL); would be racy in this case because sfeed_curses has interactive and non-interactive programs. Note while testing: if the markread program would be slow and in the meantime a plumb process would exit. This signal is now pending and is a zombie process until the SIGCHLD signal can be processed. This is fine. This also fixes a regression from commit 30a70fa2dab1925b0eaea04f67e3f86b360386dd because SIGCHLD was ignored in the parent for interactive processes aswell. This broke reading the exit status of the markread program, reproducable by plumbing an item and then trying to mark it as read (with SFEED_URL_FILE set). --- sfeed_curses.c | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) (limited to 'sfeed_curses.c') diff --git a/sfeed_curses.c b/sfeed_curses.c index abd6740..64fb314 100644 --- a/sfeed_curses.c +++ b/sfeed_curses.c @@ -554,6 +554,7 @@ init(void) sigemptyset(&sa.sa_mask); sa.sa_flags = SA_RESTART; /* require BSD signal semantics */ sa.sa_handler = sighandler; + sigaction(SIGCHLD, &sa, NULL); sigaction(SIGHUP, &sa, NULL); sigaction(SIGINT, &sa, NULL); sigaction(SIGTERM, &sa, NULL); @@ -563,7 +564,6 @@ init(void) void processexit(pid_t pid, int interactive) { - pid_t wpid; struct sigaction sa; memset(&sa, 0, sizeof(sa)); @@ -574,17 +574,12 @@ processexit(pid_t pid, int interactive) /* ignore SIGINT (^C) in parent for interactive applications */ sa.sa_handler = SIG_IGN; sigaction(SIGINT, &sa, NULL); - /* wait for process to change state */ - while ((wpid = wait(NULL)) >= 0 && wpid != pid) - ; + /* wait for process to change state, ignore errors */ + waitpid(pid, NULL, 0); init(); updatesidebar(); updategeom(); updatetitle(); - } else { - /* ignore SIGCHLD: for non-interactive programs: don't become a zombie */ - sa.sa_handler = SIG_IGN; - sigaction(SIGCHLD, &sa, NULL); } } @@ -1010,6 +1005,7 @@ lineeditor(void) } else if (ch < 0) { switch (sigstate) { case 0: + case SIGCHLD: case SIGWINCH: /* continue editing: process signal later */ continue; @@ -1582,6 +1578,7 @@ void sighandler(int signo) { switch (signo) { + case SIGCHLD: case SIGHUP: case SIGINT: case SIGTERM: @@ -1838,7 +1835,7 @@ markread(struct pane *p, off_t from, off_t to, int isread) FILE *fp; off_t i; const char *cmd; - int isnew = !isread, pid, wpid, status = -1, visstart; + int isnew = !isread, pid, status = -1, visstart; if (!urlfile || !p->nrows) return; @@ -1869,11 +1866,9 @@ markread(struct pane *p, off_t from, off_t to, int isread) status = WIFEXITED(status) ? WEXITSTATUS(status) : 127; _exit(status); default: - while ((wpid = wait(&status)) >= 0 && wpid != pid) - ; - - /* fail: exit statuscode was non-zero */ - if (status) + /* waitpid() and block on process status change, + fail if exit statuscode was unavailable or non-zero */ + if (waitpid(pid, &status, 0) <= 0 || status) break; visstart = p->pos - (p->pos % p->height); /* visible start */ @@ -2343,6 +2338,14 @@ event: continue; /* just a time-out, nothing to do */ switch (sigstate) { + case SIGCHLD: + /* wait on child processes so they don't become a zombie, + do not block the parent process if there is no status, + ignore errors */ + while (waitpid((pid_t)-1, NULL, WNOHANG) > 0) + ; + sigstate = 0; + break; case SIGHUP: feeds_reloadall(); sigstate = 0; -- cgit v1.2.3 From b4344cc3b01ff098b8e3cc06aebf8a097dac78d3 Mon Sep 17 00:00:00 2001 From: Hiltjo Posthuma Date: Fri, 1 Apr 2022 00:15:03 +0200 Subject: sfeed_curses: improve multiple signal handling Keep a bitmask of the received signals and handle them all. Also handle them in a particular order now. --- sfeed_curses.c | 64 +++++++++++++++++++++++----------------------------------- 1 file changed, 25 insertions(+), 39 deletions(-) (limited to 'sfeed_curses.c') diff --git a/sfeed_curses.c b/sfeed_curses.c index 64fb314..55791f0 100644 --- a/sfeed_curses.c +++ b/sfeed_curses.c @@ -172,7 +172,8 @@ static time_t comparetime; static char *urlfile, **urls; static size_t nurls; -volatile sig_atomic_t sigstate = 0; +enum Signals { SigChld = 1, SigHup = 2, SigInt = 4, SigTerm = 8, SigWinch = 16 }; +volatile sig_atomic_t sigstate = 0; /* bitmask state of received signals */ static char *plumbercmd = "xdg-open"; /* env variable: $SFEED_PLUMBER */ static char *pipercmd = "sfeed_content"; /* env variable: $SFEED_PIPER */ @@ -1003,22 +1004,12 @@ lineeditor(void) ttywrite(&input[nchars]); nchars++; } else if (ch < 0) { - switch (sigstate) { - case 0: - case SIGCHLD: - case SIGWINCH: - /* continue editing: process signal later */ - continue; - case SIGINT: - /* cancel prompt, but do not quit */ - sigstate = 0; /* reset: do not handle it */ - break; - default: /* other: SIGHUP, SIGTERM */ - /* cancel prompt and handle signal after */ - break; - } + if (sigstate & SigInt) + sigstate &= ~SigInt; /* reset: do not handle it later */ + else if (!sigstate || (sigstate & (SigChld | SigWinch))) + continue; /* do not cancel: process signal later */ free(input); - return NULL; + return NULL; /* cancel prompt */ } } return input; @@ -1578,15 +1569,11 @@ void sighandler(int signo) { switch (signo) { - case SIGCHLD: - case SIGHUP: - case SIGINT: - case SIGTERM: - case SIGWINCH: - /* SIGTERM is more important, do not override it */ - if (sigstate != SIGTERM) - sigstate = signo; - break; + case SIGCHLD: sigstate |= SigChld; break; + case SIGHUP: sigstate |= SigHup; break; + case SIGINT: sigstate |= SigInt; break; + case SIGTERM: sigstate |= SigTerm; break; + case SIGWINCH: sigstate |= SigWinch; break; } } @@ -2337,28 +2324,27 @@ event: else if (ch == -3 && sigstate == 0) continue; /* just a time-out, nothing to do */ - switch (sigstate) { - case SIGCHLD: + /* handle signals, in order of importance */ + if (sigstate & SigChld) { + sigstate &= ~SigChld; /* wait on child processes so they don't become a zombie, do not block the parent process if there is no status, ignore errors */ while (waitpid((pid_t)-1, NULL, WNOHANG) > 0) ; - sigstate = 0; - break; - case SIGHUP: - feeds_reloadall(); - sigstate = 0; - break; - case SIGINT: - case SIGTERM: + } + if (sigstate & (SigInt | SigTerm)) { cleanup(); - _exit(128 + sigstate); - case SIGWINCH: + _exit(128 + (sigstate & SigTerm ? SIGTERM : SIGINT)); + } + if (sigstate & SigHup) { + sigstate &= ~SigHup; + feeds_reloadall(); + } + if (sigstate & SigWinch) { + sigstate &= ~SigWinch; resizewin(); updategeom(); - sigstate = 0; - break; } draw(); -- cgit v1.2.3 From 6279bf321ee17d9aff27843dfc78b601df8cbd35 Mon Sep 17 00:00:00 2001 From: Hiltjo Posthuma Date: Fri, 1 Apr 2022 00:57:49 +0200 Subject: sfeed_curses: small code-style change --- sfeed_curses.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'sfeed_curses.c') diff --git a/sfeed_curses.c b/sfeed_curses.c index 55791f0..52dba93 100644 --- a/sfeed_curses.c +++ b/sfeed_curses.c @@ -1569,10 +1569,10 @@ void sighandler(int signo) { switch (signo) { - case SIGCHLD: sigstate |= SigChld; break; - case SIGHUP: sigstate |= SigHup; break; - case SIGINT: sigstate |= SigInt; break; - case SIGTERM: sigstate |= SigTerm; break; + case SIGCHLD: sigstate |= SigChld; break; + case SIGHUP: sigstate |= SigHup; break; + case SIGINT: sigstate |= SigInt; break; + case SIGTERM: sigstate |= SigTerm; break; case SIGWINCH: sigstate |= SigWinch; break; } } @@ -2324,7 +2324,7 @@ event: else if (ch == -3 && sigstate == 0) continue; /* just a time-out, nothing to do */ - /* handle signals, in order of importance */ + /* handle signals in a particular order */ if (sigstate & SigChld) { sigstate &= ~SigChld; /* wait on child processes so they don't become a zombie, -- cgit v1.2.3 From b2d6839a8c025698cd80118331f21fa4bb459f02 Mon Sep 17 00:00:00 2001 From: Hiltjo Posthuma Date: Fri, 1 Apr 2022 21:24:22 +0200 Subject: sfeed_curses: don't use bitmasks to keep the states for signals Reported by Leon Fisher, thanks! "Each signal should have its own sig_atomic_t variable if you want to keep state for all of them independently." A similar issue was referenced in a OpenBSD tech mailinglist thread: https://marc.info/?l=openbsd-tech&m=162940120614641&w=2 --- sfeed_curses.c | 45 ++++++++++++++++++++++++++------------------- 1 file changed, 26 insertions(+), 19 deletions(-) (limited to 'sfeed_curses.c') diff --git a/sfeed_curses.c b/sfeed_curses.c index 52dba93..4f92115 100644 --- a/sfeed_curses.c +++ b/sfeed_curses.c @@ -172,8 +172,8 @@ static time_t comparetime; static char *urlfile, **urls; static size_t nurls; -enum Signals { SigChld = 1, SigHup = 2, SigInt = 4, SigTerm = 8, SigWinch = 16 }; -volatile sig_atomic_t sigstate = 0; /* bitmask state of received signals */ +volatile sig_atomic_t state_sigchld = 0, state_sighup = 0, state_sigint = 0; +volatile sig_atomic_t state_sigterm = 0, state_sigwinch = 0; static char *plumbercmd = "xdg-open"; /* env variable: $SFEED_PLUMBER */ static char *pipercmd = "sfeed_content"; /* env variable: $SFEED_PIPER */ @@ -1004,9 +1004,11 @@ lineeditor(void) ttywrite(&input[nchars]); nchars++; } else if (ch < 0) { - if (sigstate & SigInt) - sigstate &= ~SigInt; /* reset: do not handle it later */ - else if (!sigstate || (sigstate & (SigChld | SigWinch))) + if (state_sigint) + state_sigint = 0; /* reset: do not handle it later */ + else if (state_sighup || state_sigterm) + ; /* cancel prompt and handle these signals */ + else /* no signal, time-out or SIGCHLD or SIGWINCH */ continue; /* do not cancel: process signal later */ free(input); return NULL; /* cancel prompt */ @@ -1569,11 +1571,11 @@ void sighandler(int signo) { switch (signo) { - case SIGCHLD: sigstate |= SigChld; break; - case SIGHUP: sigstate |= SigHup; break; - case SIGINT: sigstate |= SigInt; break; - case SIGTERM: sigstate |= SigTerm; break; - case SIGWINCH: sigstate |= SigWinch; break; + case SIGCHLD: state_sigchld = 1; break; + case SIGHUP: state_sighup = 1; break; + case SIGINT: state_sigint = 1; break; + case SIGTERM: state_sigterm = 1; break; + case SIGWINCH: state_sigwinch = 1; break; } } @@ -2321,28 +2323,33 @@ nextpage: event: if (ch == EOF) goto end; - else if (ch == -3 && sigstate == 0) + else if (ch == -3 && !state_sigchld && !state_sighup && + !state_sigint && !state_sigterm && !state_sigwinch) continue; /* just a time-out, nothing to do */ /* handle signals in a particular order */ - if (sigstate & SigChld) { - sigstate &= ~SigChld; + if (state_sigchld) { + state_sigchld = 0; /* wait on child processes so they don't become a zombie, do not block the parent process if there is no status, ignore errors */ while (waitpid((pid_t)-1, NULL, WNOHANG) > 0) ; } - if (sigstate & (SigInt | SigTerm)) { + if (state_sigterm) { cleanup(); - _exit(128 + (sigstate & SigTerm ? SIGTERM : SIGINT)); + _exit(128 + SIGTERM); } - if (sigstate & SigHup) { - sigstate &= ~SigHup; + if (state_sigint) { + cleanup(); + _exit(128 + SIGINT); + } + if (state_sighup) { + state_sighup = 0; feeds_reloadall(); } - if (sigstate & SigWinch) { - sigstate &= ~SigWinch; + if (state_sigwinch) { + state_sigwinch = 0; resizewin(); updategeom(); } -- cgit v1.2.3 From 3eb3533fae6c43907adbd340b24bee79f709504e Mon Sep 17 00:00:00 2001 From: Hiltjo Posthuma Date: Sat, 2 Apr 2022 00:32:28 +0200 Subject: sfeed_curses: line editor, temporarily disable the mouse when using the line editor This allows pasting in the terminal and also doesnt spam mouse events, which are not useful here. --- sfeed_curses.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'sfeed_curses.c') diff --git a/sfeed_curses.c b/sfeed_curses.c index 4f92115..a12b41f 100644 --- a/sfeed_curses.c +++ b/sfeed_curses.c @@ -983,6 +983,8 @@ lineeditor(void) size_t cap = 0, nchars = 0; int ch; + if (usemouse) + mousemode(0); for (;;) { if (nchars + 2 >= cap) { cap = cap ? cap * 2 : 32; @@ -1011,9 +1013,12 @@ lineeditor(void) else /* no signal, time-out or SIGCHLD or SIGWINCH */ continue; /* do not cancel: process signal later */ free(input); - return NULL; /* cancel prompt */ + input = NULL; + break; /* cancel prompt */ } } + if (usemouse) + mousemode(usemouse); return input; } -- cgit v1.2.3 From f4c4b97bba99c7848bf3cda287564db8219b0f40 Mon Sep 17 00:00:00 2001 From: Hiltjo Posthuma Date: Sat, 2 Apr 2022 00:33:29 +0200 Subject: sfeed_curses: line editor: handle SIGCHLD directly This makes sure when processes exit they are reaped immediately (instead of after closing the line editor). --- sfeed_curses.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'sfeed_curses.c') diff --git a/sfeed_curses.c b/sfeed_curses.c index a12b41f..03c38fe 100644 --- a/sfeed_curses.c +++ b/sfeed_curses.c @@ -1006,12 +1006,19 @@ lineeditor(void) ttywrite(&input[nchars]); nchars++; } else if (ch < 0) { + if (state_sigchld) { + state_sigchld = 0; + /* wait on child processes so they don't become a zombie */ + while (waitpid((pid_t)-1, NULL, WNOHANG) > 0) + ; + } if (state_sigint) - state_sigint = 0; /* reset: do not handle it later */ + state_sigint = 0; /* cancel prompt and don't handle this signal */ else if (state_sighup || state_sigterm) ; /* cancel prompt and handle these signals */ else /* no signal, time-out or SIGCHLD or SIGWINCH */ continue; /* do not cancel: process signal later */ + free(input); input = NULL; break; /* cancel prompt */ -- cgit v1.2.3 From 031b279e81cf461584789c00ce7d10c4f1d0d90f Mon Sep 17 00:00:00 2001 From: Hiltjo Posthuma Date: Sat, 2 Apr 2022 13:54:49 +0200 Subject: sfeed_curses: code-style: mouse mode: just use a constant No functional change intended. Just slightly more clear. --- sfeed_curses.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'sfeed_curses.c') diff --git a/sfeed_curses.c b/sfeed_curses.c index 03c38fe..d09f8a0 100644 --- a/sfeed_curses.c +++ b/sfeed_curses.c @@ -549,7 +549,7 @@ init(void) cursormode(0); if (usemouse) - mousemode(usemouse); + mousemode(1); memset(&sa, 0, sizeof(sa)); sigemptyset(&sa.sa_mask); @@ -1025,7 +1025,7 @@ lineeditor(void) } } if (usemouse) - mousemode(usemouse); + mousemode(1); return input; } -- cgit v1.2.3 From 78e54359372d02d17e9ab453c7bc0cd725b807f2 Mon Sep 17 00:00:00 2001 From: Hiltjo Posthuma Date: Thu, 5 May 2022 06:28:11 +0200 Subject: sfeed_curses: close stdin for spawning a plumb program in non-interactive mode This is only for plumbing in non-interactive mode in forkexec(), but not piping content. Probably obvious what the descriptors are, but also add a few comments to dup2 of the file descriptors (stdin, stdout, stderr). To reproduce a behaviour: Plumb script: #!/bin/sh dmenu Then launch it: SFEED_PLUMB_INTERACTIVE=0 SFEED_PLUMB=thescript sfeed_curses ~/.sfeed/feeds/* The program now waits on input while in non-interactive mode and only seems to hang. After: The program starts but just has no input passed to it. --- sfeed_curses.1 | 3 ++- sfeed_curses.c | 13 +++++++------ 2 files changed, 9 insertions(+), 7 deletions(-) (limited to 'sfeed_curses.c') diff --git a/sfeed_curses.1 b/sfeed_curses.1 index 30d6543..be68d92 100644 --- a/sfeed_curses.1 +++ b/sfeed_curses.1 @@ -1,4 +1,4 @@ -.Dd May 4, 2022 +.Dd May 5, 2022 .Dt SFEED_CURSES 1 .Os .Sh NAME @@ -290,6 +290,7 @@ In non-interactive mode .Nm doesn't wait until the process exits. Stdout and stderr of the program are not written as output. +When plumbing an URL then stdin is closed also. .Sh EXIT STATUS .Ex -std The exit status is 130 on SIGINT and 143 on SIGTERM. diff --git a/sfeed_curses.c b/sfeed_curses.c index d09f8a0..78071b7 100644 --- a/sfeed_curses.c +++ b/sfeed_curses.c @@ -604,8 +604,8 @@ pipeitem(const char *cmd, struct item *item, int field, int interactive) die("fork"); case 0: if (!interactive) { - dup2(devnullfd, 1); - dup2(devnullfd, 2); + dup2(devnullfd, 1); /* stdout */ + dup2(devnullfd, 2); /* stderr */ } errno = 0; @@ -642,8 +642,9 @@ forkexec(char *argv[], int interactive) die("fork"); case 0: if (!interactive) { - dup2(devnullfd, 1); - dup2(devnullfd, 2); + dup2(devnullfd, 0); /* stdin */ + dup2(devnullfd, 1); /* stdout */ + dup2(devnullfd, 2); /* stderr */ } if (execvp(argv[0], argv) == -1) _exit(1); @@ -1847,8 +1848,8 @@ markread(struct pane *p, off_t from, off_t to, int isread) case -1: die("fork"); case 0: - dup2(devnullfd, 1); - dup2(devnullfd, 2); + dup2(devnullfd, 1); /* stdout */ + dup2(devnullfd, 2); /* stderr */ errno = 0; if (!(fp = popen(cmd, "w"))) -- cgit v1.2.3 From c64dff716eced3fd554428b8d9e5d2f12ceac9e8 Mon Sep 17 00:00:00 2001 From: Hiltjo Posthuma Date: Sat, 7 May 2022 20:18:58 +0200 Subject: sfeed_curses: interrupt waitpid while interactive child program is running This now handles SIGTERM on sfeed_curses properly while an interactive child program is running. Test-case program: https://git.codemadness.org/sfeed_tests/commit/cd4268d4f71b5d7ab0df593d95e70188475d76bb.html --- sfeed_curses.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'sfeed_curses.c') diff --git a/sfeed_curses.c b/sfeed_curses.c index 78071b7..d22d16c 100644 --- a/sfeed_curses.c +++ b/sfeed_curses.c @@ -575,8 +575,14 @@ processexit(pid_t pid, int interactive) /* ignore SIGINT (^C) in parent for interactive applications */ sa.sa_handler = SIG_IGN; sigaction(SIGINT, &sa, NULL); + + sa.sa_flags = 0; /* do not restart SIGTERM: this interrupts waitpid() */ + sa.sa_handler = sighandler; + sigaction(SIGTERM, &sa, NULL); + /* wait for process to change state, ignore errors */ waitpid(pid, NULL, 0); + init(); updatesidebar(); updategeom(); -- cgit v1.2.3 From 8b7c95d1a6a3d640e0193f7ab0811694d62cd593 Mon Sep 17 00:00:00 2001 From: Hiltjo Posthuma Date: Sat, 7 May 2022 20:33:08 +0200 Subject: sfeed_curses: improve comment Do not restart the syscall waitpid, explicitly mention not setting SA_RESTART. --- sfeed_curses.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'sfeed_curses.c') diff --git a/sfeed_curses.c b/sfeed_curses.c index d22d16c..a38a25e 100644 --- a/sfeed_curses.c +++ b/sfeed_curses.c @@ -576,7 +576,7 @@ processexit(pid_t pid, int interactive) sa.sa_handler = SIG_IGN; sigaction(SIGINT, &sa, NULL); - sa.sa_flags = 0; /* do not restart SIGTERM: this interrupts waitpid() */ + sa.sa_flags = 0; /* SIGTERM: interrupt waitpid(), no SA_RESTART */ sa.sa_handler = sighandler; sigaction(SIGTERM, &sa, NULL); -- cgit v1.2.3 From cc3dd4534bcbbc750d563992b93b1131410a2a76 Mon Sep 17 00:00:00 2001 From: Hiltjo Posthuma Date: Sun, 5 Jun 2022 23:38:22 +0200 Subject: sfeed_curses: processexit(): remove unneeded code for non-interactive processes This was used in commit a58fa45f25da4f18d7b8c1a815884f67b965406f and previous, but the code for non-interactive process cleanup was later removed, so clearing the struct is not not needed anymore, because it is unused. --- sfeed_curses.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'sfeed_curses.c') diff --git a/sfeed_curses.c b/sfeed_curses.c index a38a25e..e05d1c9 100644 --- a/sfeed_curses.c +++ b/sfeed_curses.c @@ -567,11 +567,11 @@ processexit(pid_t pid, int interactive) { struct sigaction sa; - memset(&sa, 0, sizeof(sa)); - sigemptyset(&sa.sa_mask); - sa.sa_flags = SA_RESTART; /* require BSD signal semantics */ - if (interactive) { + memset(&sa, 0, sizeof(sa)); + sigemptyset(&sa.sa_mask); + sa.sa_flags = SA_RESTART; /* require BSD signal semantics */ + /* ignore SIGINT (^C) in parent for interactive applications */ sa.sa_handler = SIG_IGN; sigaction(SIGINT, &sa, NULL); -- cgit v1.2.3 From 6890a40099bf940bb7bf21c0f5b073766ff67f5f Mon Sep 17 00:00:00 2001 From: Hiltjo Posthuma Date: Tue, 5 Jul 2022 15:57:35 +0200 Subject: sfeed_curses: write out plumbercmd argument in a verbose manner Write it in a more verbose, clear and C90-style manner. This workarounds a bug in scc too (reported upstream and will be fixed of course). All tools in sfeed can now be compiled with minicurses-mode with the scc compiler and musl libc without any modifications needed. scc: http://www.simple-cc.org/ --- sfeed_curses.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'sfeed_curses.c') diff --git a/sfeed_curses.c b/sfeed_curses.c index e05d1c9..bc2e8ba 100644 --- a/sfeed_curses.c +++ b/sfeed_curses.c @@ -1432,13 +1432,15 @@ feed_plumb_selected_item(struct pane *p, int field) { struct row *row; struct item *item; - char *cmd[] = { plumbercmd, NULL, NULL }; + char *cmd[3]; /* will have: { plumbercmd, arg, NULL } */ if (!(row = pane_row_get(p, p->pos))) return; markread(p, p->pos, p->pos, 1); item = row->data; + cmd[0] = plumbercmd; cmd[1] = item->fields[field]; /* set first argument for plumber */ + cmd[2] = NULL; forkexec(cmd, plumberia); } -- cgit v1.2.3 From 7b2bec5985b79a73613c0858a845b97ad614794d Mon Sep 17 00:00:00 2001 From: NRK Date: Tue, 5 Jul 2022 21:11:37 +0600 Subject: remove __dead code this check is already done in util.h and is no longer needed after the `sfeed_curses -> sfeed` merge. --- sfeed_curses.c | 5 ----- 1 file changed, 5 deletions(-) (limited to 'sfeed_curses.c') diff --git a/sfeed_curses.c b/sfeed_curses.c index bc2e8ba..b75c2cc 100644 --- a/sfeed_curses.c +++ b/sfeed_curses.c @@ -208,11 +208,6 @@ ttywrite(const char *s) return write(1, s, strlen(s)); } -/* Hint for compilers and static analyzers that a function exits. */ -#ifndef __dead -#define __dead -#endif - /* Print to stderr, call cleanup() and _exit(). */ __dead void die(const char *fmt, ...) -- cgit v1.2.3 From 59ba2ed29bcbe67de6e9ee1e7fb18744f7490c22 Mon Sep 17 00:00:00 2001 From: Hiltjo Posthuma Date: Sun, 17 Jul 2022 12:46:34 +0200 Subject: sfeed_curses: cleanup code for handling read items from an URL file This makes it easier to reuse the code from reading plain-text list of items from a file and uses a struct urls to keep its state in a cleaner way. + some small code-style improvements and reshuffling. Inspired by a question from NRK by mail about implementing a "read later" feature. (A quick local experiment shows it can be done in ~70 lines of added code). --- sfeed_curses.c | 82 ++++++++++++++++++++++++++++++++-------------------------- 1 file changed, 45 insertions(+), 37 deletions(-) (limited to 'sfeed_curses.c') diff --git a/sfeed_curses.c b/sfeed_curses.c index b75c2cc..9f57ef9 100644 --- a/sfeed_curses.c +++ b/sfeed_curses.c @@ -129,10 +129,16 @@ struct item { off_t offset; /* line offset in file for lazyload */ }; +struct urls { + char **items; /* array of urls */ + size_t len; /* amount of items */ + size_t cap; /* available capacity */ +}; + struct items { - struct item *items; /* array of items */ - size_t len; /* amount of items */ - size_t cap; /* available capacity */ + struct item *items; /* array of items */ + size_t len; /* amount of items */ + size_t cap; /* available capacity */ }; void alldirty(void); @@ -144,9 +150,9 @@ void pane_draw(struct pane *); void sighandler(int); void updategeom(void); void updatesidebar(void); -void urls_free(void); -int urls_isnew(const char *); -void urls_read(void); +void urls_free(struct urls *); +int urls_hasmatch(struct urls *, const char *); +void urls_read(struct urls *, const char *); static struct linebar linebar; static struct statusbar statusbar; @@ -169,8 +175,8 @@ static struct feed *feeds; static struct feed *curfeed; static size_t nfeeds; /* amount of feeds */ static time_t comparetime; -static char *urlfile, **urls; -static size_t nurls; +struct urls urls; +static char *urlfile; volatile sig_atomic_t state_sigchld = 0, state_sighup = 0, state_sigint = 0; volatile sig_atomic_t state_sigterm = 0, state_sigwinch = 0; @@ -1197,9 +1203,9 @@ feed_items_get(struct feed *f, FILE *fp, struct items *itemsret) if (n <= 0 || feof(fp)) break; } - itemsret->cap = cap; itemsret->items = items; itemsret->len = nitems; + itemsret->cap = cap; free(line); } @@ -1218,7 +1224,7 @@ updatenewitems(struct feed *f) row = &(p->rows[i]); /* do not use pane_row_get() */ item = row->data; if (urlfile) - item->isnew = urls_isnew(item->matchnew); + item->isnew = !urls_hasmatch(&urls, item->matchnew); else item->isnew = (item->timeok && item->timestamp >= comparetime); row->bold = item->isnew; @@ -1264,7 +1270,7 @@ feed_count(struct feed *f, FILE *fp) parseline(line, fields); if (urlfile) { - f->totalnew += urls_isnew(fields[fields[FieldLink][0] ? FieldLink : FieldId]); + f->totalnew += !urls_hasmatch(&urls, fields[fields[FieldLink][0] ? FieldLink : FieldId]); } else { parsedtime = 0; if (!strtotime(fields[FieldUnixTimestamp], &parsedtime)) @@ -1383,9 +1389,9 @@ feeds_reloadall(void) pos = panes[PaneItems].pos; /* store numeric item position */ feeds_set(curfeed); /* close and reopen feed if possible */ - urls_read(); + urls_read(&urls, urlfile); feeds_load(feeds, nfeeds); - urls_free(); + urls_free(&urls); /* restore numeric item position */ pane_setpos(&panes[PaneItems], pos); updatesidebar(); @@ -1408,10 +1414,10 @@ feed_open_selected(struct pane *p) return; f = row->data; feeds_set(f); - urls_read(); + urls_read(&urls, urlfile); if (f->fp) feed_load(f, f->fp); - urls_free(); + urls_free(&urls); /* redraw row: counts could be changed */ updatesidebar(); updatetitle(); @@ -1901,32 +1907,34 @@ urls_cmp(const void *v1, const void *v2) return strcmp(*((char **)v1), *((char **)v2)); } -int -urls_isnew(const char *url) +void +urls_free(struct urls *urls) { - return (!nurls || - bsearch(&url, urls, nurls, sizeof(char *), urls_cmp) == NULL); + while (urls->len > 0) { + urls->len--; + free(urls->items[urls->len]); + } + urls->items = NULL; + urls->len = 0; + urls->cap = 0; } -void -urls_free(void) +int +urls_hasmatch(struct urls *urls, const char *url) { - while (nurls > 0) - free(urls[--nurls]); - free(urls); - urls = NULL; - nurls = 0; + return (urls->len && + bsearch(&url, urls->items, urls->len, sizeof(char *), urls_cmp)); } void -urls_read(void) +urls_read(struct urls *urls, const char *urlfile) { FILE *fp; char *line = NULL; - size_t linesiz = 0, cap = 0; + size_t linesiz = 0; ssize_t n; - urls_free(); + urls_free(urls); if (!urlfile) return; @@ -1936,19 +1944,19 @@ urls_read(void) while ((n = getline(&line, &linesiz, fp)) > 0) { if (line[n - 1] == '\n') line[--n] = '\0'; - if (nurls + 1 >= cap) { - cap = cap ? cap * 2 : 16; - urls = erealloc(urls, cap * sizeof(char *)); + if (urls->len + 1 >= urls->cap) { + urls->cap = urls->cap ? urls->cap * 2 : 16; + urls->items = erealloc(urls->items, urls->cap * sizeof(char *)); } - urls[nurls++] = estrdup(line); + urls->items[urls->len++] = estrdup(line); } if (ferror(fp)) die("getline: %s", urlfile); fclose(fp); free(line); - if (nurls > 0) - qsort(urls, nurls, sizeof(char *), urls_cmp); + if (urls->len > 0) + qsort(urls->items, urls->len, sizeof(char *), urls_cmp); } int @@ -2016,9 +2024,9 @@ main(int argc, char *argv[]) nfeeds = argc - 1; } feeds_set(&feeds[0]); - urls_read(); + urls_read(&urls, urlfile); feeds_load(feeds, nfeeds); - urls_free(); + urls_free(&urls); if (!isatty(0)) { if ((fd = open("/dev/tty", O_RDONLY)) == -1) -- cgit v1.2.3 From b6731ae35b125963a37dcaacaf76169992ad1f67 Mon Sep 17 00:00:00 2001 From: Hiltjo Posthuma Date: Wed, 20 Jul 2022 20:37:14 +0200 Subject: slightly improve some comments --- sfeed.c | 4 ++-- sfeed_curses.c | 2 +- sfeed_gopher.c | 2 +- sfeed_mbox.c | 4 ++-- xml.h | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) (limited to 'sfeed_curses.c') diff --git a/sfeed.c b/sfeed.c index 7b0ef6c..8a2843e 100644 --- a/sfeed.c +++ b/sfeed.c @@ -530,7 +530,7 @@ gettzoffset(const char *s) ; if (i != 3) return 0; - /* compare tz and adjust offset relative to UTC */ + /* compare timezone and adjust offset relative to UTC */ for (i = 0; i < sizeof(tzones) / sizeof(*tzones); i++) { if (!memcmp(s, tzones[i].name, 3)) return tzones[i].offhour; @@ -978,7 +978,7 @@ xmltagend(XMLParser *p, const char *t, size_t tl, int isshort) } else if (ctx.tag.id && istag(ctx.tag.name, ctx.tag.len, t, tl)) { /* matched tag end: close it */ /* copy also to the link field if the attribute isPermaLink="true" - and it is not set by a tag with higher prio. */ + and it is not set by a tag with higher priority. */ if (ctx.tag.id == RSSTagGuidPermalinkTrue && ctx.field && ctx.tag.id > ctx.fields[FeedFieldLink].tagid) { string_clear(&ctx.fields[FeedFieldLink].str); diff --git a/sfeed_curses.c b/sfeed_curses.c index 9f57ef9..b1a56d6 100644 --- a/sfeed_curses.c +++ b/sfeed_curses.c @@ -130,7 +130,7 @@ struct item { }; struct urls { - char **items; /* array of urls */ + char **items; /* array of URLs */ size_t len; /* amount of items */ size_t cap; /* available capacity */ }; diff --git a/sfeed_gopher.c b/sfeed_gopher.c index 7da41f6..b4ce7d9 100644 --- a/sfeed_gopher.c +++ b/sfeed_gopher.c @@ -65,7 +65,7 @@ printfeed(FILE *fpitems, FILE *fpin, struct feed *f) if (fields[FieldLink][0]) { itemtype = 'h'; - /* if it's a gopher URL then change it into a direntry */ + /* if it's a gopher URL then change it into a DirEntity */ if (!strncmp(fields[FieldLink], "gopher://", 9) && uri_parse(fields[FieldLink], &u) != -1) { itemhost = u.host; diff --git a/sfeed_mbox.c b/sfeed_mbox.c index 30ac875..0cfd836 100644 --- a/sfeed_mbox.c +++ b/sfeed_mbox.c @@ -22,8 +22,8 @@ djb2(unsigned char *s, unsigned long long hash) } /* Unescape / decode fields printed by string_print_encoded() - * "\\" to "\", "\t", to TAB, "\n" to newline. Unrecognised escape sequences - * are ignored: "\z" etc. Mangle "From " in mboxrd style (always prefix >). */ + * "\\" to "\", "\t", to TAB, "\n" to newline. Other escape sequences are + * ignored: "\z" etc. Mangle "From " in mboxrd style (always prefix >). */ static void printcontent(const char *s, FILE *fp) { diff --git a/xml.h b/xml.h index ad53396..cef4a05 100644 --- a/xml.h +++ b/xml.h @@ -30,7 +30,7 @@ typedef struct xmlparser { /* current tag */ char tag[1024]; size_t taglen; - /* current tag is in short form ? */ + /* current tag is in shortform ? */ int isshorttag; /* current attribute name */ char name[1024]; -- cgit v1.2.3 From d69467dff3c00ec0a17a5856ccbbe124a8eb7d99 Mon Sep 17 00:00:00 2001 From: Hiltjo Posthuma Date: Wed, 17 Aug 2022 01:34:10 +0200 Subject: sfeed_curses: fix a memleak caused by a mistake in refactoring the code Introduced by a code cleanup/refactor in commit 59ba2ed29bcbe67de6e9ee1e7fb18744f7490c22 --- sfeed_curses.c | 1 + 1 file changed, 1 insertion(+) (limited to 'sfeed_curses.c') diff --git a/sfeed_curses.c b/sfeed_curses.c index b1a56d6..4d2b698 100644 --- a/sfeed_curses.c +++ b/sfeed_curses.c @@ -1914,6 +1914,7 @@ urls_free(struct urls *urls) urls->len--; free(urls->items[urls->len]); } + free(urls->items); urls->items = NULL; urls->len = 0; urls->cap = 0; -- cgit v1.2.3 From dbb7f7b66d2d10a4bf14a404b66fa20cbf8a02ca Mon Sep 17 00:00:00 2001 From: Hiltjo Posthuma Date: Fri, 3 Feb 2023 16:15:35 +0100 Subject: fix comment for ASCII symbols for dumb terminals This was a copy-pasta. --- sfeed_curses.c | 6 +++--- util.h | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'sfeed_curses.c') diff --git a/sfeed_curses.c b/sfeed_curses.c index 4d2b698..abfa95b 100644 --- a/sfeed_curses.c +++ b/sfeed_curses.c @@ -37,10 +37,10 @@ #define LINEBAR_SYMBOL_BAR "\xe2\x94\x80" /* symbol: "light horizontal" */ #define LINEBAR_SYMBOL_RIGHT "\xe2\x94\xa4" /* symbol: "light vertical and left" */ #else -#define SCROLLBAR_SYMBOL_BAR "|" /* symbol: "light vertical" */ +#define SCROLLBAR_SYMBOL_BAR "|" #define SCROLLBAR_SYMBOL_TICK " " -#define LINEBAR_SYMBOL_BAR "-" /* symbol: "light horizontal" */ -#define LINEBAR_SYMBOL_RIGHT "|" /* symbol: "light vertical and left" */ +#define LINEBAR_SYMBOL_BAR "-" +#define LINEBAR_SYMBOL_RIGHT "|" #endif /* color-theme */ diff --git a/util.h b/util.h index fac6424..9138de7 100644 --- a/util.h +++ b/util.h @@ -26,8 +26,8 @@ size_t strlcpy(char *, const char *, size_t); #define PAD_TRUNCATE_SYMBOL "\xe2\x80\xa6" /* symbol: "ellipsis" */ #define UTF_INVALID_SYMBOL "\xef\xbf\xbd" /* symbol: "replacement" */ #else -#define PAD_TRUNCATE_SYMBOL "." /* symbol: "ellipsis" */ -#define UTF_INVALID_SYMBOL "?" /* symbol: "replacement" */ +#define PAD_TRUNCATE_SYMBOL "." +#define UTF_INVALID_SYMBOL "?" #endif /* feed info */ -- cgit v1.2.3 From f95834446f8d722cc09b4ed8eab642d1cc01c505 Mon Sep 17 00:00:00 2001 From: Hiltjo Posthuma Date: Thu, 16 Feb 2023 20:32:23 +0100 Subject: sfeed_curses: add SCO keys for next, prior (CSI I and CSI G) This fixes the page up and page down keys in the cons25 console on DragonFlyBSD. See also the table: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html Section "Non-Function Keys". --- sfeed_curses.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'sfeed_curses.c') diff --git a/sfeed_curses.c b/sfeed_curses.c index abfa95b..841f276 100644 --- a/sfeed_curses.c +++ b/sfeed_curses.c @@ -2119,12 +2119,15 @@ main(int argc, char *argv[]) mousereport(button, release, keymask, x - 1, y - 1); break; + /* DEC/SUN: ESC O char, HP: ESC char or SCO: ESC [ char */ case 'A': goto keyup; /* arrow up */ case 'B': goto keydown; /* arrow down */ case 'C': goto keyright; /* arrow right */ case 'D': goto keyleft; /* arrow left */ case 'F': goto endpos; /* end */ + case 'G': goto nextpage; /* page down */ case 'H': goto startpos; /* home */ + case 'I': goto prevpage; /* page up */ default: if (!(ch >= '0' && ch <= '9')) break; -- cgit v1.2.3 From eb635966d33e2718094aab9d6ee06b5655b8efeb Mon Sep 17 00:00:00 2001 From: Hiltjo Posthuma Date: Thu, 16 Feb 2023 20:33:51 +0100 Subject: sfeed_curses: add SUN keys support This fixes the keys on the sun-color console on OpenIndiana/Illumos/OpenSolaris (and other systems using these keys). See also the table: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html Section "Non-Function Keys". --- sfeed_curses.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'sfeed_curses.c') diff --git a/sfeed_curses.c b/sfeed_curses.c index 841f276..50080cf 100644 --- a/sfeed_curses.c +++ b/sfeed_curses.c @@ -2146,6 +2146,13 @@ main(int argc, char *argv[]) case 7: goto startpos; /* home: urxvt */ case 8: goto endpos; /* end: urxvt */ } + } else if (ch == 'z') { /* SUN: ESC [ num z */ + switch (i) { + case 214: goto startpos; /* home */ + case 216: goto prevpage; /* page up */ + case 220: goto endpos; /* end */ + case 222: goto nextpage; /* page down */ + } } break; } -- cgit v1.2.3 From 426fa33dd276fbe662b3794c41db1ab6d59b3c2a Mon Sep 17 00:00:00 2001 From: Hiltjo Posthuma Date: Tue, 7 Mar 2023 21:04:36 +0100 Subject: sfeed_curses: fix (very hard to trigger) memleak when getline() returns EOF for lazyloaded items Fix the code pattern of freeing the line when getline returns -1 but no error flag is set on the stream (such as EOF). Note that on errors (even ENOMEM: out-of-memory) an error flag is set on the stream and the process would exit and clean up all it's resources. This would be very hard to trigger. The following conditions would have to be true: * Lazyloading of items is enabled: SFEED_LAZYLOAD=1 is set. * Items of the feed are read and their offsets stored. * The line is read/lazy-loaded again by it's offset but returns EOF (not a read error) this time. This could maybe happen if the feed file was changed and made smaller while sfeed_curses is running and the remembered offset is now beyond the file. Note that the sfeed_curses(1) man page describes a workaround for a similar condition by sending SIGHUP if the sfeed(5) data was changed to reload the feed file. References: * https://man.openbsd.org/getline "It is the responsibility of the caller to free(3) *lineptr when it is no longer needed. Even when it fails, getdelim() may update *lineptr." * https://pubs.opengroup.org/onlinepubs/9699919799/functions/getline.html --- sfeed_curses.c | 1 + 1 file changed, 1 insertion(+) (limited to 'sfeed_curses.c') diff --git a/sfeed_curses.c b/sfeed_curses.c index 50080cf..1abb046 100644 --- a/sfeed_curses.c +++ b/sfeed_curses.c @@ -1791,6 +1791,7 @@ item_row_get(struct pane *p, off_t pos) if ((linelen = getline(&line, &linesize, f->fp)) <= 0) { if (ferror(f->fp)) die("getline: %s", f->path); + free(line); return NULL; } -- cgit v1.2.3 From 6e4136753bd0faa15c198118b05c529d96d908c5 Mon Sep 17 00:00:00 2001 From: Alvar Penning Date: Mon, 24 Apr 2023 22:01:23 +0200 Subject: sfeed_{curses,frames,gopher,html,plain}: SFEED_NEW_MAX_SECS By introducing the new environment variable $SFEED_NEW_MAX_SECS in all sfeed_* utilities marking feeds as new based on comparing their age, it is now possible to override this age limit. This allows, for example, to be notified about new feeds within the last hour with SFEED_NEW_MAX_SECS=3600 sfeed_plain ~/.sfeed/feeds/* while creating a beautiful web report for last week's news by SFEED_NEW_MAX_SECS=604800 sfeed_html ~/.sfeed/feeds/* --- README | 10 ++++++---- sfeed_curses.1 | 4 ++++ sfeed_curses.c | 11 ++++++++--- sfeed_frames.1 | 7 +++++++ sfeed_frames.c | 15 ++++++++++++--- sfeed_gopher.1 | 4 ++++ sfeed_gopher.c | 15 ++++++++++++--- sfeed_html.1 | 7 +++++++ sfeed_html.c | 15 ++++++++++++--- sfeed_plain.1 | 7 +++++++ sfeed_plain.c | 16 +++++++++++++--- 11 files changed, 92 insertions(+), 19 deletions(-) (limited to 'sfeed_curses.c') diff --git a/README b/README index 6892e89..313ab4c 100644 --- a/README +++ b/README @@ -289,10 +289,12 @@ Just like the other format programs included in sfeed you can run it like this: sfeed_curses < ~/.sfeed/feeds/xkcd -By default sfeed_curses marks the items of the last day as new/bold. To manage -read/unread items in a different way a plain-text file with a list of the read -URLs can be used. To enable this behaviour the path to this file can be -specified by setting the environment variable $SFEED_URL_FILE to the URL file: +By default sfeed_curses marks the items of the last day as new/bold. This limit +might be overridden by setting the environment variable $SFEED_NEW_MAX_SECS to +the desired maximum in seconds. To manage read/unread items in a different way +a plain-text file with a list of the read URLs can be used. To enable this +behaviour the path to this file can be specified by setting the environment +variable $SFEED_URL_FILE to the URL file: export SFEED_URL_FILE="$HOME/.sfeed/urls" [ -f "$SFEED_URL_FILE" ] || touch "$SFEED_URL_FILE" diff --git a/sfeed_curses.1 b/sfeed_curses.1 index 94ffd4c..b3cccf2 100644 --- a/sfeed_curses.1 +++ b/sfeed_curses.1 @@ -30,6 +30,7 @@ arguments are specified then the data is read from stdin and the feed name is .Pp Items with a timestamp from the last day compared to the system time at the time of loading the feed are marked as new and bold. +This value might be overridden through environment variables. There is also an alternative mode available to mark items as read by matching it against a list of URLs from a plain-text file. Items with an enclosure are marked with a @ symbol. @@ -207,6 +208,9 @@ SIGWINCH. Read and process a sequence of keys as input commands from this environment variable first, afterwards it reads from the tty as usual. This can be useful to automate certain actions at the start. +.It Ev SFEED_NEW_MAX_SECS +Overwrite the maximum age in seconds to mark feeds as new. +By default this is 86400, which equals one day. .It Ev SFEED_PIPER A program where the whole TAB-Separated Value line is piped to. By default this is "sfeed_content". diff --git a/sfeed_curses.c b/sfeed_curses.c index 1abb046..cce608e 100644 --- a/sfeed_curses.c +++ b/sfeed_curses.c @@ -191,6 +191,7 @@ static int plumberia = 0; /* env variable: $SFEED_PLUMBER_INTERACTIVE */ static int piperia = 1; /* env variable: $SFEED_PIPER_INTERACTIVE */ static int yankeria = 0; /* env variable: $SFEED_YANKER_INTERACTIVE */ static int lazyload = 0; /* env variable: $SFEED_LAZYLOAD */ +static int newmaxsecs = 86400; /* env variable: $SFEED_NEW_MAX_SECS */ int ttywritef(const char *fmt, ...) @@ -1322,8 +1323,7 @@ feeds_load(struct feed *feeds, size_t nfeeds) errno = 0; if ((comparetime = time(NULL)) == (time_t)-1) die("time"); - /* 1 day is old news */ - comparetime -= 86400; + comparetime -= newmaxsecs; for (i = 0; i < nfeeds; i++) { f = &feeds[i]; @@ -1967,7 +1967,7 @@ main(int argc, char *argv[]) struct pane *p; struct feed *f; struct row *row; - char *name, *tmp; + char *name, *tmp, *endptr; char *search = NULL; /* search text */ int button, ch, fd, i, keymask, release, x, y; off_t pos; @@ -1997,6 +1997,11 @@ main(int argc, char *argv[]) markunreadcmd = tmp; if ((tmp = getenv("SFEED_LAZYLOAD"))) lazyload = !strcmp(tmp, "1"); + if ((tmp = getenv("SFEED_NEW_MAX_SECS"))) { + newmaxsecs = (int) strtol(tmp, &endptr, 10); + if (*tmp == '\0' || *endptr != '\0' || newmaxsecs <= 0) + err(1, "cannot parse $SFEED_NEW_MAX_SECS"); + } urlfile = getenv("SFEED_URL_FILE"); /* can be NULL */ cmdenv = getenv("SFEED_AUTOCMD"); /* can be NULL */ diff --git a/sfeed_frames.1 b/sfeed_frames.1 index e29498b..976d5ed 100644 --- a/sfeed_frames.1 +++ b/sfeed_frames.1 @@ -23,6 +23,7 @@ file is not written. Items with a timestamp from the last day compared to the system time at the time of formatting are counted and marked as new. Items are marked as new using a bold markup. +This value might be overridden through environment variables. .Pp There is an example style.css stylesheet file included in the distribution. .Sh FILES WRITTEN @@ -37,6 +38,12 @@ feeds. The HTML file of the menu frame which contains navigation "anchor" links (like "#feedname") to the feed names in items.html. .El +.Sh ENVIRONMENT VARIABLES +.Bl -tag -width Ds +.It Ev SFEED_NEW_MAX_SECS +Overwrite the maximum age in seconds to mark feeds as new. +By default this is 86400, which equals one day. +.El .Sh EXIT STATUS .Ex -std .Sh EXAMPLES diff --git a/sfeed_frames.c b/sfeed_frames.c index 178a4a2..e52abd1 100644 --- a/sfeed_frames.c +++ b/sfeed_frames.c @@ -77,8 +77,9 @@ int main(int argc, char *argv[]) { FILE *fpindex, *fpitems, *fpmenu = NULL, *fp; - char *name; + char *name, *tmp, *endptr; int i, showsidebar = (argc > 1); + long l; struct feed *f; if (pledge("stdio rpath wpath cpath", NULL) == -1) @@ -89,8 +90,16 @@ main(int argc, char *argv[]) if ((comparetime = time(NULL)) == (time_t)-1) errx(1, "time"); - /* 1 day is old news */ - comparetime -= 86400; + + if ((tmp = getenv("SFEED_NEW_MAX_SECS"))) { + l = strtol(tmp, &endptr, 10); + if (*tmp == '\0' || *endptr != '\0' || l <= 0) + err(1, "cannot parse $SFEED_NEW_MAX_SECS"); + comparetime -= l; + } else { + /* 1 day is old news */ + comparetime -= 86400; + } /* write main index page */ if (!(fpindex = fopen("index.html", "wb"))) diff --git a/sfeed_gopher.1 b/sfeed_gopher.1 index 43a11c7..f602d2c 100644 --- a/sfeed_gopher.1 +++ b/sfeed_gopher.1 @@ -32,6 +32,7 @@ written to stdout and no files are written. .Pp Items with a timestamp from the last day compared to the system time at the time of formatting are counted and marked as new. +This value might be overridden through environment variables. Items are marked as new with the prefix "N" at the start of the line. .Sh ENVIRONMENT .Bl -tag -width Ds @@ -45,6 +46,9 @@ The default is "127.0.0.1". .It Ev SFEED_GOPHER_PORT This environment variable can be used as the Gopher Port field. The default is "70". +.It Ev SFEED_NEW_MAX_SECS +Overwrite the maximum age in seconds to mark feeds as new. +By default this is 86400, which equals one day. .El .Sh EXIT STATUS .Ex -std diff --git a/sfeed_gopher.c b/sfeed_gopher.c index f62c6ed..007a244 100644 --- a/sfeed_gopher.c +++ b/sfeed_gopher.c @@ -122,8 +122,9 @@ int main(int argc, char *argv[]) { FILE *fpitems, *fpindex, *fp; - char *name, *p; + char *name, *p, *tmp, *endptr; int i; + long l; if (argc == 1) { if (pledge("stdio", NULL) == -1) @@ -139,8 +140,16 @@ main(int argc, char *argv[]) if ((comparetime = time(NULL)) == (time_t)-1) errx(1, "time"); - /* 1 day is old news */ - comparetime -= 86400; + + if ((tmp = getenv("SFEED_NEW_MAX_SECS"))) { + l = strtol(tmp, &endptr, 10); + if (*tmp == '\0' || *endptr != '\0' || l <= 0) + err(1, "cannot parse $SFEED_NEW_MAX_SECS"); + comparetime -= l; + } else { + /* 1 day is old news */ + comparetime -= 86400; + } if ((p = getenv("SFEED_GOPHER_HOST"))) host = p; diff --git a/sfeed_html.1 b/sfeed_html.1 index efeb289..98784c5 100644 --- a/sfeed_html.1 +++ b/sfeed_html.1 @@ -26,9 +26,16 @@ is empty. .Pp Items with a timestamp from the last day compared to the system time at the time of formatting are counted and marked as new. +This value might be overridden through environment variables. Items are marked as new using a bold markup. .Pp There is an example style.css stylesheet file included in the distribution. +.Sh ENVIRONMENT VARIABLES +.Bl -tag -width Ds +.It Ev SFEED_NEW_MAX_SECS +Overwrite the maximum age in seconds to mark feeds as new. +By default this is 86400, which equals one day. +.El .Sh EXIT STATUS .Ex -std .Sh EXAMPLES diff --git a/sfeed_html.c b/sfeed_html.c index ce96687..89506be 100644 --- a/sfeed_html.c +++ b/sfeed_html.c @@ -78,9 +78,10 @@ int main(int argc, char *argv[]) { struct feed *f; - char *name; + char *name, *tmp, *endptr; FILE *fp; int i; + long l; if (pledge(argc == 1 ? "stdio" : "stdio rpath", NULL) == -1) err(1, "pledge"); @@ -89,8 +90,16 @@ main(int argc, char *argv[]) err(1, "calloc"); if ((comparetime = time(NULL)) == (time_t)-1) errx(1, "time"); - /* 1 day is old news */ - comparetime -= 86400; + + if ((tmp = getenv("SFEED_NEW_MAX_SECS"))) { + l = strtol(tmp, &endptr, 10); + if (*tmp == '\0' || *endptr != '\0' || l <= 0) + err(1, "cannot parse $SFEED_NEW_MAX_SECS"); + comparetime -= l; + } else { + /* 1 day is old news */ + comparetime -= 86400; + } fputs("\n" "\n" diff --git a/sfeed_plain.1 b/sfeed_plain.1 index 466ae41..93ed41d 100644 --- a/sfeed_plain.1 +++ b/sfeed_plain.1 @@ -26,6 +26,7 @@ is empty. .Pp Items with a timestamp from the last day compared to the system time at the time of formatting are marked as new. +This value might be overridden through environment variables. Items are marked as new with the prefix "N" at the start of the line. .Pp .Nm @@ -39,6 +40,12 @@ per rune, using .Xr mbtowc 3 and .Xr wcwidth 3 . +.Sh ENVIRONMENT VARIABLES +.Bl -tag -width Ds +.It Ev SFEED_NEW_MAX_SECS +Overwrite the maximum age in seconds to mark feeds as new. +By default this is 86400, which equals one day. +.El .Sh EXIT STATUS .Ex -std .Sh EXAMPLES diff --git a/sfeed_plain.c b/sfeed_plain.c index 8b1f00f..c790ec4 100644 --- a/sfeed_plain.c +++ b/sfeed_plain.c @@ -2,6 +2,7 @@ #include #include +#include #include #include @@ -52,8 +53,9 @@ int main(int argc, char *argv[]) { FILE *fp; - char *name; + char *name, *tmp, *endptr; int i; + long l; if (pledge("stdio rpath", NULL) == -1) err(1, "pledge"); @@ -65,8 +67,16 @@ main(int argc, char *argv[]) if ((comparetime = time(NULL)) == (time_t)-1) errx(1, "time"); - /* 1 day is old news */ - comparetime -= 86400; + + if ((tmp = getenv("SFEED_NEW_MAX_SECS"))) { + l = strtol(tmp, &endptr, 10); + if (*tmp == '\0' || *endptr != '\0' || l <= 0) + err(1, "cannot parse $SFEED_NEW_MAX_SECS"); + comparetime -= l; + } else { + /* 1 day is old news */ + comparetime -= 86400; + } if (argc == 1) { printfeed(stdin, ""); -- cgit v1.2.3 From bdcbf8589716c047a732db3cc349ee6114ccc25f Mon Sep 17 00:00:00 2001 From: Hiltjo Posthuma Date: Sun, 7 May 2023 12:39:26 +0200 Subject: iterate on previous commit which adds $SFEED_NEW_MAX_SECS Separate the common pattern to get the time to compare new items in format tools to the new util function: getcomparetime(). Some changes and notes: - Change it so it is OK to set this value to 0 or negative (in the future). - sfeed_curses: truncating newmaxsecs to an int would limit the value too much. - Just use strtotime() and parse the value to time_t. This is a signed long (32-bit, until 2038) or signed long long (64-bit) on most platforms. - sfeed_curses gets the comparison time on reload aswell and it needs errno = 0, because it uses die(). time() is not guaranteed to set an errno if it fails. - Rename environment variable to $SFEED_NEW_AGE. --- README | 6 +++--- sfeed_curses.1 | 2 +- sfeed_curses.c | 13 +++---------- sfeed_frames.1 | 2 +- sfeed_frames.c | 17 +++-------------- sfeed_gopher.1 | 2 +- sfeed_gopher.c | 17 +++-------------- sfeed_html.1 | 2 +- sfeed_html.c | 17 +++-------------- sfeed_plain.1 | 2 +- sfeed_plain.c | 18 +++--------------- util.c | 18 ++++++++++++++++++ util.h | 1 + 13 files changed, 42 insertions(+), 75 deletions(-) (limited to 'sfeed_curses.c') diff --git a/README b/README index 313ab4c..427435d 100644 --- a/README +++ b/README @@ -290,9 +290,9 @@ Just like the other format programs included in sfeed you can run it like this: sfeed_curses < ~/.sfeed/feeds/xkcd By default sfeed_curses marks the items of the last day as new/bold. This limit -might be overridden by setting the environment variable $SFEED_NEW_MAX_SECS to -the desired maximum in seconds. To manage read/unread items in a different way -a plain-text file with a list of the read URLs can be used. To enable this +might be overridden by setting the environment variable $SFEED_NEW_AGE to the +desired maximum in seconds. To manage read/unread items in a different way a +plain-text file with a list of the read URLs can be used. To enable this behaviour the path to this file can be specified by setting the environment variable $SFEED_URL_FILE to the URL file: diff --git a/sfeed_curses.1 b/sfeed_curses.1 index b3cccf2..56b2a92 100644 --- a/sfeed_curses.1 +++ b/sfeed_curses.1 @@ -208,7 +208,7 @@ SIGWINCH. Read and process a sequence of keys as input commands from this environment variable first, afterwards it reads from the tty as usual. This can be useful to automate certain actions at the start. -.It Ev SFEED_NEW_MAX_SECS +.It Ev SFEED_NEW_AGE Overwrite the maximum age in seconds to mark feeds as new. By default this is 86400, which equals one day. .It Ev SFEED_PIPER diff --git a/sfeed_curses.c b/sfeed_curses.c index cce608e..b6f995f 100644 --- a/sfeed_curses.c +++ b/sfeed_curses.c @@ -191,7 +191,6 @@ static int plumberia = 0; /* env variable: $SFEED_PLUMBER_INTERACTIVE */ static int piperia = 1; /* env variable: $SFEED_PIPER_INTERACTIVE */ static int yankeria = 0; /* env variable: $SFEED_YANKER_INTERACTIVE */ static int lazyload = 0; /* env variable: $SFEED_LAZYLOAD */ -static int newmaxsecs = 86400; /* env variable: $SFEED_NEW_MAX_SECS */ int ttywritef(const char *fmt, ...) @@ -1321,9 +1320,8 @@ feeds_load(struct feed *feeds, size_t nfeeds) size_t i; errno = 0; - if ((comparetime = time(NULL)) == (time_t)-1) - die("time"); - comparetime -= newmaxsecs; + if ((comparetime = getcomparetime()) == (time_t)-1) + die("getcomparetime"); for (i = 0; i < nfeeds; i++) { f = &feeds[i]; @@ -1967,7 +1965,7 @@ main(int argc, char *argv[]) struct pane *p; struct feed *f; struct row *row; - char *name, *tmp, *endptr; + char *name, *tmp; char *search = NULL; /* search text */ int button, ch, fd, i, keymask, release, x, y; off_t pos; @@ -1997,11 +1995,6 @@ main(int argc, char *argv[]) markunreadcmd = tmp; if ((tmp = getenv("SFEED_LAZYLOAD"))) lazyload = !strcmp(tmp, "1"); - if ((tmp = getenv("SFEED_NEW_MAX_SECS"))) { - newmaxsecs = (int) strtol(tmp, &endptr, 10); - if (*tmp == '\0' || *endptr != '\0' || newmaxsecs <= 0) - err(1, "cannot parse $SFEED_NEW_MAX_SECS"); - } urlfile = getenv("SFEED_URL_FILE"); /* can be NULL */ cmdenv = getenv("SFEED_AUTOCMD"); /* can be NULL */ diff --git a/sfeed_frames.1 b/sfeed_frames.1 index 976d5ed..455c1db 100644 --- a/sfeed_frames.1 +++ b/sfeed_frames.1 @@ -40,7 +40,7 @@ The HTML file of the menu frame which contains navigation "anchor" links (like .El .Sh ENVIRONMENT VARIABLES .Bl -tag -width Ds -.It Ev SFEED_NEW_MAX_SECS +.It Ev SFEED_NEW_AGE Overwrite the maximum age in seconds to mark feeds as new. By default this is 86400, which equals one day. .El diff --git a/sfeed_frames.c b/sfeed_frames.c index e52abd1..b2f75cf 100644 --- a/sfeed_frames.c +++ b/sfeed_frames.c @@ -77,9 +77,8 @@ int main(int argc, char *argv[]) { FILE *fpindex, *fpitems, *fpmenu = NULL, *fp; - char *name, *tmp, *endptr; + char *name; int i, showsidebar = (argc > 1); - long l; struct feed *f; if (pledge("stdio rpath wpath cpath", NULL) == -1) @@ -88,18 +87,8 @@ main(int argc, char *argv[]) if (!(feeds = calloc(argc, sizeof(struct feed)))) err(1, "calloc"); - if ((comparetime = time(NULL)) == (time_t)-1) - errx(1, "time"); - - if ((tmp = getenv("SFEED_NEW_MAX_SECS"))) { - l = strtol(tmp, &endptr, 10); - if (*tmp == '\0' || *endptr != '\0' || l <= 0) - err(1, "cannot parse $SFEED_NEW_MAX_SECS"); - comparetime -= l; - } else { - /* 1 day is old news */ - comparetime -= 86400; - } + if ((comparetime = getcomparetime()) == (time_t)-1) + errx(1, "getcomparetime"); /* write main index page */ if (!(fpindex = fopen("index.html", "wb"))) diff --git a/sfeed_gopher.1 b/sfeed_gopher.1 index f602d2c..bc45121 100644 --- a/sfeed_gopher.1 +++ b/sfeed_gopher.1 @@ -46,7 +46,7 @@ The default is "127.0.0.1". .It Ev SFEED_GOPHER_PORT This environment variable can be used as the Gopher Port field. The default is "70". -.It Ev SFEED_NEW_MAX_SECS +.It Ev SFEED_NEW_AGE Overwrite the maximum age in seconds to mark feeds as new. By default this is 86400, which equals one day. .El diff --git a/sfeed_gopher.c b/sfeed_gopher.c index 007a244..78e1f12 100644 --- a/sfeed_gopher.c +++ b/sfeed_gopher.c @@ -122,9 +122,8 @@ int main(int argc, char *argv[]) { FILE *fpitems, *fpindex, *fp; - char *name, *p, *tmp, *endptr; + char *name, *p; int i; - long l; if (argc == 1) { if (pledge("stdio", NULL) == -1) @@ -138,18 +137,8 @@ main(int argc, char *argv[]) err(1, "pledge"); } - if ((comparetime = time(NULL)) == (time_t)-1) - errx(1, "time"); - - if ((tmp = getenv("SFEED_NEW_MAX_SECS"))) { - l = strtol(tmp, &endptr, 10); - if (*tmp == '\0' || *endptr != '\0' || l <= 0) - err(1, "cannot parse $SFEED_NEW_MAX_SECS"); - comparetime -= l; - } else { - /* 1 day is old news */ - comparetime -= 86400; - } + if ((comparetime = getcomparetime()) == (time_t)-1) + errx(1, "getcomparetime"); if ((p = getenv("SFEED_GOPHER_HOST"))) host = p; diff --git a/sfeed_html.1 b/sfeed_html.1 index 98784c5..e517a63 100644 --- a/sfeed_html.1 +++ b/sfeed_html.1 @@ -32,7 +32,7 @@ Items are marked as new using a bold markup. There is an example style.css stylesheet file included in the distribution. .Sh ENVIRONMENT VARIABLES .Bl -tag -width Ds -.It Ev SFEED_NEW_MAX_SECS +.It Ev SFEED_NEW_AGE Overwrite the maximum age in seconds to mark feeds as new. By default this is 86400, which equals one day. .El diff --git a/sfeed_html.c b/sfeed_html.c index 89506be..9269413 100644 --- a/sfeed_html.c +++ b/sfeed_html.c @@ -78,28 +78,17 @@ int main(int argc, char *argv[]) { struct feed *f; - char *name, *tmp, *endptr; + char *name; FILE *fp; int i; - long l; if (pledge(argc == 1 ? "stdio" : "stdio rpath", NULL) == -1) err(1, "pledge"); if (!(feeds = calloc(argc, sizeof(struct feed)))) err(1, "calloc"); - if ((comparetime = time(NULL)) == (time_t)-1) - errx(1, "time"); - - if ((tmp = getenv("SFEED_NEW_MAX_SECS"))) { - l = strtol(tmp, &endptr, 10); - if (*tmp == '\0' || *endptr != '\0' || l <= 0) - err(1, "cannot parse $SFEED_NEW_MAX_SECS"); - comparetime -= l; - } else { - /* 1 day is old news */ - comparetime -= 86400; - } + if ((comparetime = getcomparetime()) == (time_t)-1) + errx(1, "getcomparetime"); fputs("\n" "\n" diff --git a/sfeed_plain.1 b/sfeed_plain.1 index 93ed41d..2e8e6ad 100644 --- a/sfeed_plain.1 +++ b/sfeed_plain.1 @@ -42,7 +42,7 @@ and .Xr wcwidth 3 . .Sh ENVIRONMENT VARIABLES .Bl -tag -width Ds -.It Ev SFEED_NEW_MAX_SECS +.It Ev SFEED_NEW_AGE Overwrite the maximum age in seconds to mark feeds as new. By default this is 86400, which equals one day. .El diff --git a/sfeed_plain.c b/sfeed_plain.c index c790ec4..f8ce7ec 100644 --- a/sfeed_plain.c +++ b/sfeed_plain.c @@ -2,7 +2,6 @@ #include #include -#include #include #include @@ -53,9 +52,8 @@ int main(int argc, char *argv[]) { FILE *fp; - char *name, *tmp, *endptr; + char *name; int i; - long l; if (pledge("stdio rpath", NULL) == -1) err(1, "pledge"); @@ -65,18 +63,8 @@ main(int argc, char *argv[]) if (pledge(argc == 1 ? "stdio" : "stdio rpath", NULL) == -1) err(1, "pledge"); - if ((comparetime = time(NULL)) == (time_t)-1) - errx(1, "time"); - - if ((tmp = getenv("SFEED_NEW_MAX_SECS"))) { - l = strtol(tmp, &endptr, 10); - if (*tmp == '\0' || *endptr != '\0' || l <= 0) - err(1, "cannot parse $SFEED_NEW_MAX_SECS"); - comparetime -= l; - } else { - /* 1 day is old news */ - comparetime -= 86400; - } + if ((comparetime = getcomparetime()) == (time_t)-1) + errx(1, "getcomparetime"); if (argc == 1) { printfeed(stdin, ""); diff --git a/util.c b/util.c index 0b7da06..e5aec3b 100644 --- a/util.c +++ b/util.c @@ -318,6 +318,24 @@ strtotime(const char *s, time_t *t) return 0; } +time_t +getcomparetime(void) +{ + time_t now, t; + char *p; + + if ((now = time(NULL)) == (time_t)-1) + return (time_t)-1; + + if ((p = getenv("SFEED_NEW_AGE"))) { + if (strtotime(p, &t) == -1) + return (time_t)-1; + return now - t; + } + + return now - 86400; /* 1 day is old news */ +} + /* Escape characters below as HTML 2.0 / XML 1.0. */ void xmlencode(const char *s, FILE *fp) diff --git a/util.h b/util.h index 9138de7..3ce5e41 100644 --- a/util.h +++ b/util.h @@ -71,6 +71,7 @@ int uri_makeabs(struct uri *, struct uri *, struct uri *); int uri_parse(const char *, struct uri *); void checkfileerror(FILE *, const char *, int); +time_t getcomparetime(void); void parseline(char *, char *[FieldLast]); void printutf8pad(FILE *, const char *, size_t, int); int strtotime(const char *, time_t *); -- cgit v1.2.3 From 538e7dc0ccf065bf59b952a46ff5658ea19f3bab Mon Sep 17 00:00:00 2001 From: Hiltjo Posthuma Date: Sun, 14 May 2023 23:38:17 +0200 Subject: sfeed_curses.c: make struct urls static like the other variables --- sfeed_curses.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'sfeed_curses.c') diff --git a/sfeed_curses.c b/sfeed_curses.c index b6f995f..f54b4d6 100644 --- a/sfeed_curses.c +++ b/sfeed_curses.c @@ -175,7 +175,7 @@ static struct feed *feeds; static struct feed *curfeed; static size_t nfeeds; /* amount of feeds */ static time_t comparetime; -struct urls urls; +static struct urls urls; static char *urlfile; volatile sig_atomic_t state_sigchld = 0, state_sighup = 0, state_sigint = 0; -- cgit v1.2.3 From 21790adad1672689225efe38b6a59494181d323b Mon Sep 17 00:00:00 2001 From: Hiltjo Posthuma Date: Tue, 16 May 2023 20:11:21 +0200 Subject: improve to use proper includes Reduce using some of the unneeded sys/* headers too. This makes it slightly more portable or easier to port also. --- sfeed_atom.c | 2 -- sfeed_curses.c | 2 -- sfeed_frames.c | 2 -- sfeed_gopher.c | 2 -- sfeed_html.c | 2 -- sfeed_json.c | 3 +-- sfeed_plain.c | 2 -- sfeed_twtxt.c | 2 -- 8 files changed, 1 insertion(+), 16 deletions(-) (limited to 'sfeed_curses.c') diff --git a/sfeed_atom.c b/sfeed_atom.c index 99facad..d0b139d 100644 --- a/sfeed_atom.c +++ b/sfeed_atom.c @@ -1,5 +1,3 @@ -#include - #include #include #include diff --git a/sfeed_curses.c b/sfeed_curses.c index f54b4d6..0ce9a4e 100644 --- a/sfeed_curses.c +++ b/sfeed_curses.c @@ -1,7 +1,5 @@ #include #include -#include -#include #include #include diff --git a/sfeed_frames.c b/sfeed_frames.c index b2f75cf..53f44a6 100644 --- a/sfeed_frames.c +++ b/sfeed_frames.c @@ -1,5 +1,3 @@ -#include - #include #include #include diff --git a/sfeed_gopher.c b/sfeed_gopher.c index af6a49c..c879864 100644 --- a/sfeed_gopher.c +++ b/sfeed_gopher.c @@ -1,5 +1,3 @@ -#include - #include #include #include diff --git a/sfeed_html.c b/sfeed_html.c index 9269413..2142145 100644 --- a/sfeed_html.c +++ b/sfeed_html.c @@ -1,5 +1,3 @@ -#include - #include #include #include diff --git a/sfeed_json.c b/sfeed_json.c index e177d2b..4fe5942 100644 --- a/sfeed_json.c +++ b/sfeed_json.c @@ -1,7 +1,6 @@ #include -#include #include -#include +#include #include "util.h" diff --git a/sfeed_plain.c b/sfeed_plain.c index f8ce7ec..adeefdb 100644 --- a/sfeed_plain.c +++ b/sfeed_plain.c @@ -1,5 +1,3 @@ -#include - #include #include #include diff --git a/sfeed_twtxt.c b/sfeed_twtxt.c index 1d8ab36..1bb9d3b 100644 --- a/sfeed_twtxt.c +++ b/sfeed_twtxt.c @@ -1,5 +1,3 @@ -#include - #include #include #include -- cgit v1.2.3 From 7afd4987e578631e41333867aa702e326cab87f1 Mon Sep 17 00:00:00 2001 From: Hiltjo Posthuma Date: Fri, 7 Jul 2023 11:10:01 +0200 Subject: sfeed_curses: move one line down when marking an item as read or unread I don't mind either behaviour, but it has been suggested by a few people. For example the mutt mail client also has this behaviour. --- sfeed_curses.c | 1 + 1 file changed, 1 insertion(+) (limited to 'sfeed_curses.c') diff --git a/sfeed_curses.c b/sfeed_curses.c index 0ce9a4e..95421fd 100644 --- a/sfeed_curses.c +++ b/sfeed_curses.c @@ -2337,6 +2337,7 @@ nextpage: if (selpane == PaneItems && panes[selpane].nrows) { p = &panes[selpane]; markread(p, p->pos, p->pos, ch == 'r'); + pane_scrolln(&panes[selpane], +1); } break; case 's': /* toggle layout between monocle or non-monocle */ -- cgit v1.2.3 From 21a263cb27aeaf02b4a0a0319f435fac92f1ea28 Mon Sep 17 00:00:00 2001 From: Hiltjo Posthuma Date: Tue, 15 Aug 2023 19:10:51 +0200 Subject: improve wording and small typos --- sfeed.c | 6 +++--- sfeed_curses.c | 2 +- sfeed_opml_import.c | 2 +- sfeed_web.c | 2 +- sfeed_xmlenc.c | 2 +- xml.c | 4 ++-- xml.h | 2 +- 7 files changed, 10 insertions(+), 10 deletions(-) (limited to 'sfeed_curses.c') diff --git a/sfeed.c b/sfeed.c index 888a575..cdd528c 100644 --- a/sfeed.c +++ b/sfeed.c @@ -724,8 +724,8 @@ xmlattr(XMLParser *p, const char *t, size_t tl, const char *n, size_t nl, if (!ctx.tag.id) return; - /* content-type may be: Atom: text, xhtml, html or mime-type. - MRSS (media:description): plain, html. */ + /* content-type may be for Atom: text, xhtml, html or a mime-type. + for MRSS (media:description): plain, html. */ if (ISCONTENTTAG(ctx)) { if (isattr(n, nl, STRP("type"))) string_append(&attrtype, v, vl); @@ -1073,7 +1073,7 @@ main(int argc, char *argv[]) parser.xmltagstart = xmltagstart; parser.xmltagstartparsed = xmltagstartparsed; - /* NOTE: getnext is defined in xml.h for inline optimization */ + /* NOTE: GETNEXT is defined in xml.h for inline optimization */ xml_parse(&parser); checkfileerror(stdin, "", 'r'); diff --git a/sfeed_curses.c b/sfeed_curses.c index 95421fd..0434812 100644 --- a/sfeed_curses.c +++ b/sfeed_curses.c @@ -1875,7 +1875,7 @@ markread(struct pane *p, off_t from, off_t to, int isread) _exit(status); default: /* waitpid() and block on process status change, - fail if exit statuscode was unavailable or non-zero */ + fail if the exit status code was unavailable or non-zero */ if (waitpid(pid, &status, 0) <= 0 || status) break; diff --git a/sfeed_opml_import.c b/sfeed_opml_import.c index 9922133..ce33aac 100644 --- a/sfeed_opml_import.c +++ b/sfeed_opml_import.c @@ -96,7 +96,7 @@ main(void) "# list of feeds to fetch:\n" "feeds() {\n" " # feed [basesiteurl] [encoding]\n", stdout); - /* NOTE: getnext is defined in xml.h for inline optimization */ + /* NOTE: GETNEXT is defined in xml.h for inline optimization */ xml_parse(&parser); fputs("}\n", stdout); diff --git a/sfeed_web.c b/sfeed_web.c index 0082f2d..e25e91c 100644 --- a/sfeed_web.c +++ b/sfeed_web.c @@ -132,7 +132,7 @@ main(int argc, char *argv[]) parser.xmltagstart = xmltagstart; parser.xmltagstartparsed = xmltagstartparsed; - /* NOTE: getnext is defined in xml.h for inline optimization */ + /* NOTE: GETNEXT is defined in xml.h for inline optimization */ xml_parse(&parser); checkfileerror(stdin, "", 'r'); diff --git a/sfeed_xmlenc.c b/sfeed_xmlenc.c index 7fc93ae..461c047 100644 --- a/sfeed_xmlenc.c +++ b/sfeed_xmlenc.c @@ -52,7 +52,7 @@ main(void) parser.xmlattrend = xmlattrend; parser.xmltagstart = xmltagstart; - /* NOTE: getnext is defined in xml.h for inline optimization */ + /* NOTE: GETNEXT is defined in xml.h for inline optimization */ xml_parse(&parser); checkfileerror(stdin, "", 'r'); diff --git a/xml.c b/xml.c index a82053e..1524d1f 100644 --- a/xml.c +++ b/xml.c @@ -317,7 +317,7 @@ xml_parse(XMLParser *x) x->taglen = 1; x->isshorttag = isend = 0; - /* treat processing instruction as shorttag, don't strip "?" prefix. */ + /* treat processing instruction as short tag, don't strip "?" prefix. */ if (c == '?') { x->isshorttag = 1; } else if (c == '/') { @@ -346,7 +346,7 @@ xml_parse(XMLParser *x) if (x->xmltagstartparsed) x->xmltagstartparsed(x, x->tag, x->taglen, x->isshorttag); } - /* call tagend for shortform or processing instruction */ + /* call tagend for short tag or processing instruction */ if (x->isshorttag) { if (x->xmltagend) x->xmltagend(x, x->tag, x->taglen, x->isshorttag); diff --git a/xml.h b/xml.h index 122726c..6f3cf71 100644 --- a/xml.h +++ b/xml.h @@ -30,7 +30,7 @@ typedef struct xmlparser { /* current tag */ char tag[1024]; size_t taglen; - /* current tag is in shortform ? */ + /* current tag is a short tag ? */ int isshorttag; /* current attribute name */ char name[1024]; -- cgit v1.2.3 From db69f0f81d4796816c04e6330b963f907cbfded1 Mon Sep 17 00:00:00 2001 From: NRK Date: Thu, 21 Sep 2023 03:20:19 +0600 Subject: sfeed_curses: mark functions as static no reason for them not to be `static` and this also silences -Wmissing-prototypes warning (note: most of this patch was done by a sed(1) command.) --- sfeed_curses.c | 182 ++++++++++++++++++++++++++++----------------------------- 1 file changed, 91 insertions(+), 91 deletions(-) (limited to 'sfeed_curses.c') diff --git a/sfeed_curses.c b/sfeed_curses.c index 0434812..3359340 100644 --- a/sfeed_curses.c +++ b/sfeed_curses.c @@ -139,18 +139,18 @@ struct items { size_t cap; /* available capacity */ }; -void alldirty(void); -void cleanup(void); -void draw(void); -int getsidebarsize(void); -void markread(struct pane *, off_t, off_t, int); -void pane_draw(struct pane *); -void sighandler(int); -void updategeom(void); -void updatesidebar(void); -void urls_free(struct urls *); -int urls_hasmatch(struct urls *, const char *); -void urls_read(struct urls *, const char *); +static void alldirty(void); +static void cleanup(void); +static void draw(void); +static int getsidebarsize(void); +static void markread(struct pane *, off_t, off_t, int); +static void pane_draw(struct pane *); +static void sighandler(int); +static void updategeom(void); +static void updatesidebar(void); +static void urls_free(struct urls *); +static int urls_hasmatch(struct urls *, const char *); +static void urls_read(struct urls *, const char *); static struct linebar linebar; static struct statusbar statusbar; @@ -190,7 +190,7 @@ static int piperia = 1; /* env variable: $SFEED_PIPER_INTERACTIVE */ static int yankeria = 0; /* env variable: $SFEED_YANKER_INTERACTIVE */ static int lazyload = 0; /* env variable: $SFEED_LAZYLOAD */ -int +static int ttywritef(const char *fmt, ...) { va_list ap; @@ -204,7 +204,7 @@ ttywritef(const char *fmt, ...) return n; } -int +static int ttywrite(const char *s) { if (!s) @@ -213,7 +213,7 @@ ttywrite(const char *s) } /* Print to stderr, call cleanup() and _exit(). */ -__dead void +__dead static void die(const char *fmt, ...) { va_list ap; @@ -234,7 +234,7 @@ die(const char *fmt, ...) _exit(1); } -void * +static void * erealloc(void *ptr, size_t size) { void *p; @@ -244,7 +244,7 @@ erealloc(void *ptr, size_t size) return p; } -void * +static void * ecalloc(size_t nmemb, size_t size) { void *p; @@ -254,7 +254,7 @@ ecalloc(size_t nmemb, size_t size) return p; } -char * +static char * estrdup(const char *s) { char *p; @@ -265,7 +265,7 @@ estrdup(const char *s) } /* Wrapper for tparm() which allows NULL parameter for str. */ -char * +static char * tparmnull(const char *str, long p1, long p2, long p3, long p4, long p5, long p6, long p7, long p8, long p9) { @@ -276,7 +276,7 @@ tparmnull(const char *str, long p1, long p2, long p3, long p4, long p5, long p6, } /* Counts column width of character string. */ -size_t +static size_t colw(const char *s) { wchar_t wc; @@ -308,7 +308,7 @@ colw(const char *s) /* Format `len` columns of characters. If string is shorter pad the rest with characters `pad`. */ -int +static int utf8pad(char *buf, size_t bufsiz, const char *s, size_t len, int pad) { wchar_t wc; @@ -373,13 +373,13 @@ utf8pad(char *buf, size_t bufsiz, const char *s, size_t len, int pad) return 0; } -void +static void resetstate(void) { ttywrite("\x1b""c"); /* rs1: reset title and state */ } -void +static void updatetitle(void) { unsigned long totalnew = 0, total = 0; @@ -392,32 +392,32 @@ updatetitle(void) ttywritef("\x1b]2;(%lu/%lu) - sfeed_curses\x1b\\", totalnew, total); } -void +static void appmode(int on) { ttywrite(tparmnull(on ? enter_ca_mode : exit_ca_mode, 0, 0, 0, 0, 0, 0, 0, 0, 0)); } -void +static void mousemode(int on) { ttywrite(on ? "\x1b[?1000h" : "\x1b[?1000l"); /* xterm X10 mouse mode */ ttywrite(on ? "\x1b[?1006h" : "\x1b[?1006l"); /* extended SGR mouse mode */ } -void +static void cursormode(int on) { ttywrite(tparmnull(on ? cursor_normal : cursor_invisible, 0, 0, 0, 0, 0, 0, 0, 0, 0)); } -void +static void cursormove(int x, int y) { ttywrite(tparmnull(cursor_address, y, x, 0, 0, 0, 0, 0, 0, 0)); } -void +static void cursorsave(void) { /* do not save the cursor if it won't be restored anyway */ @@ -425,7 +425,7 @@ cursorsave(void) ttywrite(tparmnull(save_cursor, 0, 0, 0, 0, 0, 0, 0, 0, 0)); } -void +static void cursorrestore(void) { /* if the cursor cannot be hidden then move to a consistent position */ @@ -435,7 +435,7 @@ cursorrestore(void) cursormove(0, 0); } -void +static void attrmode(int mode) { switch (mode) { @@ -456,19 +456,19 @@ attrmode(int mode) } } -void +static void cleareol(void) { ttywrite(tparmnull(clr_eol, 0, 0, 0, 0, 0, 0, 0, 0, 0)); } -void +static void clearscreen(void) { ttywrite(tparmnull(clear_screen, 0, 0, 0, 0, 0, 0, 0, 0, 0)); } -void +static void cleanup(void) { struct sigaction sa; @@ -497,7 +497,7 @@ cleanup(void) sigaction(SIGWINCH, &sa, NULL); } -void +static void win_update(struct win *w, int width, int height) { if (width != w->width || height != w->height) @@ -506,7 +506,7 @@ win_update(struct win *w, int width, int height) w->height = height; } -void +static void resizewin(void) { struct winsize winsz; @@ -521,7 +521,7 @@ resizewin(void) alldirty(); } -void +static void init(void) { struct sigaction sa; @@ -561,7 +561,7 @@ init(void) sigaction(SIGWINCH, &sa, NULL); } -void +static void processexit(pid_t pid, int interactive) { struct sigaction sa; @@ -594,7 +594,7 @@ processexit(pid_t pid, int interactive) if `interactive` is 1 then cleanup and restore the tty and wait on the process. if 0 then don't do that and also write stdout and stderr to /dev/null. */ -void +static void pipeitem(const char *cmd, struct item *item, int field, int interactive) { FILE *fp; @@ -634,7 +634,7 @@ pipeitem(const char *cmd, struct item *item, int field, int interactive) } } -void +static void forkexec(char *argv[], int interactive) { pid_t pid; @@ -658,7 +658,7 @@ forkexec(char *argv[], int interactive) } } -struct row * +static struct row * pane_row_get(struct pane *p, off_t pos) { if (pos < 0 || pos >= p->nrows) @@ -669,7 +669,7 @@ pane_row_get(struct pane *p, off_t pos) return p->rows + pos; } -char * +static char * pane_row_text(struct pane *p, struct row *row) { /* custom formatter */ @@ -678,7 +678,7 @@ pane_row_text(struct pane *p, struct row *row) return row->text; } -int +static int pane_row_match(struct pane *p, struct row *row, const char *s) { if (p->row_match) @@ -686,7 +686,7 @@ pane_row_match(struct pane *p, struct row *row, const char *s) return (strcasestr(pane_row_text(p, row), s) != NULL); } -void +static void pane_row_draw(struct pane *p, off_t pos, int selected) { struct row *row; @@ -719,7 +719,7 @@ pane_row_draw(struct pane *p, off_t pos, int selected) cursorrestore(); } -void +static void pane_setpos(struct pane *p, off_t pos) { if (pos < 0) @@ -743,7 +743,7 @@ pane_setpos(struct pane *p, off_t pos) p->pos = pos; } -void +static void pane_scrollpage(struct pane *p, int pages) { off_t pos; @@ -761,13 +761,13 @@ pane_scrollpage(struct pane *p, int pages) } } -void +static void pane_scrolln(struct pane *p, int n) { pane_setpos(p, p->pos + n); } -void +static void pane_setfocus(struct pane *p, int on) { if (p->focused != on) { @@ -776,7 +776,7 @@ pane_setfocus(struct pane *p, int on) } } -void +static void pane_draw(struct pane *p) { off_t pos, y; @@ -793,7 +793,7 @@ pane_draw(struct pane *p) pane_row_draw(p, y + pos, (y + pos) == p->pos); } -void +static void setlayout(int n) { if (layout != LayoutMonocle) @@ -801,7 +801,7 @@ setlayout(int n) layout = n; } -void +static void updategeom(void) { int h, w, x = 0, y = 0; @@ -875,7 +875,7 @@ updategeom(void) alldirty(); } -void +static void scrollbar_setfocus(struct scrollbar *s, int on) { if (s->focused != on) { @@ -884,7 +884,7 @@ scrollbar_setfocus(struct scrollbar *s, int on) } } -void +static void scrollbar_update(struct scrollbar *s, off_t pos, off_t nrows, int pageheight) { int tickpos = 0, ticksize = 0; @@ -909,7 +909,7 @@ scrollbar_update(struct scrollbar *s, off_t pos, off_t nrows, int pageheight) s->ticksize = ticksize; } -void +static void scrollbar_draw(struct scrollbar *s) { off_t y; @@ -948,7 +948,7 @@ scrollbar_draw(struct scrollbar *s) cursorrestore(); } -int +static int readch(void) { unsigned char b; @@ -982,7 +982,7 @@ readch(void) } } -char * +static char * lineeditor(void) { char *input = NULL; @@ -1035,7 +1035,7 @@ lineeditor(void) return input; } -char * +static char * uiprompt(int x, int y, char *fmt, ...) { va_list ap; @@ -1065,7 +1065,7 @@ uiprompt(int x, int y, char *fmt, ...) return input; } -void +static void linebar_draw(struct linebar *b) { int i; @@ -1086,7 +1086,7 @@ linebar_draw(struct linebar *b) cursorrestore(); } -void +static void statusbar_draw(struct statusbar *s) { if (!s->dirty) @@ -1106,7 +1106,7 @@ statusbar_draw(struct statusbar *s) cursorrestore(); } -void +static void statusbar_update(struct statusbar *s, const char *text) { if (s->text && !strcmp(s->text, text)) @@ -1118,7 +1118,7 @@ statusbar_update(struct statusbar *s, const char *text) } /* Line to item, modifies and splits line in-place. */ -int +static int linetoitem(char *line, struct item *item) { char *fields[FieldLast]; @@ -1144,7 +1144,7 @@ linetoitem(char *line, struct item *item) return 0; } -void +static void feed_items_free(struct items *items) { size_t i; @@ -1159,7 +1159,7 @@ feed_items_free(struct items *items) items->cap = 0; } -void +static void feed_items_get(struct feed *f, FILE *fp, struct items *itemsret) { struct item *item, *items = NULL; @@ -1207,7 +1207,7 @@ feed_items_get(struct feed *f, FILE *fp, struct items *itemsret) free(line); } -void +static void updatenewitems(struct feed *f) { struct pane *p; @@ -1231,7 +1231,7 @@ updatenewitems(struct feed *f) f->total = p->nrows; } -void +static void feed_load(struct feed *f, FILE *fp) { /* static, reuse local buffers */ @@ -1252,7 +1252,7 @@ feed_load(struct feed *f, FILE *fp) updatenewitems(f); } -void +static void feed_count(struct feed *f, FILE *fp) { char *fields[FieldLast]; @@ -1281,7 +1281,7 @@ feed_count(struct feed *f, FILE *fp) free(line); } -void +static void feed_setenv(struct feed *f) { if (f && f->path) @@ -1291,7 +1291,7 @@ feed_setenv(struct feed *f) } /* Change feed, have one file open, reopen file if needed. */ -void +static void feeds_set(struct feed *f) { if (curfeed) { @@ -1311,7 +1311,7 @@ feeds_set(struct feed *f) curfeed = f; } -void +static void feeds_load(struct feed *feeds, size_t nfeeds) { struct feed *f; @@ -1354,7 +1354,7 @@ feeds_load(struct feed *feeds, size_t nfeeds) } /* find row position of the feed if visible, else return -1 */ -off_t +static off_t feeds_row_get(struct pane *p, struct feed *f) { struct row *row; @@ -1371,7 +1371,7 @@ feeds_row_get(struct pane *p, struct feed *f) return -1; } -void +static void feeds_reloadall(void) { struct pane *p; @@ -1400,7 +1400,7 @@ feeds_reloadall(void) pane_setpos(p, 0); } -void +static void feed_open_selected(struct pane *p) { struct feed *f; @@ -1424,7 +1424,7 @@ feed_open_selected(struct pane *p) } } -void +static void feed_plumb_selected_item(struct pane *p, int field) { struct row *row; @@ -1441,7 +1441,7 @@ feed_plumb_selected_item(struct pane *p, int field) forkexec(cmd, plumberia); } -void +static void feed_pipe_selected_item(struct pane *p) { struct row *row; @@ -1454,7 +1454,7 @@ feed_pipe_selected_item(struct pane *p) pipeitem(pipercmd, item, -1, piperia); } -void +static void feed_yank_selected_item(struct pane *p, int field) { struct row *row; @@ -1467,7 +1467,7 @@ feed_yank_selected_item(struct pane *p, int field) } /* calculate optimal (default) size */ -int +static int getsidebarsizedefault(void) { struct feed *feed; @@ -1500,7 +1500,7 @@ getsidebarsizedefault(void) return 0; } -int +static int getsidebarsize(void) { int size; @@ -1510,7 +1510,7 @@ getsidebarsize(void) return size; } -void +static void adjustsidebarsize(int n) { int size; @@ -1533,7 +1533,7 @@ adjustsidebarsize(int n) } } -void +static void updatesidebar(void) { struct pane *p; @@ -1585,7 +1585,7 @@ updatesidebar(void) p->pos = p->nrows - 1; } -void +static void sighandler(int signo) { switch (signo) { @@ -1597,7 +1597,7 @@ sighandler(int signo) } } -void +static void alldirty(void) { win.dirty = 1; @@ -1609,7 +1609,7 @@ alldirty(void) statusbar.dirty = 1; } -void +static void draw(void) { struct row *row; @@ -1643,7 +1643,7 @@ draw(void) statusbar_draw(&statusbar); } -void +static void mousereport(int button, int release, int keymask, int x, int y) { struct pane *p; @@ -1715,7 +1715,7 @@ mousereport(int button, int release, int keymask, int x, int y) } /* Custom formatter for feed row. */ -char * +static char * feed_row_format(struct pane *p, struct row *row) { /* static, reuse local buffers */ @@ -1756,7 +1756,7 @@ feed_row_format(struct pane *p, struct row *row) return text; } -int +static int feed_row_match(struct pane *p, struct row *row, const char *s) { struct feed *feed; @@ -1766,7 +1766,7 @@ feed_row_match(struct pane *p, struct row *row, const char *s) return (strcasestr(feed->name, s) != NULL); } -struct row * +static struct row * item_row_get(struct pane *p, off_t pos) { struct row *itemrow; @@ -1803,7 +1803,7 @@ item_row_get(struct pane *p, off_t pos) } /* Custom formatter for item row. */ -char * +static char * item_row_format(struct pane *p, struct row *row) { /* static, reuse local buffers */ @@ -1835,7 +1835,7 @@ item_row_format(struct pane *p, struct row *row) return text; } -void +static void markread(struct pane *p, off_t from, off_t to, int isread) { struct row *row; @@ -1898,13 +1898,13 @@ markread(struct pane *p, off_t from, off_t to, int isread) } } -int +static int urls_cmp(const void *v1, const void *v2) { return strcmp(*((char **)v1), *((char **)v2)); } -void +static void urls_free(struct urls *urls) { while (urls->len > 0) { @@ -1917,14 +1917,14 @@ urls_free(struct urls *urls) urls->cap = 0; } -int +static int urls_hasmatch(struct urls *urls, const char *url) { return (urls->len && bsearch(&url, urls->items, urls->len, sizeof(char *), urls_cmp)); } -void +static void urls_read(struct urls *urls, const char *urlfile) { FILE *fp; -- cgit v1.2.3