From d19cbcb5e3dd83e2628d25d2cd23892a4cac83b0 Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Tue, 12 Sep 2000 22:23:59 +0000 Subject: 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 if nl_langinfo exists. * lang-options.h: Document --classpath, --CLASSPATH, --main, and --encoding. * jcf-parse.c Include 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 if HAVE_ICONV defined. (java_lexer): New structure. (UNGETC): Removed. (GETC): Removed. (DEFAULT_ENCODING): New define. (java_destroy_lexer): Declare. From-SVN: r36377 --- gcc/java/jcf-parse.c | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) (limited to 'gcc/java/jcf-parse.c') diff --git a/gcc/java/jcf-parse.c b/gcc/java/jcf-parse.c index 02becc07483..4b76f598ca0 100644 --- a/gcc/java/jcf-parse.c +++ b/gcc/java/jcf-parse.c @@ -35,6 +35,10 @@ The Free Software Foundation is independent of Sun Microsystems, Inc. */ #include "toplev.h" #include "parse.h" +#ifdef HAVE_NL_LANGINFO +#include +#endif + /* A CONSTANT_Utf8 element is converted to an IDENTIFIER_NODE at parse time. */ #define JPOOL_UTF(JCF, INDEX) CPOOL_UTF(&(JCF)->cpool, INDEX) #define JPOOL_UTF_LENGTH(JCF, INDEX) IDENTIFIER_LENGTH (JPOOL_UTF (JCF, INDEX)) @@ -83,7 +87,7 @@ static struct JCF main_jcf[1]; static tree give_name_to_class PARAMS ((JCF *jcf, int index)); static void parse_zip_file_entries PARAMS ((void)); static void process_zip_dir PARAMS ((void)); -static void parse_source_file PARAMS ((tree)); +static void parse_source_file PARAMS ((tree, FILE *)); static void jcf_parse_source PARAMS ((void)); static int jcf_figure_file_type PARAMS ((JCF *)); static int find_in_current_zip PARAMS ((const char *, struct JCF **)); @@ -564,6 +568,7 @@ static void jcf_parse_source () { tree file; + FILE *finput; java_parser_context_save_global (); java_push_parser_context (); @@ -576,7 +581,7 @@ jcf_parse_source () if (!(finput = fopen (input_filename, "r"))) fatal ("input file `%s' just disappeared - jcf_parse_source", input_filename); - parse_source_file (file); + parse_source_file (file, finput); if (fclose (finput)) fatal ("can't close input file `%s' stream - jcf_parse_source", input_filename); @@ -754,8 +759,9 @@ parse_class_file () /* Parse a source file, as pointed by the current value of INPUT_FILENAME. */ static void -parse_source_file (file) +parse_source_file (file, finput) tree file; + FILE *finput; { int save_error_count = java_error_count; /* Mark the file as parsed */ @@ -765,7 +771,21 @@ parse_source_file (file) lang_init_source (1); /* Error msgs have no method prototypes */ - java_init_lex (); /* Initialize the parser */ + /* 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 (current_encoding == NULL) + current_encoding = nl_langinfo (CODESET); +#endif /* HAVE_NL_LANGINFO */ +#endif /* HAVE_ICONV */ + if (current_encoding == NULL || *current_encoding == '\0') + current_encoding = DEFAULT_ENCODING; + + /* Initialize the parser */ + java_init_lex (finput, current_encoding); java_parse_abort_on_error (); java_parse (); /* Parse and build partial tree nodes. */ @@ -796,6 +816,7 @@ yyparse () int several_files = 0; char *list = xstrdup (input_filename), *next; tree node, current_file_list = NULL_TREE; + FILE *finput; do { @@ -901,7 +922,7 @@ yyparse () case JCF_SOURCE: java_push_parser_context (); java_parser_context_save_global (); - parse_source_file (name); + parse_source_file (name, finput); java_parser_context_restore_global (); java_pop_parser_context (1); break; -- cgit v1.2.1