add codecnv

- add ucs4(UTF32) function
- OPENFILENAMEW function
This commit is contained in:
AZO234 2020-04-03 23:26:46 +09:00
parent ff6c3a99a7
commit 8761b4ca9c
24 changed files with 859 additions and 155 deletions

View File

@ -21,8 +21,19 @@ UINT codecnv_euctoucs2(UINT16 *lpOutput, UINT cchOutput, const char *lpInput, UI
UINT codecnv_utf8toucs2(UINT16 *lpOutput, UINT cchOutput, const char *lpInput, UINT cchInput);
UINT codecnv_utf8tosjis(char *lpOutput, UINT cchOutput, const char *lpInput, UINT cchInput);
UINT codecnv_ucs2len(const UINT16 *lpString);
UINT codecnv_ucs2tosjis(char *lpOutput, UINT cchOutput, const UINT16 *lpInput, UINT cchInput);
UINT codecnv_ucs2toutf8(char *lpOutput, UINT cchOutput, const UINT16 *lpInput, UINT cchInput);
UINT codecnv_utf8toucs2(UINT16 *lpOutput, UINT cchOutput, const char *lpInput, UINT cchInput);
UINT codecnv_utf8toucs4_1(UINT32 *lpOutput, const char *lpInput, UINT cchInput);
UINT codecnv_utf8toucs4(UINT32 *lpOutput, UINT cchOutput, const char *lpInput, UINT cchInput);
UINT codecnv_ucs4toutf8(char *lpOutput, UINT cchOutput, const UINT32 *lpInput, UINT cchInput);
UINT codecnv_ucs4len(const UINT32 *lpString);
UINT codecnv_ucs4toucs2_1(UINT16 *lpOutput, UINT cchOutput, const UINT32 *lpInput);
UINT codecnv_ucs2toucs4(UINT32 *lpOutput, UINT cchOutput, const UINT16 *lpInput, UINT cchInput);
UINT codecnv_ucs4toucs2(UINT16 *lpOutput, UINT cchOutput, const UINT32 *lpInput, UINT cchInput);
#ifdef __cplusplus
}

View File

@ -3,7 +3,11 @@
* @brief Implementation of converting EUC to S-JIS
*/
#ifdef CODECNV_TEST
#include "compiler_base.h"
#else
#include "compiler.h"
#endif
#include "codecnv.h"
static UINT euctosjis(char *lpOutput, UINT cchOutput, const char *lpInput, UINT cchInput);

View File

@ -3,7 +3,11 @@
* @brief Implementation of converting EUC to UTF-16
*/
#ifdef CODECNV_TEST
#include "compiler_base.h"
#else
#include "compiler.h"
#endif
#include "codecnv.h"
static UINT euctoucs2(UINT16 *lpOutput, UINT cchOutput, const char *lpInput, UINT cchInput);

View File

@ -3,7 +3,11 @@
* @brief Implementation of converting S-JIS to EUC
*/
#ifdef CODECNV_TEST
#include "compiler_base.h"
#else
#include "compiler.h"
#endif
#include "codecnv.h"
static UINT sjistoeuc(char *lpOutput, UINT cchOutput, const char *lpInput, UINT cchInput);

View File

@ -3,7 +3,11 @@
* @brief Implementation of converting S-JIS to UCS2
*/
#ifdef CODECNV_TEST
#include "compiler_base.h"
#else
#include "compiler.h"
#endif
#include "codecnv.h"
//! undefined code

View File

@ -3,7 +3,11 @@
* @brief Implementation of converting UCS2 to S-JIS
*/
#ifdef CODECNV_TEST
#include "compiler_base.h"
#else
#include "compiler.h"
#endif
#include "codecnv.h"
//! undefined code

115
codecnv/ucs2ucs4.c Executable file
View File

