/usr/share/ada/adainclude/alog/alog-helpers.adb is in libalog0.4.1-base-dev 0.4.1-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 | --
-- Copyright (c) 2008-2009,
-- Reto Buerki, Adrian-Ken Rueegsegger
--
-- This file is part of Alog.
--
-- Alog is free software; you can redistribute it and/or modify
-- it under the terms of the GNU Lesser General Public License as published
-- by the Free Software Foundation; either version 2.1 of the License, or
-- (at your option) any later version.
--
-- Alog is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU Lesser General Public License for more details.
--
-- You should have received a copy of the GNU Lesser General Public License
-- along with Alog; if not, write to the Free Software
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
-- MA 02110-1301 USA
--
with Ada.Text_IO;
with Ada.Strings.Fixed;
package body Alog.Helpers is
-------------------------------------------------------------------------
function Assert_Files_Equal
(Filename1 : String;
Filename2 : String)
return Boolean
is
File1 : D_IO.File_Type;
File2 : D_IO.File_Type;
Char1, Char2 : My_Rec;
Result : Boolean := True;
begin
-- Open both files.
Open (File => File1,
Mode => In_File,
Name => Filename1);
Open (File => File2,
Mode => In_File,
Name => Filename2);
-- Check length of files first.
if Size (File1) /= Size (File2) then
Close (File => File1);
Close (File => File2);
return False;
end if;
while not End_Of_File (File1) loop
-- Read one byte from both files.
Read (File => File1, Item => Char1);
Read (File => File2, Item => Char2);
-- Compare it.
if Char1 /= Char2 then
Result := False;
end if;
end loop;
-- Close them files again.
Close (File => File1);
Close (File => File2);
return Result;
end Assert_Files_Equal;
-------------------------------------------------------------------------
procedure Read_Loglevels
(Filename : String;
Default_Level : in out Log_Level;
Identifiers : out Maps.Wildcard_Level_Map)
is
Conf_File : Ada.Text_IO.File_Type;
Line_Count : Natural := 0;
Line : String (1 .. 1_024);
Last : Integer;
begin
Ada.Text_IO.Open (File => Conf_File,
Mode => Ada.Text_IO.In_File,
Name => Filename);
while not Ada.Text_IO.End_Of_File (File => Conf_File) loop
Ada.Text_IO.Get_Line
(File => Conf_File,
Item => Line,
Last => Last);
Line_Count := Line_Count + 1;
if Last - Line'First >= 0 then
declare
Trimmed : constant String := Ada.Strings.Fixed.Trim
(Source => Line (Line'First .. Last),
Side => Ada.Strings.Both);
Eq : Natural;
begin
if Trimmed'Length /= 0
and then Trimmed (Trimmed'First) /= '#'
then
Eq := Ada.Strings.Fixed.Index
(Source => Trimmed,
Pattern => "=");
if Eq not in Trimmed'First + 1 .. Trimmed'Last then
Ada.Text_IO.Close (File => Conf_File);
raise Invalid_Config with "Syntax error in file "
& Filename & " on line"
& Line_Count'Img & ": no assignment operator";
end if;
-- Line seems valid
declare
Key : constant String := Ada.Strings.Fixed.Trim
(Source => Trimmed (Trimmed'First .. Eq - 1),
Side => Ada.Strings.Both);
Value : constant String := Ada.Strings.Fixed.Trim
(Source => Trimmed (Eq + 1 .. Trimmed'Last),
Side => Ada.Strings.Both);
Loglevel : Log_Level;
begin
begin
Loglevel := Log_Level'Value (Value);
exception
when others =>
Ada.Text_IO.Close (File => Conf_File);
raise Invalid_Config with "Syntax error in file "
& Filename & " on line"
& Line_Count'Img & ": invalid loglevel '"
& Value & "'";
end;
if Key = "Default" or Key = "default" then
Default_Level := Loglevel;
else
Identifiers.Insert (Key => Key,
Item => Loglevel);
end if;
end;
end if;
end;
end if;
end loop;
Ada.Text_IO.Close (File => Conf_File);
end Read_Loglevels;
end Alog.Helpers;
|