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
36 #include "cacaoh/headers.h"
38 #include "mm/gc-common.h"
39 #include "mm/memory.h"
41 #include "toolbox/hashtable.h"
42 #include "toolbox/logging.h"
44 #include "vm/exceptions.h"
45 #include "vm/global.h"
46 #include "vm/stringlocal.h"
49 #include "vmcore/classcache.h"
50 #include "vmcore/loader.h"
51 #include "vmcore/options.h"
52 #include "vmcore/statistics.h"
53 #include "vmcore/suck.h"
56 /* define cacaoh options ******************************************************/
71 { "help", false, OPT_HELP },
72 { "version", false, OPT_VERSION },
73 { "verbose", false, OPT_VERBOSE },
74 { "d", true, OPT_DIRECTORY },
75 { "classpath", true, OPT_CLASSPATH },
76 { "bootclasspath", true, OPT_BOOTCLASSPATH },
81 /* usage ***********************************************************************
83 Obviously prints usage information of cacaoh.
85 *******************************************************************************/
89 printf("Usage: cacaoh [options] <classes>\n"
92 " -help Print this message\n"
93 " -classpath <path> \n"
94 " -bootclasspath <path> \n"
95 " -d <dir> Output directory\n"
96 " -version Print version information\n"
97 " -verbose Enable verbose output\n");
99 /* exit with error code */
105 /* version *********************************************************************
107 Prints cacaoh version information.
109 *******************************************************************************/
111 static void version(void)
113 printf("cacaoh version "VERSION"\n");
114 printf("Copyright (C) 1996-2005, 2006, 2007 R. Grafl, A. Krall, C. Kruegel,\n");
115 printf("C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,\n");
116 printf("E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,\n");
117 printf("J. Wenninger, Institut f. Computersprachen - TU Wien\n\n");
119 printf("This program is free software; you can redistribute it and/or\n");
120 printf("modify it under the terms of the GNU General Public License as\n");
121 printf("published by the Free Software Foundation; either version 2, or (at\n");
122 printf("your option) any later version.\n\n");
124 printf("This program is distributed in the hope that it will be useful, but\n");
125 printf("WITHOUT ANY WARRANTY; without even the implied warranty of\n");
126 printf("MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n");
127 printf("General Public License for more details.\n");
133 /* forward declarations *******************************************************/
135 static JavaVMInitArgs *cacaoh_options_prepare(int argc, char **argv);
138 /* main ************************************************************************
142 *******************************************************************************/
144 int main(int argc, char **argv)
146 JavaVMInitArgs *vm_args;
152 /********** internal (only used by main) *****************************/
162 /* set the bootclasspath */
164 cp = getenv("BOOTCLASSPATH");
167 bootclasspath = MNEW(char, strlen(cp) + strlen("0"));
168 strcpy(bootclasspath, cp);
172 #if defined(WITH_CLASSPATH_GNU)
173 strlen(CACAO_VM_ZIP) +
176 strlen(CLASSPATH_CLASSES) +
179 bootclasspath = MNEW(char, cplen);
180 #if defined(WITH_CLASSPATH_GNU)
181 strcat(bootclasspath, CACAO_VM_ZIP);
182 strcat(bootclasspath, ":");
184 strcat(bootclasspath, CLASSPATH_CLASSES);
188 /* set the classpath */
190 cp = getenv("CLASSPATH");
193 classpath = MNEW(char, strlen(cp) + strlen("0"));
194 strcat(classpath, cp);
197 classpath = MNEW(char, strlen(".") + strlen("0"));
198 strcpy(classpath, ".");
202 /* initialize options with default values */
205 opt_directory = NULL;
208 /* parse the options ******************************************************/
210 vm_args = cacaoh_options_prepare(argc, argv);
212 while ((opt = options_get(opts, vm_args)) != OPT_DONE) {
222 /* forget old classpath and set the argument as new classpath */
223 MFREE(classpath, char, strlen(classpath));
225 classpath = MNEW(char, strlen(opt_arg) + strlen("0"));
226 strcpy(classpath, opt_arg);
229 case OPT_BOOTCLASSPATH:
230 /* Forget default bootclasspath and set the argument as
231 new boot classpath. */
232 MFREE(bootclasspath, char, strlen(bootclasspath));
234 bootclasspath = MNEW(char, strlen(opt_arg) + strlen("0"));
235 strcpy(bootclasspath, opt_arg);
239 opt_directory = MNEW(char, strlen(opt_arg) + strlen("0"));
240 strcpy(opt_directory, opt_arg);
258 /**************************** Program start **************************/
262 log_println("Java - header-generator started");
265 /* initialize the utf8 hashtable stuff: lock, often used utf8 strings
266 (must be done _after_ threads_preinit) */
269 vm_abort("utf8_init failed\n");
271 /* initialize the classcache hashtable stuff: lock, hashtable
272 (must be done _after_ threads_preinit) */
274 if (!classcache_init())
275 vm_abort("classcache_init failed\n");
277 /* initialize the loader with bootclasspath (must be done _after_
281 vm_abort("suck_init failed\n");
283 suck_add(bootclasspath);
285 /* Also add the normal classpath, so the bootstrap class loader
286 can find the files. */
290 /* initialize the loader subsystems (must be done _after_
294 vm_abort("loader_init failed\n");
297 /* load Java classes ******************************************************/
299 for (i = opt_index; i < vm_args->nOptions; i++) {
300 cp = vm_args->options[i].optionString;
302 /* convert classname */
304 for (j = strlen(cp) - 1; j >= 0; j--) {
315 /* exceptions are catched with new_exception call */
317 if (!(c = load_class_bootstrap(utf_new_char(cp))))
318 vm_abort("java.lang.NoClassDefFoundError: %s\n", cp);
321 vm_abort("java.lang.LinkageError: %s\n", cp);
323 headerfile_generate(c, opt_directory);
326 /************************ Release all resources **********************/
331 log_println("Java - header-generator stopped");
332 #if defined(ENABLE_STATISTICS)
333 statistics_print_memory_usage();
341 /* cacaoh_options_prepare ******************************************************
343 Prepare the JavaVMInitArgs.
345 *******************************************************************************/
347 static JavaVMInitArgs *cacaoh_options_prepare(int argc, char **argv)
349 JavaVMInitArgs *vm_args;
352 vm_args = NEW(JavaVMInitArgs);
354 vm_args->nOptions = argc - 1;
355 vm_args->options = MNEW(JavaVMOption, argc);
357 for (i = 1; i < argc; i++)
358 vm_args->options[i - 1].optionString = argv[i];
365 * These are local overrides for various environment variables in Emacs.
366 * Please do not remove this and leave it at the end of the file, where
367 * Emacs will automagically detect them.
368 * ---------------------------------------------------------------------
371 * indent-tabs-mode: t