diff options
author | Tom Tromey <tromey@cygnus.com> | 2000-09-12 22:23:59 +0000 |
---|---|---|
committer | Tom Tromey <tromey@gcc.gnu.org> | 2000-09-12 22:23:59 +0000 |
commit | d19cbcb5e3dd83e2628d25d2cd23892a4cac83b0 (patch) | |
tree | 21cc6935b87686835780712e1d9a7d64eae418d0 /gcc/java/jv-scan.c | |
parent | ee17a29049f330ff40a486e56826468a223323c2 (diff) | |
download | gcc-d19cbcb5e3dd83e2628d25d2cd23892a4cac83b0.zip gcc-d19cbcb5e3dd83e2628d25d2cd23892a4cac83b0.tar.gz gcc-d19cbcb5e3dd83e2628d25d2cd23892a4cac83b0.tar.bz2 |
re GNATS gcj/33 (gcj mangles composed characters)
Fix for PR gcj/33:
* jv-scan.c (help): Document --encoding.
(options): Added `encoding' entry.
(OPT_ENCODING): New define.
(main): Handle --encoding.
Include <langinfo.h> if nl_langinfo exists.
* lang-options.h: Document --classpath, --CLASSPATH, --main, and
--encoding.
* jcf-parse.c Include <langinfo.h> if we have nl_langinfo.
(parse_source_file): Correctly call java_init_lex. Added `finput'
argument. Use nl_langinfo to determine default encoding.
* java-tree.h (current_encoding): Declare.
* parse.y (java_parser_context_restore_global): Don't restore
`finput'.
(java_parser_context_save_global): Don't set `finput' field.
(java_pop_parser_context): Don't restore `finput'. Free old lexer
if required.
* lang.c (current_encoding): New global.
(lang_decode_option): Recognize `-fencoding='.
(finish_parse): Don't close finput.
* parse.h (struct parser_ctxt): Removed `finput' and
`unget_utf8_value' fields. Added `lexer' field.
(java_init_lex): Fixed declaration.
* lex.c (java_new_lexer): New function.
(java_destroy_lexer): Likewise.
(java_read_char): Added `lex' argument. Handle iconv case.
(java_read_unicode): Added `lex' argument. Count backslashes in
lexer structure.
(java_init_lex): Added `finput' and `encoding' arguments. Set
`lexer' field in ctxp.
(BAD_UTF8_VALUE): Removed.
(java_lex): Handle seeing UEOF in the middle of a string literal.
* lex.h: Include <iconv.h> if HAVE_ICONV defined.
(java_lexer): New structure.
(UNGETC): Removed.
(GETC): Removed.
(DEFAULT_ENCODING): New define.
(java_destroy_lexer): Declare.
From-SVN: r36377
Diffstat (limited to 'gcc/java/jv-scan.c')
-rw-r--r-- | gcc/java/jv-scan.c | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/gcc/java/jv-scan.c b/gcc/java/jv-scan.c index adb7ba3..ae9c91d 100644 --- a/gcc/java/jv-scan.c +++ b/gcc/java/jv-scan.c @@ -26,6 +26,10 @@ Boston, MA 02111-1307, USA. */ #include "version.h" +#ifdef HAVE_NL_LANGINFO +#include <langinfo.h> +#endif + #include <getopt.h> void fatal PARAMS ((const char *s, ...)) ATTRIBUTE_PRINTF_1 ATTRIBUTE_NORETURN; @@ -61,6 +65,7 @@ int flag_list_filename = 0; #define OPT_HELP LONG_OPT (0) #define OPT_VERSION LONG_OPT (1) +#define OPT_ENCODING LONG_OPT (2) static struct option options[] = { @@ -69,6 +74,7 @@ static struct option options[] = { "print-main", no_argument, &flag_find_main, 1 }, { "list-filename", no_argument, &flag_list_filename, 1 }, { "list-class", no_argument, &flag_dump_class, 1 }, + { "encoding", required_argument, NULL, OPT_ENCODING }, { NULL, no_argument, NULL, 0 } }; @@ -84,6 +90,7 @@ help () { printf ("Usage: jv-scan [OPTION]... FILE...\n\n"); printf ("Print useful information read from Java source files.\n\n"); + printf (" --encoding NAME Specify encoding of input file\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"); @@ -114,6 +121,7 @@ DEFUN (main, (argc, argv), { int i = 1; const char *output_file = NULL; + const char *encoding = NULL; long ft; int opt; @@ -144,6 +152,10 @@ DEFUN (main, (argc, argv), version (); break; + case OPT_ENCODING: + encoding = optarg; + break; + default: usage (); break; @@ -172,7 +184,20 @@ DEFUN (main, (argc, argv), input_filename = argv [i]; if ( (finput = fopen (argv [i], "r")) ) { - java_init_lex (); + /* There's no point in trying to find the current encoding + unless we are going to do something intelligent with it + -- hence the test for iconv. */ +#ifdef HAVE_ICONV +#ifdef HAVE_NL_LANGINFO + setlocale (LC_CTYPE, ""); + if (encoding == NULL) + encoding = nl_langinfo (CODESET); +#endif /* HAVE_NL_LANGINFO */ +#endif /* HAVE_ICONV */ + if (encoding == NULL || *encoding == '\0') + encoding = DEFAULT_ENCODING; + + java_init_lex (finput, encoding); yyparse (); if (ftell (out) != ft) fputc ('\n', out); |