Skip to content
This repository has been archived by the owner on May 1, 2021. It is now read-only.

Commit

Permalink
Updated sources
Browse files Browse the repository at this point in the history
---- log_filter_handlers ----
+ File header
+ Readability
+ Comments
Edited variables visibility
Removed Init_Objects procedure
---- log_filter ----
+ File header
+ Readability
+ Comments
Renamed Filter_Check into Check_Filters
Edited variables visibility
  • Loading branch information
Lyaaaaaaaaaaaaaaa authored Sep 20, 2019
1 parent f1dc838 commit cac2479
Show file tree
Hide file tree
Showing 5 changed files with 138 additions and 58 deletions.
50 changes: 35 additions & 15 deletions src/log_filter.adb
Original file line number Diff line number Diff line change
@@ -1,6 +1,27 @@
----------------------------------------------------------
-- Copyright (c), The MIT License (MIT)
-- Author: Lyaaaaaaaaaaaaaaa
--
-- Revision History:
-- 18/09/2019 Lyaaaaaaaaaaaaaaa
-- - Added file header
-- - Filter_Check becomes Check_Filters
----------------------------------------------------------

package body Log_Filter is

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

-------------------------------------------
-- Variables --
-------------------------------------------

File : File_Type;
Line : Unbounded_String;
Lines : Unbounded_String;
Lines_Count : Integer;

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

