-
Notifications
You must be signed in to change notification settings - Fork 0
/
v12.cpp
89 lines (72 loc) · 1.49 KB
/
v12.cpp
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
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
typedef char VCHAR;
typedef char VNAME[256];
typedef char VTEXT[];
typedef void* VFILE;
void vAppDone (int) {
ExitProcess(0);
}
void vOutText (const char* head, const char* tail) {
HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
DWORD size = tail - head;
if (size == 0)
return;
WriteFile(hOut, head, size, &size, NULL);
FlushFileBuffers(hOut);
}
void vOutText (const char* text)
{
vOutText(text, text + strlen(text));
}
void vOutLine ()
{
vOutText("\r\n");
}
void vTextCopy(char* dst, const char* src)
{
while ((*dst++ = *src++) != 0);
}
int vTextCompare(const char* dst, const char* src)
{
int i;
do {
i = *src++ - *dst++;
if (i != 0)
break;
} while (*src);
return i;
}
VCHAR *vTextFromNumberX(VTEXT text, unsigned int number)
{
int i = 7;
text[8] = '\0';
do {
text[i] = "0123456789ABCDEF"[number % 16];
number /= 16;
} while (i--);
return (text);
}
unsigned int vGetText(VTEXT text)
{
DWORD size = 0;
HANDLE hGet = GetStdHandle(STD_INPUT_HANDLE);
if (ReadFile(hGet, text, 255, &size, NULL)) {
text[size] = 0;
return (size);
}
return (0);
}
VCHAR *vTextFromNumberD(VTEXT text, int number)
{
VCHAR dst[16];
VCHAR *c = &dst[16];
unsigned int n = number < 0 ? -number : number;
*--c = 0;
do *--c = '0' + (VCHAR)(n % 10);
while (n /= 10);
if (number < 0)
*--c = '-';
vTextCopy(text, c);
return (text);
}