23 #include <sys/types.h>
25 #include <grass/gis.h>
26 #include <grass/graphics.h>
30 #include <grass/glocale.h>
32 #define REC(a,b) if ((ateof=rec((a),(b)))) break
33 #define RECTEXT(x,s) if ((ateof=rectext(&x,&s))) break
34 #define SEND(a,b) _send((a),(b))
35 #define SENDTEXT(x) sendtext((x))
37 static int rec(
void *,
int);
38 static int rectext(
char **,
int *);
39 static int _send(
const void *,
int);
40 static int sendtext(
const char *);
41 static int RESULT(
int);
46 static char inbuf[4096];
50 static char current_command;
56 static unsigned char *blua;
57 static unsigned char *grna;
58 static unsigned char *reda;
59 static unsigned char *nula;
72 static void *xalloc(
void *buf,
int *cur,
int new,
int len)
75 buf = G_realloc(buf, (
size_t)
new * len);
98 static void send_fonts(
void (*func) (
char ***,
int *))
104 (*func) (&fonts, &num_fonts);
105 SEND(&num_fonts,
sizeof num_fonts);
106 for (i = 0; i < num_fonts; i++)
114 static int name_size;
120 unsigned char red, grn, blu;
129 int src[2][2], dst[2][2];
134 for (index = -10; index < BEGIN_SYNC_COUNT; index++)
145 SEND(&index,
sizeof index);
148 REC(&index,
sizeof index);
152 REC(&red,
sizeof red);
153 REC(&grn,
sizeof grn);
154 REC(&blu,
sizeof blu);
158 REC(&number,
sizeof number);
186 case GET_LOCATION_WITH_BOX:
194 SEND(&button,
sizeof button);
196 case GET_LOCATION_WITH_LINE:
204 SEND(&button,
sizeof button);
206 case GET_LOCATION_WITH_POINTER:
209 REC(&button,
sizeof button);
213 SEND(&button,
sizeof button);
231 REC(&index,
sizeof index);
233 (
unsigned char *)xalloc(blua, &blu_alloc, x * y,
sizeof(*blua));
234 REC(blua, x * y *
sizeof(
char));
237 case BEGIN_SCALED_RASTER:
238 REC(&index,
sizeof(
int));
239 REC(&src[0][0], 4 *
sizeof(
int));
240 REC(&dst[0][0], 4 *
sizeof(
int));
246 reda = (
unsigned char *)xalloc(reda, &red_alloc, x,
sizeof(*reda));
247 grna = (
unsigned char *)xalloc(grna, &grn_alloc, x,
sizeof(*grna));
248 blua = (
unsigned char *)xalloc(blua, &blu_alloc, x,
sizeof(*blua));
249 nula = (
unsigned char *)xalloc(nula, &nul_alloc, x,
sizeof(*nula));
250 REC(reda, x *
sizeof(
char));
251 REC(grna, x *
sizeof(
char));
252 REC(blua, x *
sizeof(
char));
253 REC(nula, x *
sizeof(
char));
256 SEND(&ret,
sizeof ret);
258 case END_SCALED_RASTER:
262 REC(&number,
sizeof number);
263 xarray = (
int *)xalloc(xarray, &n_xarray, number,
sizeof(*xarray));
264 yarray = (
int *)xalloc(yarray, &n_yarray, number,
sizeof(*yarray));
265 REC(xarray, number *
sizeof(xarray[0]));
266 REC(yarray, number *
sizeof(yarray[0]));
270 REC(&number,
sizeof number);
271 xarray = (
int *)xalloc(xarray, &n_xarray, number,
sizeof(*xarray));
272 yarray = (
int *)xalloc(yarray, &n_yarray, number,
sizeof(*yarray));
273 REC(xarray, number *
sizeof(xarray[0]));
274 REC(yarray, number *
sizeof(yarray[0]));
278 REC(&number,
sizeof number);
279 xarray = (
int *)xalloc(xarray, &n_xarray, number,
sizeof(*xarray));
280 yarray = (
int *)xalloc(yarray, &n_yarray, number,
sizeof(*yarray));
281 REC(xarray, number *
sizeof(xarray[0]));
282 REC(yarray, number *
sizeof(yarray[0]));
286 REC(&number,
sizeof number);
287 xarray = (
int *)xalloc(xarray, &n_xarray, number,
sizeof(*xarray));
288 yarray = (
int *)xalloc(yarray, &n_yarray, number,
sizeof(*yarray));
289 REC(xarray, number *
sizeof(xarray[0]));
290 REC(yarray, number *
sizeof(yarray[0]));
294 REC(&number,
sizeof number);
295 xarray = (
int *)xalloc(xarray, &n_xarray, number,
sizeof(*xarray));
296 yarray = (
int *)xalloc(yarray, &n_yarray, number,
sizeof(*yarray));
297 REC(xarray, number *
sizeof(xarray[0]));
298 REC(yarray, number *
sizeof(yarray[0]));
302 REC(&number,
sizeof number);
303 xarray = (
int *)xalloc(xarray, &n_xarray, number,
sizeof(*xarray));
304 yarray = (
int *)xalloc(yarray, &n_yarray, number,
sizeof(*yarray));
305 REC(xarray, number *
sizeof(xarray[0]));
306 REC(yarray, number *
sizeof(yarray[0]));
311 SEND(&index,
sizeof index);
315 SEND(&index,
sizeof index);
319 SEND(&index,
sizeof index);
323 SEND(&index,
sizeof index);
396 if (curpad == NULL) {
409 else if (*curpad->
name == 0)
441 if (curpad == NULL) {
451 for (list = item->
list; list != NULL; list = list->
next)
460 if (curpad == NULL) {
471 case PAD_APPEND_ITEM:
474 REC(&index,
sizeof index);
475 if (curpad == NULL) {
485 case PAD_DELETE_ITEM:
487 if (curpad == NULL) {
496 if (curpad == NULL) {
501 for (item = curpad->
items; item != NULL; item = item->
next)
508 G_warning(_(
"Unknown command: %d last: %d"), c, lc);
516 static int read1(
char *c)
518 if (atbuf == n_read) {
520 n_read = read(_rfd, inbuf,
sizeof inbuf);
522 perror(
"Monitor: read1: Error reading input");
533 if ((*c = current_command)) {
542 while (read1(c) == 0) {
543 if (*c != COMMAND_ESC)
545 while (*c == COMMAND_ESC)
547 G_warning(_(
"Monitor: get_command: Premature EOF"));
556 static int get1(
char *c)
560 if (*c != COMMAND_ESC)
565 current_command = *c;
572 static int rec(
void *buf,
int n)
578 if ((stat = get1(cbuf++)) != 0)
584 static int rectext(
char **buff_p,
int *size_p)
586 char *buff = *buff_p;
598 *size_p = size = size ? size * 2 : 1000;
599 *buff_p = buff = G_realloc(buff, size);
609 static int _send(
const void *buf,
int n)
611 int r = write(_wfd, buf, n);
614 perror(
"Monitor: _send: write");
618 G_warning(
"Monitor: _send: write returned short count: %d of %d",
625 static int sendtext(
const char *
s)
627 SEND(s, strlen(s) + 1);
631 static int RESULT(
int n)