From 08f3bcd3f6b63124f03ae02bb0e29713a94ad50c Mon Sep 17 00:00:00 2001 From: Laurent Mazet Date: Mon, 13 May 2024 00:19:21 +0200 Subject: [PATCH] add follow action --- cmd.c | 4 ++++ cmore.c | 46 +++++++++++++++++++++++++--------------------- 2 files changed, 29 insertions(+), 21 deletions(-) diff --git a/cmd.c b/cmd.c index 355b633..95d1718 100644 --- a/cmd.c +++ b/cmd.c @@ -112,6 +112,10 @@ void free_lines (char **lines) { int i = 0; + if (!lines) { + return; + } + while (lines[i]) { free (lines[i++]); } diff --git a/cmore.c b/cmore.c index 6271d23..ad2243b 100644 --- a/cmore.c +++ b/cmore.c @@ -17,19 +17,28 @@ char *version = "0.1"; char *input = NULL; char *command = NULL; +char **lines = NULL; int second = 0; -void display (char **lines, int xmax, int ymax) +void display (char **lines, int xmax, int ymax, int keep_skip) { int stop = 0; + if (!lines) { + return; + } + #ifdef __PDCURSES__ statusmsg ("Press 'q' or escape to quit"); #else statusmsg ("Press 'q' or double-escape to quit"); #endif - int skip = 0; + static int skip; + if (!keep_skip) { + skip = 0; + } + while (!stop) { clsbody (); int i = 0; @@ -107,8 +116,6 @@ void display (char **lines, int xmax, int ymax) void process (void) { - static char **lines = NULL; - int xmax, ymax; WINDOW *wbody = bodywin (); getmaxyx (wbody, ymax, xmax); @@ -132,18 +139,10 @@ void process (void) exit (1); } - if (!lines) { - lines = split_lines (buffer, xmax); - free (buffer); - } - - if (lines) { - display (lines, xmax, ymax); - if (buffer) { - free_lines (lines); - lines = NULL; - } - } + free_lines (lines); + lines = split_lines (buffer, xmax); + free (buffer); + display (lines, xmax, ymax, 0); if (second > 0) { VERBOSE (DEBUG, fprintf (stdout, "sleeping for %d''\n", second)); @@ -153,6 +152,15 @@ void process (void) } } +void follow (void) +{ + int xmax, ymax; + WINDOW *wbody = bodywin (); + getmaxyx (wbody, ymax, xmax); + + display (lines, xmax, ymax, 1); +} + void about (void) { int xmax, ymax; @@ -205,15 +213,11 @@ void chfile (void) } } -void contdisp (void) -{ -} - menu SubMenu0[] = { { "Command", chcmd, "Change command"}, { "File", chfile, "Change file"}, - { "Display", contdisp, "Continue"}, + { "Display", follow, "Continue"}, { "Refresh", process, "Refresh"}, { "Exit", DoExit, "Terminate program" }, { "", (FUNC)0, "" } -- 2.30.2