OSDN Git Service

2003-04-16 Jonathan Wakely <redi@gcc.gnu.org>
[pf3gnuchains/gcc-fork.git] / libjava / gij.cc
1 /* Copyright (C) 1999, 2000, 2001, 2002  Free Software Foundation
2
3    This file is part of libgcj.
4
5 This software is copyrighted work licensed under the terms of the
6 Libgcj License.  Please consult the file "LIBGCJ_LICENSE" for
7 details.  */
8
9 /* Author: Kresten Krab Thorup <krab@gnu.org>  */
10
11 #include <config.h>
12
13 #include <jvm.h>
14 #include <gcj/cni.h>
15 #include <java-props.h>
16
17 #include <stdio.h>
18 #include <string.h>
19 #include <stdlib.h>
20
21 #include <java/lang/System.h>
22 #include <java/util/Properties.h>
23
24 static void
25 help ()
26 {
27   printf ("Usage: gij [OPTION] ... CLASS [ARGS] ...\n");
28   printf ("          to interpret Java bytecodes, or\n");
29   printf ("       gij -jar [OPTION] ... JARFILE [ARGS] ...\n");
30   printf ("          to execute a jar file\n\n");
31   printf ("  --cp LIST         set class path\n");
32   printf ("  --classpath LIST  set class path\n");
33   printf ("  -DVAR=VAL         define property VAR with value VAL\n");
34   printf ("  --help            print this help, then exit\n");
35   printf ("  --ms=NUMBER       set initial heap size\n");
36   printf ("  --mx=NUMBER       set maximum heap size\n");
37   printf ("  --showversion     print version number, then keep going\n");
38   printf ("  --version         print version number, then exit\n");
39   printf ("\nOptions can be specified with `-' or `--'.\n");
40   printf ("\nSee http://gcc.gnu.org/java/ for information on reporting bugs\n");
41   exit (0);
42 }
43
44 static void
45 version ()
46 {
47   printf ("gij (GNU libgcj) version %s\n\n", __VERSION__);
48   printf ("Copyright (C) 2002 Free Software Foundation, Inc.\n");
49   printf ("This is free software; see the source for copying conditions.  There is NO\n");
50   printf ("warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n");
51 }
52
53 int
54 main (int argc, const char **argv)
55 {
56   /* We rearrange ARGV so that all the -D options appear near the
57      beginning.  */
58   int last_D_option = 0;
59   bool jar_mode = false;
60
61   int i;
62   for (i = 1; i < argc; ++i)
63     {
64       const char *arg = argv[i];
65
66       /* A non-option stops processing.  */
67       if (arg[0] != '-')
68         break;
69       /* A "--" stops processing.  */
70       if (! strcmp (arg, "--"))
71         {
72           ++i;
73           break;
74         }
75
76       if (! strncmp (arg, "-D", 2))
77         {
78           argv[last_D_option++] = arg + 2;
79           continue;
80         }
81
82       if (! strcmp (arg, "-jar"))
83         {
84           jar_mode = true;
85           continue;
86         }
87
88       /* Allow both single or double hyphen for all remaining
89          options.  */
90       if (arg[1] == '-')
91         ++arg;
92
93       if (! strcmp (arg, "-help"))
94         help ();
95       else if (! strcmp (arg, "-version"))
96         {
97           version ();
98           exit (0);
99         }
100       else if (! strcmp (arg, "-showversion"))
101         version ();
102       /* FIXME: use getopt and avoid the ugliness here.
103          We at least need to handle the argument in a better way.  */
104       else if (! strncmp (arg, "-ms=", 4))
105         _Jv_SetInitialHeapSize (arg + 4);
106       else if (! strcmp (arg, "-ms"))
107         {
108           if (i >= argc - 1)
109             {
110             no_arg:
111               fprintf (stderr, "gij: option requires an argument -- `%s'\n",
112                        argv[i]);
113               fprintf (stderr, "Try `gij --help' for more information.\n");
114               exit (1);
115             }
116           _Jv_SetInitialHeapSize (argv[++i]);
117         }
118       else if (! strncmp (arg, "-mx=", 4))
119         _Jv_SetMaximumHeapSize (arg + 4);
120       else if (! strcmp (arg, "-mx"))
121         {
122           if (i >= argc - 1)
123             goto no_arg;
124           _Jv_SetMaximumHeapSize (argv[++i]);
125         }
126       else if (! strcmp (arg, "-cp") || ! strcmp (arg, "-classpath"))
127         {
128           if (i >= argc - 1)
129             goto no_arg;
130           // We set _Jv_Jar_Class_Path.  If the user specified `-jar'
131           // then the jar code will override this.  This is the
132           // correct behavior.
133           _Jv_Jar_Class_Path = argv[++i];
134         }
135       else
136         {
137           fprintf (stderr, "gij: unrecognized option -- `%s'\n", argv[i]);
138           fprintf (stderr, "Try `gij --help' for more information.\n");
139           exit (1);
140         }
141     }
142
143   argv[last_D_option] = NULL;
144   _Jv_Compiler_Properties = argv;
145
146   if (argc - i < 1)
147     {
148       fprintf (stderr, "Usage: gij [OPTION] ... CLASS [ARGS] ...\n");
149       fprintf (stderr, "          to invoke CLASS.main, or\n");
150       fprintf (stderr, "       gij -jar [OPTION] ... JARFILE [ARGS] ...\n");
151       fprintf (stderr, "          to execute a jar file\n");
152       fprintf (stderr, "Try `gij --help' for more information.\n");
153       exit (1);
154     }
155
156   _Jv_RunMain (NULL, argv[i], argc - i, argv + i, jar_mode);
157 }