/* Remove waiting data from buffer, return number of bytes ** If data pointer is null, adjust pointers but don't transfer data */ WORD buff_try(CBUFF *bp, BYTE *data, WORD maxlen) { WORD trial, n, n1, n2; trial = (WORD)bp->trial & (bp->len-1); /* Mask trial len to buffer area */ n = minw(maxlen, buff_untriedlen(bp)); /* Get max allowable length */ n1 = minw(n,(WORD)(bp->len -trial)); /* Length up to end of buff */ n2 = n - n1; /* Length from start of buff */ if(n1 && data) /* If anything to copy.. */ memcpy(data, &bp->data[trial], n1); /* ..copy up to end of buffer.. */ if(n2 && data) /* ..and maybe also.. */ memcpy(&data[n1], bp->data, n2); /* ..copy from start of buffer */ bp->trial += n; /* Bump trial pointer */ return(n); }
/* Load data into buffer, return num of bytes that could be accepted ** If data pointer is null. adjust pointers but don't transfer data */ WORD buff_in(CBUFF *bp, BYTE *data, WORD len) { WORD in, n, n1, n2; in = (WORD)bp->in & (bp->len-1); /* Mask len to buffer area */ n = minw(len, buff_freelen(bp)); /* Get max allowable length */ n1 = minw(n,(WORD)(bp->len - in)); /* Length up to end of buff */ n2 = n - n1; /* Length from start of buff */ if(n1 && data) /* If anything to copy ... */ memcpy (&bp->data[in], data, n1); /* ..copy up to end of buffer ..*/ if(n2 && data) /* and maybe also.. */ memcpy (&bp->data, &data[n1], n2); /* ..copy into start of buffer */ bp->in += n; /* Bump point */ return (n); }
/* Remove data from buffer, return number of bytes ** If data pointer is null, adjust pointers but don't transfer data */ WORD buff_out(CBUFF *bp, BYTE *data, WORD maxlen) { WORD out, n, n1, n2; out = (WORD)bp->out & (bp->len-1); /* Mask len to buffer area */ n = minw(maxlen, buff_dlen(bp)); /* Get max allowable length */ n1 = minw(n, (WORD)(bp->len - out)); /* Length up to end of buff */ n2 = n - n1; /* Length from start of buff */ if(n1 && data) /* If anything to copy.. */ memcpy(data, &bp->data[out], n1); /* ..copy up to end of buffer.. */ if(n2 && data) /* ..and maybe also.. */ memcpy(&data[n1], bp->data, n2); /* ..copy from start of buffer */ bp->out +=n; /* Bump O/P pointer */ if(buff_untriedlen(bp)) /* ..and maybe trial pointer */ bp->trial = bp->out; return(n); }
int main(int argc, char *argv[]) { int n; float (*points)[2]; struct wt **weight; scanf("%d", &n); weight = malloc(n * sizeof(*weight)); points = calloc(n, sizeof(*points)); for (int i=0; i<n; ++i) { scanf("%f %f", &points[i][0], &points[i][1]); weight[i] = malloc(n * sizeof(**weight)); } minw(weight, points, n); printf("%f\n", weight[0][n-1].w); print_tris(weight, 0, n-1); for (int i=0; i<n; ++i) free(weight[i]); free(weight); free(points); return 0; }
/* Rewind the trial pointer by the given byte count, return actual count */ WORD buff_retry(CBUFF *bp, WORD len) { len = minw(len, buff_trylen(bp)); bp->trial -= len; return(len); }