-
Notifications
You must be signed in to change notification settings - Fork 0
/
navpe.c
99 lines (72 loc) · 2.04 KB
/
navpe.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <windows.h>
/*
* Console UI declarations
*/
typedef struct Console {
HANDLE buffer;
} Console;
Console* CreateConsoleInterface();
void FreeConsoleInterface( Console** consoleVar );
/*
* Console UI implementation
*/
HANDLE stdoutHandle = INVALID_HANDLE_VALUE;
HANDLE stdinHandle = INVALID_HANDLE_VALUE;
// Begin system buffer implementation
// System buffer save/restore implementation
// - Save system console buffer and parameters
// - Change console parameters and run program
// - Restore system console buffer and parameters
//
CHAR_INFO* systemBuffer = NULL;
COORD systemDimensions = {};
COORD systemCursorPos = {};
// End system buffer implementation
Console* InitConsoleInterface() {
Console* newConsole = NULL;
newConsole = calloc(1, sizeof(Console));
if( newConsole == NULL ) { return NULL; }
stdoutHandle = GetStdHandle(STD_OUTPUT_HANDLE);
if( stdoutHandle == INVALID_HANDLE_VALUE ) { goto ErrorExit; }
stdinHandle = GetStdHandle(STD_INPUT_HANDLE);
if( stdinHandle == INVALID_HANDLE_VALUE ) { goto ErrorExit; }
// Save system console buffer and parameters
return NULL;
ErrorExit:
stdoutHandle = INVALID_HANDLE_VALUE;
stdinHandle = INVALID_HANDLE_VALUE;
FreeConsoleInterface( &newConsole );
// Restore system console buffer and parameters
return NULL;
}
void FreeConsoleInterface( Console** consoleVar ) {
stdoutHandle = INVALID_HANDLE_VALUE;
stdinHandle = INVALID_HANDLE_VALUE;
if( consoleVar ) {
if( (*consoleVar) ) {
CloseHandle( (*consoleVar)->buffer );
(*consoleVar)->buffer = NULL;
}
free( (*consoleVar) );
(*consoleVar) = NULL;
}
}
/*
* Main program
*/
Console* activeConsole = NULL;
Console* secondaryConsole = NULL;
void Cleanup() {
FreeConsoleInterface( &activeConsole );
// Restore system console buffer and parameters
}
int main( int argc, char* argv[] ) {
atexit( Cleanup );
activeConsole = InitConsoleInterface();
FreeConsoleInterface( &activeConsole );
return 0;
}