Filenames with accented characters
João Garcia
jgarcia@uk2.net
Sun Nov 16 12:40:00 GMT 2003
Hi Mohan,
>This is a known issue. João has solved this problem, but I
>can't find his original post on java-patches. Here is what
>is left of the thread:
>>http://gcc.gnu.org/ml/java-patches/2003-q3/threads.html#00622
>>>It seems to be this post:
http://gcc.gnu.org/ml/java-patches/2003-q3/msg00634.html
>My offer to make an unofficial 3.4 build if João gives me a patch
>which applies to 3.4 still stands.
>>And I am still willing to accept it.
I was not able to build neither a cross-compiler nor a native compiler
for Mingw (different errors) with the 3.4 snapshot that I had got by the
end of September (and this errors occured before I applied my patch to
the snapshot)...
Since the begining of October up until now I have run out of spare-time
to use in this project... I am sorry. I will give it another try as soon
as possible.
I would not dare to suggest an untested version of the full patch for
3.4 (char and wchar_t version). But I will do so for a simple char
version in the following lines...
This works for all win32 desktop flavours (so it is better as a
temporary solution) and can be done in three simple steps:
1-Replace all references to JV_TEMP_UTF_STRING by
JV_TEMP_UTF_STRING_WIN32 in files
libjava/java/io/natFileDescriptorWin32.cc and
libjava/java/io/natFileWin32.cc.
2-Put the following code (untested code) in libjava/include/win32.h.
////////////////////////////////////////////////
//begin (helper class, macro and function declaration)
/* Helper class which converts a jstring to a temporary char*.
Uses the supplied buffer, if non-null. Otherwise, allocates
the buffer on the heap. Use the JV_TEMP_UTF_STRING_WIN32 macro,
which follows, to automatically allocate a stack buffer if
the string is small enough. */
class _Jv_TempUTFStringWin32
{
public:
_Jv_TempUTFStringWin32(jstring jstr, char* buf=0, int offset=0);
~_Jv_TempUTFStringWin32();
// Accessors
operator const char*() const
{
return buf_;
}
const char* buf() const
{
return buf_;
}
char* buf()
{
return buf_;
}
jsize total()
{
return len;
}
private:
char* buf_;
bool heapAllocated_;
jsize len;
};
inline _Jv_TempUTFStringWin32::_Jv_TempUTFStringWin32 (jstring jstr,
char* buf, int offset)
: buf_(0), heapAllocated_(false)
{
if (!jstr) return;
len = (jsize) WideCharToMultiByte(GetACP(), 0, (const WCHAR*)
JvGetStringChars(jstr), jstr->length(), NULL, 0, NULL, NULL);
//JvGetStringUTFLength (jstr);
if (buf)
buf_ = buf;
else
{
buf_ = (char*) _Jv_Malloc (len +1 +offset);
heapAllocated_ = true;
}
WideCharToMultiByte(GetACP(), 0, (const WCHAR*)
JvGetStringChars(jstr), jstr->length(), buf_, (int) len, NULL, NULL);
if (offset==0) buf_[len] = '0円';
}
inline _Jv_TempUTFStringWin32::~_Jv_TempUTFStringWin32 ()
{
if (heapAllocated_)
_Jv_Free (buf_);
}
/* Macro which uses _Jv_TempUTFStringWin32. Allocates a stack-based
buffer if the string and its null terminator are <= 256
characters in length. Otherwise, a heap-based buffer is
used. The parameters to this macro are the variable name
which is an instance of _Jv_TempUTFStringWin32 (above) and a
jstring.
Sample Usage:
jstring jstr = getAJString();
JV_TEMP_UTF_STRING_WIN32(utfstr, jstr, offset);
printf("The string is: %s\n", utfstr.buf());
*/
#define JV_TEMP_UTF_STRING_WIN32(utfstr, jstr, offset) \
jstring utfstr##thejstr = (jstr); \
jsize utfstr##_len = utfstr##thejstr ? (jsize)
WideCharToMultiByte(GetACP(), 0, (const WCHAR*)
JvGetStringChars(utfstr##thejstr), (utfstr##thejstr)->length(), NULL, 0,
NULL, NULL) + 1 + (offset) : 0; \
char utfstr##_buf[utfstr##_len <= 256 ? utfstr##_len : 0]; \
_Jv_TempUTFStringWin32 utfstr(utfstr##thejstr, sizeof(utfstr##_buf)==0
? 0 : utfstr##_buf, (offset))
extern jstring
JvNewStringUTFWin32 (const char *bytes);
//end (helper class, macro and function declaration)
/////////////////////////////////////////////////////////////////////////////
3- Put the following code (untested code) in libjava/win32.cc
/////////////////////////////////////////////////////////////////////
//begin (convert win32-locale string to jstring)
jstring
JvNewStringUTFWin32 (const 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;
}
//end (convert win32-locale string to jstring)
///////////////////////////////////////////////////////////////////
I hope this can be of some help as a temporary solution.
João
More information about the Java
mailing list