[GRASS-SVN] r40662 - grass/trunk/lib/gis

svn_grass at osgeo.org svn_grass at osgeo.org
Tue Jan 26 07:28:41 EST 2010


Author: glynn
Date: 2010-01-26 07:28:40 -0500 (Tue, 26 Jan 2010)
New Revision: 40662

Added:
   grass/trunk/lib/gis/pager.c
Log:
Add pager.c (omitted from r40648)


Added: grass/trunk/lib/gis/pager.c
===================================================================
--- grass/trunk/lib/gis/pager.c	                        (rev 0)
+++ grass/trunk/lib/gis/pager.c	2010-01-26 12:28:40 UTC (rev 40662)
@@ -0,0 +1,65 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <signal.h>
+
+#include <unistd.h>
+
+#include <grass/gis.h>
+
+#ifdef SIGPIPE
+static RETSIGTYPE (*sigpipe)(int);
+#endif
+
+FILE *G_open_pager(struct Popen *pager)
+{
+    const char *program = getenv("GRASS_PAGER");
+    FILE *fp;
+
+    if (!program)
+	return stdout;
+
+    if (!isatty(STDOUT_FILENO))
+	return stdout;
+
+#ifdef SIGPIPE
+    sigpipe = signal(SIGPIPE, SIG_IGN);
+#endif
+
+    fp = G_popen_write(pager, program, NULL);
+
+    return fp ? fp : stdout;
+}
+
+void G_close_pager(struct Popen *pager)
+{
+    G_popen_close(pager);
+
+#ifdef SIGPIPE
+    if (sigpipe)
+	signal(SIGPIPE, sigpipe);
+#endif
+}
+
+FILE *G_open_mail(struct Popen *mail)
+{
+    const char *user = G_whoami();
+    const char *argv[3];
+    FILE *fp;
+
+    if (!user || !*user)
+	return NULL;
+
+    argv[0] = "mail";
+    argv[1] = user;
+    argv[2] = NULL;
+
+    fp = G_popen_write(mail, "mail", argv);
+
+    return fp;
+}
+
+void G_close_mail(struct Popen *mail)
+{
+    G_popen_close(mail);
+}
+



More information about the grass-commit mailing list