GRASS GIS 8 Programmer's Manual  8.5.0dev(2024)-36359e2344
pager.c
Go to the documentation of this file.
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <signal.h>
4 
5 #include <unistd.h>
6 
7 #include <grass/gis.h>
8 
9 #ifdef SIGPIPE
10 static void (*sigpipe)(int);
11 #endif
12 
13 FILE *G_open_pager(struct Popen *pager)
14 {
15  const char *program = getenv("GRASS_PAGER");
16  FILE *fp;
17 
18  G_popen_clear(pager);
19 
20  if (!program)
21  return stdout;
22 
23  if (!isatty(STDOUT_FILENO))
24  return stdout;
25 
26 #ifdef SIGPIPE
27  sigpipe = signal(SIGPIPE, SIG_IGN);
28 #endif
29 
30  fp = G_popen_write(pager, program, NULL);
31 
32  return fp ? fp : stdout;
33 }
34 
35 void G_close_pager(struct Popen *pager)
36 {
37  G_popen_close(pager);
38 
39 #ifdef SIGPIPE
40  if (sigpipe)
41  signal(SIGPIPE, sigpipe);
42 #endif
43 }
44 
45 FILE *G_open_mail(struct Popen *mail)
46 {
47  const char *user = G_whoami();
48  const char *argv[3];
49  FILE *fp;
50 
51  G_popen_clear(mail);
52 
53  if (!user || !*user)
54  return NULL;
55 
56  argv[0] = "mail";
57  argv[1] = user;
58  argv[2] = NULL;
59 
60  fp = G_popen_write(mail, "mail", argv);
61 
62  return fp;
63 }
64 
65 void G_close_mail(struct Popen *mail)
66 {
67  G_popen_close(mail);
68 }
#define NULL
Definition: ccmath.h:32
void G_popen_clear(struct Popen *)
Definition: popen.c:56
const char * G_whoami(void)
Gets user's name.
Definition: gis/whoami.c:35
void G_popen_close(struct Popen *)
Definition: popen.c:72
FILE * G_popen_write(struct Popen *, const char *, const char **)
Definition: popen.c:62
FILE * G_open_pager(struct Popen *pager)
Definition: pager.c:13
FILE * G_open_mail(struct Popen *mail)
Definition: pager.c:45
void G_close_mail(struct Popen *mail)
Definition: pager.c:65
void G_close_pager(struct Popen *pager)
Definition: pager.c:35
Definition: gis.h:623