-- computerman is multiway user tools.
-- Computerman is Copyright (C) 2024 Manuel De Girardi ; 
--
--   This program is free software; you can redistribute it and/or modify
--   it under the terms of the GNU General Public License as published by
--   the Free Software Foundation; either version 2 of the License, or
--   (at your option) any later version.
--
--   This program is distributed in the hope that it will be useful,
--   but WITHOUT ANY WARRANTY; without even the implied warranty of
--   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
--   GNU General Public License for more details.
--
--   You should have received a copy of the GNU General Public License
--   along with this program; if not, write to the Free Software
--   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
--
-- Date := 2024-06-16 15:37:42 ; 
-- Version := 17.0.1a ; 
with Computer ; 
with Computer.Errors ; 
with Computer.Parameters ; 
with Computer.Options ; 
with Computer.Versions ; 
with Computer.Versions.Version_io ; 
with Computer.Interfaces ; 
with Computer.Shared ; 
with Computer.Shell ; 
use Computer.Shared;
use Computer.Shell;
with Computer.Attributes;
use Computer.Attributes;
with Computer.Tools;
with Computer.Stock;
use Computer.Stock;
with Computer.Stocks_Manager;
with Computer.Balance;
use Computer;
with Computer.Errors;
use Computer.Errors;
with Computer.Versions;
with Computer.Versions.Version_Io;
use Computer.Versions;

with Text_Io;
with Ada.Characters.Handling;
use Ada.Characters;

with Ada.Wide_Text_Io;

with Ada.Strings.Fixed;
use Ada.Strings.Fixed;
with Ada.Strings.Wide_Fixed;
use Ada.Strings;
with Gnat.Os_Lib;
use Gnat.Os_Lib;

with Text_Io;
use Text_Io;
with Ada.Characters.Handling;
with Ada.Calendar;
with Ada.Calendar.Formatting;
use Ada.Calendar;
use Ada;
with Ada.Wide_Characters.Handling;
use Ada.Wide_Characters.Handling;

with Gnat.Directory_Operations;
use Gnat.Directory_Operations;

with Gnat.Semaphores;
use Gnat.Semaphores;

with Computer.MIDI.Portmidi;
with Computer.Midi.Messages;
with Computer.Midi.Devices;
with Computer.Midi.Drivers;
with Computer.Midi.Sequencer;
use Computer.MIDI.Portmidi;
use Computer.Midi.Messages;
use Computer.Midi.Devices;
use Computer.Midi.Drivers;
use Computer.Midi.Sequencer;
with PragmARC.Genetic_Algorithm;
with Computer.Frame;
use Computer;

with Interfaces.C;
use Interfaces.C;


with PragmARC.Ansi_Tty_Control;
use PragmARC.Ansi_Tty_Control;

with Ada.Unchecked_Deallocation;
with Gnat.Semaphores;
use Gnat.Semaphores;

with Ada.Containers.Vectors;
use Ada.Containers;


with Gnos;

with Gnos.Parameters;
use Gnos.Parameters;
with Gnos.Classified;
with Gnos.Abstracts;
with Gnos.Projects;
use Gnos;
use Gnos.Classified;
with Gnos.Results;

with Gnos.Versions;
with Gnos.Versions.Editting;

use Gnos.Versions.Editting;
with Gnos.Versions.Environment;
with Gnos.Gnose;
with Gnos.Machines;
with Gnos.Objects;

package body Computer.Main is
   
   
   Gnose_Params : Gnose_Parameters_Type;
   
   Projects_Params : Projects_Parameters_Type;
   
   package Gnos_Projects is new Gnos.Projects(Projects_Params);
   use Gnos_Projects;
   
   
   package Agnose is new Gnos.Gnose(Gnose_Params);
   use Agnose;
   use Agnose.Neural;
   use Agnose.Neural.Objects_System;
   use Agnose.Neural.Objects_System.Objects_system;
   use Agnose.Neural.Objects_System.Objects_System.Language;
   use Agnose.Neural.Objects_System.Objects_System.Language.Agnose_Projects;
   
   package Environment is new Gnos.Versions.Environment(Agnose.Neural.Objects_System.Objects_System.Language.Agnose_Projects);
   use Environment;
   
   
   
   
   
   
   
   
   
   
   
   
   
   --  function Version_Update(Version : in  Computer.Versions.Version_Type) return Computer.Versions.Version_Type is
   --     The_Version : Computer.Versions.Version_Type := version;

   --  begin
   --     --Set_date(Shared_Date, Calendar.Clock);
   --     if not Gnos.Versions.New_Version then
   --  	 return Version;
   --     end if;
   --     -- Change major if is the current year > Major_Version.
   --     if The_Version.Major_Version < Calendar.Year(Calendar.Clock) then 
   --  	 if The_Version.Major_Version + 1 < Major_Version_Type'Last then
   --  	    The_Version.Major_Version := The_Version.Major_Version + 1;
   --  	    The_Version.Minor_Version := 0;
   --  	    The_Version.Revision_Version := 0;
   --  	 else
   --  	    raise Impl_Limit;
   --  	 end if;
   --     end if;
   --     if New_Description or New_Action then
   --  	 The_Version.Release_Version := 'a';
   --     elsif The_Version.Release_Version = 'a' then
   --  	 The_Version.Release_Version := 'b';
   --     else
   --  	 return The_Version;
   --     end if;      
            
   --     -- Change minor if some data description is modified or added.
   --     if New_Description then	    
   --  	 if The_Version.Minor_Version + 1 < Minor_Version_Type'Last then
   --  	    The_Version.Minor_Version := The_Version.Minor_Version + 1;	      
   --  	    The_Version.Revision_Version := 0;		  	    
   --  	 else
   --  	    raise Impl_Limit;
   --  	 end if;
   --     end if;
      
   --     -- Change minor if some function is modified or added.
   --     if New_Action then	       
   --  	 if The_Version.Revision_Version + 1 < Revision_Version_Type'Last then
   --  	    The_Version.Revision_Version := The_Version.Revision_Version + 1;
   --  	 else
   --  	    raise Impl_Limit;
   --  	 end if;
   --     end if;
      
   --     return The_Version;

   --  end Version_Update;

   
   function Version_Update(Version : in  Computer.Versions.Version_Type) return Computer.Versions.Version_Type is
      The_Version : Computer.Versions.Version_Type := version;

   begin
      if New_Action and (not New_Description) then
	 if The_Version.Revision_Version + 1 < Revision_Version_Type'Last then
   	    The_Version.Revision_Version := The_Version.Revision_Version + 1;
   	 elsif The_Version.Major_Version + 1 < Major_Version_Type'Last then
	    The_Version.Major_Version := The_Version.Major_Version + 1;
	    The_Version.Minor_Version := 0;
	    The_Version.Revision_Version := 0;
	 else
	    raise Impl_Limit;
	 end if;
      elsif New_Description and New_Action then
	 if The_Version.Minor_Version + 1 < Minor_Version_Type'Last then
	    The_Version.Minor_Version := The_Version.Minor_Version + 1;	      
	    The_Version.Revision_Version := 0;		  	    
	 elsif The_Version.Revision_Version + 1 < Revision_Version_Type'Last then
	    The_Version.Revision_Version := The_Version.Revision_Version + 1;
	 elsif The_Version.Major_Version + 1 < Major_Version_Type'Last then
	    The_Version.Major_Version := The_Version.Major_Version + 1;
	    The_Version.Minor_Version := 0;
	    The_Version.Revision_Version := 0;
	 else
	    raise Impl_Limit;
	 end if;
      elsif New_Description then
	 The_Version.Release_Version := 'a';
	 
	 if The_Version.Minor_Version + 1 < Minor_Version_Type'Last then
	    The_Version.Minor_Version := The_Version.Minor_Version + 1;	      
	    The_Version.Revision_Version := 0;		  	    
	 elsif The_Version.Revision_Version + 1 < Revision_Version_Type'Last then
	    The_Version.Revision_Version := The_Version.Revision_Version + 1;
	 elsif The_Version.Major_Version + 1 < Major_Version_Type'Last then
	    The_Version.Major_Version := The_Version.Major_Version + 1;
	    The_Version.Minor_Version := 0;
	    The_Version.Revision_Version := 0;
	 else
	    raise Impl_Limit;
	 end if;
      elsif The_Version.Release_Version = 'a' then
	 The_Version.Release_Version := 'b';
	 if The_Version.Minor_Version + 1 < Minor_Version_Type'Last then
	    The_Version.Minor_Version := The_Version.Minor_Version + 1;	      
	    The_Version.Revision_Version := 0;		  	    
	 elsif The_Version.Revision_Version + 1 < Revision_Version_Type'Last then
	    The_Version.Revision_Version := The_Version.Revision_Version + 1;
	 elsif The_Version.Major_Version + 1 < Major_Version_Type'Last then
	    The_Version.Major_Version := The_Version.Major_Version + 1;
	    The_Version.Minor_Version := 0;
	    The_Version.Revision_Version := 0;
	 else
	    raise Impl_Limit;
	 end if;
      else
	 The_Version.Release_Version := 'r';
	 if The_Version.Revision_Version + 1 < Revision_Version_Type'Last then
	    The_Version.Revision_Version := The_Version.Revision_Version + 1;
	    
	 elsif The_Version.Minor_Version + 1 < Minor_Version_Type'Last then
	    The_Version.Minor_Version := The_Version.Minor_Version + 1;	      
	    The_Version.Revision_Version := 0;		  	    
	    
	 elsif The_Version.Major_Version + 1 < Major_Version_Type'Last then
	    The_Version.Major_Version := The_Version.Major_Version + 1;
	    The_Version.Minor_Version := 0;
	    The_Version.Revision_Version := 0;
	 else
	    raise Impl_Limit;
	 end if;
      end if;
      
      return The_Version;

   end Version_Update;

   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   type Gnose_Record is limited
      record
	 Context              : access Agnose.Gnose_Context_Record;
	 System               : Agnose.Neural.Neural_System;
      end record;
   
   package W_Io renames Ada.Wide_Text_Io;
      
   function System(Cmd : in String) return Integer;
   pragma Import (C, System, "system");
   
   Errno : Integer := 0;
   
   use Ansi_Windows;
   use Windows;
   
   
   
   
   procedure Load_File (Set : in out Wide_String_Set; Name : in String; Last : out Line_Index_Range) is
      
      File : W_Io.File_Type;
      
   begin
      W_Io.Open(File, W_Io.In_File, Name, Form => "WCEM=8");
      Last := 0;
      
      while not W_Io.End_Of_File(File) loop

   	 declare
   	    Line : constant Wide_String :=W_Io.Get_Line(File);
   	 begin

   	    Set.Lines(Last+1) := new Wide_String ' (Line);
   	    Last := Last + 1;

   	 end;
      end loop;
      Set.Line_Last := Last;
      W_Io.Close(File);
   end Load_File;

   
   
   subtype Cpu_String is String (1..6);
   
   Home_Dir : String := Getenv("HOME").all;
   
   task CPU_Process is
      entry Initialize;
      entry Cpu_Get(CPU_Usage : out CPU_String);
      entry Halt;
   end CPU_Process;
   
   task body CPU_Process is
      
      Cpu_Cmd : constant String := "sh -c """ & Home_Dir & "/bin/cpu > " & Home_Dir & "/.cpu_usage.txt""" & Character'Val(0);
      Cpu_File : Text_Io.File_Type;
      Cpu_Error : Integer := 0;
      Cpu : Cpu_String := (others => ' ');
      Success  : Boolean := False;
   begin
      loop
	 select
	    accept Initialize do
	       Cpu_Error := System(Cpu_Cmd);
	       
	       if Is_Regular_File(Home_Dir & "/.cpu_usage.txt") then
		  Cpu := (others => ' ');
		  
		  Text_Io.Open(Cpu_File, Text_Io.In_File, Home_Dir & "/.cpu_usage.txt");
		  declare
		     Line : constant String := Get_Line(Cpu_File);
		     Pos  : Natural := Line'Length + ((Cpu_String'Length-1) - Line'Length) ;
		  begin
		     
		     for I in reverse Line'Range loop
			Cpu(Pos) := Line(I);
			Pos := Pos - 1;
		     end loop;
		     Cpu(Cpu'Length) := '%';
		  end;
		  
		  Text_Io.Close(Cpu_File);
		  
		  Delete_File(Home_Dir & "/.cpu_usage.txt", Success);
		  
	       end if;
	    
	       
	    end Initialize;
	 or
	    accept Cpu_Get(CPU_Usage : out CPU_String) do
	       CPU_Usage := Cpu;
	    end Cpu_Get;
	 or
	    accept Halt;
	    exit;
	 end select;
      end loop;
   end CPU_Process;
      
   
   
   
   -------------------------------------------------------------------------------------------------------------
   --                                                                                                         --
   --
   -------------------------------------------------------------------------------------------------------------
   task body shell_Process is
      
      
      Lock : Binary_Semaphore(True, Default_Ceiling);
      Text : Wide_String_Access := new Wide_String ' ("");
      Old_Length    : Natural := 0; -- save text'length
      Old_Total_Length    : Natural := 0; -- save total_type'image(total_sum)'length
      Old_Pwd   : String_Access;
      
      Cpu_Lock : Binary_Semaphore(True, Default_Ceiling);
      
      
      task Screen is
	 entry Refresh;
	 entry Halt;
      end Screen;
      
      task body Screen is
	 Prompt : String_Access;
	 
	 
	 Cpu    : Cpu_String := (others => ' ');
	 
      begin
	 loop
	    
	    select
	       accept Halt;
	       exit;
	    or
	       accept Refresh do
		  Lock.Seize;

		  
		  Cpu_Lock.Seize;
		  Cpu_Process.Initialize;
		  Cpu_Process.Cpu_Get(Cpu);
		  Cpu_Lock.Release;
		  Free(Prompt);
		  Prompt := new String ' (Term_Enum'Image(This.Term_Name) & ':' & cpu & ": " & Formatting.Image(Clock)(12..Formatting.Image(Clock)'Length) & ":" & Total_Type'Image(Total_Sum)  & "$ ");

		  if Text /= null then		     
		     
		     Put(Character'Val (13) & Prompt.all);
		     Put((Old_Length+Old_Total_Length+Cpu'length) * ' ');
		     Put(Character'Val (13) & Prompt.all);
		     W_Io.Put(Text.all);

		  else
		     Put(Character'Val (13) & Prompt.all);
		     Put((Old_Length+Old_Total_Length+Cpu'length) * ' ');
		     Put(Character'Val (13) & Prompt.all);

		  end if;
		  Old_Total_Length := Total_Type'Image(Total_Sum)'Length;
		  Old_Length := 0;
		  
		  Lock.Release;

	       end Refresh;	      
	    
	    end select;
	 end loop;
      end Screen;
      
      
      task Deamon is
	 entry Halt;
	 entry Lock;
	 entry Unlock;
      end Deamon;
      task body Deamon is
	 End_Of_Task : Boolean := False;
      begin
     Main_Loop :
	 while not End_Of_Task loop
	    loop
	       select
		  accept Halt;
		  End_Of_Task := True;
		  exit Main_Loop;
	       or
		  accept Lock;
	       or
		  accept Unlock;		  
		  screen.Refresh;
		  exit;
	       end select;
	    end loop;
	    while not End_Of_Task loop
	       select
		  accept Halt;
		  End_Of_Task := True;	    
		  exit Main_Loop;
	       or
		  accept Lock;
		  exit;
	       or
		  accept Unlock;
	       or
		  delay 1.0;
		  screen.Refresh;
	       end select;	    
	    end loop;	    
	 end loop Main_Loop;
      end Deamon;
      
      Args_Index        : Natural := 0;
      Arguments         : Wide_String_Access;
      
      Var_Set           : Attributs(2048);
      Alias_Set         : Attributs(2048);
      Internal_Cmd : Int_Cmd_Enum := None;
      Is_Internal_Cmd : Boolean := False;
      Buffer : Wide_String_Access;
      
      Completion_Result : Wide_Result_Access;      
      History_Set   : Wide_String_Set(2048);
      History_Last  : Natural := 0;
      History_Index : Natural := 0;
      
      Errno : Integer := 0;  
   begin

      begin
     Main_Loop:
	 loop
	    loop
	       select
		  accept Halt do

		     Deamon.Halt;

		     Screen.Halt;

		  end Halt;
		  exit Main_Loop;
	       or
		  accept Suspend do
		     Deamon.Lock;
		  end Suspend;
		  exit;
	       or
		  accept Wake_Up;
	       or
		  accept Receive (Wchar : in Wide_Character) do
		     
		     if Is_Control(Wchar) then
			
			case Wchar is
			   when Wide_Character'Val(9) =>
			      Lock.Seize;
			      declare
				 Line : constant String_Access := 
				   new String ' (Handling.To_String(Text.all));
				 
				 Path_On_Line : Wide_String_Access;
				 buffer : String_Access := new String ' ("");
			      begin
				 if Completion_Result /= null then
				    U_Array_Free(Completion_Result.Wlines);
				 end if;
				 Completion(Line.all, Path_On_Line, Completion_Result);				    
				 if Path_On_Line /= null then
				    Buffer := new String ' (Handling.To_String(Path_On_Line.all));
				    Wide_Free(Path_On_Line);					  
				    Wide_Free(Text);
				    Text := new Wide_String ' (Handling.To_Wide_String(Buffer.all));
				    Free(Buffer);
				    U_Array_Free(Completion_Result.Wlines);
				    Wide_Result_Free(Completion_Result);
				 else
				    for I in Completion_Result.Wlines'Range loop
				       Put_Line(Delete_Local_Prefix(Handling.To_String((-Completion_Result.Wlines(I)))));
				    end loop;
				 end if;
				 
			      end;
			      Lock.Release;
			   when Wide_Character'Val(10) | Wide_Character'Val(13) =>			
			      if Text /= null and then
				Text'Length > 0 then
				 
				 Lock.Seize;
				 Text_Io.New_Line;
				 Deamon.Lock;
				 
				 if Text(1) = '-' or Text(1) = '+' then
				    if Text'Length > 1 then
				       declare
					  Val : Total_Type := 0.0;
				       begin
					  Val := Total_Type'Value(Handling.To_String(Text.all));
					  Total_Sum := Total_Sum + Val;
					  Wide_Free(Text);
					  Text := new Wide_String ' ("");
					  
				       exception
					  when Constraint_error =>
					     Put_Line("-: error");
				       end;
				    end if;
				    
				 else
				    
				    
				    
				    Internal_Cmd := Internal_Cmd_Value(Handling.To_String(Text.all));
				    Is_Internal_Cmd := True;
				    case Internal_Cmd is
				       when none =>
					  Is_Internal_Cmd := False;
				       when Alias =>
					  
					  Alias(Handling.To_String(Text.all), Alias_Set);
					  
				       when Unalias =>
					  
					  Unalias(Handling.To_String(Text.all), Alias_Set);
					  
				       when Cd =>
					  begin
					     Cpu_Lock.Seize;
					     Change_Directory(Handling.To_String(Text.all), Old_Pwd);
					     Cpu_Lock.Release;
					  exception
					     when Directory_Error =>
						Cpu_Lock.Release;
						Text_Io.Put("Directory not found");
						Text_Io.New_Line;
					  end;
				       when Set =>

					  Set(Handling.To_String(Text.all), Var_Set);
					  
				       when Unset =>

					  Unset(Handling.To_String(Text.all), Var_Set);
					  
				       when Put =>

					  Args_Index := Index(Handling.To_String(Text.all), " ")+1;
					  if Args_Index /= 0 then
					     Arguments := new Wide_String ' (Text(Args_Index..Text'Length));
					     Put(Handling.To_String(Arguments.all), Var_Set);
					  end if;
					  Text_Io.New_Line;
				       when Put_Line =>

					  Args_Index := Index(Handling.To_String(Text.all), " ")+1;
					  if Args_Index /= 0 then
					     Arguments := new Wide_String ' (Text(Args_Index..Text'length));
					     Put_Line(Handling.To_String(Arguments.all), Var_Set);
					  end if;
					  
				    end case;
				    
				    
				    if not Is_Internal_Cmd then
				       
				       --New_Line;
				       declare
					  Alias_Ptr   : String_Access;
					  Buffer      : String_Access;
					  Normal      : String_Access;				 
				       begin

					  for Iter in 1..Alias_Set.Index loop
					     declare
						Alias : constant Attribut_Record := Alias_Set.List(Iter);
						First_Space : Natural := 
						  Index(Handling.To_String(Text.all), " ");
						Non_Blank   : constant Natural :=
						  Index_Non_Blank(Handling.To_String(Text.all), Backward);
					     begin	
						if Non_Blank < First_Space then
						   First_Space := 0;
						end if;
						if First_Space /= 0 then
						   if Names(Alias) =
						     Handling.To_String(Text(Text'First..First_Space - 1)) then
						      Alias_Ptr := new String ' (Images(Alias));
						      exit;
						   end if;
						else
						   if Names(Alias) = Handling.To_String(Text(Text'First..Index_Non_Blank(Handling.To_String(Text.all), Backward))) then
						      Alias_Ptr := new String ' (Images(Alias));
						      exit;
						   end if;
						end if;
					     end;
					  end loop;

					  if Alias_Ptr /= null then
					     declare
						First_Space : constant Natural := 
						  Index(Handling.To_String(Text.all), " ");
					     begin

						if First_Space /= 0 then
						   Buffer := new String ' 
						     (Alias_Ptr.all & ' ' & Handling.To_String(Text(First_Space+1..Text ' Last)));

						else
						   Buffer := new String ' (Alias_Ptr.all);
						end if;
					     end;
					     Wide_Free(Text);

					     Normal := new String ' (Normalize_Quoted_Argument(Buffer.all));
					     Text := new Wide_String ' (Handling.To_Wide_String(Normal.all));
					     
					  end if;
				       end;
				       
				       
				       
				       if Locate_Exec_On_path(Command_Name(Handling.To_String(Text.all))) /= null then
					  
					  
					  if Command_Name(Handling.To_String(Text.all))'Length = Text'Length then
					     
					     declare
						
						Args : constant Argument_List_Access := Argument_String_To_List
						  (
						   "-c " &
						     Locate_Exec_On_path(Command_Name(Handling.To_String(Text.all))).all);
					     begin
						if Locate_Exec_On_path(Command_Name(Handling.To_String(Text.all))).all'Length /= 0 then
						   Errno := Spawn("/usr/bin/sh", Args.all);
						end if;
					     end;
					     
					  else
					     
					     declare
						
						Args : constant Argument_List_Access := new Argument_List ' (new String ' ("-c"), 
													     new String ' (Locate_Exec_On_path(Command_Name(Handling.To_String(Text.all))).all & " " & 
															     Handling.To_String(Text.all)(Command_Name(Handling.To_String(Text.all))'Length+2..Text'Last)
															  )
													    );
						
					     begin
						Normalize_Arguments(Args.all);
						Errno := Spawn("/usr/bin/sh", Args.all);
					     end;
					     
					     
					  end if;
				       else
					  New_Line;
					  Put_Line("Command not found");
				       end if;
				    end if;
				    if Errno /= 0 then	    
				       Put_Line("Error: errno = " & Integer'Image(Errno));
				    end if;
				    Old_Length := Text'Length;
				    Add_Line(History_Set, History_Last, Text.all);
				    History_Index := 0;
				    Wide_Free(Text);
				    Text := new Wide_String ' ("");			   
				 end if;
				 Deamon.Unlock;
				 Lock.Release;
			      end if;
			   when Wide_Character'Val(12) =>
			      Errno := System("clear" & Character'Val(0));
			      Screen.Refresh;
			   when Wide_Character'Val(127) =>
			      Old_Length := Text'Length;
			      Screen.Refresh;
			      Buffer := new Wide_String ' (Text.all(Text'First..Text'Last-1));
			      Wide_Free(Text);
			      Text := new Wide_String ' (Buffer.all);
			      Wide_Free(Buffer);			
			   when others =>
			      null;
			end case;
		     else
			Lock.Seize;
			Buffer := new Wide_String ' (Text.all & Wchar);
			Wide_Free(Text);
			Text := new Wide_String ' (buffer.all);
			Wide_Free(Buffer);
			Old_Length := Text'Length;
			Lock.Release;
		     end if;
		     
		  end Receive;
		  Screen.Refresh;
	       or
		  accept Refresh;
		  Screen.Refresh;
		  
	       or
		  accept Page_Down;
	       or
		  accept Page_Up;
	       or
		  accept Up_Arrow do
		     
		     if (History_Last > 0) and then
		       (History_Last - History_Index) > 0 then		  
			Old_Length := Text'Length;

			Screen.Refresh;

			Wide_Free(Text);
			Text := new Wide_String ' (History_Set.Lines(History_Last - (History_Index)).all);
			History_Index := History_Index + 1;		  			

			Screen.Refresh;

		     else
			Put(Character'Val(7));
		     end if;
		  end up_arrow;
	       or
		  accept Down_Arrow do
		     
		     if (History_Index > 1) then		  
			Old_Length := Text'Length;
			Wide_Free(Text);
			
			Text := new Wide_String ' (History_Set.Lines(History_Last - (History_Index - 2)).all);
			
			History_Index := History_Index - 1;
			Screen.Refresh;
		     elsif History_Index = 1 then
			Old_Length := Text'Length;
			Wide_Free(Text);		  
			Text := new Wide_String ' ("");
			
			History_Index := History_Index - 1;
			Screen.Refresh;
		     else
			Put(Character'Val(7));
		     end if;
		  end Down_Arrow;
	       or
		  accept Left_Arrow;
	       or
		  accept Right_Arrow;
	       or
		  accept Full_Screen;
	       or
		  accept Del;
	       or
		  accept Begin_Of;
	       or
		  accept End_Of;
	       or
		  accept Overwrite;
	       or
		  accept Screen_Print;
		  
	       end select;
	    end loop;
	    loop
	       select
		  
		  accept Halt do
		     Deamon.Halt;
		     Screen.Halt;
		  end Halt;
		  exit Main_Loop;
	       or
		  accept Suspend;
	       or
		  accept Wake_Up do
		     Text_Io.Put_Line("Greetings " & Getenv("USER").all & "!");
		     Deamon.Unlock;
		  end Wake_Up;
		  exit;
	       end select;
	    end loop;
	 end loop Main_Loop;
      end;
   end Shell_Process;
   

   -------------------------------------------------------------------------------------------------------------
   --                                                                                                         --
   --
   -------------------------------------------------------------------------------------------------------------
   
   -------------------------------------------------------------------------------------------------------------
   --                                                                                                         --
   --
   -------------------------------------------------------------------------------------------------------------
   task body Game_Process is
   begin

      begin
     Main_Loop:
	 loop
	    loop
	       select
		  accept Halt;
		  exit Main_Loop;
	       or
		  accept Suspend;
		  exit;
	       or
		  accept Wake_Up;
	       or
		  
		  accept Receive(Wchar : in Wide_Character);
	       or

		  accept Refresh;
		  
	       or
		  accept Page_Down;
	       or
		  accept Page_Up;
	       or
		  accept Up_Arrow do
		     null;
		  end up_arrow;
	       or
		  accept Down_Arrow do
		     null;
		  end Down_Arrow;
	       or
		  accept Left_Arrow;
	       or
		  accept Right_Arrow;
	       or
		  accept Full_Screen;
	       or
		  accept Del;
	       or
		  accept Begin_Of;
	       or
		  accept End_Of;
	       or
		  accept Overwrite;
	       or
		  accept Screen_Print;

	       end select;
	    end loop;
	    
	    loop
	       select
		  
		  accept Halt do
		     null;
		  end Halt;
		  exit Main_Loop;
	       or
		  accept Suspend;
	       or
		  accept Wake_Up Do
		     Errno := System("clear" & Character'Val(0));
		     null;
		  end Wake_Up;
		  exit;
	       end select;
	    end loop;
	 end loop Main_Loop;
      end;
   end Game_Process;
   
   
   -------------------------------------------------------------------------------------------------------------
   --                                                                                                         --
   --
   -------------------------------------------------------------------------------------------------------------
   
   -------------------------------------------------------------------------------------------------------------
   --                                                                                                         --
   --                                    MIDICtrl : Virtual MIDI sequencer                                    --
   --                                                                                                         --
   -------------------------------------------------------------------------------------------------------------
   
   
   procedure Genetic_Frame_Algorithm is new PragmARC.Genetic_Algorithm (Frame.Frame_Type, 
   									Frame."=", 
   									Frame.Frame_Rand.Frame_Random,
   									Frame.Frame_Fitness,
   									Frame.Frame_Mate,
   									Frame.Frame_Mutate);
   
   
   use Step_Vectors;
   
   
   
   
   procedure Set_Prog_changes(From : in String; Part : in out Step_Seq_Array; Channel : in Channel_type) is
      File : Text_Io.File_Type;
      Line_Nb : Natural := 0;
      
      Message_Prog_change : Long := 0;

      
      
   begin
      if Is_Regular_File(From) then
	 Text_Io.Open(File, Text_Io.In_File, From);

	 while not Text_Io.End_Of_File(File) loop
	    declare
	       Line : constant String := Text_Io.Get_Line(File);
	       Pos  : Natural := 0;
	       Val  : Natural := 0;
	      
	    begin

	       if Line'Length /= 0 then

		  if Index(Line, " ") < Line'Length then

		     Val := Natural'Value(Line(Line'First..Index(Line, " ")-1));

		     Pos := Natural'Value(Line(Index(Line, " ")+1..Line'Last));

		     Message_Prog_Change :=
		       To_Long(Program_Change(Long(Long(Channel)), 
					      Long(Val)));

		     Part(Pos) := Part(Pos) & Message_Prog_Change;
		     
		  end if;
	       end if;
	       
	    end;

	    
	 end loop;

	 Text_Io.Close(File);

      end if;

   end Set_Prog_Changes;
   
   
   
   procedure Read(From : in String; Part : in out Step_Seq_Array; Channel : in Channel_type) is
      
      File : Text_Io.File_Type;
      Line_Nb : Natural := 0;
      
      Message_Note_On  : Long := 0;
      Message_Note_Off : Long := 0;
      
      Done : Boolean := False;
   begin
            if Is_Regular_File(From) then
	 Text_Io.Open(File, Text_Io.In_File, From);
	 
	 while not Text_Io.End_Of_File(File) loop
	   declare
	      Line : constant String := Text_Io.Get_Line(File);
	      Pos  : Natural := 0;
	      Val  : Natural := 0;
	      
	   begin
	      Line_Nb := Line_Nb + 1;
	      if Line'Length /= 0 then
		 Done := True;
		 
		 while Index(Line, " ", Pos+1) /= 0 loop
		    Val := Natural'Value(Line(Pos+1..Index(Line, " ", Pos+1)-1));
		    Done := False;		    
		    
		    
		    
		    Message_Note_On :=
		      To_Long(Note_On(Long(Long(Channel)), 
		 		      Long(Val), 
		 		      Long(85))); 
		    
		    Message_Note_Off :=
		      To_Long(Note_off(Long(Long(Channel)), 
		 		       Long(Val))); 

		    Part(Line_Nb) := Part(Line_Nb) & Message_Note_On;
		    Part(Line_Nb) := Part(Line_Nb) & Message_Note_Off;

		    Pos := Index(Line, " ", Pos+1);
		 end loop;
		 
		 if not Done and Pos /= 0 then		    

		    Val := Natural'Value(Line(Pos+1..Line'last));
		    Message_Note_On :=
		      To_Long(Note_On(Long(Long(Channel)), 
		 		      Long(Val), 
		 		      Long(85))); 
		    
		    Message_Note_Off :=
		      To_Long(Note_off(Long(Long(Channel)), 
		 		       Long(Val))); 

		    Part(Line_Nb) := Part(Line_Nb) & Message_Note_On;
		    Part(Line_Nb) := Part(Line_Nb) & Message_Note_Off;
		 elsif Done then

		    Val := Natural'Value(Line);
		    Message_Note_On :=
		      To_Long(Note_On(Long(Long(Channel)), 
		 		      Long(Val), 
		 		      Long(85))); 
		    
		    Message_Note_Off :=
		      To_Long(Note_off(Long(Long(Channel)), 
		 		       Long(Val))); 

		    Part(Line_Nb) := Part(Line_Nb) & Message_Note_On;
		    Part(Line_Nb) := Part(Line_Nb) & Message_Note_Off;
		 end if;
		 Pos := 0;
	      end if;
	   end;

	   Done := False;
	 end loop;

	 Text_Io.Close(File);

      end if;

   end Read;
		   
      
      
   type Printed_Message_Type is
      record
	 Data_Type : String_Access;
	 Channel     : String_Access;
	 Data1       : String_Access;
	 Data2       : String_Access;
	 Hour        : String_Access;
	 Hexa_Sum    : String_Access;
      end record;
   
   type Printed_Message_Access is access Printed_Message_Type;
   
   procedure Free is new Ada.Unchecked_Deallocation(Printed_Message_Type, Printed_Message_Access);
   
   procedure Add_Line (Set : in out Wide_String_Set;
		       Last : in out Line_Index_Range;
		       Line : in Wide_String) is           
   begin
      Last := Set.Line_Last;
      if Last = Set.Lines'Last then
	 Wide_Free (Set.Lines ( 1 ) );
	 for Line in 1..Last - 1 loop
	    Set.Lines(Line) := Set.Lines (Line + 1);
	 end loop;
	 Set.lines(Last) := new Wide_String ' (Line);
      else
	 Set.Lines(Last+1) := new Wide_String ' (Line);
	 Last := Last + 1;
      end if;
      Set.Line_Last := Last;
   end Add_Line;
   
   
   
   
   function Print_Set (Set : in Wide_String_Set;
		       Into : in Window_Record;
		       Top : in Line_Index_Range;		       
		       Total_Lines: out Natural) return Boolean is
      height : constant Positive := Into.Win.H-2;
      Width  : constant Positive := Into.Win.W-2;
      Line_Count : Natural := 0;      
   begin
      Total_Lines := 0;
      if Set.Line_Last = 0 then
	 return True;
      end if;
      
      
  Print_Loop:
      for I in Top+1 .. Positive'min(Top+Height, Set.Line_Last) loop
	 
	 declare
	    tmp : constant Wide_String := Set.Lines(I).all;
	    Line : constant Wide_String := Tmp(Tmp'First..Wide_Fixed.Index_Non_Blank((Tmp), Backward));
	    
	    Chars_Max : constant Positive := Width-1;
	    Lines_Max : constant Positive := Height;
	    
	    
	    B_Inf : Positive := 1;
	    B_Sup : Positive := Chars_Max;
	    
	    Bot   : Natural := 0;
	 begin
	    
	    --  if Real_Length(Line) > Width then
	    --     Bot := Wide_Fixed.Index (Line(B_Inf..B_Sup), "</span>", Backward);
	    --  end if;
	    
	    if Real_Length(Line) > 0 and Real_Length(Line) < (Chars_Max * Lines_Max) then
	       
	       --if Bot = 0 then
	       
	       for Line_Window in 0 .. Integer'min(Real_Length(Line)/Chars_Max, Lines_Max) loop
		  
		  B_Inf := Line_Window*Chars_Max + 1;
		  B_Sup := Integer'min((Line_Window + 1)*Chars_Max, Real_Length(Line));
		  begin
		     
		     if Real_length(Line) <= Chars_max then
			Draw_Text(Into, Line_Count + 1, 1, White, Line);
		     else
			Draw_Text(Into, Line_Count + 1, 1, White, Line(B_Inf..B_Sup));                            
		     end if;                 
		  end;
		  
		  Line_Count := Line_Count + 1;
		  if Line_Count >= height then		     
		     exit Print_Loop;
		  end if;
		  
	       end loop;
	       --  el7se
	       
	       --  	  for Line_Window in 0 .. Integer'Min(Bot, Integer'min(Real_Length(Line)/Chars_Max, Lines_Max)) loop

	       
	       --  	     B_Sup := Bot + 6;
	       --  	     begin
	       
	       --  		if Real_length(Line) <= Chars_max then
	       --  		   Draw_Text(Into, Line_Count + 1, 1, White, Line);
	       --  		else
	       --  		   Draw_Text(Into, Line_Count + 1, 1, White, Line(B_Inf..B_Sup));                            
	       --  		end if;                 
	       --  	     end;
	       
	       --  	     Line_Count := Line_Count + 1;
	       --  	     if Line_Count >= height then		     
	       --  		exit Print_Loop;
	       --  	     end if;
	       
	       --  	     B_Inf := Bot + 1;
	       --  	     Bot := Wide_Fixed.Index (Line(B_inf..B_inf+Chars_Max), "</span>", Backward);
	       --  	     if Bot /= 0 then
	       --  		B_Sup := Bot + 6;
	       --  	     else
	       --  		B_Sup := B_Inf + Chars_Max;
	       --  	     end if;
	       --  	  end loop;
	       --  end if;
	    else
	       
	       Line_Count := Line_Count + 1;
	    end if;                           
	 end;
	 
	 if Line_Count > height then	    
	    exit Print_Loop;
	 end if;	 
      end loop Print_Loop;
      
      Total_Lines := Line_Count;
      return True;
   exception
      when others =>
	 return False;
   end Print_Set;
   
   
   
   
   
   Messages_Lock : Binary_Semaphore(True, Default_Ceiling);

   Messages_Set  : Wide_String_Set(20);
   Messages_Last : Natural := 0;
   
   
   task body Midictrl_Process is
      
      task Prog_change_Process is
      	       entry Start(Start_Time : in Time; Tempo : in Tempo_Type; Signature : in Time_Signature_type);
      	       entry Stop;
      	       entry Halt;
      	    end Prog_change_Process;
	    
      	    task body Prog_change_Process is
	       
	       
      	       Started : Boolean := False;
	       
	       
      	       Prog_change_Part : Step_Seq_Array(1..200*16*16);
      	       Part_Index : Natural := 0;
	       
      	       Quantum     : Duration := 0.0;
	       
      	       Tempo : Tempo_Type := 60.0;	 
      	       Signature : Time_Signature_Type := (4, 16);
      	       Date      : Time := Clock;
	       
      	       End_Of_Task : Boolean := False;
      	    begin
	       
	       
	       
	       
      	       while not End_Of_Task loop

      		  loop
      		     select
			
      			accept Start(Start_Time : in Time; Tempo : in Tempo_Type; Signature : in Time_Signature_type) do
			   
      			   if Is_Regular_File("prog_changes_part.txt") then

      			      for Step in Prog_Change_Part'Range loop
				 Step_Vectors.clear(Prog_Change_Part(Step));
			      end loop;

      			      Set_Prog_changes(From => "prog_changes_part.txt", Part => Prog_change_Part, Channel => 0);

      			   end if;
      			   Quantum :=  Duration(60000.0/Float(Tempo))/Signature.Unit/1000.0;

      			   Date := Start_Time;

      			end Start;
      			Started := True;
      			exit;
      		     or
      			accept Stop;
      		     or
      			accept Halt do
      			   End_Of_Task := True;
      			end Halt;
      			exit;
      		     end select;
      		  end loop;
      		  while not End_Of_Task loop
      		     select
			
      			accept Start(Start_Time : in Time; Tempo : in Tempo_Type; Signature : in Time_Signature_type) do
      			   Quantum :=  Duration(60000.0/Float(Tempo))/Signature.Unit/1000.0;
      			   Date := Start_Time;
      			end Start;
			
      		     or
      			accept Stop;
      			exit;
      		     or
      			accept Halt do
      			   End_Of_Task := True;
      			end Halt;
      			exit;
      		     or
      			delay until Date;
			
      			if Started then
			   
      			   if not Is_Empty(Prog_change_Part(Part_Index+1)) then
      			      for Messages in 1..Length(Prog_change_Part(Part_Index+1)) loop
      				 declare
      				    Message : Long := Element(Prog_change_Part(Part_Index+1), Integer(Messages));
      				 begin
				    
      				    if This.Instruments /= null then
				       
      				       for I in This.Instruments.Orchester'Range loop
					  
      					  if This.Instruments.Orchester(I) /= null and then
      					    This.Instruments.Orchester(I).Output_Device_Driver /= null then
      					     declare
      						Printed_Message : constant Printed_Message_Access := new Printed_Message_Type '
      						  (Data_Type => new String ' (Control_Type'Image(Control_Of(Message))),
      						   Channel => new String ' (Channel_Type'Image(Channel_Of(Message))),
      						   Data1 => new String ' (Long'Image(Portmidi.Data1(Message))),
      						   Data2 => new String ' (Long'Image(Portmidi.Data2(Message))),
      						   Hour => new String ' (Formatting.Image(Date, True)),
      						   Hexa_Sum => new String ' (Hex_Image(Message)));
      						--Long_Sum => new String ' (Long'Image(Message)));
						
      						Wide_Line : Wide_String_Access :=
      						  new Wide_String '
      						  (Handling.To_Wide_String(Printed_Message.Data_Type.all) & Wide_Character'Val(9) & 
      						     Handling.To_Wide_String(Printed_Message.Channel.all) & Wide_Character'Val(9) & 
      						     Handling.To_Wide_String(Printed_Message.Data1.all) & Wide_Character'Val(9) & 
      						     Handling.To_Wide_String(Printed_Message.Data2.all) & Wide_Character'Val(9) & 
      						     Handling.To_Wide_String(Printed_Message.Hour.all) & Wide_Character'Val(9) & 
      						     Handling.To_Wide_String(Printed_Message.Hexa_Sum.all) & Wide_Character'Val(9));
      					     begin
						
      						This.Instruments.Orchester(I).Output_Device_Driver.Output_Driver.Receive(Message);
      						Messages_Lock.Seize;
						
      						Add_Line(Messages_Set,
      							 Messages_Last,
      							 Wide_Line.all);
      						Messages_Lock.Release;	     
						
      					     end;
					     
					     
					     
					     
      					  end if;
      				       end loop;
      				    else
      				       Put_Line("Device not found");
      				    end if;
      				 end;
      			      end loop;
      			   end if;
      			   Part_Index := Part_Index + 1;
      			   --delay (Quantum *  Signature.Unit);				 
      			   if Part_Index = Prog_change_Part'Length then
      			      Part_Index := 0;
      			   end if;
      			   Date := Date + Quantum;
      			end if;
      		     end select;
      		  end loop;
      	       end loop;

      	    end Prog_Change_Process;
	    
	    
	    --  task Genetical_Process is
	    --     entry Start(Start_Time : in Time; Tempo : in Tempo_Type; Signature : in Time_Signature_type);
	    --     entry Stop;
	    --     entry Halt;
	    --  end Genetical_Process;
	    
	    --  task body Genetical_Process is
	       
	    --     Best_Frame : Frame.Frame_Type;
	    --     Fit_Frame  : Float := 0.0;
	       
	    --     Date       : Time := Clock;

	       
	    --     Quantum     : Duration := 0.0;
	       
	    --     Tempo : Tempo_Type := 60.0;	 
	    --     Signature : Time_Signature_Type := (4, 4);
	       
	       
	    --     End_Of_Task : Boolean := False;
	    --  begin
	    --     while not End_Of_Task loop

	    --  	  loop
	    --  	     select
			
	    --  		accept Start(Start_Time : in Time; Tempo : in Tempo_Type; Signature : in Time_Signature_type) do
	    --  		   Quantum :=  Duration(60000.0/Float(Tempo))/Signature.Unit/1000.0;
	    --  		   Date := Start_Time;
	    --  		end Start;
	    --  		exit;
	    --  	     or
	    --  		accept Stop;
	    --  	     or
	    --  		accept Halt do
	    --  		   End_Of_Task := True;
	    --  		end Halt;
	    --  		exit;
	    --  	     end select;
	    --  	  end loop;
	    --  	  while not End_Of_Task loop
	    --  	     select
			
	    --  		accept Start(Start_Time : in Time; Tempo : in Tempo_Type; Signature : in Time_Signature_type) do
	    --  		   Quantum :=  Duration(60000.0/Float(Tempo))/Signature.Unit/1000.0;
	    --  		   Date := Start_Time;
	    --  		end Start;
			
	    --  	     or
	    --  		accept Stop;
	    --  		exit;
	    --  	     or
	    --  		accept Halt do
	    --  		   End_Of_Task := True;
	    --  		end Halt;
	    --  		exit;
	    --  	     or
	    --  		delay until Date;
	    --  		Frame.Frame_Rand.Reset;
			
	    --  		Genetic_Frame_Algorithm(Population_Size           => 100,
	    --  					Max_Generations           => 25,
	    --  					Num_No_Change_Generations => 5,
	    --  					Mutation_Probability      => 33.0,
	    --  					Num_Elite_Saved           => 10,
	    --  					Best                      => Best_Frame,
	    --  					Fit                       => Fit_Frame);	       	       
			
	    --  		for Digit_Id in Best_Frame.B_Inf..Best_Frame.B_Sup loop
			   
	    --  		   declare
			      
			      
			      
			      
	    --  		      Message_Note_On  : Long := To_Long(Note_On(Long(Long(5)), 
	    --  								 Long(Best_Frame.Digital_Series(Digit_Id).Position.Digit.Class_Id), 
	    --  								 Long(Best_Frame.Digital_Series(Digit_Id).Position.Digit.Value_Id))); 
			      
			      
			      
			      
	    --  		      Message_Note_Off : Long := To_Long(Note_Off(Long(5), 
	    --  								  Long(Best_Frame.Digital_Series(Digit_Id).Position.Digit.Class_Id)));
			      
	    --  		      Length   : Duration := (Quantum) * Natural((Long(Best_Frame.Digital_Series(Digit_Id).Position.Digit.Data_Id)));
			      
	    --  		   begin
			      
			      
	    --  		      Date := Clock;
			      
	    --  		      if This.Instruments /= null then
				 
	    --  			 for I in This.Instruments.Orchester'Range loop
				    
	    --  			    if This.Instruments.Orchester(I) /= null and then
	    --  			      This.Instruments.Orchester(I).Output_Device_Driver /= null then
				       
				       
	    --  			       This.Instruments.Orchester(I).Output_Device_Driver.Output_Driver.Receive(Message_Note_On);
	    --  			       delay Quantum/16.0;
	    --  			       This.Instruments.Orchester(I).Output_Device_Driver.Output_Driver.Receive(Message_Note_Off);
				       
				       
	    --  			    end if;
	    --  			 end loop;
	    --  		      else
	    --  			 Put_Line("Device not found");
	    --  		      end if;
			      
			      
			      
			      
			      
	    --  		      date := date + Quantum*Signature.Unit/4;
			      
	    --  		   end;
			   
	    --  		end loop;
	    --  	     end select;
	    --  	  end loop;
	    --     end loop;

	    --  end Genetical_Process;
	    
      task Drums_Process is
	 entry Start(Start_Time : in Time; Tempo : in Tempo_Type; Signature : in Time_Signature_type);
	 entry Stop;
	 entry Halt;
      end Drums_Process;
      
      task body Drums_Process is
	 
	 
	 
	 
	 
	 Drums_Part : Step_Seq_Array(1..128);
	 Part_Index : Natural := 0;
	 
	 Quantum     : Duration := 0.0;
	 
	 Tempo : Tempo_Type := 60.0;	 
	 Signature : Time_Signature_Type := (4, 8);
	 Date      : Time := Clock;
	 
	 End_Of_Task : Boolean := False;
      begin
	 
	 
	 
	 
	 while not End_Of_Task loop

	    loop
	       select
		  
		  accept Start(Start_Time : in Time; Tempo : in Tempo_Type; Signature : in Time_Signature_type) do
		     if Is_Regular_File("drums_part.txt") then
			Drums_Part := (others => Empty_Vector);
			Read(From => "drums_part.txt", Part => Drums_Part, Channel => 9);
		     end if;
		     Quantum :=  Duration(60000.0/Float(Tempo))/Signature.Unit/1000.0;
		     Date := Start_Time;
		  end Start;
		  exit;
	       or
		  accept Stop;
	       or
		  accept Halt do
		     End_Of_Task := True;
		  end Halt;
		  exit;
	       end select;
	    end loop;
	    while not End_Of_Task loop
	       select
		  
		  accept Start(Start_Time : in Time; Tempo : in Tempo_Type; Signature : in Time_Signature_type) do
		     Quantum :=  Duration(60000.0/Float(Tempo))/Signature.Unit/1000.0;
		     Date := Start_Time;
		  end Start;
		  
	       or
		  accept Stop;
		  exit;
	       or
		  accept Halt do
		     End_Of_Task := True;
		  end Halt;
		  exit;
	       or
		  delay until Date;
		  
		  
		  
		  if not Is_Empty(Drums_Part(Part_Index+1)) then
		     for Messages in 1..Length(Drums_Part(Part_Index+1)) loop
			declare
			   Message : Long := Element(Drums_Part(Part_Index+1), Integer(Messages));
			begin
			   
			   if This.Instruments /= null then
			      
			      for I in This.Instruments.Orchester'Range loop
				 
				 if This.Instruments.Orchester(I) /= null and then
				   This.Instruments.Orchester(I).Output_Device_Driver /= null then
				    declare
				       Printed_Message : constant Printed_Message_Access := new Printed_Message_Type '
					 (Data_Type => new String ' (Control_Type'Image(Control_Of(Message))),
					  Channel => new String ' (Channel_Type'Image(Channel_Of(Message))),
					  Data1 => new String ' (Long'Image(Portmidi.Data1(Message))),
					  Data2 => new String ' (Long'Image(Portmidi.Data2(Message))),
					  Hour => new String ' (Formatting.Image(Date, True)),
					  Hexa_Sum => new String ' (Hex_Image(Message)));
				       --Long_Sum => new String ' (Long'Image(Message)));
				       
				       Wide_Line : Wide_String_Access :=
					 new Wide_String '
					 (Handling.To_Wide_String(Printed_Message.Data_Type.all) & Wide_Character'Val(9) & 
					    Handling.To_Wide_String(Printed_Message.Channel.all) & Wide_Character'Val(9) & 
					    Handling.To_Wide_String(Printed_Message.Data1.all) & Wide_Character'Val(9) & 
					    Handling.To_Wide_String(Printed_Message.Data2.all) & Wide_Character'Val(9) & 
					    Handling.To_Wide_String(Printed_Message.Hour.all) & Wide_Character'Val(9) & 
					    Handling.To_Wide_String(Printed_Message.Hexa_Sum.all) & Wide_Character'Val(9));
				    begin
				       
				       This.Instruments.Orchester(I).Output_Device_Driver.Output_Driver.Receive(Message);
				       Messages_Lock.Seize;
				       
				       Add_Line(Messages_Set,
						Messages_Last,
						Wide_Line.all);
				       Messages_Lock.Release;	     
				       
				    end;
				    
				    
				    
				    
				 end if;
			      end loop;
			   else
			      Put_Line("Device not found");
			   end if;
			end;
		     end loop;
		  end if;
		  Part_Index := Part_Index + 1;
		  --delay (Quantum *  Signature.Unit);				 
		  if Part_Index = Drums_Part'Length then
		     Part_Index := 0;
		  end if;
		  Date := Date + Quantum;
		  
	       end select;
	    end loop;
	 end loop;

      end Drums_Process;
      
      task Bass_Process is
	 entry Start(Start_Time : in Time; Tempo : in Tempo_Type; Signature : in Time_Signature_type);
	 entry Stop;
	 entry Halt;
      end Bass_Process;
      
      task body Bass_Process is
	 
	 Bass_Part : Step_Seq_Array(1..128);
	 Part_Index : Natural := 0;
	 
	 Quantum     : Duration := 0.0;
	 
	 Tempo : Tempo_Type := 60.0;	 
	 Signature : Time_Signature_Type := (4, 8);
	 Date      : Time := Clock;
	 
	 End_Of_Task : Boolean := False;
      begin
	 
	 
	 
	 
	 while not End_Of_Task loop

	    loop
	       select
		  
		  accept Start(Start_Time : in Time; Tempo : in Tempo_Type; Signature : in Time_Signature_type) do
		     if Is_Regular_File("bass_part.txt") then
			Bass_Part := (others => Empty_Vector);
			Read(From => "bass_part.txt", Part => Bass_Part, Channel => 7);
		     end if;
		     Quantum :=  Duration(60000.0/Float(Tempo))/Signature.Unit/1000.0;
		     Date := Start_Time;
		  end Start;
		  exit;
	       or
		  accept Stop;
	       or
		  accept Halt do
		     End_Of_Task := True;
		  end Halt;
		  exit;
	       end select;
	    end loop;
	    while not End_Of_Task loop
	       select
		  
		  accept Start(Start_Time : in Time; Tempo : in Tempo_Type; Signature : in Time_Signature_type) do
		     Quantum :=  Duration(60000.0/Float(Tempo))/Signature.Unit/1000.0;
		     Date := Start_Time;
		  end Start;
		  
	       or
		  accept Stop;
		  exit;
	       or
		  accept Halt do
		     End_Of_Task := True;
		  end Halt;
		  exit;
	       or
		  delay until Date;
		  
		  
		  
		  if not Is_Empty(Bass_Part(Part_Index+1)) then
		     for Messages in 1..Length(Bass_Part(Part_Index+1)) loop
			declare
			   Message : Long := Element(Bass_Part(Part_Index+1), Integer(Messages));
			begin
			   
			   if This.Instruments /= null then
			      
			      for I in This.Instruments.Orchester'Range loop
				 
				 if This.Instruments.Orchester(I) /= null and then
				   This.Instruments.Orchester(I).Output_Device_Driver /= null then
				    declare
				       Printed_Message : constant Printed_Message_Access := new Printed_Message_Type '
					 (Data_Type => new String ' (Control_Type'Image(Control_Of(Message))),
					  Channel => new String ' (Channel_Type'Image(Channel_Of(Message))),
					  Data1 => new String ' (Long'Image(Portmidi.Data1(Message))),
					  Data2 => new String ' (Long'Image(Portmidi.Data2(Message))),
					  Hour => new String ' (Formatting.Image(Date, True)),
					  Hexa_Sum => new String ' (Hex_Image(Message)));
				       --Long_Sum => new String ' (Long'Image(Message)));
				       Wide_Line : Wide_String_Access :=
					 new Wide_String '
					 (Handling.To_Wide_String(Printed_Message.Data_Type.all) & Wide_Character'Val(9) & 
					    Handling.To_Wide_String(Printed_Message.Channel.all) & Wide_Character'Val(9) & 
					    Handling.To_Wide_String(Printed_Message.Data1.all) & Wide_Character'Val(9) & 
					    Handling.To_Wide_String(Printed_Message.Data2.all) & Wide_Character'Val(9) & 
					    Handling.To_Wide_String(Printed_Message.Hour.all) & Wide_Character'Val(9) & 
					    Handling.To_Wide_String(Printed_Message.Hexa_Sum.all) & Wide_Character'Val(9));
				    begin
				       This.Instruments.Orchester(I).Output_Device_Driver.Output_Driver.Receive(Message);
				       Messages_Lock.Seize;
				       Add_Line(Messages_Set,
						Messages_Last,
						Wide_Line.all);
				       Messages_Lock.Release;
				    end;
				    
				    
				    
				    
				 end if;
			      end loop;
			   else
			      Put_Line("Device not found");
			   end if;
			end;
		     end loop;
		  end if;
		  Part_Index := Part_Index + 1;
		  --delay (Quantum *  Signature.Unit);
		  if Part_Index = Bass_Part'Length then
		     Part_Index := 0;
		  end if;
		  Date := Date + Quantum * Signature.Unit/8;
		  
	       end select;
	    end loop;
	 end loop;

      end Bass_Process;
      
      
      task Lead_Process is
	 entry Start(Start_Time : in Time; Tempo : in Tempo_Type; Signature : in Time_Signature_type);
	 entry Stop;
	 entry Halt;
      end Lead_Process;
      
      task body Lead_Process is
	 
	 Lead_Part : Step_Seq_Array(1..16);
	 Part_Index : Natural := 0;
	 
	 Quantum     : Duration := 0.0;
	 
	 Tempo : Tempo_Type := 60.0;	 
	 Signature : Time_Signature_Type := (4, 8);
	 Date      : Time := Clock;
	 
	 End_Of_Task : Boolean := False;
      begin
	 
	 
	 
	 
	 while not End_Of_Task loop

	    loop
	       select
		  
		  accept Start(Start_Time : in Time; Tempo : in Tempo_Type; Signature : in Time_Signature_type) do
		     if Is_Regular_File("lead_part.txt") then
			Lead_Part := (others => Empty_Vector);
			Read(From => "lead_part.txt", Part => Lead_Part, Channel => 6);
		     end if;
		     Quantum :=  Duration(60000.0/Float(Tempo))/Signature.Unit/1000.0;
		     Date := Start_Time;
		  end Start;
		  exit;
	       or
		  accept Stop;
	       or
		  accept Halt do
		     End_Of_Task := True;
		  end Halt;
		  exit;
	       end select;
	    end loop;
	    while not End_Of_Task loop
	       select
		  
		  accept Start(Start_Time : in Time; Tempo : in Tempo_Type; Signature : in Time_Signature_type) do
		     Quantum :=  Duration(60000.0/Float(Tempo))/Signature.Unit/1000.0;
		     Date := Start_Time;
		  end Start;
		  
	       or
		  accept Stop;
		  exit;
	       or
		  accept Halt do
		     End_Of_Task := True;
		  end Halt;
		  exit;
	       or
		  delay until Date;
		  
		  
		  
		  if not Is_Empty(Lead_Part(Part_Index+1)) then
		     for Messages in 1..Length(Lead_Part(Part_Index+1)) loop
			declare
			   Message : Long := Element(Lead_Part(Part_Index+1), Integer(Messages));
			begin
			   
			   if This.Instruments /= null then
			      
			      for I in This.Instruments.Orchester'Range loop
				 
				 if This.Instruments.Orchester(I) /= null and then
				   This.Instruments.Orchester(I).Output_Device_Driver /= null then
				    declare
				       Printed_Message : constant Printed_Message_Access := new Printed_Message_Type '
					 (Data_Type => new String ' (Control_Type'Image(Control_Of(Message))),
					  Channel => new String ' (Channel_Type'Image(Channel_Of(Message))),
					  Data1 => new String ' (Long'Image(Portmidi.Data1(Message))),
					  Data2 => new String ' (Long'Image(Portmidi.Data2(Message))),
					  Hour => new String ' (Formatting.Image(Date, True)),
					  Hexa_Sum => new String ' (Hex_Image(Message)));
				       --Long_Sum => new String ' (Long'Image(Message)));
				       Wide_Line : Wide_String_Access :=
					 new Wide_String '
					 (Handling.To_Wide_String(Printed_Message.Data_Type.all) & Wide_Character'Val(9) & 
					    Handling.To_Wide_String(Printed_Message.Channel.all) & Wide_Character'Val(9) & 
					    Handling.To_Wide_String(Printed_Message.Data1.all) & Wide_Character'Val(9) & 
					    Handling.To_Wide_String(Printed_Message.Data2.all) & Wide_Character'Val(9) & 
					    Handling.To_Wide_String(Printed_Message.Hour.all) & Wide_Character'Val(9) & 
					    Handling.To_Wide_String(Printed_Message.Hexa_Sum.all) & Wide_Character'Val(9));
				    begin
				       This.Instruments.Orchester(I).Output_Device_Driver.Output_Driver.Receive(Message);
				       Messages_Lock.Seize;
				       Add_Line(Messages_Set,
						Messages_Last,
						Wide_Line.all);
				       Messages_Lock.Release;
				    end;
				    
				    
				    
				    
				 end if;
			      end loop;
			   else
			      Put_Line("Device not found");
			   end if;
			end;
		     end loop;
		  end if;
		  Part_Index := Part_Index + 1;
		  --delay (Quantum *  Signature.Unit);
		  if Part_Index = Lead_Part'Length then
		     Part_Index := 0;
		  end if;
		  Date := Date + Quantum * Signature.Unit/8;
		  
	       end select;
	    end loop;
	 end loop;

      end Lead_Process;

      
      
      
      
      
      
      
      Start_Time  : Time := Clock;
      Quantum     : Duration := 0.0;
      
      Tempo : Tempo_Type := 60.0;	 
      Signature : Time_Signature_Type := (4, 4);
      
      Date      : Time := Clock;
      
      
      Mod_Play_On : Boolean := False;
      Mod_Rec_On  : Boolean := False;
      
      
      
      End_Of_Task : Boolean := False;
   begin
  Main_Loop:
      while not End_Of_Task loop

	 loop

	    select
	       accept Initialize do
		  null;
	       end Initialize;
	    or
	       accept Start(Tempo : in Tempo_Type) do

		  Start_Time := Clock;

		  Quantum :=  Duration(60000.0/Float(Tempo))/Signature.Unit/1000.0;

		  if This.Instruments /= null then

		     for I in This.Instruments.Orchester'Range loop

			This.Instruments.Orchester(i).Mod_Seq.Start(Tempo, Signature);
			--Text_Io.Put_Line("Mod_Seq started");

			This.Instruments.Orchester(i).Tempo_Sync.Start(Start_Time, Tempo, Signature);
			--Text_Io.Put_Line("Tempo_Sync started");
		     end loop;
		  end if;

		  Prog_Change_Process.Start(Start_Time, Tempo, Signature);

		  --  Genetical_Process.Start(Start_Time, Tempo, Signature);
		  Drums_Process.Start(Start_Time, Tempo, Signature);

		  Bass_Process.Start(Start_Time, Tempo, Signature);

		  Lead_Process.Start(Start_Time, Tempo, Signature);

	       end Start;
	       exit;
	    or
	       accept Stop do
		  Prog_Change_Process.Stop;
		  --  Genetical_Process.Stop;
		  Drums_Process.Stop;
		  Bass_Process.Stop;
		  Lead_Process.Stop;
		  --  if This.Instruments /= null then
		  --     for I in This.Instruments.Orchester'Range loop
		  --  	This.Instruments.Orchester(i).Mod_Seq.stop;
		  --  	This.Instruments.Orchester(i).Tempo_Sync.stop;
		  --     end loop;
		  --  end if;
		  null;
	       end Stop;
	    or
	       accept Mod_Rec do
		  Mod_Rec_On := not Mod_Rec_On;
		  if This.Instruments /= null then
		     for I in This.Instruments.Orchester'Range loop
			This.Instruments.Orchester(i).Mod_Seq.Rec(Mod_Rec_On);
		     end loop;
		  end if;
	       end Mod_Rec;
	    or
	       accept Mod_Play do
		  Mod_Play_On := not Mod_Play_On;
		  if This.Instruments /= null then
		     for I in This.Instruments.Orchester'Range loop
			This.Instruments.Orchester(i).Mod_Seq.Play(Mod_Play_on);
		     end loop;
		  end if;
	       end Mod_Play;
	    or
	       accept Mod_Reset do
		  if This.Instruments /= null then
		     for I in This.Instruments.Orchester'Range loop
			This.Instruments.Orchester(i).Mod_Seq.Reset;
		     end loop;
		  end if;
	       end Mod_Reset;
	    or
	       accept Halt do
		  
		  
		  Prog_Change_Process.Halt;
		  --Genetical_Process.Halt;
		  delay 0.1;
		  Drums_Process.Halt;
		  delay 0.1;
		  Bass_Process.Halt;
		  delay 0.1;
		  Lead_Process.Halt;
		  delay 0.1;
		  if This.Instruments /= null then
		     for I in This.Instruments.Orchester'Range loop
			
			This.Instruments.Orchester(i).Mod_Seq.Halt;
			This.Instruments.Orchester(i).Tempo_Sync.Halt;
			if This.Instruments.Orchester(i).Input_Device_Driver /= null then
			   
			   This.Instruments.Orchester(i).Input_Device_Driver.Input_Driver.Halt;
			   
			   Input_Driver_Free(This.Instruments.Orchester(i).Input_Device_Driver);
			else
			   Text_Io.Put_Line("No input driver for instrument N" &Integer'Image(Integer(I)));
			end if;
		     end loop;
		     This.Instruments.Finalize;    
		  end if;
		  
		  End_Of_Task := True;
	       end Halt;
	       exit Main_Loop;
	    end select;

	 end loop;


	 declare
	    	    
	 begin
	    while not End_Of_Task loop
	       select
		  accept Initialize;
	       or
		  accept Start(Tempo : in Tempo_Type) do
		     Quantum :=  Duration(60000.0/Float(Tempo))/Signature.Unit/1000.0;
		     
		     Start_Time := Clock;
		     
		     if This.Instruments /= null then
		     	for I in This.Instruments.Orchester'Range loop
		     	   
		     	   This.Instruments.Orchester(i).Mod_Seq.Start(Tempo, Signature);
		     	   --Text_Io.Put_Line("Mod_Seq started");
		     	   This.Instruments.Orchester(i).Tempo_Sync.Start(Start_Time, Tempo, Signature);
		     	   --Text_Io.Put_Line("Tempo_Sync started");
		     	end loop;
		     end if;
		     Prog_Change_Process.Start(Start_Time, Tempo, Signature);
		     --  Genetical_Process.Start(Start_Time, Tempo, Signature);
		     Drums_Process.Start(Start_Time, Tempo, Signature);
		     Bass_Process.Start(Start_Time, Tempo, Signature);
		     Lead_Process.Start(Start_Time, Tempo, Signature);
		  end Start;
	       or
		  accept Stop do
		     Prog_Change_Process.Stop;
		     
		     --Genetical_Process.Stop;

		     Drums_Process.Stop;

		     Bass_Process.Stop;

		     Lead_Process.Stop;

		     
		     
		     if This.Instruments /= null then

		     	for I in This.Instruments.Orchester'Range loop

		     	   This.Instruments.Orchester(i).Mod_Seq.stop;
		     	   This.Instruments.Orchester(i).Tempo_Sync.stop;
		     	end loop;
		     end if;

		  end Stop;
		  exit;
	       or

		  accept Mod_Rec do
		     Mod_Rec_On := not Mod_Rec_On;
		     if This.Instruments /= null then
			for I in This.Instruments.Orchester'Range loop
			   This.Instruments.Orchester(i).Mod_Seq.Rec(Mod_Rec_On);
			end loop;
		     end if;
		  end Mod_Rec;
	       or
		  accept Mod_Play do
		     Mod_Play_On := not Mod_Play_On;
		     if This.Instruments /= null then
			for I in This.Instruments.Orchester'Range loop
			   This.Instruments.Orchester(i).Mod_Seq.Play(Mod_Play_on);
			end loop;
		     end if;
		  end Mod_Play;
	       or
		  accept Mod_Reset do
		     if This.Instruments /= null then
			for I in This.Instruments.Orchester'Range loop
			   This.Instruments.Orchester(i).Mod_Seq.Reset;
			end loop;
		     end if;
		  end Mod_Reset;
	       or
		  accept Halt do

		     Prog_Change_Process.Halt;
		     
		     --Genetical_Process.Halt;
		     
		     Drums_Process.Halt;
		     
		     Bass_Process.Halt;
		     
		     Lead_Process.Halt;
		     
		     if This.Instruments /= null then
			for I in This.Instruments.Orchester'Range loop
			   
			   This.Instruments.Orchester(i).Mod_Seq.Halt;
			   This.Instruments.Orchester(i).Tempo_Sync.Halt;
			   if This.Instruments.Orchester(i).Input_Device_Driver /= null then
			      
			      This.Instruments.Orchester(i).Input_Device_Driver.Input_Driver.Halt;
			      
			      Input_Driver_Free(This.Instruments.Orchester(i).Input_Device_Driver);
			   else
			      Text_Io.Put_Line("No input driver for instrument N" & Integer'Image(Integer(I)));
			   end if;
			end loop;
			This.Instruments.Finalize;    
		     end if;

		     End_Of_Task := True;
		  end Halt;
		  exit Main_Loop;
	       end select;

	    end loop;

	 end;

      end loop Main_Loop;
      
   end Midictrl_Process;
   
   


   Window : Window_Type;
   
   
   task body Midiconsole_Process is
      
      
      
      
      
      
      Midictrl_header    : Window_Record := (1, 1, 8, This.Columns/2, Blue, window);
      Midictrl_Messages  : Window_Record := (9+(This.Lines-16)/2, 1, (This.Lines-16)/2, This.Columns/2, Blue, Window);
      Midictrl_Transport : Window_Record := (This.Lines-7, 1, 5, This.Columns/2, Blue, Window);
      Midictrl_Cmd_Line  : Window_Record := (This.Lines-2, 1, 3, This.Columns/2, Blue, Window);
   

      Start_Time  : Time := Clock;
      Quantum     : Duration := 0.0;
      
      Tempo : Tempo_Type := 60.0;	 
      
      
      
      
      Cmd_Line : Wide_String (1..20);
      Cmd_Last : Natural := 0;
      
      
      type MIDICmd_Enum is (None, Start, Stop, Halt);
      
      function Value (Line : in Wide_String) return MIDICmd_Enum is
	 Cmd : MIDICmd_Enum := None;
      begin
	 if Wide_Fixed.Index(Line, " ") /= 0 then

	    Cmd := MIDICmd_Enum'Value (Handling.To_String(Line(Line'First..Wide_Fixed.Index(Line, " ") - 1)));

	 else

	    Cmd := MIDICmd_Enum'Value (Handling.To_String(Line));

	 end if;
	 return Cmd;
      exception
	 when Constraint_Error =>

	    return Cmd;
      end Value;
      
      
      
      function Elapsed_Time (Top, Bot : in Time) return String is
	 Years    : Natural := 0;
	 Months   : Natural := 0;
	 Days     : Natural := 0;
	 Houres   : Natural := 0;
	 Minutes  : Natural := 0;
	 Seconds  : Natural := 0;
	 Rest     : Duration := 0.0;
      begin
	 Tools.Difference_In_Years(Top, Bot, Years, Months, Days, Houres, Minutes, Seconds, Rest);
	 return Natural'Image(Years) & " years, " &
	   Natural'Image(Months) & " months, " &
	   Natural'Image(Days) & " days, " &
	   Natural'Image(Houres) & ":" &
	   Natural'Image(Minutes) & ":" &
	   Natural'Image(Seconds);
      end Elapsed_Time;
      
      
      MIDICmd : MIDICmd_Enum := None;
      Started : Boolean := False;
      Mod_Play : Boolean := False;
      Mod_Rec  : Boolean := False;
      
      Cpu    : Cpu_String := (others => ' ');
      Total_Line : Natural := 0;
      
      Success : Boolean := False;
            
      
   begin      
      
      Initialize(Midictrl_Header, 1, 1, 8, This.Columns/2, Blue, White);
      Initialize(Midictrl_messages, 9+(This.Lines-16)/2, 1, (This.Lines-16)/2, This.Columns/2, Blue, White);
      Initialize(Midictrl_Transport, This.Lines-7, 1, 5, This.Columns/2, Blue, White);
      Initialize(Midictrl_Cmd_Line, This.Lines-2, 1, 3, This.Columns/2, Blue, White);
      
	 	 
      begin	 
     Main_Loop:
	 loop
	    loop
	       select
		  
		  accept Halt do
		     
		     This.Midictrl.Halt;
		     
		  end Halt;
		  exit Main_Loop;
	       or
		  accept Suspend;
	       or
		  accept Wake_Up Do
		     Errno := System("clear" & Character'Val(0));
		     Draw_Window(Midictrl_Header);
		     Draw_Text(Midictrl_Header, 2, Columns/4-8, Yellow, "Computerman 18.1.4r");
		     if Mod_Rec then
			Draw_Text(Midictrl_Header, 3, 2, white, "Mod Rec : On");
		     else
			Draw_Text(Midictrl_Header, 3, 2, white, "Mod Rec : Off");
		     end if;
		     if Mod_Play then
			Draw_Text(Midictrl_Header, 4, 2, white, "Mod Play : On");
		     else
			Draw_Text(Midictrl_Header, 4, 2, white, "Mod Play : Off");
		     end if;
		     Draw_Window(Midictrl_Messages);
		     Draw_Window(Midictrl_Transport);
		     if Started then
			Draw_Text(Midictrl_Header, 5, 2, White, "Status : Started");
		     else
			Draw_Text(Midictrl_header, 5, 2, White, "Status : Stopped");
		     end if;
		     Draw_Text(MIDICtrl_header, 6, 2, White, "CPU : " & Handling.To_Wide_String(Cpu));
		     Draw_Text(Midictrl_Transport, 2, Columns/4+1, White, "Tempo    : " & Handling.To_Wide_String(Tempo_Type'Image(Tempo)));
		     Draw_Window(Midictrl_Cmd_Line);
		     if Cmd_Last = 0 then
			Draw_Text(MidiCtrl_Cmd_Line, 1, 1, White, "");
		     else
			Draw_Text(MidiCtrl_Cmd_Line, 1, 1, White, Cmd_Line(1..Cmd_Last));
		     end if;
		  
		     
		  end Wake_Up;
		  exit;
	       end select;
	    end loop;
	    loop
	       select
		  accept Halt do
		     This.Midictrl.Halt;
		  end Halt;
		  exit Main_Loop;
	       or
		  accept Suspend do
		     null;
		  end Suspend;
		     
		  exit;
	       or
		  accept Wake_Up;
	       or
		  
		  accept Receive(Wchar : in Wide_Character) do
		     if Is_Control (Wchar) then
			case Wchar is
			   when Wide_Character'Val (5) =>
			      -- Ctrl+E : Mod_Reset
			      This.Midictrl.Mod_Reset;
			   when Wide_Character'Val (9) =>
			      null;
			   when Wide_Character'Val (10) =>
			      if Cmd_Last /= 0 then

				 MIDICmd := Value(Cmd_Line);

				 case MIDICmd is
				    when None =>
				       null;
				    when Start =>
				       if Cmd_Last > MIDICmd_Enum'Image(MIDICmd)'Last+1 then
					  begin
					     
					     Tempo := Tempo_Type'Value(Handling.To_String(Cmd_Line(MIDICmd_Enum'Image(MIDICmd)'Last+2..Cmd_Last)));
					     
					  exception
					     when Constraint_Error =>
						null;
					  end;
				       end if;

				       This.Midictrl.Start(Tempo);
				       if not Started then
					  Start_Time := Clock;
				       end if;
				       Started := True;
				    when Stop =>
				       This.Midictrl.Stop;
				       Started := False;
				       
				    when Halt =>
				       This.Midictrl.Halt;
				 end case;
				 Cmd_Line := (others => ' ');
				 Cmd_Last := 0;
			      end if;
			   when Wide_Character'Val (16) =>
			      -- Ctrl+P : Mod_Play
			      This.Midictrl.Mod_Play;
			      Mod_Play := not Mod_Play;
			   when Wide_Character'Val (18) =>
			      -- Ctrl+R : Mod_Rec
			      This.Midictrl.Mod_Rec;
			      Mod_Rec := not Mod_Rec;
			   when Wide_Character'Val (127) =>
			      Cmd_Line(Cmd_Last) := ' ';
			      Cmd_Last := Cmd_Last - 1;
			   when others =>
			      null;
			end case;
		     elsif Cmd_Last = 0 and Wchar = ' ' then
			case Started is
			   when False =>
			      This.Midictrl.Start(Tempo);
			      Start_Time := Clock;
			      Started := True;
			   when True =>
			      This.Midictrl.Stop;
			      Started := False;
			end case;
			
		     else
			Cmd_Line(Cmd_Last + 1) := Wchar;
			Cmd_Last := Cmd_Last + 1;
		     end if;
		     
		  end Receive;
		  Draw_Window(Midictrl_Header);
		  Draw_Text(Midictrl_Header, 2, Columns/4-8, Yellow, "Computerman 18.1.4r");
		  if Mod_Rec then
		     Draw_Text(Midictrl_Header, 3, 2, white, "Mod Rec : On");
		  else
		     Draw_Text(Midictrl_Header, 3, 2, white, "Mod Rec : Off");
		  end if;
		  if Mod_Play then
			Draw_Text(Midictrl_Header, 4, 2, white, "Mod Play : On");
		  else
		     Draw_Text(Midictrl_Header, 4, 2, white, "Mod Play : Off");
		  end if;
		  if Started then
		     Draw_Text(Midictrl_Header, 5, 2, White, "Status : Started");
		  else
		     Draw_Text(Midictrl_header, 5, 2, White, "Status : Stopped");
		  end if;
		  Draw_Window(Midictrl_Transport);
		  Draw_Text(Midictrl_Transport, 2, Columns/4+1, White, "Tempo    : " & Handling.To_Wide_String(Tempo_Type'Image(Tempo)));
		  Draw_Window(Midictrl_Cmd_Line);
		  if Cmd_Last = 0 then
		     Draw_Text(MidiCtrl_Cmd_Line, 1, 1, White, "");
		  else
		     Draw_Text(MidiCtrl_Cmd_Line, 1, 1, White, Cmd_Line(1..Cmd_Last));
		  end if;
	       or
		  accept Refresh;
		  
	       or
		  accept Page_Down;
	       or
		  accept Page_Up;
	       or
		  accept Up_Arrow do
		     null;
		  end up_arrow;
	       or
		  accept Down_Arrow do
		     null;
		  end Down_Arrow;
	       or
		  accept Left_Arrow;
	       or
		  accept Right_Arrow;
	       or
		  accept Full_Screen;
	       or
		  accept Del;
	       or
		  accept Begin_Of;
	       or
		  accept End_Of;
	       or
		  accept Overwrite;
	       or
		  accept Screen_Print;
	       or
		  delay 0.5;
		  
		  Cpu_Process.Initialize;
		  CPU_Process.Cpu_Get(Cpu);
		  
		  Messages_Lock.Seize;
		  Text_Io.Put(Save_Cursor);
		  
		  Draw_Text(MIDICtrl_header, 6, 2, White, "CPU : " & Handling.To_Wide_String(Cpu));
		  
		  Draw_Window(Midictrl_Transport);
		  Draw_Text(Midictrl_Transport, 2, Columns/4+1, White, "Tempo   : " & Handling.To_Wide_String(Tempo_Type'Image(Tempo)));
		  if Started then
		     Draw_Text(MIDICtrl_Transport, 3, Columns/4+1, White, "Elapsed : " & Handling.To_Wide_String(Elapsed_Time(Start_Time, clock)));
		     
		  end if;
		  
		  if Messages_Last > 0 then
		     Draw_Window(Midictrl_Messages);
		     Success := Print_Set(Messages_Set,
					  MIDICtrl_Messages,
					  0,
					  Total_Line);
		     
		  end if;
		  Text_Io.Put(Restore_Cursor);
		  Messages_Lock.Release;   
		     
		  
		     
	       end select;
	    end loop;
	    
	    
	 end loop Main_Loop;
      end;

   end Midiconsole_Process;
   
   
   
   --
   
   
   
   -------------------------------------------------------------------------------------------------------------
   --                                                                                                         --
   --
   -------------------------------------------------------------------------------------------------------------
   task body Editor_Process is
   begin

      begin
     Main_Loop:
	 loop
	    loop
	       select
		  accept Halt;
		  exit Main_Loop;
	       or
		  accept Suspend;
		  exit;
	       or
		  accept Wake_Up;
	       or
		  
		  accept Receive(Wchar : in Wide_Character);
	       or

		  accept Refresh;
		  
	       or
		  accept Page_Down;
	       or
		  accept Page_Up;
	       or
		  accept Up_Arrow do
		     null;
		  end up_arrow;
	       or
		  accept Down_Arrow do
		     null;
		  end Down_Arrow;
	       or
		  accept Left_Arrow;
	       or
		  accept Right_Arrow;
	       or
		  accept Full_Screen;
	       or
		  accept Del;
	       or
		  accept Begin_Of;
	       or
		  accept End_Of;
	       or
		  accept Overwrite;
	       or
		  accept Screen_Print;

	       end select;
	    end loop;
	    
	    loop
	       select
		  
		  accept Halt do
		     null;
		  end Halt;
		  exit Main_Loop;
	       or
		  accept Suspend;
	       or
		  accept Wake_Up Do
		     Errno := System("clear" & Character'Val(0));
		     null;
		  end Wake_Up;
		  exit;
	       end select;
	    end loop;
	 end loop Main_Loop;
      end;
   end Editor_Process;
   
   
   -------------------------------------------------------------------------------------------------------------
   --                                                                                                         --
   --
   -------------------------------------------------------------------------------------------------------------

   -------------------------------------------------------------------------------------------------------------
   --                                                                                                         --
   --
   -------------------------------------------------------------------------------------------------------------
   
   type Value_Enum is (None_Value, Name_Value, Price_Ht_Value, Quantity_Value, Tva_Rate_Value,
		       Total_Ht_Value, Total_Tva_Value, Total_Ttc_Value, Delete_value);
   
   type Value_Type is
      record
	 Name : Value_Enum := None_Value;
	 Line : Wstring_32 := (others => ' ');
	 Line_Last : Natural := 0;
	 Line_Pos      : Line_Range := 1;
	 Column_Pos    : Column_Range := 1;
      end record;
   
   type Value_Array is array (Value_Enum) of Value_Type;
   
   type Line_Cursor_Type is
      record
	 Values  : Value_Array;
	 Val_Cur : Value_Enum := name_Value;	 
      end record;
   
   function Initialize return Line_Cursor_Type is
      Curs : Line_Cursor_Type;
   begin
      Curs.Values(Name_value) :=
	(Name_Value,
	 (others => ' '),
	 0,
	 3,
	 13
	);
      Curs.Values(Price_Ht_value) :=
	(Price_Ht_Value,
	 (others => ' '),
	 0,
	 5,
	 13
	);
      Curs.Values(Quantity_value) :=
	(Quantity_Value,
	 (others => ' '),
	 0,
	 7,
	 13
	);
      Curs.Values(TVA_Rate_value) :=
	(TVA_Rate_Value,
	 (others => ' '),
	 0,
	 9,
	 13
	);
      Curs.Values(Total_Ht_value) :=
	(Total_Ht_Value,
	 (others => ' '),
	 0,
	 11,
	 13
	);
      Curs.Values(Total_Tva_value) :=
	(Total_Tva_Value,
	 (others => ' '),
	 0,
	 13,
	 13
	);
      Curs.Values(Total_ttc_value) :=
	(Total_Ttc_Value,
	 (others => ' '),
	 0,
	 15,
	 13
	);
      Curs.Val_Cur := Name_Value;
      return Curs;
   end Initialize;
   
   
   function To_Account_Line (Curs : in Line_Cursor_Type;Account_Num : in Account_Num_Range;Line_Num : in Account_Line_Range) return Account_Line_Type is
      Line : Account_Line_Type := Null_Line;
   begin
      Line.Line_Num := Line_Num;
      Line.Description(1..Curs.Values(Name_Value).Line_Last) := 
	Curs.Values(Name_Value).Line(1..Curs.Values(Name_Value).Line_Last);

      Line.Account_num := Account_Num;
      
      Line.Unit_Ht_Price := 
	Fixed_Unit_Ht'Value(Handling.To_String(Curs.Values(Price_Ht_Value).Line(1..Curs.Values(Price_Ht_Value).Line_Last)));
      
      Line.Tva_Rate := 
	Fixed_Factor'Value(Handling.To_String(Curs.Values(Tva_Rate_Value).Line(1..Curs.Values(Tva_Rate_Value).Line_Last)));
      
      Line.Quantity := 
	Quantity_Range'Value(Handling.To_String(Curs.Values(Quantity_Value).Line(1..Curs.Values(Quantity_Value).Line_Last)));
      
      
      Line.Total_Ht := Fixed_Total(Line.Unit_Ht_Price * Fixed_Unit_Ht(Line.Quantity));
      
      Line.Total_Tva := Fixed_total(Line.Total_Ht / Fixed_Total(100.0)) * Fixed_Total(Line.Tva_Rate);
      
      Line.Total_Ttc := Line.Total_Ht + Line.Total_Tva;

      return Line;
   exception
      when others =>
	 raise Spec_Error;
   end To_Account_Line;
   
   
   function To_String (Line : in Account_Line_Type) return Wide_String is
   begin
      return 
	Handling.To_Wide_String
	(
	 Natural'Image(Line.Line_Num) & Character'Val(9) &
	   " " & Handling.To_String(Line.Description(1..16)) 
	   & "  " & Quantity_Range'Image(Line.Quantity) & Character'Val(9) &
	   Fixed_Factor'Image(Line.Tva_Rate) & Character'Val(9) &
	   Fixed_total'Image(Line.total_ht) & Character'Val(9) &
	   Fixed_total'Image(Line.total_TVA) & Character'Val(9) &
	   Fixed_total'Image(Line.total_TTC)
	);
   end To_String;
	
   
   
   
   
   
   procedure Initialize(Wins : out Ticket_Windows_Type;
			Space_Left : in Line_Range;
			Width      : in Column_Range;
			L       : in Line_Range;
			C        : in Column_Range) is
   begin
      
      
      Wins.Line_Num_Win := (L+2, C, Space_Left-2, 8,  
			    Cyan, Window);
      Wins.Description_Win := (L+2, C+8, Space_Left-2, 18,
      			       Cyan, Window);
      Wins.unit_Ht_Win := (L+2, C+26, Space_Left-2, 12,  
      			    Cyan, Window);
      Wins.Quantity_Win := (L+2, C+38, Space_Left-2, 14,  
      			       Cyan, Window);
      Wins.Total_Ht_Win := (L+2, C+52, Space_Left-2, 16,  
      			    Cyan, Window);
      Wins.TVA_Win := (L+2, C+68, Space_Left-2, 10,  
      		    Cyan, Window);
      Wins.Total_TVA_Win := (L+2, C+78, Space_Left-2, 16,  
      			     Cyan, Window);
      Wins.Total_TTC_Win := (L+2, C+94, Space_Left-2, 16,  
      			     Cyan, Window);
      
      Initialize(Wins.Line_Num_Win, L+2, C, Space_Left-2, 8,  Cyan, Red);
      Initialize(Wins.Description_Win, L+2, C+8, Space_Left-2, 18,  Cyan, Red);
      Initialize(Wins.unit_Ht_Win, L+2, C+26, Space_Left-2, 12, Cyan, Red);
      Initialize(Wins.quantity_Win, L+2, C+38, Space_Left-2, 14,  Cyan, Red);
      Initialize(Wins.Total_Ht_Win, L+2, C+52, Space_Left-2, 16, Cyan, Red);
      Initialize(Wins.TVA_Win, L+2, C+68, Space_Left-2, 10, Cyan, Red);
      Initialize(Wins.Total_TVA_Win, L+2, C+78, Space_Left-2, 16, Cyan, Red);
      Initialize(Wins.Total_TTC_Win, L+2, C+94, Space_Left-2, 16, Cyan, Red);
      
      null;
   end Initialize;

   
   procedure Ticket_Wins_Draw(Wins : Ticket_Windows_Type) is
      
   begin
      Draw_Window(Wins.Line_Num_Win);
      Draw_Window(Wins.Description_Win);
      Draw_Window(Wins.Unit_Ht_Win);
      Draw_Window(Wins.Quantity_Win);
      Draw_Window(Wins.Total_Ht_Win);
      Draw_Window(Wins.TVA_Win);
      Draw_Window(Wins.Total_TVA_Win);
      Draw_Window(Wins.Total_Ttc_Win);
   end Ticket_Wins_Draw;      
   
   
   procedure Ticket_Line_Draw(Wins : Ticket_Windows_Type; Line : in Line_Range; Account_Line : in Account_Line_Type) is
      
   begin
      Draw_Text(Wins.Line_Num_Win, Line, 1, White, Handling.To_Wide_String(Voice_Num_Range'Image(Account_Line.Line_Num)));
      Draw_Text(Wins.Description_Win, Line, 1, White, Account_Line.Description(1..16));
      Draw_Text(Wins.unit_Ht_Win, Line, 1, White, Handling.To_Wide_String(Fixed_Unit_ht'Image(Account_Line.Unit_Ht_price)));
      Draw_Text(Wins.Quantity_win, Line, 1, White, Handling.To_Wide_String(Quantity_Range'Image(Account_Line.Quantity)));
      Draw_Text(Wins.Total_Ht_Win, Line, 1, White, Handling.To_Wide_String(Fixed_Total'Image(Account_Line.Total_Ht)));
      Draw_Text(Wins.TVA_Win, Line, 1, White, Handling.To_Wide_String(Fixed_Factor'Image(Account_Line.TVA_Rate)));
      Draw_Text(Wins.Total_TVA_Win, Line, 1, White, Handling.To_Wide_String(Fixed_Total'Image(Account_Line.Total_TVA)));
      Draw_Text(Wins.Total_Ttc_Win, Line, 1, White, Handling.To_Wide_String(Fixed_Total'Image(Account_Line.Total_TTC)));
   end ticket_Line_Draw;      
   
   
   procedure Voice_Print (Voice : in Abstracted_Voice'Class;
			  Win : in Ticket_Windows_Type;
			  Line_Index : in Account_Line_Range;
			  Line_Max : in Positive) is
      Line_Count : natural := 0;
   begin
      if Voice.Line_Last = 0 then
	 return;
      end if;
      for Line in Line_Index+1..Natural'Min(Line_Index+Line_Max, Voice.Line_Last) loop
	 Ticket_Line_Draw(Win, Line_Count+1, Voice.Accounting(Line));
	 Line_Count := Line_Count + 1;
	 exit when Line_Count = Line_Max;
      end loop;
   end Voice_Print;

   
   task body Moneybox_Process is
      
      Removed_Line_Num : Wide_String(1..4) := (others => Wide_Character ' Val (32));
      Line_Num  : Account_Line_Range;
      Line_Num_Last : Natural := 0;
      Remove_Case : Boolean := False;
      
      Account_Line_Index : Account_Line_Range := 0;
      
      Text : Wide_String_Access := new Wide_String ' ("");
      
      Line_Curs : Line_Cursor_Type := Initialize;
      
      Deal_Name : Deal_Enum := Deal_In;
      
      Outvoice : Outvoice_Record := Null_Outvoice;
      invoice : Invoice_Record := Null_Invoice;
      Payed   : Boolean := False;
      
      
      Validated : Boolean := False;
      
      Box_Dealin  : Window_Record := (1, 1, 17, This.Columns/2, Red, Window);
      Box_Dealout : Window_Record := (1, 1, 17, This.Columns/2, Green, Window);
      Voice       : Window_Record := (18, 1, This.Lines-28, This.Columns/2, Blue, Window);
      Ticket      : Window_Record := (This.Lines-10, 1, 5, This.Columns/2, white, Window);
      Balance     : Window_Record := (This.Lines-5, 1, 3, This.Columns/2, Yellow, Window);
      Cmd_Win     : Window_Record := (This.Lines-2, 1, 3, This.Columns/2, White, Window);
   begin

      Initialize(Box_Dealin, 1, 1, 17, This.Columns/2, Red, White);
      Initialize(Box_Dealout, 1, 1, 17, This.Columns/2, Green, White);
      Initialize(Voice, 18, 1, This.Lines-28, This.Columns/2, Blue, White);
      Initialize(Ticket, This.Lines-10, 1, 5, This.Columns/2, white, Blue);
      Initialize(Balance, This.Lines-5, 1, 3, This.Columns/2, Yellow, Blue);
      Initialize(Cmd_Win, This.Lines-2, 1, 3, This.Columns/2, White, Red);
      
      Initialize(This.Ticket_Wins, This.Lines-30, This.Columns/2-2, 19, 2);
      begin
     Main_Loop:
	 loop
	    loop
	       select
		  
		  accept Halt do
		     null;
		  end Halt;
		  exit Main_Loop;
	       or
		  accept Suspend;
	       or
		  accept Wake_Up Do
		     Errno := System("clear" & Character'Val(0));
		     if Deal_Name = Deal_Out then
			Draw_Window(Box_Dealout);
			Draw_Text(Box_Dealout, 1, This.Columns/4-10, White, "Moneybox DealOut");
			Draw_Text(Box_Dealout, 3, 1, White, "Name      : ");
			Draw_Text(Box_Dealout, 5, 1, White, "Price HT  : ");
			Draw_Text(Box_Dealout, 7, 1, White, "Quantity  : ");
			Draw_Text(Box_Dealout, 9, 1, White, "TVA rate  : ");
			Draw_Text(Box_Dealout, 11, 1, White, "Total HT  : ");
			Draw_Text(Box_Dealout, 13, 1, White, "Total TVA : ");
			Draw_Text(Box_Dealout, 15, 1, White, "Total TTC : ");
			Draw_Window(Ticket);
			Draw_Text(Ticket, 1, 1, White, "Total HT  : " & Handling.To_Wide_String(Fixed_Total'image(Outvoice.Total_ht)));
			Draw_Text(Ticket, 2, 1, White, "Total TVA : " & Handling.To_Wide_String(Fixed_Total'Image(Outvoice.Total_Tva)));
			Draw_Text(Ticket, 3, 1, White, "Total TTC : " & Handling.To_Wide_String(Fixed_Total'Image(Outvoice.Total_TTC)));
		     
		     else
			Draw_Window(Box_Dealin);
			Draw_Text(Box_Dealin, 1, This.Columns/4-10, White, "Moneybox DealIn");
			Draw_Text(Box_Dealin, 3, 1, White, "Name      : ");
			Draw_Text(Box_Dealin, 5, 1, White, "Price HT  : ");
			Draw_Text(Box_Dealin, 7, 1, White, "Quantity  : ");
			Draw_Text(Box_Dealin, 9, 1, White, "TVA rate  : ");
			Draw_Text(Box_Dealout, 11, 1, White, "Total HT  : ");
			Draw_Text(Box_Dealout, 13, 1, White, "Total TVA : ");
			Draw_Text(Box_Dealout, 15, 1, White, "Total TTC : ");
			
			Draw_Window(Ticket);
			Draw_Text(Ticket, 1, 1, White, "Total HT  : " & Handling.To_Wide_String(Fixed_Total'Image(Invoice.Total_ht)));
			Draw_Text(Ticket, 2, 1, White, "Total TVA : " & Handling.To_Wide_String(Fixed_Total'Image(Invoice.Total_Tva)));
			Draw_Text(Ticket, 3, 1, White, "Total TTC : " & Handling.To_Wide_String(Fixed_Total'Image(Invoice.Total_TTC)));
			
		     end if;
		     Draw_Window(Voice);
		     Draw_Window(Balance);
		     Draw_Text(Balance, 1, 1, White, 
			       
			       " Capital : " & Handling.To_Wide_String(Fixed_Total'Image(Computer.Balance.Balance.Capital)) &
				 ", Material :" & Handling.To_Wide_String(Fixed_Total'Image(Computer.Balance.Balance.Material)) &
				 ", TVA In :" & Handling.To_Wide_String(Fixed_Total'Image(Computer.Balance.Balance.TVA_In)) &
				 ", TVA Out :" & Handling.To_Wide_String(Fixed_Total'Image(Computer.Balance.Balance.TVA_Out)) & ""
			      );
		     
		     Draw_Window(Cmd_Win);
		     Draw_Text(Voice, 1, 1, White, "N     , Name            , Unit HT    , Quantity    , Total HT     , TVA %  , Total TVA       , Total Price TTC");
		     Draw_Text(Voice, 2, 1, Blue, Handling.To_Wide_String(((This.Columns/2-2) * '-')));
		     
		     Ticket_Wins_Draw(This.Ticket_Wins);
		     

		     
		     
		     if Deal_Name = Deal_Out then
			Voice_Print(Outvoice, This.Ticket_Wins, Account_Line_Index, This.Lines-34);
			Draw_Text(Box_Dealout , Line_Curs.values(Line_Curs.Val_Cur).Line_Pos,
				  Line_Curs.values(Line_Curs.Val_Cur).Column_Pos,
				  White,
				  Line_Curs.values(Line_Curs.Val_Cur).Line(1..Line_Curs.values(Line_Curs.Val_Cur).Line_Last));
		     else

			Voice_Print(Invoice, This.Ticket_Wins, Account_Line_Index, This.Lines-34);
			Draw_Text(Box_Dealin, Line_Curs.values(Line_Curs.Val_Cur).Line_Pos,
				  Line_Curs.values(Line_Curs.Val_Cur).Column_Pos,
				  White,
						  Line_Curs.values(Line_Curs.Val_Cur).Line(1..Line_Curs.values(Line_Curs.Val_Cur).Line_Last));
		     end if;
		     
		  end Wake_Up;
		  
		  
		  exit;
	       or
		  
		  accept Refresh do
		     if Deal_Name = Deal_Out then
			Draw_Window(Box_Dealout);
			Draw_Text(Box_Dealout, 1, This.Columns/4-10, White, "Moneybox DealOut");
			Draw_Text(Box_Dealout, 3, 1, White, "Name      : ");
			Draw_Text(Box_Dealout, 5, 1, White, "Price HT  : ");
			Draw_Text(Box_Dealout, 7, 1, White, "Quantity  : ");
			Draw_Text(Box_Dealout, 9, 1, White, "TVA rate  : ");
			Draw_Text(Box_Dealout, 11, 1, White, "Total HT  : ");
			Draw_Text(Box_Dealout, 13, 1, White, "Total TVA : ");
			Draw_Text(Box_Dealout, 15, 1, White, "Total TTC : ");
			Draw_Window(Ticket);
			Draw_Text(Ticket, 1, 1, White, "Total HT  : " & Handling.To_Wide_String(Fixed_Total'Image(Outvoice.Total_ht)));
			Draw_Text(Ticket, 2, 1, White, "Total TVA : " & Handling.To_Wide_String(Fixed_Total'Image(Outvoice.Total_Tva)));
			Draw_Text(Ticket, 3, 1, White, "Total TTC : " & Handling.To_Wide_String(Fixed_Total'Image(Outvoice.Total_TTC)));
		     else
			Draw_Window(Box_Dealin);
			Draw_Text(Box_Dealin, 1, This.Columns/4-10, White, "Moneybox DealIn");
			Draw_Text(Box_Dealin, 3, 1, White, "Name      : ");
			Draw_Text(Box_Dealin, 5, 1, White, "Price HT  : ");
			Draw_Text(Box_Dealin, 7, 1, White, "Quantity  : ");
			Draw_Text(Box_Dealin, 9, 1, White, "TVA rate  : ");
			Draw_Text(Box_Dealout, 11, 1, White, "Total HT  : ");
			Draw_Text(Box_Dealout, 13, 1, White, "Total TVA : ");
			Draw_Text(Box_Dealout, 15, 1, White, "Total TTC : ");
			Draw_Window(Ticket);
			Draw_Text(Ticket, 1, 1, White, "Total HT  : " & Handling.To_Wide_String(Fixed_Total'Image(Invoice.Total_ht)));
			Draw_Text(Ticket, 2, 1, White, "Total TVA : " & Handling.To_Wide_String(Fixed_Total'Image(Invoice.Total_Tva)));
			Draw_Text(Ticket, 3, 1, White, "Total TTC : " & Handling.To_Wide_String(Fixed_Total'Image(Invoice.Total_TTC)));
		     end if;
		     Draw_Window(Voice);
		     
		     
		     
		     Draw_Window(Balance);
		     
		     
		     
		     Draw_Text(Balance, 1, 1, White, 
			       
			       " Capital : " & Handling.To_Wide_String(Fixed_Total'Image(Computer.Balance.Balance.Capital)) &
				 ", Material :" & Handling.To_Wide_String(Fixed_Total'Image(Computer.Balance.Balance.Material)) &
				 ", TVA In :" & Handling.To_Wide_String(Fixed_Total'Image(Computer.Balance.Balance.TVA_In)) &
				 ", TVA Out :" & Handling.To_Wide_String(Fixed_Total'Image(Computer.Balance.Balance.TVA_Out)) & ""
			      );
		     Draw_Window(Cmd_Win);
		     Draw_Text(Voice, 1, 1, White, "N     , Name            , Unit HT    , Quantity    , Total HT     , TVA %  , Total TVA       , Total Price TTC");

		     Draw_Text(Voice, 2, 1, Blue, Handling.To_Wide_String(((This.Columns/2-2) * '-')));
		     
		     
		     Ticket_Wins_Draw(This.Ticket_Wins);
		     
		     if Deal_Name = Deal_Out then
			Voice_Print(Outvoice, This.Ticket_Wins, Account_Line_Index, This.Lines-34);

			Draw_Text(Box_Dealout , Line_Curs.values(Line_Curs.Val_Cur).Line_Pos,
				  Line_Curs.values(Line_Curs.Val_Cur).Column_Pos,
				  White,
				  Line_Curs.values(Line_Curs.Val_Cur).Line(1..Line_Curs.values(Line_Curs.Val_Cur).Line_Last));
		     else
			Voice_Print(Invoice, This.Ticket_Wins, Account_Line_Index, This.Lines-34);
			
			Draw_Text(Box_Dealin, Line_Curs.values(Line_Curs.Val_Cur).Line_Pos,
				  Line_Curs.values(Line_Curs.Val_Cur).Column_Pos,
				  White, Line_Curs.values(Line_Curs.Val_Cur).Line(1..Line_Curs.values(Line_Curs.Val_Cur).Line_Last));
		     end if;
		     
		  end Refresh;

	       end select;
	    end loop;

	    loop
	       select
		  accept Halt;
		  exit Main_Loop;
	       or
		  accept Suspend do
		     null;
		  end Suspend;
		  exit;
	       or
		  accept Wake_Up do
		     Errno := System("clear" & Character'Val(0));
		     if Deal_Name = Deal_Out then
			Draw_Window(Box_Dealout);
			Draw_Text(Box_Dealout, 1, This.Columns/4-10, White, "Moneybox DealOut");
			Draw_Text(Box_Dealout, 3, 1, White, "Name      : ");
			Draw_Text(Box_Dealout, 5, 1, White, "Price HT  : ");
			Draw_Text(Box_Dealout, 7, 1, White, "Quantity  : ");
			Draw_Text(Box_Dealout, 9, 1, White, "TVA rate  : ");
			Draw_Text(Box_Dealout, 11, 1, White, "Total HT  : ");
			Draw_Text(Box_Dealout, 13, 1, White, "Total TVA : ");
			Draw_Text(Box_Dealout, 15, 1, White, "Total TTC : ");
			Draw_Window(Ticket);
			Draw_Text(Ticket, 1, 1, White, "Total HT  : " & Handling.To_Wide_String(Fixed_Total'Image(Outvoice.Total_ht)));
			Draw_Text(Ticket, 2, 1, White, "Total TVA : " & Handling.To_Wide_String(Fixed_Total'Image(Outvoice.Total_Tva)));
			Draw_Text(Ticket, 3, 1, White, "Total TTC : " & Handling.To_Wide_String(Fixed_Total'Image(Outvoice.Total_TTC)));

		     else
			Draw_Window(Box_Dealin);
			Draw_Text(Box_Dealin, 1, This.Columns/4-10, White, "Moneybox DealIn");
			Draw_Text(Box_Dealin, 3, 1, White, "Name      : ");
			Draw_Text(Box_Dealin, 5, 1, White, "Price HT  : ");
			Draw_Text(Box_Dealin, 7, 1, White, "Quantity  : ");
			Draw_Text(Box_Dealin, 9, 1, White, "TVA rate  : ");
			Draw_Text(Box_Dealout, 11, 1, White, "Total HT  : ");
			Draw_Text(Box_Dealout, 13, 1, White, "Total TVA : ");
			Draw_Text(Box_Dealout, 15, 1, White, "Total TTC : ");
			Draw_Window(Ticket);
			Draw_Text(Ticket, 1, 1, White, "Total HT  : " & Handling.To_Wide_String(Fixed_Total'Image(Invoice.Total_ht)));
			Draw_Text(Ticket, 2, 1, White, "Total TVA : " & Handling.To_Wide_String(Fixed_Total'Image(Invoice.Total_Tva)));
			Draw_Text(Ticket, 3, 1, White, "Total TTC : " & Handling.To_Wide_String(Fixed_Total'Image(Invoice.Total_TTC)));
		     end if;
		     Draw_Window(Voice);
		     Draw_Window(Balance);
		     Draw_Text(Balance, 1, 1, White, 
			       
			       " Capital : " & Handling.To_Wide_String(Fixed_Total'Image(Computer.Balance.Balance.Capital)) &
				 ", Material :" & Handling.To_Wide_String(Fixed_Total'Image(Computer.Balance.Balance.Material)) &
				 ", TVA In :" & Handling.To_Wide_String(Fixed_Total'Image(Computer.Balance.Balance.TVA_In)) &
				 ", TVA Out :" & Handling.To_Wide_String(Fixed_Total'Image(Computer.Balance.Balance.TVA_Out)) & ""
			      );
		     Draw_Window(Cmd_Win);
		     Draw_Text(Voice, 1, 1, White, "N     , Name            , Unit HT    , Quantity    , Total HT     , TVA %  , Total TVA       , Total Price TTC");

		     Draw_Text(Voice, 2, 1, Blue, Handling.To_Wide_String(((This.Columns/2-2) * '-')));
		     
		     Ticket_Wins_Draw(This.Ticket_Wins);
		     
		     if Deal_Name = Deal_Out then
			Voice_Print(Outvoice, This.Ticket_Wins, Account_Line_Index, This.Lines-34);

			Draw_Text(Box_Dealout , Line_Curs.values(Line_Curs.Val_Cur).Line_Pos,
				  Line_Curs.values(Line_Curs.Val_Cur).Column_Pos,
				  White,
				  Line_Curs.values(Line_Curs.Val_Cur).Line(1..Line_Curs.values(Line_Curs.Val_Cur).Line_Last));
		     else
			Voice_Print(Invoice, This.Ticket_Wins, Account_Line_Index, This.Lines-34);

			Draw_Text(Box_Dealin, Line_Curs.values(Line_Curs.Val_Cur).Line_Pos,
				  Line_Curs.values(Line_Curs.Val_Cur).Column_Pos,
				  White,
						  Line_Curs.values(Line_Curs.Val_Cur).Line(1..Line_Curs.values(Line_Curs.Val_Cur).Line_Last));
		     end if;

		  end Wake_Up;
		     
	       or when Remove_Case =>
		  accept Receive(Wchar : in Wide_Character) do
			if Is_Control(Wchar) then
			   case Wchar is
			      when Wide_Character'Val(1) =>
				 Line_Curs := Initialize;
				 Invoice := Null_Invoice;
				 Outvoice := Null_Outvoice;
			      when Wide_Character'Val(9) =>
				 if (Text = null) or else
				   Text'Length = 0 then
				    if Deal_Name = Deal_Out then
				       Deal_Name := Deal_In;
				    else
				       Deal_Name := Deal_out;
				    end if;
				    
				 end if;
			      when Wide_Character'Val(10) =>
				 if Line_Num_Last > 0 then
				    begin
				       Line_Num := 
					 Account_Line_Range'Value
					 (
					  Handling.To_String(Removed_Line_Num(1..Line_Num_Last))
					 );
				    exception
				       when Constraint_Error =>
					  null;
				    end;
				 end if;
				 if Line_Num /= 0 then
				    if Deal_Name = Deal_Out then
				       Line_Remove(Abstracted_Voice(Outvoice), Line_Num);
				    else
				       Line_Remove(Abstracted_Voice(Invoice), Line_Num);
				    end if;
				    
				 end if;				 
				 Line_Num := 0;
				 Removed_Line_Num := (others => Wide_Character'Val(32));
				 Line_Num_Last := 0;
				 Remove_Case := False;
			      when Wide_Character'Val(127) =>
				 if Line_Num_Last > 0 then
				    Removed_Line_Num(Line_Num_Last) := ' ';
				    Line_Num_Last := Line_Num_Last - 1;
				 end if;
			      when others =>
				 null;
			   end case;
			   if Deal_Name = Deal_Out then
			      Draw_Window(Box_Dealout);
			      Draw_Text(Box_Dealout, 1, This.Columns/4-10, White, "Moneybox DealOut");
			      Draw_Text(Box_Dealout, 3, 1, White, "Name      : ");
			      Draw_Text(Box_Dealout, 5, 1, White, "Price HT  : ");
			      Draw_Text(Box_Dealout, 7, 1, White, "Quantity  : ");
			      Draw_Text(Box_Dealout, 9, 1, White, "TVA rate  : ");
			      Draw_Text(Box_Dealout, 11, 1, White, "Total HT  : ");
			      Draw_Text(Box_Dealout, 13, 1, White, "Total TVA : ");
			      Draw_Text(Box_Dealout, 15, 1, White, "Total TTC : ");
			      Draw_Window(Ticket);
			      Draw_Text(Ticket, 1, 1, White, "Total HT  : " & Handling.To_Wide_String(Fixed_Total'Image(Outvoice.Total_ht)));
			      Draw_Text(Ticket, 2, 1, White, "Total TVA : " & Handling.To_Wide_String(Fixed_Total'Image(Outvoice.Total_Tva)));
			      Draw_Text(Ticket, 3, 1, White, "Total TTC : " & Handling.To_Wide_String(Fixed_Total'Image(Outvoice.Total_TTC)));
			   else
			      Draw_Window(Box_Dealin);
			      Draw_Text(Box_Dealin, 1, This.Columns/4-10, White, "Moneybox DealIn");
			      Draw_Text(Box_Dealin, 3, 1, White, "Name      : ");
			      Draw_Text(Box_Dealin, 5, 1, White, "Price HT  : ");
			      Draw_Text(Box_Dealin, 7, 1, White, "Quantity  : ");
			      Draw_Text(Box_Dealin, 9, 1, White, "TVA rate  : ");
			      Draw_Text(Box_Dealout, 11, 1, White, "Total HT  : ");
			      Draw_Text(Box_Dealout, 13, 1, White, "Total TVA : ");
			      Draw_Text(Box_Dealout, 15, 1, White, "Total TTC : ");
			      Draw_Window(Ticket);
			      Draw_Text(Ticket, 1, 1, White, "Total HT  : " & Handling.To_Wide_String(Fixed_Total'Image(Invoice.Total_ht)));
			      Draw_Text(Ticket, 2, 1, White, "Total TVA : " & Handling.To_Wide_String(Fixed_Total'Image(Invoice.Total_Tva)));
			      Draw_Text(Ticket, 3, 1, White, "Total TTC : " & Handling.To_Wide_String(Fixed_Total'Image(Invoice.Total_TTC)));
			   end if;
			   Draw_Window(Voice);
			   Draw_Window(Balance);
			   Draw_Window(Cmd_Win);
			   Draw_Text(Balance, 1, 1, White, 
				     
				     " Capital : " & Handling.To_Wide_String(Fixed_Total'Image(Computer.Balance.Balance.Capital)) &
				       ", Material :" & Handling.To_Wide_String(Fixed_Total'Image(Computer.Balance.Balance.Material)) &
				       ", TVA In :" & Handling.To_Wide_String(Fixed_Total'Image(Computer.Balance.Balance.TVA_In)) &
				       ", TVA Out :" & Handling.To_Wide_String(Fixed_Total'Image(Computer.Balance.Balance.TVA_Out)) & ""
				    );
			   --Draw_Window(Cmd_Win);
			   Draw_Text(Voice, 1, 1, White, "N     , Name            , Unit HT    , Quantity    , Total HT     , TVA %  , Total TVA       , Total Price TTC");

			   Draw_Text(Voice, 2, 1, Blue, Handling.To_Wide_String(((This.Columns/2-2) * '-')));
			   Ticket_Wins_Draw(This.Ticket_Wins);
			   if Deal_Name = Deal_Out then
			      for Val in Name_Value..Total_Ttc_Value loop
				 Draw_Text(Box_Dealout , Line_Curs.values(Val).Line_Pos,
					   Line_Curs.values(Val).Column_Pos,
					   White,
					   Line_Curs.values(Val).Line(1..Line_Curs.values(Val).Line_Last));
			      end loop;
			      Voice_Print(Outvoice, This.Ticket_Wins, Account_Line_Index, This.Lines-34);
			      
			      Draw_Text(Box_Dealout, Line_Curs.Values(Line_Curs.Val_Cur).Line_Pos,
					Line_Curs.Values(Line_Curs.Val_Cur).Column_Pos,
					White,
					Line_Curs.Values(Line_Curs.Val_Cur).Line(1..Line_Curs.Values(Line_Curs.Val_Cur).Line_Last));
			   else
			      
			      for Val in Name_Value..Total_Ttc_Value loop
				 Draw_Text(Box_Dealin , Line_Curs.values(Val).Line_Pos,
					   Line_Curs.values(Val).Column_Pos,
					   White,
					   Line_Curs.values(Val).Line(1..Line_Curs.values(Val).Line_Last));
			      end loop;
			      Voice_Print(Invoice, This.Ticket_Wins, Account_Line_Index, This.Lines-34);

			      Draw_Text(Box_Dealin, Line_Curs.Values(Line_Curs.Val_Cur).Line_Pos,
					Line_Curs.Values(Line_Curs.Val_Cur).Column_Pos,
					White,
					Line_Curs.Values(Line_Curs.Val_Cur).Line(1..Line_Curs.Values(Line_Curs.Val_Cur).Line_Last));
			   end if;

			   
			   
			   
			elsif Is_digit(Wchar) and then
			  Line_Num_Last < Removed_Line_Num'Length then
			   Removed_Line_Num(Line_Num_Last + 1) := Wchar;
			   Line_Num_Last := Line_Num_Last + 1;
			   Draw_Window(Cmd_Win);
			   Draw_Text(Cmd_Win, 1, 1, White, "Line num : " & Removed_Line_Num(1..Line_Num_Last));
			else
			  Put(Character'Val(7));
			end if;
			
			
			
		  end Receive;
	       or
		  when not Remove_Case and This.Initialized =>
		     accept Receive(Wchar : in Wide_Character) do
			if Is_Control(Wchar) then
			   case Wchar is
			      when Wide_Character'Val(1) =>
				 Line_Curs := Initialize;
				 Invoice := Null_Invoice;
				 Outvoice := Null_Outvoice;
			      when Wide_Character'Val(9) =>
				 if (Text = null) or else
				   Text'Length = 0 then
				    if Deal_Name = Deal_Out then
				       Deal_Name := Deal_In;
				    else
				       Deal_Name := Deal_out;
				    end if;
				    
				 end if;
			      when Wide_Character'Val(10) =>				 
				 if Line_Curs.Values(Line_Curs.Val_Cur).Line_Last /= 0 then
				    case Line_Curs.Val_Cur is
				       when None_Value =>
					  null;
				       when TVA_Rate_Value =>
					  
					  if Deal_Name = Deal_Out then
					     begin
						Line_Add(Abstracted_Voice(Outvoice), To_Account_Line(Line_Curs, 707, Outvoice.Line_count + 1));
						Outvoice.Line_Count := Outvoice.Line_Count + 1;
						if Outvoice.Line_Last >= (This.Lines-34) then
						   Account_Line_Index := Account_Line_Index + 1;
						end if;
					     exception
						when Spec_Error =>
						   Errno := System("clear" & Character'Val(0));
						   Put_Line("Outvoice error");
						   declare
						      Char : Character;
						   begin
						      Text_Io.Put_Line("Press any key to continue");
						      Get_Immediate(Char);
						   end;
					     end;
					  else
					     begin
						Line_Add(Abstracted_Voice(Invoice), To_Account_Line(Line_Curs, 607, Invoice.Line_Count + 1));
						Invoice.Line_Count := Invoice.Line_Count + 1;
						if Invoice.Line_Last >= (This.Lines-34) then
						   Account_Line_Index := Account_Line_Index + 1;
						end if;
						exception
						when Spec_Error =>
						   Errno := System("clear" & Character'Val(0));
						   Put_Line("Invoice error");
						   declare
						      Char : Character;
						   begin
						      Text_Io.Put_Line("Press any key to continue");
						      Get_Immediate(Char);
						   end;
					     end;
					  end if;
					  Line_Curs := Initialize;				    
				       when others =>
					  Line_Curs.Val_Cur := Value_Enum'Succ(Line_Curs.Val_Cur);
				    end case;
				    Validated := True;
				 else
				    Put(Character'Val(7));
				 end if;
			      when Wide_Character ' Val (127) =>
				 if Line_Curs.Values(Line_Curs.Val_Cur).Line_Last > 1 then 
				    Line_Curs.Values(Line_Curs.Val_Cur).Line(Line_Curs.Values(Line_Curs.Val_Cur).Line_Last) := ' ';
				    Line_Curs.Values(Line_Curs.Val_Cur).Line_Last := 
				      Line_Curs.Values(Line_Curs.Val_Cur).Line_Last - 1;
				 end if;
			      when Wide_Character'Val(18) =>
				 Remove_Case := True;
				 
			      when Wide_Character'Val(20) => -- Ctrl+T : charge and billed.
				 if Deal_Name = Deal_Out then

				    Charge(Computer.Balance.Balance, Outvoice, Payed);

				    if Payed then

				       Outvoice.Date := Clock;

				       Outvoice.Account_Num := Outvoice.Accounting(1).Account_Num;

				       Outvoice.voice_Num := Computer.Balance.Outvoice_Num + 1;

				       Computer.Balance.Outvoice_Num := Computer.Balance.Outvoice_Num + 1;

				       if Save(Outvoice, "charged.txt") then
					  
					  Add(Accounts, Outvoice);

					  for Iter in 1..Outvoice.Line_Last loop
					     
						declare
						   Line : constant Account_Line_Type := Outvoice.Accounting(Iter);
						begin
						   if not Stocks_Manager.In_Stocks(Stocks_Manager.Hardware, Line.Description) then
						      
						      raise Spec_Error;
						   else
						      declare
							 Stock : Stock_Record := (0, Line.Description, Line.Quantity, Line.Unit_Ht_Price, Line.TVA_Rate);
						      begin
							 
							 Stocks_Manager.Remove_From_stock(Stocks_Manager.Hardware, Stock.Name, Stock.Quantity);
							 
						      end;
						   end if;
						   
						end;
					     end loop;
					  Outvoice := Null_Outvoice;
				       end if;
				    end if;
				 else

				    billed(Computer.Balance.Balance, invoice, Payed);

				    if Payed then

				       Invoice.Date := Clock;

				       Invoice.Account_Num := Invoice.Accounting(1).Account_Num;

				       Invoice.voice_Num := Computer.Balance.Invoice_Num + 1;

				       Computer.Balance.Invoice_Num := Computer.Balance.Invoice_Num + 1;

				       if Save(Invoice, "billed.txt") then

					  Add(Accounts, Invoice);

					  for Iter in 1..Invoice.Line_Last loop

						declare
						   Line : constant Account_Line_Type := Invoice.Accounting(Iter);
						begin

						   if not Stocks_Manager.In_Stocks(Stocks_Manager.Hardware, Line.Description) then

						      declare
							 Stock : Stock_Record := (Stocks_Manager.Hard_Num + 1, Line.Description, Line.Quantity, Line.Unit_Ht_Price, Line.TVA_Rate);
						      begin

							 Stocks_Manager.Hard_Num := 
							   Stocks_Manager.Hard_Num + 1;
							 
							 Stocks_Manager.Stock_Add(Stocks_Manager.Hardware, Stock);

						      end;
						   else

						      declare
							 Stock : Stock_Record := (0, Line.Description, (Line.Quantity), Line.Unit_Ht_Price, Line.TVA_Rate);
						      begin

							 Stocks_Manager.Update_Stock(Stocks_Manager.Hardware, Stock);

						      end;
						   end if;
						   
						end;
					     end loop;
					     
					     Invoice := Null_Invoice;

				       end if;
				    end if;

				 end if;

			      when others =>
				 null;
			   end case;
			   if Deal_Name = Deal_Out then
			      Draw_Window(Box_Dealout);
			      Draw_Text(Box_Dealout, 1, This.Columns/4-10, White, "Moneybox DealOut");
			      Draw_Text(Box_Dealout, 3, 1, White, "Name      : ");
			      Draw_Text(Box_Dealout, 5, 1, White, "Price HT  : ");
			      Draw_Text(Box_Dealout, 7, 1, White, "Quantity  : ");
			      Draw_Text(Box_Dealout, 9, 1, White, "TVA rate  : ");
			      Draw_Text(Box_Dealout, 11, 1, White, "Total HT  : ");
			      Draw_Text(Box_Dealout, 13, 1, White, "Total TVA : ");
			      Draw_Text(Box_Dealout, 15, 1, White, "Total TTC : ");
			      Draw_Window(Ticket);
			      Draw_Text(Ticket, 1, 1, White, "Total HT  : " & Handling.To_Wide_String(Fixed_Total'Image(Outvoice.Total_ht)));
			      Draw_Text(Ticket, 2, 1, White, "Total TVA : " & Handling.To_Wide_String(Fixed_Total'Image(Outvoice.Total_Tva)));
			      Draw_Text(Ticket, 3, 1, White, "Total TTC : " & Handling.To_Wide_String(Fixed_Total'Image(Outvoice.Total_TTC)));
			   else
			      Draw_Window(Box_Dealin);
			      Draw_Text(Box_Dealin, 1, This.Columns/4-10, White, "Moneybox DealIn");
			      Draw_Text(Box_Dealin, 3, 1, White, "Name      : ");
			      Draw_Text(Box_Dealin, 5, 1, White, "Price HT  : ");
			      Draw_Text(Box_Dealin, 7, 1, White, "Quantity  : ");
			      Draw_Text(Box_Dealin, 9, 1, White, "TVA rate  : ");
			      Draw_Text(Box_Dealout, 11, 1, White, "Total HT  : ");
			      Draw_Text(Box_Dealout, 13, 1, White, "Total TVA : ");
			      Draw_Text(Box_Dealout, 15, 1, White, "Total TTC : ");
			      Draw_Window(Ticket);
			      Draw_Text(Ticket, 1, 1, White, "Total HT  : " & Handling.To_Wide_String(Fixed_Total'Image(Invoice.Total_ht)));
			      Draw_Text(Ticket, 2, 1, White, "Total TVA : " & Handling.To_Wide_String(Fixed_Total'Image(Invoice.Total_Tva)));
			      Draw_Text(Ticket, 3, 1, White, "Total TTC : " & Handling.To_Wide_String(Fixed_Total'Image(Invoice.Total_TTC)));
			   end if;
			   Draw_Window(Voice);
			   Draw_Window(Balance);
			   Draw_Text(Balance, 1, 1, White, 
				     
				     " Capital : " & Handling.To_Wide_String(Fixed_Total'Image(Computer.Balance.Balance.Capital)) &
				       ", Material :" & Handling.To_Wide_String(Fixed_Total'Image(Computer.Balance.Balance.Material)) &
				       ", TVA In :" & Handling.To_Wide_String(Fixed_Total'Image(Computer.Balance.Balance.TVA_In)) &
				       ", TVA Out :" & Handling.To_Wide_String(Fixed_Total'Image(Computer.Balance.Balance.TVA_Out)) & ""
				    );
			   --Draw_Window(Cmd_Win);
			   Draw_Text(Voice, 1, 1, White, "N     , Name            , Unit HT    , Quantity    , Total HT     , TVA %  , Total TVA       , Total Price TTC");
			   
			   Draw_Text(Voice, 2, 1, Blue, Handling.To_Wide_String(((This.Columns/2-2) * '-')));
			   Ticket_Wins_Draw(This.Ticket_Wins);
			   if Deal_Name = Deal_Out then
			      for Val in Name_Value..Total_Ttc_Value loop
				 Draw_Text(Box_Dealout , Line_Curs.values(Val).Line_Pos,
					   Line_Curs.values(Val).Column_Pos,
					   White,
					   Line_Curs.values(Val).Line(1..Line_Curs.values(Val).Line_Last));
			      end loop;
			      Voice_Print(Outvoice, This.Ticket_Wins, Account_Line_Index, This.Lines-34);

			      Draw_Text(Box_Dealout, Line_Curs.Values(Line_Curs.Val_Cur).Line_Pos,
					Line_Curs.Values(Line_Curs.Val_Cur).Column_Pos,
					White,
					Line_Curs.Values(Line_Curs.Val_Cur).Line(1..Line_Curs.Values(Line_Curs.Val_Cur).Line_Last));
			   else
			      
			      for Val in Name_Value..Total_Ttc_Value loop
				 Draw_Text(Box_Dealin , Line_Curs.values(Val).Line_Pos,
					   Line_Curs.values(Val).Column_Pos,
					   White,
					   Line_Curs.values(Val).Line(1..Line_Curs.values(Val).Line_Last));
			      end loop;
			      Voice_Print(Invoice, This.Ticket_Wins, Account_Line_Index, This.Lines-34);
			      
			      Draw_Text(Box_Dealin, Line_Curs.Values(Line_Curs.Val_Cur).Line_Pos,
					Line_Curs.Values(Line_Curs.Val_Cur).Column_Pos,
					White,
					Line_Curs.Values(Line_Curs.Val_Cur).Line(1..Line_Curs.Values(Line_Curs.Val_Cur).Line_Last));
			   end if;
			   if Remove_Case then
			      Draw_Window(Cmd_Win);
			      Draw_Text(Cmd_Win, 1, 1, White, "Line num : ");
			   end if;

			   
			elsif Line_Curs.Values(Line_Curs.Val_Cur).Line_Last < 32 then
			   
			   Line_Curs.Values(Line_Curs.Val_Cur).Line(Line_Curs.Values(Line_Curs.Val_Cur).Line_Last + 1) := Wchar;
			   Line_Curs.Values(Line_Curs.Val_Cur).Line_Last := 
			     Line_Curs.Values(Line_Curs.Val_Cur).Line_Last + 1;
			   if Deal_Name = Deal_Out then
			      for Val in Name_Value..Total_Ttc_Value loop
				 Draw_Text(Box_Dealout , Line_Curs.values(Val).Line_Pos,
					   Line_Curs.values(Val).Column_Pos,
					   White,
					   Line_Curs.values(Val).Line(1..Line_Curs.values(Val).Line_Last));
			      end loop;

			      Draw_Text(Box_Dealout, Line_Curs.Values(Line_Curs.Val_Cur).Line_Pos,
					Line_Curs.Values(Line_Curs.Val_Cur).Column_Pos,
					White,
					Line_Curs.Values(Line_Curs.Val_Cur).Line(1..Line_Curs.Values(Line_Curs.Val_Cur).Line_Last));
			   else
			      
			      for Val in Name_Value..Total_Ttc_Value loop
				 Draw_Text(Box_Dealin , Line_Curs.values(Val).Line_Pos,
					   Line_Curs.values(Val).Column_Pos,
					   White,
					   Line_Curs.values(Val).Line(1..Line_Curs.values(Val).Line_Last));
			      end loop;

			      Draw_Text(Box_Dealin, Line_Curs.Values(Line_Curs.Val_Cur).Line_Pos,
					Line_Curs.Values(Line_Curs.Val_Cur).Column_Pos,
					White,
					Line_Curs.Values(Line_Curs.Val_Cur).Line(1..Line_Curs.Values(Line_Curs.Val_Cur).Line_Last));
			   end if;
			   
			else
			   Put(Character'Val(7));
			end if;
		     end Receive;
	       or
		  when (not Remove_Case) and (not This.Initialized) =>
		     accept Receive(Wchar : in Wide_Character) do
			if Is_Control(Wchar) then
			   case Wchar is
			      when Wide_Character'Val(1) =>
				 Line_Curs := Initialize;
				 Invoice := Null_Invoice;
				 Outvoice := Null_Outvoice;
			      when Wide_Character'Val(9) =>
				 if (Text = null) or else
				   Text'Length = 0 then
				    if Deal_Name = Deal_Out then
				       Deal_Name := Deal_In;
				    else
				       Deal_Name := Deal_out;
				    end if;
				    
				 end if;
			      when Wide_Character'Val(10) =>
				 if Line_Curs.Values(Line_Curs.Val_Cur).Line_Last /= 0 then
				    case Line_Curs.Val_Cur is
				       when None_Value =>
					  null;
				       when TVA_Rate_Value =>

					  if Deal_Name = Deal_Out then
					     begin
						
						Line_Add(Abstracted_Voice(Outvoice), To_Account_Line(Line_Curs, 10, Outvoice.Line_Count + 1));
						Outvoice.Line_Count := Outvoice.Line_Count + 1;
						if Outvoice.Line_Last >= (This.Lines-34) then
						   Account_Line_Index := Account_Line_Index + 1;
						end if;
					     exception
						when Spec_Error =>
						   Errno := System("clear" & Character'Val(0));
						   Put_Line("Outvoice error");
						   declare
						      Char : Character;
						   begin
						      Text_Io.Put_Line("Press any key to continue");
						      Get_Immediate(Char);
						   end;
					     end;
					  else
					     begin
						Line_Add(Abstracted_Voice(Invoice), To_Account_Line(Line_Curs, 607, Invoice.Line_Count + 1));
						Invoice.Line_Count := Invoice.Line_Count + 1;
						if Invoice.Line_Last >= (This.Lines-34) then
						   Account_Line_Index := Account_Line_Index + 1;
						end if;
						exception
						when Spec_Error =>
						   Errno := System("clear" & Character'Val(0));
						   Put_Line("Invoice error");
						   declare
						      Char : Character;
						   begin
						      Text_Io.Put_Line("Press any key to continue");
						      Get_Immediate(Char);
						   end;
					     end;
					  end if;
					  Line_Curs := Initialize;				    
				       when others =>
					  Line_Curs.Val_Cur := Value_Enum'Succ(Line_Curs.Val_Cur);
				    end case;
				    Validated := True;
				 else
				    Put(Character'Val(7));
				 end if;
			      when Wide_Character ' Val (127) =>
				 if Line_Curs.Values(Line_Curs.Val_Cur).Line_Last > 1 then
				    Line_Curs.Values(Line_Curs.Val_Cur).Line(Line_Curs.Values(Line_Curs.Val_Cur).Line_Last) := ' ';
				    Line_Curs.Values(Line_Curs.Val_Cur).Line_Last := 
				      Line_Curs.Values(Line_Curs.Val_Cur).Line_Last - 1;
				 end if;
			      when Wide_Character'Val(18) =>
				 Remove_Case := True;
				 
			      when Wide_Character'Val(20) => -- Ctrl+T : charge and billed.
				 if Deal_Name = Deal_Out then
				    if Outvoice.Line_Last > 0 then
				       Open(Computer.Balance.Balance, Accountant.Accounts);			    
				       Charge(Computer.Balance.Balance, Outvoice, Payed);
				       if Payed then
					  Outvoice.Date := Clock;
					  Outvoice.Account_Num := Outvoice.Accounting(1).Account_Num;
					  Outvoice.voice_Num := Computer.Balance.Outvoice_Num + 1;
					  Computer.Balance.Outvoice_Num := Computer.Balance.Outvoice_Num + 1;
					  if Save(Outvoice, "charged.txt") then
					     Add(Accounts, Outvoice);
					     
					     for Iter in 1..Outvoice.Line_Last loop
						
						declare
						   Line : constant Account_Line_Type := Outvoice.Accounting(Iter);
						begin
						   if not Stocks_Manager.In_Stocks(Stocks_Manager.Software, Line.Description) then
						      declare
							 Stock : Stock_Record := (Stocks_Manager.soft_Num + 1, Line.Description, Line.Quantity, Line.Unit_Ht_Price, Line.TVA_Rate);
						      begin
							 Stocks_Manager.Soft_Num := 
							   Stocks_Manager.Soft_Num + 1;
							 Stocks_Manager.Stock_Add(Stocks_Manager.Software, Stock);
						      end;
						   else
						      declare
							 Stock : Stock_Record := (0, Line.Description, Line.Quantity, Line.Unit_Ht_Price, Line.TVA_Rate);
						      begin
							 
							 Stocks_Manager.Add_To_stock(Stocks_Manager.Software, Stock.Name, Stock.Quantity);
						      end;
						   end if;
						   
						end;
					     end loop;
					     
					     Outvoice := Null_Outvoice;
					  end if;
					  close(Computer.Balance.Balance, Accountant.Accounts);
				       end if;
				       Open(Computer.Balance.Balance, Accountant.Accounts);
				       Outvoice := Null_Outvoice;
				       This.Initialized := True;
				    end if;
				 else
				    billed(Computer.Balance.Balance, invoice, Payed);
				    if Payed then
				       Invoice.Date := Clock;
				       Invoice.Account_Num := Invoice.Accounting(1).Account_Num;
				       Invoice.voice_Num := Computer.Balance.Invoice_Num + 1;
				       Computer.Balance.Invoice_Num := Computer.Balance.Invoice_Num + 1;
				       if Save(Invoice, "billed.txt") then
					  Add(Accounts, Invoice);
					  invoice := Null_invoice;
				       end if;

				    end if;
				    invoice := Null_invoice;
				 end if;
			      when others =>
				 null;
			   end case;
			   if Deal_Name = Deal_Out then
			      Draw_Window(Box_Dealout);
			      Draw_Text(Box_Dealout, 1, This.Columns/4-10, White, "Moneybox DealOut");
			      Draw_Text(Box_Dealout, 3, 1, White, "Name      : ");
			      Draw_Text(Box_Dealout, 5, 1, White, "Price HT  : ");
			      Draw_Text(Box_Dealout, 7, 1, White, "Quantity  : ");
			      Draw_Text(Box_Dealout, 9, 1, White, "TVA rate  : ");
			      Draw_Text(Box_Dealout, 11, 1, White, "Total HT  : ");
			      Draw_Text(Box_Dealout, 13, 1, White, "Total TVA : ");
			      Draw_Text(Box_Dealout, 15, 1, White, "Total TTC : ");
			      Draw_Window(Ticket);
			      Draw_Text(Ticket, 1, 1, White, "Total HT  : " & Handling.To_Wide_String(Fixed_Total'Image(Outvoice.Total_ht)));
			      Draw_Text(Ticket, 2, 1, White, "Total TVA : " & Handling.To_Wide_String(Fixed_Total'Image(Outvoice.Total_Tva)));
			      Draw_Text(Ticket, 3, 1, White, "Total TTC : " & Handling.To_Wide_String(Fixed_Total'Image(Outvoice.Total_TTC)));
			   else
			      Draw_Window(Box_Dealin);
			      Draw_Text(Box_Dealin, 1, This.Columns/4-10, White, "Moneybox DealIn");
			      Draw_Text(Box_Dealin, 3, 1, White, "Name      : ");
			      Draw_Text(Box_Dealin, 5, 1, White, "Price HT  : ");
			      Draw_Text(Box_Dealin, 7, 1, White, "Quantity  : ");
			      Draw_Text(Box_Dealin, 9, 1, White, "TVA rate  : ");
			      Draw_Text(Box_Dealout, 11, 1, White, "Total HT  : ");
			      Draw_Text(Box_Dealout, 13, 1, White, "Total TVA : ");
			      Draw_Text(Box_Dealout, 15, 1, White, "Total TTC : ");
			      Draw_Window(Ticket);
			      Draw_Text(Ticket, 1, 1, White, "Total HT  : " & Handling.To_Wide_String(Fixed_Total'Image(Invoice.Total_ht)));
			      Draw_Text(Ticket, 2, 1, White, "Total TVA : " & Handling.To_Wide_String(Fixed_Total'Image(Invoice.Total_Tva)));
			      Draw_Text(Ticket, 3, 1, White, "Total TTC : " & Handling.To_Wide_String(Fixed_Total'Image(Invoice.Total_TTC)));
			   end if;
			   Draw_Window(Voice);
			   Draw_Window(Balance);
			   Draw_Text(Balance, 1, 1, White, 
			     
				     " Capital : " & Handling.To_Wide_String(Fixed_Total'Image(Computer.Balance.Balance.Capital)) &
				       ", Material :" & Handling.To_Wide_String(Fixed_Total'Image(Computer.Balance.Balance.Material)) &
				       ", TVA In :" & Handling.To_Wide_String(Fixed_Total'Image(Computer.Balance.Balance.TVA_In)) &
				       ", TVA Out :" & Handling.To_Wide_String(Fixed_Total'Image(Computer.Balance.Balance.TVA_Out)) & ""
				    );
			   --Draw_Window(Cmd_Win);
			   Draw_Text(Voice, 1, 1, White, "N     , Name            , Unit HT    , Quantity    , Total HT     , TVA %  , Total TVA       , Total Price TTC");

			   Draw_Text(Voice, 2, 1, Blue, Handling.To_Wide_String(((This.Columns/2-2) * '-')));
			   Ticket_Wins_Draw(This.Ticket_Wins);
			   if Deal_Name = Deal_Out then
			      for Val in Name_Value..Total_Ttc_Value loop
				 Draw_Text(Box_Dealout , Line_Curs.values(Val).Line_Pos,
					   Line_Curs.values(Val).Column_Pos,
					   White,
					   Line_Curs.values(Val).Line(1..Line_Curs.values(Val).Line_Last));
			      end loop;
			      Voice_Print(Outvoice, This.Ticket_Wins, Account_Line_Index, This.Lines-34);
			      
			      Draw_Text(Box_Dealout, Line_Curs.Values(Line_Curs.Val_Cur).Line_Pos,
					Line_Curs.Values(Line_Curs.Val_Cur).Column_Pos,
					White,
					Line_Curs.Values(Line_Curs.Val_Cur).Line(1..Line_Curs.Values(Line_Curs.Val_Cur).Line_Last));
			   else
			      
			      for Val in Name_Value..Total_Ttc_Value loop
				 Draw_Text(Box_Dealin , Line_Curs.values(Val).Line_Pos,
					   Line_Curs.values(Val).Column_Pos,
					   White,
					   Line_Curs.values(Val).Line(1..Line_Curs.values(Val).Line_Last));
			      end loop;
			      Voice_Print(Invoice, This.Ticket_Wins, Account_Line_Index, This.Lines-34);

			      Draw_Text(Box_Dealin, Line_Curs.Values(Line_Curs.Val_Cur).Line_Pos,
					Line_Curs.Values(Line_Curs.Val_Cur).Column_Pos,
					White,
					Line_Curs.Values(Line_Curs.Val_Cur).Line(1..Line_Curs.Values(Line_Curs.Val_Cur).Line_Last));
			   end if;
			   if Remove_Case then
			      Draw_Window(Cmd_Win);
			      Draw_Text(Cmd_Win, 1, 1, White, "Line num : ");
			   end if;

			   
			elsif Line_Curs.Values(Line_Curs.Val_Cur).Line_Last < 32 then
			   
			   Line_Curs.Values(Line_Curs.Val_Cur).Line(Line_Curs.Values(Line_Curs.Val_Cur).Line_Last + 1) := Wchar;
			   Line_Curs.Values(Line_Curs.Val_Cur).Line_Last := 
			     Line_Curs.Values(Line_Curs.Val_Cur).Line_Last + 1;
			   if Deal_Name = Deal_Out then
			      for Val in Name_Value..Total_Ttc_Value loop
				 Draw_Text(Box_Dealout , Line_Curs.values(Val).Line_Pos,
					   Line_Curs.values(Val).Column_Pos,
					   White,
					   Line_Curs.values(Val).Line(1..Line_Curs.values(Val).Line_Last));
			      end loop;

			      Draw_Text(Box_Dealout, Line_Curs.Values(Line_Curs.Val_Cur).Line_Pos,
					Line_Curs.Values(Line_Curs.Val_Cur).Column_Pos,
					White,
					Line_Curs.Values(Line_Curs.Val_Cur).Line(1..Line_Curs.Values(Line_Curs.Val_Cur).Line_Last));
			   else
			      
			      for Val in Name_Value..Total_Ttc_Value loop
				 Draw_Text(Box_Dealin , Line_Curs.values(Val).Line_Pos,
					   Line_Curs.values(Val).Column_Pos,
					   White,
					   Line_Curs.values(Val).Line(1..Line_Curs.values(Val).Line_Last));
			      end loop;

			      Draw_Text(Box_Dealin, Line_Curs.Values(Line_Curs.Val_Cur).Line_Pos,
					Line_Curs.Values(Line_Curs.Val_Cur).Column_Pos,
					White,
					Line_Curs.Values(Line_Curs.Val_Cur).Line(1..Line_Curs.Values(Line_Curs.Val_Cur).Line_Last));
			   end if;
			   
			else
			   Put(Character'Val(7));
			end if;
		     end Receive;
		     
		     --if Validated then
		     --   exit;		  
		     --end if;
	       or

		  accept Refresh do
		     null;
		  end Refresh;
		  
	       or
		  accept Page_Down do
		     if Deal_Name = Deal_Out then
			if Outvoice.Line_Last >= (This.Lines-34) then
			   if Account_Line_Index + (This.Lines-34) < Outvoice.Line_Last then
			      Account_Line_Index := Account_Line_Index + (This.Lines-34);
			   else
			      Account_Line_Index := Outvoice.Line_Last - (This.Lines-34);
			   end if;
			end if;
		     else
			if Invoice.Line_Last >= (This.Lines-34) then
			   if Account_Line_Index + (This.Lines-34) < Invoice.Line_Last then
			      Account_Line_Index := Account_Line_Index + (This.Lines-34);
			   else
			      Account_Line_Index := Invoice.Line_Last - (This.Lines-34);
			   end if;
			end if;
		     end if;
		     Ticket_Wins_Draw(This.Ticket_Wins);
		     if Deal_Name = Deal_Out then
			for Val in Name_Value..Total_Ttc_Value loop
			   Draw_Text(Box_Dealout , Line_Curs.values(Val).Line_Pos,
				     Line_Curs.values(Val).Column_Pos,
				     White,
				     Line_Curs.values(Val).Line(1..Line_Curs.values(Val).Line_Last));
			end loop;
			Voice_Print(Outvoice, This.Ticket_Wins, Account_Line_Index, This.Lines-34);

			Draw_Text(Box_Dealout, Line_Curs.Values(Line_Curs.Val_Cur).Line_Pos,
				  Line_Curs.Values(Line_Curs.Val_Cur).Column_Pos,
				  White,
				  Line_Curs.Values(Line_Curs.Val_Cur).Line(1..Line_Curs.Values(Line_Curs.Val_Cur).Line_Last));
		     else
			
			for Val in Name_Value..Total_Ttc_Value loop
			   Draw_Text(Box_Dealin , Line_Curs.values(Val).Line_Pos,
				     Line_Curs.values(Val).Column_Pos,
				     White,
				     Line_Curs.values(Val).Line(1..Line_Curs.values(Val).Line_Last));
			end loop;
			Voice_Print(Invoice, This.Ticket_Wins, Account_Line_Index, This.Lines-34);
			
			Draw_Text(Box_Dealin, Line_Curs.Values(Line_Curs.Val_Cur).Line_Pos,
				  Line_Curs.Values(Line_Curs.Val_Cur).Column_Pos,
				  White,
				  Line_Curs.Values(Line_Curs.Val_Cur).Line(1..Line_Curs.Values(Line_Curs.Val_Cur).Line_Last));
		     end if;
		     if Remove_Case then
			Draw_Window(Cmd_Win);
			Draw_Text(Cmd_Win, 1, 1, White, "Line num : ");
		     end if;
		  end Page_Down;
	       or
		  accept Page_Up do
		     if Deal_Name = Deal_Out then
			if Outvoice.Line_Last >= (This.Lines-34) then
			   if Account_Line_Index - (This.Lines-34) >= 0 then
			      Account_Line_Index := Account_Line_Range'Max(Account_Line_Index - (This.Lines-34), 0);
			   else
			      Account_Line_Index := 0;
			   end if;
			end if;
		     else
			if Invoice.Line_Last >= (This.Lines-34) then
			   if Account_Line_Index - (This.Lines-34) >= 0 then
			      Account_Line_Index := Account_Line_Range'Max(Account_Line_Index - (This.Lines-34), 0);
			   else
			      Account_Line_Index := 0;
			   end if;
			end if;
		     end if;
		     Ticket_Wins_Draw(This.Ticket_Wins);
		     if Deal_Name = Deal_Out then
			for Val in Name_Value..Total_Ttc_Value loop
			   Draw_Text(Box_Dealout , Line_Curs.values(Val).Line_Pos,
				     Line_Curs.values(Val).Column_Pos,
				     White,
				     Line_Curs.values(Val).Line(1..Line_Curs.values(Val).Line_Last));
			end loop;
			Voice_Print(Outvoice, This.Ticket_Wins, Account_Line_Index, This.Lines-34);

			Draw_Text(Box_Dealout, Line_Curs.Values(Line_Curs.Val_Cur).Line_Pos,
				  Line_Curs.Values(Line_Curs.Val_Cur).Column_Pos,
				  White,
				  Line_Curs.Values(Line_Curs.Val_Cur).Line(1..Line_Curs.Values(Line_Curs.Val_Cur).Line_Last));
		     else
			
			for Val in Name_Value..Total_Ttc_Value loop
			   Draw_Text(Box_Dealin , Line_Curs.values(Val).Line_Pos,
				     Line_Curs.values(Val).Column_Pos,
				     White,
				     Line_Curs.values(Val).Line(1..Line_Curs.values(Val).Line_Last));
			end loop;
			Voice_Print(Invoice, This.Ticket_Wins, Account_Line_Index, This.Lines-34);
			
			Draw_Text(Box_Dealin, Line_Curs.Values(Line_Curs.Val_Cur).Line_Pos,
				  Line_Curs.Values(Line_Curs.Val_Cur).Column_Pos,
				  White,
				  Line_Curs.Values(Line_Curs.Val_Cur).Line(1..Line_Curs.Values(Line_Curs.Val_Cur).Line_Last));
		     end if;
		     if Remove_Case then
			Draw_Window(Cmd_Win);
			Draw_Text(Cmd_Win, 1, 1, White, "Line num : ");
		     end if;
		  end Page_Up;
	       or
		  accept Up_Arrow do
		     null;
		  end up_arrow;
	       or
		  accept Down_Arrow do
		     null;
		  end Down_Arrow;
	       or
		  accept Left_Arrow;
	       or
		  accept Right_Arrow;
	       or
		  accept Full_Screen;
	       or
		  accept Del;
	       or
		  accept Begin_Of do
		     Account_Line_Index := 0;
		     Ticket_Wins_Draw(This.Ticket_Wins);
		     if Deal_Name = Deal_Out then
			for Val in Name_Value..Total_Ttc_Value loop
			   Draw_Text(Box_Dealout , Line_Curs.values(Val).Line_Pos,
				     Line_Curs.values(Val).Column_Pos,
				     White,
				     Line_Curs.values(Val).Line(1..Line_Curs.values(Val).Line_Last));
			end loop;
			Voice_Print(Outvoice, This.Ticket_Wins, Account_Line_Index, This.Lines-34);

			Draw_Text(Box_Dealout, Line_Curs.Values(Line_Curs.Val_Cur).Line_Pos,
				  Line_Curs.Values(Line_Curs.Val_Cur).Column_Pos,
				  White,
				  Line_Curs.Values(Line_Curs.Val_Cur).Line(1..Line_Curs.Values(Line_Curs.Val_Cur).Line_Last));
		     else
			
			for Val in Name_Value..Total_Ttc_Value loop
			   Draw_Text(Box_Dealin , Line_Curs.values(Val).Line_Pos,
				     Line_Curs.values(Val).Column_Pos,
				     White,
				     Line_Curs.values(Val).Line(1..Line_Curs.values(Val).Line_Last));
			end loop;
			Voice_Print(Invoice, This.Ticket_Wins, Account_Line_Index, This.Lines-34);
			
			Draw_Text(Box_Dealin, Line_Curs.Values(Line_Curs.Val_Cur).Line_Pos,
				  Line_Curs.Values(Line_Curs.Val_Cur).Column_Pos,
				  White,
				  Line_Curs.Values(Line_Curs.Val_Cur).Line(1..Line_Curs.Values(Line_Curs.Val_Cur).Line_Last));
		     end if;
		     if Remove_Case then
			Draw_Window(Cmd_Win);
			Draw_Text(Cmd_Win, 1, 1, White, "Line num : ");
		     end if;
		  end Begin_Of;
	       or
		  accept end_Of;
	       or
		  accept Overwrite;
	       or
		  accept Screen_Print;

	       end select;
	    end loop;
	    if Validated then
	       
	       Validated := False;
	    end if;
	 end loop Main_Loop;
      end;
   end Moneybox_Process;
   
   
   -------------------------------------------------------------------------------------------------------------
   --                                                                                                         --
   --
   -------------------------------------------------------------------------------------------------------------
   -------------------------------------------------------------------------------------------------------------
   --                                                                                                         --
   --
   -------------------------------------------------------------------------------------------------------------
   
   
   use Projects_Dll;
   
   function Get_Info(Projects : in Projects_Record; Project_Num : in Project_Num_Range) return Project_Info_Record is
      Curs : Projects_Dll.Cursor;
      First : Projects_Dll.Cursor;
   begin
      if Projects_Dll.Length(Projects.List) /= 0 then
	 Curs := Projects_Dll.First(Projects.List);
	 First := Curs;
	 loop
	    declare
	       Current : constant Project.Project_Access := Projects_Dll.Element(Curs);	       
	    begin
	       if Current.Project_Num = Project_Num then
		  return Project_Info_Record(Current.all);
	       end if;
	    end;
	    Curs := Projects_Dll.Next(Curs);
	    exit when Curs = First;
	 end loop;
	 
      end if;
      return Project_Info_Record(Null_Project);
   exception
      when others =>
	 return Project_Info_Record(Null_Project);
   end Get_Info;
   
   function Get_Project(Projects : in Projects_Record; Project_Num : in Project_Num_Range) return Project.Project_Access is
      Curs : Projects_Dll.Cursor;
      
   begin

      if Projects_Dll.Length(Projects.List) /= 0 then

	 Curs := Projects_Dll.First(Projects.List);

	 for Ier in 1..Projects_Dll.Length(Projects.List) loop
	    declare
	       Current : constant Project.Project_Access := Projects_Dll.Element(Curs);	       
	    begin

	       if Current.Project_Num = Project_Num then

		  return Current;
	       end if;
	    end;

	    Curs := Projects_Dll.Next(Curs);

	 end loop;
	 
      end if;

      return null;
   exception
      when others =>
	 return null;
   end Get_Project;
   
   
   procedure Component_Info_Draw (Name   : in String;
				  Line_Pos : in Line_Range;
				  Width    : in Column_Range) is
      Win : Window_Record := (Line_Pos, 2, 3, Width, Cyan, Window);
   begin

      Initialize(Win, Line_Pos, 2, 3, Width, Cyan, Yellow);

      Draw_Window(Win);

      Draw_Text(Win, 1, 1, White, "Library name : " & Handling.To_Wide_String(Name));

   end Component_Info_Draw;
   procedure Enlight_Component_Info_Draw (Name : in String;
					Line_Pos : in Line_Range;
					Width    : in Column_Range) is
      Win : Window_Record := (Line_Pos, 2, 3, Width, Cyan, Window);
   begin

      Initialize(Win, Line_Pos, 2, 3, Width, Cyan, Yellow);

      enlight_Window(Win);

      Put(Normal_Mode);

      Draw_Text(Win, 1, 1, White, "Library name : " & Handling.To_Wide_String(Name));

   end Enlight_Component_Info_Draw;
   
   procedure Components_Print(Project : in Project_Record;
			      Component_Index : in Natural; 			       
			      Highlighted : in Natural;
			      lines       : in Line_Range;
			      columns       : in Column_Range) is
      Line_Pos : Line_Range := 7;
   begin

      if Project.Lib_Last > 0 then

	 for Iter in Component_Index+1 .. Project.Lib_Last loop

	    declare
	       Libname : constant String_Access := Project.Libs(Iter).Unit_Name;
	    begin

	       if Libname /= null then

		  if Highlighted /= 0 and Iter = Highlighted then		     

		     Enlight_Component_Info_Draw(Libname.all, Line_Pos, Columns/2-2);

		  else

		     Component_Info_Draw(Libname.all, Line_Pos, Columns/2-2);

		  end if;
		  Line_Pos := Line_Pos + 3;
		  exit when Line_Pos >= Lines + 7;
	       end if;

	    end;
	    
	 end loop;

      end if;

   end Components_Print;

   
   procedure Archive_Info_Draw (Info : in Project_Info_Record;
      				   Line_Pos : in Line_Range;
      				   Width    : in Column_Range) is
      	 Win : Window_Record := (Line_Pos, 2, 5, Width, Blue, Window);
      	 
      	 
      begin
      	 Initialize(Win, Line_Pos, 2, 5, Width, Blue, Red);

      	 Draw_Window(Win);

      	 Draw_Text(Win, 1, 1, White, "Project Name : " & Handling.To_Wide_String(Info.Project_Name.all));
      	 Draw_Text(Win, 2, 1, White, "Version      : " & Handling.To_Wide_String(Version_io.To_String(Info.Version)));
      	 Draw_Text(Win, 3, 1, White, "Elapsed      : " & Handling.To_Wide_String(Long_Integer'Image(Long_Integer(Long_Integer(Info.Days) * 86400 + Long_Integer(Info.Elapsed/3600.0))/3600)) & " hours");

      end Archive_Info_Draw;
      procedure Enlight_Archive_Info_Draw (Info : in Project_Info_Record;
      					   Line_Pos : in Line_Range;
      					   Width    : in Column_Range) is
      	 Win : Window_Record := (Line_Pos, 2, 5, Width, Blue, Window);
      	 
      	 
      begin
	 
      	 Initialize(Win, Line_Pos, 2, 5, Width, Blue, Red);
	 
      	 enlight_Window(Win);
      	 Put(Normal_Mode);
      	 Draw_Text(Win, 1, 1, White, "Project Name : " & Handling.To_Wide_String(Info.Project_Name.all));
      	 Draw_Text(Win, 2, 1, White, "Version      : " & Handling.To_Wide_String(Version_Io.To_String(Info.Version)));
      	 Draw_Text(Win, 3, 1, White, "Elapsed      : " & Handling.To_Wide_String(Long_Integer'Image(Long_Integer(Long_Integer(Info.Days) * 86400 + Long_Integer(Info.Elapsed/3600.0))/3600)) & " hours");
	 
      end Enlight_Archive_Info_Draw;
      
   
   procedure Archives_Print(Archives : in Projects_Record;
			    Project_Index : in Natural; 			       
			    Highlighted : in Project_Num_Range;
			    lines       : in Line_Range;
			    columns       : in Column_Range) is
      Curs : Projects_Dll.Cursor;
      First : Projects_Dll.Cursor;
      Line_Pos : Line_Range := 7;
   begin

      if Projects_Dll.Length(Archives.List) /= 0 then

	 Curs := Projects_Dll.First(Archives.List);
	 First := Curs;

	 for I in 1..Project_Index loop
	    Curs := Projects_Dll.Next(Curs);
	 end loop;

	 loop
	    declare
	       The_Project : constant Project.Project_Access := Projects_Dll.Element(Curs);	       
	    begin

	       if The_Project /= null then

		  if The_Project.Project_Num = Highlighted then		     
		     
		     Enlight_Archive_Info_Draw(Project_Info_Record(The_Project.all), Line_Pos, Columns/2-2);
		     
		     
		     
		  else
		     
		     Archive_Info_Draw(Project_Info_Record(The_Project.all), Line_Pos, Columns/2-2);
		     

		  end if;
		  Line_Pos := Line_Pos + 5;
		  exit when Line_Pos >= Lines;
	       end if;

	    end;
	    if Curs /= Last(Archives.List) then

	       Curs := Projects_Dll.Next(Curs);

	    else
	       exit;
	    end if;

	 end loop;
      end if;
   end Archives_Print;



      
   procedure Project_Info_Draw (Info : in Project_Info_Record;
				Line_Pos : in Line_Range;
				Width    : in Column_Range) is
      Win : Window_Record := (Line_Pos, 2, 5, Width, Cyan, Window);
   begin
      Initialize(Win, Line_Pos, 2, 5, Width, Cyan, White);
      Draw_Window(Win);
      Draw_Text(Win, 1, 1, White, "Project Name : " & Handling.To_Wide_String(Info.Project_Name.all));
      Draw_Text(Win, 2, 1, White, "Version      : " & Handling.To_Wide_String(Version_io.To_String(Info.Version)));
      Draw_Text(Win, 3, 1, White, "Project path : " & Handling.To_Wide_String(Info.Source_Path.all));
   end Project_Info_Draw;
   procedure Enlight_Project_Info_Draw (Info : in Project_Info_Record;
					Line_Pos : in Line_Range;
					Width    : in Column_Range) is
      Win : Window_Record := (Line_Pos, 2, 5, Width, Cyan, Window);
   begin
      Initialize(Win, Line_Pos, 2, 5, Width, Cyan, White);
      enlight_Window(Win);
      Put(Normal_Mode);
      Draw_Text(Win, 1, 1, White, "Project Name : " & Handling.To_Wide_String(Info.Project_Name.all));
      Draw_Text(Win, 2, 1, White, "Version      : " & Handling.To_Wide_String(Version_Io.To_String(Info.Version)));
      Draw_Text(Win, 3, 1, White, "Project path : " & Handling.To_Wide_String(Info.Source_Path.all));
   end Enlight_Project_Info_Draw;
   
   
   
   
   procedure Projects_Print(Projects : in Projects_Record;
			    Project_Index : in Natural; 			       
			    Highlighted : in Project_Num_Range;
			    lines       : in Line_Range;
			       columns       : in Column_Range) is
      Curs : Projects_Dll.Cursor;
      First : Projects_Dll.Cursor;
      Line_Pos : Line_Range := 7;
   begin
      if Projects_Dll.Length(Projects.List) /= 0 then
	 Curs := Projects_Dll.First(Projects.List);
	 First := Curs;
	 for I in 1..Project_Index loop
	    Curs := Projects_Dll.Next(Curs);
	 end loop;
	 loop
	    declare
	       The_Project : constant Project.Project_Access := Projects_Dll.Element(Curs);	       
	    begin
	       if The_Project /= null then

		  if The_Project.Project_Num = Highlighted then		     
		     
		     Enlight_Project_Info_Draw(Project_Info_Record(The_Project.all), Line_Pos, Columns/2-2);
		     Put(Normal_Mode);
		  else

		     Project_Info_Draw(Project_Info_Record(The_Project.all), Line_Pos, Columns/2-2);
		     
		  end if;
		  Line_Pos := Line_Pos + 5;
		  exit when Line_Pos >= Lines;
	       end if;
	       
	    end;
	    if Curs /= Last(Projects.List) then
	       Curs := Projects_Dll.Next(Curs);
	    else
	       exit;
	    end if;
	    
	 end loop;
      end if;
   end Projects_Print;

   
   type Part_Enum is (Creator_None, Creator_Abstract, Creator_Name, Creator_Version, Creator_Author, Creator_Library);
   
   type Part_Record is
      record	 
	Tag  : String(1..12) := (others => Character'Val(32));
	Part : Part_Enum := Creator_None;
	Line : Wide_String(1..78) := (others => Wide_Character ' Val (32)) ; 
	Last : Natural := 0;
	Win : Window_Record;
	Line_Pos : Line_Range := 1;
	Column_Pos : Column_Range := 13;
     end record;
   
   type Part_Array is array (Part_Enum) of Part_Record;
   
   type Page_Curs_Type is
      record
	 Parts : Part_Array;
	 Part_Cur : Part_Enum := Creator_None;
      end record;
   
   type Win_Set is array (Part_Enum range Creator_Abstract .. Creator_Library) of Window_Record;
   
   
   procedure Cursor_Set(Curs : in out Page_Curs_Type; From : in Project_Record) is
   begin
      
      Wide_Fixed.Move(Handling.To_Wide_String(From.Project_Name.all), Curs.Parts(Creator_Name).Line, Error, Left);
      Curs.Parts(Creator_Name).Last := From.Project_Name'Length;
      
      Wide_Fixed.Move(Handling.To_Wide_String(Version_Io.To_String(From.Version)), Curs.Parts(Creator_Version).Line, Error, Left);
      Curs.Parts(Creator_Version).Last := Version_Io.To_String(From.Version)'Length;
      
      Wide_Fixed.Move(Handling.To_Wide_String(From.Copyright.all), Curs.Parts(Creator_Author).Line, Error, Left);
      Curs.Parts(Creator_Author).Last := From.Copyright'Length;
      
      Curs.Part_Cur := Creator_Library;
             
      
   end Cursor_Set;
   
   
   
   function Initialize (Wins : Win_Set) return Page_Curs_Type is
      Page_Curs : Page_Curs_Type;
   begin
      Page_Curs.Part_Cur := Creator_Abstract;
      Page_Curs.Parts(Creator_Abstract) :=
	(
	 "Abstract  : ",
	 Creator_Abstract,
	 (others => Wide_Character ' Val (32)),
	 0,
   	 Wins(Creator_Abstract),
	 1,
	 13
	);
      Page_Curs.Parts(Creator_Name) :=
      	(
	 "Name      : ",
      	 Creator_Name,	 
      	 (others => Wide_Character ' Val (32)),
      	 0,
      	 Wins(Creator_Name),
      	    1,
      	 13
      	);
      Page_Curs.Parts(Creator_Version) :=
      	(
	 "Version   : ",
      	 Creator_Version,
      	 (others => Wide_Character ' Val (32)),
      	 0,
      	 Wins(Creator_Version),
      	    1,
      	 13
      	);
      Page_Curs.Parts(Creator_Author) :=
      	(
	 "Author    : ",
      	 Creator_Author,
      	 (others => Wide_Character ' Val (32)),
      	 0,
      	 Wins(Creator_Author),
      	    1,
      	 13
      	);
      
      Page_Curs.Parts(Creator_Library) :=
      	(
	 "Library   : ",
      	 Creator_Library,
      	 (others => Wide_Character ' Val (32)),
      	 0,
      	 Wins(Creator_Library),
      	    1,
      	 13
      	);
      
      return Page_Curs;
   end Initialize;
   procedure Page_Print(Page : in Page_Curs_Type) is
   begin
      for Part in Creator_Abstract .. Page.Part_Cur loop
	 Draw_Window(Page.Parts(Part).Win);
	 Draw_Text(Page.Parts(Part).Win,
		   Page.Parts(Part).Line_Pos,
		   1,
		   White,
		   Handling.To_Wide_String(Page.Parts(Part).Tag));
	 Draw_Text(Page.Parts(Part).Win,
		   Page.Parts(Part).Line_Pos,
		   Page.Parts(Part).Column_Pos,
		   White,
		   Page.Parts(Part).Line(1..Page.Parts(Part).Last));
      end loop;
   end Page_Print;
   
   
   procedure List_Print (Project : in Project_Record; Win : in Window_Record ; Lib_Index : in Natural) is
      Line_Pos : Natural := 1;
   begin
      Draw_Window(Win);

      for Lib in Lib_Index + 1 .. Project.Lib_Last loop
	 
	 Draw_Text(Win, Line_Pos, 1, White, 
		   Handling.To_Wide_String(Natural'Image(Lib) & " - " &
		     Project.Libs(Lib).Unit_Name.all));
	 Line_Pos := Line_Pos + 1;
	 exit when Line_Pos > Win.win.H-2;
      end loop;

   end List_Print;
   
   
   type Creator_Record is
      record
	 Curs    : Page_Curs_Type;
	 New_Project : Project.Project_Access;
      end record;
   
   
   
   function To_Project (Creator : in Creator_Record; Num : in Project_Num_Range) return Project.Project_Access is
      
      
   begin
      Creator.New_Project.Project_Num := Num;
      Creator.New_Project.Project_Name :=
	new String '
	(
	 Handling.To_String(Creator.Curs.Parts(Creator_Name).Line(1..Creator.Curs.Parts(Creator_Name).Last))
	);
      Creator.New_Project.Copyright :=
	new String '
	(
	 Handling.To_String(Creator.Curs.Parts(Creator_Author).Line(1..Creator.Curs.Parts(Creator_Author).Last))
	);
      Creator.New_Project.Version := Version_Io.To_Version(From => Handling.To_String(Creator.Curs.Parts(Creator_Version).Line(1..Creator.Curs.Parts(Creator_Version).Last)));
	
      return Creator.New_Project;
   end To_Project;
   
   procedure Write_To_Append (Filename : in String; Line : in String) is
      File : File_Type;
   begin
      Open(File, Append_File, Filename);      
      Put_Line(File, Line);
      Close(File);
   end Write_To_Append;
   
   procedure List_Save (Project : in Project_Record) is
      Filename : constant String := Project.Project_Name.all & "-" & Version_Io.To_String(Project.Version) & '/' & "Project.lst";
      File : File_Type;
   begin
      if Project.Lib_Last /= 0 then
	 Create(File, Out_File, filename);
	 Put_Line(File, Project.Project_Name.all);
	 Put_Line(File, Project.Project_Name.all);
	 for lib in 1..Project.Lib_Last loop
	    Put_Line(File, Project.Libs(Lib).Unit_Name.all);
	 end loop;
	 Close(File);
      end if;
   end List_Save;
   
   
   procedure Make_Project (Creator : in Creator_Record) is
      
      Info : constant Project_Info_Record := Project_Info_record(Creator.New_Project.all);
      
   begin
      --  mkdir $project-$2
      Make_Dir(Creator.New_Project.Project_Name.all & "-" & Version_Io.To_String(Creator.New_Project.Version));
      
      --  cd $project-$2
      Change_Dir(Creator.New_Project.Project_Name.all & "-" & Version_Io.To_String(Creator.New_Project.Version));            
      
      --  gunzip ./.Ada/Ada_Empty-6.2.2.tar.gz
      Errno := System("gunzip ../.Ada/Ada_Empty-6.2.2.tar.gz" & Character'Val(0));
      
      --  tar -x -v -f ./.Ada/Ada_Empty-6.2.2.tar
      Errno := System("tar -x -v -f ../.Ada/Ada_Empty-6.2.2.tar" & Character'Val(0));
      
      --  gzip ./.Ada/Ada_Empty-6.2.2.tar
      Errno := System("gzip ../.Ada/Ada_Empty-6.2.2.tar" & Character'Val(0));
      
      --  make pre
      Errno := System("make pre" & Character'Val(0));

      --  make head tail process prepare project all enlight-sources
      Errno := System("make head tail" & Character'Val(0));
      

      Write_To_Append("Abstract.txt", Handling.To_String(Creator.Curs.Parts(Creator_Abstract).Line(1..Creator.Curs.Parts(Creator_Abstract).Last)));
      Write_To_Append("Project.lst", Handling.To_String(Creator.Curs.Parts(Creator_Name).Line(1..Creator.Curs.Parts(Creator_Name).Last)));
      Write_To_Append("Project.lst", Handling.To_String(Creator.Curs.Parts(Creator_Name).Line(1..Creator.Curs.Parts(Creator_Name).Last)));

      for Lib in 1..Creator.New_Project.Lib_Last loop
	 Write_To_Append("Project.lst", Creator.New_Project.Libs(Lib).Unit_Name.all);
      end loop;
      Write_To_Append("Versions.lst", Version_Io.To_String(Creator.New_Project.Version));

      Write_To_Append("Copyright", Handling.To_String(Creator.Curs.Parts(Creator_Author).Line(1..Creator.Curs.Parts(Creator_Author).Last)));

      Errno := System("make prepare project all" & Character'Val(0));

      Change_Dir("..");
      --  Write_To_Append("Projects.lst", Info.Project_Name.all & '-' &
      --  			Integer'Image(Info.Version.Major_Version)(2..Integer'Image(Info.Version.Major_Version)'Last) & '.' &
      --  			Integer'Image(Info.Version.Minor_Version)(2..Integer'Image(Info.Version.Minor_Version)'Last) & '.' &
      --  			Integer'Image(Info.Version.Revision_Version)(2..Integer'Image(Info.Version.Revision_Version)'Last) & Info.Version.Release_Version);

   end Make_Project;
   
   -- upgrade of 1 the Revision of Version
   function Update (Info : Project_Info_Record; Version : in Computer.Versions.Version_Type) return Integer is
   begin
      
      
      Put_Line("version " & Info.Project_Name.all & ' ' &
		     Integer'Image(Info.Version.Major_Version)(2..Integer'Image(Info.Version.Major_Version)'Last) & ' ' &
		     Integer'Image(Info.Version.Minor_Version)(2..Integer'Image(Info.Version.Minor_Version)'Last) & ' ' &
		     Integer'Image(Info.Version.Revision_Version)(2..Integer'Image(Info.Version.Revision_Version)'Last) & ' ' &
		     Info.Version.Release_Version);
      
      Put_Line("Upgrade " & Integer'Image(Version.Major_Version)(2..Integer'Image(Version.Major_Version)'Last) & ' ' &
		     Integer'Image(Version.Minor_Version)(2..Integer'Image(Version.Minor_Version)'Last) & ' ' &
		     Integer'Image(Version.Revision_Version)(2..Integer'Image(Version.Revision_Version)'Last) & ' ' &
		 Version.Release_Version);
      
      
     return System("bin/update2.sh " & 
		     Info.Project_Name.all & ' ' &
		     Integer'Image(Info.Version.Major_Version)(2..Integer'Image(Info.Version.Major_Version)'Last) & ' ' &
		     Integer'Image(Info.Version.Minor_Version)(2..Integer'Image(Info.Version.Minor_Version)'Last) & ' ' &
		     Integer'Image(Info.Version.Revision_Version)(2..Integer'Image(Info.Version.Revision_Version)'Last) & ' ' &
		     Info.Version.Release_Version & ' ' &
		     Integer'Image(Version.Major_Version)(2..Integer'Image(Version.Major_Version)'Last) & ' ' &
		     Integer'Image(Version.Minor_Version)(2..Integer'Image(Version.Minor_Version)'Last) & ' ' &
		     Integer'Image(Version.Revision_Version)(2..Integer'Image(Version.Revision_Version)'Last) & ' ' &
		     Version.Release_Version & Character'Val(0));
			
      
      
      --  Write_To_Append("Projects.lst", Info.Project_Name.all & '-' &
      --  			Integer'Image(Info.Version.Major_Version)(2..Integer'Image(Info.Version.Major_Version)'Last) & '.' &
      --  			Integer'Image(Info.Version.Minor_Version)(2..Integer'Image(Info.Version.Minor_Version)'Last) & '.' &
      --  			Integer'Image(Info.Version.Revision_Version+1)(2..Integer'Image(Info.Version.Revision_Version)'Last) & Info.Version.Release_Version);
      
      
      
   end Update;
   
   
   procedure Remove_Name(Project : in out Project_Record; Lib_Num : in Natural) is
   begin
      if Lib_Num = 0 then
	 return;
      end if;
      if Lib_Num < Project.Lib_Last then
	 for Iter in Lib_Num..Project.Lib_Last - 1 loop
	    Project.Libs(Iter) := Project.Libs(Iter + 1);
	    Project.Libs(Project.Lib_last) := Null_Component;
	    Project.Lib_Last := Project.Lib_Last - 1;
	 end loop;
      else
	 Project.Libs(Project.Lib_last) := Null_Component;
	 Project.Lib_Last := Project.Lib_Last - 1;
      end if;
   end Remove_Name;
   
   type Project_Manager_Record is new Creator_Record;
   
   
   
   
   
   
   
   
   task body Manager_Process is
      
      
      
            
      Creator_Abs : Window_Record := (1, 1, 3, This.Columns/2, Blue, Window);
      Creator_N     : Window_Record := (4, 1, 3, This.Columns/2, Blue, Window);
      Creator_Ver   : Window_Record := (This.Lines-8, 1, 3, This.Columns/2, Blue, Window);
      Creator_Auth   : Window_Record := (This.Lines-5, 1, 3, This.Columns/2, Blue, Window);
      Creator_List     : Window_Record := (7, 1, This.Lines-15, This.Columns/2, Blue, Window);
      Creator_Lib  : Window_Record := (This.Lines-2, 1, 3, This.Columns/2, Blue, Window);
      
      Manager_Abs : Window_Record := (1, 1, 3, This.Columns/2, Blue, Window);
      Manager_N     : Window_Record := (4, 1, 3, This.Columns/2, Blue, Window);
      Manager_Ver   : Window_Record := (This.Lines-8, 1, 3, This.Columns/2, Blue, Window);
      Manager_Auth   : Window_Record := (This.Lines-5, 1, 3, This.Columns/2, Blue, Window);
      Manager_List     : Window_Record := (7, 1, This.Lines-15, This.Columns/2, Blue, Window);
      Manager_Cmd  : Window_Record := (This.Lines-2, 1, 3, This.Columns/2, Blue, Window);
   
      
      Project_Info : Project_Info_Record;
      
      
      
      Project_Header   : Window_Record := (1, 1, 5, This.Columns/2, Blue, Window);
      
      Project_Selector : Window_Record := (6, 1, This.Lines - 5, This.Columns/2, Blue, Window);
      
      
      Components_Win   : Window_Record := (6,  1, (This.Lines - 8)/2, This.Columns/2, Blue, Window);
      
      Make_Win         : Window_Record := (6 + (This.Lines - 8)/2+1, 1, (This.Lines - 8)/2, This.Columns/2, White, Window);
      
      
      
      
      
      type Step_Enum is (Prj_None, Prj_Selector, Prj_Archives, Prj_Components, Prj_Creator, Prj_Manager, Prj_Editor, Prj_Lib_Remove, Prj_Upgrade, Prj_help);
      
      type Upgrade_Cmd_Enum is (None, Remove, Add, Make, Upgrade, quit, help);
      
      
      function Value (Line : in String) return Upgrade_Cmd_Enum is
	 Cmd : Upgrade_Cmd_Enum := None;
      begin
	 if Index(Line, " ") /= 0 then
	    return Upgrade_Cmd_Enum'Value(Line(Line'First..Index(Line, " ")-1));
	 else
	    return Upgrade_Cmd_Enum'Value(Line);
	 end if;
	 return Cmd;
      exception
	 when Constraint_Error =>
	    return Cmd;
      end Value;
      
      
      type Lang_Enum is (En, Fr, C);
      Lang      : Lang_Enum := En;
      
      Color     : constant String := Character'Val(27) & "[01;36m";
      Normal    : constant String := Character'Val(27) & "[00m";
      
      
      En_Msg : constant String := "Hello";
      Fr_Msg : constant String := "Salut";
      C_Msg  : constant String := "Error";
   
      User_Val  : constant String := "USER";
      Lang_Val  : constant String := "LANG";
   
      The_World : constant String := "world";
      The_Msg   : constant String := "Hello";   
   
      
      The_User  : String_Access;
      The_Lang  : String_Access;
   
      
      procedure Draw_Header(Project : in Project_Record; Project_Header : in Window_Record) is
      begin
	 if The_User /= null then            
	    case Lang is
	       when Fr =>
		  Draw_Text(Project_Header, 1, 1, White, Wide_Fixed."*"((The_User'Length+Fr_Msg'Length+10), '-'));
		  Draw_Text(Project_Header, 2, 1, White, Handling.To_Wide_String("-- " & Fr_Msg & ' ' & Color & The_User.all & Normal & " ! " & " --"));
		  Draw_Text(Project_Header, 3, 1, White, Wide_Fixed."*"((The_User'Length+fr_Msg'Length+10), '-'));
		  
		  Draw_Text(Project_Header, 1, (The_User'Length+fr_Msg'Length+10)+2, White, "Project name  : " & Handling.To_Wide_String(Project.Project_Name.all));
		  Draw_Text(Project_Header, 2, (The_User'Length+fr_Msg'Length+10)+2, White, "Elapsed       : " & Handling.To_Wide_String(Long_Integer'Image(Long_Integer(Project.Days) * 86400 + Long_Integer(Project.Elapsed) / 3600)) & " hours");
		  --Draw_Text(Project_Header, 3, The_User'Length+fr_Msg'Length+10)+2, White, );
	       when En =>
		  Draw_Text(Project_Header, 1, 1, White, Wide_Fixed."*"((The_User'Length+En_Msg'Length+10), '-'));
		  Draw_Text(Project_Header, 2, 1, White, Handling.To_Wide_String("-- " & En_Msg & ' ' & Color & The_User.all & Normal & " ! " & " --"));
		  Draw_Text(Project_Header, 3, 1, White, Wide_Fixed."*"((The_User'Length+En_Msg'Length+10), '-'));
		  Draw_Text(Project_Header, 1, (The_User'Length+En_Msg'Length+10)+2, White, "Project name  : " & Handling.To_Wide_String(Project.Project_Name.all));
		  Draw_Text(Project_Header, 2, (The_User'Length+En_Msg'Length+10)+2, White, "Elapsed       : " & Handling.To_Wide_String(Long_Integer'Image((Long_Integer(Project.Days) * 86400 + Long_Integer(Project.Elapsed)) / 3600)) & " hours");
		  --Draw_Text(Project_Header, 3, The_User'Length+En_Msg'Length+10)+2, White, );
	       when C =>
		  Draw_Text(Project_Header, 1, 1, White, Wide_Fixed."*"((The_User'Length+C_Msg'Length+10), '-'));
		  Draw_Text(Project_Header, 2, 1, White, Handling.To_Wide_String("-- " & C_Msg & ' ' & Color & The_User.all & Normal & " ! " & " --"));
		  Draw_Text(Project_Header, 3, 1, White, Wide_Fixed."*"((The_User'Length+C_Msg'Length+10), '-'));
		  Draw_Text(Project_Header, 1, (The_User'Length+C_Msg'Length+10)+2, White, "Project name  : " & Handling.To_Wide_String(Project.Project_Name.all));
		  Draw_Text(Project_Header, 2, (The_User'Length+C_Msg'Length+10)+2, White, "Elapsed       : " & Handling.To_Wide_String(Long_Integer'Image((Long_Integer(Project.Days) * 86400 + Long_Integer(Project.Elapsed)) / 3600)) & " hours");
		  --Draw_Text(Project_Header, 3, The_User'Length+C_Msg'Length+10)+2, White, );
	    end case;
	 else
	    Draw_Text(Project_Header, 1, 1, White, Wide_Fixed."*"((The_World'Length+The_Msg'Length+10), '-'));
	    Draw_Text(Project_Header, 2, 1, White, Handling.To_Wide_String("-- " & The_Msg & ' ' & Color & The_world & Normal & " ! " & " --"));
	    Draw_Text(Project_Header, 3, 1, White, Wide_Fixed."*"((The_World'Length+The_Msg'Length+10), '-'));
	    Draw_Text(Project_Header, 1, (The_World'Length+The_Msg'Length+10)+2, White, "Project name  : " & Handling.To_Wide_String(Project.Project_Name.all));
	    Draw_Text(Project_Header, 2, (The_World'Length+The_Msg'Length+10)+2, White, "Elapsed       : " & Handling.To_Wide_String(Long_Integer'Image((Long_Integer(Project.Days) * 86400 + Long_Integer(Project.Elapsed)) / 3600)) & " hours");
	    --Draw_Text(Project_Header, 3, The_World'Length+The_Msg'Length+10)+2, White, );
	 end if;
      end Draw_Header;
      
      
      
      
      Arch_Num : Project_Num_Range := 1;
      Arch_Index : Project_Num_Range := 0;
      Arch_Count : Natural := 0;
      
      Arch_Curs : Projects_Dll.Cursor;
      
      Component_Cur : Natural := 0;
      Component_Index : Natural := 0;

      
      
      Step_Cur : Step_Enum := Prj_Selector;
      
      Project_Index : Project_Num_Range := 0;
      
      Project_Count : Natural := 0;    
      
      
      Curs : Projects_Dll.Cursor;
      
      Creator : Creator_Record;
      Project_Manager : Project_Manager_Record;
      
      Upgraded : Project.Project_Access;
      
      
      Lib_Index : Natural := 0;
      
      Lib_Name  : Wide_String(1..3) := (others => Wide_Character'Val(32));
      Lib_Name_Last : Natural := 0;
      
      Line_Remove : Boolean := False;
      Line_Num : Natural := 0;
      
      
      
      Cmd_line : Wide_String(1..256) := (others => Wide_Character'Val(0));
      Cmd_Last : Natural := 0;
      Cmd : Upgrade_Cmd_Enum := None;
      
      
      Make_On_Bin      : String_Access := Locate_Exec_On_Path("make");
      Args             : Argument_List_Access := Argument_String_To_List("all");
      Outfilename      : constant String := "computer-spawn.stdout";
      File_Set         : Wide_String_Set(65536);
      File_Index       : Natural := 0;
      Line_Last        : Natural := 0;
      Success : Boolean := False;
      Total_Lines      : Natural := 0;
      
      
      Gnose_Context : access Gnos_Projects.Projects_Context_Record := new gnos_Projects.Projects_Context_Record;
      
      Project_Context : access Agnose_Projects.Projects_Context_Record := new Agnose_Projects.Projects_Context_Record;

      
      
   begin
      
      Initialize(Creator_Abs, 1, 1, 3, This.Columns/2, Blue, White);
      Initialize(Creator_N, 4, 1, 3, This.Columns/2, Blue, White);
      Initialize(Creator_Ver, This.Lines-8, 1, 3, This.Columns/2, Blue, White);
      Initialize(Creator_Auth, This.Lines-5, 1, 3, This.Columns/2, Blue, White);
      Initialize(Creator_List, 7, 1, This.Lines-15, This.Columns/2, Blue, White);
      Initialize(Creator_Lib, This.Lines-2, 1, 3, This.Columns/2, Blue, white);
      
      Initialize(Manager_Abs, 1, 1, 3, This.Columns/2, Blue, White);
      Initialize(Manager_N, 4, 1, 3, This.Columns/2, Blue, White);
      Initialize(Manager_Ver, This.Lines-8, 1, 3, This.Columns/2, Blue, White);
      Initialize(Manager_Auth, This.Lines-5, 1, 3, This.Columns/2, Blue, White);
      Initialize(Manager_List, 7, 1, This.Lines-15, This.Columns/2, Blue, White);
      Initialize(Manager_cmd, This.Lines-2, 1, 3, This.Columns/2, Blue, white);
      
      
      Initialize(Project_Header, 1, 1, 5, This.Columns/2, Blue, White);
      Initialize(Project_Selector, 6, 1, This.Lines - 5, This.Columns/2, Blue, White);
      
      Initialize(Components_Win, 6,  1, (This.Lines - 10)/2, This.Columns/2, Blue, Red);
      
      Initialize(Make_Win, 6 + (This.Lines - 10)/2+1, 1, (This.Lines - 10)/2, This.Columns/2, White, Magenta);
	  
      
      declare
	 
	 Project_Num : Project_Num_Range := 0;
      begin
	 
	 The_User := Getenv(User_Val);
	 The_Lang := Getenv(Lang_Val);
	 if The_Lang /= null then
	    begin
	       Lang := Lang_Enum'Value(The_Lang.all(1..2));
			exception
	       when Constraint_Error =>
		  W_Io.Put_Line("Uncknow language ; ");
	    end;
	 end if;	       
	 
	 
	 
     Main_Loop:
	 loop
	    loop
	       select
		  
		  accept Halt do
		     null;
		  end Halt;
		  exit Main_Loop;
	       or
		  accept Suspend;
	       or
		  accept Wake_Up Do
		     Errno := System("clear" & Character'Val(0));
		     if Curs = Projects_Dll.No_Element then
			Project_Num := 0;
			if Projects_Dll.Length(This.Projects.List) = 1 then
			   Curs := first(This.Projects.List);			   
			   Project_Num := First_Element(This.Projects.List).Project_Num;
			   Project_Manager.New_Project := Get_Project(This.Projects, Project_Num);
			elsif Projects_Dll.Length(This.Projects.List) > 1 then
			   Curs := First(This.Projects.List);			   
			   Project_Num := First_Element(This.Projects.List).Project_Num;
			   Project_Manager.New_Project := Get_Project(This.Projects, Project_Num);
			end if;
			
		     end if;
		     if Arch_Curs = Projects_Dll.No_Element then
			if Length(This.Archives.List) > 0 then
			   Arch_Curs := First(This.Archives.List);
			end if;
		     end if;
			
		  end Wake_Up;
		  case Step_Cur is
		     when Prj_Archives =>
			Draw_Window(Project_Header);
			Draw_Window(Project_Selector);
			if Length(This.Archives.List) /= 0 then
			   Archives_Print(This.Archives, Arch_Index, Arch_Num, This.Lines, This.Columns);
			end if;
		     when Prj_Components =>
			null;
		     when Prj_Selector =>
			Draw_Window(Project_Header);
			if Project_Manager.New_Project /= null then
			   Draw_Header(Project_Manager.New_Project.all, Project_Header);
			else
			   Draw_Header(Null_Project, Project_Header);
			end if;
			
			Draw_Window(Project_Selector);
			Projects_Print(This.Projects, Project_Index, Project_Num, This.Lines, This.Columns);
		     when Prj_Creator =>
			Draw_Window(Creator_Abs);
			Draw_Text(Creator_Abs, 1, 1, White, "Abstract  : ");
			Draw_Window(Creator_N);
			Draw_Text(Creator_N, 1, 1, White, "Name      : ");
			Draw_Window(Creator_Ver);
			Draw_Text(Creator_Ver, 1, 1, White, "Version   : ");
			Draw_Window(Creator_Auth);
			Draw_Text(Creator_Auth, 1, 1, White, "Author    : ");
			Draw_Window(Creator_List);
			if Creator.New_Project /= null then
			   List_Print(Creator.New_Project.all, Creator_List, Lib_Index);
			end if;
			Draw_Window(Creator_Lib);
			Draw_Text(Creator_Lib, 1, 1, White, "Library   : ");
			   Page_Print(Creator.Curs);
			   Draw_Text(
			   	     Creator.Curs.Parts(Creator.Curs.Part_Cur).Win,
			   	     Creator.Curs.Parts(Creator.Curs.Part_Cur).Line_Pos,
			   	     Creator.Curs.Parts(Creator.Curs.Part_Cur).Column_Pos,
			   	     White,
			   	     Creator.Curs.Parts
			   	       (Creator.Curs.Part_Cur).Line(1..Creator.Curs.Parts(Creator.Curs.Part_Cur).Last)
			   	    );
		     when Prj_Lib_Remove =>
			Draw_Window(Creator_Abs);
			Draw_Text(Creator_Abs, 1, 1, White, "Abstract  : ");
			Draw_Window(Creator_N);
			Draw_Text(Creator_N, 1, 1, White, "Name      : ");
			Draw_Window(Creator_Ver);
			Draw_Text(Creator_Ver, 1, 1, White, "Version   : ");
			Draw_Window(Creator_Auth);
			Draw_Text(Creator_Auth, 1, 1, White, "Author    : ");
			Draw_Window(Creator_List);
			
			List_Print(Creator.New_Project.all, Creator_List, Lib_Index);
			
			Draw_Window(Creator_Lib);
			Draw_Text(Creator_Lib, 1, 1, White, "Library   : ");
			Page_Print(Creator.Curs);
			Draw_Text(
				  Creator.Curs.Parts(Creator.Curs.Part_Cur).Win,
				  Creator.Curs.Parts(Creator.Curs.Part_Cur).Line_Pos,
				  Creator.Curs.Parts(Creator.Curs.Part_Cur).Column_Pos,
				  White,
				  Creator.Curs.Parts
				    (Creator.Curs.Part_Cur).Line(1..Creator.Curs.Parts(Creator.Curs.Part_Cur).Last)
				 );
			if Lib_Name_Last > 0 then
			   Draw_Text(Creator_Lib, 1, 1, White, "Line num : " & Lib_Name(1..Lib_Name_last));
			else
			   Draw_Text(Creator_Lib, 1, 1, White, "Line num : ");
			end if;
		     when Prj_Manager =>
			Draw_Window(Manager_Abs);
			Draw_Text(Manager_Abs, 1, 1, White, "Abstract  : ");
			Draw_Window(Manager_N);
			Draw_Text(Manager_N, 1, 1, White, "Name      : " & Handling.To_Wide_String(Project_Manager.New_Project.Project_Name.all));
			Draw_Window(Manager_Ver);
			Draw_Text(Manager_Ver, 1, 1, White, "Version   : " & Handling.To_Wide_String(Version_Io.To_String(Project_Manager.New_Project.Version)));
			Draw_Window(Manager_Auth);
			Draw_Text(Manager_Auth, 1, 1, White, "Author    : " & Handling.To_Wide_String(Project_Manager.New_Project.Copyright.all));
			Draw_Window(Manager_List);
			   
			List_Print(Project_Manager.New_Project.all, Manager_List, Lib_Index);
			
			Draw_Window(Manager_cmd);
			Draw_Text(Manager_cmd, 1, 1, White, "Command   : ");
			
			Page_Print(Project_Manager.Curs);
			Draw_Text(
				  Project_Manager.Curs.Parts(Project_Manager.Curs.Part_Cur).Win,
				  Project_Manager.Curs.Parts(Project_Manager.Curs.Part_Cur).Line_Pos,
				  Project_Manager.Curs.Parts(Project_Manager.Curs.Part_Cur).Column_Pos,
				  White,
				  Project_Manager.Curs.Parts
				    (Project_Manager.Curs.Part_Cur).Line(1..Project_Manager.Curs.Parts(Project_Manager.Curs.Part_Cur).Last)
				 );
			if Line_Remove then
			   if Lib_Name_Last > 0 then
			      Draw_Text(Manager_cmd, 1, 1, White, "Line num : " & Lib_Name(1..Lib_Name_last));
			   else
			      Draw_Text(Manager_cmd, 1, 1, White, "Line num : ");
			   end if;
			elsif Cmd_Last > 0 then
			   Draw_Window(Manager_cmd);
			   Draw_Text(Manager_cmd, 1, 1, White, "Command   : " & Cmd_Line(Cmd_Line'First..Cmd_Last));
			else
			   Draw_Window(Manager_cmd);
			   Draw_Text(Manager_cmd, 1, 1, White, "Command   : ");
			end if;
		     when Prj_Upgrade =>
			Draw_Window(Components_Win);
			Component_Cur := 0;
			Components_Print(Project_Manager.New_Project.all, Component_Index , Component_cur, (This.Lines-8)/2-2, This.Columns);
			
			Draw_Window(Make_Win);
			if not Print_Set(File_Set, Make_Win, File_Index, Total_Lines) then
			   raise Program_Error;
			end if;
			if Cmd_Last > 0 then

			   Draw_Window(Manager_cmd);
			   
			   Draw_Text(Manager_cmd, 1, 1, White, "Command   : " & Cmd_Line(Cmd_Line'First..Cmd_Last));

			else

			   Draw_Window(Manager_cmd);
			   Draw_Text(Manager_cmd, 1, 1, White, "Command   : ");

			end if;
		     when others =>
			null;
		  end case;
		  exit;
	       or
		  accept Refresh do
		     null;
		  end Refresh;

	       end select;
	    end loop;

	    loop
	       select
		  accept Halt;
		  exit Main_Loop;
	       or
		  accept Suspend;
		  exit;
	       or
		  accept Wake_Up;
		  
	       or
		  when Step_Cur = Prj_Selector =>
		     accept Receive(Wchar : in Wide_Character) do
		     if Is_Control(Wchar) then
			case Wchar is
			   when Wide_Character'Val(9) =>

			      Project_Num := Projects_Dll.Element(Curs).Project_Num;
			      
			      if Project_Num = 0 then
				 null; -- open archives;
				 Arch_Count := 0;
				 Arch_Index := 0;
				 if Length(This.Archives.List) > 0 then
				    Arch_Curs := First(This.Archives.List);
				 end if;
				 Step_Cur := Prj_Archives;
			      else		
				 
				 Project_Manager.New_Project := Get_Project(This.Projects, Project_Num);
				 
				 
				 
				 
				 if Project_Manager.New_Project /= null then
				    
				    
				    Gnos_Projects.Initialize(Gnose_Context.all, Projects_Params);   
				    
				    Project_Context.Project := new Agnose_Projects.Project_Record_Type(With_Ada);
				    
				    
				    
				    Agnose_Projects.Load_project(Project_Context.Project.all, Project_Manager.New_Project.Project_Name.all & 
								 '-' & Version_Io.To_String(Project_Manager.New_Project.Version));   
				    
				    Set_Start_Time;
				    Calendar.Split(Clock, Gnos.Versions.Start_Date.Year, Gnos.Versions.Start_Date.Month, Gnos.Versions.Start_Date.Day, Gnos.Versions.Start_Date.Hours);
				    
				    Project_Manager.Curs := Initialize((Manager_Abs,
									Manager_N,
								     Manager_Ver,
								     Manager_Auth,
								     Manager_Cmd));
				    
				    Step_Cur := Prj_Upgrade;
				    Component_Cur := 0;
				    Project.Open(Project_Manager.New_Project.all, clock);
				    Errno := System("clear" & Character'Val(0));
				 end if;
			      end if;
			   when Wide_Character'Val(10) => 
			      Project_Num := Element(Curs).Project_Num;
			      if Project_Num = 0 then
				 Errno := System("clear" & Character'Val(0));
				 
				 Creator.Curs := Initialize((Creator_Abs,
							     Creator_N,
				 			     Creator_Ver,
				 			     Creator_Auth,
				 			     Creator_Lib));
				 Project_Free(Creator.New_Project);
				 Creator.New_Project := new Project_Record(256);
				 
				 Step_Cur := Prj_Creator;
			      else
				 Project_Manager.Curs := Initialize((Manager_Abs,
								     Manager_N,
								     Manager_Ver,
								     Manager_Auth,
								     Manager_Cmd));
				 
				 
				 Project_Manager.New_Project := Get_Project(This.Projects, Project_Num);
				 Project.Open(Project_Manager.New_Project.all, Clock);
				 Cursor_Set(Project_Manager.Curs, From => Project_Manager.New_Project.all);
				 if Project_Manager.New_Project /= null then
				    Step_Cur := Prj_Manager;
				 end if;
			      end if;
			   when Wide_Character'Val(127) =>
			      
			      if This.Archives.Projects_Num + 1 <= Project_Num_Range'Last then
				 if Project_Num /= 0 then
				    null;-- move archive to projects.List;
				    Arch_Curs := Projects_Dll.last(This.Archives.List);
				    
				    declare
				       El : constant Project.Project_Access := Get_Project(This.Projects, Project_Num);
				    begin
				       if El.Project_Name /= null and then
					 El.Project_Name'Length /= 0 then
					  
					  Errno := System("mv " & El.Project_Name.all & 
							    '-' & Versions.Version_Io.To_String(El.Version) &
							    " Archives/" & Character'Val(0));
					  if Errno = 0 then
					     This.Archives.Projects_Num := This.Archives.Projects_Num + 1;
					     El.Project_Num := This.Archives.Projects_Num;
					     Projects_Dll.Append(This.Archives.List, El);
					     Delete(This.Projects.List, Curs);
					     if Length(This.Projects.List) > 0 then
						Curs := First(This.Projects.List);
						Project_Num := First_Element(This.Projects.List).Project_Num;
						Project_Manager.New_Project := Get_Project(This.Projects, Project_Num);
						Project_Count := 0;
						Project_Index := 0;
					     end if;
					     Projects_Manager.Archives_Save(This.Archives, "Archives/Projects.lst");
					     Projects_Manager.Manager_Save(This.Archives, "Projects.lst");
					  end if;
				       end if;
				    end;
				 end if;				    
			      end if;
			   when others =>
			      null;
			   end case;
		     else
			null;
		     end if;
		     end Receive;
		     case Step_Cur is
			when Prj_None =>
			   null;
			when Prj_Archives =>
			   Draw_Window(Project_Header);
			   Draw_Window(Project_Selector);
			   if Length(This.Archives.List) /= 0 then
			      Archives_Print(This.Archives, Arch_Index, Arch_Num, This.Lines, This.Columns);
			   end if;
			when prj_Components =>
			   
			   null;
			   
			when Prj_Selector =>
			   Draw_Window(Project_Header);
			   if Project_Manager.New_Project /= null then
			      Draw_Header(Project_Manager.New_Project.all, Project_Header);
			   end if;
			   Draw_Window(Project_Selector);
			   Projects_Print(This.Projects, Project_Index, Project_Num, This.Lines, This.Columns);
			when Prj_Creator =>
			   Draw_Window(Creator_Abs);
			   Draw_Text(Creator_Abs, 1, 1, White, "Abstract  : ");
			   Draw_Window(Creator_N);
			   Draw_Text(Creator_N, 1, 1, White, "Name      : ");
			   Draw_Window(Creator_Ver);
			   Draw_Text(Creator_Ver, 1, 1, White, "Version   : ");
			   Draw_Window(Creator_Auth);
			   Draw_Text(Creator_Auth, 1, 1, White, "Author    : ");
			   Draw_Window(Creator_List);
			   Draw_Window(Creator_Lib);
			   Draw_Text(Creator_Lib, 1, 1, White, "Library   : ");
			   Page_Print(Creator.Curs);
			   Draw_Text(
			   	     Creator.Curs.Parts(Creator.Curs.Part_Cur).Win,
			   	     Creator.Curs.Parts(Creator.Curs.Part_Cur).Line_Pos,
			   	     Creator.Curs.Parts(Creator.Curs.Part_Cur).Column_Pos,
			   	     White,
			   	     Creator.Curs.Parts
			   	       (Creator.Curs.Part_Cur).Line(1..Creator.Curs.Parts(Creator.Curs.Part_Cur).Last)
			   	    );
			   
			when Prj_Manager =>
			   Draw_Window(Manager_Abs);
			   Draw_Text(Manager_Abs, 1, 1, White, "Abstract  : ");
			   Draw_Window(Manager_N);
			   Draw_Text(Manager_N, 1, 1, White, "Name      : " & Handling.To_Wide_String(Project_Manager.New_Project.Project_Name.all));
			   Draw_Window(Manager_Ver);
			   Draw_Text(Manager_Ver, 1, 1, White, "Version   : " & Handling.To_Wide_String(Version_Io.To_String(Project_Manager.New_Project.Version)));
			   Draw_Window(Manager_Auth);
			   Draw_Text(Manager_Auth, 1, 1, White, "Author    : " & Handling.To_Wide_String(Project_Manager.New_Project.Copyright.all));
			   Draw_Window(Manager_List);
			   
			   List_Print(Project_Manager.New_Project.all, Manager_List, Lib_Index);
			   
			   Draw_Window(Manager_cmd);
			   Draw_Text(Manager_cmd, 1, 1, White, "Command   : ");
			   
			   Page_Print(Project_Manager.Curs);
			   Draw_Text(
				     Project_Manager.Curs.Parts(Project_Manager.Curs.Part_Cur).Win,
				     Project_Manager.Curs.Parts(Project_Manager.Curs.Part_Cur).Line_Pos,
				     Project_Manager.Curs.Parts(Project_Manager.Curs.Part_Cur).Column_Pos,
				     White,
				     Project_Manager.Curs.Parts
				       (Project_Manager.Curs.Part_Cur).Line(1..Project_Manager.Curs.Parts(Project_Manager.Curs.Part_Cur).Last)
				    );
			   if Line_Remove then
			      if Lib_Name_Last > 0 then
				 Draw_Text(Manager_cmd, 1, 1, White, "Line num : " & Lib_Name(1..Lib_Name_last));
			      else
				 Draw_Text(Manager_cmd, 1, 1, White, "Line num : ");
			      end if;
			   elsif Cmd_Last > 0 then
			      Draw_Window(Manager_cmd);
			      Draw_Text(Manager_cmd, 1, 1, White, "Command   : " & Cmd_Line(Cmd_Line'First..Cmd_Last));
			   else
			      Draw_Window(Manager_cmd);
			      Draw_Text(Manager_cmd, 1, 1, White, "Command   : ");
			   end if;
			when Prj_Upgrade =>
			   Draw_Window(Components_Win);

			   Components_Print(Project_Manager.New_Project.all, Component_Index , Component_cur, (This.Lines-8)/2-2, This.Columns);

			   Draw_Window(Make_Win);
			   if Cmd_Last > 0 then

			      Draw_Window(Manager_cmd);
			      Draw_Text(Manager_cmd, 1, 1, White, "Command   : " & Cmd_Line(Cmd_Line'First..Cmd_Last));

			   else

			      Draw_Window(Manager_cmd);
			      Draw_Text(Manager_cmd, 1, 1, White, "Command   : ");

			   end if;
			when others =>
			   null;
		     end case;
	       or
		  when Step_Cur = Prj_creator =>
		     accept Receive(Wchar : in Wide_Character) do
			if Is_Control(Wchar) then
			   case Wchar is
			      when Wide_Character'Val(1) =>
				 Creator.Curs := Initialize((Creator_Abs,
							     Creator_N,
				 			     Creator_Ver,
				 			     Creator_Auth,
				 			     Creator_Lib));
				 Project_Free(Creator.New_Project);
				 Creator.New_Project := new Project_Record(256);
				 
			      when Wide_Character'Val(5) => 
				 Step_Cur := Prj_Lib_Remove;
			      when Wide_Character'Val(10) => 
				 if Creator.Curs.Part_Cur = Creator_Library then
				    
				    if Creator.Curs.Parts(Creator.Curs.Part_Cur).Last /= 0 then

				       Lib_Add
					 (Creator.New_Project.all, 
					  Handling.To_String
					    (Creator.Curs.Parts(Creator.Curs.Part_Cur).Line(1..Creator.Curs.Parts(Creator.Curs.Part_Cur).Last)));

				       Creator.Curs.Parts(Creator.Curs.Part_Cur).Line := (others => ' ');
				       Creator.Curs.Parts(Creator.Curs.Part_Cur).Last := 0;
				    end if;
				 else
				    Creator.Curs.Part_Cur := Part_Enum'Succ(Creator.Curs.Part_Cur);
				 end if;
			      when Wide_Character'Val(12) =>
				 Errno := System("clear" & Character'Val(0));
			      when Wide_Character'Val(18) => 
				 Step_Cur := Prj_Selector;
				 
			      when Wide_Character'Val(20) =>
				 
				 
				 Creator.New_Project := To_Project(Creator, This.Projects.Projects_Num + 1);

				 Make_Project(Creator);
				 
				 Curs := Last(This.Projects.List);
				 
				 Insert(This.Projects.List, Curs, Creator.New_Project);

				 This.Projects.Projects_Num := This.Projects.Projects_Num + 1;

				 Project_Num := This.Projects.Projects_Num;

				 

				 
				 Creator.Curs := Initialize((Creator_Abs,
							     Creator_N,
				 			     Creator_Ver,
				 			     Creator_Auth,
				 			     Creator_Lib));

				 

				 Step_Cur := Prj_Selector;

			      when Wide_Character'Val(127) =>
				 
				 if Creator.Curs.Parts(Creator.Curs.Part_Cur).Last > 0 then
				    Creator.Curs.Parts(Creator.Curs.Part_Cur).Line(Creator.Curs.Parts(Creator.Curs.Part_Cur).Last) := Wide_Character'Val(32);
				    Creator.Curs.Parts(Creator.Curs.Part_Cur).Last := 
				      Creator.Curs.Parts(Creator.Curs.Part_Cur).Last - 1;
				 else
				    Text_Io.Put(Character'Val(7));
				 end if;
			      when others =>
				 null;
			   end case;
			   case Step_Cur is
			      when Prj_None =>
				 null;
			      when Prj_Selector =>
				 Draw_Window(Project_Header);
				 if Project_Manager.New_Project /= null then
				    Draw_Header(Project_Manager.New_Project.all, Project_Header);
				 end if;
				 
				 Draw_Window(Project_Selector);
				 Projects_Print(This.Projects, Project_Index, Project_Num, This.Lines, This.Columns);
			      when Prj_Creator =>
				 Draw_Window(Creator_Abs);
				 Draw_Text(Creator_Abs, 1, 1, White, "Abstract  : ");
				 Draw_Window(Creator_N);
				 Draw_Text(Creator_N, 1, 1, White, "Name      : ");
				 Draw_Window(Creator_Ver);
				 Draw_Text(Creator_Ver, 1, 1, White, "Version   : ");
				 Draw_Window(Creator_Auth);
				 Draw_Text(Creator_Auth, 1, 1, White, "Author    : ");
				 Draw_Window(Creator_List);
				 
				 List_Print(Creator.New_Project.all, Creator_List, Lib_Index);
				 
				 Draw_Window(Creator_Lib);
				 Draw_Text(Creator_Lib, 1, 1, White, "Library   : ");
				 Page_Print(Creator.Curs);
				 Draw_Text(
					   Creator.Curs.Parts(Creator.Curs.Part_Cur).Win,
					   Creator.Curs.Parts(Creator.Curs.Part_Cur).Line_Pos,
					   Creator.Curs.Parts(Creator.Curs.Part_Cur).Column_Pos,
					   White,
					   Creator.Curs.Parts
					     (Creator.Curs.Part_Cur).Line(1..Creator.Curs.Parts(Creator.Curs.Part_Cur).Last)
					  );				 
			      when Prj_Lib_Remove =>
				 if Lib_Name_Last > 0 then
				    Draw_Text(Creator_Lib, 1, 1, White, "Line num  : " & Lib_Name(1..Lib_Name_last));
				 else
				    Draw_Text(Creator_Lib, 1, 1, White, "Line num  : ");
				 end if;
			      when others =>
				 null;
			   end case;
			elsif Creator.Curs.Parts(Creator.Curs.Part_Cur).Last + 1 <= 
			  Creator.Curs.Parts(Creator.Curs.Part_Cur).Line'Length then
			  
			   Creator.Curs.Parts(Creator.Curs.Part_Cur).Line(Creator.Curs.Parts(Creator.Curs.Part_Cur).Last + 1) := Wchar;
			   Creator.Curs.Parts(Creator.Curs.Part_Cur).Last :=
			     Creator.Curs.Parts(Creator.Curs.Part_Cur).Last + 1;
			   Draw_Window(Creator.Curs.Parts(Creator.Curs.Part_Cur).Win);
			   Page_Print(Creator.Curs);
			   Draw_Text(
				     Creator.Curs.Parts(Creator.Curs.Part_Cur).Win,
				     Creator.Curs.Parts(Creator.Curs.Part_Cur).Line_Pos,
				     Creator.Curs.Parts(Creator.Curs.Part_Cur).Column_Pos,
				     White,
				     Creator.Curs.Parts
				       (Creator.Curs.Part_Cur).Line(1..Creator.Curs.Parts(Creator.Curs.Part_Cur).Last)
				    );
			   
			else
			   Text_Io.Put(Character ' Val (7));
			end if;
		     end Receive;
		     
	       or
		  when Step_Cur = Prj_Manager =>
		     accept Receive(Wchar : in Wide_Character) do
			if Is_Control(Wchar) then			   
			   case Wchar is
			      when Wide_Character'Val(10) => 
				 begin
				    Cmd := Value(Handling.To_String(Cmd_Line(Cmd_Line'First..Cmd_Last)));
				    case Cmd is
				       when None =>
					  null;
				       when Help =>
					  null;
				       when Make =>
					  if Cmd_Last = 4 then
					     Errno := System("make" & Character'Val(0));
					  elsif Cmd_Last > 5 then
					     Change_Dir(Project_Manager.New_Project.Project_Name.all & "-" & Version_Io.To_String(Creator.New_Project.Version));            
					     
					     Free(Args);
					     Args := Argument_String_To_List(Handling.To_String(Cmd_Line(6..Cmd_Last)) & Character'Val(0));
					     Spawn(Make_On_Bin.all, Args.all, Outfilename, Success, errno);						   						   
					     
						   
					     --Errno := System("make " &  Handling.To_String(Cmd_Line(6..Cmd_Last)) & Character'Val(0));
					     Load_File(File_Set, Outfilename, Line_Last);
					     Change_Dir("..");
					     
					     
					  end if;
				       when Add =>
					  if Cmd_Last > 4 then
					     Lib_Add(Project_Manager.New_Project.all, Handling.To_String(Cmd_Line(5..Cmd_Last)));
					     List_Save(Project_Manager.New_Project.all);
					  else
					     Put(Character'Val(7));
					  end if;
				       when Remove =>
					  begin
					     Line_Num := Natural'Value(Handling.To_String(Cmd_Line(Cmd_Line'First+7..Cmd_Last)));
					     
					     Remove_Name(Project_Manager.New_Project.all, Line_Num);
					     List_Save(Project_Manager.New_Project.all);
					  exception
					     when others =>
						null;
					  end;
				       when Upgrade =>
					  
					  
					  
					  ----------------------------------------------------------------------------------------------------------
					  --
					  --
					  --
					  --
					  --
					  --
					  
					  Upgraded := new Project_Record ' (Project_Manager.New_project.all);
					  
					  
					  
					  
					  
					  Text_Io.Put_Line("Update version...");
					  
					  
					  
					  Text_Io.Put_Line("-- check for New Specifications...");
					  
					  Versions.New_Description := Environment.Check_Modification_To_New_Description(Project_Context.all);
					  
					  
					  Put_Line("New Description : " & Boolean'Image(Versions.New_Description));					  
					  
					  
					  Text_Io.Put_Line("-- check for New Implementation...");
					  
					  Versions.New_Action := Environment.Check_Modification_To_New_Action(Project_Context.all);
					  
					  Put_Line("New Implementation : " & Boolean'Image(Versions.New_Action));					  
					  
					  Text_Io.Put_Line("-- Version Update...");
					  -- update Version !
					  if Gnose_Context.Project.Project_Prefix /= null then
					     Text_Io.Put_Line("Project prefix : " & Gnose_Context.Project.Project_Prefix.all);
					     Text_Io.Put_Line("Project name : " & Gnose_Context.Project.Project_Name.all); 
					     declare

						Node_Name : access String := new String ' (Gnose_Context.Project.Project_Name(Gnose_Context.Project.Project_Prefix'Length+1..Gnose_Context.Project.Project_Name'Last));

					     begin
						
						
						if Versions.New_Description then
						   Put_Line("Current version is : " & Versions.Version_Io.To_String(Upgraded.Version));
						   Upgraded.Version := 
						     Version_Update(Upgraded.Version);
						   Put_Line("version is updated :" & Versions.Version_Io.To_String(Upgraded.Version));
						   
						   --  if Environment.Version_Update /= 0 then
						   --     raise Program_Error;
						   --  end if;		  
						   Text_Io.Put_Line("-- Editting minor version...");
						   
						   Main_Description(Gnose_Context.Project.Project_Name.all, Gnose_Context.Project.Project_Prefix.all, "Date", Formatting.Image(Clock), Node_Name.all);
						   Main_Description(Gnose_Context.Project.Project_Name.all, Gnose_Context.Project.Project_Prefix.all, "Version", Versions.Version_Io.To_String(Upgraded.Version), Node_Name.all);
						   
						   for File_Id in Specifications_Filenames_Search.File_Content'Range loop
						      Update(Handling.To_String(Results."-"(Specifications_Filenames_Search.File_Content(File_Id))), "Date", Formatting.Image(Clock));
						      Update(Handling.To_String(Results."-"(Specifications_Filenames_Search.File_Content(File_Id))), "Version", Versions.Version_Io.To_String(Upgraded.Version));
						   end loop;
						   
						   
						end if;
						
						if Versions.New_Action then
						   Put_Line("Current version is : " & Versions.Version_Io.To_String(Upgraded.Version));
						   Upgraded.Version := 
						     Version_Update(Upgraded.Version);
						   Put_Line("version is updated :" & Versions.Version_Io.To_String(Upgraded.Version));
						   
						   --  if Environment.Version_Update /= 0 then
						   --     raise Program_Error;
						   --  end if;		  
						   Text_Io.Put_Line("-- Editting revision version...");
						   
						   Main_Description(Gnose_Context.Project.Project_Name.all, Gnose_Context.Project.Project_Prefix.all, "Date", Formatting.Image(Clock), Node_Name.all);
						   Main_Description(Gnose_Context.Project.Project_Name.all, Gnose_Context.Project.Project_Prefix.all, "Version", Versions.Version_Io.To_String(Upgraded.Version), Node_Name.all);
						   for File_Id in Implementations_Filenames_Search.File_Content'Range loop
						      Update(Handling.To_String(Results."-"(Implementations_Filenames_Search.File_Content(File_Id))), "Date", Formatting.Image(Clock));
						      Update(Handling.To_String(Results."-"(Implementations_Filenames_Search.File_Content(File_Id))), "Version", Versions.Version_Io.To_String(Upgraded.Version));
						   end loop;
						   
						   
						end if;
						
						if Versions.New_Action or Versions.New_Description then
						   Put_Line("Current version is : " & Versions.Version_Io.To_String(Upgraded.Version));
						   Upgraded.Version := 
						     Version_Update(Upgraded.Version);
						   Put_Line("version is updated :" & Versions.Version_Io.To_String(Upgraded.Version));
						   --  if Environment.Version_Update /= 0 then
						   --     raise Program_Error;
						   --  end if;		  
						   Text_Io.Put_Line("-- Editting major version...");
						   To_Major(Gnose_Context.Project.Project_Name.all, Gnose_Context.Project.Project_Prefix.all);
						   To_Minor(Gnose_Context.Project.Project_Name.all, Gnose_Context.Project.Project_Prefix.all);
						   To_Revision(Gnose_Context.Project.Project_Name.all, Gnose_Context.Project.Project_Prefix.all);
						   
						else
						   Put_Line("Current version is : " & Versions.Version_Io.To_String(Upgraded.Version));
						   Upgraded.Version := 
						     Version_Update(Upgraded.Version);
						   Put_Line("version is updated :" & Versions.Version_Io.To_String(Upgraded.Version));
						   
						   --  if Environment.Version_Update /= 0 then
						   --     raise Program_Error;
						   --  end if;		  
						   Text_Io.Put_Line("-- Editting release version...");
						   To_Release(Gnose_Context.Project.Project_Name.all,
							      Gnose_Context.Project.Project_Prefix.all);
						end if;
						Versions.New_Action := False;	       
						Versions.New_Description := False;
						
					     end;
					  else
					     Text_Io.Put_Line("Project name : " & Gnose_Context.Project.Project_Name.all); 
					     declare
						
						Node_Name : access String := new String ' ("");

					     begin
						
						
						if Versions.New_Description then
						   Put_Line("Current version is : " & Versions.Version_Io.To_String(Upgraded.Version));
						   Upgraded.Version := 
						     Version_Update(Upgraded.Version);
						   Put_Line("version is updated :" & Versions.Version_Io.To_String(Upgraded.Version));
						   --  if Environment.Version_Update /= 0 then
						   --     raise Program_Error;
						   --  end if;		  
						   
						   
						   Main_Description(Gnose_Context.Project.Project_Name.all, "", "Date", Formatting.Image(Clock), Node_Name.all);
						   Main_Description(Gnose_Context.Project.Project_Name.all, "", "Version", Versions.Version_Io.To_String(Project_Manager.New_Project.Version), Node_Name.all);
						   
						   for File_Id in Specifications_Filenames_Search.File_Content'Range loop
						      Update(Handling.To_String(Results."-"(Specifications_Filenames_Search.File_Content(File_Id))), "Date", Formatting.Image(Clock));
						      Update(Handling.To_String(Results."-"(Specifications_Filenames_Search.File_Content(File_Id))), "Version", Versions.Version_Io.To_String(Project_Manager.New_Project.Version));
						   end loop;
						   
						   
						end if;
						
						if Versions.New_Action then
						   Put_Line("Current version is : " & Versions.Version_Io.To_String(Upgraded.Version));
						   Upgraded.Version := 
						     Version_Update(Upgraded.Version);
						   Put_Line("version is updated :" & Versions.Version_Io.To_String(Upgraded.Version));
						   
						   
						   --  if Environment.Version_Update /= 0 then
						   --     raise Program_Error;
						   --  end if;		  		  
						   Main_Description(Gnose_Context.Project.Project_Name.all, "", "Date", Formatting.Image(Clock), Node_Name.all);
						   Main_Description(Gnose_Context.Project.Project_Name.all, "", "Version", Versions.Version_Io.To_String(Project_Manager.New_Project.Version), Node_Name.all);
						   for File_Id in Implementations_Filenames_Search.File_Content'Range loop
						      Update(Handling.To_String(Results."-"(Implementations_Filenames_Search.File_Content(File_Id))), "Date", Formatting.Image(Clock));
						      Update(Handling.To_String(Results."-"(Implementations_Filenames_Search.File_Content(File_Id))), "Version", Versions.Version_Io.To_String(Project_Manager.New_Project.Version));
						   end loop;
						   
						   
						end if;
						
						if Versions.New_Action or Versions.New_Description then
						   Text_Io.Put_Line("-- Editting revision version...");
						   To_Revision(Gnose_Context.Project.Project_Name.all, "");
						   Text_Io.Put_Line("-- Editting minor version...");
						   To_Minor(Gnose_Context.Project.Project_Name.all, "");
						   Text_Io.Put_Line("-- Editting major version...");
						   To_Major(Gnose_Context.Project.Project_Name.all, "");
						else
						   Put_Line("Current version is : " & Versions.Version_Io.To_String(Upgraded.Version));
						   Upgraded.Version := 
						     Version_Update(Upgraded.Version);
						   Put_Line("version is updated :" & Versions.Version_Io.To_String(Upgraded.Version));
						   
						   --  if Environment.Version_Update /= 0 then
						   --     raise Program_Error;
						   --  end if;		  
						   Text_Io.Put_Line("-- Editting release version...");
						   To_Release(Gnose_Context.Project.Project_Name.all,
							      "");
						end if;
						Versions.New_Action := False;	       
						Versions.New_Description := False;
						
					     end;
					     
					  end if;

					  
					  
					  

					  
					  
					  
					  --
					  --
					  --
					  --
					  --
					  --
					  --
					  -----------------------------------------------------------------------------------------------------------
					  
					  
					  
					  
					  
					  
					  if Upgraded /= null then
					     
					     This.Projects.Projects_Num := This.Projects.Projects_Num + 1;
					     Upgraded.Project_Num := This.Projects.Projects_Num;
					     Curs := Last(This.Projects.List);
					     Projects_DLL.Delete(This.Projects.List, Curs);
					     if Upgraded.Version.Revision_Version + 1 < Computer.Versions.Revision_Version_Type'Last then
						Upgraded.Version.Revision_Version := 
						  Upgraded.Version.Revision_Version + 1;
					     end if;
					     
					     Append(This.Projects.List, Upgraded);
					     Projects_Manager.Manager_Save(This.Projects, "./Projects.lst");
					     if Update(Get_Info(This.Projects, Project_Manager.New_Project.Project_Num), Upgraded.Version) = 0 then
						
						Clear(This.Projects.List);
						Projects_Manager.Manager_Load(This.Projects, "./Projects.lst");
					     end if;
					     
					     This.Projects.Projects_Num := This.Projects.Projects_Num + 1;
					     Append(This.Projects.List, 
						    new Project_Record ' (Null_Project));
					     
					  end if;
					  Project.Close(Project_Manager.New_Project.all, Clock);
					  Project_Count := 0;
					  Project_Index := 0;
					  Curs := First(This.Projects.List);			   
					  Project_Num := First_Element(This.Projects.List).Project_Num;
					  Project_Manager.New_Project := Get_Project(This.Projects, Project_Num);
					  Projects_Manager.Manager_Save(This.Archives, "Projects.lst");
					  Step_Cur := Prj_Selector;
				       when Quit =>
					  null;
				    end case;
				    
				    Cmd_Last := 0;
				    Cmd_Line := (others => Wide_Character'Val(32));
				 exception
				    when others =>
				       null;
				 end;
			      when Wide_Character'Val(18) => 
				 Project.Close(Project_Manager.New_Project.all, Clock);
				 Step_Cur := Prj_Selector;
				 Draw_Window(Project_Header);
				 
				 
				 Draw_Window(Project_Selector);
				 Projects_Print(This.Projects, Project_Index, Project_Num, This.Lines, This.Columns);

			      when Wide_Character'Val(21) =>
				 
				 ----------------------------------------------------------------------------------------------------------
				 --
				 --
				 --
				 --
				 --
				 --
				 
				 
				 
				 
				 
				 Upgraded := new Project_Record ' (Project_Manager.New_project.all);
				 
				 Text_Io.Put_Line("Update version...");
				 
				 
				 
				 Text_Io.Put_Line("-- check for New Specifications...");
				 
				 Versions.New_Description := Environment.Check_Modification_To_New_Description(Project_Context.all);
				 
				 
				 --Put_Line("New Description : " & Boolean'Image(Versions.New_Description));
				 
				 
				 Text_Io.Put_Line("-- check for New Implementation...");
				 
				 Versions.New_Action := Environment.Check_Modification_To_New_Action(Project_Context.all);
				 
				 Text_Io.Put_Line("-- Version Update...");
				 -- update Version !
				 if Gnose_Context.Project.Project_Prefix /= null then
				    Text_Io.Put_Line("Project prefix : " & Gnose_Context.Project.Project_Prefix.all);
				    Text_Io.Put_Line("Project name : " & Gnose_Context.Project.Project_Name.all); 
				    declare

				       Node_Name : access String := new String ' (Gnose_Context.Project.Project_Name(Gnose_Context.Project.Project_Prefix'Length+1..Gnose_Context.Project.Project_Name'Last));

				    begin
				       
				       
				       if Versions.New_Description then
					  Put_Line("Current version is : " & Versions.Version_Io.To_String(Upgraded.Version));
						   Upgraded.Version := 
						     Version_Update(Upgraded.Version);
						   Put_Line("version is updated :" & Versions.Version_Io.To_String(Upgraded.Version));
						   
					  --  if Environment.Version_Update /= 0 then
					  --     raise Program_Error;
					  --  end if;		  
					  Text_Io.Put_Line("-- Editting minor version...");
					  
					  Main_Description(Gnose_Context.Project.Project_Name.all, Gnose_Context.Project.Project_Prefix.all, "Date", Formatting.Image(Clock), Node_Name.all);
					  Main_Description(Gnose_Context.Project.Project_Name.all, Gnose_Context.Project.Project_Prefix.all, "Version", Versions.Version_Io.To_String(Project_Manager.New_Project.Version), Node_Name.all);
					  
					  for File_Id in Specifications_Filenames_Search.File_Content'Range loop
					     Update(Handling.To_String(Results."-"(Specifications_Filenames_Search.File_Content(File_Id))), "Date", Formatting.Image(Clock));
					     Update(Handling.To_String(Results."-"(Specifications_Filenames_Search.File_Content(File_Id))), "Version", Versions.Version_Io.To_String(Project_Manager.New_Project.Version));
					  end loop;
					  
					  
				       end if;
				       
				       if Versions.New_Action then
					  Put_Line("Current version is : " & Versions.Version_Io.To_String(Upgraded.Version));
						   Upgraded.Version := 
						     Version_Update(Upgraded.Version);
						   Put_Line("version is updated :" & Versions.Version_Io.To_String(Upgraded.Version));
						   
					  --  if Environment.Version_Update /= 0 then
					  --     raise Program_Error;
					  --  end if;		  
					  Text_Io.Put_Line("-- Editting revision version...");
					  
					  Main_Description(Gnose_Context.Project.Project_Name.all, Gnose_Context.Project.Project_Prefix.all, "Date", Formatting.Image(Clock), Node_Name.all);
					  Main_Description(Gnose_Context.Project.Project_Name.all, Gnose_Context.Project.Project_Prefix.all, "Version", Versions.Version_Io.To_String(Project_Manager.New_Project.Version), Node_Name.all);
					  for File_Id in Implementations_Filenames_Search.File_Content'Range loop
					     Update(Handling.To_String(Results."-"(Implementations_Filenames_Search.File_Content(File_Id))), "Date", Formatting.Image(Clock));
					     Update(Handling.To_String(Results."-"(Implementations_Filenames_Search.File_Content(File_Id))), "Version", Versions.Version_Io.To_String(Project_Manager.New_Project.Version));
					  end loop;
					  
					  
				       end if;
				       
				       if Versions.New_Action or Versions.New_Description then
					  Put_Line("Current version is : " & Versions.Version_Io.To_String(Upgraded.Version));
						   Upgraded.Version := 
						     Version_Update(Upgraded.Version);
						   Put_Line("version is updated :" & Versions.Version_Io.To_String(Upgraded.Version));
						   
					  --  if Environment.Version_Update /= 0 then
					  --     raise Program_Error;
					  --  end if;		  
					  Text_Io.Put_Line("-- Editting major version...");
					  To_Major(Gnose_Context.Project.Project_Name.all, Gnose_Context.Project.Project_Prefix.all);
					  To_Minor(Gnose_Context.Project.Project_Name.all, Gnose_Context.Project.Project_Prefix.all);
					  To_Revision(Gnose_Context.Project.Project_Name.all, Gnose_Context.Project.Project_Prefix.all);
					  
				       else
					  Put_Line("Current version is : " & Versions.Version_Io.To_String(Upgraded.Version));
						   Upgraded.Version := 
						     Version_Update(Upgraded.Version);
						   Put_Line("version is updated :" & Versions.Version_Io.To_String(Upgraded.Version));
						   
					  --  if Environment.Version_Update /= 0 then
					  --     raise Program_Error;
					  --  end if;		  
					  Text_Io.Put_Line("-- Editting release version...");
					  To_Release(Gnose_Context.Project.Project_Name.all,
						     Gnose_Context.Project.Project_Prefix.all);
				       end if;
				       Versions.New_Action := False;	       
				       Versions.New_Description := False;
				       
				    end;
				 else
				    Text_Io.Put_Line("Project name : " & Gnose_Context.Project.Project_Name.all); 
				    declare
				       
				       Node_Name : access String := new String ' ("");

				    begin
				       
				       
				       if Versions.New_Description then
					  Put_Line("Current version is : " & Versions.Version_Io.To_String(Upgraded.Version));
						   Upgraded.Version := 
						     Version_Update(Upgraded.Version);
						   Put_Line("version is updated :" & Versions.Version_Io.To_String(Upgraded.Version));
						   
					  --  if Environment.Version_Update /= 0 then
					  --     raise Program_Error;
					  --  end if;		  
					  
					  
					  Main_Description(Gnose_Context.Project.Project_Name.all, "", "Date", Formatting.Image(Clock), Node_Name.all);
					  Main_Description(Gnose_Context.Project.Project_Name.all, "", "Version", Versions.Version_Io.To_String(Project_Manager.New_Project.Version), Node_Name.all);
					  
					  for File_Id in Specifications_Filenames_Search.File_Content'Range loop
					     Update(Handling.To_String(Results."-"(Specifications_Filenames_Search.File_Content(File_Id))), "Date", Formatting.Image(Clock));
					     Update(Handling.To_String(Results."-"(Specifications_Filenames_Search.File_Content(File_Id))), "Version", Versions.Version_Io.To_String(Project_Manager.New_Project.Version));
					  end loop;
					  
					  
				       end if;
				       
				       if Versions.New_Action then
					  Put_Line("Current version is : " & Versions.Version_Io.To_String(Upgraded.Version));
						   Upgraded.Version := 
						     Version_Update(Upgraded.Version);
						   Put_Line("version is updated :" & Versions.Version_Io.To_String(Upgraded.Version));
						   
					  --  if Environment.Version_Update /= 0 then
					  --     raise Program_Error;
					  --  end if;		  		  
					  Main_Description(Gnose_Context.Project.Project_Name.all, "", "Date", Formatting.Image(Clock), Node_Name.all);
					  Main_Description(Gnose_Context.Project.Project_Name.all, "", "Version", Versions.Version_Io.To_String(Project_Manager.New_Project.Version), Node_Name.all);
					  for File_Id in Implementations_Filenames_Search.File_Content'Range loop
					     Update(Handling.To_String(Results."-"(Implementations_Filenames_Search.File_Content(File_Id))), "Date", Formatting.Image(Clock));
					     Update(Handling.To_String(Results."-"(Implementations_Filenames_Search.File_Content(File_Id))), "Version", Versions.Version_Io.To_String(Project_Manager.New_Project.Version));
					  end loop;
					  
					  
				       end if;
				       
				       if Versions.New_Action or Versions.New_Description then
					  Text_Io.Put_Line("-- Editting revision version...");
					  To_Revision(Gnose_Context.Project.Project_Name.all, "");
					  Text_Io.Put_Line("-- Editting minor version...");
					  To_Minor(Gnose_Context.Project.Project_Name.all, "");
					  Text_Io.Put_Line("-- Editting major version...");
					  To_Major(Gnose_Context.Project.Project_Name.all, "");
				       else
					  Put_Line("Current version is : " & Versions.Version_Io.To_String(Upgraded.Version));
						   Upgraded.Version := 
						     Version_Update(Upgraded.Version);
						   Put_Line("version is updated :" & Versions.Version_Io.To_String(Upgraded.Version));
						   
					  --  if Environment.Version_Update /= 0 then
					  --     raise Program_Error;
					  --  end if;		  
					  Text_Io.Put_Line("-- Editting release version...");
					  To_Release(Gnose_Context.Project.Project_Name.all,
						     "");
				       end if;
				       Versions.New_Action := False;	       
				       Versions.New_Description := False;
				       
				    end;
				    
				 end if;

				 
				 
				 

				 
				 
				 
				 --
				 --
				 --
				 --
				 --
				 --
				 --
				 -----------------------------------------------------------------------------------------------------------
				 
				 
				 if Upgraded /= null then
				    
				    This.Projects.Projects_Num := This.Projects.Projects_Num + 1;
				    Upgraded.Project_Num := This.Projects.Projects_Num;
				    Curs := Last(This.Projects.List);
				    Projects_DLL.Delete(This.Projects.List, Curs);
				    if Upgraded.Version.Revision_Version + 1 < Computer.Versions.Revision_Version_Type'Last then
				       Upgraded.Version.Revision_Version := 
					 Upgraded.Version.Revision_Version + 1;
				    end if;
				    
				    Append(This.Projects.List, Upgraded);
				    Projects_Manager.Manager_Save(This.Projects, "./Projects.lst");
				    if Update(Get_Info(This.Projects, Project_Manager.New_Project.Project_Num), Upgraded.Version) = 0 then
				       
				       Clear(This.Projects.List);
				       Projects_Manager.Manager_Load(This.Projects, "./Projects.lst");
				    end if;
				    
				    This.Projects.Projects_Num := This.Projects.Projects_Num + 1;
				    Append(This.Projects.List, 
					   new Project_Record ' (Null_Project));
				    
				 end if;
				 Project.Close(Project_Manager.New_Project.all, Clock);
				 Project_Count := 0;
				 Project_Index := 0;
				 Curs := First(This.Projects.List);			   
				 Project_Num := First_Element(This.Projects.List).Project_Num;
				 Project_Manager.New_Project := Get_Project(This.Projects, Project_Num);
				 
				 Projects_Manager.Manager_Save(This.Projects, "./Projects.lst");
				 
				 Step_Cur := Prj_Selector;
				 
				 
			      when Wide_Character'Val(127) =>
				 if Cmd_Last > 0 then
				    Cmd_Line(Cmd_Last) :=  Wide_Character'Val(32);
				    Cmd_Last := Cmd_Last - 1;
				 else
				    Put(Character'Val(7));
				 end if;
			      when others =>
				 null;
			   end case;
			elsif Cmd_Last < Cmd_Line'Length then
			   Cmd_Line(Cmd_Last + 1) := Wchar;
			   Cmd_Last := Cmd_Last + 1;
			else
			   Put(Character'Val(7));
			end if;
		     end Receive;
		     case Step_Cur is
			when Prj_Selector =>
			   Draw_Window(Project_Header);
			   if Project_Manager.New_Project /= null then
			      Draw_Header(Project_Manager.New_Project.all, Project_Header);
			   end if;
			   
			   Draw_Window(Project_Selector);
			   Projects_Print(This.Projects, Project_Index, Project_Num, This.Lines, This.Columns);
			when Prj_Creator =>
			   Draw_Window(Creator_Abs);
			   Draw_Text(Creator_Abs, 1, 1, White, "Abstract  : ");
			   Draw_Window(Creator_N);
			   Draw_Text(Creator_N, 1, 1, White, "Name      : ");
			   Draw_Window(Creator_Ver);
			   Draw_Text(Creator_Ver, 1, 1, White, "Version   : ");
			   Draw_Window(Creator_Auth);
			   Draw_Text(Creator_Auth, 1, 1, White, "Author    : ");
			   Draw_Window(Creator_List);
			   Draw_Window(Creator_Lib);
			   Draw_Text(Creator_Lib, 1, 1, White, "Library   : ");
			   Page_Print(Creator.Curs);
			   Draw_Text(
			   	     Creator.Curs.Parts(Creator.Curs.Part_Cur).Win,
			   	     Creator.Curs.Parts(Creator.Curs.Part_Cur).Line_Pos,
			   	     Creator.Curs.Parts(Creator.Curs.Part_Cur).Column_Pos,
			   	     White,
			   	     Creator.Curs.Parts
			   	       (Creator.Curs.Part_Cur).Line(1..Creator.Curs.Parts(Creator.Curs.Part_Cur).Last)
			   	    );
			when Prj_Lib_Remove =>
			   Draw_Window(Creator_Abs);
			   Draw_Text(Creator_Abs, 1, 1, White, "Abstract  : ");
			   Draw_Window(Creator_N);
			   Draw_Text(Creator_N, 1, 1, White, "Name      : ");
			   Draw_Window(Creator_Ver);
			   Draw_Text(Creator_Ver, 1, 1, White, "Version   : ");
			   Draw_Window(Creator_Auth);
			   Draw_Text(Creator_Auth, 1, 1, White, "Author    : ");
			   Draw_Window(Creator_List);
			   
			   List_Print(Creator.New_Project.all, Creator_List, Lib_Index);
			   
			   Draw_Window(Creator_Lib);
			   Draw_Text(Creator_Lib, 1, 1, White, "Library   : ");
			   Page_Print(Creator.Curs);
			   Draw_Text(
				     Creator.Curs.Parts(Creator.Curs.Part_Cur).Win,
				     Creator.Curs.Parts(Creator.Curs.Part_Cur).Line_Pos,
				     Creator.Curs.Parts(Creator.Curs.Part_Cur).Column_Pos,
				     White,
				     Creator.Curs.Parts
				       (Creator.Curs.Part_Cur).Line(1..Creator.Curs.Parts(Creator.Curs.Part_Cur).Last)
				    );
			   if Lib_Name_Last > 0 then
			      Draw_Text(Creator_Lib, 1, 1, White, "Line num : " & Lib_Name(1..Lib_Name_last));
			   else
			      Draw_Text(Creator_Lib, 1, 1, White, "Line num : ");
			   end if;
			when Prj_Manager =>
			   Draw_Window(Manager_Abs);
			   Draw_Text(Manager_Abs, 1, 1, White, "Abstract  : ");
			   Draw_Window(Manager_N);
			   Draw_Text(Manager_N, 1, 1, White, "Name      : " & Handling.To_Wide_String(Project_Manager.New_Project.Project_Name.all));
			   Draw_Window(Manager_Ver);
			   Draw_Text(Manager_Ver, 1, 1, White, "Version   : " & Handling.To_Wide_String(Version_Io.To_String(Project_Manager.New_Project.Version)));
			   Draw_Window(Manager_Auth);
			   Draw_Text(Manager_Auth, 1, 1, White, "Author    : " & Handling.To_Wide_String(Project_Manager.New_Project.Copyright.all));
			
			   Draw_Window(Manager_List);
			   
			   List_Print(Project_Manager.New_Project.all, Manager_List, Lib_Index);
			   
			   Draw_Window(Manager_cmd);
			   Draw_Text(Manager_cmd, 1, 1, White, "Command   : ");
			   Page_Print(Project_Manager.Curs);
			   Draw_Text(
				     Project_Manager.Curs.Parts(Project_Manager.Curs.Part_Cur).Win,
				     Project_Manager.Curs.Parts(Project_Manager.Curs.Part_Cur).Line_Pos,
				     Project_Manager.Curs.Parts(Project_Manager.Curs.Part_Cur).Column_Pos,
				     White,
				     Project_Manager.Curs.Parts
				       (Project_Manager.Curs.Part_Cur).Line(1..Project_Manager.Curs.Parts(Project_Manager.Curs.Part_Cur).Last)
				    );
			   if Line_Remove then
			      if Lib_Name_Last > 0 then
				 Draw_Text(Manager_cmd, 1, 1, White, "Line num : " & Lib_Name(1..Lib_Name_last));
			      else
				 Draw_Text(Manager_cmd, 1, 1, White, "Line num : ");
			      end if;
			   elsif Cmd_Last > 0 then
			      Draw_Window(Manager_cmd);
			      Draw_Text(Manager_cmd, 1, 1, White, "Command   : " & Cmd_Line(Cmd_Line'First..Cmd_Last));
			   else
			      Draw_Window(Manager_cmd);
			      Draw_Text(Manager_cmd, 1, 1, White, "Command   : ");
			   end if;
			when Prj_Upgrade =>
			   Draw_Window(Components_Win);
			   Components_Print(Project_Manager.New_Project.all, Component_Index , Component_cur, (This.Lines-8)/2-2, This.Columns);
			   
			   Draw_Window(Make_Win);
			   if Cmd_Last > 0 then
			      Draw_Window(Manager_cmd);
			      Draw_Text(Manager_cmd, 1, 1, White, "Command   : " & Cmd_Line(Cmd_Line'First..Cmd_Last));
			   else
			      Draw_Window(Manager_cmd);
			      Draw_Text(Manager_cmd, 1, 1, White, "Command   : ");
			   end if;
			when others =>
			   null;
		     end case;
		     
	       or
		  when Step_Cur = Prj_archives =>
		     accept Receive(Wchar : in Wide_Character) do
			if Is_Control(Wchar) then
			   case Wchar is
			      when Wide_Character'Val(9) =>			
				 if Length(This.Archives.List) > 0 then
				    Arch_Num := Element(Arch_Curs).Project_Num;
				    Put_Line("Arch_Num : " & Integer'Image(Integer(Arch_Num)));
				    
				    if This.Projects.Projects_Num + 1 <= Project_Num_Range'Last then
				      
				       if Arch_Num /= 0 then
					  null;-- move archive to projects.List;
					  Curs := Projects_Dll.First(This.Projects.List);
					  Project_Count := 0;
					  Project_Index := 0;
					  declare
					     El : constant Project.Project_Access := Get_Project(This.Archives, Arch_Num);
					  begin
					     if El.Project_Name /= null and then
					       El.Project_Name'Length /= 0 then
						
						Errno := System("mv Archives/" & El.Project_Name.all & '-' & 
								  Versions.Version_Io.To_String(El.Version) & 
								  " ." & Character'Val(0));
						
						
						
						
						
						
						if Errno = 0 then
						   El.Project_Num := This.Projects.Projects_Num + 1;
						   This.Projects.Projects_Num := This.Projects.Projects_Num + 1;
						   
						   Insert(This.Projects.List, Curs, El, Curs);
						   Delete(This.Archives.List, Arch_Curs);
						   Projects_Manager.Archives_Save(This.Archives, "Archives/Projects.lst");
						   Projects_Manager.Manager_Save(This.Archives, "Projects.lst");
						end if;
					     end if;
					  end;
				       end if;				    
				    end if;
				 end if;
				 if Length(This.Archives.List) > 0 then
				    Arch_Curs := First(This.Archives.List);
				 end if;
				 Step_Cur := Prj_Selector;
			      when Wide_Character'Val(10) => 
				 null; -- nothing to be done.
			      when Wide_Character'Val(18) => 
				 Step_Cur := Prj_Selector;
			      when Wide_Character'Val(127) =>
				 Step_Cur := Prj_Selector;
			      when others =>
				 null;
			   end case;
			else
			   null;
			end if;
		     end Receive;
		     case Step_Cur is
			when Prj_Archives =>
			   Draw_Window(Project_Selector);
			   Archives_Print(This.Archives, Arch_Index, Arch_Num, This.Lines, This.Columns);
			when Prj_None =>
			   null;
			when Prj_Manager =>
			   null;
			when Prj_Selector =>
			   Draw_Window(Project_Header);
			   if Project_Manager.New_Project /= null then
			      Draw_Header(Project_Manager.New_Project.all, Project_Header);
			   end if;
			   Draw_Window(Project_Selector);
			   Projects_Print(This.Projects, Project_Index, Project_Num, This.Lines, This.Columns);
			when others =>
			   null;
		     end case;
	       
	       or
		  when Step_Cur = Prj_Components =>
		     accept Receive(Wchar : in Wide_Character) do
			if Is_Control(Wchar) then
			   case Wchar is
			      when Wide_Character'Val(10) => 
				 null;
			      when Wide_Character'Val(18) => 
				 Step_Cur := Prj_Manager;
			      when others =>
				 null;
			   end case;
			else
			   null;
			end if;
		     end Receive;
		     case Step_Cur is
			when Prj_None =>
			   null;
			when Prj_Manager =>
			   null;
			when Prj_Selector =>
			   Draw_Window(Project_Header);
			   if Project_Manager.New_Project /= null then
			      Draw_Header(Project_Manager.New_Project.all, Project_Header);
			   end if;
			   Draw_Window(Project_Selector);
			   Projects_Print(This.Projects, Project_Index, Project_Num, This.Lines, This.Columns);
			when others =>
			   null;
		     end case;
	       
		     
	       or
		  when Step_Cur = Prj_Editor =>
		     accept Receive(Wchar : in Wide_Character) do
			if Is_Control(Wchar) then
			   case Wchar is
			      when Wide_Character'Val(10) => 
				 null;
			      when Wide_Character'Val(18) => 
				 Step_Cur := Prj_Manager;
			      when others =>
				 null;
			   end case;
			else
			   null;
			end if;
		     end Receive;
		     case Step_Cur is
			when Prj_None =>
			   null;
			when Prj_Manager =>
			   null;
			when Prj_Selector =>
			   Draw_Window(Project_Header);
			   if Project_Manager.New_Project /= null then
			      Draw_Header(Project_Manager.New_Project.all, Project_Header);
			   end if;
			   Draw_Window(Project_Selector);
			   Projects_Print(This.Projects, Project_Index, Project_Num, This.Lines, This.Columns);
			when others =>
			   null;
		     end case;
	       or
		  when Step_Cur = Prj_Lib_Remove =>
		     accept Receive(Wchar : in Wide_Character) do
			if Is_Control(Wchar) then
			   case Wchar is
			      when Wide_Character'Val(10) => 
				 declare
				    Line_Num : Natural := 0;
				 begin
				    Line_Num := Natural'Value(Handling.To_String(Lib_Name(1..Lib_Name_Last)));
				    Remove_Name(Creator.New_Project.all, Line_Num);
				    
				 exception
				    when others =>
				       null;
				 end;
				 Step_Cur := Prj_Creator;
				 Lib_Name := (others => Wide_Character'Val(32));
				 Lib_Name_Last := 0;
			      when Wide_Character'Val(12) =>
				 Errno := System("clear" & Character'Val(0));
			      when Wide_Character'Val(18) => 
				 Step_Cur := Prj_Selector;
			      when Wide_Character'Val(127) => 
				 if Lib_Name_Last > 0 then
				    Lib_Name(Lib_Name_Last) := Wide_Character'Val(32);
				    Lib_Name_Last := Lib_Name_Last - 1;
				 else
				    Put(Character'Val(7));
				 end if;
			      when others =>
				 null;
			   end case;
			   case Step_Cur is
			      when Prj_None =>
				 null;
			      when Prj_Selector =>
				 Draw_Window(Project_Header);
				 if Project_Manager.New_Project /= null then
				    Draw_Header(Project_Manager.New_Project.all, Project_Header);
				 end if;
				 Draw_Window(Project_Selector);
				 Projects_Print(This.Projects, Project_Index, Project_Num, This.Lines, This.Columns);
			      when Prj_Creator =>
				 Draw_Window(Creator_Abs);
				 Draw_Text(Creator_Abs, 1, 1, White, "Abstract  : ");
				 Draw_Window(Creator_N);
				 Draw_Text(Creator_N, 1, 1, White, "Name      : ");
				 Draw_Window(Creator_Ver);
				 Draw_Text(Creator_Ver, 1, 1, White, "Version   : ");
				 Draw_Window(Creator_Auth);
				 Draw_Text(Creator_Auth, 1, 1, White, "Author    : ");
				 Draw_Window(Creator_List);
				 
				 List_Print(Creator.New_Project.all, Creator_List, Lib_Index);
				 
				 Draw_Window(Creator_Lib);
				 Draw_Text(Creator_Lib, 1, 1, White, "Library   : ");
				 Page_Print(Creator.Curs);
				 Draw_Text(
					   Creator.Curs.Parts(Creator.Curs.Part_Cur).Win,
					   Creator.Curs.Parts(Creator.Curs.Part_Cur).Line_Pos,
					   Creator.Curs.Parts(Creator.Curs.Part_Cur).Column_Pos,
					   White,
					   Creator.Curs.Parts
					     (Creator.Curs.Part_Cur).Line(1..Creator.Curs.Parts(Creator.Curs.Part_Cur).Last)
					  );				 
			      when Prj_Lib_Remove =>
				 Draw_Window(Creator_Lib);
				 if Lib_Name_Last > 0 then
				    Draw_Text(Creator_Lib, 1, 1, White, "Line num  : " & Lib_Name(1..Lib_Name_last));
				 else
				    Draw_Text(Creator_Lib, 1, 1, White, "Line num  : ");
				 end if;

			      when others =>
				 null;
			   end case;
			elsif Lib_Name_Last < Lib_Name'Length then
			   Draw_Window(Creator_Lib);
			   if Lib_Name_Last > 0 then
			      Draw_Text(Creator_Lib, 1, 1, White, "Line num  : " & Lib_Name(1..Lib_Name_last));
			   else
			      Draw_Text(Creator_Lib, 1, 1, White, "Line num  : ");
			   end if;
			   
			   Lib_Name(Lib_Name_Last + 1) := Wchar;
			   Lib_Name_Last := Lib_Name_Last + 1;
			else
			   Put(Character'Val(7));
			
			end if;
		     end Receive;
	       or
		  when Step_Cur = Prj_help =>
		     accept Receive(Wchar : in Wide_Character) do
			if Is_Control(Wchar) then
			   case Wchar is
			      when Wide_Character'Val(10) => 
				 null;
			      when Wide_Character'Val(18) => 
				 Step_Cur := Prj_Manager;
			      when others =>
				 null;
			   end case;
			else
			   null;
			end if;
		     end Receive;
		     case Step_Cur is
			when Prj_None =>
			   null;
			when Prj_Manager =>
			   null;
			when Prj_Selector =>
			   Draw_Window(Project_Header);
			   if Project_Manager.New_Project /= null then
			      Draw_Header(Project_Manager.New_Project.all, Project_Header);
			   end if;
			   Draw_Window(Project_Selector);
			   Projects_Print(This.Projects, Project_Index, Project_Num, This.Lines, This.Columns);
			when others =>
			   null;
		     end case;
	       or
		  when Step_Cur = Prj_Upgrade =>
		     accept Receive(Wchar : in Wide_Character) do
			if Is_Control(Wchar) then
			   case Wchar is			      
			      when Wide_Character'Val(10) => 
				 if Cmd_Last = 0 then
				    if Component_Cur > 0 then
				       Args := Argument_String_To_List(Project_Manager.New_Project.Project_Name.all & '-' & Versions.Version_Io.To_String(Project_Manager.New_Project.Version)
									 & Directory_Separator & 
									 Project_Manager.New_Project.Project_Name.all & Directory_Separator & 
									 Project_Manager.New_Project.Libs(Component_Cur).Unit_Name.all & Directory_Separator);
				       
				       Spawn(Locate_Exec_On_Path("emacs").all, Args.all, Outfilename, Success, errno);
				       Errno := System("clear" & Character'Val(0));
				       Load_File(File_Set, Outfilename, Line_Last);
				    end if;
				 else
				       
				       begin
					  Cmd := Value(Handling.To_String(Cmd_Line(Cmd_Line'First..Cmd_Last)));
					  case Cmd is
					     when None =>
						null;
					     when Help =>
						null;
					     when Make =>
						if Cmd_Last = 4 then
						   Free(Args);
						   Args := new Argument_List(1..0);
						   Spawn(Make_On_Bin.all, Args.all, Outfilename, Success, errno);
						   Load_File(File_Set, Outfilename, Line_Last);
						   
						   
						elsif Cmd_Last > 5 then
						   
						   
						   begin
						      Change_Dir(Project_Manager.New_Project.Project_Name.all & "-" & Version_Io.To_String(Project_manager.New_Project.Version));            
						      
						      Free(Args);
						      Args := Argument_String_To_List(Handling.To_String(Cmd_Line(6..Cmd_Last)) & Character'Val(0));
						      
						      Spawn(Make_On_Bin.all, Args.all, Outfilename, Success, errno);						   						   
						      Load_File(File_Set, Outfilename, Line_Last);
						      Change_Dir("..");
						   
						      
						      
						   exception
						      when Name_Error =>
							 Put_Line("name error");
						      when Constraint_Error =>
							 Put_Line("constraint error");
						      when others =>
							 Put_Line("others error");
						   end ;
						   
						end if;
					     when Add =>
						if Cmd_Last > 4 then
						   Lib_Add(Project_Manager.New_Project.all, Handling.To_String(Cmd_Line(5..Cmd_Last)));
						   List_Save(Project_Manager.New_Project.all);
						else
						   Put(Character'Val(7));
						end if;
					     when Remove =>
						begin
						   Line_Num := Natural'Value(Handling.To_String(Cmd_Line(Cmd_Line'First+7..Cmd_Last)));
						   
						   Remove_Name(Project_Manager.New_Project.all, Line_Num);
						   List_Save(Project_Manager.New_Project.all);
						exception
						   when others =>
						      null;
						end;
					     when Upgrade =>
						

						
						
						----------------------------------------------------------------------------------------------------------
						--
						--
						--
						--
						--
						--
						
						Upgraded := new Project_Record ' (Project_Manager.New_project.all);
						
						
						
						
						
						Text_Io.Put_Line("Update version...");
						
						
						
						Text_Io.Put_Line("-- check for New Specifications...");
						
						Versions.New_Description := Environment.Check_Modification_To_New_Description(Project_Context.all);
						
						
						--Put_Line("New Description : " & Boolean'Image(Versions.New_Description));
						
						
						Text_Io.Put_Line("-- check for New Implementation...");
						
						Versions.New_Action := Environment.Check_Modification_To_New_Action(Project_Context.all);
						
						Text_Io.Put_Line("-- Version Update...");
						-- update Version !
						if Gnose_Context.Project.Project_Prefix /= null then
						   Text_Io.Put_Line("Project prefix : " & Gnose_Context.Project.Project_Prefix.all);
						   Text_Io.Put_Line("Project name : " & Gnose_Context.Project.Project_Name.all); 
						   declare

						      Node_Name : access String := new String ' (Gnose_Context.Project.Project_Name(Gnose_Context.Project.Project_Prefix'Length+1..Gnose_Context.Project.Project_Name'Last));

						   begin
						      
						      
						      if Versions.New_Description then
							 Upgraded.Version := 
							   Version_Update(Upgraded.Version);
							 --  if Environment.Version_Update /= 0 then
							 --     raise Program_Error;
							 --  end if;		  
							 Text_Io.Put_Line("-- Editting minor version...");
							 
							 Main_Description(Gnose_Context.Project.Project_Name.all, Gnose_Context.Project.Project_Prefix.all, "Date", Formatting.Image(Clock), Node_Name.all);
							 Main_Description(Gnose_Context.Project.Project_Name.all, Gnose_Context.Project.Project_Prefix.all, "Version", Versions.Version_Io.To_String(Upgraded.Version), Node_Name.all);
							 
							 for File_Id in Specifications_Filenames_Search.File_Content'Range loop
							    Update(Handling.To_String(Results."-"(Specifications_Filenames_Search.File_Content(File_Id))), "Date", Formatting.Image(Clock));
							    Update(Handling.To_String(Results."-"(Specifications_Filenames_Search.File_Content(File_Id))), "Version", Versions.Version_Io.To_String(Upgraded.Version));
							 end loop;
							 
							 
						      end if;
						      
						      if Versions.New_Action then
							 Upgraded.Version := 
							   Version_Update(Upgraded.Version);
							 --  if Environment.Version_Update /= 0 then
							 --     raise Program_Error;
							 --  end if;		  
							 Text_Io.Put_Line("-- Editting revision version...");
							 
							 Main_Description(Gnose_Context.Project.Project_Name.all, Gnose_Context.Project.Project_Prefix.all, "Date", Formatting.Image(Clock), Node_Name.all);
							 Main_Description(Gnose_Context.Project.Project_Name.all, Gnose_Context.Project.Project_Prefix.all, "Version", Versions.Version_Io.To_String(Upgraded.Version), Node_Name.all);
							 for File_Id in Implementations_Filenames_Search.File_Content'Range loop
							    Update(Handling.To_String(Results."-"(Implementations_Filenames_Search.File_Content(File_Id))), "Date", Formatting.Image(Clock));
							    Update(Handling.To_String(Results."-"(Implementations_Filenames_Search.File_Content(File_Id))), "Version", Versions.Version_Io.To_String(Upgraded.Version));
							 end loop;
							 
							 
						      end if;
						      
						      if Versions.New_Action or Versions.New_Description then
							 Upgraded.Version := 
							   Version_Update(Upgraded.Version);
							 --  if Environment.Version_Update /= 0 then
							 --     raise Program_Error;
							 --  end if;		  
							 Text_Io.Put_Line("-- Editting major version...");
							 To_Major(Gnose_Context.Project.Project_Name.all, Gnose_Context.Project.Project_Prefix.all);
							 To_Minor(Gnose_Context.Project.Project_Name.all, Gnose_Context.Project.Project_Prefix.all);
							 To_Revision(Gnose_Context.Project.Project_Name.all, Gnose_Context.Project.Project_Prefix.all);
							 
						      else
							 Upgraded.Version := 
							   Version_Update(Upgraded.Version);
							 --  if Environment.Version_Update /= 0 then
							 --     raise Program_Error;
							 --  end if;		  
							 Text_Io.Put_Line("-- Editting release version...");
							 To_Release(Gnose_Context.Project.Project_Name.all,
								    Gnose_Context.Project.Project_Prefix.all);
						      end if;
						      Versions.New_Action := False;	       
						      Versions.New_Description := False;
						      
						   end;
						else
						   Text_Io.Put_Line("Project name : " & Gnose_Context.Project.Project_Name.all); 
						   declare
						      
						      Node_Name : access String := new String ' ("");

						   begin
						      
						      
						      if Versions.New_Description then
							 Upgraded.Version := 
							   Version_Update(Upgraded.Version);
							 --  if Environment.Version_Update /= 0 then
							 --     raise Program_Error;
							 --  end if;		  
							 
							 
							 Main_Description(Gnose_Context.Project.Project_Name.all, "", "Date", Formatting.Image(Clock), Node_Name.all);
							 Main_Description(Gnose_Context.Project.Project_Name.all, "", "Version", Versions.Version_Io.To_String(Upgraded.Version), Node_Name.all);
							 
							 for File_Id in Specifications_Filenames_Search.File_Content'Range loop
							    Update(Handling.To_String(Results."-"(Specifications_Filenames_Search.File_Content(File_Id))), "Date", Formatting.Image(Clock));
							    Update(Handling.To_String(Results."-"(Specifications_Filenames_Search.File_Content(File_Id))), "Version", Versions.Version_Io.To_String(Upgraded.Version));
							 end loop;
							 
							 
						      end if;
						      
						      if Versions.New_Action then
							 Upgraded.Version := 
							   Version_Update(Upgraded.Version);
							 --  if Environment.Version_Update /= 0 then
							 --     raise Program_Error;
							 --  end if;		  		  
							 Main_Description(Gnose_Context.Project.Project_Name.all, "", "Date", Formatting.Image(Clock), Node_Name.all);
							 Main_Description(Gnose_Context.Project.Project_Name.all, "", "Version", Versions.Version_Io.To_String(Upgraded.Version), Node_Name.all);
							 for File_Id in Implementations_Filenames_Search.File_Content'Range loop
							    Update(Handling.To_String(Results."-"(Implementations_Filenames_Search.File_Content(File_Id))), "Date", Formatting.Image(Clock));
							    Update(Handling.To_String(Results."-"(Implementations_Filenames_Search.File_Content(File_Id))), "Version", Versions.Version_Io.To_String(Upgraded.Version));
							 end loop;
							 
							 
						      end if;
						      
						      if Versions.New_Action or Versions.New_Description then
							 Text_Io.Put_Line("-- Editting revision version...");
							 To_Revision(Gnose_Context.Project.Project_Name.all, "");
							 Text_Io.Put_Line("-- Editting minor version...");
							 To_Minor(Gnose_Context.Project.Project_Name.all, "");
							 Text_Io.Put_Line("-- Editting major version...");
							 To_Major(Gnose_Context.Project.Project_Name.all, "");
						      else
							 Upgraded.Version := 
							   Version_Update(Upgraded.Version);
							 --  if Environment.Version_Update /= 0 then
							 --     raise Program_Error;
							 --  end if;		  
							 Text_Io.Put_Line("-- Editting release version...");
							 To_Release(Gnose_Context.Project.Project_Name.all,
								    "");
						      end if;
						      Versions.New_Action := False;	       
						      Versions.New_Description := False;
						      
						   end;
						   
						end if;

						
						
						

						
						
						
						--
						--
						--
						--
						--
						--
						--
						-----------------------------------------------------------------------------------------------------------
						
						
						
						if Upgraded /= null then
						   
						   This.Projects.Projects_Num := This.Projects.Projects_Num + 1;
						   Upgraded.Project_Num := This.Projects.Projects_Num;
						   Curs := Last(This.Projects.List);
						   Projects_DLL.Delete(This.Projects.List, Curs);
						   --  if Upgraded.Version.Revision_Version + 1 < Computer.Versions.Revision_Version_Type'Last then
						   --     Upgraded.Version.Revision_Version := 
						   --  	Upgraded.Version.Revision_Version + 1;
						   --  end if;
						   
						   Append(This.Projects.List, Upgraded);
						   Projects_Manager.Manager_Save(This.Projects, "./Projects.lst");
						   if Update(Get_Info(This.Projects, Project_Manager.New_Project.Project_Num), Upgraded.Version) = 0 then
						      
						      Clear(This.Projects.List);
						      Projects_Manager.Manager_Load(This.Projects, "./Projects.lst");
						   end if;
						   
						   This.Projects.Projects_Num := This.Projects.Projects_Num + 1;
						   Append(This.Projects.List, 
							  new Project_Record ' (Null_Project));
						   
						end if;
						Project.Close(Project_Manager.New_Project.all, Clock);
						Project_Count := 0;
						Project_Index := 0;
						Curs := First(This.Projects.List);			   
						Project_Num := First_Element(This.Projects.List).Project_Num;
						Project_Manager.New_Project := Get_Project(This.Projects, Project_Num);
						Projects_Manager.Manager_Save(This.Projects, "./Projects.lst");
						Step_Cur := Prj_Selector;
					     when Quit =>
						null;
					  end case;
					  
					  
					  
					  
					  Cmd_Last := 0;
					  Cmd_Line := (others => Wide_Character'Val(32));
				       exception
					  when others =>
					     null;
				       end;
				    end if;
				    if Cmd_Last = 0 then
				       
				       null;
				       
				    else
				       
				       null;
				       
				    end if;
			      when Wide_Character'Val(12) => 
				 Errno := System("clear" & Character'Val(0));
			      when Wide_Character'Val(18) => 
				 Step_Cur := Prj_manager;
				 Cursor_Set(Project_Manager.Curs, From => Project_Manager.New_Project.all);
				 Project.Close(Project_Manager.New_Project.all, Clock);
				 
			      when Wide_Character'Val(21) =>
				 
				 
				 				 
				 ----------------------------------------------------------------------------------------------------------
				 --
				 --
				 --
				 --
				 --
				 --
				 Upgraded := new Project_Record ' (Project_Manager.New_project.all);
				 
				 Text_Io.Put_Line("Update version...");
				 
				 
				 
				 Text_Io.Put_Line("-- check for New Specifications...");
				 
				 Versions.New_Description := Environment.Check_Modification_To_New_Description(Project_Context.all);
				 
				 
				 
				 Text_Io.Put_Line("-- check for New Implementation...");
				 
				 Versions.New_Action := Environment.Check_Modification_To_New_Action(Project_Context.all);
				 
				 Text_Io.Put_Line("-- Version Update...");
				 -- update Version !
				 if Project_Context.Project.Project_Prefix /= null then
				    
				    Text_Io.Put_Line("Project prefix : " & Project_Context.Project.Project_Prefix.all);
				    
				    Text_Io.Put_Line("Project name : " & Project_Context.Project.Project_Name.all); 
				    declare
				       
				       Node_Name : access String := new String ' (Project_Context.Project.Project_Name(Project_Context.Project.Project_Prefix'Length+1..Project_Context.Project.Project_Name'Last));

				    begin
				       
				       
				       if Versions.New_Description then
					  Put_Line("Current version is : " & Versions.Version_Io.To_String(Upgraded.Version));
						   Upgraded.Version := 
						     Version_Update(Upgraded.Version);
						   Put_Line("version is updated :" & Versions.Version_Io.To_String(Upgraded.Version));
						   
					  --  if Environment.Version_Update /= 0 then
					  --  	raise Program_Error;
					  --  end if;		  
					  Text_Io.Put_Line("-- Editting minor version...");
					  
					  Main_Description(Project_Context.Project.Project_Name.all, Project_Context.Project.Project_Prefix.all, "Date", Formatting.Image(Clock), Node_Name.all);
					  Main_Description(Project_Context.Project.Project_Name.all, Project_Context.Project.Project_Prefix.all, "Version", Versions.Version_Io.To_String(Upgraded.Version), Node_Name.all);
					  
					  for File_Id in Specifications_Filenames_Search.File_Content'Range loop
					     Update(Handling.To_String(Results."-"(Specifications_Filenames_Search.File_Content(File_Id))), "Date", Formatting.Image(Clock));
					     Update(Handling.To_String(Results."-"(Specifications_Filenames_Search.File_Content(File_Id))), "Version", Versions.Version_Io.To_String(Upgraded.Version));
					  end loop;
					  
					  
				       end if;
				       
				       if Versions.New_Action then
					  Put_Line("Current version is : " & Versions.Version_Io.To_String(Upgraded.Version));
						   Upgraded.Version := 
						     Version_Update(Upgraded.Version);
						   Put_Line("version is updated :" & Versions.Version_Io.To_String(Upgraded.Version));
						   
					  --  if Environment.Version_Update /= 0 then
					  --     raise Program_Error;
					  --  end if;		  
					  Text_Io.Put_Line("-- Editting revision version...");
					  
					  Main_Description(Project_Context.Project.Project_Name.all, Project_Context.Project.Project_Prefix.all, "Date", Formatting.Image(Clock), Node_Name.all);
					  Main_Description(Project_Context.Project.Project_Name.all, Project_Context.Project.Project_Prefix.all, "Version", Versions.Version_Io.To_String(Upgraded.Version), Node_Name.all);
					  for File_Id in Implementations_Filenames_Search.File_Content'Range loop
					     Update(Handling.To_String(Results."-"(Implementations_Filenames_Search.File_Content(File_Id))), "Date", Formatting.Image(Clock));
					     Update(Handling.To_String(Results."-"(Implementations_Filenames_Search.File_Content(File_Id))), "Version", Versions.Version_Io.To_String(Upgraded.Version));
					  end loop;
					  
					  
				       end if;
				       
				       if Versions.New_Action or Versions.New_Description then
					  Put_Line("Current version is : " & Versions.Version_Io.To_String(Upgraded.Version));
						   Upgraded.Version := 
						     Version_Update(Upgraded.Version);
						   Put_Line("version is updated :" & Versions.Version_Io.To_String(Upgraded.Version));
						   
					  --  if Environment.Version_Update /= 0 then
					  --     raise Program_Error;
					  --  end if;		  
					  Text_Io.Put_Line("-- Editting major version...");
					  To_Major(Project_Context.Project.Project_Name.all, Project_Context.Project.Project_Prefix.all);
					  To_Minor(Project_Context.Project.Project_Name.all, Project_Context.Project.Project_Prefix.all);
					  To_Revision(Project_Context.Project.Project_Name.all, Project_Context.Project.Project_Prefix.all);
					  
				       else
					  Upgraded.Version := 
							   Version_Update(Upgraded.Version);
					  --  if Environment.Version_Update /= 0 then
					  --     raise Program_Error;
					  --  end if;		  
					  Text_Io.Put_Line("-- Editting release version...");
					  To_Release(Project_Context.Project.Project_Name.all,
						     Project_Context.Project.Project_Prefix.all);
				       end if;
				       Versions.New_Action := False;	       
				       Versions.New_Description := False;
				       
				    end;
				 else

				    Text_Io.Put_Line("Project name : " & Project_Context.Project.Project_Name.all); 
				    declare
				       
				       Node_Name : access String := new String ' ("");

				    begin
				       
				       
				       if Versions.New_Description then
					  Put_Line("Current version is : " & Versions.Version_Io.To_String(Upgraded.Version));
						   Upgraded.Version := 
						     Version_Update(Upgraded.Version);
						   Put_Line("version is updated :" & Versions.Version_Io.To_String(Upgraded.Version));
						   
					  --  if Environment.Version_Update /= 0 then
					  --  	raise Program_Error;
					  --  end if;		  
					  
					  
					  Main_Description(Project_Context.Project.Project_Name.all, "", "Date", Formatting.Image(Clock), Node_Name.all);
					  Main_Description(Project_Context.Project.Project_Name.all, "", "Version", Versions.Version_Io.To_String(Upgraded.Version), Node_Name.all);
					  
					  for File_Id in Specifications_Filenames_Search.File_Content'Range loop
					     Update(Handling.To_String(Results."-"(Specifications_Filenames_Search.File_Content(File_Id))), "Date", Formatting.Image(Clock));
					     Update(Handling.To_String(Results."-"(Specifications_Filenames_Search.File_Content(File_Id))), "Version", Versions.Version_Io.To_String(Upgraded.Version));
					  end loop;
					  
					  
				       end if;
				       
				       if Versions.New_Action then
					  Put_Line("Current version is : " & Versions.Version_Io.To_String(Upgraded.Version));
						   Upgraded.Version := 
						     Version_Update(Upgraded.Version);
						   Put_Line("version is updated :" & Versions.Version_Io.To_String(Upgraded.Version));
						   
					  --  if Environment.Version_Update /= 0 then
					  --  	raise Program_Error;
					  --  end if;		  		  
					  Main_Description(Project_Context.Project.Project_Name.all, "", "Date", Formatting.Image(Clock), Node_Name.all);
					  Main_Description(Project_Context.Project.Project_Name.all, "", "Version", Versions.Version_Io.To_String(Upgraded.Version), Node_Name.all);
					  for File_Id in Implementations_Filenames_Search.File_Content'Range loop
					     Update(Handling.To_String(Results."-"(Implementations_Filenames_Search.File_Content(File_Id))), "Date", Formatting.Image(Clock));
					     Update(Handling.To_String(Results."-"(Implementations_Filenames_Search.File_Content(File_Id))), "Version", Versions.Version_Io.To_String(Upgraded.Version));
					  end loop;
					  
					  
				       end if;
				       
				       if Versions.New_Action or Versions.New_Description then
					  Text_Io.Put_Line("-- Editting revision version...");
					  To_Revision(Project_Context.Project.Project_Name.all, "");
					  Text_Io.Put_Line("-- Editting minor version...");
					  To_Minor(Project_Context.Project.Project_Name.all, "");
					  Text_Io.Put_Line("-- Editting major version...");
					  To_Major(Project_Context.Project.Project_Name.all, "");
				       else
					  if Environment.Version_Update /= 0 then
					     raise Program_Error;
					  end if;		  
					  Text_Io.Put_Line("-- Editting release version...");
					  To_Release(Project_Context.Project.Project_Name.all,
						     "");
				       end if;
				       Versions.New_Action := False;	       
				       Versions.New_Description := False;
				       
				    end;
				    
				 end if;
				 
				 --
				 --
				 --
				 --
				 --
				 --
				 --
				 -----------------------------------------------------------------------------------------------------------
				 
				 
				 
				 
				 if Upgraded /= null then
				    
				    This.Projects.Projects_Num := This.Projects.Projects_Num + 1;
				    Upgraded.Project_Num := This.Projects.Projects_Num;
				    Curs := Last(This.Projects.List);
				    Projects_DLL.Delete(This.Projects.List, Curs);
				    --  if Upgraded.Version.Revision_Version + 1 < Computer.Versions.Revision_Version_Type'Last then
				    --     Upgraded.Version.Revision_Version := 
				    --  	 Upgraded.Version.Revision_Version + 1;
				    --  end if;
				    
				    Append(This.Projects.List, Upgraded);
				    Projects_Manager.Manager_Save(This.Projects, "./Projects.lst");
				    
				    if Update(Get_Info(This.Projects, Project_Manager.New_Project.Project_Num), Upgraded.Version) = 0 then
				    
				       Clear(This.Projects.List);
				       Projects_Manager.Manager_Load(This.Projects, "./Projects.lst");
				       
				    end if;
				    
				    This.Projects.Projects_Num := This.Projects.Projects_Num + 1;
				    Append(This.Projects.List, 
					   new Project_Record ' (Null_Project));
				    
				    Projects_Manager.Manager_Save(This.Projects, "./Projects.lst");
				 end if;
				 Project.Close(Project_Manager.New_Project.all, Clock);
				 Project_Count := 0;
				 Project_Index := 0;
				 Curs := First(This.Projects.List);			   
				 Project_Num := First_Element(This.Projects.List).Project_Num;
				 Project_Manager.New_Project := Get_Project(This.Projects, Project_Num);
				 Step_Cur := Prj_Selector;
			      when Wide_Character'Val(127) =>
				 if Cmd_Last > 0 then
				    Cmd_Line(Cmd_Last) :=  Wide_Character'Val(32);
				    Cmd_Last := Cmd_Last - 1;
				 else
				    Step_Cur := Prj_Selector;
				 end if;
			      when others =>
				 null;
			   end case;
			elsif Cmd_Last < Cmd_Line'Length then
			   Cmd_Line(Cmd_Last + 1) := Wchar;
			   Cmd_Last := Cmd_Last + 1;
			else
			   Put(Character'Val(7));
			end if;
			
		     end Receive;
		     case Step_Cur is
			when Prj_None =>
			   null;
			when Prj_Selector =>
			   Draw_Window(Project_Header);
			   if Project_Manager.New_Project /= null then
			      Draw_Header(Project_Manager.New_Project.all, Project_Header);
			   end if;
			   Draw_Window(Project_Selector);
			   Projects_Print(This.Projects, Project_Index, Project_Num, This.Lines, This.Columns);
			   
			when Prj_Manager =>

			   Draw_Window(Manager_Abs);
			   Draw_Text(Manager_Abs, 1, 1, White, "Abstract  : ");
			   Draw_Window(Manager_N);
			   Draw_Text(Manager_N, 1, 1, White, "Name      : " & Handling.To_Wide_String(Project_Manager.New_Project.Project_Name.all));
			   Draw_Window(Manager_Ver);
			   Draw_Text(Manager_Ver, 1, 1, White, "Version   : " & Handling.To_Wide_String(Version_Io.To_String(Project_Manager.New_Project.Version)));
			   Draw_Window(Manager_Auth);
			   Draw_Text(Manager_Auth, 1, 1, White, "Author    : " & Handling.To_Wide_String(Project_Manager.New_Project.Copyright.all));

			   Draw_Window(Manager_List);

			   List_Print(Project_Manager.New_Project.all, Manager_List, Lib_Index);

			   Draw_Window(Manager_cmd);
			   Draw_Text(Manager_cmd, 1, 1, White, "Command   : ");

			   --  Page_Print(Project_Manager.Curs);

			   Draw_Text(
			   	     Project_Manager.Curs.Parts(Project_Manager.Curs.Part_Cur).Win,
			   	     Project_Manager.Curs.Parts(Project_Manager.Curs.Part_Cur).Line_Pos,
			   	     Project_Manager.Curs.Parts(Project_Manager.Curs.Part_Cur).Column_Pos,
			   	     White,
			   	     Project_Manager.Curs.Parts
			   	       (Project_Manager.Curs.Part_Cur).Line(1..Project_Manager.Curs.Parts(Project_Manager.Curs.Part_Cur).Last)
			   	    );

			   if Line_Remove then
			      if Lib_Name_Last > 0 then
				 Draw_Text(Manager_cmd, 1, 1, White, "Line num : " & Lib_Name(1..Lib_Name_last));
			      else
				 Draw_Text(Manager_cmd, 1, 1, White, "Line num : ");
			      end if;
			   elsif Cmd_Last > 0 then
			      Draw_Window(Manager_cmd);
			      Draw_Text(Manager_cmd, 1, 1, White, "Command   : " & Cmd_Line(Cmd_Line'First..Cmd_Last));
			   else
			      Draw_Window(Manager_cmd);
			      Draw_Text(Manager_cmd, 1, 1, White, "Command   : ");
			   end if;

			when Prj_Upgrade =>
			   Draw_Window(Components_Win);
			   Components_Print(Project_Manager.New_Project.all, Component_Index , Component_cur, (This.Lines-8)/2-2, This.Columns);

			   Draw_Window(Make_Win);
			   if not Print_Set(File_Set, Make_Win, File_Index, Total_lines) then
			      raise Program_Error;
			   end if;
			   if Cmd_Last > 0 then
			      Draw_Window(Manager_cmd);
			      Draw_Text(Manager_cmd, 1, 1, White, "Command   : " & Cmd_Line(Cmd_Line'First..Cmd_Last));
			   else
			      Draw_Window(Manager_cmd);
			      Draw_Text(Manager_cmd, 1, 1, White, "Command   : ");
			   end if;
			when others =>
			   null;
		     end case;
	       or

		  accept Refresh do
		     null;
		  end Refresh;
		  
	       or
		  accept Page_Down do
		     case Step_Cur is
			when Prj_Selector =>
			   null;
			when Prj_Creator =>
			   if Lib_Index + (Creator_List.Win.H-2) < Creator.New_Project.Lib_Last then
			      Lib_Index := Lib_Index + (Creator_List.Win.H-2);
			      Draw_Window(Creator_List);
				 
			      List_Print(Creator.New_Project.all, Creator_List, Lib_Index);
			   else
			      Put(character'Val(0));
			   end if;
			when Prj_Manager =>
			   if Lib_Index + (Manager_List.Win.H-2) < Project_Manager.New_Project.Lib_Last then
			      Lib_Index := Lib_Index + (Manager_List.Win.H-2);
			      Draw_Window(Manager_List);
				 
			      List_Print(Project_Manager.New_Project.all, Manager_List, Lib_Index);
			   else
			      Put(character'Val(0));
			   end if;
			when Prj_Upgrade =>
			   if File_Index < Integer'Min(File_Index + (This.Lines-8)/2-2, Line_Last) then
			      File_Index := Integer'Min(File_Index + (This.Lines-8)/2-2, Line_Last);
			   end if;
			   Draw_Window(Make_Win);
			   if not Print_Set(File_Set, Make_Win, File_Index, Total_lines) then
			      raise Program_Error;
			   end if;
			when others =>
			   null;
		     end case;
		  end Page_Down;
	       or
		  accept Page_Up do
		     case Step_Cur is
			when Prj_Selector =>
			   null;
			when Prj_Creator =>
			   if Lib_Index - (Creator_List.Win.H-2) >= 0 then
			     
			     Lib_Index := Lib_Index - (Creator_List.Win.H-2);
			     Draw_Window(Creator_List);
				 
			     List_Print(Creator.New_Project.all, Creator_List, Lib_Index);
			   elsif Lib_Index /= 0 then
			      Lib_Index := 0;
			      Draw_Window(Creator_List);
				 
			      List_Print(Creator.New_Project.all, Creator_List, Lib_Index);
			   else
			      Put(character'Val(0));
			   end if;
			when Prj_Manager =>
			   if Lib_Index - (Creator_List.Win.H-2) >= 0 then
			     
			     Lib_Index := Lib_Index - (Manager_List.Win.H-2);
			     Draw_Window(Creator_List);
				 
			     List_Print(Project_Manager.New_Project.all, Manager_List, Lib_Index);
			   elsif Lib_Index /= 0 then
			      Lib_Index := 0;
			      Draw_Window(Manager_List);
				 
			      List_Print(Project_manager.New_Project.all, Manager_List, Lib_Index);
			   else
			      Put(character'Val(0));
			   end if;
			when Prj_Upgrade =>
			   if File_Index - (This.Lines-8)/2-2 >= 0 then 
			      File_Index := File_Index - (This.Lines-8)/2-2;
			   else
			      File_Index := 0;
			   end if;
			   Draw_Window(Make_Win);
			   if not Print_Set(File_Set, Make_Win, File_Index, Total_lines) then
			      raise Program_Error;
			   end if;
			when others =>
			   null;
		     end case;
		  end Page_Up;
	       or
		  accept Up_Arrow do
		     case Step_Cur is
			when Prj_Archives =>
			   if Arch_Curs /= First(This.Archives.List) then
			      Previous(Arch_Curs);
			      if Arch_Count > 0 then
				 Arch_Count := Arch_Count - 1;
			      elsif Arch_Index > 0 then
				 Arch_Index := Arch_Index - 1;
			      end if;
			      
			   end if;
			   
			   Arch_Num := Projects_dll.Element(Arch_Curs).Project_Num;
			   
			   Draw_Window(Project_Selector);
			   Archives_Print(This.Archives, Arch_Index, Arch_Num, This.Lines, This.Columns);
			   
			when Prj_Selector =>
			   if Curs /= First(This.Projects.List) then
			      
			      Previous(Curs);
			      if Project_Count > 0 then
				 Project_Count := Project_Count - 1;
			      elsif Project_Index > 0 then
				 Project_Index := Project_Index - 1;
			      end if;
				 
			      declare
				 Current : constant Project.Project_Access := Element(Curs);
			      begin	
				 if Current /= null then
				    
				    Project_Num := Current.Project_Num;
				    
				 end if;
			      end;
			      
			      
			   
			   end if;
			   Project_Manager.New_Project := Get_Project(This.Projects, Project_Num);
			   Draw_Window(Project_Header);
			   if Project_Manager.New_Project /= null then
			      Draw_Header(Project_Manager.New_Project.all, Project_Header);
			   else
			      Draw_Header(Null_Project, Project_Header);
			   end if;
			   
			   Draw_Window(Project_Selector);
			   Projects_Print(This.Projects, Project_Index, Project_Num, This.Lines, This.Columns);
			when Prj_Creator =>
			   null;
			when Prj_Manager =>
			   null;
			when Prj_Upgrade =>
			   if Project_Manager.New_Project /= null and then
			     Component_Cur - 1 >= 0 then
			      Component_Cur := Component_Cur - 1;
			      
			      Component_Index := Integer'Max(0, Component_Cur - ((This.Lines-8)/2-2)/3);
			      
			      Draw_Window(Components_Win);
			      Components_Print(Project_Manager.New_Project.all, Component_Index , Component_cur, (This.Lines-8)/2-2, This.Columns);
			      
			      --  Draw_Window(Make_Win);
			      --  if not Print_Set(File_Set, Make_Win, File_Index, Total_lines) then
			      --  	 raise Program_Error;
			      --  end if;
			      if Cmd_Last > 0 then
				 Draw_Window(Manager_cmd);
				 Draw_Text(Manager_cmd, 1, 1, White, "Command   : " & Cmd_Line(Cmd_Line'First..Cmd_Last));
			      else
				 Draw_Window(Manager_cmd);
				 Draw_Text(Manager_cmd, 1, 1, White, "Command   : ");
			      end if;
			   else
			      Put(Character'Val(7));
			   end if;
			when others =>
			   null;
		     end case;
			      
		  end up_arrow;
	       or
		  accept Down_Arrow do
		     
		     case Step_Cur is
			when Prj_Archives =>
			   if Arch_Curs /= Last(This.Archives.List) then
			      
			      Arch_Curs := Next(Arch_Curs);
			      
			      if Arch_Count < (This.Lines-7)/5-1 then
				 
				 Arch_Count := Arch_Count + 1;
			      elsif Arch_Index < Natural(Projects_Dll.Length(This.Archives.List)) then
				 
				 Arch_Index := Arch_Index + 1;
			      end if;

			      Arch_Num := Projects_dll.Element(Arch_Curs).Project_Num;

			   
			   end if;
			   
			   
			   Draw_Window(Project_Selector);
			   
			   Archives_Print(This.Archives, Arch_Index, Arch_Num, This.Lines, This.Columns);
			when Prj_Selector =>			   
			   
			   if Curs /= Last(This.Projects.List) then
			      
			      Curs := Next(Curs);
			      
			      if Project_Count < (This.Lines-7)/5-1 then
				 Project_Count := Project_Count + 1;
			      elsif Project_Index < Natural(Projects_Dll.Length(This.Projects.List)) then
				 Project_Index := Project_Index + 1;
			      end if;
			      
			      
			      
			      declare
				 Current : constant Project.Project_Access := Element(Curs);
			      begin	
				 
				 Project_Num := Current.Project_Num;
				 
			      end;
			      
			      
			   end if;
			   Project_Manager.New_Project := Get_Project(This.Projects, Project_Num);
			   Draw_Window(Project_Header);
			   if Project_Manager.New_Project /= null then
			      Draw_Header(Project_Manager.New_Project.all, Project_Header);
			   else
			      Draw_Header(Null_Project, Project_Header);
			   end if;
			   
			   Draw_Window(Project_Selector);
			   Projects_Print(This.Projects, Project_Index, Project_Num, This.Lines, This.Columns);
		     
			when Prj_Creator =>
			   null;
			when Prj_Manager =>
			   null;
			when Prj_Upgrade =>
			   if Project_Manager.New_Project /= null and then
			     Component_Cur + 1 <= Project_Manager.New_Project.Lib_Last then
			      Component_Cur := Component_Cur + 1;
			      
			      Component_Index := Integer'Max(0, Component_Cur - ((This.Lines-8)/2-2)/3);
			      
			      Draw_Window(Components_Win);
			      Components_Print(Project_Manager.New_Project.all, Component_Index , Component_cur, (This.Lines-8)/2-2, This.Columns);
			      
			      --  Draw_Window(Make_Win);
			      --  if not Print_Set(File_Set, Make_Win, File_Index, Total_lines) then
			      --  	 raise Program_Error;
			      --  end if;
			      if Cmd_Last > 0 then
				 Draw_Window(Manager_cmd);
				 Draw_Text(Manager_cmd, 1, 1, White, "Command   : " & Cmd_Line(Cmd_Line'First..Cmd_Last));
			      else
				 Draw_Window(Manager_cmd);
				 Draw_Text(Manager_cmd, 1, 1, White, "Command   : ");
			      end if;
			   end if;
			when others =>
			   null;
		     end case;
		  end Down_Arrow;
	       or
		  accept Left_Arrow;
	       or
		  accept Right_Arrow;
	       or
		  accept Full_Screen;
	       or
		  accept Del;
	       or
		  accept Begin_Of do
		     case Step_Cur is
			when Prj_Selector =>
			   Curs := First(This.Projects.List);
			   Project_Num := Element(Curs).Project_Num;
			   Project_Manager.New_Project := Get_Project(This.Projects, Project_Num);
			   Draw_Window(Project_Header);
			   if Project_Manager.New_Project /= null then
			      Draw_Header(Project_Manager.New_Project.all, Project_Header);
			   else
			      Draw_Header(Null_Project, Project_Header);
			   end if;
			   Project_Count := 0;
			   Project_Index := 0;
			   Draw_Window(Project_Selector);
			   Projects_Print(This.Projects, Project_Index, Project_Num, This.Lines, This.Columns);
			when Prj_Archives =>
			   Arch_Curs := First(This.Archives.List);
			   Arch_Num := Element(Arch_Curs).Project_Num;
			   Draw_Window(Project_Selector);
			   Archives_Print(This.Archives, Arch_Index, Arch_Num, This.Lines, This.Columns);
			   Arch_Count := 0;
			   Arch_Index := 0;
			when Prj_Components =>
			   null;
			when others =>
			   null;
		     end case;
		  end Begin_Of;
	       or
		  accept End_Of do
		     case Step_Cur is
			when Prj_Selector =>
			   Curs := Last(This.Projects.List);
			   Project_Num := Element(Curs).Project_Num;
			   Project_Manager.New_Project := Get_Project(This.Projects, Project_Num);
			   Draw_Window(Project_Header);
			   if Project_Manager.New_Project /= null then
			      Draw_Header(Project_Manager.New_Project.all, Project_Header);
			   else
			      Draw_Header(Null_Project, Project_Header);
			   end if;
			   Project_Count := Integer(Length(This.Projects.List) - 1);
			   Project_Index := Integer'max(0, Integer(Length(This.Projects.List)) - ((This.Lines-7)/5)-1);
			   Draw_Window(Project_Selector);
			   Projects_Print(This.Projects, Project_Index, Project_Num, This.Lines, This.Columns);
			when Prj_Archives =>
			   Arch_Curs := Last(This.Archives.List);
			   Arch_Num := Element(Arch_Curs).Project_Num;
			   Draw_Window(Project_Selector);
			   Archives_Print(This.Archives, Arch_Index, Arch_Num, This.Lines, This.Columns);
			   Arch_Count := Integer(Length(This.Archives.List) - 1);
			   Arch_Index := Integer'max(0, Integer(Length(This.Archives.List)) - ((This.Lines-7)/5)-1);
			when Prj_Components =>
			   null;
			when others =>
			   null;
		     end case;
		  end End_Of;
	       or
		  accept Overwrite;
	       or
		  accept Screen_Print;

	       end select;
	    end loop;
	    
	 end loop Main_Loop;
      end;
   end Manager_Process;
   
   
   -------------------------------------------------------------------------------------------------------------
   --                                                                                                         --
   --
   -------------------------------------------------------------------------------------------------------------
   

   -------------------------------------------------------------------------------------------------------------
   --                                                                                                         --
   --
   -------------------------------------------------------------------------------------------------------------
   
   
   
   
   procedure Accounting_Wins_Draw(Wins : Accounting_Windows_Type) is
      
   begin
      Draw_Window(Wins.Voice_Num_Win);
      Draw_Window(Wins.Acc_Num_Win);
      Draw_Window(Wins.Total_Ht_Win);
      Draw_Window(Wins.Total_TVA_Win);
      Draw_Window(Wins.Total_Ttc_Win);
      Draw_Window(Wins.Date_Win);
      Draw_Window(Wins.Peer_Win);
   end Accounting_Wins_Draw;      
   
   
   procedure Accounting_Line_Draw(Wins : Accounting_Windows_Type; Line : in Line_Range; Voice : in Abstracted_Voice) is
      
   begin
      Draw_Text(Wins.Voice_Num_Win, Line, 1, White, Handling.To_Wide_String(Voice_Num_Range'Image(Voice.Voice_Num)));
      Draw_Text(Wins.Acc_Num_Win, Line, 1, White, Handling.To_Wide_String(Account_Num_Range'Image(Voice.Account_Num)));
      Draw_Text(Wins.Total_Ht_Win, Line, 1, White, Handling.To_Wide_String(Fixed_Total'Image(Voice.Total_Ht)));
      Draw_Text(Wins.Total_TVA_Win, Line, 1, White, Handling.To_Wide_String(Fixed_Total'Image(Voice.Total_TVA)));
      Draw_Text(Wins.Total_Ttc_Win, Line, 1, White, Handling.To_Wide_String(Fixed_Total'Image(Voice.Total_TTC)));
      Draw_Text(Wins.Date_Win, Line, 1, White, Handling.To_Wide_String(Formatting.Image(Voice.Date)));
      Draw_Text(Wins.Peer_Win, Line, 1, White, Voice.Peer_Name(1..16));
   end Accounting_Line_Draw;      
   
   
   subtype Voice_Index_Range is Positive range 1..Positive'Last;
   type Voice_Access is access all Abstracted_Voice;
   function Same(Left, Right : in Voice_Access) return Boolean is
   begin
      return Left.all = Right.all;
   end Same;
   
   package Voice_Vectors is new Ada.Containers.Vectors (Voice_Index_Range, Voice_Access, Same);
   
   function "<"(Left, Right : in Voice_Access) return Boolean is
   begin
      return Left.Date < Right.Date;
   end "<";
   
   package Sorting is new Voice_Vectors.Generic_Sorting("<");
   
   use Voice_Vectors;
   
   type State_Type is
      record
	 Date         : Time := Time_Of(1970, 1, 1, 0.0);
	 Deal_In_HT   : Fixed_Total := 0.0;
	 Deal_In_Ttc  : Fixed_Total := 0.0;
	 Tva_Out      : Fixed_Total := 0.0;
	 Deal_Out_HT  : Fixed_Total := 0.0;
	 Deal_Out_Ttc : Fixed_Total := 0.0;
	 Tva_in       : Fixed_Total := 0.0;
	 Result       : Fixed_Total := 0.0;
      end record;
   
   
   procedure Make_State (Voices : in Voice_Vectors.Vector; From : in Time; To : in Time; State : out State_Type) is
      
   begin
      
      
      
      
      
      if not Is_Empty(Voices) then
	 for Iter in 1..Length(Voices) loop
	    declare
	       Voice : Voice_Access := Voice_Vectors.Element(Voices, Integer(Iter));
	    begin	       
	       case Voice.Account_Num is
		  when 607 =>
		     State.Deal_In_Ht := State.Deal_In_Ht + Voice.Total_Ht;
		     State.Deal_In_TTC := State.Deal_In_TTC + Voice.Total_TTC;
		     State.Tva_Out := State.Tva_Out + Voice.Total_Tva;
		  when 707 =>
		     State.Deal_Out_Ht := State.Deal_Out_Ht + Voice.Total_Ht;
		     State.Deal_Out_TTC := State.Deal_Out_TTC + Voice.Total_TTC;
		     State.Tva_In := State.Tva_In + Voice.Total_Tva;
		  when 10 =>
		     State.Result := State.Result + Voice.Total_Ht;
		  when others =>
		     null;
	       end case;
	       exit when Voice.Date > To;
	    end;	    
	 end loop;
	 State.Result := State.Result - State.Deal_In_Ttc;
	 State.Result := State.Result + State.Deal_Out_Ttc;
	 State.Result := State.Result - State.Tva_In;
	 State.Result := State.Result + State.Tva_Out;
      end if;
   end Make_State;
   
	 
   
   task body Activity_Process is
      Activity_From    : Window_Record := (3, 1, 10, This.Columns/4, Blue,  Window);
      Activity_To      : Window_Record := (3, (This.Columns/4)+1, 10, This.Columns/4, Blue, Window);
      Activity_Compta  : Window_Record := (13, This.Columns/2+1, (This.Lines-20), This.Columns/2, Cyan, Window);
      Activity_Balance : Window_Record := (This.Lines-5, This.Columns/2+1, 3, This.Columns/2,  Yellow, Window);
      Activity_Cmd     : Window_Record := (This.Lines-2, 1, 3, This.Columns/2, White, Window);
      
      
      
      
      procedure State_Print(Date : in Time; Line_Max : in Line_Range) is
	 
	 
	 
	 
	 
	 
	 State : Voice_Vectors.Vector;
	 
	 Page : Voice_Vectors.Vector;
	 
	 From : State_Type;
	 To   : State_Type;
	 
	 From_Line : Abstracted_Voice(256);
	 To_Line   : Abstracted_Voice(256);
	 
	 
      begin
	 
	 for Invoice in 1..Accounts.Invoice_Last loop
	    Append(State, new Abstracted_Voice ' (abstracted_voice(Accounts.Billed(Invoice))));
	 end loop;
	 for outvoice in 1..Accounts.Outvoice_Last loop
	    Append(State, new Abstracted_Voice ' (abstracted_voice(Accounts.Charges(outvoice))));
	 end loop;
	 Sorting.Sort(State);
	 
	 if not Is_Empty(State) then
	    for Iter in 1..Length(State) loop
	       declare
		  Voice : Abstracted_Voice := Element(State, Voice_Index_Range(Iter)).all;
	       begin
		  if Voice.Date >= Date then
		     Append(Page, new Abstracted_Voice ' (abstracted_voice(Voice)));
		  end if;
		  exit when Length(Page) = Count_Type(Line_Max);
	       end;
	    end loop;
	 end if;
	 
	 
	 
	 Make_State(State, Time_Of(1970, 1, 1, 0.0), Date, From);
	 
	 if not Is_Empty(Page) then
	 
	    From_Line := First_Element(Page).all;
	    From.Date := From_Line.date;
	 end if;
	 
	 Draw_Window(Activity_From);
	 
	 
	 
	 Draw_Text(Activity_From, 1, 1, White, "From         : " & Handling.To_Wide_String(Formatting.Image(From.Date)));
	 Draw_Text(Activity_From, 2, 1, White, "Deal  in HT  : " & Handling.To_Wide_String(Fixed_Total'Image(From.Deal_In_Ht)));
	 Draw_Text(Activity_From, 3, 1, White, "Deal  in TTC : " & Handling.To_Wide_String(Fixed_Total'Image(From.Deal_In_TTC)));
	 Draw_Text(Activity_From, 4, 1, White, "TVA  out     : " & Handling.To_Wide_String(Fixed_Total'Image(From.TVA_Out)));
	 Draw_Text(Activity_From, 5, 1, White, "Deal out HT  : " & Handling.To_Wide_String(Fixed_Total'Image(From.Deal_Out_Ht)));
	 Draw_Text(Activity_From, 6, 1, White, "Deal out TTC : " & Handling.To_Wide_String(Fixed_Total'Image(From.Deal_Out_Ht)));
	 Draw_Text(Activity_From, 7, 1, White, "TVA   in     : " & Handling.To_Wide_String(Fixed_Total'Image(From.TVA_In)));
	 Draw_Text(Activity_From, 8, 1, White, "Result       : " & Handling.To_Wide_String(Fixed_Total'Image(From.Result)));
	 
	 if not Is_Empty(Page) then
	    Make_State(State, Time_Of(1970, 1, 1, 0.0), Last_Element(Page).Date, To);
	 end if;
	 
	 if not Is_Empty(Page) then
	    To_Line := Last_Element(Page).all;
	    To.Date := To_Line.date;
	 end if;
	 
	 Draw_Window(Activity_To);
	 
	 Draw_Text(Activity_To, 1, 1, White, "To           : " & Handling.To_Wide_String(Formatting.Image(To.Date)));
	 Draw_Text(Activity_To, 2, 1, White, "Deal  in HT  : " & Handling.To_Wide_String(Fixed_Total'Image(To.Deal_In_Ht)));
	 Draw_Text(Activity_To, 3, 1, White, "Deal  in TTC : " & Handling.To_Wide_String(Fixed_Total'Image(To.Deal_In_TTC)));
	 Draw_Text(Activity_To, 4, 1, White, "TVA  out     : " & Handling.To_Wide_String(Fixed_Total'Image(To.TVA_Out)));
	 Draw_Text(Activity_To, 5, 1, White, "Deal out HT  : " & Handling.To_Wide_String(Fixed_Total'Image(To.Deal_Out_Ht)));
	 Draw_Text(Activity_To, 6, 1, White, "Deal out TTC : " & Handling.To_Wide_String(Fixed_Total'Image(To.Deal_Out_Ht)));
	 Draw_Text(Activity_To, 7, 1, White, "TVA   in     : " & Handling.To_Wide_String(Fixed_Total'Image(To.TVA_In)));
	 Draw_Text(Activity_To, 8, 1, White, "Result       : " & Handling.To_Wide_String(Fixed_Total'Image(To.Result)));
	 
	 Draw_Window(Activity_Compta);
	 
	 Draw_Text(Activity_Compta, 1, 1, White, "Voice Num, Acc N , Total HT      , Total TVA    , Total TTC     , date              , Peer Name");

	 Accounting_Wins_Draw(This.Activity_Wins);
	 
	 
	 if not Is_Empty(Page) then
	    for Iter in 1..Length(Page) loop
	       declare
		  Voice : Abstracted_Voice := Element(Page, Voice_Index_Range(Iter)).all;
	       begin
		  Accounting_Line_Draw(This.Activity_Wins, Line_Range(Iter), Voice);
	       end;
	    end loop;
	 end if;
	 
      end State_Print;
      
      
      
      
      
      
      
      
      
      
      
      
      
      
   begin
      
      -- Print right side of screen
      --  Initialize(Activity_From  ,4, This.Columns/2+1, (This.Lines-2)/4, (This.Columns-1)/4, Blue,  White);
      --  Initialize(Activity_To    ,4, This.Columns/4*3+1, (This.Lines-2)/4, (This.Columns-2)/4, Blue, White);
      --  Initialize(Activity_Compta,(This.Lines-3)/8*2+3+3, This.Columns/2+1, (This.Lines-4)/16*13, (This.Columns-2)/2, Blue, White);
      --  Initialize(Activity_Bilan ,(This.Lines-3)/8*7+3+2, This.Columns/2+1, (This.Lines-4)/16*2, (This.Columns-2)/2,  Blue, White);
      
      
      -- Print left side of screen.
      Initialize(Activity_From  , 3, 1, 10, (This.Columns)/4, Blue,  White);
      Initialize(Activity_To    , 3, This.Columns/4+1, 10, This.Columns/4, Blue, White);
      Initialize(Activity_Compta, 13, 1, (This.Lines-20), This.Columns/2, Cyan, White);
      Initialize(Activity_Balance ,This.Lines-5, 1, 3, This.Columns/2,  Yellow, White);
      Initialize(Activity_Cmd, This.Lines-2, 1, 3, This.Columns/2, White, White);
      
      
      
      Initialize(This.Activity_Wins, This.Lines-23, This.Columns/2, 13, 2);
      
      
      declare
	 
	 
	 Date : Time := Clock;
	 
	 Line : Wide_String(1..This.Columns/2-2);
	 Line_Last : Natural := 0;
	 
	 
      begin
     Main_Loop:
	 loop
	    	    loop
	       select
		  
		  accept Halt do
		     null;
		  end Halt;
		  exit Main_Loop;
	       or
		  accept Suspend;
	       or
		  accept Wake_Up Do
		     Errno := System("clear" & Character'Val(0));
		     
		     State_Print(Date-86400.0, This.Lines-25);
		     
		     Draw_Window(Activity_Balance);
		     Draw_Text(Activity_Balance, 1, 1, White, 
			       
			       " Capital : " & Handling.To_Wide_String(Fixed_Total'Image(Computer.Balance.Balance.Capital)) &
				 ", Material :" & Handling.To_Wide_String(Fixed_Total'Image(Computer.Balance.Balance.Material)) &
				 ", TVA In :" & Handling.To_Wide_String(Fixed_Total'Image(Computer.Balance.Balance.TVA_In)) &
				 ", TVA Out :" & Handling.To_Wide_String(Fixed_Total'Image(Computer.Balance.Balance.TVA_Out)) & ""
			      );
		     Draw_Window(Activity_Cmd);
		     if Line_Last > 0 then
			Draw_text(Activity_Cmd, 1, 1, White, "Date : " & Line(Line'First..Line_Last));
		     else
			Draw_text(Activity_Cmd, 1, 1, White, "Date : ");
		     end if;
		     
		     
		  end Wake_Up;
		  exit;
	       end select;
	    end loop;

	    loop
	       
	       select
		  accept Halt;
		  exit Main_Loop;
	       or
		  accept Suspend;
		  exit;
	       or
		  accept Wake_Up;
	       or
		  
		  accept Receive(Wchar : in Wide_Character) do
		     if Is_Control(Wchar) then
			case Wchar is
			   when Wide_Character ' Val (10) =>
			      begin
				 Date := Formatting.Value(Handling.To_String(Line(1..Line_Last)));
				 Line := (others => Wide_Character'Val(0));
				 Line_Last := 0;
			      exception
				 when Constraint_Error =>
				    null;
			      end;
			   when Wide_Character'Val (20) =>
			      Accountant.Close(Computer.Balance.Balance,
					       Accountant.Accounts);
			   when Wide_Character'Val(127) =>
			      if Line_Last > 0 then
				 Line(Line_Last) := Wide_Character'Val(32);
				 Line_Last := Line_Last - 1;
			      end if;
			   when others =>
			      null;
			end case;
			Errno := System("clear" & Character'Val(0));
		     
			State_Print(Date-86400.0, This.Lines-25);
		     
			Draw_Window(Activity_Balance);
			Draw_Text(Activity_Balance, 1, 1, White, 
				  
				  " Capital : " & Handling.To_Wide_String(Fixed_Total'Image(Computer.Balance.Balance.Capital)) &
				    ", Material :" & Handling.To_Wide_String(Fixed_Total'Image(Computer.Balance.Balance.Material)) &
				 ", TVA In :" & Handling.To_Wide_String(Fixed_Total'Image(Computer.Balance.Balance.TVA_In)) &
				    ", TVA Out :" & Handling.To_Wide_String(Fixed_Total'Image(Computer.Balance.Balance.TVA_Out)) & ""
				 );
			Draw_Window(Activity_Cmd);
			if Line_Last > 0 then
			   Draw_text(Activity_Cmd, 1, 1, White, "Date : " & Line(Line'First..Line_Last));
			else
			   Draw_text(Activity_Cmd, 1, 1, White, "Date : ");
			end if;
		     elsif Line_Last < This.Columns/2-2 then
			Line(Line_Last + 1) := Wchar;
			Line_Last := Line_Last + 1;
			Draw_Window(Activity_Cmd);
			if Line_Last > 0 then
			   Draw_text(Activity_Cmd, 1, 1, White, "Date : " & Line(Line'First..Line_Last));
			else
			   Draw_text(Activity_Cmd, 1, 1, White, "Date : ");
			end if;
		     else
			Put(Character'Val(7));
		     end if;
		  end Receive;
	       or

		  accept Refresh;
		  
	       or
		  accept Page_Down;
	       or
		  accept Page_Up;
	       or
		  accept Up_Arrow do
		     null;
		  end up_arrow;
	       or
		  accept Down_Arrow do
		     null;
		  end Down_Arrow;
	       or
		  accept Left_Arrow;
	       or
		  accept Right_Arrow;
	       or
		  accept Full_Screen;
	       or
		  accept Del;
	       or
		  accept Begin_Of;
	       or
		  accept End_Of;
	       or
		  accept Overwrite;
	       or
		  accept Screen_Print;

	       end select;
	    end loop;
	    
	 end loop Main_Loop;
      end;
   end Activity_Process;
   
   
   -------------------------------------------------------------------------------------------------------------
   --                                                                                                         --
   --
   -------------------------------------------------------------------------------------------------------------
   
   -------------------------------------------------------------------------------------------------------------
   --                                                                                                         --
   --
   -------------------------------------------------------------------------------------------------------------
   task body Contacts_Process is
   begin

      declare
	 
      begin
     Main_Loop:
	 loop
	    loop
	       select
		  accept Halt;
		  exit Main_Loop;
	       or
		  accept Suspend;
		  exit;
	       or
		  accept Wake_Up;
	       or
		  
		  accept Receive(Wchar : in Wide_Character);
	       or

		  accept Refresh;
		  
	       or
		  accept Page_Down;
	       or
		  accept Page_Up;
	       or
		  accept Up_Arrow do
		     null;
		  end up_arrow;
	       or
		  accept Down_Arrow do
		     null;
		  end Down_Arrow;
	       or
		  accept Left_Arrow;
	       or
		  accept Right_Arrow;
	       or
		  accept Full_Screen;
	       or
		  accept Del;
	       or
		  accept Begin_Of;
	       or
		  accept End_Of;
	       or
		  accept Overwrite;
	       or
		  accept Screen_Print;

	       end select;
	    end loop;
	    
	    loop
	       select
		  
		  accept Halt do
		     null;
		  end Halt;
		  exit Main_Loop;
	       or
		  accept Suspend;
	       or
		  accept Wake_Up Do
		     Errno := System("clear" & Character'Val(0));
		     null;
		  end Wake_Up;
		  exit;
	       end select;
	    end loop;
	 end loop Main_Loop;
      end;
   end Contacts_Process;
   
   
   -------------------------------------------------------------------------------------------------------------
   --                                                                                                         --
   --
   -------------------------------------------------------------------------------------------------------------
   
   -------------------------------------------------------------------------------------------------------------
   --                                                                                                         --
   --
   -------------------------------------------------------------------------------------------------------------
   task body Planning_Process is
   begin

      declare
	 
      begin
     Main_Loop:
	 loop
	    loop
	       select
		  accept Halt;
		  exit Main_Loop;
	       or
		  accept Suspend;
		  exit;
	       or
		  accept Wake_Up;
	       or
		  
		  accept Receive(Wchar : in Wide_Character);
	       or

		  accept Refresh;
		  
	       or
		  accept Page_Down;
	       or
		  accept Page_Up;
	       or
		  accept Up_Arrow do
		     null;
		  end up_arrow;
	       or
		  accept Down_Arrow do
		     null;
		  end Down_Arrow;
	       or
		  accept Left_Arrow;
	       or
		  accept Right_Arrow;
	       or
		  accept Full_Screen;
	       or
		  accept Del;
	       or
		  accept Begin_Of;
	       or
		  accept End_Of;
	       or
		  accept Overwrite;
	       or
		  accept Screen_Print;

	       end select;
	    end loop;
	    
	    loop
	       select
		  
		  accept Halt do
		     null;
		  end Halt;
		  exit Main_Loop;
	       or
		  accept Suspend;
	       or
		  accept Wake_Up Do
		     Errno := System("clear" & Character'Val(0));
		     null;
		  end Wake_Up;
		  exit;
	       end select;
	    end loop;
	 end loop Main_Loop;
      end;
   end Planning_Process;
   
   
   -------------------------------------------------------------------------------------------------------------
   --                                                                                                         --
   --
   -------------------------------------------------------------------------------------------------------------
   
   -------------------------------------------------------------------------------------------------------------
   --                                                                                                         --
   --
   -------------------------------------------------------------------------------------------------------------
   type Stock_enum is (Stock_None, Stock_Name, Stock_Quantity);
   
   type Stock_Type is
      record
	 Name : Stock_Enum := Stock_None;
	 Line : Wstring_32 := (others => ' ');
	 Line_Last : Natural := 0;
	 Line_Pos      : Line_Range := 1;
	 Column_Pos    : Column_Range := 1;
      end record;
   
   type Curs_Set is array (Stock_Enum) of Stock_Type;
   
   type Stock_Cursor_Type is
      record
	 Values  : Curs_Set;
	 Val_Cur : Stock_Enum := Stock_Name;	 
      end record;
   
   function Initialize return Stock_Cursor_Type is
      Curs : Stock_Cursor_Type;
   begin
      Curs.Values(Stock_Name) :=
	(Stock_name,
	 (others => ' '),
	 0,
	 2,
	 13
	);
      Curs.Values(Stock_Quantity) :=
	(Stock_quantity,
	 (others => ' '),
	 0,
	 4,
	 13
	);
      Curs.Val_Cur := Stock_name;
      return Curs;
   end Initialize;
   
   
   function To_Stock (Curs : in stock_Cursor_Type;Line_Num : in Stock_Num_Range;Stock_Num : in Stock_Num_Range) return Stock_Record is
      Stock : Stock_Record := Null_Stock;
   begin
      Stock.Num := Stock_Num;
      Stock.Name(1..Curs.Values(Stock_Name).Line_Last) := 
	Curs.Values(Stock_Name).Line(1..Curs.Values(Stock_Name).Line_Last);
      Stock.Quantity := 
	Quantity_Range'Value(Handling.To_String(Curs.Values(Stock_Quantity).Line(1..Curs.Values(Stock_Quantity).Line_Last)));
      
      return stock;
   exception
      when others =>
	 raise Spec_Error;
   end To_Stock;

   
   procedure Initialize(Wins : out Stock_Windows_Type;
			Space_Left : in Line_Range;
			Width      : in Column_Range;
			L       : in Line_Range;
			C        : in Column_Range) is
   begin
      
      
      Wins.Stock_Num_Win := (L+2, C, Space_Left-2, 8,  
			    Cyan, Window);
      Wins.Name_Win := (L+2, C+8, Space_Left-2, 26,
      			       Cyan, Window);
      Wins.Quantity_Win := (L+2, C+36, Space_Left-2, 16,  
      			       Cyan, Window);
      Wins.Unit_Ht_Win := (L+2, C+52, Space_Left-2, 16,  
      			    Cyan, Window);
      Wins.TVA_Win := (L+2, C+68, Space_Left-2, 10,  
      		    Cyan, Window);
      
      
      Initialize(Wins.Stock_Num_Win, L+2, C, Space_Left-2, 8,  Cyan, Red);
      Initialize(Wins.Name_Win, L+2, C+8, Space_Left-2, 26,  Cyan, Red);
      Initialize(Wins.quantity_Win, L+2, C+36, Space_Left-2, 16,  Cyan, Red);
      Initialize(Wins.Unit_Ht_Win, L+2, C+52, Space_Left-2, 16, Cyan, Red);
      Initialize(Wins.TVA_Win, L+2, C+68, Space_Left-2, 10, Cyan, Red);

      
      null;
   end Initialize;

   
   procedure Stock_Wins_Draw(Wins : Stock_Windows_Type) is
      
   begin
      Draw_Window(Wins.Stock_Num_Win);
      Draw_Window(Wins.Name_Win);
      Draw_Window(Wins.Quantity_Win);
      Draw_Window(Wins.Unit_Ht_Win);
      Draw_Window(Wins.TVA_Win);
   end Stock_Wins_Draw;      
   
   
   procedure Stock_Line_Draw(Wins : Stock_Windows_Type; Line : in Line_Range; Stock : in Stock_Record) is
      
   begin
      Draw_Text(Wins.stock_Num_Win, Line, 1, White, Handling.To_Wide_String(stock_Num_Range'Image(Stock.Num)));
      Draw_Text(Wins.Name_Win, Line, 1, White, Stock.name(1..24));
      Draw_Text(Wins.Quantity_win, Line, 1, White, Handling.To_Wide_String(Quantity_Range'Image(Stock.Quantity)));
      Draw_Text(Wins.Unit_Ht_Win, Line, 1, White, Handling.To_Wide_String(Fixed_Unit_Ht'Image(Stock.Unit_Ht)));
      Draw_Text(Wins.TVA_Win, Line, 1, White, Handling.To_Wide_String(Fixed_Factor'Image(Stock.TVA_Rate)));
      
   end stock_Line_Draw;      
   
   
   procedure Stocks_Print (Stocks : in Stocks_Manager.Stocks_manager;
			   Wins : in Stock_Windows_Type;
			   Line_Index : in Stock_num_Range;
			   Line_Max : in Positive) is
      Line_Count : natural := 0;
   begin
      if Stocks.Stock_Last = 0 then
	 return;
      end if;
      for Line in Line_Index+1..Natural'Min(Line_Index+Line_Max, Stocks.Stock_Last) loop
	 Stock_Line_Draw(Wins, Line_Count+1, Stocks.stocks(Line));
	 Line_Count := Line_Count + 1;
	 exit when Line_Count = Line_Max;
      end loop;
   end Stocks_Print;

   
   task body Stocks_Process is
      
      type Stocks_Enum is (None, Hardware, Software);
      Stocks_cur : Stocks_Enum := Software;
      
      
      
      function Format (Stock : in Stock_Record) return Wide_String is
   	 Line : Wide_String(1..This.Columns/2-2) := (others => Wide_Character'Val(32));
      begin
   	 Wide_Fixed.Move(Handling.To_Wide_String(Natural'Image(Stock.Num)), Line, Error, Left);
   	 Wide_Fixed.Replace_Slice(Line, 9, Line'Last, Stock.name);
   	 Wide_Fixed.Replace_Slice(Line, 42, Line'Last, Handling.To_Wide_String(Quantity_Range'Image(Stock.Quantity)));
   	 Wide_Fixed.Replace_Slice(Line, 55, Line'Last, Handling.To_Wide_String(Fixed_Unit_Ht'Image(Stock.Unit_Ht)));
   	 Wide_Fixed.Replace_Slice(Line, 62, Line'Last, Handling.To_Wide_String(Fixed_Factor'Image(Stock.TVA_Rate)));
   	 return Line;
      end Format;
      
      Soft_win : Window_Record := (2, 1, 10, This.Columns/2, Cyan, Window);
      Hard_win : Window_Record := (2, 1, 10, This.Columns/2, yellow, Window);
      Stocks_Win : Window_Record := (11, 1, This.Lines-13, This.Columns/2, Blue, Window);
      Cmd_Win    : Window_Record := (This.Lines-2, 1, 3, This.Columns/2, White, Window);
      
      --Stocks_index : Natural := 0;
      Stock_Line_Index : Natural := 0;
      
      Remove_Case : Boolean := False;
      Stock_Num   : Stock_Num_Range := 0;
      Line_num    : Wide_String(1..10) := (others => ' ');
      Line_Last   : Natural := 0;
      Stock_Curs : Stock_Cursor_Type := Initialize;
      
   begin
      Initialize(Stocks_Win, 11, 1, This.Lines-13, This.Columns/2, Blue, white);
      Initialize(Soft_Win, 2, 1, 10, This.Columns/2, Cyan, White);
      Initialize(Hard_Win, 2, 1, 10, This.Columns/2, yellow, White);
      Initialize(Cmd_Win, This.Lines-2, 1, 3, This.Columns/2, White, Red);
      
      Initialize(This.Stocks_Wins, This.Lines-15, This.Columns/2-4, 12, 2);
      
      
      declare
   	 Num      : Stock_Num_Range := 1;
   	 Name     : Wide_String := "Inconito.net";
   	 Line     : Wide_String(1..32) := (others => Wide_Character'Val(32));
   	 Qt       : Quantity_Range := 0.0;
   	 Ht_Price : Fixed_Unit_Ht := 0.0;
   	 TVA      : Fixed_Factor := 0.0;
   	 Stock    : Stock_Record;
      begin
   	 --  Wide_Fixed.Move(Name, Line, Error, Left);
   	 --  Stock := (Num, Line, Qt, Ht_Price, TVA);
   	 --  Stocks_Manager.Stock_Add(Stocks_Manager.Software, Stock);
     Main_Loop:
   	 loop
   	    loop
   	       select
   		  accept Halt;
   		  exit Main_Loop;
   	       or
   		  accept Suspend;
   		  exit;
   	       or
   		  accept Wake_Up;
   	       or
		when not Remove_Case =>  
   		  accept Receive(Wchar : in Wide_Character) do
   		     if Is_Control(Wchar) then
   			case Wchar is
   			   when Wide_Character ' Val (9) =>
   			      case Stocks_Cur is
   				 when None =>
   				    Stocks_Cur := Software;
   				 when Hardware =>
   				    Stocks_Cur := Software;
   				 when Software =>
   				    Stocks_Cur := Hardware;
   			      end case;
			   when Wide_Character'Val(5) =>
			      Remove_Case := True;
			   when Wide_Character'Val(10) =>				 
			      if Stock_Curs.Values(Stock_Curs.Val_Cur).Line_Last /= 0 then
				 case Stock_Curs.Val_Cur is
				    when Stock_None =>
				       null;
				       
				    when Stock_Quantity =>
				       
				       if Stocks_Cur = Software then
					  declare
					     Stock : Stock_Record;
					  begin

						
					     Stock := To_Stock(Stock_Curs, Stocks_Manager.Software.Stock_Last + 1, Stocks_Manager.Soft_Num);
					     --if Stock.Quantity > 0.0 then
						Stocks_Manager.Add_To_Stock(Stocks_Manager.Software, Stock.Name, Stock.Quantity);
					     --else
						--Stocks_Manager.Remove_From_Stock(Stocks_Manager.Software, Stock.Name, Stock.Quantity);
						--end if;
					  exception
					     when Spec_Error =>
						Errno := System("clear" & Character'Val(0));
						Put_Line("Stocks Error");
						declare
						   Char : Character;
						begin
						   Put_Line("Press any key to continue");
						   Get_Immediate(Char);
						end;						
					  end;
					  Stock_Curs := Initialize;				    
				       elsif Stocks_Cur = Hardware then
					  declare
					     Stock : Stock_Record;
					  begin
					     --if Stock.Quantity > 0.0 then
					     Stock := To_Stock(Stock_Curs, Stocks_Manager.Hardware.Stock_Last + 1, Stocks_Manager.Hard_Num);
					     Stocks_Manager.Add_To_Stock(Stocks_Manager.Hardware, Stock.Name, Stock.Quantity);
					     --else
						--Stocks_Manager.Remove_From_Stock(Stocks_Manager.Hardware, Stock.Name, Stock.Quantity);
						--end if;
						exception
					     when Spec_Error =>
						Errno := System("clear" & Character'Val(0));
						Put_Line("Stocks Error");
						declare
						   Char : Character;
						begin
						   Put_Line("Press any key to continue");
						   Get_Immediate(Char);
						end;						
					  end;
					     Stock_Curs := Initialize;				    

				       end if;
					  
				       
				    when others =>
				       Stock_Curs.Val_Cur := Stock_Enum'Succ(Stock_Curs.Val_Cur);
				 end case;
				 
			      else
				 Put(Character'Val(7));
			      end if;
			   when Wide_Character ' Val (127) =>
			      if Stock_Curs.Values(Stock_Curs.Val_Cur).Line_Last > 1 then
				 Stock_Curs.Values(Stock_Curs.Val_Cur).Line(Stock_Curs.Values(Stock_Curs.Val_Cur).Line_Last) := ' ';
				 Stock_Curs.Values(Stock_Curs.Val_Cur).Line_Last := 
				   Stock_Curs.Values(Stock_Curs.Val_Cur).Line_Last - 1;
			      end if;
			   when Wide_Character'Val(18) =>
			      Remove_Case := False;			      
			      
   			   when others =>
   			      null;
   			end case;
		     elsif Stock_Curs.Values(Stock_Curs.Val_Cur).Line_Last < 32 then
			
			   Stock_Curs.Values(Stock_Curs.Val_Cur).Line(Stock_Curs.Values(Stock_Curs.Val_Cur).Line_Last + 1) := Wchar;
			   Stock_Curs.Values(Stock_Curs.Val_Cur).Line_Last := 
			     Stock_Curs.Values(Stock_Curs.Val_Cur).Line_Last + 1;
			   if Stocks_cur = software then
			      for Val in Stock_Name..Stock_Quantity loop
				 Draw_Text(Soft_Win , Stock_Curs.values(Val).Line_Pos,
					   Stock_Curs.values(Val).Column_Pos,
					   White,
					   Stock_Curs.values(Val).Line(1..Stock_Curs.values(Val).Line_Last));
			      end loop;

			      Draw_Text(Soft_Win, Stock_Curs.Values(Stock_Curs.Val_Cur).Line_Pos,
					Stock_Curs.Values(Stock_Curs.Val_Cur).Column_Pos,
					White,
					Stock_Curs.Values(Stock_Curs.Val_Cur).Line(1..Stock_Curs.Values(Stock_Curs.Val_Cur).Line_Last));
			   elsif Stocks_Cur = Hardware then
			      
			      for Val in Stock_Name..Stock_Quantity loop
				 Draw_Text(Hard_Win , Stock_Curs.values(Val).Line_Pos,
					   Stock_Curs.values(Val).Column_Pos,
					   White,
					   Stock_Curs.values(Val).Line(1..Stock_Curs.values(Val).Line_Last));
			      end loop;

			      Draw_Text(Hard_Win, Stock_Curs.Values(Stock_Curs.Val_Cur).Line_Pos,
					Stock_Curs.Values(Stock_Curs.Val_Cur).Column_Pos,
					White,
					Stock_Curs.Values(Stock_Curs.Val_Cur).Line(1..Stock_Curs.Values(Stock_Curs.Val_Cur).Line_Last));
			   end if;
			   
			else
			   Put(Character'Val(7));
			end if;
			Draw_Window(Stocks_Win);
   		     Draw_Text(Stocks_Win, 1, 1, White, "N    , Name                        , " & 
   				 "Quantity      , Unit HT     , TVA rate");
   		     Draw_Text(Stocks_Win, 2, 1, Blue, Handling.To_Wide_String(((This.Columns/2)-2) * '-'));
		     Draw_Window(Cmd_Win);
   		     Stock_Wins_Draw(This.Stocks_Wins);
		     case Stocks_Cur is			
   			when None =>
   			   null;
   			when Software =>
			   Draw_Window(Soft_Win);
			   Draw_Text(Soft_Win, 1, This.Columns/4-10, White, "Software Stocks : Update stock");
			   Draw_Text(Soft_Win, 2, 1, White, "Name      : ");
			   Draw_Text(Soft_Win, 4, 1, White, "Quantity  : ");
		     
			   for Val in Stock_Name..Stock_Quantity Loop
			   Draw_Text(Soft_Win , Stock_Curs.values(Val).Line_Pos,
				     Stock_Curs.values(Val).Column_Pos,
				     White,
				     Stock_Curs.values(Val).Line(1..Stock_Curs.values(Val).Line_Last));
			   end loop;

			Stocks_Print(Stocks_Manager.Software, This.Stocks_Wins, stock_Line_Index, This.Lines-19);

			Draw_Text(Soft_Win, Stock_Curs.Values(Stock_Curs.Val_Cur).Line_Pos,
				  Stock_Curs.Values(Stock_Curs.Val_Cur).Column_Pos,
				  White,
				  Stock_Curs.Values(Stock_Curs.Val_Cur).Line(1..Stock_Curs.Values(Stock_Curs.Val_Cur).Line_Last));

   			when Hardware =>
			   Draw_Window(Hard_Win);
			   Draw_Text(Hard_Win, 1, This.Columns/4-10, White, "Hardware Stocks : Update stock");
			   Draw_Text(Hard_Win, 2, 1, White, "Name      : ");
			   Draw_Text(Hard_Win, 4, 1, White, "Quantity  : ");
			   
			   for Val in Stock_Name..Stock_quantity loop
			      Draw_Text(Hard_Win , Stock_Curs.values(Val).Line_Pos,
					Stock_Curs.values(Val).Column_Pos,
					White,
					Stock_Curs.values(Val).Line(1..Stock_Curs.values(Val).Line_Last));
			   end loop;
			   Stocks_Print(Stocks_Manager.Hardware, This.Stocks_Wins, stock_Line_Index, This.Lines-19);
			   
			   Draw_Text(Hard_Win, Stock_Curs.Values(Stock_Curs.Val_Cur).Line_Pos,
				     Stock_Curs.Values(Stock_Curs.Val_Cur).Column_Pos,
				     White,
				     Stock_Curs.Values(Stock_Curs.Val_Cur).Line(1..Stock_Curs.Values(Stock_Curs.Val_Cur).Line_Last));
			   
   			   --Stocks_Print(Stocks_Manager.Hardware, This.Stocks_Wins, Stocks_Index, This.Lines-7);
   		     end case;
		     if Remove_Case then
			
			Draw_Text(Cmd_Win, 1, 1, White, "Line num : ");
		     end if;

   		  end Receive;
		  
	       or
		  when Remove_Case =>
		     accept Receive(Wchar : in Wide_Character) do
   		     if Is_Control(Wchar) then
   			case Wchar is
   			   when Wide_Character ' Val (9) =>
   			      case Stocks_Cur is
   				 when None =>
   				    Stocks_Cur := Software;
   				 when Hardware =>
   				    Stocks_Cur := Software;
   				 when Software =>
   				    Stocks_Cur := Hardware;
   			      end case;
			   when Wide_Character'Val(10) =>				 
			      if Line_Last > 0 then
				 begin
				    Stock_Num := Stock_Num_Range'Value(Handling.To_String(Line_num(Line'First..Line_Last)));
				    if Stock_Num /= 0 then
				       begin
					  case Stocks_Cur is
					     when None =>
						null;
					     when Software =>
						Stocks_Manager.Stock_Remove(Stocks_Manager.Software, Stock_Num);
					     when Hardware =>
						Stocks_Manager.Stock_Remove(Stocks_Manager.Hardware, Stock_Num);
					  end case;
				       exception
					  when others =>
					     null;
				       end;

				    end if;
				 exception
				    when others =>
				       null;
				 end;				 
			      end if;
			      Line_Num := (others => ' ');
			      Line_Last := 0;
			      Remove_Case := False;
				 
			   when Wide_Character'Val(127) =>
			      if Line_Last > 0 then
				 Line(Line_Last) := Wide_Character'Val(32);
				 Line_Last := Line_Last - 1;
			      else
				 Put(Character'Val(7));
			      end if;
			   when others =>
			      null;
			end case;
			Draw_Window(Stocks_Win);
			Draw_Text(Stocks_Win, 1, 1, White, "N    , Name                        , " & 
				    "Quantity      , Unit HT     , TVA rate");
			Draw_Text(Stocks_Win, 2, 1, Blue, Handling.To_Wide_String(((This.Columns/2)-2) * '-'));
			
			Stock_Wins_Draw(This.Stocks_Wins);
			Draw_Window(Cmd_Win);
			case Stocks_Cur is			
			   when None =>
			      null;
			   when Software =>
			      Draw_Window(Soft_Win);
			      Draw_Text(Soft_Win, 1, This.Columns/4-10, White, "Software Stocks : Update stock");
			      Draw_Text(Soft_Win, 2, 1, White, "Name      : ");
			      Draw_Text(Soft_Win, 4, 1, White, "Quantity  : ");
			      
			      for Val in Stock_Name..Stock_quantity loop
				 Draw_Text(Soft_Win , Stock_Curs.values(Val).Line_Pos,
					   Stock_Curs.values(Val).Column_Pos,
					   White,
					   Stock_Curs.values(Val).Line(1..Stock_Curs.values(Val).Line_Last));
			      end loop;
			      Stocks_Print(Stocks_Manager.Software, This.Stocks_Wins, stock_Line_Index, This.Lines-19);
			      
			      Draw_Text(Soft_Win, Stock_Curs.Values(Stock_Curs.Val_Cur).Line_Pos,
					Stock_Curs.Values(Stock_Curs.Val_Cur).Column_Pos,
					White,
					Stock_Curs.Values(Stock_Curs.Val_Cur).Line(1..Stock_Curs.Values(Stock_Curs.Val_Cur).Line_Last));

			   when Hardware =>
			      Draw_Window(Hard_Win);
			      Draw_Text(hard_Win, 1, This.Columns/4-10, White, "Hardware Stocks  : update stock");
			      Draw_Text(hard_Win, 2, 1, White, "Name      : ");
			      Draw_Text(hard_Win, 4, 1, White, "Quantity  : ");
			      
			      for Val in Stock_Name..Stock_quantity loop
				 Draw_Text(Hard_Win , Stock_Curs.values(Val).Line_Pos,
					   Stock_Curs.values(Val).Column_Pos,
					   White,
					   Stock_Curs.values(Val).Line(1..Stock_Curs.values(Val).Line_Last));
			      end loop;
			      Stocks_Print(Stocks_Manager.Hardware, This.Stocks_Wins, stock_Line_Index, This.Lines-19);

			      Draw_Text(Hard_Win, Stock_Curs.Values(Stock_Curs.Val_Cur).Line_Pos,
					Stock_Curs.Values(Stock_Curs.Val_Cur).Column_Pos,
					White,
					Stock_Curs.Values(Stock_Curs.Val_Cur).Line(1..Stock_Curs.Values(Stock_Curs.Val_Cur).Line_Last));

			      --Stocks_Print(Stocks_Manager.Hardware, This.Stocks_Wins, Stocks_Index, This.Lines-7);
			end case;
			if Remove_Case then
			   if Line_Last > 0 then
			      
			      Draw_Text(Cmd_Win, 1, 1, White, "Line num : " & Line_num(Line'First..Line_last));
			else
			   Draw_Text(Cmd_Win, 1, 1, White, "Line num : ");
			   end if;   		     
			end if;   		     
		     elsif Line_Last < Line_num'Length then
			Line_Num(Line_Last + 1) := Wchar;
			Line_Last := Line_Last + 1;
			Draw_Window(Cmd_Win);
			if Line_Last > 0 then
			   
			   Draw_Text(Cmd_Win, 1, 1, White, "Line num : " & Line_num(Line'First..Line_last));
			else
			   Draw_Text(Cmd_Win, 1, 1, White, "Line num : ");
			end if;   		     
		     else
			  Put(Character'Val(7));
		     end if;
		     end Receive;
   	       or

   		  accept Refresh do
   		     Draw_Window(Stocks_Win);
   		     Draw_Text(Stocks_Win, 1, 1, White, "N    , Name                        , " & 
   				 "Quantity      , Unit HT     , TVA rate");
   		     Draw_Text(Stocks_Win, 2, 1, Blue, Handling.To_Wide_String(((This.Columns/2)-2) * '-'));
		     
   		     Stock_Wins_Draw(This.Stocks_Wins);
		     Draw_Window(Cmd_Win);
		     case Stocks_Cur is			
   			when None =>
   			   null;
   			when Software =>
			   Draw_Window(Soft_Win);
			   Draw_Text(Soft_Win, 1, This.Columns/4-10, White, "Software Stocks : Update stock");
			   Draw_Text(Soft_Win, 2, 1, White, "Name      : ");
			   Draw_Text(Soft_Win, 4, 1, White, "Quantity  : ");
		     
			   for Val in Stock_Name..Stock_quantity loop
			   Draw_Text(Soft_Win , Stock_Curs.values(Val).Line_Pos,
				     Stock_Curs.values(Val).Column_Pos,
				     White,
				     Stock_Curs.values(Val).Line(1..Stock_Curs.values(Val).Line_Last));
			end loop;
			Stocks_Print(Stocks_Manager.Software, This.Stocks_Wins, stock_Line_Index, This.Lines-19);
			
			Draw_Text(Soft_Win, Stock_Curs.Values(Stock_Curs.Val_Cur).Line_Pos,
				  Stock_Curs.Values(Stock_Curs.Val_Cur).Column_Pos,
				  White,
				  Stock_Curs.Values(Stock_Curs.Val_Cur).Line(1..Stock_Curs.Values(Stock_Curs.Val_Cur).Line_Last));

   			when Hardware =>
			   Draw_Window(Hard_Win);
			   Draw_Text(hard_Win, 1, This.Columns/4-10, White, "Hardware Stocks  : update stock");
			   Draw_Text(hard_Win, 2, 1, White, "Name      : ");
			   Draw_Text(hard_Win, 4, 1, White, "Quantity  : ");
		     
			   			for Val in Stock_Name..Stock_quantity loop
			   Draw_Text(Hard_Win , Stock_Curs.values(Val).Line_Pos,
				     Stock_Curs.values(Val).Column_Pos,
				     White,
				     Stock_Curs.values(Val).Line(1..Stock_Curs.values(Val).Line_Last));
			end loop;
			Stocks_Print(Stocks_Manager.Hardware, This.Stocks_Wins, stock_Line_Index, This.Lines-19);

			Draw_Text(Hard_Win, Stock_Curs.Values(Stock_Curs.Val_Cur).Line_Pos,
				  Stock_Curs.Values(Stock_Curs.Val_Cur).Column_Pos,
				  White,
				  Stock_Curs.Values(Stock_Curs.Val_Cur).Line(1..Stock_Curs.Values(Stock_Curs.Val_Cur).Line_Last));

   			   --Stocks_Print(Stocks_Manager.Hardware, This.Stocks_Wins, Stocks_Index, This.Lines-7);
   		     end case;
		     if Remove_Case then
			
			Draw_Text(Cmd_Win, 1, 1, White, "Line num : ");
		     end if;   		     
   		  end Refresh;
		  
   	       or
   		  accept Page_Down do
		     Stock_Wins_Draw(This.Stocks_Wins);
		     case Stocks_Cur is
			when None =>
			   null;
			when Software =>
			   if Stock_Line_Index < Stocks_Manager.Software.Stock_Last then
			      Stock_Line_Index := Stock_Line_Index + Stock_Num_Range'Min (Stock_Line_Index+(This.Lines-19), Stocks_Manager.Software.Stock_Last);
			   else
			      Put(Character'Val(7));
			   end if;
			   Draw_Window(Soft_Win);
			   Draw_Text(Soft_Win, 1, This.Columns/4-10, White, "Software Stocks : Update stock");
			   Draw_Text(Soft_Win, 2, 1, White, "Name      : ");
			   Draw_Text(Soft_Win, 4, 1, White, "Quantity  : ");
			   
			   for Val in Stock_Name..Stock_Quantity Loop
			   Draw_Text(Soft_Win , Stock_Curs.values(Val).Line_Pos,
				     Stock_Curs.values(Val).Column_Pos,
				     White,
				     Stock_Curs.values(Val).Line(1..Stock_Curs.values(Val).Line_Last));
			   end loop;

			Stocks_Print(Stocks_Manager.Software, This.Stocks_Wins, stock_Line_Index, This.Lines-19);

			Draw_Text(Soft_Win, Stock_Curs.Values(Stock_Curs.Val_Cur).Line_Pos,
				  Stock_Curs.Values(Stock_Curs.Val_Cur).Column_Pos,
				  White,
				  Stock_Curs.Values(Stock_Curs.Val_Cur).Line(1..Stock_Curs.Values(Stock_Curs.Val_Cur).Line_Last));

			when Hardware =>
			   if Stock_Line_Index < Stocks_Manager.hardware.Stock_Last then
			      Stock_Line_Index := Stock_Line_Index + Stock_Num_Range'Min (Stock_Line_Index+(This.Lines-19), Stocks_Manager.hardware.Stock_Last);
			   else
			      Put(Character'Val(7));
			   end if;
			   Draw_Window(Hard_Win);
			   Draw_Text(Hard_Win, 1, This.Columns/4-10, White, "Hardware Stocks : Update stock");
			   Draw_Text(Hard_Win, 2, 1, White, "Name      : ");
			   Draw_Text(Hard_Win, 4, 1, White, "Quantity  : ");
			   
			   for Val in Stock_Name..Stock_quantity loop
			      Draw_Text(Hard_Win , Stock_Curs.values(Val).Line_Pos,
					Stock_Curs.values(Val).Column_Pos,
					White,
					Stock_Curs.values(Val).Line(1..Stock_Curs.values(Val).Line_Last));
			   end loop;
			   Stocks_Print(Stocks_Manager.Hardware, This.Stocks_Wins, stock_Line_Index, This.Lines-19);
			   
			   Draw_Text(Hard_Win, Stock_Curs.Values(Stock_Curs.Val_Cur).Line_Pos,
				     Stock_Curs.Values(Stock_Curs.Val_Cur).Column_Pos,
				     White,
				     Stock_Curs.Values(Stock_Curs.Val_Cur).Line(1..Stock_Curs.Values(Stock_Curs.Val_Cur).Line_Last));
			   
		     end case;
		  end Page_Down;
   	       or
   		  accept Page_Up do
		     Stock_Wins_Draw(This.Stocks_Wins);
		     case Stocks_Cur is
			when None =>
			   null;
			when Software =>
			   if Stock_Line_Index - (This.Lines-19) > 0 then
			      Stock_Line_Index := Stock_Line_Index + Stock_Line_Index - (This.Lines-19);
			   else
			      Stock_Line_Index := 0;
			   end if;

			   Draw_Window(Soft_Win);
			   Draw_Text(Soft_Win, 1, This.Columns/4-10, White, "Software Stocks : Update stock");
			   Draw_Text(Soft_Win, 2, 1, White, "Name      : ");
			   Draw_Text(Soft_Win, 4, 1, White, "Quantity  : ");

			   for Val in Stock_Name..Stock_Quantity Loop
			   Draw_Text(Soft_Win , Stock_Curs.values(Val).Line_Pos,
				     Stock_Curs.values(Val).Column_Pos,
				     White,
				     Stock_Curs.values(Val).Line(1..Stock_Curs.values(Val).Line_Last));
			   end loop;

			   Stocks_Print(Stocks_Manager.Software, This.Stocks_Wins, stock_Line_Index, This.Lines-19);

			   Draw_Text(Soft_Win, Stock_Curs.Values(Stock_Curs.Val_Cur).Line_Pos,
				     Stock_Curs.Values(Stock_Curs.Val_Cur).Column_Pos,
				     White,
				     Stock_Curs.Values(Stock_Curs.Val_Cur).Line(1..Stock_Curs.Values(Stock_Curs.Val_Cur).Line_Last));

			when Hardware =>
			   if Stock_Line_Index - (This.Lines-19) > 0 then
			      Stock_Line_Index := Stock_Line_Index + Stock_Line_Index - (This.Lines-19);
			   else
			      Stock_Line_Index := 0;
			   end if;

			   Draw_Window(Hard_Win);
			   Draw_Text(Hard_Win, 1, This.Columns/4-10, White, "Hardware Stocks : Update stock");
			   Draw_Text(Hard_Win, 2, 1, White, "Name      : ");
			   Draw_Text(Hard_Win, 4, 1, White, "Quantity  : ");

			   for Val in Stock_Name..Stock_quantity loop
			      Draw_Text(Hard_Win , Stock_Curs.values(Val).Line_Pos,
					Stock_Curs.values(Val).Column_Pos,
					White,
					Stock_Curs.values(Val).Line(1..Stock_Curs.values(Val).Line_Last));
			   end loop;

			   Stocks_Print(Stocks_Manager.Hardware, This.Stocks_Wins, stock_Line_Index, This.Lines-19);

			   Draw_Text(Hard_Win, Stock_Curs.Values(Stock_Curs.Val_Cur).Line_Pos,
				     Stock_Curs.Values(Stock_Curs.Val_Cur).Column_Pos,
				     White,
				     Stock_Curs.Values(Stock_Curs.Val_Cur).Line(1..Stock_Curs.Values(Stock_Curs.Val_Cur).Line_Last));

		     end case;
		  end Page_Up;
   	       or
   		  accept Up_Arrow do
   		     null;
   		  end up_arrow;
   	       or
   		  accept Down_Arrow do
   		     null;
   		  end Down_Arrow;
   	       or
   		  accept Left_Arrow;
   	       or
   		  accept Right_Arrow;
   	       or
   		  accept Full_Screen;
   	       or
   		  accept Del;
   	       or
   		  accept Begin_Of;
   	       or
   		  accept End_Of;
   	       or
   		  accept Overwrite;
   	       or
   		  accept Screen_Print;

   	       end select;
   	    end loop;
	    
   	    loop
   	       select
		  
   		  accept Halt do
   		     null;
   		  end Halt;
   		  exit Main_Loop;
   	       or
   		  accept Suspend;
   	       or
   		  accept Wake_Up Do
   		     Errno := System("clear" & Character'Val(0));
   		     Draw_Window(Stocks_Win);
   		     Draw_Text(Stocks_Win, 1, 1, White, "N    , Name                        , " & 
   				 "Quantity      , Unit HT     , TVA rate");
   		     Draw_Text(Stocks_Win, 2, 1, Blue, Handling.To_Wide_String(((This.Columns/2)-2) * '-'));
		     Draw_Window(Cmd_Win);
   		     Stock_Wins_Draw(This.Stocks_Wins);
		     
   		     case Stocks_Cur is			
   			when None =>
   			   null;
   			when Software =>
			   Draw_Window(Soft_Win);
			   Draw_Text(Soft_Win, 1, This.Columns/4-10, White, "Software Stocks : Update stock");
			   Draw_Text(Soft_Win, 2, 1, White, "Name      : ");
			   Draw_Text(Soft_Win, 4, 1, White, "Quantity  : ");
		     
			   
			   for Val in Stock_Name..Stock_Quantity loop
			      Draw_Text(Soft_Win , Stock_Curs.values(Val).Line_Pos,
				     Stock_Curs.values(Val).Column_Pos,
				     White,
				     Stock_Curs.values(Val).Line(1..Stock_Curs.values(Val).Line_Last));
			end loop;
			Stocks_Print(Stocks_Manager.Software, This.Stocks_Wins, stock_Line_Index, This.Lines-19);

			Draw_Text(Soft_Win, Stock_Curs.Values(Stock_Curs.Val_Cur).Line_Pos,
				  Stock_Curs.Values(Stock_Curs.Val_Cur).Column_Pos,
				  White,
				  Stock_Curs.Values(Stock_Curs.Val_Cur).Line(1..Stock_Curs.Values(Stock_Curs.Val_Cur).Line_Last));

   			when Hardware =>
			   Draw_Window(Hard_Win);
			   Draw_Text(hard_Win, 1, This.Columns/4-10, White, "Hardware Stocks  : update stock");
			   Draw_Text(hard_Win, 2, 1, White, "Name      : ");
			   Draw_Text(hard_Win, 4, 1, White, "Quantity  : ");
		     

			   			for Val in Stock_Name..Stock_Quantity loop
			   Draw_Text(Hard_Win , Stock_Curs.values(Val).Line_Pos,
				     Stock_Curs.values(Val).Column_Pos,
				     White,
				     Stock_Curs.values(Val).Line(1..Stock_Curs.values(Val).Line_Last));
			end loop;
			Stocks_Print(Stocks_Manager.Hardware, This.Stocks_Wins, stock_Line_Index, This.Lines-19);

			Draw_Text(Hard_Win, Stock_Curs.Values(Stock_Curs.Val_Cur).Line_Pos,
				  Stock_Curs.Values(Stock_Curs.Val_Cur).Column_Pos,
				  White,
				  Stock_Curs.Values(Stock_Curs.Val_Cur).Line(1..Stock_Curs.Values(Stock_Curs.Val_Cur).Line_Last));

   			   --Stocks_Print(Stocks_Manager.Hardware, This.Stocks_Wins, Stocks_Index, This.Lines-7);
   		     end case;
		     
		     if Remove_Case then
			
			Draw_Text(Cmd_Win, 1, 1, White, "Line num : ");
		     end if;
   		  end Wake_Up;
   		  exit;
   	       end select;
   	    end loop;
   	 end loop Main_Loop;
      end;
   end Stocks_Process;
   
   
   -------------------------------------------------------------------------------------------------------------
   --                                                                                                         --
   --
   -------------------------------------------------------------------------------------------------------------
   
-------------------------------------------------------------------------------------------------------------
   --                                                                                                         --
   --
   -------------------------------------------------------------------------------------------------------------
   task body Accounting_Process is
      Accounting_Win     : Window_Record := (4, 1, This.Lines - 7, This.Columns/2, Blue, Window);
      Account_Input      : Window_Record := (This.Lines-3, 1, 3, This.Columns/2, Blue, Window);
   begin
      Initialize(Accounting_Win    ,4, 1, This.Lines - 7, This.Columns/2, Blue, White);
      Initialize(Account_Input     ,This.Lines-3, 1, 3, This.Columns/2, Blue, White);
      
      Initialize(This.Accounting_Wins, This.Lines-8, This.Columns/2, 4, 2);
      
      declare
	 
      begin
     Main_Loop:
	 loop
	    loop
	       select
		  accept Halt;
		  exit Main_Loop;
	       or
		  accept Suspend;
		  exit;
	       or
		  accept Wake_Up;
	       or
		  
		  accept Receive(Wchar : in Wide_Character);
	       or

		  accept Refresh;
		  
	       or
		  accept Page_Down;
	       or
		  accept Page_Up;
	       or
		  accept Up_Arrow do
		     null;
		  end up_arrow;
	       or
		  accept Down_Arrow do
		     null;
		  end Down_Arrow;
	       or
		  accept Left_Arrow;
	       or
		  accept Right_Arrow;
	       or
		  accept Full_Screen;
	       or
		  accept Del;
	       or
		  accept Begin_Of;
	       or
		  accept End_Of;
	       or
		  accept Overwrite;
	       or
		  accept Screen_Print;

	       end select;
	    end loop;
	    
	    loop
	       select
		  
		  accept Halt do
		     null;
		  end Halt;
		  exit Main_Loop;
	       or
		  accept Suspend;
	       or
		  accept Wake_Up Do
		     Errno := System("clear" & Character'Val(0));
		     Draw_Window(Accounting_Win);
		     Draw_Text(Accounting_win, 1, 1, White, "N   , Description                  , Date op            , Date val           , Sum");
		     --Accounting_Wins_Draw(This.Accounting_Wins);
		     
		     Draw_Window(Account_Input);
		     Draw_Text(Account_Input, 1, 1, White, "");
		  end Wake_Up;
		  exit;
	       end select;
	    end loop;
	 end loop Main_Loop;
      end;
   end Accounting_Process;
   
   
   -------------------------------------------------------------------------------------------------------------
   --                                                                                                         --
   --
   -------------------------------------------------------------------------------------------------------------
   
      -------------------------------------------------------------------------------------------------------------
   --                                                                                                         --
   --
   -------------------------------------------------------------------------------------------------------------
   task body Dialog_Process is
      

   begin

      declare
	 
      begin
     Main_Loop:
	 loop
	    loop
	       select
		  accept Halt;
		  exit Main_Loop;
	       or
		  accept Suspend;
		  exit;
	       or
		  accept Wake_Up;
	       or
		  
		  accept Receive(Wchar : in Wide_Character);
	       or

		  accept Refresh;
		  
	       or
		  accept Page_Down;
	       or
		  accept Page_Up;
	       or
		  accept Up_Arrow do
		     null;
		  end up_arrow;
	       or
		  accept Down_Arrow do
		     null;
		  end Down_Arrow;
	       or
		  accept Left_Arrow;
	       or
		  accept Right_Arrow;
	       or
		  accept Full_Screen;
	       or
		  accept Del;
	       or
		  accept Begin_Of;
	       or
		  accept End_Of;
	       or
		  accept Overwrite;
	       or
		  accept Screen_Print;

	       end select;
	    end loop;
	    
	    loop
	       select
		  
		  accept Halt do
		     null;
		  end Halt;
		  exit Main_Loop;
	       or
		  accept Suspend;
	       or
		  accept Wake_Up Do
		     Errno := System("clear" & Character'Val(0));
		     null;
		  end Wake_Up;
		  exit;
	       end select;
	    end loop;
	 end loop Main_Loop;
      end;
   end Dialog_Process;
   
   
   -------------------------------------------------------------------------------------------------------------
   --                                                                                                         --
   --
   -------------------------------------------------------------------------------------------------------------

      
   procedure Initialize (This : in out Computer_Type) is
   begin
      
      Interfaces.Initialize(Interfaces.Interface_Record(This));           
      if Balance.Initialized or (Balance.Balance.Capital > 0.0) then
	 This.Initialized := True;
      end if;
      --Text_Io.Put_Line("initialized");
      if Is_Regular_File("billed.txt") then
	 Invoices_Restore(Accounts.Billed, Accounts.Invoice_Last, "billed.txt");
      end if;
      if Is_Regular_File("charged.txt") then
	 Outvoices_Restore(Accounts.Charges, Accounts.Outvoice_Last, "charged.txt");
      end if;
      
      
      begin
	 Make_Dir("Archives");
      exception
	 when others =>
	    begin
	       Change_Dir("Archives");
	       Change_Dir("..");
	    exception
	       when others =>
		  raise Spec_Error;
	    end;
		  
      end;
      
	       
      
   end Initialize;
   
   procedure Term_Init (This : in out Computer_Type) is
      Env : constant String_Access := Getenv("TERM");
   begin
      --Text_Io.Put_Line("term_init");
      This.Term_Name := Term_Enum'Value(Env.all);
   exception
      when Constraint_Error =>
	 This.Term_Name := None;
   end Term_Init;
   
   
   
   
   
   
   
   
   
   task body Computer_Process is
      
      On_Esc : Boolean := False;
      End_Of_This_Task : Boolean := False;
   begin
      
      loop                                       
	 
	 select
	    
	    accept Halt;

	    This.Shell.Halt;
	    
	    This.Game.Halt;
	    
	    This.Midiconsole.Halt;
	    
	    This.Editor.Halt;
	    
	    This.Moneybox.Halt;
	    
	    This.Manager.Halt;
	    

	    
	    This.Activity.Halt;

	    This.Contacts.Halt;

	    This.Planning.Halt;

	    This.Stocks.Halt;

	    This.Accounting.Halt;

	    This.Dialog.Halt;


	    exit;
	    
	    
	 or
	    
	    
	    accept Mode (Mode : out Mode_Enum) do
	       Mode := This.Mode_Cur;
	    end Mode;
	    
	 or
	    accept Reset;

	    This.Mode_Prev := This.Mode_Cur;
	    This.Mode_Cur := None;
	    This.game.Suspend;

	    This.Midiconsole.Suspend;

	    This.editor.Suspend;
	    This.moneybox.Suspend;
	    This.manager.Suspend;
	    

	    This.activity.Suspend;
	    This.contacts.Suspend;
	    This.planning.Suspend;
	    This.Stocks.Suspend;
	    This.Accounting.Suspend;
	    This.Dialog.Suspend;

	    On_Esc := False;
	    
	    End_Of_This_Task := False;
	    
	    Errno := System("clear" & Character'Val(0));
	    This.Mode_Cur := none;
	    This.Shell.Wake_Up;
	    This.Shell.Refresh;

	    
	    
	    
	 or
	    accept Switch (Mode : in Mode_Enum) do

	       This.Mode_prev := None;
	       This.Mode_Cur := Mode;
	    end Switch; 
	    


	    
	    case This.Mode_Cur is
	       
	       when Quit =>
		  --My_Ansi_Consoles.Clear_screen;
		  --Mode_Info_Status(W1, Null_Item);
		  --Main_Quit_Info_Status(W3, On_Esc);
		  --Quit_Info_Status(W4);
		  if End_Of_This_Task then
		     --My_Ansi_Consoles.Clear_screen;
		     --Main_Quit(W4);

		     accept Halt;

		     This.Shell.Halt;

		     This.Game.Halt;

		     This.Midiconsole.Halt;

		     This.Editor.Halt;

		     This.Moneybox.Halt;

		     This.Manager.Halt;


		     
		     This.Activity.Halt;

		     This.Contacts.Halt;

		     This.Planning.Halt;

		     This.Stocks.Halt;

		     This.Accounting.Halt;

		     This.Dialog.halt;

		     exit;
		  else
		     
		     This.Shell.Suspend;
		     W_Io.Put("Realy quit ? (press two esc character or return else)");
		  end if;		  
		  End_Of_This_Task := True;
	       when None =>              
		  End_Of_This_Task := False;
	       when others =>
		  null;
	    end case;
	    delay 0.2;
	    case This.Mode_Cur is
	       when None =>
		  
		  This.game.Suspend;
		  
		  This.Midiconsole.Suspend;
		  
		  This.editor.Suspend;
		  This.moneybox.Suspend;
		  This.manager.Suspend;
		  

		  This.activity.Suspend;
		  This.contacts.Suspend;
		  This.planning.Suspend;
		  This.Stocks.Suspend;
		  This.Accounting.Suspend;
		  This.Dialog.Suspend;
		  
		  This.Mode_Cur := none;
		  
		  This.Shell.Wake_Up;
		  This.Shell.Refresh;


	       when Quit =>
		  null;
	       when Shell =>
		  null;
	       when Games =>
		  This.Shell.suspend;
		  This.Midiconsole.Suspend;
		  This.editor.Suspend;
		  This.moneybox.Suspend;
		  This.manager.Suspend;

		  
		  This.activity.Suspend;
		  This.contacts.Suspend;
		  This.planning.Suspend;
		  This.Stocks.Suspend;
		  This.Accounting.Suspend;
		  This.Dialog.Suspend;
		  
		  This.Mode_Cur := games;
		  This.Game.Wake_up;
		  This.game.Refresh;

	       when Midictrl =>
		  This.game.suspend;
		  This.Shell.suspend;
		  This.editor.Suspend;
		  This.moneybox.Suspend;
		  This.manager.Suspend;


		  This.activity.Suspend;
		  This.contacts.Suspend;
		  This.planning.Suspend;
		  This.Stocks.Suspend;
		  This.Accounting.Suspend;
		  This.Dialog.Suspend;
		  
		  This.Mode_Cur := midictrl;
		  This.Midiconsole.Wake_up;
		  This.Midiconsole.Refresh;

	       when Editor =>
		  This.Midiconsole.suspend;
		  This.game.suspend;
		  This.Shell.suspend;	       
		  This.moneybox.Suspend;
		  This.manager.Suspend;


		  This.activity.Suspend;
		  This.contacts.Suspend;
		  This.planning.Suspend;
		  This.Stocks.Suspend;
		  This.Accounting.Suspend;
		  This.Dialog.Suspend;
		  
		  This.Mode_Cur := editor;
		  This.editor.Wake_up;
		  This.editor.Refresh;

	       when Moneybox =>
		  This.Editor.suspend;
		  This.Midiconsole.suspend;
		  This.game.suspend;
		  This.Shell.suspend;
		  This.manager.Suspend;


		  This.activity.Suspend;
		  This.contacts.Suspend;
		  This.planning.Suspend;
		  This.Stocks.Suspend;
		  This.Accounting.Suspend;
		  This.Dialog.Suspend;
		  
		  This.Mode_Cur := moneybox;
		  This.Moneybox.Wake_up;
		  This.Moneybox.refresh;

	       when Manager =>
		  This.Moneybox.Suspend;	       
		  This.Editor.suspend;
		  This.Midiconsole.suspend;
		  This.Shell.suspend;
		  This.game.Suspend;


		  This.activity.Suspend;
		  This.contacts.Suspend;
		  This.planning.Suspend;
		  This.Stocks.Suspend;
		  This.Accounting.Suspend;
		  This.Dialog.Suspend;
		  
		  This.Mode_Cur := manager;
		  This.manager.Wake_up;
		  This.manager.Refresh;

	       
	       when Activity =>

		  This.manager.suspend;
		  This.Moneybox.Suspend;	       
		  This.Editor.suspend;
		  This.Shell.suspend;
		  This.game.Suspend;
		  This.Midiconsole.Suspend;

		  This.contacts.Suspend;
		  This.planning.Suspend;
		  This.Stocks.Suspend;
		  This.Accounting.Suspend;
		  This.Dialog.Suspend;
		  
		  
		  This.Mode_Cur := activity;	 
		  This.activity.Wake_up;
		  This.activity.Refresh;

	       when Contacts =>
		  This.manager.suspend;
		  This.Moneybox.Suspend;	       
		  This.Editor.suspend;
		  This.Midiconsole.suspend;
		  This.game.suspend;
		  This.Shell.suspend;
		  This.game.Suspend;
		  This.editor.Suspend;
		  This.moneybox.Suspend;
		  This.Accounting.Suspend;
		  This.Dialog.Suspend;
		  
		  
		  This.Mode_Cur := contacts;
		  This.contacts.Wake_up;
		  This.contacts.Refresh;

	       when Planning =>
		  This.contacts.Suspend;	       
		  This.activity.Suspend;


		  This.manager.suspend;
		  This.Moneybox.Suspend;	       
		  This.Editor.suspend;
		  This.Midiconsole.suspend;
		  This.game.suspend;
		  This.Shell.suspend;
		  This.Stocks.Suspend;
		  This.Accounting.Suspend;
		  This.Dialog.Suspend;
		  
		  
		  This.Mode_Cur := planning;
		  This.planning.Wake_up;
		  This.planning.Refresh;

	       when Stocks =>
		  This.Shell.suspend;
		  This.game.Suspend;
		  This.Midiconsole.Suspend;
		  This.editor.Suspend;
		  This.moneybox.Suspend;
		  This.manager.Suspend;


		  This.activity.Suspend;
		  This.contacts.Suspend;
		  This.planning.Suspend;
		  This.Accounting.Suspend;
		  This.Dialog.Suspend;
		  
		  This.Mode_Cur := stocks;
		  This.Stocks.Wake_up;
		  This.Stocks.Refresh;	       

	       when Accounting =>
		  
		  This.Shell.suspend;
		  This.game.Suspend;
		  This.Midiconsole.Suspend;
		  This.editor.Suspend;
		  This.moneybox.Suspend;
		  This.manager.Suspend;
		  This.activity.Suspend;
		  This.contacts.Suspend;
		  This.planning.Suspend;
		  This.Stocks.Suspend;
		  This.Accounting.Suspend;
		  This.Dialog.Suspend;
		  
		  
		  This.Mode_Cur := accounting;
		  This.accounting.Wake_up;
		  This.accounting.Refresh;
	       when Dialog =>
		  This.Shell.suspend;
		  This.game.Suspend;
		  This.Midiconsole.Suspend;
		  This.editor.Suspend;
		  This.moneybox.Suspend;
		  This.manager.Suspend;
		  

		  This.activity.Suspend;
		  This.contacts.Suspend;
		  This.planning.Suspend;
		  This.Stocks.Suspend;
		  This.accounting.Suspend;
		  This.Dialog.Suspend;
		  
		  This.Mode_Cur := Dialog;
		  This.Dialog.Wake_up;
		  This.Dialog.Refresh;
		  
		  
	    end case;
	    delay 0.2;
	    
	 or
	    accept Set_On_Esc(Is_Escape : in Boolean) do            
	       On_Esc := Is_Escape;
	    end Set_On_Esc;
	    
	    case This.Mode_Cur is
	       when Quit =>
		  --My_Ansi_Consoles.Clear_Screen;			
		  --Mode_Info_Status(W1, Current_Mode);
		  --Quit_Info_Status(W4);
		  --Main_Quit_Info_Status(W3, On_Esc);
		  null;
	       when others =>
		  --Main_Quit_Info_Status(W3, On_Esc);
		  null;
	    end case;
	 or
	    accept Initialize do	
	       

   	       --  This.Shell.Initialize;      

   	       --  This.game.Initialize;

   	       --  This.Midiconsole.Initialize;

   	       --  This.editor.Initialize;

   	       --  This.moneybox.Initialize;

   	       --  This.manager.Initialize;


   	       --  This.activity.Initialize;

   	       --  This.contacts.Initialize;

   	       --  This.planning.Initialize;

   	       --  This.Stocks.Initialize;

	       --  This.Accounting.Initialize;

   	       --  This.Dialog.Initialize;
	       


   	       This.Shell.Suspend;   

   	       This.Game.Suspend;

   	       This.Midiconsole.Suspend;

   	       This.Editor.Suspend;

   	       This.Moneybox.Suspend;

   	       This.Manager.Suspend;

   	       This.Activity.Suspend;

   	       This.Contacts.Suspend;

   	       This.Planning.Suspend;

   	       This.Stocks.Suspend;

	       This.Accounting.Suspend;

   	       This.Dialog.Suspend;

   	       --Text_Io.Put_Line("computer initialized");
	       
   	    end Initialize;
   	 or
	    
   	    accept Receive(Wchar : in Wide_Character) do
	       
   	       case This.Mode_Cur is
   		  when None =>  
   		     This.Shell.Receive(Wchar);
   		  when Shell =>  
   		     null;
   		  when Games =>  
   		     This.game.Receive(Wchar);
   		  when Midictrl =>  
   		     This.Midiconsole.Receive(Wchar);
   		  when Editor =>  
   		     This.editor.Receive(Wchar);
   		  when Moneybox =>  
   		     This.moneybox.Receive(Wchar);
   		  when Manager =>  
   		     This.manager.Receive(Wchar);

   		  when Activity =>  
   		     This.activity.Receive(Wchar);
   		  when Contacts =>  
   		     This.contacts.Receive(Wchar);
   		  when Planning =>  
   		     This.planning.Receive(Wchar);
   		  when Stocks =>
   		     This.Stocks.Receive(Wchar);
		  when Accounting =>
		     This.accounting.Receive(Wchar);
		  when Dialog =>
		     This.Dialog.Receive(Wchar);
		  when others =>
		     null;
   	       end case;
   	    end Receive;
	 or
   	    accept Page_Down do
	       case This.Mode_Cur is
   		  when None =>  
   		     This.Shell.Page_Down;
   		  when Shell =>  
   		     null;
   		  when Games =>  
   		     This.game.Page_Down;
   		  when Midictrl =>  
   		     This.Midiconsole.Page_Down;
   		  when Editor =>  
   		     This.editor.Page_Down;
   		  when Moneybox =>  
   		     This.moneybox.Page_Down;
   		  when Manager =>  
   		     This.manager.Page_Down;

   		  when Activity =>  
   		     This.activity.Page_Down;
   		  when Contacts =>  
   		     This.contacts.Page_Down;
   		  when Planning =>  
   		     This.planning.Page_Down;
   		  when Stocks =>
   		     This.Stocks.Page_Down;
		  when Accounting =>
		     This.accounting.Page_Down;
		  when Dialog =>
		     This.Dialog.Page_Down;
		  when others =>
		     null;
   	       end case;
	    end Page_Down;
   	 or
   	    accept Page_Up do
	       case This.Mode_Cur is
   		  when None =>  
   		     This.Shell.Page_Up;
   		  when Shell =>  
   		     null;
   		  when Games =>  
   		     This.game.Page_Up;
   		  when Midictrl =>  
   		     This.Midiconsole.Page_Up;
   		  when Editor =>  
   		     This.editor.Page_Up;
   		  when Moneybox =>  
   		     This.moneybox.Page_Up;
   		  when Manager =>  
   		     This.manager.Page_Up;

   		  when Activity =>  
   		     This.activity.Page_Up;
   		  when Contacts =>  
   		     This.contacts.Page_Up;
   		  when Planning =>  
   		     This.planning.Page_Up;
   		  when Stocks =>
   		     This.Stocks.Page_Up;
		  when Accounting =>
		     This.accounting.Page_Up;
		  when Dialog =>
		     This.Dialog.Page_Up;
		  when others =>
		     null;
   	       end case;
	    end Page_Up;
   	 or
   	    accept Up_Arrow do
   	       case This.Mode_Cur is
   		  when None =>  
   		     This.Shell.Up_Arrow;
   		  when Shell =>  
   		     null;
   		  when Games =>  
   		     This.game.Up_Arrow;
   		  when Midictrl =>  
   		     This.Midiconsole.Up_Arrow;
   		  when Editor =>  
   		     This.editor.Up_Arrow;
   		  when Moneybox =>  
   		     This.moneybox.Up_Arrow;
   		  when Manager =>  
   		     This.manager.Up_Arrow;

   		  when Activity =>  
   		     This.activity.Up_Arrow;
   		  when Contacts =>  
   		     This.contacts.Up_Arrow;
   		  when Planning =>  
   		     This.planning.Up_Arrow;
   		  when Stocks =>
   		     This.Stocks.Up_Arrow;
		  when Accounting =>
		     This.accounting.Up_Arrow;
		  when Dialog =>
		     This.Dialog.Up_Arrow;
		  when others =>
		     null;
   	       end case;
   	    end up_arrow;
   	 or
   	    accept Down_Arrow do
   	       case This.Mode_Cur is
   		  when None =>  
   		     This.Shell.Down_Arrow;
   		  when Shell =>  
   		     null;
   		  when Games =>  
   		     This.game.Down_Arrow;
   		  when Midictrl =>  
   		     This.Midiconsole.Down_Arrow;
   		  when Editor =>  
   		     This.editor.Down_Arrow;
   		  when Moneybox =>  
   		     This.moneybox.Down_Arrow;
   		  when Manager =>  
   		     This.manager.Down_Arrow;

   		  when Activity =>  
   		     This.activity.Down_Arrow;
   		  when Contacts =>  
   		     This.contacts.Down_Arrow;
   		  when Planning =>  
   		     This.planning.Down_Arrow;
   		  when Stocks =>
   		     This.Stocks.Down_Arrow;
		  when Accounting =>
		     This.accounting.Down_Arrow;
		  when Dialog =>
		     This.Dialog.Down_Arrow;
		  when others =>
		     null;
   	       end case;
   	    end Down_Arrow;
   	 or
   	    accept Left_Arrow;
   	 or
   	    accept Right_Arrow;   	 
   	 or
   	    accept Del;
   	 or
   	    accept Begin_Of do
	       case This.Mode_Cur is
   		  when None =>  
   		     This.Shell.Begin_Of;
   		  when Shell =>  
   		     null;
   		  when Games =>  
   		     This.game.Begin_Of;
   		  when Midictrl =>  
   		     This.Midiconsole.Begin_Of;
   		  when Editor =>  
   		     This.editor.Begin_Of;
   		  when Moneybox =>  
   		     This.moneybox.Begin_Of;
   		  when Manager =>  
   		     This.manager.Begin_Of;

   		  when Activity =>  
   		     This.activity.Begin_Of;
   		  when Contacts =>  
   		     This.contacts.Begin_Of;
   		  when Planning =>  
   		     This.planning.Begin_Of;
   		  when Stocks =>
   		     This.Stocks.Begin_Of;
		  when Accounting =>
		     This.accounting.Begin_Of;
		  when Dialog =>
		     This.Dialog.Begin_Of;
		  when others =>
		     null;
   	       end case;
	    end Begin_Of;
   	 or
   	    accept End_Of do
	       case This.Mode_Cur is
   		  when None =>  
   		     This.Shell.End_Of;
   		  when Shell =>  
   		     null;
   		  when Games =>  
   		     This.game.End_Of;
   		  when Midictrl =>  
   		     This.Midiconsole.End_Of;
   		  when Editor =>  
   		     This.editor.End_Of;
   		  when Moneybox =>  
   		     This.moneybox.End_Of;
   		  when Manager =>  
   		     This.manager.End_Of;

   		  when Activity =>  
   		     This.activity.End_Of;
   		  when Contacts =>  
   		     This.contacts.End_Of;
   		  when Planning =>  
   		     This.planning.End_Of;
   		  when Stocks =>
   		     This.Stocks.End_Of;
		  when Accounting =>
		     This.accounting.End_Of;
		  when Dialog =>
		     This.Dialog.End_Of;
		  when others =>
		     null;
   	       end case;
	    end End_Of;
   	 or
   	    accept Overwrite;
   	 or
   	    accept Screen_Print;
	    
	 end select;
      end loop;
      
   end Computer_Process;
   
   
   
   procedure Bell(Quiet : in boolean) is
   begin
      if not Quiet then
	 Ansi.Console.Beep;
      end if;
   end Bell;
      
   
   
   
   
   procedure Main (This : in out Computer_Type) is
      End_Of_Task : Boolean := False;
      Success : Boolean := False;
      
      
      End_Of_Program : Boolean := False;
      Mode : Mode_Enum := None;      
      
      
   begin
      
      This.Proc.Initialize;

      This.Proc.Switch(None);
      --This.Proc.Initialize;
      --if Is_Regular_File(Home_Dir & "/bin/hello") then
	-- Errno := System(Home_Dir & "/bin/hello" & Character'Val(0));
      --end if;
      --This.Proc.Switch(None);
      while not End_Of_Task loop
	 
	 declare
	    Wchar : Wide_Character := ' ';
	 begin
	    
	    case This.Term_Name is
	       when Linux =>

		  begin
		     This.Proc.Mode(Mode);
		     W_Io.Get_Immediate(Wchar);
		     --Matrix_Saver.Suspend;
		     case Wchar is
			when Wide_Character'Val(27) =>                                       
			   This.Proc.Set_On_Esc(True);
			   W_Io.Get_Immediate(Wchar);         
			   case Wchar is
			      when Wide_Character'Val(27) =>                             
				 

				 case Mode is                                                            
				    when games .. Accounting =>
				       This.Proc.Reset;                                 
				    when Shell =>
				       null;
				    when None =>

				       This.Proc.Set_On_Esc(False);
				       
				       This.Proc.Switch(Quit);  

				       End_Of_Program := True;
				       
				    when others =>
				       if End_Of_Program then         
					  
					  --This.Proc.Switch(Quit);
					  
					  This.Proc.Halt;
					  
					  exit;
				       end if;
				 end case;                          
			      when others =>
				 This.Proc.Mode(Mode);
				 case Mode is
				    
				    when Quit =>
				       if End_Of_Program then         
					  
					  --This.Proc.Switch(Quit);

					  This.Proc.Halt;
					  
					  exit;
				       end if;
				       
				    when others =>
				       This.Proc.Set_On_Esc(False);
				       
				       --This.Proc.Switch(mode);
				       End_Of_Program := False;
				 end case;
			   end case;                     
			   
			   case Wchar is
			      when Wide_Character'Val(91) =>                           
				 W_Io.Get_Immediate(Wchar);                           
				 This.Proc.Set_On_Esc(False);                           
				 case Wchar is
				    when Wide_Character'Val(49) =>
				       W_Io.Get_Immediate(Wchar);                
				       case Wchar is
					  when Wide_Character'Val(55) =>
					     null;--  Text_Io.Put_Line(" -- F6");
					     This.Proc.Switch(Activity);
					     W_Io.Get_Immediate(Wchar);                  
					  when Wide_Character'Val(56) =>
					     null;--  Text_Io.Put_Line(" -- F7");
					     This.Proc.Switch(Stocks);
					     W_Io.Get_Immediate(Wchar);                  
					  when Wide_Character'Val(57) =>
					     null;--  Text_Io.Put_Line(" -- F8");
					     This.Proc.Switch(accounting);
					     W_Io.Get_Immediate(Wchar);                  
					  when Wide_Character'Val(126) =>                     
					     null;--  Text_Io.Put_Line(" -- begin");
					     This.Proc.Begin_Of;
					  when others =>
					     null;
				       end case;                      
				    when Wide_Character'Val(50) =>                    
				       W_Io.Get_Immediate(Wchar);
				       case Wchar is
					  when Wide_Character'Val(48) =>
					     null;--  Text_Io.Put_Line(" -- F9");
					     This.Proc.Switch(Contacts);
					     W_Io.Get_Immediate(Wchar);
					  when Wide_Character'Val(49) =>
					     null;--  Text_Io.Put_Line(" -- F10");
					     This.Proc.Switch(Planning);

					     W_Io.Get_Immediate(Wchar);                                       
					  when Wide_Character'Val(51) =>                                  
					     null;--  Text_Io.Put_Line(" -- F11");
					     This.Proc.Switch(Dialog);
					     W_Io.Get_Immediate(Wchar);
					  when Wide_Character'Val(52) =>
					     null;--  Text_Io.Put_Line(" -- F12");
					     --This.Proc.Switch(Account);
					     W_Io.Get_Immediate(Wchar);
					  when Wide_Character'Val(53) =>                            
					     null;  Text_Io.Put_Line(" -- Maj+F1");
					  when Wide_Character'Val(54) =>                            
					     null;  Text_Io.Put_Line(" -- Maj+F2");
					  when Wide_Character'Val(56) =>                            
					     null;  Text_Io.Put_Line(" -- Maj+F3");
					  when Wide_Character'Val(57) =>
					     null;  Text_Io.Put_Line(" -- Maj+F4");
					  when Wide_Character'Val(126) =>
					     null;--  Text_Io.Put_Line(" -- insert");                                
					  when others =>
					     null;                             
				       end case;                               
				    when Wide_Character'Val(51) =>                    
				       null;--  Text_Io.Put_Line(" -- del");                     
				       W_Io.Get_Immediate(Wchar);   
				    when Wide_Character'Val(52) =>                    
				       null;--  Text_Io.Put_Line(" -- end");                     
				       W_Io.Get_Immediate(Wchar);   
				       This.Proc.End_Of;
				    when Wide_Character'Val(53) =>
				       null;--  Text_Io.Put_Line(" -- page up");
				       This.Proc.Page_Up;
				       W_Io.Get_Immediate(Wchar);   
				    when Wide_Character'Val(54) =>
				       null;--  Text_Io.Put_Line(" -- page down");
				       This.Proc.Page_Down;
				       W_Io.Get_Immediate(Wchar);   
				    when Wide_Character'Val(65) =>
				       null;--  Text_Io.Put_Line(" -- up");
				       This.Proc.Up_Arrow;
				    when Wide_Character'Val(66) =>
				       null;--  Text_Io.Put_Line(" -- down");
				       This.Proc.Down_Arrow;
				    when Wide_Character'Val(67) =>
				       null;--  Text_Io.Put_Line(" -- right");
				       This.Proc.Right_Arrow;
				    when Wide_Character'Val(68) =>
				       null;--  Text_Io.Put_Line(" -- left");
				       This.Proc.Left_Arrow;
				    when Wide_Character'Val(91) =>
				       W_Io.Get_Immediate(Wchar);                
				       case Wchar is                               
					  when Wide_Character'Val(65) =>
					     null;--  Text_Io.Put_Line(" -- F1");                                 
					     This.Proc.Switch(MidiCtrl);
					  when Wide_Character'Val(66) =>
					     null;--  Text_Io.Put_Line(" -- F2");
					     This.Proc.Switch(Games);
					  when Wide_Character'Val(67) =>
					     null;--  Text_Io.Put_Line(" -- F3");                                 
					     This.Proc.Switch(Editor);
					  when Wide_Character'Val(68) =>
					     null;--  Text_Io.Put_Line(" -- F4");
					     This.Proc.Switch(Manager);
					  when Wide_Character'Val(69) =>
					     null;--  Text_Io.Put_Line(" -- F5");
					     This.Proc.Switch(Moneybox);
					     
					  when others =>
					     null;
				       end case;
				       
				    when others =>
				       
				       This.Proc.Reset;            
				       
				       End_Of_Program := False;

				       This.Proc.Receive(Wchar);
				       
				 end case;

			      when others =>

				 This.Proc.Set_On_Esc(False);

			   end case;                                       
			   
			when others =>                    
			   case Mode is
			      when Quit =>

				 This.Proc.Switch(none);

			      when others =>
				 null;
			   end case;

			   This.Proc.Set_On_Esc(False);

			   
			   End_Of_Program := False;
			   
			   This.Proc.Receive(Wchar);

		     end case;
		     
		  exception
		     
		     
		     
		     when Text_Io.End_Error =>
			

			--Bell(Quiet);
			delay 0.5;                   
			This.Proc.reset;

		  end;

	       when Xterm =>
		  
		  begin
		     This.Proc.Mode(Mode);
		     W_Io.Get_Immediate(Wchar);
		     --Matrix_Saver.Suspend;
		     case Wchar is
			when Wide_Character'Val(27) =>                                       
			   This.Proc.Set_On_Esc(True);
			   W_Io.Get_Immediate(Wchar);         
			   case Wchar is
			      when Wide_Character'Val(27) =>				    

				 case Mode is                                                            
				    when Games .. Accounting =>
				       This.Proc.Reset;                                 
				    when None =>

				       This.Proc.Set_On_Esc(False);                                 
				       This.Proc.Switch(Quit);                                 
				       End_Of_Program := True;
				    when Shell =>
				       null;
				    when others =>
				       if End_Of_Program then         
					  
					  --This.Proc.Switch(Quit);
					  This.Proc.Halt;
					  exit;
				       end if;
				 end case;                          
			      when others =>
				 This.Proc.Mode(Mode);
				 case Mode is
				    when Quit =>
				       if End_Of_Program then         
					  
					  --This.Proc.Switch(Quit);
					  This.Proc.Halt;
					  exit;
				       end if;
				    when Shell =>
				       null;
				    when others =>
				       This.Proc.Set_On_Esc(False);
				       This.Proc.Switch(mode);
				       End_Of_Program := False;
				 end case;
			   end case;                     
			   
			   case Wchar is
			      when Wide_Character'Val(79) =>                           
				 
				 W_Io.Get_Immediate(Wchar);
				 This.Proc.Set_On_Esc(False);
				 case Wchar is
				    when Wide_Character'Val(80) =>
				       null;--  Text_Io.Put_Line(" -- F1");                               
				       This.Proc.Switch(Midictrl);
				    when Wide_Character'Val(81) =>
				       null;--  Text_Io.Put_Line(" -- F2");
				       This.Proc.Switch(Games);
				    when Wide_Character'Val(82) =>
				       null;--  Text_Io.Put_Line(" -- F3");                               
				       This.Proc.Switch(Editor);
				    when Wide_Character'Val(83) =>
				       null;--  Text_Io.Put_Line(" -- F4");
				       This.Proc.Switch(Manager);

				    when others =>
				       null;
				 end case;
				 
			      when Wide_Character'Val(91) =>

				 This.Proc.Set_On_Esc(False);
				 W_Io.Get_Immediate(Wchar);              
				 case Wchar is
				    when Wide_Character'Val(49) =>
				       W_Io.Get_Immediate(Wchar);
				       case Wchar is
					  when Wide_Character'Val(53) =>
					     null;--  Text_Io.Put_Line(" -- F5");                                                                    
					     This.Proc.Switch(Moneybox);
					  when Wide_Character'Val(55) =>
					     null;--  Text_Io.Put_Line(" -- F6");
					     This.Proc.Switch(activity);
					  when Wide_Character'Val(56) =>
					     null;--  Text_Io.Put_Line(" -- F7");
					     This.Proc.Switch(Stocks);
					  when Wide_Character'Val(57) =>
					     null;--  Text_Io.Put_Line(" -- F8");
					     This.Proc.Switch(Accounting);
					  when others =>
					     null;
				       end case;
				       W_Io.Get_Immediate(Wchar);
				    when Wide_Character'Val(50) =>
				       W_Io.Get_Immediate(Wchar);
				       case Wchar is
					  when Wide_Character'Val(48) =>       
					     null;--  Text_Io.Put_Line(" -- F9");
					     This.Proc.Switch(Contacts);

					     W_Io.Get_Immediate(Wchar);
					  when Wide_Character'Val(49) =>
					     null;--  Text_Io.Put_Line(" -- F10");
					     This.Proc.Switch(Planning);

					     W_Io.Get_Immediate(Wchar);
					  when Wide_Character'Val(51) =>
					     null;--  Text_Io.Put_Line(" -- F11");
					     This.Proc.Switch(Dialog);
					     W_Io.Get_Immediate(Wchar);
					  when Wide_Character'Val(52) =>
					     --null;Text_Io.Put_Line(" -- F12");
					     --This.Proc.Switch(Account);
					     W_Io.Get_Immediate(Wchar);
					  when Wide_Character'Val(53) =>
					     null;Text_Io.Put_Line(" -- Maj+F1");                                 
					  when Wide_Character'Val(54) =>                            
					     null;Text_Io.Put_Line(" -- Maj+F2");
					  when Wide_Character'Val(56) =>                            
					     null;Text_Io.Put_Line(" -- Maj+F3");
					  when Wide_Character'Val(57) =>
					     null;Text_Io.Put_Line(" -- Maj+F4");
					  when Wide_Character'Val(126) =>
					     null;--  Text_Io.Put_Line(" -- insert");
					     
					  when others =>
					     null;                             
				       end case;                               
				       
				    when Wide_Character'Val(51) =>                    
				       null;--  Text_Io.Put_Line(" -- del");                           
				       W_Io.Get_Immediate(Wchar);                            
				    when Wide_Character'Val(53) =>
				       null;--  Text_Io.Put_Line(" -- page up");
				       This.Proc.Page_Up;
				       W_Io.Get_Immediate(Wchar);
				    when Wide_Character'Val(54) =>
				       null;--  Text_Io.Put_Line(" -- page down");
				       This.Proc.Page_Down;
				       W_Io.Get_Immediate(Wchar);
				    when Wide_Character'Val(65) =>
				       null;--  Text_Io.Put_Line(" -- up");
				       This.Proc.Up_Arrow;
				    when Wide_Character'Val(66) =>
				       null;--  Text_Io.Put_Line(" -- down");
				       This.Proc.Down_Arrow;
				    when Wide_Character'Val(67) =>
				       null;--  Text_Io.Put_Line(" -- right");
				       This.Proc.Right_Arrow;
				    when Wide_Character'Val(68) =>                          
				       null;--  Text_Io.Put_Line(" -- left");
				       This.Proc.Left_Arrow;
				    when Wide_Character'Val(70) =>
				       null;--  Text_Io.Put_Line(" -- end");
				       This.Proc.End_Of;
				    when Wide_Character'Val(72) =>
				       null;--  Text_Io.Put_Line(" -- begin");                                                              
				       This.Proc.Begin_Of;
				    when Wide_Character'Val(91) =>
				       W_Io.Get_Immediate(Wchar);                
				       case Wchar is                               
					  when Wide_Character'Val(69) =>
					     
					     -- screen print ?
					     
					     W_Io.Get_Immediate(Wchar);                  
					  when others =>
					     null;
				       end case;
				       
				    when others =>
				       
				       This.Proc.Reset;            
				       
				       End_Of_Program := False;

				       This.Proc.Receive(Wchar);
				       
				 end case;

			      when others =>


				 This.Proc.Set_On_Esc(False);



				 
			   end case;                                       

			when others =>                    
			   case Mode is
			      when Quit =>
				 This.Proc.Switch(none);
			      when others =>
				 null;
			   end case;
			   
			   This.Proc.Set_On_Esc(False);
			   
			   End_Of_Program := False;
			   
			   This.Proc.Receive(Wchar);
			   
		     end case;

		  exception
		     
		     -- A la saisie de Ctrl+D End Error is raised.
		     
		     when Text_Io.End_Error =>
			
			--Bell(Quiet);
			delay 0.5;                   
			This.Proc.reset;
			
		  end;            

		  

	       when others =>
		  null;
	    end case;
	 end;
	 
      end loop;
      
   exception
      when W_Io.End_Error =>
	 null;
	 
	 --This.Proc.Halt;


   end Main;
   
   -------------------------------------------------------------------------------------------------------------
   --                                                                                                         --
   --
   -------------------------------------------------------------------------------------------------------------
   
   
   
   procedure Run (This : in out Computer_Type) is
      
   begin
      declare
	 Help_Parameter : constant Parameters.Parameter_Record :=
	   Get_Parameter(Interface_Record(This), Help);
	 Version_Parameter : constant Parameters.Parameter_Record :=
	   Get_Parameter(Interface_Record(This), Computer.Version);
	 Term_Name_Parameter : constant Parameters.Parameter_Record :=
	   Get_Parameter(Interface_Record(This), Term_Name);
	 Initialize_Parameter : constant Parameters.Parameter_Record :=
	   Get_Parameter(Interface_Record(This), Initialize);
	 Add_Parameter : constant Parameters.Parameter_Record :=
	   Get_Parameter(Interface_Record(This), Add);
	 Remove_Parameter : constant Parameters.Parameter_Record :=
	   Get_Parameter(Interface_Record(This), Remove);
	 Total_Parameter : constant Parameters.Parameter_Record :=
	   Get_Parameter(Interface_Record(This), Total);
      begin
	 

	 if Help_Parameter.Is_Setted then
	    Interfaces.Parameters_Descriptions(Interface_Record(This));
	    This.Proc.Halt;
	    Cpu_Process.Halt;
	    return;
	 else
	    if Version_Parameter.Is_Setted then
	       Text_Io.Put_Line(Versions.Version_Io.To_String(Versions.Version));

	       This.Proc.Halt;
	       Cpu_Process.Halt;
	       return;
	    end if;	    
	 end if;

	 --Interfaces.Print_Parameters(Interf);
	 if Term_Name_Parameter.Is_Setted then
	    begin
	       This.Term_Name := Term_Enum'Value(Handling.To_String(Term_Name_Parameter.Value.all));
	    exception
	       when Constraint_Error =>
		  Text_Io.Put_Line("Uncknow terminal name : " & Handling.To_String(Term_Name_Parameter.Value.all));
		  This.Proc.Halt;
		  Cpu_Process.Halt;
		  return;
	    end;
	 else
	    Term_Init(This);
	 end if;

	 if Initialize_Parameter.Is_Setted then
	    Total_Sum := Total_Type'Value(Handling.To_String(Initialize_Parameter.Value.all));
	    This.Proc.Halt;
	    Cpu_Process.Halt;
	    return;
	 end if;

	 if Add_Parameter.Is_Setted then
	    Total_Sum := Total_Sum + Total_Type'Value(Handling.To_String(Add_Parameter.Value.all));
	    This.Proc.Halt;
	    Cpu_Process.Halt;
	    return;
	 end if;

	 if Remove_Parameter.Is_Setted then
	    Total_Sum := Total_Sum + Total_Type'Value(Handling.To_String(Remove_Parameter.Value.all));
	    This.Proc.Halt;
	    Cpu_Process.Halt;
	    return;
	 end if;

	 if Total_Parameter.Is_Setted then
	    Text_Io.Put_Line(Total_Type'Image(Total_Sum));
	    This.Proc.Halt;
	    Cpu_Process.Halt;
	    return;
	 end if;

	 
	 
	 
      end;
      
      
      
      
      
      Computer.Main.Initialize(This);
      
      
      if Is_Regular_File("Projects.lst") then
	 Projects_Manager.Manager_Load(This.Projects, "Projects.lst");
      end if;
      if Is_Regular_File("Archives/Projects.lst") then
	 Projects_Manager.Archives_Load(This.Archives, "Archives/Projects.lst");      
      end if;
      --  Put_Line("Projects count : " & Integer'Image(Integer(Length(This.Projects.List))));
      --  Put_Line("Archives count : " & Integer'Image(Integer(Length(This.Archives.List))));
      
      
            
      Append(This.Projects.List, new Project_Record ' (Null_Project));

      --This.Projects.Projects_Num := This.Projects.Projects_Num + 1;
      if Nb_Of_Instrument > 1 then
	 Text_Io.Put_Line("Creating Bandmaster");
	 This.Instruments := new Sequencer.Bandmaster_Record(Instrument_Id(Nb_Of_Instrument-2));
	 
	 Text_Io.Put_Line("Bandmaster created");
	 This.Instruments.Initialize(True);
	 Text_Io.Put_Line("Bandmaster initialized");
      end if;
      --Text_Io.Put_Line("Greetings " & Getenv("USER").all & "!");         
      Cpu_Process.Initialize;
      
      Main(This);
      
      Projects_Manager.Manager_Save(This.Projects, "Projects.lst");
      Projects_Manager.Archives_Save(This.Archives, "Archives/Projects.lst");
      delay 0.2;
      Cpu_Process.Halt;
      

      
      Text_Io.Put_Line("End process.");
   exception
      when Spec_Error =>
	 Put_Line("Specification error raised.");
	 This.Proc.Halt;
	 Cpu_Process.Halt;	 
      when others =>
	 Put_Line("An error occured.");
	 
	 This.Proc.Halt;
	 Cpu_Process.Halt;
	 delay 1.0;
	 raise;
   end Run;

   procedure Finalize (This : in out Computer_Type) is
   begin
      if This.Instruments /= null then
	 for Id in This.Instruments.Orchester'Range loop
	    if This.Instruments.Orchester(Id).Output_Device_Driver.Output /= null then
	       Computer.Midi.Devices.Close(This.Instruments.Orchester(Id).Output_Device_Driver.Output.all);
	    end if;
	 end loop;
      end if;
   end Finalize;
   
   procedure Initialize(Wins : out Accounting_Windows_Type;
			Space_Left : in Line_Range;
			Width      : in Column_Range;
			L       : in Line_Range;
			C        : in Column_Range) is
   begin
      
      
      Wins.Voice_Num_Win := (L+2, C, Space_Left-2, 10,  
			     Cyan, Window);
      Wins.Acc_Num_Win := (L+2, C+10, Space_Left-2, 8,  
			   Cyan, Window);
      Wins.Total_Ht_Win := (L+2, C+18, Space_Left-2, 16,  
			    Cyan, Window);
      Wins.Total_TVA_Win := (L+2, C+34, Space_Left-2, 16,  
			     Cyan, Window);
      Wins.Total_TTC_Win := (L+2, C+50, Space_Left-2, 16,  
			     Cyan, Window);
      Wins.Date_Win := (L+2, C+66, Space_Left-2, 22,  
		    Cyan, Window);
      
      Wins.Peer_Win := (L+2, C+88, Space_Left-2, Width-(C+88+2),  
			Cyan, Window);
	 
      Initialize(Wins.Voice_Num_Win, L+2, C, Space_Left-2, 10,  Cyan, Red);
      Initialize(Wins.Acc_Num_Win, L+2, C+10, Space_Left-2, 8,  Cyan, Red);
      Initialize(Wins.Total_Ht_Win, L+2, C+18, Space_Left-2, 16, Cyan, Red);
      Initialize(Wins.Total_TVA_Win, L+2, C+34, Space_Left-2, 16, Cyan, Red);
      Initialize(Wins.Total_TTC_Win, L+2, C+50, Space_Left-2, 16, Cyan, Red);
      Initialize(Wins.Date_Win, L+2, C+66, Space_Left-2, 22, Cyan, Red);
      Initialize(Wins.Peer_Win, L+2, C+88, Space_Left-2, Width-(C+88+2), Cyan, Red);
      
   end Initialize;
   
   
   
end Computer.Main ;