Just ignore some files.
[cacao.git] / src / cacaoh / cacaoh.c
index eeef09d52dc120893cfcc30977a39da1670e7919..bfea7dab813321ce7f664e6ef5ea19adc85d5f90 100644 (file)
@@ -1,9 +1,9 @@
 /* cacaoh/cacaoh.c - main for header generation (cacaoh)
 
-   Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
-   R. Grafl, A. Krall, C. Kruegel, C. Oates, R. Obermaisser,
-   M. Probst, S. Ring, E. Steiner, C. Thalinger, D. Thuernbeck,
-   P. Tomsich, J. Wenninger
+   Copyright (C) 1996-2005 R. Grafl, A. Krall, C. Kruegel, C. Oates,
+   R. Obermaisser, M. Platter, M. Probst, S. Ring, E. Steiner,
+   C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich, J. Wenninger,
+   Institut f. Computersprachen - TU Wien
 
    This file is part of CACAO.
 
@@ -30,7 +30,7 @@
             Philipp Tomsich
             Christian Thalinger
 
-   $Id: cacaoh.c 1621 2004-11-30 13:06:55Z twisti $
+   $Id: cacaoh.c 1910 2005-02-10 09:55:49Z twisti $
 
 */
 
@@ -44,6 +44,7 @@
 #include "cacaoh/headers.h"
 #include "mm/boehm.h"
 #include "mm/memory.h"
+#include "native/include/java_lang_Throwable.h"
 
 #if defined(USE_THREADS)
 # if defined(NATIVE_THREADS)
 #endif
 
 #include "toolbox/logging.h"
+#include "vm/exceptions.h"
 #include "vm/global.h"
 #include "vm/loader.h"
 #include "vm/options.h"
+#include "vm/statistics.h"
+#include "vm/stringlocal.h"
 #include "vm/tables.h"
 
 
+/* define heap sizes **********************************************************/
+
+#define HEAP_MAXSIZE      2 * 1024 * 1024;  /* default 2MB                    */
+#define HEAP_STARTSIZE    100 * 1024;       /* default 100kB                  */
+
+
 /* define cacaoh options ******************************************************/
 
-#define OPT_HELP      2
-#define OPT_VERSION   3
-#define OPT_VERBOSE   4
-#define OPT_DIRECTORY 5
+#define OPT_HELP          2
+#define OPT_VERSION       3
+#define OPT_VERBOSE       4
+#define OPT_DIRECTORY     5
+#define OPT_CLASSPATH     6
+#define OPT_BOOTCLASSPATH 7
 
 opt_struct opts[] = {
-       { "help",             false, OPT_HELP      },
-       { "version",          false, OPT_VERSION   },
-       { "verbose",          false, OPT_VERBOSE   },
-       { "d",                true,  OPT_DIRECTORY },
-       { NULL,               false, 0 }
+       { "help",             false, OPT_HELP          },
+       { "version",          false, OPT_VERSION       },
+       { "verbose",          false, OPT_VERBOSE       },
+       { "d",                true,  OPT_DIRECTORY     },
+       { "classpath",        true,  OPT_CLASSPATH     },
+       { "bootclasspath",    true,  OPT_BOOTCLASSPATH },
+       { NULL,               false, 0                 }
 };
 
 
@@ -87,10 +101,12 @@ static void usage()
        printf("Usage: cacaoh [options] <classes>\n"
                   "\n"
                   "Options:\n"
-                  "        -help           Print this message\n"
-                  "        -version        Print version information\n"
-                  "        -verbose        Enable verbose output\n"
-                  "        -d <dir>        Output directory\n");
+                  "    -help                 Print this message\n"
+                  "    -classpath <path>     \n"
+                  "    -bootclasspath <path> \n"
+                  "    -d <dir>              Output directory\n"
+                  "    -version              Print version information\n"
+                  "    -verbose              Enable verbose output\n");
 
        /* exit with error code */
 
