mblaze

Unix utilities to deal with Maildir - my mirror
git clone https://pi.duncano.de/git/mblaze.git
Log | Files | Refs | README | COPYING

commit 94854ad1852527b3ef03b323948c2fd6c63803ef
parent e8107b1889a620b6ba446953e698b30f1803b2cb
Author: Leah Neukirchen <leah@vuxu.org>
Date:   Tue, 23 May 2017 15:25:28 +0200

mscan: spawn a pager for interactive use

Diffstat:
Makefile | 1+
man/mscan.1 | 14+++++++++++++-
mscan.c | 20+++++++++++++++++++-
3 files changed, 33 insertions(+), 2 deletions(-)

diff --git a/Makefile b/Makefile @@ -25,6 +25,7 @@ maddr magrep mexport mflag mgenmid mhdr mlist mpick mscan msed mseq mshow msort maddr magrep mhdr mpick mscan mshow : rfc2047.o magrep mshow : rfc2045.o mshow : filter.o safe_u8putstr.o rfc2231.o pipeto.o +mscan : pipeto.o msort : mystrverscmp.o mmime : slurp.o diff --git a/man/mscan.1 b/man/mscan.1 @@ -22,7 +22,8 @@ If no are passed, .Nm reads file names from standard input, -or uses the mails in the current sequence when used interactively. +or uses the mails in the current sequence when used interactively +(using a pager). .Pp By default, .Ar format @@ -166,6 +167,17 @@ You are in You are in .Sq Li "Resent-To:" . .El +.Sh ENVIRONMENT +.Bl -tag -width MBLAZE_PAGER +.It Ev MBLAZE_PAGER +Any non-empty value of the environment variable +.Ev MBLAZE_PAGER +is used instead of the standard pagination program, specified in +.Ev PAGER . +When empty or set to +.Sq Ic cat , +no pager is spawned. +.El .Sh EXIT STATUS .Ex -std .Sh SEE ALSO diff --git a/mscan.c b/mscan.c @@ -488,6 +488,8 @@ oneline(char *file) int main(int argc, char *argv[]) { + pid_t pid1 = -1; + int c; while ((c = getopt(argc, argv, "If:n")) != -1) switch(c) { @@ -516,8 +518,21 @@ main(int argc, char *argv[]) replacement = 0xfffd; struct winsize w; - if (ioctl(1, TIOCGWINSZ, &w) == 0) + if (ioctl(1, TIOCGWINSZ, &w) == 0) { cols = w.ws_col; + + char *pg; + pg = getenv("MBLAZE_PAGER"); + if (!pg) + pg = getenv("PAGER"); + if (pg && *pg && strcmp(pg, "cat") != 0) { + pid1 = pipeto(pg); + if (pid1 < 0) + fprintf(stderr, + "mscan: spawning pager '%s': %s\n", + pg, strerror(errno)); + } + } if (getenv("COLUMNS")) cols = atoi(getenv("COLUMNS")); if (cols <= 40) @@ -550,5 +565,8 @@ main(int argc, char *argv[]) i = blaze822_loop(argc-optind, argv+optind, oneline); fprintf(stderr, "%ld mails scanned\n", i); + if (pid1 > 0) + pipeclose(pid1); + return 0; }