Example #1
0
BBArray *bbArrayConcat( const char *type,BBArray *x,BBArray *y ){

	BBArray *arr;
	char *data;
	int length=x->scales[0]+y->scales[0];
	
	if( length<=0 ) return &bbEmptyArray;

	arr=allocateArray( type,1,&length );
	
	data=(char*)BBARRAYDATA( arr,1 );
	
	memcpy( data,BBARRAYDATA( x,1 ),x->size );
	memcpy( data+x->size,BBARRAYDATA( y,1 ),y->size );
	
#ifdef BB_GC_RC
	if( type[0]==':' || type[0]=='$' || type[0]=='[' ){
		int i;
		BBObject **p=(BBObject**)data;
		for( i=0;i<length;++i ){
			BBObject *o=*p++;
			BBINCREFS( o );
		}
	}
#endif
	return arr;
}
Example #2
0
File: glue.c Project: GWRon/TVTower
BBArray * bmx_stringbuffer_splitbuffer_toarray(struct MaxSplitBuffer * buf) {
    int i, n;
    BBString **p,*bit;
    BBArray *bits;

    n = buf->count;

    bits = bbArrayNew1D("$", n);
    p = (BBString**)BBARRAYDATA(bits, 1);

    i = 0;
    while (n--) {
        bit = bmx_stringbuffer_substring(buf->buffer, buf->startIndex[i], buf->endIndex[i]);
        BBINCREFS( bit );
        *p++ = bit;
        i++;
    }
    return bits;
}
Example #3
0
void bbStartup( int argc,char *argv[],void *dummy1,void *dummy2 ){

	int i,k;
	BBString **p;
	
	//Start up GC and create bbAppFile, bbAppDir and bbLaunchDir
	
#if _WIN32

	char *ebp;
	OSVERSIONINFO os={ sizeof(os) };
	
	//asm( "movl %%ebp,%0;":"=r"(ebp) );//::"%ebp" );
	
	//bbGCStackTop=ebp+28;
	
	// BaH bbThreadStartup();
	bbGCStartup();

	if( GetVersionEx( &os ) ){
		if( os.dwPlatformId==VER_PLATFORM_WIN32_NT ){
			_bbusew=1;
		}
	}
	
	if( _bbusew ){
		int e=0;
		wchar_t buf[MAX_PATH];
		
		_wgetcwd( buf,MAX_PATH );
		for( i=0;buf[i];++i ){
			if( buf[i]=='\\' ) buf[i]='/';
		}
		bbLaunchDir=bbStringFromWString( buf );
		
		GetModuleFileNameW( GetModuleHandleW(0),buf,MAX_PATH );
		for( i=0;buf[i];++i ){
			if( buf[i]=='\\' ) buf[i]='/';
			if( buf[i]=='/' ) e=i;
		}
		bbAppFile=bbStringFromWString( buf );

		if( e ){
			if( buf[e-1]==':' ) ++e;
			bbAppDir=bbStringFromShorts( buf,e );
		}else{
			bbAppDir=&bbEmptyString;
		}

		_wchdir( bbTmpWString( bbAppDir ) );
		
	}else{
		int e=0;
		char buf[MAX_PATH];

		_getcwd( buf,MAX_PATH );
		for( i=0;buf[i];++i ){
			if( buf[i]=='\\' ) buf[i]='/';
		}
		bbLaunchDir=bbStringFromCString( buf );
		
		GetModuleFileNameA( GetModuleHandleA(0),buf,MAX_PATH );
		for( i=0;buf[i];++i ){
			if( buf[i]=='\\' ) buf[i]='/';
			if( buf[i]=='/' ) e=i;
		}
		bbAppFile=bbStringFromCString( buf );

		if( e ){
			if( buf[e-1]==':' ) ++e;
			bbAppDir=bbStringFromBytes( buf,e );
		}else{
			bbAppDir=&bbEmptyString;
		}

		_chdir( bbTmpCString( bbAppDir ) );
	}

#elif __linux

	char *ebp;
	char buf[PATH_MAX];
	char lnk[PATH_MAX];
	pid_t pid;
	
	// asm( "movl %%ebp,%0;":"=r"(ebp) );//::"%ebp" );
	
	bbGCStackTop=ebp+28;
	
	// BaH bbThreadStartup();
	bbGCStartup();
	
	getcwd( buf,PATH_MAX );
	bbLaunchDir=bbStringFromUTF8String( buf );
	
	pid=getpid();
	sprintf( lnk,"/proc/%i/exe",pid );
	i=readlink( lnk,buf,PATH_MAX );
	if( i>0 ){
		char *p;
		buf[i]=0;
		bbAppFile=bbStringFromUTF8String( buf );
		p=strrchr( buf,'/' );
		if( p ){
			*p=0;
			bbAppDir=bbStringFromUTF8String( buf );
		}else{
			bbAppDir=&bbEmptyString;
		}
	}else{
		bbAppFile=&bbEmptyString;
		bbAppDir=&bbEmptyString;
	}
	
	chdir( bbTmpUTF8String( bbAppDir ) );
	
#elif __APPLE__
	
	CFURLRef url;
	char buf[PATH_MAX],*e;
	
//#if BB_ARGP
//	bbGCStackTop=bbArgp(0);
//#else
	bbGCStackTop=&argc;
//#endif

	// BaH bbThreadStartup();
	bbGCStartup();
	
	getcwd( buf,PATH_MAX );
	bbLaunchDir=bbStringFromUTF8String( buf );
	
	url=CFBundleCopyExecutableURL( CFBundleGetMainBundle() );
	CFURLGetFileSystemRepresentation( url,true,(UInt8*)buf,PATH_MAX );
	CFRelease( url );
	
	bbAppFile=bbStringFromUTF8String( buf );

	if( e=strstr( buf,".app/Contents/MacOS/" ) ){
		*e=0;
	}
	if( e=strrchr( buf,'/' ) ){
		*e=0;
		bbAppDir=bbStringFromUTF8String( buf );
	}else{
		bbAppDir=&bbEmptyString;
	}
	
	chdir( bbTmpUTF8String( bbAppDir ) );
	
#endif

	BBINCREFS( bbLaunchDir );
	BBINCREFS( bbAppDir );
	BBINCREFS( bbAppFile );

	bbAppTitle=bbStringFromCString( "BlitzMax Application" );
	BBINCREFS( bbAppTitle );

	bbAppArgs=bbArrayNew1D( "$",argc );
	BBINCREFS( bbAppArgs );

	p=(BBString**)BBARRAYDATA( bbAppArgs,1 );
	
	for( k=0;k<argc;++k ){
		BBString *arg=bbStringFromCString( argv[k] );
		BBINCREFS( arg );
		*p++=arg;
	}
	
	startup();
}
Example #4
0
BBArray *bbArraySlice( const char *type,BBArray *inarr,int beg,int end ){

	char *p;
	void *init;
	BBArray *arr;
	int n,k,el_size;
	int length=end-beg;

	if( length<=0 ) return &bbEmptyArray;
	
	arr=allocateArray( type,1,&length );

	el_size=arr->size/length;
	
	init=arrayInitializer( arr );
	p=(char*)BBARRAYDATA( arr,1 );

	n=-beg;
	if( n>0 ){
		if( beg+n>end ) n=end-beg;
		if( init ){
			void **dst=(void**)p;
			for( k=0;k<n;++k ) *dst++=init;
			p=(char*)dst;
		}else{
			memset( p,0,n*el_size );
			p+=n*el_size;
		}
		beg+=n;
		if( beg==end ) return arr;
	}
	n=inarr->scales[0]-beg;
	if( n>0 ){
		if( beg+n>end ) n=end-beg;
#ifdef BB_GC_RC
		if( type[0]==':' || type[0]=='$' || type[0]=='[' ){
			BBObject **dst=(BBObject**)p;
			BBObject **src=(BBObject**)BBARRAYDATA(inarr,inarr->dims)+beg;
			for( k=0;k<n;++k ){ 
				BBObject *o=*src++;
				BBINCREFS( o );
				*dst++=o; 
			}
			p=(char*)dst;
		}else{
			memcpy( p,(char*)BBARRAYDATA(inarr,inarr->dims)+beg*el_size,n*el_size );
			p+=n*el_size;
		}
#else
		memcpy( p,(char*)BBARRAYDATA(inarr,inarr->dims)+beg*el_size,n*el_size );
		p+=n*el_size;
#endif
		beg+=n;
		if( beg==end ) return arr;
	}
	n=end-beg;
	if( n>0 ){
		if( init ){
			void **dst=(void**)p;
			for( k=0;k<n;++k ) *dst++=init;
		}else{
			memset( p,0,n*el_size );
		}
	}
	return arr;
}