Commit 399e70e8 by Robert Dewar Committed by Arnaud Charlet

a-textio.adb (Set_Col): Fix two errors noticed recently...

2005-06-14  Robert Dewar  <dewar@adacore.com>

	* a-textio.adb (Set_Col): Fix two errors noticed recently, having to
	do with treatment of Set_Col when positioned at end of line character.

From-SVN: r101025
parent 758c442c
------------------------------------------------------------------------------
-- --
-- GNAT RUNTIME COMPONENTS --
-- GNAT RUN-TIME COMPONENTS --
-- --
-- A D A . T E X T _ I O --
-- --
......@@ -1340,43 +1340,82 @@ package body Ada.Text_IO is
FIO.Check_File_Open (AP (File));
if To = File.Col then
return;
end if;
-- Output case
if Mode (File) >= Out_File then
-- Error if we attempt to set Col to a value greater than the
-- maximum permissible line length.
if File.Line_Length /= 0 and then To > File.Line_Length then
raise Layout_Error;
end if;
-- If we are behind current position, then go to start of new line
if To < File.Col then
New_Line (File);
end if;
-- Loop to output blanks till we are at the required column
while File.Col < To loop
Put (File, ' ');
end loop;
-- Input case
else
-- If we are logically before a LM, but physically after it, the
-- file position still reflects the position before the LM, so eat
-- it now and adjust the file position appropriately.
if File.Before_LM then
File.Before_LM := False;
File.Before_LM_PM := False;
File.Line := File.Line + 1;
File.Col := 1;
end if;
-- Loop reading characters till we get one at the required Col value
loop
-- Read next character. The reason we have to read ahead is to
-- skip formatting characters, the effect of Set_Col is to set
-- us to a real character with the right Col value, and format
-- characters don't count.
ch := Getc (File);
-- Error if we hit an end of file
if ch = EOF then
raise End_Error;
-- If line mark, eat it and adjust file position
elsif ch = LM then
File.Line := File.Line + 1;
File.Col := 1;
-- If recognized page mark, eat it, and adjust file position
elsif ch = PM and then File.Is_Regular_File then
File.Page := File.Page + 1;
File.Line := 1;
File.Col := 1;
-- Otherwise this is the character we are looking for, so put it
-- back in the input stream (we have not adjusted the file
-- position yet, so everything is set right after this ungetc).
elsif To = File.Col then
Ungetc (ch, File);
return;
-- Keep skipping characters if we are not there yet, updating the
-- file position past the skipped character.
else
File.Col := File.Col + 1;
end if;
......
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