Teach cacaoh to understand -d <dir> to install generated header files into
authortwisti <none@none>
Wed, 17 Nov 2004 17:19:14 +0000 (17:19 +0000)
committertwisti <none@none>
Wed, 17 Nov 2004 17:19:14 +0000 (17:19 +0000)
a destination directory. Default is `.'.

13 files changed:
Makefile.am
cacaoh.c
headers.c
headers.h
main.c
options.c
options.h
src/cacao/cacao.c
src/cacaoh/cacaoh.c
src/cacaoh/headers.c
src/cacaoh/headers.h
src/vm/options.c
src/vm/options.h

index 1044f9f5b357a74fea8175f2d8f8f91b40e72a77..3cda951f05beff52fc3a5ba9d28e56941ad461b1 100644 (file)
@@ -1,6 +1,6 @@
 ## Process this file with automake to produce Makefile.in
 
-# $Id: Makefile.am 1486 2004-11-12 10:02:54Z twisti $
+# $Id: Makefile.am 1529 2004-11-17 17:19:14Z twisti $
 
 @SET_MAKE@
 
@@ -124,10 +124,15 @@ gennativetable_LDADD = \
        @THREAD_LIB@
 
 natheaders: cacaoh
-       CLASSPATH=$(top_srcdir)/classpath/lib/bootstrap.zip ./cacaoh $(CLASSES)
+       CLASSPATH=$(top_srcdir)/classpath/lib/bootstrap.zip \
+       ./cacaoh -d nat/ \
+       $(CLASSES)
 
 nativetable.inc: gennativetable nat/implementednatives.data
-       CLASSPATH=$(top_srcdir)/classpath/lib/bootstrap.zip $(top_srcdir)/gennativetable $(CLASSES) > nativetable.inc
+       CLASSPATH=$(top_srcdir)/classpath/lib/bootstrap.zip \
+       $(top_srcdir)/gennativetable \
+       $(CLASSES) \
+       > nativetable.inc
 
 native.c: nativetable.inc
 
index c27c6a88470be9b875851239d686604af655c41d..f19066cafc453ae0f8e7dc798568d414c0e7289a 100644 (file)
--- a/cacaoh.c
+++ b/cacaoh.c
@@ -30,7 +30,7 @@
             Philipp Tomsich
             Christian Thalinger
 
-   $Id: cacaoh.c 1406 2004-08-17 10:03:55Z twisti $
+   $Id: cacaoh.c 1529 2004-11-17 17:19:14Z twisti $
 
 */
 
@@ -42,6 +42,7 @@
 #include "global.h"
 #include "headers.h"
 #include "loader.h"
+#include "options.h"
 #include "tables.h"
 #include "mm/boehm.h"
 #include "threads/thread.h"
 #include "toolbox/memory.h"
 
 
-/************************** Function: main *******************************
+/* define cacaoh options ******************************************************/
+
+#define OPT_V         2
+#define OPT_DIRECTORY 3
+
+opt_struct opts[] = {
+       { "v",                true,   OPT_V         },
+       { "d",                true,   OPT_DIRECTORY },
+       { NULL,               false,  0 }
+};
+
+
+/* usage ***********************************************************************
+
+   Obviously prints usage information of cacaoh.
+
+*******************************************************************************/
+
+static void usage()
+{
+       printf("Usage: cacaoh [options] <classes>\n");
+       printf("\n");
+       printf("        -v              verbose\n");
+       printf("        -d <dir>        output directory\n");
+
+       /* exit with error code */
+
+       exit(1);
+}
+
+
+/* main ************************************************************************
 
    Main program.
    
-**************************************************************************/
+*******************************************************************************/
 
 int main(int argc, char **argv)
 {
-       s4 i,a;
+       s4 i, a;
        char *cp;
        classinfo *c;
-               
+       bool opt_v;
+       char *opt_directory;
 
        /********** internal (only used by main) *****************************/
    
@@ -71,10 +104,8 @@ int main(int argc, char **argv)
 
        /************ Collect some info from the environment *****************/
 
-       if (argc < 2) {
-               printf("Usage: cacaoh class [class..]\n");
-               exit(1);
-       }
+       if (argc < 2)
+               usage();
 
        cp = getenv("CLASSPATH");
        if (cp) {
@@ -82,11 +113,36 @@ int main(int argc, char **argv)
                strcpy(classpath + strlen(classpath), cp);
        }
 
+       /* initialize options with default values */
+
+       opt_v = false;
+       opt_directory = NULL;
+
+       while ((i = get_opt(argc, argv, opts)) != OPT_DONE) {
+               switch (i) {
+               case OPT_IGNORE:
+                       break;
+
+               case OPT_V:
+                       opt_v = true;
+                       break;
 
+               case OPT_DIRECTORY:
+                       opt_directory = MNEW(char, strlen(opt_arg));
+                       strcpy(opt_directory, opt_arg);
+                       break;
+
+               default:
+                       usage();
+               }
+       }
+                       
        /**************************** Program start **************************/
 
-       log_init(NULL);
-       log_text("Java - header-generator started"); 
+       if (opt_v) {
+               log_init(NULL);
+               log_text("Java - header-generator started"); 
+       }
        
        /* initialize the garbage collector */
        gc_init(heapmaxsize, heapstartsize);
@@ -110,7 +166,7 @@ int main(int argc, char **argv)
        nativemethod_chain = chain_new();
        nativeclass_chain = chain_new();
        
-       for (a = 1; a < argc; a++) {
+       for (a = opt_ind; a < argc; a++) {
                cp = argv[a];
 
                /* convert classname */
@@ -128,7 +184,7 @@ int main(int argc, char **argv)
                class_load(c);
                class_link(c);
 
-               headerfile_generate(c);
+               headerfile_generate(c, opt_directory);
        }
 
        /************************ Release all resources **********************/
@@ -138,9 +194,11 @@ int main(int argc, char **argv)
 
        /* Print "finished" message */
 
-       log_text("Java - header-generator stopped");
-       log_cputime();
-       mem_usagelog(1);
+       if (opt_v) {
+               log_text("Java - header-generator stopped");
+               log_cputime();
+               mem_usagelog(1);
+       }
        
        return 0;
 }
index e7ebadb782cd400aef7c9b911702392b08295398..3bb7609678f5bdbac5cbd5fcdc0b6a1664664f47 100644 (file)
--- a/headers.c
+++ b/headers.c
@@ -30,7 +30,7 @@
             Philipp Tomsich
             Christian Thalinger
 
-   $Id: headers.c 1492 2004-11-12 13:26:03Z twisti $
+   $Id: headers.c 1529 2004-11-17 17:19:14Z twisti $
 
 */
 
@@ -407,7 +407,7 @@ void gen_header_filename(char *buffer, utf *u)
 
 /* create headerfile for classes and store native methods in chain ************/
 
-void headerfile_generate(classinfo *c)
+void headerfile_generate(classinfo *c, char *opt_directory)
 {
        char header_filename[1024] = "";
        char classname[1024]; 
@@ -427,9 +427,16 @@ void headerfile_generate(classinfo *c)
        /* create chain for renaming fields */
        ident_chain = chain_new();
        
-       sprintf(header_filename, "nat/%s.h", classname);
+       if (opt_directory) {
+               sprintf(header_filename, "%s/%s.h", opt_directory, classname);
+
+       } else {
+               sprintf(header_filename, "%s.h", classname);
+       }
+
        file = fopen(header_filename, "w");
-       if (!file) panic("Can not open file to store header information");
+       if (!file)
+               panic("Can not open file to store header information");
 
        fprintf(file, "/* This file is machine generated, don't edit it !*/\n\n");
 
index 9964fe8a1d49702d192bda9a40c2207c1ae9057a..d3426dc345f2797b4524a81cdda52c0453e2c3ad 100644 (file)
--- a/headers.h
+++ b/headers.h
@@ -26,7 +26,7 @@
 
    Authors: Christian Thalinger
 
-   $Id: headers.h 1243 2004-06-30 20:12:42Z twisti $
+   $Id: headers.h 1529 2004-11-17 17:19:14Z twisti $
 
 */
 
@@ -50,7 +50,7 @@ void literalstring_free(java_objectheader *o);
 void printmethod(methodinfo *m);
 void gen_header_filename(char *buffer, utf *u);
 void printnativetableentry(methodinfo *m);
-void headerfile_generate(classinfo *c);
+void headerfile_generate(classinfo *c, char *opt_directory);
 
 #endif /* _HEADERS_H */
 
diff --git a/main.c b/main.c
index 20e7d8f0909c7aa2e8357ede388b46ed9a6f6f05..e9302bd400f0706f4768e4b8c94d9fdd2375e614 100644 (file)
--- a/main.c
+++ b/main.c
@@ -37,7 +37,7 @@
      - Calling the class loader
      - Running the main method
 
-   $Id: main.c 1505 2004-11-14 14:15:58Z jowenn $
+   $Id: main.c 1529 2004-11-17 17:19:14Z twisti $
 
 */
 
@@ -81,15 +81,7 @@ void **stackbottom = 0;
 #endif
 
 
-/* internal function: get_opt *************************************************
-       
-       decodes the next command line option
-       
-******************************************************************************/
-
-#define OPT_DONE       -1
-#define OPT_ERROR       0
-#define OPT_IGNORE      1
+/* define command line options ************************************************/
 
 #define OPT_CLASSPATH   2
 #define OPT_D           3
@@ -122,7 +114,7 @@ void **stackbottom = 0;
 #define OPT_EAGER            33
 
 
-struct {char *name; bool arg; int value;} opts[] = {
+opt_struct opts[] = {
        {"classpath",        true,   OPT_CLASSPATH},
        {"cp",               true,   OPT_CLASSPATH},
        {"D",                true,   OPT_D},
@@ -165,53 +157,6 @@ struct {char *name; bool arg; int value;} opts[] = {
        {NULL,               false,  0}
 };
 
-static int opt_ind = 1;
-static char *opt_arg;
-
-
-static int get_opt(int argc, char **argv)
-{
-       char *a;
-       int i;
-       
-       if (opt_ind >= argc) return OPT_DONE;
-       
-       a = argv[opt_ind];
-       if (a[0] != '-') return OPT_DONE;
-
-       for (i = 0; opts[i].name; i++) {
-               if (!opts[i].arg) {
-                       if (strcmp(a + 1, opts[i].name) == 0) { /* boolean option found */
-                               opt_ind++;
-                               return opts[i].value;
-                       }
-
-               } else {
-                       if (strcmp(a + 1, opts[i].name) == 0) { /* parameter option found */
-                               opt_ind++;
-                               if (opt_ind < argc) {
-                                       opt_arg = argv[opt_ind];
-                                       opt_ind++;
-                                       return opts[i].value;
-                               }
-                               return OPT_ERROR;
-
-                       } else {
-                               size_t l = strlen(opts[i].name);
-                               if (strlen(a + 1) > l) {
-                                       if (memcmp(a + 1, opts[i].name, l) == 0) {
-                                               opt_ind++;
-                                               opt_arg = a + 1 + l;
-                                               return opts[i].value;
-                                       }
-                               }
-                       }
-               }
-       } /* end for */ 
-
-       return OPT_ERROR;
-}
-
 
 /******************** interne Function: print_usage ************************
 
@@ -219,7 +164,7 @@ Prints the correct usage syntax to stdout.
 
 ***************************************************************************/
 
-static void print_usage()
+static void usage()
 {
        printf("USAGE: cacao [options] classname [program arguments]\n");
        printf("Options:\n");
@@ -270,6 +215,10 @@ static void print_usage()
        printf("          -rt .................. use rapid type analysis\n");
        printf("          -xta ................. use x type analysis\n");
        printf("          -vta ................. use variable type analysis\n");
+
+       /* exit with error code */
+
+       exit(1);
 }   
 
 
@@ -371,9 +320,10 @@ int main(int argc, char **argv)
        checknull = false;
        opt_noieee = false;
 
-       while ((i = get_opt(argc, argv)) != OPT_DONE) {
+       while ((i = get_opt(argc, argv, opts)) != OPT_DONE) {
                switch (i) {
-               case OPT_IGNORE: break;
+               case OPT_IGNORE:
+                       break;
                        
                case OPT_CLASSPATH:
                        /* forget old classpath and set the argument as new classpath */
@@ -394,8 +344,7 @@ int main(int argc, char **argv)
                                                goto didit;
                                        }
                                }
-                               print_usage();
-                               exit(10);
+                               usage();
                                        
                        didit: ;
                        }       
@@ -489,8 +438,7 @@ int main(int argc, char **argv)
                                        checksync = false;
                                        break;
                                default:
-                                       print_usage();
-                                       exit(10);
+                                       usage();
                                }
                        }
                        break;
@@ -544,8 +492,7 @@ int main(int argc, char **argv)
                                        showutf = true;
                                        break;
                                default:
-                                       print_usage();
-                                       exit(10);
+                                       usage();
                                }
                        }
                        break;
@@ -580,8 +527,7 @@ int main(int argc, char **argv)
                                        inlineoutsiders = true;
                                        break;
                                default:
-                                       print_usage();
-                                       exit(10);
+                                       usage();
                                }
                        }
                        break;
@@ -599,15 +545,12 @@ int main(int argc, char **argv)
                        break;
 
                default:
-                       print_usage();
-                       exit(10);
+                       usage();
                }
        }
 
-       if (opt_ind >= argc) {
-               print_usage();
-               exit(10);
-       }
+       if (opt_ind >= argc)
+               usage();
 
        mainstring = argv[opt_ind++];
        for (i = strlen(mainstring) - 1; i >= 0; i--) {     /* Transform dots into slashes */
index c8f1b9ff8820f2edc06a64f4c15daa0c24648f6a..6c2d93a9931e3010c6e5255d3f5a3b2979e6c83a 100644 (file)
--- a/options.c
+++ b/options.c
 
    Authors: Christian Thalinger
 
-   $Id: options.c 1474 2004-11-11 10:09:10Z carolyn $
+   $Id: options.c 1529 2004-11-17 17:19:14Z twisti $
 
 */
 
 
-#include "global.h"
+#include <string.h>
+#include "options.h"
+#include "types.h"
 
 
 /* command line option */
@@ -88,6 +90,62 @@ bool opt_verify = true;        /* true if classfiles should be verified      */
 bool opt_eager = false;
 
 
+int opt_ind = 1;               /* index of processed arguments               */
+char *opt_arg;                 /* this one exports the option argument       */
+
+
+/* get_opt *********************************************************************
+
+   DOCUMENT ME!!!
+
+*******************************************************************************/
+
+int get_opt(int argc, char **argv, opt_struct *opts)
+{
+       char *a;
+       int i;
+       
+       if (opt_ind >= argc)
+               return OPT_DONE;
+       
+       a = argv[opt_ind];
+       if (a[0] != '-')
+               return OPT_DONE;
+
+       for (i = 0; opts[i].name; i++) {
+               if (!opts[i].arg) {
+                       if (strcmp(a + 1, opts[i].name) == 0) { /* boolean option found */
+                               opt_ind++;
+                               return opts[i].value;
+                       }
+
+               } else {
+                       if (strcmp(a + 1, opts[i].name) == 0) { /* parameter option found */
+                               opt_ind++;
+                               if (opt_ind < argc) {
+                                       opt_arg = argv[opt_ind];
+                                       opt_ind++;
+                                       return opts[i].value;
+                               }
+                               return OPT_ERROR;
+
+                       } else {
+                               size_t l = strlen(opts[i].name);
+                               if (strlen(a + 1) > l) {
+                                       if (memcmp(a + 1, opts[i].name, l) == 0) {
+                                               opt_ind++;
+                                               opt_arg = a + 1 + l;
+                                               return opts[i].value;
+                                       }
+                               }
+                       }
+               }
+       } /* end for */ 
+
+       return OPT_ERROR;
+}
+
+
 /*
  * These are local overrides for various environment variables in Emacs.
  * Please do not remove this and leave it at the end of the file, where
index b649ee0092a9800c6d6264d794729fa182de4b57..4fa468b3d76e72edda303e0efa97c56b729843c4 100644 (file)
--- a/options.h
+++ b/options.h
@@ -27,7 +27,7 @@
 
    Authors: Christian Thalinger
 
-   $Id: options.h 1474 2004-11-11 10:09:10Z carolyn $
+   $Id: options.h 1529 2004-11-17 17:19:14Z twisti $
 
 */
 
 #include "global.h"
 
 
-/* global variables */
+/* reserved option numbers ****************************************************/
+
+#define OPT_DONE       -1
+#define OPT_ERROR       0
+#define OPT_IGNORE      1
+
+
+typedef struct opt_struct opt_struct;
+
+struct opt_struct {
+       char *name;
+       bool  arg;
+       int   value;
+};
+
+
+/* global variables ***********************************************************/
 
 extern bool compileall;
 extern bool verbose;
@@ -95,6 +111,14 @@ extern bool opt_stat;
 extern bool opt_verify;
 extern bool opt_eager;
 
+extern int opt_ind;
+extern char *opt_arg;
+
+
+/* function prototypes ********************************************************/
+
+int get_opt(int argc, char **argv, opt_struct *opts);
+
 #endif /* _OPTIONS_H */
 
 
index e7db2d6af9125f74635a5f4b20331507bcca37d1..f7be0ffe9bf6ffa071f75cc302336f6eadc81c0b 100644 (file)
@@ -37,7 +37,7 @@
      - Calling the class loader
      - Running the main method
 
-   $Id: cacao.c 1505 2004-11-14 14:15:58Z jowenn $
+   $Id: cacao.c 1529 2004-11-17 17:19:14Z twisti $
 
 */
 
@@ -81,15 +81,7 @@ void **stackbottom = 0;
 #endif
 
 
-/* internal function: get_opt *************************************************
-       
-       decodes the next command line option
-       
-******************************************************************************/
-
-#define OPT_DONE       -1
-#define OPT_ERROR       0
-#define OPT_IGNORE      1
+/* define command line options ************************************************/
 
 #define OPT_CLASSPATH   2
 #define OPT_D           3
@@ -122,7 +114,7 @@ void **stackbottom = 0;
 #define OPT_EAGER            33
 
 
-struct {char *name; bool arg; int value;} opts[] = {
+opt_struct opts[] = {
        {"classpath",        true,   OPT_CLASSPATH},
        {"cp",               true,   OPT_CLASSPATH},
        {"D",                true,   OPT_D},
@@ -165,53 +157,6 @@ struct {char *name; bool arg; int value;} opts[] = {
        {NULL,               false,  0}
 };
 
-static int opt_ind = 1;
-static char *opt_arg;
-
-
-static int get_opt(int argc, char **argv)
-{
-       char *a;
-       int i;
-       
-       if (opt_ind >= argc) return OPT_DONE;
-       
-       a = argv[opt_ind];
-       if (a[0] != '-') return OPT_DONE;
-
-       for (i = 0; opts[i].name; i++) {
-               if (!opts[i].arg) {
-                       if (strcmp(a + 1, opts[i].name) == 0) { /* boolean option found */
-                               opt_ind++;
-                               return opts[i].value;
-                       }
-
-               } else {
-                       if (strcmp(a + 1, opts[i].name) == 0) { /* parameter option found */
-                               opt_ind++;
-                               if (opt_ind < argc) {
-                                       opt_arg = argv[opt_ind];
-                                       opt_ind++;
-                                       return opts[i].value;
-                               }
-                               return OPT_ERROR;
-
-                       } else {
-                               size_t l = strlen(opts[i].name);
-                               if (strlen(a + 1) > l) {
-                                       if (memcmp(a + 1, opts[i].name, l) == 0) {
-                                               opt_ind++;
-                                               opt_arg = a + 1 + l;
-                                               return opts[i].value;
-                                       }
-                               }
-                       }
-               }
-       } /* end for */ 
-
-       return OPT_ERROR;
-}
-
 
 /******************** interne Function: print_usage ************************
 
@@ -219,7 +164,7 @@ Prints the correct usage syntax to stdout.
 
 ***************************************************************************/
 
-static void print_usage()
+static void usage()
 {
        printf("USAGE: cacao [options] classname [program arguments]\n");
        printf("Options:\n");
@@ -270,6 +215,10 @@ static void print_usage()
        printf("          -rt .................. use rapid type analysis\n");
        printf("          -xta ................. use x type analysis\n");
        printf("          -vta ................. use variable type analysis\n");
+
+       /* exit with error code */
+
+       exit(1);
 }   
 
 
@@ -371,9 +320,10 @@ int main(int argc, char **argv)
        checknull = false;
        opt_noieee = false;
 
-       while ((i = get_opt(argc, argv)) != OPT_DONE) {
+       while ((i = get_opt(argc, argv, opts)) != OPT_DONE) {
                switch (i) {
-               case OPT_IGNORE: break;
+               case OPT_IGNORE:
+                       break;
                        
                case OPT_CLASSPATH:
                        /* forget old classpath and set the argument as new classpath */
@@ -394,8 +344,7 @@ int main(int argc, char **argv)
                                                goto didit;
                                        }
                                }
-                               print_usage();
-                               exit(10);
+                               usage();
                                        
                        didit: ;
                        }       
@@ -489,8 +438,7 @@ int main(int argc, char **argv)
                                        checksync = false;
                                        break;
                                default:
-                                       print_usage();
-                                       exit(10);
+                                       usage();
                                }
                        }
                        break;
@@ -544,8 +492,7 @@ int main(int argc, char **argv)
                                        showutf = true;
                                        break;
                                default:
-                                       print_usage();
-                                       exit(10);
+                                       usage();
                                }
                        }
                        break;
@@ -580,8 +527,7 @@ int main(int argc, char **argv)
                                        inlineoutsiders = true;
                                        break;
                                default:
-                                       print_usage();
-                                       exit(10);
+                                       usage();
                                }
                        }
                        break;
@@ -599,15 +545,12 @@ int main(int argc, char **argv)
                        break;
 
                default:
-                       print_usage();
-                       exit(10);
+                       usage();
                }
        }
 
-       if (opt_ind >= argc) {
-               print_usage();
-               exit(10);
-       }
+       if (opt_ind >= argc)
+               usage();
 
        mainstring = argv[opt_ind++];
        for (i = strlen(mainstring) - 1; i >= 0; i--) {     /* Transform dots into slashes */
index c27c6a88470be9b875851239d686604af655c41d..f19066cafc453ae0f8e7dc798568d414c0e7289a 100644 (file)
@@ -30,7 +30,7 @@
             Philipp Tomsich
             Christian Thalinger
 
-   $Id: cacaoh.c 1406 2004-08-17 10:03:55Z twisti $
+   $Id: cacaoh.c 1529 2004-11-17 17:19:14Z twisti $
 
 */
 
@@ -42,6 +42,7 @@
 #include "global.h"
 #include "headers.h"
 #include "loader.h"
+#include "options.h"
 #include "tables.h"
 #include "mm/boehm.h"
 #include "threads/thread.h"
 #include "toolbox/memory.h"
 
 
-/************************** Function: main *******************************
+/* define cacaoh options ******************************************************/
+
+#define OPT_V         2
+#define OPT_DIRECTORY 3
+
+opt_struct opts[] = {
+       { "v",                true,   OPT_V         },
+       { "d",                true,   OPT_DIRECTORY },
+       { NULL,               false,  0 }
+};
+
+
+/* usage ***********************************************************************
+
+   Obviously prints usage information of cacaoh.
+
+*******************************************************************************/
+
+static void usage()
+{
+       printf("Usage: cacaoh [options] <classes>\n");
+       printf("\n");
+       printf("        -v              verbose\n");
+       printf("        -d <dir>        output directory\n");
+
+       /* exit with error code */
+
+       exit(1);
+}
+
+
+/* main ************************************************************************
 
    Main program.
    
-**************************************************************************/
+*******************************************************************************/
 
 int main(int argc, char **argv)
 {
-       s4 i,a;
+       s4 i, a;
        char *cp;
        classinfo *c;
-               
+       bool opt_v;
+       char *opt_directory;
 
        /********** internal (only used by main) *****************************/
    
@@ -71,10 +104,8 @@ int main(int argc, char **argv)
 
        /************ Collect some info from the environment *****************/
 
-       if (argc < 2) {
-               printf("Usage: cacaoh class [class..]\n");
-               exit(1);
-       }
+       if (argc < 2)
+               usage();
 
        cp = getenv("CLASSPATH");
        if (cp) {
@@ -82,11 +113,36 @@ int main(int argc, char **argv)
                strcpy(classpath + strlen(classpath), cp);
        }
 
+       /* initialize options with default values */
+
+       opt_v = false;
+       opt_directory = NULL;
+
+       while ((i = get_opt(argc, argv, opts)) != OPT_DONE) {
+               switch (i) {
+               case OPT_IGNORE:
+                       break;
+
+               case OPT_V:
+                       opt_v = true;
+                       break;
 
+               case OPT_DIRECTORY:
+                       opt_directory = MNEW(char, strlen(opt_arg));
+                       strcpy(opt_directory, opt_arg);
+                       break;
+
+               default:
+                       usage();
+               }
+       }
+                       
        /**************************** Program start **************************/
 
-       log_init(NULL);
-       log_text("Java - header-generator started"); 
+       if (opt_v) {
+               log_init(NULL);
+               log_text("Java - header-generator started"); 
+       }
        
        /* initialize the garbage collector */
        gc_init(heapmaxsize, heapstartsize);
@@ -110,7 +166,7 @@ int main(int argc, char **argv)
        nativemethod_chain = chain_new();
        nativeclass_chain = chain_new();
        
-       for (a = 1; a < argc; a++) {
+       for (a = opt_ind; a < argc; a++) {
                cp = argv[a];
 
                /* convert classname */
@@ -128,7 +184,7 @@ int main(int argc, char **argv)
                class_load(c);
                class_link(c);
 
-               headerfile_generate(c);
+               headerfile_generate(c, opt_directory);
        }
 
        /************************ Release all resources **********************/
@@ -138,9 +194,11 @@ int main(int argc, char **argv)
 
        /* Print "finished" message */
 
-       log_text("Java - header-generator stopped");
-       log_cputime();
-       mem_usagelog(1);
+       if (opt_v) {
+               log_text("Java - header-generator stopped");
+               log_cputime();
+               mem_usagelog(1);
+       }
        
        return 0;
 }
index e7ebadb782cd400aef7c9b911702392b08295398..3bb7609678f5bdbac5cbd5fcdc0b6a1664664f47 100644 (file)
@@ -30,7 +30,7 @@
             Philipp Tomsich
             Christian Thalinger
 
-   $Id: headers.c 1492 2004-11-12 13:26:03Z twisti $
+   $Id: headers.c 1529 2004-11-17 17:19:14Z twisti $
 
 */
 
@@ -407,7 +407,7 @@ void gen_header_filename(char *buffer, utf *u)
 
 /* create headerfile for classes and store native methods in chain ************/
 
-void headerfile_generate(classinfo *c)
+void headerfile_generate(classinfo *c, char *opt_directory)
 {
        char header_filename[1024] = "";
        char classname[1024]; 
@@ -427,9 +427,16 @@ void headerfile_generate(classinfo *c)
        /* create chain for renaming fields */
        ident_chain = chain_new();
        
-       sprintf(header_filename, "nat/%s.h", classname);
+       if (opt_directory) {
+               sprintf(header_filename, "%s/%s.h", opt_directory, classname);
+
+       } else {
+               sprintf(header_filename, "%s.h", classname);
+       }
+
        file = fopen(header_filename, "w");
-       if (!file) panic("Can not open file to store header information");
+       if (!file)
+               panic("Can not open file to store header information");
 
        fprintf(file, "/* This file is machine generated, don't edit it !*/\n\n");
 
index 9964fe8a1d49702d192bda9a40c2207c1ae9057a..d3426dc345f2797b4524a81cdda52c0453e2c3ad 100644 (file)
@@ -26,7 +26,7 @@
 
    Authors: Christian Thalinger
 
-   $Id: headers.h 1243 2004-06-30 20:12:42Z twisti $
+   $Id: headers.h 1529 2004-11-17 17:19:14Z twisti $
 
 */
 
@@ -50,7 +50,7 @@ void literalstring_free(java_objectheader *o);
 void printmethod(methodinfo *m);
 void gen_header_filename(char *buffer, utf *u);
 void printnativetableentry(methodinfo *m);
-void headerfile_generate(classinfo *c);
+void headerfile_generate(classinfo *c, char *opt_directory);
 
 #endif /* _HEADERS_H */
 
index c8f1b9ff8820f2edc06a64f4c15daa0c24648f6a..6c2d93a9931e3010c6e5255d3f5a3b2979e6c83a 100644 (file)
 
    Authors: Christian Thalinger
 
-   $Id: options.c 1474 2004-11-11 10:09:10Z carolyn $
+   $Id: options.c 1529 2004-11-17 17:19:14Z twisti $
 
 */
 
 
-#include "global.h"
+#include <string.h>
+#include "options.h"
+#include "types.h"
 
 
 /* command line option */
@@ -88,6 +90,62 @@ bool opt_verify = true;        /* true if classfiles should be verified      */
 bool opt_eager = false;
 
 
+int opt_ind = 1;               /* index of processed arguments               */
+char *opt_arg;                 /* this one exports the option argument       */
+
+
+/* get_opt *********************************************************************
+
+   DOCUMENT ME!!!
+
+*******************************************************************************/
+
+int get_opt(int argc, char **argv, opt_struct *opts)
+{
+       char *a;
+       int i;
+       
+       if (opt_ind >= argc)
+               return OPT_DONE;
+       
+       a = argv[opt_ind];
+       if (a[0] != '-')
+               return OPT_DONE;
+
+       for (i = 0; opts[i].name; i++) {
+               if (!opts[i].arg) {
+                       if (strcmp(a + 1, opts[i].name) == 0) { /* boolean option found */
+                               opt_ind++;
+                               return opts[i].value;
+                       }
+
+               } else {
+                       if (strcmp(a + 1, opts[i].name) == 0) { /* parameter option found */
+                               opt_ind++;
+                               if (opt_ind < argc) {
+                                       opt_arg = argv[opt_ind];
+                                       opt_ind++;
+                                       return opts[i].value;
+                               }
+                               return OPT_ERROR;
+
+                       } else {
+                               size_t l = strlen(opts[i].name);
+                               if (strlen(a + 1) > l) {
+                                       if (memcmp(a + 1, opts[i].name, l) == 0) {
+                                               opt_ind++;
+                                               opt_arg = a + 1 + l;
+                                               return opts[i].value;
+                                       }
+                               }
+                       }
+               }
+       } /* end for */ 
+
+       return OPT_ERROR;
+}
+
+
 /*
  * These are local overrides for various environment variables in Emacs.
  * Please do not remove this and leave it at the end of the file, where
index b649ee0092a9800c6d6264d794729fa182de4b57..4fa468b3d76e72edda303e0efa97c56b729843c4 100644 (file)
@@ -27,7 +27,7 @@
 
    Authors: Christian Thalinger
 
-   $Id: options.h 1474 2004-11-11 10:09:10Z carolyn $
+   $Id: options.h 1529 2004-11-17 17:19:14Z twisti $
 
 */
 
 #include "global.h"
 
 
-/* global variables */
+/* reserved option numbers ****************************************************/
+
+#define OPT_DONE       -1
+#define OPT_ERROR       0
+#define OPT_IGNORE      1
+
+
+typedef struct opt_struct opt_struct;
+
+struct opt_struct {
+       char *name;
+       bool  arg;
+       int   value;
+};
+
+
+/* global variables ***********************************************************/
 
 extern bool compileall;
 extern bool verbose;
@@ -95,6 +111,14 @@ extern bool opt_stat;
 extern bool opt_verify;
 extern bool opt_eager;
 
+extern int opt_ind;
+extern char *opt_arg;
+
+
+/* function prototypes ********************************************************/
+
+int get_opt(int argc, char **argv, opt_struct *opts);
+
 #endif /* _OPTIONS_H */