procedure Create_Filters (P_Number_Of_Filters : Natural;
P_User_Filters_Input : String;
Expand All @@ -12,7 +33,7 @@ package body Log_Filter is
subtype array_line_control is
Natural range 1 .. 40;

filters : store_filter (1 .. 40, 1..p_number_of_filters);
Filters : store_filter (1 .. 40, 1..p_number_of_filters);
Columns_Position : array_column_control := 1;
Lines_Position : array_line_control := 1;

Expand All @@ -21,26 +42,25 @@ package body Log_Filter is
for I in 1 .. P_Last_Inputs_Position loop

if P_User_Filters_Input (I) /= ' ' then

-- We use To_Lower to store filters in lower case in a variable.
-- So we won't miss the word carl because the user entered Carl.

filters (Lines_Position, Columns_Position) :=
Filters (Lines_Position, Columns_Position) :=
To_Lower (P_User_Filters_Input (I));

-- We use To_Lower to store filters in lower case in a variable.
-- So we won't miss the word carl because the user entered Carl.

Lines_Position := Lines_Position + 1;

if I = P_Last_Inputs_Position then

filters (Lines_Position, Columns_Position) := '|';
Filters (Lines_Position, Columns_Position) := '|';

end if;

elsif P_User_Filters_Input (I) = ' ' and I /= 1 then

if P_User_Filters_Input (I-1) /= ' ' then

filters (Lines_Position, Columns_Position) := '|';
Filters (Lines_Position, Columns_Position) := '|';
Lines_Position := 1;

if Columns_Position < p_number_of_filters then
Expand All @@ -53,7 +73,7 @@ package body Log_Filter is

end loop;

Read_File (filters, p_number_of_filters);
Read_File (Filters, p_number_of_filters);

end create_filters;

Expand All @@ -69,10 +89,10 @@ package body Log_Filter is

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

procedure Filter_Check (P_Filters : store_Filter;
P_Number_Of_Filters : Natural;
P_Word : String;
P_Filters_State : in out store_Filters_State) is
procedure Check_Filters (P_Filters : store_Filter;
P_Number_Of_Filters : Natural;
P_Word : String;
P_Filters_State : in out store_Filters_State) is

are_characters_identical : Boolean := true;

Expand Down Expand Up @@ -105,7 +125,7 @@ package body Log_Filter is

end loop;

end Filter_Check;
end Check_Filters;

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

Expand Down Expand Up @@ -192,7 +212,7 @@ package body Log_Filter is

elsif Element (line,I) = ' ' or End_Of_Line (file) = true then

Filter_Check (P_filters => P_filters,
Check_Filters (P_filters => P_filters,
P_number_of_filters => P_number_of_filters,
P_word => word,
P_Filters_State => P_Filters_State);
Expand Down
36 changes: 26 additions & 10 deletions src/log_filter.ads
Original file line number Diff line number Diff line change
@@ -1,24 +1,40 @@
----------------------------------------------------------
-- Copyright (c), The MIT License (MIT)
-- Author: Lyaaaaaaaaaaaaaaa
--
-- Revision History:
-- 18/09/2019 Lyaaaaaaaaaaaaaaa
-- - Added file header
-- - Filter_Check becomes Check_Filters
--
-- Encoding issues :
-- - Needs UTF-8 encoded files,
-- otherwise it will return wrong data.
--
-- Limitations :
-- - Filters can't be longer than 40 characters.
-- See array_line_control 's range in Create_Filters.
-- See Filters in Create_Filters and its subtype.
----------------------------------------------------------

with Text_IO; use Text_IO;
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
with Text_IO.Unbounded_IO;
with Ada.Characters.Handling; use Ada.Characters.Handling;

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

package Log_Filter is

-------------------------------------------
-- Variables --
-------------------------------------------

File : File_Type;
Line : Unbounded_String;
Lines : Unbounded_String;
Lines_Count : Integer;
----------------------------------------------------------

type Store_Filter is
array (Natural range <>, Natural range <>) of Character;

type Store_Filters_State is
array (Natural range <>) of Boolean;

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

--------------------------------------------
-- Procedures and functions --
Expand All @@ -36,7 +52,7 @@ package Log_Filter is
-- Inserts into 2D table "Store_Filter" input words in lower case.
-- Calls Read_File

procedure Filter_Check
procedure Check_Filters
(P_Filters : store_Filter;
P_Number_Of_Filters : Natural;
P_Word : String;
Expand All @@ -63,7 +79,7 @@ package Log_Filter is
P_Number_Of_Filters : Natural;
P_Filters_State : in out Store_Filters_State);
-- Reads Line character by character and inserts them into strings "Word"
-- Then, calls Filter_Check.
-- Then, calls Check_Filters.

procedure Reset_Lines;

Expand Down
40 changes: 33 additions & 7 deletions src/log_filter_handlers.adb
Original file line number Diff line number Diff line change
@@ -1,6 +1,39 @@
----------------------------------------------------------
-- Copyright (c), The MIT License (MIT)
-- Author: Lyaaaaaaaaaaaaaaa
--
-- Revision History:
-- 18/09/2019 Lyaaaaaaaaaaaaaaa
-- - Added file header
-- - Removed procedure Init_Objects (unused procedure)
----------------------------------------------------------

package body Log_Filter_Handlers is

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

-------------------------------------------
-- Variables --
-------------------------------------------

Error : aliased Glib.Error.GError;
Button_Start : Gtk_Button;
Builder : Gtkada_Builder;
Return_Code : Guint;
Main_Window : Gtk_Window;
Filters_Entry : Gtk_Entry_Buffer;
Application_Output : Gtk_Text_Buffer;
Button_Select_File : Gtk_Button;
Retour : Unbounded_String;
Help_Assistant : Gtk_Assistant;
Help_Menu_Item : Gtk_Menu_Item;
About_Menu_Item : Gtk_Menu_Item;
About_Dialog : Gtk_About_Dialog;
Spinner : Gtk_Spinner;
File_Label : Gtk_Label;

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

procedure Init is
begin

Expand Down Expand Up @@ -77,14 +110,7 @@ package body Log_Filter_Handlers is


end Register_Handlers;
----------------------------------------------------------

-- procedure Init_Objects is
-- begin


-- end Init_Objects;

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

procedure Start_Interface is
Expand Down
61 changes: 36 additions & 25 deletions src/log_filter_handlers.ads
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
----------------------------------------------------------
-- Copyright (c), The MIT License (MIT)
-- Author: Lyaaaaaaaaaaaaaaa
--
-- Revision History:
-- 18/09/2019 Lyaaaaaaaaaaaaaaa
-- - Added file header
-- - Removed procedure Init_Objects (unused procedure)
----------------------------------------------------------

----------------------
-- Gtk includes --
----------------------

with GtkAda;
with Gtk; use Gtk;
with Glib; use Glib;
with Gtk.Box; use Gtk.Box;
Expand All @@ -20,34 +35,34 @@ with Gtk.Entry_Buffer; use Gtk.Entry_Buffer;
with Gtk.About_Dialog; use Gtk.About_Dialog;
with Gtkada.File_Selection; use Gtkada.File_Selection;

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

----------------------
-- Ada includes --
----------------------

with Ada.Text_IO;
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;

-- Don't forget to delete the useless inclusions.
-- Custom include
----------------------------------------------------------

-------------------------
-- Custom includes --
-------------------------

with Log_Filter; use Log_Filter;

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

package Log_Filter_Handlers is
-- Init GtkAda, connect the interface file with the package
-- Connect the signals with the handlers.

Error : aliased Glib.Error.GError;
Button_Start : Gtk_Button;
Builder : Gtkada_Builder;
Return_Code : Guint;
Main_Window : Gtk_Window;
Filters_Entry : Gtk_Entry_Buffer;
Application_Output : Gtk_Text_Buffer;
Button_Select_File : Gtk_Button;
Retour : Unbounded_String;
Help_Assistant : Gtk_Assistant;
Help_Menu_Item : Gtk_Menu_Item;
About_Menu_Item : Gtk_Menu_Item;
About_Dialog : Gtk_About_Dialog;
Spinner : Gtk_Spinner;
File_Label : Gtk_Label;
----------------------------------------------------------

--------------------------------------------
-- Procedures and functions --
--------------------------------------------

procedure Init;
-- Inits will Initialize GTKAda and create the objetcs.
Expand All @@ -60,17 +75,13 @@ package Log_Filter_Handlers is
procedure Register_Handlers;
-- Links Gtk's signals with the Log_Filter_Handlers.

-- procedure Init_Objects;
-- -- Set up the parameters of the objects.

procedure Start_Interface;
-- Displays the main window and start gtk's loop.

procedure Quit
(Self : access Gtk_Widget_Record'Class);
-- Unreference the builder and shutdown the application.


-----------------
-- Buttons --
-----------------
Expand All @@ -81,7 +92,8 @@ package Log_Filter_Handlers is

procedure Button_Select_File_Clicked
(Self : access Gtk_Button_Record'Class);
-- WIP
-- The "Select file" button handler.
-- Close opened file, open file chooser dialog, display file's path

-------------------
-- Assistant --
Expand All @@ -96,7 +108,7 @@ package Log_Filter_Handlers is
-- Will show the next page of the assistant.

procedure Validate_Steps;
-- will validate the steps and unlock the "next" buttons.
-- will validate the steps (assistant dialog) and unlock the "next" buttons.

procedure Quit_Assistant
(self : access Gtk_Assistant_Record'Class);
Expand All @@ -121,7 +133,6 @@ package Log_Filter_Handlers is

function Status_Message
return String;
--Will format a text with the number of lines checked, how many valid
-- and the filters. WIP
-- Formats a text with the number of returned lines.

end Log_Filter_Handlers;
9 changes: 8 additions & 1 deletion src/log_filter_main.adb
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
--Custom include
----------------------------------------------------------
-- Copyright (c), The MIT License (MIT)
-- Author: Lyaaaaaaaaaaaaaaa
--
-- Revision History:
-- 18/09/2019 Lyaaaaaaaaaaaaaaa
-- - Added file header
----------------------------------------------------------

with Log_Filter_Handlers;

Expand Down

0 comments on commit cac2479

Please sign in to comment.