mirror of https://github.com/berriedale/arun
Enabled warnings and style checks (GNAT style). Adapted the sources to match.
This commit is contained in:
parent
5993fca640
commit
bb6708f96b
|
@ -1,3 +1,4 @@
|
||||||
*.sw*
|
*.sw*
|
||||||
obj/
|
obj/
|
||||||
|
bin/
|
||||||
*.glade~
|
*.glade~
|
||||||
|
|
4
Makefile
4
Makefile
|
@ -1,14 +1,14 @@
|
||||||
|
|
||||||
GPRBUILD:=$(shell which gprbuild)
|
GPRBUILD:=$(shell which gprbuild)
|
||||||
GPRCLEAN:=$(shell which gprclean)
|
GPRCLEAN:=$(shell which gprclean)
|
||||||
EXE=obj/arun
|
EXE=bin/arun
|
||||||
GPRFILE=arun.gpr
|
GPRFILE=arun.gpr
|
||||||
RESOURCES=resources
|
RESOURCES=resources
|
||||||
|
|
||||||
all: $(EXE)
|
all: $(EXE)
|
||||||
|
|
||||||
$(EXE): prepare
|
$(EXE): prepare
|
||||||
$(GPRBUILD) -P$(GPRFILE) -cargs:c $(shell pkg-config --cflags gio-2.0)
|
$(GPRBUILD) -p -P$(GPRFILE) -cargs:c $(shell pkg-config --cflags gio-2.0)
|
||||||
|
|
||||||
prepare: src/arun-resources.c
|
prepare: src/arun-resources.c
|
||||||
mkdir -p obj
|
mkdir -p obj
|
||||||
|
|
8
arun.gpr
8
arun.gpr
|
@ -5,6 +5,7 @@ project Arun is
|
||||||
for Languages use ("Ada", "C");
|
for Languages use ("Ada", "C");
|
||||||
for Source_Dirs use ("src");
|
for Source_Dirs use ("src");
|
||||||
for Object_Dir use "obj";
|
for Object_Dir use "obj";
|
||||||
|
for Exec_Dir use "bin";
|
||||||
for Main use ("main.adb");
|
for Main use ("main.adb");
|
||||||
|
|
||||||
package Linker is
|
package Linker is
|
||||||
|
@ -20,7 +21,12 @@ project Arun is
|
||||||
for Switches ("Ada") use ("-gnat2012",
|
for Switches ("Ada") use ("-gnat2012",
|
||||||
"-fstack-check",
|
"-fstack-check",
|
||||||
"-gnata",
|
"-gnata",
|
||||||
"-gnato");
|
"-gnato",
|
||||||
|
"-gnatf", -- Full, verbose error messages
|
||||||
|
"-gnatwa", -- All optional warnings
|
||||||
|
"-gnatVa", -- All validity checks
|
||||||
|
"-gnaty3abcdefhiklmnoOprstux", -- Style checks
|
||||||
|
"-gnatwe"); -- Treat warnings as errors
|
||||||
end Compiler;
|
end Compiler;
|
||||||
|
|
||||||
end Arun;
|
end Arun;
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
---
|
---
|
||||||
-- Basic GtkAda handlers for Arun
|
-- Basic GtkAda handlers for Arun
|
||||||
---
|
---
|
||||||
------------------------------------------------------------------------------
|
------------------------------------------------------------------------------
|
||||||
--
|
--
|
||||||
|
@ -17,18 +17,16 @@
|
||||||
--
|
--
|
||||||
-- You should have received a copy of the GNU General Public License
|
-- You should have received a copy of the GNU General Public License
|
||||||
-- along with this program; if not, write to the Free Software
|
-- along with this program; if not, write to the Free Software
|
||||||
-- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
-- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||||
|
-- 02110-1301, USA.
|
||||||
------------------------------------------------------------------------------
|
------------------------------------------------------------------------------
|
||||||
|
|
||||||
with Ada.Text_IO;
|
with Ada.Text_IO;
|
||||||
with GNAT.OS_Lib;
|
|
||||||
with Gdk.Event;
|
|
||||||
with Gdk.Types.Keysyms;
|
with Gdk.Types.Keysyms;
|
||||||
with Glib;
|
with Glib;
|
||||||
with Gtk.Main;
|
with Gtk.Main;
|
||||||
with Gtk.Widget;
|
|
||||||
with Gtk.Search_Entry;
|
with Gtk.Search_Entry;
|
||||||
with Gtkada.Builder; use Gtkada.Builder;
|
|
||||||
|
|
||||||
with GNAT.String_Split;
|
with GNAT.String_Split;
|
||||||
|
|
||||||
|
@ -38,35 +36,10 @@ with Arun.View; use Arun.View;
|
||||||
|
|
||||||
package body Arun.Handlers is
|
package body Arun.Handlers is
|
||||||
|
|
||||||
procedure Quit (Object : access Gtkada_Builder_Record'Class) is
|
use Gtkada.Builder;
|
||||||
pragma Unreferenced (Object);
|
|
||||||
begin
|
|
||||||
Ada.Text_IO.Put_Line ("Exiting arun");
|
|
||||||
Gtk.Main.Main_Quit;
|
|
||||||
end Quit;
|
|
||||||
|
|
||||||
procedure Search_Changed (Object : access Gtkada_Builder_Record'Class) is
|
function Slice_Command (Text : in String)
|
||||||
use Ada.Text_IO;
|
return GNAT.String_Split.Slice_Set;
|
||||||
use Gtk.Search_Entry;
|
|
||||||
use Gtkada.Builder;
|
|
||||||
|
|
||||||
Widget : Gtk_Search_Entry := Gtk_Search_Entry (Get_Object (Object, "commandEntry"));
|
|
||||||
begin
|
|
||||||
Put_Line ("Searching for " & Widget.Get_Text);
|
|
||||||
end Search_Changed;
|
|
||||||
|
|
||||||
|
|
||||||
function Slice_Command (Text : in String) return GNAT.String_Split.Slice_Set is
|
|
||||||
use GNAT.String_Split;
|
|
||||||
|
|
||||||
Separator : constant String := " ";
|
|
||||||
Slices : Slice_Set;
|
|
||||||
begin
|
|
||||||
|
|
||||||
Create (Slices, Text, Separator, Single);
|
|
||||||
|
|
||||||
return Slices;
|
|
||||||
end Slice_Command;
|
|
||||||
|
|
||||||
procedure Execute_Command (Object : access Gtkada_Builder_Record'Class) is
|
procedure Execute_Command (Object : access Gtkada_Builder_Record'Class) is
|
||||||
use Ada.Text_IO;
|
use Ada.Text_IO;
|
||||||
|
@ -74,10 +47,11 @@ package body Arun.Handlers is
|
||||||
use Gtkada.Builder;
|
use Gtkada.Builder;
|
||||||
use GNAT.String_Split;
|
use GNAT.String_Split;
|
||||||
|
|
||||||
Widget : Gtk_Search_Entry := Gtk_Search_Entry (Get_Object (Object, "commandEntry"));
|
Widget : constant Gtk_Search_Entry :=
|
||||||
Builder : Arun.View.Arun_Builder_Record renames Arun.View.Arun_Builder_Record (Object.all);
|
Gtk_Search_Entry (Get_Object (Object, "commandEntry"));
|
||||||
L : Arun.Launchers.Unix.UnixLauncher renames Arun.Launchers.Unix.UnixLauncher (Builder.Launcher);
|
Builder : Arun.View.Arun_Builder_Record
|
||||||
|
renames Arun.View.Arun_Builder_Record (Object.all);
|
||||||
|
L : Arun.Launchers.Unix.UnixLauncher renames Builder.Launcher;
|
||||||
|
|
||||||
Slices : constant Slice_Set := Slice_Command (Widget.Get_Text);
|
Slices : constant Slice_Set := Slice_Command (Widget.Get_Text);
|
||||||
Command : constant String := Slice (S => Slices, Index => 1);
|
Command : constant String := Slice (S => Slices, Index => 1);
|
||||||
|
@ -92,32 +66,66 @@ package body Arun.Handlers is
|
||||||
Gtk.Main.Main_Quit;
|
Gtk.Main.Main_Quit;
|
||||||
end Execute_Command;
|
end Execute_Command;
|
||||||
|
|
||||||
function Search_KeyPress (Widget : access Gtk.Widget.Gtk_Widget_Record'Class;
|
procedure Quit (Object : access Gtkada_Builder_Record'Class) is
|
||||||
Event : in Gdk.Event.Gdk_Event_Key) return Boolean is
|
pragma Unreferenced (Object);
|
||||||
|
begin
|
||||||
|
Ada.Text_IO.Put_Line ("Exiting arun");
|
||||||
|
Gtk.Main.Main_Quit;
|
||||||
|
end Quit;
|
||||||
|
|
||||||
|
procedure Search_Changed (Object : access Gtkada_Builder_Record'Class) is
|
||||||
|
use Ada.Text_IO;
|
||||||
|
use Gtk.Search_Entry;
|
||||||
|
use Gtkada.Builder;
|
||||||
|
|
||||||
|
Widget : constant Gtk_Search_Entry :=
|
||||||
|
Gtk_Search_Entry (Get_Object (Object, "commandEntry"));
|
||||||
|
begin
|
||||||
|
Put_Line ("Searching for " & Widget.Get_Text);
|
||||||
|
end Search_Changed;
|
||||||
|
|
||||||
|
function Search_Keypress
|
||||||
|
(Widget : access Gtk.Widget.Gtk_Widget_Record'Class;
|
||||||
|
Event : in Gdk.Event.Gdk_Event_Key) return Boolean
|
||||||
|
is
|
||||||
use Ada.Text_IO;
|
use Ada.Text_IO;
|
||||||
use Gdk.Types;
|
use Gdk.Types;
|
||||||
use Gdk.Types.Keysyms;
|
use Gdk.Types.Keysyms;
|
||||||
begin
|
begin
|
||||||
|
|
||||||
if Event.Keyval = GDK_Tab then
|
if Event.Keyval = GDK_Tab then
|
||||||
-- When the Tab key is presented, let's assume the user is finishing
|
-- When the Tab key is presented, let's assume the user is
|
||||||
-- an auto-complete operation jump to the end so
|
-- finishing an auto-complete operation jump to the end so
|
||||||
-- they can add arguments if desired
|
-- they can add arguments if desired
|
||||||
declare
|
declare
|
||||||
use Glib;
|
use Glib;
|
||||||
Search_Entry : Gtk.Search_Entry.Gtk_Search_Entry_Record renames Gtk.Search_Entry.Gtk_Search_Entry_Record (Widget.all);
|
Search_Entry : Gtk.Search_Entry.Gtk_Search_Entry_Record
|
||||||
|
renames Gtk.Search_Entry.Gtk_Search_Entry_Record (Widget.all);
|
||||||
begin
|
begin
|
||||||
Search_Entry.Set_Position (-1);
|
Search_Entry.Set_Position (-1);
|
||||||
end;
|
end;
|
||||||
end if;
|
end if;
|
||||||
|
|
||||||
|
|
||||||
if Event.Keyval = GDK_Escape then
|
if Event.Keyval = GDK_Escape then
|
||||||
Put_Line ("Escape! Exiting arun");
|
Put_Line ("Escape! Exiting arun");
|
||||||
Gtk.Main.Main_Quit;
|
Gtk.Main.Main_Quit;
|
||||||
end if;
|
end if;
|
||||||
|
|
||||||
return True;
|
return True;
|
||||||
end Search_KeyPress;
|
end Search_Keypress;
|
||||||
|
|
||||||
|
function Slice_Command (Text : in String)
|
||||||
|
return GNAT.String_Split.Slice_Set
|
||||||
|
is
|
||||||
|
use GNAT.String_Split;
|
||||||
|
|
||||||
|
Separator : constant String := " ";
|
||||||
|
Slices : Slice_Set;
|
||||||
|
begin
|
||||||
|
|
||||||
|
Create (Slices, Text, Separator, Single);
|
||||||
|
|
||||||
|
return Slices;
|
||||||
|
end Slice_Command;
|
||||||
|
|
||||||
end Arun.Handlers;
|
end Arun.Handlers;
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
---
|
---
|
||||||
-- Basic GtkAda handlers for Arun
|
-- Basic GtkAda handlers for Arun
|
||||||
---
|
---
|
||||||
------------------------------------------------------------------------------
|
------------------------------------------------------------------------------
|
||||||
--
|
--
|
||||||
|
@ -17,31 +17,32 @@
|
||||||
--
|
--
|
||||||
-- You should have received a copy of the GNU General Public License
|
-- You should have received a copy of the GNU General Public License
|
||||||
-- along with this program; if not, write to the Free Software
|
-- along with this program; if not, write to the Free Software
|
||||||
-- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
-- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||||
|
-- 02110-1301, USA.
|
||||||
------------------------------------------------------------------------------
|
------------------------------------------------------------------------------
|
||||||
|
|
||||||
with Gtkada.Builder; use Gtkada.Builder;
|
with Gtkada.Builder; use Gtkada.Builder;
|
||||||
with Gtk.Widget;
|
with Gtk.Widget;
|
||||||
with Gdk.Event;
|
with Gdk.Event;
|
||||||
|
|
||||||
with Arun.Launchers.Unix;
|
|
||||||
|
|
||||||
with Arun.View; use Arun.View;
|
|
||||||
|
|
||||||
package Arun.Handlers is
|
package Arun.Handlers is
|
||||||
|
|
||||||
procedure Quit (Object : access Gtkada_Builder_Record'Class);
|
procedure Quit (Object : access Gtkada_Builder_Record'Class);
|
||||||
|
|
||||||
|
-- Whenever the search entry changes call this handler for
|
||||||
|
-- autocompletion
|
||||||
|
--
|
||||||
procedure Search_Changed (Object : access Gtkada_Builder_Record'Class);
|
procedure Search_Changed (Object : access Gtkada_Builder_Record'Class);
|
||||||
-- Whenever the search entry changes call this handler for autocompletion
|
|
||||||
|
|
||||||
|
-- On "activate" of the search entry call this handler (basically
|
||||||
|
-- when the user hits the enter key
|
||||||
|
--
|
||||||
procedure Execute_Command (Object : access Gtkada_Builder_Record'Class);
|
procedure Execute_Command (Object : access Gtkada_Builder_Record'Class);
|
||||||
-- On "activate" of the search entry call this handler (basically when the user
|
|
||||||
-- hits the enter key
|
|
||||||
|
|
||||||
function Search_KeyPress (Widget : access Gtk.Widget.Gtk_Widget_Record'Class;
|
|
||||||
Event : in Gdk.Event.Gdk_Event_Key) return Boolean;
|
|
||||||
-- On key-presses in the commandEntry field
|
|
||||||
|
|
||||||
|
-- On key-presses in the commandEntry field
|
||||||
|
--
|
||||||
|
function Search_Keypress
|
||||||
|
(Widget : access Gtk.Widget.Gtk_Widget_Record'Class;
|
||||||
|
Event : in Gdk.Event.Gdk_Event_Key) return Boolean;
|
||||||
|
|
||||||
end Arun.Handlers;
|
end Arun.Handlers;
|
||||||
|
|
|
@ -14,120 +14,44 @@
|
||||||
--
|
--
|
||||||
-- You should have received a copy of the GNU General Public License
|
-- You should have received a copy of the GNU General Public License
|
||||||
-- along with this program; if not, write to the Free Software
|
-- along with this program; if not, write to the Free Software
|
||||||
-- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
-- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||||
|
-- 02110-1301, USA.
|
||||||
------------------------------------------------------------------------------
|
------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
with Ada.Text_IO; use Ada.Text_IO;
|
with Ada.Text_IO; use Ada.Text_IO;
|
||||||
with Ada.Command_Line.Environment;
|
|
||||||
with Ada.Environment_Variables;
|
with Ada.Environment_Variables;
|
||||||
|
|
||||||
with GNAT.Directory_Operations;
|
with GNAT.Directory_Operations;
|
||||||
with GNAT.OS_Lib;
|
with GNAT.OS_Lib;
|
||||||
with GNAT.String_Split;
|
|
||||||
with Interfaces.C;
|
with Interfaces.C;
|
||||||
with Interfaces.C.Strings;
|
with Interfaces.C.Strings;
|
||||||
|
|
||||||
|
|
||||||
package body Arun.Launchers.Unix is
|
package body Arun.Launchers.Unix is
|
||||||
|
|
||||||
procedure Initialize (L : in out UnixLauncher) is
|
function Exec_And_Replace
|
||||||
use Gnat.String_Split;
|
(Filename : in Interfaces.C.char_array;
|
||||||
|
Arguments : in Interfaces.C.Strings.chars_ptr_array) return Integer
|
||||||
PATH : constant String := Ada.Environment_Variables.Value ("PATH");
|
|
||||||
Separator : constant String := ":";
|
|
||||||
begin
|
|
||||||
|
|
||||||
Create (L.Path_Components, PATH, Separator, Single);
|
|
||||||
L.Initialized := True;
|
|
||||||
end Initialize;
|
|
||||||
|
|
||||||
|
|
||||||
function Find_Full_Path (L : in UnixLauncher;
|
|
||||||
Path_Snippet : in String) return String is
|
|
||||||
use GNAT.String_Split;
|
|
||||||
begin
|
|
||||||
|
|
||||||
if L.Initialized /= True then
|
|
||||||
Put_Line ("Uninitialized UnixLauncher!");
|
|
||||||
return "";
|
|
||||||
end if;
|
|
||||||
|
|
||||||
for Index in 1 .. Slice_Count (L.Path_Components) loop
|
|
||||||
Put_Line ("Looking for an executable in " & Slice (S => L.Path_Components,
|
|
||||||
Index => Index));
|
|
||||||
declare
|
|
||||||
Path_Component : constant String := Slice (S => L.Path_Components,
|
|
||||||
Index => Index);
|
|
||||||
Computed_Location : constant String := Path_Component & "/" & Path_Snippet;
|
|
||||||
begin
|
|
||||||
|
|
||||||
if GNAT.OS_Lib.Is_Executable_File (Computed_Location) then
|
|
||||||
Put_Line ("Found executable at " & Computed_Location);
|
|
||||||
return Computed_Location;
|
|
||||||
end if;
|
|
||||||
end;
|
|
||||||
|
|
||||||
end loop;
|
|
||||||
|
|
||||||
return "";
|
|
||||||
end Find_Full_Path;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function Exec_And_Replace (Filename : in Interfaces.C.Char_Array;
|
|
||||||
Arguments : in Interfaces.C.Strings.Chars_Ptr_Array) return Integer
|
|
||||||
with Import,
|
with Import,
|
||||||
Convention => C,
|
Convention => C,
|
||||||
Link_Name => "execv";
|
Link_Name => "execv";
|
||||||
|
|
||||||
procedure Print_Errno (Message : in String)
|
procedure Print_Errno (Message : in String)
|
||||||
with Import,
|
with Import,
|
||||||
Convention => C,
|
Convention => C,
|
||||||
Link_Name => "perror";
|
Link_Name => "perror";
|
||||||
|
|
||||||
procedure Execute (L : in UnixLauncher;
|
overriding
|
||||||
Executable_Path : in String;
|
function Discover_Executables (L : in UnixLauncher)
|
||||||
Argv : in GNAT.String_Split.Slice_Set) is
|
return Arun.String_Vectors.Vector
|
||||||
use GNAT.String_Split;
|
is
|
||||||
use Interfaces.C;
|
|
||||||
use Interfaces.C.Strings;
|
|
||||||
|
|
||||||
Status : Integer;
|
|
||||||
Argc : constant Size_T := Size_T (Slice_Count (Argv));
|
|
||||||
Arguments : Chars_Ptr_Array (1 .. (Argc + 1)) := (others => Null_Ptr);
|
|
||||||
begin
|
|
||||||
-- For the first argument, we must replace the executable name with
|
|
||||||
-- the full path, e.g. "xeyes" => "/usr/bin/xeyes"
|
|
||||||
Arguments (1) := New_String (Executable_Path);
|
|
||||||
for Index in 1 .. Argc loop
|
|
||||||
Arguments (Index) := New_String (Slice (S => Argv,
|
|
||||||
Index => Slice_Number (Index)));
|
|
||||||
end loop;
|
|
||||||
|
|
||||||
Put_Line ("Spawning " & Executable_Path);
|
|
||||||
|
|
||||||
Status := Exec_And_Replace (Filename => To_C (Item => Executable_Path,
|
|
||||||
Append_Nul => True),
|
|
||||||
Arguments => Arguments);
|
|
||||||
|
|
||||||
-- If the Exec_And_Replace function returns then something has gone wrong
|
|
||||||
if Status /= 0 then
|
|
||||||
Print_Errno ("Something went wrong");
|
|
||||||
end if;
|
|
||||||
end Execute;
|
|
||||||
|
|
||||||
|
|
||||||
function Discover_Executables (L : in UnixLauncher) return Arun.String_Vectors.Vector is
|
|
||||||
use GNAT.Directory_Operations;
|
use GNAT.Directory_Operations;
|
||||||
use GNAT.OS_Lib;
|
use GNAT.OS_Lib;
|
||||||
use GNAT.String_Split;
|
use GNAT.String_Split;
|
||||||
use Ada.Strings.Unbounded;
|
use Ada.Strings.Unbounded;
|
||||||
|
|
||||||
Dir : Dir_Type;
|
Dir : Dir_Type;
|
||||||
File_Name : String (1 .. MAX_FILENAME_LENGTH);
|
File_Name : String (1 .. MAX_FILENAME_LENGTH);
|
||||||
File_Index : Natural := 0;
|
File_Index : Natural := 0;
|
||||||
Executables : Arun.String_Vectors.Vector;
|
Executables : Arun.String_Vectors.Vector;
|
||||||
begin
|
begin
|
||||||
for Index in 1 .. Slice_Count (L.Path_Components) loop
|
for Index in 1 .. Slice_Count (L.Path_Components) loop
|
||||||
|
@ -155,5 +79,86 @@ package body Arun.Launchers.Unix is
|
||||||
return Executables;
|
return Executables;
|
||||||
end Discover_Executables;
|
end Discover_Executables;
|
||||||
|
|
||||||
|
overriding
|
||||||
|
procedure Execute (L : in UnixLauncher;
|
||||||
|
Executable_Path : in String;
|
||||||
|
Argv : in GNAT.String_Split.Slice_Set) is
|
||||||
|
pragma Unreferenced (L);
|
||||||
|
|
||||||
|
use GNAT.String_Split;
|
||||||
|
use Interfaces.C;
|
||||||
|
use Interfaces.C.Strings;
|
||||||
|
|
||||||
|
Status : Integer;
|
||||||
|
Argc : constant size_t := size_t (Slice_Count (Argv));
|
||||||
|
Arguments : chars_ptr_array (1 .. (Argc + 1)) := (others => Null_Ptr);
|
||||||
|
begin
|
||||||
|
-- For the first argument, we must replace the executable name
|
||||||
|
-- with the full path, e.g. "xeyes" => "/usr/bin/xeyes"
|
||||||
|
Arguments (1) := New_String (Executable_Path);
|
||||||
|
for Index in 1 .. Argc loop
|
||||||
|
Arguments (Index) :=
|
||||||
|
New_String (Slice (S => Argv,
|
||||||
|
Index => Slice_Number (Index)));
|
||||||
|
end loop;
|
||||||
|
|
||||||
|
Put_Line ("Spawning " & Executable_Path);
|
||||||
|
|
||||||
|
Status :=
|
||||||
|
Exec_And_Replace (Filename => To_C (Item => Executable_Path,
|
||||||
|
Append_Nul => True),
|
||||||
|
Arguments => Arguments);
|
||||||
|
|
||||||
|
-- If the Exec_And_Replace function returns then something has
|
||||||
|
-- gone wrong
|
||||||
|
if Status /= 0 then
|
||||||
|
Print_Errno ("Something went wrong");
|
||||||
|
end if;
|
||||||
|
end Execute;
|
||||||
|
|
||||||
|
overriding
|
||||||
|
function Find_Full_Path (L : in UnixLauncher;
|
||||||
|
Path_Snippet : in String) return String is
|
||||||
|
use GNAT.String_Split;
|
||||||
|
begin
|
||||||
|
|
||||||
|
if not L.Initialized then
|
||||||
|
Put_Line ("Uninitialized UnixLauncher!");
|
||||||
|
return "";
|
||||||
|
end if;
|
||||||
|
|
||||||
|
for Index in 1 .. Slice_Count (L.Path_Components) loop
|
||||||
|
Put_Line ("Looking for an executable in " &
|
||||||
|
Slice (S => L.Path_Components,
|
||||||
|
Index => Index));
|
||||||
|
declare
|
||||||
|
Path_Component : constant String :=
|
||||||
|
Slice (S => L.Path_Components,
|
||||||
|
Index => Index);
|
||||||
|
Computed_Location : constant String :=
|
||||||
|
Path_Component & "/" & Path_Snippet;
|
||||||
|
begin
|
||||||
|
|
||||||
|
if GNAT.OS_Lib.Is_Executable_File (Computed_Location) then
|
||||||
|
Put_Line ("Found executable at " & Computed_Location);
|
||||||
|
return Computed_Location;
|
||||||
|
end if;
|
||||||
|
end;
|
||||||
|
|
||||||
|
end loop;
|
||||||
|
|
||||||
|
return "";
|
||||||
|
end Find_Full_Path;
|
||||||
|
|
||||||
|
procedure Initialize (L : in out UnixLauncher) is
|
||||||
|
use GNAT.String_Split;
|
||||||
|
|
||||||
|
PATH : constant String := Ada.Environment_Variables.Value ("PATH");
|
||||||
|
Separator : constant String := ":";
|
||||||
|
begin
|
||||||
|
|
||||||
|
Create (L.Path_Components, PATH, Separator, Single);
|
||||||
|
L.Initialized := True;
|
||||||
|
end Initialize;
|
||||||
|
|
||||||
end Arun.Launchers.Unix;
|
end Arun.Launchers.Unix;
|
||||||
|
|
|
@ -14,7 +14,8 @@
|
||||||
--
|
--
|
||||||
-- You should have received a copy of the GNU General Public License
|
-- You should have received a copy of the GNU General Public License
|
||||||
-- along with this program; if not, write to the Free Software
|
-- along with this program; if not, write to the Free Software
|
||||||
-- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
-- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||||
|
-- 02110-1301, USA.
|
||||||
------------------------------------------------------------------------------
|
------------------------------------------------------------------------------
|
||||||
|
|
||||||
with Arun;
|
with Arun;
|
||||||
|
@ -29,27 +30,33 @@ package Arun.Launchers.Unix is
|
||||||
|
|
||||||
procedure Initialize (L : in out UnixLauncher);
|
procedure Initialize (L : in out UnixLauncher);
|
||||||
|
|
||||||
|
-- Determine the full path of the snippet based on PATH or other
|
||||||
|
-- environment variables.
|
||||||
|
--
|
||||||
|
-- Will return an empty string if a full path was not discoverable.
|
||||||
|
--
|
||||||
|
overriding
|
||||||
function Find_Full_Path (L : in UnixLauncher;
|
function Find_Full_Path (L : in UnixLauncher;
|
||||||
Path_Snippet : in String) return String;
|
Path_Snippet : in String) return String;
|
||||||
-- Determine the full path of the snippet based on PATH or other environment
|
|
||||||
-- variables.
|
-- Execute a command using the given UnixLauncher with an "Argv"
|
||||||
|
-- Slice_Set assuming the first argument is the command and
|
||||||
|
-- subsequent values are arguments for that command.
|
||||||
--
|
--
|
||||||
-- Will return an empty string if a full path was not discoverable.
|
overriding
|
||||||
|
|
||||||
|
|
||||||
procedure Execute (L : in UnixLauncher;
|
procedure Execute (L : in UnixLauncher;
|
||||||
Executable_Path : in String;
|
Executable_Path : in String;
|
||||||
Argv : in GNAT.String_Split.Slice_Set);
|
Argv : in GNAT.String_Split.Slice_Set);
|
||||||
-- Execute a command using the given UnixLauncher with an "Argv"
|
|
||||||
-- Slice_Set assuming the first argument is the command and subsequent values
|
|
||||||
-- are arguments for that command.
|
|
||||||
|
|
||||||
function Discover_Executables (L : in UnixLauncher) return Arun.String_Vectors.Vector;
|
overriding
|
||||||
|
function Discover_Executables (L : in UnixLauncher)
|
||||||
|
return Arun.String_Vectors.Vector;
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
type UnixLauncher is new Arun.Launcher_Type with record
|
type UnixLauncher is new Arun.Launcher_Type with record
|
||||||
Initialized : Boolean := False;
|
Initialized : Boolean := False;
|
||||||
Path_Components : Gnat.String_Split.Slice_Set;
|
Path_Components : GNAT.String_Split.Slice_Set;
|
||||||
end record;
|
end record;
|
||||||
|
|
||||||
end Arun.Launchers.Unix;
|
end Arun.Launchers.Unix;
|
||||||
|
|
|
@ -14,9 +14,9 @@
|
||||||
--
|
--
|
||||||
-- You should have received a copy of the GNU General Public License
|
-- You should have received a copy of the GNU General Public License
|
||||||
-- along with this program; if not, write to the Free Software
|
-- along with this program; if not, write to the Free Software
|
||||||
-- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
-- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||||
|
-- 02110-1301, USA.
|
||||||
------------------------------------------------------------------------------
|
------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
package Arun.Launchers is
|
package Arun.Launchers is
|
||||||
end Arun.Launchers;
|
end Arun.Launchers;
|
||||||
|
|
|
@ -14,21 +14,20 @@
|
||||||
--
|
--
|
||||||
-- You should have received a copy of the GNU General Public License
|
-- You should have received a copy of the GNU General Public License
|
||||||
-- along with this program; if not, write to the Free Software
|
-- along with this program; if not, write to the Free Software
|
||||||
-- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
-- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||||
|
-- 02110-1301, USA.
|
||||||
------------------------------------------------------------------------------
|
------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
with Gtk.Widget; use Gtk.Widget;
|
with Gtk.Widget; use Gtk.Widget;
|
||||||
with Ada.Text_IO;
|
|
||||||
|
|
||||||
package body Arun.View is
|
package body Arun.View is
|
||||||
|
|
||||||
function From_Object (Builder : out Arun_Builder_Record'Class;
|
function From_Object (Builder : out Arun_Builder_Record'Class;
|
||||||
Object_Name : in String) return Gtk_Widget is
|
Object_Name : in String) return Gtk_Widget is
|
||||||
-- Return the Gtk_Widget for the specified Object_Name in the Builder.
|
-- Return the Gtk_Widget for the specified Object_Name in the Builder.
|
||||||
-- Basically pass the name of the widget given in Glade.
|
-- Basically pass the name of the widget given in Glade.
|
||||||
begin
|
begin
|
||||||
return Gtk_Widget (Builder.Get_Object (Object_Name));
|
return Gtk_Widget (Builder.Get_Object (Object_Name));
|
||||||
end From_Object;
|
end From_Object;
|
||||||
|
|
||||||
end Arun.View;
|
end Arun.View;
|
||||||
|
|
|
@ -14,7 +14,8 @@
|
||||||
--
|
--
|
||||||
-- You should have received a copy of the GNU General Public License
|
-- You should have received a copy of the GNU General Public License
|
||||||
-- along with this program; if not, write to the Free Software
|
-- along with this program; if not, write to the Free Software
|
||||||
-- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
-- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||||
|
-- 02110-1301, USA.
|
||||||
------------------------------------------------------------------------------
|
------------------------------------------------------------------------------
|
||||||
|
|
||||||
with Gtkada.Builder; use Gtkada.Builder;
|
with Gtkada.Builder; use Gtkada.Builder;
|
||||||
|
|
103
src/arun.adb
103
src/arun.adb
|
@ -14,14 +14,10 @@
|
||||||
--
|
--
|
||||||
-- You should have received a copy of the GNU General Public License
|
-- You should have received a copy of the GNU General Public License
|
||||||
-- along with this program; if not, write to the Free Software
|
-- along with this program; if not, write to the Free Software
|
||||||
-- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
-- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||||
|
-- 02110-1301, USA.
|
||||||
------------------------------------------------------------------------------
|
------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
with GNAT.OS_Lib;
|
|
||||||
with GNAT.Directory_Operations;
|
|
||||||
with Ada.Strings.Unbounded;
|
|
||||||
|
|
||||||
with Gtk.Widget; use Gtk.Widget;
|
with Gtk.Widget; use Gtk.Widget;
|
||||||
with Gtk.GEntry;
|
with Gtk.GEntry;
|
||||||
with Gtk.Entry_Completion;
|
with Gtk.Entry_Completion;
|
||||||
|
@ -40,47 +36,9 @@ with Arun.View;
|
||||||
|
|
||||||
package body Arun is
|
package body Arun is
|
||||||
|
|
||||||
procedure Rig_Autocomplete (Builder : in Arun.View.Arun_Builder) is
|
-- Rig up the autocomplete support for the "commandEntry"
|
||||||
-- Rig up the autocomplete support for the "commandEntry"
|
--
|
||||||
|
procedure Rig_Autocomplete (Builder : in Arun.View.Arun_Builder);
|
||||||
use Gtk.Entry_Completion;
|
|
||||||
use Gtk.List_Store;
|
|
||||||
use Gtk.Tree_Model;
|
|
||||||
use Ada.Strings.Unbounded;
|
|
||||||
|
|
||||||
Completion_Types : constant GType_Array (1 .. 1) := (1 => GType_String);
|
|
||||||
Items : Gtk_List_Store := Gtk_List_Store_Newv (Types => Completion_Types);
|
|
||||||
Iter : Gtk_Tree_Iter;
|
|
||||||
Command_Entry : Gtk.GEntry.Gtk_Entry := Gtk.GEntry.Gtk_Entry (Builder.From_Object ("commandEntry"));
|
|
||||||
Command_Completion : aliased Gtk_Entry_Completion := Gtk_Entry_Completion_New;
|
|
||||||
|
|
||||||
Completion_String : Glib.Values.GValue;
|
|
||||||
|
|
||||||
Executables : String_Vectors.Vector := Builder.Launcher.Discover_Executables;
|
|
||||||
begin
|
|
||||||
for Element of Executables loop
|
|
||||||
Items.Append (Iter);
|
|
||||||
Glib.Values.Init_Set_String (Completion_String,
|
|
||||||
To_String (Element));
|
|
||||||
Items.Set_Value (Iter, 0, Completion_String);
|
|
||||||
end loop;
|
|
||||||
|
|
||||||
Command_Completion.Set_Model (Items.To_Interface);
|
|
||||||
Command_Completion.Set_Text_Column (Column => 0);
|
|
||||||
Command_Completion.Set_Inline_Completion (True);
|
|
||||||
Command_Completion.Set_Inline_Selection (True);
|
|
||||||
Command_Entry.Set_Completion (Completion => Command_Completion);
|
|
||||||
Command_Entry.On_Key_Release_Event (Call => Arun.Handlers.Search_KeyPress'Access,
|
|
||||||
After => False);
|
|
||||||
end Rig_Autocomplete;
|
|
||||||
|
|
||||||
function Compare_Strings (Left : in Ada.Strings.Unbounded.Unbounded_String;
|
|
||||||
Right : in Ada.Strings.Unbounded.Unbounded_String) return Boolean is
|
|
||||||
-- Simple comparision function for the String_Vector
|
|
||||||
use Ada.Strings.Unbounded;
|
|
||||||
begin
|
|
||||||
return Left = Right;
|
|
||||||
end Compare_Strings;
|
|
||||||
|
|
||||||
procedure Main is
|
procedure Main is
|
||||||
use Ada.Text_IO;
|
use Ada.Text_IO;
|
||||||
|
@ -98,13 +56,17 @@ package body Arun is
|
||||||
Gtkada.Builder.Initialize (Builder);
|
Gtkada.Builder.Initialize (Builder);
|
||||||
Builder.Launcher.Initialize;
|
Builder.Launcher.Initialize;
|
||||||
|
|
||||||
Return_Code := Add_From_Resource (Builder => Builder,
|
Return_Code :=
|
||||||
Resource_Path => "/io/lasagna/arun/arun.glade",
|
Add_From_Resource (Builder => Builder,
|
||||||
Error => Error'Access);
|
Resource_Path => "/io/lasagna/arun/arun.glade",
|
||||||
|
Error => Error'Access);
|
||||||
if Error /= null then
|
if Error /= null then
|
||||||
Put_Line ("Error : " & Get_Message (Error));
|
Put_Line ("Error : " & Get_Message (Error));
|
||||||
Error_Free (Error);
|
Error_Free (Error);
|
||||||
return;
|
return;
|
||||||
|
elsif Return_Code /= 0 then
|
||||||
|
Put_Line ("Error " & Return_Code'Image);
|
||||||
|
return;
|
||||||
end if;
|
end if;
|
||||||
|
|
||||||
Register_Handler (Builder => Builder,
|
Register_Handler (Builder => Builder,
|
||||||
|
@ -125,4 +87,45 @@ package body Arun is
|
||||||
Gtk.Main.Main;
|
Gtk.Main.Main;
|
||||||
Unref (Builder);
|
Unref (Builder);
|
||||||
end Main;
|
end Main;
|
||||||
|
|
||||||
|
procedure Rig_Autocomplete (Builder : in Arun.View.Arun_Builder) is
|
||||||
|
|
||||||
|
use Gtk.Entry_Completion;
|
||||||
|
use Gtk.List_Store;
|
||||||
|
use Gtk.Tree_Model;
|
||||||
|
use Ada.Strings.Unbounded;
|
||||||
|
|
||||||
|
Completion_Types : constant GType_Array (1 .. 1) :=
|
||||||
|
(1 => GType_String);
|
||||||
|
Items : constant Gtk_List_Store :=
|
||||||
|
Gtk_List_Store_Newv (Types => Completion_Types);
|
||||||
|
Iter : Gtk_Tree_Iter;
|
||||||
|
Command_Entry : constant Gtk.GEntry.Gtk_Entry :=
|
||||||
|
Gtk.GEntry.Gtk_Entry (Builder.From_Object
|
||||||
|
("commandEntry"));
|
||||||
|
Command_Completion : aliased constant Gtk_Entry_Completion :=
|
||||||
|
Gtk_Entry_Completion_New;
|
||||||
|
|
||||||
|
Completion_String : Glib.Values.GValue;
|
||||||
|
|
||||||
|
Executables : constant String_Vectors.Vector :=
|
||||||
|
Builder.Launcher.Discover_Executables;
|
||||||
|
begin
|
||||||
|
for Element of Executables loop
|
||||||
|
Items.Append (Iter);
|
||||||
|
Glib.Values.Init_Set_String (Completion_String,
|
||||||
|
To_String (Element));
|
||||||
|
Items.Set_Value (Iter, 0, Completion_String);
|
||||||
|
end loop;
|
||||||
|
|
||||||
|
Command_Completion.Set_Model (Items.To_Interface);
|
||||||
|
Command_Completion.Set_Text_Column (Column => 0);
|
||||||
|
Command_Completion.Set_Inline_Completion (True);
|
||||||
|
Command_Completion.Set_Inline_Selection (True);
|
||||||
|
Command_Entry.Set_Completion (Completion => Command_Completion);
|
||||||
|
Command_Entry.On_Key_Release_Event
|
||||||
|
(Call => Arun.Handlers.Search_Keypress'Access,
|
||||||
|
After => False);
|
||||||
|
end Rig_Autocomplete;
|
||||||
|
|
||||||
end Arun;
|
end Arun;
|
||||||
|
|
49
src/arun.ads
49
src/arun.ads
|
@ -14,7 +14,8 @@
|
||||||
--
|
--
|
||||||
-- You should have received a copy of the GNU General Public License
|
-- You should have received a copy of the GNU General Public License
|
||||||
-- along with this program; if not, write to the Free Software
|
-- along with this program; if not, write to the Free Software
|
||||||
-- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
-- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||||
|
-- 02110-1301, USA.
|
||||||
------------------------------------------------------------------------------
|
------------------------------------------------------------------------------
|
||||||
|
|
||||||
with GNAT.String_Split;
|
with GNAT.String_Split;
|
||||||
|
@ -26,32 +27,38 @@ package Arun is
|
||||||
|
|
||||||
type Launcher_Type is interface;
|
type Launcher_Type is interface;
|
||||||
|
|
||||||
type Discovered_Executable_Handler is access function (L : in Launcher_Type'Class;
|
type Discovered_Executable_Handler is
|
||||||
Name : in String;
|
access function (L : in Launcher_Type'Class;
|
||||||
Full_Path : in String) return Boolean;
|
Name : in String;
|
||||||
|
Full_Path : in String) return Boolean;
|
||||||
|
|
||||||
procedure Initialize (L : in Launcher_Type'Class) is abstract;
|
-- Determine the full path of the snippet based on PATH or other
|
||||||
-- Launcher_Type-specific initialization routine
|
-- environment variables.
|
||||||
|
|
||||||
function Find_Full_Path (L : in Launcher_Type;
|
|
||||||
Path_Snippet : in String) return String is abstract;
|
|
||||||
-- Determine the full path of the snippet based on PATH or other environment
|
|
||||||
-- variables.
|
|
||||||
--
|
--
|
||||||
-- Will return an empty string if a full path was not discoverable.
|
-- Will return an empty string if a full path was not
|
||||||
|
-- discoverable.
|
||||||
|
--
|
||||||
|
function Find_Full_Path (L : in Launcher_Type;
|
||||||
|
Path_Snippet : in String) return String is
|
||||||
|
abstract;
|
||||||
|
|
||||||
|
-- Spawn the Executable in place of the current process
|
||||||
|
--
|
||||||
procedure Execute (L : in Launcher_Type;
|
procedure Execute (L : in Launcher_Type;
|
||||||
Executable_Path : in String;
|
Executable_Path : in String;
|
||||||
Argv : in GNAT.String_Split.Slice_Set) is abstract;
|
Argv : in GNAT.String_Split.Slice_Set) is
|
||||||
-- Spawn the Executable in place of the current process
|
abstract;
|
||||||
|
|
||||||
function Compare_Strings (Left : in Ada.Strings.Unbounded.Unbounded_String;
|
package String_Vectors is
|
||||||
Right : in Ada.Strings.Unbounded.Unbounded_String) return Boolean;
|
new Ada.Containers.Vectors
|
||||||
package String_Vectors is new Ada.Containers.Vectors (Index_Type => Natural,
|
(Index_Type => Natural,
|
||||||
Element_Type => Ada.Strings.Unbounded.Unbounded_String,
|
Element_Type => Ada.Strings.Unbounded.Unbounded_String,
|
||||||
"=" => Compare_Strings);
|
"=" => Ada.Strings.Unbounded."=");
|
||||||
|
|
||||||
function Discover_Executables (L : in Launcher_Type) return String_Vectors.Vector is abstract;
|
-- Discover executables which can be launched by the configured
|
||||||
-- Discover executables which can be launched by the configured Launcher_Type
|
-- Launcher_Type
|
||||||
|
--
|
||||||
|
function Discover_Executables (L : in Launcher_Type)
|
||||||
|
return String_Vectors.Vector is abstract;
|
||||||
|
|
||||||
end Arun;
|
end Arun;
|
||||||
|
|
|
@ -14,7 +14,8 @@
|
||||||
--
|
--
|
||||||
-- You should have received a copy of the GNU General Public License
|
-- You should have received a copy of the GNU General Public License
|
||||||
-- along with this program; if not, write to the Free Software
|
-- along with this program; if not, write to the Free Software
|
||||||
-- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
-- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||||
|
-- 02110-1301, USA.
|
||||||
------------------------------------------------------------------------------
|
------------------------------------------------------------------------------
|
||||||
with Arun;
|
with Arun;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue