comp.lang.ada
 help / color / mirror / Atom feed
* windows ada compiler error
@ 2003-10-14  4:05 Andrew
  2003-10-14  5:19 ` tmoran
  2003-10-14 20:42 ` Jeffrey Carter
  0 siblings, 2 replies; 7+ messages in thread
From: Andrew @ 2003-10-14  4:05 UTC (permalink / raw)


I have run into a bit of a problem when I compile the below program on a 
red hat 9.0 linux computer it runs just fine.. but if I try to compile 
it on a windows xp computer I get the following error.
==========================
Start Position is
across is <some number>
down is <some number>
Exit is located at
across is <some number>
down is <some number>
Found Exit

raised ADA.IO_EXCEPTION.NAME_ERROR : s-fileio.adb:869
======================
where <some number> is a randomly determined number

but I always get the
raised ADA.IO_EXCEPTION.NAME_ERROR : s-fileio.adb:869
error

is there something special that I need to add to get it to compile on a 
windows xp computer? Something that has to be changed?
just in case it matters
ftp://cs.nyu.edu/pub/gnat
that is where I got the windows compiler from
and the windows xp and the linux computer is the same computer (it's a 
dual boot).
===
source code below
===



-- This program is to randomly create a maze, using a multi-dimensional 
array.
-- Then it is to create a file called 'Map', and put that array into the 
file.

with TEXT_IO, ADA.NUMERICS.DISCRETE_RANDOM;
use TEXT_IO;
procedure Mazecreate is
    spot: CHARACTER;
    spott:character:='T';
    sitt: Boolean:=True;
    temprow: INTEGER:=5;  -- point of origin for map
    down: Integer:=10;  -- down map
    acros: INTEGER:=10; -- across map
    row: INTEGER:=1;
    rowstart:Integer;
    col: INTEGER:=1;
    colstart:INTEGER;
    FoundExit : INTEGER:=0;
    Move:CHARACTER;
    map_file:FILE_TYPE;
    type map_hold is array (INTEGER range <>, INTEGER range<>) of CHARACTER;
    map_array:map_hold(1..down,1..acros);
    direction: INTEGER;
    EntranceExit : INTEGER;

    package Number_IO is new INTEGER_IO(INTEGER);
    use Number_IO;
    package FLOAT1_IO is new FLOAT_IO(FLOAT);
    use FLOAT1_IO;

    -- this is used to randomly find the direction
    subtype Options is INTEGER range 1 .. 4;
    package Generate_Options is new Ada.Numerics.Discrete_Random(Options);
    use Generate_Options;
    A_Generator : Generate_Options.Generator;

    -- this is used to randomly find the beginning and ending of the maze
    subtype StartStop is INTEGER range 1 .. 10;
    package Generate_StartStop is new 
Ada.Numerics.Discrete_Random(StartStop);
    use Generate_StartStop;
    B_Generator : Generate_StartStop.Generator;



Begin
    -- *************************
    -- ** Section to load the **
    -- **  multi-dimensional  **
    -- **  array with stars   **
    -- *************************

    for i in 1..down loop
       for j in 1..acros loop
          map_array(i,j):='X';
       end loop;
    end loop;


    -- **************************
    -- ** Section to determine **
    -- **  the Start and Exit  **
    -- **     of the maze.     **
    -- **************************

