1 /* src/vm/package.cpp - Java boot-package functions
3 Copyright (C) 2007, 2008
4 CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
6 This file is part of CACAO.
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License as
10 published by the Free Software Foundation; either version 2, or (at
11 your option) any later version.
13 This program is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
30 #include "toolbox/list.h"
32 #include "mm/memory.h"
34 #include "native/jni.h"
36 #include "vm/package.hpp"
37 #include "vm/string.hpp"
39 #include "vmcore/options.h"
40 #include "vmcore/utf8.h"
43 /* internal property structure ************************************************/
45 typedef struct list_package_entry_t list_package_entry_t;
47 struct list_package_entry_t {
48 /* java_string_t *packagename; */
54 /* global variables ***********************************************************/
56 static list_t *list_package = NULL;
60 * Initialize the package list.
62 void Package::initialize(void)
64 TRACESUBSYSTEMINITIALIZATION("package_init");
66 /* create the properties list */
68 list_package = list_create(OFFSET(list_package_entry_t, linkage));
73 * Add a package to the boot-package list.
75 * @param packagename Package name as Java string.
77 /* void package_add(java_handle_t *packagename) */
78 void Package::add(utf *packagename)
80 /* java_string_t *s; */
81 list_package_entry_t *lpe;
83 /* Intern the Java string to get a unique address. */
85 /* s = javastring_intern(packagename); */
87 /* Check if the package is already stored. */
89 if (Package::find(packagename) != NULL)
92 /* Add the package. */
95 if (opt_DebugPackage) {
97 log_print("[package_add: packagename=");
98 utf_display_printable_ascii(packagename);
104 lpe = NEW(list_package_entry_t);
106 lpe->packagename = packagename;
108 list_add_last(list_package, lpe);
113 * Find a package in the list.
115 * @param packagename Package name as Java string.
117 * @return Package name as Java string.
119 /* java_handle_t *package_find(java_handle_t *packagename) */
120 utf* Package::find(utf *packagename)
122 /* java_string_t *s; */
124 list_package_entry_t *lpe;
126 /* Intern the Java string to get a unique address. */
128 /* s = javastring_intern(packagename); */
130 /* For convenience. */
134 for (lpe = (list_package_entry_t*) list_first(l); lpe != NULL; lpe = (list_package_entry_t*) list_next(l, lpe)) {
135 /* if (lpe->packagename == s) */
136 if (lpe->packagename == packagename)
137 return lpe->packagename;
144 /* Legacy C interface *********************************************************/
148 void Package_initialize(void) { Package::initialize(); }
149 void Package_add(utf* packagename) { Package::add(packagename); }
150 utf* Package_find(utf *packagename) { return Package::find(packagename); }
156 * These are local overrides for various environment variables in Emacs.
157 * Please do not remove this and leave it at the end of the file, where
158 * Emacs will automagically detect them.
159 * ---------------------------------------------------------------------
162 * indent-tabs-mode: t
166 * vim:noexpandtab:sw=4:ts=4: