ruby-changes:33511
From: usa <ko1@a...>
Date: Tue, 15 Apr 2014 19:39:41 +0900 (JST)
Subject: [ruby-changes:33511] usa:r45592 (trunk): * include/ruby/win32.h (rb_w32_cmdvector): removed.
usa 2014-04-15 19:39:36 +0900 (Tue, 15 Apr 2014) New Revision: 45592 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=45592 Log: * include/ruby/win32.h (rb_w32_cmdvector): removed. * win32/win32.c (rb_w32_sysinit): use WCHAR version of GetCommandLine() internally. * win32/win32.c (w32_cmdvector): renamed from rb_w32_cmdvector. use WCHAR* instead of char* internally. these changes are expected to not changing the behavior yet. Modified files: trunk/ChangeLog trunk/include/ruby/win32.h trunk/win32/win32.c Index: include/ruby/win32.h =================================================================== --- include/ruby/win32.h (revision 45591) +++ include/ruby/win32.h (revision 45592) @@ -263,7 +263,6 @@ struct ifaddrs { https://github.com/ruby/ruby/blob/trunk/include/ruby/win32.h#L263 #endif extern DWORD rb_w32_osid(void); -extern int rb_w32_cmdvector(const char *, char ***); extern rb_pid_t rb_w32_pipe_exec(const char *, const char *, int, int *, int *); extern int flock(int fd, int oper); extern int rb_w32_io_cancelable_p(int); Index: ChangeLog =================================================================== --- ChangeLog (revision 45591) +++ ChangeLog (revision 45592) @@ -1,3 +1,15 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Tue Apr 15 19:36:42 2014 NAKAMURA Usaku <usa@r...> + + * include/ruby/win32.h (rb_w32_cmdvector): removed. + + * win32/win32.c (rb_w32_sysinit): use WCHAR version of GetCommandLine() + internally. + + * win32/win32.c (w32_cmdvector): renamed from rb_w32_cmdvector. use + WCHAR* instead of char* internally. + + these changes are expected to not changing the behavior yet. + Tue Apr 15 19:26:05 2014 Tanaka Akira <akr@f...> * ext/extmk.rb: Re-generate extmk.mk and dummy makefiles only if Index: win32/win32.c =================================================================== --- win32/win32.c (revision 45591) +++ win32/win32.c (revision 45592) @@ -741,6 +741,7 @@ socklist_delete(SOCKET *sockp, int *flag https://github.com/ruby/ruby/blob/trunk/win32/win32.c#L741 return ret; } +static int w32_cmdvector(const WCHAR *, char ***, UINT); // // Initialization stuff // @@ -764,7 +765,7 @@ rb_w32_sysinit(int *argc, char ***argv) https://github.com/ruby/ruby/blob/trunk/win32/win32.c#L765 // // subvert cmd.exe's feeble attempt at command line parsing // - *argc = rb_w32_cmdvector(GetCommandLine(), argv); + *argc = w32_cmdvector(GetCommandLineW(), argv, CP_ACP); // // Now set up the correct time stuff @@ -1482,7 +1483,7 @@ insert(const char *path, VALUE vinfo, vo https://github.com/ruby/ruby/blob/trunk/win32/win32.c#L1483 /* License: Artistic or GPL */ static NtCmdLineElement ** -cmdglob(NtCmdLineElement *patt, NtCmdLineElement **tail) +cmdglob(NtCmdLineElement *patt, NtCmdLineElement **tail, UINT cp) { char buffer[MAXPATHLEN], *buf = buffer; char *p; @@ -1494,7 +1495,7 @@ cmdglob(NtCmdLineElement *patt, NtCmdLin https://github.com/ruby/ruby/blob/trunk/win32/win32.c#L1495 strlcpy(buf, patt->str, patt->len + 1); buf[patt->len] = '\0'; - for (p = buf; *p; p = CharNext(p)) + for (p = buf; *p; p = CharNextExA(cp, p, 0)) if (*p == '\\') *p = '/'; status = ruby_brace_glob(buf, 0, insert, (VALUE)&tail); @@ -1563,39 +1564,39 @@ has_redirection(const char *cmd, UINT cp https://github.com/ruby/ruby/blob/trunk/win32/win32.c#L1564 } /* License: Ruby's */ -static inline char * -skipspace(char *ptr) +static inline WCHAR * +skipspace(WCHAR *ptr) { - while (ISSPACE(*ptr)) + while (iswspace(*ptr)) ptr++; return ptr; } /* License: Artistic or GPL */ -int -rb_w32_cmdvector(const char *cmd, char ***vec) +static int +w32_cmdvector(const WCHAR *cmd, char ***vec, UINT cp) { int globbing, len; int elements, strsz, done; int slashes, escape; - char *ptr, *base, *buffer, *cmdline; + WCHAR *ptr, *base, *cmdline; + char *cptr, *buffer; char **vptr; - char quote; + WCHAR quote; NtCmdLineElement *curr, **tail; NtCmdLineElement *cmdhead = NULL, **cmdtail = &cmdhead; // // just return if we don't have a command line // - - while (ISSPACE(*cmd)) + while (iswspace(*cmd)) cmd++; if (!*cmd) { *vec = NULL; return 0; } - ptr = cmdline = strdup(cmd); + ptr = cmdline = wcsdup(cmd); // // Ok, parse the command line, building a list of CmdLineElements. @@ -1617,13 +1618,13 @@ rb_w32_cmdvector(const char *cmd, char * https://github.com/ruby/ruby/blob/trunk/win32/win32.c#L1618 // switch (*ptr) { - case '\\': - if (quote != '\'') slashes++; + case L'\\': + if (quote != L'\'') slashes++; break; - case ' ': - case '\t': - case '\n': + case L' ': + case L'\t': + case L'\n': // // if we're not in a string, then we're finished with this // element @@ -1635,22 +1636,22 @@ rb_w32_cmdvector(const char *cmd, char * https://github.com/ruby/ruby/blob/trunk/win32/win32.c#L1636 } break; - case '*': - case '?': - case '[': - case '{': + case L'*': + case L'?': + case L'[': + case L'{': // // record the fact that this element has a wildcard character // N.B. Don't glob if inside a single quoted string // - if (quote != '\'') + if (quote != L'\'') globbing++; slashes = 0; break; - case '\'': - case '\"': + case L'\'': + case L'\"': // // if we're already in a string, see if this is the // terminating close-quote. If it is, we're finished with @@ -1662,9 +1663,9 @@ rb_w32_cmdvector(const char *cmd, char * https://github.com/ruby/ruby/blob/trunk/win32/win32.c#L1663 if (!quote) quote = *ptr; else if (quote == *ptr) { - if (quote == '"' && quote == ptr[1]) + if (quote == L'"' && quote == ptr[1]) ptr++; - quote = '\0'; + quote = L'\0'; } } escape++; @@ -1672,7 +1673,7 @@ rb_w32_cmdvector(const char *cmd, char * https://github.com/ruby/ruby/blob/trunk/win32/win32.c#L1673 break; default: - ptr = CharNext(ptr); + ptr = CharNextW(ptr); slashes = 0; continue; } @@ -1694,31 +1695,31 @@ rb_w32_cmdvector(const char *cmd, char * https://github.com/ruby/ruby/blob/trunk/win32/win32.c#L1695 // if (escape) { - char *p = base, c; + WCHAR *p = base, c; slashes = quote = 0; while (p < base + len) { switch (c = *p) { - case '\\': + case L'\\': p++; - if (quote != '\'') slashes++; + if (quote != L'\'') slashes++; break; - case '\'': - case '"': + case L'\'': + case L'"': if (!(slashes & 1) && quote && quote != c) { p++; slashes = 0; break; } memcpy(p - ((slashes + 1) >> 1), p + (~slashes & 1), - base + len - p); + sizeof(WCHAR) * (base + len - p)); len -= ((slashes + 1) >> 1) + (~slashes & 1); p -= (slashes + 1) >> 1; if (!(slashes & 1)) { if (quote) { - if (quote == '"' && quote == *p) + if (quote == L'"' && quote == *p) p++; - quote = '\0'; + quote = L'\0'; } else quote = c; @@ -1729,7 +1730,7 @@ rb_w32_cmdvector(const char *cmd, char * https://github.com/ruby/ruby/blob/trunk/win32/win32.c#L1730 break; default: - p = CharNext(p); + p = CharNextW(p); slashes = 0; break; } @@ -1738,10 +1739,10 @@ rb_w32_cmdvector(const char *cmd, char * https://github.com/ruby/ruby/blob/trunk/win32/win32.c#L1739 curr = (NtCmdLineElement *)calloc(sizeof(NtCmdLineElement), 1); if (!curr) goto do_nothing; - curr->str = base; - curr->len = len; + curr->str = rb_w32_wstr_to_mbstr(cp, base, len, &curr->len); + curr->flags |= NTMALLOC; - if (globbing && (tail = cmdglob(curr, cmdtail))) { + if (globbing && (tail = cmdglob(curr, cmdtail, cp))) { cmdtail = tail; } else { @@ -1777,7 +1778,7 @@ rb_w32_cmdvector(const char *cmd, char * https://github.com/ruby/ruby/blob/trunk/win32/win32.c#L1778 // // make vptr point to the start of the buffer - // and ptr point to the area we'll consider the string table. + // and cptr point to the area we'll consider the string table. // // buffer (*vec) // | @@ -1789,12 +1790,12 @@ rb_w32_cmdvector(const char *cmd, char * https://github.com/ruby/ruby/blob/trunk/win32/win32.c#L1790 vptr = (char **) buffer; - ptr = buffer + (elements+1) * sizeof(char *); + cptr = buffer + (elements+1) * sizeof(char *); while (curr = cmdhead) { - strlcpy(ptr, curr->str, curr->len + 1); - *vptr++ = ptr; - ptr += curr->len + 1; + strlcpy(cptr, curr->str, curr->len + 1); + *vptr++ = cptr; + cptr += curr->len + 1; cmdhead = curr->next; if (curr->flags & NTMALLOC) free(curr->str); free(curr); -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/