Allow xmsg to read from stdin.
authormdw <mdw>
Sat, 7 May 2005 10:01:05 +0000 (10:01 +0000)
committermdw <mdw>
Sat, 7 May 2005 10:01:05 +0000 (10:01 +0000)
.links
setup
xmsg.1
xmsg.c

diff --git a/.links b/.links
index 10f134c..5ecd9c6 100644 (file)
--- a/.links
+++ b/.links
@@ -1,4 +1 @@
 COPYING
-install-sh
-missing
-mkinstalldirs
diff --git a/setup b/setup
index 27dde72..77f8a03 100755 (executable)
--- 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 (file)
--- 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 (file)
--- 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);