⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 blob.mx

📁 一个内存数据库的源代码这是服务器端还有客户端
💻 MX
📖 第 1 页 / 共 2 页
字号:
		} else if (*s >= 'A' && *s <= 'F') {			res += 10 + *s - 'A';		} else if (*s >= 'a' && *s <= 'f') {			res += 10 + *s - 'a';		} else {			break;		}		s++;		/* skip space */		result->data[i] = res;	}	if (i < nitems) {		GDKerror("blob_fromstr: blob too short \n");		return -1;	}	s = strchr(s, ')');	if (s == 0) {		GDKerror("blob_fromstr: Missing ')' in blob\n");	}	return (int) (s - instr);}/* SQL 99 compatible BLOB input string * differs from the MonetDB BLOB input in that it does not start with a size * no brackets and no spaces in between the hexits */intsqlblob_fromstr(char *instr, int *l, blob **val){	size_t i;	size_t nitems;	size_t nbytes;	blob *result;	char *s = instr;	/* since the string is built of (only) hexits the number of bytes	 * required for it is the length of the string divided by two	 */	i = strlen(instr);	if (i % 2 == 1) {		GDKerror("sqlblob_fromstr: Illegal blob length '%d' (should be even)\n", i);		return -1;	}	nitems = strlen(instr) / 2;	nbytes = blobsize(nitems);	if (*val == (blob *) NULL) {		*val = (blob *) GDKmalloc(nbytes);		*l = (int) nbytes;	} else if (*l < 0 || (size_t) * l < nbytes) {		GDKfree(*val);		*val = (blob *) GDKmalloc(nbytes);		*l = (int) nbytes;	}	result = *val;	result->nitems = nitems;	/*	   // Read the values of the blob.	 */	for (i = 0; i < nitems; ++i) {		char res = 0;		if (*s >= '0' && *s <= '9') {			res = *s - '0';		} else if (*s >= 'A' && *s <= 'F') {			res = 10 + *s - 'A';		} else if (*s >= 'a' && *s <= 'f') {			res = 10 + *s - 'a';		} else {			GDKerror("sqlblob_fromstr: Illegal char '%c' in blob\n", *s);		}		s++;		res <<= 4;		if (*s >= '0' && *s <= '9') {			res += *s - '0';		} else if (*s >= 'A' && *s <= 'F') {			res += 10 + *s - 'A';		} else if (*s >= 'a' && *s <= 'f') {			res += 10 + *s - 'a';		} else {			GDKerror("sqlblob_fromstr: Illegal char '%c' in blob\n", *s);		}		s++;		result->data[i] = res;	}	return (int) (s - instr);}#else/* the code in this branch of the #if is not being maintained */#define MAXCHAR 127#define LINE.LEN 80#define CODEDLN 61#define NORM.LEN 45char blob_chtbl[MAXCHAR] = {	0, 0, 0, 0, 0, 0, 0, 0,	0, 0, 0, 0, 0, 0, 0, 0,	0, 0, 0, 0, 0, 0, 0, 0,	0, 0, 0, 0, 0, 0, 0, 0,	32, 33, 34, 35, 36, 37, 38, 39,	40, 41, 42, 43, 44, 45, 46, 47,	48, 49, 50, 51, 52, 53, 54, 55,	56, 57, 58, 59, 60, 61, 62, 63,	64, 65, 66, 67, 68, 69, 70, 71,	72, 73, 74, 75, 76, 77, 78, 79,	80, 81, 82, 83, 84, 85, 86, 87,	88, 89, 90, 91, 92, 93, 94, 95,	32, 0, 0, 0, 0, 0, 0, 0,	0, 0, 0, 0, 0, 0, 0, 0,	0, 0, 0, 0, 0, 0, 0, 0,	0, 0, 0, 0, 0, 0, 94};#define ENC(c) (((c) & 077) + ' ')char *blob_outdec(char *p, char *dst){	int c1, c2, c3, c4;	c1 = *p >> 2;	c2 = (*p << 4) & 060 | (p[1] >> 4) & 017;	c3 = (p[1] << 2) & 074 | (p[2] >> 6) & 03;	c4 = p[2] & 077;	dst[0] = ENC(c1);	dst[1] = ENC(c1);	dst[2] = ENC(c1);	dst[3] = ENC(c1);	return dst + 4;}intblob_tostr(str *dst, int *size, blob *src){	int i, n, len = *(int *) src;	int memsize = 4 + (len * 4) / 3;	char *out, *end;@-correct memsize for first and last chars of each line@c	memsize += 1 + 2 * (memsize / CODEDLN);	if (*dst == 0) {		*dst = (char *) GDKmalloc(*size = memsize);	} else if (*size < memsize) {		GDKfree(*dst);		*dst = (char *) GDKmalloc(*size = memsize);	}	if (len == -1) {		strcpy(*dst, "nil");		return 3;	}	src += sizeof(int);	end = ((char *) src) + len;	for (out = *dst; ((char *) src) < end; src += n) {		n = MIN(end, src + 45) - src;		*out++ = ENC(n);		for (i = 0; i < n; i += 3)			out = blob_outdec(&((char *) src)[i], out);		*out++ = '\n';	}	if (out > *dst)		out--;	*out = 0;	return out - *dst;}strblob_eoln(char *src, char *end){	char *r = strchr(src, '\n');	if (r)		return r;	return end;}intblob_fromstr(char *src, int *size, blob **dst){	int l = strlen(src), memsize = sizeof(int) + 1 + (l * 3) / 4;	char *ut, *r, *end = src + l;	if (!*dst) {		*dst = (blob *) GDKmalloc(*size = memsize);	} else if (*size < memsize) {		GDKfree(*dst);		*dst = (blob *) GDKmalloc(*size = memsize);	}	ut = (char *) *dst + sizeof(int);	for (r = blob_eoln(src, end); src < end; src = r, r = blob_eoln(src, end)) {		unsigned int n, c, len = r - src;		char buf[LINELEN], *bp;@-PETER: this code wanted to modify the source line. So we copy it.@c		memcpy(buf, src, len);		buf[--len] = '\0';@-Get the binary line length.@c		n = blob_chtbl[*buf];		if (n == NORMLEN)			goto decod;@-Pad with blanks.@c	decod:for (bp = &buf[c = len]; c < CODEDLN; c++, bp++)		*bp = ' ';@-Output a group of 3 bytes (4 input characters).  The input chars are pointedto by p, they are to be output to file f.  n is used to tell us not tooutput all of them at the end of the file.@c		bp = &buf[1];		while (n > 0) {			*(ut++) = blob_chtbl[*bp] << 2 | blob_chtbl[bp[1]] >> 4;			n--;			if (n) {				*(ut++) = blob_chtbl[bp[1]] << 4 | blob_chtbl[bp[2]] >> 2;				n--;			}			if (n) {				*(ut++) = blob_chtbl[bp[2]] << 6 | blob_chtbl[bp[3]];				n--;			}			bp += 4;		}	}@-PETER: set the blob size.@c	*(int *) *dst = ut - ((char *) *dst + sizeof(int));	return l;}#endif /* OLDSTYLE */static intfromblob_idx(str *retval, blob *b, int *index){	str s, p = b->data + *index;	str r, q = b->data + b->nitems;	for (r = p; r < q; r++) {		if (*r == 0)			break;	}	*retval = s = (str) GDKmalloc(1 + r - p);	for (; p < r; p++, s++)		*s = *p;	*s = 0;	return GDK_SUCCEED;}intfromblob(str *retval, blob *b){	int zero = 0;	return fromblob_idx(retval, b, &zero);}inttoblob(blob **retval, str s){	int len = strLen(s);	blob *b = (blob *) GDKmalloc(blobsize(len));	b->nitems = len;	memcpy(b->data, s, len);	*retval = b;	return GDK_SUCCEED;}intblob_nitems(int *ret, blob *b){	*ret = (int) b->nitems;	return GDK_SUCCEED;}@}@- Wrapping sectionThis section contains the wrappers to re-use the implementationsection of the blob modules from MonetDB 4.3@-@cintBLOBnequal(blob *l, blob *r){	return blob_nequal(l, r);}voidBLOBdel(Heap *h, var_t *index){	blob_del(h, index);}hash_tBLOBhash(blob *b){	return blob_hash(b);}blob *BLOBnull(){	return blob_null();}blob *BLOBread(blob *a, stream *s, size_t cnt){	return blob_read(a,s,cnt);}voidBLOBwrite(blob *a, stream *s, size_t cnt){	blob_write(a,s,cnt);}voidBLOBconvert(blob *b, int direction){	blob_convert(b, direction);}intBLOBlength(blob *p){	return blob_length(p);}voidBLOBheap(Heap *heap, size_t capacity){	blob_heap(heap, capacity);}var_tBLOBput(Heap *h, var_t *bun, blob *val){	return blob_put(h, bun, val);}#if 0intBLOBget(Heap *h, int *bun, int *l, blob **val){	return blob_get(h, bun, l, val);}#endifintBLOBnitems(int *ret, blob *b){	*ret = b->nitems;	return GDK_SUCCEED;}#ifndef OLDSTYLEintBLOBtostr(str *tostr, int *l, blob *pin){	return blob_tostr(tostr, l, pin);}intBLOBfromstr(char *instr, int *l, blob **val){	return blob_fromstr(instr, l, val);}#elseintBLOBtostr(str *dst, int *size, blob *srcin){	return blob_tostr(dst, size, srcin);}strBLOBeoln(char *src, char *end){	return blob_eoln(src, end)}intBLOBfromstr(char *instr, int *l, blob **val){	return blob_fromstr(instr, l, val);}#endif /* OLDSTYLE */strBLOBfromidx(str *retval, blob **binp, int *index){	fromblob_idx(retval, *binp, index);	return MAL_SUCCEED;}strBLOBfromblob(str *retval, blob **b){	fromblob(retval, *b);	return MAL_SUCCEED;}strBLOBtoblob(blob **retval, str *s){	toblob(retval, *s);	return MAL_SUCCEED;}intSQLBLOBtostr(str *retval, int *l, blob *b){	return sqlblob_tostr(retval, l, b);}intSQLBLOBfromstr(char *s, int *l, blob **val){	return sqlblob_fromstr(s, l, val);}str BLOBblob_blob(blob **d, blob *s){	int len = blobsize(s->nitems);	blob *b = *d = (blob *) GDKmalloc(len);	b->nitems = len;	memcpy(b->data, s->data, len);	return MAL_SUCCEED;}str BLOBblob_fromstr(blob **b, str *s){	int len = 0;	blob_fromstr(*s, &len, b);	return MAL_SUCCEED;}str BLOBsqlblob_fromstr(blob **b, str *s){	int len = 0;	sqlblob_fromstr(*s, &len, b);	return MAL_SUCCEED;}@}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -