2 Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006
3 Free Software Foundation, Inc.
4 Contributed by Alexandre Petit-Bianco (apbianco@cygnus.com)
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
13 GCC is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING. If not, write to
20 the Free Software Foundation, 51 Franklin Street, Fifth Floor,
21 Boston, MA 02110-1301, USA. */
25 #include "coretypes.h"
29 #include "obstack.h" /* We use obstacks in lex.c */
37 #ifdef HAVE_LANGINFO_CODESET
43 extern void fatal_error (const char *gmsgid
, ...)
44 ATTRIBUTE_PRINTF_1 ATTRIBUTE_NORETURN
;
45 void warning (int opt
, const char *gmsgid
, ...) ATTRIBUTE_PRINTF_2
;
46 void warning0 (const char *gmsgid
, ...) ATTRIBUTE_PRINTF_1
;
49 static void usage (void) ATTRIBUTE_NORETURN
;
50 static void help (void) ATTRIBUTE_NORETURN
;
51 static void version (void) ATTRIBUTE_NORETURN
;
57 /* Current input file and output file IO streams. */
60 /* Executable name. */
63 struct line_maps line_table
;
65 /* Flags matching command line options. */
66 int flag_find_main
= 0;
67 int flag_dump_class
= 0;
68 int flag_list_filename
= 0;
69 int flag_complexity
= 0;
76 /* This is used to mark options with no short value. */
77 #define LONG_OPT(Num) ((Num) + 128)
79 #define OPT_HELP LONG_OPT (0)
80 #define OPT_VERSION LONG_OPT (1)
81 #define OPT_ENCODING LONG_OPT (2)
83 static const struct option options
[] =
85 { "help", no_argument
, NULL
, OPT_HELP
},
86 { "version", no_argument
, NULL
, OPT_VERSION
},
87 { "print-main", no_argument
, &flag_find_main
, 1 },
88 { "list-filename", no_argument
, &flag_list_filename
, 1 },
89 { "list-class", no_argument
, &flag_dump_class
, 1 },
90 { "encoding", required_argument
, NULL
, OPT_ENCODING
},
91 { "complexity", no_argument
, &flag_complexity
, 1 },
92 { "no-assert", no_argument
, &flag_assert
, 0 },
93 { "assert", no_argument
, &flag_assert
, 1 },
94 { NULL
, no_argument
, NULL
, 0 }
100 fprintf (stderr
, _("Try 'jv-scan --help' for more information.\n"));
107 printf (_("Usage: jv-scan [OPTION]... FILE...\n\n"));
108 printf (_("Print useful information read from Java source files.\n\n"));
109 printf (_(" --no-assert Don't recognize the assert keyword\n"));
110 printf (_(" --complexity Print cyclomatic complexity of input file\n"));
111 printf (_(" --encoding NAME Specify encoding of input file\n"));
112 printf (_(" --print-main Print name of class containing 'main'\n"));
113 printf (_(" --list-class List all classes defined in file\n"));
114 printf (_(" --list-filename Print input filename when listing class names\n"));
115 printf (_(" -o FILE Set output file name\n"));
117 printf (_(" --help Print this help, then exit\n"));
118 printf (_(" --version Print version number, then exit\n"));
120 printf (_("For bug reporting instructions, please see:\n"
121 "%s.\n"), bug_report_url
);
128 printf ("jv-scan (GCC) %s\n\n", version_string
);
129 printf ("Copyright %s 2006 Free Software Foundation, Inc.\n", _("(C)"));
130 printf (_("This is free software; see the source for copying conditions. There is NO\n"
131 "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\n"));
135 /* jc1-lite main entry point */
137 main (int argc
, char **argv
)
140 const char *output_file
= NULL
;
141 const char *encoding
= NULL
;
147 /* Default for output */
150 /* Unlock the stdio streams. */
151 unlock_std_streams ();
155 /* Process options first. We use getopt_long and not
156 getopt_long_only because we only support `--' long options here. */
157 while ((opt
= getopt_long (argc
, argv
, "o:", options
, NULL
)) != -1)
162 /* Already handled. */
166 output_file
= optarg
;
187 /* No flags? Do nothing */
188 if (! flag_find_main
&& ! flag_dump_class
&& ! flag_complexity
)
191 /* Check on bad usage */
192 if (flag_find_main
+ flag_dump_class
+ flag_complexity
> 1)
194 ("only one of '--print-main', '--list-class', and '--complexity' allowed");
196 if (output_file
&& !(out
= fopen (output_file
, "w")))
197 fatal_error ("can't open output file '%s'", output_file
);
201 gcc_obstack_init (&temporary_obstack
);
202 java_push_parser_context ();
204 for ( i
= optind
; i
< argc
; i
++ )
207 char *filename
= argv
[i
];
208 if ( (finput
= fopen (filename
, "r")) )
210 /* There's no point in trying to find the current encoding
211 unless we are going to do something intelligent with it
212 -- hence the test for iconv. */
213 #if defined (HAVE_LOCALE_H) && defined (HAVE_ICONV) && defined (HAVE_LANGINFO_CODESET)
214 setlocale (LC_CTYPE
, "");
215 if (encoding
== NULL
)
216 encoding
= nl_langinfo (CODESET
);
218 if (encoding
== NULL
|| *encoding
== '\0')
219 encoding
= DEFAULT_ENCODING
;
221 main_input_filename
= filename
;
222 java_init_lex (finput
, encoding
);
223 ctxp
->filename
= filename
;
226 if (ftell (out
) != ft
)
233 fatal_error ("file not found '%s'", argv
[i
]);
236 /* Flush and close */
237 if (ftell (out
) != ft
)
247 /* Error report, memory, obstack initialization and other utility
248 functions. Use actually c-format msgid, but as functions with
249 the same name elsewhere use gcc-internal-format, assume all users
250 here use intersection between c-format and gcc-internal-format. */
253 fatal_error (const char *gmsgid
, ...)
256 va_start (ap
, gmsgid
);
257 fprintf (stderr
, _("%s: error: "), exec_name
);
258 vfprintf (stderr
, _(gmsgid
), ap
);
259 fputc ('\n', stderr
);
265 warning (int opt ATTRIBUTE_UNUSED
, const char *gmsgid
, ...)
268 va_start (ap
, gmsgid
);
269 fprintf (stderr
, _("%s: warning: "), exec_name
);
270 vfprintf (stderr
, _(gmsgid
), ap
);
271 fputc ('\n', stderr
);
276 warning0 (const char *gmsgid
, ...)
279 va_start (ap
, gmsgid
);
280 fprintf (stderr
, _("%s: warning: "), exec_name
);
281 vfprintf (stderr
, _(gmsgid
), ap
);
282 fputc ('\n', stderr
);
287 fancy_abort (const char *file
, int line
, const char *func
)
289 fatal_error ("abort in %s, at %s:%d", func
, file
, line
);