-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathpentagram.cpp
166 lines (137 loc) · 3.83 KB
/
pentagram.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
/*
Copyright (C) 2002-2009 The Pentagram team
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "pent_include.h"
#include <SDL.h>
#include "GUIApp.h"
#include "MemoryManager.h"
#include "version.h"
#include "filesys/FileSystem.h"
#include "filesys/OutputLogger.h"
#ifdef _WIN32
// Disable SDLMain in Windows
#ifdef main
#undef main
#endif
#endif
int main(int argc, char* argv[])
{
const std::string &home = FileSystem::getHomePath();
OutputLogger stdoutLogger(stdout,home + "/pstdout.txt");
OutputLogger stderrLogger(stderr,home + "/pstderr.txt");
// Initialize Memory Manager here to avoid extra tools depending on it
MemoryManager mm;
GUIApp app(argc, argv);
#ifdef SAFE_CONSOLE_STREAMS
console_streambuf<char> fb;
ppout = new console_ostream<char>(&fb);
console_err_streambuf<char> err_fb;
pperr = new console_err_ostream<char>(&err_fb);
#endif
pout << "Pentagram version " << PentagramVersion::version << std::endl;
pout << "Built: " << PentagramVersion::buildtime << std::endl;
pout << "Optional features: " << PentagramVersion::features << std::endl;
pout << std::endl;
app.startup();
app.run();
return 0;
}
#ifdef _WIN32
#include <windows.h>
#include <cstdio>
PCHAR*
CommandLineToArgvA(
PCHAR CmdLine,
int* _argc
)
{
PCHAR* argv;
PCHAR _argv;
ULONG len;
ULONG argc;
CHAR a;
ULONG i, j;
BOOLEAN in_QM;
BOOLEAN in_TEXT;
BOOLEAN in_SPACE;
len = strlen(CmdLine);
i = ((len+2)/2)*sizeof(PVOID) + sizeof(PVOID);
argv = (PCHAR*)LocalAlloc(LMEM_FIXED, i + (len+2)*sizeof(CHAR));
_argv = (PCHAR)(((PUCHAR)argv)+i);
argc = 0;
argv[argc] = _argv;
in_QM = FALSE;
in_TEXT = FALSE;
in_SPACE = TRUE;
i = 0;
j = 0;
while( a = CmdLine[i] ) {
if(in_QM) {
if(a == '\"') {
in_QM = FALSE;
} else {
_argv[j] = a;
j++;
}
} else {
switch(a) {
case '\"':
in_QM = TRUE;
in_TEXT = TRUE;
if(in_SPACE) {
argv[argc] = _argv+j;
argc++;
}
in_SPACE = FALSE;
break;
case ' ':
case '\t':
case '\n':
case '\r':
if(in_TEXT) {
_argv[j] = '\0';
j++;
}
in_TEXT = FALSE;
in_SPACE = TRUE;
break;
default:
in_TEXT = TRUE;
if(in_SPACE) {
argv[argc] = _argv+j;
argc++;
}
_argv[j] = a;
j++;
in_SPACE = FALSE;
break;
}
}
i++;
}
_argv[j] = '\0';
argv[argc] = NULL;
(*_argc) = argc;
return argv;
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
int argc;
char **argv = CommandLineToArgvA(GetCommandLineA(), &argc);
int res = main(argc, argv);
// Free memory
LocalFree((HLOCAL)argv);
return res;
}
#endif