@ -0,0 +1,115 @@
/**
* @file ucs2ucs4.c
* @brief Implementation of converting UTF-16 to UTF-32
*/
#ifdef CODECNV_TEST
#include "compiler_base.h"
#else
#include "compiler.h"
#endif
#include "codecnv.h"
static BOOL isucs2highsurrogate(const UINT16 c);
static BOOL isucs2lowsurrogate(const UINT16 c);
static UINT ucs2toucs4(UINT32 *lpOutput, UINT cchOutput, const UINT16 *lpInput, UINT cchInput);
/**
* Maps a UTF-16 string to a UTF-8 string
* @param[out] lpOutput Pointer to a buffer that receives the converted string
* @param[in] cchOutput Size, in characters, of the buffer indicated by lpOutput
* @param[in] lpInput Pointer to the character string to convert
* @param[in] cchInput Size, in characters, of the buffer indicated by lpInput
* @return The number of characters written to the buffer indicated by lpOutput
*/
UINT codecnv_ucs2toucs4(UINT32 *lpOutput, UINT cchOutput, const UINT16 *lpInput, UINT cchInput) {
UINT n = 0;
UINT nLength;
if(lpOutput != NULL && lpInput != NULL) {
if(cchOutput == 0) {
lpOutput = NULL;
cchOutput = (UINT)-1;
}
if(cchInput != (UINT)-1) {
// Binary mode
n = ucs2toucs4(lpOutput, cchOutput, lpInput, cchInput);
} else {
// String mode
nLength = ucs2toucs4(lpOutput, cchOutput - 1, lpInput, codecnv_ucs2len(lpInput));
lpOutput[nLength] = '\0';
n = nLength + 1;
}
}
return n;
}
static BOOL isucs2highsurrogate(const UINT16 c) {
return 0xD800 <= c && c < 0xDC00;
}
static BOOL isucs2lowsurrogate(const UINT16 c) {
return 0xDC00 <= c && c < 0xE000;
}
/**
* Maps a UTF-16 char to a UTF-32 character
* @param[out] lpOutput Pointer to a buffer that receives the converted character
* @param[in] lpInput Pointer to the character to convert
* @param[in] cchInput Size, in characters, of the buffer indicated by lpInput
* @return The number of characters read to the buffer indicated by lpInput
*/
UINT codecnv_ucs2toucs4_1(UINT32 *lpOutput, const UINT16 *lpInput, UINT cchInput) {
int n = 0;
if(isucs2highsurrogate(lpInput[0])) {
if(isucs2lowsurrogate(lpInput[1]) && cchInput >= 2) {
lpOutput[0] = 0x10000;
lpOutput[0] += ((UINT32)lpInput[0] - 0xD800) * 0x400;
lpOutput[0] += (UINT32)lpInput[1] - 0xDC00 ;
n = 2;
} else if(lpInput[1] == 0 && cchInput >= 1) {
lpOutput[0] = lpInput[0];
n = 1;
}
} else if(isucs2lowsurrogate(lpInput[0])) {
if(lpInput[1] == 0 && cchInput >= 1) {
lpOutput[0] = lpInput[0];
n = 1;
}
} else {
if(cchInput >= 1) {
lpOutput[0] = lpInput[0];
n = 1;
}
}
return n;
}
/**
* Maps a UTF-16 string to a UTF-32 string (inner)
* @param[out] lpOutput Pointer to a buffer that receives the converted string
* @param[in] cchOutput Size, in characters, of the buffer indicated by lpOutput
* @param[in] lpInput Pointer to the character string to convert
* @param[in] cchInput Size, in characters, of the buffer indicated by lpInput
* @return The number of characters written to the buffer indicated by lpOutput
*/
static UINT ucs2toucs4(UINT32 *lpOutput, UINT cchOutput, const UINT16 *lpInput, UINT cchInput)
{
UINT nRemain;
int n = 1;
nRemain = cchOutput;
while ((cchInput > 0) && (nRemain > 0) && (n > 0)) {
n = codecnv_ucs2toucs4_1(lpOutput, lpInput, nRemain);
cchInput -= n;
lpInput += n;
lpOutput++;
nRemain--;
}
return (UINT)(cchOutput - nRemain);
}

View File

