Skip to content

Commit 10f5eff

Browse files
author
cnngimenez
committedAug 24, 2024
Backend_Memory works: desired behaviour implented.
1 parent d035fde commit 10f5eff

File tree

3 files changed

+34
-5
lines changed

3 files changed

+34
-5
lines changed
 

‎src/libraries/apagerlib/apagerlib-backend.adb

+11-4
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919

2020
-------------------------------------------------------------------------
2121

22+
with Ada.Exceptions;
23+
use Ada.Exceptions;
2224
with Ada.Characters.Latin_1;
2325

2426
package body Apagerlib.Backend is
@@ -68,7 +70,10 @@ package body Apagerlib.Backend is
6870
end loop;
6971

7072
exception
71-
when No_More_Char => raise No_Line_Found;
73+
when Exc : No_More_Char =>
74+
Raise_Exception (No_Line_Found'Identity,
75+
"Next_Line could not find new line because: " &
76+
Exception_Message (Exc));
7277
end Next_Line;
7378

7479
function Next_Line_Position (Stream : in out Backend_Stream'Class;
@@ -103,13 +108,15 @@ package body Apagerlib.Backend is
103108
raise No_Line_Found;
104109
end if;
105110

106-
while Stream.Current_Position > 1 and then C /= LF and then C /= CR
107-
loop
111+
while C /= LF and then C /= CR loop
108112
C := Stream.Previous_Char;
109113
end loop;
110114

111115
exception
112-
when No_More_Char => return;
116+
when Exc : No_More_Char =>
117+
Raise_Exception (No_Line_Found'Identity,
118+
"Could not find previous line beacuse: "
119+
& Exception_Message (Exc));
113120
end Previous_Line;
114121

115122
function Previous_Line_Position (Stream : in out Backend_Stream'Class;

‎src/libraries/apagerlib/apagerlib-memories.adb

+2-1
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,8 @@ package body Apagerlib.Memories is
262262
Memory.Current_BIP := Page_Limit;
263263
else
264264
-- No previous page!
265-
raise No_Byte_Found;
265+
Raise_Exception (No_More_Char'Identity,
266+
"Could not find previous character at first position.");
266267
end if;
267268
end if;
268269
end Previous_Char;

‎src/tools/apager_backend_test.adb

+21
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919

2020
-------------------------------------------------------------------------
2121

22+
with Ada.Exceptions;
23+
use Ada.Exceptions;
2224
with Ada.Text_IO; use Ada.Text_IO;
2325
with Ada.Command_Line; use Ada.Command_Line;
2426
with Apagerlib.Backend; use Apagerlib.Backend;
@@ -61,6 +63,15 @@ procedure Apager_Backend_Test is
6163
Memory.Next_Line;
6264
Put (Memory.Current_Position'Image);
6365
end loop;
66+
67+
exception
68+
when Exc : Apagerlib.Backend.No_Line_Found =>
69+
Put (" ");
70+
if Memory.End_Of_File then
71+
Put_Line ("No new line character at end of file.");
72+
else
73+
Put_Line (Exception_Message (Exc));
74+
end if;
6475
end Print_Next_Line;
6576

6677
procedure Print_Next_Line_Function is
@@ -76,10 +87,20 @@ procedure Apager_Backend_Test is
7687
begin
7788
Memory.End_Position;
7889

90+
-- Beware: if the End_Position is a new line it will not be printed.
7991
while Memory.Current_Position > 1 loop
8092
Memory.Previous_Line;
8193
Put (Memory.Current_Position'Image);
8294
end loop;
95+
96+
exception
97+
when Exc : Apagerlib.Backend.No_Line_Found =>
98+
Put (" ");
99+
if Memory.Current_Position = 1 then
100+
Put_Line ("No new line character at beginning of file.");
101+
else
102+
Put_Line (Exception_Message (Exc));
103+
end if;
83104
end Print_Previous_Line;
84105

85106
procedure Print_Previous_Line_Function is

0 commit comments

Comments
 (0)
Please sign in to comment.