comp.lang.ada
 help / color / mirror / Atom feed
From: Stewart <s_aitken@lineone.net>
Subject: Re: Data_Error - Where in this code?
Date: Thu, 09 Aug 2001 18:55:29 +0100
Date: 2001-08-09T18:55:29+01:00	[thread overview]
Message-ID: <d7j5ntkjr7gubqadq0scuht4nm1iroh1bn@4ax.com> (raw)
In-Reply-To: 3B728FBD.D58F9D2A@raytheon.com

On Thu, 09 Aug 2001 08:27:25 -0500, Mark Johnson
<mark_h_johnson@raytheon.com> wrote:

>Stewart wrote:
>
>> On Wed, 08 Aug 2001 08:08:24 -0500, Mark Johnson
>> <mark_h_johnson@raytheon.com> wrote:
>> [snip]
>>
>> >The rest of the code is pretty user hostile, but "should work" as you expect.
>> >  --Mark
>>
>>  Can I ask what you mean by user hostile?
>
>Well, let's demonstrate some "illegal" input...
>
>"Add Abcdef" -- "add" is misspelled
done
>"add Abcde" -- node names MUST be 6 characters long
done
>"link abcdef uvwxyz " -- a 19 character line, Edge is not set (and no warning either)
done
>If you read a line that is longer than your input buffer, no warnings, etc.
done
>The program requires you to be overly precise - a pretty good definition of "user
>hostile".
>
>  --Mark
The  'done' above all give the same message, that the command has not
been understood and to retry. It would be nice to have more specific
messages for each error but I am at my limit of understanding at the
moment. More practice required.

Code below

Thanks 

Stewart

>-- Main body combine load + menu  --
>-- Working in win98-dos & Linux. 8 Aug 2001    --
>
>   with Ada.Text_Io;
>   use Ada.Text_Io;
>--with Sorts;
>
>   procedure main is 
>      type Edge_Cost is new Integer range 1 .. 999;
>      package Cost_InOut is new Integer_Io(Edge_Cost);
>      package Number_InOut is new Integer_Io(Integer);
>      use Cost_InOut, Number_InOut;
>   
>      Max_Size  : Positive;
>   
>      procedure fileload is 
>      
>      -- this procedure reads the external text file for the pre-defined data.
>         procedure Load_Locations is 
>            Location_File : File_Type;  
>         --variable of type file.  
>            Node_A, Node_B : String (1 .. 6);  
>         --string of distance six.  
>            Edge_Weight : Edge_Cost;  
>         --distance between a b. 
>            Space : Character;  
>         
>         begin
>         
>            new_line;Put_Line(" Opening Network.txt for reading");new_line;
>            Open(Location_File, Mode => In_File, Name =>    "network.txt");
>         --opening text file for reading.
>         
>            while not End_Of_File(Location_File) loop
>            --stop at end of external text file.
>            
>               Get(Location_File,Node_A); --get the first name.
>               Get(Location_File,Space);  --move pointer.remove for linux
>               Get(Location_File,Node_B); --get the second name. 
>               Get(Location_File,Edge_Weight);
>            --distance between node_a and node_b.
>            
>            end loop;
>            Close(Location_File); --close the network.txt file after input.
>         end Load_Locations;
>      
>      begin
>         Load_Locations;
>         Put_Line(" Network.txt loaded successfully!!!"); New_Line;
>      end fileload;
>   
>      procedure Menu is
>      
>         Int_Range : Natural; 
>         Edge      : Edge_Cost; 
>         Input     : String (1 .. Max_Size);  
>         Add       : String (1 .. 3)        := "add";  
>         Remove    : String (1 .. 6)        := "remove";  
>         Link      : String (1 .. 4)        := "link";  
>         Cost      : String (1 .. 4)        := "cost";  
>         Quit      : String (1 .. 4)        := "quit";  
>         Nodea, Nodeb : String (1 .. 6);  
>         A, B : Character;
>         function checkchar (firstchar : Character) return Boolean is	
>         begin
>            return firstchar in 'a'..'z' or firstchar in 'A'..'Z';
>         end checkchar;		
>      
>      begin
>         loop
>         
>            begin -- Block to contain the exception.   --
>               Put("Please enter command: ");
>               Get_Line(Input, Max_Size);
>               if Input(1..3) = Add and  10 = Max_Size then
>                  Nodea := Input(5..10); New_Line;
>               elsif Input(1..6) = Remove and  13 = Max_Size then
>                  Nodea := Input(8..13); New_Line;
>               elsif Input(1..4) = Link and 19 < Max_Size and Max_Size < 23 then
>                  Nodea := Input(6..11); 
>                  Nodeb := Input(13..18); 
>                  Int_Range := Max_Size - 19; New_Line;
>               
>                  B := Nodeb(1); 
>                  if checkchar(B) then 
>                     null;
>                  else Put_Line(" Incorrect name for Node_B. ");
>                     Put_Line(" Name must start with a letter. "); New_Line;  
>                  end if;
>               
>                  case Int_Range is
>                     when 1 =>
>                        Edge  := Edge_Cost'Value(Input(19..20));
>                  --                   Convert a single numeral   --           
>                     when 2 =>
>                        Edge  := Edge_Cost'Value(Input(20..21));
>                  --                   Convert two numerals        --                 
>                     when 3 =>
>                        Edge  := Edge_Cost'Value(Input(20..22));
>                  --                   Convert three numerals       --              
>                     when others => null; -- To capture case 0 and 4 --
>                  end case;                 
>               elsif Input(1..4) = Cost and  11 = Max_Size then
>                  Nodea := Input(6..11); New_Line;
>               elsif Input(1..4) = Quit then
>                  exit when Input(1..4) = Quit;
>               else
>                  Put ("Sorry, do not understand command."); New_Line;
>                  Put_Line ("Try again."); New_Line;
>               end if;
>               exception
>                  when CONSTRAINT_ERROR =>
>                     Put("Error in Cost Value. Enter 1 to 999 only.");
>                     new_line;
>            end;      --  End Block to contain exception            --
>            A := Nodea(1); 
>            if checkchar(A) then
>               null;
>            else Put_Line(" Incorrect name for Node_A. ");
>               Put_Line(" Name must start with a letter. "); New_Line;            
>            end if;           
>         end loop;
>      end Menu;
>   
>   begin
>      fileload;new_line;
>      menu; new_line;
>   
>      Put(" It has been a pleasure serving you."); new_line;
>      Put(" Please return again soon.");
>   
>   end main;




      reply	other threads:[~2001-08-09 17:55 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-08-06 19:47 Data_Error - Where in this code? Stewart
2001-08-07 13:53 ` Mark Johnson
2001-08-08  9:31 ` Stewart
2001-08-08 13:08   ` Mark Johnson
2001-08-09  9:34     ` Stewart
2001-08-09 13:27       ` Mark Johnson
2001-08-09 17:55         ` Stewart [this message]
replies disabled

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