/
dodevga.c
87 lines (78 loc) · 2.54 KB
/
dodevga.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/*
* R : A Computer Language for Statistical Data Analysis
* Copyright (C) 1998, 1999 Guido Masarotto and Brian Ripley
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include "Defn.h"
#include "Mathlib.h"
#include "Graphics.h"
static SEXP gcall;
int X11DeviceDriver(DevDesc *, char *, double, double, double);
/* Return a non-relocatable copy of a string */
static char *SaveString(SEXP sxp, int offset)
{
char *s;
if (!isString(sxp) || length(sxp) <= offset)
errorcall(gcall, "invalid string argument");
s = R_alloc(strlen(CHAR(STRING(sxp)[offset])) + 1, sizeof(char));
strcpy(s, CHAR(STRING(sxp)[offset]));
return s;
}
/* This is Guido's devga device. */
/* X11 Device Driver Parameters:
* ----------------- --> ../unix/devX11.c
* display = display
* width = width in inches
* height = height in inches
* ps = pointsize
*/
SEXP do_devga(SEXP call, SEXP op, SEXP args, SEXP env)
{
DevDesc *dd;
char *display, *vmax;
double height, width, ps;
gcall = call;
vmax = vmaxget();
display = SaveString(CAR(args), 0);
args = CDR(args);
width = asReal(CAR(args));
args = CDR(args);
height = asReal(CAR(args));
args = CDR(args);
if (width <= 0 || height <= 0)
errorcall(call, "invalid width or height");
ps = asReal(CAR(args));
args = CDR(args);
/* Allocate and initialize the device driver data */
if (!(dd = (DevDesc *) malloc(sizeof(DevDesc))))
return 0;
/* Do this for early redraw attempts */
dd->displayList = R_NilValue;
GInit(&dd->dp);
if (!X11DeviceDriver(dd, display, width, height, ps)) {
free(dd);
errorcall(call, "unable to start device devga");
}
gsetVar(install(".Device"),
mkString(display[0] ? display : "windows"), R_NilValue);
addDevice(dd);
initDisplayList(dd);
vmaxset(vmax);
return R_NilValue;
}