Ejemplo n.º 1
0
/* getDynamicValue: push value of cell onto stack */
void getDynamicValue( Array *array, Symbol *s )
{
    int         index;
    char        *key;
    ArrayCell   *cell;

    /* create the key */
    key = buildKey( array, s );

    /* look for key */
    index = findKey( array, s, key );
    eFree( key );

    if (index == -1) {
        /* no item */
        pushStringCopy( "" );

    } else {
        /* address of the cell */
        cell = array->data.cell + index;

        tos++;
        stack[tos].datatype = cell->data.datatype;

        /* copy data to stack */
        switch (cell->data.datatype) {
        case DATA_NUMBER:
            stack[tos].value.number = cell->data.value.number;
            break;

        case DATA_STRING:
            stack[tos].value.string = eCopyString( cell->data.value.string );
            break;

        default:
            ePrintf( Runtime, "getDynamicElement: Array %s[%s] is corrupt",
                s->name, cell->key );
            break;

        }
    }
}
Ejemplo n.º 2
0
/* getDynamicKey: push key of cell onto stack */
int getDynamicKey( Array *array, int index )
{
    ArrayCell   *cell;

    if (index < 0 || index >= array->lower[0]) {
        /* failure */
        return 0;

    } else {
        /* address of the cell */
        cell = array->data.cell + index;

        /* copy string to stack */
        tos++;
        stack[tos].datatype = DATA_STRING;
        stack[tos].value.string = eCopyString( cell->key );

        /* success */
        return 1;
    }
}
Ejemplo n.º 3
0
/* fileLineInput: return a string from the file */
char *fileLineInput( int handle )
{
    int len;
    char buffer[FILE_BUFFER_MAX];

    fileCheckHandle( handle, 1 );

    if (fileMode[handle-1] != FILE_MODE_INPUT) {
        ePrintf( Runtime, "File #d is not open for Input", handle );
    }

    buffer[0] = '\0';
    fgets( buffer, FILE_BUFFER_MAX-1, fileHandles[handle-1] );

    /* remove eol */
    len = strlen( buffer );
    if (len) {
        if (buffer[len-1] == '\n' ) {
            buffer[len-1] = '\0';
        }
    }

    return eCopyString( buffer );
}
Ejemplo n.º 4
0
int interpret( int cmdArgc, char **cmdArgv )
{
    int i,r;
    long offset;

    /* initialize */
    argCountStack = newStack(32);	/* count of parameters */
    blockStack = newStack(32);		/* control block stack */
    lineStack = newStack(32);		/* current line number */
    sharedStack = newStack(128);	/* list of shared variables */
    currentScope = NULL;            	/* routine being defined */
    oldScopeP=0;			/* intial oldScope=0 */
    oldScope[oldScopeP]=currentScope;	/*oldScope0 =NULL */
    currentType = NULL;             	/* no type being defined */
    initKeywords();                 	/* builtin keywords */
    initBuiltins();                 	/* builtin functions */
    initConsts();                   	/* builtin constants */



    // if name of executable <> sdlBrt =autoboot
    r=strlen(cmdArgv[0]);

#ifdef UNIX
    if (strncasecmp(cmdArgv[0]+(r-6),"sdlbrt",6)!=0 ){
#else
    if (strnicmp(cmdArgv[0]+(r-10),"sdlbrt.exe",10)!=0 && strnicmp(cmdArgv[0]+(r-6),"sdlbrt",6)!=0 ){
#endif
	/* load the bindfile */
	offset=findBind( cmdArgv[0]);
	if (offset!=0){
	    if (!pushIncludeFile( cmdArgv[0], offset )){
		ePrintf( Init, "File not found\n");
		return -1;
	    }
	}
	else{
#ifdef UNIX
	    cmdArgv[cmdArgc]=(char *)malloc(strlen(cmdArgv[0])+16);
	    strcpy(cmdArgv[cmdArgc],cmdArgv[0]);
	    strcat(cmdArgv[cmdArgc],".sdlbas\0");
#else
	    cmdArgv[cmdArgc]=(char *)malloc(strlen(cmdArgv[0])+16);
	    strncpy(cmdArgv[cmdArgc],cmdArgv[0],strlen(cmdArgv[0])-4 );
	    strcat(cmdArgv[cmdArgc],".sdlbas\0");
#endif
	    if (!pushIncludeFile( cmdArgv[cmdArgc], 0 )){
		ePrintf( Init, "File not found\n");
		return -1;
	    }
	}

	/* shift args over by 1 */
        cmdArgc++;
        for ( i = cmdArgc; i > 0; i-- ) {
            cmdArgv[i] = cmdArgv[i-1];
        }
        /* first arg is "sdlbrt" */
        strcpy(cmdArgv[0] ,"sdlBrt" );
    }
    else{
	if(cmdArgc>1){
	    if (!fileExist(cmdArgv[1]) ){
		ePrintf( Init,"%s: file not found ....\n",cmdArgv[1]);
		exit(2);
	    }
	}
	/* load the file */
	if (!pushIncludeFile( cmdArgv[1], 0 )) {
	    ePrintf( Init, "File not found\n");
	    return -1;
	}
    }

    /* parse the file */
    yyparse();

    /* deferred? */
    if (deferredCode != NULL) {
        eval( deferredCode );
        freeNode( deferredCode );
    }
    return 0;
}

//____________________________________________________________________________________________________________________

int main(int argc, char **argv)
{
    int r,r1;
    char *curdir;
    int audio,socket,debug,defaults;


    /* default settings */
    audio=1;
    socket=1;
    defaults=1;
    debug=0;

    remove("sdlBasic.err");

    /* the command line param */
    r1=0;
    for (r=0;r<argc;r++){
	cmdArgv[r1]=eCopyString(argv[r]);
#ifdef UNIX
	if (strcasecmp(cmdArgv[r1],"--nodebug")==0)
	{
		printf("debugger disabled\n");
	    nodebug=1;
	}

	if (strcasecmp(cmdArgv[r1],"--nodefaults")==0)
	    defaults=0;
	if (strcasecmp(cmdArgv[r1],"--nosound")==0)
	    audio=0;
	if (strcasecmp(cmdArgv[r1],"--nosocket")==0)
	    socket=0;
	if (strcasecmp(cmdArgv[r1],"--debug")==0)
	    debug=1;
	if (strcasecmp(cmdArgv[r1],"--version")==0){
	    printf( "sdlBasic runtime(sdlBrt) release  %s\n", RELEASE);
	    exit(0);
	}
	if (strcasecmp(cmdArgv[r1],"--license")==0){
	    printf( "%s\n", LICENSE);
	    exit(0);
	}
	if (strcasecmp(cmdArgv[r1],"--copyright")==0){
	    printf(  "%s: see documentation for all contributors \n", COPYRIGHT);
	    exit(0);
	}
	if (strcasecmp(cmdArgv[r1],"--help")==0){
	    printf(  "sdlBasic runtime(sdlBrt) release  %s\n syntax: sdlBrt [option] foo.sdlbas \n Options:\n --nosound  : disable sound\n --nosocket : disable socket commands\n --nodefaults : disable creation of default display\n --debug    : start the program step by step\n --version  : software version\n --license  : license of software\n --copyright: credits of software\n --help     : this help\n",RELEASE );
	    exit(0);
	}
#else
	if (stricmp(cmdArgv[r1],"--nodefaults")==0)
	    defaults=0;
	if (stricmp(cmdArgv[r1],"--nosound")==0)
	    audio=0;
	if (stricmp(cmdArgv[r1],"--nosocket")==0)
	    socket=0;
	if (stricmp(cmdArgv[r1],"--debug")==0)
	    debug=1;
	if (stricmp(cmdArgv[r1],"--version")==0){
	    printf( "sdlBasic runtime(sdlBrt) release  %s\n", RELEASE);
	    exit(0);
	}
	if (stricmp(cmdArgv[r1],"--license")==0){
	    printf( "%s\n", LICENSE);
	    exit(0);
	}
	if (stricmp(cmdArgv[r1],"--copyright")==0){
	    printf(  "%s: see documentation for all contributors \n", COPYRIGHT);
	    exit(0);
	}
	if (strcasecmp(cmdArgv[r1],"--help")==0){
	    printf(  "sdlBasic runtime(sdlBrt) release  %s\n syntax: sdlBrt [option] foo.sdlbas \n Options:\n --nosound  : disable sound\n --nosocket : disable socket commands\n --nodefaults : disable creation of default display\n --debug    : start the program step by step\n --version  : software version\n --license  : license of software\n --copyright: credits of software\n --help     : this help\n",RELEASE );
	    exit(0);
	}
#endif
	if (cmdArgv[r1][0]!='-')
	    r1++;
	else
	    eFree(cmdArgv[r1]);
    }
    cmdArgc=r1;

    r=strlen(cmdArgv[0]);
#ifdef UNIX
    if (strncasecmp(cmdArgv[0]+(r-6),"sdlbrt",6)==0 ){
#else
    if (strnicmp(cmdArgv[0]+(r-10),"sdlbrt.exe",10)==0 || strnicmp(cmdArgv[0]+(r-6),"sdlbrt",6)==0 ){
#endif
	// if missing file name return a little message of the syntax
	if (cmdArgc <= 1) {
	   printf("sdlBasic runtime (sdlBrt) syntax: sdlBrt program.sdlbas\n");
	return 0;
	}
    }


    /*initializing SDLengine module */
    r=initialize(audio,socket,defaults);


/* gp2x Problem with allocation strings ??? */
#if defined(WIN32)
	fontPath=(char *)malloc(256);
	strcpy(fontPath,getenv("WINDIR"));
	strcat(fontPath,"\\fonts\\DejaVuSans.ttf\0");
	if (!fileExist(fontPath))fontPath=".\\DejaVuSans.ttf";
#else
	fontPath=(char *) malloc(256);
	strcpy(fontPath, font_prefix);
	strcat(fontPath,"/dejavu/DejaVuSans.ttf\0");
	if (!fileExist(fontPath))fontPath="./DejaVuSans.ttf";
#endif


/*
#if defined(WIN32)
	fontPath=(char *)malloc(256);
	strcpy(fontPath,getenv("WINDIR"));
	strcat(fontPath,"\\fonts\\DejaVuSans.ttf\0");
	if (!fileExist(fontPath))fontPath=".\\DejaVuSans.ttf";
#else
	fontPath=(char *) malloc(256);
	strcpy(fontPath,font_prefix);
	strcat(fontPath,"/dejavu/DejaVuSans.ttf\0");
	if (!fileExist(fontPath))fontPath="./DejaVuSans.ttf";
#endif
*/



    if (r != 0){
	ePrintf( Init,"error number %d. Please reinstall sdlBasic.\n",r);
	return -1;
    }
    /*initialize basic data function buffer */
    init_data();

    /* initialize lvldir */
    lvldir=0;

    /* initialize sistem memory bank */
    init_membank();

    if (cmdArgc<=1  ){
	cmdArgv[1]=cmdArgv[0];
    }
    /* autochange directory */
#ifdef UNIX
    if(cmdArgv[1][0]=='/'){
	r=strlen(cmdArgv[1]);
	curdir=(char *)malloc(r+1);
	while(cmdArgv[1][r]!='/')r--;
	strncpy(curdir,cmdArgv[1],r);
	chdir(curdir);
    }
#else
    if(cmdArgv[1][2]=='\\'){
	r=strlen(cmdArgv[1]);
	curdir=(char *)malloc(r+1);
	while(cmdArgv[1][r]!='\\')r--;
	strncpy(curdir,cmdArgv[1],r);
	chdir(curdir);
    }
#endif

    /* starting interpreter */
    r= interpret(cmdArgc, cmdArgv);
    /* terminate SDLengine */
    terminate();
    return r;
}
Ejemplo n.º 5
0
/* setDynamicValue: set cell at index to value on stack */
void setDynamicValue( Array *array, Symbol *s )
{
    int         index, hi, lo, isNew, c;
    char        *key;
    Variant     *stackData;
    ArrayCell   *cell;

    /* make sure there is a value to set */
    if (tos == 0) {
        ePrintf( Runtime, "setDynamicValue: stack underflow" );
    }

    /* create the key */
    key = buildKey( array, s );

    /* assume it will be a new key */
    isNew = 1;

    /* binary search */
    lo = 0;
    hi = array->lower[0]-1;
    index = 0;
    while (lo <= hi) {
        index = floor((lo + hi) / 2);
        cell = array->data.cell+index;
        c = strcmp( key, cell->key );
        if (c < 0) {
            hi = index - 1;
        } else if (c > 0) {
            lo = index + 1;
        } else {
            /* found prior key */
            isNew = 0;
            break;
        }
    }

    /* no prior key? */
    if (isNew) {
        /* create empty cell */
        index = lo;
        insertDynamicCell( array, index );

    }

    /* address of cell */
    cell = array->data.cell + index;

    /* need to set key? */
    if (isNew) {
        /* use key (already unique copy) */
        cell->key = key;
    } else {
        /* don't need key */
        eFree( key );

        /* clean up old value */
        if (cell->data.datatype == DATA_STRING) {
            eFree( cell->data.value.string );
        }

    }

    /* resolve datatype */
    stackData = getStackPointer( tos );
    cell->data.datatype = stackData->datatype;

    if (stackData->datatype == DATA_STRING) {
        /* ref? */
        if (stack[tos].datatype == DATA_REF) {
            /* need to make a unique copy */
            cell->data.value.string = eCopyString( stackData->value.string );
        } else {
            /* use directly */
            cell->data.value.string = stackData->value.string;
        }

    } else if (stackData->datatype == DATA_NUMBER) {
            cell->data.value.number = stackData->value.number;

    } else {
        /* oops */
        ePrintf( Runtime, "Can't assign %s to a Dynamic Array",
            datumName[stackData->datatype] );

    }
    tos--;
}