SetPort(GetWindowPort(window));
SetPort((GrafPtr)GetWindowPort(window));
void mac_updateterm(WindowPtr window) {    Session *s;    Rect bbox;#if TARGET_API_MAC_CARBON    RgnHandle visrgn;#endif    s = (Session *)GetWRefCon(window);    SetPort(GetWindowPort(window));    BeginUpdate(window);    pre_paint(s);#if TARGET_API_MAC_CARBON    visrgn = NewRgn();    GetPortVisibleRegion(GetWindowPort(window), visrgn);    GetRegionBounds(visrgn, &bbox);#else    bbox = (*window->visRgn)->rgnBBox;#endif    term_paint(s->term, s, PTOCC(bbox.left), PTOCR(bbox.top),	       PTOCC(bbox.right), PTOCR(bbox.bottom), 1);    /* Restore default colours in case the Window Manager uses them */    if (HAVE_COLOR_QD()) {	PmForeColor(DEFAULT_FG);	PmBackColor(DEFAULT_BG);    } else {	ForeColor(whiteColor);	BackColor(blackColor);    }    if (FrontWindow() != window)#if TARGET_API_MAC_CARBON	EraseRect(GetControlBounds(s->scrollbar, &bbox));    UpdateControls(window, visrgn);    DisposeRgn(visrgn);#else	EraseRect(&(*s->scrollbar)->contrlRect);    UpdateControls(window, window->visRgn);#endif    mac_drawgrowicon(s);    post_paint(s);    EndUpdate(window);}