summaryrefslogtreecommitdiff
path: root/gcc/java/jvgenmain.c
diff options
context:
space:
mode:
authortromey <tromey@138bc75d-0d04-0410-961f-82ee72b054a4>1999-10-15 16:45:31 +0000
committertromey <tromey@138bc75d-0d04-0410-961f-82ee72b054a4>1999-10-15 16:45:31 +0000
commitd25efa9c2efb1fea23f948c1b8d682e1021fde7e (patch)
tree1bcb57fa5b0f05e8d67699b59b7d8b9928c4b89a /gcc/java/jvgenmain.c
parentcd75cb43fc02da5db9db71316dd7839bcd656ff4 (diff)
downloadgcc-d25efa9c2efb1fea23f948c1b8d682e1021fde7e.tar.gz
* jvgenmain.c (usage): New function.
(main): Use it. Also, handle `-D' options. * jvspec.c (lang_specific_driver): Recognize -D. (jvgenmain_spec): Added `%{D*}' to jvgenmain invocation. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@30019 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/java/jvgenmain.c')
-rw-r--r--gcc/java/jvgenmain.c58
1 files changed, 49 insertions, 9 deletions
diff --git a/gcc/java/jvgenmain.c b/gcc/java/jvgenmain.c
index 07044848def..86040fcba3f 100644
--- a/gcc/java/jvgenmain.c
+++ b/gcc/java/jvgenmain.c
@@ -1,5 +1,5 @@
/* Program to generate "main" a Java(TM) class containing a main method.
- Copyright (C) 1998 Free Software Foundation, Inc.
+ Copyright (C) 1998, 1999 Free Software Foundation, Inc.
This file is part of GNU CC.
@@ -79,39 +79,79 @@ gcc_obstack_init (obstack)
(void (*) PROTO((void *))) OBSTACK_CHUNK_FREE);
}
+static void
+usage (const char *name)
+{
+ fprintf (stderr, "Usage: %s [OPTIONS]... CLASSNAME [OUTFILE]\n", name);
+ exit (1);
+}
+
int
main (int argc, const char **argv)
{
const char *classname;
FILE *stream;
const char *mangled_classname;
+ int i, last_arg;
+
+ if (argc < 2)
+ usage (argv[0]);
- if (argc < 2 || argc > 3)
+ for (i = 1; i < argc; ++i)
{
- fprintf (stderr, "Usage: %s CLASSNAME [OUTFILE]\n", argv[0]);
- exit(-1);
+ if (! strncmp (argv[i], "-D", 2))
+ {
+ /* Handled later. */
+ }
+ else
+ break;
}
- classname = argv[1];
+ if (i < argc - 2 || i == argc)
+ usage (argv[0]);
+ last_arg = i;
+
+ classname = argv[i];
gcc_obstack_init (&name_obstack);
append_gpp_mangled_classtype (&name_obstack, classname);
obstack_1grow (&name_obstack, '\0');
mangled_classname = obstack_finish (&name_obstack);
- if (argc > 2 && strcmp (argv[2], "-") != 0)
+ if (i < argc - 1 && strcmp (argv[i + 1], "-") != 0)
{
- const char *outfile = argv[2];
+ const char *outfile = argv[i + 1];
stream = fopen (outfile, "w");
if (stream == NULL)
{
fprintf (stderr, "%s: Cannot open output file: %s\n",
argv[0], outfile);
- exit (-1);
+ exit (1);
}
}
else
stream = stdout;
+
+ /* At this point every element of ARGV from 1 to LAST_ARG is a `-D'
+ option. Process them appropriately. */
+ fprintf (stream, "const char *_Jv_Compiler_Properties[] =\n{\n");
+ for (i = 1; i < last_arg; ++i)
+ {
+ const char *p;
+ fprintf (stream, " \"");
+ for (p = &argv[i][2]; *p; ++p)
+ {
+ if (! isascii (*p))
+ fprintf (stream, "\\%o", *p);
+ else if (*p == '\\' || *p == '"')
+ fprintf (stream, "\\%c", *p);
+ else
+ putc (*p, stream);
+ }
+ fprintf (stream, "\",\n");
+ }
+ fprintf (stream, " 0\n};\n\n");
+
fprintf (stream, "extern struct Class %s%s;\n",
class_mangling_prefix, mangled_classname);
fprintf (stream, "int main (int argc, const char **argv)\n");
@@ -123,7 +163,7 @@ main (int argc, const char **argv)
{
fprintf (stderr, "%s: Failed to close output file %s\n",
argv[0], argv[2]);
- exit (-1);
+ exit (1);
}
return 0;
}