added PCI interrupt link device
[reactos.git] / rosapps / mc / pc / cons_nt.c
1 /* Client interface for General purpose Win32 console save/restore server
2 Having the same interface as its Linux counterpart:
3 Copyright (C) 1994 Janne Kukonlehto <jtklehto@stekt.oulu.fi>
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18
19 Note:
20 show_console_contents doesn't know how to write to its window
21 the rest works fine.
22 */
23 #include <config.h>
24
25 #include <windows.h>
26 #include "trace_nt.h"
27
28 int cons_saver_pid = 1;
29
30 #include "../src/tty.h"
31 #include "../src/util.h"
32 #include "../src/win.h"
33 #include "../src/cons.saver.h"
34
35 signed char console_flag = 1;
36 static HANDLE hSaved, hNew;
37
38 void show_console_contents (int starty, unsigned char begin_line,
39 unsigned char end_line)
40 {
41 COORD c0 = { 0, 0 };
42 COORD csize;
43 SMALL_RECT rect;
44 CHAR_INFO *pchar;
45
46 csize.X = COLS;
47 csize.Y = end_line-begin_line;
48 rect.Left = 0;
49 rect.Top = begin_line;
50 rect.Right = COLS;
51 rect.Bottom = end_line;
52
53 /* -- This code reads characters and attributes */
54 pchar = malloc (sizeof(CHAR_INFO) * (end_line-begin_line) * COLS);
55 /* Copy from one console to the curses virtual screen */
56 win32APICALL(ReadConsoleOutput (hSaved, pchar, csize, c0, &rect));
57
58 /* FIXME: this should've work,
59 but refresh() is called after this write :-( */
60 win32APICALL(WriteConsoleOutput (hNew, pchar, csize, c0, &rect));
61
62 free (pchar);
63 }
64
65 void handle_console (unsigned char action)
66 {
67 static SECURITY_ATTRIBUTES sa;
68 CONSOLE_SCREEN_BUFFER_INFO csbi;
69
70 switch (action){
71 case CONSOLE_INIT:
72 /* Save Standard handle */
73 hSaved = GetStdHandle (STD_OUTPUT_HANDLE);
74
75 sa.nLength = sizeof(SECURITY_ATTRIBUTES);
76 sa.lpSecurityDescriptor = NULL;
77 /* Create a new console buffer */
78 sa.bInheritHandle = TRUE;
79 win32APICALL_HANDLE(hNew,
80 CreateConsoleScreenBuffer (GENERIC_WRITE | GENERIC_READ,
81 FILE_SHARE_READ | FILE_SHARE_WRITE, &sa,
82 CONSOLE_TEXTMODE_BUFFER, NULL));
83 win32APICALL(GetConsoleScreenBufferInfo(hSaved, &csbi));
84 csbi.dwSize.X=csbi.srWindow.Right-csbi.srWindow.Left;
85 csbi.dwSize.Y=csbi.srWindow.Bottom-csbi.srWindow.Right;
86 win32APICALL(SetConsoleScreenBufferSize(hNew, csbi.dwSize));
87
88 /* that becomes standard handle */
89 win32APICALL(SetConsoleActiveScreenBuffer(hNew));
90 win32APICALL(SetConsoleMode(hNew, ENABLE_PROCESSED_INPUT));
91 win32APICALL(SetStdHandle(STD_OUTPUT_HANDLE, hNew));
92 break;
93
94 case CONSOLE_DONE:
95 win32APICALL(CloseHandle (hNew));
96 break;
97
98 case CONSOLE_SAVE:
99 /* Current = our standard handle */
100 win32APICALL(SetConsoleActiveScreenBuffer (hNew));
101 win32APICALL(SetStdHandle (STD_OUTPUT_HANDLE, hNew));
102 break;
103
104 case CONSOLE_RESTORE:
105 /* Put saved (shell) screen buffer */
106 win32APICALL(SetConsoleActiveScreenBuffer (hSaved));
107 win32APICALL(SetStdHandle (STD_OUTPUT_HANDLE, hSaved));
108 break;
109 default:
110 win32Trace(("Invalid action code %d sent to handle_console", action));
111 }
112 }