[environment]
module GCLICMD(output);

(***************>>>>>>>>                          <<<<<<<<***************)
(*                                                                      *)
(*                                                                      *)
(* >>	Title:		GCLICMD						*)
(*                                                                      *)
(* >>	Credits Section                                                 *)
(*                                                                      *)
(*	Authors:	David A. Hansen		 2-OCT-86		*)
(*                                                                      *)
(*	Version:	1	        	 2-OCT-86		*)
(*	Revision:	NEW			 2-OCT-86		*)
(*                                                                      *)
(*	Checkers:		                                        *)
(*                                                                      *)
(* >>	Audit Trail Section                                             *)
(*									*)
(*	 2-OCT-86	DAH	Module Created.				*)
(*									*)
(*                                                                      *)
(* >>	Abstract Section                                                *)
(*									*)
(*                                                                      *)
(* >>	Interface Section                                               *)
(*                                                                      *)
(*                                                                      *)
(* >>	Code Section                                                    *)


[hidden] type
   Word_Type = [word] 0..65535;
   Big_Bool = [long] boolean;
   Str_Type = packed array [1..255] of char;
   Str_Desc = record
                 Length : Word_Type;
                 Fill : Word_Type;
                 Str_Ptr : ^Str_Type;
              end;

(***************   bit byte types for I/O stuff ********)
	$ubyte  = [byte] 0..255;
	$quad	= [quad,unsafe] record
		ts,term,len,l2:$ubyte; end;
	$UQUAD = [QUAD,UNSAFE] RECORD
		L0,L1:UNSIGNED; END;
	$UWORD = [WORD] 0..65535;


[hidden] function LIB$SIGNAL( Status : integer ) : integer; external;


[hidden] function LIB$GET_FOREIGN(
                      %stdescr Get_Str : packed array [l1..u1:integer] of char;
                      %immed Prompt_Desc_Adr : integer := 0;
                      %ref Out_Len : Word_Type;
                      %ref Force_Prompt : Big_Bool := false
                                 ) : integer; external;


[global] procedure Get_CLI_Command_Line(var Cmd_Line : varying[u1] of char;
                                        Prompt : varying[u2] of char := '' );

var
   Command:	packed array [1..255] of char;
   Length:	Word_Type;
   Force_P:	[static] Big_Bool := false;
   Prompt_Desc:		Str_Desc;
   Prompt_Desc_Adr:	integer;
   Ret_Stat:	integer;
   i:		integer;

begin
   if Prompt.length = 0 then begin
      Prompt_Desc_Adr := 0;
   end
   else begin
      Prompt_Desc.Length := Prompt.length;
      new(Prompt_Desc.Str_Ptr);
      for i := 1 to Prompt.length do
         Prompt_Desc.Str_Ptr^[i] := Prompt.body[i];
      Prompt_Desc_Adr := iaddress( Prompt_Desc );
   end;
   Ret_Stat := LIB$GET_FOREIGN(Command,Prompt_Desc_Adr,Length,Force_P);
   if not odd(Ret_Stat) then begin
      LIB$SIGNAL(Ret_Stat);
      Cmd_Line := '';
   end
   else begin
      if Length < u1 then begin
         Cmd_Line := substr(Command,1,Length);
      end
      else begin
         Cmd_Line := substr(Command,1,u1);
      end;
   end;
end; { Get_CLI_Command_Line }

end.
