static TBOOL region_andrect_internal(struct RectList *temp, struct Region *region, TINT s[], TINT dx, TINT dy) { struct RectPool *pool = region->rg_Pool; struct TNode *next, *node = region->rg_Rects.rl_List.tlh_Head; TBOOL success = TTRUE; TINT s0 = s[0] + dx; TINT s1 = s[1] + dy; TINT s2 = s[2] + dx; TINT s3 = s[3] + dy; for (; success && (next = node->tln_Succ); node = next) { struct RectNode *dr = (struct RectNode *) node; TINT x0 = dr->rn_Rect[0]; TINT y0 = dr->rn_Rect[1]; TINT x1 = dr->rn_Rect[2]; TINT y1 = dr->rn_Rect[3]; if (OVERLAP(x0, y0, x1, y1, s0, s1, s2, s3)) { success = region_insertrect(pool, temp, TMAX(x0, s0), TMAX(y0, s1), TMIN(x1, s2), TMIN(y1, s3)); } } if (!success) region_freerects(pool, temp); return success; }
static void rfb_drawpointer(struct rfb_Display *mod) { TINT x0 = mod->rfb_MouseX - mod->rfb_MouseHotX; TINT y0 = mod->rfb_MouseY - mod->rfb_MouseHotY; if (mod->rfb_Flags & RFBFL_PTR_VISIBLE) { if (x0 == mod->rfb_PtrBackBuffer.rect[0] && y0 == mod->rfb_PtrBackBuffer.rect[1]) return; rfb_restorebackbuf(mod, &mod->rfb_PtrBackBuffer); } TINT s0 = 0; TINT s1 = 0; TINT s2 = mod->rfb_Width - 1; TINT s3 = mod->rfb_Height - 1; TINT x1 = x0 + mod->rfb_PtrWidth - 1; TINT y1 = y0 + mod->rfb_PtrHeight - 1; if (REGION_OVERLAP(s0, s1, s2, s3, x0, y0, x1, y1)) { struct TVPixBuf dst = mod->rfb_DevBuf; x0 = TMAX(x0, s0); y0 = TMAX(y0, s1); x1 = TMIN(x1, s2); y1 = TMIN(y1, s3); rfb_storebackbuf(mod, &mod->rfb_PtrBackBuffer, x0, y0, x1, y1); pixconv_convert(&mod->rfb_PtrImage, &dst, x0, y0, x1, y1, 0, 0, TTRUE, TFALSE); } mod->rfb_Flags |= RFBFL_PTR_VISIBLE; }
LOCAL void win_getminmax(WINWINDOW *win, TINT *pm1, TINT *pm2, TINT *pm3, TINT *pm4, TBOOL windowsize) { TINT m1 = win->fbv_MinWidth; TINT m2 = win->fbv_MinHeight; TINT m3 = win->fbv_MaxWidth; TINT m4 = win->fbv_MaxHeight; m1 = TMAX(0, m1); m2 = TMAX(0, m2); m3 = m3 < 0 ? 1000000 : m3; m4 = m4 < 0 ? 1000000 : m4; m3 = TMAX(m3, m1); m4 = TMAX(m4, m2); if (windowsize) { m1 += win->fbv_BorderWidth; m2 += win->fbv_BorderHeight; m3 += win->fbv_BorderWidth; m4 += win->fbv_BorderHeight; } *pm1 = m1; *pm2 = m2; *pm3 = m3; *pm4 = m4; }
LOCAL void fb_setattrs(WINDISPLAY *mod, struct TVRequest *req) { struct attrdata data; struct THook hook; WINWINDOW *win = req->tvr_Op.SetAttrs.Window; TINT neww, newh; data.v = win; data.num = 0; data.mod = mod; data.neww = -1; data.newh = -1; TInitHook(&hook, setattrfunc, &data); TForEachTag(req->tvr_Op.SetAttrs.Tags, &hook); req->tvr_Op.SetAttrs.Num = data.num; win_getminmax(win, &win->fbv_MinWidth, &win->fbv_MinHeight, &win->fbv_MaxWidth, &win->fbv_MaxHeight, TFALSE); neww = data.neww < 0 ? (TINT) win->fbv_Width : data.neww; newh = data.newh < 0 ? (TINT) win->fbv_Height : data.newh; if (neww < win->fbv_MinWidth || newh < win->fbv_MinHeight) { neww = TMAX(neww, win->fbv_MinWidth); newh = TMAX(newh, win->fbv_MinHeight); neww += win->fbv_BorderWidth; newh += win->fbv_BorderHeight; SetWindowPos(win->fbv_HWnd, NULL, 0, 0, neww, newh, SWP_NOMOVE); } }
TLIBAPI TBOOL region_orrectlist(struct RectPool *pool, struct RectList *list, TINT s[4], TBOOL opportunistic) { if (list->rl_NumNodes > 0) { TINT x0 = s[0]; TINT y0 = s[1]; TINT x1 = s[2]; TINT y1 = s[3]; TUINT64 area = 0; struct TNode *next, *node = list->rl_List.tlh_Head; for (; (next = node->tln_Succ); node = next) { struct RectNode *rn = (struct RectNode *) node; TINT *r = rn->rn_Rect; if (s[0] >= r[0] && s[1] >= r[1] && s[2] <= r[2] && s[3] <= r[3]) return TTRUE; if (!opportunistic) continue; area += (r[2] - r[0] + 1) * (r[3] - r[1] + 1); x0 = TMIN(x0, r[0]); y0 = TMIN(y0, r[1]); x1 = TMAX(x1, r[2]); y1 = TMAX(y1, r[3]); } if (opportunistic) { TUINT64 area2 = (x1 - x0 + 1) * (y1 - y0 + 1); if (area2 < OPPORTUNISTIC_MERGE_THRESHOLD || (area * 256 / area2) > OPPORTUNISTIC_MERGE_RATIO) { /* merge list into a single rectangle */ TDBPRINTF(TDB_TRACE,("merge %d rects\n", list->rl_NumNodes + 1)); region_freerects(pool, list); assert(list->rl_NumNodes == 0); return region_insertrect(pool, list, x0, y0, x1, y1); } } } struct RectList temp; region_initrectlist(&temp); if (region_cutrectlist(pool, list, &temp, s)) { if (region_insertrect(pool, &temp, s[0], s[1], s[2], s[3])) { region_freerects(pool, list); region_relinkrects(list, &temp); return TTRUE; } } region_freerects(pool, &temp); return TFALSE; }
LOCAL void dfb_setattrs(DFBDISPLAY *mod, struct TVRequest *req) { struct attrdata data; struct THook hook; DFBWINDOW *v = req->tvr_Op.SetAttrs.Window; data.v = v; data.num = 0; data.mod = mod; data.sizechanged = TFALSE; TInitHook(&hook, setattrfunc, &data); TForEachTag(req->tvr_Op.SetAttrs.Tags, &hook); req->tvr_Op.SetAttrs.Num = data.num; if (data.sizechanged) { TIMSG *imsg; v->wminwidth = v->wminwidth <= 0 ? 1 : v->wminwidth; v->wminheight = v->wminheight <= 0 ? 1 : v->wminheight; v->wmaxwidth = v->wmaxwidth <= 0 ? 1000000 : v->wmaxwidth; v->wmaxheight = v->wmaxheight <= 0 ? 1000000 : v->wmaxheight; if (v->wmaxwidth > 0) v->winwidth = TMIN(v->winwidth, v->wmaxwidth); if (v->wmaxheight > 0) v->winheight = TMIN(v->winheight, v->wmaxheight); if (v->wminwidth > 0) v->winwidth = TMAX(v->winwidth, v->wminwidth); if (v->wminheight > 0) v->winheight = TMAX(v->winheight, v->wminheight); v->window->Resize(v->window, v->winwidth, v->winheight); if ((v->eventmask & TITYPE_NEWSIZE) && getimsg(mod, v, &imsg, TITYPE_NEWSIZE)) { imsg->timsg_Width = v->winwidth; imsg->timsg_Height = v->winheight; TAddTail(&v->imsgqueue, &imsg->timsg_Node); } if ((v->eventmask & TITYPE_REFRESH) && getimsg(mod, v, &imsg, TITYPE_REFRESH)) { imsg->timsg_X = v->winleft; imsg->timsg_Y = v->wintop; imsg->timsg_Width = v->winwidth; imsg->timsg_Height = v->winheight; TAddTail(&v->imsgqueue, &imsg->timsg_Node); } } }
TLIBAPI TBOOL region_intersect(TINT *d, TINT *s) { if (OVERLAP(d[0], d[1], d[2], d[3], s[0], s[1], s[2], s[3])) { d[0] = TMAX(d[0], s[0]); d[1] = TMAX(d[1], s[1]); d[2] = TMIN(d[2], s[2]); d[3] = TMIN(d[3], s[3]); return TTRUE; } return TFALSE; }
LOCAL void fb_setattrs(WINDISPLAY *mod, struct TVRequest *req) { struct attrdata data; struct THook hook; WINWINDOW *win = req->tvr_Op.SetAttrs.Window; TINT noww, nowh, neww, newh, minw, minh; data.v = win; data.num = 0; data.mod = mod; data.neww = -1; data.newh = -1; TInitHook(&hook, setattrfunc, &data); EnterCriticalSection(&win->fbv_LockExtents); TForEachTag(req->tvr_Op.SetAttrs.Tags, &hook); win_getminmax(win, &win->fbv_MinWidth, &win->fbv_MinHeight, &win->fbv_MaxWidth, &win->fbv_MaxHeight, TFALSE); noww = (TINT) win->fbv_Width; nowh = (TINT) win->fbv_Height; minw = (TINT) win->fbv_MinWidth; minh = (TINT) win->fbv_MinHeight; LeaveCriticalSection(&win->fbv_LockExtents); neww = data.neww < 0 ? noww : data.neww; newh = data.newh < 0 ? nowh : data.newh; if (neww < minw || newh < minh) { neww = TMAX(neww, minw); newh = TMAX(newh, minh); neww += win->fbv_BorderWidth; newh += win->fbv_BorderHeight; SetWindowPos(win->fbv_HWnd, NULL, 0, 0, neww, newh, SWP_NOMOVE); } req->tvr_Op.SetAttrs.Num = data.num; }
static int lib_overlap(lua_State *L) { TINT d0 = luaL_checkinteger(L, 1); TINT d1 = luaL_checkinteger(L, 2); TINT d2 = luaL_checkinteger(L, 3); TINT d3 = luaL_checkinteger(L, 4); TINT s0 = luaL_checkinteger(L, 5); TINT s1 = luaL_checkinteger(L, 6); TINT s2 = luaL_checkinteger(L, 7); TINT s3 = luaL_checkinteger(L, 8); if (OVERLAP(d0, d1, d2, d3, s0, s1, s2, s3)) { lua_pushinteger(L, TMAX(s0, d0)); lua_pushinteger(L, TMAX(s1, d1)); lua_pushinteger(L, TMIN(s2, d2)); lua_pushinteger(L, TMIN(s3, d3)); return 4; } return 0; }
TLIBAPI TBOOL region_getminmax(struct RectPool *pool, struct Region *region, TINT *minmax) { if (region_isempty(pool, region)) return TFALSE; TINT minx = 1000000; TINT miny = 1000000; TINT maxx = 0; TINT maxy = 0; struct TNode *next, *node = region->rg_Rects.rl_List.tlh_Head; for (; (next = node->tln_Succ); node = next) { struct RectNode *rn = (struct RectNode *) node; minx = TMIN(minx, rn->rn_Rect[0]); miny = TMIN(miny, rn->rn_Rect[1]); maxx = TMAX(maxx, rn->rn_Rect[2]); maxy = TMAX(maxy, rn->rn_Rect[3]); } minmax[0] = minx; minmax[1] = miny; minmax[2] = maxx; minmax[3] = maxy; return TTRUE; }
static int region_overlaprect(lua_State *L) { struct RectNode *rn = lua_touserdata(L, 2); TINT s0 = lua_tointeger(L, 3); TINT s1 = lua_tointeger(L, 4); TINT s2 = lua_tointeger(L, 5); TINT s3 = lua_tointeger(L, 6); TINT d0 = rn->rn_Rect[0]; TINT d1 = rn->rn_Rect[1]; TINT d2 = rn->rn_Rect[2]; TINT d3 = rn->rn_Rect[3]; if (OVERLAP(d0, d1, d2, d3, s0, s1, s2, s3)) { lua_pushinteger(L, TMAX(s0, d0)); lua_pushinteger(L, TMAX(s1, d1)); lua_pushinteger(L, TMIN(s2, d2)); lua_pushinteger(L, TMIN(s3, d3)); return 4; } return 0; }
int processPacket( char *packet, metaData_t *meta, void *flowdata ) { int i; struct timeval rtt; struct moduleData *data; struct icmp_echo_hdr *hdr; if ((meta->layers[2] != T_ICMP) && (meta->layers[2] != T_ICMP6)) { // only use ICMP packets! return 0; } data = (struct moduleData *) flowdata; hdr = (struct icmp_echo_hdr *) (&packet[meta->offs[2]]); /* skip layer 1 and 2 */ // only want echo request and reply if ((hdr->type != 8) && (hdr->type != 0)) { return 0; } // dont want "unreachable" replies if (hdr->code != 0) { return 0; } if (hdr->type == 8 ) { /* ICMP echo */ /* find new unused entry - if possible */ data->curr = 0; if (data->free > 0) { while (data->list[data->curr].id != 0) { data->curr += 1; } } data->list[data->curr].id = hdr->id; data->list[data->curr].seqno = hdr->seqno; data->list[data->curr].tstamp.tv_sec = meta->tv_sec; data->list[data->curr].tstamp.tv_usec = meta->tv_usec; if (data->free > 0) { data->free -= 1; } } else { /* ICMP reply */ for ( i = 0; i < data->lsize; i++ ) { if (data->list[i].id == 0) { continue; /* unused list entry */ } if ((data->list[i].id == hdr->id) && (data->list[i].seqno == hdr->seqno)) { rtt.tv_sec = meta->tv_sec - data->list[i].tstamp.tv_sec; rtt.tv_usec = meta->tv_usec - data->list[i].tstamp.tv_usec; if (rtt.tv_usec < 0) { rtt.tv_usec += 1000000; rtt.tv_sec -= 1; } /*fprintf( stderr, "%ld %ld \n", rtt.tv_sec, rtt.tv_usec );*/ data->min = TMIN( data->min, rtt ); data->max = TMAX( data->max, rtt ); data->sum.tv_usec += (unsigned long long) rtt.tv_usec; data->sum.tv_sec += (unsigned long long) rtt.tv_sec; if (data->sum.tv_usec > 1000000) { data->sum.tv_usec -= 1000000; data->sum.tv_sec += 1; } data->list[i].id = 0; data->free += 1; data->matches += 1; if (data->matches == 1 ) { data->min = rtt; } } } } return 0; }
static int layout_layoutaxis(lua_State *L) { layout *layout = lua_touserdata(L, 3); int free = layout->free; int i1 = layout->i1; int i3 = layout->i3; int n = layout->n; RECTINT *padding = layout->padding; RECTINT *margin = layout->margin; RECTINT *minmax = layout->minmax; int it = 0; size_t len; int ssb, ssn = 0; int i; /** ** local fw, tw = 0, 0 ** local list = { } ** local tmm = self.TempMinMax ** local wgh = group.Weights ** for i = 1, n do ** local mins, maxs = tmm[i1][i], tmm[i3][i] ** local free = maxs and (maxs > mins) ** local weight = wgh[i1][i] ** list[i] = { free, mins, maxs, weight, nil } ** if free then ** if weight then ** tw = tw + weight ** else ** fw = fw + 0x100 ** end ** end ** end **/ lua_Integer fw0 = 0; lua_Integer tw0 = 0; lua_Number fw; lua_Number tw; lua_createtable(L, n, 0); lua_getfield(L, 1, "TempMinMax"); lua_rawgeti(L, -1, i1); lua_rawgeti(L, -2, i3); /* s: list, tmm, tmm[i1], tmm[i3] */ lua_remove(L, -3); /* s: list, tmm[i1], tmm[i3] */ lua_getfield(L, 1, "Weights"); /* s: list, tmm[i1], tmm[i3], weights */ lua_rawgeti(L, -1, i1); /* s: list, tmm[i1], tmm[i3], weights, wgh[i1] */ lua_remove(L, -2); for (i = 1; i <= n; ++i) { int free; lua_rawgeti(L, -3, i); /* s: l, tmm[i1], tmm[i3], wgh[i1], mins */ lua_rawgeti(L, -3, i); /* s: l, tmm[i1], tmm[i3], wgh[i1], mins, maxs */ lua_rawgeti(L, -3, i); /* s: l, tmm[i1], tmm[i3], wgh[i1], mins, maxs, weight */ free = lua_toboolean(L, -2) ? lua_tointeger(L, -2) > lua_tointeger(L, -3) : 0; lua_createtable(L, 5, 0); /* s: l, tmm[i1], tmm[i3], wgh[i1], mins, maxs, weight, t */ lua_pushboolean(L, free); lua_rawseti(L, -2, 1); lua_pushvalue(L, -4); lua_rawseti(L, -2, 2); lua_pushvalue(L, -3); lua_rawseti(L, -2, 3); lua_pushvalue(L, -2); lua_rawseti(L, -2, 4); lua_pushnil(L); lua_rawseti(L, -2, 5); /* s: l, tmm[i1], tmm[i3], wgh[i1], mins, maxs, weight, t */ lua_rawseti(L, -8, i); /* s: l, tmm[i1], tmm[i3], wgh[i1], mins, maxs, weight */ if (free) { if (lua_toboolean(L, -1)) tw0 += lua_tointeger(L, -1); else fw0 += 0x100; } lua_pop(L, 3); } lua_pop(L, 3); /** ** if tw < 0x10000 then ** if fw == 0 then ** tw = 0x10000 ** else ** fw, tw = (0x10000 - tw) * 0x100 / fw, 0x10000 ** end ** else ** fw = 0 ** end **/ if (tw0 < 0x10000) { if (fw0 == 0) tw0 = 0x10000; else { fw = 0x10000; fw -= tw0; fw *= 0x100; fw0 = fw / fw0; tw0 = 0x10000; } } else fw0 = 0; tw = tw0 / 0x100; fw = fw0 / 0x100; /** ** local mab = group.MarginAndBorder ** local ss = group:getSameSize(i1) and ** (group.MinMax[i1] - mab[i1] - mab[i3] - pad[i1] - pad[i3]) / n **/ ssb = layout_getsamesize(L, 2, i1); if (ssb) { ssn = minmax[i1 - 1]; ssn -= margin[i1 - 1]; ssn -= margin[i3 - 1]; ssn -= padding[i1 - 1]; ssn -= padding[i3 - 1]; ssn /= n; } lua_getglobal(L, "table"); lua_getfield(L, -1, "insert"); lua_getfield(L, -2, "remove"); lua_remove(L, -3); /* s: list, insert, remove */ /** ** local e = { unpack(list) } **/ #if LUA_VERSION_NUM < 502 len = lua_objlen(L, -3); #else len = lua_rawlen(L, -3); #endif lua_createtable(L, len, 0); /* s: list, insert, remove, e */ for (i = 1; i <= (int) len; ++i) { lua_rawgeti(L, -4, i); lua_rawseti(L, -2, i); } /** ** local it = 0 ** while #e > 0 do **/ #if LUA_VERSION_NUM < 502 while ((len = lua_objlen(L, -1)) > 0) #else while ((len = lua_rawlen(L, -1)) > 0) #endif { /** ** local rest = free ** local newfree = free ** it = it + 1 ** local e2 = { } **/ lua_Integer rest = free; lua_Integer newfree = free; it++; lua_createtable(L, len, 0); /* s: insert, remove, e, e2 */ /** ** repeat ** ... ** until #e == 0 **/ do { lua_Integer olds, news, ti; /** ** delta = 0 ** ** c = remove(e, 1) ** ** if c[1] then -- free ** if c[4] then -- weight ** delta = free * (c[4] / 0x100) * (tw / 0x100) / 0x10000 ** else ** delta = free * 0x100 * (fw / 0x100) / 0x10000 ** end ** delta = floor(delta) ** end **/ lua_Integer delta = 0; /* s: insert, remove, e, e2 */ lua_pushvalue(L, -3); /* s: insert, remove, e, e2, remove */ lua_pushvalue(L, -3); /* s: insert, remove, e, e2, remove, e */ lua_pushinteger(L, 1); /* s: insert, remove, e, e2, remove, e, 1 */ lua_call(L, 2, 1); /* s: insert, remove, e, e2, c */ lua_rawgeti(L, -1, 1); /* s: insert, remove, e, e2, c, c[1] */ if (lua_toboolean(L, -1)) { lua_Number t; lua_rawgeti(L, -2, 4); /* s: insert, remove, e, e2, c, c[1], c[4] */ if (lua_toboolean(L, -1)) { t = lua_tointeger(L, -1); t /= 0x100; t *= tw; t *= free; } else { t = free; t *= 0x100; t *= fw; } t /= 0x10000; delta = t; lua_pop(L, 1); } /* s: insert, remove, e, e2, c, c[1] */ /** ** if delta == 0 and it > 1 then ** delta = rest ** end **/ if (delta == 0 && it > 1) delta = rest; /** ** olds = c[5] or ss or c[2] -- size, mins ** news = max(olds + delta, ss or c[2]) -- mins ** if not (ss and isgrid) and c[3] and news > c[3] then -- maxs ** news = c[3] -- maxs ** end ** c[5] = news **/ lua_rawgeti(L, -2, 5); lua_rawgeti(L, -3, 2); /* s: insert, remove, e, e2, c, c[1], c[5], c[2] */ if (lua_toboolean(L, -2)) olds = lua_tointeger(L, -2); else if (ssb) olds = ssn; else olds = lua_tointeger(L, -1); /* s: insert, remove, e, e2, c, c[1], c[5], c[2] */ ti = ssb ? ssn : lua_tointeger(L, -1); news = TMAX(olds + delta, ti); lua_rawgeti(L, -4, 3); /* s: insert, remove, e, e2, c, c[1], c[5], c[2], c[3] */ if (!(ssb && layout->isgrid) && lua_toboolean(L, -1) && news > lua_tointeger(L, -1)) news = lua_tointeger(L, -1); lua_pushinteger(L, news); lua_rawseti(L, -6, 5); /** ** delta = news - olds ** newfree = newfree - delta ** rest = rest - delta **/ delta = news - olds; newfree -= delta; rest -= delta; /** ** if not c[3] or c[3] >= HUGE or c[5] < c[3] then -- maxs ** insert(e2, c) ** end **/ if (!lua_toboolean(L, -1) || lua_tointeger(L, -1) >= TEKUI_HUGE || lua_tointeger(L, -3) < lua_tointeger(L, -1)) { /* redo in next iteration: */ /* s: ins, rem, e, e2, c, c[1], c[5], c[2], c[3] */ lua_pushvalue(L, -9); /* s: ins, rem, e, e2, c, c[1], c[5], c[2], c[3], ins */ lua_pushvalue(L, -7); /* s: ins, rem, e, e2, c, c[1], c[5], c[2], c[3], ins, e2 */ lua_pushvalue(L, -7); /* s: ins, rem, e, e2, c, c[1], c[5], c[2], c[3], ins, e2, c */ lua_call(L, 2, 0); /* s: insert, remove, e, e2, c, c[1], c[5], c[2], c[3] */ } lua_pop(L, 5); /* s: insert, remove, e, e2 */ #if LUA_VERSION_NUM < 502 } while (lua_objlen(L, -2) > 0); #else } while (lua_rawlen(L, -2) > 0); #endif /** ** if newfree < 1 then ** break ** end ** ** free = newfree ** e = e2 **/ free = newfree; if (free < 1) { lua_pop(L, 1); break; } /* s: insert, remove, e, e2 */ lua_replace(L, -2); /* s: insert, remove, e */ }
static TINT rfb_cmdrectaffected(struct rfb_Display *mod, struct TVRequest *req, TINT result[4], TBOOL source_affect) { struct rfb_Window *v = TNULL; TINT *rect = TNULL; TINT *xywh = TNULL; TINT temprect[4]; switch (req->tvr_Req.io_Command) { default: /* not affected, no rect */ return 0; case TVCMD_FLUSH: case TVCMD_SETATTRS: case TVCMD_CLOSEWINDOW: /* yes, affected, but no rect */ return -1; /* window rect: */ case TVCMD_DRAWSTRIP: v = req->tvr_Op.Strip.Window; break; case TVCMD_DRAWFAN: v = req->tvr_Op.Fan.Window; break; case TVCMD_TEXT: v = req->tvr_Op.Text.Window; break; /* specific rect: */ case TVCMD_RECT: v = req->tvr_Op.Rect.Window; xywh = req->tvr_Op.Rect.Rect; break; case TVCMD_FRECT: v = req->tvr_Op.FRect.Window; xywh = req->tvr_Op.FRect.Rect; break; case TVCMD_LINE: v = req->tvr_Op.Line.Window; xywh = req->tvr_Op.Line.Rect; break; case TVCMD_DRAWBUFFER: v = req->tvr_Op.DrawBuffer.Window; xywh = req->tvr_Op.DrawBuffer.RRect; break; case TVCMD_COPYAREA: { v = req->tvr_Op.CopyArea.Window; TINT *s = req->tvr_Op.CopyArea.Rect; TINT dx0 = req->tvr_Op.CopyArea.DestX; TINT dy0 = req->tvr_Op.CopyArea.DestY; TINT sx0 = s[0]; TINT sy0 = s[1]; TINT sx1 = s[0] + s[2] - 1; TINT sy1 = s[1] + s[3] - 1; TINT dx = dx0 - sx0; TINT dy = dy0 - sy0; TINT dx1 = sx1 + dx; TINT dy1 = sy1 + dy; rect = temprect; if (source_affect) { rect[0] = TMIN(sx0, dx0); rect[1] = TMIN(sy0, dy0); rect[2] = TMAX(sx1, dx1); rect[3] = TMAX(sy1, dy1); break; } rect[0] = dx0; rect[1] = dy0; rect[2] = dx1; rect[3] = dy1; break; } case TVCMD_PLOT: v = req->tvr_Op.Plot.Window; rect = temprect; rect[0] = req->tvr_Op.Plot.Rect[0]; rect[1] = req->tvr_Op.Plot.Rect[1]; rect[2] = req->tvr_Op.Plot.Rect[0]; rect[3] = req->tvr_Op.Plot.Rect[1]; break; } if (v->rfbw_ClipRect.r[0] == -1) return 0; if (xywh) { rect = temprect; rect[0] = xywh[0]; rect[1] = xywh[1]; rect[2] = xywh[0] + xywh[2] - 1; rect[3] = xywh[1] + xywh[3] - 1; } if (rect) { result[0] = rect[0] + v->rfbw_WinRect.r[0]; result[1] = rect[1] + v->rfbw_WinRect.r[1]; result[2] = rect[2] + v->rfbw_WinRect.r[0]; result[3] = rect[3] + v->rfbw_WinRect.r[1]; } else memcpy(result, v->rfbw_WinRect.r, 16); return region_intersect(result, v->rfbw_ClipRect.r); }
static TBOOL tek_lib_visual_io_init(struct TTask *task) { struct TExecBase *TExecBase = TGetExecBase(task); struct IOData *iodata = TGetTaskData(task); #if defined(ENABLE_FILENO) || defined(ENABLE_DGRAM) TEKVisual *vis = iodata->vis; iodata->fd_pipe[0] = -1; iodata->fd_pipe[1] = -1; iodata->fdmax = 0; TInitHook(&iodata->mphook, tek_lib_visual_io_mphookfunc, iodata); TSetPortHook(TGetUserPort(TNULL), &iodata->mphook); #endif #if defined(ENABLE_FILENO) int fd = vis->vis_IOFileNo; iodata->fd_stdin = fd == -1 ? STDIN_FILENO : fd; visual_io_reader_init(&iodata->linereader, iodata->fd_stdin, IOMAXMSGSIZE); iodata->fdmax = TMAX(iodata->fdmax, iodata->fd_stdin); #endif #if defined(ENABLE_DGRAM) iodata->fd_dgram = socket(PF_INET, SOCK_DGRAM, 0); if (iodata->fd_dgram != -1) { int reuse = 1; setsockopt(iodata->fd_dgram, SOL_SOCKET, SO_REUSEADDR, (char *) &reuse, sizeof(reuse)); struct sockaddr_in addr; memset(&addr, 0, sizeof(struct sockaddr_in)); addr.sin_family = AF_INET; addr.sin_addr.s_addr = inet_addr(ENABLE_DGRAM_ADDR); addr.sin_port = htons(ENABLE_DGRAM); if (bind(iodata->fd_dgram, (struct sockaddr *) &addr, sizeof addr) == -1) { close(iodata->fd_dgram); iodata->fd_dgram = -1; } } if (iodata->fd_dgram == -1) { tek_lib_visual_io_exit(task); return TFALSE; } iodata->fdmax = TMAX(iodata->fdmax, iodata->fd_dgram); #endif #if defined(ENABLE_FILENO) || defined(ENABLE_DGRAM) if (pipe(iodata->fd_pipe) != 0) return TFALSE; iodata->fdmax = TMAX(iodata->fdmax, iodata->fd_pipe[0]) + 1; #endif TAPTR atom = TLockAtom(iodata->atomname, TATOMF_CREATE | TATOMF_NAME); if (atom) { TSetAtomData(atom, (TTAG) TGetUserPort(TNULL)); TUnlockAtom(atom, TATOMF_KEEP); } return TTRUE; }
LOCAL void dfb_openvisual(DFBDISPLAY *mod, struct TVRequest *req) { TTAGITEM *tags = req->tvr_Op.OpenWindow.Tags; TAPTR exec = TGetExecBase(mod); DFBWINDOW *v; DFBWindowDescription wdsc; struct FontNode *fn; v = TExecAlloc0(exec, mod->dfb_MemMgr, sizeof(DFBWINDOW)); req->tvr_Op.OpenWindow.Window = v; if (v == TNULL) return; v->userdata = TGetTag(tags, TVisual_UserData, TNULL); v->eventmask = (TUINT) TGetTag(tags, TVisual_EventMask, 0); TInitList(&v->penlist); v->bgpen = TVPEN_UNDEFINED; v->fgpen = TVPEN_UNDEFINED; TInitList(&v->imsgqueue); v->imsgport = req->tvr_Op.OpenWindow.IMsgPort; v->title = (TSTRPTR) TGetTag(tags, TVisual_Title, (TTAG) "TEKlib visual"); /* size/position calculation: */ v->winwidth = (TINT) TGetTag(tags, TVisual_Width, (TTAG) TMIN(mod->dfb_ScrWidth, DEF_WINWIDTH)); v->winheight = (TINT) TGetTag(tags, TVisual_Height, (TTAG) TMIN(mod->dfb_ScrHeight, DEF_WINHEIGHT)); if (TGetTag(tags, TVisual_Center, TFALSE)) { v->winleft = (mod->dfb_ScrWidth - v->winwidth) / 2; v->wintop = (mod->dfb_ScrHeight - v->winheight) / 2; } else if (TGetTag(tags, TVisual_FullScreen, TFALSE)) { v->winwidth = mod->dfb_ScrWidth; v->winheight = mod->dfb_ScrHeight; v->winleft = 0; v->wintop = 0; } else { v->winleft = (TINT) TGetTag(tags, TVisual_WinLeft, (TTAG) -1); v->wintop = (TINT) TGetTag(tags, TVisual_WinTop, (TTAG) -1); } if (!TGetTag(tags, TVisual_Borderless, TFALSE)) { v->wminwidth = (TINT) TGetTag(tags, TVisual_MinWidth, (TTAG) -1); v->wminheight = (TINT) TGetTag(tags, TVisual_MinHeight, (TTAG) -1); v->wmaxwidth = (TINT) TGetTag(tags, TVisual_MaxWidth, (TTAG) -1); v->wmaxheight = (TINT) TGetTag(tags, TVisual_MaxHeight, (TTAG) -1); if (v->wmaxwidth > 0) v->winwidth = TMIN(v->winwidth, v->wmaxwidth); if (v->wmaxheight > 0) v->winheight = TMIN(v->winheight, v->wmaxheight); if (v->wminwidth > 0) v->winwidth = TMAX(v->winwidth, v->wminwidth); if (v->wminheight > 0) v->winheight = TMAX(v->winheight, v->wminheight); v->wminwidth = v->wminwidth <= 0 ? 1 : v->wminwidth; v->wminheight = v->wminheight <= 0 ? 1 : v->wminheight; v->wmaxwidth = v->wmaxwidth <= 0 ? 1000000 : v->wmaxwidth; v->wmaxheight = v->wmaxheight <= 0 ? 1000000 : v->wmaxheight; } v->winleft = TMAX(v->winleft, 0); v->wintop = TMAX(v->wintop, 0); if (TGetTag(tags, TVisual_Borderless, TFALSE)) v->borderless = TTRUE; wdsc.flags = (DWDESC_POSX | DWDESC_POSY | DWDESC_WIDTH | DWDESC_HEIGHT); wdsc.posx = v->winleft; wdsc.posy = v->wintop; wdsc.width = v->winwidth; wdsc.height = v->winheight; if (mod->dfb_Layer->CreateWindow(mod->dfb_Layer, &wdsc, &v->window) == DFB_OK) { v->window->GetSurface(v->window, &v->winsurface); v->window->SetOpacity(v->window, 0xFF); v->window->GetID(v->window, &v->winid); v->window->AttachEventBuffer(v->window, mod->dfb_Events); v->window->RequestFocus(v->window); v->window->RaiseToTop(v->window); if (!v->borderless) { /* generate focus events */ genimsg(mod, (DFBWINDOW *)mod->dfb_Focused, v, TITYPE_FOCUS); mod->dfb_Focused = (TAPTR) v; } v->winsurface->SetColor(v->winsurface, 0x00, 0x00, 0xff, 0xff); v->winsurface->DrawRectangle(v->winsurface, 0, 0, wdsc.width, wdsc.height); v->winsurface->SetColor(v->winsurface, 0x80, 0x80, 0x80, 0xff); v->winsurface->FillRectangle(v->winsurface, 1, 1, wdsc.width-2, wdsc.height-2); v->winsurface->Flip(v->winsurface, NULL, 0); /* init default font */ fn = mod->dfb_fm.deffont; v->curfont = fn; mod->dfb_fm.defref++; if (v->winsurface->SetFont(v->winsurface, fn->font) == DFB_OK) { if (v->winsurface->SetFont(v->winsurface, fn->font) == DFB_OK) { TDBPRINTF(TDB_TRACE,("Add window: %p\n", v->window)); TAddHead(&mod->dfb_vlist, &v->node); /* success: */ return; } } } TExecFree(exec, v); /* failure: */ TDBPRINTF(TDB_ERROR,("Open failed\n")); req->tvr_Op.OpenWindow.Window = TNULL; }
void load_database(cron_db *old_db) { struct stat spool_stat, syscron_stat, crond_stat; cron_db new_db; user *u, *nu; time_t new_mtime; Debug(DLOAD, ("[%ld] load_database()\n", (long)getpid())); /* before we start loading any data, do a stat on SPOOL_DIR * so that if anything changes as of this moment (i.e., before we've * cached any of the database), we'll see the changes next time. */ if (stat(SPOOL_DIR, &spool_stat) < OK) { log_it("CRON", getpid(), "STAT FAILED", SPOOL_DIR); (void) exit(ERROR_EXIT); } /* track system crontab directory */ if (stat(CROND_DIR, &crond_stat) < OK) crond_stat.st_mtime = 0; /* track system crontab file */ if (stat(SYSCRONTAB, &syscron_stat) < OK) syscron_stat.st_mtime = 0; /* if spooldir's mtime has not changed, we don't need to fiddle with * the database. * * Note that old_db->mtime is initialized to 0 in main(), and * so is guaranteed to be different than the stat() mtime the first * time this function is called. */ new_mtime = TMAX(crond_stat.st_mtime, TMAX(spool_stat.st_mtime, syscron_stat.st_mtime)); if (old_db->mtime == new_mtime) { Debug(DLOAD, ("[%ld] spool dir mtime unch, no load needed.\n", (long)getpid())); return; } /* something's different. make a new database, moving unchanged * elements from the old database, reloading elements that have * actually changed. Whatever is left in the old database when * we're done is chaff -- crontabs that disappeared. */ new_db.mtime = new_mtime; new_db.head = new_db.tail = NULL; if (syscron_stat.st_mtime) process_crontab("root", NULL, SYSCRONTAB, &syscron_stat, &new_db, old_db); if (crond_stat.st_mtime) process_dir(CROND_DIR, &crond_stat, 1, &new_db, old_db); process_dir(SPOOL_DIR, &spool_stat, 0, &new_db, old_db); /* if we don't do this, then when our children eventually call * getpwnam() in do_command.c's child_process to verify MAILTO=, * they will screw us up (and v-v). */ endpwent(); /* whatever's left in the old database is now junk. */ Debug(DLOAD, ("unlinking old database:\n")); for (u = old_db->head; u != NULL; u = nu) { Debug(DLOAD, ("\t%s\n", u->name)); nu = u->next; unlink_user(old_db, u); free_user(u); } /* overwrite the database control block with the new one. */ *old_db = new_db; Debug(DLOAD, ("load_database is done\n")); }
TLIBAPI TAPTR TEKlib_LoadModule(TAPTR boot, TSTRPTR progdir, TSTRPTR moddir, TSTRPTR modname, TTAGITEM *tags) { TAPTR knmod = TNULL; TINT len1, len2, len3; TSTRPTR t; struct TInitModule *imod; struct host_modhandle *handle; handle = TEKlib_Alloc(boot, sizeof(*handle)); if (!handle) return TNULL; imod = host_lookupmodule(modname, tags); if (imod) { handle->entry.func = imod->tinm_InitFunc; handle->type = TYPE_LIB; return handle; } len1 = progdir ? strlen(progdir) : 0; len2 = moddir ? strlen(moddir) : 0; len3 = strlen(modname); /* + mod/ + .so + \0 */ t = TEKlib_Alloc(boot, TMAX(len1, len2) + len3 + 4 + TEKHOST_EXTLEN + 1); if (t) { if (progdir) strcpy(t, progdir); strcpy(t + len1, "mod/"); strcpy(t + len1 + 4, modname); strcpy(t + len1 + 4 + len3, TEKHOST_EXTSTR); TDBPRINTF(3,("trying dlopen %s\n", t)); knmod = host_getmodule(t); if (!knmod) { if (moddir) strcpy(t, moddir); strcpy(t + len2, modname); strcpy(t + len2 + len3, TEKHOST_EXTSTR); TDBPRINTF(3,("trying dlopen %s\n", t)); knmod = host_getmodule(t); } if (!knmod) TDBPRINTF(20,("dlopen %s failed\n", modname)); TEKlib_FreeVec(boot, t); } if (knmod) { handle->entry.object = knmod; handle->type = TYPE_DLL; } else { TEKlib_FreeVec(boot, handle); handle = TNULL; } return handle; }
LOCAL void fbp_drawtriangle(struct rfb_Display *mod, struct rfb_Window *v, TINT x0, TINT y0, TINT x1, TINT y1, TINT x2, TINT y2, struct rfb_Pen *pen) { struct Coord res[MAX_VERT]; TINT outlen; struct Region R; if (!rfb_getlayermask(mod, &R, v->rfbw_ClipRect.r, v, 0, 0)) return; TUINT p = pixconv_rgbfmt(v->rfbw_PixBuf.tpb_Format, pen->rgb); struct TNode *next, *node = R.rg_Rects.rl_List.tlh_Head.tln_Succ; for (; (next = node->tln_Succ); node = next) { struct RectNode *rn = (struct RectNode *) node; TINT *r = rn->rn_Rect; if (!clippoly(res, &outlen, x0, y0, x1, y1, x2, y2, r[0], r[1], r[2], r[3])) continue; TINT d[4]; if (outlen == 1) { d[0] = res[0].x; d[1] = res[0].y; d[2] = res[0].x; d[3] = res[0].y; rfb_markdirty(mod, v, d); pixconv_setpixelbuf(&v->rfbw_PixBuf, res[0].x, res[0].y, p); } else if (outlen == 2) { TINT rect[4] = { res[0].x, res[0].y, res[1].x, res[1].y }; rfb_markdirty(mod, v, rect); fbp_drawline(mod, v, rect, pen); } else { TINT i; d[0] = TMIN(TMIN(res[0].x, res[1].x), res[2].x); d[1] = TMIN(TMIN(res[0].y, res[1].y), res[2].y); d[2] = TMAX(TMAX(res[0].x, res[1].x), res[2].x); d[3] = TMAX(TMAX(res[0].y, res[1].y), res[2].y); rfb_markdirty(mod, v, d); rendertriangle(v, res[0], res[1], res[2], p); for (i = 2; i < outlen; i++) { if ((i + 1) < outlen) rendertriangle(v, res[0], res[i], res[i + 1], p); } } } region_free(&mod->rfb_RectPool, &R); }