From: Gurusamy Sarathy Date: Tue, 29 Feb 2000 18:11:34 +0000 (+0000) Subject: utf8-ize @ARGV when -C switch is used on Windows X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=729a02f2394e6a50fe8352c9471391b53e54ac40;p=p5sagit%2Fp5-mst-13.2.git utf8-ize @ARGV when -C switch is used on Windows p4raw-id: //depot/perl@5364 --- diff --git a/perl.c b/perl.c index cba035f..ef6a8bd 100644 --- a/perl.c +++ b/perl.c @@ -906,12 +906,16 @@ S_parse_body(pTHX_ char **env, XSINIT_t xsinit) s = argv[0]+1; reswitch: switch (*s) { + case 'C': +#ifdef WIN32 + win32_argv2utf8(aTHX_ argc-1, argv+1); + /* FALL THROUGH */ +#endif #ifndef PERL_STRICT_CR case '\r': #endif case ' ': case '0': - case 'C': case 'F': case 'a': case 'c': @@ -3153,7 +3157,10 @@ S_init_postdump_symbols(pTHX_ register int argc, register char **argv, register (void)gv_AVadd(PL_argvgv); av_clear(GvAVn(PL_argvgv)); for (; argc > 0; argc--,argv++) { - av_push(GvAVn(PL_argvgv),newSVpv(argv[0],0)); + SV *sv = newSVpv(argv[0],0); + av_push(GvAVn(PL_argvgv),sv); + if (PL_widesyscalls) + sv_utf8_upgrade(sv); } } if (PL_envgv = gv_fetchpv("ENV",TRUE, SVt_PVHV)) { diff --git a/win32/Makefile b/win32/Makefile index 27e597f..88e270d 100644 --- a/win32/Makefile +++ b/win32/Makefile @@ -294,7 +294,7 @@ ARCHNAME = $(ARCHNAME)-thread # VC 6.0 can load the socket dll on demand. Makes the test suite # run in about 10% less time. -DELAYLOAD = -DELAYLOAD:wsock32.dll delayimp.lib +DELAYLOAD = -DELAYLOAD:wsock32.dll -DELAYLOAD:shell32.dll delayimp.lib # VC 6.0 seems capable of compiling perl correctly with optimizations # enabled. Anything earlier fails tests. @@ -818,7 +818,7 @@ perldll.def : $(MINIPERL) $(CONFIGPM) ..\global.sym ..\pp.sym ..\makedef.pl $(PERLDLL): perldll.def $(PERLDLL_OBJ) $(PERLDLL_RES) $(LINK32) -dll -def:perldll.def -out:$@ @<< - $(LINK_FLAGS) $(LIBFILES) $(PERLDLL_OBJ) $(PERLDLL_RES) + $(LINK_FLAGS) /base:0x28000000 $(LIBFILES) $(PERLDLL_OBJ) $(PERLDLL_RES) << $(XCOPY) $(PERLIMPLIB) $(COREDIR) diff --git a/win32/makefile.mk b/win32/makefile.mk index 44b5b3a..724fb63 100644 --- a/win32/makefile.mk +++ b/win32/makefile.mk @@ -297,7 +297,7 @@ ARCHNAME !:= $(ARCHNAME)-thread # VC 6.0 can load the socket dll on demand. Makes the test suite # run in about 10% less time. -DELAYLOAD *= -DELAYLOAD:wsock32.dll delayimp.lib +DELAYLOAD *= -DELAYLOAD:wsock32.dll -DELAYLOAD:shell32.dll delayimp.lib # VC 6.0 seems capable of compiling perl correctly with optimizations # enabled. Anything earlier fails tests. @@ -1042,7 +1042,7 @@ $(PERLDLL): perldll.def $(PERLDLL_OBJ) $(PERLDLL_RES) perl.exp $(LKPOST)) .ELSE $(LINK32) -dll -def:perldll.def -out:$@ \ - @$(mktmp $(BLINK_FLAGS) $(LIBFILES) $(PERLDLL_RES) $(PERLDLL_OBJ:s,\,\\)) + @$(mktmp $(BLINK_FLAGS) $(LIBFILES) /base:0x28000000 $(PERLDLL_RES) $(PERLDLL_OBJ:s,\,\\)) .ENDIF $(XCOPY) $(PERLIMPLIB) $(COREDIR) diff --git a/win32/win32.c b/win32/win32.c index ff52692..87d4111 100644 --- a/win32/win32.c +++ b/win32/win32.c @@ -15,6 +15,7 @@ #define Win32_Winsock #endif #include +#include #include #include @@ -4004,3 +4005,31 @@ Perl_sys_intern_dup(pTHX_ struct interp_intern *src, struct interp_intern *dst) } #endif +static void +win32_free_argvw(pTHXo_ void *ptr) +{ + char** argv = (char**)ptr; + while(*argv) { + Safefree(*argv); + *argv++ = Nullch; + } +} + +void +win32_argv2utf8(pTHX_ int argc, char** argv) +{ + char* psz; + int length, wargc; + LPWSTR* lpwStr = CommandLineToArgvW(GetCommandLineW(), &wargc); + if (lpwStr && argc) { + while (argc--) { + length = WideCharToMultiByte(CP_UTF8, 0, lpwStr[--wargc], -1, NULL, 0, NULL, NULL); + Newz(0, psz, length, char); + WideCharToMultiByte(CP_UTF8, 0, lpwStr[wargc], -1, psz, length, NULL, NULL); + argv[argc] = psz; + } + call_atexit(win32_free_argvw, argv); + } + GlobalFree((HGLOBAL)lpwStr); +} + diff --git a/win32/win32.h b/win32/win32.h index 6f4c0d0..a96e205 100644 --- a/win32/win32.h +++ b/win32/win32.h @@ -321,6 +321,7 @@ extern char * win32_get_privlib(char *pl); extern char * win32_get_sitelib(char *pl); extern int IsWin95(void); extern int IsWinNT(void); +extern void win32_argv2utf8(pTHX_ int argc, char** argv); extern char * staticlinkmodules[];