static int do_buf(unsigned char *buf, int buflen,
			int type, unsigned char flags, char *quotes, char_io *io_ch, void *arg)
{
	int i, outlen, len;
	unsigned char orflags, *p, *q;
	unsigned long c;
	p = buf;
	q = buf + buflen;
	outlen = 0;
	while(p != q) {
		if(p == buf) orflags = CHARTYPE_FIRST_ESC_2253;
		else orflags = 0;
		switch(type & BUF_TYPE_WIDTH_MASK) {
			case 4:
			c = ((unsigned long)*p++) << 24;
			c |= ((unsigned long)*p++) << 16;
			c |= ((unsigned long)*p++) << 8;
			c |= *p++;
			break;
			case 2:
			c = ((unsigned long)*p++) << 8;
			c |= *p++;
			break;
			case 1:
			c = *p++;
			break;
			case 0:
			i = UTF8_getc(p, buflen, &c);
			if(i < 0) return -1;
			p += i;
			break;
		}
		if (p == q) orflags = CHARTYPE_LAST_ESC_2253;
		if(type & BUF_TYPE_CONVUTF8) {
			unsigned char utfbuf[6];
			int utflen;
			utflen = UTF8_putc(utfbuf, 6, c);
			for(i = 0; i < utflen; i++) {
				len = do_esc_char(utfbuf[i], flags | orflags, quotes, io_ch, arg);
				if(len < 0) return -1;
				outlen += len;
			}
		} else {
			len = do_esc_char(c, flags | orflags, quotes, io_ch, arg);
			if(len < 0) return -1;
			outlen += len;
		}
	}
	return outlen;
}
['static int do_buf(unsigned char *buf, int buflen,\n\t\t\tint type, unsigned char flags, char *quotes, char_io *io_ch, void *arg)\n{\n\tint i, outlen, len;\n\tunsigned char orflags, *p, *q;\n\tunsigned long c;\n\tp = buf;\n\tq = buf + buflen;\n\toutlen = 0;\n\twhile(p != q) {\n\t\tif(p == buf) orflags = CHARTYPE_FIRST_ESC_2253;\n\t\telse orflags = 0;\n\t\tswitch(type & BUF_TYPE_WIDTH_MASK) {\n\t\t\tcase 4:\n\t\t\tc = ((unsigned long)*p++) << 24;\n\t\t\tc |= ((unsigned long)*p++) << 16;\n\t\t\tc |= ((unsigned long)*p++) << 8;\n\t\t\tc |= *p++;\n\t\t\tbreak;\n\t\t\tcase 2:\n\t\t\tc = ((unsigned long)*p++) << 8;\n\t\t\tc |= *p++;\n\t\t\tbreak;\n\t\t\tcase 1:\n\t\t\tc = *p++;\n\t\t\tbreak;\n\t\t\tcase 0:\n\t\t\ti = UTF8_getc(p, buflen, &c);\n\t\t\tif(i < 0) return -1;\n\t\t\tp += i;\n\t\t\tbreak;\n\t\t}\n\t\tif (p == q) orflags = CHARTYPE_LAST_ESC_2253;\n\t\tif(type & BUF_TYPE_CONVUTF8) {\n\t\t\tunsigned char utfbuf[6];\n\t\t\tint utflen;\n\t\t\tutflen = UTF8_putc(utfbuf, 6, c);\n\t\t\tfor(i = 0; i < utflen; i++) {\n\t\t\t\tlen = do_esc_char(utfbuf[i], flags | orflags, quotes, io_ch, arg);\n\t\t\t\tif(len < 0) return -1;\n\t\t\t\toutlen += len;\n\t\t\t}\n\t\t} else {\n\t\t\tlen = do_esc_char(c, flags | orflags, quotes, io_ch, arg);\n\t\t\tif(len < 0) return -1;\n\t\t\toutlen += len;\n\t\t}\n\t}\n\treturn outlen;\n}']