diff options
author | Hans Bolinder <[email protected]> | 2013-09-03 08:10:33 +0200 |
---|---|---|
committer | Hans Bolinder <[email protected]> | 2013-09-03 08:10:33 +0200 |
commit | 1de23e3a31b77db4c9dca952644b764bd37e2e8f (patch) | |
tree | 9eed394935b8c5172e8c1e1b20649e5a2ebb0d0e /lib/parsetools/src | |
parent | 2f1007e60d1a0817e5d80e46c3ab21501d1f714b (diff) | |
parent | 298ff42f5f80a603306a007540d1c75a013bcf81 (diff) | |
download | otp-1de23e3a31b77db4c9dca952644b764bd37e2e8f.tar.gz otp-1de23e3a31b77db4c9dca952644b764bd37e2e8f.tar.bz2 otp-1de23e3a31b77db4c9dca952644b764bd37e2e8f.zip |
Merge branch 'hb/parsetools/unicode_bugfix/OTP-11286' into maint
* hb/parsetools/unicode_bugfix/OTP-11286:
Fix a Unicode filename bug affecting Leex and Yecc
Diffstat (limited to 'lib/parsetools/src')
-rw-r--r-- | lib/parsetools/src/leex.erl | 10 | ||||
-rw-r--r-- | lib/parsetools/src/yecc.erl | 12 |
2 files changed, 15 insertions, 7 deletions
diff --git a/lib/parsetools/src/leex.erl b/lib/parsetools/src/leex.erl index e531b78a5b..7039aea1ae 100644 --- a/lib/parsetools/src/leex.erl +++ b/lib/parsetools/src/leex.erl @@ -1645,10 +1645,14 @@ output_encoding_comment(File, #leex{encoding = Encoding}) -> output_file_directive(File, Filename, Line) -> io:fwrite(File, <<"-file(~ts, ~w).\n">>, - [format_filename(Filename), Line]). + [format_filename(Filename, File), Line]). -format_filename(Filename) -> - io_lib:write_string(filename:flatten(Filename)). +format_filename(Filename0, File) -> + Filename = filename:flatten(Filename0), + case lists:keyfind(encoding, 1, io:getopts(File)) of + {encoding, unicode} -> io_lib:write_string(Filename); + _ -> io_lib:write_string_as_latin1(Filename) + end. quote($^) -> "\\^"; quote($.) -> "\\."; diff --git a/lib/parsetools/src/yecc.erl b/lib/parsetools/src/yecc.erl index f9207d926e..b698beb558 100644 --- a/lib/parsetools/src/yecc.erl +++ b/lib/parsetools/src/yecc.erl @@ -482,7 +482,7 @@ generate(St0) -> F = case member(time, St1#yecc.options) of true -> io:fwrite(<<"Generating parser from grammar in ~ts\n">>, - [format_filename(St1#yecc.infile)]), + [format_filename(St1#yecc.infile, St1)]), fun timeit/3; false -> fun(_Name, Fn, St) -> Fn(St) end @@ -2519,7 +2519,7 @@ output_encoding_comment(#yecc{encoding = Encoding}=St) -> output_file_directive(St, Filename, Line) when St#yecc.file_attrs -> fwrite(St, <<"-file(~ts, ~w).\n">>, - [format_filename(Filename), Line]); + [format_filename(Filename, St), Line]); output_file_directive(St, _Filename, _Line) -> St. @@ -2547,8 +2547,12 @@ nl(#yecc{outport = Outport, line = Line}=St) -> io:nl(Outport), St#yecc{line = Line + 1}. -format_filename(Filename) -> - io_lib:write_string(filename:flatten(Filename)). +format_filename(Filename0, St) -> + Filename = filename:flatten(Filename0), + case lists:keyfind(encoding, 1, io:getopts(St#yecc.outport)) of + {encoding, unicode} -> io_lib:write_string(Filename); + _ -> io_lib:write_string_as_latin1(Filename) + end. format_assoc(left) -> "Left"; |