@@ -114,33 +130,60 @@ static void version()
 int main(int argc, char **argv)
 {
        s4 i, a;
-       char *cp;
        classinfo *c;
        char *opt_directory;
+       void *dummy;
 
        /********** internal (only used by main) *****************************/
    
-       char classpath[500] = "";
-       u4 heapmaxsize = 2 * 1024 * 1024;
-       u4 heapstartsize = 100 * 1024;
-
-
-       /************ Collect some info from the environment *****************/
+       char *bootclasspath;
+       char *classpath;
+       char *cp;
+       s4    cplen;
+       u4    heapmaxsize;
+       u4    heapstartsize;
 
        if (argc < 2)
                usage();
 
+
+       /* set the bootclasspath */
+
+       cp = getenv("BOOTCLASSPATH");
+       if (cp) {
+               bootclasspath = MNEW(char, strlen(cp) + 1);
+               strcpy(bootclasspath, cp);
+
+       } else {
+               cplen = strlen(CACAO_INSTALL_PREFIX) + strlen(CACAO_RT_JAR_PATH);
+
+               bootclasspath = MNEW(char, cplen + 1);
+               strcpy(bootclasspath, CACAO_INSTALL_PREFIX);
+               strcat(bootclasspath, CACAO_RT_JAR_PATH);
+       }
+
+
+       /* set the classpath */
+
        cp = getenv("CLASSPATH");
        if (cp) {
-               strcpy(classpath + strlen(classpath), ":");
-               strcpy(classpath + strlen(classpath), cp);
+               classpath = MNEW(char, strlen(cp) + 1);
+               strcat(classpath, cp);
+
+       } else {
+               classpath = MNEW(char, 2);
+               strcpy(classpath, ".");
        }
 
+
        /* initialize options with default values */
 
        opt_verbose = false;
        opt_directory = NULL;
 
+       heapmaxsize = HEAP_MAXSIZE;
+       heapstartsize = HEAP_STARTSIZE;
+
        while ((i = get_opt(argc, argv, opts)) != OPT_DONE) {
                switch (i) {
                case OPT_IGNORE:
@@ -150,19 +193,36 @@ int main(int argc, char **argv)
                        usage();
                        break;
 
-               case OPT_VERSION:
-                       version();
+               case OPT_CLASSPATH:
+                       /* forget old classpath and set the argument as new classpath */
+                       MFREE(classpath, char, strlen(classpath));
+
+                       classpath = MNEW(char, strlen(opt_arg) + 1);
+                       strcpy(classpath, opt_arg);
                        break;
 
-               case OPT_VERBOSE:
-                       opt_verbose = true;
+               case OPT_BOOTCLASSPATH:
+                       /* Forget default bootclasspath and set the argument as new boot  */
+                       /* classpath.                                                     */
+                       MFREE(bootclasspath, char, strlen(bootclasspath));
+
+                       bootclasspath = MNEW(char, strlen(opt_arg) + 1);
+                       strcpy(bootclasspath, opt_arg);
                        break;
 
                case OPT_DIRECTORY:
-                       opt_directory = MNEW(char, strlen(opt_arg));
+                       opt_directory = MNEW(char, strlen(opt_arg) + 1);
                        strcpy(opt_directory, opt_arg);
                        break;
 
+               case OPT_VERSION:
+                       version();
+                       break;
+
+               case OPT_VERBOSE:
+                       opt_verbose = true;
+                       break;
+
                default:
                        usage();
                }
@@ -176,10 +236,14 @@ int main(int argc, char **argv)
        }
        
        /* initialize the garbage collector */
+
        gc_init(heapmaxsize, heapstartsize);
 
        tables_init();
+       
+       /* initialize the loader with bootclasspath and append classpath entries */
 
+       suck_init(bootclasspath);
        suck_init(classpath);
    
 #if defined(USE_THREADS)
@@ -189,7 +253,11 @@ int main(int argc, char **argv)
        initLocks();
 #endif
 
-       loader_init();
+       /* initialize some cacao subsystems */
+
+       utf8_init();
+       class_init_foo();
+       loader_init((u1 *) &dummy);
 
 
        /*********************** Load JAVA classes  **************************/
@@ -201,19 +269,26 @@ int main(int argc, char **argv)
                cp = argv[a];
 
                /* convert classname */
+
                for (i = strlen(cp) - 1; i >= 0; i--) {
                        switch (cp[i]) {
-                       case '.': cp[i]='/';
+                       case '.': cp[i] = '/';
                                break;
-                       case '_': cp[i]='$';    
+                       case '_': cp[i] = '$';
                        }
                }
        
                c = class_new(utf_new_char(cp));
 
                /* exceptions are catched with new_exception call */
-               class_load(c);
-               class_link(c);
+
+               if (!class_load(c))
+                       throw_cacao_exception_exit(string_java_lang_NoClassDefFoundError,
+                                                                          cp);
+
+               if (!class_link(c))
+                       throw_cacao_exception_exit(string_java_lang_LinkageError,
+                                                                          cp);
 
                headerfile_generate(c, opt_directory);
        }
@@ -221,12 +296,12 @@ int main(int argc, char **argv)
        /************************ Release all resources **********************/
 
        loader_close();
-       tables_close(literalstring_free);
+       tables_close();
 
        if (opt_verbose) {
                log_text("Java - header-generator stopped");
                log_cputime();
-               mem_usagelog(1);
+               mem_usagelog(true);
        }
        
        return 0;