void Sys_SetUpConsoleAndSignals(void) { #ifndef USE_WINDOWS_CONSOLE #ifdef FEATURE_CURSES if (nocurses) { CON_Init_tty(); } else { CON_Init(); } #else CON_Init(); #endif #endif signal(SIGILL, Sys_SigHandler); signal(SIGFPE, Sys_SigHandler); signal(SIGSEGV, Sys_SigHandler); signal(SIGTERM, Sys_SigHandler); signal(SIGINT, Sys_SigHandler); }
/* ================= main ================= */ int main(int argc, char **argv) { int i; char commandLine[MAX_STRING_CHARS] = { 0 }; #ifndef DEDICATED // SDL version check // Compile time # if !SDL_VERSION_ATLEAST(MINSDL_MAJOR, MINSDL_MINOR, MINSDL_PATCH) # error A more recent version of SDL is required # endif // Run time const SDL_version *ver = SDL_Linked_Version(); #define MINSDL_VERSION \ XSTRING(MINSDL_MAJOR) "." \ XSTRING(MINSDL_MINOR) "." \ XSTRING(MINSDL_PATCH) if (SDL_VERSIONNUM(ver->major, ver->minor, ver->patch) < SDL_VERSIONNUM(MINSDL_MAJOR, MINSDL_MINOR, MINSDL_PATCH)) { Sys_Dialog(DT_ERROR, va("SDL version " MINSDL_VERSION " or greater is required, " "but only version %d.%d.%d was found. You may be able to obtain a more recent copy " "from http://www.libsdl.org/.", ver->major, ver->minor, ver->patch), "SDL Library Too Old"); Sys_Exit(1); } #endif #ifdef __MORPHOS__ // don't let locales with decimal comma screw up the string to float conversions setlocale(LC_NUMERIC, "C"); DynLoadBase = OpenLibrary("dynload.library", 51); if (DynLoadBase && DynLoadBase->lib_Revision < 3) { CloseLibrary(DynLoadBase); DynLoadBase = NULL; } if (!DynLoadBase) { Sys_Dialog(DT_ERROR, "Unable to open dynload.library version 51.3 or newer", "dynload.library error"); Sys_Exit(1); } #endif Sys_PlatformInit(); // Set the initial time base Sys_Milliseconds(); Sys_ParseArgs(argc, argv); #if defined(__APPLE__) && !defined(DEDICATED) // argv[0] would be /Users/seth/etlegacy/etl.app/Contents/MacOS // But on OS X we want to pretend the binary path is the .app's parent // So that way the base folder is right next to the .app allowing { char parentdir[1024]; CFURLRef url = CFBundleCopyBundleURL(CFBundleGetMainBundle()); if (!url) { Sys_Dialog(DT_ERROR, "A CFURL for the app bundle could not be found.", "Can't set Sys_SetBinaryPath"); Sys_Exit(1); } CFURLRef url2 = CFURLCreateCopyDeletingLastPathComponent(0, url); if (!url2 || !CFURLGetFileSystemRepresentation(url2, 1, (UInt8 *)parentdir, 1024)) { Sys_Dialog(DT_ERROR, "CFURLGetFileSystemRepresentation returned an error when finding the app bundle's parent directory.", "Can't set Sys_SetBinaryPath"); Sys_Exit(1); } Sys_SetBinaryPath(parentdir); CFRelease(url); CFRelease(url2); } #else Sys_SetBinaryPath(Sys_Dirname(argv[0])); #endif Sys_SetDefaultInstallPath(DEFAULT_BASEDIR); // Sys_BinaryPath() by default // Concatenate the command line for passing to Com_Init for (i = 1; i < argc; i++) { const qboolean containsSpaces = (qboolean)(strchr(argv[i], ' ') != NULL); if (containsSpaces) { Q_strcat(commandLine, sizeof(commandLine), "\""); } Q_strcat(commandLine, sizeof(commandLine), argv[i]); if (containsSpaces) { Q_strcat(commandLine, sizeof(commandLine), "\""); } Q_strcat(commandLine, sizeof(commandLine), " "); } Com_Init(commandLine); NET_Init(); #ifdef FEATURE_CURSES if (nocurses) { CON_Init_tty(); } else { CON_Init(); } #else CON_Init(); #endif signal(SIGILL, Sys_SigHandler); signal(SIGFPE, Sys_SigHandler); signal(SIGSEGV, Sys_SigHandler); signal(SIGTERM, Sys_SigHandler); signal(SIGINT, Sys_SigHandler); while (1) { IN_Frame(); Com_Frame(); } return 0; }
/* ================= main ================= */ int main(int argc, char **argv) { int i; char commandLine[MAX_STRING_CHARS] = { 0 }; #ifndef DEDICATED // SDL version check // Compile time # if !SDL_VERSION_ATLEAST(MINSDL_MAJOR, MINSDL_MINOR, MINSDL_PATCH) # error A more recent version of SDL is required # endif // Run time const SDL_version *ver = SDL_Linked_Version(); #define MINSDL_VERSION \ XSTRING(MINSDL_MAJOR) "." \ XSTRING(MINSDL_MINOR) "." \ XSTRING(MINSDL_PATCH) if (SDL_VERSIONNUM(ver->major, ver->minor, ver->patch) < SDL_VERSIONNUM(MINSDL_MAJOR, MINSDL_MINOR, MINSDL_PATCH)) { Sys_Dialog(DT_ERROR, va("SDL version " MINSDL_VERSION " or greater is required, " "but only version %d.%d.%d was found. You may be able to obtain a more recent copy " "from http://www.libsdl.org/.", ver->major, ver->minor, ver->patch), "SDL Library Too Old"); Sys_Exit(1); } #endif Sys_PlatformInit(); // Set the initial time base Sys_Milliseconds(); Sys_ParseArgs(argc, argv); Sys_SetBinaryPath(Sys_Dirname(argv[0])); Sys_SetDefaultInstallPath(DEFAULT_BASEDIR); // Concatenate the command line for passing to Com_Init for (i = 1; i < argc; i++) { const qboolean containsSpaces = (qboolean)(strchr(argv[i], ' ') != NULL); if (containsSpaces) { Q_strcat(commandLine, sizeof(commandLine), "\""); } Q_strcat(commandLine, sizeof(commandLine), argv[i]); if (containsSpaces) { Q_strcat(commandLine, sizeof(commandLine), "\""); } Q_strcat(commandLine, sizeof(commandLine), " "); } Com_Init(commandLine); NET_Init(); #ifdef FEATURE_CURSES if (nocurses) { CON_Init_tty(); } else { CON_Init(); } #else CON_Init(); #endif signal(SIGILL, Sys_SigHandler); signal(SIGFPE, Sys_SigHandler); signal(SIGSEGV, Sys_SigHandler); signal(SIGTERM, Sys_SigHandler); signal(SIGINT, Sys_SigHandler); while (1) { IN_Frame(); Com_Frame(); } return 0; }
/* ================== CON_Init Initialize the console in curses mode, fall back to tty mode on failure ================== */ void CON_Init(void) { int col; #ifndef _WIN32 // If the process is backgrounded (running non interactively) // then SIGTTIN or SIGTOU is emitted, if not caught, turns into a SIGSTP signal(SIGTTIN, SIG_IGN); signal(SIGTTOU, SIG_IGN); #endif // Make sure we're on a tty if (isatty(STDIN_FILENO) != 1 || isatty(STDOUT_FILENO) != 1 || isatty(STDERR_FILENO) != 1) { CON_Init_tty(); return; } // Initialize curses and set up the root window if (!curses_on) { SCREEN *test = newterm(NULL, stdout, stdin); if (!test) { CON_Init_tty(); CON_Print_tty("Couldn't initialize curses, falling back to tty\n"); return; } endwin(); delscreen(test); initscr(); cbreak(); noecho(); nonl(); intrflush(stdscr, FALSE); nodelay(stdscr, TRUE); keypad(stdscr, TRUE); wnoutrefresh(stdscr); // Set up colors if (has_colors()) { use_default_colors(); start_color(); init_pair(1, COLOR_BLACK, -1); init_pair(2, COLOR_RED, -1); init_pair(3, COLOR_GREEN, -1); init_pair(4, COLOR_YELLOW, -1); init_pair(5, COLOR_BLUE, -1); init_pair(6, COLOR_CYAN, -1); init_pair(7, COLOR_MAGENTA, -1); init_pair(8, -1, -1); } } // Create the border borderwin = newwin(LOG_LINES + 2, LOG_COLS + 2, 1, 0); CON_SetColor(borderwin, 2); box(borderwin, 0, 0); wnoutrefresh(borderwin); // Create the log window logwin = newpad(MAX_LOG_LINES, LOG_COLS); scrollok(logwin, TRUE); idlok(logwin, TRUE); if (curses_on) CON_ColorPrint(logwin, logbuf, qtrue); getyx(logwin, lastline, col); if (col) lastline++; scrollline = lastline - LOG_LINES; if (scrollline < 0) scrollline = 0; pnoutrefresh(logwin, scrollline, 0, 2, 1, LOG_LINES + 1, LOG_COLS + 1); // Create the scroll bar scrollwin = newwin(LOG_LINES, 1, 2, COLS - 1); CON_DrawScrollBar(); CON_SetColor(stdscr, 3); mvaddch(1, COLS - 1, SCRLBAR_UP); mvaddch(LINES - 2, COLS - 1, SCRLBAR_DOWN); // Create the input field inputwin = newwin(1, COLS - Q_PrintStrlen(PROMPT) - 8, LINES - 1, Q_PrintStrlen(PROMPT) + 8); input_field.widthInChars = COLS - Q_PrintStrlen(PROMPT) - 9; if (curses_on) { if (input_field.cursor < input_field.scroll) input_field.scroll = input_field.cursor; else if (input_field.cursor >= input_field.scroll + input_field.widthInChars) input_field.scroll = input_field.cursor - input_field.widthInChars + 1; CON_ColorPrint(inputwin, input_field.buffer + input_field.scroll, qfalse); } CON_UpdateCursor(); wnoutrefresh(inputwin); // Create the clock clockwin = newwin(1, 8, LINES - 1, 0); CON_UpdateClock(); // Display the title and input prompt move(0, (COLS - Q_PrintStrlen(TITLE)) / 2); CON_ColorPrint(stdscr, TITLE, qtrue); move(LINES - 1, 8); CON_ColorPrint(stdscr, PROMPT, qtrue); wnoutrefresh(stdscr); doupdate(); #ifndef _WIN32 // Catch window resizes signal(SIGWINCH, (void *)CON_Resize); #endif curses_on = qtrue; }