scroll

scrollbackbuffer program for st
git clone git://git.suckless.org/scroll
Log | Files | Refs | README

commit 6e7406cde8b517ecee582856ffbaaaea63e98661
parent 8718290ad5b7f43ad577f5dbc1cf481228c311e5
Author: Jan Klemkow <j.klemkow@wemelug.de>
Date:   Tue, 14 Apr 2020 22:24:39 +0200

remove debug code from ptty, add C flag to test closing of fd to scroll

Diffstat:
Mptty.c | 15++++++++++-----
1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/ptty.c b/ptty.c @@ -4,6 +4,7 @@ #include <inttypes.h> #include <limits.h> #include <stdarg.h> +#include <stdbool.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -39,7 +40,7 @@ die(const char *fmt, ...) void usage(void) { - fputs("ptty cmd\n", stderr); + fputs("ptty [-C] [-c cols] [-r rows] cmd\n", stderr); exit(EXIT_FAILURE); } @@ -48,8 +49,9 @@ main(int argc, char *argv[]) { struct winsize ws = {.ws_row = 25, .ws_col = 80, 0, 0}; int ch; + bool closeflag = false; - while ((ch = getopt(argc, argv, "c:r:h")) != -1) { + while ((ch = getopt(argc, argv, "c:r:Ch")) != -1) { switch (ch) { case 'c': /* cols */ ws.ws_col = strtoimax(optarg, NULL, 10); @@ -61,6 +63,9 @@ main(int argc, char *argv[]) if (errno != 0) die("strtoimax: %s", optarg); break; + case 'C': + closeflag = true; + break; case 'h': default: usage(); @@ -87,11 +92,11 @@ main(int argc, char *argv[]) if (fh == NULL) die("fdopen"); - if (close(mfd) == -1) + if (closeflag && close(mfd) == -1) die("close:"); -// char buf[BUFSIZ]; -// while (fgets(buf, sizeof buf, fh) != NULL); + char buf[BUFSIZ]; + while (fgets(buf, sizeof buf, fh) != NULL); int status; waitpid(pid, &status, 0);