comp.lang.ada
 help / color / mirror / Atom feed
From: Xavier Petit <xpetit@becoast.fr>
Subject: Re: Help with constructing an Ada Shell
Date: Sat, 31 Oct 2015 00:19:16 +0100
Date: 2015-10-31T00:19:16+01:00	[thread overview]
Message-ID: <5633faf4$0$3023$426a74cc@news.free.fr> (raw)
In-Reply-To: <9e1e5dc4-f5e6-4d8d-9677-1b66117d8a85@googlegroups.com>

Hello, I would suggest you to learn Ada with more easy and abstract 
stuff, not shells ^^ which are platform dependent and related to the 
Unix/C philosophy.
GNAT provides OS abstraction but I think that dealing with process 
spawning is not the best way to learn Ada.

Here a working example of what you wanna do, based on previous answers.
(Sorry for my terrible english)

with Ada.Text_IO,
      GNAT.OS_Lib;

procedure Ada_Shell is
    procedure Execute_System (Command : String)
    is
       use GNAT.OS_Lib;

       List : String_List_Access := Argument_String_To_List (Command);
       Exec_Path : String_Access := Locate_Exec_On_Path (List (1).all);
       Success : Boolean;

    begin
       if Exec_Path /= null then
          Spawn (Program_Name => Exec_Path.all,
                 Args         => List (2 .. List'Last),
                 Success      => Success);
          Free (Exec_Path);
       else
          Ada.Text_IO.Put_Line ("Command not found");
       end if;

       Free (List);
    end Execute_System;

begin
    Main : loop
       Ada.Text_IO.Put ("ash> ");

       declare
          Input : constant String := Ada.Text_IO.Get_Line;
       begin
          exit Main when Input = "exit";

          if Input'Length > 0 then
             Execute_System (Command => Input);
          end if;
       end;
    end loop Main;

exception
    when Ada.Text_IO.End_Error => null; -- Handling [Ctrl]-[D]
end Ada_Shell;

-- 
Xavier Petit

      parent reply	other threads:[~2015-10-30 23:19 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-10-30  4:53 Help with constructing an Ada Shell annihilan
2015-10-30  8:37 ` Jacob Sparre Andersen
2015-11-03  0:47   ` Nick Gordon
2015-10-30  9:10 ` Simon Wright
2015-10-30 13:52 ` David Botton
2015-10-30 23:19 ` Xavier Petit [this message]
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox