int i;
static unsigned char *compressline(termline *ldata){    struct buf buffer = { NULL, 0, 0 }, *b = &buffer;    /*     * First, store the column count, 7 bits at a time, least     * significant `digit' first, with the high bit set on all but     * the last.     */    {	int n = ldata->cols;	while (n >= 128) {	    add(b, (unsigned char)((n & 0x7F) | 0x80));	    n >>= 7;	}	add(b, (unsigned char)(n));    }    /*     * Next store the lattrs; same principle.     */    {	int n = ldata->lattr;	while (n >= 128) {	    add(b, (unsigned char)((n & 0x7F) | 0x80));	    n >>= 7;	}	add(b, (unsigned char)(n));    }    /*     * Now we store a sequence of separate run-length encoded     * fragments, each containing exactly as many symbols as there     * are columns in the ldata.     *      * All of these have a common basic format:     *      *  - a byte 00-7F indicates that X+1 literals follow it     * 	- a byte 80-FF indicates that a single literal follows it     * 	  and expects to be repeated (X-0x80)+2 times.     *      * The format of the `literals' varies between the fragments.     */    makerle(b, ldata, makeliteral_chr);    makerle(b, ldata, makeliteral_attr);    /*     * Diagnostics: ensure that the compressed data really does     * decompress to the right thing.     */#ifndef CHECK_SB_COMPRESSION    {	int dused;	termline *dcl;#ifdef DIAGNOSTIC_SB_COMPRESSION	int i;	for (i = 0; i < b->len; i++) {	    printf(" %02x ", b->data[i]);	}	printf("\n");#endif	dcl = decompressline(b->data, &dused);	assert(b->len == dused);	assert(ldata->cols == dcl->cols);	assert(ldata->lattr == dcl->lattr);	assert(!memcmp(ldata->chars, dcl->chars, ldata->cols * TSIZE));#ifdef DIAGNOSTIC_SB_COMPRESSION	printf("%d cols (%d bytes) -> %d bytes (factor of %g)\n",	       ldata->cols, 4 * ldata->cols, dused,	       (double)dused / (4 * ldata->cols));#endif	freeline(dcl);    }#endif    /*     * Trim the allocated memory so we don't waste any, and return.     */    return sresize(b->data, b->len, unsigned char);}