From 4954eef226519a87cd932f72f2119d1866153619 Mon Sep 17 00:00:00 2001 From: mdw Date: Sat, 7 May 2005 10:01:05 +0000 Subject: [PATCH] Allow xmsg to read from stdin. --- .links | 3 --- setup | 2 +- xmsg.1 | 11 +++++++++++ xmsg.c | 21 ++++++++++++++++++++- 4 files changed, 32 insertions(+), 5 deletions(-) diff --git a/.links b/.links index 10f134c..5ecd9c6 100644 --- a/.links +++ b/.links @@ -1,4 +1 @@ COPYING -install-sh -missing -mkinstalldirs diff --git a/setup b/setup index 27dde72..77f8a03 100755 --- a/setup +++ b/setup @@ -4,5 +4,5 @@ set -e mklinks mkaclocal autoconf -automake +automake -a mkdir build diff --git a/xmsg.1 b/xmsg.1 index 57cb3e1..32bf249 100644 --- a/xmsg.1 +++ b/xmsg.1 @@ -29,6 +29,17 @@ one per argument, after the message. If no buttons are requested, an .B OK button is provided anyway. .PP +If the +.I message +is +.RB ` \- ' +then instead the message to display is read from standard input. If the +first character of +.I message +is +.RB ` % ' +then that character is removed. +.PP A button may be selected as being the default (i.e., may be chosen by pressing .IR enter ), diff --git a/xmsg.c b/xmsg.c index 4810e4e..edce12a 100644 --- a/xmsg.c +++ b/xmsg.c @@ -1,6 +1,6 @@ /* -*-c-*- * - * $Id: xmsg.c,v 1.2 2004/04/08 01:36:29 mdw Exp $ + * $Id$ * * Display a message to the user * @@ -108,6 +108,7 @@ int main(int argc, char *argv[]) button_v bv = DA_INIT; button *b; dstr d = DSTR_INIT; + dstr msgbuf = DSTR_INIT; size_t n, i; unsigned f = 0; @@ -193,6 +194,24 @@ int main(int argc, char *argv[]) exit(EXIT_FAILURE); } message = argv[optind++]; + if (*message == '%') + message++; + else if (strcmp(message, "-") == 0) { + for (;;) { + size_t n; + + dstr_ensure(&msgbuf, 4096); + n = fread(msgbuf.buf + msgbuf.len, 1, + msgbuf.sz - msgbuf.len, stdin); + if (!n) + break; + msgbuf.len += n; + } + if (msgbuf.len && msgbuf.buf[msgbuf.len - 1]) + msgbuf.len--; + dstr_putz(&msgbuf); + message = msgbuf.buf; + } if (optind >= argc) { DA_ENSURE(&bv, 1); -- 2.11.0