* src/vm/properties.c (properties_init) [ENABLE_JAVAME_CLDC1_1]: Set
[cacao.git] / src / vm / properties.c
index dfe0e8e4724d191278548b3b5a43c9d3aa215486..cc443b6c9129ca07623ae5d52a12601fa606d160 100644 (file)
@@ -26,7 +26,7 @@
 
    Authors: Christian Thalinger
 
-   $Id: properties.c 5988 2006-11-15 17:58:25Z twisti $
+   $Id: properties.c 6249 2006-12-27 23:00:59Z twisti $
 
 */
 
 
 #include "vm/global.h"
 #include "native/include/java_lang_String.h"
-#include "native/include/java_util_Properties.h"
+
+#if defined(ENABLE_JAVASE)
+# include "native/include/java_util_Properties.h"
+#endif
+
 #include "toolbox/list.h"
 #include "toolbox/util.h"
 #include "vm/method.h"
@@ -90,7 +94,7 @@ bool properties_init(void)
        char           *extdirs;
        char           *lang;
        char           *country;
-       struct utsname  utsnamebuf;
+       struct utsname *utsnamebuf;
        s4              len;
 #endif
 
@@ -107,7 +111,9 @@ bool properties_init(void)
        env_home      = getenv("HOME");
        env_lang      = getenv("LANG");
 
-       uname(&utsnamebuf);
+       utsnamebuf = NEW(struct utsname);
+
+       uname(utsnamebuf);
 
        /* set JAVA_HOME to default prefix if not defined */
 
@@ -131,15 +137,13 @@ bool properties_init(void)
 
        properties_add("java.home", java_home);
 
-       MFREE(java_home, char, len);
-
        properties_add("java.vm.specification.version", "1.0");
        properties_add("java.vm.specification.vendor", "Sun Microsystems Inc.");
        properties_add("java.vm.specification.name", "Java Virtual Machine Specification");
        properties_add("java.vm.version", VERSION);
        properties_add("java.vm.vendor", "CACAO Team");
        properties_add("java.vm.name", "CACAO");
-       properties_add("java.specification.version", "1.4");
+       properties_add("java.specification.version", "1.5");
        properties_add("java.specification.vendor", "Sun Microsystems Inc.");
        properties_add("java.specification.name", "Java Platform API Specification");
        properties_add("java.class.version", CLASS_VERSION);
@@ -195,8 +199,6 @@ bool properties_init(void)
 
        properties_add("java.ext.dirs", extdirs);
 
-       MFREE(extdirs, char, len);
-
        properties_add("java.endorsed.dirs", ""CACAO_PREFIX"/jre/lib/endorsed");
 
 #if defined(DISABLE_GC)
@@ -223,11 +225,11 @@ bool properties_init(void)
 # else
        /* default to what uname returns */
 
-       properties_add("os.arch", utsnamebuf.machine);
+       properties_add("os.arch", utsnamebuf->machine);
 # endif
 
-       properties_add("os.name", utsnamebuf.sysname);
-       properties_add("os.version", utsnamebuf.release);
+       properties_add("os.name", utsnamebuf->sysname);
+       properties_add("os.version", utsnamebuf->release);
 #endif
 
        properties_add("file.separator", "/");
@@ -279,14 +281,10 @@ bool properties_init(void)
                properties_add("user.language", "en");
                properties_add("user.country", "US");
        }
-       
-       /* clean up */
-
-       MFREE(cwd, char, 0);
 #elif defined(ENABLE_JAVAME_CLDC1_1)
     properties_add("microedition.configuration", "CLDC-1.1");
-    properties_add("microedition.platform", "PowerPC");
-    properties_add("microedition.encoding", "ISO-8859-1");
+    properties_add("microedition.platform", "generic");
+    properties_add("microedition.encoding", "ISO8859_1");
     properties_add("microedition.profiles", "");
 #else
 #error unknown Java configuration
@@ -321,20 +319,36 @@ bool properties_postinit(void)
 
 /* properties_add **************************************************************
 
-   Adds a property entry to the internal property list.
+   Adds a property entry to the internal property list.  If there's
+   already an entry with the same key, replace it.
 
 *******************************************************************************/
 
 void properties_add(char *key, char *value)
 {
-       list_properties_entry *p;
+       list_properties_entry *pe;
+
+       /* search for the entry */
+
+       for (pe = list_first_unsynced(list_properties); pe != NULL;
+                pe = list_next_unsynced(list_properties, pe)) {
+               if (strcmp(pe->key, key) == 0) {
+                       /* entry was found, replace the value */
+
+                       pe->value = value;
+
+                       return;
+               }
+       }
+
+       /* entry was not found, insert a new one */
 
-       p = NEW(list_properties_entry);
+       pe = NEW(list_properties_entry);
 
-       p->key   = key;
-       p->value = value;
+       pe->key   = key;
+       pe->value = value;
 
-       list_add_last_unsynced(list_properties, p);
+       list_add_last_unsynced(list_properties, pe);
 }
 
 
@@ -351,8 +365,8 @@ char *properties_get(char *key)
        /* We search backwards, so we get the newest entry for a key, as
           the list may contain more than one entry for a specific key. */
 
-       for (pe = list_last(list_properties); pe != NULL;
-                pe = list_prev(list_properties, pe)) {
+       for (pe = list_last_unsynced(list_properties); pe != NULL;
+                pe = list_prev_unsynced(list_properties, pe)) {
                if (strcmp(pe->key, key) == 0)
                        return pe->value;
        }