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/options.h"
37 #include "vm/package.hpp"
38 #include "vm/string.hpp"
42 /* internal property structure ************************************************/
44 typedef struct list_package_entry_t list_package_entry_t;
46 struct list_package_entry_t {
47 /* java_string_t *packagename; */
53 /* global variables ***********************************************************/
55 static list_t *list_package = NULL;
59 * Initialize the package list.
61 void Package::initialize(void)
63 TRACESUBSYSTEMINITIALIZATION("package_init");
65 /* create the properties list */
67 list_package = list_create(OFFSET(list_package_entry_t, linkage));
72 * Add a package to the boot-package list.
74 * @param packagename Package name as Java string.
76 /* void package_add(java_handle_t *packagename) */
77 void Package::add(utf *packagename)
79 /* java_string_t *s; */
80 list_package_entry_t *lpe;
82 /* Intern the Java string to get a unique address. */
84 /* s = javastring_intern(packagename); */
86 /* Check if the package is already stored. */
88 if (Package::find(packagename) != NULL)
91 /* Add the package. */
94 if (opt_DebugPackage) {
96 log_print("[package_add: packagename=");
97 utf_display_printable_ascii(packagename);
103 lpe = NEW(list_package_entry_t);
105 lpe->packagename = packagename;
107 list_add_last(list_package, lpe);
112 * Find a package in the list.
114 * @param packagename Package name as Java string.
116 * @return Package name as Java string.
118 /* java_handle_t *package_find(java_handle_t *packagename) */
119 utf* Package::find(utf *packagename)
121 /* java_string_t *s; */
123 list_package_entry_t *lpe;
125 /* Intern the Java string to get a unique address. */
127 /* s = javastring_intern(packagename); */
129 /* For convenience. */
133 for (lpe = (list_package_entry_t*) list_first(l); lpe != NULL; lpe = (list_package_entry_t*) list_next(l, lpe)) {
134 /* if (lpe->packagename == s) */
135 if (lpe->packagename == packagename)
136 return lpe->packagename;
143 /* Legacy C interface *********************************************************/
147 void Package_initialize(void) { Package::initialize(); }
148 void Package_add(utf* packagename) { Package::add(packagename); }
149 utf* Package_find(utf *packagename) { return Package::find(packagename); }
155 * These are local overrides for various environment variables in Emacs.
156 * Please do not remove this and leave it at the end of the file, where
157 * Emacs will automagically detect them.
158 * ---------------------------------------------------------------------
161 * indent-tabs-mode: t
165 * vim:noexpandtab:sw=4:ts=4: