Debian Codegraph @

tests/utils.adb

raw
1 with Ada.Text_IO;
2 with Ada.IO_Exceptions;
3
4 package body Utils is
5
6 -------------------------------------------------------------------------
7
8 function Read_Line_From_File (Filename : String) return String
9 is
10 File : Ada.Text_IO.File_Type;
11 begin
12 begin
13 Ada.Text_IO.Open
14 (File => File,
15 Mode => Ada.Text_IO.In_File,
16 Name => Filename,
17 Form => "shared=no");
18
19 exception
20 when others =>
21 raise Open_File_Error with
22 "Unable to open file '" & Filename & "'";
23 end;
24
25 Read_Line :
26 begin
27 declare
28 Line : constant String := Ada.Text_IO.Get_Line (File => File);
29 begin
30 Ada.Text_IO.Close (File);
31 return Line;
32 end;
33
34 exception
35 when Ada.IO_Exceptions.End_Error =>
36 Ada.Text_IO.Close (File);
37 raise IO_Error with "Unable to read line from empty "
38 & "file '" & Filename & "'";
39 when others =>
40 Ada.Text_IO.Close (File);
41 raise IO_Error with "Error reading data from file '"
42 & Filename & "'";
43 end Read_Line;
44 end Read_Line_From_File;
45
46 end Utils;