GRASS GIS 7 Programmer's Manual
7.8.4(2020)-exported
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
RETSIGTYPE (*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
}
69
G_close_mail
void G_close_mail(struct Popen *mail)
Definition:
pager.c:65
G_whoami
const char * G_whoami(void)
Gets user's name.
Definition:
whoami.c:35
G_popen_close
void G_popen_close(struct Popen *state)
Definition:
popen.c:75
G_popen_write
FILE * G_popen_write(struct Popen *state, const char *program, const char **args)
Definition:
popen.c:65
NULL
#define NULL
Definition:
ccmath.h:32
G_close_pager
void G_close_pager(struct Popen *pager)
Definition:
pager.c:35
G_open_mail
FILE * G_open_mail(struct Popen *mail)
Definition:
pager.c:45
G_popen_clear
void G_popen_clear(struct Popen *state)
Definition:
popen.c:59
G_open_pager
FILE * G_open_pager(struct Popen *pager)
Definition:
pager.c:13
gis
pager.c
Generated on Mon Oct 5 2020 08:56:03 for GRASS GIS 7 Programmer's Manual by
1.8.18