~ubuntu-branches/ubuntu/vivid/grass/vivid-proposed

« back to all changes in this revision

Viewing changes to lib/driver/command.c

  • Committer: Package Import Robot
  • Author(s): Bas Couwenberg
  • Date: 2015-02-20 23:12:08 UTC
  • mfrom: (8.2.6 experimental)
  • Revision ID: package-import@ubuntu.com-20150220231208-1u6qvqm84v430b10
Tags: 7.0.0-1~exp1
* New upstream release.
* Update python-ctypes-ternary.patch to use if/else instead of and/or.
* Drop check4dev patch, rely on upstream check.
* Add build dependency on libpq-dev to grass-dev for libpq-fe.h.
* Drop patches applied upstream, refresh remaining patches.
* Update symlinks for images switched from jpg to png.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
 
2
 
/****************************************************************************
3
 
 *
4
 
 * MODULE:       driver
5
 
 * AUTHOR(S):    Glynn Clements <glynn gclements.plus.com> (original contributor)
6
 
 *               Jachym Cepicky <jachym les-ejk.cz>
7
 
 * PURPOSE:      
8
 
 * COPYRIGHT:    (C) 2006-2007 by the GRASS Development Team
9
 
 *
10
 
 *               This program is free software under the GNU General Public
11
 
 *               License (>=v2). Read the file COPYING that comes with GRASS
12
 
 *               for details.
13
 
 *
14
 
 *****************************************************************************/
15
 
#include <stdio.h>
16
 
#include <string.h>
17
 
#include <stdlib.h>
18
 
#include <signal.h>
19
 
#include <setjmp.h>
20
 
#include <unistd.h>
21
 
#include <errno.h>
22
 
#include <sys/time.h>
23
 
#include <sys/types.h>
24
 
 
25
 
#include <grass/gis.h>
26
 
#include <grass/graphics.h>
27
 
#include "driverlib.h"
28
 
#include "driver.h"
29
 
#include "pad.h"
30
 
#include <grass/glocale.h>
31
 
 
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))
36
 
 
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);
42
 
 
43
 
static int _wfd;
44
 
static int _rfd;
45
 
 
46
 
static char inbuf[4096];
47
 
static int n_read;
48
 
static int atbuf;
49
 
 
50
 
static char current_command;
51
 
 
52
 
static int ateof;
53
 
 
54
 
static PAD *curpad;             /* current selected pad */
55
 
 
56
 
static unsigned char *blua;
57
 
static unsigned char *grna;
58
 
static unsigned char *reda;
59
 
static unsigned char *nula;
60
 
static int blu_alloc;
61
 
static int grn_alloc;
62
 
static int red_alloc;
63
 
static int nul_alloc;
64
 
 
65
 
static int *xarray;
66
 
static int *yarray;
67
 
static int n_xarray;
68
 
static int n_yarray;
69
 
 
70
 
static char lc;
71
 
 
72
 
static void *xalloc(void *buf, int *cur, int new, int len)
73
 
{
74
 
    if (*cur < new) {
75
 
        buf = G_realloc(buf, (size_t) new * len);
76
 
        *cur = new;
77
 
    }
78
 
 
79
 
    return buf;
80
 
}
81
 
 
82
 
void command_init(int rfd, int wfd)
83
 
{
84
 
    _rfd = rfd;
85
 
    _wfd = wfd;
86
 
 
87
 
    atbuf = n_read = 0;
88
 
    current_command = 0;
89
 
 
90
 
    ateof = 0;
91
 
}
92
 
 
93
 
int LIB_command_get_input(void)
94
 
{
95
 
    return _rfd;
96
 
}
97
 
 
98
 
static void send_fonts(void (*func) (char ***, int *))
99
 
{
100
 
    char **fonts;
101
 
    int num_fonts;
102
 
    int i;
103
 
 
104
 
    (*func) (&fonts, &num_fonts);
105
 
    SEND(&num_fonts, sizeof num_fonts);
106
 
    for (i = 0; i < num_fonts; i++)
107
 
        SENDTEXT(fonts[i]);
108
 
    free_font_list(fonts, num_fonts);
109
 
}
110
 
 
111
 
int process_command(int c)
112
 
