GRASS GIS 7 Programmer's Manual  7.5.svn(2018)-r72103
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 
void G_popen_close(struct Popen *state)
Definition: popen.c:75
FILE * G_popen_write(struct Popen *state, const char *program, const char **args)
Definition: popen.c:65
FILE * G_open_mail(struct Popen *mail)
Definition: pager.c:45
FILE * G_open_pager(struct Popen *pager)
Definition: pager.c:13
#define NULL
Definition: ccmath.h:32
const char * G_whoami(void)
Gets user&#39;s name.
Definition: gis/whoami.c:35
void G_close_pager(struct Popen *pager)
Definition: pager.c:35
Definition: gis.h:575
void G_close_mail(struct Popen *mail)
Definition: pager.c:65
void G_popen_clear(struct Popen *state)
Definition: popen.c:59
int
Reads the categories file for map name in mapset and stores the categories in the pcats structure...
#define RETSIGTYPE
Definition: config.h:97
char * getenv()