static sraSpan * sraSpanDup(const sraSpan *src) { sraSpan *span; if (!src) return NULL; span = sraSpanCreate(src->start, src->end, src->subspan); return span; }
static sraSpan * sraSpanDup(const sraSpan *src) { sraSpan *span; if (IsBadReadPtr(src,sizeof(sraSpan))) return NULL; span = sraSpanCreate(src->start, src->end, src->subspan); return span; }
sraRegion * sraRgnCreateRect(int x1, int y1, int x2, int y2) { sraSpanList *vlist, *hlist; sraSpan *vspan, *hspan; /* - Build the horizontal portion of the span */ hlist = sraSpanListCreate(); hspan = sraSpanCreate(x1, x2, NULL); sraSpanInsertAfter(hspan, &(hlist->front)); /* - Build the vertical portion of the span */ vlist = sraSpanListCreate(); vspan = sraSpanCreate(y1, y2, hlist); sraSpanInsertAfter(vspan, &(vlist->front)); sraSpanListDestroy(hlist); return (sraRegion*)vlist; }
static rfbBool sraSpanListSubtract(sraSpanList *dest, const sraSpanList *src) { sraSpan *d_curr, *s_curr; if (!dest) { if (!src) { return 1; } else { printf("sraSpanListSubtract:incompatible spans (only one NULL!)\n"); return FALSE; } } d_curr = dest->front._next; s_curr = src->front._next; while ((s_curr != &(src->back)) && (d_curr != &(dest->back))) { /* - If we haven't reached a destination span yet then move on */ if (d_curr->start >= s_curr->end) { s_curr = s_curr->_next; continue; } /* - If we are beyond the current destination span then skip it */ if (d_curr->end <= s_curr->start) { d_curr = d_curr->_next; continue; } /* - If we partially overlap the current span then split it up */ if (s_curr->start > d_curr->start) { sraSpanInsertBefore(sraSpanCreate(d_curr->start, s_curr->start, d_curr->subspan), d_curr); d_curr->start = s_curr->start; } if (s_curr->end < d_curr->end) { sraSpanInsertAfter(sraSpanCreate(s_curr->end, d_curr->end, d_curr->subspan), d_curr); d_curr->end = s_curr->end; } /* - Now recursively process the affected span */ if ((!d_curr->subspan) || !sraSpanListSubtract(d_curr->subspan, s_curr->subspan)) { /* - The destination subspan is now empty, so we should remove it */ sraSpan *next = d_curr->_next; sraSpanRemove(d_curr); sraSpanDestroy(d_curr); d_curr = next; } else { /* Merge this span with previous or next? */ if (d_curr->_prev != &(dest->front)) sraSpanMergePrevious(d_curr); if (d_curr->_next != &(dest->back)) sraSpanMergeNext(d_curr); /* - Move on to the next span */ if (s_curr->end > d_curr->end) { d_curr = d_curr->_next; } else { s_curr = s_curr->_next; } } } return !sraSpanListEmpty(dest); }
static void sraSpanListOr(sraSpanList *dest, const sraSpanList *src) { sraSpan *d_curr, *s_curr; int s_start, s_end; if (!dest) { if (!src) { return; } else { printf("sraSpanListOr:incompatible spans (only one NULL!)\n"); return; } } d_curr = dest->front._next; s_curr = src->front._next; s_start = s_curr->start; s_end = s_curr->end; while (s_curr != &(src->back)) { /* - If we are at end of destination list OR If the new span comes before the next destination one */ if ((d_curr == &(dest->back)) || (d_curr->start >= s_end)) { /* - Add the span */ sraSpanInsertBefore(sraSpanCreate(s_start, s_end, s_curr->subspan), d_curr); if (d_curr != &(dest->back)) sraSpanMergePrevious(d_curr); s_curr = s_curr->_next; s_start = s_curr->start; s_end = s_curr->end; } else { /* - If the new span overlaps the existing one */ if ((s_start < d_curr->end) && (s_end > d_curr->start)) { /* - Insert new span before the existing destination one? */ if (s_start < d_curr->start) { sraSpanInsertBefore(sraSpanCreate(s_start, d_curr->start, s_curr->subspan), d_curr); sraSpanMergePrevious(d_curr); } /* Split the existing span if necessary */ if (s_end < d_curr->end) { sraSpanInsertAfter(sraSpanCreate(s_end, d_curr->end, d_curr->subspan), d_curr); d_curr->end = s_end; } if (s_start > d_curr->start) { sraSpanInsertBefore(sraSpanCreate(d_curr->start, s_start, d_curr->subspan), d_curr); d_curr->start = s_start; } /* Recursively OR subspans */ sraSpanListOr(d_curr->subspan, s_curr->subspan); /* Merge this span with previous or next? */ if (d_curr->_prev != &(dest->front)) sraSpanMergePrevious(d_curr); if (d_curr->_next != &(dest->back)) sraSpanMergeNext(d_curr); /* Move onto the next pair to compare */ if (s_end > d_curr->end) { s_start = d_curr->end; d_curr = d_curr->_next; } else { s_curr = s_curr->_next; s_start = s_curr->start; s_end = s_curr->end; } } else { /* - No overlap. Move to the next destination span */ d_curr = d_curr->_next; } } } }
static rfbBool sraSpanListAnd(sraSpanList *dest, const sraSpanList *src) { sraSpan *d_curr, *s_curr, *d_next; if (!dest) { if (!src) { return 1; } else { ///rfbErr("sraSpanListAnd:incompatible spans (only one NULL!)\n"); return FALSE; } } else if (!src) return FALSE; d_curr = dest->front._next; s_curr = src->front._next; while ((s_curr != &(src->back)) && (d_curr != &(dest->back))) { /* - If we haven't reached a destination span yet then move on */ if (d_curr->start >= s_curr->end) { s_curr = s_curr->_next; continue; } /* - If we are beyond the current destination span then remove it */ if (d_curr->end <= s_curr->start) { sraSpan *next = d_curr->_next; sraSpanRemove(d_curr); sraSpanDestroy(d_curr); d_curr = next; continue; } /* - If we partially overlap a span then split it up or remove bits */ if (s_curr->start > d_curr->start) { /* - The top bit of the span does not match */ d_curr->start = s_curr->start; } if (s_curr->end < d_curr->end) { /* - The end of the span does not match */ sraSpanInsertAfter(sraSpanCreate(s_curr->end, d_curr->end, d_curr->subspan), d_curr); d_curr->end = s_curr->end; } /* - Now recursively process the affected span */ if (!sraSpanListAnd(d_curr->subspan, s_curr->subspan)) { /* - The destination subspan is now empty, so we should remove it */ sraSpan *next = d_curr->_next; sraSpanRemove(d_curr); sraSpanDestroy(d_curr); d_curr = next; } else { /* Merge this span with previous or next? */ if (d_curr->_prev != &(dest->front)) sraSpanMergePrevious(d_curr); /* - Move on to the next span */ d_next = d_curr; if (s_curr->end >= d_curr->end) { d_next = d_curr->_next; } if (s_curr->end <= d_curr->end) { s_curr = s_curr->_next; } d_curr = d_next; } } while (d_curr != &(dest->back)) { sraSpan *next = d_curr->_next; sraSpanRemove(d_curr); sraSpanDestroy(d_curr); d_curr=next; } return !sraSpanListEmpty(dest); }