{
113
 
    static char *name;
114
 
    static int name_size;
115
 
    static char *text;
116
 
    static int text_size;
117
 
 
118
 
    int t, b, l, r, ret;
119
 
    int x, y;
120
 
    unsigned char red, grn, blu;
121
 
    int number;
122
 
    int index;
123
 
    int button;
124
 
    float wx;
125
 
    ITEM *item;
126
 
    LIST *list;
127
 
    PAD *pad;
128
 
    unsigned char ch;
129
 
    int src[2][2], dst[2][2];
130
 
 
131
 
    switch (c) {
132
 
    case BEGIN:
133
 
        ch = 0;
134
 
        for (index = -10; index < BEGIN_SYNC_COUNT; index++)
135
 
            SEND(&ch, 1);
136
 
        ch = COMMAND_ESC;
137
 
        SEND(&ch, 1);
138
 
        break;
139
 
    case RESPOND:
140
 
        COM_Respond();
141
 
        SEND(&ch, 1);
142
 
        break;
143
 
    case GET_NUM_COLORS:
144
 
        COM_Number_of_colors(&index);
145
 
        SEND(&index, sizeof index);
146
 
        break;
147
 
    case STANDARD_COLOR:
148
 
        REC(&index, sizeof index);
149
 
        COM_Standard_color(index);
150
 
        break;
151
 
    case RGB_COLOR:
152
 
        REC(&red, sizeof red);
153
 
        REC(&grn, sizeof grn);
154
 
        REC(&blu, sizeof blu);
155
 
        COM_Color_RGB(red, grn, blu);
156
 
        break;
157
 
    case LINE_WIDTH:
158
 
        REC(&number, sizeof number);
159
 
        COM_Line_width(number);
160
 
        break;
161
 
    case CONT_ABS:
162
 
        REC(&x, sizeof x);
163
 
        REC(&y, sizeof y);
164
 
        COM_Cont_abs(x, y);
165
 
        break;
166
 
    case CONT_REL:
167
 
        REC(&x, sizeof x);
168
 
        REC(&y, sizeof y);
169
 
        COM_Cont_rel(x, y);
170
 
        break;
171
 
    case BOX_ABS:
172
 
        REC(&l, sizeof l);
173
 
        REC(&t, sizeof t);
174
 
        REC(&r, sizeof r);
175
 
        REC(&b, sizeof b);
176
 
        COM_Box_abs(l, t, r, b);
177
 
        break;
178
 
    case BOX_REL:
179
 
        REC(&l, sizeof l);
180
 
        REC(&t, sizeof t);
181
 
        COM_Box_rel(l, t);
182
 
        break;
183
 
    case ERASE:
184
 
        COM_Erase();
185
 
        break;
186
 
    case GET_LOCATION_WITH_BOX:
187
 
        REC(&t, sizeof t);
188
 
        REC(&b, sizeof b);
189
 
        REC(&x, sizeof x);
190
 
        REC(&y, sizeof y);
191
 
        COM_Get_location_with_box(t, b, &x, &y, &button);
192
 
        SEND(&x, sizeof x);
193
 
        SEND(&y, sizeof y);
194
 
        SEND(&button, sizeof button);
195
 
        break;
196
 
    case GET_LOCATION_WITH_LINE:
197
 
        REC(&t, sizeof t);
198
 
        REC(&b, sizeof b);
199
 
        REC(&x, sizeof x);
200
 
        REC(&y, sizeof y);
201
 
        COM_Get_location_with_line(t, b, &x, &y, &button);
202
 
        SEND(&x, sizeof x);
203
 
        SEND(&y, sizeof y);
204
 
        SEND(&button, sizeof button);
205
 
        break;
206
 
    case GET_LOCATION_WITH_POINTER:
207
 
        REC(&x, sizeof x);
208
 
        REC(&y, sizeof y);
209
 
        REC(&button, sizeof button);
210
 
        COM_Get_location_with_pointer(&x, &y, &button);
211
 
        SEND(&x, sizeof x);
212
 
        SEND(&y, sizeof y);
213
 
        SEND(&button, sizeof button);
214
 
        break;
215
 
    case GRAPH_CLOSE:
216
 
        COM_Graph_close();
217
 
        exit(0);
218
 
    case MOVE_ABS:
219
 
        REC(&x, sizeof x);
220
 
        REC(&y, sizeof y);
221
 
        COM_Move_abs(x, y);
222
 
        break;
223
 
    case MOVE_REL:
224
 
        REC(&x, sizeof x);
225
 
        REC(&y, sizeof y);
226
 
        COM_Move_rel(x, y);
227
 
        break;
228
 
    case BITMAP:
229
 
        REC(&x, sizeof x);
230
 
        REC(&y, sizeof y);
231
 
        REC(&index, sizeof index);
232
 
        blua =
233
 
            (unsigned char *)xalloc(blua, &blu_alloc, x * y, sizeof(*blua));
234
 
        REC(blua, x * y * sizeof(char));
235
 
        COM_Bitmap(x, y, index, blua);
236
 
        break;
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));
241
 
        COM_begin_scaled_raster(index, src, dst);
