File: utils.adb

package info (click to toggle)
dbusada 0.6.3-2.1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 748 kB
  • sloc: ada: 5,892; ansic: 98; makefile: 81; sh: 47
file content (46 lines) | stat: -rw-r--r-- 1,221 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
with Ada.Text_IO;
with Ada.IO_Exceptions;

package body Utils is

   -------------------------------------------------------------------------

   function Read_Line_From_File (Filename : String) return String
   is
      File : Ada.Text_IO.File_Type;
   begin
      begin
         Ada.Text_IO.Open
           (File => File,
            Mode => Ada.Text_IO.In_File,
            Name => Filename,
            Form => "shared=no");

      exception
         when others =>
            raise Open_File_Error with
              "Unable to open file '" & Filename & "'";
      end;

      Read_Line :
      begin
         declare
            Line : constant String := Ada.Text_IO.Get_Line (File => File);
         begin
            Ada.Text_IO.Close (File);
            return Line;
         end;

      exception
         when Ada.IO_Exceptions.End_Error =>
            Ada.Text_IO.Close (File);
            raise IO_Error with "Unable to read line from empty "
              & "file '" & Filename & "'";
         when others =>
            Ada.Text_IO.Close (File);
            raise IO_Error with "Error reading data from file '"
              & Filename & "'";
      end Read_Line;
   end Read_Line_From_File;

end Utils;