COP-3212: Intermediate Programming


Running Ada on UNIX

Setting up Ada on UNIX


For the time being, you can only use serss0 to run Ada programs on Unix

If you do not have access to serss0, you can log onto serss1, and then issue

	rlogin serss0

this will get you onto serss0. When you log off, you will need to log off serss0, and then serss1.


You must set up your .cshrc file in order to run Ada programs on UNIX. There are two ways to do this:

  1. I have included a file called ada.cshrc in the cbin directory in my home directory. It has a basic .cshrc file with the Ada environment variables in it. This is the easier way to set up .cshrc. Just copy the file to your .cshrc file
    	cp  ~downeyt/cbin/ada.cshrc  .cshrc
    

    then proceed with executing your .cshrc.

  2. For those of you who have customized your .cshrc file and do not want to lose your customizations, I have included a file called ada.include in the cbin directory in my home directory. This file contains all the Ada environment variables and can be included into your .cshrc file.The full path name to this file is:
    	~downeyt/cbin/ada.include
    

    The easiest way to add this to your .cshrc file is to call the emacs editor

    	emacs .cshrc
    

    Then move the cursor to the end of the file (this is very important) and issue the command

    	CTRL-X I
    	~downeyt/cbin/ada.include
    

    then save your changes and exit

    	CTRL-X CTRL-S
    	CTRL-X CTRL-C
    

    and continuing with executing your .cshrc.

Back to Index


Executing .cshrc

Once you have set this up then you must be sure to re-execute your .cshrc file. There are two ways to do this

  1. Log out and then log in again
  2. Or, issue the commands
    	set path = ()
    	source .cshrc
    

Back to Index


Ada commands for UNIX

Now that you have set up Ada for your UNIX account, you can run an Ada program. These are the steps you would follow:

  1. In order to do this, you must first create the source file using an editor. Be sure that all your Ada files have an extension of .adb or .ads.
  2. Assuming that your file is stored in prog.adb, you then issue the command
    	gcc -c prog.adb
    
  3. If this compiles cleanly, then you can bind and link it
    	gnatbl -o prog prog.ali
    
  4. To run the program, issue the command
    	prog
    
  5. Use the cat command to have the contents of the file displayed on the screen (only needed when creating a listing to be handed in)
    	cat prog.adb
    

Back to Index


End of file key on UNIX

When you test for End_Of_File in an Ada program, UNIX is looking for the CRTL-D key. So, if you are using a while not End_Of_File loop and reading input from the terminal, the user can terminate the loop by entering CTRL-D.

Be careful not to enter CTRL-Z, since this will stop your program, not the loop. When you press CTRL-Z on a UNIX system, the current job is interupted (not terminated) and placed in the background. To recover from such an error, you can type the fg command to bring the job back to the foreground. Then you can press CTRL-D to terminate the loop.

Back to Index


Using Ada mode in emacs on UNIX

I have placed a file called ada.emacs in my cbin directory. It contains the LISP code needed to use Ada mode in emacs. Ada mode will automatically format your source file as you type. It will also check that your end statements match the statement that you are finishing. Just remember to use CTRL-J at the end of a line, instead of the RETURN key. There are two methods for setting this up:

  1. If you do not have a .emacs file already, then just copy my file to your .emacs file
    	cp ~downeyt/cbin/ada.emacs .emacs
    
  2. If you already have a .emacs file that you don't want to lose, then just include my file in your .emacs file. First call up the .emacs file, then include my file:
    	CTRL-X I
    	~downeyt/cbin/ada.emacs
    

I have also included some commented code in the ada.emacs file. This is for a function that allows you to abbreviate the words procedure, function, and package with pr, fu, and pa respectively. In order to implement this, you must copy the file prog.abrv.elc from my cbin directory into your root directory, then edit the .emacs file and remove the semicolons from the definition of the function.

Back to Index


Running Ada on DOS

Ada commands for DOS

First, you must download Ada95 for DOS. Once you have done this, and set up your DOS machine for Ada, these are the steps you would follow to run a program:

  1. First create the source file using a text editor. Be sure that all your Ada files have an extension of .adb or .ads.
  2. Assuming that your file is stored in prog.adb, you then issue the command
    	gcc -c prog.adb
    
  3. If this compiles cleanly, then you can bind and link it
    	gnatbl -o prog.exe prog.ali
    
  4. To run the program, issue the command
    	prog
    
  5. Use the type command to have the contents of the file displayed on the screen (only needed when creating a listing to be handed in)
    	type prog.adb
    

Back to Index


Creating a listing to be handed in from DOS

If you haven't downloaded Adacaps, then you will need to in order to create the listing that I want. In the Adacaps zip file, there is another zip file called Script.zip. Unzip this, and you will have a file called script.com. You will use this to echo all the output to your screen into a file. It is very similar to the UNIX script command.

When handing in an assignment, I would like to see a copy of all the output on your terminal when you compile, link, and run the program. This listing should include all the input and output to the program as well as a listing of the complete program. The command to do this is script.

	script

When you run script, a new process is created. All information that is displayed on the terminal in this process is also copied to a file called typescri in your original process. Once inside the subprocess, you would issue the commands to compile, link, and run the Ada program, then you would use the type command to display the contents of the program source files. When you are done, you press CRTL-Z to exit the subprocess, then you can print the typescri file using print or by calling up a text editor and printing the file.

The default file is typescri, but it is possible to use any file by including it in the script command.

	script -f file

Then you would print file instead of typescri.

Back to Index


End of file key on DOS

When you test for End_Of_File in an Ada program, DOS is looking for the CRTL-Z key. So, if you are using a while not End_Of_File loop and reading input from the terminal, the user can terminate the loop by entering CTRL-Z.

Back to Index


You are visitor number [an error occurred while processing this directive] to visit this page since 10/4/96.