summaryrefslogtreecommitdiffstats
path: root/gcc/ada/gnatchop.adb
diff options
context:
space:
mode:
authorcharlet <charlet@138bc75d-0d04-0410-961f-82ee72b054a4>2009-04-15 12:43:58 +0000
committercharlet <charlet@138bc75d-0d04-0410-961f-82ee72b054a4>2009-04-15 12:43:58 +0000
commit53e876ae3c965af2dee43bf0ff7904c8dedcb41b (patch)
tree384f96baae68288a3efecddd80744a86175fa651 /gcc/ada/gnatchop.adb
parent9a8abef624fe1d8fc3528def0388a606a58046bd (diff)
downloadppe42-gcc-53e876ae3c965af2dee43bf0ff7904c8dedcb41b.tar.gz
ppe42-gcc-53e876ae3c965af2dee43bf0ff7904c8dedcb41b.zip
2009-04-15 Robert Dewar <dewar@adacore.com>
* gnatchop.adb (BOM_Length): New global variable (Write_Unit): Add new parameter Write_BOM (Write_Chopped_Files): Check for BOM and set Write_BOM for call to Write_Unit * gnat_ugn.texi: Add note on propagation of BOM by gnatchop 2009-04-15 Geert Bosch <bosch@adacore.com> * system-mingw-x86_64.ads, system-darwin-x86_64.ads (Backend_Overflow_Checks): Set to True. 2009-04-15 Gary Dismukes <dismukes@adacore.com> * par-ch3.adb (P_Type_Declaration): Issue an error if the synchronized keyword is given in a record extension. 2009-04-15 Hristian Kirtchev <kirtchev@adacore.com> * exp_ch7.adb (Expand_Ctrl_Function_Call): Procede with the expansion of a controlled function call in the context of a record aggregate. This does not apply to array aggregates since the call will be expanded into assignments. 2009-04-15 Ed Falis <falis@adacore.com> * s-osinte-vxworks-kernel.adb, s-osinte-vxworks.adb, s-osinte-vxworks.ads s-vxwext.ads, s-vxwext-kernel.adb, s-vxwext-kernel.ads: Reorganize s-osinte-vxworks* and s-vxwext*. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@146108 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/ada/gnatchop.adb')
-rw-r--r--gcc/ada/gnatchop.adb57
1 files changed, 44 insertions, 13 deletions
diff --git a/gcc/ada/gnatchop.adb b/gcc/ada/gnatchop.adb
index 9c78975fb5b..ec32c073d56 100644
--- a/gcc/ada/gnatchop.adb
+++ b/gcc/ada/gnatchop.adb
@@ -30,13 +30,14 @@ with Ada.Streams.Stream_IO; use Ada.Streams;
with Ada.Text_IO; use Ada.Text_IO;
with System.CRTL; use System; use System.CRTL;
+with GNAT.Byte_Order_Mark; use GNAT.Byte_Order_Mark;
with GNAT.Command_Line; use GNAT.Command_Line;
with GNAT.OS_Lib; use GNAT.OS_Lib;
with GNAT.Heap_Sort_G;
with GNAT.Table;
with Hostparm;
-with Switch; use Switch;
+with Switch; use Switch;
with Types;
procedure Gnatchop is
@@ -67,6 +68,9 @@ procedure Gnatchop is
-- but properly treated if present. Not generated in output files except
-- as a result of copying input file.
+ BOM_Length : Natural := 0;
+ -- Reset to non-zero value if BOM detected at start of file
+
--------------------
-- File arguments --
--------------------
@@ -323,11 +327,15 @@ procedure Gnatchop is
-- of line sequence to be written at the end of the pragma.
procedure Write_Unit
- (Source : not null access String;
- Num : Unit_Num;
- TS_Time : OS_Time;
- Success : out Boolean);
- -- Write one compilation unit of the source to file
+ (Source : not null access String;
+ Num : Unit_Num;
+ TS_Time : OS_Time;
+ Write_BOM : Boolean;
+ Success : out Boolean);
+ -- Write one compilation unit of the source to file. Source is the pointer
+ -- to the input string, Num is the unit number, TS_Time is the timestamp,
+ -- Write_BOM is set True to write a UTF-8 BOM at the start of the file.
+ -- Success is set True unless the write attempt fails.
---------
-- dup --
@@ -1426,6 +1434,10 @@ procedure Gnatchop is
Success : Boolean;
TS_Time : OS_Time;
+ BOM_Present : Boolean;
+ BOM : BOM_Kind;
+ -- Record presence of UTF8 BOM in input
+
begin
FD := Open_Read (Name'Address, Binary);
TS_Time := File_Time_Stamp (FD);
@@ -1447,11 +1459,21 @@ procedure Gnatchop is
Put_Line ("splitting " & File.Table (Input).Name.all & " into:");
end if;
+ -- Test for presence of BOM
+
+ Read_BOM (Buffer.all, BOM_Length, BOM, False);
+ BOM_Present := BOM /= Unknown;
+
-- Only chop those units that come from this file
- for Num in 1 .. Unit.Last loop
- if Unit.Table (Num).Chop_File = Input then
- Write_Unit (Buffer, Num, TS_Time, Success);
+ for Unit_Number in 1 .. Unit.Last loop
+ if Unit.Table (Unit_Number).Chop_File = Input then
+ Write_Unit
+ (Source => Buffer,
+ Num => Unit_Number,
+ TS_Time => TS_Time,
+ Write_BOM => BOM_Present and then Unit_Number /= 1,
+ Success => Success);
exit when not Success;
end if;
end loop;
@@ -1613,10 +1635,11 @@ procedure Gnatchop is
----------------
procedure Write_Unit
- (Source : not null access String;
- Num : Unit_Num;
- TS_Time : OS_Time;
- Success : out Boolean)
+ (Source : not null access String;
+ Num : Unit_Num;
+ TS_Time : OS_Time;
+ Write_BOM : Boolean;
+ Success : out Boolean)
is
procedure OS_Filename
@@ -1695,6 +1718,14 @@ procedure Gnatchop is
Length := Info.Length;
end if;
+ -- Write BOM if required
+
+ if Write_BOM then
+ String'Write
+ (Stream_IO.Stream (File),
+ Source.all (Source'First .. Source'First + BOM_Length - 1));
+ end if;
+
-- Prepend configuration pragmas if necessary
if Success and then Info.Bufferg /= null then
OpenPOWER on IntegriCloud