Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
wine-cw
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wine
wine-cw
Commits
8daef164
Commit
8daef164
authored
Oct 20, 2012
by
Akihiro Sagawa
Committed by
Alexandre Julliard
Oct 22, 2012
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cmd: Properly handle multibyte characters in batch files.
parent
ed9e7455
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
38 additions
and
16 deletions
+38
-16
batch.c
programs/cmd/batch.c
+38
-16
No files found.
programs/cmd/batch.c
View file @
8daef164
...
...
@@ -234,31 +234,53 @@ WCHAR *WCMD_fgets(WCHAR *buf, DWORD noChars, HANDLE h)
{
DWORD
charsRead
;
BOOL
status
;
LARGE_INTEGER
filepos
;
DWORD
i
;
/* We can't use the native f* functions because of the filename syntax differences
between DOS and Unix. Also need to lose the LF (or CRLF) from the line. */
if
(
!
WCMD_is_console_handle
(
h
))
{
/* Save current file position */
filepos
.
QuadPart
=
0
;
SetFilePointerEx
(
h
,
filepos
,
&
filepos
,
FILE_CURRENT
);
}
LARGE_INTEGER
filepos
;
char
*
bufA
;
UINT
cp
;
const
char
*
p
;
cp
=
GetConsoleCP
();
bufA
=
HeapAlloc
(
GetProcessHeap
(),
0
,
noChars
);
if
(
!
bufA
)
return
NULL
;
/* Save current file position */
filepos
.
QuadPart
=
0
;
SetFilePointerEx
(
h
,
filepos
,
&
filepos
,
FILE_CURRENT
);
status
=
ReadFile
(
h
,
bufA
,
noChars
,
&
charsRead
,
NULL
);
if
(
!
status
||
charsRead
==
0
)
{
HeapFree
(
GetProcessHeap
(),
0
,
bufA
);
return
NULL
;
}
status
=
WCMD_ReadFile
(
h
,
buf
,
noChars
,
&
charsRead
);
if
(
!
status
||
charsRead
==
0
)
return
NULL
;
/* Find first EOL */
for
(
p
=
bufA
;
p
<
(
bufA
+
charsRead
);
p
=
CharNextExA
(
cp
,
p
,
0
))
{
if
(
*
p
==
'\n'
||
*
p
==
'\r'
)
break
;
}
/* Find first EOL */
for
(
i
=
0
;
i
<
charsRead
;
i
++
)
{
if
(
buf
[
i
]
==
'\n'
||
buf
[
i
]
==
'\r'
)
break
;
}
/* Sets file pointer to the start of the next line, if any */
filepos
.
QuadPart
+=
p
-
bufA
+
1
+
(
*
p
==
'\r'
?
1
:
0
);
SetFilePointerEx
(
h
,
filepos
,
NULL
,
FILE_BEGIN
);
if
(
!
WCMD_is_console_handle
(
h
)
&&
i
!=
charsRead
)
{
/* Sets file pointer to the start of the next line, if any */
filepos
.
QuadPart
+=
i
+
1
+
(
buf
[
i
]
==
'\r'
?
1
:
0
);
SetFilePointerEx
(
h
,
filepos
,
NULL
,
FILE_BEGIN
);
i
=
MultiByteToWideChar
(
cp
,
0
,
bufA
,
p
-
bufA
,
buf
,
noChars
);
HeapFree
(
GetProcessHeap
(),
0
,
bufA
);
}
else
{
status
=
WCMD_ReadFile
(
h
,
buf
,
noChars
,
&
charsRead
);
if
(
!
status
||
charsRead
==
0
)
return
NULL
;
/* Find first EOL */
for
(
i
=
0
;
i
<
charsRead
;
i
++
)
{
if
(
buf
[
i
]
==
'\n'
||
buf
[
i
]
==
'\r'
)
break
;
}
}
/* Truncate at EOL (or end of buffer) */
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment