397
400
endcontext(&cntxt);
403
if(fdView >= 0) { /* might be open after viewers, but unlikely */
404
removeInputHandler(&R_InputHandlers,
405
getInputHandler(R_InputHandlers,fdView));
410
XFreeFontSet(iodisplay, font_set);
400
414
XCloseDisplay(iodisplay);
401
415
iodisplay = NULL;
1060
static SEXP lang5(SEXP s, SEXP t, SEXP u, SEXP v, SEXP w)
1063
s = LCONS(s, list4(t, u, v, w));
1068
static SEXP processEscapes(SEXP x)
1070
SEXP newval, pattern, replacement, expr;
1073
/* We process escape sequences in a scalar string by escaping
1074
unescaped quotes, then quoting the whole thing and parsing it. This
1075
is supposed to be equivalent to the R code
1077
newval <- gsub(perl=TRUE, "(?<!\\\\)((\\\\\\\\)*)\"", "\\1\\\\\"", x)
1078
newval <- sub('(^.*$)', '"\1"', newval)
1079
newval <- eval(parse(text=newval))
1081
We do it this way to avoid extracting the escape handling
1082
code from the parser. We need it in C code because this may be executed
1083
numerous times from C in dataentry.c */
1085
PROTECT( pattern = mkString("(?<!\\\\)((\\\\\\\\)*)\"") );
1086
PROTECT( replacement = mkString("\\1\\\\\"") );
1087
PROTECT( expr = lang5(install("gsub"), ScalarLogical(1), pattern, replacement, x) );
1088
SET_TAG( CDR(expr), install("perl") );
1090
PROTECT( newval = eval(expr, R_BaseEnv) );
1091
PROTECT( pattern = mkString("(^.*$)") );
1092
PROTECT( replacement = mkString("\"\\1\"") );
1093
PROTECT( expr = lang4(install("sub"), pattern, replacement, newval) );
1094
PROTECT( newval = eval(expr, R_BaseEnv) );
1095
PROTECT( expr = R_ParseVector( newval, 1, &status, R_NilValue) );
1097
/* We only handle the first entry. If this were available more generally,
1098
we'd probably want to loop over all of expr */
1100
if (status == PARSE_OK && length(expr))
1101
PROTECT( newval = eval(VECTOR_ELT(expr, 0), R_BaseEnv) );
1103
PROTECT( newval = R_NilValue ); /* protect just so the count doesn't change */
1046
1108
/* close up the entry to a cell, put the value that has been entered
1047
1109
into the correct place and as the correct type */
1091
1153
double new = R_strtod(buf, &endp);
1092
1154
Rboolean warn = !isBlankString(endp);
1093
if (TYPEOF(cvec) == STRSXP)
1094
SET_STRING_ELT(cvec, wrow - 1, mkChar(buf));
1155
if (TYPEOF(cvec) == STRSXP) {
1157
PROTECT( newval = mkString(buf) );
1158
PROTECT( newval = processEscapes(newval) );
1159
if (TYPEOF(newval) == STRSXP && length(newval) == 1)
1160
SET_STRING_ELT(cvec, wrow - 1, STRING_ELT(newval, 0));
1162
warning("dataentry: parse error on string");
1096
1165
REAL(cvec)[wrow - 1] = new;
1097
1166
if (newcol && warn) {
1098
1167
/* change mode to character */
1492
1561
DEEvent ioevent;
1495
1565
while (done == 0) {
1496
1566
XNextEvent(iodisplay, &ioevent);
1567
XFindContext(iodisplay, ioevent.xany.window, deContext, &temp);
1568
if ((DEstruct) temp != DE) { /* so a View window */
1569
if (WhichEvent(ioevent) == Expose)
1570
drawwindow((DEstruct) temp);
1498
1572
#ifdef USE_FONTSET
1499
1573
if (XFilterEvent(&ioevent, None)){
1608
1682
if(nView == 0) {
1683
/* NB: this is removing the handler that is currently
1684
being used: only OK to free here in R > 2.8.0 */
1609
1685
removeInputHandler(&R_InputHandlers,
1610
1686
getInputHandler(R_InputHandlers,fdView));
1690
XFreeFontSet(iodisplay, font_set);
1612
1694
XCloseDisplay(iodisplay);
1613
1695
iodisplay = NULL;
1928
2011
sprintf(opt_fontset_name, s, "medium", "r", 12);
1929
2012
} else strcpy(opt_fontset_name, fontset_name);
1931
font_set = XCreateFontSet(iodisplay, opt_fontset_name,
1932
&missing_charset_list,
1933
&missing_charset_count, &def_string);
1934
if (missing_charset_count) XFreeStringList(missing_charset_list);
2014
if(font_set == NULL) {
2015
font_set = XCreateFontSet(iodisplay, opt_fontset_name,
2016
&missing_charset_list,
2017
&missing_charset_count, &def_string);
2018
if (missing_charset_count) XFreeStringList(missing_charset_list);
1935
2020
if (font_set == NULL) {
1936
2021
warning("unable to create fontset %s", opt_fontset_name);
1937
2022
return TRUE; /* ERROR */
2099
2184
DE->iogc = XCreateGC(iodisplay, DE->iowindow, 0, 0);
2101
2186
#ifdef USE_FONTSET
2187
if(mbcslocale && DE->isEditor) {
2103
2188
ioim = XOpenIM(iodisplay, NULL, NULL, NULL);
2105
2190
XDestroyWindow(iodisplay, DE->iowindow);