Index: a-textio.adb =================================================================== RCS file: /cvs/gcc/gcc/gcc/ada/a-textio.adb,v retrieving revision 1.9 diff -u -p -r1.9 a-textio.adb --- a-textio.adb 10 Feb 2005 13:51:39 -0000 1.9 +++ a-textio.adb 15 Jun 2005 15:45:58 -0000 @@ -1,6 +1,6 @@ ------------------------------------------------------------------------------ -- -- --- 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;