Merge from the pain train
[official-gcc.git] / libjava / gij.cc
blob1894d9b9c968c4ecc0b771ec5d1d72d53197e17d
1 /* Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004 Free Software Foundation
3 This file is part of libgcj.
5 This software is copyrighted work licensed under the terms of the
6 Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
7 details. */
9 /* Author: Kresten Krab Thorup <krab@gnu.org> */
11 #include <config.h>
13 #include <jvm.h>
14 #include <gcj/cni.h>
15 #include <java-props.h>
17 #include <stdio.h>
18 #include <string.h>
19 #include <stdlib.h>
21 #include <java/lang/System.h>
22 #include <java/util/Properties.h>
24 static void
25 help ()
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 (" -X print help on supported -X options, then exit\n");
36 printf (" --ms=NUMBER set initial heap size\n");
37 printf (" --mx=NUMBER set maximum heap size\n");
38 printf (" --verbose[:class] print information about class loading\n");
39 printf (" --showversion print version number, then keep going\n");
40 printf (" --version print version number, then exit\n");
41 printf ("\nOptions can be specified with `-' or `--'.\n");
42 printf ("\nSee http://gcc.gnu.org/java/ for information on reporting bugs\n");
43 exit (0);
46 static void
47 version ()
49 printf ("gij (GNU libgcj) version %s\n\n", __VERSION__);
50 printf ("Copyright (C) 2005 Free Software Foundation, Inc.\n");
51 printf ("This is free software; see the source for copying conditions. There is NO\n");
52 printf ("warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n");
55 int
56 main (int argc, const char **argv)
58 /* We rearrange ARGV so that all the -D options appear near the
59 beginning. */
60 int last_D_option = 0;
61 bool jar_mode = false;
63 int i;
64 for (i = 1; i < argc; ++i)
66 const char *arg = argv[i];
68 /* A non-option stops processing. */
69 if (arg[0] != '-')
70 break;
71 /* A "--" stops processing. */
72 if (! strcmp (arg, "--"))
74 ++i;
75 break;
78 if (! strncmp (arg, "-D", 2))
80 argv[last_D_option++] = arg + 2;
81 continue;
84 if (! strcmp (arg, "-jar"))
86 jar_mode = true;
87 continue;
90 /* Allow both single or double hyphen for all remaining
91 options. */
92 if (arg[1] == '-')
93 ++arg;
95 if (! strcmp (arg, "-help") || ! strcmp (arg, "-?"))
96 help ();
97 else if (! strcmp (arg, "-version"))
99 version ();
100 exit (0);
102 else if (! strcmp (arg, "-showversion"))
103 version ();
104 /* FIXME: use getopt and avoid the ugliness here.
105 We at least need to handle the argument in a better way. */
106 else if (! strncmp (arg, "-ms=", 4))
107 _Jv_SetInitialHeapSize (arg + 4);
108 else if (! strcmp (arg, "-ms"))
110 if (i >= argc - 1)
112 no_arg:
113 fprintf (stderr, "gij: option requires an argument -- `%s'\n",
114 argv[i]);
115 fprintf (stderr, "Try `gij --help' for more information.\n");
116 exit (1);
118 _Jv_SetInitialHeapSize (argv[++i]);
120 else if (! strncmp (arg, "-mx=", 4))
121 _Jv_SetMaximumHeapSize (arg + 4);
122 else if (! strcmp (arg, "-mx"))
124 if (i >= argc - 1)
125 goto no_arg;
126 _Jv_SetMaximumHeapSize (argv[++i]);
128 else if (! strcmp (arg, "-cp") || ! strcmp (arg, "-classpath"))
130 if (i >= argc - 1)
131 goto no_arg;
132 // We set _Jv_Jar_Class_Path. If the user specified `-jar'
133 // then the jar code will override this. This is the
134 // correct behavior.
135 _Jv_Jar_Class_Path = argv[++i];
137 else if (! strcmp (arg, "-verbose") || ! strcmp (arg, "-verbose:class"))
138 gcj::verbose_class_flag = true;
139 else if (arg[1] == 'X')
141 if (arg[2] == '\0')
143 printf ("gij: currently no -X options are recognized\n");
144 exit (0);
146 /* Ignore other -X options. */
148 else
150 fprintf (stderr, "gij: unrecognized option -- `%s'\n", argv[i]);
151 fprintf (stderr, "Try `gij --help' for more information.\n");
152 exit (1);
156 argv[last_D_option] = NULL;
157 _Jv_Compiler_Properties = argv;
159 if (argc - i < 1)
161 fprintf (stderr, "Usage: gij [OPTION] ... CLASS [ARGS] ...\n");
162 fprintf (stderr, " to invoke CLASS.main, or\n");
163 fprintf (stderr, " gij -jar [OPTION] ... JARFILE [ARGS] ...\n");
164 fprintf (stderr, " to execute a jar file\n");
165 fprintf (stderr, "Try `gij --help' for more information.\n");
166 exit (1);
169 _Jv_RunMain (NULL, argv[i], argc - i, argv + i, jar_mode);