www.delorie.com/gnu/docs/gcc/gnat_ug_12.html   search  
Buy the book!

Untitled Document

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

1.5.1 Building a New Program with Glide

The simplest way to invoke Glide is to enter glide at the command prompt. It will generally be useful to issue this as a background command, thus allowing you to continue using your command window for other purposes while Glide is running:

$ glide&

Glide will start up with an initial screen displaying the top-level menu items as well as some other information. The menu selections are as follows

For this introductory example, you will need to create a new Ada source file. First, select the Files menu. This will pop open a menu with around a dozen or so items. To create a file, select the Open file... choice. Depending on the platform, you may see a pop-up window where you can browse to an appropriate directory and then enter the file name, or else simply see a line at the bottom of the Glide window where you can likewise enter the file name. Note that in Glide, when you attempt to open a non-existent file, the effect is to create a file with that name. For this example enter `hello.adb' as the name of the file.

A new buffer will now appear, occupying the entire Glide window, with the file name at the top. The menu selections are slightly different from the ones you saw on the opening screen; there is an Entities item, and in place of Glide there is now an Ada item. Glide uses the file extension to identify the source language, so `adb' indicates an Ada source file.

You will enter some of the source program lines explicitly, and use the syntax-oriented template mechanism to enter other lines. First, type the following text:
with Ada.Text_IO; use Ada.Text_IO;
procedure Hello is

Observe that Glide uses different colors to distinguish reserved words from identifiers. Also, after the procedure Hello is line, the cursor is automatically indented in anticipation of declarations. When you enter begin, Glide recognizes that there are no declarations and thus places begin flush left. But after the begin line the cursor is again indented, where the statement(s) will be placed.

The main part of the program will be a for loop. Instead of entering the text explicitly, however, use a statement template. Select the Ada item on the top menu bar, move the mouse to the Statements item, and you will see a large selection of alternatives. Choose for loop. You will be prompted (at the bottom of the buffer) for a loop name; simply press the Enter key since a loop name is not needed. You should see the beginning of a for loop appear in the source program window. You will now be prompted for the name of the loop variable; enter a line with the identifier ind (lower case). Note that, by default, Glide capitalizes the name (you can override such behavior if you wish, although this is outside the scope of this introduction). Next, Glide prompts you for the loop range; enter a line containing 1..5 and you will see this also appear in the source program, together with the remaining elements of the for loop syntax.

Next enter the statement (with an intentional error, a missing semicolon) that will form the body of the loop:
Put_Line("Hello, World" & Integer'Image(I))

Finally, type end Hello; as the last line in the program. Now save the file: choose the File menu item, and then the Save buffer selection. You will see a message at the bottom of the buffer confirming that the file has been saved.

You are now ready to attempt to build the program. Select the Ada item from the top menu bar. Although we could choose simply to compile the file, we will instead attempt to do a build (which invokes gnatmake) since, if the compile is successful, we want to build an executable. Thus select Ada build. This will fail because of the compilation error, and you will notice that the Glide window has been split: the top window contains the source file, and the bottom window contains the output from the GNAT tools. Glide allows you to navigate from a compilation error to the source file position corresponding to the error: click the middle mouse button (or simultaneously press the left and right buttons, on a two-button mouse) on the diagnostic line in the tool window. The focus will shift to the source window, and the cursor will be positioned on the character at which the error was detected.

Correct the error: type in a semicolon to terminate the statement. Although you can again save the file explicitly, you can also simply invoke Ada => Build and you will be prompted to save the file. This time the build will succeed; the tool output window shows you the options that are supplied by default. The GNAT tools' output (e.g., object and ALI files, executable) will go in the directory from which Glide was launched.

To execute the program, choose Ada and then Run. You should see the program's output displayed in the bottom window:

Hello, world 1
Hello, world 2
Hello, world 3
Hello, world 4
Hello, world 5

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

  webmaster     delorie software   privacy  
  Copyright 2003   by The Free Software Foundation     Updated Jun 2003