bbt_0.0.6_807c8d3a/src/bbt-settings.adb

 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
-- -----------------------------------------------------------------------------
-- bbt, the black box tester (https://github.com/LionelDraghi/bbt)
-- Author : Lionel Draghi
-- SPDX-License-Identifier: APSL-2.0
-- SPDX-FileCopyrightText: 2024, Lionel Draghi
-- -----------------------------------------------------------------------------

with Ada.Directories;

package body BBT.Settings is

   -- --------------------------------------------------------------------------
   -- Most of the variable here are "write once, read more".
   -- To avoid the cost of Unbounded strings manipulation,
   -- they are implemented as access to String
   -- Runfl_Name      : access String := null;
   -- Cmd_Line        : Unbounded_String := Null_Unbounded_String;
   Launch_Dir                  : constant access String :=
     new String'(Ada.Directories.Current_Directory);
   Outfile_Name, Exec_Dir_Name : access String := null;

   -- --------------------------------------------------------------------------
   --  function Is_File_In (File, Dir : String) return Boolean is
   --     Compared_Length : constant Natural := (if Dir (Dir'Last) = '*'
   --                                            then Dir'Length - 1
   --                                            else Dir'Length);
   --     -- return True if File is in Dir, supposing that both are full name.
   --     -- e.g. (Dir => /usr/*, File => /usr/lib/locale) return True
   --     -- e.g. (Dir => /usr/*, File => locale)          return False
   --  begin
   --     return (File'Length >= Compared_Length and then
   --             File (File'First .. File'First - 1 + Compared_Length)
   --             = Dir (Dir'First .. Dir'First  - 1 + Compared_Length));
   --  end Is_File_In;

   -- --------------------------------------------------------------------------
   function Launch_Directory return String
   is (Launch_Dir.all);

   -- --------------------------------------------------------------------------
   procedure Set_Exec_Dir (Dir_Name : String) is
   begin
      Exec_Dir_Name := new String'(Dir_Name);
   end Set_Exec_Dir;

   function Exec_Dir return String is
    (if Exec_Dir_Name = null then Ada.Directories.Current_Directory
       else Exec_Dir_Name.all);

   -- --------------------------------------------------------------------------
   function Output_File_Dir return String is (Exec_Dir);

   -- --------------------------------------------------------------------------
   procedure Set_Result_File (File_Name : String) is
   begin
      Outfile_Name := new String'(File_Name);
   end Set_Result_File;

   function Result_File_Name return String is
    (if Outfile_Name = null then "" else Outfile_Name.all);

   function Result_Dir return String is
    (if Outfile_Name = null then Ada.Directories.Current_Directory
       else Ada.Directories.Containing_Directory (Outfile_Name.all));

end BBT.Settings;