int main() { set_escdelay(0); setlocale(LC_ALL, ""); initscr(); char a; mvwprintw(stdscr, 1, (getmaxx(stdscr) - 18) / 2, "Добро пожаловать в\n"); while (a != 'q' && a != 'Q' && a != 27) { hangman(); keypad(stdscr, true); attron(A_REVERSE); mvwprintw(stdscr, getmaxy(stdscr) - 1, 0, "Нажмите ENTER для начала, Q или ESC для выхода"); attroff(A_REVERSE); cbreak(); refresh(); a = getch(); if (a == '\n') { game(); } clear(); } keypad(stdscr, false); endwin(); printf("Bye - bye!\n"); return 0; }
// // Initalise ncurses et les paires de couleurs. // void initDisplay() { //initialisation écran initscr(); //initialisation couleurs start_color(); //utiliser les couleurs par défaut du terminal use_default_colors(); //paires de couleurs pour chaque robot init_pair(1, COLOR_WHITE, COLOR_RED); init_pair(2, COLOR_WHITE, COLOR_GREEN); init_pair(3, COLOR_WHITE, COLOR_BLUE); init_pair(4, COLOR_BLACK, COLOR_YELLOW); //paires de couleurs pour cases objectif init_pair(11, COLOR_RED, -1); init_pair(12, COLOR_GREEN, -1); init_pair(13, COLOR_BLUE, -1); init_pair(14, COLOR_YELLOW, -1); keypad(stdscr, true); //activation des touches fléchées etc. set_tabsize(4); //taille des tabulations set_escdelay(25); //délai après l'appui sur echap }
void curses_init () { /* Start curses mode */ initscr (); start_color (); init_pair(1, COLOR_RED, COLOR_BLACK); init_pair(2, COLOR_GREEN, COLOR_BLACK); init_pair(3, COLOR_YELLOW, COLOR_BLACK); init_pair(4, COLOR_BLUE, COLOR_BLACK); init_pair(5, COLOR_MAGENTA, COLOR_BLACK); init_pair(6, COLOR_CYAN, COLOR_BLACK); init_pair(7, COLOR_WHITE, COLOR_BLACK); init_pair(8, COLOR_WHITE, COLOR_RED); noecho (); raw (); set_escdelay (100); nodelay (stdscr,TRUE); /* We want scrolling */ scrollok (stdscr, TRUE); /* We want arrows and stuff */ keypad (stdscr, TRUE); curs_set (0); return; }
bool init () { if (!is_initialized) { initscr (); if (!has_colors ()) { endwin (); return false; } raw (); noecho (); nonl (); keypad (stdscr, TRUE); intrflush (stdscr, FALSE); #ifdef HAVE_SET_ESCDELAY // The default value set in ncurses is way too long // VIM uses 25 milliseconds if (getenv ("ESCDELAY") == 0) { set_escdelay (50); } #endif start_color (); init_color_pairs (); set_palettes (); static bool ever_registered = false; if (!ever_registered) { atexit (&finalize); ever_registered = true; } is_initialized = true; } return true; }
void start_screen() { initscr(); main_win = newwin(LINES - RESROW, COLS, RESROW, 0); input_win = newwin(RESROW, COLS, 0, 0); // just 2 rows (RESROW = 2) #ifdef USECOLORS if (has_colors()) { start_color(); if (get_d_colors_param() == NULL) { start_default_ucolors(); // in case we decide to change colors // esto crea un diccionario y guarda en el // la equivalencia entre las macros y los valores // de las claves que se definen en los archivos .sc set_colors_param_dict(); } //wbkgd(input_win, COLOR_PAIR(DEFAULT)); //wbkgd(main_win, COLOR_PAIR(DEFAULT)); } #endif wtimeout(input_win, TIMEOUT_CURSES); noecho(); curs_set(0); #ifndef NETBSD if ((char *) getenv ("ESCDELAY") == NULL) set_escdelay(ESC_DELAY); #endif cbreak(); keypad(input_win, 1); }
int main() { signal(SIGINT, finish); srand(time(NULL)); initscr(); curs_set(0); // hide the cursor keypad(stdscr, TRUE); nodelay(stdscr, TRUE); set_escdelay(10); cbreak(); // return after reading one char noecho(); start_color(); init_pair(1, COLOR_GREEN, COLOR_BLACK); init_pair(2, COLOR_MAGENTA, COLOR_BLACK); init_pair(3, COLOR_RED, COLOR_BLACK); init_pair(4, COLOR_BLUE, COLOR_BLACK); init_pair(5, COLOR_CYAN, COLOR_BLACK); init_pair(6, COLOR_YELLOW, COLOR_BLACK); init_pair(7, COLOR_WHITE, COLOR_BLACK); init_pair(8, COLOR_BLACK, COLOR_WHITE); game_loop(Startscreen_create()); /* print_glyphs(); */ finish(0); }
SheetView::SheetView(Spreadsheet &sheet) :sheet(sheet){ initscr(); start_color(); noecho(); keypad(stdscr, TRUE); redraw(); set_escdelay(25); }
Input::Input() { this->keybinding = Config::provider->GetConfig().GetKeybinding(); this->InputTimeout = -1; notimeout(stdscr, TRUE); #ifndef PDCURSES set_escdelay(0); // Needed so ESC key doesn't take a full second to do something. #endif }
void init_term_gui(void) { /* Fix ESC key */ set_escdelay(25); initscr(); start_color(); cbreak(); noecho(); if (can_change_color()) { init_color(XS_COLOR_BLUE, 43, 180, 349); init_color(XS_COLOR_RED, 886, 27, 124); init_pair(XS_COLOR_PAIR_1, COLOR_WHITE, XS_COLOR_RED); init_pair(XS_COLOR_PAIR_2, COLOR_WHITE, XS_COLOR_BLUE); } else{ init_pair(XS_COLOR_PAIR_1, COLOR_WHITE, COLOR_RED); init_pair(XS_COLOR_PAIR_2, COLOR_WHITE, COLOR_BLUE); } /* int max_rows; */ /* int max_cols; */ /* getmaxyx(stdscr, max_rows, max_cols); */ show_recent_apps(); prepare_for_new_results(False); mvprintw(0, 0, "$"); mvwprintw(window, MAX_Y - 2, 0, "Loading paths..."); refresh(); field[0] = new_field( 1, // columns 20, // width 0, // pos y 2, // pos x 0, 0 ); /* Hide cursor */ curs_set(0); set_field_fore(field[0], COLOR_PAIR(XS_COLOR_PAIR_2)); field[1] = NULL; form = new_form(field); post_form(form); wrefresh(window); }
void TerminalChatConsole::initOfCurses() { initscr(); cbreak(); //raw(); noecho(); keypad(stdscr, TRUE); nodelay(stdscr, TRUE); timeout(100); // To make esc not delay up to one second. According to the internet, // this is the value vim uses, too. set_escdelay(25); getmaxyx(stdscr, m_rows, m_cols); m_can_draw_text = reformat_backend(&m_chat_backend, m_rows, m_cols); }
void reset(int code) { endwin(); initscr(); nonl(); cbreak(); noecho(); keypad(stdscr, TRUE); nodelay(stdscr, TRUE); curs_set(FALSE); set_escdelay(10); start_color(); use_default_colors(); assume_default_colors(COLOR_WHITE, COLOR_BLACK); idlok(stdscr, TRUE); clear(); refresh(); }
void prep_screen() { initscr(); start_color(); use_default_colors(); raw(); keypad(stdscr, 1); set_escdelay(1); noecho(); curs_set(0); init_pair(1, COLOR_RED, 0); init_pair(2, COLOR_GREEN, 0); init_pair(3, COLOR_YELLOW, 0); init_pair(4, COLOR_BLUE, 0); init_pair(5, COLOR_MAGENTA, 0); init_pair(6, COLOR_CYAN, 0); init_pair(7, COLOR_WHITE, 0); init_ioctl(); }
void initCurses() { initscr(); clear(); noecho(); set_escdelay(0); cbreak(); keypad(stdscr, true); curs_set(0); timeout(100); start_color(); INIT_PAIR(WHITE, BLACK); INIT_PAIR(BLACK, WHITE); INIT_PAIR(WHITE, BLUE); INIT_PAIR(BLACK, BLUE); INIT_PAIR(RED, BLUE); INIT_PAIR(GREEN, BLUE); INIT_PAIR(BLUE, RED); INIT_PAIR(WHITE, RED); srand(time(0)); }
void create_input_window(void) { #ifdef NCURSES_REENTRANT set_escdelay(25); #else ESCDELAY = 25; #endif rl_readline_name = "profanity"; rl_getc_function = _inp_rl_getc; rl_startup_hook = _inp_rl_startup_hook; rl_callback_handler_install(NULL, _inp_rl_linehandler); inp_win = newpad(1, INP_WIN_MAX); wbkgd(inp_win, theme_attrs(THEME_INPUT_TEXT));; keypad(inp_win, TRUE); wmove(inp_win, 0, 0); _inp_win_update_virtual(); }
void main() { tolog("main start\n"); void keytogame(), keytoinv(), map(), notify(), sounds_print(), loadgame(), eraseanimals(), *mech(); int ch; pthread_t mechthread; printf("\nEyecube\nCopyright (C) 2011 Alexander Kromm\nThis program comes with ABSOLUTELY NO WARRANTY.\nThis is free software, and you are welcome to redistribute it\nunder certain conditions; see README for details.\n\n"); (void)set_escdelay(10); // signal='w'; (void)initscr(); (void)start_color(); // (void)cbreak(); (void)raw(); (void)noecho(); (void)keypad(stdscr, TRUE); // setlocale(LC_ALL, "ru_Ru.utf8"); curs_set(0); //make cursor invisible (void)init_pair(WHITE_BLUE, COLOR_WHITE, COLOR_BLUE ); //player, sky (void)init_pair(BLACK_GREEN, COLOR_BLACK, COLOR_GREEN ); //grass, dwarf (void)init_pair(BLACK_WHITE, COLOR_BLACK, COLOR_WHITE ); //stone, skin (void)init_pair(RED_YELLOW, COLOR_RED, COLOR_YELLOW); //sun, fire1 (void)init_pair(RED_WHITE, COLOR_RED, COLOR_WHITE ); //chiken (void)init_pair(WHITE_BLACK, COLOR_WHITE, COLOR_BLACK ); //?, heap (void)init_pair(YELLOW_RED, COLOR_YELLOW, COLOR_RED ); //fire2 (void)init_pair(BLACK_RED, COLOR_BLACK, COLOR_RED ); //pointer (void)init_pair(BLACK_YELLOW, COLOR_BLACK, COLOR_YELLOW); //wood (void)init_pair(BLUE_YELLOW, COLOR_BLUE, COLOR_YELLOW); //clock (void)init_pair(WHITE_CYAN, COLOR_WHITE, COLOR_CYAN ); //noon sky (void)init_pair(BLACK_BLUE, COLOR_BLACK, COLOR_BLUE ); //raven (void)init_pair(BLACK_CYAN, COLOR_BLACK, COLOR_CYAN ); //raven (void)init_pair(RED_BLUE, COLOR_RED, COLOR_BLUE ); //bird (void)init_pair(RED_CYAN, COLOR_RED, COLOR_CYAN ); //bird (void)init_pair(RED_BLACK, COLOR_RED, COLOR_BLACK ); //bird world= newwin(23, 44, 0, 0); pocketwin= newwin(1, 44, 23, 0); textwin= newwin(5, 36, 24, 8); sound_window=newwin(5, 8, 24, 0); (void)refresh(); loadgame(); //start parallel thread (void)pthread_create(&mechthread, NULL, mech, NULL); map(); sounds_print(); notify("Game started.", 0); //this is the game itself while ((ch=getch())!=(int)'Q') { switch (view) { case VIEW_SURFACE: case VIEW_FLOOR: case VIEW_HEAD: case VIEW_SKY: case VIEW_FRONT: keytogame(ch); break; case VIEW_MENU: key_to_menu(ch); break; default: keytoinv(ch); break; } // sleep(1); usleep(10000); } //stop parallel thread eraseanimals(1); (void)pthread_cancel(mechthread); (void)delwin(world ); (void)delwin(textwin ); (void)delwin(pocketwin); (void)endwin(); tolog("main finish\n"); }
shNCursesInterface::shNCursesInterface () { WINDOW *win = initscr (); if (!win) { fprintf (stderr, "Sorry, curses support is required.\n"); exitPRIME (-1); } if (!has_colors ()) { endwin (); fprintf (stderr, "Sorry, color support is required.\n"); exitPRIME (-1); } start_color (); for (int i = 1; i < COLOR_PAIRS; ++i) { init_pair (i, i %8, i/8); } #ifdef _WIN32 curs_set (1); ColorMap[kBlack] = COLOR_BLACK; ColorMap[kRed] = COLOR_PAIR (4); ColorMap[kGreen] = COLOR_PAIR (2); ColorMap[kBrown] = COLOR_PAIR (6); ColorMap[kBlue] = COLOR_PAIR (1); ColorMap[kMagenta] = COLOR_PAIR (5); ColorMap[kCyan] = COLOR_PAIR (3); ColorMap[kGray] = COLOR_PAIR (7); ColorMap[kOrange] = COLOR_PAIR (4) | A_BOLD; ColorMap[kLime] = COLOR_PAIR (2) | A_BOLD; ColorMap[kYellow] = COLOR_PAIR (6) | A_BOLD; ColorMap[kNavy] = COLOR_PAIR (1)| A_BOLD; ColorMap[kPink] = COLOR_PAIR (5) | A_BOLD; ColorMap[kAqua] = COLOR_PAIR (3) | A_BOLD; ColorMap[kWhite] = COLOR_PAIR (7) | A_BOLD; #else ColorMap[kBlack] = COLOR_BLACK; ColorMap[kRed] = COLOR_PAIR (1); ColorMap[kGreen] = COLOR_PAIR (2); ColorMap[kBrown] = COLOR_PAIR (3); ColorMap[kBlue] = COLOR_PAIR (4); ColorMap[kMagenta] = COLOR_PAIR (5); ColorMap[kCyan] = COLOR_PAIR (6); ColorMap[kGray] = COLOR_PAIR (7); ColorMap[kOrange] = COLOR_PAIR (1) | A_BOLD; ColorMap[kLime] = COLOR_PAIR (2) | A_BOLD; ColorMap[kYellow] = COLOR_PAIR (3) | A_BOLD; ColorMap[kNavy] = COLOR_PAIR (4)| A_BOLD; ColorMap[kPink] = COLOR_PAIR (5) | A_BOLD; ColorMap[kAqua] = COLOR_PAIR (6) | A_BOLD; ColorMap[kWhite] = COLOR_PAIR (7) | A_BOLD; #endif mColor = kGray; // cbreak (); raw (); noecho (); #ifdef DJGPP nl (); #else nonl (); #endif mXMax = 64; mYMax = 20; mWin[kMain] = newwin (20, mXMax, 0, 0); if (!mWin[kMain]) goto toosmall; mPan[kMain] = new_panel (mWin[kMain]); notimeout (mWin[kMain], TRUE); mWin[kSide] = newwin (20, 80 - mXMax, 0, mXMax); if (!mWin[kSide]) goto toosmall; mPan[kSide] = new_panel (mWin[kSide]); mWin[kLog] = newwin (5, 80, 20, 0); if (!mWin[kLog]) goto toosmall; mPan[kLog] = new_panel (mWin[kLog]); mWin[kDiag] = NULL; if (BOFH and LINES >= 30) { mWin[kDiag] = newwin (0, 80, 25, 0); scrollok (mWin[kDiag], TRUE); } mWin[kTemp] = newwin (0, 0, 0, 0); notimeout (mWin[kLog], TRUE); mLogSize = 5; mLogRow = 0; mHistoryIdx = 0; mHistoryWrapped = 0; mNoNewline = 0; mLogSCount = 0; mPause = 0; mX0 = 0; mY0 = 0; intrflush (mWin[kMain], FALSE); keypad (mWin[kMain], TRUE); intrflush (mWin[kLog], FALSE); scrollok (mWin[kLog], TRUE); #ifndef WIN32 set_escdelay (50); #endif debug.log ("COLORS: %d", COLORS); debug.log ("COLOR_PAIRS: %d", COLOR_PAIRS); debug.log ("can change: %d", can_change_color()); return; toosmall: endwin (); fprintf (stderr, "Sorry, but a terminal with dimensions of at least 80x25" " is required.\n"); exitPRIME (-1); }
Ui *ui_curses_new(void) { UiCurses *uic = calloc(1, sizeof(UiCurses)); Ui *ui = (Ui*)uic; if (!uic) return NULL; if (!(uic->termkey = termkey_new(STDIN_FILENO, TERMKEY_FLAG_UTF8))) goto err; termkey_set_canonflags(uic->termkey, TERMKEY_CANON_DELBS); setlocale(LC_CTYPE, ""); if (!getenv("ESCDELAY")) set_escdelay(50); char *term = getenv("TERM"); if (!term) term = "xterm"; if (!newterm(term, stderr, stdin)) { snprintf(uic->info, sizeof(uic->info), "Warning: unknown term `%s'", term); if (!newterm(strstr(term, "-256color") ? "xterm-256color" : "xterm", stderr, stdin)) goto err; } start_color(); use_default_colors(); raw(); noecho(); nonl(); keypad(stdscr, TRUE); meta(stdscr, TRUE); curs_set(0); /* needed because we use getch() which implicitly calls refresh() which would clear the screen (overwrite it with an empty / unused stdscr */ refresh(); *ui = (Ui) { .init = ui_init, .start = ui_start, .free = ui_curses_free, .termkey_get = ui_termkey_get, .suspend = ui_suspend, .resize = ui_resize, .update = ui_update, .window_new = ui_window_new, .window_free = ui_window_free, .window_focus = ui_window_focus, .window_swap = ui_window_swap, .draw = ui_draw, .redraw = ui_redraw, .arrange = ui_arrange, .die = ui_die, .info = ui_info, .info_hide = ui_info_hide, .haskey = ui_haskey, .getkey = ui_getkey, .terminal_save = ui_terminal_save, .terminal_restore = ui_terminal_restore, }; struct sigaction sa; sa.sa_flags = 0; sigemptyset(&sa.sa_mask); sa.sa_handler = sigwinch_handler; sigaction(SIGWINCH, &sa, NULL); sigaction(SIGCONT, &sa, NULL); ui_resize(ui); return ui; err: ui_curses_free(ui); return NULL; }
int APIENTRY WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { int argc = __argc; char **argv = __argv; #else int main(int argc, char *argv[]) { #endif int seed = time(NULL); bool verifyexit = false; bool check_all_mods = false; // Set default file paths #ifdef PREFIX #define Q(STR) #STR #define QUOTE(STR) Q(STR) init_base_path(std::string(QUOTE(PREFIX))); #else PATH_INFO::init_base_path(""); #endif #ifdef USE_HOME_DIR PATH_INFO::init_user_dir(); #else PATH_INFO::init_user_dir("./"); #endif PATH_INFO::set_standart_filenames(); MAP_SHARING::setDefaults(); // Process CLI arguments int saved_argc = --argc; // skip program name char **saved_argv = ++argv; while (argc) { if(std::string(argv[0]) == "--seed") { argc--; argv++; if(argc) { seed = djb2_hash((unsigned char *)argv[0]); argc--; argv++; } } else if(std::string(argv[0]) == "--jsonverify") { argc--; argv++; verifyexit = true; } else if(std::string(argv[0]) == "--check-mods") { argc--; argv++; check_all_mods = true; } else if(std::string(argv[0]) == "--basepath") { argc--; argv++; if(argc) { PATH_INFO::init_base_path(std::string(argv[0])); PATH_INFO::set_standart_filenames(); argc--; argv++; } } else if(std::string(argv[0]) == "--userdir") { argc--; argv++; if (argc) { PATH_INFO::init_user_dir( argv[0] ); PATH_INFO::set_standart_filenames(); argc--; argv++; } } else if(std::string(argv[0]) == "--username") { argc--; argv++; if (argc) { MAP_SHARING::setUsername(std::string(argv[0])); argc--; argv++; } } else if(std::string(argv[0]) == "--addadmin") { argc--; argv++; if (argc) { MAP_SHARING::addAdmin(std::string(argv[0])); argc--; argv++; } } else if(std::string(argv[0]) == "--adddebugger") { argc--; argv++; if (argc) { MAP_SHARING::addDebugger(std::string(argv[0])); argc--; argv++; } } else if(std::string(argv[0]) == "--shared") { argc--; argv++; MAP_SHARING::setSharing(true); MAP_SHARING::setCompetitive(true); MAP_SHARING::setWorldmenu(false); } else if(std::string(argv[0]) == "--competitive") { argc--; argv++; MAP_SHARING::setCompetitive(true); } else { // Skipping other options. argc--; argv++; } } while (saved_argc) { if(std::string(saved_argv[0]) == "--worldmenu") { saved_argc--; saved_argv++; MAP_SHARING::setWorldmenu(true); } else if(std::string(saved_argv[0]) == "--datadir") { saved_argc--; saved_argv++; if(saved_argc) { PATH_INFO::update_pathname("datadir", std::string(saved_argv[0])); PATH_INFO::update_datadir(); saved_argc--; saved_argv++; } } else if(std::string(saved_argv[0]) == "--savedir") { saved_argc--; saved_argv++; if(saved_argc) { PATH_INFO::update_pathname("savedir", std::string(saved_argv[0])); saved_argc--; saved_argv++; } } else if(std::string(saved_argv[0]) == "--configdir") { saved_argc--; saved_argv++; if(saved_argc) { PATH_INFO::update_pathname("config_dir", std::string(saved_argv[0])); PATH_INFO::update_config_dir(); saved_argc--; saved_argv++; } } else if(std::string(saved_argv[0]) == "--optionfile") { saved_argc--; saved_argv++; if(saved_argc) { PATH_INFO::update_pathname("options", std::string(saved_argv[0])); saved_argc--; saved_argv++; } } else if(std::string(saved_argv[0]) == "--keymapfile") { saved_argc--; saved_argv++; if(saved_argc) { PATH_INFO::update_pathname("keymap", std::string(saved_argv[0])); saved_argc--; saved_argv++; } } else if(std::string(saved_argv[0]) == "--autopickupfile") { saved_argc--; saved_argv++; if(saved_argc) { PATH_INFO::update_pathname("autopickup", std::string(saved_argv[0])); saved_argc--; saved_argv++; } } else if(std::string(saved_argv[0]) == "--motdfile") { saved_argc--; saved_argv++; if(saved_argc) { PATH_INFO::update_pathname("motd", std::string(saved_argv[0])); saved_argc--; saved_argv++; } } else { // ignore unknown args. saved_argc--; saved_argv++; } } // setup debug loggind #ifdef ENABLE_LOGGING setupDebug(); #endif // set locale to system default setlocale(LC_ALL, ""); #ifdef LOCALIZE const char *locale_dir; #ifdef __linux__ if (!FILENAMES["base_path"].empty()) { locale_dir = std::string(FILENAMES["base_path"] + "share/locale").c_str(); } else { locale_dir = "lang/mo"; } #else locale_dir = "lang/mo"; #endif // __linux__ bindtextdomain("cataclysm-dda", locale_dir); bind_textdomain_codeset("cataclysm-dda", "UTF-8"); textdomain("cataclysm-dda"); #endif // LOCALIZE // ncurses stuff initOptions(); load_options(); // For getting size options #ifdef LOCALIZE setlocale(LC_ALL, OPTIONS["USE_LANG"].getValue().c_str()); #endif // LOCALIZE if (initscr() == NULL) { // Initialize ncurses DebugLog() << "initscr failed!\n"; return 1; } init_interface(); noecho(); // Don't echo keypresses cbreak(); // C-style breaks (e.g. ^C to SIGINT) keypad(stdscr, true); // Numpad is numbers #if !(defined TILES || defined _WIN32 || defined WINDOWS) // For tiles or windows, this is handled already in initscr(). init_colors(); #endif // curs_set(0); // Invisible cursor set_escdelay(10); // Make escape actually responsive std::srand(seed); g = new game; // First load and initialize everything that does not // depend on the mods. try { if (!assure_dir_exist(FILENAMES["user_dir"].c_str())) { debugmsg("Can't open or create %s. Check permissions.", FILENAMES["user_dir"].c_str()); exit_handler(-999); } g->load_static_data(); if (verifyexit) { if(g->game_error()) { exit_handler(-999); } exit_handler(0); } if (check_all_mods) { // Here we load all the mods and check their // consistency (both is done in check_all_mod_data). g->init_ui(); popup_nowait("checking all mods"); g->check_all_mod_data(); if(g->game_error()) { exit_handler(-999); } // At this stage, the mods (and core game data) // are find and we could start playing, but this // is only for verifying that stage, so we exit. exit_handler(0); } } catch(std::string &error_message) { if(!error_message.empty()) { debugmsg("%s", error_message.c_str()); } exit_handler(-999); } // Now we do the actuall game g->init_ui(); if(g->game_error()) { exit_handler(-999); } curs_set(0); // Invisible cursor here, because MAPBUFFER.load() is crash-prone #if (!(defined _WIN32 || defined WINDOWS)) struct sigaction sigIntHandler; sigIntHandler.sa_handler = exit_handler; sigemptyset(&sigIntHandler.sa_mask); sigIntHandler.sa_flags = 0; sigaction(SIGINT, &sigIntHandler, NULL); #endif bool quit_game = false; do { if(!g->opening_screen()) { quit_game = true; } while (!quit_game && !g->do_turn()) ; if (g->game_quit() || g->game_error()) { quit_game = true; } } while (!quit_game); exit_handler(-999); return 0; }
int APIENTRY WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { int argc = __argc; char **argv = __argv; #else int main(int argc, char *argv[]) { #endif #ifdef ENABLE_LOGGING setupDebug(); #endif int seed = time(NULL); // set locale to system default setlocale(LC_ALL, ""); bindtextdomain("cataclysm-dda", "lang/mo"); textdomain("cataclysm-dda"); //args: world seeding only. argc--; argv++; while (argc){ if(std::string(argv[0]) == "--seed"){ argc--; argv++; if(argc){ seed = djb2_hash((unsigned char*)argv[0]); argc--; argv++; } } else // ignore unknown args. argc--; argv++; } // ncurses stuff load_options(); // For getting size options initscr(); // Initialize ncurses noecho(); // Don't echo keypresses cbreak(); // C-style breaks (e.g. ^C to SIGINT) keypad(stdscr, true); // Numpad is numbers init_colors(); // See color.cpp // curs_set(0); // Invisible cursor set_escdelay(10); // Make escape actually responsive std::srand(seed); bool quit_game = false; bool delete_world = false; g = new game; g->init_ui(); MAPBUFFER.set_game(g); g->load_artifacts(); //artifacts have to be loaded before any items are created MAPBUFFER.load(); curs_set(0); // Invisible cursor here, because MAPBUFFER.load() is crash-prone #if (!(defined _WIN32 || defined WINDOWS)) struct sigaction sigIntHandler; sigIntHandler.sa_handler = exit_handler; sigemptyset(&sigIntHandler.sa_mask); sigIntHandler.sa_flags = 0; sigaction(SIGINT, &sigIntHandler, NULL); #endif do { g->setup(); while (!g->do_turn()) ; if (g->uquit == QUIT_DELETE_WORLD) delete_world = true; if (g->game_quit()) quit_game = true; } while (!quit_game); if (delete_world) { g->delete_save(); } else { MAPBUFFER.save_if_dirty(); } exit_handler(-999); return 0; }
int APIENTRY WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { int argc = __argc; char **argv = __argv; #else int main(int argc, char *argv[]) { #endif #ifdef ENABLE_LOGGING setupDebug(); #endif int seed = time(NULL); // set locale to system default setlocale(LC_ALL, ""); #ifdef LOCALIZE bindtextdomain("cataclysm-dda", "lang/mo"); bind_textdomain_codeset("cataclysm-dda", "UTF-8"); textdomain("cataclysm-dda"); #endif //args: world seeding only. argc--; argv++; while (argc){ if(std::string(argv[0]) == "--seed"){ argc--; argv++; if(argc){ seed = djb2_hash((unsigned char*)argv[0]); argc--; argv++; } } else // ignore unknown args. argc--; argv++; } // ncurses stuff initOptions(); load_options(); // For getting size options initscr(); // Initialize ncurses #ifdef SDLTILES init_tiles(); #endif // SDLTILES noecho(); // Don't echo keypresses cbreak(); // C-style breaks (e.g. ^C to SIGINT) keypad(stdscr, true); // Numpad is numbers init_colors(); // See color.cpp // curs_set(0); // Invisible cursor set_escdelay(10); // Make escape actually responsive std::srand(seed); bool quit_game = false; g = new game; g->init_data(); if(g->game_error()) exit_handler(-999); g->init_ui(); MAPBUFFER.set_game(g); if(g->game_error()) exit_handler(-999); curs_set(0); // Invisible cursor here, because MAPBUFFER.load() is crash-prone #if (!(defined _WIN32 || defined WINDOWS)) struct sigaction sigIntHandler; sigIntHandler.sa_handler = exit_handler; sigemptyset(&sigIntHandler.sa_mask); sigIntHandler.sa_flags = 0; sigaction(SIGINT, &sigIntHandler, NULL); #endif do { if(!g->opening_screen()) { quit_game = true; } while (!g->do_turn()) ; if (g->game_quit() || g->game_error()) quit_game = true; } while (!quit_game); exit_handler(-999); return 0; }
newterm(NCURSES_CONST char *name, FILE *ofp, FILE *ifp) { int value; int errret; SCREEN *current; SCREEN *result = 0; TERMINAL *its_term; START_TRACE(); T((T_CALLED("newterm(\"%s\",%p,%p)"), name, ofp, ifp)); _nc_init_pthreads(); _nc_lock_global(curses); current = SP; its_term = (SP ? SP->_term : 0); /* this loads the capability entry, then sets LINES and COLS */ if (setupterm(name, fileno(ofp), &errret) != ERR) { int slk_format = _nc_globals.slk_format; /* * This actually allocates the screen structure, and saves the original * terminal settings. */ _nc_set_screen(0); /* allow user to set maximum escape delay from the environment */ if ((value = _nc_getenv_num("ESCDELAY")) >= 0) { set_escdelay(value); } if (_nc_setupscreen(LINES, COLS, ofp, _nc_prescreen.filter_mode, slk_format) == ERR) { _nc_set_screen(current); result = 0; } else { assert(SP != 0); /* * In setupterm() we did a set_curterm(), but it was before we set * SP. So the "current" screen's terminal pointer was overwritten * with a different terminal. Later, in _nc_setupscreen(), we set * SP and the terminal pointer in the new screen. * * Restore the terminal-pointer for the pre-existing screen, if * any. */ if (current) current->_term = its_term; /* if the terminal type has real soft labels, set those up */ if (slk_format && num_labels > 0 && SLK_STDFMT(slk_format)) _nc_slk_initialize(stdscr, COLS); SP->_ifd = fileno(ifp); typeahead(fileno(ifp)); #ifdef TERMIOS SP->_use_meta = ((cur_term->Ottyb.c_cflag & CSIZE) == CS8 && !(cur_term->Ottyb.c_iflag & ISTRIP)); #else SP->_use_meta = FALSE; #endif SP->_endwin = FALSE; /* * Check whether we can optimize scrolling under dumb terminals in * case we do not have any of these capabilities, scrolling * optimization will be useless. */ SP->_scrolling = ((scroll_forward && scroll_reverse) || ((parm_rindex || parm_insert_line || insert_line) && (parm_index || parm_delete_line || delete_line))); baudrate(); /* sets a field in the SP structure */ SP->_keytry = 0; /* * Check for mismatched graphic-rendition capabilities. Most SVr4 * terminfo trees contain entries that have rmul or rmso equated to * sgr0 (Solaris curses copes with those entries). We do this only * for curses, since many termcap applications assume that * smso/rmso and smul/rmul are paired, and will not function * properly if we remove rmso or rmul. Curses applications * shouldn't be looking at this detail. */ #define SGR0_TEST(mode) (mode != 0) && (exit_attribute_mode == 0 || strcmp(mode, exit_attribute_mode)) SP->_use_rmso = SGR0_TEST(exit_standout_mode); SP->_use_rmul = SGR0_TEST(exit_underline_mode); /* compute movement costs so we can do better move optimization */ _nc_mvcur_init(); /* initialize terminal to a sane state */ _nc_screen_init(); /* Initialize the terminal line settings. */ _nc_initscr(); _nc_signal_handler(TRUE); result = SP; } } _nc_unlock_global(curses); returnSP(result); }
int main(int argc, char *argv[]) { #ifdef ENABLE_LOGGING setupDebug(); #endif int seed = time(NULL); //args: world seeding only. argc--; argv++; while (argc){ if(std::string(argv[0]) == "--seed"){ argc--; argv++; if(argc){ seed = djb2_hash((unsigned char*)argv[0]); argc--; argv++; } } else // ignore unknown args. argc--; argv++; } // ncurses stuff load_options(); // For getting size options initscr(); // Initialize ncurses noecho(); // Don't echo keypresses cbreak(); // C-style breaks (e.g. ^C to SIGINT) keypad(stdscr, true); // Numpad is numbers init_colors(); // See color.cpp curs_set(0); // Invisible cursor set_escdelay(10); // Make escape actually responsive std::srand(seed); bool quit_game = false; bool delete_world = false; game *g = new game; g->init_ui(); MAPBUFFER.set_game(g); MAPBUFFER.load(); #if (!(defined _WIN32 || defined WINDOWS)) struct sigaction sigIntHandler; sigIntHandler.sa_handler = exit_handler; sigemptyset(&sigIntHandler.sa_mask); sigIntHandler.sa_flags = 0; sigaction(SIGINT, &sigIntHandler, NULL); #endif do { g->setup(); while (!g->do_turn()) ; if (g->uquit == QUIT_DELETE_WORLD) delete_world = true; if (g->game_quit()) quit_game = true; } while (!quit_game); if (delete_world) { g->delete_save(); } else { MAPBUFFER.save_if_dirty(); } exit_handler(-999); return 0; }
int main(int argc, char *argv[]) { int option; int option_index; int passes_through_deck = 3; int use_utf8 = 0; static const struct option options[] = { {"help", no_argument, NULL, 'h'}, {"version", no_argument, NULL, 'v'}, {"passes", required_argument, NULL, 'p'}, {"utf8", no_argument, NULL, 'u'} }; program_name = argv[0]; while ((option = getopt_long(argc, argv, "hvp:u", options, &option_index)) != -1) { switch (option) { case 'v': version(); exit(0); case 'p': passes_through_deck = atoi(optarg); break; case 'u': use_utf8 = true; break; case 'h': default: usage(program_name); exit(0); } } set_utf8_mode(use_utf8); setlocale(LC_ALL, ""); initscr(); raw(); noecho(); keypad(stdscr, TRUE); start_color(); curs_set(FALSE); set_escdelay(0); assume_default_colors(COLOR_WHITE, COLOR_GREEN); init_pair(1, COLOR_BLACK, COLOR_WHITE); init_pair(2, COLOR_RED, COLOR_WHITE); init_pair(3, COLOR_WHITE, COLOR_BLUE); init_pair(4, COLOR_WHITE, COLOR_GREEN); int key; while (!term_size_ok()) { clear(); mvprintw(1, 1, SMALL_TERM_MSG); refresh(); if ((key = getch()) == 'q' || key == 'Q') { endwin(); return(0); } } clear(); draw_greeting(); refresh(); for (;;) { if ((key = getch()) == 'q' || key == 'Q') { endwin(); return(0); } if (term_size_ok()) { clear(); draw_greeting(); refresh(); if (key == KEY_SPACEBAR) { clear(); refresh(); game_init(&game, passes_through_deck); break; } } else if (key == KEY_RESIZE) { clear(); mvprintw(1, 1, SMALL_TERM_MSG); refresh(); } } do { keyboard_event(getch()); } while (!game_won()); endwin(); game_end(); printf("You won.\n"); return(0); }
Screen::Screen( World * const wor, Player * const pl) : VirtScreen(wor, pl), updated(false), cleaned(false) { //ifdefs are adjustments for windows console, added by Panzerschrek #ifdef Q_OS_WIN32 AllocConsole(); freopen( "conout$", "w", stdout ); freopen( "conin$", "r", stdin ); #endif #ifdef Q_OS_WIN32 resize_term( (SCREEN_SIZE + 2) + (2 + 5) + (2 + 3), SCREEN_SIZE * 4 + 4 ); #else set_escdelay(10); #endif initscr(); start_color(); raw(); //send typed keys directly noecho(); //do not print typed symbols keypad(stdscr, TRUE); //use arrows curs_set(0); //invisible cursor //all available color pairs (maybe some of them will not be used) const short colors[]={ //do not change colors order! COLOR_BLACK, COLOR_RED, COLOR_GREEN, COLOR_YELLOW, COLOR_BLUE, COLOR_MAGENTA, COLOR_CYAN, COLOR_WHITE }; for (short i=BLACK_BLACK; i<=WHITE_WHITE; ++i) { init_pair(i, colors[(i-1)/8], colors[(i-1)%8]); } leftWin =newwin(SCREEN_SIZE+2, SCREEN_SIZE*2+2, 0, 0); rightWin=newwin(SCREEN_SIZE+2, SCREEN_SIZE*2+2, 0, SCREEN_SIZE*2+2); hudWin=newwin(3, (SCREEN_SIZE*2+2)*2, SCREEN_SIZE+2, 0); notifyWin=newwin(0, COLS, SCREEN_SIZE+2+3, 0); scrollok(notifyWin, TRUE); notifyLog=fopen("messages.txt", "a"); QSettings sett(QDir::currentPath()+"/freg.ini", QSettings::IniFormat); sett.beginGroup("screen_curses"); shiftFocus=sett.value("focus_shift", 0).toInt(); actionMode=sett.value("action_mode", USE).toInt(); command =sett.value("last_command", "hello").toString(); addstr("Press any key."); qsrand(getch()); Notify("Game started."); input=new IThread(this); input->start(); timer=new QTimer(this); connect(timer, SIGNAL(timeout()), this, SLOT(Print())); timer->start(100); }
static void test_set_escdelay(void) { set_escdelay((100 + ESCDELAY) / 2); }
int APIENTRY WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { int argc = __argc; char **argv = __argv; #else int main(int argc, char *argv[]) { #endif #ifdef ENABLE_LOGGING setupDebug(); #endif int seed = time(NULL); bool verifyexit = false; // set locale to system default setlocale(LC_ALL, ""); #ifdef LOCALIZE bindtextdomain("cataclysm-dda", "lang/mo"); bind_textdomain_codeset("cataclysm-dda", "UTF-8"); textdomain("cataclysm-dda"); #endif //args: world seeding only. argc--; argv++; while (argc) { if(std::string(argv[0]) == "--seed") { argc--; argv++; if(argc) { seed = djb2_hash((unsigned char *)argv[0]); argc--; argv++; } } else if(std::string(argv[0]) == "--jsonverify") { argc--; verifyexit = true; } else { // ignore unknown args. argc--; } argv++; } // ncurses stuff initOptions(); load_options(); // For getting size options initscr(); // Initialize ncurses init_interface(); noecho(); // Don't echo keypresses cbreak(); // C-style breaks (e.g. ^C to SIGINT) keypad(stdscr, true); // Numpad is numbers #if !(defined TILES || defined _WIN32 || defined WINDOWS) // For tiles or windows, this is handled already in initscr(). init_colors(); #endif // curs_set(0); // Invisible cursor set_escdelay(10); // Make escape actually responsive std::srand(seed); bool quit_game = false; g = new game; g->init_data(); if(g->game_error()) { exit_handler(-999); } if ( verifyexit ) { item_controller->check_itype_definitions(); item_controller->check_items_of_groups_exist(); MonsterGenerator::generator().check_monster_definitions(); MonsterGroupManager::check_group_definitions(); check_recipe_definitions(); exit_handler(0); } g->init_ui(); if(g->game_error()) { exit_handler(-999); } curs_set(0); // Invisible cursor here, because MAPBUFFER.load() is crash-prone #if (!(defined _WIN32 || defined WINDOWS)) struct sigaction sigIntHandler; sigIntHandler.sa_handler = exit_handler; sigemptyset(&sigIntHandler.sa_mask); sigIntHandler.sa_flags = 0; sigaction(SIGINT, &sigIntHandler, NULL); #endif do { if(!g->opening_screen()) { quit_game = true; } while (!quit_game && !g->do_turn()) ; if (g->game_quit() || g->game_error()) { quit_game = true; } } while (!quit_game); exit_handler(-999); return 0; }
int main(int argc, char *argv[]) { const char title[] = "MAME YOUR POISON:"; char *cfg = NULL, cmdline[1024]; const char *c; Game *g; int i; if((NULL == (rom = fullPath(romPath))) || (NULL == (xml = fullPath(xmlFile)))) { (void)printf("%s: malloc() fail (rom/xml)\n", argv[0]); return 1; } // ncurses setup initscr(); cbreak(); noecho(); set_escdelay(0); curs_set(0); // Determine if screen is in portrait or landscape mode, get // path to corresponding advmame config file. Method is to // check for 'rotate=0' in TFT module config file. If present // (system() returns 0), is portrait screen, else landscape. c = cfgWide; // Assume landscape screen to start for(i=0; i<N_TFT_FILES; i++) { // Check each TFT config location... (void)sprintf(cmdline, "grep %s=0 %s", tftCfg[i].keyword, tftCfg[i].filename); if(!system(cmdline)) { // Found portrait reference! c = cfgTall; break; } } if(NULL == (cfg = fullPath(c))) { endwin(); (void)printf("%s: malloc() fail (cfg)\n", argv[0]); return 1; } mvprintw(0, (COLS - strlen(title)) / 2, title); mvprintw(LINES-2, 0 , "Up/Down: Choose"); mvprintw(LINES-1, 0 , "Enter : Run game"); mvprintw(LINES-2, COLS/2, "R : Rescan ROMs"); mvprintw(LINES-1, COLS/2, geteuid() ? "Esc: Quit" : "Esc: Shutdown"); mainWin = newwin(LINES-3, COLS, 1, 0); keypad(mainWin, TRUE); box(mainWin, 0, 0); refresh(); find_roms(); for(;;) { switch(wgetch(mainWin)) { case KEY_DOWN: menu_driver(menu, REQ_DOWN_ITEM); break; case KEY_UP: menu_driver(menu, REQ_UP_ITEM); break; case KEY_NPAGE: menu_driver(menu, REQ_SCR_DPAGE); break; case KEY_PPAGE: menu_driver(menu, REQ_SCR_UPAGE); break; case 'r': // Re-scan ROM folder find_roms(); break; case 'R': // Rotate-and-reboot if(!geteuid()) { // Must be root clear(); refresh(); endwin(); for(i=0; i<N_TFT_FILES; i++) { (void)sprintf(cmdline, "sed -i 's/%s=90/Fo0BaR/;" "s/%s=0/%s=90/;" "s/Fo0BaR/%s=0/' %s", tftCfg[i].keyword, tftCfg[i].keyword, tftCfg[i].keyword, tftCfg[i].keyword, tftCfg[i].filename); (void)system(cmdline); } (void)system("reboot"); } break; case 27: // Esc = shutdown (if run as root) or quit clear(); refresh(); endwin(); if(geteuid()) return 0; // Not root, quit to console (void)system("shutdown -h now"); break; case '\n': // Enter case 'z': case 'x': if((g = item_userptr(current_item(menu)))) { (void)sprintf(cmdline, "%s -cfg %s %s", mameCmd, cfg, g->name); def_prog_mode(); endwin(); i = system(cmdline); reset_prog_mode(); if(i) { // If error message, wait for input (void)printf("Press any button..."); fflush(stdout); while(!getch()); } } break; } wrefresh(mainWin); } return 0; }
int APIENTRY WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { int argc = __argc; char **argv = __argv; #else int main(int argc, char *argv[]) { #endif int seed = time(NULL); bool verifyexit = false; bool check_all_mods = false; // Set default file paths #ifdef PREFIX #define Q(STR) #STR #define QUOTE(STR) Q(STR) PATH_INFO::init_base_path(std::string(QUOTE(PREFIX))); #else PATH_INFO::init_base_path(""); #endif #if (defined USE_HOME_DIR || defined USE_XDG_DIR) PATH_INFO::init_user_dir(); #else PATH_INFO::init_user_dir("./"); #endif PATH_INFO::set_standard_filenames(); MAP_SHARING::setDefaults(); { const char *section_default = nullptr; const char *section_map_sharing = "Map sharing"; const char *section_user_directory = "User directories"; const arg_handler first_pass_arguments[] = { { "--seed", "<string of letters and or numbers>", "Sets the random number generator's seed value", section_default, [&seed](int num_args, const char **params) -> int { if (num_args < 1) return -1; const unsigned char *hash_input = (const unsigned char *) params[0]; seed = djb2_hash(hash_input); return 1; } }, { "--jsonverify", nullptr, "Checks the cdda json files", section_default, [&verifyexit](int, const char **) -> int { verifyexit = true; return 0; } }, { "--check-mods", nullptr, "Checks the json files belonging to cdda mods", section_default, [&check_all_mods](int, const char **) -> int { check_all_mods = true; return 0; } }, { "--basepath", "<path>", "Base path for all game data subdirectories", section_default, [](int num_args, const char **params) { if (num_args < 1) return -1; PATH_INFO::init_base_path(params[0]); PATH_INFO::set_standard_filenames(); return 1; } }, { "--shared", nullptr, "Activates the map-sharing mode", section_map_sharing, [](int, const char **) -> int { MAP_SHARING::setSharing(true); MAP_SHARING::setCompetitive(true); MAP_SHARING::setWorldmenu(false); return 0; } }, { "--username", "<name>", "Instructs map-sharing code to use this name for your character.", section_map_sharing, [](int num_args, const char **params) -> int { if (num_args < 1) return -1; MAP_SHARING::setUsername(params[0]); return 1; } }, { "--addadmin", "<username>", "Instructs map-sharing code to use this name for your character and give you " "access to the cheat functions.", section_map_sharing, [](int num_args, const char **params) -> int { if (num_args < 1) return -1; MAP_SHARING::addAdmin(params[0]); return 1; } }, { "--adddebugger", "<username>", "Informs map-sharing code that you're running inside a debugger", section_map_sharing, [](int num_args, const char **params) -> int { if (num_args < 1) return -1; MAP_SHARING::addDebugger(params[0]); return 1; } }, { "--competitive", nullptr, "Instructs map-sharing code to disable access to the in-game cheat functions", section_map_sharing, [](int, const char **) -> int { MAP_SHARING::setCompetitive(true); return 0; } }, { "--userdir", "<path>", "Base path for user-overrides to files from the ./data directory and named below", section_user_directory, [](int num_args, const char **params) -> int { if (num_args < 1) return -1; PATH_INFO::init_user_dir(params[0]); PATH_INFO::set_standard_filenames(); return 1; } } }; // The following arguments are dependent on one or more of the previous flags and are run // in a second pass. const arg_handler second_pass_arguments[] = { { "--worldmenu", nullptr, "Enables the world menu in the map-sharing code", section_map_sharing, [](int, const char **) -> int { MAP_SHARING::setWorldmenu(true); return true; } }, { "--datadir", "<directory name>", "Sub directory from which game data is loaded", nullptr, [](int num_args, const char **params) -> int { if (num_args < 1) return -1; PATH_INFO::update_pathname("datadir", params[0]); PATH_INFO::update_datadir(); return 1; } }, { "--savedir", "<directory name>", "Subdirectory for game saves", section_user_directory, [](int num_args, const char **params) -> int { if (num_args < 1) return -1; PATH_INFO::update_pathname("savedir", params[0]); return 1; } }, { "--configdir", "<directory name>", "Subdirectory for game configuration", section_user_directory, [](int num_args, const char **params) -> int { if (num_args < 1) return -1; PATH_INFO::update_pathname("config_dir", params[0]); PATH_INFO::update_config_dir(); return 1; } }, { "--memorialdir", "<directory name>", "Subdirectory for memorials", section_user_directory, [](int num_args, const char **params) -> int { if (num_args < 1) return -1; PATH_INFO::update_pathname("memorialdir", params[0]); return 1; } }, { "--optionfile", "<filename>", "Name of the options file within the configdir", section_user_directory, [](int num_args, const char **params) -> int { if (num_args < 1) return -1; PATH_INFO::update_pathname("options", params[0]); return 1; } }, { "--keymapfile", "<filename>", "Name of the keymap file within the configdir", section_user_directory, [](int num_args, const char **params) -> int { if (num_args < 1) return -1; PATH_INFO::update_pathname("keymap", params[0]); return 1; } }, { "--autopickupfile", "<filename>", "Name of the autopickup options file within the configdir", nullptr, [](int num_args, const char **params) -> int { if (num_args < 1) return -1; PATH_INFO::update_pathname("autopickup", params[0]); return 1; } }, { "--motdfile", "<filename>", "Name of the message of the day file within the motd directory", nullptr, [](int num_args, const char **params) -> int { if (num_args < 1) return -1; PATH_INFO::update_pathname("motd", params[0]); return 1; } }, }; // Process CLI arguments. const size_t num_first_pass_arguments = sizeof(first_pass_arguments) / sizeof(first_pass_arguments[0]); const size_t num_second_pass_arguments = sizeof(second_pass_arguments) / sizeof(second_pass_arguments[0]); int saved_argc = --argc; // skip program name const char **saved_argv = (const char **)++argv; while (argc) { if(!strcmp(argv[0], "--help")) { printHelpMessage(first_pass_arguments, num_first_pass_arguments, second_pass_arguments, num_second_pass_arguments); return 0; } else { bool arg_handled = false; for (size_t i = 0; i < num_first_pass_arguments; ++i) { auto &arg_handler = first_pass_arguments[i]; if (!strcmp(argv[0], arg_handler.flag)) { argc--; argv++; int args_consumed = arg_handler.handler(argc, (const char **)argv); if (args_consumed < 0) { printf("Failed parsing parameter '%s'\n", *(argv - 1)); exit(1); } argc -= args_consumed; argv += args_consumed; arg_handled = true; break; } } // Skip other options. if (!arg_handled) { --argc; ++argv; } } } while (saved_argc) { bool arg_handled = false; for (size_t i = 0; i < num_second_pass_arguments; ++i) { auto &arg_handler = second_pass_arguments[i]; if (!strcmp(saved_argv[0], arg_handler.flag)) { --saved_argc; ++saved_argv; int args_consumed = arg_handler.handler(saved_argc, saved_argv); if (args_consumed < 0) { printf("Failed parsing parameter '%s'\n", *(argv - 1)); exit(1); } saved_argc -= args_consumed; saved_argv += args_consumed; arg_handled = true; break; } } // Ingore unknown options. if (!arg_handled) { --saved_argc; ++saved_argv; } } } if (!assure_dir_exist(FILENAMES["user_dir"].c_str())) { printf("Can't open or create %s. Check permissions.\n", FILENAMES["user_dir"].c_str()); exit(1); } setupDebug(); if (setlocale(LC_ALL, "") == NULL) { DebugLog(D_WARNING, D_MAIN) << "Error while setlocale(LC_ALL, '')."; } // Options strings loaded with system locale get_options().init(); get_options().load(); set_language(true); if (initscr() == NULL) { // Initialize ncurses DebugLog( D_ERROR, DC_ALL ) << "initscr failed!"; return 1; } init_interface(); noecho(); // Don't echo keypresses cbreak(); // C-style breaks (e.g. ^C to SIGINT) keypad(stdscr, true); // Numpad is numbers #if !(defined TILES || defined _WIN32 || defined WINDOWS) // For tiles or windows, this is handled already in initscr(). init_colors(); #endif // curs_set(0); // Invisible cursor set_escdelay(10); // Make escape actually responsive std::srand(seed); g = new game; // First load and initialize everything that does not // depend on the mods. try { g->load_static_data(); if (verifyexit) { if(g->game_error()) { exit_handler(-999); } exit_handler(0); } if (check_all_mods) { // Here we load all the mods and check their // consistency (both is done in check_all_mod_data). g->init_ui(); popup_nowait("checking all mods"); g->check_all_mod_data(); if(g->game_error()) { exit_handler(-999); } // At this stage, the mods (and core game data) // are find and we could start playing, but this // is only for verifying that stage, so we exit. exit_handler(0); } } catch( const std::exception &err ) { debugmsg( "%s", err.what() ); exit_handler(-999); } // Now we do the actual game. g->init_ui(); if(g->game_error()) { exit_handler(-999); } curs_set(0); // Invisible cursor here, because MAPBUFFER.load() is crash-prone #if (!(defined _WIN32 || defined WINDOWS)) struct sigaction sigIntHandler; sigIntHandler.sa_handler = exit_handler; sigemptyset(&sigIntHandler.sa_mask); sigIntHandler.sa_flags = 0; sigaction(SIGINT, &sigIntHandler, NULL); #endif bool quit_game = false; do { if(!g->opening_screen()) { quit_game = true; } while (!quit_game && !g->do_turn()) ; if (g->game_quit() || g->game_error()) { quit_game = true; } } while (!quit_game); exit_handler(-999); return 0; }
/** initialize user interface */ void ui_init() { /* modify stdin terminals attributes to allow Ctrl-Q/S key recognition */ tcgetattr(STDIN_FILENO, &oldt); newt = oldt; newt.c_iflag &= ~(IXON); tcsetattr(STDIN_FILENO, TCSANOW, &newt); /* getting users terminal string and (if RXVT) setting rxvt colours on it */ /* LZ3NY hack :) */ char *term = getenv("TERM"); if (strcasecmp(term, "rxvt") == 0) { use_rxvt = 1; } else if (strcasecmp(term, "xterm") == 0) { use_xterm = 1; use_rxvt = 1; } /* Check the environment variable ESCDELAY. * * If unset set it to 25 mS which should allow enough time to capture * escaped key codes and yet be fast enough to call stoptx() when needed * by the user. When unset Ncurses assumes a default value of 1000 mS so * use set_escdelay(0) to set it as the Ncurses documentation declares this * method to be thread safe. * * Else let Ncurses honor the user defined value of the env variable. */ if (getenv("ESCDELAY") == NULL) { set_escdelay(25); } /* activate ncurses terminal control */ if ((mainscreen = newterm(NULL, stdout, stdin)) == NULL) { perror("initscr"); printf ("\nSorry, wrong terminal type !!!!! \nTry a linux text terminal or set TERM=linux !!!\n"); sleep(2); exit(EXIT_FAILURE); } InitSearchPanel(); /* at least one panel has to be defined for refreshp() to work */ getmaxyx(stdscr, ymax, xmax); if ((ymax < 25) || (xmax < 80)) { char c; showmsg("!! TLF needs at least 25 lines and 80 columns !!"); showmsg(" Continue anyway? Y/(N)"); c = toupper(key_get()); if (c != 'Y') { showmsg("73 es cuagn"); sleep(1); endwin(); exit(EXIT_FAILURE); } showmsg(""); } if (!has_colors() || (start_color() == ERR)) { showmsg("Sorry, terminal does not support color"); showmsg("Try TERM=linux or use a text console !!"); sleep(2); endwin(); exit(EXIT_FAILURE); } refreshp(); noecho(); cbreak(); keypad(stdscr, TRUE); lookup_keys(); }
int APIENTRY WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { int argc = __argc; char **argv = __argv; #else int main(int argc, char *argv[]) { #endif int seed = time(NULL); bool verifyexit = false; bool check_mods = false; std::string dump; dump_mode dmode = dump_mode::TSV; std::vector<std::string> opts; std::string world; /** if set try to load first save in this world on startup */ // Set default file paths #ifdef PREFIX #define Q(STR) #STR #define QUOTE(STR) Q(STR) PATH_INFO::init_base_path(std::string(QUOTE(PREFIX))); #else PATH_INFO::init_base_path(""); #endif #if (defined USE_HOME_DIR || defined USE_XDG_DIR) PATH_INFO::init_user_dir(); #else PATH_INFO::init_user_dir("./"); #endif PATH_INFO::set_standard_filenames(); MAP_SHARING::setDefaults(); { const char *section_default = nullptr; const char *section_map_sharing = "Map sharing"; const char *section_user_directory = "User directories"; const std::array<arg_handler, 12> first_pass_arguments = {{ { "--seed", "<string of letters and or numbers>", "Sets the random number generator's seed value", section_default, [&seed](int num_args, const char **params) -> int { if (num_args < 1) return -1; const unsigned char *hash_input = (const unsigned char *) params[0]; seed = djb2_hash(hash_input); return 1; } }, { "--jsonverify", nullptr, "Checks the cdda json files", section_default, [&verifyexit](int, const char **) -> int { verifyexit = true; return 0; } }, { "--check-mods", "[mods...]", "Checks the json files belonging to cdda mods", section_default, [&check_mods,&opts]( int n, const char *params[] ) -> int { check_mods = true; test_mode = true; for( int i = 0; i < n; ++i ) { opts.emplace_back( params[ i ] ); } return 0; } }, { "--dump-stats", "<what> [mode = TSV] [opts...]", "Dumps item stats", section_default, [&dump,&dmode,&opts](int n, const char *params[]) -> int { if( n < 1 ) { return -1; } test_mode = true; dump = params[ 0 ]; for( int i = 2; i < n; ++i ) { opts.emplace_back( params[ i ] ); } if( n >= 2 ) { if( !strcmp( params[ 1 ], "TSV" ) ) { dmode = dump_mode::TSV; return 0; } else if( !strcmp( params[ 1 ], "HTML" ) ) { dmode = dump_mode::HTML; return 0; } else { return -1; } } return 0; } }, { "--world", "<name>", "Load world", section_default, [&world](int n, const char *params[]) -> int { if( n < 1 ) { return -1; } world = params[0]; return 1; } }, { "--basepath", "<path>", "Base path for all game data subdirectories", section_default, [](int num_args, const char **params) { if (num_args < 1) return -1; PATH_INFO::init_base_path(params[0]); PATH_INFO::set_standard_filenames(); return 1; } }, { "--shared", nullptr, "Activates the map-sharing mode", section_map_sharing, [](int, const char **) -> int { MAP_SHARING::setSharing(true); MAP_SHARING::setCompetitive(true); MAP_SHARING::setWorldmenu(false); return 0; } }, { "--username", "<name>", "Instructs map-sharing code to use this name for your character.", section_map_sharing, [](int num_args, const char **params) -> int { if (num_args < 1) return -1; MAP_SHARING::setUsername(params[0]); return 1; } }, { "--addadmin", "<username>", "Instructs map-sharing code to use this name for your character and give you " "access to the cheat functions.", section_map_sharing, [](int num_args, const char **params) -> int { if (num_args < 1) return -1; MAP_SHARING::addAdmin(params[0]); return 1; } }, { "--adddebugger", "<username>", "Informs map-sharing code that you're running inside a debugger", section_map_sharing, [](int num_args, const char **params) -> int { if (num_args < 1) return -1; MAP_SHARING::addDebugger(params[0]); return 1; } }, { "--competitive", nullptr, "Instructs map-sharing code to disable access to the in-game cheat functions", section_map_sharing, [](int, const char **) -> int { MAP_SHARING::setCompetitive(true); return 0; } }, { "--userdir", "<path>", "Base path for user-overrides to files from the ./data directory and named below", section_user_directory, [](int num_args, const char **params) -> int { if (num_args < 1) return -1; PATH_INFO::init_user_dir(params[0]); PATH_INFO::set_standard_filenames(); return 1; } } }}; // The following arguments are dependent on one or more of the previous flags and are run // in a second pass. const std::array<arg_handler, 9> second_pass_arguments = {{ { "--worldmenu", nullptr, "Enables the world menu in the map-sharing code", section_map_sharing, [](int, const char **) -> int { MAP_SHARING::setWorldmenu(true); return true; } }, { "--datadir", "<directory name>", "Sub directory from which game data is loaded", nullptr, [](int num_args, const char **params) -> int { if (num_args < 1) return -1; PATH_INFO::update_pathname("datadir", params[0]); PATH_INFO::update_datadir(); return 1; } }, { "--savedir", "<directory name>", "Subdirectory for game saves", section_user_directory, [](int num_args, const char **params) -> int { if (num_args < 1) return -1; PATH_INFO::update_pathname("savedir", params[0]); return 1; } }, { "--configdir", "<directory name>", "Subdirectory for game configuration", section_user_directory, [](int num_args, const char **params) -> int { if (num_args < 1) return -1; PATH_INFO::update_pathname("config_dir", params[0]); PATH_INFO::update_config_dir(); return 1; } }, { "--memorialdir", "<directory name>", "Subdirectory for memorials", section_user_directory, [](int num_args, const char **params) -> int { if (num_args < 1) return -1; PATH_INFO::update_pathname("memorialdir", params[0]); return 1; } }, { "--optionfile", "<filename>", "Name of the options file within the configdir", section_user_directory, [](int num_args, const char **params) -> int { if (num_args < 1) return -1; PATH_INFO::update_pathname("options", params[0]); return 1; } }, { "--keymapfile", "<filename>", "Name of the keymap file within the configdir", section_user_directory, [](int num_args, const char **params) -> int { if (num_args < 1) return -1; PATH_INFO::update_pathname("keymap", params[0]); return 1; } }, { "--autopickupfile", "<filename>", "Name of the autopickup options file within the configdir", nullptr, [](int num_args, const char **params) -> int { if (num_args < 1) return -1; PATH_INFO::update_pathname("autopickup", params[0]); return 1; } }, { "--motdfile", "<filename>", "Name of the message of the day file within the motd directory", nullptr, [](int num_args, const char **params) -> int { if (num_args < 1) return -1; PATH_INFO::update_pathname("motd", params[0]); return 1; } }, }}; // Process CLI arguments. const size_t num_first_pass_arguments = sizeof(first_pass_arguments) / sizeof(first_pass_arguments[0]); const size_t num_second_pass_arguments = sizeof(second_pass_arguments) / sizeof(second_pass_arguments[0]); int saved_argc = --argc; // skip program name const char **saved_argv = (const char **)++argv; while (argc) { if(!strcmp(argv[0], "--help")) { printHelpMessage(first_pass_arguments.data(), num_first_pass_arguments, second_pass_arguments.data(), num_second_pass_arguments); return 0; } else { bool arg_handled = false; for (size_t i = 0; i < num_first_pass_arguments; ++i) { auto &arg_handler = first_pass_arguments[i]; if (!strcmp(argv[0], arg_handler.flag)) { argc--; argv++; int args_consumed = arg_handler.handler(argc, (const char **)argv); if (args_consumed < 0) { printf("Failed parsing parameter '%s'\n", *(argv - 1)); exit(1); } argc -= args_consumed; argv += args_consumed; arg_handled = true; break; } } // Skip other options. if (!arg_handled) { --argc; ++argv; } } } while (saved_argc) { bool arg_handled = false; for (size_t i = 0; i < num_second_pass_arguments; ++i) { auto &arg_handler = second_pass_arguments[i]; if (!strcmp(saved_argv[0], arg_handler.flag)) { --saved_argc; ++saved_argv; int args_consumed = arg_handler.handler(saved_argc, saved_argv); if (args_consumed < 0) { printf("Failed parsing parameter '%s'\n", *(argv - 1)); exit(1); } saved_argc -= args_consumed; saved_argv += args_consumed; arg_handled = true; break; } } // Ingore unknown options. if (!arg_handled) { --saved_argc; ++saved_argv; } } } if (!assure_dir_exist(FILENAMES["user_dir"].c_str())) { printf("Can't open or create %s. Check permissions.\n", FILENAMES["user_dir"].c_str()); exit(1); } setupDebug(); if (setlocale(LC_ALL, "") == NULL) { DebugLog(D_WARNING, D_MAIN) << "Error while setlocale(LC_ALL, '')."; } else { try { std::locale::global( std::locale( "" ) ); } catch( const std::exception& ) { // if user default locale retrieval isn't implemented by system try{ // default to basic C locale std::locale::global( std::locale::classic() ); } catch( const std::exception &err ) { debugmsg( "%s", err.what() ); exit_handler(-999); } } } get_options().init(); get_options().load(); set_language(); // in test mode don't initialize curses to avoid escape sequences being inserted into output stream if( !test_mode ) { if( initscr() == nullptr ) { // Initialize ncurses DebugLog( D_ERROR, DC_ALL ) << "initscr failed!"; return 1; } init_interface(); noecho(); // Don't echo keypresses cbreak(); // C-style breaks (e.g. ^C to SIGINT) keypad(stdscr, true); // Numpad is numbers } #if !(defined TILES || defined _WIN32 || defined WINDOWS) // For tiles or windows, this is handled already in initscr(). init_colors(); #endif // curs_set(0); // Invisible cursor set_escdelay(10); // Make escape actually responsive srand(seed); g = new game; // First load and initialize everything that does not // depend on the mods. try { g->load_static_data(); if (verifyexit) { exit_handler(0); } if( !dump.empty() ) { init_colors(); exit( g->dump_stats( dump, dmode, opts ) ? 0 : 1 ); } if( check_mods ) { init_colors(); loading_ui ui( false ); exit( g->check_mod_data( opts, ui ) && !test_dirty ? 0 : 1 ); } } catch( const std::exception &err ) { debugmsg( "%s", err.what() ); exit_handler(-999); } // Now we do the actual game. g->init_ui(); curs_set(0); // Invisible cursor here, because MAPBUFFER.load() is crash-prone #if (!(defined _WIN32 || defined WINDOWS)) struct sigaction sigIntHandler; sigIntHandler.sa_handler = exit_handler; sigemptyset(&sigIntHandler.sa_mask); sigIntHandler.sa_flags = 0; sigaction(SIGINT, &sigIntHandler, NULL); #endif while( true ) { if( !world.empty() ) { if( !g->load( world ) ) { break; } world.clear(); // ensure quit returns to opening screen } else { main_menu menu; if( !menu.opening_screen() ) { break; } } while( !g->do_turn() ); }; exit_handler(-999); return 0; }