* 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. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45592 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
07b12e1ee2
commit
1242292de9
12
ChangeLog
12
ChangeLog
@ -1,3 +1,15 @@
|
|||||||
|
Tue Apr 15 19:36:42 2014 NAKAMURA Usaku <usa@ruby-lang.org>
|
||||||
|
|
||||||
|
* 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@fsij.org>
|
Tue Apr 15 19:26:05 2014 Tanaka Akira <akr@fsij.org>
|
||||||
|
|
||||||
* ext/extmk.rb: Re-generate extmk.mk and dummy makefiles only if
|
* ext/extmk.rb: Re-generate extmk.mk and dummy makefiles only if
|
||||||
|
@ -263,7 +263,6 @@ struct ifaddrs {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
extern DWORD rb_w32_osid(void);
|
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 rb_pid_t rb_w32_pipe_exec(const char *, const char *, int, int *, int *);
|
||||||
extern int flock(int fd, int oper);
|
extern int flock(int fd, int oper);
|
||||||
extern int rb_w32_io_cancelable_p(int);
|
extern int rb_w32_io_cancelable_p(int);
|
||||||
|
@ -741,6 +741,7 @@ socklist_delete(SOCKET *sockp, int *flagp)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int w32_cmdvector(const WCHAR *, char ***, UINT);
|
||||||
//
|
//
|
||||||
// Initialization stuff
|
// Initialization stuff
|
||||||
//
|
//
|
||||||
@ -764,7 +765,7 @@ rb_w32_sysinit(int *argc, char ***argv)
|
|||||||
//
|
//
|
||||||
// subvert cmd.exe's feeble attempt at command line parsing
|
// 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
|
// Now set up the correct time stuff
|
||||||
@ -1482,7 +1483,7 @@ insert(const char *path, VALUE vinfo, void *enc)
|
|||||||
|
|
||||||
/* License: Artistic or GPL */
|
/* License: Artistic or GPL */
|
||||||
static NtCmdLineElement **
|
static NtCmdLineElement **
|
||||||
cmdglob(NtCmdLineElement *patt, NtCmdLineElement **tail)
|
cmdglob(NtCmdLineElement *patt, NtCmdLineElement **tail, UINT cp)
|
||||||
{
|
{
|
||||||
char buffer[MAXPATHLEN], *buf = buffer;
|
char buffer[MAXPATHLEN], *buf = buffer;
|
||||||
char *p;
|
char *p;
|
||||||
@ -1494,7 +1495,7 @@ cmdglob(NtCmdLineElement *patt, NtCmdLineElement **tail)
|
|||||||
|
|
||||||
strlcpy(buf, patt->str, patt->len + 1);
|
strlcpy(buf, patt->str, patt->len + 1);
|
||||||
buf[patt->len] = '\0';
|
buf[patt->len] = '\0';
|
||||||
for (p = buf; *p; p = CharNext(p))
|
for (p = buf; *p; p = CharNextExA(cp, p, 0))
|
||||||
if (*p == '\\')
|
if (*p == '\\')
|
||||||
*p = '/';
|
*p = '/';
|
||||||
status = ruby_brace_glob(buf, 0, insert, (VALUE)&tail);
|
status = ruby_brace_glob(buf, 0, insert, (VALUE)&tail);
|
||||||
@ -1563,39 +1564,39 @@ has_redirection(const char *cmd, UINT cp)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* License: Ruby's */
|
/* License: Ruby's */
|
||||||
static inline char *
|
static inline WCHAR *
|
||||||
skipspace(char *ptr)
|
skipspace(WCHAR *ptr)
|
||||||
{
|
{
|
||||||
while (ISSPACE(*ptr))
|
while (iswspace(*ptr))
|
||||||
ptr++;
|
ptr++;
|
||||||
return ptr;
|
return ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* License: Artistic or GPL */
|
/* License: Artistic or GPL */
|
||||||
int
|
static int
|
||||||
rb_w32_cmdvector(const char *cmd, char ***vec)
|
w32_cmdvector(const WCHAR *cmd, char ***vec, UINT cp)
|
||||||
{
|
{
|
||||||
int globbing, len;
|
int globbing, len;
|
||||||
int elements, strsz, done;
|
int elements, strsz, done;
|
||||||
int slashes, escape;
|
int slashes, escape;
|
||||||
char *ptr, *base, *buffer, *cmdline;
|
WCHAR *ptr, *base, *cmdline;
|
||||||
|
char *cptr, *buffer;
|
||||||
char **vptr;
|
char **vptr;
|
||||||
char quote;
|
WCHAR quote;
|
||||||
NtCmdLineElement *curr, **tail;
|
NtCmdLineElement *curr, **tail;
|
||||||
NtCmdLineElement *cmdhead = NULL, **cmdtail = &cmdhead;
|
NtCmdLineElement *cmdhead = NULL, **cmdtail = &cmdhead;
|
||||||
|
|
||||||
//
|
//
|
||||||
// just return if we don't have a command line
|
// just return if we don't have a command line
|
||||||
//
|
//
|
||||||
|
while (iswspace(*cmd))
|
||||||
while (ISSPACE(*cmd))
|
|
||||||
cmd++;
|
cmd++;
|
||||||
if (!*cmd) {
|
if (!*cmd) {
|
||||||
*vec = NULL;
|
*vec = NULL;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
ptr = cmdline = strdup(cmd);
|
ptr = cmdline = wcsdup(cmd);
|
||||||
|
|
||||||
//
|
//
|
||||||
// Ok, parse the command line, building a list of CmdLineElements.
|
// Ok, parse the command line, building a list of CmdLineElements.
|
||||||
@ -1617,13 +1618,13 @@ rb_w32_cmdvector(const char *cmd, char ***vec)
|
|||||||
//
|
//
|
||||||
|
|
||||||
switch (*ptr) {
|
switch (*ptr) {
|
||||||
case '\\':
|
case L'\\':
|
||||||
if (quote != '\'') slashes++;
|
if (quote != L'\'') slashes++;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ' ':
|
case L' ':
|
||||||
case '\t':
|
case L'\t':
|
||||||
case '\n':
|
case L'\n':
|
||||||
//
|
//
|
||||||
// if we're not in a string, then we're finished with this
|
// if we're not in a string, then we're finished with this
|
||||||
// element
|
// element
|
||||||
@ -1635,22 +1636,22 @@ rb_w32_cmdvector(const char *cmd, char ***vec)
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case '*':
|
case L'*':
|
||||||
case '?':
|
case L'?':
|
||||||
case '[':
|
case L'[':
|
||||||
case '{':
|
case L'{':
|
||||||
//
|
//
|
||||||
// record the fact that this element has a wildcard character
|
// record the fact that this element has a wildcard character
|
||||||
// N.B. Don't glob if inside a single quoted string
|
// N.B. Don't glob if inside a single quoted string
|
||||||
//
|
//
|
||||||
|
|
||||||
if (quote != '\'')
|
if (quote != L'\'')
|
||||||
globbing++;
|
globbing++;
|
||||||
slashes = 0;
|
slashes = 0;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case '\'':
|
case L'\'':
|
||||||
case '\"':
|
case L'\"':
|
||||||
//
|
//
|
||||||
// if we're already in a string, see if this is the
|
// if we're already in a string, see if this is the
|
||||||
// terminating close-quote. If it is, we're finished with
|
// terminating close-quote. If it is, we're finished with
|
||||||
@ -1662,9 +1663,9 @@ rb_w32_cmdvector(const char *cmd, char ***vec)
|
|||||||
if (!quote)
|
if (!quote)
|
||||||
quote = *ptr;
|
quote = *ptr;
|
||||||
else if (quote == *ptr) {
|
else if (quote == *ptr) {
|
||||||
if (quote == '"' && quote == ptr[1])
|
if (quote == L'"' && quote == ptr[1])
|
||||||
ptr++;
|
ptr++;
|
||||||
quote = '\0';
|
quote = L'\0';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
escape++;
|
escape++;
|
||||||
@ -1672,7 +1673,7 @@ rb_w32_cmdvector(const char *cmd, char ***vec)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
ptr = CharNext(ptr);
|
ptr = CharNextW(ptr);
|
||||||
slashes = 0;
|
slashes = 0;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -1694,31 +1695,31 @@ rb_w32_cmdvector(const char *cmd, char ***vec)
|
|||||||
//
|
//
|
||||||
|
|
||||||
if (escape) {
|
if (escape) {
|
||||||
char *p = base, c;
|
WCHAR *p = base, c;
|
||||||
slashes = quote = 0;
|
slashes = quote = 0;
|
||||||
while (p < base + len) {
|
while (p < base + len) {
|
||||||
switch (c = *p) {
|
switch (c = *p) {
|
||||||
case '\\':
|
case L'\\':
|
||||||
p++;
|
p++;
|
||||||
if (quote != '\'') slashes++;
|
if (quote != L'\'') slashes++;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case '\'':
|
case L'\'':
|
||||||
case '"':
|
case L'"':
|
||||||
if (!(slashes & 1) && quote && quote != c) {
|
if (!(slashes & 1) && quote && quote != c) {
|
||||||
p++;
|
p++;
|
||||||
slashes = 0;
|
slashes = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
memcpy(p - ((slashes + 1) >> 1), p + (~slashes & 1),
|
memcpy(p - ((slashes + 1) >> 1), p + (~slashes & 1),
|
||||||
base + len - p);
|
sizeof(WCHAR) * (base + len - p));
|
||||||
len -= ((slashes + 1) >> 1) + (~slashes & 1);
|
len -= ((slashes + 1) >> 1) + (~slashes & 1);
|
||||||
p -= (slashes + 1) >> 1;
|
p -= (slashes + 1) >> 1;
|
||||||
if (!(slashes & 1)) {
|
if (!(slashes & 1)) {
|
||||||
if (quote) {
|
if (quote) {
|
||||||
if (quote == '"' && quote == *p)
|
if (quote == L'"' && quote == *p)
|
||||||
p++;
|
p++;
|
||||||
quote = '\0';
|
quote = L'\0';
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
quote = c;
|
quote = c;
|
||||||
@ -1729,7 +1730,7 @@ rb_w32_cmdvector(const char *cmd, char ***vec)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
p = CharNext(p);
|
p = CharNextW(p);
|
||||||
slashes = 0;
|
slashes = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -1738,10 +1739,10 @@ rb_w32_cmdvector(const char *cmd, char ***vec)
|
|||||||
|
|
||||||
curr = (NtCmdLineElement *)calloc(sizeof(NtCmdLineElement), 1);
|
curr = (NtCmdLineElement *)calloc(sizeof(NtCmdLineElement), 1);
|
||||||
if (!curr) goto do_nothing;
|
if (!curr) goto do_nothing;
|
||||||
curr->str = base;
|
curr->str = rb_w32_wstr_to_mbstr(cp, base, len, &curr->len);
|
||||||
curr->len = len;
|
curr->flags |= NTMALLOC;
|
||||||
|
|
||||||
if (globbing && (tail = cmdglob(curr, cmdtail))) {
|
if (globbing && (tail = cmdglob(curr, cmdtail, cp))) {
|
||||||
cmdtail = tail;
|
cmdtail = tail;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -1777,7 +1778,7 @@ rb_w32_cmdvector(const char *cmd, char ***vec)
|
|||||||
|
|
||||||
//
|
//
|
||||||
// make vptr point to the start of the buffer
|
// 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)
|
// buffer (*vec)
|
||||||
// |
|
// |
|
||||||
@ -1789,12 +1790,12 @@ rb_w32_cmdvector(const char *cmd, char ***vec)
|
|||||||
|
|
||||||
vptr = (char **) buffer;
|
vptr = (char **) buffer;
|
||||||
|
|
||||||
ptr = buffer + (elements+1) * sizeof(char *);
|
cptr = buffer + (elements+1) * sizeof(char *);
|
||||||
|
|
||||||
while (curr = cmdhead) {
|
while (curr = cmdhead) {
|
||||||
strlcpy(ptr, curr->str, curr->len + 1);
|
strlcpy(cptr, curr->str, curr->len + 1);
|
||||||
*vptr++ = ptr;
|
*vptr++ = cptr;
|
||||||
ptr += curr->len + 1;
|
cptr += curr->len + 1;
|
||||||
cmdhead = curr->next;
|
cmdhead = curr->next;
|
||||||
if (curr->flags & NTMALLOC) free(curr->str);
|
if (curr->flags & NTMALLOC) free(curr->str);
|
||||||
free(curr);
|
free(curr);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user