Put_Line("Start Position is ");
Reset (B_Generator);
    EntranceExit:=Generate_StartStop.Random(B_Generator);
   Put_Line("across is" & Options'image(EntranceExit));

   row:=EntranceExit;
   temprow:=EntranceExit;
   rowstart:=EntranceExit;

Reset (B_Generator);
    EntranceExit:=Generate_StartStop.Random(B_Generator);
   Put_Line("down is" & Options'image(EntranceExit));

   col:=EntranceExit;
   colstart:=EntranceExit;

   map_array(row,col):='S';
Put_Line("Exit is located at ");
while temprow=row loop
Reset (B_Generator);
    EntranceExit:=Generate_StartStop.Random(B_Generator);
    row:=EntranceExit;
end loop;
Put_Line("across is" & Options'image(EntranceExit));

Reset (B_Generator);
    EntranceExit:=Generate_StartStop.Random(B_Generator);
   Put_Line("down is" & Options'image(EntranceExit));

   col:=EntranceExit;

   map_array(row,col):='E';




    -- ***********************
    -- ** Section to create **
    -- **  the entire maze  **
    -- ***********************

  row:=rowstart;
  col:=colstart;
while FoundExit /= 1 loop

Reset (A_Generator);
    direction:=Generate_Options.Random(A_Generator);
   --Put_Line("Selected direction is" & Options'image(direction));

   if direction=1 and row>1 then --north
      row:=row-1;
        if map_array(row,col)='E' then
           Put_Line("Found Exit");
           FoundExit:=1;
        else
           if map_array(row,col)/='S' then
              map_array(row,col):='P';
           end if;
        end if;
   elsif
      direction=2 and col<10 then --east
      col:=col+1;
        if map_array(row,col)='E' then
           Put_Line("Found Exit");
           FoundExit:=1;
        else
            if map_array(row,col)/='S' then
               map_array(row,col):='P';
            end if;
        end if;
   elsif
        direction=3 and row<10 then --south
      row:=row+1;
        if map_array(row,col)='E' then
           Put_Line("Found Exit");
           FoundExit:=1;
        else
            if map_array(row,col)/='S' then
               map_array(row,col):='P';
            end if;
        end if;
   elsif
        direction=4 and col>1 then --west
      col:=col-1;
        if map_array(row,col)='E' then
           Put_Line("Found Exit");
           FoundExit:=1;
        else
            if map_array(row,col)/='S' then
               map_array(row,col):='P';
            end if;
        end if;
   end if;

end loop;


   Open (map_file, out_FILE, "Map");

    -- *********************
    -- **   section to    **
    -- **    print the    **
    -- ** square of Stars **
    -- *********************

    if IS_OPEN(map_file) then
       for i in 1..down loop
          for j in 1..acros loop
          spot:=map_array(i,j);
             put (spot);
          end loop;
          --if j = 11 then
             NEW_LINE;
          --end if;
       end loop;
       Put(map_file, spott);
       CLOSE (map_file);

  else
      Put_Line("Map file didn't open .. Killing Program");

   end if;

   -- *********************
   -- ** section to move **
   -- ** through the map **
   -- *********************

    --putting player at start
    row:=rowstart;
    col:=colstart;
    FoundExit := 0;
while FoundExit /= 1 loop

    Put_Line("Which direction would you like to move?");
    Put("You can move ");
    if row>1 then
       if map_array(row-1,col)='P' then
       put("N ");
       end if;
    end if;
    if row<10 then
       if map_array(row+1,col)='P' then
       put("S ");
       end if;
    end if;
    if col>1 then
       if map_array(row,col-1)='P' then
       put("W ");
       end if;
    end if;
    if col<10 then
       if map_array(row,col+1)='P' then
       put("E ");
       end if;
    end if;
    Put(">");
    Get(Move);
    Put_Line(" moving");
    put(Move);

    if Move='N' then
       row:=row-1;
    elsif
      Move='S' then
       row:=row+1;
    elsif
      Move='W' then
       col:=col-1;
    elsif
      Move='E' then
       col:=col+1;
    else
       Put(" ");
    end if;
    if map_array(row,col)='E' then
       FoundExit :=1;
    end if;
end loop;

end Mazecreate;




^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: windows ada compiler error
  2003-10-14  4:05 windows ada compiler error Andrew
@ 2003-10-14  5:19 ` tmoran
  2003-10-14 15:29   ` Andrew
  2003-10-14 15:35   ` Andrew
  2003-10-14 20:42 ` Jeffrey Carter
  1 sibling, 2 replies; 7+ messages in thread
From: tmoran @ 2003-10-14  5:19 UTC (permalink / raw)


>red hat 9.0 linux computer it runs just fine.. but if I try to compile
>it on a windows xp computer I get the following error.
  I think you mean it compiles fine, but it doesn't execute fine.

>raised ADA.IO_EXCEPTION.NAME_ERROR : s-fileio.adb:869
  You might look at file s-fileio.adb, line 869, and see what it's
trying to do.  Better yet, use the Gnat facilities for printing a
walkback so it will show what line of your program caused the problem.
I used a compiler that prints walkbacks of user, not library, code
and got:

** Unhandled ADA.IO_EXCEPTIONS.NAME_ERROR
   File not found on open - Map
On Line Number 159 In MAZECREATE

You probably want a Create, not an Open.

  Your prof or TA should be helping you out.



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: windows ada compiler error
  2003-10-14  5:19 ` tmoran
@ 2003-10-14 15:29   ` Andrew
  2003-10-14 15:35   ` Andrew
  1 sibling, 0 replies; 7+ messages in thread
From: Andrew @ 2003-10-14 15:29 UTC (permalink / raw)




tmoran@acm.org wrote:
>>red hat 9.0 linux computer it runs just fine.. but if I try to compile
>>it on a windows xp computer I get the following error.
> 
>   I think you mean it compiles fine, but it doesn't execute fine.
> 
> 
>>raised ADA.IO_EXCEPTION.NAME_ERROR : s-fileio.adb:869
> 
>   You might look at file s-fileio.adb, line 869, and see what it's
> trying to do.  Better yet, use the Gnat facilities for printing a
> walkback so it will show what line of your program caused the problem.
> I used a compiler that prints walkbacks of user, not library, code
> and got:
> 
> ** Unhandled ADA.IO_EXCEPTIONS.NAME_ERROR
>    File not found on open - Map
> On Line Number 159 In MAZECREATE
> 
> You probably want a Create, not an Open.
> 
>   Your prof or TA should be helping you out.

thanks for the tip .. I'll look into it

as for a prof *L* I've been out of college for a few years now, and 
decided to try programming in Ada and a lot of what I used to know I've 
forgotten.  Although it is very much like riding a bike.. once you 
learn, and quite riding for a few years you can never forget all the 
ways to fall off of bike.




^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: windows ada compiler error
  2003-10-14  5:19 ` tmoran
  2003-10-14 15:29   ` Andrew
@ 2003-10-14 15:35   ` Andrew
  2003-10-14 16:17     ` Stephen Leake
  1 sibling, 1 reply; 7+ messages in thread
From: Andrew @ 2003-10-14 15:35 UTC (permalink / raw)




tmoran@acm.org wrote:
>>red hat 9.0 linux computer it runs just fine.. but if I try to compile
>>it on a windows xp computer I get the following error.
> 
>   I think you mean it compiles fine, but it doesn't execute fine.
> 
> 
>>raised ADA.IO_EXCEPTION.NAME_ERROR : s-fileio.adb:869
> 
>   You might look at file s-fileio.adb, line 869, and see what it's
> trying to do.  Better yet, use the Gnat facilities for printing a
> walkback so it will show what line of your program caused the problem.
> I used a compiler that prints walkbacks of user, not library, code
> and got:
> 
> ** Unhandled ADA.IO_EXCEPTIONS.NAME_ERROR
>    File not found on open - Map
> On Line Number 159 In MAZECREATE
> 
> You probably want a Create, not an Open.
> 
>   Your prof or TA should be helping you out.

i just typed man gnat and man gnatmake
what would I type to be able to read how to use the gnat facilities?
and also what would the command line be to do the walkback?




^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: windows ada compiler error
  2003-10-14 15:35   ` Andrew
@ 2003-10-14 16:17     ` Stephen Leake
  2003-10-14 19:06       ` Andrew
  0 siblings, 1 reply; 7+ messages in thread
From: Stephen Leake @ 2003-10-14 16:17 UTC (permalink / raw)


Andrew <eagletalon@chartermi.net> writes:

> i just typed man gnat and man gnatmake
> what would I type to be able to read how to use the gnat facilities?

GNAT 3.15p has an HTML version of its user guide and reference manual;
look in GNAT/Doc/...

You can also get 'info' versions in the file
gnat-3.15p-unx-docs.tar.gz.

> and also what would the command line be to do the walkback?

Use the gdb debugger (distributed with GNAT). Sample session:

$ gdb my_program.exe
gdb> break exception
gdb> run
(message about stopping on a line)
gdb> where

that shows you the stack. Then you can use normal debugging stuff to
figure it out; do 'help' in gdb, or find the gdb manual in GNAT/Doc.

-- 
-- Stephe



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: windows ada compiler error
  2003-10-14 16:17     ` Stephen Leake
@ 2003-10-14 19:06       ` Andrew
  0 siblings, 0 replies; 7+ messages in thread
From: Andrew @ 2003-10-14 19:06 UTC (permalink / raw)




Stephen Leake wrote:
> Andrew <eagletalon@chartermi.net> writes:
> 
> 
>>i just typed man gnat and man gnatmake
>>what would I type to be able to read how to use the gnat facilities?
> 
> 
> GNAT 3.15p has an HTML version of its user guide and reference manual;
> look in GNAT/Doc/...
> 
> You can also get 'info' versions in the file
> gnat-3.15p-unx-docs.tar.gz.
> 
> 
>>and also what would the command line be to do the walkback?
> 
> 
> Use the gdb debugger (distributed with GNAT). Sample session:
> 
> $ gdb my_program.exe
> gdb> break exception
> gdb> run
> (message about stopping on a line)
> gdb> where
> 
> that shows you the stack. Then you can use normal debugging stuff to
> figure it out; do 'help' in gdb, or find the gdb manual in GNAT/Doc.
> 

ahh thank you .. I'll look into all this




^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: windows ada compiler error
  2003-10-14  4:05 windows ada compiler error Andrew
  2003-10-14  5:19 ` tmoran
@ 2003-10-14 20:42 ` Jeffrey Carter
  1 sibling, 0 replies; 7+ messages in thread
From: Jeffrey Carter @ 2003-10-14 20:42 UTC (permalink / raw)


Andrew wrote:

> but I always get the
> raised ADA.IO_EXCEPTION.NAME_ERROR : s-fileio.adb:869
> error

That means there's a problem with your file name. Most likely, you're 
trying to open a file that doesn't exist. Since you're creating the 
file, you probably want to use Create rather than Open.

Your code is full of things that indicate you don't understand basic Ada 
concepts. I'll try to point them out so you can learn about them.

I notice that the code has a number of initialized variables that you 
never assign to. These are called constants, and should be declared as 
such. For example,

>    down: Integer:=10;  -- down map
>    acros: INTEGER:=10; -- across map

should probably be

Down   : constant := 10;
Across : cosntant := 10;

>    for i in 1..down loop
>       for j in 1..acros loop
>          map_array(i,j):='X';
>       end loop;
>    end loop;

You can create a literal for an entire array in Ada:

Map_Array := (others => (others => 'X') );

You don't need to assign element by element. In fact, you can do this 
when you declare the object:

Map_Array : Map_Hold (1 .. Down, 1 .. Across) :=
    (others => (others => 'X') );

When you do need to iterate over an array, you don't need to remember 
what range you declared it with:

for I in Map_Array'range (1) loop
    for J in Map_Array'range (2) loop

For a one-dimensional array, you can just use Name'range, without the "(1)".
> while FoundExit /= 1 loop

This indicates that you don't understand Booleans. You should have

Found_Exit : Boolean := False;
...
loop
    exit when Found_Exit;
...
    Found_Exit := True;

A loop with an exit reads better and is easier to understand than

while not Found_Exit loop

>   Open (map_file, out_FILE, "Map");

This fails if a file name "Map" doesn't already exist.

>    if IS_OPEN(map_file) then

If Open fails, an exception is raised (as you have discovered). 
Therefore, this test will always be true if you get here. You don't need 
it and it complicates your code. Add an exception handler to deal with 
the exceptional case.

>  else
>      Put_Line("Map file didn't open .. Killing Program");
>   end if;

[else to the if above] You can never get here. And if you did, you don't 
kill the program anyway.

Finally, your indentation and capitalization seem random. Regular 
indentation helps the reader see the structure of the program. Regular 
capitalization and putting underlines between words in identifiers makes 
your code easier to read.

-- 
Jeff Carter
"Death awaits you all, with nasty, big, pointy teeth!"
Monty Python & the Holy Grail
20




^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2003-10-14 20:42 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-10-14  4:05 windows ada compiler error Andrew
2003-10-14  5:19 ` tmoran
2003-10-14 15:29   ` Andrew
2003-10-14 15:35   ` Andrew
2003-10-14 16:17     ` Stephen Leake
2003-10-14 19:06       ` Andrew
2003-10-14 20:42 ` Jeffrey Carter

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox