Esempio n. 1
0
 Value * CDExpNotEqual::sql(const char * prefix,const char * suffix){
     InvokeTickBegin
     hbuffer_t buf = buffer_alloc(128, 128);
     Value * v = NULL;
     
     buffer_append_str(buf, "(");
     
     v = _left->sql(prefix, suffix);
     
     if(v){
         buffer_append_str(buf, v->stringValue());
     }
     
     buffer_append_str(buf, " <= ");
     
     v = _right->sql(prefix, suffix);
     
     if(v){
         buffer_append_str(buf, v->stringValue());
     }
     
     
     buffer_append_str(buf, ")");
     
     
     v = (Value *)(new Value(buffer_to_str(buf)))->autorelease();
     
     buffer_dealloc(buf);
     
     return v;
 }
Esempio n. 2
0
/**
 * Generate list of all values as bracketed list.
 * This string might be fed into cfg parser.
 *
 * Caller has to deallocate resulting output buffer.
 */
isc_result_t
fwd_print_bracketed_values_buf(isc_mem_t *mctx, ldap_valuelist_t *values,
			      isc_buffer_t **string) {
	isc_result_t result;
	ldap_value_t *value;
	const char prefix[] = "{ ";
	const char suffix[] = "}";
	isc_buffer_t tmp_buf; /* hack: only the base buffer is allocated */

	REQUIRE(string != NULL && *string == NULL);

	isc_buffer_initnull(&tmp_buf);
	tmp_buf.mctx = mctx;

	buffer_append_str(&tmp_buf, prefix, 2);
	for (value = HEAD(*values);
	     value != NULL && value->value != NULL;
	     value = NEXT(value, link)) {
		buffer_append_str(&tmp_buf, value->value, strlen(value->value));
		buffer_append_str(&tmp_buf, "; ", 2);
	}
	buffer_append_str(&tmp_buf, suffix, 2);

	/* create and copy string from tmp to output buffer */
	CHECK(isc_buffer_allocate(mctx, string, tmp_buf.used));
	isc_buffer_putmem(*string, isc_buffer_base(&tmp_buf), tmp_buf.used);

cleanup:
	if (tmp_buf.base != NULL)
		isc_mem_put(mctx, tmp_buf.base, tmp_buf.length);
	return result;
}
Esempio n. 3
0
void hdata_xml_value_decode(hcchar * value,hbuffer_t buffer,InvokeTickDeclare){
	hchar * p = (hchar *)value;
	while(*p != '\0'){
		
		if(p[0] == '&' && p[1] == 'n' && p[2] == 'b' && p[3] == 's' && p[4] == 'p' && p[5] == ';'){
			buffer_append_str(buffer, " ");
			p+= 5;
		}
		else if(p[0] == '&' && p[1] == 'l' && p[2] == 't' && p[3] == ';'){
			buffer_append_str(buffer, "<");
			p+= 3;
		}
		else if(p[0] == '&' && p[1] == 'g' && p[2] == 't' && p[3] == ';'){
			buffer_append_str(buffer, ">");
			p+= 3;
		}
		else if(p[0] == '&' && p[1] == 'a' && p[2] == 'm' && p[3] == 'p' && p[4] == ';' ){
			buffer_append_str(buffer, "&");
			p+= 4;
		}
		else {
			buffer_append(buffer,p,1);
		}
		p ++;
	}
}
Esempio n. 4
0
static void get_base() {

	struct buffer buf = BUFFER_INIT;
	char *ptr = getenv("HOME");

	if (!ptr)
		ptr = ".";
	buffer_append_str(&buf, ptr);
	buffer_append_str(&buf, "/.dlight");

	base = buffer_cstr_release(&buf);
	atexit(free_base);
}
Esempio n. 5
0
void buffer_vprintf(buffer *b, const char *format, va_list ap)
{
    char c;
    const char *s;
    buffer *buf;
    
    while (*format) {
        if (*format == '%') {
            format++;
            switch (*format) {
                case 'c':
                    c = va_arg(ap, int);
                    buffer_append_char(b, c);
                    break;
                case 's':
                    s = va_arg(ap, const char *);
                    buffer_append_str(b, s);
                    break;
                case 'b':
                    buf = va_arg(ap, buffer *);
                    buffer_append_buffer(b, buf);
                    break;
                default:
                    buffer_append_char(b, '%');
                    break;
            }
        } else
Esempio n. 6
0
EXTERN buffer alloc_buffer( const char *init ) {
	buffer b = (buffer)malloc(sizeof(struct _buffer));
	b->totlen = 0;
	b->blen = 16;
	b->data = NULL;
	if( init )
		buffer_append_str(b,init);
	return b;
}
Esempio n. 7
0
 Value * Bundle::getFilePathV(const char * format,va_list va){
     InvokeTickBegin
     hbuffer_t path = buffer_alloc(MAX_PATH, 128);
     Value * v = NULL;
     buffer_append_str(path,_bundlePath.c_str());
     if(buffer_length(path) >0 && * (buffer_data(path) + buffer_length(path) -1) != PATH_SPLIT){
         buffer_append_str(path, "/");
     }
     buffer_append_format_va_list(path, format, va);
     if(_parent){
         v = _parent->getFilePath(buffer_to_str(path));
     }
     else{
         v = Value::newValue(buffer_to_str(path));
     }
     buffer_dealloc(path);
     return v;
 }
Esempio n. 8
0
buffer *buffer_new(const char *s)
{
    buffer *b = (buffer *) malloc(sizeof(buffer));
    
    b->first_block = NULL;
    buffer_reset(b);
    
    buffer_append_str(b, s);
    
    return b;
}
Esempio n. 9
0
void hdata_xml_value_encode(hcchar * value,hbuffer_t buffer,InvokeTickDeclare){
	hchar * p = (hchar *)value;
	while(*p != '\0'){
		
		if(*p == ' '){
			buffer_append_str(buffer, "&nbsp;");
		}
		else if(*p == '<'){
			buffer_append_str(buffer, "&lt;");
		}
		else if(*p == '<'){
			buffer_append_str(buffer, "&gt;");
		}
		else if(*p == '&'){
			buffer_append_str(buffer, "&amp;");
		}
		else {
			buffer_append(buffer,p,1);
		}
		p ++;
	}
}
Esempio n. 10
0
File: hdata.c Progetto: hailongz/c
static void _hdata_json_write_object_echo(hdata_t data,hcchar *key,hdata_t value,hany dest,InvokeTickDeclare){
	_hdata_write_object_each_arg_t *arg = (_hdata_write_object_each_arg_t *)dest;
	if(arg->pattern){
		_hdata_json_write_level(arg->buffer,arg->level,InvokeTickArg);
	}
	
	if(arg->first && arg->pattern){
		buffer_append_str(arg->buffer, "\n");
		_hdata_json_write_level(arg->buffer,arg->level,InvokeTickArg);
	}
	if(!arg->first){
		buffer_append_str(arg->buffer, ",");
	}
	hdata_json_write_string((hcchar *)key,arg->buffer,InvokeTickArg);
	buffer_append_str(arg->buffer, ":");
	_hdata_write(arg->data_class,(hdata_t)value,arg->buffer,arg->pattern,arg->level,InvokeTickArg);
	if(arg->pattern){
		buffer_append_str(arg->buffer, "\n");
	}
	
	if(arg->first){
		arg->first = hbool_false;
	}
}
Esempio n. 11
0
static vmClassMetaOffset vmBinaryUniqueKey(vmBinary * binary,hcchar * key,hbool isNilString,InvokeTickDeclare){
    hint32 i;
    vmClassMetaOffset offset = 0;
    hchar * p = buffer_data(binary->uniqueKeys);
    hchar e = 0;
    
    if(key == NULL || (!isNilString && *key == 0)){
        return 0;
    }
    
    for(i=0;i<binary->uniqueKeyCount;i++){
        if(mem_strcmp(p, key) ==0){
            return (vmClassMetaOffset)(p - buffer_data(binary->uniqueKeys) + UNIQUE_KEY_OFFSET);
        }
        p = p + strlen(p) +1;
    }
    offset = buffer_length(binary->uniqueKeys) + UNIQUE_KEY_OFFSET;
    buffer_append_str(binary->uniqueKeys, key);
    buffer_append(binary->uniqueKeys,&e,1);
    binary->uniqueKeyCount ++;
    return offset;
}
Esempio n. 12
0
File: hdata.c Progetto: hailongz/c
static void hdata_json_write_string(hcchar * str,hbuffer_t buffer,InvokeTickDeclare){
	hchar *p = (hchar *)str;
	buffer_append_str(buffer,"\"");
	while(*p != '\0'){
		if(*p == '\n'){
			buffer_append_str(buffer, "\\\n");
		}
		else if(*p == '\r'){
			buffer_append_str(buffer, "\\\r");
		}
		else if(*p == '\t'){
			buffer_append_str(buffer, "\\\t");
		}
		else if(*p == '\"'){
			buffer_append_str(buffer, "\\\"");
		}
		else{
			buffer_append(buffer,p,1);
		}
		p++;
	}
	buffer_append_str(buffer,"\"");
}
Esempio n. 13
0
File: hjson.c Progetto: hailongz/c
hany hjson_decode(hjson_t * json,hcchar * str,InvokeTickDeclare){
    hany data = NULL;
	hchar * p=(hchar *)str;
	hlist_t data_stack = list_alloc(20,20);
	hlist_t state_stack =list_alloc(20,20);
	hbuffer_t value_buffer = buffer_alloc(128,  256);
	hbuffer_t name_buffer = buffer_alloc(128,  256);
    hbuffer_t base64_buffer= buffer_alloc(1024,1024);
	hintptr s;
    hwchar wchar;
    hint32 iwchar;
    hchar wchbuf[8];
	//hint32 object_level=0;
	//hint32 array_level =0;
	list_add(state_stack, (hany) 0);
	
	
	while (p && *p != '\0') {
		s = (hintptr)list_last(state_stack);
		if(s == 0x00){
			if(SPACE_CHAR(*p)){
			}
			else if( *p == '{'){
				list_add(state_stack, (hany)0x10);
				data = (*json->object_new)(json,InvokeTickArg);
				list_add(data_stack, data);
				list_add(data_stack, data);
				//hlog("object begin %ld\n",object_level++);
			}
			else if( *p == '['){
				list_add(state_stack, (hany)0x20);
				data = (*json->array_new)(json,InvokeTickArg);
				list_add(data_stack, data);
				list_add(data_stack, data);
				//hlog("array begin %ld\n",array_level++);
			}
			else if( *p == '\"'){
				list_add(state_stack, (hany)0x01);
				list_add(state_stack, (hany)0x30);
			}
			else if( TRUE_EQUAL(p)){
				data = (*json->booleanValue)(json,hbool_true,InvokeTickArg);
				list_add(data_stack, data);
				break;
			}
			else if( FALSE_EQUAL(p)){
				data = (*json->booleanValue)(json,hbool_false,InvokeTickArg);
				list_add(data_stack, data);
				break;
			}
			else if( NULL_EQUAL(p)){
				data = (*json->nullValue)(json,InvokeTickArg);
				list_add(data_stack, data);
				break;
			}
			else{
				list_add(state_stack, (hany)0x02);
				list_add(state_stack, (hany)0x40);
				continue;
			}
		}
		else if(s == 0x01){
			// string value end
			data = (*json->stringValue)(json,buffer_to_str(value_buffer),base64_buffer,InvokeTickArg);
			list_add(data_stack, data);
			break;
		}
		else if(s == 0x02){
			// number value end
			data = (*json->numberValue)(json,buffer_to_str(value_buffer),InvokeTickArg);
			list_add(data_stack, data);
			break;
		}
		else if(s ==0x10) {
			// object
			if(SPACE_CHAR(*p) || *p ==','){
			}
			else if(*p == '\"'){
				list_add(state_stack, (hany)0x11);
			}
			else if(*p == ':'){
				list_add(state_stack, (hany)0x12);
			}
			else if(*p == '}'){
				list_pop(state_stack);
				list_pop(data_stack);
				buffer_clear(name_buffer);
				buffer_clear(value_buffer);
				//hlog("object end %ld\n",--object_level);
                
			}
			else{
				buffer_append(name_buffer,p,1);
				list_add(state_stack, (hany)0x11);
			}
		}
		else if(s == 0x11){
			// object value key
			if(*p == '\\' && p[1] == '"'){
				p++;
				buffer_append(name_buffer, p, 1);
			}
			else if( *p == '"'){
				list_pop(state_stack);
			}
			else if( *p == ':'){
				list_pop(state_stack);
				list_add(state_stack, (hany)0x12);
			}
			else{
				buffer_append(name_buffer, p, 1);
			}
		}
		else if(s == 0x12){
			// object value
			if(SPACE_CHAR(*p)){
			}
			else if( *p == '{'){
				list_pop(state_stack);
				list_add(state_stack, (hany)0x10);
				data = (*json->object_new)(json,InvokeTickArg);
                (*json->object_put)(json,list_last(data_stack),buffer_to_str(name_buffer),data,InvokeTickArg);
				list_add(data_stack, data);
				buffer_clear(name_buffer);
				buffer_clear(value_buffer);
				//hlog("object begin %ld\n",object_level++);
                
			}
			else if( *p == '['){
				list_pop(state_stack);
				list_add(state_stack, (hany)0x20);
				data = (*json->array_new)(json,InvokeTickArg);
				(*json->object_put)(json,list_last(data_stack),buffer_to_str(name_buffer),data,InvokeTickArg);
				list_add(data_stack, data);
				buffer_clear(name_buffer);
				buffer_clear(value_buffer);
				//hlog("array begin %ld\n",array_level++);
			}
			else if( *p =='"'){
				// string value
				list_pop(state_stack);
				list_add(state_stack, (hany)0x13);
				list_add(state_stack, (hany)0x30);
			}
			else if( TRUE_EQUAL(p)){
				list_pop(state_stack);
                
                data = (*json->booleanValue)(json,hbool_true,InvokeTickArg);
                (*json->object_put)(json,list_last(data_stack),buffer_to_str(name_buffer),data,InvokeTickArg);
                
				buffer_clear(name_buffer);
				buffer_clear(value_buffer);
				p += 3;
			}
			else if( FALSE_EQUAL(p)){
				list_pop(state_stack);
                data = (*json->booleanValue)(json,hbool_false,InvokeTickArg);
                (*json->object_put)(json,list_last(data_stack),buffer_to_str(name_buffer),data,InvokeTickArg);
                
				buffer_clear(name_buffer);
				buffer_clear(value_buffer);
				p += 4;
			}
			else if( NULL_EQUAL(p)){
				list_pop(state_stack);
                data = (*json->nullValue)(json,InvokeTickArg);
                (*json->object_put)(json,list_last(data_stack),buffer_to_str(name_buffer),data,InvokeTickArg);
                
				buffer_clear(name_buffer);
				buffer_clear(value_buffer);
				p += 3;
			}
			else {
				list_pop(state_stack);
				list_add(state_stack, (hany)0x14);
				list_add(state_stack, (hany)0x40);
				continue;
			}
		}
		else if(s == 0x13){
			// string value end
            data = (*json->stringValue)(json,buffer_to_str(value_buffer),base64_buffer,InvokeTickArg);
            (*json->object_put)(json,list_last(data_stack),buffer_to_str(name_buffer),data,InvokeTickArg);
			buffer_clear(name_buffer);
			buffer_clear(value_buffer);
			list_pop(state_stack);
			continue;
		}
		else if(s == 0x14){
			// number value end
			data = (*json->numberValue)(json,buffer_to_str(value_buffer),InvokeTickArg);
            (*json->object_put)(json,list_last(data_stack),buffer_to_str(name_buffer),data,InvokeTickArg);
			buffer_clear(name_buffer);
			buffer_clear(value_buffer);
			list_pop(state_stack);
			continue;
		}
		else if(s ==0x20){
			// array value
			if(SPACE_CHAR(*p) || *p ==','){
			}
			else if( *p ==']'){
				list_pop(state_stack);
				list_pop(data_stack);
				buffer_clear(name_buffer);
				buffer_clear(value_buffer);
				//hlog("array end %ld\n",--array_level);
			}
			else if( *p == '{'){
				list_add(state_stack, (hany)0x23);
				list_add(state_stack, (hany)0x10);
				data = (*json->object_new)(json,InvokeTickArg);
                (*json->array_add)(json,list_last(data_stack),data,InvokeTickArg);
				list_add(data_stack, data);
				//hlog("object begin %ld\n",object_level++);
                
			}
			else if( *p == '['){
				list_add(state_stack, (hany)0x23);
				list_add(state_stack, (hany)0x20);
                data = (*json->array_new)(json,InvokeTickArg);
				(*json->array_add)(json,list_last(data_stack),data,InvokeTickArg);
				list_add(data_stack, data);
				//hlog("array begin %ld\n",array_level++);
			}
			else if( *p =='"'){
				// string value
				list_add(state_stack, (hany)0x21);
				list_add(state_stack, (hany)0x30);
			}
			else if( TRUE_EQUAL(p)){
                data = (*json->booleanValue)(json,hbool_true,InvokeTickArg);
				(*json->array_add)(json,list_last(data_stack),data,InvokeTickArg);
				p += 3;
			}
			else if( FALSE_EQUAL(p)){
                data = (*json->booleanValue)(json,hbool_false,InvokeTickArg);
				(*json->array_add)(json,list_last(data_stack),data,InvokeTickArg);
				p += 4;
			}
			else if( NULL_EQUAL(p)){
                data = (*json->nullValue)(json,InvokeTickArg);
				(*json->array_add)(json,list_last(data_stack),data,InvokeTickArg);
				p += 3;
			}
			else {
				list_add(state_stack, (hany)0x22);
				list_add(state_stack, (hany)0x40);
				continue;
			}
		}
		else if(s == 0x21){
			// string value end
            
            data = (*json->stringValue)(json,buffer_to_str(value_buffer),base64_buffer,InvokeTickArg);
            (*json->array_add)(json,list_last(data_stack),data,InvokeTickArg);
            
			buffer_clear(name_buffer);
			buffer_clear(value_buffer);
			list_pop(state_stack);
			continue;
		}
		else if(s == 0x22){
			// number value end
            data = (*json->numberValue)(json,buffer_to_str(value_buffer),InvokeTickArg);
            (*json->array_add)(json,list_last(data_stack),data,InvokeTickArg);
            
			buffer_clear(name_buffer);
			buffer_clear(value_buffer);
			list_pop(state_stack);
			continue;
		}
		else if(s == 0x23){
			// object || array value end
			/*
             data = list_pop(data_stack);
             if(data ){
             hdata_array_add((hdata_t)list_last(data_stack), data);
             }
			 */
			buffer_clear(name_buffer);
			buffer_clear(value_buffer);
			list_pop(state_stack);
			continue;
		}
		else if(s ==0x30){
			// string value
			if( *p == '\\'){
				if( p[1] == 'n'){
					buffer_append_str(value_buffer,"\n");
				}
				else if( p[1] == 'r'){
					buffer_append_str(value_buffer,"\r");
				}
				else if( p[1] == 't'){
					buffer_append_str(value_buffer,"\t");
				}
				else if( p[1] == '\\'){
					buffer_append_str(value_buffer,"\\");
				}
				else if( p[1] == '\"'){
					buffer_append_str(value_buffer,"\"");
				}
				else if( p[1] == '\''){
					buffer_append_str(value_buffer,"\'");
				}
                else if( p[1] == 'u' ||  p[1] == 'U'){
                    iwchar = 0;
					sscanf(p + 2, "%04x",&iwchar);
                    wchar = iwchar;
                    strcpy(wchbuf, "");
                    buffer_append(value_buffer, wchbuf,wstr_to_str(&wchar, 1, wchbuf));
                    p+= 4;
				}
				else{
					buffer_append(value_buffer,p+1,1);
				}
				p++;
			}
			else if( *p == '\"'){
				list_pop(state_stack);
			}
			else{
				buffer_append(value_buffer,p,1);
			}
		}
		else if(s == 0x40){
			// number value
			if(NUMBER_CHAR(*p)){
				buffer_append(value_buffer, p, 1);
			}
			else{
				list_pop(state_stack);
				continue;
			}
		}
		
		p++;
	}
	
	while((data = list_pop(data_stack))){
        if(list_count(data_stack) ==0){
            break;
        }
        (*json->object_dealloc)(json,data,InvokeTickArg);
	}
	
	buffer_dealloc(value_buffer);
	buffer_dealloc(name_buffer);
    buffer_dealloc(base64_buffer);
	list_dealloc(data_stack);
	list_dealloc(state_stack);
    
    return data;
}
Esempio n. 14
0
hdata_t hdata_xml_alloc(hcchar * xml_str,InvokeTickDeclare){
	hdata_t data = NULL,data_temp;
	hchar * p=(hchar *)xml_str;
	hstack_t data_stack = stack_alloc();
	hstack_t state_stack = stack_alloc();
	hbuffer_t tag_name_buffer = buffer_alloc(128,  256);
	hbuffer_t content_buffer = buffer_alloc(1024,  1024);
	hbuffer_t attr_name_buffer =buffer_alloc(128,  256);
	hbuffer_t attr_value_buffer = buffer_alloc(128,  256);
	hintptr s;
	hchar str_begin = 0;
	stack_push(state_stack, (hany) 0);
	stack_push(data_stack,hdata_array_alloc( 20, 20));
	
	while (*p != '\0') {
		s = (hintptr)stack_peek(state_stack);
		if(s == 0x00){
			if(SPACE_CHAR(*p)){
			}
			else if( *p == '<' && p[1] == '?'){
				stack_push(state_stack, (hany)0x10);
				p++;
			}
			else if( *p == '<' && p[1] == '!'){
				stack_push(state_stack, (hany)0x11);
				p++;
			}
			else if( *p == '<' && p[1] == '/'){
				data_temp = stack_pop(data_stack);
				data = stack_pop(data_stack);
				if( hdata_array_size(&hdata_class, data_temp) ==0){
					hdata_object_remove(data, kCHILDS);
				}
				if(buffer_length(content_buffer) >0){
					hdata_object_put(data, kVALUE, hdata_xml_value_parse(buffer_to_str(content_buffer),InvokeTickArg));
					buffer_clear(content_buffer);
				}
				while( *p != '\0' && *p != '>'){
					p ++;
				}
				if(*p == '\0'){
					break;
				}
			}
			else if( *p == '<'){
				buffer_clear(content_buffer);
				buffer_clear(tag_name_buffer);
				data = hdata_object_alloc();
				hdata_array_add(stack_peek(data_stack), data);
				stack_push(data_stack, data);
				stack_push(state_stack, (hany)0x20);
			}
			else{
				buffer_append(content_buffer,p,1);
			}
		}
		else if(s ==0x10){
			// <? ?>
			if( p[0] == '?' && p[1] == '>'){
				p++;
				stack_pop(state_stack);
			}
		}
		else if(s == 0x11){
			// <!
			if(p[0] == '>' ){
				stack_pop(state_stack);
			}
		}
		else if(s == 0x20){
			// <tagname 
			if(SPACE_CHAR(*p)){
				hdata_object_put((hdata_t)stack_peek(data_stack), kTAGNAME, hdata_string_alloc( buffer_to_str(tag_name_buffer)));
				buffer_clear(tag_name_buffer);
				stack_pop(state_stack);
				stack_push(state_stack, (hany)0x21);
			}
			else if( *p == '/' && p[1] =='>'){
				hdata_object_put((hdata_t)stack_peek(data_stack), kTAGNAME, hdata_string_alloc( buffer_to_str(tag_name_buffer)));
				buffer_clear(tag_name_buffer);
				stack_pop(data_stack);
				stack_pop(state_stack);
				p++;
			}
			else if( *p == '>'){
				hdata_object_put((hdata_t)stack_peek(data_stack), kTAGNAME, hdata_string_alloc( buffer_to_str(tag_name_buffer)));
				buffer_clear(tag_name_buffer);
				data = hdata_array_alloc( 20, 20);
				hdata_object_put(stack_peek(data_stack), kCHILDS, data);
				stack_push(data_stack, data);
				stack_pop(state_stack);
			}
			else{
				buffer_append(tag_name_buffer, p, 1);
			}
		}
		else if(s == 0x21){
			// <tagname attrname=
			if(SPACE_CHAR(*p)){
			}
			else if( *p == '/' && p[1] =='>'){
				stack_pop(data_stack);
				stack_pop(state_stack);
				p++;
			}
			else if( *p == '>'){
				data = hdata_array_alloc( 20, 20);
				hdata_object_put(stack_peek(data_stack), kCHILDS, data);
				stack_push(data_stack, data);
				stack_pop(state_stack);
			}
			else if( *p == '='){
				stack_push(state_stack, (hany)0x22);
			}
			else {
				buffer_append(attr_name_buffer,p,1);
			}
		}
		else if(s == 0x22){
			// <tagname attrname=valuebegin
			if(SPACE_CHAR(*p)){
			}
			else if( *p == '\''){
				str_begin = '\'';
				stack_pop(state_stack);
				stack_push(state_stack, (hany)0x23);
			}
			else if( *p == '"'){
				str_begin = '"';
				stack_pop(state_stack);
				stack_push(state_stack, (hany)0x23);
			}
			else {
				str_begin = 0;
				stack_pop(state_stack);
				stack_push(state_stack, (hany)0x23);
				buffer_append(attr_value_buffer, p, 1);
			}

		}
		else if( s == 0x23){
			// <tagname attrname=value
			if(str_begin ==0){
				if(SPACE_CHAR(*p)){
					hdata_object_put((hdata_t)stack_peek(data_stack),buffer_to_str(attr_name_buffer),hdata_xml_value_parse(buffer_to_str(attr_value_buffer),InvokeTickArg));
					buffer_clear(attr_name_buffer);
					buffer_append_str(attr_name_buffer, "@");
					buffer_clear(attr_value_buffer);
					stack_pop(state_stack);
				}
				else{
					buffer_append(attr_value_buffer, p, 1);
				}
			}
			else {
				if( p[0] == '\\' ){
					if(p[1] == '\\'){
						buffer_append_str(attr_value_buffer, "\\");
					}
					else if(p[1] == 'n'){
						buffer_append_str(attr_value_buffer, "\n");
					}
					else if(p[1] == 'r'){
						buffer_append_str(attr_value_buffer, "\r");
					}
					else if(p[1] == 't'){
						buffer_append_str(attr_value_buffer, "\t");
					}
					else if(p[1] == '"'){
						buffer_append_str(attr_value_buffer, "\"");
					}
					else if(p[1] == '\''){
						buffer_append_str(attr_value_buffer, "\'");
					}
					else{
						buffer_append(attr_value_buffer,p+1,1);
					}
					p ++;
				}
				else if( p[0] == str_begin){
					hdata_object_put((hdata_t)stack_peek(data_stack),buffer_to_str(attr_name_buffer),hdata_xml_value_parse(buffer_to_str(attr_value_buffer),InvokeTickArg));
					buffer_clear(attr_name_buffer);
					buffer_append_str(attr_name_buffer, "@");
					buffer_clear(attr_value_buffer);
					stack_pop(state_stack);
				}
				else{
					buffer_append(attr_value_buffer,p,1);
				}
			}
		}

		
		p++;
	}
	
	
	
	data = (hdata_t)stack_pop(data_stack);
	data_temp = (hdata_t)stack_pop(data_stack);
	
	while(data_temp){
		hdata_dealloc(data);
		data = data_temp;
		data_temp = (hdata_t)stack_pop(data_stack);
	}
	

	buffer_dealloc(tag_name_buffer);
	buffer_dealloc(content_buffer);
	buffer_dealloc(attr_name_buffer);
	buffer_dealloc(attr_value_buffer);
	stack_dealloc(data_stack);
	stack_dealloc(state_stack);
	
	return data;
}
Esempio n. 15
0
/**
	process_run : cmd:string -> args:string array -> 'process
	<doc>
	Start a process using a command and the specified arguments.
	</doc>
**/
CAMLprim value process_run( value cmd, value vargs ) {
	int i;
	vprocess *p;
	val_check(cmd,string);
	val_check(vargs,array);
#	ifdef _WIN32
	{
		SECURITY_ATTRIBUTES sattr;
		STARTUPINFO sinf;
		HANDLE proc = GetCurrentProcess();
		HANDLE oread,eread,iwrite;
		// creates commandline
		buffer b = alloc_buffer(NULL);
		char *sargs;
		buffer_append_char(b,'"');
		buffer_append_str(b,val_string(cmd));
		buffer_append_char(b,'"');
		for(i=0;i<val_array_size(vargs);i++) {
			value v = val_array_ptr(vargs)[i];
			int j,len;
			val_check(v,string);
			len = val_strlen(v);
			buffer_append_str(b," \"");
			for(j=0;j<len;j++) {
				char c = val_string(v)[j];
				switch( c ) {
				case '"':
					buffer_append_str(b,"\\\"");
					break;
				case '\\':
					buffer_append_str(b,"\\\\");
					break;
				default:
					buffer_append_char(b,c);
					break;
				}
			}
			buffer_append_char(b,'"');
		}
		sargs = buffer_to_string(b);
		p = (vprocess*)alloc_private(sizeof(vprocess));
		// startup process
		sattr.nLength = sizeof(sattr);
		sattr.bInheritHandle = TRUE;
		sattr.lpSecurityDescriptor = NULL;
		memset(&sinf,0,sizeof(sinf));
		sinf.cb = sizeof(sinf);
		sinf.dwFlags = STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW;
		sinf.wShowWindow = SW_HIDE;
		CreatePipe(&oread,&sinf.hStdOutput,&sattr,0);
		CreatePipe(&eread,&sinf.hStdError,&sattr,0);
		CreatePipe(&sinf.hStdInput,&iwrite,&sattr,0);
		DuplicateHandle(proc,oread,proc,&p->oread,0,FALSE,DUPLICATE_SAME_ACCESS);
		DuplicateHandle(proc,eread,proc,&p->eread,0,FALSE,DUPLICATE_SAME_ACCESS);
		DuplicateHandle(proc,iwrite,proc,&p->iwrite,0,FALSE,DUPLICATE_SAME_ACCESS);
		CloseHandle(oread);
		CloseHandle(eread);
		CloseHandle(iwrite);
		
		if( !CreateProcess(NULL,val_string(sargs),NULL,NULL,TRUE,0,NULL,NULL,&sinf,&p->pinf) ) {
			CloseHandle(p->eread);
			CloseHandle(p->oread);
			CloseHandle(p->iwrite);
			free(sargs);
			neko_error();
		}
		free(sargs);
		// close unused pipes
		CloseHandle(sinf.hStdOutput);
		CloseHandle(sinf.hStdError);
		CloseHandle(sinf.hStdInput);
	}
#	else
	char **argv = (char**)alloc_private(sizeof(char*)*(val_array_size(vargs)+2));
	argv[0] = val_string(cmd);
	for(i=0;i<val_array_size(vargs);i++) {
		value v = val_array_ptr(vargs)[i];
		val_check(v,string);
		argv[i+1] = val_string(v);
	}
	argv[i+1] = NULL;
	int input[2], output[2], error[2];
	if( pipe(input) || pipe(output) || pipe(error) )
		neko_error();
	p = (vprocess*)alloc_private(sizeof(vprocess));
	p->pid = fork();
	if( p->pid == -1 ) {
		do_close(input[0]);
		do_close(input[1]);
		do_close(output[0]);
		do_close(output[1]);
		do_close(error[0]);
		do_close(error[1]);
		neko_error();
	}
	// child
	if( p->pid == 0 ) {
		close(input[1]);
		close(output[0]);
		close(error[0]);
		dup2(input[0],0);
		dup2(output[1],1);
		dup2(error[1],2);
		execvp(val_string(cmd),argv);
		fprintf(stderr,"Command not found : %s\n",val_string(cmd));
		exit(1);
	}
	// parent
	do_close(input[0]);
	do_close(output[1]);
	do_close(error[1]);
	p->iwrite = input[1];
	p->oread = output[0];
	p->eread = error[0];
#	endif
	{
		value vp = alloc_abstract(k_process,p);
		val_gc(vp,free_process);
		return vp;
	}
}
Esempio n. 16
0
/**
	process_run : cmd:string -> args:string array option -> 'process
	<doc>
	Start a process using a command and the specified arguments.
	When args is not null, cmd and args will be auto-quoted/escaped.
	If no auto-quoting/escaping is desired, you should append necessary 
	arguments to cmd as if it is inputted to the shell directly, and pass
	null as args.
	</doc>
**/
CAMLprim value process_run( value cmd, value vargs ) {
	int i, isRaw;
	vprocess *p;
	val_check(cmd,string);
	isRaw = vargs == val_null;
	if (!isRaw) {
		val_check(vargs,array);
		vargs = val_some(vargs);
	}
#	ifdef _WIN32
	{
		SECURITY_ATTRIBUTES sattr;
		STARTUPINFO sinf;
		HANDLE proc = GetCurrentProcess();
		HANDLE oread,eread,iwrite;
		// creates commandline
		buffer b = alloc_buffer(NULL);
		char *sargs;
		if (isRaw) {
			char* cmdexe;
			buffer_append_char(b,'"');
			cmdexe = getenv("COMSPEC");
			if (!cmdexe) cmdexe = "cmd.exe";
			buffer_append_str(b,cmdexe);
			buffer_append_char(b,'"');
			buffer_append_str(b,"/C \"");
			buffer_append_str(b,val_string(cmd));
			buffer_append_char(b,'"');
		} else {
			buffer_append_char(b,'"');
			buffer_append_str(b,val_string(cmd));
			buffer_append_char(b,'"');
			for(i=0;i<val_array_size(vargs);i++) {
				value v = val_array_ptr(vargs)[i];
				int j,len;
				unsigned int bs_count = 0;
				unsigned int k;
				val_check(v,string);
				len = val_strlen(v);
				buffer_append_str(b," \"");
				for(j=0;j<len;j++) {
					char c = val_string(v)[j];
					switch( c ) {
					case '"':
						// Double backslashes.
						for (k=0;k<bs_count*2;k++) {
							buffer_append_char(b,'\\');
						}
						bs_count = 0;
						buffer_append_str(b, "\\\"");
						break;
					case '\\':
						// Don't know if we need to double yet.
						bs_count++;
						break;
					default:
						// Normal char
						for (k=0;k<bs_count;k++) {
							buffer_append_char(b,'\\');
						}
						bs_count = 0;
						buffer_append_char(b,c);
						break;
					}
				}
				// Add remaining backslashes, if any.
				for (k=0;k<bs_count*2;k++) {
					buffer_append_char(b,'\\');
				}
				buffer_append_char(b,'"');
			}
		}
		sargs = buffer_to_string(b);
		p = (vprocess*)alloc_private(sizeof(vprocess));
		// startup process
		sattr.nLength = sizeof(sattr);
		sattr.bInheritHandle = TRUE;
		sattr.lpSecurityDescriptor = NULL;
		memset(&sinf,0,sizeof(sinf));
		sinf.cb = sizeof(sinf);
		sinf.dwFlags = STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW;
		sinf.wShowWindow = SW_HIDE;
		CreatePipe(&oread,&sinf.hStdOutput,&sattr,0);
		CreatePipe(&eread,&sinf.hStdError,&sattr,0);
		CreatePipe(&sinf.hStdInput,&iwrite,&sattr,0);
		DuplicateHandle(proc,oread,proc,&p->oread,0,FALSE,DUPLICATE_SAME_ACCESS);
		DuplicateHandle(proc,eread,proc,&p->eread,0,FALSE,DUPLICATE_SAME_ACCESS);
		DuplicateHandle(proc,iwrite,proc,&p->iwrite,0,FALSE,DUPLICATE_SAME_ACCESS);
		CloseHandle(oread);
		CloseHandle(eread);
		CloseHandle(iwrite);
		
		if( !CreateProcess(NULL,val_string(sargs),NULL,NULL,TRUE,0,NULL,NULL,&sinf,&p->pinf) ) {
			CloseHandle(p->eread);
			CloseHandle(p->oread);
			CloseHandle(p->iwrite);
			free(sargs);
			neko_error();
		}
		free(sargs);
		// close unused pipes
		CloseHandle(sinf.hStdOutput);
		CloseHandle(sinf.hStdError);
		CloseHandle(sinf.hStdInput);
	}
#	else
	char **argv;
	if (isRaw) {
		argv = (char**)alloc_private(sizeof(char*)*4);
		argv[0] = "/bin/sh";
		argv[1] = "-c";
		argv[2] = val_string(cmd);
		argv[3] = NULL;
	} else {
		argv = (char**)alloc_private(sizeof(char*)*(val_array_size(vargs)+2));
		argv[0] = val_string(cmd);
		for(i=0;i<val_array_size(vargs);i++) {
			value v = val_array_ptr(vargs)[i];
			val_check(v,string);
			argv[i+1] = val_string(v);
		}
		argv[i+1] = NULL;
	}
	int input[2], output[2], error[2];
	if( pipe(input) || pipe(output) || pipe(error) )
		neko_error();
	p = (vprocess*)alloc_private(sizeof(vprocess));
	p->pid = fork();
	if( p->pid == -1 ) {
		do_close(input[0]);
		do_close(input[1]);
		do_close(output[0]);
		do_close(output[1]);
		do_close(error[0]);
		do_close(error[1]);
		neko_error();
	}
	// child
	if( p->pid == 0 ) {
		close(input[1]);
		close(output[0]);
		close(error[0]);
		dup2(input[0],0);
		dup2(output[1],1);
		dup2(error[1],2);
		execvp(argv[0],argv);
		fprintf(stderr,"Command not found : %s\n",val_string(cmd));
		exit(1);
	}
	// parent
	do_close(input[0]);
	do_close(output[1]);
	do_close(error[1]);
	p->iwrite = input[1];
	p->oread = output[0];
	p->eread = error[0];
#	endif
	{
		value vp = alloc_abstract(k_process,p);
		val_gc(vp,free_process);
		return vp;
	}
}
Esempio n. 17
0
/**
	process_run_raw : cmd:string -> 'process
	<doc>
	Start a process using a command. The input string contains
	the command as well as the arguments. Shell meta-characters
	will not be auto escaped/quoted. 
	</doc>
**/
CAMLprim value process_run_raw( value cmd ) {
	int i;
	vprocess *p;
	val_check(cmd,string);
	char* cmdStr = val_string(cmd);
#	ifdef _WIN32
	{
		SECURITY_ATTRIBUTES sattr;
		STARTUPINFO sinf;
		HANDLE proc = GetCurrentProcess();
		HANDLE oread,eread,iwrite;
		// creates commandline
		buffer b = alloc_buffer(NULL);
		char *sargs;
		buffer_append_char(b,'"');
		char* cmdexe = getenv("COMSPEC");
		if (!cmdexe) cmdexe = "cmd.exe";
		buffer_append_str(b,cmdexe);
		buffer_append_char(b,'"');
		buffer_append_str(b,"/C \"");
		buffer_append_str(b,cmdStr);
		buffer_append_char(b,'"');
		sargs = buffer_to_string(b);
		p = (vprocess*)alloc_private(sizeof(vprocess));
		// startup process
		sattr.nLength = sizeof(sattr);
		sattr.bInheritHandle = TRUE;
		sattr.lpSecurityDescriptor = NULL;
		memset(&sinf,0,sizeof(sinf));
		sinf.cb = sizeof(sinf);
		sinf.dwFlags = STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW;
		sinf.wShowWindow = SW_HIDE;
		CreatePipe(&oread,&sinf.hStdOutput,&sattr,0);
		CreatePipe(&eread,&sinf.hStdError,&sattr,0);
		CreatePipe(&sinf.hStdInput,&iwrite,&sattr,0);
		DuplicateHandle(proc,oread,proc,&p->oread,0,FALSE,DUPLICATE_SAME_ACCESS);
		DuplicateHandle(proc,eread,proc,&p->eread,0,FALSE,DUPLICATE_SAME_ACCESS);
		DuplicateHandle(proc,iwrite,proc,&p->iwrite,0,FALSE,DUPLICATE_SAME_ACCESS);
		CloseHandle(oread);
		CloseHandle(eread);
		CloseHandle(iwrite);
		
		if( !CreateProcess(NULL,val_string(sargs),NULL,NULL,TRUE,0,NULL,NULL,&sinf,&p->pinf) ) {
			CloseHandle(p->eread);
			CloseHandle(p->oread);
			CloseHandle(p->iwrite);
			free(sargs);
			neko_error();
		}
		free(sargs);
		// close unused pipes
		CloseHandle(sinf.hStdOutput);
		CloseHandle(sinf.hStdError);
		CloseHandle(sinf.hStdInput);
	}
#	else
	char **argv = (char**)alloc_private(sizeof(char*)*4);
	argv[0] = cmd = "/bin/sh";
	argv[1] = "-c";
	argv[2] = cmdStr;
	argv[3] = NULL;
	int input[2], output[2], error[2];
	if( pipe(input) || pipe(output) || pipe(error) )
		neko_error();
	p = (vprocess*)alloc_private(sizeof(vprocess));
	p->pid = fork();
	if( p->pid == -1 ) {
		do_close(input[0]);
		do_close(input[1]);
		do_close(output[0]);
		do_close(output[1]);
		do_close(error[0]);
		do_close(error[1]);
		neko_error();
	}
	// child
	if( p->pid == 0 ) {
		close(input[1]);
		close(output[0]);
		close(error[0]);
		dup2(input[0],0);
		dup2(output[1],1);
		dup2(error[1],2);
		execvp(val_string(cmd),argv);
		fprintf(stderr,"Command not found : %s\n",val_string(cmd));
		exit(1);
	}
	// parent
	do_close(input[0]);
	do_close(output[1]);
	do_close(error[1]);
	p->iwrite = input[1];
	p->oread = output[0];
	p->eread = error[0];
#	endif
	{
		value vp = alloc_abstract(k_process,p);
		val_gc(vp,free_process);
		return vp;
	}
}
Esempio n. 18
0
File: hdata.c Progetto: hailongz/c
void _hdata_write(const hdata_class_t * data_class,hdata_t data,hbuffer_t buffer,hbool pattern,hint32 level,InvokeTickDeclare){
	hint32 c,i;
	_hdata_write_object_each_arg_t arg;
	hdata_type_code type;
	if(data && data_class && buffer){
		type = hdata_type(data_class,data,InvokeTickArg);
		if(type == HDATA_TYPE_NULL){
			buffer_append_str(buffer, "null");
		}
		else if(type == HDATA_TYPE_INT16 ){
			buffer_append_format(buffer, "%d",InvokeTickArg, hdata_int16(data_class,data,0,InvokeTickArg));
		}
		else if(type == HDATA_TYPE_INT32){
			buffer_append_format(buffer, "%ld",InvokeTickArg,hdata_int32(data_class,data,0,InvokeTickArg));
		}
		else if(type == HDATA_TYPE_INT64){
			buffer_append_format(buffer, "%lld",InvokeTickArg,hdata_int64(data_class,data,0,InvokeTickArg));
		}
		else if(type == HDATA_TYPE_DOUBLE){
			buffer_append_format(buffer, "%f",InvokeTickArg,hdata_double(data_class,data,0,InvokeTickArg));
		}
		else if(type == HDATA_TYPE_BOOL){
			if(hdata_boolean(data_class,data,hbool_false,InvokeTickArg)){
				buffer_append_str(buffer, "true");
			}
			else{
				buffer_append_str(buffer, "false");
			}
		}
		else if(type == HDATA_TYPE_STRING){
			if(hdata_string(data_class,data,NULL,InvokeTickArg)){
				hdata_json_write_string(hdata_string(data_class,data,"",InvokeTickArg),buffer,InvokeTickArg);
			}
			else{
				buffer_append_str(buffer, "null");
			}
		}
		else if(type ==HDATA_TYPE_ARRAY){
			buffer_append_str(buffer, "[");
			c = hdata_array_size(data_class,data,InvokeTickArg);
			for(i=0;i<c;i++){
				if(i==0 && pattern){
					buffer_append_str(buffer, "\n");
					_hdata_json_write_level(buffer,level+1,InvokeTickArg);
				}
				else if(pattern){
					_hdata_json_write_level(buffer,level+1,InvokeTickArg);
				}
				_hdata_write(data_class,hdata_array(data_class,data,i,InvokeTickArg),buffer,pattern,level+1,InvokeTickArg);
				if(i != c-1){
					buffer_append_str(buffer, ",");
				}
				if(pattern){
					buffer_append_str(buffer, "\n");
				}
			}
			if(pattern && c>0){
				_hdata_json_write_level(buffer,level,InvokeTickArg);
				buffer_append_str(buffer, "]");
			}
			else{
				buffer_append_str(buffer, "]");
			}
		}
		else if(type ==HDATA_TYPE_OBJECT){
			buffer_append_str(buffer, "{");
			arg.buffer = buffer;
			arg.pattern = pattern;
			arg.level = level+1;
			arg.first = hbool_true;
			arg.data_class = data_class;
			
			hdata_object_each(data_class,data, _hdata_json_write_object_echo,&arg,InvokeTickArg);
			
			if(pattern && *((hchar *)buffer_data(buffer) + buffer_length(buffer) -1) != '{'){
				_hdata_json_write_level(buffer,level,InvokeTickArg);
				buffer_append_str(buffer, "}");
			}
			else{
				buffer_append_str(buffer, "}");
			}
		}
        else if(type == HDATA_TYPE_BYTES){
            buffer_append_str(buffer, "\"");
            buffer_append_str(buffer, HDATA_BASE64_TAG);
            hbase64_encode(hdata_bytes(data_class, data,InvokeTickArg),hdata_bytes_size(data_class, data,InvokeTickArg),buffer);
            buffer_append_str(buffer, "\"");
        }
	}
}
Esempio n. 19
0
/**
 
 Return : any
 */
static vmVariant vmSqliteClassInvokeCallback(vmRuntimeContext context,vmClass * clazz,vmObject * object,vmUniqueKey name,vmVariantList args,InvokeTickDeclare){
    vmVariant rs = {vmVariantTypeVoid,0};
    vmSqlite * sqlite = (vmSqlite *) object;
    
    if(!sqlite->_sqlite){
        return vmRuntimeContextException(context, 0, "not open sqlite file");
    }
    
    if(sqlite->uniqueKeys.exec == name){
        {
            hbuffer_t sql = buffer_alloc(128, 128);
            hchar * error = NULL;
            vmVariantToString(context, vmVariantListGet(args, 0), sql);
            
            sqlite3_exec(sqlite->_sqlite, buffer_to_str(sql), NULL, NULL, &error);
            
            if(error){
                rs = vmRuntimeContextException(context, sqlite3_errcode(sqlite->_sqlite), error);
            }
            
            buffer_dealloc(sql);
        }
    }
    else if(sqlite->uniqueKeys.query == name){
        {
            hbuffer_t sql = buffer_alloc(128, 128);
            hchar * error = NULL;
            hchar ** dbResult = NULL;
            hint32 nRow = 0;
            hint32 nColumn = 0;
            hint32 i,j;
            vmVariant row;
            vmVariant value;
            vmVariantToString(context, vmVariantListGet(args, 0), sql);
            
            sqlite3_get_table(sqlite->_sqlite, buffer_to_str(sql), &dbResult, &nRow, &nColumn, &error);

            
            if(error){
                sqlite3_free_table(dbResult);
                rs = vmRuntimeContextException(context, sqlite3_errcode(sqlite->_sqlite), error);
            }
            else{
                rs = vmArrayAlloc(context);
                for(i=0;i<nRow;i++){
                    row = vmDictionaryAlloc(context);
                    for(j=0;j<nColumn;j++){
                        value = vmStringAlloc(context, dbResult[nColumn + i * nColumn + j]);
                        vmDictionaryPut(context, row.value.objectValue, dbResult[j], value);
                    }
                    vmArrayAdd(context, rs.value.objectValue, row);
                }
                sqlite3_free_table(dbResult);
            }
            
            buffer_dealloc(sql);
        }
    }
    else if(sqlite->uniqueKeys.lastRowId == name){
        rs.type = vmVariantTypeInt64;
        rs.value.int64Value = sqlite3_last_insert_rowid(sqlite->_sqlite);
    }
    else if(sqlite->uniqueKeys.encode == name){
        {
            hbuffer_t str = buffer_alloc(128, 128);
            hbuffer_t enc = buffer_alloc(128, 128);
            vmVariant  var = vmVariantListGet(args, 0);
            hchar * p ;
            
            if(var.type != vmVariantTypeVoid){
                vmVariantToString(context, var, str);
                
                buffer_append_str(enc, "'");
                
                p = (hchar *)buffer_to_str(str);
                
                while(*p != 0){
                    
                    if( *p == '\''){
                        buffer_append_str(enc, "''");
                    }
                    else if( *p == '\t'){
                        buffer_append_str(enc, "\\t");
                    }
                    else if( *p == '\r'){
                        buffer_append_str(enc, "\\r");
                    }
                    else if( *p == '\n'){
                        buffer_append_str(enc, "\\n");
                    }
                    else{
                        buffer_append(enc,p,1);
                    }
                    
                    p ++;
                }
                
                buffer_append_str(enc, "'");
            }
            else{
                buffer_append_str(enc, "NULL");
            }
            
            rs =vmStringAlloc(context, buffer_to_str(enc));
            
            buffer_dealloc(str);
            buffer_dealloc(enc);
        }
    }
    else if(sqlite->uniqueKeys.sql == name){
        {
            hbuffer_t str = buffer_alloc(128, 128);
            hbuffer_t enc = buffer_alloc(128, 128);
            hbuffer_t key = buffer_alloc(64, 64);
            hbuffer_t value = buffer_alloc(128, 128);
            vmVariant var = vmVariantListGet(args, 0);
            vmVariant data = vmVariantListGet(args, 1);
            vmVariant v;
            hchar * p , *pp;
            hint32 s = 0;
            
            vmVariantToString(context, var, str);
            
            p = (hchar *)buffer_to_str(str);
            
            while(p){
                
                switch (s) {
                    case 0:
                    {
                        if(*p=='@'){
                            buffer_clear(key);
                            s = 1;
                        }
                        else{
                            buffer_append(enc,p,1);
                        }
                    }
                        break;
                    case 1:
                    {
                        if( ( *p >= 'A' && *p <= 'Z' ) || ( *p >= 'a' && *p <= 'z' ) || ( *p >= '0' && *p <= '9' ) || ( *p == '_' )){
                            buffer_append(key,p,1);
                        }
                        else{
                            if((data.type & vmVariantTypeObject) && data.value.objectValue){
                                v = vmObjectGetProperty(context, data.value.objectValue->vmClass, data.value.objectValue, vmRuntimeContextGetUniqueKey(context, buffer_to_str(key)));
                                if(v.type != vmVariantTypeVoid){
                                    buffer_clear(value);
                                    vmVariantToString(context, v, value);
                                    
                                    pp = (hchar *)buffer_to_str(value);
                                  
                                    buffer_append_str(enc, "'");
                                  
                                    while(*pp != 0){
                                        
                                        if( *pp == '\''){
                                            buffer_append_str(enc, "''");
                                        }
                                        else if( *pp == '\t'){
                                            buffer_append_str(enc, "\\t");
                                        }
                                        else if( *pp == '\r'){
                                            buffer_append_str(enc, "\\r");
                                        }
                                        else if( *pp == '\n'){
                                            buffer_append_str(enc, "\\n");
                                        }
                                        else{
                                            buffer_append(enc,pp,1);
                                        }
                                    
                                        pp ++;
                                    }
                                    
                                    buffer_append_str(enc, "'");
                                   
                                }
                                else{
                                    buffer_append_str(enc, "NULL");
                                }

                            }
                            else{
                                buffer_append_str(enc, "NULL");
                            }
                            buffer_append(enc,p,1);
                            s = 0;
                        }
                    }
                        break;
                    default:
                        break;
                }
                
                if(*p == '\0'){
                    break;
                }
                p ++;
            }
            
            
            rs = vmStringAlloc(context, buffer_to_str(enc));
            
            buffer_dealloc(value);
            buffer_dealloc(str);
            buffer_dealloc(enc);
            buffer_dealloc(key);
        }
    }
    
    return rs;
}
Esempio n. 20
0
File: hdata.c Progetto: hailongz/c
static void _hdata_json_write_level(hbuffer_t buffer,hint32 level,InvokeTickDeclare){
	hint32 i;
	for(i=0;i<level;i++){
		buffer_append_str(buffer, "\t");
	}
}
Esempio n. 21
0
void buffer_append_long(buffer *b, long value, pool_t *p) {
    char strInt[16];
    snprintf(strInt, 16, "%ld", value);
    buffer_append_str(b, strInt, strlen(strInt),p);
}