void vfu_load_dir_colors() { #ifdef _TARGET_UNIX_ VArray va; va.fload( "/etc/DIR_COLORS" ); if (va.count() == 0) return; while( va.count() ) { VString str = va[0]; va.del( 0 ); int comment = str_find( str, '#' ); if ( comment != -1 ) str_sleft( str, comment ); str_cut( str, " \t" ); if ( str_len( str ) == 0 ) continue; if ( strncmp( str, "TERM " , 5 ) == 0 ) continue; if ( strncmp( str, "COLOR " , 6 ) == 0 ) continue; if ( strncmp( str, "OPTIONS ", 8 ) == 0 ) continue; int pos = -1; if ( str_find( str, "31" ) != -1 ) pos = cRED; else if ( str_find( str, "32" ) != -1 ) pos = cGREEN; else if ( str_find( str, "33" ) != -1 ) pos = cYELLOW; else if ( str_find( str, "34" ) != -1 ) pos = cBLUE; else if ( str_find( str, "35" ) != -1 ) pos = cMAGENTA; else if ( str_find( str, "36" ) != -1 ) pos = cCYAN; else if ( str_find( str, "37" ) != -1 ) pos = cWHITE; else ; int spc = str_find( str, ' ' ); if ( spc == -1 || pos == -1 ) continue; str_sleft( str, spc ); str_replace( str, "DIR", ".[].<>" ); str_replace( str, "LINK", ".->" ); str_replace( str, "FIFO", ".()" ); str_replace( str, "SOCK", ".##" ); str_replace( str, "BLK", ".==" ); str_replace( str, "CHR", ".++" ); str_replace( str, "EXEC", ".**" ); str_ins( ext_colors[pos], 0, str ); }; for ( int z = 0; z < 16; z++ ) if( str_len( ext_colors[z] ) > 0 ) { ext_colors[z] += "."; if ( opt.lower_case_ext_config ) str_low( ext_colors[z] ); } #endif /* _TARGET_UNIX_ */ }
// returns the numerical location of str needle // from the start of the string long strstrl(char *haystack, char *needle) { long x; if (!strstr(haystack,needle)) // no needle there. return -1; for (x = 0; x < strlen(haystack); x++) { if (needle[0] == haystack[x]) { if (!strcmp(needle,str_cut(x+1,strlen(needle),haystack))) return x; } } return -1; }
void gen_new_token(t_info *info) { char **token; int y; int x; int i; y = info->token.tok_y; i = 0; token = (char **)malloc(sizeof(char *) * (info->token.tok_y_b - y + 1)); while (y < info->token.tok_y_b + 1) { x = info->token.tok_x; token[i] = str_cut(info->token.map[y], x, info->token.tok_x_b + 1); y++; i++; } free_grid(&info->token); info->token.map = token; info->token.x = info->token.tok_x_b - info->token.tok_x + 1; info->token.y = info->token.tok_y_b - info->token.tok_y + 1; }
void vfu_read_archive_files( int a_recursive ) { char line[2048] = ""; struct stat st; memset( &st, 0, sizeof(st)); if ( a_recursive ) archive_path = ""; /* cannot have path when recursing archive */ VString s; s = "rx_auto "; s += ( a_recursive ) ? "v \"" : "l \""; s += archive_name; s += "\" \""; s += archive_path; s += "\" 2> /dev/null"; /* NOTE: calling rx_* should be safe and result should be proper all bugs must be traced outside VFU ... */ FILE *f = popen( s, "r" ); s = ""; if ( !f ) { say2( "Archive cannot be recognized or cannot be read" ); } else while( fgets(line, 2048-1, f) ) { str_cut( line, "\n\r" ); if ( strncmp( line, "NAME:", 5 ) == 0 ) { s = line+5; if ( str_get_ch( s, -1 ) == '/' ) /* i.e. last char */ { str_trim_right( s, 1 ); st.st_mode |= S_IFDIR; } /* FIXME: my man page for stat() says S_IFDIR is not POSIX?! */ } else if ( strncmp( line, "SIZE:", 5 ) == 0 ) { st.st_size = atoi( line+5 ); } else if ( strncmp( line, "TIME:", 5 ) == 0 ) { struct tm t; memset( &t, 0, sizeof(t) ); VRegexp r( "^(....)(..)(..)(..)(..)(..)?" ); r.m( line + 5 ); t.tm_year = atoi( r[1] ) - 1900; //r[0] is whole t.tm_mon = atoi( r[2] ) - 1; t.tm_mday = atoi( r[3] ); t.tm_hour = atoi( r[4] ); t.tm_min = atoi( r[5] ); t.tm_sec = atoi( r[6] ); //for (int x=0;x<7; x++) printf( "%s ", (const char *)r[x]); st.st_mtime = st.st_ctime = st.st_atime = mktime( &t ); //printf( "%d \n", st.st_atime); } else if ( line[0] == 0 ) { if ( str_len( s ) > 0 ) vfu_add_file( s, &st, 0 ); /* FIXME: there's no links for now */ s = ""; memset( &st, 0, sizeof(st) ); } } pclose( f ); };
void debugger() { char cmd[8]; char subcmd[256]; char *subopt1; char *subopt2; int chr_check_result; int sublen; int opt = 0; int menu = 1; while(menu) { memset(cmd,0,sizeof(cmd)); memset(subcmd,0,sizeof(subcmd)); printf("\n"); printf("LameNES debugger command>"); if(fgets(cmd, 5,stdin) != NULL) { if(cmd[0] != '\0' && cmd[strlen(cmd) - 1] == '\n') cmd[strlen(cmd) - 1] = '\0'; } switch(cmd[0]) { case 'b': printf("\nenter breakpoint: 0x"); if(fgets(subcmd, 7,stdin) != NULL) { if(subcmd[0] != '\0' && subcmd[strlen(subcmd) - 1] == '\n') subcmd[strlen(subcmd) - 1] = '\0'; } sublen = strlen(subcmd); if(sublen > 5) { printf("error: address range must be between 0x0000 and 0xFFFF\n"); } else { chr_check_result = str_chrchk(subcmd,"0123456789abcdef"); if((chr_check_result > 0) && (strlen(subcmd) == chr_check_result)) { breakpoint = strtoul(subcmd, NULL, 16); } else { printf("error: unknown memory address given!\n"); } } break; case 'c': printf("continue with emulation!\n"); hit_break = 0; disassemble = 0; menu = 0; break; case 'd': if(stackdebug == 1) { printf("stack debugging disabled!\n"); stackdebug = 0; } else { printf("stack debugging enabled!\n"); stackdebug = 1; } break; case 'f': printf("[%d] ppu_control1: %x\n",debug_cnt,ppu_control1); printf("[%d] ppu_control2: %x\n",debug_cnt,ppu_control2); printf("[%d] ppu_status: %x\n",debug_cnt,ppu_status); printf("[%d] ppu_status_ret: %x\n",debug_cnt,(ppu_status & 0xE0) | (ppu_addr_tmp & 0x1F)); printf("[%d] current scanline: %d\n",debug_cnt,current_scanline); printf("[%d] current nametable: %x\n",debug_cnt,0x2000 + (loopyV & 0x0fff)); printf("[%d] loopyT: %x\n",debug_cnt,loopyT); printf("[%d] loopyV: %x\n",debug_cnt,loopyV); printf("[%d] loopyX: %x\n",debug_cnt,loopyX); printf("[%d] exec_nmi_on_vblank: %x\n",debug_cnt,exec_nmi_on_vblank); printf("[%d] sprite_16: %d\n",debug_cnt,sprite_16); printf("[%d] background_addr_hi: %x\n",debug_cnt,background_addr_hi); printf("[%d] sprite_addr_hi: %d\n",debug_cnt,sprite_addr_hi); printf("[%d] increment_32: %d\n",debug_cnt,increment_32); printf("[%d] sprite_on: %d\n",debug_cnt,sprite_on); printf("[%d] background_on: %d\n",debug_cnt,background_on); printf("[%d] sprite_clipping_off: %d\n",debug_cnt,sprite_clipping_off); printf("[%d] background_clipping_off: %d\n",debug_cnt,background_clipping_off); printf("[%d] monochrome_on: %d\n",debug_cnt,monochrome_on); printf("[%d] vblank_on: %d\n",debug_cnt,vblank_on); printf("[%d] sprite_zero: %d\n",debug_cnt,sprite_zero); printf("[%d] scanline_sprite_count: %d\n",debug_cnt,scanline_sprite_count); printf("[%d] vram_write_flag: %d\n",debug_cnt,vram_write_flag); break; case 'h': printf("------------------------------\n"); printf("LameNES debugger command list:\n"); printf("------------------------------\n"); printf("(b)reakpoint -> set breakpoint\n"); printf("(c)ontinue -> continue emulation\n"); printf("(d)ebug stack operations -> enable/disable stack debugging\n"); printf("(i)nstruction counter break -> set instruction counter breakpoint\n"); printf("(f)lags states -> show all states of current flags\n"); printf("(h)elp -> this screen\n"); printf("(l)oad state -> loads emulation state\n"); printf("(m)emorydump -> show or dump the complete nes memory\n"); printf("(p)pu status -> show ppu status\n"); printf("(q)uit -> quit LameNES\n"); printf("(s)ave state -> saves emulation state\n"); printf("(u)pdate controller io -> send joypad1 io\n"); printf("(anything else) -> executes the next instruction\n"); break; case 'i': printf("\nenter instruction counter breakpoint: "); if(fgets(subcmd, 255,stdin) != NULL) { if(subcmd[0] != '\0' && subcmd[strlen(subcmd) - 1] == '\n') subcmd[strlen(subcmd) - 1] = '\0'; } sublen = strlen(subcmd); if(sublen > 255) { printf("error: counter too large!\n"); } else { stop_at_debug_cnt = atoi(subcmd); } break; case 'l': load_state(); break; case 'm': printf("memory options:\n" "m <memory address> -> display main ram from given address + next 100 bytes\n" "p <memory address> -> display ppu ram from given address + next 100 bytes\n" "s <memory address> -> display sprite ram from given address + next 100 bytes\n" "a -> dump all memory registers to bin files\n" "enter option: " ); if(fgets(subcmd, 255,stdin) != NULL) { if(subcmd[0] != '\0' && subcmd[strlen(subcmd) - 1] == '\n') subcmd[strlen(subcmd) - 1] = '\0'; } sublen = strlen(subcmd); if(sublen > 10) { printf("error: option string too large\n"); break; } switch(subcmd[0]) { case 'a': printf("dumping main memory to: lamenes_nesmem.bin\n"); dump_mem("lamenes_nesmem.bin"); printf("dumping ppu memory to: lamenes_ppumem.bin\n"); dump_ppu_mem("lamenes_ppumem.bin"); printf("dumping sprite memory to: lamenes_spritemem.bin\n"); dump_sprite_mem("lamenes_spritemem.bin"); printf("dumping nametables to: lamenes_nametables.bin\n"); dump_ppu_nam("lamenes_nametables.bin"); printf("dumping palette to: lamenes_palette.bin\n"); dump_ppu_palette("lamenes_palette.bin"); printf("dumping main ram to: lamenes_nesram.bin\n"); dump_nesram("lamenes_nesram.bin"); printf("dumping ppu ram to: lamenes_ppuram.bin\n"); dump_ppuram("lamenes_ppuram.bin"); printf("dumping stack to: lamenes_stackdump.bin\n"); dump_stack("lamenes_stackdump.bin"); break; case 'm': subopt1 = str_cut(subcmd," "); subopt2 = str_cut(NULL," "); chr_check_result = str_chrchk(subopt2,"0123456789abcdef"); if((chr_check_result > 0) && (strlen(subopt2) == chr_check_result)) { opt = strtoul(subopt2, NULL, 16); show_mem("main",opt); } else { printf("error: unknown memory address given!\n"); } break; case 'p': subopt1 = str_cut(subcmd," "); subopt2 = str_cut(NULL," "); chr_check_result = str_chrchk(subopt2,"0123456789abcdef"); if((chr_check_result > 0) && (strlen(subopt2) == chr_check_result)) { opt = strtoul(subopt2, NULL, 16); show_mem("ppu",opt); } else { printf("error: unknown memory address given!\n"); } break; case 's': subopt1 = str_cut(subcmd," "); subopt2 = str_cut(NULL," "); chr_check_result = str_chrchk(subopt2,"0123456789abcdef"); if((chr_check_result > 0) && (strlen(subopt2) == chr_check_result)) { opt = strtoul(subopt2, NULL, 16); show_mem("sprite",opt); } else { printf("error: unknown memory address given!\n"); } break; default: break; } break; case 'p': printf("ppu status options:\n" "(s)prite attributes -> display current sprite attributes\n" "enter option: " ); if(fgets(subcmd, 255,stdin) != NULL) { if(subcmd[0] != '\0' && subcmd[strlen(subcmd) - 1] == '\n') subcmd[strlen(subcmd) - 1] = '\0'; } sublen = strlen(subcmd); if(sublen > 10) { printf("error: option string too large\n"); break; } switch(subcmd[0]) { case 's': show_sprite_attribs(); break; default: break; } break; case 'q': quit_emulation(); break; case 's': save_state(); break; case 'u': printf("\nchoose the following joypad1 oi command to send:\n" "1 -> down\n" "2 -> up\n" "3 -> left\n" "4 -> right\n" "5 -> start\n" "6 -> select\n" "7 -> A\n" "8 -> B\n" "enter selection: "); if(fgets(subcmd, 2,stdin) != NULL) { if(subcmd[0] != '\0' && subcmd[strlen(subcmd) - 1] == '\n') subcmd[strlen(subcmd) - 1] = '\0'; } sublen = strlen(subcmd); if(sublen > 2) { printf("error: too many arguments!\n"); break; } chr_check_result = str_chrchk(subcmd,"12345678"); if((chr_check_result > 0) && (strlen(subcmd) == chr_check_result)) { opt = atoi(subcmd); switch(opt) { /* down */ case 1: printf("sending joypad1 [down] to io.\n"); set_input(1); break; /* up */ case 2: printf("sending joypad1 [up] to io.\n"); set_input(2); break; /* left */ case 3: printf("sending joypd1 [left] to io.\n"); set_input(3); break; /* right */ case 4: printf("sending joypad1 [right] to io.\n"); set_input(4); break; /* start */ case 5: printf("sending joypad1 [start] to io.\n"); set_input(5); break; /* select */ case 6: printf("sending joypad1 [select] to io.\n"); set_input(6); break; /* A */ case 7: printf("sending joypad1 [A] to io.\n"); set_input(7); break; /* B */ case 8: printf("sending joypad1 [B] to io.\n"); set_input(8); break; default: printf("error: unknown option!\n"); break; } } else { printf("error: wrong argument!\n"); } break; case 'v': printf("interrupt vectors:\n\n"); printf("INIT [0xfffc] -> 0x%x\n",(memory[0xfffd] << 8) | memory[0xfffc]); printf("IRQ [0xfffe] -> 0x%x\n",(memory[0xffff] << 8) | memory[0xfffe]); printf("NMI [0xfffa] -> 0x%x\n",(memory[0xfffb] << 8) | memory[0xfffa]); break; default: printf("executing next instruction!\n"); menu = 0; break; } } }
main() { char buf[20]; mt_clear(); login(); init(); fgets(buf,sizeof(buf_ini),stdin); //clear echon buffer while(1) { getcwd(prsnt_dirname,MAX_SIZE); //to decide prompt if(user_type == 0) printf("mt@linux:%s#",prsnt_dirname); else printf("mt@linux:%s$",prsnt_dirname); fgets(buf_ini,sizeof(buf_ini),stdin); buf_ini[strlen(buf_ini)-1]='\0'; str_cut(buf_ini,buf_cnv); if(strncmp(buf_ini,"exit",4)==0) { break; } else if(strncmp(buf_ini,"clear",5)==0) { mt_clear(); } else if(strncmp(buf_ini,"pwd",3)==0) { mt_pwd(prsnt_dirname); } else if(strncmp(buf_ini,"date",4)==0) { mt_date(); } else if(strncmp(buf_ini,"ls",2)==0) { mt_ls(prsnt_dirname,buf_cnv); } else if(strncmp(buf_ini,"cd",2)==0) { mt_cd(prsnt_dirname,buf_cnv); } else if(strncmp(buf_ini,"mkdir",5) == 0) { mt_mkdir(prsnt_dirname,buf_cnv); } else if(strncmp(buf_ini,"rmdir",5) == 0) { mt_rmdir(prsnt_dirname,buf_cnv); } else if(strncmp(buf_ini,"rm",2) == 0) { mt_rm(prsnt_dirname,buf_cnv); } else if(strncmp(buf_ini,"vi",2) == 0) //this function uses system call { mt_vi(buf_cnv); } else if(strncmp(buf_ini,"man",3) == 0) //manual page { mt_man(); } else { printf("Command Not Found\n"); } return(0); } void login() { user_type = mt_login(); judge_utype(); }
void vfu_settings_load() { VString str; user_externals.undef(); history.undef(); see_filters.undef(); panelizers.undef(); archive_extensions.undef(); path_bookmarks.undef(); /***** LOAD DEFAULTS *******/ memset( &opt, 0, sizeof( opt ) ); opt.svo.reset(); opt.seo.reset(); opt.seo.handle_tab = 1; opt.sort_order = 'N'; opt.sort_direction = 'A'; opt.sort_top_dirs = 1; opt.f_size = 1; opt.f_time = 1; opt.f_mode = 1; opt.f_group = 1; opt.f_owner = 1; opt.f_type = 1; opt.f_time_type = 1; opt.long_name_view = 0; opt.tree_compact = 0; opt.tree_cd = 1; opt.show_hidden_files = 1; opt.allow_beep = 1; opt.use_colors = 1; opt.use_dir_colors = 1; opt.lower_case_ext_config = 1; opt.copy_free_space_check = 1; opt.copy_calc_totals = 1; opt.copy_keep_mode = 1; opt.tag_mark_type = 0; opt.internal_browser = 1; opt.internal_editor = 1; opt.mask_auto_expand = 1; opt.shell_cls = 1; opt.zap_ro = 0; opt.show_user_free = 1; opt.menu_borders = 0; opt.lynx_navigation = 0; opt.auto_mount = 1; opt.keep_selection = 1; opt.bytes_freed = 1; opt.use_si_sizes = 0; opt.smart_home_end = 1; /***** LOAD DEFAULTS END ***/ FILE *fsett; Options tmp_opt; memset( &tmp_opt, 0, sizeof( tmp_opt ) ); if ( file_load_crc32( filename_opt, &tmp_opt, sizeof( tmp_opt ) ) == 0 ) memcpy( &opt, &tmp_opt, sizeof(Options) ); else say1( "warning: bad vfu.options file, loading defaults..." ); history.fload( filename_history ); if (getenv("EDITOR")) { shell_editor = getenv("EDITOR"); shell_editor += " %f"; } if (getenv("PAGER") ) { shell_browser = getenv("PAGER"); shell_browser += " %f"; } else if (getenv("BROWSER") ) { shell_browser = getenv("BROWSER"); shell_browser += " %f"; } else if (getenv("VIEWER") ) { shell_browser = getenv("VIEWER"); shell_browser += " %f"; } VRegexp re_ux("^\\s*u?x\\s*=\\s*([^,]*)[ \011]*,\\s*([^, \011]*)\\s*,\\s*([^, \011]*)\\s*,(.*)$", "i"); VRegexp re_see( "^\\s*see\\s*=\\s*([^, \011]*)\\s*,(.*)$", "i" ); VRegexp re_pan( "^\\s*panelize\\s*=\\s*([^,]*)\\s*,(.*)$", "i" ); char line[1024]; if ( (fsett = fopen( filename_conf, "r")) ) { while(fgets(line, 1024, fsett)) { if ( line[0] == '#' ) continue; if ( line[0] == ';' ) continue; str_cut( line, "\n\r" ); if ( strlen( line ) == 0 ) continue; if(set_str( line, "browser", shell_browser))continue; if(set_str( line, "pager", shell_browser))continue; if(set_str( line, "viewer", shell_browser))continue; if(set_arr( line, "archive", archive_extensions))continue; if(set_str( line, "editor", shell_editor))continue; if(set_str( line, "diff", shell_diff))continue; if(set_arr( line, "bookmark", path_bookmarks))continue; // follow 10 are deprecated /* if(set_arr( line, "bookmark1", path_bookmarks))continue; if(set_arr( line, "bookmark2", path_bookmarks))continue; if(set_arr( line, "bookmark3", path_bookmarks))continue; if(set_arr( line, "bookmark4", path_bookmarks))continue; if(set_arr( line, "bookmark5", path_bookmarks))continue; if(set_arr( line, "bookmark6", path_bookmarks))continue; if(set_arr( line, "bookmark7", path_bookmarks))continue; if(set_arr( line, "bookmark8", path_bookmarks))continue; if(set_arr( line, "bookmark9", path_bookmarks))continue; */ /* if(set_str( line, "cblack" , ext_colors[0]); */ if(set_str( line, "cgreen" , ext_colors[cGREEN]))continue; if(set_str( line, "cred" , ext_colors[cRED]))continue; if(set_str( line, "ccyan" , ext_colors[cCYAN]))continue; if(set_str( line, "cwhite" , ext_colors[cWHITE]))continue; if(set_str( line, "cmagenta" , ext_colors[cMAGENTA]))continue; if(set_str( line, "cblue" , ext_colors[cBLUE]))continue; if(set_str( line, "cyellow" , ext_colors[cYELLOW]))continue; if(set_str( line, "chblack" , ext_colors[chBLACK]))continue; if(set_str( line, "chgreen" , ext_colors[chGREEN]))continue; if(set_str( line, "chred" , ext_colors[chRED]))continue; if(set_str( line, "chcyan" , ext_colors[chCYAN]))continue; if(set_str( line, "chwhite" , ext_colors[chWHITE]))continue; if(set_str( line, "chmagenta", ext_colors[chMAGENTA]))continue; if(set_str( line, "chblue" , ext_colors[chBLUE]))continue; if(set_str( line, "chyellow" , ext_colors[chYELLOW]))continue; if(set_splitter( line, "trimtree", trim_tree ))continue; /* following code is used to clean input data */ if( re_ux.m( line ) ) { str = ""; str = str + re_ux[1] + ","; /* get description */ str = str + re_ux[2] + ","; /* get key name */ VString t = re_ux[3]; /* get extensions */ if ( t != "*" && t[-1] != '.' ) t += "."; str = str + t + ","; str += re_ux[4]; /* get shell line */ user_externals.push( str ); continue; } else if( re_see.m( line ) ) { str = ""; see_filters.push( str + re_see[1] + "," + re_see[2] ); continue; } else if( re_pan.m( line ) ) { str = ""; panelizers.push( str + re_see[1] + "," + re_see[2] ); continue; } } fclose(fsett); } #ifdef _TARGET_GO32_ int z; for ( z = 0; z < 16; z++ ) str_low( ext_colors[z] ); #endif if (opt.use_dir_colors) vfu_load_dir_colors(); // if (file_load_crc32( filename_size_cache, &size_cache, sizeof(size_cache))) // memset( &size_cache, 0, sizeof(size_cache) ); size_cache.undef(); size_cache.fload( filename_size_cache ); }