1 /* src/vm/properties.c - handling commandline properties
3 Copyright (C) 1996-2005, 2006 R. Grafl, A. Krall, C. Kruegel,
4 C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
5 E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
6 J. Wenninger, Institut f. Computersprachen - TU Wien
8 This file is part of CACAO.
10 This program is free software; you can redistribute it and/or
11 modify it under the terms of the GNU General Public License as
12 published by the Free Software Foundation; either version 2, or (at
13 your option) any later version.
15 This program is distributed in the hope that it will be useful, but
16 WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
25 Contact: cacao@cacaojvm.org
27 Authors: Christian Thalinger
31 $Id: properties.c 4559 2006-03-05 23:24:50Z twisti $
42 #include "mm/memory.h"
44 #include "vm/global.h"
45 #include "native/include/java_lang_String.h"
46 #include "native/include/java_util_Properties.h"
47 #include "toolbox/list.h"
48 #include "vm/method.h"
49 #include "vm/options.h"
50 #include "vm/stringlocal.h"
52 #include "vm/jit/asmpart.h"
55 /* temporary property structure ***********************************************/
57 typedef struct list_properties_entry list_properties_entry;
59 struct list_properties_entry {
66 /* global variables ***********************************************************/
68 static list *list_properties = NULL;
70 static java_util_Properties *psystem;
71 static methodinfo *mput;
74 /* properties_init *************************************************************
76 Initialize the properties list.
78 *******************************************************************************/
80 bool properties_init(void)
82 list_properties = NEW(list);
84 list_init(list_properties, OFFSET(list_properties_entry, linkage));
92 /* properties_postinit *********************************************************
94 Post-initialize the properties. The passed properties table is the
95 Java system properties table.
97 *******************************************************************************/
99 bool properties_postinit(java_util_Properties *p)
101 /* set global Java system properties pointer */
105 /* search for method to add properties */
107 mput = class_resolveclassmethod(p->header.vftbl->class,
109 utf_new_char("(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;"),
120 /* properties_add **************************************************************
122 Adds a property entry for a command line property definition.
124 *******************************************************************************/
126 void properties_add(char *key, char *value)
128 list_properties_entry *p;
130 p = NEW(list_properties_entry);
134 list_addlast(list_properties, p);
138 /* get_property ****************************************************************
140 Get a property entry from a command line property definition.
142 *******************************************************************************/
144 char *properties_get(char *key)
146 list_properties_entry *p;
148 for (p = list_first(list_properties); p != NULL;
149 p = list_next(list_properties, p)) {
150 if (strcmp(p->key, key) == 0)
158 /* properties_system_add *******************************************************
160 Adds a property to the Java system properties.
162 *******************************************************************************/
164 void properties_system_add(char *key, char *value)
169 k = javastring_new_char(key);
170 v = javastring_new_char(value);
172 (void) vm_call_method(mput, (java_objectheader *) psystem, k, v);
176 /* properties_system_add_all ***************************************************
178 Adds a all properties from the properties list to the Java system
181 *******************************************************************************/
183 void properties_system_add_all(void)
185 list_properties_entry *p;
187 for (p = list_first(list_properties); p != NULL;
188 p = list_first(list_properties)) {
189 /* add to the Java system properties */
191 properties_system_add(p->key, p->value);
193 /* remove the entry from the list */
195 list_remove(list_properties, p);
197 /* and free the memory */
199 FREE(p, list_properties_entry);
205 * These are local overrides for various environment variables in Emacs.
206 * Please do not remove this and leave it at the end of the file, where
207 * Emacs will automagically detect them.
208 * ---------------------------------------------------------------------
211 * indent-tabs-mode: t