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