Commit c89c53eb by Tom Tromey Committed by Tom Tromey

jv-scan.c: Include version.c, <getopt.h>.

	* jv-scan.c: Include version.c, <getopt.h>.
	(LONG_OPT, OPT_HELP, OPT_VERSION): New macros.
	(options): New array.
	(usage): New function.
	(version): New function.
	(main): Use getopt_long to parse command line.
	* jcf-dump.c: Include version.c, <getopt.h>.
	(LONG_OPT, OPT_classpath, OPT_CLASSPATH, OPT_HELP, OPT_VERSION,
	OPT_JAVAP): New macros.
	(options): New array.
	(usage): Return `void'.  Changed message.
	(help): New function.
	(version): New function.
	(main): Use getopt_long_only to parse command line.
	* gjavah.c: Include <getopt.h>.
	(LONG_OPT, OPT_classpath, OPT_CLASSPATH, OPT_HELP, OPT_TEMP,
	OPT_VERSION, OPT_PREPEND, OPT_FRIEND, OPT_ADD, OPT_APPEND, OPT_M,
	OPT_MM, OPT_MG, OPT_MD, OPT_MMD): New macros.
	(options): New array.
	(java_no_argument): Removed.
	(help): Updated with missing options.
	(main): Use getopt_long_only to parse command line.
	(usage): Changed message.

From-SVN: r31765
parent 2e695cbb
2000-02-02 Tom Tromey <tromey@cygnus.com>
* jv-scan.c: Include version.c, <getopt.h>.
(LONG_OPT, OPT_HELP, OPT_VERSION): New macros.
(options): New array.
(usage): New function.
(version): New function.
(main): Use getopt_long to parse command line.
* jcf-dump.c: Include version.c, <getopt.h>.
(LONG_OPT, OPT_classpath, OPT_CLASSPATH, OPT_HELP, OPT_VERSION,
OPT_JAVAP): New macros.
(options): New array.
(usage): Return `void'. Changed message.
(help): New function.
(version): New function.
(main): Use getopt_long_only to parse command line.
* gjavah.c: Include <getopt.h>.
(LONG_OPT, OPT_classpath, OPT_CLASSPATH, OPT_HELP, OPT_TEMP,
OPT_VERSION, OPT_PREPEND, OPT_FRIEND, OPT_ADD, OPT_APPEND, OPT_M,
OPT_MM, OPT_MG, OPT_MD, OPT_MMD): New macros.
(options): New array.
(java_no_argument): Removed.
(help): Updated with missing options.
(main): Use getopt_long_only to parse command line.
(usage): Changed message.
2000-01-30 Anthony Green <green@redhat.com> 2000-01-30 Anthony Green <green@redhat.com>
* jcf-write.c (generate_bytecode_insns): Use TYPE_IS_WIDE to * jcf-write.c (generate_bytecode_insns): Use TYPE_IS_WIDE to
......
...@@ -35,6 +35,10 @@ The Free Software Foundation is independent of Sun Microsystems, Inc. */ ...@@ -35,6 +35,10 @@ The Free Software Foundation is independent of Sun Microsystems, Inc. */
#include "version.c" #include "version.c"
#include <getopt.h>
/* The output file. */ /* The output file. */
FILE *out = NULL; FILE *out = NULL;
...@@ -134,7 +138,6 @@ static const unsigned char *decode_signature_piece ...@@ -134,7 +138,6 @@ static const unsigned char *decode_signature_piece
static void print_class_decls PARAMS ((FILE *, JCF *, int)); static void print_class_decls PARAMS ((FILE *, JCF *, int));
static void usage PARAMS ((void)) ATTRIBUTE_NORETURN; static void usage PARAMS ((void)) ATTRIBUTE_NORETURN;
static void help PARAMS ((void)) ATTRIBUTE_NORETURN; static void help PARAMS ((void)) ATTRIBUTE_NORETURN;
static void java_no_argument PARAMS ((const char *)) ATTRIBUTE_NORETURN;
static void version PARAMS ((void)) ATTRIBUTE_NORETURN; static void version PARAMS ((void)) ATTRIBUTE_NORETURN;
JCF_u2 current_field_name; JCF_u2 current_field_name;
...@@ -161,7 +164,7 @@ static int method_pass; ...@@ -161,7 +164,7 @@ static int method_pass;
if (out && ! stubs) \ if (out && ! stubs) \
print_field_info (out, jcf, current_field_name, \ print_field_info (out, jcf, current_field_name, \
current_field_signature, \ current_field_signature, \
current_field_flags); \ current_field_flags); \
} \ } \
else \ else \
if (! stubs) add_class_decl (out, jcf, current_field_signature); if (! stubs) add_class_decl (out, jcf, current_field_signature);
...@@ -901,7 +904,7 @@ DEFUN(print_full_cxx_name, (stream, jcf, name_index, signature_index, is_init, n ...@@ -901,7 +904,7 @@ DEFUN(print_full_cxx_name, (stream, jcf, name_index, signature_index, is_init, n
fputs (")", stream); fputs (")", stream);
} }
} }
static void static void
DEFUN(print_stub, (stream, jcf, name_index, signature_index, is_init, DEFUN(print_stub, (stream, jcf, name_index, signature_index, is_init,
name_override), name_override),
...@@ -1490,10 +1493,51 @@ DEFUN(process_file, (jcf, out), ...@@ -1490,10 +1493,51 @@ DEFUN(process_file, (jcf, out),
} }
} }
/* This is used to mark options with no short value. */
#define LONG_OPT(Num) ((Num) + 128)
#define OPT_classpath LONG_OPT (0)
#define OPT_CLASSPATH LONG_OPT (1)
#define OPT_HELP LONG_OPT (2)
#define OPT_TEMP LONG_OPT (3)
#define OPT_VERSION LONG_OPT (4)
#define OPT_PREPEND LONG_OPT (5)
#define OPT_FRIEND LONG_OPT (6)
#define OPT_ADD LONG_OPT (7)
#define OPT_APPEND LONG_OPT (8)
#define OPT_M LONG_OPT (9)
#define OPT_MM LONG_OPT (10)
#define OPT_MG LONG_OPT (11)
#define OPT_MD LONG_OPT (12)
#define OPT_MMD LONG_OPT (13)
static struct option options[] =
{
{ "classpath", required_argument, NULL, OPT_classpath },
{ "CLASSPATH", required_argument, NULL, OPT_CLASSPATH },
{ "help", no_argument, NULL, OPT_HELP },
{ "stubs", no_argument, &stubs, 1 },
{ "td", required_argument, NULL, OPT_TEMP },
{ "verbose", no_argument, NULL, 'v' },
{ "version", no_argument, NULL, OPT_VERSION },
{ "prepend", required_argument, NULL, OPT_PREPEND },
{ "friend", required_argument, NULL, OPT_FRIEND },
{ "add", required_argument, NULL, OPT_ADD },
{ "append", required_argument, NULL, OPT_APPEND },
{ "M", no_argument, NULL, OPT_M },
{ "MM", no_argument, NULL, OPT_MM },
{ "MG", no_argument, NULL, OPT_MG },
{ "MD", no_argument, NULL, OPT_MD },
{ "MMD", no_argument, NULL, OPT_MMD },
{ NULL, no_argument, NULL, 0 }
};
static void static void
usage () usage ()
{ {
fprintf (stderr, "gcjh: no classes specified\n"); fprintf (stderr, "Try `gcjh --help' for more information.\n");
exit (1); exit (1);
} }
...@@ -1502,32 +1546,40 @@ help () ...@@ -1502,32 +1546,40 @@ help ()
{ {
printf ("Usage: gcjh [OPTION]... CLASS...\n\n"); printf ("Usage: gcjh [OPTION]... CLASS...\n\n");
printf ("Generate C++ header files from .class files\n\n"); printf ("Generate C++ header files from .class files\n\n");
printf (" -stubs Generate an implementation stub file\n");
printf ("\n");
printf (" -add TEXT Insert TEXT into class body\n");
printf (" -append TEXT Insert TEXT after class declaration\n");
printf (" -friend TEXT Insert TEXT as `friend' declaration\n");
printf (" -prepend TEXT Insert TEXT before start of class\n");
printf ("\n");
printf (" --classpath PATH Set path to find .class files\n"); printf (" --classpath PATH Set path to find .class files\n");
printf (" --CLASSPATH PATH Set path to find .class files\n"); printf (" --CLASSPATH PATH Set path to find .class files\n");
printf (" -IDIR Append directory to class path\n"); printf (" -IDIR Append directory to class path\n");
printf (" -d DIRECTORY Set output directory name\n"); printf (" -d DIRECTORY Set output directory name\n");
printf (" --help Print this help, then exit\n");
printf (" -o FILE Set output file name\n"); printf (" -o FILE Set output file name\n");
printf (" -stubs Generate a C++ implementation stub file\n");
printf (" -td DIRECTORY Set temporary directory name\n"); printf (" -td DIRECTORY Set temporary directory name\n");
printf (" -v, --verbose Print extra information while running\n"); printf ("\n");
printf (" --help Print this help, then exit\n");
printf (" --version Print version number, then exit\n"); printf (" --version Print version number, then exit\n");
/* FIXME: print bug-report information. */ printf (" -v, --verbose Print extra information while running\n");
printf ("\n");
printf (" -M Print all dependencies to stdout;\n");
printf (" suppress ordinary output\n");
printf (" -MM Print non-system dependencies to stdout;\n");
printf (" suppress ordinary output\n");
printf (" -MD Print all dependencies to stdout\n");
printf (" -MMD Print non-system dependencies to stdout\n");
/* We omit -MG until it is implemented. */
printf ("\n");
printf ("For bug reporting instructions, please see:\n");
printf ("<URL:http://www.gnu.org/software/gcc/faq.html#bugreport>.\n");
exit (0); exit (0);
} }
static void static void
java_no_argument (opt)
const char *opt;
{
fprintf (stderr, "gcjh: no argument given for option `%s'\n", opt);
exit (1);
}
static void
version () version ()
{ {
/* FIXME: use version.c? */
printf ("gcjh (%s)\n\n", version_string); printf ("gcjh (%s)\n\n", version_string);
printf ("Copyright (C) 1998, 1999 Free Software Foundation, Inc.\n"); printf ("Copyright (C) 1998, 1999 Free Software Foundation, Inc.\n");
printf ("This is free software; see the source for copying conditions. There is NO\n"); printf ("This is free software; see the source for copying conditions. There is NO\n");
...@@ -1543,148 +1595,123 @@ DEFUN(main, (argc, argv), ...@@ -1543,148 +1595,123 @@ DEFUN(main, (argc, argv),
int argi; int argi;
char *output_file = NULL; char *output_file = NULL;
int emit_dependencies = 0, suppress_output = 0; int emit_dependencies = 0, suppress_output = 0;
int opt;
if (argc <= 1) if (argc <= 1)
usage (); {
fprintf (stderr, "gcjh: no classes specified\n");
usage ();
}
jcf_path_init (); jcf_path_init ();
for (argi = 1; argi < argc; argi++) /* We use getopt_long_only to allow single `-' long options. For
some of our options this is more natural. */
while ((opt = getopt_long_only (argc, argv, "I:d:o:v", options, NULL)) != -1)
{ {
char *arg = argv[argi]; switch (opt)
{
case 0:
/* Already handled. */
break;
if (arg[0] != '-' || ! strcmp (arg, "--")) case 'o':
break; output_file = optarg;
break;
/* Just let all arguments be given in either "-" or "--" form. */ case 'd':
if (arg[1] == '-') output_directory = optarg;
++arg; break;
if (strcmp (arg, "-o") == 0) case 'I':
{ jcf_path_include_arg (optarg);
if (argi + 1 < argc) break;
output_file = argv[++argi];
else case 'v':
java_no_argument (argv[argi]); verbose++;
} break;
else if (strcmp (arg, "-d") == 0)
{ case OPT_classpath:
if (argi + 1 < argc) jcf_path_classpath_arg (optarg);
output_directory = argv[++argi]; break;
else
java_no_argument (argv[argi]); case OPT_CLASSPATH:
} jcf_path_CLASSPATH_arg (optarg);
else if (strcmp (arg, "-td") == 0) break;
{
if (argi + 1 < argc) case OPT_HELP:
temp_directory = argv[++argi]; help ();
else break;
java_no_argument (argv[argi]);
} case OPT_TEMP:
else if (strcmp (arg, "-prepend") == 0) temp_directory = optarg;
{ break;
if (argi + 1 < argc)
{ case OPT_VERSION:
if (prepend_count == 0) version ();
prepend_specs = (char**) ALLOC ((argc-argi) * sizeof (char*)); break;
prepend_specs[prepend_count++] = argv[++argi];
} case OPT_PREPEND:
else if (prepend_count == 0)
java_no_argument (argv[argi]); prepend_specs = (char**) ALLOC (argc * sizeof (char*));
} prepend_specs[prepend_count++] = optarg;
else if (strcmp (arg, "-friend") == 0) break;
{
if (argi + 1 < argc) case OPT_FRIEND:
{ if (friend_count == 0)
if (friend_count == 0) friend_specs = (char**) ALLOC (argc * sizeof (char*));
friend_specs = (char**) ALLOC ((argc-argi) * sizeof (char*)); friend_specs[friend_count++] = optarg;
friend_specs[friend_count++] = argv[++argi]; break;
}
else case OPT_ADD:
java_no_argument (argv[argi]); if (add_count == 0)
} add_specs = (char**) ALLOC (argc * sizeof (char*));
else if (strcmp (arg, "-add") == 0) add_specs[add_count++] = optarg;
{ break;
if (argi + 1 < argc)
{ case OPT_APPEND:
if (add_count == 0) if (append_count == 0)
add_specs = (char**) ALLOC ((argc-argi) * sizeof (char*)); append_specs = (char**) ALLOC (argc * sizeof (char*));
add_specs[add_count++] = argv[++argi]; append_specs[append_count++] = optarg;
} break;
else
java_no_argument (argv[argi]); case OPT_M:
}
else if (strcmp (arg, "-append") == 0)
{
if (argi + 1 < argc)
{
if (append_count == 0)
append_specs = (char**) ALLOC ((argc-argi) * sizeof (char*));
append_specs[append_count++] = argv[++argi];
}
else
java_no_argument (argv[argi]);
}
else if (strcmp (arg, "-classpath") == 0)
{
if (argi + 1 < argc)
jcf_path_classpath_arg (argv[++argi]);
else
java_no_argument (argv[argi]);
}
else if (strcmp (arg, "-CLASSPATH") == 0)
{
if (argi + 1 < argc)
jcf_path_CLASSPATH_arg (argv[++argi]);
else
java_no_argument (argv[argi]);
}
else if (strncmp (arg, "-I", 2) == 0)
jcf_path_include_arg (arg + 2);
else if (strcmp (arg, "-verbose") == 0 || strcmp (arg, "-v") == 0)
verbose++;
else if (strcmp (arg, "-stubs") == 0)
stubs++;
else if (strcmp (arg, "-help") == 0)
help ();
else if (strcmp (arg, "-version") == 0)
version ();
else if (strcmp (arg, "-M") == 0)
{
emit_dependencies = 1; emit_dependencies = 1;
suppress_output = 1; suppress_output = 1;
jcf_dependency_init (1); jcf_dependency_init (1);
} break;
else if (strcmp (arg, "-MM") == 0)
{ case OPT_MM:
emit_dependencies = 1; emit_dependencies = 1;
suppress_output = 1; suppress_output = 1;
jcf_dependency_init (0); jcf_dependency_init (0);
} break;
else if (strcmp (arg, "-MG") == 0)
{ case OPT_MG:
fprintf (stderr, "gcjh: `%s' option is unimplemented\n", argv[argi]); fprintf (stderr, "gcjh: `%s' option is unimplemented\n", argv[argi]);
exit (1); exit (1);
}
else if (strcmp (arg, "-MD") == 0) case OPT_MD:
{
emit_dependencies = 1; emit_dependencies = 1;
jcf_dependency_init (1); jcf_dependency_init (1);
} break;
else if (strcmp (arg, "-MMD") == 0)
{ case OPT_MMD:
emit_dependencies = 1; emit_dependencies = 1;
jcf_dependency_init (0); jcf_dependency_init (0);
} break;
else
{ default:
fprintf (stderr, "%s: illegal argument\n", argv[argi]); usage ();
exit (1); break;
} }
} }
if (argi == argc) if (optind == argc)
usage (); {
fprintf (stderr, "gcjh: no classes specified\n");
usage ();
}
jcf_path_seal (); jcf_path_seal ();
...@@ -1694,7 +1721,7 @@ DEFUN(main, (argc, argv), ...@@ -1694,7 +1721,7 @@ DEFUN(main, (argc, argv),
exit (1); exit (1);
} }
for (; argi < argc; argi++) for (argi = optind; argi < argc; argi++)
{ {
char *classname = argv[argi]; char *classname = argv[argi];
char *current_output_file; char *current_output_file;
...@@ -1782,12 +1809,3 @@ DEFUN(main, (argc, argv), ...@@ -1782,12 +1809,3 @@ DEFUN(main, (argc, argv),
return found_error; return found_error;
} }
/* TODO:
* Emit "structure forward declarations" when needed.
* Generate C headers, like javah
*/
...@@ -53,6 +53,10 @@ The Free Software Foundation is independent of Sun Microsystems, Inc. */ ...@@ -53,6 +53,10 @@ The Free Software Foundation is independent of Sun Microsystems, Inc. */
#include "tree.h" #include "tree.h"
#include "java-tree.h" #include "java-tree.h"
#include "version.c"
#include <getopt.h>
/* Outout file. */ /* Outout file. */
FILE *out; FILE *out;
/* Name of output file, if NULL if stdout. */ /* Name of output file, if NULL if stdout. */
...@@ -86,7 +90,9 @@ static void disassemble_method PARAMS ((JCF*, const unsigned char *, int)); ...@@ -86,7 +90,9 @@ static void disassemble_method PARAMS ((JCF*, const unsigned char *, int));
static void print_name PARAMS ((FILE*, JCF*, int)); static void print_name PARAMS ((FILE*, JCF*, int));
static void print_signature PARAMS ((FILE*, JCF*, int, int)); static void print_signature PARAMS ((FILE*, JCF*, int, int));
static int utf8_equal_string PARAMS ((struct JCF*, int, const char *)); static int utf8_equal_string PARAMS ((struct JCF*, int, const char *));
static int usage PARAMS ((void)) ATTRIBUTE_NORETURN; static void usage PARAMS ((void)) ATTRIBUTE_NORETURN;
static void help PARAMS ((void)) ATTRIBUTE_NORETURN;
static void version PARAMS ((void)) ATTRIBUTE_NORETURN;
static void process_class PARAMS ((struct JCF *)); static void process_class PARAMS ((struct JCF *));
static void print_constant_pool PARAMS ((struct JCF *)); static void print_constant_pool PARAMS ((struct JCF *));
static void print_exception_table PARAMS ((struct JCF *, static void print_exception_table PARAMS ((struct JCF *,
...@@ -679,13 +685,6 @@ DEFUN(print_exception_table, (jcf, entries, count), ...@@ -679,13 +685,6 @@ DEFUN(print_exception_table, (jcf, entries, count),
#include "jcf-reader.c" #include "jcf-reader.c"
static int
DEFUN (usage, (), )
{
fprintf (stderr, "Usage: jcf-dump [-o outputfile] [-c] classname\n");
exit(1);
}
static void static void
DEFUN(process_class, (jcf), DEFUN(process_class, (jcf),
JCF *jcf) JCF *jcf)
...@@ -732,56 +731,140 @@ DEFUN(process_class, (jcf), ...@@ -732,56 +731,140 @@ DEFUN(process_class, (jcf),
jcf->filename = NULL; jcf->filename = NULL;
} }
/* This is used to mark options with no short value. */
#define LONG_OPT(Num) ((Num) + 128)
#define OPT_classpath LONG_OPT (0)
#define OPT_CLASSPATH LONG_OPT (1)
#define OPT_HELP LONG_OPT (2)
#define OPT_VERSION LONG_OPT (3)
#define OPT_JAVAP LONG_OPT (4)
static struct option options[] =
{
{ "classpath", required_argument, NULL, OPT_classpath },
{ "CLASSPATH", required_argument, NULL, OPT_CLASSPATH },
{ "help", no_argument, NULL, OPT_HELP },
{ "verbose", no_argument, NULL, 'v' },
{ "version", no_argument, NULL, OPT_VERSION },
{ "javap", no_argument, NULL, OPT_JAVAP },
{ "print-main", no_argument, &flag_print_main, 1 },
{ NULL, no_argument, NULL, 0 }
};
static void
usage ()
{
fprintf (stderr, "Try `jcf-dump --help' for more information.\n");
exit (1);
}
static void
help ()
{
printf ("Usage: jcf-dump [OPTION]... CLASS...\n\n");
printf ("Display contents of a class file in readable form.\n\n");
printf (" -c Disassemble method bodies\n");
printf (" --javap Generate output in `javap' format\n");
printf ("\n");
printf (" --classpath PATH Set path to find .class files\n");
printf (" --CLASSPATH PATH Set path to find .class files\n");
printf (" -IDIR Append directory to class path\n");
printf (" -o FILE Set output file name\n");
printf ("\n");
printf (" --help Print this help, then exit\n");
printf (" --version Print version number, then exit\n");
printf (" -v, --verbose Print extra information while running\n");
printf ("\n");
printf ("For bug reporting instructions, please see:\n");
printf ("<URL:http://www.gnu.org/software/gcc/faq.html#bugreport>.\n");
exit (0);
}
static void
version ()
{
printf ("jcf-dump (%s)\n\n", version_string);
printf ("Copyright (C) 1998, 1999 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\n");
exit (0);
}
int int
DEFUN(main, (argc, argv), DEFUN(main, (argc, argv),
int argc AND char** argv) int argc AND char** argv)
{ {
JCF jcf[1]; JCF jcf[1];
int argi; int argi, opt;
if (argc <= 1) if (argc <= 1)
usage (); {
fprintf (stderr, "jcf-dump: no classes specified\n");
usage ();
}
jcf_path_init (); jcf_path_init ();
for (argi = 1; argi < argc; argi++) /* We use getopt_long_only to allow single `-' long options. For
some of our options this is more natural. */
while ((opt = getopt_long_only (argc, argv, "o:I:vc", options, NULL)) != -1)
{ {
const char *arg = argv[argi]; switch (opt)
{
case 0:
/* Already handled. */
break;
if (arg[0] != '-' || ! strcmp (arg, "--")) case 'o':
break; output_file = optarg;
break;
/* Just let all arguments be given in either "-" or "--" form. */ case 'I':
if (arg[1] == '-') jcf_path_include_arg (optarg);
++arg; break;
if (strcmp (arg, "-o") == 0 && argi + 1 < argc) case 'v':
output_file = argv[++argi]; verbose++;
else if (strcmp (arg, "-classpath") == 0 && argi + 1 < argc) break;
jcf_path_classpath_arg (argv[++argi]);
else if (strcmp (arg, "-CLASSPATH") == 0 && argi + 1 < argc) case 'c':
jcf_path_CLASSPATH_arg (argv[++argi]); flag_disassemble_methods = 1;
else if (strncmp (arg, "-I", 2) == 0) break;
jcf_path_include_arg (arg + 2);
else if (strcmp (arg, "-verbose") == 0) case OPT_classpath:
verbose++; jcf_path_classpath_arg (optarg);
else if (strcmp (arg, "-print-main") == 0) break;
flag_print_main++;
else if (strcmp (arg, "-c") == 0) case OPT_CLASSPATH:
flag_disassemble_methods++; jcf_path_CLASSPATH_arg (optarg);
else if (strcmp (arg, "-javap") == 0) break;
{
case OPT_HELP:
help ();
break;
case OPT_VERSION:
version ();
break;
case OPT_JAVAP:
flag_javap_compatible++; flag_javap_compatible++;
flag_print_constant_pool = 0; flag_print_constant_pool = 0;
} break;
else
{ default:
fprintf (stderr, "%s: illegal argument\n", argv[argi]); usage ();
return FATAL_EXIT_CODE;
} }
} }
if (argi == argc) if (optind == argc)
usage (); {
fprintf (stderr, "jcf-dump: no classes specified\n");
usage ();
}
jcf_path_seal (); jcf_path_seal ();
...@@ -806,7 +889,7 @@ DEFUN(main, (argc, argv), ...@@ -806,7 +889,7 @@ DEFUN(main, (argc, argv),
else else
out = stdout; out = stdout;
if (argi >= argc) if (optind >= argc)
{ {
fprintf (out, "Reading .class from <standard input>.\n"); fprintf (out, "Reading .class from <standard input>.\n");
#if JCF_USE_STDIO #if JCF_USE_STDIO
...@@ -818,7 +901,7 @@ DEFUN(main, (argc, argv), ...@@ -818,7 +901,7 @@ DEFUN(main, (argc, argv),
} }
else else
{ {
for (; argi < argc; argi++) for (argi = optind; argi < argc; argi++)
{ {
char *arg = argv[argi]; char *arg = argv[argi];
const char *class_filename = find_class (arg, strlen (arg), jcf, 0); const char *class_filename = find_class (arg, strlen (arg), jcf, 0);
...@@ -927,6 +1010,8 @@ DEFUN(main, (argc, argv), ...@@ -927,6 +1010,8 @@ DEFUN(main, (argc, argv),
return SUCCESS_EXIT_CODE; return SUCCESS_EXIT_CODE;
} }
static void static void
DEFUN(disassemble_method, (jcf, byte_ops, len), DEFUN(disassemble_method, (jcf, byte_ops, len),
JCF* jcf AND const unsigned char *byte_ops AND int len) JCF* jcf AND const unsigned char *byte_ops AND int len)
......
...@@ -24,10 +24,18 @@ Boston, MA 02111-1307, USA. */ ...@@ -24,10 +24,18 @@ Boston, MA 02111-1307, USA. */
#include "obstack.h" /* We use obstacks in lex.c */ #include "obstack.h" /* We use obstacks in lex.c */
#include "version.c"
#include <getopt.h>
void fatal PARAMS ((const char *s, ...)) ATTRIBUTE_PRINTF_1 ATTRIBUTE_NORETURN; void fatal PARAMS ((const char *s, ...)) ATTRIBUTE_PRINTF_1 ATTRIBUTE_NORETURN;
void warning PARAMS ((const char *s, ...)) ATTRIBUTE_PRINTF_1; void warning PARAMS ((const char *s, ...)) ATTRIBUTE_PRINTF_1;
void gcc_obstack_init PARAMS ((struct obstack *obstack)); void gcc_obstack_init PARAMS ((struct obstack *obstack));
static void usage PARAMS ((void)) ATTRIBUTE_NORETURN;
static void help PARAMS ((void)) ATTRIBUTE_NORETURN;
static void version PARAMS ((void)) ATTRIBUTE_NORETURN;
#define JC1_LITE #define JC1_LITE
#include "jcf.h" #include "jcf.h"
#include "parse.h" #include "parse.h"
...@@ -46,6 +54,59 @@ int flag_find_main = 0; ...@@ -46,6 +54,59 @@ int flag_find_main = 0;
int flag_dump_class = 0; int flag_dump_class = 0;
int flag_list_filename = 0; int flag_list_filename = 0;
/* This is used to mark options with no short value. */
#define LONG_OPT(Num) ((Num) + 128)
#define OPT_HELP LONG_OPT (0)
#define OPT_VERSION LONG_OPT (1)
static struct option options[] =
{
{ "help", no_argument, NULL, OPT_HELP },
{ "version", no_argument, NULL, OPT_VERSION },
{ "print-main", no_argument, &flag_find_main, 1 },
{ "list-filename", no_argument, &flag_list_filename, 1 },
{ "list-class", no_argument, &flag_dump_class, 1 },
{ NULL, no_argument, NULL, 0 }
};
static void
usage ()
{
fprintf (stderr, "Try `jv-scan --help' for more information.\n");
exit (1);
}
static void
help ()
{
printf ("Usage: jv-scan [OPTION]... FILE...\n\n");
printf ("Print useful information read from Java source files.\n\n");
printf (" --print-main Print name of class containing `main'\n");
printf (" --list-class List all classes defined in file\n");
printf (" --list-filename Print input filename when listing class names\n");
printf (" -o FILE Set output file name\n");
printf ("\n");
printf (" --help Print this help, then exit\n");
printf (" --version Print version number, then exit\n");
printf ("\n");
printf ("For bug reporting instructions, please see:\n");
printf ("<URL:http://www.gnu.org/software/gcc/faq.html#bugreport>.\n");
exit (0);
}
static void
version ()
{
printf ("jv-scan (%s)\n\n", version_string);
printf ("Copyright (C) 1998, 1999 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\n");
exit (0);
}
/* jc1-lite main entry point */ /* jc1-lite main entry point */
int int
DEFUN (main, (argc, argv), DEFUN (main, (argc, argv),
...@@ -54,43 +115,39 @@ DEFUN (main, (argc, argv), ...@@ -54,43 +115,39 @@ DEFUN (main, (argc, argv),
int i = 1; int i = 1;
const char *output_file = NULL; const char *output_file = NULL;
long ft; long ft;
int opt;
exec_name = argv[0]; exec_name = argv[0];
/* Default for output */ /* Default for output */
out = stdout; out = stdout;
/* Process options first */ /* Process options first. We use getopt_long and not
while (argv [i]) getopt_long_only because we only support `--' long options here. */
while ((opt = getopt_long (argc, argv, "o:", options, NULL)) != -1)
{ {
if (argv [i][0] == '-') switch (opt)
{ {
/* Dump result into a file */ case 0:
if (!strcmp (argv [i], "-o") && i+1 < argc) /* Already handled. */
{ break;
argv [i] = NULL;
output_file = argv [++i]; case 'o':
argv [i] = NULL; output_file = optarg;
} break;
/* Print the name of the class that contains main */ case OPT_HELP:
else if (!strcmp (argv [i], "--print-main")) help ();
flag_find_main = 1; break;
else if (!strcmp (argv [i], "--list-filename")) case OPT_VERSION:
flag_list_filename = 1; version ();
break;
/* List all the classes found in a source file */
else if (!strcmp (argv [i], "--list-class")) default:
flag_dump_class = 1; usage ();
break;
else
warning ("Unrecognized argument `%s'", argv[i]);
/* non recognized argument ignored silently */
argv [i] = NULL; /* Nullify so it's not considered a file */
} }
i++;
} }
/* No flags? Do nothing */ /* No flags? Do nothing */
...@@ -109,7 +166,7 @@ DEFUN (main, (argc, argv), ...@@ -109,7 +166,7 @@ DEFUN (main, (argc, argv),
gcc_obstack_init (&temporary_obstack); gcc_obstack_init (&temporary_obstack);
java_push_parser_context (); java_push_parser_context ();
for ( i = 1; i < argc; i++ ) for ( i = optind; i < argc; i++ )
if (argv [i]) if (argv [i])
{ {
input_filename = argv [i]; input_filename = argv [i];
...@@ -136,6 +193,8 @@ DEFUN (main, (argc, argv), ...@@ -136,6 +193,8 @@ DEFUN (main, (argc, argv),
return 0; return 0;
} }
/* Error report, memory, obstack initialization and other utility /* Error report, memory, obstack initialization and other utility
functions */ functions */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment