diff options
Diffstat (limited to 'gcc/ada')
-rw-r--r-- | gcc/ada/i-cstrea.ads | 26 | ||||
-rw-r--r-- | gcc/ada/mingw32.h | 14 | ||||
-rw-r--r-- | gcc/ada/s-crtl-vms64.ads | 18 | ||||
-rw-r--r-- | gcc/ada/s-crtl.ads | 15 | ||||
-rw-r--r-- | gcc/ada/s-ficobl.ads | 10 | ||||
-rw-r--r-- | gcc/ada/s-fileio.adb | 46 |
6 files changed, 93 insertions, 36 deletions
diff --git a/gcc/ada/i-cstrea.ads b/gcc/ada/i-cstrea.ads index a7a30b2..ac5e80f4 100644 --- a/gcc/ada/i-cstrea.ads +++ b/gcc/ada/i-cstrea.ads @@ -6,7 +6,7 @@ -- -- -- S p e c -- -- -- --- Copyright (C) 1995-2005, Free Software Foundation, Inc. -- +-- Copyright (C) 1995-2006, 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- -- @@ -105,10 +105,14 @@ package Interfaces.C_Streams is function fileno (stream : FILEs) return int; - function fopen (filename : chars; Mode : chars) return FILEs + function fopen + (filename : chars; + mode : chars; + encoding : System.CRTL.Filename_Encoding := System.CRTL.UTF8) + return FILEs renames System.CRTL.fopen; -- Note: to maintain target independence, use text_translation_required, - -- a boolean variable defined in a-sysdep.c to deal with the target + -- a boolean variable defined in sysdep.c to deal with the target -- dependent text translation requirement. If this variable is set, -- then b/t should be appended to the standard mode argument to set -- the text translation mode off or on as required. @@ -140,14 +144,16 @@ package Interfaces.C_Streams is function freopen (filename : chars; mode : chars; - stream : FILEs) - return FILEs renames System.CRTL.freopen; + stream : FILEs; + encoding : System.CRTL.Filename_Encoding := System.CRTL.UTF8) + return FILEs + renames System.CRTL.freopen; function fseek (stream : FILEs; offset : long; - origin : int) - return int renames System.CRTL.fseek; + origin : int) return int + renames System.CRTL.fseek; function ftell (stream : FILEs) return long renames System.CRTL.ftell; @@ -156,8 +162,7 @@ package Interfaces.C_Streams is (buffer : voids; size : size_t; count : size_t; - stream : FILEs) - return size_t; + stream : FILEs) return size_t; function isatty (handle : int) return int renames System.CRTL.isatty; @@ -170,8 +175,7 @@ package Interfaces.C_Streams is (stream : FILEs; buffer : chars; mode : int; - size : size_t) - return int; + size : size_t) return int; procedure tmpnam (string : chars) renames System.CRTL.tmpnam; -- The parameter must be a pointer to a string buffer of at least L_tmpnam diff --git a/gcc/ada/mingw32.h b/gcc/ada/mingw32.h index 7b63531..6637fd1 100644 --- a/gcc/ada/mingw32.h +++ b/gcc/ada/mingw32.h @@ -71,13 +71,19 @@ the proper translations using the UTF-8 encoding. */ #ifdef GNAT_UNICODE_SUPPORT +#define S2WSU(wstr,str,len) \ + MultiByteToWideChar (CP_UTF8,0,str,-1,wstr,len) +#define WS2SU(str,wstr,len) \ + WideCharToMultiByte (CP_UTF8,0,wstr,-1,str,len,NULL,NULL) #define S2WS(wstr,str,len) \ - MultiByteToWideChar (CP_UTF8,0,str,-1,wstr,len); + MultiByteToWideChar (CP_ACP,0,str,-1,wstr,len) #define WS2S(str,wstr,len) \ - WideCharToMultiByte (CP_UTF8,0,wstr,-1,str,len,NULL,NULL); + WideCharToMultiByte (CP_ACP,0,wstr,-1,str,len,NULL,NULL) #else -#define S2WS(wstr,str,len) strncpy(wstr,str,len); -#define WS2S(str,wstr,len) strncpy(str,wstr,len); +#define S2WSU(wstr,str,len) strncpy(wstr,str,len) +#define WS2SU(str,wstr,len) strncpy(str,wstr,len) +#define S2WS(wstr,str,len) strncpy(wstr,str,len) +#define WS2S(str,wstr,len) strncpy(str,wstr,len) #endif #include <stdlib.h> diff --git a/gcc/ada/s-crtl-vms64.ads b/gcc/ada/s-crtl-vms64.ads index 83292b7..c221d05 100644 --- a/gcc/ada/s-crtl-vms64.ads +++ b/gcc/ada/s-crtl-vms64.ads @@ -57,6 +57,11 @@ package System.CRTL is type size_t is mod 2 ** Standard'Address_Size; + type Filename_Encoding is (UTF8, ASCII_8bits); + for Filename_Encoding use (UTF8 => 0, ASCII_8bits => 1); + pragma Convention (C, Filename_Encoding); + -- Describes the filename's encoding + function atoi (A : System.Address) return Integer; pragma Import (C, atoi, "decc$atoi"); @@ -84,8 +89,11 @@ package System.CRTL is function fgets (strng : chars; n : int; stream : FILEs) return chars; pragma Import (C, fgets, "decc$_fgets64"); - function fopen (filename : chars; Mode : chars) return FILEs; - pragma Import (C, fopen, "decc$fopen"); + function fopen + (filename : chars; + mode : chars; + encoding : Filename_Encoding := UTF8) return FILEs; + pragma Import (C, fopen, "__gnat_fopen"); function fputc (C : int; stream : FILEs) return int; pragma Import (C, fputc, "decc$fputc"); @@ -99,9 +107,10 @@ package System.CRTL is function freopen (filename : chars; mode : chars; - stream : FILEs) + stream : FILEs; + encoding : Filename_Encoding := UTF8) return FILEs; - pragma Import (C, freopen, "decc$freopen"); + pragma Import (C, freopen, "__gnat_freopen"); function fseek (stream : FILEs; @@ -175,4 +184,5 @@ package System.CRTL is function write (fd : int; buffer : chars; nbytes : int) return int; pragma Import (C, write, "decc$write"); + end System.CRTL; diff --git a/gcc/ada/s-crtl.ads b/gcc/ada/s-crtl.ads index 5397776..30bca62 100644 --- a/gcc/ada/s-crtl.ads +++ b/gcc/ada/s-crtl.ads @@ -57,6 +57,11 @@ package System.CRTL is type size_t is mod 2 ** Standard'Address_Size; + type Filename_Encoding is (UTF8, ASCII_8bits); + for Filename_Encoding use (UTF8 => 0, ASCII_8bits => 1); + pragma Convention (C, Filename_Encoding); + -- Describes the filename's encoding + function atoi (A : System.Address) return Integer; pragma Import (C, atoi, "atoi"); @@ -84,7 +89,10 @@ package System.CRTL is function fgets (strng : chars; n : int; stream : FILEs) return chars; pragma Import (C, fgets, "fgets"); - function fopen (filename : chars; Mode : chars) return FILEs; + function fopen + (filename : chars; + mode : chars; + encoding : Filename_Encoding := UTF8) return FILEs; pragma Import (C, fopen, "__gnat_fopen"); function fputc (C : int; stream : FILEs) return int; @@ -99,8 +107,8 @@ package System.CRTL is function freopen (filename : chars; mode : chars; - stream : FILEs) - return FILEs; + stream : FILEs; + encoding : Filename_Encoding := UTF8) return FILEs; pragma Import (C, freopen, "__gnat_freopen"); function fseek @@ -175,4 +183,5 @@ package System.CRTL is function write (fd : int; buffer : chars; nbytes : int) return int; pragma Import (C, write, "write"); + end System.CRTL; diff --git a/gcc/ada/s-ficobl.ads b/gcc/ada/s-ficobl.ads index f19ea79..7c1e1c4 100644 --- a/gcc/ada/s-ficobl.ads +++ b/gcc/ada/s-ficobl.ads @@ -6,7 +6,7 @@ -- -- -- S p e c -- -- -- --- Copyright (C) 1992-2004 Free Software Foundation, Inc. -- +-- Copyright (C) 1992-2006, 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- -- @@ -39,6 +39,7 @@ with Ada.Streams; with Interfaces.C_Streams; +with System.CRTL; package System.File_Control_Block is @@ -90,6 +91,9 @@ package System.File_Control_Block is -- files, and also for standard files (stdin, stdout, stderr). The -- name is always null-terminated if it is non-null. + Encoding : System.CRTL.Filename_Encoding; + -- Encoding used to specified the filename + Form : Pstring; -- A pointer to the form string. This is the string used in the -- fopen call, and must be supplied by the caller (there are no @@ -143,13 +147,13 @@ package System.File_Control_Block is -- that the argument Control_Block is not used other than as the argument -- that controls which version of AFCB_Allocate is called. - procedure AFCB_Close (File : access AFCB) is abstract; + procedure AFCB_Close (File : not null access AFCB) is abstract; -- Performs any specialized close actions on a file before the file is -- actually closed at the system level. This is called by Close, and -- the reason we need the primitive operation is for the automatic -- close operations done as part of finalization. - procedure AFCB_Free (File : access AFCB) is abstract; + procedure AFCB_Free (File : not null access AFCB) is abstract; -- Frees the AFCB referenced by the given parameter. It is not necessary -- to free the strings referenced by the Form and Name fields, but if the -- extension has any other heap objects, they must be freed as well. This diff --git a/gcc/ada/s-fileio.adb b/gcc/ada/s-fileio.adb index 4317cb3..06c0858 100644 --- a/gcc/ada/s-fileio.adb +++ b/gcc/ada/s-fileio.adb @@ -199,13 +199,13 @@ package body System.File_IO is Dup_Strm : Boolean := False; begin - Check_File_Open (File); - AFCB_Close (File); - -- Take a task lock, to protect the global data value Open_Files SSL.Lock_Task.all; + Check_File_Open (File); + AFCB_Close (File); + -- Sever the association between the given file and its associated -- external file. The given file is left closed. Do not perform system -- closes on the standard input, output and error files and also do @@ -435,7 +435,7 @@ package body System.File_IO is Amethod : Character; Fopstr : out Fopen_String) is - Fptr : Positive; + Fptr : Positive; begin case Mode is @@ -733,6 +733,9 @@ package body System.File_IO is Full_Name_Len : Integer; -- Length of name actually stored in Fullname + Encoding : System.CRTL.Filename_Encoding; + -- Filename encoding specified into the form parameter + begin if File_Ptr /= null then raise Status_Error; @@ -773,6 +776,28 @@ package body System.File_IO is end if; end; + -- Acquire setting of shared parameter + + declare + V1, V2 : Natural; + + begin + Form_Parameter (Formstr, "encoding", V1, V2); + + if V1 = 0 then + Encoding := System.CRTL.UTF8; + + elsif Formstr (V1 .. V2) = "utf8" then + Encoding := System.CRTL.UTF8; + + elsif Formstr (V1 .. V2) = "8bits" then + Encoding := System.CRTL.ASCII_8bits; + + else + raise Use_Error; + end if; + end; + -- If we were given a stream (call from xxx.C_Streams.Open), then set -- the full name to the given one, and skip to end of processing. @@ -928,7 +953,7 @@ package body System.File_IO is -- current working directory may have changed and -- we do not want to delete a different file! - Stream := fopen (Namestr'Address, Fopstr'Address); + Stream := fopen (Namestr'Address, Fopstr'Address, Encoding); if Stream = NULL_Stream then if file_exists (Namestr'Address) = 0 then @@ -946,18 +971,17 @@ package body System.File_IO is File_Ptr := AFCB_Allocate (Dummy_FCB); - File_Ptr.Is_Regular_File := (is_regular_file - (fileno (Stream)) /= 0); + File_Ptr.Is_Regular_File := (is_regular_file (fileno (Stream)) /= 0); File_Ptr.Is_System_File := False; File_Ptr.Is_Text_File := Text; File_Ptr.Shared_Status := Shared; File_Ptr.Access_Method := Amethod; File_Ptr.Stream := Stream; File_Ptr.Form := new String'(Formstr); - File_Ptr.Name := new String'(Fullname - (1 .. Full_Name_Len)); + File_Ptr.Name := new String'(Fullname (1 .. Full_Name_Len)); File_Ptr.Mode := Mode; File_Ptr.Is_Temporary_File := Tempfile; + File_Ptr.Encoding := Encoding; Chain_File (File_Ptr); Append_Set (File_Ptr); @@ -1050,8 +1074,8 @@ package body System.File_IO is Fopen_Mode (Mode, File.Is_Text_File, False, File.Access_Method, Fopstr); - File.Stream := - freopen (File.Name.all'Address, Fopstr'Address, File.Stream); + File.Stream := freopen + (File.Name.all'Address, Fopstr'Address, File.Stream, File.Encoding); if File.Stream = NULL_Stream then Close (File); |