Example #1
0
static void FRAME_AddList( DaoProcess *proc, DaoValue *p[], int N )
{
	DaoxDataColumn *col;
	DaoxDataFrame *self = (DaoxDataFrame*) p[0];
	DaoList *list = (DaoList*) p[1];
	DString *lab = DaoValue_TryGetString( p[2] );
	DaoType *etype = dao_type_any;
	daoint i, M = self->dims[0] * self->dims[2];

	if( list->unitype && list->unitype->nested->size ){
		DaoType *tp = list->unitype->nested->items.pType[0];
		if( tp != NULL && !(tp->tid & DAO_ANY) ) etype = tp;
	}

	DaoxDataFrame_Sliced( self );
	col = DaoxDataFrame_MakeColumn( self, etype );
	DArray_Append( self->columns, col );
	DaoxDataColumn_Reset( col, M );
	self->dims[1] += 1;

	if( lab->size ){
		DString_ToMBS( lab );
		DaoxDataFrame_AddLabel( self, DAOX_DF_COL, lab->mbs, self->dims[1]-1 );
	}

	if( M > list->items.size ) M = list->items.size;
	for(i=0; i<M; ++i) DaoxDataColumn_SetCell( col, i, list->items.items.pValue[i] );
	M = self->dims[0] * self->dims[2];
	for(i=list->items.size; i<M; ++i) DaoxDataColumn_SetCell( col, i, NULL );
}
Example #2
0
static void FRAME_AddArray( DaoProcess *proc, DaoValue *p[], int N )
{
	DaoValue value = {0};
	DaoxDataColumn *col;
	DaoxDataFrame *self = (DaoxDataFrame*) p[0];
	DaoArray *array = (DaoArray*) p[1];
	DString *lab = DaoValue_TryGetString( p[2] );
	DaoType *etype = dao_array_types[array->etype];
	daoint i, M = self->dims[0] * self->dims[2];

	etype = etype->nested->items.pType[0];

	DaoxDataFrame_Sliced( self );
	col = DaoxDataFrame_MakeColumn( self, etype );
	DArray_Append( self->columns, col );
	DaoxDataColumn_Reset( col, M );
	self->dims[1] += 1;

	if( lab->size ){
		DString_ToMBS( lab );
		DaoxDataFrame_AddLabel( self, DAOX_DF_COL, lab->mbs, self->dims[1]-1 );
	}

	if( M > array->size ) M = array->size;
	for(i=0; i<M; ++i){
		DaoArray_GetValue( array, i, & value );
		DaoxDataColumn_SetCell( col, i, & value );
	}
	M = self->dims[0] * self->dims[2];
	for(i=array->size; i<M; ++i) DaoxDataColumn_SetCell( col, i, NULL );
}
Example #3
0
static void FRAME_GetIndex( DaoProcess *proc, DaoValue *p[], int N )
{
	DaoxDataFrame *self = (DaoxDataFrame*) p[0];
	DString *lab = DaoValue_TryGetString( p[2] );
	daoint idx, dim = p[1]->xEnum.value;
	DString_ToMBS( lab );
	idx = DaoxDataFrame_GetIndex( self, dim, lab->mbs );
	DaoProcess_PutInteger( proc, idx );
}
Example #4
0
static void FRAME_AddLabel( DaoProcess *proc, DaoValue *p[], int N )
{
	DaoxDataFrame *self = (DaoxDataFrame*) p[0];
	DString *lab = DaoValue_TryGetString( p[2] );
	daoint dim = p[1]->xEnum.value;
	daoint idx = p[3]->xInteger.value;
	DString_ToMBS( lab );
	DaoxDataFrame_AddLabel( self, dim, lab->mbs, idx );
}
Example #5
0
void DaoCGI_SendFile( DaoProcess *proc, DaoValue *p[], int N )
{
    DString *mbs;
    DString *file = DaoValue_TryGetString( p[0] );
    DString *mime = DaoValue_TryGetString( p[1] );
    DString *notfound = DaoValue_TryGetString( p[2] );
    char buf[IO_BUF_SIZE];
    FILE *fin = fopen( DString_GetData( file ), "r" );
    if( fin == NULL ) {
        printf( "%s", DString_GetData( notfound ) );
        return;
    }
    mbs = DString_New();
    printf( "Content-Type: %s\n\n", DString_GetData( mime ) );
    while(1) {
        size_t count = fread( buf, 1, IO_BUF_SIZE, fin );
        if( count ==0 ) break;
        DString_Reset( mbs, 0 );
        DString_AppendBytes( mbs, buf, count );
        DaoFile_WriteString( stdout, mbs );
    }
    fclose( fin );
    DString_Delete( mbs );
}
Example #6
0
static int DaoRoutine_GetFieldIndex( DaoRoutine *self, DString *name )
{
	DString none = DString_WrapMBS( "" );
	DaoString str = {DAO_STRING,0,0,0,0,NULL};
	DaoString *s = & str;
	daoint i;
	if( name == NULL ) name = & none;
	for(i=0; i<self->routConsts->items.size; ++i){
		DaoValue *item = DaoList_GetItem( self->routConsts, i );
		DString *field = DaoValue_TryGetString( item );
		if( field == NULL ) continue;
		if( DString_EQ( field, name ) ) return i;
	}
	str.data = name;
	return DaoRoutine_AddConstant( self, (DaoValue*) s );
}