-
-
Notifications
You must be signed in to change notification settings - Fork 308
/
pager.c
69 lines (49 loc) · 1.01 KB
/
pager.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#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;
G_popen_clear(pager);
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;
G_popen_clear(mail);
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);
}