Archive-Unzip-Burst
view release on metacpan or search on metacpan
unzip-6.0/win32/win32.c view on Meta::CPAN
ret = buf[0];
/* when the user hits return we get CR LF. We discard the LF, not the CR,
* because when we call this for the first time after a previous input
* such as the one for "replace foo? [y]es, ..." the LF may still be in
* the input stream before whatever the user types at our prompt. */
if (ret == '\n')
if (ReadFile(stin, &buf, 1, &rc, NULL) && rc == 1)
ret = buf[0];
if (odemode != ~(DWORD)0)
SetConsoleMode(stin, odemode);
# ifndef PASSWD_FROM_STDIN
CloseHandle(stin);
# endif
return ret;
}
#endif /* !WINDLL */
#if (defined(UNICODE_SUPPORT) && !defined(FUNZIP))
/* convert wide character string to multi-byte character string */
char *wide_to_local_string(wide_string, escape_all)
ZCONST zwchar *wide_string;
int escape_all;
{
int i;
wchar_t wc;
int bytes_char;
int default_used;
int wsize = 0;
int max_bytes = 9;
char buf[9];
char *buffer = NULL;
char *local_string = NULL;
for (wsize = 0; wide_string[wsize]; wsize++) ;
if (max_bytes < MB_CUR_MAX)
max_bytes = MB_CUR_MAX;
if ((buffer = (char *)malloc(wsize * max_bytes + 1)) == NULL) {
return NULL;
}
/* convert it */
buffer[0] = '\0';
for (i = 0; i < wsize; i++) {
if (sizeof(wchar_t) < 4 && wide_string[i] > 0xFFFF) {
/* wchar_t probably 2 bytes */
/* could do surrogates if state_dependent and wctomb can do */
wc = zwchar_to_wchar_t_default_char;
} else {
wc = (wchar_t)wide_string[i];
}
/* Unter some vendor's C-RTL, the Wide-to-MultiByte conversion functions
* (like wctomb() et. al.) do not use the same codepage as the other
* string arguments I/O functions (fopen, mkdir, rmdir etc.).
* Therefore, we have to fall back to the underlying Win32-API call to
* achieve a consistent behaviour for all supported compiler environments.
* Failing RTLs are for example:
* Borland (locale uses OEM-CP as default, but I/O functions expect ANSI
* names)
* Watcom (only "C" locale, wctomb() always uses OEM CP)
* (in other words: all supported environments except the Microsoft RTLs)
*/
bytes_char = WideCharToMultiByte(
CP_ACP, WC_COMPOSITECHECK,
&wc, 1,
(LPSTR)buf, sizeof(buf),
NULL, &default_used);
if (default_used)
bytes_char = -1;
if (escape_all) {
if (bytes_char == 1 && (uch)buf[0] <= 0x7f) {
/* ASCII */
strncat(buffer, buf, 1);
} else {
/* use escape for wide character */
char *escape_string = wide_to_escape_string(wide_string[i]);
strcat(buffer, escape_string);
free(escape_string);
}
} else if (bytes_char > 0) {
/* multi-byte char */
strncat(buffer, buf, bytes_char);
} else {
/* no MB for this wide */
/* use escape for wide character */
char *escape_string = wide_to_escape_string(wide_string[i]);
strcat(buffer, escape_string);
free(escape_string);
}
}
if ((local_string = (char *)realloc(buffer, strlen(buffer) + 1)) == NULL) {
free(buffer);
return NULL;
}
return local_string;
}
#if 0
wchar_t *utf8_to_wchar_string(utf8_string)
char *utf8_string; /* path to get utf-8 name for */
{
wchar_t *qw;
int ulen;
int ulenw;
if (utf8_string == NULL)
return NULL;
/* get length */
ulenw = MultiByteToWideChar(
CP_UTF8, /* UTF-8 code page */
0, /* flags for character-type options */
utf8_string, /* string to convert */
-1, /* string length (-1 = NULL terminated) */
NULL, /* buffer */
0 ); /* buffer length (0 = return length) */
if (ulenw == 0) {
/* failed */
( run in 1.053 second using v1.01-cache-2.11-cpan-302cb4679cc )