Commit 18f2c460 by Pascal Obry Committed by Arnaud Charlet

a-textio.adb: Rename Is_Text_File to Text_Encoding.

2014-07-18  Pascal Obry  <obry@adacore.com>

	* a-textio.adb: Rename Is_Text_File to Text_Encoding.
	* a-ztexio.adb: Likewise.
	* a-witeio.adb: Likewise.
	(Open): Pass file's translation mode to set_text_mode.
	* s-ficobl.ads (Content_Encoding): New type.
	(Text_Content_Encoding): New subtype.
	(AFCB): Rename Is_Text_File to Text_Encoding.
	* s-fileio.adb (Open): Handles new text_translation
	values. Remove Is_Text_File which is equivalent to Text_Encoding
	in Text_Content_Encoding.
	* adaint.h (__gnat_set_mode): New routine.
	* sysdep.c (__gnat_set_wide_text_mode): Removed.
	(__gnat_set_mode): New routine.

From-SVN: r212810
parent 19ac960a
2014-07-18 Pascal Obry <obry@adacore.com>
* a-textio.adb: Rename Is_Text_File to Text_Encoding.
* a-ztexio.adb: Likewise.
* a-witeio.adb: Likewise.
(Open): Pass file's translation mode to set_text_mode.
* s-ficobl.ads (Content_Encoding): New type.
(Text_Content_Encoding): New subtype.
(AFCB): Rename Is_Text_File to Text_Encoding.
* s-fileio.adb (Open): Handles new text_translation
values. Remove Is_Text_File which is equivalent to Text_Encoding
in Text_Content_Encoding.
* adaint.h (__gnat_set_mode): New routine.
* sysdep.c (__gnat_set_wide_text_mode): Removed.
(__gnat_set_mode): New routine.
2014-07-18 Arnaud Charlet <charlet@adacore.com>
* gcc-interface/decl.c, gcc-interface/trans.c,
......
......@@ -6,7 +6,7 @@
-- --
-- B o d y --
-- --
-- Copyright (C) 1992-2013, Free Software Foundation, Inc. --
-- Copyright (C) 1992-2014, Free Software Foundation, Inc. --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
......@@ -921,7 +921,7 @@ package body Ada.Text_IO is
Standard_Err.Is_Regular_File := is_regular_file (fileno (stderr)) /= 0;
Standard_Err.Is_Temporary_File := False;
Standard_Err.Is_System_File := True;
Standard_Err.Is_Text_File := True;
Standard_Err.Text_Encoding := FCB.Default_Text;
Standard_Err.Access_Method := 'T';
Standard_Err.Self := Standard_Err;
Standard_Err.WC_Method := Default_WCEM;
......@@ -933,7 +933,7 @@ package body Ada.Text_IO is
Standard_In.Is_Regular_File := is_regular_file (fileno (stdin)) /= 0;
Standard_In.Is_Temporary_File := False;
Standard_In.Is_System_File := True;
Standard_In.Is_Text_File := True;
Standard_In.Text_Encoding := FCB.Default_Text;
Standard_In.Access_Method := 'T';
Standard_In.Self := Standard_In;
Standard_In.WC_Method := Default_WCEM;
......@@ -945,7 +945,7 @@ package body Ada.Text_IO is
Standard_Out.Is_Regular_File := is_regular_file (fileno (stdout)) /= 0;
Standard_Out.Is_Temporary_File := False;
Standard_Out.Is_System_File := True;
Standard_Out.Is_Text_File := True;
Standard_Out.Text_Encoding := FCB.Default_Text;
Standard_Out.Access_Method := 'T';
Standard_Out.Self := Standard_Out;
Standard_Out.WC_Method := Default_WCEM;
......
......@@ -892,7 +892,7 @@ package body Ada.Wide_Text_IO is
Standard_Err.Is_Regular_File := is_regular_file (fileno (stderr)) /= 0;
Standard_Err.Is_Temporary_File := False;
Standard_Err.Is_System_File := True;
Standard_Err.Is_Text_File := True;
Standard_Err.Text_Encoding := FCB.Default_Text;
Standard_Err.Access_Method := 'T';
Standard_Err.Self := Standard_Err;
Standard_Err.WC_Method := Default_WCEM;
......@@ -904,7 +904,7 @@ package body Ada.Wide_Text_IO is
Standard_In.Is_Regular_File := is_regular_file (fileno (stdin)) /= 0;
Standard_In.Is_Temporary_File := False;
Standard_In.Is_System_File := True;
Standard_In.Is_Text_File := True;
Standard_In.Text_Encoding := FCB.Default_Text;
Standard_In.Access_Method := 'T';
Standard_In.Self := Standard_In;
Standard_In.WC_Method := Default_WCEM;
......@@ -916,7 +916,7 @@ package body Ada.Wide_Text_IO is
Standard_Out.Is_Regular_File := is_regular_file (fileno (stdout)) /= 0;
Standard_Out.Is_Temporary_File := False;
Standard_Out.Is_System_File := True;
Standard_Out.Is_Text_File := True;
Standard_Out.Text_Encoding := FCB.Default_Text;
Standard_Out.Access_Method := 'T';
Standard_Out.Self := Standard_Out;
Standard_Out.WC_Method := Default_WCEM;
......@@ -1227,6 +1227,8 @@ package body Ada.Wide_Text_IO is
(File : File_Type;
Item : Wide_Character)
is
use type FCB.Content_Encoding;
wide_text_translation_required : Boolean;
for wide_text_translation_required'Size use Character'Size;
pragma Import (C, wide_text_translation_required,
......@@ -1256,8 +1258,12 @@ package body Ada.Wide_Text_IO is
begin
FIO.Check_Write_Status (AP (File));
if wide_text_translation_required then
set_wide_text_mode (fileno (File.Stream));
if wide_text_translation_required
or else File.Text_Encoding /= FCB.Default_Text
then
set_mode
(fileno (File.Stream),
FCB.Text_Content_Encoding'Pos (File.Text_Encoding));
Discard := fputwc (Wide_Character'Pos (Item), File.Stream);
else
WC_Out (Item, File.WC_Method);
......
......@@ -6,7 +6,7 @@
-- --
-- B o d y --
-- --
-- Copyright (C) 1992-2013, Free Software Foundation, Inc. --
-- Copyright (C) 1992-2014, Free Software Foundation, Inc. --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
......@@ -892,7 +892,7 @@ package body Ada.Wide_Wide_Text_IO is
Standard_Err.Is_Regular_File := is_regular_file (fileno (stderr)) /= 0;
Standard_Err.Is_Temporary_File := False;
Standard_Err.Is_System_File := True;
Standard_Err.Is_Text_File := True;
Standard_Err.Text_Encoding := FCB.Default_Text;
Standard_Err.Access_Method := 'T';
Standard_Err.Self := Standard_Err;
Standard_Err.WC_Method := Default_WCEM;
......@@ -904,7 +904,7 @@ package body Ada.Wide_Wide_Text_IO is
Standard_In.Is_Regular_File := is_regular_file (fileno (stdin)) /= 0;
Standard_In.Is_Temporary_File := False;
Standard_In.Is_System_File := True;
Standard_In.Is_Text_File := True;
Standard_In.Text_Encoding := FCB.Default_Text;
Standard_In.Access_Method := 'T';
Standard_In.Self := Standard_In;
Standard_In.WC_Method := Default_WCEM;
......@@ -916,7 +916,7 @@ package body Ada.Wide_Wide_Text_IO is
Standard_Out.Is_Regular_File := is_regular_file (fileno (stdout)) /= 0;
Standard_Out.Is_Temporary_File := False;
Standard_Out.Is_System_File := True;
Standard_Out.Is_Text_File := True;
Standard_Out.Text_Encoding := FCB.Default_Text;
Standard_Out.Access_Method := 'T';
Standard_Out.Self := Standard_Out;
Standard_Out.WC_Method := Default_WCEM;
......
......@@ -244,6 +244,7 @@ extern int __gnat_pipe (int *);
extern int __gnat_expect_poll (int *, int, int, int *);
extern void __gnat_set_binary_mode (int);
extern void __gnat_set_text_mode (int);
extern void __gnat_set_mode (int,int);
extern char *__gnat_ttyname (int);
extern int __gnat_lseek (int, long, int);
extern int __gnat_set_close_on_exec (int, int);
......
......@@ -17367,7 +17367,7 @@ between values. The order of the entries is not important. Currently
the following keywords defined.
@smallexample
TEXT_TRANSLATION=[YES|NO]
TEXT_TRANSLATION=[YES|NO|TEXT|BINARY|U8TEXT|WTEXT|U16TEXT]
SHARED=[YES|NO]
WCEM=[n|h|u|s|e|8|b]
ENCODING=[UTF8|8BITS]
......@@ -18096,14 +18096,35 @@ manner described for stream attributes.
@noindent
@samp{Text_Translation=@var{xxx}} may be used as the Form parameter
passed to Text_IO.Create and Text_IO.Open:
@samp{Text_Translation=@var{Yes}} is the default, which means to
passed to Text_IO.Create and Text_IO.Open. @samp{Text_Translation=@var{xxx}}
has no effect on Unix systems. Possible values are:
@itemize @bullet
@item
@samp{@var{Yes} or @var{Text}} is the default, which means to
translate LF to/from CR/LF on Windows systems.
@samp{Text_Translation=@var{No}} disables this translation; i.e. it
@samp{@var{No}} disables this translation; i.e. it
uses binary mode. For output files, @samp{Text_Translation=@var{No}}
may be used to create Unix-style files on
Windows. @samp{Text_Translation=@var{xxx}} has no effect on Unix
systems.
Windows.
@item
@samp{@var{wtext}} translation enabled in Unicode mode.
(corresponds to _O_WTEXT).
@item
@samp{@var{u8text}} translation enabled in Unicode UTF-8 mode.
(corresponds to O_U8TEXT).
@item
@samp{@var{u16text}} translation enabled in Unicode UTF-16
mode. (corresponds to_O_U16TEXT).
@end itemize
@node Shared Files
@section Shared Files
......
......@@ -228,11 +228,17 @@ package Interfaces.C_Streams is
-- versa. These functions have no effect if text_translation_required is
-- false (e.g. in normal unix mode). Use fileno to get a stream handle.
procedure set_wide_text_mode (handle : int);
-- This is similar to set_text_mode but switches the translation to 16-bit
-- wide-character instead of 8-bit character. Again, this routine has no
-- effect if text_translation_required is false. On Windows this is used
-- to have proper 16-bit wide-string output on the console for example.
procedure set_mode (handle : int; Mode : int);
-- As above but can set the handle to any mode. On Windows this can be used
-- to have proper 16-bit wide-string output on the console for example. The
-- mode value corresponds to Content_Encoding'Pos:
-- 0 = binary, equivalent to set_binary_mode
-- 1 = default mode, as set by the GNAT_CCS_ENCODING or equivalent to 2
-- 2 = text, equivalent to set_text_mode
-- 3 = u8text, set encoding to Unicode UTF-8
-- 4 = wide-text, set encoding to Unicode
-- 5 = u16text, set encoding to Unicode UTF-16
-- Wouldn't it be better to use an enumeration type here???
----------------------------
-- Full Path Name support --
......@@ -264,7 +270,7 @@ private
pragma Import (C, set_binary_mode, "__gnat_set_binary_mode");
pragma Import (C, set_text_mode, "__gnat_set_text_mode");
pragma Import (C, set_wide_text_mode, "__gnat_set_wide_text_mode");
pragma Import (C, set_mode, "__gnat_set_mode");
pragma Import (C, max_path_len, "__gnat_max_path_len");
pragma Import (C, full_name, "__gnat_full_name");
......
......@@ -6,7 +6,7 @@
-- --
-- S p e c --
-- --
-- Copyright (C) 1992-2012, Free Software Foundation, Inc. --
-- Copyright (C) 1992-2014, Free Software Foundation, Inc. --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
......@@ -78,6 +78,25 @@ package System.File_Control_Block is
-- stream with the semantics specified in the RM for file sharing. All
-- files opened with "shared=no" will have their own stream.
type Content_Encoding is (None, Default_Text, Text, U8text, Wtext, U16text);
-- Described the text encoding for file content:
-- None : No text encoding, this file is treated as a binary file
-- Default_Text : A text file but not from Text_Translation form string
-- In this mode we are eventually using the system-wide
-- translation if activated.
-- Text : Text encoding activated
-- Wtext : Unicode mode
-- U16text : Unicode UTF-16 encoding
-- U8text : Unicode UTF-8 encoding
--
-- This encoding is system dependent and only used on Windows systems.
--
-- Note that modifications to Content_Encoding must be synchronized
-- with sysdep.c:__gnat_set_mode.
subtype Text_Content_Encoding
is Content_Encoding range Default_Text .. U16text;
type AFCB is tagged;
type AFCB_Ptr is access all AFCB'Class;
......@@ -116,8 +135,8 @@ package System.File_Control_Block is
Is_System_File : Boolean;
-- A flag set only for system files (stdin, stdout, stderr)
Is_Text_File : Boolean;
-- A flag set if the file was opened in text mode
Text_Encoding : Content_Encoding;
-- A flag set to describe file content encoding
Shared_Status : Shared_Status_Type;
-- Indicates sharing status of file, see description of type above
......
......@@ -36,6 +36,7 @@ with Interfaces.C;
with Interfaces.C_Streams; use Interfaces.C_Streams;
with System.CRTL;
with System.Case_Util; use System.Case_Util;
with System.OS_Lib;
with System.Soft_Links;
......@@ -958,7 +959,7 @@ package body System.File_IO is
Formstr : aliased String (1 .. Form'Length + 1);
-- Form string with ASCII.NUL appended, folded to lower case
Is_Text_File : Boolean;
Text_Encoding : Content_Encoding;
Tempfile : constant Boolean := (Name'Length = 0);
-- Indicates temporary file case
......@@ -1042,11 +1043,37 @@ package body System.File_IO is
-- if the Form says Text_Translation=No, we use binary mode, so new-line
-- will be just LF, even on Windows.
Is_Text_File := Text;
if Text then
Text_Encoding := Default_Text;
else
Text_Encoding := None;
end if;
if Is_Text_File then
Is_Text_File :=
Form_Boolean (Formstr, "text_translation", Default => True);
if Text_Encoding in Text_Content_Encoding then
declare
V1, V2 : Natural;
begin
Form_Parameter (Formstr, "text_translation", V1, V2);
if V1 = 0 then
null;
elsif Formstr (V1 .. V2) = "no" then
Text_Encoding := None;
elsif Formstr (V1 .. V2) = "text"
or else Formstr (V1 .. V2) = "yes"
then
Text_Encoding := File_Control_Block.Text;
elsif Formstr (V1 .. V2) = "wtext" then
Text_Encoding := Wtext;
elsif Formstr (V1 .. V2) = "u8text" then
Text_Encoding := U8text;
elsif Formstr (V1 .. V2) = "u16text" then
Text_Encoding := U16text;
else
raise Use_Error with "invalid Form";
end if;
end;
end if;
-- Acquire settings of target specific form parameters on VMS. Only
......@@ -1200,7 +1227,9 @@ package body System.File_IO is
-- Open specified file if we did not find an existing stream
if Stream = NULL_Stream then
Fopen_Mode (Mode, Is_Text_File, Creat, Amethod, Fopstr);
Fopen_Mode
(Mode, Text_Encoding in Text_Content_Encoding,
Creat, Amethod, Fopstr);
-- A special case, if we are opening (OPEN case) a file and the
-- mode returned by Fopen_Mode is not "r" or "r+", then we first
......@@ -1274,7 +1303,7 @@ package body System.File_IO is
File_Ptr.Is_Regular_File := (is_regular_file (fileno (Stream)) /= 0);
File_Ptr.Is_System_File := False;
File_Ptr.Is_Text_File := Is_Text_File;
File_Ptr.Text_Encoding := Text_Encoding;
File_Ptr.Shared_Status := Shared;
File_Ptr.Access_Method := Amethod;
File_Ptr.Stream := Stream;
......@@ -1398,7 +1427,8 @@ package body System.File_IO is
else
Fopen_Mode
(Mode, File.Is_Text_File, False, File.Access_Method, Fopstr);
(Mode, File.Text_Encoding in Text_Content_Encoding,
False, File.Access_Method, Fopstr);
Form_VMS_RMS_Keys (File.Form.all, VMS_Formstr);
......
......@@ -152,9 +152,26 @@ __gnat_set_text_mode (int handle)
}
void
__gnat_set_wide_text_mode (int handle)
__gnat_set_mode (int handle, int mode)
{
WIN_SETMODE (handle, CurrentCCSEncoding);
/* the values here must be synchronized with
System.File_Control_Block.Content_Encodding:
None = 0
Default_Text = 1
Text = 2
U8text = 3
Wtext = 4
U16text = 5 */
switch (mode) {
case 0 : WIN_SETMODE (handle, _O_BINARY); break;
case 1 : WIN_SETMODE (handle, CurrentCCSEncoding); break;
case 2 : WIN_SETMODE (handle, _O_TEXT); break;
case 3 : WIN_SETMODE (handle, _O_U8TEXT); break;
case 4 : WIN_SETMODE (handle, _O_WTEXT); break;
case 5 : WIN_SETMODE (handle, _O_U16TEXT); break;
}
}
#ifdef __CYGWIN__
......@@ -254,7 +271,7 @@ __gnat_set_text_mode (int handle ATTRIBUTE_UNUSED)
}
void
__gnat_set_wide_text_mode (int handle ATTRIBUTE_UNUSED)
__gnat_set_mode (int handle ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED)
{
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment