* WITH_BINUTILS_DISASSEMBLER: Added.
[cacao.git] / src / vm / properties.c
1 /* src/vm/properties.c - handling commandline properties
2
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
7
8    This file is part of CACAO.
9
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.
14
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.
19
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
23    02111-1307, USA.
24
25    Contact: cacao@complang.tuwien.ac.at
26
27    Authors: Christian Thalinger
28
29    Changes:
30
31    $Id: properties.c 4003 2005-12-22 15:07:43Z twisti $
32
33 */
34
35
36 #include "config.h"
37 #include "vm/types.h"
38
39 #include "vm/global.h"
40 #include "native/include/java_lang_String.h"
41 #include "native/include/java_util_Properties.h"
42 #include "toolbox/list.h"
43 #include "vm/method.h"
44 #include "vm/stringlocal.h"
45 #include "vm/jit/asmpart.h"
46
47
48 /* temporary property structure ***********************************************/
49
50 typedef struct list_properties_entry list_properties_entry;
51
52 struct list_properties_entry {
53         char     *key;
54         char     *value;
55         listnode linkage;
56 };
57
58
59 /* global variables ***********************************************************/
60
61 static list *list_properties = NULL;
62
63 static java_util_Properties *psystem;
64 static methodinfo *mput;
65
66
67 /* properties_init *************************************************************
68
69    Initialize the properties list.
70
71 *******************************************************************************/
72
73 bool properties_init(void)
74 {
75         list_properties = NEW(list);
76
77         list_init(list_properties, OFFSET(list_properties_entry, linkage));
78
79         /* everything's ok */
80
81         return true;
82 }
83
84
85 /* properties_postinit *********************************************************
86
87    Post-initialize the properties.  The passed properties table is the
88    Java system properties table.
89
90 *******************************************************************************/
91
92 bool properties_postinit(java_util_Properties *p)
93 {
94         /* set global Java system properties pointer */
95
96         psystem = p;
97
98         /* search for method to add properties */
99
100         mput = class_resolveclassmethod(p->header.vftbl->class,
101                                                                         utf_new_char("put"),
102                                                                         utf_new_char("(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;"),
103                                                                         NULL,
104                                                                         true);
105
106         if (mput == NULL)
107                 return false;
108
109         return true;
110 }
111
112
113 /* properties_add **************************************************************
114
115    Adds a property entry for a command line property definition.
116
117 *******************************************************************************/
118
119 void properties_add(char *key, char *value)
120 {
121         list_properties_entry *p;
122
123         p = NEW(list_properties_entry);
124         p->key   = key;
125         p->value = value;
126
127         list_addlast(list_properties, p);
128 }
129
130
131 /* get_property ****************************************************************
132
133    Get a property entry from a command line property definition.
134
135 *******************************************************************************/
136
137 char *properties_get(char *key)
138 {
139         list_properties_entry *p;
140
141         for (p = list_first(list_properties); p != NULL;
142                  p = list_next(list_properties, p)) {
143                 if (strcmp(p->key, key) == 0)
144                         return p->value;
145         }
146
147         return NULL;
148 }
149
150
151 /* properties_system_add *******************************************************
152
153    Adds a property to the Java system properties.
154
155 *******************************************************************************/
156
157 void properties_system_add(char *key, char *value)
158 {
159         java_lang_String *k;
160         java_lang_String *v;
161
162         k = javastring_new_char(key);
163         v = javastring_new_char(value);
164
165         asm_calljavafunction(mput, psystem, k, v, NULL);
166 }
167
168
169 /* properties_system_add_all ***************************************************
170
171    Adds a all properties from the properties list to the Java system
172    properties.
173
174 *******************************************************************************/
175
176 void properties_system_add_all(void)
177 {
178         list_properties_entry *p;
179
180         for (p = list_first(list_properties); p != NULL;
181                  p = list_first(list_properties)) {
182                 /* add to the Java system properties */
183
184                 properties_system_add(p->key, p->value);
185
186                 /* remove the entry from the list */
187
188                 list_remove(list_properties, p);
189
190                 /* and free the memory */
191
192                 FREE(p, list_properties_entry);
193         }
194 }
195
196
197 /*
198  * These are local overrides for various environment variables in Emacs.
199  * Please do not remove this and leave it at the end of the file, where
200  * Emacs will automagically detect them.
201  * ---------------------------------------------------------------------
202  * Local variables:
203  * mode: c
204  * indent-tabs-mode: t
205  * c-basic-offset: 4
206  * tab-width: 4
207  * End:
208  */