242
 
        break;
243
 
    case SCALED_RASTER:
244
 
        REC(&x, sizeof x);
245
 
        REC(&y, sizeof y);
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));
254
 
        REC(&t, sizeof t);
255
 
        ret = COM_scaled_raster(x, y, reda, grna, blua, t ? nula : NULL);
256
 
        SEND(&ret, sizeof ret);
257
 
        break;
258
 
    case END_SCALED_RASTER:
259
 
        COM_end_scaled_raster();
260
 
        break;
261
 
    case POLYGON_ABS:
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]));
267
 
        COM_Polygon_abs(xarray, yarray, number);
268
 
        break;
269
 
    case POLYGON_REL:
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]));
275
 
        COM_Polygon_rel(xarray, yarray, number);
276
 
        break;
277
 
    case POLYLINE_ABS:
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]));
283
 
        COM_Polyline_abs(xarray, yarray, number);
284
 
        break;
285
 
    case POLYLINE_REL:
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]));
291
 
        COM_Polyline_rel(xarray, yarray, number);
292
 
        break;
293
 
    case POLYDOTS_ABS:
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]));
299
 
        COM_Polydots_abs(xarray, yarray, number);
300
 
        break;
301
 
    case POLYDOTS_REL:
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]));
307
 
        COM_Polydots_rel(xarray, yarray, number);
308
 
        break;
309
 
    case SCREEN_LEFT:
310
 
        COM_Screen_left(&index);
311
 
        SEND(&index, sizeof index);
312
 
        break;
313
 
    case SCREEN_RITE:
314
 
        COM_Screen_rite(&index);
315
 
        SEND(&index, sizeof index);
316
 
        break;
317
 
    case SCREEN_BOT:
318
 
        COM_Screen_bot(&index);
319
 
        SEND(&index, sizeof index);
320
 
        break;
321
 
    case SCREEN_TOP:
322
 
        COM_Screen_top(&index);
323
 
        SEND(&index, sizeof index);
324
 
        break;
325
 
    case SET_WINDOW:
326
 
        REC(&t, sizeof t);
327
 
        REC(&b, sizeof b);
328
 
        REC(&l, sizeof l);
329
 
        REC(&r, sizeof r);
330
 
        COM_Set_window(t, b, l, r);
331
 
        break;
332
 
    case GET_TEXT_BOX:
333
 
        RECTEXT(text, text_size);
334
 
        COM_Get_text_box(text, &t, &b, &l, &r);
335
 
        SEND(&t, sizeof t);
336
 
        SEND(&b, sizeof b);
337
 
        SEND(&l, sizeof l);
338
 
        SEND(&r, sizeof r);
339
 
        break;
340
 
    case FONT:
341
 
        RECTEXT(text, text_size);
342
 
        COM_Font_get(text);
343
 
        break;
344
 
    case CHARSET:
345
 
        RECTEXT(text, text_size);
346
 
        COM_Font_init_charset(text);
347
 
        break;
348
 
    case FONT_LIST:
349
 
        send_fonts(COM_Font_list);
350
 
        break;
351
 
    case FONT_INFO:
352
 
        send_fonts(COM_Font_info);
353
 
        break;
354
 
    case TEXT:
355
 
        RECTEXT(text, text_size);
356
 
        COM_Text(text);
357
 
        break;
358
 
    case TEXT_SIZE:
359
 
        REC(&x, sizeof x);
360
 
        REC(&y, sizeof y);
361
 
        COM_Text_size(x, y);
362
 
        break;
363
 
    case TEXT_ROTATION:
364
 
        REC(&wx, sizeof wx);
365
 
        COM_Text_rotation(wx);
366
 
        break;
367
 
    case PANEL_SAVE:
368
 
        RECTEXT(text, text_size);
369
 
        REC(&t, sizeof t);
370
 
        REC(&b, sizeof b);
371
 
        REC(&l, sizeof l);
372
 
        REC(&r, sizeof r);
373
 
        COM_Panel_save(text, t, b, l, r);
374
 
        break;
375
 
    case PANEL_RESTORE:
376
 
        RECTEXT(text, text_size);
377
 
        COM_Panel_restore(text);
378
 
        break;
379
 
    case PANEL_DELETE:
380
 
        RECTEXT(text, text_size);
