summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorblythe%netscape.com <devnull@localhost>2002-02-05 20:45:25 +0000
committerblythe%netscape.com <devnull@localhost>2002-02-05 20:45:25 +0000
commit55a123b1a31e8eac4590099a18cfd3dd7444c48d (patch)
treea1959f57a866c929d4365dfffb183617aa4902b0
parent31f75db7c9c9744fd30f0698e9ec3931fca1fd0e (diff)
downloadnspr-hg-55a123b1a31e8eac4590099a18cfd3dd7444c48d.tar.gz
First stab at a ANSI code page multibyte string to unicode wide character converter.
-rw-r--r--pr/include/md/_win32_unicode.h51
-rw-r--r--pr/include/md/_wince.h1
-rw-r--r--pr/src/io/prlog.c17
-rw-r--r--pr/src/md/windows/Makefile.in1
-rw-r--r--pr/src/md/windows/objs.mk3
-rw-r--r--pr/src/md/windows/w32unicode.c96
-rw-r--r--pr/src/md/windows/w95io.c2
7 files changed, 157 insertions, 14 deletions
diff --git a/pr/include/md/_win32_unicode.h b/pr/include/md/_win32_unicode.h
new file mode 100644
index 00000000..71e16e7b
--- /dev/null
+++ b/pr/include/md/_win32_unicode.h
@@ -0,0 +1,51 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/*
+ * The contents of this file are subject to the Mozilla Public
+ * License Version 1.1 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS
+ * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
+ * implied. See the License for the specific language governing
+ * rights and limitations under the License.
+ *
+ * The Original Code is the Netscape Portable Runtime (NSPR).
+ *
+ * The Initial Developer of the Original Code is Netscape
+ * Communications Corporation. Portions created by Netscape are
+ * Copyright (C) 1998-2000 Netscape Communications Corporation. All
+ * Rights Reserved.
+ *
+ * Contributor(s):
+ * Garrett Arch Blythe 02/05/2002
+ *
+ * Alternatively, the contents of this file may be used under the
+ * terms of the GNU General Public License Version 2 or later (the
+ * "GPL"), in which case the provisions of the GPL are applicable
+ * instead of those above. If you wish to allow use of your
+ * version of this file only under the terms of the GPL and not to
+ * allow others to use your version of this file under the MPL,
+ * indicate your decision by deleting the provisions above and
+ * replace them with the notice and other provisions required by
+ * the GPL. If you do not delete the provisions above, a recipient
+ * may use your version of this file under either the MPL or the
+ * GPL.
+ */
+
+#ifndef nspr_win32_unicode_h___
+#define nspr_win32_unicode_h___
+
+#include <windows.h>
+
+/*
+ * _PR_MD_MALLOC_A2W
+ *
+ * Automatically PR_Malloc a wide char string and return it based on the
+ * ANSI (multi byte, ansi code page) string passed in.
+ *
+ * Caller must PR_Free the return value if non-NULL.
+ */
+LPWSTR _PR_MD_MALLOC_A2W(LPCSTR inString);
+
+#endif /* nspr_win32_unicode_h___ */
diff --git a/pr/include/md/_wince.h b/pr/include/md/_wince.h
index 22cc70c4..f62fd96b 100644
--- a/pr/include/md/_wince.h
+++ b/pr/include/md/_wince.h
@@ -41,6 +41,7 @@
#include <winnt.h>
#include <stdlib.h>
#include "_win32_time.h"
+#include "_win32_unicode.h"
#include "prio.h"
diff --git a/pr/src/io/prlog.c b/pr/src/io/prlog.c
index 5c8ac12b..b086f37b 100644
--- a/pr/src/io/prlog.c
+++ b/pr/src/io/prlog.c
@@ -115,20 +115,13 @@ static PRLock *_pr_logLock;
#if defined(WINCE)
#define CEOutputDebugString(str) \
PR_BEGIN_MACRO \
- int neededWChars = 0; \
+ LPWSTR wstr = NULL; \
\
- neededWChars = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, (str), -1, NULL, 0); \
- if(0 < neededWChars) \
+ wstr = _PR_MD_MALLOC_A2W(str); \
+ if(NULL != wstr) \
{ \
- LPTSTR wstr = NULL; \
- \
- wstr = (LPWSTR)PR_Malloc(sizeof(WCHAR) * neededWChars); \
- if(NULL != wstr) \
- { \
- MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, (str), -1, wstr, neededWChars); \
- OutputDebugString(wstr); \
- PR_Free(wstr); \
- } \
+ OutputDebugString(wstr); \
+ PR_Free(wstr); \
} \
PR_END_MACRO
#endif
diff --git a/pr/src/md/windows/Makefile.in b/pr/src/md/windows/Makefile.in
index fad5ebb1..49a38eb6 100644
--- a/pr/src/md/windows/Makefile.in
+++ b/pr/src/md/windows/Makefile.in
@@ -76,6 +76,7 @@ CSRCS = \
w32shm.c \
w95dllmain.c \
w32time.c \
+ w32unicode.c \
$(NULL)
else
ifeq ($(OS_TARGET), WIN95)
diff --git a/pr/src/md/windows/objs.mk b/pr/src/md/windows/objs.mk
index 8a89b24f..7023f308 100644
--- a/pr/src/md/windows/objs.mk
+++ b/pr/src/md/windows/objs.mk
@@ -63,7 +63,8 @@ CSRCS = ntmisc.c \
w32rng.c \
w32shm.c \
w95dllmain.c \
- w32time.c
+ w32time.c \
+ w32unicode.c
else
ifeq ($(OS_TARGET),WIN95)
CSRCS = ntmisc.c \
diff --git a/pr/src/md/windows/w32unicode.c b/pr/src/md/windows/w32unicode.c
new file mode 100644
index 00000000..66ade756
--- /dev/null
+++ b/pr/src/md/windows/w32unicode.c
@@ -0,0 +1,96 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/*
+ * The contents of this file are subject to the Mozilla Public
+ * License Version 1.1 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS
+ * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
+ * implied. See the License for the specific language governing
+ * rights and limitations under the License.
+ *
+ * The Original Code is the Netscape Portable Runtime (NSPR).
+ *
+ * The Initial Developer of the Original Code is Netscape
+ * Communications Corporation. Portions created by Netscape are
+ * Copyright (C) 1998-2000 Netscape Communications Corporation. All
+ * Rights Reserved.
+ *
+ * Contributor(s):
+ * Garrett Arch Blythe, 02/05/2002
+ *
+ * Alternatively, the contents of this file may be used under the
+ * terms of the GNU General Public License Version 2 or later (the
+ * "GPL"), in which case the provisions of the GPL are applicable
+ * instead of those above. If you wish to allow use of your
+ * version of this file only under the terms of the GPL and not to
+ * allow others to use your version of this file under the MPL,
+ * indicate your decision by deleting the provisions above and
+ * replace them with the notice and other provisions required by
+ * the GPL. If you do not delete the provisions above, a recipient
+ * may use your version of this file under either the MPL or the
+ * GPL.
+ */
+
+/*
+ * w32unicode.c
+ *
+ * This file exists mainly to provide easy ways to convert internal
+ * multibyte string representations into their wide character
+ * counterparts.
+ *
+ * FYI:
+ *
+ * WinCE only has the UNICODE Win32 API (funcW vs. funcA), and so there
+ * is no choice as to which API to utilize (the main reason this file
+ * exists).
+ * WinNT functions as a UNICODE Win32 API with automatic conversions
+ * functioning in the funcA (using funcW would be faster for NT).
+ * Win95 functions as a multibyte Win32 API with automatic conversions
+ * functioning in the funcW (using funcA would be faster for win9x).
+ */
+
+#include "primpl.h"
+
+/*
+ * _PR_MD_MALLOC_A2W
+ *
+ * Automatically PR_Malloc a wide char string and return it based on the
+ * ANSI (multi byte, ansi code page) string passed in.
+ *
+ * Caller must PR_Free the return value if non-NULL.
+ */
+LPWSTR _PR_MD_MALLOC_A2W(LPCSTR inString)
+{
+ LPWSTR retval = NULL;
+
+ if(NULL != inString)
+ {
+ int neededWChars = 0;
+
+ neededWChars = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, (inString), -1, NULL, 0); \
+ if(0 < neededWChars)
+ {
+ LPWSTR wstr = NULL;
+
+ wstr = (LPWSTR)PR_Malloc(sizeof(WCHAR) * neededWChars);
+ if(NULL != wstr)
+ {
+ int convertRes = 0;
+
+ convertRes = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, (str), -1, wstr, neededWChars);
+ if(0 == convertRes)
+ {
+ PR_Free(wstr);
+ }
+ else
+ {
+ retval = wstr;
+ }
+ }
+ }
+ }
+
+ return retval;
+}
diff --git a/pr/src/md/windows/w95io.c b/pr/src/md/windows/w95io.c
index b08786a5..2d8395c6 100644
--- a/pr/src/md/windows/w95io.c
+++ b/pr/src/md/windows/w95io.c
@@ -997,7 +997,7 @@ _PR_MD_SET_FD_INHERITABLE(PRFileDesc *fd, PRBool inheritable)
}
return PR_SUCCESS;
#else
- _PR_MD_CE_NOT_IMPLEMENTED;
+ _PR_MD_MAP_DEFAULT_ERROR(ERROR_CALL_NOT_IMPLEMENTED);
return PR_FAILURE;
#endif
}