From: annihilan@gmail.com
Subject: Help with constructing an Ada Shell
Date: Thu, 29 Oct 2015 21:53:20 -0700 (PDT)
Date: 2015-10-29T21:53:20-07:00 [thread overview]
Message-ID: <9e1e5dc4-f5e6-4d8d-9677-1b66117d8a85@googlegroups.com> (raw)
Okay. So I've been trying to learn Ada recently, which unfortunately means that my question isn't going to be very sophisticated. I have the following code:
with Ada.Text_IO; use Ada.Text_IO;
with GNAT.OS_Lib; use GNAT.OS_Lib;
with GNAT.Strings;
package body Ada_Shell is
Input : aliased String := (1 .. 255 => ' ');
Last : Integer;
procedure Main is
package IO renames Ada.Text_IO;
begin
IO.Put_Line("Welcome to ash! This is an extreme work in progress.");
Main_Loop:
loop
Input := (others=> ' ');
IO.Put("ash> ");
IO.Get_Line(Input, Last);
if Input(Input'First..Last) = "quit" then
exit Main_Loop;
else
Execute_System;
end if;
end loop Main_Loop;
end Main;
procedure Execute_System is
Result : Integer;
Arguments : Argument_List :=
(1 => Input'Access);
begin
Spawn (Program_Name => Input, -- truncate strings or Input(Input'First..Last)??
Args => Arguments,
Output_File_Descriptor => Standout,
Return_Code => Result);
-- for Index in Arguments'Range loop
-- Free(Arguments(Index));
-- end loop;
Put_Line(Integer'Image(Result));
end Execute_System;
end Ada_Shell;
This code is executed by a simple procedure that calls the Main loop of the package. I don't know if there's a "better" way to make a repeating main loop like this, but I couldn't contrive a better solution.
Besides, this code does not work. It compiles, sure, but it doesn't work. No matter what command is passed at the prompt, a return value of 1 is given.
Things I have tried that work:
hardcoding the program at Spawn(Program_Name=>"/bin/ls") or similar
Things I have tried that have not worked:
Having Execute_System be in a separate file, and having its signature as Execute_System(Command:access String) (this worked especially poorly, bringing in aliasing problems that I couldn't solve.
I really don't know why this doesn't work. The reason that the result code and command line are global was to eliminate "non-local pointer references local object" and "implicit conversion of anonymous access formal" errors. I haven't tried uncommenting the Free block since I fixed everything, though.
I would massively appreciate any help that could be given to me. I don't really have any clue at all what's going on.
next reply other threads:[~2015-10-30 4:53 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-10-30 4:53 annihilan [this message]
2015-10-30 8:37 ` Help with constructing an Ada Shell 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
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox