1 /* src/cacaoh/cacaoh.c - main for header generation (cacaoh)
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: Reinhard Grafl
33 $Id: cacaoh.c 5013 2006-06-06 11:22:56Z twisti $
46 #include "cacaoh/headers.h"
48 #include "mm/memory.h"
49 #include "native/include/java_lang_Throwable.h"
51 #if defined(ENABLE_THREADS)
52 # include "threads/native/threads.h"
55 #include "toolbox/logging.h"
56 #include "vm/classcache.h"
57 #include "vm/exceptions.h"
58 #include "vm/global.h"
59 #include "vm/hashtable.h"
60 #include "vm/loader.h"
61 #include "vm/options.h"
62 #include "vm/statistics.h"
63 #include "vm/stringlocal.h"
67 /* define heap sizes **********************************************************/
69 #define HEAP_MAXSIZE 2 * 1024 * 1024 /* default 2MB */
70 #define HEAP_STARTSIZE 100 * 1024 /* default 100kB */
73 /* define cacaoh options ******************************************************/
88 { "help", false, OPT_HELP },
89 { "version", false, OPT_VERSION },
90 { "verbose", false, OPT_VERBOSE },
91 { "d", true, OPT_DIRECTORY },
92 { "classpath", true, OPT_CLASSPATH },
93 { "bootclasspath", true, OPT_BOOTCLASSPATH },
98 /* usage ***********************************************************************
100 Obviously prints usage information of cacaoh.
102 *******************************************************************************/
104 static void usage(void)
106 printf("Usage: cacaoh [options] <classes>\n"
109 " -help Print this message\n"
110 " -classpath <path> \n"
111 " -bootclasspath <path> \n"
112 " -d <dir> Output directory\n"
113 " -version Print version information\n"
114 " -verbose Enable verbose output\n");
116 /* exit with error code */
122 /* version *********************************************************************
124 Prints cacaoh version information.
126 *******************************************************************************/
128 static void version(void)
130 printf("cacaoh version "VERSION"\n");
131 printf("Copyright (C) 1996-2005, 2006 R. Grafl, A. Krall, C. Kruegel,\n");
132 printf("C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,\n");
133 printf("E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,\n");
134 printf("J. Wenninger, Institut f. Computersprachen - TU Wien\n\n");
136 printf("This program is free software; you can redistribute it and/or\n");
137 printf("modify it under the terms of the GNU General Public License as\n");
138 printf("published by the Free Software Foundation; either version 2, or (at\n");
139 printf("your option) any later version.\n\n");
141 printf("This program is distributed in the hope that it will be useful, but\n");
142 printf("WITHOUT ANY WARRANTY; without even the implied warranty of\n");
143 printf("MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n");
144 printf("General Public License for more details.\n");
150 /* main ************************************************************************
154 *******************************************************************************/
156 int main(int argc, char **argv)
158 JavaVMInitArgs *vm_args;
164 /********** internal (only used by main) *****************************/
177 #if defined(DISABLE_GC)
178 nogc_init(HEAP_MAXSIZE, HEAP_STARTSIZE);
181 /* set the bootclasspath */
183 cp = getenv("BOOTCLASSPATH");
186 bootclasspath = MNEW(char, strlen(cp) + strlen("0"));
187 strcpy(bootclasspath, cp);
190 cplen = strlen(CACAO_VM_ZIP) +
192 strlen(CLASSPATH_GLIBJ_ZIP) +
195 bootclasspath = MNEW(char, cplen);
196 strcat(bootclasspath, CACAO_VM_ZIP);
197 strcat(bootclasspath, ":");
198 strcat(bootclasspath, CLASSPATH_GLIBJ_ZIP);
202 /* set the classpath */
204 cp = getenv("CLASSPATH");
207 classpath = MNEW(char, strlen(cp) + strlen("0"));
208 strcat(classpath, cp);
211 classpath = MNEW(char, strlen(".") + strlen("0"));
212 strcpy(classpath, ".");
216 /* initialize options with default values */
219 opt_directory = NULL;
221 heapmaxsize = HEAP_MAXSIZE;
222 heapstartsize = HEAP_STARTSIZE;
225 /* parse the options ******************************************************/
227 vm_args = options_prepare(argc, argv);
229 while ((opt = options_get(opts, vm_args)) != OPT_DONE) {
239 /* forget old classpath and set the argument as new classpath */
240 MFREE(classpath, char, strlen(classpath));
242 classpath = MNEW(char, strlen(opt_arg) + strlen("0"));
243 strcpy(classpath, opt_arg);
246 case OPT_BOOTCLASSPATH:
247 /* Forget default bootclasspath and set the argument as
248 new boot classpath. */
249 MFREE(bootclasspath, char, strlen(bootclasspath));
251 bootclasspath = MNEW(char, strlen(opt_arg) + strlen("0"));
252 strcpy(bootclasspath, opt_arg);
256 opt_directory = MNEW(char, strlen(opt_arg) + strlen("0"));
257 strcpy(opt_directory, opt_arg);
275 /**************************** Program start **************************/
279 log_text("Java - header-generator started");
282 /* initialize the garbage collector */
284 gc_init(heapmaxsize, heapstartsize);
286 #if defined(ENABLE_THREADS)
290 /* initialize the string hashtable stuff: lock (must be done
291 _after_ threads_preinit) */
294 throw_main_exception_exit();
296 /* initialize the utf8 hashtable stuff: lock, often used utf8 strings
297 (must be done _after_ threads_preinit) */
300 throw_main_exception_exit();
302 /* initialize the classcache hashtable stuff: lock, hashtable
303 (must be done _after_ threads_preinit) */
305 if (!classcache_init())
306 throw_main_exception_exit();
308 /* initialize the loader with bootclasspath (must be done _after_
312 throw_main_exception_exit();
314 suck_add(bootclasspath);
316 /* Also add the normal classpath, so the bootstrap class loader
317 can find the files. */
321 /* initialize the loader subsystems (must be done _after_
325 throw_main_exception_exit();
328 /* load Java classes ******************************************************/
330 for (i = opt_index; i < vm_args->nOptions; i++) {
331 cp = vm_args->options[i].optionString;
333 /* convert classname */
335 for (j = strlen(cp) - 1; j >= 0; j--) {
346 /* exceptions are catched with new_exception call */
348 if (!(c = load_class_bootstrap(utf_new_char(cp))))
349 throw_cacao_exception_exit(string_java_lang_NoClassDefFoundError,
353 throw_cacao_exception_exit(string_java_lang_LinkageError,
356 headerfile_generate(c, opt_directory);
359 /************************ Release all resources **********************/
364 log_text("Java - header-generator stopped");
365 #if defined(ENABLE_STATISTICS)
375 * These are local overrides for various environment variables in Emacs.
376 * Please do not remove this and leave it at the end of the file, where
377 * Emacs will automagically detect them.
378 * ---------------------------------------------------------------------
381 * indent-tabs-mode: t