----------------------------------
-- Port of Glade-1.03p to Win32 --
----------------------------------

	The GLADE/GNAT implementation of Ada DSA requires a few modifications
to work with Windows 95. The modifications are needed in two separate
areas. First, we need to port the the Garlic libraries to use the MS
Winsock implementation of TCP/IP sockets. And second, to port the 
gnatdist utility, we need to replace calls to Unix utilities with the
corresponding *.bat utilities (this avoids the need to bring in a Windows
shell environment like bash). 

The good news is that absolutely no MS products are needed to get 
the examples to work. The GNAT provided mingw32 libraries are sufficient.

Instructions:
1.	UnTar the distribution using gzip (gzip -d glade103.taz) and 
	tar (tar xf glade103.tar) launching from the C:\ root directory. 
	The gnatdist utilities will be placed in \usr\bin. 
	The garlic libraries will be placed in \glade-1.03p\garlic.

2.	(a) You will have to execute the make.bat located in the garlic 
	subdirectory to build the garlic library up from the source.
	(b) To build gnatdist, launch the make.bat file located in the dist 
	subdirectory.  This will create dist1.exe and copy it to c:\usr\bin.

3.	Instructions for how to build DSA Ada applications using GLADE are 
	included in the GLADE documentation ftp://cs.nyu.edu/pub/gnat/glade.
	Remember that GLADE requires that you have a network node assigned
	to your PC. 

Example:
	Banking Sim. Go to the example directory and run "gnatdist -v simcity".
        Once compilation is complete, open two windows.
	Launch "bank_server" in one window and create an account.
	Launch "bank_client --slave" in the other window and make a deposit.
        Further instructions are in the local readme. 

Bonus Example: Interactive Chat program and 
               Chat configuration using DSA RACW.

Download Win32 glade-1.03p (tar+gzip 300K)

---------------------------------------------------------------------------
Porting Notes:
---------------------------------------------------------------------------
The most significant modification needed to GLADE is in the way Winsock 
handles socket calls. First off, before any application can use Winsock,
it has to make a call to WSAStartup. A small C routine is contained in
a file called winsock0.c that handles this during the elaboration of 
the S-GARTHI.ADS package spec (I used a C-routine to avoid any elaboration
order issues that may arise, it will pop up a Host/Version message if Winsock is
correctly installed on your system. If the host name shows up incorrectly
you have a Winsock that does not include a working 'gethostname', a source
code workaround is possible).  The linking of the winsock0.o object file 
is handled by gnatdist.bat. Second, most of the Winsock calls expect a
Stdcall pragma convention rather than a C convention. Lastly, we can only 
use Send and Recv on socket calls and not the Write and Read that GLADE 
uses under Unix. This required a modification to S-GARTCP.ADB.

A couple of minor changes are in the way Winsock defines their Hostent 
structure, "close" has to be renamed as "closesocket", and "error" has
a special "WSAGetLastError" that we can use.  
See the file S-GARCON.ADS for platform specific constants.

Porting the GLADE remote launching facilities was not attempted.

Source code changes are indicated by a -- WIN32
------------------
File S-GARTHI.ADS:
      H_Addrtype  : C.Short;  -- WIN32 Hostent field was C.int
      H_Length    : C.Short;  -- WIN32 Hostent field was C.int
   pragma Import (Stdcall, C_Accept, "accept");  --  WIN32
   pragma Import (Stdcall, C_Bind, "bind");  --  WIN32
   pragma Import (Stdcall, C_Close, "closesocket");  --  WIN32 was "close"
   pragma Import (Stdcall, C_Connect, "connect");  --  WIN32
   pragma Import (Stdcall, C_Gethostbyaddr, "gethostbyaddr");  --  WIN32
   pragma Import (Stdcall, C_Gethostbyname, "gethostbyname");  --  WIN32
   pragma Import (Stdcall, C_Gethostname, "gethostname");  --  WIN32
   pragma Import (Stdcall, C_Getsockname, "getsockname");  --  WIN32
   pragma Import (Stdcall, C_Getsockopt, "getsockopt");  --  WIN32
   pragma Import (Stdcall, C_Inet_Addr, "inet_addr");  --  WIN32
   pragma Import (Stdcall, C_Listen, "listen");  --  WIN32
   pragma Import (Stdcall, C_Recv, "recv");  --  WIN32
   pragma Import (Stdcall, C_Send, "send");  --  WIN32
   pragma Import (Stdcall, C_Setsockopt, "setsockopt");  --  WIN32
   pragma Import (Stdcall, C_Shutdown, "shutdown");  --  WIN32
   pragma Import (Stdcall, C_Socket, "socket");  --  WIN32
   function Start_Winsock return Integer;  --  WIN32 "winsock0.c"
   pragma Import (C, Start_Winsock);       --  WIN32 Link "winsock0.o"
   Started : Integer := Start_Winsock;     --  WIN32 Startup Winsock
