* [Ada] Handle limited line length for enumeration put (AI2012-R036)
@ 2011-10-24 12:04 Arnaud Charlet
0 siblings, 0 replies; only message in thread
From: Arnaud Charlet @ 2011-10-24 12:04 UTC (permalink / raw)
To: gcc-patches; +Cc: Robert Dewar
[-- Attachment #1: Type: text/plain, Size: 1065 bytes --]
This patch adjusts enumeration put to conform with the ruling in
ramification AI Ada2012-R036. Width number of characters must be
output on a single line, if impossible, a layout error is raised.
The following test program:
1. with Ada.Text_IO;
2. use Ada.Text_IO;
3. procedure Test_Enum_IO is
4. type Enum is (Literal);
5. package Enum_IO is new Enumeration_IO (Enum);
6. use Enum_IO;
7. begin
8. Set_Line_Length (20);
9. Put_Line ("12345678901234567890");
10. Set_Col (11);
11. Put (Literal, Width => 11);
12. Put (Literal, Width => 21);
13. end Test_Enum_IO;
Must output the first literal on the second line, because it
does not fit on the first, and the second put causes layout
error because the width exceeds the line length.
12345678901234567890
LITERAL
raised ADA.IO_EXCEPTIONS.LAYOUT_ERROR : a-tienau.adb:136
Tested on x86_64-pc-linux-gnu, committed on trunk
2011-10-24 Robert Dewar <dewar@adacore.com>
* a-tienau.adb (Put): Deal properly with limited line length.
[-- Attachment #2: difs --]
[-- Type: text/plain, Size: 1880 bytes --]
Index: a-tienau.adb
===================================================================
--- a-tienau.adb (revision 180365)
+++ a-tienau.adb (working copy)
@@ -6,7 +6,7 @@
-- --
-- B o d y --
-- --
--- Copyright (C) 1992-2009, Free Software Foundation, Inc. --
+-- Copyright (C) 1992-2011, 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- --
@@ -126,6 +126,25 @@
Actual_Width : constant Count := Count'Max (Count (Width), Item'Length);
begin
+ -- Deal with limited line length
+
+ if Line_Length /= 0 then
+
+ -- If actual width exceeds line length, raise Layout_Error
+
+ if Actual_Width > Line_Length then
+ raise Layout_Error;
+ end if;
+
+ -- If full width cannot fit on current line move to new line
+
+ if Actual_Width + (Col - 1) > Line_Length then
+ New_Line (File);
+ end if;
+ end if;
+
+ -- Output in lower case if necessary
+
if Set = Lower_Case and then Item (Item'First) /= ''' then
declare
Iteml : String (Item'First .. Item'Last);
@@ -138,10 +157,14 @@
Put_Item (File, Iteml);
end;
+ -- Otherwise output in upper case
+
else
Put_Item (File, Item);
end if;
+ -- Fill out item with spaces to width
+
for J in 1 .. Actual_Width - Item'Length loop
Put (File, ' ');
end loop;
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2011-10-24 10:32 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-10-24 12:04 [Ada] Handle limited line length for enumeration put (AI2012-R036) Arnaud Charlet
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).