summaryrefslogtreecommitdiff
path: root/gcc/java/jcf-parse.c
diff options
context:
space:
mode:
authorTom Tromey <tromey@cygnus.com>2000-09-12 22:23:59 +0000
committerTom Tromey <tromey@gcc.gnu.org>2000-09-12 22:23:59 +0000
commitd19cbcb5e3dd83e2628d25d2cd23892a4cac83b0 (patch)
tree21cc6935b87686835780712e1d9a7d64eae418d0 /gcc/java/jcf-parse.c
parentee17a29049f330ff40a486e56826468a223323c2 (diff)
downloadgcc-d19cbcb5e3dd83e2628d25d2cd23892a4cac83b0.tar.gz
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/jcf-parse.c')
-rw-r--r--gcc/java/jcf-parse.c31
1 files changed, 26 insertions, 5 deletions
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 <langinfo.h>
+#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;