Beispiel #1
0
int DString_Change( DString *self, const char *pat, const char *target, int index )
{
	DString *str = DString_New();
	DString *tg = DString_New();
	DaoRegex *regex;
	int rc;
	DString_SetChars( str, pat );
	DString_SetChars( tg, target );
	regex = (DaoRegex*) dao_malloc( DaoRegex_CheckSize( str ) );
	DaoRegex_Init( regex, str );
	DString_Delete( str );
	rc = DaoRegex_Change( regex, self, tg, index );
	DString_Delete( tg );
	dao_free( regex );
	return rc;
}
Beispiel #2
0
static char* DaoReadLine( const char *s, DString *buffer )
{
	int ch;
	char *line;

	DString_Reset( buffer, 0 );

#ifdef DAO_WITH_THREAD
	if( ! DThread_IsMain() ){
		printf( "%s", s );
		fflush( stdout );
		while( (ch = getchar()) != '\n' ) DString_AppendWChar( buffer, ch );
		return DString_GetData( buffer );
	}
#endif

	readingline = 1;
	count = 0;

#ifdef DAO_USE_READLINE
	line = readline( s );
	DString_SetChars( buffer, line );
	free( line );
#endif
	readingline = 0;
	return DString_GetData( buffer );
}
Beispiel #3
0
static void DaoObject_Print( DaoValue *self0, DaoProcess *proc, DaoStream *stream, DMap *cycData )
{
	int ec;
	char buf[50];
	DaoObject *self = & self0->xObject;
	sprintf( buf, "[%p]", self );
	if( self0 == self->defClass->objType->value ){
		DaoStream_WriteString( stream, self->defClass->className );
		DaoStream_WriteChars( stream, "[null]" );
		return;
	}
	if( cycData != NULL && DMap_Find( cycData, self ) != NULL ){
		DaoStream_WriteString( stream, self->defClass->className );
		DaoStream_WriteChars( stream, buf );
		return;
	}
	if( cycData ) MAP_Insert( cycData, self, self );

	DString_SetChars( proc->mbstring, "serialize" );
	DaoValue_Clear( & proc->stackValues[0] );
	ec = DaoObject_InvokeMethod( self, proc->activeObject, proc, proc->mbstring, NULL,0,1,1 );
	if( ec && ec != DAO_ERROR_FIELD_NOTEXIST ){
		DaoProcess_RaiseException( proc, daoExceptionNames[ec], proc->mbstring->chars, NULL );
	}else if( ec == DAO_ERROR_FIELD_NOTEXIST || proc->stackValues[0] == NULL ){
		DaoStream_WriteString( stream, self->defClass->className );
		DaoStream_WriteChars( stream, buf );
	}else{
		DaoValue_Print( proc->stackValues[0], proc, stream, cycData );
	}
}
Beispiel #4
0
static int DaoObject_DoSetField( DaoValue *self, DaoString *name, DaoValue *value, DaoProcess *proc )
{
	DaoObject *object = (DaoObject*) self;
	DaoObject *host = proc->activeObject;
	DaoClass *hostClass = host ? host->defClass : NULL;
	int ec = DaoObject_SetData( object, name->value, value, host );
	if( ec != DAO_OK ){
		DString *field = proc->string;
		DaoRoutine *rout;

		DString_SetChars( field, "." );
		DString_Append( field, name->value );
		DString_AppendChars( field, "=" );
		rout = DaoClass_FindMethod( object->defClass, field->chars, hostClass );
		if( rout != NULL ){
			ec = DaoProcess_PushCall( proc, rout, self, & value, 1 );
		}else{
			DaoValue *args[2];
			args[0] = (DaoValue*) name;
			args[1] = value;
			rout = DaoClass_FindMethod( object->defClass, ".=", hostClass );
			if( rout == NULL ) return DAO_ERROR_FIELD_ABSENT;
			ec = DaoProcess_PushCall( proc, rout, self, args, 2 );
		}
		if( rout == NULL ) return DAO_ERROR_FIELD_ABSENT;
	}
	if( ec ) DaoProcess_RaiseError( proc, daoExceptionNames[ec], name->value->chars );
	return ec;
}
Beispiel #5
0
static DaoValue* DaoObject_DoGetField( DaoValue *self, DaoString *name, DaoProcess *proc )
{
	DaoObject *object = (DaoObject*) self;
	DaoObject *host = proc->activeObject;
	DaoClass *hostClass = host ? host->defClass : NULL;
	DaoValue *value = NULL;
	int rc = DaoObject_GetData( object, name->value, & value, host );
	if( rc ){
		DaoRoutine *rout;
		DString *field = proc->string;

		DString_SetChars( field, "." );
		DString_Append( field, name->value );
		rout = DaoClass_FindMethod( object->defClass, field->chars, hostClass );
		if( rout != NULL ){
			rc = DaoProcess_PushCall( proc, rout, self, NULL, 0 );
		}else{
			DaoValue *arg = (DaoValue*) name;
			rout = DaoClass_FindMethod( object->defClass, ".", hostClass );
			if( rout != NULL ) rc = DaoProcess_PushCall( proc, rout, self, & arg, 1 );
		}
		if( rout == NULL ) return NULL;
	}else{
		DaoProcess_PutValue( proc, value );
	}
	if( rc ) DaoProcess_RaiseError( proc, daoExceptionNames[rc], name->value->chars );
	return NULL;
}
Beispiel #6
0
static void DaoObject_GetItem( DaoValue *self0, DaoProcess *proc, DaoValue *ids[], int N )
{
	DaoObject *self = & self0->xObject;
	int rc = 0;
	DString_SetChars( proc->string, "[]" );
	rc = DaoObject_InvokeMethod( self, proc->activeObject, proc, proc->string, ids, N,0,0 );
	if( rc ) DaoProcess_RaiseException( proc, daoExceptionNames[rc], proc->string->chars, NULL );
}
Beispiel #7
0
void DString_SetBytes( DString *self, const char *bytes, daoint count )
{
	if( count < 0 ){
		DString_SetChars( self, bytes );
	}else{
		DString_Clear( self );
		DString_AppendBytes( self, bytes, count );
	}
}
Beispiel #8
0
static void DaoObject_SetItem( DaoValue *self0, DaoProcess *proc, DaoValue *ids[], int N, DaoValue *value )
{
	DaoObject *self = & self0->xObject;
	DaoValue *ps[ DAO_MAX_PARAM ];
	int rc;
	memcpy( ps+1, ids, N*sizeof(DaoValue*) );
	ps[0] = value;
	DString_SetChars( proc->string, "[]=" );
	rc = DaoObject_InvokeMethod( self, proc->activeObject, proc, proc->string, ps, N+1,1,0 );
	if( rc ) DaoProcess_RaiseException( proc, daoExceptionNames[rc], proc->string->chars, NULL );
}
Beispiel #9
0
static void DaoObject_Core_GetField( DaoValue *self0, DaoProcess *proc, DString *name )
{
	DaoObject *self = & self0->xObject;
	DaoValue *value = NULL;
	int rc = DaoObject_GetData( self, name, & value, proc->activeObject );
	if( rc ){
		DString *field = proc->string;
		DString_SetChars( field, "." );
		DString_Append( field, name );
		rc = DaoObject_InvokeMethod( self, proc->activeObject, proc, field, NULL,0,0,0 );
		if( rc == DAO_ERROR_FIELD_NOTEXIST ){
			DaoString str = {DAO_STRING,0,0,0,1,NULL};
			DaoValue *pars = (DaoValue*) & str;
			str.value = name;
			DString_SetChars( field, "." );
			rc = DaoObject_InvokeMethod( self, proc->activeObject, proc, field, &pars,1,0,0 );
		}
	}else{
		DaoProcess_PutValue( proc, value );
	}
	if( rc ) DaoProcess_RaiseException( proc, daoExceptionNames[rc], name->chars, NULL );
}
Beispiel #10
0
int DString_Match( DString *self, const char *pat, daoint *start, daoint *end )
{
	DString *str = DString_New();
	DaoRegex *regex;
	int rc;
	DString_SetChars( str, pat );
	regex = (DaoRegex*) dao_malloc( DaoRegex_CheckSize( str ) );
	DaoRegex_Init( regex, str );
	DString_Delete( str );
	rc = DaoRegex_Match( regex, self, start, end );
	dao_free( regex );
	return rc;
}
Beispiel #11
0
static void DaoObject_Core_SetField( DaoValue *self0, DaoProcess *proc, DString *name, DaoValue *value )
{
	DaoObject *self = & self0->xObject;
	int ec = DaoObject_SetData( self, name, value, proc->activeObject );
	int ec2 = ec;
	if( ec != DAO_ERROR ){
		DString *mbs = proc->string;
		DString_SetChars( mbs, "." );
		DString_Append( mbs, name );
		DString_AppendChars( mbs, "=" );
		ec = DaoObject_InvokeMethod( self, proc->activeObject, proc, mbs, & value, 1,1,0 );
		if( ec == DAO_ERROR_FIELD_NOTEXIST ){
			DaoString str = {DAO_STRING,0,0,0,1,NULL};
			DaoValue *pars[2];
			pars[0] = (DaoValue*) & str;
			pars[1] = value;
			str.value = name;
			DString_SetChars( mbs, ".=" );
			ec = DaoObject_InvokeMethod( self, proc->activeObject, proc, mbs, pars,2,1,0 );
		}
		if( ec == DAO_ERROR_FIELD_NOTEXIST ) ec = ec2;
	}
	if( ec ) DaoProcess_RaiseException( proc, daoExceptionNames[ec], name->chars, NULL );
}
Beispiel #12
0
DaoXmlParser* DaoXmlParser_New()
{
	DaoXmlParser *self = (DaoXmlParser*) dao_calloc( 1, sizeof(DaoXmlParser) );
	self->key = DString_New();
	self->value = DString_New();
	self->escape = DString_New();
	self->escapes = DHash_New( DAO_DATA_STRING, DAO_DATA_STRING );
	DString_SetChars( self->key, "lt" );
	DString_SetChars( self->value, "<" );
	DMap_Insert( self->escapes, self->key, self->value );
	DString_SetChars( self->key, "gt" );
	DString_SetChars( self->value, ">" );
	DMap_Insert( self->escapes, self->key, self->value );
	DString_SetChars( self->key, "amp" );
	DString_SetChars( self->value, "&" );
	DMap_Insert( self->escapes, self->key, self->value );
	DString_SetChars( self->key, "apos" );
	DString_SetChars( self->value, "'" );
	DMap_Insert( self->escapes, self->key, self->value );
	DString_SetChars( self->key, "quot" );
	DString_SetChars( self->value, "\"" );
	DMap_Insert( self->escapes, self->key, self->value );
	return self;
}
Beispiel #13
0
DString* DaoValue_GetString( DaoValue *self, DString *str )
{
	dao_complex *com;
	char chs[100] = {0};
	DString_Clear( str );
	switch( self->type ){
	case DAO_COMPLEX :
		com = & self->xComplex.value;
		sprintf( chs, (com->imag < 0) ? "%g%gC" : "%g+%gC", com->real, com->imag ); break;
	case DAO_BOOLEAN : strcat( chs, self->xBoolean.value ? "true" : "false" ); break;
	case DAO_INTEGER : sprintf( chs, "%"DAO_I64, (long long) self->xInteger.value ); break;
	case DAO_FLOAT   : sprintf( chs, "%g", self->xFloat.value ); break;
	case DAO_STRING : DString_Assign( str, self->xString.value ); break;
	case DAO_ENUM : DaoEnum_MakeName( & self->xEnum, str ); break;
	default : break;
	}
	if( self->type <= DAO_COMPLEX ) DString_SetChars( str, chs );
	return str;
}
Beispiel #14
0
int DaoValue_DoSetField( DaoValue *self, DaoType *type, DaoString *name, DaoValue *value, DaoProcess *proc )
{
    DaoRoutine *rout;

    DString_SetChars( proc->string, "." );
    DString_Append( proc->string, name->value );
    DString_AppendChars( proc->string, "=" );
    rout = DaoType_FindFunction( type, proc->string );
	if( rout != NULL ){
		return DaoProcess_PushCall( proc, rout, self, & value, 1 );
	}else{
		DaoValue *args[2];
		args[0] = (DaoValue*) name;
		args[1] = value;
		rout = DaoType_FindFunctionChars( type, ".=" );
		if( rout == NULL ) return DAO_ERROR_FIELD_ABSENT;
		return DaoProcess_PushCall( proc, rout, self, args, 2 );
	}
	return DAO_ERROR_FIELD_ABSENT;
}
Beispiel #15
0
DaoValue* DaoValue_DoGetField( DaoValue *self, DaoType *type, DaoString *name, DaoProcess *proc )
{
	DaoValue *value = DaoType_FindValue( type, name->value );
	DaoRoutine *rout;

	if( value != NULL ) return value;

	DString_SetChars( proc->string, "." );
	DString_Append( proc->string, name->value );
	rout = DaoType_FindFunction( type, proc->string );
	if( rout != NULL ){
		DaoProcess_PushCall( proc, rout, self, NULL, 0 );
	}else{
		DaoValue *arg = (DaoValue*) name;
		rout = DaoType_FindFunctionChars( type, "." );
		if( rout == NULL ) return NULL;
		DaoProcess_PushCall( proc, rout, self, & arg, 1 );
	}
	return NULL;
}
Beispiel #16
0
DString* DString_NewChars( const char *mbs )
{
	DString *self = DString_New();
	DString_SetChars( self, mbs );
	return self;
}