Skip to content

Commit

Permalink
MSDOS fixes from Jason Hood.
Browse files Browse the repository at this point in the history
  • Loading branch information
gwsw committed Jul 25, 2017
1 parent 18e0088 commit f0f0eda
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 23 deletions.
2 changes: 1 addition & 1 deletion charset.c
Original file line number Diff line number Diff line change
Expand Up @@ -814,7 +814,7 @@ is_ubin_char(ch)
* Consider it binary if it can't be converted.
*/
BOOL used_default = TRUE;
WideCharToMultiByte(CP_OEMCP, 0, (LPCWSTR) &ch, 1, NULL, 0, NULL, &used_default);
WideCharToMultiByte(GetConsoleOutputCP(), WC_NO_BEST_FIT_CHARS, (LPCWSTR) &ch, 1, NULL, 0, NULL, &used_default);
if (used_default)
ubin = 1;
}
Expand Down
2 changes: 1 addition & 1 deletion cmdbuf.c
Original file line number Diff line number Diff line change
Expand Up @@ -1218,7 +1218,7 @@ cmd_char(c)
if (IS_ASCII_OCTET(c))
cmd_mbc_buf_len = 1;
#if MSDOS_COMPILER || OS2
else if (c == '\340' && IS_ASCII_OCTET(peekcc()))
else if (c == (unsigned char) '\340' && IS_ASCII_OCTET(peekcc()))
{
/* Assume a special key. */
cmd_mbc_buf_len = 1;
Expand Down
12 changes: 6 additions & 6 deletions filename.c
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,7 @@ lglob(filename)
char *p;
int len;
int n;
char *filename;
char *pfilename;
char *qfilename;
DECL_GLOB_NAME(fnd,drive,dir,fname,ext,handle)

Expand All @@ -690,10 +690,10 @@ lglob(filename)
p = gfilename;
do {
n = (int) (strlen(drive) + strlen(dir) + strlen(fnd.GLOB_NAME) + 1);
filename = (char *) ecalloc(n, sizeof(char));
SNPRINTF3(filename, n, "%s%s%s", drive, dir, fnd.GLOB_NAME);
qfilename = shell_quote(filename);
free(filename);
pfilename = (char *) ecalloc(n, sizeof(char));
SNPRINTF3(pfilename, n, "%s%s%s", drive, dir, fnd.GLOB_NAME);
qfilename = shell_quote(pfilename);
free(pfilename);
if (qfilename != NULL)
{
n = (int) strlen(qfilename);
Expand Down Expand Up @@ -952,7 +952,7 @@ close_altfile(altfilename, filename)
return;
if (num_pct_s(lessclose) > 2)
{
error("LESSCLOSE ignored; must contain no more than 2 %s", NULL_PARG);
error("LESSCLOSE ignored; must contain no more than 2 %%s", NULL_PARG);
return;
}
len = (int) (strlen(lessclose) + strlen(filename) + strlen(altfilename) + 2);
Expand Down
10 changes: 0 additions & 10 deletions line.c
Original file line number Diff line number Diff line change
Expand Up @@ -1012,16 +1012,6 @@ do_append(ch, rep, pos)
STORE_CHAR(*s, AT_BINARY, NULL, pos);
} else
{
#if MSDOS_COMPILER==WIN32C
if (utf_mode == 2 && ch < 0x10000)
{
char mb[4];
int i;
int len = WideCharToMultiByte(CP_OEMCP, 0, (LPCWSTR) &ch, 1, mb, 4, NULL, NULL);
for (i = 0; i < len; i++)
STORE_CHAR(mb[i], a, NULL, pos);
} else
#endif
STORE_CHAR(ch, a, rep, pos);
}
return (0);
Expand Down
7 changes: 4 additions & 3 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -186,15 +186,16 @@ main(argc, argv)
struct textlist tlist;
char *filename;
char *gfilename;
char *qfilename;

gfilename = lglob(*argv++);
init_textlist(&tlist, gfilename);
filename = NULL;
while ((filename = forw_textlist(&tlist, filename)) != NULL)
{
filename = shell_unquote(filename);
(void) get_ifile(filename, ifile);
free(filename);
qfilename = shell_unquote(filename);
(void) get_ifile(qfilename, ifile);
free(qfilename);
ifile = prev_ifile(NULL_IFILE);
}
free(gfilename);
Expand Down
15 changes: 13 additions & 2 deletions screen.c
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ static void win32_deinit_term();
#define MAKEATTR(fg,bg) ((WORD)((fg)|((bg)<<4)))
#define SETCOLORS(fg,bg) { curr_attr = MAKEATTR(fg,bg); \
if (SetConsoleTextAttribute(con_out, curr_attr) == 0) \
error("SETCOLORS failed"); }
error("SETCOLORS failed", NULL_PARG); }
#endif

#if MSDOS_COMPILER
Expand Down Expand Up @@ -2501,7 +2501,18 @@ WIN32textout(text, len)
{
#if MSDOS_COMPILER==WIN32C
DWORD written;
WriteConsole(con_out, text, len, &written, NULL);
if (utf_mode == 2)
{
/*
* We've got UTF-8 text in a non-UTF-8 console. Convert it to
* wide and use WriteConsoleW.
*/
WCHAR wtext[1024];
len = MultiByteToWideChar(CP_UTF8, 0, text, len, wtext,
sizeof(wtext)/sizeof(*wtext));
WriteConsoleW(con_out, wtext, len, &written, NULL);
} else
WriteConsole(con_out, text, len, &written, NULL);
#else
char c = text[len];
text[len] = '\0';
Expand Down

0 comments on commit f0f0eda

Please sign in to comment.