~ chicken-core (chicken-5) 8468908f6c0bed3c2db491a1704349a67655d9fc
commit 8468908f6c0bed3c2db491a1704349a67655d9fc Author: felix <felix@call-with-current-continuation.org> AuthorDate: Wed May 14 15:49:09 2025 +0100 Commit: felix <felix@call-with-current-continuation.org> CommitDate: Wed May 14 15:49:09 2025 +0100 simplify argv handling on win32, remove duplicate code diff --git a/chicken.h b/chicken.h index 5779c03d..6ab9b8df 100644 --- a/chicken.h +++ b/chicken.h @@ -1614,11 +1614,7 @@ typedef void (C_ccall *C_proc)(C_word, C_word *) C_noret; * "/proc/<pid>/exe" or some similar trick). */ #ifdef SEARCH_EXE_PATH -# if defined(_WIN32) && !defined(__CYGWIN__) -# define C_set_main_exe(fname) C_main_exe = C_resolve_executable_pathname(C_utf8(fname)) -# else -# define C_set_main_exe(fname) C_main_exe = C_resolve_executable_pathname(fname) -# endif +# define C_set_main_exe(fname) C_main_exe = C_resolve_executable_pathname(fname) #else # define C_set_main_exe(fname) #endif @@ -1633,15 +1629,6 @@ typedef void (C_ccall *C_proc)(C_word, C_word *) C_noret; C_private_repository(); \ return CHICKEN_main(0, NULL, (void *)C_toplevel); \ } -# elif defined(_WIN32) && !defined(__CYGWIN__) -# define C_main_entry_point \ - int wmain(int argc, wchar_t *argv[]) \ - { \ - C_set_gui_mode; \ - C_set_main_exe(argv[0]); \ - C_private_repository(); \ - return CHICKEN_main(argc, argv, (void*)C_toplevel); \ - } # else # define C_main_entry_point \ int main(int argc, char *argv[]) \ diff --git a/runtime.c b/runtime.c index 6e331d6d..b5409600 100644 --- a/runtime.c +++ b/runtime.c @@ -608,39 +608,10 @@ int CHICKEN_main(int argc, char *argv[], void *toplevel) { C_word h, s, n; - if(C_gui_mode) { #ifdef _WIN32 parse_argv(C_utf8(GetCommandLineW())); argc = C_main_argc; argv = C_main_argv; -#else - /* ??? */ -#endif - } -#if defined(_WIN32) && !defined(__CYGWIN__) - else { - int i, n; - C_char *aptr, *arg; - C_main_argv = (C_char **)malloc((MAXIMAL_NUMBER_OF_COMMAND_LINE_ARGUMENTS + 1) * sizeof(C_char *)); - - if(C_main_argv == NULL) - panic(C_text("cannot allocate argument-list buffer")); - - for(i = 0; i < argc; ++i) { - arg = argv[ i ]; - n = strlen(arg); - aptr = (C_char *)malloc(n + 1); - - if(!aptr) panic(C_text("cannot allocate argument buffer")); - - C_strlcpy(aptr, arg, n + 1); - C_main_argv[ i ] = aptr; - } - - C_main_argc = argc; - C_main_argv[ argc ] = NULL; - argv = C_main_argv; - } #endif pass_serious_signals = 0; @@ -672,12 +643,15 @@ void parse_argv(C_char *cmds) if(*ptr == '\0') break; - for(bptr0 = bptr = buffer; !C_utf_isspace((int)(*ptr)) && *ptr != '\0'; *(bptr++) = *(ptr++)) + bptr0 = bptr = buffer; + n = 0; + while(!C_utf_isspace((int)(*ptr)) && *ptr != '\0') { + *(bptr++) = *(ptr++); ++n; + } *bptr = '\0'; aptr = (C_char*)malloc(n + 1); - if(!aptr) panic(C_text("cannot allocate argument buffer")); C_strlcpy(aptr, bptr0, n + 1);Trap