text
stringlengths
0
234
GCP_Map.Insert ("LOCAL_LISTEN_PORT", Parse_Local_Listen_Port'Access);
GCP_Map.Insert ("UPSTREAM_DNS_SERVER", Parse_Upstream_DNS_Server'Access);
GCP_Map.Insert
("UPSTREAM_DNS_SERVER_PORT", Parse_Upstream_DNS_Server_Port'Access);
end Initialize_Config_Parse;
procedure Read_Cfg_File
(Config : in out Configuration;
Config_File_Path : String)
is
Config_File : Ada.Text_IO.File_Type;
Line_Count : Integer := 1;
Exception_Message : Unbounded_String;
use GCP_Management;
begin
Initialize_Config_Parse;
-- Try to open the configuration file
Open
(File => Config_File,
Mode => Ada.Text_IO.In_File,
Name => Config_File_Path);
while not End_Of_File (Config_File)
loop
declare
Current_Line : constant String := Get_Line (Config_File);
Key_End_Loc : Integer := 0;
Equals_Loc : Integer := 0;
Value_Loc : Integer := 0;
Is_Whitespace : Boolean := True;
begin
-- Skip lines starting with a comment or blank
if Current_Line = ""
then
goto Config_Parse_Continue;
end if;
-- Has to be done seperately or it blows an index check
if Current_Line (1) = '#'
then
goto Config_Parse_Continue;
end if;
-- Skip line if its all whitespace
for I in Current_Line'range
loop
if Current_Line (I) /= ' ' and
Current_Line (I) /= Ada.Characters.Latin_1.HT
then
Is_Whitespace := False;
end if;
if Current_Line (I) = '='
then
Equals_Loc := I;
end if;
-- Determine length of the key
--
-- This is a little non-obvious at first glance. We subtract 2
-- here to remove the character we want, and the previous char
-- because a 17 char string will be 1..18 in the array.
if (Is_Whitespace or Current_Line (I) = '=') and Key_End_Loc = 0
then
Key_End_Loc := I - 2;
end if;
exit when Is_Whitespace and Equals_Loc /= 0;
-- We also want to confirm there's a = in there somewhere
end loop;
-- It's all whitespace, skip it
if Is_Whitespace
then
goto Config_Parse_Continue;
end if;
if Equals_Loc = 0
then
Exception_Message :=
To_Unbounded_String ("Malformed line (no = found) at");
Append (Exception_Message, Line_Count'Image);
Append (Exception_Message, ": ");
Append (Exception_Message, Current_Line);
raise Malformed_Line with To_String (Exception_Message);
end if;
-- Read in the essential values
for C in GCP_Map.Iterate
loop
-- Slightly annoying, but need to handle not reading past the
-- end of Current_Line. We also need to check that the next char
-- is a space or = so we don't match substrings by accident.
if Key_End_Loc = Key (C)'Length
then
if Key (C) = To_Upper (Current_Line
(1 .. Key (C)'Length))