void GEaddDevice(pGEDevDesc gdd) { int i; Rboolean appnd; SEXP s, t; pGEDevDesc oldd; PROTECT(s = getSymbolValue(R_DevicesSymbol)); if (!NoDevices()) { oldd = GEcurrentDevice(); if(oldd->dev->deactivate) oldd->dev->deactivate(oldd->dev); } /* find empty slot for new descriptor */ i = 1; if (CDR(s) == R_NilValue) appnd = TRUE; else { s = CDR(s); appnd = FALSE; } while (R_Devices[i] != NULL) { i++; if (CDR(s) == R_NilValue) appnd = TRUE; else s = CDR(s); } R_CurrentDevice = i; R_NumDevices++; R_Devices[i] = gdd; active[i] = TRUE; GEregisterWithDevice(gdd); if(gdd->dev->activate) gdd->dev->activate(gdd->dev); /* maintain .Devices (.Device has already been set) */ t = PROTECT(duplicate(getSymbolValue(R_DeviceSymbol))); if (appnd) SETCDR(s, CONS(t, R_NilValue)); else SETCAR(s, t); UNPROTECT(2); /* In case a device driver did not call R_CheckDeviceAvailable before starting its allocation, we complete the allocation and then call killDevice here. This ensures that the device gets a chance to deallocate its resources and the current active device is restored to a sane value. */ if (i == R_MaxDevices - 1) { killDevice(i); error(_("too many open devices")); } }
int selectDevice(int devNum) { /* Valid to select nullDevice, but that will open a new device. See ?dev.set. */ if((devNum >= 0) && (devNum < R_MaxDevices) && (R_Devices[devNum] != NULL) && active[devNum]) { pGEDevDesc gdd; if (!NoDevices()) { pGEDevDesc oldd = GEcurrentDevice(); if (oldd->dev->deactivate) oldd->dev->deactivate(oldd->dev); } R_CurrentDevice = devNum; /* maintain .Device */ gsetVar(R_DeviceSymbol, elt(getSymbolValue(R_DevicesSymbol), devNum), R_BaseEnv); gdd = GEcurrentDevice(); /* will start a device if current is null */ if (!NoDevices()) /* which it always will be */ if (gdd->dev->activate) gdd->dev->activate(gdd->dev); return devNum; } else return selectDevice(nextDevice(devNum)); }
/* historically the close was in the [kK]illDevices. only use findNext = FALSE when shutting R dowm, and .Device[s] are not updated. */ static void removeDevice(int devNum, Rboolean findNext) { /* Not vaild to remove nullDevice */ if((devNum > 0) && (devNum < R_MaxDevices) && (R_Devices[devNum] != NULL) && active[devNum]) { int i; SEXP s; pGEDevDesc g = R_Devices[devNum]; active[devNum] = FALSE; /* stops it being selected again */ R_NumDevices--; if(findNext) { /* maintain .Devices */ PROTECT(s = getSymbolValue(R_DevicesSymbol)); for (i = 0; i < devNum; i++) s = CDR(s); SETCAR(s, mkString("")); UNPROTECT(1); /* determine new current device */ if (devNum == R_CurrentDevice) { R_CurrentDevice = nextDevice(R_CurrentDevice); /* maintain .Device */ gsetVar(R_DeviceSymbol, elt(getSymbolValue(R_DevicesSymbol), R_CurrentDevice), R_BaseEnv); /* activate new current device */ if (R_CurrentDevice) { pGEDevDesc gdd = GEcurrentDevice(); if(gdd->dev->activate) gdd->dev->activate(gdd->dev); } } } g->dev->close(g->dev); GEdestroyDevDesc(g); R_Devices[devNum] = NULL; } }
void factor () { if (token.sym == identsym) { emit(1,0,getSymbolValue(token.word)); getToken(); } else if(token.sym == numbersym) { emit(1, 0, atoi(token.word)); getToken(); } else if(token.sym == '(') { getToken(); expression(); if(token.sym != ')') getError(9); getToken(); } else getError(10); }