comp.lang.ada
 help / color / mirror / Atom feed
* Help with constructing an Ada Shell
@ 2015-10-30  4:53 annihilan
  2015-10-30  8:37 ` Jacob Sparre Andersen
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: annihilan @ 2015-10-30  4:53 UTC (permalink / 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.


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2015-11-03  0:47 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox