button * add_button(Rectangle r, char *name, char *default_label, Pixel color, void *param) { button *b = (button *)malloc(sizeof(button)); utf8 *label[bstates]; assert(b); // allocating button memory b->type = Button; b->r = r; b->name = name; b->state = default_button_state; b->next = 0; b->param = param; b->category = default_category; last_button = b; if ( !(ptinrect(r.min, screen_rect) && r.max.x <= screen_rect.max.x && r.max.y <= screen_rect.max.y)) { fprintf(stderr, "*** button %s is off screen, ignored: %d,%d - %d,%d\n", name, r.min.x, r.min.y, r.max.x, r.max.y); return 0; } /* lookup configuration file alternates for our default label names. */ label[Off] = lookup(name, ".off", default_label); label[On] = lookup(name, ".on", default_label); label[Unavailable] = lookup(name, ".unavail", default_label); fprintf(stderr, "0 "); make_PixMap(&b->pm[Off], (Rectangle){{0,0},{DX(r),DY(r)}}, color); fprintf(stderr, "1 "); make_PixMap(&b->pm[On], (Rectangle){{0,0},{DX(r),DY(r)}}, color); fprintf(stderr, "1 "); make_PixMap(&b->pm[Unavailable],(Rectangle){{0,0},{DX(r),DY(r)}}, dim_color(color)); fprintf(stderr, "2\n"); b_fill_rect(b->pm[Off], inset(b->pm[Off].r, BUTTON_RIM), dim_color(color)); b_fill_rect(b->pm[On], inset(b->pm[On].r, BUTTON_RIM), Black); string_on_pixmap(&(b->pm[Off]), label[Off], White, 1, 1); string_on_pixmap(&(b->pm[On]), label[On], White, 1, 1); string_on_pixmap(&(b->pm[Unavailable]), label[Unavailable], dim_color(White), 1, 1); /* Add button to the end of the linked list */ fprintf(stderr, "2 "); if (buttons == 0) buttons = b; else { button *bp = buttons; while (bp->next) bp = bp->next; bp->next = b; } return b; }
void ereshaped(Rectangle r){ screen.r=r; r=inset(r, 4); plpack(root, r); bitblt(&screen, screen.r.min, &screen, screen.r, Zero); pldraw(root, &screen); }
void CharacterSegmenter::cleanMostlyFullBoxes(vector<Mat> thresholds, const vector<Rect> charRegions) { float MAX_FILLED = 0.95 * 255; for (int i = 0; i < charRegions.size(); i++) { Mat mask = Mat::zeros(thresholds[0].size(), CV_8U); rectangle(mask, charRegions[i], Scalar(255,255,255), -1); for (int j = 0; j < thresholds.size(); j++) { if (mean(thresholds[j], mask)[0] > MAX_FILLED) { // Empty the rect rectangle(thresholds[j], charRegions[i], Scalar(0,0,0), -1); if (this->config->debugCharSegmenter) { Rect inset(charRegions[i].x + 2, charRegions[i].y - 2, charRegions[i].width - 4, charRegions[i].height - 4); rectangle(imgDbgCleanStages[j], inset, COLOR_DEBUG_FULLBOX, 1); } } } } }
/* in all cases set b will be cleared */ void merge(t_set seta, t_set setb) { int i; for(i=0; i < seta[0]; i++) { if (inset(setb,i)) addset(seta,i); } clearset(setb); }
/* * r is a rectangle holding the text elements. * return the rectangle, including its black edge, holding element i. */ static Rectangle menurect(Rectangle r, int i) { if(i < 0) return Rect(0, 0, 0, 0); r.min.y += (fontheight()+Vspacing)*i; r.max.y = r.min.y+fontheight()+Vspacing; return inset(r, Border-Margin); }
/* printset will print all contained elements to stdout in O(N)*/ void printset(t_set set) { int i; if (!isemptyset(set)) { for(i=0; i < set[0]; i++) { if (inset(set,i)) printf("%d ", i); } } }
extern void raycont( /* check for clipped object and continue */ RAY *r ) { if ((r->clipset != NULL && inset(r->clipset, r->ro->omod)) || !rayshade(r, r->ro->omod)) raytrans(r); }
void dowork() { int mi; if (my_rank == print_node) { #ifdef RC #pragma omp parallel { #pragma omp master { printf("Using %d threads\n", omp_get_num_threads()); } } #endif printf("My rank is %d has %d:", my_rank, mpi_chunksize); if (mpi_chunksize < 20) for (mi = 0; mi < mpi_chunksize; mi++) printf("%d ", scram[mi]); printf("\n"); } int x,y; float xv, yv; int i; double complex z; #ifdef RC #pragma omp parallel for reduction(+:count) private(x,y,xv,yv,i,z) #else //#pragma omp single //{ printf("Using %d threads\n", omp_get_num_threads()); } #ifdef STATIC #pragma omp parallel for reduction(+:count) schedule(static) private(x,y,xv,yv,i,z) #elif defined DYNAMIC #pragma omp parallel for reduction(+:count) schedule(dynamic) private(x,y,xv,yv,i,z) #elif defined GUIDED #pragma omp parallel for reduction(+:count) schedule(guided) private(x,y,xv,yv,i,z) #endif #endif for (i=0; i < mpi_chunksize; i++) { // no there is myrange and scatter distribute different data x = scram[i]; for (y=0; y < nptsside; y++) { xv = (x - side2) / side4; yv = (y - side2) / side4; z = xv + yv*I; if (inset(z)) { count++; } } } MPI_Reduce(&count, &tot_count, 1, MPI_INT, MPI_SUM, print_node, MPI_COMM_WORLD); }
void onDraw(SkCanvas* canvas) override { canvas->translate(8.5f, 8.5f); const SkRect rect = { 0, 0, 80, 80 }; const SkScalar RAD = rect.width()/8; int i = 0; for (int insetFirst = 0; insetFirst <= 1; ++insetFirst) { for (int doEvenOdd = 0; doEvenOdd <= 1; ++doEvenOdd) { for (int outerRR = 0; outerRR <= 1; ++outerRR) { for (int innerRR = 0; innerRR <= 1; ++innerRR) { for (int outerCW = 0; outerCW <= 1; ++outerCW) { for (int innerCW = 0; innerCW <= 1; ++innerCW) { SkPath path; path.setFillType(doEvenOdd ? SkPath::kEvenOdd_FillType : SkPath::kWinding_FillType); SkPath::Direction outerDir = outerCW ? SkPath::kCW_Direction : SkPath::kCCW_Direction; SkPath::Direction innerDir = innerCW ? SkPath::kCW_Direction : SkPath::kCCW_Direction; SkRect r = insetFirst ? inset(rect) : rect; if (outerRR) { path.addRoundRect(r, RAD, RAD, outerDir); } else { path.addRect(r, outerDir); } r = insetFirst ? rect : inset(rect); if (innerRR) { path.addRoundRect(r, RAD, RAD, innerDir); } else { path.addRect(r, innerDir); } SkScalar dx = (i / 8) * rect.width() * 6 / 5; SkScalar dy = (i % 8) * rect.height() * 6 / 5; i++; path.offset(dx, dy); this->show(canvas, path); } } } } } } }
void compatibility_sysv_utmp_core_event_handler (struct einit_event *ev) { switch (ev->type) { case einit_core_service_update: if ((ev->status & status_enabled) && ev->set && (inset ((const void **)ev->set, "fs-var", SET_TYPE_STRING) || inset ((const void **)ev->set, "fs-var-run", SET_TYPE_STRING))) { compatibility_sysv_utmp_clean(); } break; default: break; } }
void getscreen(int argc, char **argv) { int fd; Rectangle r; signal(SIGINT, SIG_IGN); xtbinit(0, "Sam", &argc, argv, fallbacks); r = inset(screen.r, 4); bitblt(&screen, r.min, &screen, r, 0); }
static Py_ssize_t _lowerencode(char *dest, size_t destsize, const char *src, Py_ssize_t len) { static const uint32_t onebyte[8] = { 1, 0x2bfffbfb, 0xe8000001, 0x2fffffff }; static const uint32_t lower[8] = { 0, 0, 0x7fffffe }; Py_ssize_t i, destlen = 0; for (i = 0; i < len; i++) { if (inset(onebyte, src[i])) charcopy(dest, &destlen, destsize, src[i]); else if (inset(lower, src[i])) charcopy(dest, &destlen, destsize, src[i] + 32); else escape3(dest, &destlen, destsize, src[i]); } return destlen; }
uint16_t service_usage_query_group (enum einit_usage_query task, const struct lmodule *module, const char *service) { uint16_t ret = 0; struct stree *ha; if (!service) return 0; emutex_lock (&service_usage_mutex); if (task & service_add_group_provider) { if (!module || !module->module) { emutex_unlock (&service_usage_mutex); return 0; } if (!service_usage || !(ha = streefind (service_usage, service, tree_find_first))) { struct service_usage_item nitem; memset (&nitem, 0, sizeof (struct service_usage_item)); nitem.provider = (struct lmodule **)setadd ((void **)nitem.provider, (void *)module, SET_NOALLOC); service_usage = streeadd (service_usage, service, &nitem, sizeof (struct service_usage_item), NULL); } else { struct service_usage_item *citem = (struct service_usage_item *)ha->value; if (citem) { if (!inset ((const void **)citem->provider, (void *)module, SET_NOALLOC)) { citem->provider = (struct lmodule **)setadd ((void **)citem->provider, (void *)module, SET_NOALLOC); } } } } if (task & service_set_group_providers) { if (!service_usage || !(ha = streefind (service_usage, service, tree_find_first))) { struct service_usage_item nitem; memset (&nitem, 0, sizeof (struct service_usage_item)); nitem.provider = (struct lmodule **)setdup ((const void **)module, SET_NOALLOC); service_usage = streeadd (service_usage, service, &nitem, sizeof (struct service_usage_item), NULL); } else { struct service_usage_item *citem = (struct service_usage_item *)ha->value; if (citem) { free (citem->provider); citem->provider = (struct lmodule **)setdup ((const void **)module, SET_NOALLOC); } } } emutex_unlock (&service_usage_mutex); return ret; }
static void menuscrollpaint(Rectangle scrollr, int off, int nitem, int nitemdrawn) { Rectangle r; bitblt(&screen, scrollr.min, &screen, scrollr, 0); r.min.x = scrollr.min.x; r.max.x = scrollr.max.x; r.min.y = scrollr.min.y + (Dy(scrollr)*off)/nitem; r.max.y = scrollr.min.y + (Dy(scrollr)*(off+nitemdrawn))/nitem; if(r.max.y < r.min.y+2) r.max.y = r.min.y+2; border(&screen, r, 1, F, _bgpixel); if(darkgrey) texture(&screen, inset(r, 1), darkgrey, S); }
void menupaint(Menu *menu, Rectangle textr, int off, int nitemdrawn) { int i; Point pt; Rectangle r; char *item; r = inset(textr, Border-Margin); bitblt(&screen, r.min, &screen, r, 0); pt = Pt(textr.min.x+textr.max.x, textr.min.y); for(i = 0; i<nitemdrawn; i++, pt.y += fontheight()+Vspacing){ item = menu->item? menu->item[i+off] : (*menu->gen)(i+off); string(&screen, Pt((pt.x-strwidth(font, item))/2, pt.y), font, item, S); } }
int onethird(Flayer *l, long a) { Text *t; Rectangle s; long lines; t = l->user1; if(!t->lock && (a<l->origin || l->origin+l->f.nchars<a)){ if(a > t->rasp.nrunes) a = t->rasp.nrunes; s = inset(l->scroll, 1); lines = ((s.max.y-s.min.y)/l->f.fheight+1)/3; if (lines < 2) lines = 2; outTsll(Torigin, t->tag, a, lines); return 1; } return 0; }
void dowork() { int i, x, y; float xv, yv; double complex z; for (i=0; i < mpi_chunksize; i++) { x = scram[i]; //printf("%d\n",x ); for (y=0; y < nptsside; y++) { xv = (x - side2) / side4; yv = (y - side2) / side4; z = xv + yv*I; if (inset(z)) count++; } } MPI_Reduce(&count, &tot_count, 1, MPI_INT, MPI_SUM, print_node, MPI_COMM_WORLD); }
void Window::drawWindow(Renderer2D &out, IRect rect, FColor color, int outline) { FColor lighter(color.rgb() * 1.2f, color.a); FColor darker(color.rgb() * 0.8f, color.a); int aoutline = fwk::abs(outline); if(outline) { int2 hsize(rect.width(), aoutline); int2 vsize(aoutline, rect.height()); FColor col1 = outline < 0? darker : lighter; out.addFilledRect(IRect(rect.min, rect.min + hsize), col1); out.addFilledRect(IRect(rect.min, rect.min + vsize), col1); int2 p1(rect.min.x, rect.max.y - aoutline); int2 p2(rect.max.x - aoutline, rect.min.y); FColor col2 = outline < 0? lighter : darker; out.addFilledRect(IRect(p1, p1 + hsize), col2); out.addFilledRect(IRect(p2, p2 + vsize), col2); } int2 off(aoutline, aoutline); out.addFilledRect(inset(rect, off, off), color); }
int zmq_poll (zmq_pollitem_t *items_, int nitems_, long timeout_) { #if defined ZMQ_HAVE_POLLER // if poller is present, use that if there is at least 1 thread-safe socket, // otherwise fall back to the previous implementation as it's faster. for (int i = 0; i != nitems_; i++) { if (items_[i].socket && as_socket_base_t (items_[i].socket)->is_thread_safe ()) { return zmq_poller_poll (items_, nitems_, timeout_); } } #endif // ZMQ_HAVE_POLLER #if defined ZMQ_POLL_BASED_ON_POLL || defined ZMQ_POLL_BASED_ON_SELECT if (unlikely (nitems_ < 0)) { errno = EINVAL; return -1; } if (unlikely (nitems_ == 0)) { if (timeout_ == 0) return 0; #if defined ZMQ_HAVE_WINDOWS Sleep (timeout_ > 0 ? timeout_ : INFINITE); return 0; #elif defined ZMQ_HAVE_VXWORKS struct timespec ns_; ns_.tv_sec = timeout_ / 1000; ns_.tv_nsec = timeout_ % 1000 * 1000000; return nanosleep (&ns_, 0); #else return usleep (timeout_ * 1000); #endif } if (!items_) { errno = EFAULT; return -1; } zmq::clock_t clock; uint64_t now = 0; uint64_t end = 0; #if defined ZMQ_POLL_BASED_ON_POLL zmq::fast_vector_t<pollfd, ZMQ_POLLITEMS_DFLT> pollfds (nitems_); // Build pollset for poll () system call. for (int i = 0; i != nitems_; i++) { // If the poll item is a 0MQ socket, we poll on the file descriptor // retrieved by the ZMQ_FD socket option. if (items_[i].socket) { size_t zmq_fd_size = sizeof (zmq::fd_t); if (zmq_getsockopt (items_[i].socket, ZMQ_FD, &pollfds[i].fd, &zmq_fd_size) == -1) { return -1; } pollfds[i].events = items_[i].events ? POLLIN : 0; } // Else, the poll item is a raw file descriptor. Just convert the // events to normal POLLIN/POLLOUT for poll (). else { pollfds[i].fd = items_[i].fd; pollfds[i].events = (items_[i].events & ZMQ_POLLIN ? POLLIN : 0) | (items_[i].events & ZMQ_POLLOUT ? POLLOUT : 0) | (items_[i].events & ZMQ_POLLPRI ? POLLPRI : 0); } } #else // Ensure we do not attempt to select () on more than FD_SETSIZE // file descriptors. // TODO since this function is called by a client, we could return errno EINVAL/ENOMEM/... here zmq_assert (nitems_ <= FD_SETSIZE); zmq::optimized_fd_set_t pollset_in (nitems_); FD_ZERO (pollset_in.get ()); zmq::optimized_fd_set_t pollset_out (nitems_); FD_ZERO (pollset_out.get ()); zmq::optimized_fd_set_t pollset_err (nitems_); FD_ZERO (pollset_err.get ()); zmq::fd_t maxfd = 0; // Build the fd_sets for passing to select (). for (int i = 0; i != nitems_; i++) { // If the poll item is a 0MQ socket we are interested in input on the // notification file descriptor retrieved by the ZMQ_FD socket option. if (items_[i].socket) { size_t zmq_fd_size = sizeof (zmq::fd_t); zmq::fd_t notify_fd; if (zmq_getsockopt (items_[i].socket, ZMQ_FD, ¬ify_fd, &zmq_fd_size) == -1) return -1; if (items_[i].events) { FD_SET (notify_fd, pollset_in.get ()); if (maxfd < notify_fd) maxfd = notify_fd; } } // Else, the poll item is a raw file descriptor. Convert the poll item // events to the appropriate fd_sets. else { if (items_[i].events & ZMQ_POLLIN) FD_SET (items_[i].fd, pollset_in.get ()); if (items_[i].events & ZMQ_POLLOUT) FD_SET (items_[i].fd, pollset_out.get ()); if (items_[i].events & ZMQ_POLLERR) FD_SET (items_[i].fd, pollset_err.get ()); if (maxfd < items_[i].fd) maxfd = items_[i].fd; } } zmq::optimized_fd_set_t inset (nitems_); zmq::optimized_fd_set_t outset (nitems_); zmq::optimized_fd_set_t errset (nitems_); #endif bool first_pass = true; int nevents = 0; while (true) { #if defined ZMQ_POLL_BASED_ON_POLL // Compute the timeout for the subsequent poll. zmq::timeout_t timeout = zmq::compute_timeout (first_pass, timeout_, now, end); // Wait for events. { int rc = poll (&pollfds[0], nitems_, timeout); if (rc == -1 && errno == EINTR) { return -1; } errno_assert (rc >= 0); } // Check for the events. for (int i = 0; i != nitems_; i++) { items_[i].revents = 0; // The poll item is a 0MQ socket. Retrieve pending events // using the ZMQ_EVENTS socket option. if (items_[i].socket) { size_t zmq_events_size = sizeof (uint32_t); uint32_t zmq_events; if (zmq_getsockopt (items_[i].socket, ZMQ_EVENTS, &zmq_events, &zmq_events_size) == -1) { return -1; } if ((items_[i].events & ZMQ_POLLOUT) && (zmq_events & ZMQ_POLLOUT)) items_[i].revents |= ZMQ_POLLOUT; if ((items_[i].events & ZMQ_POLLIN) && (zmq_events & ZMQ_POLLIN)) items_[i].revents |= ZMQ_POLLIN; } // Else, the poll item is a raw file descriptor, simply convert // the events to zmq_pollitem_t-style format. else { if (pollfds[i].revents & POLLIN) items_[i].revents |= ZMQ_POLLIN; if (pollfds[i].revents & POLLOUT) items_[i].revents |= ZMQ_POLLOUT; if (pollfds[i].revents & POLLPRI) items_[i].revents |= ZMQ_POLLPRI; if (pollfds[i].revents & ~(POLLIN | POLLOUT | POLLPRI)) items_[i].revents |= ZMQ_POLLERR; } if (items_[i].revents) nevents++; } #else // Compute the timeout for the subsequent poll. timeval timeout; timeval *ptimeout; if (first_pass) { timeout.tv_sec = 0; timeout.tv_usec = 0; ptimeout = &timeout; } else if (timeout_ < 0) ptimeout = NULL; else { timeout.tv_sec = static_cast<long> ((end - now) / 1000); timeout.tv_usec = static_cast<long> ((end - now) % 1000 * 1000); ptimeout = &timeout; } // Wait for events. Ignore interrupts if there's infinite timeout. while (true) { memcpy (inset.get (), pollset_in.get (), zmq::valid_pollset_bytes (*pollset_in.get ())); memcpy (outset.get (), pollset_out.get (), zmq::valid_pollset_bytes (*pollset_out.get ())); memcpy (errset.get (), pollset_err.get (), zmq::valid_pollset_bytes (*pollset_err.get ())); #if defined ZMQ_HAVE_WINDOWS int rc = select (0, inset.get (), outset.get (), errset.get (), ptimeout); if (unlikely (rc == SOCKET_ERROR)) { errno = zmq::wsa_error_to_errno (WSAGetLastError ()); wsa_assert (errno == ENOTSOCK); return -1; } #else int rc = select (maxfd + 1, inset.get (), outset.get (), errset.get (), ptimeout); if (unlikely (rc == -1)) { errno_assert (errno == EINTR || errno == EBADF); return -1; } #endif break; } // Check for the events. for (int i = 0; i != nitems_; i++) { items_[i].revents = 0; // The poll item is a 0MQ socket. Retrieve pending events // using the ZMQ_EVENTS socket option. if (items_[i].socket) { size_t zmq_events_size = sizeof (uint32_t); uint32_t zmq_events; if (zmq_getsockopt (items_[i].socket, ZMQ_EVENTS, &zmq_events, &zmq_events_size) == -1) return -1; if ((items_[i].events & ZMQ_POLLOUT) && (zmq_events & ZMQ_POLLOUT)) items_[i].revents |= ZMQ_POLLOUT; if ((items_[i].events & ZMQ_POLLIN) && (zmq_events & ZMQ_POLLIN)) items_[i].revents |= ZMQ_POLLIN; } // Else, the poll item is a raw file descriptor, simply convert // the events to zmq_pollitem_t-style format. else { if (FD_ISSET (items_[i].fd, inset.get ())) items_[i].revents |= ZMQ_POLLIN; if (FD_ISSET (items_[i].fd, outset.get ())) items_[i].revents |= ZMQ_POLLOUT; if (FD_ISSET (items_[i].fd, errset.get ())) items_[i].revents |= ZMQ_POLLERR; } if (items_[i].revents) nevents++; } #endif // If timeout is zero, exit immediately whether there are events or not. if (timeout_ == 0) break; // If there are events to return, we can exit immediately. if (nevents) break; // At this point we are meant to wait for events but there are none. // If timeout is infinite we can just loop until we get some events. if (timeout_ < 0) { if (first_pass) first_pass = false; continue; } // The timeout is finite and there are no events. In the first pass // we get a timestamp of when the polling have begun. (We assume that // first pass have taken negligible time). We also compute the time // when the polling should time out. if (first_pass) { now = clock.now_ms (); end = now + timeout_; if (now == end) break; first_pass = false; continue; } // Find out whether timeout have expired. now = clock.now_ms (); if (now >= end) break; } return nevents; #else // Exotic platforms that support neither poll() nor select(). errno = ENOTSUP; return -1; #endif }
int newPhoton (PhotonMap* pmap, const RAY* ray) { unsigned i; Photon photon; COLOR photonFlux; /* Account for distribution ratio */ if (!pmap || pmapRandom(pmap -> randState) > pmap -> distribRatio) return -1; /* Don't store on sources */ if (ray -> robj > -1 && islight(objptr(ray -> ro -> omod) -> otype)) return -1; /* if modifier in include/exclude set */ if (ambincl != -1 && ray -> ro && ambincl != inset(ambset, ray -> ro -> omod)) return -1; if (pmapNumROI && pmapROI) { unsigned inROI = 0; /* Store photon if within a region of interest (for ze Ecksperts!) */ for (i = 0; !inROI && i < pmapNumROI; i++) inROI = (ray -> rop [0] >= pmapROI [i].min [0] && ray -> rop [0] <= pmapROI [i].max [0] && ray -> rop [1] >= pmapROI [i].min [1] && ray -> rop [1] <= pmapROI [i].max [1] && ray -> rop [2] >= pmapROI [i].min [2] && ray -> rop [2] <= pmapROI [i].max [2]); if (!inROI) return -1; } /* Adjust flux according to distribution ratio and ray weight */ copycolor(photonFlux, ray -> rcol); scalecolor(photonFlux, ray -> rweight / (pmap -> distribRatio ? pmap -> distribRatio : 1)); setPhotonFlux(&photon, photonFlux); /* Set photon position and flags */ VCOPY(photon.pos, ray -> rop); photon.flags = 0; photon.caustic = PMAP_CAUSTICRAY(ray); /* Set contrib photon's primary ray and subprocess index (the latter * to linearise the primary ray indices after photon distribution is * complete). Also set primary ray's source index, thereby marking it * as used. */ if (isContribPmap(pmap)) { photon.primary = pmap -> numPrimary; photon.proc = PMAP_GETRAYPROC(ray); pmap -> lastPrimary.srcIdx = ray -> rsrc; } else photon.primary = 0; /* Set normal */ for (i = 0; i <= 2; i++) photon.norm [i] = 127.0 * (isVolumePmap(pmap) ? ray -> rdir [i] : ray -> ron [i]); if (!pmap -> heapBuf) { /* Lazily allocate heap buffa */ #if NIX /* Randomise buffa size to temporally decorellate flushes in * multiprocessing mode */ srandom(randSeed + getpid()); pmap -> heapBufSize = PMAP_HEAPBUFSIZE * (0.5 + frandom()); #else /* Randomisation disabled for single processes on WIN; also useful * for reproducability during debugging */ pmap -> heapBufSize = PMAP_HEAPBUFSIZE; #endif if (!(pmap -> heapBuf = calloc(pmap -> heapBufSize, sizeof(Photon)))) error(SYSTEM, "failed heap buffer allocation in newPhoton"); pmap -> heapBufLen = 0; } /* Photon initialised; now append to heap buffa */ memcpy(pmap -> heapBuf + pmap -> heapBufLen, &photon, sizeof(Photon)); if (++pmap -> heapBufLen >= pmap -> heapBufSize) /* Heap buffa full, flush to heap file */ flushPhotonHeap(pmap); pmap -> numPhotons++; return 0; }
static Py_ssize_t _encode(const uint32_t twobytes[8], const uint32_t onebyte[8], char *dest, Py_ssize_t destlen, size_t destsize, const char *src, Py_ssize_t len, int encodedir) { enum path_state state = START; Py_ssize_t i = 0; /* * Python strings end with a zero byte, which we use as a * terminal token as they are not valid inside path names. */ while (i < len) { switch (state) { case START: switch (src[i]) { case '/': charcopy(dest, &destlen, destsize, src[i++]); break; case '.': state = LDOT; escape3(dest, &destlen, destsize, src[i++]); break; case ' ': state = DEFAULT; escape3(dest, &destlen, destsize, src[i++]); break; case 'a': state = A; charcopy(dest, &destlen, destsize, src[i++]); break; case 'c': state = C; charcopy(dest, &destlen, destsize, src[i++]); break; case 'l': state = L; charcopy(dest, &destlen, destsize, src[i++]); break; case 'n': state = N; charcopy(dest, &destlen, destsize, src[i++]); break; case 'p': state = P; charcopy(dest, &destlen, destsize, src[i++]); break; default: state = DEFAULT; break; } break; case A: if (src[i] == 'u') { state = AU; charcopy(dest, &destlen, destsize, src[i++]); } else state = DEFAULT; break; case AU: if (src[i] == 'x') { state = THIRD; i++; } else state = DEFAULT; break; case THIRD: state = DEFAULT; switch (src[i]) { case '.': case '/': case '\0': escape3(dest, &destlen, destsize, src[i - 1]); break; default: i--; break; } break; case C: if (src[i] == 'o') { state = CO; charcopy(dest, &destlen, destsize, src[i++]); } else state = DEFAULT; break; case CO: if (src[i] == 'm') { state = COMLPT; i++; } else if (src[i] == 'n') { state = THIRD; i++; } else state = DEFAULT; break; case COMLPT: switch (src[i]) { case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': state = COMLPTn; i++; break; default: state = DEFAULT; charcopy(dest, &destlen, destsize, src[i - 1]); break; } break; case COMLPTn: state = DEFAULT; switch (src[i]) { case '.': case '/': case '\0': escape3(dest, &destlen, destsize, src[i - 2]); charcopy(dest, &destlen, destsize, src[i - 1]); break; default: memcopy(dest, &destlen, destsize, &src[i - 2], 2); break; } break; case L: if (src[i] == 'p') { state = LP; charcopy(dest, &destlen, destsize, src[i++]); } else state = DEFAULT; break; case LP: if (src[i] == 't') { state = COMLPT; i++; } else state = DEFAULT; break; case N: if (src[i] == 'u') { state = NU; charcopy(dest, &destlen, destsize, src[i++]); } else state = DEFAULT; break; case NU: if (src[i] == 'l') { state = THIRD; i++; } else state = DEFAULT; break; case P: if (src[i] == 'r') { state = PR; charcopy(dest, &destlen, destsize, src[i++]); } else state = DEFAULT; break; case PR: if (src[i] == 'n') { state = THIRD; i++; } else state = DEFAULT; break; case LDOT: switch (src[i]) { case 'd': case 'i': state = HGDI; charcopy(dest, &destlen, destsize, src[i++]); break; case 'h': state = H; charcopy(dest, &destlen, destsize, src[i++]); break; default: state = DEFAULT; break; } break; case DOT: switch (src[i]) { case '/': case '\0': state = START; memcopy(dest, &destlen, destsize, "~2e", 3); charcopy(dest, &destlen, destsize, src[i++]); break; case 'd': case 'i': state = HGDI; charcopy(dest, &destlen, destsize, '.'); charcopy(dest, &destlen, destsize, src[i++]); break; case 'h': state = H; memcopy(dest, &destlen, destsize, ".h", 2); i++; break; default: state = DEFAULT; charcopy(dest, &destlen, destsize, '.'); break; } break; case H: if (src[i] == 'g') { state = HGDI; charcopy(dest, &destlen, destsize, src[i++]); } else state = DEFAULT; break; case HGDI: if (src[i] == '/') { state = START; if (encodedir) memcopy(dest, &destlen, destsize, ".hg", 3); charcopy(dest, &destlen, destsize, src[i++]); } else state = DEFAULT; break; case SPACE: switch (src[i]) { case '/': case '\0': state = START; memcopy(dest, &destlen, destsize, "~20", 3); charcopy(dest, &destlen, destsize, src[i++]); break; default: state = DEFAULT; charcopy(dest, &destlen, destsize, ' '); break; } break; case DEFAULT: while (inset(onebyte, src[i])) { charcopy(dest, &destlen, destsize, src[i++]); if (i == len) goto done; } switch (src[i]) { case '.': state = DOT; i++; break; case ' ': state = SPACE; i++; break; case '/': state = START; charcopy(dest, &destlen, destsize, '/'); i++; break; default: if (inset(onebyte, src[i])) { do { charcopy(dest, &destlen, destsize, src[i++]); } while (i < len && inset(onebyte, src[i])); } else if (inset(twobytes, src[i])) { char c = src[i++]; charcopy(dest, &destlen, destsize, '_'); charcopy(dest, &destlen, destsize, c == '_' ? '_' : c + 32); } else escape3(dest, &destlen, destsize, src[i++]); break; } break; } } done: return destlen; }
// Like a==b, with a little slop recognizing that float equality can be weird. static bool sloppy_rect_eq(SkRect a, SkRect b) { SkRect inset(a), outset(a); inset.inset(1, 1); outset.outset(1, 1); return outset.contains(b) && !inset.contains(b); }
VOID PASCAL CODESIZE evaltop ( struct evalrec *ptr ){ register struct psop *psol; /* parse stack operand structure */ register struct psop *psor; /* parse stack operand structure */ struct exprec a; a.p = ptr; /* Get right operand */ a.valright = popvalue (a.p->p); itemptr = NULL; if (a.p->p->lastitem) { /* Get OPERATOR */ a.stkoper = popoperator (a.p->p); a.valleft = NULL; /* assume is unary */ if (!inset (a.stkoper, unaryset)) /* Not unary OPERATOR */ a.valleft = (a.stkoper == OPUNPLUS || a.stkoper == OPUNMINUS) ? defaultdsc() : popvalue (a.p->p); /* Save for EVALtop */ a.p->idx = a.stkoper; if (a.valleft) a.valleft->prec = a.valright->prec; psol = &(a.valleft->dsckind.opnd); psor = &(a.valright->dsckind.opnd); switch (a.stkoper) { /* All OPERATORs are executed thru this CASE statement. The * VALcheck routine makes sure operands are of the correct * type and may create dummy entries in the case of the real * operand not being of type result when required. The REStype * routine uses it's argument to know what part of the result * record should be kept and the type of the result. Unary * and binary OPERATORs both return their results in VALright. */ case OPAND: case OPOR: case OPXOR: /* Make sure operands ok */ valcheck (CALLABS, FALSE, &a); /* Must work on 16 bits */ foldsigns (&a); switch (a.stkoper) { case OPAND: psor->doffset = a.left & a.right; break; case OPOR: psor->doffset = a.left | a.right; break; case OPXOR: psor->doffset = a.left ^ a.right; break; } psor->dsign = FALSE; /* Must clear out Dsign in case was signed value */ break; case OPNOT: /* TRUE constant arg */ valcheck (CALLABS, TRUE, &a); foldsigns (&a); psor->doffset = ~a.right; psor->dsign = FALSE; if (optyp == TDB && (psor->doffset & ((OFFSET) ~0xff)) == ((OFFSET) ~0xff)) psor->doffset &= 0xFF; #ifdef V386_noCode if (!(cputype & P386)) /* truncate result to 16 bits */ psor->doffset &= 0xffff; /* for compatablity */ #endif break; case OPSHL: case OPSHR: valcheck (CALLABS, FALSE, &a); psor->doffset = shiftoper (&a); psor->dsign = FALSE; break; case OPSEG: /* Must have segment */ valcheck (CSEG, TRUE, &a); if (psor->dcontext && !(psor->dtype&M_EXPLCOLON)) psor->dsegment = psor->dcontext; psor->dtype = (psor->dtype&M_FORTYPE) | M_SEGRESULT| M_RCONST; psor->doffset = 0; psor->dsign = FALSE; break; case OPDOT: /* See if idx reg */ idxcheck (FALSE, &a); valcheck (CONEABS, FALSE, &a); psol = &(a.valleft->dsckind.opnd); psor = &(a.valright->dsckind.opnd); if (psor->dsize) psol->dsize = psor->dsize; /* Adjust signs on records */ signadjust (FALSE, &a); psol = &(a.valleft->dsckind.opnd); psor = &(a.valright->dsckind.opnd); break; case OPUNPLUS: case OPPLUS: /* See if idx reg */ idxcheck (FALSE, &a); valcheck (CONEABS, FALSE, &a); psol = &(a.valleft->dsckind.opnd); psor = &(a.valright->dsckind.opnd); /* Adjust signs on records */ signadjust (FALSE, &a); psol = &(a.valleft->dsckind.opnd); psor = &(a.valright->dsckind.opnd); break; case OPUNMINUS: case OPMINUS: idxcheck (TRUE, &a); if (psor->dsegment == psol->dsegment && psol->dsegment) { if (psol->dtype & M_SEGRESULT) { psol->dtype = M_SEGRESULT | M_RCONST; psol->doffset = 0; psol->dsign = FALSE; } if (psor->dtype & M_SEGRESULT) { psor->dtype = M_SEGRESULT | M_RCONST; psor->doffset = 0; psor->dsign = FALSE; } } valcheck (CSAMABS, FALSE, &a); signadjust (TRUE, &a); psol = &(a.valleft->dsckind.opnd); psor = &(a.valright->dsckind.opnd); if (psol->dsegment) { /* clear Dcontext if have var-var */ psor->dtype = (psor->dtype & (M_EXPLOFFSET | M_PTRSIZE | M_FORTYPE)) | M_RCONST; psor->dsegment = NULL; psor->dcontext = NULL; psor->dsize = 0; oblititem (a.valleft); a.valleft = NULL; } break; case OPMULT: #ifdef V386 if (M_REGRESULT & (psol->dtype|psor->dtype)) { if (cputype&P386) { idxcheck (2, &a); if (a.p->p->index&0x78) break; } else errorc (E_IRV); } #endif /* fall through */ case OPDIV: valcheck (CALLABS, FALSE, &a); /* Both are constant */ if (a.stkoper == OPMULT) psor->doffset = a.left * a.right; else if (a.right == 0) errorc (E_DVZ); else psor->doffset = a.left / a.right; if (psor->doffset == 0) psor->dsign = FALSE; else psor->dsign = (psol->dsign != psor->dsign); break; case OPHIGH: if (psor->dtype & M_RCONST) { if (psor->dsign) { psor->doffset = -psor->doffset; psor->dsign = 0; } psor->doffset = psor->doffset >> 8 & 0xff; } psor->dtype |= M_HIGH; goto highlow; case OPLOW: if (psor->dtype & M_RCONST) psor->doffset &= 0xFF; psor->dtype |= M_LOW; highlow: psor->dsize = 1; if ((!(psor->dflag & XTERNAL && psor->dtype & M_EXPLOFFSET)) && psor->dsegment && (psor->dtype & (M_EXPLOFFSET | M_SEGRESULT | M_REGRESULT | M_GROUPSEG | M_DATA | M_CODE))) errorc (E_CXP); break; case OPOFFSET: psor->fixtype = FOFFSET; if (!(psor->dsegment || psor->dflag == XTERNAL)) errorc(E_OSG|E_WARN2); if (!(M_DATA & psor->dtype)) psor->dcontext = NULL; psor->dtype = (psor->dtype | M_RCONST | M_EXPLOFFSET) & ~(M_SEGRESULT); if (fSimpleSeg) makeGrpRel (psor); /* preserve OFFSET arg size it's a const */ if ((psor->dsegment || psor->dcontext || psor->dflag == XTERNAL) && !(M_PTRSIZE & psor->dtype)) psor->dsize = 0; break; case OPLENGTH: case OPSIZE: /* Must be data associated */ valcheck (CDATA, TRUE, &a); psol = &(a.valleft->dsckind.opnd); psor = &(a.valright->dsckind.opnd); if (a.stkoper == OPLENGTH) psor->doffset = psor->dlength; else psor->doffset = psor->dsize * psor->dlength; psor->dflag &= ~XTERNAL; break; case OPTYPE: a.right = psor->dsize; oblititem (a.valright); a.valright = defaultdsc (); psor = &(a.valright->dsckind.opnd); psor->doffset = a.right; a.p->p->base = 0; a.p->p->index = 0; break; case OPMASK: case OPWIDTH: /* Must be record or field */ valcheck (CREC, TRUE, &a); if (psor->dextptr && psor->dflag != XTERNAL) { if (a.stkoper == OPWIDTH) if (psor->dextptr->symkind == REC) psor->doffset = psor->dextptr->length; else psor->doffset = psor->dextptr->symu.rec.recwid; else if (psor->dextptr->symkind == REC) psor->doffset = psor->dextptr->offset; else psor->doffset = psor->dextptr->symu.rec.recmsk; } break; case OPSTYPE: a.right = 0; if (errorcode == 0) { if (psor->dflag == XTERNAL) a.right |= 0x80; /* external */ if (psor->dflag != UNDEFINED) a.right |= 0x20; /* defined */ if (psor->dtype & M_DATA) a.right |= 0x02; /* data */ if (psor->dtype & M_CODE) a.right |= 0x01; /* program */ if ((a.p->p->base == 0) && (a.p->p->index == 0)) { if (psor->dtype == xltsymtoresult[REGISTER]) a.right |= 0x10; /* register */ else if (psor->dtype & M_RCONST) a.right |= 0x04; /* constant */ else if (psor->dtype & M_DATA) a.right |= 0x08; /* direct */ } else { a.p->p->base = 0; a.p->p->index = 0; } } oblititem (a.valright); a.valright = defaultdsc (); psor = &(a.valright->dsckind.opnd); psor->doffset = a.right; errorcode = 0; break; case OPLPAR: case OPLBRK: if (!(a.p->parenflag || a.p->p->exprdone)) pushpar (a.p); else if (a.stkoper == OPLBRK) a.valright = regcheck (a.valright, FALSE, &a); psol = &(a.valleft->dsckind.opnd); psor = &(a.valright->dsckind.opnd); break; case OPMOD: valcheck (CALLABS, FALSE, &a); if (a.right == 0) { /* div 0 */ errorc (E_DVZ); psor->doffset = 0; psor->dsign = FALSE; } else { psor->doffset = a.left % a.right; if (psor->doffset == 0 || !psol->dsign) psor->dsign = FALSE; else psor->dsign = TRUE; } break; case OPTHIS: valcheck (CLSIZE, TRUE, &a); /* Unary, right is size */ psor->s = 0; psor->dsize = a.right; psor->doffset = pcoffset; psor->dsegment = pcsegment; if (a.right >= CSFAR_LONG) psor->dcontext = regsegment[CSSEG]; break; case OPSHORT: valcheck (CCODE, TRUE, &a); /* Unary, must be code */ psor->dtype |= M_SHRT; break; case OPPTR: valcheck (CLSIZE, FALSE, &a); if (psol->doffset >= CSFAR_LONG && (M_RCONST == psor->dtype || (psor->dcontext && (M_DATA&psor->dtype && !(M_CODE&psor->dtype))) )) errorc (E_NSO); /* Can't code_data */ else { psor->dsize = a.left; if ((M_DATA & psol->dtype) && !(M_DATA & psor->dtype)) psor->dcontext = NULL; /* Change code/data */ psor->dtype = (psor->dtype & ~(M_CODE | M_DATA) | (psol->dtype & (M_CODE | M_DATA))) & ~(M_FORTYPE) | (M_PTRSIZE); } break; case OPEQ: case OPGE: case OPGT: case OPLE: case OPLT: case OPNE: valcheck (CSAME, FALSE, &a); signadjust (TRUE, &a); /* Do signed R=L-R */ psol = &(a.valleft->dsckind.opnd); psor = &(a.valright->dsckind.opnd); if (!fArth32) a.right &= 0xffff; switch (a.stkoper) { case OPEQ: a.right = (a.right == 0); break; case OPGE: a.right = !psor->dsign; break; case OPGT: a.right = (!psor->dsign && a.right); break; case OPLE: a.right = (psor->dsign || a.right == 0); break; case OPLT: a.right = psor->dsign; break; case OPNE: a.right = (a.right != 0); break; } /* Set Dsign if result TRUE */ psor->doffset = a.right; psor->dsign = (a.right == 1); psor->dcontext = NULL; oblititem (a.valleft); a.valleft = NULL; break; case OPCOLON: /* <segment> : <var> */ valcheck (CLSEG, FALSE, &a); if ((a.p->p->bracklevel || a.p->evalop == OPLBRK) && (M_REGRESULT & (psol->dtype | psor->dtype))) errorc(E_ISR); psor->dtype = (psor->dtype|M_EXPLCOLON|M_DATA) & ~M_RCONST; if (psol->dsegment) { if (psol->dsegment->symkind == GROUP) psor->dtype |= M_GROUPSEG; if (!psor->dsegment && !(M_REGRESULT & psol->dtype) && !(a.p->p->base || a.p->p->index)) psor->dsegment = psol->dsegment; } psor->dcontext = psol->dsegment; break; } /* operator case */ if (!inset (a.stkoper, parseset)) { /* Have constant or segment result */ psor->dlength = 0; psor->dsize = 0; psor->sized = 0; if (a.valleft) psol->dsize = 0; /* Have constant result( typeless ) */ if (a.stkoper != OPSEG) { psor->dtype = (psor->dtype & M_FORTYPE) | M_RCONST; psor->dsegment = NULL; if (a.valleft) psol->dtype &= ~M_PTRSIZE; } } a.p->p->curresult = a.valright; psor = &(a.p->p->curresult->dsckind.opnd); if (!fArth32 && optyp != TDD) psor->doffset &= 0xffff; if (a.valleft) { /* Might need to copy some info */ /* Prevent OPERATORs like +, -, . from losing the [DATA] flag if it it is the Left operand. This is ok, except when surrounded by a PTR which will drop segment override if not data type */ if (a.stkoper != OPCOLON) psor->dtype |= psol->dtype & (M_DATA | M_CODE); if (psor->dflag == KNOWN) psor->dflag = psol->dflag; if (!psor->dcontext) psor->dcontext = psol->dcontext; if (psor->dsize == 0) psor->dsize = psol->dsize; if (psor->fixtype == FCONSTANT) psor->fixtype = psol->fixtype; psor->dtype |= psol->dtype & (M_PTRSIZE|M_EXPLOFFSET|M_FORTYPE); /* Above makes sure PTR or OFFSET is not lost */ oblititem (a.valleft); a.valleft = NULL; } }
extern void multambient( /* compute ambient component & multiply by coef. */ COLOR aval, RAY *r, FVECT nrm ) { static int rdepth = 0; /* ambient recursion */ COLOR acol; double d, l; if (ambdiv <= 0) /* no ambient calculation */ goto dumbamb; /* check number of bounces */ if (rdepth >= ambounce) goto dumbamb; /* check ambient list */ if (ambincl != -1 && r->ro != NULL && ambincl != inset(ambset, r->ro->omod)) goto dumbamb; if (ambacc <= FTINY) { /* no ambient storage */ copycolor(acol, aval); rdepth++; d = doambient(acol, r, r->rweight, NULL, NULL); rdepth--; if (d <= FTINY) goto dumbamb; copycolor(aval, acol); return; } if (tracktime) /* sort to minimize thrashing */ sortambvals(0); /* interpolate ambient value */ setcolor(acol, 0.0, 0.0, 0.0); d = sumambient(acol, r, nrm, rdepth, &atrunk, thescene.cuorg, thescene.cusize); if (d > FTINY) { d = 1.0/d; scalecolor(acol, d); multcolor(aval, acol); return; } rdepth++; /* need to cache new value */ d = makeambient(acol, r, nrm, rdepth-1); rdepth--; if (d > FTINY) { multcolor(aval, acol); /* got new value */ return; } dumbamb: /* return global value */ if ((ambvwt <= 0) | (navsum == 0)) { multcolor(aval, ambval); return; } l = bright(ambval); /* average in computations */ if (l > FTINY) { d = (log(l)*(double)ambvwt + avsum) / (double)(ambvwt + navsum); d = exp(d) / l; scalecolor(aval, d); multcolor(aval, ambval); /* apply color of ambval */ } else { d = exp( avsum / (double)navsum ); scalecolor(aval, d); /* neutral color */ } }
int menuhit(int but, Mouse *m, Menu *menu) { int i, nitem, nitemdrawn, maxwid, lasti, off, noff, wid, screenitem; bool scrolling; Rectangle r, menur, sc, textr, scrollr; Bitmap *b; Point pt; char *item; extern unsigned int cursor; unsigned int oldcursor = cursor; cursorswitch(ArrowCursor); sc = screen.clipr; clipr(&screen, screen.r); maxwid = 0; for(nitem = 0; (item = menu->item? menu->item[nitem] : (*menu->gen)(nitem)); nitem++){ i = strwidth(font, item); if(i > maxwid) maxwid = i; } if(menu->lasthit<0 || menu->lasthit>=nitem) menu->lasthit = 0; screenitem = (Dy(screen.r)-10)/(fontheight()+Vspacing); if(nitem>Maxunscroll || nitem>screenitem){ scrolling = true; nitemdrawn = Nscroll; if(nitemdrawn > screenitem) nitemdrawn = screenitem; wid = maxwid + Gap + Scrollwid; off = menu->lasthit - nitemdrawn/2; if(off < 0) off = 0; if(off > nitem-nitemdrawn) off = nitem-nitemdrawn; lasti = menu->lasthit-off; }else{ scrolling = false; nitemdrawn = nitem; wid = maxwid; off = 0; lasti = menu->lasthit; } r = inset(Rect(0, 0, wid, nitemdrawn*(fontheight()+Vspacing)), -Margin); r = rsubp(r, Pt(wid/2, lasti*(fontheight()+Vspacing)+fontheight()/2)); r = raddp(r, m->xy); pt = Pt(0, 0); if(r.max.x>screen.r.max.x) pt.x = screen.r.max.x-r.max.x; if(r.max.y>screen.r.max.y) pt.y = screen.r.max.y-r.max.y; if(r.min.x<screen.r.min.x) pt.x = screen.r.min.x-r.min.x; if(r.min.y<screen.r.min.y) pt.y = screen.r.min.y-r.min.y; menur = raddp(r, pt); textr.max.x = menur.max.x-Margin; textr.min.x = textr.max.x-maxwid; textr.min.y = menur.min.y+Margin; textr.max.y = textr.min.y + nitemdrawn*(fontheight()+Vspacing); if(scrolling){ scrollr = inset(menur, Border); scrollr.max.x = scrollr.min.x+Scrollwid; }else scrollr = Rect(0, 0, 0, 0); b = balloc(menur, screen.ldepth); if(b == 0) b = &screen; bitblt(b, menur.min, &screen, menur, S); bitblt(&screen, menur.min, &screen, menur, 0); border(&screen, menur, Blackborder, F, _bgpixel); r = menurect(textr, lasti); cursorset(divpt(add(r.min, r.max), 2)); menupaint(menu, textr, off, nitemdrawn); if(scrolling) menuscrollpaint(scrollr, off, nitem, nitemdrawn); r = menurect(textr, lasti); cursorset(divpt(add(r.min, r.max), 2)); menupaint(menu, textr, off, nitemdrawn); if(scrolling) menuscrollpaint(scrollr, off, nitem, nitemdrawn); while(m->buttons & (1<<(but-1))){ lasti = menuscan(but, m, textr, lasti); if(lasti >= 0) break; while(!ptinrect(m->xy, textr) && (m->buttons & (1<<(but-1)))){ if(scrolling && ptinrect(m->xy, scrollr)){ noff = ((m->xy.y-scrollr.min.y)*nitem)/Dy(scrollr); noff -= nitemdrawn/2; if(noff < 0) noff = 0; if(noff > nitem-nitemdrawn) noff = nitem-nitemdrawn; if(noff != off){ off = noff; menupaint(menu, textr, off, nitemdrawn); menuscrollpaint(scrollr, off, nitem, nitemdrawn); } } *m = emouse(); } } bitblt(&screen, menur.min, b, menur, S); if(b != &screen) bfree(b); clipr(&screen, sc); if(lasti >= 0){ menu->lasthit = lasti+off; return cursorswitch(oldcursor), menu->lasthit; } cursorswitch(oldcursor); return -1; }
void inset(double n) { inset(n, n, n); }
void inset(double n, volume &dst) const { inset(n, n, n, dst); }
uint16_t service_usage_query (enum einit_usage_query task, const struct lmodule *module, const char *service) { uint16_t ret = 0; struct stree *ha; char **t; uint32_t i; struct service_usage_item *item; if ((!module || !module->module) && !service) return 0; emutex_lock (&service_usage_mutex); if (task & service_not_in_use) { ret |= service_not_in_use; struct stree *ha = service_usage; /* a service is "in use" if * it's the provider for something, and * it's the only provider for that for that specific service, and * all of the users of that service use the */ while (ha) { if (((struct service_usage_item *)(ha->value))->users && (((struct service_usage_item *)(ha->value))->provider) && ((((struct service_usage_item *)(ha->value))->provider)[0]) && (!((((struct service_usage_item *)(ha->value))->provider)[1])) && inset ((const void **)(((struct service_usage_item *)(ha->value))->provider), module, -1)) { /* this one might be a culprit */ uint32_t i = 0, r = 0; for (; (((struct service_usage_item *)(ha->value))->users)[i]; i++) { if ((((struct service_usage_item *)(ha->value))->users)[i]->si && (((struct service_usage_item *)(ha->value))->users)[i]->si->requires) { if (inset ((const void **)((((struct service_usage_item *)(ha->value))->users)[i]->si->requires), ha->key, SET_TYPE_STRING)) { r++; } } } /* yep, really is in use */ if (i == r) { ret ^= service_not_in_use; break; } } ha = streenext (ha); } } else if (task & service_requirements_met) { ret |= service_requirements_met; if (module->si && (t = module->si->requires)) { for (i = 0; t[i]; i++) { if (!service_usage || !(ha = streefind (service_usage, t[i], tree_find_first)) || !((struct service_usage_item *)(ha->value))->provider) { ret ^= service_requirements_met; break; } } } } else if (task & service_update) { modules_last_change = time(NULL); if (module->status & status_enabled) { if (module->si && (t = module->si->requires)) { for (i = 0; t[i]; i++) { if (service_usage && (ha = streefind (service_usage, t[i], tree_find_first)) && (item = (struct service_usage_item *)ha->value)) { item->users = (struct lmodule **)setadd ((void **)item->users, (void *)module, SET_NOALLOC); } } } if (module->si && (t = module->si->provides)) { for (i = 0; t[i]; i++) { if (service_usage && (ha = streefind (service_usage, t[i], tree_find_first)) && (item = (struct service_usage_item *)ha->value)) { item->provider = (struct lmodule **)setadd ((void **)item->provider, (void *)module, SET_NOALLOC); } else { struct service_usage_item nitem; memset (&nitem, 0, sizeof (struct service_usage_item)); nitem.provider = (struct lmodule **)setadd ((void **)nitem.provider, (void *)module, SET_NOALLOC); service_usage = streeadd (service_usage, t[i], &nitem, sizeof (struct service_usage_item), NULL); } } } } /* more cleanup code */ ha = service_usage; while (ha) { item = (struct service_usage_item *)ha->value; if (!(module->status & status_enabled)) { item->provider = (struct lmodule **)setdel ((void **)item->provider, (void *)module); item->users = (struct lmodule **)setdel ((void **)item->users, (void *)module); } if (!item->provider && !item->users) { // service_usage = streedel (service_usage, ha); service_usage = streedel (ha); ha = service_usage; } else ha = streenext (ha); } } else if (task & service_is_required) { if (service_usage && (ha = streefind (service_usage, service, tree_find_first)) && (item = (struct service_usage_item *)ha->value) && (item->users)) ret |= service_is_required; } else if (task & service_is_provided) { if (service_usage && (ha = streefind (service_usage, service, tree_find_first)) && (item = (struct service_usage_item *)ha->value) && (item->provider)) ret |= service_is_provided; } emutex_unlock (&service_usage_mutex); return ret; }