This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Patch: New version of "UTF-16 to 'Win32 locale' conversions"and filenames (replacing convertion tables with Win32 API calls)


It seems that the original post with the patch never made it to the archive. So, I'm sending the patch again to java-patches@gcc.gnu.org.
It is for GCC 3.3.1 and I cannot find much code redundancy when compared with the original sources.


João

ChangeLog
2003-09-01  Joao Garcia  <jgarcia@uk2.net>

   * natFileDescriptorWin32.cc: JvGetStringUTFRegion() repalced
   by WideCharToMultiByte() from Win32 API (suported since Win95)
   that is able to perform char-conversions from unicode to win32
   locale-dependent codes (8 bits).
   * natFileWin32.cc: JvGetStringUTFRegion() repalced by
   WideCharToMultiByte(). Added JvNewStringWindows(), based on
   MultiByteToWideChar() from Win32 API (suported since Win95) that
   is able to perform char-conversions from win32 locale-dependent
   codes (8 bits) to unicode. JvNewStringUTF() replaced by
   JvNewStringWindows().

--- libjava/java/io/natFileDescriptorWin32.cc Tue Feb 11 21:09:08 2003
+++ libjava/java/io/natFileDescriptorWin32.cc Mon Sep 1 17:17:46 2003
@@ -87,9 +87,9 @@
HANDLE handle = NULL;
DWORD access = 0;
DWORD create = OPEN_EXISTING;
- char buf[MAX_PATH] = "";
-
- jsize total = JvGetStringUTFRegion(path, 0, path->length(), buf);
+ jsize total = (jsize) WideCharToMultiByte(GetACP(), 0, (const WCHAR*) JvGetStringChars(path), path->length(), NULL, 0, NULL, NULL);
+ char *buf = (char *) __builtin_alloca ((int) total + 1);
+ WideCharToMultiByte(GetACP(), 0, (const WCHAR*) JvGetStringChars(path), path->length(), buf, (int) total, NULL, NULL);
buf[total] = '\0';


JvAssert((jflags & READ) || (jflags & WRITE));

--- libjava/java/io/natFileWin32.cc    Thu Apr 24 12:05:00 2003
+++ libjava/java/io/natFileWin32.cc    Mon Sep  1 17:14:56 2003
@@ -26,12 +26,12 @@
#include <java/io/FileFilter.h>
#include <java/lang/System.h>

-// Java timestamps are milliseconds since the UNIX epoch (00:00:00 UTC on
+// Java timestamps are milliseconds since the UNIX epoch (00:00:00 UTC on
// January 1, 1970) while Win32 file-times are 100-nanosecond intervals
// since the Win32 epoch (00:00:00 UTC on January 1, 1601). The following
// constant represents the number of milliseconds to be added to a
// Java timestamp to base it on the Win32 epoch.
-//
+//
// There were 369 years between 1601 and 1970, including 89 leap years
// (since 1700, 1800 and 1900 were not leap years):
//
@@ -39,14 +39,18 @@
//
#define WIN32_EPOCH_MILLIS 11644473600000LL

