[Ada] remove trailing spaces in compiler output

Arnaud Charlet charlet@adacore.com
Wed Aug 29 08:36:00 GMT 2007


Tested on i686-linux, committed on trunk

This patch ensures that all outputs from the compiler will not end with
trailing spaces, except when the output is a source line.
Trailing spaces are not visible in outputs and having no trailing spaces
makes it easier to check expected outputs, without inadvertently removing
the trailings spaces, as done automatically by some text editors.

2007-08-14  Vincent Celier  <celier@adacore.com>

	* output.ads, output.adb (Write_Eol): Remove trailing spaces before
	writing the line.
	(Write_Eol_Keep_Blanks): New procedure to write a line, including
	possible trailing spaces.
	(Output_Source_Line): Call Write_Eol_Keep_Blanks to output a source line

-------------- next part --------------
Index: output.ads
===================================================================
--- output.ads	(revision 127358)
+++ output.ads	(working copy)
@@ -6,7 +6,7 @@
 --                                                                          --
 --                                 S p e c                                  --
 --                                                                          --
---          Copyright (C) 1992-2006, Free Software Foundation, Inc.         --
+--          Copyright (C) 1992-2007, 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- --
@@ -95,7 +95,10 @@ package Output is
    --  e.g. CR/LF for DOS, or LF for Unix) to the standard output file.
    --  This routine also empties the line buffer, actually writing it
    --  to the file. Note that Write_Eol is the only routine that causes
-   --  any actual output to be written.
+   --  any actual output to be written. Trailing spaces are removed.
+
+   procedure Write_Eol_Keep_Blanks;
+   --  Similar as Write_Eol, except that trailing spaces are not removed
 
    procedure Write_Int (Val : Int);
    --  Write an integer value with no leading blanks or zeroes. Negative
Index: output.adb
===================================================================
--- output.adb	(revision 127358)
+++ output.adb	(working copy)
@@ -254,11 +254,28 @@ package body Output is
 
    procedure Write_Eol is
    begin
+      --  Remove any trailing space
+
+      while Next_Col > 1 and then Buffer (Next_Col - 1) = ' ' loop
+         Next_Col := Next_Col - 1;
+      end loop;
+
       Buffer (Next_Col) := ASCII.LF;
       Next_Col := Next_Col + 1;
       Flush_Buffer;
    end Write_Eol;
 
+   ---------------------------
+   -- Write_Eol_Keep_Blanks --
+   ---------------------------
+
+   procedure Write_Eol_Keep_Blanks is
+   begin
+      Buffer (Next_Col) := ASCII.LF;
+      Next_Col := Next_Col + 1;
+      Flush_Buffer;
+   end Write_Eol_Keep_Blanks;
+
    ----------------------
    -- Write_Erase_Char --
    ----------------------


More information about the Gcc-patches mailing list