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]

Patch: PR 1147 / command-line arguments


This patch fixes PR 1174.  It changes command-line argument processing
to assume that the arguments are encoded in the default encoding.
What do people think of this?

What if an application author writes `-Dfile.encoding=something'?
Do we want that to override the default (as it does now for file
encodings)?  Or do we want to assume that the user's locale rules?
Is this even the right thing to do?  (I've been assuming it is, but
I couldn't quote a standard or anything like that.)

Tom

Index: ChangeLog
from  Tom Tromey  <tromey@redhat.com>

	For PR libgcj/1147:
	* prims.cc (JvConvertArgv): Convert using current locale's
	encoding.

Index: prims.cc
===================================================================
RCS file: /cvs/gcc/gcc/libjava/prims.cc,v
retrieving revision 1.62
diff -u -r1.62 prims.cc
--- prims.cc 2001/10/23 05:42:02 1.62
+++ prims.cc 2001/11/29 18:52:26
@@ -657,12 +657,20 @@
   if (argc < 0)
     argc = 0;
   jobjectArray ar = JvNewObjectArray(argc, &StringClass, NULL);
-  jobject* ptr = elements(ar);
+  jobject *ptr = elements(ar);
+  jbyteArray bytes = NULL;
   for (int i = 0;  i < argc;  i++)
     {
       const char *arg = argv[i];
-      // FIXME - should probably use JvNewStringUTF.
-      *ptr++ = JvNewStringLatin1(arg, strlen(arg));
+      int len = strlen (arg);
+      if (bytes == NULL || bytes->length < len)
+	bytes = JvNewByteArray (len);
+      jbyte *bytePtr = elements (bytes);
+      // We assume jbyte == char.
+      memcpy (bytePtr, arg, len);
+
+      // Now convert using the default encoding.
+      *ptr++ = new java::lang::String (bytes, 0, len);
     }
   return (JArray<jstring>*) ar;
 }
@@ -993,7 +1001,7 @@
       runtime = java::lang::Runtime::getRuntime ();
 
       arg_vec = JvConvertArgv (argc - 1, argv + 1);
-      
+
       if (klass)
 	main_thread = new gnu::gcj::runtime::FirstThread (klass, arg_vec);
       else


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