int exec_parsed(){ // Execs a parsed command line. int error=0,i,got=-1,n; // Now execute the command. if(parse_nwords!=0){ // Search for a matching known command. for(i=0;i<max_cmds;i++){ if(strcmp(con_cmds[i].name,parse_words[0])==0){ got=i; } } if(got>=0){ // Make sure that we have the correct number of arguments for a command. if(con_cmds[got].type=='C'){ if(parse_nwords!=con_cmds[got].max+1){ got=-2; } } // If we have a variable, deal with it here. else{ // No arguments means view the variable. if(parse_nwords==1){ view_variable(got); got=1000; } // One argument means set the variable. if(parse_nwords==2){ // Find the value to set the variable to. if(con_cmds[got].type=='F'){ // It's a FIXED variable. n=ftofix(atof(parse_words[1])); } if(con_cmds[got].type=='I'){ // It's an INT. n=atoi(parse_words[1]); } if(con_cmds[got].type=='S'){ // It's a string. internal_setstring(con_cmds[got].s_mirror,parse_words[1]); } else{ // Put the value within limits. if(n<con_cmds[got].min){n=con_cmds[got].min;} if(n>con_cmds[got].max){n=con_cmds[got].max;} // Set the mirror to the value. con_cmds[got].mirror=n; } } // If we don't have one or two arguments, then its an error. if(parse_nwords>2){ got=-2; } } } // Execute an actual command, or set a given variable. switch(got){ case -1: internal_error();break; case 0: cmd_clear();break; case 1: player_crosshair=n;break; case 2: player_crosshair_color=n;break; case 3: cmd_dir();break; case 4: cmd_disconnect();break; case 5: cmd_exec();break; case 6: player_floors=n;break; case 7: player_fov_degrees=fixtof(n);break; case 8: player_fps=n;break; case 9: player_gamma=n;cmd_gamma();break; case 10: player_gfx_mode=n;cmd_gfx_mode();break; case 11: cmd_gfx_modes();break; case 12: player_heightfix=n;break; case 13: player_invert=n;break; case 14: light_con=n;break; case 15: light_depth=fixtof(n);break; case 16: cmd_loopdemo();break; case 17: cmd_map();break; case 18: cmd_mapinfo();break; case 19: player_map_rotate=n;break; case 20: player_map=n;break; case 21: player_map_size=n;break; case 22: cmd_mem();break; case 23: internal_setstring(player_pic_con,parse_words[1]); cmd_pic_con();break; case 24: cmd_playdemo();break; case 25: cmd_pwad();break; case 26: cmd_quit();break; case 27: cmd_recdemo();break; case 28: player_r_grad=n;break; case 29: player_r_gun=n;break; case 30: cmd_stop();break; case 31: cmd_syntax();break; case 32: cmd_time();break; case 33: cmd_timerefresh();break; case 34: player_trace=1;break; case 35: cmd_viewpic();break; case 36: cmd_viewtex();break; case 37: player_vsync=n;break; case 38: cmd_wads();break; case 39: player_walls=n;break; case 40: player_windowsize=n;break; } } // Return the error value. DEBUG: Do we use this? return(error); }
int main(void) { /* int c = 0;*/ /* int i = 0;*/ /* int data = 0;*/ /* IntVector *vec;*/ /* IntList *lst;*/ /* INTR_DISABLE;*/ init(); /* INTR_ENABLE;*/ puts("Hello, World!\n"); /* printval();*/ /* puts("overwrite variables.\n");*/ /* global_data++;*/ /* global_bss++;*/ /* static_data++;*/ /* static_bss++;*/ /* printval();*/ cmd_map(); #if 0 vec = IntVector_new(); /* lst = IntList_new();*/ while (1) { static char buf[32]; char *p; PRINTF0(">"); gets(buf, sizeof buf); p = strpbrk(buf, "\r\n"); if (p) *p = '\0'; PRINTF1("%s\n", buf); if (sw_is_on(SW1)) { led_on(LED1); i++; if (i > 100) { i = 0; if (IntVector_push_back(vec, data)) { PRINTF1("IntVector_push_back: %d", data); /* putdval(data, 0);*/ data++; PRINTF1(", IntVector_size: %d\n", IntVector_size(vec)); /* putdval(IntVector_size(vec), 0);*/ /* puts("\n");*/ } else { puts("IntVector_push_back: failed\n"); puts("IntVector_capacity: "); putdval(IntVector_capacity(vec), 0); puts(", IntVector_size: "); putdval(IntVector_size(vec), 0); puts("\n"); } } } else { led_off(LED1); } if (sw_is_on(SW2)) { if (!IntVector_empty(vec)) { puts("IntVector_back: "); putdval(*IntVector_back(vec), 0); puts(", IntVector_pop_back"); IntVector_pop_back(vec); puts("\n"); } } if (sw_is_on(SW5_8)) { led_on(LED2); } else { led_off(LED2); } if (sw_is_on(SW3)) { putxval(c++, 0); puts("\n"); } if (sw_is_on(SW4)) { putdval(c++, 0); puts("\n"); } } #endif return 0; }
int main( int argc, char ** argv ) { char path[_MAX_PATH]; char buffer[ MAX_COMMAND_LINE + 2 ] = { (char)MAX_COMMAND_LINE }; /* Used with _cgets() - maximum number of characters in must be set in 1st byte */ int _argc; char * _argv[ MAX_ARGS ], * result, * fullpath; int archive_handle = -1; /* last attached archive */ int i, cmd; if( !ResInit( NULL )) return( 1 ); /* ResInit failed */ /* these would be called after parsing an .ini file or similar */ IF_DEBUG( ResDbgLogOpen( "resource.log" )); print_heading(); _getcwd( path, _MAX_PATH ); printf( "PATH: %s\n", path ); do { do { #if( !RES_USE_FLAT_MODEL ) printf( "\n%s> ", GLOBAL_CURRENT_PATH ); #else printf( "\nRoot > " ); #endif _getcwd( path, _MAX_PATH ); printf( "[SD: %s]>", path ); result = GETS( buffer ); /* Input a line of text */ } while( !buffer[1] ); if( !stricmp( result, "exit" )) break; _argc = parse_args( result, _argv ); cmd = COMMAND_ERROR; for( i=0; i<COMMAND_COUNT; i++ ) { if( !stricmp( result, command[i] )) { cmd = i; break; } } if( cmd == COMMAND_EXIT && !_argc ) break; if( _argc > 1 ) { if( !stricmp( _argv[1], "?" ) || !stricmp( _argv[1], "help" )) { show_help( cmd ); continue; } else if( strchr( _argv[1], ASCII_BACKSLASH )) { res_fullpath( path, _argv[1], _MAX_PATH ); fullpath = path; } else fullpath = _argv[1]; } switch( cmd ) { case COMMAND_DIR: #if( RES_USE_FLAT_MODEL ) printf( "This function is only meaningful when using the hierarchical model.\n" ); break; #endif if( _argc > 1 ) cmd_dir( _argv[1] ); else cmd_dir( NULL ); break; case COMMAND_ANALYZE: { #if( !RES_USE_FLAT_MODEL ) HASH_ENTRY * entry; if( _argc == 1 ) entry = hash_find( GLOBAL_CURRENT_PATH, GLOBAL_HASH_TABLE ); else entry = hash_find( fullpath, GLOBAL_HASH_TABLE ); if( entry ) { #if( RES_DEBUG_VERSION ) if( entry -> dir ) dbg_analyze_hash( (HASH_TABLE *)entry -> dir ); else printf( "No directory table for this directory.\n" ); #endif /* RES_DEBUG_VERSION */ } else printf( "Directory not found.\n" ); #else printf( "This command only meaningful when using the hierarchical model!\n" ); #endif break; } case COMMAND_RUN: cmd_run( _argc, _argv ); break; case COMMAND_CD: if( _argc > 1 ) { if( !ResSetDirectory( fullpath )) printf( "Error changing to directory %s\n", fullpath ); } else printf( "Current directory is: %s\n", GLOBAL_CURRENT_PATH ); break; case COMMAND_ADD: if( _argc > 1 ) { int test = FALSE, flag = -1; if( _argc > 2 ) flag = is_bool( _argv[2] ); if( flag == -1 ) flag = TRUE; if( !GLOBAL_SEARCH_INDEX ) test = ResCreatePath( fullpath, flag ); else test = ResAddPath( fullpath, flag ); if( !test ) printf( "Error adding %s to search path\n", fullpath ); } else show_help(cmd); break; case COMMAND_STREAM: { FILE * fptr; char c; int test; if( _argc < 2 ) { show_help(cmd); break; } fptr = fopen( _argv[1], "r" ); if( fptr ) { while( (test = fscanf( fptr, "%c", &c )) != EOF ) printf( "%c", c ); printf( "\n\n\n\n ************** REWINDING ****************** \n\n\n\n\n\n\n" ); fseek( fptr, 0, SEEK_SET ); while( (test = fscanf( fptr, "%c", &c )) != EOF ) printf( "%c", c ); fclose( fptr ); } else { printf( "Error opening file %s\n", _argv[1] ); } break; } case COMMAND_PATH: { int x=0; char b[_MAX_PATH]; if( GLOBAL_PATH_LIST ) { while( ResGetPath( x++, b )) printf( "%s\n", b ); } else printf( "No path created.\n" ); break; } case COMMAND_EXTRACT: { /* extracts the archive to the local directory with the same filename */ if( _argc < 3 ) show_help(cmd); else ResExtractFile( _argv[1], _argv[2] ); break; } case COMMAND_READ: if( _argc >= 2 ) cmd_read( _argv[1] ); else show_help(cmd); break; case COMMAND_ATTACH: { char dst[_MAX_PATH]; int flag = -1; if( _argc < 2 ) { show_help(cmd); break; } if( _argc >= 3 ) flag = is_bool( _argv[ _argc - 1 ] ); if( _argc >= 3 ) res_fullpath( dst, _argv[2], _MAX_PATH ); if( _argc == 2 ) archive_handle = ResAttach( GLOBAL_CURRENT_PATH, fullpath, FALSE ); else if( _argc == 3 ) { if( flag != -1 ) archive_handle = ResAttach( GLOBAL_CURRENT_PATH, fullpath, flag ); else archive_handle = ResAttach( fullpath, dst, FALSE ); } else if( _argc == 4 ) archive_handle = ResAttach( fullpath, dst, flag == -1 ? 0 : flag ); if( archive_handle == -1 ) printf( "Error attaching zip file %s\n", fullpath ); break; } case COMMAND_DUMP: ResDbgDump(); MemDump(); printf("\n"); MemFindLevels(); printf("\n"); MemFindUsage(); break; case COMMAND_DETACH: if( archive_handle != -1 ) { ResDetach( archive_handle ); archive_handle = -1; } else printf( "No archives currently attached.\n" ); break; case COMMAND_MAP: if( _argc < 2 ) show_help(cmd); else cmd_map( _argv[1] ); break; case COMMAND_FIND: if( _argc < 2 ) show_help(cmd); else cmd_find( fullpath ); break; case COMMAND_HELP: print_heading(); show_help(cmd); break; case COMMAND_ERROR: default: printf( "Syntax error\n" ); break; } } while( TRUE ); ResExit(); MemDump(); _getcwd( path, _MAX_PATH ); printf( "PATH: %s\n", path ); return(0); }