]>
git.saurik.com Git - apple/javascriptcore.git/blob - os-win32/WinMain.cpp
2 * Copyright (C) 2009 Patrick Gansterer (paroga@paroga.com)
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public License
15 * along with this library; see the file COPYING.LIB. If not, write to
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
25 #include <wtf/UnusedParam.h>
27 int main(int argc
, char** argv
);
29 static inline char* convertToUtf8(LPCWSTR widecharString
, int length
)
31 int requiredSize
= WideCharToMultiByte(CP_UTF8
, 0, widecharString
, length
, 0, 0, 0, 0);
32 char* multibyteString
= new char[requiredSize
+ 1];
34 WideCharToMultiByte(CP_UTF8
, 0, widecharString
, length
, multibyteString
, requiredSize
, 0, 0);
35 multibyteString
[requiredSize
] = '\0';
37 return multibyteString
;
40 int WINAPI
WinMain(HINSTANCE hInstance
, HINSTANCE hPrevInstance
, LPWSTR lpCmdLine
, int nCmdShow
)
42 UNUSED_PARAM(hInstance
);
43 UNUSED_PARAM(hPrevInstance
);
44 UNUSED_PARAM(nCmdShow
);
46 Vector
<char*> arguments
;
47 TCHAR buffer
[MAX_PATH
];
49 int length
= GetModuleFileNameW(0, buffer
, MAX_PATH
);
50 arguments
.append(convertToUtf8(buffer
, length
));
52 WCHAR
* commandLine
= lpCmdLine
;
53 while (commandLine
[0] != '\0') {
54 int commandLineLength
= 1;
57 while (commandLine
[0] == ' ')
60 if (commandLine
[0] == '\"') {
65 while (commandLine
[commandLineLength
] != endChar
&& commandLine
[commandLineLength
] != '\0')
68 arguments
.append(convertToUtf8(commandLine
, commandLineLength
));
70 commandLine
+= commandLineLength
;
71 if (endChar
!= ' ' && commandLine
[0] != '\0')
75 int res
= main(arguments
.size(), arguments
.data());
77 for (size_t i
= 0; i
< arguments
.size(); i
++)