From 6f43e1dfef3e5632976529a6f678292b15bd5a0c Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sat, 28 Mar 2015 03:32:56 +1100 Subject: Cleanup: win32 mixed declare/statements in main() Make it a more clear where declarations end (ifdef's all over made it a bit confusing). --- source/creator/creator.c | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) (limited to 'source/creator') diff --git a/source/creator/creator.c b/source/creator/creator.c index b2b650419d6..5b4f828842e 100644 --- a/source/creator/creator.c +++ b/source/creator/creator.c @@ -1559,13 +1559,13 @@ char **environ = NULL; * or exit when running in background mode. */ int main( - int argc, + int argc, #ifdef WIN32 const char **UNUSED(argv_c) #else const char **argv #endif - ) + ) { bContext *C; SYS_SystemHandle syshandle; @@ -1574,6 +1574,14 @@ int main( bArgs *ba; #endif +#ifdef WIN32 + char **argv; + int argv_num; +#endif + + /* --- end declarations --- */ + + #ifdef WIN32 /* FMA3 support in the 2013 CRT is broken on Vista and Windows 7 RTM (fixed in SP1). Just disable it. */ # if defined(_MSC_VER) && _MSC_VER >= 1800 && defined(_M_X64) @@ -1584,16 +1592,15 @@ int main( /* NOTE: cannot use guardedalloc malloc here, as it's not yet initialized * (it depends on the args passed in, which is what we're getting here!) */ - wchar_t **argv_16 = CommandLineToArgvW(GetCommandLineW(), &argc); - char **argv = malloc(argc * sizeof(char *)); - int argci = 0; - - for (argci = 0; argci < argc; argci++) { - argv[argci] = alloc_utf_8_from_16(argv_16[argci], 0); + { + wchar_t **argv_16 = CommandLineToArgvW(GetCommandLineW(), &argc); + argv = malloc(argc * sizeof(char *)); + for (argv_num = 0; argv_num < argc; argv_num++) { + argv[argv_num] = alloc_utf_8_from_16(argv_16[argv_num], 0); + } + LocalFree(argv_16); } - - LocalFree(argv_16); -#endif +#endif /* WIN32 */ /* NOTE: Special exception for guarded allocator type switch: * we need to perform switch from lock-free to fully @@ -1661,7 +1668,7 @@ int main( setCallbacks(); #if defined(__APPLE__) && !defined(WITH_PYTHON_MODULE) -/* patch to ignore argument finder gives us (pid?) */ + /* patch to ignore argument finder gives us (pid?) */ if (argc == 2 && STREQLEN(argv[1], "-psn_", 5)) { extern int GHOST_HACK_getFirstFile(char buf[]); static char firstfilebuf[512]; @@ -1819,8 +1826,8 @@ int main( #endif #ifdef WIN32 - while (argci) { - free(argv[--argci]); + while (argv_num) { + free(argv[--argv_num]); } free(argv); argv = NULL; -- cgit v1.2.3