+jstring
+JvNewStringWindows (const char *bytes);
+
jboolean
java::io::File::_access (jint query)
{
jstring canon = getCanonicalPath();
if (! canon)
return false;
- char *buf = (char *) __builtin_alloca (JvGetStringUTFLength (canon) + 1);
- jsize total = JvGetStringUTFRegion (canon, 0, canon->length(), buf);
+ jsize total = (jsize) WideCharToMultiByte(GetACP(), 0, (const WCHAR*) JvGetStringChars(canon), canon->length(), NULL, 0, NULL, NULL);
+ char *buf = (char *) __builtin_alloca ((int) total + 1);
+ WideCharToMultiByte(GetACP(), 0, (const WCHAR*) JvGetStringChars(canon), canon->length(), buf, (int) total, NULL, NULL);
buf[total] = '\0';


JvAssert (query == READ || query == WRITE || query == EXISTS);
@@ -68,8 +72,9 @@
jstring canon = getCanonicalPath();
if (! canon)
return false;
- char *buf = (char *) __builtin_alloca (JvGetStringUTFLength (canon) + 1);
- jsize total = JvGetStringUTFRegion (canon, 0, canon->length(), buf);
+ jsize total = (jsize) WideCharToMultiByte(GetACP(), 0, (const WCHAR*) JvGetStringChars(canon), canon->length(), NULL, 0, NULL, NULL);
+ char *buf = (char *) __builtin_alloca ((int) total + 1);
+ WideCharToMultiByte(GetACP(), 0, (const WCHAR*) JvGetStringChars(canon), canon->length(), buf, (int) total, NULL, NULL);
buf[total] = '\0';


JvAssert (query == DIRECTORY || query == ISFILE);
@@ -90,8 +95,9 @@
jstring canon = getCanonicalPath();
if (! canon)
return false;
- char *buf = (char *) __builtin_alloca (JvGetStringUTFLength (canon) + 1);
- jsize total = JvGetStringUTFRegion (canon, 0, canon->length(), buf);
+ jsize total = (jsize) WideCharToMultiByte(GetACP(), 0, (const WCHAR*) JvGetStringChars(canon), canon->length(), NULL, 0, NULL, NULL);
+ char *buf = (char *) __builtin_alloca ((int) total + 1);
+ WideCharToMultiByte(GetACP(), 0, (const WCHAR*) JvGetStringChars(canon), canon->length(), buf, (int) total, NULL, NULL);
buf[total] = '\0';


JvAssert (query == MODIFIED || query == LENGTH);
@@ -119,8 +125,9 @@
jstring
java::io::File::getCanonicalPath (void)
{
- char *buf = (char *) __builtin_alloca (JvGetStringUTFLength (path) + 1);
- jsize total = JvGetStringUTFRegion (path, 0, path->length(), buf);
+ jsize total = (jsize) WideCharToMultiByte(GetACP(), 0, (const WCHAR*) JvGetStringChars(path), path->length(), NULL, 0, NULL, NULL);
+ char *buf = (char *) __builtin_alloca ((int) total + 1);
+ WideCharToMultiByte(GetACP(), 0, (const WCHAR*) JvGetStringChars(path), path->length(), buf, (int) total, NULL, NULL);
buf[total] = '\0';


  LPTSTR unused;
@@ -130,7 +137,7 @@

  // FIXME: what encoding to assume for file names?  This affects many
  // calls.
-  return JvNewStringUTF(buf2);
+  return JvNewStringWindows(buf2);
}

jboolean
@@ -169,8 +176,9 @@
jstring canon = getCanonicalPath();
if (! canon)
return NULL;
- char *buf = (char *) __builtin_alloca (JvGetStringUTFLength (canon) + 5);
- jsize total = JvGetStringUTFRegion (canon, 0, canon->length(), buf);
+ jsize total = (jsize) WideCharToMultiByte(GetACP(), 0, (const WCHAR*) JvGetStringChars(canon), canon->length(), NULL, 0, NULL, NULL);
+ char *buf = (char *) __builtin_alloca ((int) total + 5);
+ WideCharToMultiByte(GetACP(), 0, (const WCHAR*) JvGetStringChars(canon), canon->length(), buf, (int) total, NULL, NULL);
if (buf[total-1] == '\\')
strcpy (&buf[total], "*.*");
else
@@ -187,7 +195,7 @@
{
if (strcmp (data.cFileName, ".") && strcmp (data.cFileName, ".."))
{
- jstring name = JvNewStringUTF (data.cFileName);
+ jstring name = JvNewStringWindows (data.cFileName);


if (filter && !filter->accept(this, name))
continue;
@@ -217,8 +225,9 @@
jboolean
java::io::File::performMkdir (void)
{
- char *buf = (char *) __builtin_alloca (JvGetStringUTFLength (path) + 1);
- jsize total = JvGetStringUTFRegion(path, 0, path->length(), buf);
+ jsize total = (jsize) WideCharToMultiByte(GetACP(), 0, (const WCHAR*) JvGetStringChars(path), path->length(), NULL, 0, NULL, NULL);
+ char *buf = (char *) __builtin_alloca ((int) total + 1);
+ WideCharToMultiByte(GetACP(), 0, (const WCHAR*) JvGetStringChars(path), path->length(), buf, (int) total, NULL, NULL);
buf[total] = '\0';


return (CreateDirectory(buf, NULL)) ? true : false;
@@ -227,12 +236,13 @@
jboolean
java::io::File::performRenameTo (File *dest)
{
- char *buf = (char *) __builtin_alloca (JvGetStringUTFLength (path) + 1);
- jsize total = JvGetStringUTFRegion(path, 0, path->length(), buf);
+ jsize total = (jsize) WideCharToMultiByte(GetACP(), 0, (const WCHAR*) JvGetStringChars(path), path->length(), NULL, 0, NULL, NULL);
+ char *buf = (char *) __builtin_alloca ((int) total + 1);
+ WideCharToMultiByte(GetACP(), 0, (const WCHAR*) JvGetStringChars(path), path->length(), buf, (int) total, NULL, NULL);
buf[total] = '\0';
- char *buf2 = (char *) __builtin_alloca (JvGetStringUTFLength (dest->path)
- + 1);
- total = JvGetStringUTFRegion(dest->path, 0, dest->path->length(), buf2);
+ total = (jsize) WideCharToMultiByte(GetACP(), 0, (const WCHAR*) JvGetStringChars(dest->path), dest->path->length(), NULL, 0, NULL, NULL);
+ char *buf2 = (char *) __builtin_alloca ((int) total + 1);
+ WideCharToMultiByte(GetACP(), 0, (const WCHAR*) JvGetStringChars(dest->path), dest->path->length(), buf2, (int) total, NULL, NULL);
buf2[total] = '\0';


return (MoveFile(buf, buf2)) ? true : false;
@@ -242,8 +252,9 @@
java::io::File::performDelete ()
{
jstring canon = getCanonicalPath();
- char *buf = (char *) __builtin_alloca (JvGetStringUTFLength (canon) + 1);
- jsize total = JvGetStringUTFRegion(canon, 0, canon->length(), buf);
+ jsize total = (jsize) WideCharToMultiByte(GetACP(), 0, (const WCHAR*) JvGetStringChars(canon), canon->length(), NULL, 0, NULL, NULL);
+ char *buf = (char *) __builtin_alloca ((int) total + 1);
+ WideCharToMultiByte(GetACP(), 0, (const WCHAR*) JvGetStringChars(canon), canon->length(), buf, (int) total, NULL, NULL);
buf[total] = '\0';


  DWORD attributes = GetFileAttributes (buf);
@@ -256,14 +267,15 @@
    return (DeleteFile (buf)) ? true : false;
}

-jboolean java::io::File::performCreate (void)
+jboolean java::io::File::performCreate (void)
{
jstring canon = getCanonicalPath ();
- char *buf = (char *) __builtin_alloca (JvGetStringUTFLength (canon) + 1);
- jsize total = JvGetStringUTFRegion (canon, 0, canon->length (), buf);
+ jsize total = (jsize) WideCharToMultiByte(GetACP(), 0, (const WCHAR*) JvGetStringChars(canon), canon->length(), NULL, 0, NULL, NULL);
+ char *buf = (char *) __builtin_alloca ((int) total + 1);
+ WideCharToMultiByte(GetACP(), 0, (const WCHAR*) JvGetStringChars(canon), canon->length(), buf, (int) total, NULL, NULL);
buf[total] = '\0';


- HANDLE h = CreateFile (buf, 0, 0, NULL, CREATE_NEW,
+ HANDLE h = CreateFile (buf, 0, 0, NULL, CREATE_NEW,
FILE_ATTRIBUTE_NORMAL, NULL);
if (h != INVALID_HANDLE_VALUE)
{
@@ -282,8 +294,9 @@
jboolean java::io::File::performSetReadOnly ()
{
jstring canon = getCanonicalPath ();
- char *buf = (char *) __builtin_alloca (JvGetStringUTFLength (canon) + 1);
- jsize total = JvGetStringUTFRegion (canon, 0, canon->length (), buf);
+ jsize total = (jsize) WideCharToMultiByte(GetACP(), 0, (const WCHAR*) JvGetStringChars(canon), canon->length(), NULL, 0, NULL, NULL);
+ char *buf = (char *) __builtin_alloca ((int) total + 1);
+ WideCharToMultiByte(GetACP(), 0, (const WCHAR*) JvGetStringChars(canon), canon->length(), buf, (int) total, NULL, NULL);
buf[total] = '\0';


DWORD attrs = GetFileAttributes (buf);
@@ -301,8 +314,9 @@
jboolean java::io::File::performSetLastModified (jlong time)
{
jstring canon = getCanonicalPath ();
- char *buf = (char *) __builtin_alloca (JvGetStringUTFLength (canon) + 1);
- jsize total = JvGetStringUTFRegion (canon, 0, canon->length (), buf);
+ jsize total = (jsize) WideCharToMultiByte(GetACP(), 0, (const WCHAR*) JvGetStringChars(canon), canon->length(), NULL, 0, NULL, NULL);
+ char *buf = (char *) __builtin_alloca ((int) total + 1);
+ WideCharToMultiByte(GetACP(), 0, (const WCHAR*) JvGetStringChars(canon), canon->length(), buf, (int) total, NULL, NULL);
buf[total] = '\0';


  FILETIME modTime;
@@ -314,7 +328,7 @@

  jboolean retVal = false;
  HANDLE h = CreateFile (buf, FILE_WRITE_ATTRIBUTES,
-                         FILE_SHARE_READ | FILE_SHARE_WRITE,
+                         FILE_SHARE_READ | FILE_SHARE_WRITE,
                         NULL, OPEN_EXISTING, 0, NULL);

  if (h != INVALID_HANDLE_VALUE)
@@ -344,7 +358,7 @@
    }

  JArray<java::io::File *> *roots
-    = reinterpret_cast <JArray<java::io::File *>*>
+    = reinterpret_cast <JArray<java::io::File *>*>
        (JvNewObjectArray (numDrives, &java::io::File::class$, NULL));

  ::java::io::File **rootsArray = elements (roots);
@@ -355,7 +369,7 @@
    {
      if ((drivesBitmap & mask) != 0)
        {
-          rootsArray[j]
+          rootsArray[j]
            = new ::java::io::File (JvNewStringLatin1 (aDriveRoot));
          j++;
        }
@@ -364,4 +378,21 @@
    }

return roots;
+}
+
+jstring
+JvNewStringWindows (const char *bytes)
+{
+ //unsigned char *p = (unsigned char *) bytes;
+
+ int length = strlen (bytes);
+ if (length < 0)
+ return NULL;
+
+ jstring jstr = JvAllocString (MultiByteToWideChar(GetACP(), 0, bytes, length, NULL, 0));
+ jchar *chrs = JvGetStringChars (jstr);
+
+ MultiByteToWideChar(GetACP(), 0, bytes, length, (WCHAR*) chrs, jstr->length());
+
+ return jstr;
}



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]