381
 
        COM_Panel_delete(text);
382
 
        break;
383
 
    case PAD_CREATE:
384
 
        RECTEXT(text, text_size);
385
 
        if (*text == 0)         /* this is scratch pad */
386
 
            RESULT(OK);
387
 
        else if (find_pad(text) != NULL)
388
 
            RESULT(DUPLICATE);  /* duplicate pad */
389
 
        else if (create_pad(text))
390
 
            RESULT(OK);
391
 
        else
392
 
            RESULT(NO_MEMORY);
393
 
        break;
394
 
 
395
 
    case PAD_CURRENT:
396
 
        if (curpad == NULL) {
397
 
            RESULT(NO_CUR_PAD);
398
 
            SENDTEXT("");
399
 
        }
400
 
        else {
401
 
            RESULT(OK);
402
 
            SENDTEXT(curpad->name);
403
 
        }
404
 
        break;
405
 
 
406
 
    case PAD_DELETE:
407
 
        if (curpad == NULL)
408
 
            RESULT(NO_CUR_PAD);
409
 
        else if (*curpad->name == 0)
410
 
            RESULT(ILLEGAL);
411
 
        else {
412
 
            delete_pad(curpad);
413
 
            curpad = NULL;
414
 
            RESULT(OK);
415
 
        }
416
 
        break;
417
 
 
418
 
    case PAD_INVENT:
419
 
        invent_pad(text);
420
 
        SENDTEXT(text);
421
 
        break;
422
 
 
423
 
    case PAD_LIST:
424
 
        for (pad = pad_list(); pad != NULL; pad = pad->next)
425
 
            if (*pad->name)
426
 
                SENDTEXT(pad->name);
427
 
        SENDTEXT("");
428
 
        break;
429
 
 
430
 
    case PAD_SELECT:
431
 
        RECTEXT(text, text_size);       /* pad name */
432
 
        curpad = find_pad(text);
433
 
        if (curpad == NULL)
434
 
            RESULT(NO_PAD);
435
 
        else
436
 
            RESULT(OK);
437
 
        break;
438
 
 
439
 
    case PAD_GET_ITEM:
440
 
        RECTEXT(text, text_size);       /* item name */
441
 
        if (curpad == NULL) {
442
 
            RESULT(NO_CUR_PAD);
443
 
            break;
444
 
        }
445
 
        item = find_item(curpad, text);
446
 
        if (item == NULL) {
447
 
            RESULT(NO_ITEM);
448
 
            break;
449
 
        }
450
 
        RESULT(OK);
451
 
        for (list = item->list; list != NULL; list = list->next)
452
 
            if (*list->value)
453
 
                SENDTEXT(list->value);
454
 
        SENDTEXT("");
455
 
        break;
456
 
 
457
 
    case PAD_SET_ITEM:
458
 
        RECTEXT(name, name_size);       /* item name */
459
 
        RECTEXT(text, text_size);       /* item value */
460
 
        if (curpad == NULL) {
461
 
            RESULT(NO_CUR_PAD);
462
 
            break;
463
 
        }
464
 
        delete_item(curpad, name);
465
 
        if (append_item(curpad, name, text, 0))
466
 
            RESULT(OK);
467
 
        else
468
 
            RESULT(NO_MEMORY);
469
 
        break;
470
 
 
471
 
    case PAD_APPEND_ITEM:
472
 
        RECTEXT(name, name_size);       /* item name */
473
 
        RECTEXT(text, text_size);       /* item value */
474
 
        REC(&index, sizeof index);      /* replace flag */
475
 
        if (curpad == NULL) {
476
 
            RESULT(NO_CUR_PAD);
477
 
            break;
478
 
        }
479
 
        if (append_item(curpad, name, text, index))
480
 
            RESULT(OK);
481
 
        else
482
 
            RESULT(NO_MEMORY);
483
 
        break;
484
 
 
485
 
    case PAD_DELETE_ITEM:
486
 
        RECTEXT(text, text_size);       /* item name */
487
 
        if (curpad == NULL) {
488
 
            RESULT(NO_CUR_PAD);
489
 
            break;
490
 
        }
491
 
        delete_item(curpad, text);
492
 
        RESULT(OK);
493
 
        break;
494
 
 
495
 
    case PAD_LIST_ITEMS:
496
 
        if (curpad == NULL) {
497
 
            RESULT(NO_CUR_PAD);
498
 
            break;
499
 
        }
500
 
        RESULT(OK);
501
 
        for (item = curpad->items; item != NULL; item = item->next)
