123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207 |
- /*************************************************************************/
- /* godot_win.cpp */
- /*************************************************************************/
- /* This file is part of: */
- /* GODOT ENGINE */
- /* http://www.godotengine.org */
- /*************************************************************************/
- /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
- /* */
- /* Permission is hereby granted, free of charge, to any person obtaining */
- /* a copy of this software and associated documentation files (the */
- /* "Software"), to deal in the Software without restriction, including */
- /* without limitation the rights to use, copy, modify, merge, publish, */
- /* distribute, sublicense, and/or sell copies of the Software, and to */
- /* permit persons to whom the Software is furnished to do so, subject to */
- /* the following conditions: */
- /* */
- /* The above copyright notice and this permission notice shall be */
- /* included in all copies or substantial portions of the Software. */
- /* */
- /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
- /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
- /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
- /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
- /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
- /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
- /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
- /*************************************************************************/
- #include "os_windows.h"
- #include "main/main.h"
- #include <stdio.h>
- 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*)GlobalAlloc(GMEM_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 main(int argc, char** argv) {
- OS_Windows os(NULL);
- Main::setup(argv[0], argc - 1, &argv[1]);
- if (Main::start())
- os.run();
- Main::cleanup();
- return os.get_exit_code();
- };
- HINSTANCE godot_hinstance = NULL;
- int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
- int argc;
- char** argv;
- char* arg;
- int index;
- int result;
- // count the arguments
- argc = 1;
- arg = lpCmdLine;
- while (arg[0] != 0) {
- while (arg[0] != 0 && arg[0] == ' ') {
- arg++;
- }
- if (arg[0] != 0) {
- argc++;
- while (arg[0] != 0 && arg[0] != ' ') {
- arg++;
- }
- }
- }
- // tokenize the arguments
- argv = (char**)malloc(argc * sizeof(char*));
- arg = lpCmdLine;
- index = 1;
- while (arg[0] != 0) {
- while (arg[0] != 0 && arg[0] == ' ') {
- arg++;
- }
- if (arg[0] != 0) {
- argv[index] = arg;
- index++;
- while (arg[0] != 0 && arg[0] != ' ') {
- arg++;
- }
- if (arg[0] != 0) {
- arg[0] = 0;
- arg++;
- }
- }
- }
- // put the program name into argv[0]
- char filename[_MAX_PATH];
- GetModuleFileName(NULL, filename, _MAX_PATH);
- argv[0] = filename;
- // call the user specified main function
- result = main(argc, argv);
- free(argv);
- return result;
- }
|