aboutsummaryrefslogtreecommitdiff
path: root/libjava/gij.cc
blob: 64457857a1321e52b65546a0ee884ac7834a71d9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
/* Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004  Free Software Foundation

   This file is part of libgcj.

This software is copyrighted work licensed under the terms of the
Libgcj License.  Please consult the file "LIBGCJ_LICENSE" for
details.  */

/* Author: Kresten Krab Thorup <krab@gnu.org>  */

#include <config.h>

#include <jvm.h>
#include <gcj/cni.h>
#include <java-props.h>

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

#include <java/lang/System.h>
#include <java/util/Properties.h>

static void
help ()
{
  printf ("Usage: gij [OPTION] ... CLASS [ARGS] ...\n");
  printf ("          to interpret Java bytecodes, or\n");
  printf ("       gij -jar [OPTION] ... JARFILE [ARGS] ...\n");
  printf ("          to execute a jar file\n\n");
  printf ("  --cp LIST         set class path\n");
  printf ("  --classpath LIST  set class path\n");
  printf ("  -DVAR=VAL         define property VAR with value VAL\n");
  printf ("  -?, --help        print this help, then exit\n");
  printf ("  -X                print help on supported -X options, then exit\n");
  printf ("  --ms=NUMBER       set initial heap size\n");
  printf ("  --mx=NUMBER       set maximum heap size\n");
  printf ("  --verbose[:class] print information about class loading\n");
  printf ("  --showversion     print version number, then keep going\n");
  printf ("  --version         print version number, then exit\n");
  printf ("\nOptions can be specified with `-' or `--'.\n");
  printf ("\nSee http://gcc.gnu.org/java/ for information on reporting bugs\n");
  exit (0);
}

static void
version ()
{
  printf ("gij (GNU libgcj) version %s\n\n", __VERSION__);
  printf ("Copyright (C) 2002 Free Software Foundation, Inc.\n");
  printf ("This is free software; see the source for copying conditions.  There is NO\n");
  printf ("warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n");
}

int
main (int argc, const char **argv)
{
  /* We rearrange ARGV so that all the -D options appear near the
     beginning.  */
  int last_D_option = 0;
  bool jar_mode = false;

  int i;
  for (i = 1; i < argc; ++i)
    {
      const char *arg = argv[i];

      /* A non-option stops processing.  */
      if (arg[0] != '-')
	break;
      /* A "--" stops processing.  */
      if (! strcmp (arg, "--"))
	{
	  ++i;
	  break;
	}

      if (! strncmp (arg, "-D", 2))
	{
	  argv[last_D_option++] = arg + 2;
	  continue;
	}

      if (! strcmp (arg, "-jar"))
	{
	  jar_mode = true;
	  continue;
	}

      /* Allow both single or double hyphen for all remaining
	 options.  */
      if (arg[1] == '-')
	++arg;

      if (! strcmp (arg, "-help") || ! strcmp (arg, "-?"))
	help ();
      else if (! strcmp (arg, "-version"))
	{
	  version ();
	  exit (0);
	}
      else if (! strcmp (arg, "-showversion"))
	version ();
      /* FIXME: use getopt and avoid the ugliness here.
	 We at least need to handle the argument in a better way.  */
      else if (! strncmp (arg, "-ms=", 4))
	_Jv_SetInitialHeapSize (arg + 4);
      else if (! strcmp (arg, "-ms"))
	{
	  if (i >= argc - 1)
	    {
	    no_arg:
	      fprintf (stderr, "gij: option requires an argument -- `%s'\n",
		       argv[i]);
	      fprintf (stderr, "Try `gij --help' for more information.\n");
	      exit (1);
	    }
	  _Jv_SetInitialHeapSize (argv[++i]);
	}
      else if (! strncmp (arg, "-mx=", 4))
	_Jv_SetMaximumHeapSize (arg + 4);
      else if (! strcmp (arg, "-mx"))
	{
	  if (i >= argc - 1)
	    goto no_arg;
	  _Jv_SetMaximumHeapSize (argv[++i]);
	}
      else if (! strcmp (arg, "-cp") || ! strcmp (arg, "-classpath"))
	{
	  if (i >= argc - 1)
	    goto no_arg;
	  // We set _Jv_Jar_Class_Path.  If the user specified `-jar'
	  // then the jar code will override this.  This is the
	  // correct behavior.
	  _Jv_Jar_Class_Path = argv[++i];
	}
      else if (! strcmp (arg, "-verbose") || ! strcmp (arg, "-verbose:class"))
	gcj::verbose_class_flag = true;
      else if (arg[1] == 'X')
	{
	  if (arg[2] == '\0')
	    {
	      printf ("gij: currently no -X options are recognized\n");
	      exit (0);
	    }
	  /* Ignore other -X options.  */
	}
      else
	{
	  fprintf (stderr, "gij: unrecognized option -- `%s'\n", argv[i]);
	  fprintf (stderr, "Try `gij --help' for more information.\n");
	  exit (1);
	}
    }

  argv[last_D_option] = NULL;
  _Jv_Compiler_Properties = argv;

  if (argc - i < 1)
    {
      fprintf (stderr, "Usage: gij [OPTION] ... CLASS [ARGS] ...\n");
      fprintf (stderr, "          to invoke CLASS.main, or\n");
      fprintf (stderr, "       gij -jar [OPTION] ... JARFILE [ARGS] ...\n");
      fprintf (stderr, "          to execute a jar file\n");
      fprintf (stderr, "Try `gij --help' for more information.\n");
      exit (1);
    }

  _Jv_RunMain (NULL, argv[i], argc - i, argv + i, jar_mode);
}