File S-GARTCP.ADB:
         --  WIN32 Code := Net.C_Read (FD, To_Chars_Ptr (Current), Rest);
         Code := Net.C_Recv (FD, To_Chars_Ptr (Current), Rest, 0);  --  WIN32
         --  WIN32 Code := Net.C_Write (FD, To_Chars_Ptr (Current), Rest);
         Code := Net.C_Send (FD, To_Chars_Ptr (Current), Rest, 0);  --  WIN32
File S-GARSER.ADB:
--  WIN32 @LAUNCHING_INCLUDED@with System.Garlic.Remote;
         --  WIN32 @LAUNCHING_INCLUDED@Remote.Detach;
File S-GAOSLI.ADS:
   --  WIN32 pragma Import (C, C_Errno, "@CERRNO@");
   pragma Import (Stdcall, C_Errno, "WSAGetLastError");  --  WIN32
File S-GARCON.ADS:
   Af_Inet        : constant := 2;                --  WIN32
   Sock_Dgram     : constant := 2;                --  WIN32
   Sock_Stream    : constant := 1;                --  WIN32
   So_Reuseaddr   : constant := 4;                --  WIN32
   Sol_Socket     : constant := 16#ffff#;         --  WIN32
   Host_Not_Found : constant := 11001;            --  WIN32
   Try_Again      : constant := 11002;            --  WIN32
   No_Recovery    : constant := 11003;            --  WIN32
   No_Data        : constant := 11004;            --  WIN32
   No_Address     : constant := No_Data;          --  WIN32



------------------------------------------------------------
The gnatdist utility is actually a batch file that makes a
call to dist1. Windows 95 expects that executables have 
names with extensions *.bat or *.exe, so that it was a simple 
matter to make calls to the appropriate batch commands.

File XE_UTILS.ADB:
      XE_Gcc          := Locate ("xe-gcc.bat");    --  WIN32
      Gcc             := Locate ("gcc.exe");       --  WIN32
      Mkdir           := Locate ("mkdir.bat");     --  WIN32
      Copy            := Locate ("cp.bat");        --  WIN32
      Chmod           := Locate ("chmod.bat");     --  WIN32
      Rm              := Locate ("rm.bat");        --  WIN32
      Gnatbind        := Locate ("gnatbind.exe");  --  WIN32
      Gnatlink        := Locate ("gnatlink.exe");  --  WIN32
      Gnatmake        := Locate ("gnatmake.exe");  --  WIN32
File XE_STUBS.ADB:
      Exec_File  : File_Name_Type := Executable & Str_To_Id (".exe");  -- WIN32
      if not Is_Regular_File (Exec_File) then  -- WIN32
            Message ("", Exec_File, " doesn't exist");  -- WIN32
      elsif Partitions.Table (Partition).Most_Recent > Exec_File then  -- WIN32
              (Partitions.Table (Partition).Most_Recent, Exec_File);  -- WIN32
      elsif Exec_File > Stamp_File then  -- WIN32
            Write_Stamp_Comparison (Exec_File, Stamp_File);  -- WIN32
      Produce_Partition_Executable               --  WIN32
        (Part_Name, Configuration, Executable);  --  WIN32
File XE_DEFS.ADB:
package body XE_Defs is  --  WIN32 version
File SDEFAULT.ADB:
package body Sdefault is  -- WIN32 version

---------------------------------------------------------------------------
Paul Pukite puk@umn.edu

The views and opinions expressed in this page are strictly those of the page author.
The contents of this page have not been reviewed or approved by the University of Minnesota.