1 /* src/cacaoh/cacaoh.c - main for header generation (cacaoh)
3 Copyright (C) 1996-2005, 2006, 2007 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 $Id: cacaoh.c 8123 2007-06-20 23:50:55Z michi $
38 #include "cacaoh/headers.h"
40 #include "mm/gc-common.h"
41 #include "mm/memory.h"
43 #include "toolbox/hashtable.h"
44 #include "toolbox/logging.h"
46 #include "vm/exceptions.h"
47 #include "vm/global.h"
48 #include "vm/stringlocal.h"
51 #include "vmcore/classcache.h"
52 #include "vmcore/loader.h"
53 #include "vmcore/options.h"
54 #include "vmcore/statistics.h"
55 #include "vmcore/suck.h"
58 /* define cacaoh options ******************************************************/
73 { "help", false, OPT_HELP },
74 { "version", false, OPT_VERSION },
75 { "verbose", false, OPT_VERBOSE },
76 { "d", true, OPT_DIRECTORY },
77 { "classpath", true, OPT_CLASSPATH },
78 { "bootclasspath", true, OPT_BOOTCLASSPATH },
83 /* usage ***********************************************************************
85 Obviously prints usage information of cacaoh.
87 *******************************************************************************/
91 printf("Usage: cacaoh [options] <classes>\n"
94 " -help Print this message\n"
95 " -classpath <path> \n"
96 " -bootclasspath <path> \n"
97 " -d <dir> Output directory\n"
98 " -version Print version information\n"
99 " -verbose Enable verbose output\n");
101 /* exit with error code */
107 /* version *********************************************************************
109 Prints cacaoh version information.
111 *******************************************************************************/
113 static void version(void)
115 printf("cacaoh version "VERSION"\n");
116 printf("Copyright (C) 1996-2005, 2006, 2007 R. Grafl, A. Krall, C. Kruegel,\n");
117 printf("C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,\n");
118 printf("E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,\n");
119 printf("J. Wenninger, Institut f. Computersprachen - TU Wien\n\n");
121 printf("This program is free software; you can redistribute it and/or\n");
122 printf("modify it under the terms of the GNU General Public License as\n");
123 printf("published by the Free Software Foundation; either version 2, or (at\n");
124 printf("your option) any later version.\n\n");
126 printf("This program is distributed in the hope that it will be useful, but\n");
127 printf("WITHOUT ANY WARRANTY; without even the implied warranty of\n");
128 printf("MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n");
129 printf("General Public License for more details.\n");
135 /* forward declarations *******************************************************/
137 static JavaVMInitArgs *cacaoh_options_prepare(int argc, char **argv);
140 /* main ************************************************************************
144 *******************************************************************************/
146 int main(int argc, char **argv)
148 JavaVMInitArgs *vm_args;
154 /********** internal (only used by main) *****************************/
164 /* set the bootclasspath */
166 cp = getenv("BOOTCLASSPATH");
169 bootclasspath = MNEW(char, strlen(cp) + strlen("0"));
170 strcpy(bootclasspath, cp);
174 #if defined(WITH_CLASSPATH_GNU)
175 strlen(CACAO_VM_ZIP) +
178 strlen(CLASSPATH_CLASSES) +
181 bootclasspath = MNEW(char, cplen);
182 #if defined(WITH_CLASSPATH_GNU)
183 strcat(bootclasspath, CACAO_VM_ZIP);
184 strcat(bootclasspath, ":");
186 strcat(bootclasspath, CLASSPATH_CLASSES);
190 /* set the classpath */
192 cp = getenv("CLASSPATH");
195 classpath = MNEW(char, strlen(cp) + strlen("0"));
196 strcat(classpath, cp);
199 classpath = MNEW(char, strlen(".") + strlen("0"));
200 strcpy(classpath, ".");
204 /* initialize options with default values */
207 opt_directory = NULL;
210 /* parse the options ******************************************************/
212 vm_args = cacaoh_options_prepare(argc, argv);
214 while ((opt = options_get(opts, vm_args)) != OPT_DONE) {
224 /* forget old classpath and set the argument as new classpath */
225 MFREE(classpath, char, strlen(classpath));
227 classpath = MNEW(char, strlen(opt_arg) + strlen("0"));
228 strcpy(classpath, opt_arg);
231 case OPT_BOOTCLASSPATH:
232 /* Forget default bootclasspath and set the argument as
233 new boot classpath. */
234 MFREE(bootclasspath, char, strlen(bootclasspath));
236 bootclasspath = MNEW(char, strlen(opt_arg) + strlen("0"));
237 strcpy(bootclasspath, opt_arg);
241 opt_directory = MNEW(char, strlen(opt_arg) + strlen("0"));
242 strcpy(opt_directory, opt_arg);
260 /**************************** Program start **************************/
264 log_println("Java - header-generator started");
267 /* initialize the utf8 hashtable stuff: lock, often used utf8 strings
268 (must be done _after_ threads_preinit) */
271 vm_abort("utf8_init failed\n");
273 /* initialize the classcache hashtable stuff: lock, hashtable
274 (must be done _after_ threads_preinit) */
276 if (!classcache_init())
277 vm_abort("classcache_init failed\n");
279 /* initialize the loader with bootclasspath (must be done _after_
283 vm_abort("suck_init failed\n");
285 suck_add(bootclasspath);
287 /* Also add the normal classpath, so the bootstrap class loader
288 can find the files. */
292 /* initialize the loader subsystems (must be done _after_
296 vm_abort("loader_init failed\n");
299 /* load Java classes ******************************************************/
301 for (i = opt_index; i < vm_args->nOptions; i++) {
302 cp = vm_args->options[i].optionString;
304 /* convert classname */
306 for (j = strlen(cp) - 1; j >= 0; j--) {
317 /* exceptions are catched with new_exception call */
319 if (!(c = load_class_bootstrap(utf_new_char(cp))))
320 vm_abort("java.lang.NoClassDefFoundError: %s\n", cp);
323 vm_abort("java.lang.LinkageError: %s\n", cp);
325 headerfile_generate(c, opt_directory);
328 /************************ Release all resources **********************/
333 log_println("Java - header-generator stopped");
334 #if defined(ENABLE_STATISTICS)
335 statistics_print_memory_usage();
343 /* cacaoh_options_prepare ******************************************************
345 Prepare the JavaVMInitArgs.
347 *******************************************************************************/
349 static JavaVMInitArgs *cacaoh_options_prepare(int argc, char **argv)
351 JavaVMInitArgs *vm_args;
354 vm_args = NEW(JavaVMInitArgs);
356 vm_args->nOptions = argc - 1;
357 vm_args->options = MNEW(JavaVMOption, argc);
359 for (i = 1; i < argc; i++)
360 vm_args->options[i - 1].optionString = argv[i];
367 * These are local overrides for various environment variables in Emacs.
368 * Please do not remove this and leave it at the end of the file, where
369 * Emacs will automagically detect them.
370 * ---------------------------------------------------------------------
373 * indent-tabs-mode: t