1 #include <grass/config.h>
12 #include <grass/gis.h>
13 #include <grass/glocale.h>
14 #include <grass/raster.h>
15 #include <grass/graphics.h>
20 #define BUFFERSIZ 2048
25 int sync_driver(
char *);
27 static unsigned char outbuf[BUFFERSIZ];
29 static volatile int no_mon;
31 static RETSIGTYPE dead(
int);
33 static int _get(
char *
buf,
int n)
38 x = read(_rfd, buf, n);
40 fprintf(stderr, _(
"ERROR %s from graphics driver.\n"),
41 x ?
"reading" :
"eof");
51 static int flushout(
void)
54 write(_wfd, outbuf, (
size_t) cursiz);
61 int _send_ident(
int anint)
67 if ((cursiz + 2) >= BUFFERSIZ)
69 outbuf[cursiz++] = COMMAND_ESC;
70 outbuf[cursiz++] = achar;
75 int _send_char(
const unsigned char *achar)
77 if ((cursiz + 2) >= BUFFERSIZ)
79 outbuf[cursiz++] = *achar;
80 if (*achar == COMMAND_ESC)
86 int _send_char_array(
int num,
const unsigned char *achar)
94 int _send_int_array(
int num,
const int *anint)
96 return _send_char_array(num *
sizeof(
int), (
const unsigned char *)anint);
99 int _send_float_array(
int num,
const float *afloat)
101 return _send_char_array(num *
sizeof(
float),
102 (
const unsigned char *)afloat);
105 int _send_int(
const int *anint)
107 return _send_char_array(
sizeof(
int), (
const unsigned char *)anint);
110 int _send_float(
const float *afloat)
112 return _send_char_array(
sizeof(
float), (
const unsigned char *)afloat);
115 int _send_text(
const char *text)
117 return _send_char_array(1 + strlen(text), (
const unsigned char *)text);
120 int _get_char(
char *achar)
128 int _get_int(
int *anint)
131 _get((
char *)anint,
sizeof(
int));
136 int _get_float(
float *afloat)
139 _get((
char *)afloat,
sizeof(
float));
144 int _get_text(
char *buf)
156 char *_get_text_2(
void)
165 buf = G_realloc(buf, len);
167 fprintf(stderr, _(
"Unable to allocate memory\n"));
186 int sync_driver(
char *
name)
189 RETSIGTYPE(*sigalarm) (
int);
206 sigalarm =
signal(SIGALRM, dead);
208 for (
try = 0;
try < 2;
try++) {
213 while (no_mon == 0) {
214 if (read(_rfd, &c, (
size_t) 1) != 1) {
217 fprintf(stderr, _(
"ERROR - eof from graphics monitor.\n"));
222 else if (c == COMMAND_ESC && count >= BEGIN_SYNC_COUNT)
229 signal(SIGALRM, sigalarm);
237 _(
"Warning - no response from graphics monitor <%s>.\n"),
239 fprintf(stderr, _(
"Check to see if the mouse is still active.\n"));
244 fprintf(stderr, _(
"ERROR - no response from graphics monitor <%s>.\n"),
249 static RETSIGTYPE dead(
int sig)
254 void _hold_signals(
int hold)
256 static RETSIGTYPE(*sigint) (
int);
259 static RETSIGTYPE(*sigquit) (
int);
263 sigint =
signal(SIGINT, SIG_IGN);
265 sigquit =
signal(SIGQUIT, SIG_IGN);
294 _send_ident(RESPOND);
302 _send_ident(GRAPH_CLOSE);
304 read(_rfd, &dummy, 1);
void R_release_driver(void)
int REM__open_quiet(void)
void REM_close_driver(void)
char buf[GNAME_MAX+sizeof(G3D_DIRECTORY)+2]
void REM_kill_driver(void)
void REM_release_driver(void)