1 /* src/vm/properties.c - handling commandline properties
3 Copyright (C) 1996-2005 R. Grafl, A. Krall, C. Kruegel, C. Oates,
4 R. Obermaisser, M. Platter, M. Probst, S. Ring, E. Steiner,
5 C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich, J. Wenninger,
6 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., 59 Temple Place - Suite 330, Boston, MA
25 Contact: cacao@complang.tuwien.ac.at
27 Authors: Christian Thalinger
31 $Id: properties.c 4145 2006-01-12 21:06:07Z twisti $
42 #include "vm/global.h"
43 #include "native/include/java_lang_String.h"
44 #include "native/include/java_util_Properties.h"
45 #include "toolbox/list.h"
46 #include "vm/method.h"
47 #include "vm/options.h"
48 #include "vm/stringlocal.h"
49 #include "vm/jit/asmpart.h"
52 /* temporary property structure ***********************************************/
54 typedef struct list_properties_entry list_properties_entry;
56 struct list_properties_entry {
63 /* global variables ***********************************************************/
65 static list *list_properties = NULL;
67 static java_util_Properties *psystem;
68 static methodinfo *mput;
71 /* properties_init *************************************************************
73 Initialize the properties list.
75 *******************************************************************************/
77 bool properties_init(void)
79 list_properties = NEW(list);
81 list_init(list_properties, OFFSET(list_properties_entry, linkage));
89 /* properties_postinit *********************************************************
91 Post-initialize the properties. The passed properties table is the
92 Java system properties table.
94 *******************************************************************************/
96 bool properties_postinit(java_util_Properties *p)
98 /* set global Java system properties pointer */
102 /* search for method to add properties */
104 mput = class_resolveclassmethod(p->header.vftbl->class,
106 utf_new_char("(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;"),
117 /* properties_add **************************************************************
119 Adds a property entry for a command line property definition.
121 *******************************************************************************/
123 void properties_add(char *key, char *value)
125 list_properties_entry *p;
127 p = NEW(list_properties_entry);
131 list_addlast(list_properties, p);
135 /* get_property ****************************************************************
137 Get a property entry from a command line property definition.
139 *******************************************************************************/
141 char *properties_get(char *key)
143 list_properties_entry *p;
145 for (p = list_first(list_properties); p != NULL;
146 p = list_next(list_properties, p)) {
147 if (strcmp(p->key, key) == 0)
155 /* properties_system_add *******************************************************
157 Adds a property to the Java system properties.
159 *******************************************************************************/
161 void properties_system_add(char *key, char *value)
166 k = javastring_new_char(key);
167 v = javastring_new_char(value);
169 ASM_CALLJAVAFUNCTION(mput, psystem, k, v, NULL);
173 /* properties_system_add_all ***************************************************
175 Adds a all properties from the properties list to the Java system
178 *******************************************************************************/
180 void properties_system_add_all(void)
182 list_properties_entry *p;
184 for (p = list_first(list_properties); p != NULL;
185 p = list_first(list_properties)) {
186 /* add to the Java system properties */
188 properties_system_add(p->key, p->value);
190 /* remove the entry from the list */
192 list_remove(list_properties, p);
194 /* and free the memory */
196 FREE(p, list_properties_entry);
202 * These are local overrides for various environment variables in Emacs.
203 * Please do not remove this and leave it at the end of the file, where
204 * Emacs will automagically detect them.
205 * ---------------------------------------------------------------------
208 * indent-tabs-mode: t