diff options
author | charlet <charlet@138bc75d-0d04-0410-961f-82ee72b054a4> | 2005-06-16 08:33:07 +0000 |
---|---|---|
committer | charlet <charlet@138bc75d-0d04-0410-961f-82ee72b054a4> | 2005-06-16 08:33:07 +0000 |
commit | 01b34824d636187f81948cca15fce00e91c4df52 (patch) | |
tree | e851743b4a1567322ce1b55e6cb7961155e19956 /gcc/ada/a-textio.adb | |
parent | aad6babd3202684e69d09d60051b89b59092cc2d (diff) | |
download | gcc-01b34824d636187f81948cca15fce00e91c4df52.tar.gz |
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.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@101025 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/ada/a-textio.adb')
-rw-r--r-- | gcc/ada/a-textio.adb | 47 |
1 files changed, 43 insertions, 4 deletions
diff --git a/gcc/ada/a-textio.adb b/gcc/ada/a-textio.adb index 3fc95f02bd8..306ab592e8c 100644 --- a/gcc/ada/a-textio.adb +++ b/gcc/ada/a-textio.adb @@ -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; |