502
 
            if (*item->name)
503
 
                SENDTEXT(item->name);
504
 
        SENDTEXT("");
505
 
        break;
506
 
 
507
 
    default:
508
 
        G_warning(_("Unknown command: %d last: %d"), c, lc);
509
 
        break;
510
 
    }
511
 
    lc = c;
512
 
 
513
 
    return ateof;
514
 
}
515
 
 
516
 
static int read1(char *c)
517
 
{
518
 
    if (atbuf == n_read) {
519
 
        atbuf = 0;
520
 
        n_read = read(_rfd, inbuf, sizeof inbuf);
521
 
        if (n_read < 0)
522
 
            perror("Monitor: read1: Error reading input");
523
 
        if (n_read <= 0)
524
 
            return 1;           /* EOF */
525
 
    }
526
 
    *c = inbuf[atbuf++];
527
 
    return 0;
528
 
}
529
 
 
530
 
int get_command(char *c)
531
 
{
532
 
    /* is there a command char pending? */
533
 
    if ((*c = current_command)) {
534
 
        current_command = 0;
535
 
        return 0;
536
 
    }
537
 
 
538
 
    /*
539
 
     * look for 1 (or more) COMMAND_ESC chars
540
 
     * followed by a non-zero comamnd token char
541
 
     */
542
 
    while (read1(c) == 0) {     /* while !EOF */
543
 
        if (*c != COMMAND_ESC)
544
 
            continue;
545
 
        while (*c == COMMAND_ESC)
546
 
            if (read1(c) != 0) {
547
 
                G_warning(_("Monitor: get_command: Premature EOF"));
548
 
                return 1;       /* EOF */
549
 
            }
550
 
        if (*c)
551
 
            return 0;           /* got the command token */
552
 
    }
553
 
    return 1;                   /* EOF */
554
 
}
555
 
 
556
 
static int get1(char *c)
557
 
{
558
 
    if (read1(c) != 0)
559
 
        return 1;               /* EOF */
560
 
    if (*c != COMMAND_ESC)
561
 
        return 0;               /* OK */
562
 
    if (read1(c) != 0)
563
 
        return 1;               /* EOF */
564
 
    if (*c) {
565
 
        current_command = *c;
566
 
        return -1;              /* Got command within data */
567
 
    }
568
 
    *c = COMMAND_ESC;           /* sequence COMMAND_ESC,0 becomes data COMMAND_ESC */
569
 
    return 0;                   /* OK */
570
 
}
571
 
 
572
 
static int rec(void *buf, int n)
573
 
{
574
 
    char *cbuf = buf;
575
 
    int stat;
576
 
 
577
 
    while (n-- > 0) {
578
 
        if ((stat = get1(cbuf++)) != 0)
579
 
            return stat;        /* EOF or COMMAND_ESC */
580
 
    }
581
 
    return 0;
582
 
}
583
 
 
584
 
static int rectext(char **buff_p, int *size_p)
585
 
{
586
 
    char *buff = *buff_p;
587
 
    int size = *size_p;
588
 
    int i, stat;
589
 
 
590
 
    for (i = 0;; i++) {
591
 
        char c;
592
 
 
593
 
        stat = get1(&c);
594
 
        if (stat != 0)
595
 
            return stat;        /* EOF or COMMAND_ESC */
596
 
 
597
 
        if (i >= size) {
598
 
            *size_p = size = size ? size * 2 : 1000;
599
 
            *buff_p = buff = G_realloc(buff, size);
600
 
        }
601
 
 
602
 
        buff[i] = c;
603
 
 
604
 
        if (!c)
605
 
            return 0;
606
 
    }
607
 
}
608
 
 
609
 
static int _send(const void *buf, int n)
610
 
{
611
 
    int r = write(_wfd, buf, n);
612
 
 
613
 
    if (r < 0) {
614
 
        perror("Monitor: _send: write");
615
 
        return 1;
616
 
    }
617
 
    if (r < n) {
618
 
        G_warning("Monitor: _send: write returned short count: %d of %d",
619
 
                  r, n);
620
 
        return 1;
621
 
    }
622
 
    return 0;
623
 
}
624
 
 
625
 
static int sendtext(const char *s)
626
 
{
627
 
    SEND(s, strlen(s) + 1);
628
 
    return 0;
629
 
}
630
 
 
631
 
static int RESULT(int n)
632
 
{
633
 
    unsigned char c;
634
 
 
635
 
    c = n;
636
 
    SEND(&c, 1);
637
 
 
638
 
    return 0;
639
 
}