示例#1
0
void DaoxGraphData_Reset( DaoxGraphData *self, DaoxGraph *graph, int nodeSize, int edgeSize )
{
	daoint i, M, N;
	char *data;

	if( self->graph ){
		N = self->graph->nodes->size;
		M = self->graph->edges->size;
		for(i=0; i<N; i++){
			DaoxNode *node = self->graph->nodes->items.pgNode[i];
			node->X.Void = NULL;
		}
		for(i=0; i<N; i++){
			DaoxEdge *edge = self->graph->edges->items.pgEdge[i];
			edge->X.Void = NULL;
		}
	}
	GC_Assign( & self->graph, graph );
	if( graph == NULL ) return;

	N = graph->nodes->size;
	M = graph->edges->size;
	DString_Reserve( self->nodeData, N * nodeSize );
	DString_Reserve( self->edgeData, M * edgeSize );
	for(i=0, data=self->nodeData->chars;  i<N;  i++, data+=nodeSize){
		DaoxNode *node = graph->nodes->items.pgNode[i];
		node->X.Void = data;
	}
	for(i=0, data=self->edgeData->chars;  i<M;  i++, data+=edgeSize){
		DaoxEdge *edge = graph->edges->items.pgEdge[i];
		edge->X.Void = data;
	}
}
示例#2
0
void DString_AppendChar( DString *self, const char ch )
{
	DString_Reserve( self, self->size + 1 );
	self->chars[self->size] = ch;
	self->size += 1;
	self->chars[ self->size ] = 0;
}
示例#3
0
static void UT_CastToString( DaoProcess *proc, DaoValue *p[], int n )
{
	DaoxUserType *self = (DaoxUserType*) p[0];
	DString *res = DaoProcess_PutChars( proc, "" );
	DString_Reserve( res, 50 );
	res->size = sprintf( res->chars, "UserType.{%" DAO_I64 "}", self->value );
}
示例#4
0
static void ZIP_Decompress( DaoProcess *proc, DaoValue *p[], int N )
{
	DString *source = p[0]->xString.value;
	DString *res = DaoProcess_PutChars( proc, "" );
	unsigned int resLen;

	/* TODO: get decompressed size from the compressed data? */
	DString_Reserve( res, source->size );
	resLen = res->bufSize;
	while( resLen == res->bufSize ){
		DString_Reserve( res, 2*resLen );
		resLen = res->bufSize;
		BZ2_bzBuffToBuffDecompress( res->chars, & resLen, source->chars, source->size, 0, 0 );
	}
	DString_Reset( res, resLen );
}
示例#5
0
void DString_AppendBytes( DString *self, const char *chs, daoint n )
{
	daoint i;
	DString_Reserve( self, self->size + n );
	memcpy( self->chars + self->size, chs, n * sizeof(char) );
	self->size += n;
	self->chars[ self->size ] = 0;
}
示例#6
0
void DString_InsertChars( DString *self, const char* chs, daoint at, daoint rm, daoint cp )
{
	daoint i;
	if( chs == NULL ) return;
	if( cp <= 0 ) cp = strlen( chs ); // XXX <
	if( at > self->size ) at = self->size;
	if( rm < 0 ) rm = self->size;
	if( rm + at > self->size ) rm = self->size - at;
	DString_Detach( self, self->size + cp - rm );
	if( cp < rm ){
		memmove( self->chars + at+cp, self->chars + at+rm, (self->size-rm-at)*sizeof(char) );
		DString_Reserve( self, self->size + cp - rm );
	}else if( cp > rm ){
		DString_Reserve( self, self->size + cp - rm );
		memmove( self->chars + at+cp, self->chars + at+rm, (self->size-rm-at)*sizeof(char) );
	}
	memcpy( self->chars + at, chs, cp * sizeof(char) );
	self->size += cp-rm;
	self->chars[self->size] = 0;
}
示例#7
0
void DString_AppendWChar( DString *self, size_t ch )
{
	DString_Reserve( self, self->size + 4 );

	if( ch >= 0x2000000 ) ch = 0xFFFD; /* replacement character; */

	if( ch < 0x80 ){  /* 0xxxxxxx */
		self->chars[self->size++] = ch;
	}else if( ch < 0x800 ){  /* 110xxxxx 10xxxxxx */
		self->chars[self->size++] = (char)((ch >> 6) + (0x3 << 6));
		self->chars[self->size++] = U8TrailMake( ch, 0 );
	}else if( ch < 0x10000 ){   /* 1110xxxx 10xxxxxx 10xxxxxx */
示例#8
0
static void ZIP_Compress( DaoProcess *proc, DaoValue *p[], int N )
{
	DString *source = p[0]->xString.value;
	DString *res = DaoProcess_PutChars( proc, "" );
	unsigned int resLen = source->size;
	int block = 100000;
	daoint size = source->size;

	DString_Reserve( res, size );
	size = 1 + size / block;
	if( size > 9 ) size = 9;
	BZ2_bzBuffToBuffCompress( res->chars, & resLen, source->chars, source->size, size, 0, 30 );
	DString_Reset( res, resLen );
}
示例#9
0
文件: daoStream.c 项目: daokoder/dao
int DaoFile_ReadLine( FILE *fin, DString *line )
{
	int ch;

	DString_Reset( line, 0 );
	if( feof( fin ) ) return 0;

	while( (ch = fgetc(fin)) != EOF ){
		if( line->size == line->bufSize ) DString_Reserve( line, 5 + 1.2*line->size );
		line->chars[ line->size ++ ] = ch;
		line->chars[ line->size ] = '\0';
		if( ch == '\n' ) break;
	}
	return 1;
}
示例#10
0
文件: daoStream.c 项目: daokoder/dao
daoint DaoStream_Read( DaoStream *self, DString *output, daoint count )
{
	DString_Reset( output, 0 );
	if( self->Read == NULL ) return 0;
	if( count == -1 ){
		return self->Read( self, output, -1 );
	}else if( count <= -2 ){
		return self->Read( self, output, -2 );
	}else if( count <= 0x7fffffff ){
		return self->Read( self, output, count );
	}
	DString_Reserve( output, count );
	count = DaoStream_ReadBytes( self, output->chars, count );
	if( count > 0 ) DString_Reset( output, count );
	return count;
}
示例#11
0
static void DaoIO_ReadFile( DaoProcess *proc, DaoValue *p[], int N )
{
	DString *res = DaoProcess_PutChars( proc, "" );
	daoint silent = p[1]->xBoolean.value;
	if( DString_Size( p[0]->xString.value ) ==0 ){
		char buf[4096];
		while(1){
			size_t count = fread( buf, 1, sizeof( buf ), stdin );
			if( count ==0 ) break;
			DString_AppendBytes( res, buf, count );
		}
	}else{
		FILE *fin = DaoIO_OpenFile( proc, p[0]->xString.value, "r", silent );
		struct stat info;
		if( fin == NULL ) return;
		fstat( fileno( fin ), &info );
		DString_Reserve( res, info.st_size );
		DString_Reset( res, fread( res->chars, 1, info.st_size, fin ) );
		fclose( fin );
	}
}
示例#12
0
static void ParseKeyValueString( DaoProcess *proc, DaoMap *mulmap, DaoMap *map, const char *data )
{
    const char *end = data + strlen( data );
    DaoValue *vk = (DaoValue*) DaoProcess_NewString( proc, NULL, 0 );
    DaoValue *vv = (DaoValue*) DaoProcess_NewString( proc, NULL, 0 );
    DString *key = DaoString_Get( DaoValue_CastString( vk ) );
    DString *value = DaoString_Get( DaoValue_CastString( vv ) );
    DString *buffer = key;

    buffer->size = 0;
    for(; data < end; ++data) {
        if( buffer->size >= buffer->bufSize ) DString_Reserve( buffer, 1.5*buffer->size + 8 );
        if( *data == '=' ) {
            buffer->chars[ buffer->size ] = 0;
            buffer = value;
            buffer->size = 0;
        } else if( *data == '&' || *data == ';' ) {
            buffer->chars[ buffer->size ] = 0;
            InsertKeyValue( proc, mulmap, map, vk, vv );
            DString_Reset( key, 0 );   /* also detaching shared memory; */
            DString_Reset( value, 0 ); /* also detaching shared memory; */
            buffer = key;
        } else if( *data != ' ' ) {
            if( *data == '%' ) {
                char a = tolower( data[1] );
                char b = tolower( data[2] );
                buffer->chars[ buffer->size ++ ] = (char) ((HEXTOI(a) << 4) | HEXTOI(b));
                data += 2;
            } else if( *data == '+' ) {
                buffer->chars[ buffer->size ++ ] = ' ';
            } else {
                buffer->chars[ buffer->size ++ ] = *data;
            }
        }
    }
    if( key->size ) InsertKeyValue( proc, mulmap, map, vk, vv );
}
示例#13
0
static void DaoSTD_Assert( DaoProcess *proc, DaoValue *p[], int n )
{
	DaoType *etype;
	DaoException *exception;
	DaoRoutine *rout = proc->activeRoutine;
	DString *file = proc->activeNamespace->name;
	int line, id = (ushort_t) (proc->activeCode - proc->topFrame->active->codes);

	if( p[0]->xBoolean.value ) return;

	line = rout->defLine;
	if( id < rout->body->vmCodes->size ) line = rout->body->annotCodes->items.pVmc[id]->line;

	etype = DaoVmSpace_MakeExceptionType( proc->vmSpace, "Error::Assertion" );
	exception = DaoException_New( etype );
	DList_Append( proc->exceptions, exception );

	DaoException_Init( exception, proc, NULL, NULL );

	DString_Reserve( exception->info, file->size + 100 );
	id = sprintf( exception->info->chars, dao_assertion_format, line, file->chars );
	if( id ) exception->info->size = id;
	DString_Append( exception->info, p[1]->xString.value );
}