Allow xmsg to read from stdin.
[xtoys] / xmsg.c
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);