@ -3,10 +3,13 @@
* @brief Implementation of converting UCS2 to UTF-8
*/
#ifdef CODECNV_TEST
#include "compiler_base.h"
#else
#include "compiler.h"
#endif
#include "codecnv.h"
static UINT ucs2len(const UINT16 *lpString);
static UINT ucs2toutf8(char *lpOutput, UINT cchOutput, const UINT16 *lpInput, UINT cchInput);
/**
@ -17,36 +20,28 @@ static UINT ucs2toutf8(char *lpOutput, UINT cchOutput, const UINT16 *lpInput, UI
* @param[in] cchInput Size, in characters, of the buffer indicated by lpInput
* @return The number of characters written to the buffer indicated by lpOutput
*/
UINT codecnv_ucs2toutf8(char *lpOutput, UINT cchOutput, const UINT16 *lpInput, UINT cchInput)
{
UINT codecnv_ucs2toutf8(char *lpOutput, UINT cchOutput, const UINT16 *lpInput, UINT cchInput) {
UINT n = 0;
UINT nLength;
if (lpInput == NULL)
{
return 0;
}
if (cchOutput == 0)
{
if(lpOutput != NULL && lpInput != NULL) {
if(cchOutput == 0) {
lpOutput = NULL;
cchOutput = (UINT)-1;
}
if (cchInput != (UINT)-1)
{
if(cchInput != (UINT)-1) {
// Binary mode
return ucs2toutf8(lpOutput, cchOutput, lpInput, cchInput);
}
else
{
n = ucs2toutf8(lpOutput, cchOutput, lpInput, cchInput);
} else {
// String mode
nLength = ucs2toutf8(lpOutput, cchOutput - 1, lpInput, ucs2len(lpInput));
if (lpOutput)
{
nLength = ucs2toutf8(lpOutput, cchOutput - 1, lpInput, codecnv_ucs2len(lpInput));
lpOutput[nLength] = '\0';
n = nLength + 1;
}
return nLength + 1;
}
return n;
}
/**
@ -54,13 +49,13 @@ UINT codecnv_ucs2toutf8(char *lpOutput, UINT cchOutput, const UINT16 *lpInput, U
* @param[in] lpString Null-terminated string
* @return the number of characters in lpString
*/
static UINT ucs2len(const UINT16 *lpString)
{
UINT codecnv_ucs2len(const UINT16 *lpString) {
const UINT16 *p = lpString;
while (*p != 0)
{
while (*p != 0) {
p++;
}
return (UINT)(p - lpString);
}
@ -72,52 +67,23 @@ static UINT ucs2len(const UINT16 *lpString)
* @param[in] cchInput Size, in characters, of the buffer indicated by lpInput
* @return The number of characters written to the buffer indicated by lpOutput
*/
static UINT ucs2toutf8(char *lpOutput, UINT cchOutput, const UINT16 *lpInput, UINT cchInput)
{
static UINT ucs2toutf8(char *lpOutput, UINT cchOutput, const UINT16 *lpInput, UINT cchInput) {
UINT n, m;
UINT nRemain;
UINT c;
UINT32 c[2];
n = m = 1;
nRemain = cchOutput;
while ((cchInput > 0) && (nRemain > 0))
{
c = *lpInput++;
cchInput--;
while ((cchInput > 0) && (nRemain > 0) && (m > 0) && (n > 0)) {
n = codecnv_ucs2toucs4(c, 1, lpInput, 2);
if(n) {
m = codecnv_ucs4toutf8(lpOutput, nRemain, c, 1);
lpInput += n;
cchInput -= n;
lpOutput += m;
nRemain -= m;
}
}
if (c < 0x80)
{
nRemain--;
if (lpOutput)
{
*lpOutput++ = (char)c;
}
}
else if (c < 0x800)
{
if (nRemain < 2)
{
break;
}
nRemain -= 2;
if (lpOutput)
{
*lpOutput++ = (char)(0xc0 + ((c >> 6) & 0x1f));
*lpOutput++ = (char)(0x80 + ((c >> 0) & 0x3f));
}
}
else
{
if (nRemain < 3)
{
break;
}
nRemain -= 3;
if (lpOutput)
{
*lpOutput++ = (char)(0xe0 + ((c >> 12) & 0x0f));
*lpOutput++ = (char)(0x80 + ((c >> 6) & 0x3f));
*lpOutput++ = (char)(0x80 + ((c >> 0) & 0x3f));
}
}
}
return (UINT)(cchOutput - nRemain);
}

111
codecnv/ucs4ucs2.c Normal file
View File

@ -0,0 +1,111 @@
/**
* @file ucs4ucs2.c
* @brief Implementation of converting UCS4 to UCS2
*/
#ifdef CODECNV_TEST
#include "compiler_base.h"
#else
#include "compiler.h"
#endif
#include "codecnv.h"
static UINT ucs4toucs2(UINT16 *lpOutput, UINT cchOutput, const UINT32 *lpInput, UINT cchInput);
/**
* Maps a UTF-32 string to a UTF-16 string
* @param[out] lpOutput Pointer to a buffer that receives the converted string
* @param[in] cchOutput Size, in characters, of the buffer indicated by lpOutput
* @param[in] lpInput Pointer to the character string to convert
* @param[in] cchInput Size, in characters, of the buffer indicated by lpInput
* @return The number of characters written to the buffer indicated by lpOutput
*/
UINT codecnv_ucs4toucs2(UINT16 *lpOutput, UINT cchOutput, const UINT32 *lpInput, UINT cchInput) {
UINT n = 0;
UINT nLength;
if(lpOutput != NULL && lpInput != NULL) {
if(cchOutput == 0) {
lpOutput = NULL;
cchOutput = (UINT)-1;
}
if(cchInput != (UINT)-1) {
// Binary mode
n = ucs4toucs2(lpOutput, cchOutput, lpInput, cchInput);
} else {
// String mode
nLength = ucs4toucs2(lpOutput, cchOutput - 1, lpInput, codecnv_ucs4len(lpInput));
lpOutput[nLength] = '\0';
n = nLength + 1;
}
}
return n;
}
/**
* Get the length of input string
* @param[in] lpString Null-terminated string
* @return the number of characters in lpString
*/
UINT codecnv_ucs4len(const UINT32 *lpString) {
const UINT32 *p = lpString;
while(*p != 0) {
p++;
}
return (UINT)(p - lpString);
}
/**
* Maps a UTF-32 char to a UTF-16 character
* @param[out] lpOutput Pointer to a buffer that receives the converted character
* @param[in] cchOutput Size, in characters, of the buffer indicated by lpOutput
* @param[in] lpInput Pointer to the character to convert
* @return The number of characters written to the buffer indicated by lpOutput
*/
UINT codecnv_ucs4toucs2_1(UINT16 *lpOutput, UINT cchOutput, const UINT32 *lpInput) {
UINT n = 0;
if (lpInput[0] > 0x10FFFF) {
return n;
}
if(lpInput[0] < 0x10000 && cchOutput > 1) {
lpOutput[0] = (UINT16)lpInput[0];
lpOutput[1] = 0;
n = 1;
} else if(cchOutput > 2) {
lpOutput[0] = (UINT16)((lpInput[0] - 0x10000) / 0x400 + 0xD800);
lpOutput[1] = (UINT16)((lpInput[0] - 0x10000) % 0x400 + 0xDC00);
n = 2;
}
return n;
}
/**
* Maps a UTF-32 string to a UTF-16 string (inner)
* @param[out] lpOutput Pointer to a buffer that receives the converted string
* @param[in] cchOutput Size, in characters, of the buffer indicated by lpOutput
* @param[in] lpInput Pointer to the character string to convert
* @param[in] cchInput Size, in characters, of the buffer indicated by lpInput
* @return The number of characters written to the buffer indicated by lpOutput
*/
static UINT ucs4toucs2(UINT16 *lpOutput, UINT cchOutput, const UINT32 *lpInput, UINT cchInput) {
UINT nRemain;
UINT n = 1;
nRemain = cchOutput;
while ((cchInput > 0) && (nRemain > 0) && (n > 0)) {
n = codecnv_ucs4toucs2_1(lpOutput, nRemain, lpInput);
lpOutput += n;
nRemain -= n;
lpInput++;
cchInput--;
}
return (UINT)(cchOutput - nRemain);
}

104
codecnv/ucs4utf8.c Normal file
View File

@ -0,0 +1,104 @@
/**
* @file ucs4utf8.c
* @brief Implementation of converting UCS4 to UTF-8
*/
#ifdef CODECNV_TEST
#include "compiler_base.h"
#else
#include "compiler.h"
#endif
#include "codecnv.h"
static UINT ucs4toutf8(char *lpOutput, UINT cchOutput, const UINT32 *lpInput, UINT cchInput);
/**
* Maps a UTF-32 string to a UTF-8 string
* @param[out] lpOutput Pointer to a buffer that receives the converted string
* @param[in] cchOutput Size, in characters, of the buffer indicated by lpOutput
* @param[in] lpInput Pointer to the character string to convert
* @param[in] cchInput Size, in characters, of the buffer indicated by lpInput
* @return The number of characters written to the buffer indicated by lpOutput
*/
UINT codecnv_ucs4toutf8(char *lpOutput, UINT cchOutput, const UINT32 *lpInput, UINT cchInput) {
UINT n = 0;
UINT nLength;
if(lpOutput != NULL && lpInput != NULL) {
if(cchOutput == 0) {
lpOutput = NULL;
cchOutput = (UINT)-1;
}
if(cchInput != (UINT)-1) {
// Binary mode
n = ucs4toutf8(lpOutput, cchOutput, lpInput, cchInput);
} else {
// String mode
nLength = ucs4toutf8(lpOutput, cchOutput - 1, lpInput, codecnv_ucs4len(lpInput));
lpOutput[nLength] = '\0';
n = nLength + 1;
}
}
return n;
}
/**
* Maps a UTF-32 string to a UTF-8 string (inner)
* @param[out] lpOutput Pointer to a buffer that receives the converted string
* @param[in] cchOutput Size, in characters, of the buffer indicated by lpOutput
* @param[in] lpInput Pointer to the character string to convert
* @param[in] cchInput Size, in characters, of the buffer indicated by lpInput
* @return The number of characters written to the buffer indicated by lpOutput
*/
static UINT ucs4toutf8(char *lpOutput, UINT cchOutput, const UINT32 *lpInput, UINT cchInput)
{
UINT nRemain;
UINT c;
nRemain = cchOutput;
while((cchInput > 0) && (nRemain > 0)) {
c = *lpInput++;
cchInput--;
if(c < 0x80) {
nRemain--;
if(lpOutput) {
*lpOutput++ = (char)c;
}
} else if(c < 0x800) {
if(nRemain < 2) {
break;
}
nRemain -= 2;
if(lpOutput) {
*lpOutput++ = (char)(0xc0 + ((c >> 6) & 0x1f));
*lpOutput++ = (char)(0x80 + ((c >> 0) & 0x3f));
}
} else if(c < 0x10000) {
if (nRemain < 3) {
break;
}
nRemain -= 3;
if(lpOutput) {
*lpOutput++ = (char)(0xe0 + ((c >> 12) & 0x0f));
*lpOutput++ = (char)(0x80 + ((c >> 6) & 0x3f));
*lpOutput++ = (char)(0x80 + ((c >> 0) & 0x3f));
}
} else {
if(nRemain < 4) {
break;
}
nRemain -= 4;
if(lpOutput) {
*lpOutput++ = (char)(0xe0 + ((c >> 18) & 0x07));
*lpOutput++ = (char)(0x80 + ((c >> 12) & 0x3f));
*lpOutput++ = (char)(0x80 + ((c >> 6) & 0x3f));
*lpOutput++ = (char)(0x80 + ((c >> 0) & 0x3f));
}
}
}
return (UINT)(cchOutput - nRemain);
}

View File

@ -3,7 +3,11 @@
* @brief Implementation of converting UTF-8 to UCS2
*/
#ifdef CODECNV_TEST
#include "compiler_base.h"
#else
#include "compiler.h"
#endif
#include "codecnv.h"
static UINT utf8toucs2(UINT16 *lpOutput, UINT cchOutput, const char *lpInput, UINT cchInput);
@ -16,36 +20,28 @@ static UINT utf8toucs2(UINT16 *lpOutput, UINT cchOutput, const char *lpInput, UI
* @param[in] cchInput Size, in characters, of the buffer indicated by lpInput
* @return The number of characters written to the buffer indicated by lpOutput
*/
UINT codecnv_utf8toucs2(UINT16 *lpOutput, UINT cchOutput, const char *lpInput, UINT cchInput)
{
UINT codecnv_utf8toucs2(UINT16 *lpOutput, UINT cchOutput, const char *lpInput, UINT cchInput) {
UINT n = 0;
UINT nLength;
if (lpInput == NULL)
{
return 0;
}
if (cchOutput == 0)
{
if(lpOutput != NULL && lpInput != NULL) {
if(cchOutput == 0) {
lpOutput = NULL;
cchOutput = (UINT)-1;
}
if (cchInput != (UINT)-1)
{
if(cchInput != (UINT)-1) {
// Binary mode
return utf8toucs2(lpOutput, cchOutput, lpInput, cchInput);
}
else
{
n = utf8toucs2(lpOutput, cchOutput, lpInput, cchInput);
} else {
// String mode
nLength = utf8toucs2(lpOutput, cchOutput - 1, lpInput, (UINT)strlen(lpInput));
if (lpOutput)
{
lpOutput[nLength] = '\0';
n = nLength + 1;
}
return nLength + 1;
}
return n;
}
/**
@ -56,42 +52,24 @@ UINT codecnv_utf8toucs2(UINT16 *lpOutput, UINT cchOutput, const char *lpInput, U
* @param[in] cchInput Size, in characters, of the buffer indicated by lpInput
* @return The number of characters written to the buffer indicated by lpOutput
*/
static UINT utf8toucs2(UINT16 *lpOutput, UINT cchOutput, const char *lpInput, UINT cchInput)
{
static UINT utf8toucs2(UINT16 *lpOutput, UINT cchOutput, const char *lpInput, UINT cchInput) {
UINT n, m;
UINT nRemain;
UINT c;
int nBits;
UINT32 c[2];
n = m = 1;
nRemain = cchOutput;
while ((cchInput > 0) && (nRemain > 0))
{
c = *lpInput++;
cchInput--;
if (c & 0x80)
{
nBits = 0;
while ((nBits < 6) && (c & (0x80 >> nBits)))
{
nBits++;
}
c &= (0x7f >> nBits);
nBits--;
while ((nBits > 0) && (cchInput > 0) && (((*lpInput) & 0xc0) == 0x80))
{
c = (c << 6) | ((*lpInput++) & 0x3f);
cchInput--;
nBits--;
while ((cchInput > 0) && (nRemain > 0) && (m > 0) && (n > 0)) {
n = codecnv_utf8toucs4_1(c, lpInput, cchInput);
if(n) {
c[1] = '\0';
m = codecnv_ucs4toucs2(lpOutput, 2, c, 1);
lpInput += n;
cchInput -= n;
lpOutput += m;
nRemain -= m;
}
}
nRemain--;
if (lpOutput)
{
*lpOutput++ = (UINT16)c;
}
}
return (UINT)(cchOutput - nRemain);
}

121
codecnv/utf8ucs4.c Executable file
View File

@ -0,0 +1,121 @@
/**
* @file utf8ucs4.c
* @brief Implementation of converting UTF-8 to UCS4
*/
#ifdef CODECNV_TEST
#include "compiler_base.h"
#else
#include "compiler.h"
#endif
#include "codecnv.h"
static UINT utf8toucs4(UINT32 *lpOutput, UINT cchOutput, const char *lpInput, UINT cchInput);
/**
* Maps a UTF-8 string to a UTF-32 string
* @param[out] lpOutput Pointer to a buffer that receives the converted string
* @param[in] cchOutput Size, in characters, of the buffer indicated by lpOutput
* @param[in] lpInput Pointer to the character string to convert
* @param[in] cchInput Size, in characters, of the buffer indicated by lpInput
* @return The number of characters written to the buffer indicated by lpOutput
*/
UINT codecnv_utf8toucs4(UINT32 *lpOutput, UINT cchOutput, const char *lpInput, UINT cchInput) {
UINT n = 0;
UINT nLength;
if(lpOutput != NULL && lpInput != NULL) {
if(cchOutput == 0) {
cchOutput = (UINT)-1;
}
if(cchInput != (UINT)-1) {
// Binary mode
n = utf8toucs4(lpOutput, cchOutput, lpInput, cchInput);
} else {
// String mode
nLength = utf8toucs4(lpOutput, cchOutput - 1, lpInput, (UINT)strlen(lpInput));
lpOutput[nLength] = '\0';
n = nLength + 1;
}
}
return n;
}
/**
* Maps a UTF-8 char to a UTF-32 character
* @param[out] lpOutput Pointer to a buffer that receives the converted character
* @param[in] lpInput Pointer to the character to convert
* @param[in] cchInput Size, in characters, of the buffer indicated by lpInput
* @return The number of characters read to the buffer indicated by lpInput
*/
UINT codecnv_utf8toucs4_1(UINT32 *lpOutput, const char *lpInput, UINT cchInput) {
UINT c;
UINT n;
c = (UINT8)lpInput[0];
if(c < 0x80) {
n = 1;
} else if(0xC2 <= c && c < 0xE0) {
n = 2;
} else if(0xE0 <= c && c < 0xF0) {
n = 3;
} else if(0xF0 <= c && c < 0xF8) {
n = 4;
} else {
n = 0;
}
if(cchInput < n) {
n = 0;
}
switch(n) {
case 1:
lpOutput[0] = (UINT8)lpInput[0];
break;
case 2:
lpOutput[0] = ((UINT8)lpInput[0] & 0x1F) << 6;
lpOutput[0] |= (UINT8)lpInput[1] & 0x3F;
break;
case 3:
lpOutput[0] = ((UINT8)lpInput[0] & 0x0F) << 12;
lpOutput[0] |= ((UINT8)lpInput[1] & 0x3F) << 6;
lpOutput[0] |= (UINT8)lpInput[2] & 0x3F;
break;
case 4:
lpOutput[0] = ((UINT8)lpInput[0] & 0x07) << 18;
lpOutput[0] |= ((UINT8)lpInput[1] & 0x3F) << 12;
lpOutput[0] |= ((UINT8)lpInput[2] & 0x3F) << 6;
lpOutput[0] |= (UINT8)lpInput[3] & 0x3F;
break;
}
return n;
}
/**
* Maps a UTF-8 string to a UTF-32 string (inner)
* @param[out] lpOutput Pointer to a buffer that receives the converted string
* @param[in] cchOutput Size, in characters, of the buffer indicated by lpOutput
* @param[in] lpInput Pointer to the character string to convert
* @param[in] cchInput Size, in characters, of the buffer indicated by lpInput
* @return The number of characters written to the buffer indicated by lpOutput
*/
static UINT utf8toucs4(UINT32 *lpOutput, UINT cchOutput, const char *lpInput, UINT cchInput)
{
UINT nRemain;
UINT n = 1;
nRemain = cchOutput;
while ((cchInput > 0) && (nRemain > 0) && (n > 0)) {
n = codecnv_utf8toucs4_1(lpOutput, lpInput, nRemain);
cchInput -= n;
lpInput += n;
lpOutput++;
nRemain--;
}
return (UINT)(cchOutput - nRemain);
}

View File

@ -440,8 +440,8 @@ typedef int32_t FILELEN;
#endif
#include "common.h"
#include "_memory.h"
#include "rect.h"
#include "lstarray.h"
#include "common/_memory.h"
#include "common/rect.h"
#include "common/lstarray.h"
#endif // _COMPILER_BASE_H_

View File

@ -289,7 +289,6 @@ exec_allstep(void)
static int remclock_mul = 1000;
int remclockb = 0;
int remclkcnt = 0x100;
int repflag = 0;
static int latecount = 0;
static int latecount2 = 0;
static int hltflag = 0;
@ -392,9 +391,6 @@ exec_allstep(void)
}
/* rep */
#if defined(SUPPORT_ASYNC_CPU)
repflag = CPU_ECX;
#endif
CPU_WORKCLOCK(5);
#if defined(DEBUG)
if (!cpu_debug_rep_cont) {

102
misc/test_codecnv.c Executable file
View File

@ -0,0 +1,102 @@
/* === codecnv test === (c) 2020 AZO */
// Windows(MSVC):
// cl test_codecnv.c -DCODECNV_TEST ../codecnv/sjisucs2.c ../codecnv/ucs2sjis.c ../codecnv/ucs2ucs4.c ../codecnv/ucs2utf8.c ../codecnv/ucs4ucs2.c ../codecnv/ucs4utf8.c ../codecnv/utf8ucs2.c ../codecnv/utf8ucs4.c -I../ -I../common -utf-8 -Wall
// Windows(MSYS/MinGW):
// gcc test_codecnv.c -DCODECNV_TEST ../codecnv/sjisucs2.c ../codecnv/ucs2sjis.c ../codecnv/ucs2ucs4.c ../codecnv/ucs2utf8.c ../codecnv/ucs4ucs2.c ../codecnv/ucs4utf8.c ../codecnv/utf8ucs2.c ../codecnv/utf8ucs4.c -I../ -I../codecnv -Wall -Wextra -o test_codecnv
// Linux:
// gcc test_codecnv.c -DCODECNV_TEST ../codecnv/sjisucs2.c ../codecnv/ucs2sjis.c ../codecnv/ucs2ucs4.c ../codecnv/ucs2utf8.c ../codecnv/ucs4ucs2.c ../codecnv/ucs4utf8.c ../codecnv/utf8ucs2.c ../codecnv/utf8ucs4.c -I../ -I../codecnv -Wall -Wextra -o test_codecnv
#include "compiler_base.h"
#include "codecnv.h"
#define COUNT_BUFFER 256
char strU8String[COUNT_BUFFER];
char strSJString[COUNT_BUFFER];
UINT16 su16String[COUNT_BUFFER];
UINT32 su32String[COUNT_BUFFER];
int main(int iArgc, char* strArgv[]) {
int i;
int iLen;
UINT uiCount;
// test000
printf("=== test000\n");
strcpy(strU8String, "0123ABCコンニチハこんにちは今日は");
iLen = strlen(strU8String);
printf("UTF-8 length: %d\n", iLen);
printf("UTF-8 string: %s\n", strU8String);
printf("UTF-8 code: ");
for(i = 0; i < iLen; i++) {
printf(" %02X", ((UINT8*)strU8String)[i]);
}
printf("\n");
// test001 : UTF-8 to UTF-32
printf("=== test001 : UTF-8 to UTF-32\n");
uiCount = codecnv_utf8toucs4(su32String, COUNT_BUFFER, strU8String, -1);
iLen = codecnv_ucs4len(su32String);
printf("UTF-32 count: %d\n", uiCount);
printf("UTF-32 length: %d\n", iLen);
printf("UTF-32 code: ");
for(i = 0; i < iLen; i++) {
printf(" %08X", su32String[i]);
}
printf("\n");
// test002 : UTF-32 to UTF-16
printf("=== test002 : UTF-32 to UTF-16\n");
uiCount = codecnv_ucs4toucs2(su16String, COUNT_BUFFER, su32String, -1);
iLen = codecnv_ucs2len(su16String);
printf("UTF-16 count: %d\n", uiCount);
printf("UTF-16 length: %d\n", iLen);
printf("UTF-16 code: ");
for(i = 0; i < iLen; i++) {
printf(" %04X", su16String[i]);
}
printf("\n");
// test003 : UTF-32 to UTF-8
printf("=== test003 : UTF-32 to UTF-8\n");
uiCount = codecnv_ucs4toutf8(strU8String, COUNT_BUFFER, su32String, -1);
iLen = strlen(strU8String);
printf("UTF-8 count: %d\n", uiCount);
printf("UTF-8 length: %d\n", iLen);
printf("UTF-8 string: %s\n", strU8String);
printf("UTF-8 code: ");
for(i = 0; i < iLen; i++) {
printf(" %02X", ((UINT8*)strU8String)[i]);
}
printf("\n");
// test004 : UTF-8 to UTF-16
printf("=== test004 : UTF-8 to UTF-16\n");
uiCount = codecnv_utf8toucs2(su16String, COUNT_BUFFER, strU8String, -1);
iLen = codecnv_ucs2len(su16String);
printf("UTF-16 count: %d\n", uiCount);
printf("UTF-16 length: %d\n", iLen);
printf("UTF-16 code: ");
for(i = 0; i < iLen; i++) {
printf(" %04X", su16String[i]);
}
printf("\n");
// test005 : UTF-16 to UTF-8
printf("=== test005 : UTF-16 to UTF-8\n");
uiCount = codecnv_ucs2toutf8(strU8String, COUNT_BUFFER, su16String, -1);
iLen = strlen(strU8String);
printf("UTF-8 count: %d\n", uiCount);
printf("UTF-8 length: %d\n", iLen);
printf("UTF-8 string: %s\n", strU8String);
printf("UTF-8 code: ");
for(i = 0; i < iLen; i++) {
printf(" %02X", ((UINT8*)strU8String)[i]);
}
printf("\n");
return 0;
}

View File

@ -56,10 +56,11 @@ ANK=Alphabet Numeric Katakana=1Byte。
*/
#include "milstr.h"
#include <stdio.h>
char strString1[1024];
char strString2[1024];
#define COUNT_BUFFER 256
char strString1[COUNT_BUFFER];
char strString2[COUNT_BUFFER];
int main(int iArgc, char* strArgv[]) {
// test000 : OEMSTRCPY, OEMPRINTFSTR

View File

@ -31,8 +31,8 @@
#define USE_SDL_JOYSTICK
#include "milstr.h"
#include "trace.h"
#include "common/milstr.h"
#include "sdl2/trace.h"
#endif // COMPILER_H

View File

@ -25,9 +25,9 @@
#define GETTICK() (cpu_features_get_time_usec() / 1000) // millisecond timer
#include "retro_inline.h"
#include "milstr.h"
#include "trace.h"
//#include "retro_inline.h"
#include "common/milstr.h"
#include "sdl2/trace.h"
#endif // COMPILER_H

View File

@ -31,7 +31,7 @@
#define USE_SDL_JOYSTICK
#include "milstr.h"
#include "trace.h"
#include "common/milstr.h"
#include "sdl2/trace.h"
#endif // COMPILER_H

View File

@ -31,8 +31,8 @@
#define USE_SDL_JOYSTICK
#include "milstr.h"
#include "trace.h"
#include "common/milstr.h"
#include "sdl2/trace.h"
#endif // COMPILER_H

View File

@ -74,8 +74,8 @@ WINBASEAPI BOOL WINAPI SetFilePointerEx(HANDLE, LARGE_INTEGER, PLARGE_INTEGER, D
#endif
#endif /* (_MSC_VER >= 1400) */
#include "milstr.h"
#include "trace.h"
#include "common/milstr.h"
#include "win9x/misc/trace.h"
#endif // COMPILER_H

115
win9x/dialog/winfiledlg.c Normal file
View File

@ -0,0 +1,115 @@
/* === NP2 file dialog for Windows === (c) 2020 AZO */
#include "winfiledlg.h"
#include "codecnv.h"
#define WINFILEDLG_GET_FLAG (OFN_FILEMUSTEXIST | OFN_HIDEREADONLY)
#define WINFILEDLG_SET1_FLAG (OFN_FILEMUSTEXIST | OFN_HIDEREADONLY | OFN_SHAREAWARE)
#define WINFILEDLG_SET2_FLAG (OFN_OVERWRITEPROMPT | OFN_HIDEREADONLY)
BOOL WinFileDialogW_MM(
HWND hwnd,
const WinFileDialogW_Mode_t mode,
char* path,
char* name,
const char* title,
const char* filter
) {
BOOL res;
wchar_t wpath[MAX_PATH];
wchar_t wname[MAX_PATH];
res = WinFileDialogW_MW(hwnd, mode, wpath, wname, title, filter);
codecnv_ucs2toutf8(path, MAX_PATH, wpath, MAX_PATH);
codecnv_ucs2toutf8(name, MAX_PATH, wname, MAX_PATH);
return res;
}
BOOL WinFileDialogW_MW(
HWND hwnd,
const WinFileDialogW_Mode_t mode,
wchar_t* path,
wchar_t* name,
const char* title,
const char* filter
) {
wchar_t wtitle[256];
wchar_t wfilter[MAX_PATH];
codecnv_utf8toucs2(wtitle, 256, title, 256);
codecnv_utf8toucs2(wfilter, MAX_PATH, filter, MAX_PATH);
return WinFileDialogW_WW(hwnd, mode, wpath, wname, title, filter);
}
BOOL WinFileDialogW_WM(
HWND hwnd,
const WinFileDialogW_Mode_t mode,
char* path,
char* name,
const wchar_t* title,
const wchar_t* filter
) {
BOOL res;
wchar_t wpath[MAX_PATH];
wchar_t wname[MAX_PATH];
res = WinFileDialogW_WW(hwnd, mode, wpath, wname, title, filter);
codecnv_ucs2toutf8(path, MAX_PATH, wpath, MAX_PATH);
codecnv_ucs2toutf8(name, MAX_PATH, wname, MAX_PATH);
return res;
}
BOOL WinFileDialogW_WW(
HWND hwnd,
const WinFileDialogW_Mode_t mode,
wchar_t* path,
wchar_t* name,
const wchar_t* title,
const wchar_t* filter
) {
BOOL res = TRUE;
OPENFILENAMEW ofnw;
path[0] = L'\0';
name[0] = L'\0';
memset(&ofnw, 0, sizeof(OPENFILENAMEW));
ofnw.lStructSize = sizeof(OPENFILENAMEW);
ofnw.hwndOwner = hwnd;
ofnw.lpstrFile = path;
ofnw.nMaxFile = MAX_PATH;
ofnw.lpstrFileTitle = name;
ofnw.nMaxFileTitle = MAX_PATH;
ofnw.lpstrFilter = filter;
ofnw.lpstrTitle = title;
switch(mode) {
case WINFILEDIALOGW_MODE_GET:
ofnw.Flags = WINFILEDLG_GET_FLAG;
if(GetOpenFileNameW(&ofnw) == FALSE)
res = FALSE;
break;
case WINFILEDIALOGW_MODE_SET1:
ofnw.Flags = WINFILEDLG_SET1_FLAG;
if(GetSaveFileNameW(&ofnw) == FALSE)
res = FALSE;
break;
case WINFILEDIALOGW_MODE_SET2:
ofnw.Flags = WINFILEDLG_SET2_FLAG;
if(GetSaveFileNameW(&ofnw) == FALSE)
res = FALSE;
break;
default:
res = FALSE;
break;
}
return res;
}

64
win9x/dialog/winfiledlg.h Normal file
View File

@ -0,0 +1,64 @@
/* === NP2 file dialog for Windows === (c) 2020 AZO */
#ifndef _WINFILEDLG_H_
#define _WINFILEDLG_H_
#include "compiler.h"
#define WinFileDialogW(h, m, p, n, t, f) WinFileDialogW_MM(h, m, p, n, t, f)
typedef enum {
WINFILEDIALOGW_MODE_GET = 0,
WINFILEDIALOGW_MODE_SET1,
WINFILEDIALOGW_MODE_SET2,
} WinFileDialogW_Mode_t;
#ifdef __cplusplus
extern "C" {
#endif
// [I] mode : Get(Exist file) or Set1(Overwrite file) or New(New or Overwrite)
// [O] path : Full path of file
// [O] name : Filename
// [I] title : Title of dialog
// [I] name : filename
BOOL WinFileDialogW_MM(
HWND hwnd,
const WinFileDialogW_Mode_t mode,
char* path,
char* name,
const char* title,
const char* filter
);
BOOL WinFileDialogW_MW(
HWND hwnd,
const WinFileDialogW_Mode_t mode,
wchar_t* path,
wchar_t* name,
const char* title,
const char* filter
);
BOOL WinFileDialogW_WM(
HWND hwnd,
const WinFileDialogW_Mode_t mode,
char* path,
char* name,
const wchar_t* title,
const wchar_t* filter
);
BOOL WinFileDialogW_WW(
HWND hwnd,
const WinFileDialogW_Mode_t mode,
wchar_t* path,
wchar_t* name,
const wchar_t* title,
const wchar_t* filter
);
#ifdef __cplusplus
}
#endif
#endif // _WINFILEDLG_H_

View File

@ -112,8 +112,8 @@ G_END_DECLS
extern char timidity_cfgfile_path[MAX_PATH];
#define TIMIDITY_CFGFILE timidity_cfgfile_path
#include "milstr.h"
#include "trace.h"
#include "toolkit.h"
#include "common/milstr.h"
#include "x11/trace.h"
#include "x11/toolkit.h"
#endif /* NP2_X11_COMPILER_H__ */