int m_cd(t_data *data) { char *pwd_asked; char *start_pwd; int ret; bool go_home; if (data->env == NULL || data->env[0] == NULL || data->env[1] == NULL) return (0); go_home = false; pwd_asked = data->cmd[1]; pwd_asked = set_home(data, &go_home, pwd_asked); if (data->old_pwd == NULL && pwd_asked[0] == '-') return (0); if (pwd_asked[0] == '-') pwd_asked = data->old_pwd; data->old_pwd = my_strdup(&data->pwd[4]); ret = chdir(pwd_asked); if (ret == 0) { start_pwd = data->pwd; change_path(data, pwd_asked, start_pwd, go_home); } else cannot_access(pwd_asked); return (0); }
int enter_dir(char* name) { int tmp = inode_num;//记录原始inode节点 char tmpPath[40], nameCopy[30]; char dst[30][NameLength]; strcpy(tmpPath, path); strcpy(nameCopy, name); int cnt = split(dst, nameCopy, "/"); if (name[0] == '/') {//从根目录开始 //printf("1111111111\n"); close_dir(inode_num); inode_num = 0; open_dir(inode_num); strcpy(path, "monitor@root:"); } for (int i = 0; i < cnt; i++) { //printf("%d\n", i); int res = enter_child_dir(inode_num, dst[i]); change_path(dst[i]); if (res == -1) { inode_num = tmp; open_dir(inode_num); strcpy(path, tmpPath); return -1; } } return 0; }
int main(int argc,char **argv) { GtkWidget *win; GtkWidget *button; GtkWidget *vbox; GtkWidget *hbox; GtkWidget *frame; IS_SELECT is_select; change_path(argv[0]); gtk_init(&argc,&argv); win=gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_window_set_position(GTK_WINDOW(win),GTK_WIN_POS_CENTER); gtk_window_set_title(GTK_WINDOW(win),"IScreenshot"); gtk_window_set_icon_from_file(GTK_WINDOW(win), "img/64x64/iscreenshot.png",NULL); g_signal_connect(G_OBJECT(win),"delete_event", G_CALLBACK(really_quit),NULL); init_data(&is_select,win); vbox=gtk_vbox_new(FALSE,0); gtk_container_add(GTK_CONTAINER(win),vbox); create_title_screen(vbox); frame=gtk_frame_new("Select"); hbox=gtk_hbox_new(FALSE,0); gtk_box_pack_start(GTK_BOX(vbox),frame,FALSE,FALSE,0); gtk_container_add(GTK_CONTAINER(frame),hbox); frame=gtk_frame_new("Region to capture"); gtk_box_pack_start(GTK_BOX(hbox),frame,FALSE,FALSE,0); create_radio_button(frame,&is_select); frame=gtk_frame_new("Delay before capturing"); gtk_box_pack_start(GTK_BOX(hbox),frame,FALSE,FALSE,0); create_select_time(frame,&is_select); hbox=gtk_hbox_new(FALSE,0); gtk_box_pack_start(GTK_BOX(vbox),hbox,FALSE,FALSE,0); button=gtk_button_new_from_stock(GTK_STOCK_OK); gtk_box_pack_end(GTK_BOX(hbox),button,FALSE,FALSE,10); g_signal_connect(G_OBJECT(button),"clicked", G_CALLBACK(screenshot),&is_select); button=gtk_button_new_from_stock(GTK_STOCK_CANCEL); gtk_box_pack_end(GTK_BOX(hbox),button,FALSE,FALSE,10); g_signal_connect(G_OBJECT(button),"clicked", G_CALLBACK(really_quit),NULL); gtk_widget_show_all(win); gtk_main(); }
void walking(char maze[23][30], int ghost[3], int target[2]) { int x,y; y = ghost[0]; x = ghost[1]; while (target[0] != ghost[0] || target[1] != ghost[1] ) { switch (ghost[2]) { case 1: y = y+1; break; case 2: x = x+1; break; case 3: y = y-1; break; case 4: x = x-1; break; } if (validate_position(maze, y, x)) { ghost[0] = y; ghost[1] = x; if (maze[y][x] != '7' && maze[y][x] != '8' ) { maze[y][x] = '3'; }else { if (maze[y][x] != '8') { change_path(maze,ghost,target); //neste momenro o ghost será atualizado com o melhor caminho da bifurcação } } }else { x = ghost[1]; y = ghost[0]; ghost[2] += 1; if (ghost[2] > 4) { ghost[2] = 1; } } } }
void odomCallBack(const nav_msgs::OdometryConstPtr &msg) { //Determinar posicao atual geometry_msgs::Point p; p.x = msg->pose.pose.position.x; p.y = msg->pose.pose.position.y; double d = calculateDistance(p,w2); if (d < CHANGEPATH_DISTANCE) { // ROS_INFO("mudei"); change_path(); } // ROS_INFO("%f",d); ROS_INFO("w1 = (%f,%f) w2 = (%f,%f)",w1.x,w1.y,w2.x,w2.y); w1_pub.publish(w1); w2_pub.publish(w2); }
int main(int argn ,char *argv[]) { char in[100]; while(1) { int n = strlen(para[0]); printf("%s->", para[0]); memset(in, 0, sizeof(in)); gets(in); int choice = explain(in); //根据命令解释器的返回结果执行相对应的命令 switch(choice) { case -1: printf("' %s '不是内部或外部命令,也不是可运行的程序\n或批处理文件。\n", in);break; case 0 : show_time();break; case 1 : show_version();break; case 2 : show_date();break; case 3 : clrscr(0, 0);break; case 4 : show_directory();break; case 5 : help();break; case 6 : show_current_tree(para[0], 0);break; case 7 : return 0; case 8 : print_text(para[0]);break; case 9 : if(del_dir(para[0]) == 0) del_files(para[0]);break;//如果para[0]是文件夹,则执行删除文件夹函数,否则执行文件删除函数 case 10 : creat_dir(para[0]);break; case 11 : rename_file(para[0], para[1]);break; case 12 : change_path(in);break; }//{"time", "version", "date", "cls", "dir", "help", "tree", "print", "del", "mkdir", "ren"}; if(choice != 12)//如果没有改变路径,则每次都把当前工作目录下的以外的其它字符清除 { memset(para[0] + n, 0, (100 - n) * sizeof(char)); memset(para[1] + n, 0, (100 - n) * sizeof(char)); } } return 0; }
int main() { User new_user; //初始化用户信息 new_user.username = "******"; new_user.password = "******"; user.push_back(new_user); string username; string password; string command; string subcommand; string temp_path; char t; init(); save(); SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_GREEN); cout << "welcome to system" << endl; cout << "please login" << endl; SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_BLUE|FOREGROUND_GREEN|FOREGROUND_RED); while (1) { username = ""; password = ""; cout << "username:"******"password:"******"username or password error" << endl; SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_BLUE|FOREGROUND_GREEN|FOREGROUND_RED); } } system("cls"); getline(cin, command); while (1) { SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_RED|FOREGROUND_BLUE); cout << username; SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_GREEN|FOREGROUND_RED); cout << "@filesystem "; SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_BLUE); if (path.size() == 1) cout << "/"; else { for (auto p : path) { if (p == 0) continue; cout << "/" << catalog[p].info.name; } } SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_BLUE|FOREGROUND_GREEN|FOREGROUND_RED); cout << endl << ">"; getline(cin, command); stringstream command_stream(command); command_stream >> subcommand; if (subcommand == "") { } else if (subcommand == "cd") { change_path(command); } else if (subcommand == "ls") { show_folder(command); } else if (subcommand == "create") { create(command); } else if (subcommand == "mkdir") { create_folder(command); } else if (subcommand == "delete") { delete_file(command); } else if (subcommand == "edit") { edit(command); } else if (subcommand == "search") { search_file(command); } else if (subcommand == "open") { open_file(command); } else if (subcommand == "close") { close_file(command); } else if (subcommand == "cp") { copy(command); } else if (subcommand == "mv") { move(command); } else if (subcommand == "bs"){ backstage(); } else if (subcommand == "l"){ l(); } else if (subcommand == "info"){ info(); } else if (subcommand == "format") { remove("disk.txt"); remove("diskdata.txt"); init(); } else { SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_RED); cout << "command not found" << endl; SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_BLUE|FOREGROUND_GREEN|FOREGROUND_RED); } cout << endl; save(); command = ""; subcommand = ""; } }
/* * Simple "main" function for multiple platforms. * * Note the special "--" option which terminates the processing of * standard options. All non-standard options (if any) are passed * directly to the "init_xxx()" function. */ int main(int argc, char *argv[]) { int i; bool done = FALSE; bool new_game = FALSE; int show_score = 0; cptr mstr = NULL; bool args = TRUE; /* Save the "program name" XXX XXX XXX */ argv0 = argv[0]; #ifdef USE_286 /* Attempt to use XMS (or EMS) memory for swap space */ if (_OvrInitExt(0L, 0L)) { _OvrInitEms(0, 0, 64); } #endif #ifdef SET_UID /* Default permissions on files */ (void)umask(022); # ifdef SECURE /* Authenticate */ Authenticate(); # endif #endif /* Get the file paths */ init_stuff(); #ifdef SET_UID /* Get the user id (?) */ player_uid = getuid(); #ifdef VMS /* Mega-Hack -- Factor group id */ player_uid += (getgid() * 1000); #endif # ifdef SAFE_SETUID # ifdef _POSIX_SAVED_IDS /* Save some info for later */ player_euid = geteuid(); player_egid = getegid(); # endif # if 0 /* XXX XXX XXX */ /* Redundant setting necessary in case root is running the game */ /* If not root or game not setuid the following two calls do nothing */ if (setgid(getegid()) != 0) { quit("setgid(): cannot set permissions correctly!"); } if (setuid(geteuid()) != 0) { quit("setuid(): cannot set permissions correctly!"); } # endif # endif #endif #ifdef SET_UID /* Initialize the "time" checker */ if (check_time_init() || check_time()) { quit("The gates to Angband are closed (bad time)."); } /* Initialize the "load" checker */ if (check_load_init() || check_load()) { quit("The gates to Angband are closed (bad load)."); } /* Acquire the "user name" as a default player name */ #ifdef ANGBAND_2_8_1 user_name(player_name, player_uid); #else /* ANGBAND_2_8_1 */ user_name(op_ptr->full_name, player_uid); #endif /* ANGBAND_2_8_1 */ #ifdef PRIVATE_USER_PATH /* Create a directory for the users files. */ create_user_dir(); #endif /* PRIVATE_USER_PATH */ #endif /* SET_UID */ /* Process the command line arguments */ for (i = 1; args && (i < argc); i++) { /* Require proper options */ if (argv[i][0] != '-') game_usage(); /* Analyze option */ switch (argv[i][1]) { case 'N': case 'n': { new_game = TRUE; break; } case 'F': case 'f': { arg_fiddle = TRUE; break; } case 'W': case 'w': { arg_wizard = TRUE; break; } case 'V': case 'v': { arg_sound = TRUE; break; } case 'G': case 'g': { /* HACK - Graphics mode switches on the original tiles */ arg_graphics = GRAPHICS_ORIGINAL; break; } case 'R': case 'r': { arg_force_roguelike = TRUE; break; } case 'O': case 'o': { arg_force_original = TRUE; break; } case 'S': case 's': { show_score = atoi(&argv[i][2]); if (show_score <= 0) show_score = 10; break; } case 'u': case 'U': { if (!argv[i][2]) game_usage(); #ifdef ANGBAND_2_8_1 strncpy(player_name, &argv[i][2], 32); player_name[31] = '\0'; #else /* ANGBAND_2_8_1 */ strncpy(op_ptr->full_name, &argv[i][2], 32); op_ptr->full_name[31] = '\0'; #endif /* ANGBAND_2_8_1 */ break; } case 'm': { if (!argv[i][2]) game_usage(); mstr = &argv[i][2]; break; } case 'M': { arg_monochrome = TRUE; break; } case 'd': case 'D': { change_path(&argv[i][2]); break; } case '-': { argv[i] = argv[0]; argc = argc - i; argv = argv + i; args = FALSE; break; } default: { /* Default usage-help */ game_usage(); } } } /* Hack -- Forget standard args */ if (args) { argc = 1; argv[1] = NULL; } /* Process the player name */ process_player_name(TRUE); /* Install "quit" hook */ quit_aux = quit_hook; /* * Drop privs (so X11 will work correctly) * unless we are running the Linux-SVGALib version. * * (In which case we initialize after safe_setuid_grab() * is called.) */ safe_setuid_drop(); #ifdef USE_XAW /* Attempt to use the "main-xaw.c" support */ if (!done && (!mstr || (streq(mstr, "xaw")))) { if (0 == init_xaw(argc, argv)) { ANGBAND_SYS = "xaw"; done = TRUE; } } #endif #ifdef USE_X11 /* Attempt to use the "main-x11.c" support */ if (!done && (!mstr || (streq(mstr, "x11")))) { if (0 == init_x11(argc, argv)) { ANGBAND_SYS = "x11"; done = TRUE; } } #endif #ifdef USE_XPJ /* Attempt to use the "main-xpj.c" support */ if (!done && (!mstr || (streq(mstr, "xpj")))) { if (0 == init_xpj(argc, argv)) { ANGBAND_SYS = "xpj"; done = TRUE; } } #endif #ifdef USE_GTK /* Attempt to use the "main-gtk.c" support */ if (!done && (!mstr || (streq(mstr, "gtk")))) { if (0 == init_gtk((unsigned char*) &new_game, argc, argv)) { done = TRUE; } } #endif #ifdef USE_GCU /* Attempt to use the "main-gcu.c" support */ if (!done && (!mstr || (streq(mstr, "gcu")))) { if (0 == init_gcu()) { ANGBAND_SYS = "gcu"; done = TRUE; } } #endif #ifdef USE_CAP /* Attempt to use the "main-cap.c" support */ if (!done && (!mstr || (streq(mstr, "cap")))) { if (0 == init_cap(argc, argv)) { ANGBAND_SYS = "cap"; done = TRUE; } } #endif #ifdef USE_DOS /* Attempt to use the "main-dos.c" support */ if (!done && (!mstr || (streq(mstr, "dos")))) { if (0 == init_dos()) { ANGBAND_SYS = "dos"; done = TRUE; } } #endif #ifdef USE_IBM /* Attempt to use the "main-ibm.c" support */ if (!done && (!mstr || (streq(mstr, "ibm")))) { if (0 == init_ibm()) { ANGBAND_SYS = "ibm"; done = TRUE; } } #endif #ifdef USE_EMX /* Attempt to use the "main-emx.c" support */ if (!done && (!mstr || (streq(mstr, "emx")))) { if (0 == init_emx()) { ANGBAND_SYS = "emx"; done = TRUE; } } #endif #ifdef USE_SLA /* Attempt to use the "main-sla.c" support */ if (!done && (!mstr || (streq(mstr, "sla")))) { if (0 == init_sla()) { ANGBAND_SYS = "sla"; done = TRUE; } } #endif #ifdef USE_AMI /* Attempt to use the "main-ami.c" support */ if (!done && (!mstr || (streq(mstr, "ami")))) { if (0 == init_ami()) { ANGBAND_SYS = "ami"; done = TRUE; } } #endif #ifdef USE_VME /* Attempt to use the "main-vme.c" support */ if (!done && (!mstr || (streq(mstr, "vme")))) { if (0 == init_vme()) { ANGBAND_SYS = "vme"; done = TRUE; } } #endif #ifdef USE_VCS /* Attempt to use the "main-vcs.c" support */ if (!done && (!mstr || (streq(mstr, "vcs")))) { if (0 == init_vcs(argc, argv)) { ANGBAND_SYS = "vcs"; done = TRUE; } } #endif /* USE_VCS */ /* Grab privs (dropped above for X11) */ safe_setuid_grab(); #ifdef USE_LSL /* Attempt to use the "main-lsl.c" support */ if (!done && (!mstr || (streq(mstr, "lsl")))) { if (0 == init_lsl()) { ANGBAND_SYS = "lsl"; done = TRUE; } } #endif /* Make sure we have a display! */ if (!done) quit("Unable to prepare any 'display module'!"); /* Hack -- If requested, display scores and quit */ if (show_score > 0) display_scores(0, show_score); /* Gtk initializes earlier */ if (!streq(ANGBAND_SYS, "gtk")) { /* Catch nasty signals */ signals_init(); /* Initialize */ init_angband(); } /* Wait for response */ pause_line(23); /* Play the game */ play_game(new_game); /* Quit */ quit(NULL); /* Exit */ return (0); }
/* * Simple "main" function for multiple platforms. * * Note the special "--" option which terminates the processing of * standard options. All non-standard options (if any) are passed * directly to the "init_xxx()" function. */ int main(int argc, char *argv[]) { int i; bool done = FALSE; bool new_game = FALSE; int show_score = 0; cptr mstr = NULL; bool args = TRUE; /* Save the "program name" XXX XXX XXX */ argv0 = argv[0]; #ifdef USE_286 /* Attempt to use XMS (or EMS) memory for swap space */ if (_OvrInitExt(0L, 0L)) { _OvrInitEms(0, 0, 64); } #endif #ifdef SET_UID /* Default permissions on files */ (void)umask(022); # ifdef SECURE /* Authenticate */ Authenticate(); # endif #endif /* Get the file paths */ init_stuff(); #ifdef SET_UID /* Get the user id (?) */ player_uid = getuid(); #ifdef VMS /* Mega-Hack -- Factor group id */ player_uid += (getgid() * 1000); #endif # ifdef SAFE_SETUID # ifdef _POSIX_SAVED_IDS /* Save some info for later */ player_euid = geteuid(); player_egid = getegid(); # endif # if 0 /* XXX XXX XXX */ /* Redundant setting necessary in case root is running the game */ /* If not root or game not setuid the following two calls do nothing */ if (setgid(getegid()) != 0) { quit("setgid(): cannot set permissions correctly!"); } if (setuid(geteuid()) != 0) { quit("setuid(): cannot set permissions correctly!"); } # endif # endif #endif /* Drop permissions */ safe_setuid_drop(); #ifdef SET_UID /* Initialize the "time" checker */ if (check_time_init() || check_time()) { quit("The gates to Angband are closed (bad time)."); } /* Initialize the "load" checker */ if (check_load_init() || check_load()) { quit("The gates to Angband are closed (bad load)."); } /* Acquire the "user name" as a default player name */ user_name(player_name, player_uid); #ifdef PRIVATE_USER_PATH /* Create a directory for the users files. */ create_user_dir(); #endif /* PRIVATE_USER_PATH */ #endif /* SET_UID */ /* Process the command line arguments */ for (i = 1; args && (i < argc); i++) { /* Require proper options */ if (argv[i][0] != '-') goto usage; /* Analyze option */ switch (argv[i][1]) { case 'N': case 'n': { new_game = TRUE; break; } case 'F': case 'f': { arg_fiddle = TRUE; break; } case 'W': case 'w': { arg_wizard = TRUE; break; } case 'V': case 'v': { arg_sound = TRUE; break; } case 'G': case 'g': { /* HACK - Graphics mode switches on the original tiles */ arg_graphics = GRAPHICS_ORIGINAL; break; } case 'R': case 'r': { arg_force_roguelike = TRUE; break; } case 'O': case 'o': { arg_force_original = TRUE; break; } case 'S': case 's': { show_score = atoi(&argv[i][2]); if (show_score <= 0) show_score = 10; break; } case 'u': case 'U': { if (!argv[i][2]) goto usage; strcpy(player_name, &argv[i][2]); break; } case 'm': { if (!argv[i][2]) goto usage; mstr = &argv[i][2]; break; } case 'M': { arg_monochrome = TRUE; break; } case 'd': case 'D': { change_path(&argv[i][2]); break; } case '-': { argv[i] = argv[0]; argc = argc - i; argv = argv + i; args = FALSE; break; } default: usage: { /* Dump usage information */ puts("Usage: angband [options] [-- subopts]"); puts(" -n Start a new character"); puts(" -f Request fiddle mode"); puts(" -w Request wizard mode"); puts(" -v Request sound mode"); puts(" -g Request graphics mode"); puts(" -o Request original keyset"); puts(" -r Request rogue-like keyset"); puts(" -M Request monochrome mode"); puts(" -s<num> Show <num> high scores"); puts(" -u<who> Use your <who> savefile"); puts(" -m<sys> Force 'main-<sys>.c' usage"); puts(" -d<def> Define a 'lib' dir sub-path"); puts(""); #ifdef USE_SDL puts(" -msdl To use SDL"); #endif /* USE_SDL */ #ifdef USE_X11 puts(" -mx11 To use X11"); puts(" -- Sub options"); puts(" -- -d Set display name"); puts(" -- -o Request old 8x8 tile graphics"); puts(" -- -a Request Adam Bolt 16x16 tile graphics"); puts(" -- -b Request Bigtile graphics mode"); puts(" -- -s Turn off smoothscaling graphics"); puts(" -- -n# Number of terms to use"); puts(""); #endif /* USE_X11 */ #ifdef USE_GCU puts(" -mgcu To use GCU (GNU Curses)"); #endif /* USE_GCU */ #ifdef USE_CAP puts(" -mcap To use CAP (\"Termcap\" calls)"); #endif /* USE_CAP */ #ifdef USE_DOS puts(" -mdos To use DOS (Graphics)"); #endif /* USE_DOS */ #ifdef USE_IBM puts(" -mibm To use IBM (BIOS text mode)"); #endif /* USE_IBM */ #ifdef USE_SLA puts(" -msla To use SLA (SLANG)"); #endif /* USE_SLA */ #ifdef USE_LSL puts(" -mlsl To use LSL (Linux-SVGALIB)"); #endif /* USE_LSL */ #ifdef USE_AMI puts(" -mami To use AMI (Amiga)"); #endif /* USE_AMI */ #ifdef USE_VME puts(" -mvme To use VME (VAX/ESA)"); #endif /* USE_VME */ /* Actually abort the process */ quit(NULL); } } } /* Hack -- Forget standard args */ if (args) { argc = 1; argv[1] = NULL; } /* Process the player name */ process_player_name(TRUE); /* Create any missing directories */ create_needed_dirs(); /* Install "quit" hook */ quit_aux = quit_hook; #ifdef USE_XAW /* Attempt to use the "main-xaw.c" support */ if (!done && (!mstr || (streq(mstr, "xaw")))) { extern errr init_xaw(int, char**); if (0 == init_xaw(argc, argv)) { ANGBAND_SYS = "xaw"; done = TRUE; } } #endif #ifdef USE_SDL /* Attempt to use the "main-sdl.c" support */ if (!done && (!mstr || (streq(mstr, "sdl")))) { extern errr init_sdl(int, char**); if (0 == init_sdl(argc, argv)) { ANGBAND_SYS = "sdl"; done = TRUE; } } #endif #ifdef USE_X11 /* Attempt to use the "main-x11.c" support */ if (!done && (!mstr || (streq(mstr, "x11")))) { extern errr init_x11(int, char**); if (0 == init_x11(argc, argv)) { ANGBAND_SYS = "x11"; done = TRUE; } } #endif #ifdef USE_GCU /* Attempt to use the "main-gcu.c" support */ if (!done && (!mstr || (streq(mstr, "gcu")))) { extern errr init_gcu(int, char**); if (0 == init_gcu(argc, argv)) { ANGBAND_SYS = "gcu"; done = TRUE; } } #endif #ifdef USE_CAP /* Attempt to use the "main-cap.c" support */ if (!done && (!mstr || (streq(mstr, "cap")))) { extern errr init_cap(int, char**); if (0 == init_cap(argc, argv)) { ANGBAND_SYS = "cap"; done = TRUE; } } #endif #ifdef USE_DOS /* Attempt to use the "main-dos.c" support */ if (!done && (!mstr || (streq(mstr, "dos")))) { extern errr init_dos(void); if (0 == init_dos()) { ANGBAND_SYS = "dos"; done = TRUE; } } #endif #ifdef USE_IBM /* Attempt to use the "main-ibm.c" support */ if (!done && (!mstr || (streq(mstr, "ibm")))) { extern errr init_ibm(void); if (0 == init_ibm()) { ANGBAND_SYS = "ibm"; done = TRUE; } } #endif #ifdef USE_EMX /* Attempt to use the "main-emx.c" support */ if (!done && (!mstr || (streq(mstr, "emx")))) { extern errr init_emx(void); if (0 == init_emx()) { ANGBAND_SYS = "emx"; done = TRUE; } } #endif #ifdef USE_SLA /* Attempt to use the "main-sla.c" support */ if (!done && (!mstr || (streq(mstr, "sla")))) { extern errr init_sla(void); if (0 == init_sla()) { ANGBAND_SYS = "sla"; done = TRUE; } } #endif #ifdef USE_LSL /* Attempt to use the "main-lsl.c" support */ if (!done && (!mstr || (streq(mstr, "lsl")))) { extern errr init_lsl(void); if (0 == init_lsl()) { ANGBAND_SYS = "lsl"; done = TRUE; } } #endif #ifdef USE_AMI /* Attempt to use the "main-ami.c" support */ if (!done && (!mstr || (streq(mstr, "ami")))) { extern errr init_ami(void); if (0 == init_ami()) { ANGBAND_SYS = "ami"; done = TRUE; } } #endif #ifdef USE_VME /* Attempt to use the "main-vme.c" support */ if (!done && (!mstr || (streq(mstr, "vme")))) { extern errr init_vme(void); if (0 == init_vme()) { ANGBAND_SYS = "vme"; done = TRUE; } } #endif /* Make sure we have a display! */ if (!done) quit("Unable to prepare any 'display module'!"); /* Hack -- If requested, display scores and quit */ if (show_score > 0) display_scores(0, show_score); /* Catch nasty signals */ signals_init(); /* Initialize */ init_angband(); /* Wait for response */ pause_line(23); /* Play the game */ play_game(new_game); /* Quit */ quit(NULL); /* Exit */ return (0); }
int main() { string username; string password; string command; string subcommand; string temp_path; char t; load_user(); init(); save(); while (1) { SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_GREEN); cout << "welcome to system" << endl; cout << "please login" << endl; SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED); while (1) { username = ""; password = ""; cout << "username:"******"password:"******"username or password error" << endl; SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED); } } system("cls"); getline(cin, command); while (1) { SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_BLUE); cout << username; SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_GREEN | FOREGROUND_RED); cout << "@filesystem "; SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_BLUE); if (path.size() == 1) cout << "/"; else { for (auto p : path) { if (p == 0) continue; cout << "/" << catalog[p].info.name; } } SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED); cout << endl << ">"; getline(cin, command); stringstream command_stream(command); command_stream >> subcommand; if (subcommand == "") { } else if (subcommand == "cd") { change_path(command); } else if (subcommand == "ls") { show_folder(command); } else if (subcommand == "create") { create(command); } else if (subcommand == "mkdir") { create_folder(command); } else if (subcommand == "delete") { delete_file(command); } else if (subcommand == "edit") { edit(command); } else if (subcommand == "search") { search_file(command); } else if (subcommand == "open") { open_file(command); } else if (subcommand == "close") { close_file(command); } else if (subcommand == "cp") { copy(command); } else if (subcommand == "mv") { move(command); } else if (subcommand == "bs"){ backstage(); } else if (subcommand == "l"){ l(); } else if (subcommand == "info"){ info(); } else if (subcommand == "format") { char c; cout << "Are you sure you want to format the disk?(y/N)"; c = _getch(); if (c == 'n' || c == 'N' || c == '\r') { cout << c << endl; continue; } else if (c == 'y' || c == 'Y') { remove("disk.txt"); remove("diskdata.txt"); init(); cout << c << "\nformat complete" << endl; } } else if (subcommand == "useradd") { add_user(command); } else if (subcommand == "userdelete") { delete_user(command); } else if (subcommand == "passwd") { change_password(command); } else if (subcommand == "clear") { system("cls"); } else if (subcommand == "exit") { system("cls"); break; } else { SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED); cout << "command not found" << endl; SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED); } cout << endl; save(); command = ""; subcommand = ""; } } }
/** * Simple "main" function for multiple platforms. * * Note the special "--" option which terminates the processing of * standard options. All non-standard options (if any) are passed * directly to the "init_xxx()" function. */ int main(int argc, char *argv[]) { int i; bool done = FALSE; const char *mstr = NULL; const char *soundstr = NULL; bool args = TRUE; /* Save the "program name" XXX XXX XXX */ argv0 = argv[0]; #ifdef UNIX /* Default permissions on files */ (void)umask(022); /* Get the user id */ player_uid = getuid(); #endif /* UNIX */ #ifdef SETGID /* Save the effective GID for later recall */ player_egid = getegid(); #endif /* UNIX */ /* Drop permissions */ safe_setuid_drop(); /* Get the file paths * Paths may be overriden by -d options, so this has to occur *before* * processing command line args */ init_stuff(); /* Process the command line arguments */ for (i = 1; args && (i < argc); i++) { const char *arg = argv[i]; /* Require proper options */ if (*arg++ != '-') goto usage; /* Analyze option */ switch (*arg++) { case 'l': list_saves(); exit(0); case 'n': new_game = TRUE; break; case 'w': arg_wizard = TRUE; break; case 'p': arg_power = TRUE; break; case 'r': arg_rebalance = TRUE; break; case 'g': /* Default graphics tile */ /* in graphics.txt, 2 corresponds to adam bolt's tiles */ arg_graphics = 2; if (*arg) arg_graphics = atoi(arg); break; case 'u': { if (!*arg) goto usage; my_strcpy(op_ptr->full_name, arg, sizeof op_ptr->full_name); /* The difference here is because on setgid we have to be * careful to only let the player have savefiles stored in * the central save directory. Sanitising input using * player_safe_name() removes anything like that. * * But if the player is running with per-user saves, they * can do whatever the hell they want. */ #ifdef SETGID savefile_set_name(player_safe_name(player, FALSE)); #else savefile_set_name(arg); #endif /* SETGID */ continue; } case 'm': if (!*arg) goto usage; mstr = arg; continue; case 's': if (!*arg) goto usage; soundstr = arg; continue; case 'd': change_path(arg); continue; case 'x': debug_opt(arg); continue; case '-': argv[i] = argv[0]; argc = argc - i; argv = argv + i; args = FALSE; break; default: usage: puts("Usage: angband [options] [-- subopts]"); puts(" -n Start a new character (WARNING: overwrites default savefile without -u)"); puts(" -l Lists all savefiles you can play"); puts(" -w Resurrect dead character (marks savefile)"); puts(" -r Rebalance monsters"); puts(" -g Request graphics mode"); puts(" -x<opt> Debug options; see -xhelp"); puts(" -u<who> Use your <who> savefile"); puts(" -d<dir>=<path> Override a specific directory with <path>. <path> can be:"); for (i = 0; i < (int)N_ELEMENTS(change_path_values); i++) { #ifdef SETGID if (!change_path_values[i].setgid_ok) continue; #endif printf(" %s (default is %s)\n", change_path_values[i].name, *change_path_values[i].path); } puts(" Multiple -d options are allowed."); puts(" -s<mod> Use sound module <sys>:"); for (i = 0; i < (int)N_ELEMENTS(sound_modules); i++) printf(" %s %s\n", sound_modules[i].name, sound_modules[i].help); puts(" -m<sys> Use module <sys>, where <sys> can be:"); /* Print the name and help for each available module */ for (i = 0; i < (int)N_ELEMENTS(modules); i++) printf(" %s %s\n", modules[i].name, modules[i].help); /* Actually abort the process */ quit(NULL); } if (*arg) goto usage; } /* Hack -- Forget standard args */ if (args) { argc = 1; argv[1] = NULL; } /* Install "quit" hook */ quit_aux = quit_hook; /* If we were told which mode to use, then use it */ if (mstr) ANGBAND_SYS = mstr; if (setlocale(LC_CTYPE, "")) { /* Require UTF-8 */ if (strcmp(nl_langinfo(CODESET), "UTF-8") != 0) quit("Angband requires UTF-8 support"); } /* Try the modules in the order specified by modules[] */ for (i = 0; i < (int)N_ELEMENTS(modules); i++) { /* User requested a specific module? */ if (!mstr || (streq(mstr, modules[i].name))) { ANGBAND_SYS = modules[i].name; if (0 == modules[i].init(argc, argv)) { done = TRUE; break; } } } /* Make sure we have a display! */ if (!done) quit("Unable to prepare any 'display module'!"); #ifdef UNIX /* Get the "user name" as default player name, unless set with -u switch */ if (!op_ptr->full_name[0]) { user_name(op_ptr->full_name, sizeof(op_ptr->full_name), player_uid); /* Set the savefile to load */ savefile_set_name(player_safe_name(player, FALSE)); } /* Create any missing directories */ create_needed_dirs(); #endif /* UNIX */ /* Try the modules in the order specified by sound_modules[] */ for (i = 0; i < (int)N_ELEMENTS(sound_modules); i++) if (!soundstr || streq(soundstr, sound_modules[i].name)) if (0 == sound_modules[i].init(argc, argv)) break; /* Catch nasty signals */ signals_init(); /* Set up the command hook */ cmd_get_hook = textui_get_cmd; /* Set up the display handlers and things. */ init_display(); init_angband(); textui_init(); /* Wait for response */ pause_line(Term); /* Play the game */ play_game(new_game); /* Free resources */ textui_cleanup(); cleanup_angband(); /* Quit */ quit(NULL); /* Exit */ return (0); }
/* * Simple "main" function for multiple platforms. * * Note the special "--" option which terminates the processing of * standard options. All non-standard options (if any) are passed * directly to the "init_xxx()" function. */ int main(int argc, char *argv[]) { int i; bool done = FALSE; const char *mstr = NULL; const char *soundstr = NULL; bool args = TRUE; /* Save the "program name" XXX XXX XXX */ argv0 = argv[0]; #ifdef SET_UID /* Default permissions on files */ (void)umask(022); #endif /* SET_UID */ #ifdef SET_UID /* Get the user id */ player_uid = getuid(); /* Save the effective GID for later recall */ player_egid = getegid(); #endif /* SET_UID */ /* Drop permissions */ safe_setuid_drop(); /* Process the command line arguments */ for (i = 1; args && (i < argc); i++) { const char *arg = argv[i]; /* Require proper options */ if (*arg++ != '-') goto usage; /* Analyze option */ switch (*arg++) { case 'n': new_game = TRUE; break; case 'w': arg_wizard = TRUE; break; case 'r': arg_rebalance = TRUE; break; case 'g': /* Default graphics tile */ /* in graphics.txt, 2 corresponds to adam bolt's tiles */ arg_graphics = 2; if (*arg) arg_graphics = atoi(arg); break; case 'u': if (!*arg) goto usage; /* Get the savefile name */ my_strcpy(op_ptr->full_name, arg, sizeof(op_ptr->full_name)); continue; case 'm': if (!*arg) goto usage; mstr = arg; continue; case 's': if (!*arg) goto usage; soundstr = arg; continue; case 'd': change_path(arg); continue; case 'x': debug_opt(arg); continue; case '-': argv[i] = argv[0]; argc = argc - i; argv = argv + i; args = FALSE; break; default: usage: puts("Usage: angband [options] [-- subopts]"); puts(" -n Start a new character (WARNING: overwrites default savefile without -u)"); puts(" -w Resurrect dead character (marks savefile)"); puts(" -r Rebalance monsters"); puts(" -g Request graphics mode"); puts(" -x<opt> Debug options; see -xhelp"); puts(" -u<who> Use your <who> savefile"); puts(" -d<path> Store pref files and screendumps in <path>"); puts(" -s<mod> Use sound module <sys>:"); for (i = 0; i < (int)N_ELEMENTS(sound_modules); i++) printf(" %s %s\n", sound_modules[i].name, sound_modules[i].help); puts(" -m<sys> Use module <sys>, where <sys> can be:"); /* Print the name and help for each available module */ for (i = 0; i < (int)N_ELEMENTS(modules); i++) printf(" %s %s\n", modules[i].name, modules[i].help); /* Actually abort the process */ quit(NULL); } if (*arg) goto usage; } /* Hack -- Forget standard args */ if (args) { argc = 1; argv[1] = NULL; } /* Install "quit" hook */ quit_aux = quit_hook; /* If we were told which mode to use, then use it */ if (mstr) ANGBAND_SYS = mstr; if (setlocale(LC_CTYPE, "")) { /* Require UTF-8 */ if (strcmp(nl_langinfo(CODESET), "UTF-8") != 0) quit("Angband requires UTF-8 support"); } /* Get the file paths */ init_stuff(); /* Try the modules in the order specified by modules[] */ for (i = 0; i < (int)N_ELEMENTS(modules); i++) { /* User requested a specific module? */ if (!mstr || (streq(mstr, modules[i].name))) { ANGBAND_SYS = modules[i].name; if (0 == modules[i].init(argc, argv)) { done = TRUE; break; } } } /* Make sure we have a display! */ if (!done) quit("Unable to prepare any 'display module'!"); #ifdef SET_UID /* Get the "user name" as a default player name, unless set with -u switch */ if (!op_ptr->full_name[0]) { user_name(op_ptr->full_name, sizeof(op_ptr->full_name), player_uid); } /* Create any missing directories */ create_needed_dirs(); #endif /* SET_UID */ /* Process the player name */ process_player_name(TRUE); /* Try the modules in the order specified by sound_modules[] */ for (i = 0; i < (int)N_ELEMENTS(sound_modules); i++) if (!soundstr || streq(soundstr, sound_modules[i].name)) if (0 == sound_modules[i].init(argc, argv)) break; /* Catch nasty signals */ signals_init(); /* Set up the command hook */ cmd_get_hook = default_get_cmd; /* Set up the display handlers and things. */ init_display(); /* Play the game */ play_game(); /* Free resources */ cleanup_angband(); /* Quit */ quit(NULL); /* Exit */ return (0); }
/* * Simple "main" function for multiple platforms. * * Note the special "--" option which terminates the processing of * standard options. All non-standard options (if any) are passed * directly to the "init_xxx()" function. */ int main(int argc, char *argv[]) { int i; bool done = FALSE; const char *mstr = NULL; bool args = TRUE; /* Save the "program name" XXX XXX XXX */ argv0 = argv[0]; #ifdef SET_UID /* Default permissions on files */ (void)umask(022); #endif /* SET_UID */ #ifdef SET_UID /* Get the user id */ player_uid = getuid(); /* Save the effective GID for later recall */ player_egid = getegid(); #endif /* SET_UID */ /* Drop permissions */ safe_setuid_drop(); /* Process the command line arguments */ for (i = 1; args && (i < argc); i++) { cptr arg = argv[i]; /* Require proper options */ if (*arg++ != '-') goto usage; /* Analyze option */ switch (*arg++) { case 'N': case 'n': { new_game = TRUE; break; } case 'W': case 'w': { arg_wizard = TRUE; break; } case 'R': case 'r': { arg_rebalance = TRUE; break; } case 'G': case 'g': { /* Default graphics tile */ arg_graphics = GRAPHICS_ADAM_BOLT; break; } case 'u': case 'U': { if (!*arg) goto usage; /* Get the savefile name */ my_strcpy(op_ptr->full_name, arg, sizeof(op_ptr->full_name)); continue; } case 'm': case 'M': { if (!*arg) goto usage; mstr = arg; continue; } case 'd': case 'D': { change_path(arg); continue; } case 'x': debug_opt(arg); continue; case '-': { argv[i] = argv[0]; argc = argc - i; argv = argv + i; args = FALSE; break; } default: usage: { /* Dump usage information */ puts("Usage: reposband [options] [-- subopts]"); puts(" -n Start a new character (WARNING: overwrites default savefile without -u)"); puts(" -w Resurrect dead character (marks savefile)"); puts(" -r Rebalance monsters"); puts(" -g Request graphics mode"); puts(" -x<opt> Debug options; see -xhelp"); puts(" -u<who> Use your <who> savefile"); puts(" -d<path> Store pref files and screendumps in <path>"); puts(" -m<sys> Use module <sys>, where <sys> can be:"); /* Print the name and help for each available module */ for (i = 0; i < (int)N_ELEMENTS(modules); i++) { printf(" %s %s\n", modules[i].name, modules[i].help); } /* Actually abort the process */ quit(NULL); } } if (*arg) goto usage; } /* Hack -- Forget standard args */ if (args) { argc = 1; argv[1] = NULL; } /* Get the file paths */ init_stuff(); /* Install "quit" hook */ quit_aux = quit_hook; /* Try the modules in the order specified by modules[] */ for (i = 0; i < (int)N_ELEMENTS(modules); i++) { /* User requested a specific module? */ if (!mstr || (streq(mstr, modules[i].name))) { reposband_SYS = modules[i].name; if (0 == modules[i].init(argc, argv)) { done = TRUE; /*quit_fmt("ggg %s", reposband_SYS);*/ break; } } } /* Make sure we have a display! */ if (!done) quit("Unable to prepare any 'display module'!"); #ifdef SET_UID /* Get the "user name" as a default player name, unless set with -u switch */ if (!op_ptr->full_name[0]) { user_name(op_ptr->full_name, sizeof(op_ptr->full_name), player_uid); } /* Create any missing directories */ create_needed_dirs(); #endif /* SET_UID */ /* Process the player name */ process_player_name(TRUE); #ifdef USE_SOUND /* Try the modules in the order specified by sound_modules[] */ for (i = 0; i < (int)N_ELEMENTS(sound_modules) - 1; i++) { if (0 == sound_modules[i].init(argc, argv)) break; } #endif /* Catch nasty signals */ signals_init(); /* Set up the command hook */ cmd_get_hook = default_get_cmd; /* Set up the display handlers and things. */ init_display(); /* Play the game */ play_game(); /* Free resources */ cleanup_reposband(); /* Quit */ quit(NULL); /* Exit */ return (0); }
/* * Simple "main" function for multiple platforms. * * Note the special "--" option which terminates the processing of * standard options. All non-standard options (if any) are passed * directly to the "init_xxx()" function. */ int main(int argc, char *argv[]) { int i; bool done = FALSE; bool new_game = FALSE; int show_score = 0; const char * mstr = NULL; bool args = TRUE; /* Save the "program name" XXX XXX XXX */ argv0 = argv[0]; #ifdef SET_UID /* Default permissions on files */ (void)umask(022); #endif /* Get the file paths */ init_stuff(); #ifdef SET_UID /* Get the user id */ player_uid = getuid(); /* Save the effective GID for later recall */ player_egid = getegid(); # if 0 /* XXX XXX XXX */ /* Redundant setting necessary in case root is running the game */ /* If not root or game not setuid the following two calls do nothing */ if (setgid(getegid()) != 0) { quit("setgid(): cannot set permissions correctly!"); } if (setuid(geteuid()) != 0) { quit("setuid(): cannot set permissions correctly!"); } # endif #endif /* SET_UID */ #ifdef SET_UID #ifdef PRIVATE_USER_PATH /* Create directories for the users files */ create_user_dirs(); #endif /* PRIVATE_USER_PATH */ /* Acquire the "user name" as a default player name */ user_name(op_ptr->full_name, player_uid); #endif /* SET_UID */ /* Process the command line arguments */ for (i = 1; args && (i < argc); i++) { /* Require proper options */ if (argv[i][0] != '-') goto usage; /* Analyze option */ switch (argv[i][1]) { case 'N': case 'n': { new_game = TRUE; break; } case 'F': case 'f': { arg_fiddle = TRUE; break; } case 'W': case 'w': { arg_wizard = TRUE; break; } case 'V': case 'v': { arg_sound = TRUE; break; } case 'R': case 'r': { arg_force_roguelike = TRUE; break; } case 'O': case 'o': { arg_force_original = TRUE; break; } case 'S': case 's': { show_score = atoi(&argv[i][2]); if (show_score <= 0) show_score = 10; break; } case 'u': case 'U': { if (!argv[i][2]) goto usage; strncpy(op_ptr->base_name, &argv[i][2], 32); op_ptr->base_name[31] = '\0'; break; } case 'm': { if (!argv[i][2]) goto usage; mstr = &argv[i][2]; break; } case 'M': { arg_monochrome = TRUE; break; } case 'd': case 'D': { change_path(&argv[i][2]); break; } case '-': { argv[i] = argv[0]; argc = argc - i; argv = argv + i; args = FALSE; break; } default: usage: { /* Dump usage information */ puts("Usage: angband [options] [-- subopts]"); puts(" -n Start a new character"); puts(" -f Request fiddle mode"); puts(" -w Request wizard mode"); puts(" -v Request sound mode"); puts(" -g Request graphics mode"); puts(" -o Request original keyset"); puts(" -r Request rogue-like keyset"); puts(" -M Request monochrome mode"); puts(" -s<num> Show <num> high scores"); puts(" -u<who> Use your <who> savefile"); puts(" -d<path> Store pref files and screendumps in <path>"); #ifdef USE_X11 puts(" -mx11 To use X11"); puts(" -- Sub options"); puts(" -- -d Set display name"); puts(" -- -s Turn off smoothscaling graphics"); puts(" -- -n# Number of terms to use"); #endif /* USE_X11 */ #ifdef USE_GCU puts(" -mgcu To use GCU (GNU Curses)"); puts(" -- Sub options"); puts(" -- -x No extra sub-windows"); #endif /* USE_GCU */ #ifdef USE_SLA puts(" -msla To use SLA (SLANG)"); #endif /* USE_SLA */ /* Actually abort the process */ quit(NULL); } } } /* Process the player name (but only if one is specified) */ if (strlen(op_ptr->base_name)) process_player_name(FALSE); /* Hack -- Forget standard args */ if (args) { argc = 1; argv[1] = NULL; } /* Install "quit" hook */ quit_aux = quit_hook; /* Drop privs (so X11 will work correctly) */ safe_setuid_drop(); #ifdef USE_X11 /* Attempt to use the "main-x11.c" support */ if (!done && (!mstr || (streq(mstr, "x11")))) { extern errr init_x11(int, char**); if (0 == init_x11(argc, argv)) { ANGBAND_SYS = "x11"; done = TRUE; } } #endif #ifdef USE_GCU /* Attempt to use the "main-gcu.c" support */ if (!done && (!mstr || (streq(mstr, "gcu")))) { extern errr init_gcu(int, char**); if (0 == init_gcu(argc, argv)) { ANGBAND_SYS = "gcu"; done = TRUE; } } #endif #ifdef USE_SLA /* Attempt to use the "main-sla.c" support */ if (!done && (!mstr || (streq(mstr, "sla")))) { extern errr init_sla(void); if (0 == init_sla()) { ANGBAND_SYS = "sla"; done = TRUE; } } #endif /* Grab privs (dropped above for X11) */ safe_setuid_grab(); /* Make sure we have a display! */ if (!done) quit("Unable to prepare any 'display module'!"); /* Catch nasty signals */ signals_init(); /* Initialize */ init_angband(); /* Hack -- If requested, display scores and quit */ if (show_score > 0) { show_scores(); quit(NULL); } /* Wait for response */ pause_line(23); /* Play the game */ play_game(new_game); /* Quit */ quit(NULL); /* Exit */ return (0); }
/* FIXME: documentation. */ char *tui_file_selector(const char *title, const char *directory, const char *pattern, const char *default_item, read_contents_func_type contents_func, char **browse_file_return, unsigned int *browse_file_number_return) { static char *return_path = NULL; struct file_list *fl; int curr_item, first_item, need_update; int x, y, width, height, num_cols, num_lines, field_width; int num_files; char str[0x100]; int str_len = 0; tui_area_t backing_store = NULL; if (contents_func != NULL) { *browse_file_return = NULL; } if (browse_file_number_return != NULL) { *browse_file_number_return = 0; } if (directory != NULL) { return_path = lib_stralloc(directory); } else { return_path = ioutil_current_dir(); } slashize_path(&return_path); fl = file_list_read(return_path, pattern); if (fl == NULL) { return NULL; } first_item = curr_item = 0; num_cols = 4; field_width = 18; num_lines = 17; height = num_lines + 2; width = field_width * num_cols + 4; num_files = num_cols * num_lines; if (default_item != NULL && *default_item) { int i; for (i = 0; i < fl->num_items; i++) { if (!strcasecmp(default_item, fl->items[i].name)) { curr_item = i; while (curr_item - first_item >= num_files) { first_item += num_lines; } break; } } } x = CENTER_X(width); y = CENTER_Y(height); need_update = 1; tui_area_get(&backing_store, x, y, width + 2, height + 1); tui_display_window(x, y, width, height, MENU_BORDER, MENU_BACK, title, NULL); while (1) { int key; tui_set_attr(MENU_FORE, MENU_BACK, 0); if (need_update) { file_selector_display_path(return_path, x + 1, y + height - 1, width - 2); file_selector_update(fl, first_item, x + 2, y + 1, field_width, num_lines, num_cols); tui_set_attr(FIRST_LINE_FORE, FIRST_LINE_BACK, 0); tui_display(0, tui_num_lines() - 1, tui_num_cols(), "\030\031\033\032: Move <Enter>: Select %s<Alt>-<letter>: Change drive", contents_func != NULL ? "<Space>: Preview " : ""); need_update = 0; } tui_set_attr(MENU_FORE, MENU_HIGHLIGHT, 0); file_selector_display_item(fl, curr_item, first_item, x + 2, y + 1, field_width, num_lines, num_cols); key = getkey(); tui_set_attr(MENU_FORE, MENU_BACK, 0); file_selector_display_item(fl, curr_item, first_item, x + 2, y + 1, field_width, num_lines, num_cols); switch (key) { case K_Escape: tui_area_put(backing_store, x, y); tui_area_free(backing_store); return NULL; case K_Left: str_len = 0; if (curr_item - num_lines >= 0) { curr_item -= num_lines; if (curr_item < first_item) { if (first_item >= num_lines) { first_item -= num_lines; need_update = 1; } else { curr_item += num_lines; } } } break; case K_Up: str_len = 0; if (curr_item > 0) { curr_item--; if (curr_item < first_item) { first_item = curr_item; need_update = 1; } } break; case K_Right: str_len = 0; if (curr_item + num_lines < fl->num_used_items) { curr_item += num_lines; if (curr_item - first_item >= num_files) { first_item += num_lines; need_update = 1; } } break; case K_Down: str_len = 0; if (curr_item < fl->num_used_items - 1) { curr_item++; if (curr_item == first_item + num_files) { first_item++; need_update = 1; } } break; case K_PageDown: str_len = 0; if (curr_item + num_files < fl->num_used_items) { curr_item += num_files; first_item += num_files; } need_update = 1; break; case K_PageUp: str_len = 0; if (curr_item - num_files >= 0) { curr_item -= num_files; first_item -= num_files; if (first_item < 0) { first_item = 0; } need_update = 1; } break; case K_Home: str_len = 0; curr_item = 0; if (first_item != 0) { first_item = 0; need_update = 1; } break; case K_End: str_len = 0; curr_item = fl->num_used_items - 1; first_item = curr_item - num_files + 1; if (first_item < 0) { first_item = 0; } need_update = 1; break; case K_Return: str_len = 0; if (fl->items[curr_item].type == FT_DIR) { struct file_list *new_fl; char *new_path; new_path = change_path(fl, return_path, curr_item); new_fl = file_list_read(new_path, pattern); if (new_fl != NULL) { file_list_free(fl); fl = new_fl; first_item = curr_item = 0; lib_free(return_path); return_path = new_path; need_update = 1; ioutil_chdir(return_path); } else { lib_free(new_path); } } else { char *p = util_concat(return_path, fl->items[curr_item].name, NULL); lib_free(return_path); return_path = p; tui_area_put(backing_store, x, y); tui_area_free(backing_store); return return_path; } break; case K_BackSpace: if (str_len > 1) { int n; str_len--; n = file_list_find(fl, str, str_len); if (n >= 0) { curr_item = n; if (curr_item < first_item) { first_item = curr_item; need_update = 1; } else if (first_item + num_files <= curr_item) { first_item = curr_item - num_files + 1; need_update = 1; } } } else { str_len = 0; curr_item = 0; if (first_item != 0) { first_item = 0; need_update = 1; } } break; case ' ': if (contents_func != NULL && fl->items[curr_item].type != FT_DIR && browse_file_return != NULL) { tui_display(0, tui_num_lines() - 1, tui_num_cols(), ""); *browse_file_return = tui_image_browser(fl->items[curr_item].name, contents_func, browse_file_number_return); if (*browse_file_return != NULL) { char *p = util_concat(return_path, fl->items[curr_item].name, NULL); lib_free(return_path); return_path = p; tui_area_put(backing_store, x, y); tui_area_free(backing_store); return return_path; } need_update = 1; break; } else { tui_beep(); } default: { int drive_num; drive_num = alt_key_to_drive_num(key); if (drive_num > 0) { /* `A-a' ... `A-z' change the current drive. */ int num_available_drives; int current_drive; _dos_getdrive(¤t_drive); _dos_setdrive(current_drive, &num_available_drives); if (drive_num <= num_available_drives) { char *new_path; /* FIXME: This is a hack... Maybe there is a cleaner way to do it, but for now I just don't know. */ _dos_setdrive(drive_num, &num_available_drives); new_path = ioutil_current_dir(); if (new_path != NULL) { slashize_path(&new_path); _dos_setdrive(current_drive, &num_available_drives); if (new_path != NULL) { struct file_list *new_fl; new_fl = file_list_read(new_path, pattern); if (new_fl != NULL) { file_list_free(fl); fl = new_fl; first_item = curr_item = 0; lib_free(return_path); return_path = new_path; need_update = 1; ioutil_chdir(return_path); } else { lib_free(new_path); } } } else { _dos_setdrive(current_drive, &num_available_drives); tui_beep(); } } else { tui_beep(); } } else if (isprint(key) && str_len < 0x100) { int n; str[str_len] = key; n = file_list_find(fl, str, str_len + 1); if (n < 0) { tui_beep(); } else { str_len++; curr_item = n; if (curr_item < first_item) { first_item = curr_item; need_update = 1; } else if (first_item + num_files <= curr_item) { first_item = curr_item - num_files + 1; need_update = 1; } } } } break; } } }