From: dep@swlraw.msd.ray.com (DONALD PRINCIOTTA)
Subject: Re: ADA help Urgently Requested..Please!!!!
Organization: Raytheon Company, Tewksbury, MA
Date: Wed, 2 Sep 1992 21:37:50 GMT

mgeorgy@vmsclst1.sc.csupomona.edu writes:

>Hello, the program that follows began as a simple imaging program that I was
>writing for myself.  But now it has become a big problem.  Everything ok except
>the file opening and creating.  When I run the program and select option 1 or
>2, open or create a file, I get a DEVICE ERROR.  I can tell you what is
>happening but I just don't know why.  What is happening is that when it get to
>the GET_LINE statment it uses IN_FILE_NAME's decleration of ' '.  Now I should
>tell anyone willing to help me that the statments work alone but not as part of
>another program (ie, IF statment, or sub-PROCEDURES).  I have raked my brain
>and tried everything.  

>SOMEONE PLEASE HELP ME!!!!!!

>THANX FOR ANY HELP,
>Matt Georgy
>California Polytechnic State University, Pomona  -- Computer Science

>+++++++++++++++++++++++++++++++++++++++++++++++++++++++
>+  Cal Poly, Pomona, Making Yesterdays Mistakes Today +
>+++++++++++++++++++++++++++++++++++++++++++++++++++++++



Often when using the Text_IO.Get_Line routine this problem occurs.

The Get_Line routine looks for a <CR> on the input buffer to terminate
the input stream.  In your case,  The previous 'Get' ignores the <CR>
and most likely leaves it in the input buffer.  So, Along comes your
Get_Line and 'Holy Cow'... There is a <CR> sitting in the input buffer,
probably the first byte, and since there is a <CR> you must have
completed your input... Get_Line OVER ....  a string of length ZERO(0)
has entered.

If you look at the value of INPUT_LINE_LENGTH or OUTPUT_LINE_LENGTH 
after you execute the Get_Line and prior to your attempt at opening
a file..... You'll probably find that it contains the value ZERO(0).


To fix this problem:  Try using the Text_IO.Skip_Line routine, which 
skips over the next <CR>.  The proper location for the Skip_Line is 
just prior to the Get_Line and AFTER the Get.   You'll need one 
Skip_Line before each of your Get_Line calls.  

Look at the calls below.. Try them .. and let me know if it works ...
It Should solve your problem.

                                Don Princiotta
                                dep@swlra1.msd.ray.com
~



>P.S. Please reply by posting to the news group our mail system is screwed up
>right now.

>THANX AGAIN.

>-------------------------------------------------------------------------------
>with TEXT_IO, INTEGER_TEXT_IO, SEQUENTIAL_IO;
>use TEXT_IO, INTEGER_TEXT_IO;

>procedure IMAGE is
>   
>type BYTE is range 0..255;
>for BYTE'size use 8;

>package BYTE_IO is new SEQUENTIAL_IO(BYTE);
>use BYTE_IO;

>   type BYTE_STRING is ARRAY (1..512) of BYTE;

>   INF                  :  BYTE_IO.FILE_TYPE;
>   IN_FILE_NAME         :  STRING (1..80) := (others => ' ');
>   INPUT_LINE_LENGTH    :  INTEGER := 0;
>   IN_FILE_OPEN         :  BOOLEAN := FALSE;
>   
>   OUTF                 :  BYTE_IO.FILE_TYPE;
>   OUT_FILE_NAME        :  STRING (1..80) := (others => ' ');
>   OUTPUT_LINE_LENGTH   :  INTEGER := 0;
>   OUT_FILE_OPEN        :  BOOLEAN := FALSE;
>   
>   READ_BYTE            :  BYTE;
>   READ_STRING          :  BYTE_STRING;
>   COUNTER              :  INTEGER := 0;   
>   SELECTION            :  INTEGER := 1;
>   
>   procedure IMAGING_MENU is
>   
>   begin
>   
>      NULL;
>	  
>   end IMAGING_MENU;
>   
>begin

>   while SELECTION /= 0 loop    
>  	  PUT("STATUS:     INPUT FILE: ");
>      if IN_FILE_NAME(1) = ' ' then
>	     PUT("<NONE>");
>      else
>         PUT(IN_FILE_NAME);
>		 IN_FILE_OPEN := TRUE;
>      end if;
>   	  PUT("        ");
>      PUT("   OUTPUT FILE: ");
>	  if OUT_FILE_NAME(1) = ' ' then
>	     PUT("<NONE>");
>	  else
>	     PUT(OUT_FILE_NAME);
>		 OUT_FILE_OPEN := TRUE;
>   	  end if;
>	  NEW_LINE(2);
>	  PUT("          Welcome to POLY-Vision");
>	  NEW_LINE(3);
>	  PUT_LINE("                 MAIN MENU");
>	  NEW_LINE;
>	  PUT_LINE("          (1) Get Input Filename");
>	  NEW_LINE;
>	  PUT_LINE("          (2) Get Output Filename");
>	  NEW_LINE;
>   	  PUT_LINE("          (3) Begin Image Processing");
>	  NEW_LINE;
>	  PUT_LINE("          (0) Exit POLY-Vision");
>	  NEW_LINE(2);
>      PUT_LINE("                   CHOICE: ");
>	  GET(SELECTION);
          -- <CR> left on the input buffer....
>	  if SELECTION = 1 then
>            PUT_LINE("INPUT FILE NAME: ");


             -- Insert call to remove <CR> fromthe input buffer....
             Text_IO.Skip_Line;


>            GET_LINE(IN_FILE_NAME, INPUT_LINE_LENGTH);
>	     open(INF, IN_FILE, IN_FILE_NAME(1..INPUT_LINE_LENGTH));
>	  elsif SELECTION = 2 then
>            PUT("OUTPUT FILE NAME: ( ");
>            PUT(IN_FILE_NAME(1..INPUT_LINE_LENGTH - 3));
>            PUT_LINE("NEW )");


             -- Insert call to remove <CR> fromthe input buffer....
             Text_IO.Skip_Line;


>            GET_LINE(OUT_FILE_NAME, OUTPUT_LINE_LENGTH);
>            if OUT_FILE_NAME(1) = ' ' then
>               create(OUTF, OUT_FILE, IN_FILE_NAME(1..INPUT_LINE_LENGTH - 3) & "NEW");
>            else
>               create(OUTF, OUT_FILE, OUT_FILE_NAME(1..OUTPUT_LINE_LENGTH));
>            end if; 
>	  elsif SELECTION = 3 then
>	     IMAGING_MENU;
>	  else
>		 if IN_FILE_OPEN then
>		    close(INF);
>   	     end if;
>		 if OUT_FILE_OPEN then
>            close(OUTF);
>	     end if;
>		 EXIT;
>	  end if;
>   end loop;
> 
>end IMAGE;


P.S.

Over use of the Skip_Line will result in your program waiting
for you to hit the <CR> when you really didn't want that to 
happen.  Be careful when using it and GOOD LUCK.

--- END OF MESSAGE ---