- /* initialize once, or not at all */
- if (!console_initialized) {
- int i;
- DWORD num_buttons;
- WORD a;
- BOOL buffered = FALSE;
- BOOL b;
-
- START_TRACE();
- WINCONSOLE.isTermInfoConsole = assumeTermInfo;
-
- WINCONSOLE.map = (LPDWORD)malloc(sizeof(DWORD)*MAPSIZE);
- WINCONSOLE.rmap = (LPDWORD)malloc(sizeof(DWORD)*MAPSIZE);
- WINCONSOLE.ansi_map = (LPDWORD)malloc(sizeof(DWORD)*MAPSIZE);
-
- for (i = 0; i < (N_INI + FKEYS); i++) {
- if (i < N_INI) {
- WINCONSOLE.rmap[i] = WINCONSOLE.map[i] =
- (DWORD) keylist[i];
- WINCONSOLE.ansi_map[i] = (DWORD) ansi_keys[i];
- } else {
- WINCONSOLE.rmap[i] = WINCONSOLE.map[i] =
- (DWORD) GenMap((VK_F1 + (i - N_INI)),
- (KEY_F(1) + (i - N_INI)));
- WINCONSOLE.ansi_map[i] =
- (DWORD) GenMap((VK_F1 + (i - N_INI)),
- (';' + (i - N_INI)));
- }
- }
- qsort(WINCONSOLE.ansi_map,
- (size_t) (MAPSIZE),
- sizeof(keylist[0]),
- keycompare);
- qsort(WINCONSOLE.map,
- (size_t) (MAPSIZE),
- sizeof(keylist[0]),
- keycompare);
- qsort(WINCONSOLE.rmap,
- (size_t) (MAPSIZE),
- sizeof(keylist[0]),
- rkeycompare);
-
- if (GetNumberOfConsoleMouseButtons(&num_buttons)) {
- WINCONSOLE.numButtons = (int) num_buttons;
- } else {
- WINCONSOLE.numButtons = 1;
- }
-
- a = _nc_console_MapColor(true, COLOR_WHITE) |
- _nc_console_MapColor(false, COLOR_BLACK);
- for (i = 0; i < CON_NUMPAIRS; i++)
- WINCONSOLE.pairs[i] = a;
-
- WINCONSOLE.inp = GetStdHandle(STD_INPUT_HANDLE);
- WINCONSOLE.out = GetStdHandle(STD_OUTPUT_HANDLE);
- WINCONSOLE.hdl = WINCONSOLE.out;
-
- GetConsoleMode(WINCONSOLE.inp, &WINCONSOLE.originalMode.dwFlagIn);
- GetConsoleMode(WINCONSOLE.out, &WINCONSOLE.originalMode.dwFlagOut);
-
- if (!WINCONSOLE.isTermInfoConsole) {
- b = AllocConsole();
-
- if (!b)
- b = AttachConsole(ATTACH_PARENT_PROCESS);
-
- if (getenv("NCGDB") || getenv("NCURSES_CONSOLE2")) {
- T(("... will not buffer console"));
- } else {
- T(("... creating console buffer"));
- WINCONSOLE.hdl =
- CreateConsoleScreenBuffer(GENERIC_READ | GENERIC_WRITE,
- 0,
- NULL,
- CONSOLE_TEXTMODE_BUFFER,
- NULL);
- buffered = TRUE;
- }
- }
-
- /* We set binary I/O even when using the console
- driver to cover the situation, that the
- TERM variable is set to #win32con, but actually
- Windows supports virtual terminal processing.
- So if terminfo functions are used in this setup,
- they actually may work.
- */
- _setmode(fileno(stdin), _O_BINARY);
- _setmode(fileno(stdout), _O_BINARY);
-
- if (WINCONSOLE.hdl != INVALID_HANDLE_VALUE) {
- WINCONSOLE.buffered = buffered;
- _nc_console_get_SBI();
- WINCONSOLE.save_SBI = WINCONSOLE.SBI;
- if (!buffered) {
- save_original_screen();
- _nc_console_set_scrollback(FALSE, &WINCONSOLE.SBI);
- }
- GetConsoleCursorInfo(WINCONSOLE.hdl, &WINCONSOLE.save_CI);
- T(("... initial cursor is %svisible, %d%%",
- (WINCONSOLE.save_CI.bVisible ? "" : "not-"),
- (int) WINCONSOLE.save_CI.dwSize));
- }
-
- WINCONSOLE.initialized = TRUE;
- console_initialized = TRUE;
- }
- res = (WINCONSOLE.hdl != INVALID_HANDLE_VALUE);
+ /* initialize once, or not at all */
+ if (!console_initialized) {
+ int i;
+ DWORD num_buttons;
+ WORD a;
+ BOOL buffered = FALSE;
+ BOOL b;
+
+ START_TRACE();
+ WINCONSOLE.isTermInfoConsole = assumeTermInfo;
+
+ WINCONSOLE.map = (LPDWORD) malloc(sizeof(DWORD) * MAPSIZE);
+ WINCONSOLE.rmap = (LPDWORD) malloc(sizeof(DWORD) * MAPSIZE);
+ WINCONSOLE.ansi_map = (LPDWORD) malloc(sizeof(DWORD) * MAPSIZE);
+
+ for (i = 0; i < (N_INI + FKEYS); i++) {
+ if (i < N_INI) {
+ WINCONSOLE.rmap[i] = WINCONSOLE.map[i] =
+ (DWORD) keylist[i];
+ WINCONSOLE.ansi_map[i] = (DWORD) ansi_keys[i];
+ } else {
+ WINCONSOLE.rmap[i] = WINCONSOLE.map[i] =
+ (DWORD) GenMap((VK_F1 + (i - N_INI)),
+ (KEY_F(1) + (i - N_INI)));
+ WINCONSOLE.ansi_map[i] =
+ (DWORD) GenMap((VK_F1 + (i - N_INI)),
+ (';' + (i - N_INI)));
+ }
+ }
+ qsort(WINCONSOLE.ansi_map,
+ (size_t) (MAPSIZE),
+ sizeof(keylist[0]),
+ keycompare);
+ qsort(WINCONSOLE.map,
+ (size_t) (MAPSIZE),
+ sizeof(keylist[0]),
+ keycompare);
+ qsort(WINCONSOLE.rmap,
+ (size_t) (MAPSIZE),
+ sizeof(keylist[0]),
+ rkeycompare);
+
+ if (GetNumberOfConsoleMouseButtons(&num_buttons)) {
+ WINCONSOLE.numButtons = (int) num_buttons;
+ } else {
+ WINCONSOLE.numButtons = 1;
+ }
+
+ a = _nc_console_MapColor(true, COLOR_WHITE) |
+ _nc_console_MapColor(false, COLOR_BLACK);
+ for (i = 0; i < CON_NUMPAIRS; i++)
+ WINCONSOLE.pairs[i] = a;
+
+#define SaveConsoleMode(handle, data) \
+ GetConsoleMode(WINCONSOLE.handle, &WINCONSOLE.originalMode.value)
+
+ if (WINCONSOLE.isTermInfoConsole) {
+ WINCONSOLE.inp = GetStdHandle(STD_INPUT_HANDLE);
+ WINCONSOLE.out = GetStdHandle(STD_OUTPUT_HANDLE);
+ WINCONSOLE.hdl = WINCONSOLE.out;
+
+ SaveConsoleMode(inp, dwFlagIn);
+ SaveConsoleMode(out, dwFlagOut);
+
+ } else {
+ b = AllocConsole();
+
+ if (!b)
+ b = AttachConsole(ATTACH_PARENT_PROCESS);
+
+ WINCONSOLE.inp = GetDirectHandle("CONIN$", FILE_SHARE_READ);
+ WINCONSOLE.out = GetDirectHandle("CONOUT$", FILE_SHARE_WRITE);
+
+ SaveConsoleMode(inp, dwFlagIn);
+ SaveConsoleMode(out, dwFlagOut);
+
+ if (getenv("NCGDB") || getenv("NCURSES_CONSOLE2")) {
+ WINCONSOLE.hdl = WINCONSOLE.out;
+ T(("... will not buffer console"));
+ } else {
+ T(("... creating console buffer"));
+ WINCONSOLE.hdl =
+ CreateConsoleScreenBuffer(GENERIC_READ | GENERIC_WRITE,
+ FILE_SHARE_READ | FILE_SHARE_WRITE,
+ NULL,
+ CONSOLE_TEXTMODE_BUFFER,
+ NULL);
+ buffered = TRUE;
+ }
+ }
+
+ /* We set binary I/O even when using the console
+ driver to cover the situation, that the
+ TERM variable is set to #win32con, but actually
+ Windows supports virtual terminal processing.
+ So if terminfo functions are used in this setup,
+ they actually may work.
+ */
+ _setmode(fileno(stdin), _O_BINARY);
+ _setmode(fileno(stdout), _O_BINARY);
+
+ if (WINCONSOLE.hdl != INVALID_HANDLE_VALUE) {
+ WINCONSOLE.buffered = buffered;
+ _nc_console_get_SBI();
+ WINCONSOLE.save_SBI = WINCONSOLE.SBI;
+ if (!buffered) {
+ save_original_screen();
+ _nc_console_set_scrollback(FALSE, &WINCONSOLE.SBI);
+ }
+ GetConsoleCursorInfo(WINCONSOLE.hdl, &WINCONSOLE.save_CI);
+ T(("... initial cursor is %svisible, %d%%",
+ (WINCONSOLE.save_CI.bVisible ? "" : "not-"),
+ (int) WINCONSOLE.save_CI.dwSize));
+ }
+
+ WINCONSOLE.initialized = TRUE;
+ console_initialized = TRUE;
+ }
+ res = (WINCONSOLE.hdl != INVALID_HANDLE_VALUE);