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
......
...@@ -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