Skip to content

Commit

Permalink
Discard now unused toUnicode fromUnicode fromSqueak fromSqueak2 lstrrchr
Browse files Browse the repository at this point in the history
For UNICODE compatibility,

- every String coming from image to the VM should better be interpreted UTF8, and converted to wide String via MultiByteToWideChar()
- every String going to the image from the VM should better be converted from Wide string to UTF8 via WideCharToMultiByte()

See:
https://docs.microsoft.com/en-us/windows/desktop/api/stringapiset/nf-stringapiset-multibytetowidechar
https://docs.microsoft.com/en-us/windows/desktop/api/stringapiset/nf-stringapiset-widechartomultibyte

Side note: there is also a _tcsrrchr in <tchar.h> at least since visual studio 2015
See
https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/strrchr-wcsrchr-mbsrchr-mbsrchr-l?view=vs-2017
<tchar.h> is also supported by mingw so if ever we need lstrrchr again, we'll use that.
  • Loading branch information
nicolas-cellier-aka-nice committed Dec 30, 2018
1 parent 4f6f191 commit 545ec0a
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 119 deletions.
21 changes: 0 additions & 21 deletions platforms/win32/vm/sqWin32.h
Original file line number Diff line number Diff line change
Expand Up @@ -357,27 +357,6 @@ extern BOOL f3ButtonMouse; /* Should we use a real 3 button mouse mapping? */
extern BOOL fBufferMouse; /* Should we buffer mouse input? */


/******************************************************/
/* String conversions between Unicode / Ansi / Squeak */
/******************************************************/
/* Note: fromSqueak() and fromSqueak2() are inline conversions
but operate on two different buffers. The maximum length
of strings that can be converted is MAX_PATH */
TCHAR* fromSqueak(const char *sqPtr, int sqLen); /* Inline Squeak -> C */
TCHAR* fromSqueak2(const char *sqPtr, int sqLen); /* 2nd inline conversion */
/* Note: toUnicode() and fromUnicode() are inline conversions
with for at most MAX_PATH sized strings. If the VM
is not compiled with UNICODE defined they just return
the input strings. Also, toUnicode operates on the
same buffer as fromSqueak() */
TCHAR* toUnicode(const char *ptr); /* Inline Ansi -> Unicode */
char* fromUnicode(const TCHAR *ptr); /* Inline Unicode -> Ansi */
/* Note: toUnicodeNew and fromUnicodeNew malloc() new strings.
It is up to the caller to free these! */
TCHAR* toUnicodeNew(const char *ptr); /* Inline Ansi -> Unicode */
char* fromUnicodeNew(const TCHAR *ptr); /* Inline Unicode -> Ansi */
TCHAR *lstrrchr(TCHAR *source, TCHAR c);

/******************************************************/
/* Output stuff */
/******************************************************/
Expand Down
98 changes: 0 additions & 98 deletions platforms/win32/vm/sqWin32Utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,104 +13,6 @@
#include <math.h>
#include "sq.h"

/*****************************************************************************
String conversions: Unicode / Ansi / Squeak
NOTES:
1) The length of strings in inline functions MUST NOT exceed MAX_PATH.
2) fromSqueak() and fromSqueak2() are inline conversions
but operate on two different buffers.
3) toUnicode() and fromUnicode() are inline conversions
with for at most MAX_PATH sized strings. If the VM
is not compiled with UNICODE defined they just return
the input strings. Also, toUnicode operates on the
same buffer as fromSqueak()
4) toUnicodeNew and fromUnicodeNew malloc() new strings.
It is up to the caller to free these!
*****************************************************************************/


#define MAX_BUFFER MAX_PATH
static TCHAR w_buffer1[MAX_BUFFER]; /* wide buffer 1 */
static TCHAR w_buffer2[MAX_BUFFER]; /* wide buffer 2 */
static char a_buffer1[MAX_BUFFER]; /* ansi buffer 1 */

static TCHAR *fromSqueakInto(const char *sqPtr, int sqSize, TCHAR* buffer)
{
int i;
if(sqSize >= MAX_BUFFER) sqSize = MAX_BUFFER-1;
for(i=0;i<sqSize;i++)
buffer[i] = (unsigned char) (sqPtr[i]); /* will be extended with zeros */
buffer[sqSize] = 0;
return buffer;
}

TCHAR *fromSqueak(const char *sqPtr, int sqSize)
{
return fromSqueakInto(sqPtr, sqSize, w_buffer1);
}

TCHAR *fromSqueak2(const char *sqPtr, int sqSize)
{
return fromSqueakInto(sqPtr, sqSize, w_buffer2);
}

TCHAR *toUnicode(const char *ptr)
{
#ifdef UNICODE
return fromSqueak(ptr, strlen(ptr));
#else
return (char*) ptr;
#endif
}

char *fromUnicode(const TCHAR *ptr)
{
#ifdef UNICODE
int i, size;
size = lstrlen(ptr);
if(size >= MAX_BUFFER) size = MAX_BUFFER - 1;
for(i=0;i<size;i++)
a_buffer1[i] = (unsigned char) ptr[i];
a_buffer1[size] = 0;
return a_buffer1;
#else
return (char*) ptr;
#endif
}

TCHAR *toUnicodeNew(const char *ptr)
{ TCHAR *result;
int i,size;

size = strlen(ptr)+1;
result = (TCHAR*) calloc(size,sizeof(TCHAR));
for(i=0;i<size;i++)
result[i] = (unsigned char) ptr[i];
return result;
}

char *fromUnicodeNew(const TCHAR *ptr)
{ char *result;
int i,size;

size = lstrlen(ptr)+1;
result = (char*) calloc(size,sizeof(char));
for(i=0;i<size;i++)
result[i] = (unsigned char) ptr[i];
return result;
}

TCHAR *lstrrchr(TCHAR *source, TCHAR c)
{ TCHAR *tmp;

/* point to the last char */
tmp = source + lstrlen(source)-1;
while(tmp >= source)
if(*tmp == c) return tmp;
else tmp--;
return NULL;
}


/****************************************************************************/
/* Helper to pop up a message box with a message formatted from the */
Expand Down

1 comment on commit 545ec0a

@krono
Copy link
Member

@krono krono commented on 545ec0a Jan 1, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉

Please sign in to comment.