comp.lang.ada
 help / color / mirror / Atom feed
From: Ehud Lamm <mslamm@mscc.huji.ac.il>
Subject: Re: Printing Enum Variable Re: Linux World
Date: 1999/03/04
Date: 1999-03-04T00:00:00+00:00	[thread overview]
Message-ID: <Pine.A41.3.96-heb-2.07.990304185308.28402B-100000@pluto.mscc.huji.ac.il> (raw)
In-Reply-To: 7bmafu$hnq$1@nnrp1.dejanews.com

> > Mine. For my example printed out "Red apple" as opposed to "RED_APPLE",

A little example of using generics, producing a menu, and pretry printing:

with ada.text_io; use ada.text_io;
with ada.integer_text_io; use ada.integer_text_io;
with Ada.Characters.Handling;

--generic
--   type Menu_Choice is (<>);
procedure Get_Menu_Choice (Choice:out Menu_Choice)  is
   Input:Integer range 0..Menu_Choice'Pos(Menu_Choice'Last);
   Done :Boolean;
   

   function Pretty(S:String) return String is
      -- This code is independent of 'image behaviuor.
      -- just deals with _ and capitalizes first letter in "words"
      Aux    :String(1..S'Length):=(others=>' ');
      Capital:Boolean:=True;
   begin
      for i in S'range loop
         if S(i)='_' then
               Aux(i):=' ';
               Capital:=True;
         elsif Capital then
               Aux(i):=Ada.Characters.Handling.To_Upper(S(i));
               Capital:=False;
         else
               Aux(i):=Ada.Characters.Handling.To_lower(S(i));
         end if;
      end loop;
      return Aux;
   end;

begin  -- Get_Menu
   for Choice in Menu_Choice loop
      put_line(Integer'Image(Menu_Choice'Pos(Choice)) & ' ' & 
               Pretty(Menu_Choice'image(Choice)));
   end loop;
   loop
      begin
         get(Input);
         Done:=True;
      exception
         when others =>
            put_line("minimal error message");
            Skip_Line;
            Done:=False;
      end;
      exit when Done;
    end loop;
    Choice:=Menu_Choice'val(Input);
end;

And a simple driver:

with get_menu_choice;
with ada.text_Io;
use ada.text_io;
procedure try_menu_choice is
   type menu is (First_Option,Second_Option_For_You);
   procedure Get_My_Menu_Choice is new Get_Menu_Choice(Menu_Choice=>Menu);
   
   package EIO is new Enumeration_Io(Menu);
   use EIO;
   C:menu;
begin
   get_My_Menu_Choice(C);
   put(C);
   
end;

Ehud Lamm     mslamm@pluto.mscc.huji.ac.il
http://www2.cybercities.com/e/ehud





  reply	other threads:[~1999-03-04  0:00 UTC|newest]

Thread overview: 79+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-03-02  0:00 Linux World Richard D Riehle
1999-03-02  0:00 ` fraser
1999-03-02  0:00   ` Printing Enum Variable " David Starner
1999-03-03  0:00     ` Larry Kilgallen
1999-03-03  0:00       ` Nick Roberts
1999-03-03  0:00         ` David Starner
1999-03-03  0:00     ` fraser
1999-03-03  0:00       ` David Starner
1999-03-03  0:00         ` fraser
1999-03-03  0:00         ` Samuel T. Harris
1999-03-04  0:00         ` dennison
1999-03-04  0:00           ` Ehud Lamm [this message]
1999-03-04  0:00         ` robert_dewar
1999-03-03  0:00           ` David Starner
1999-03-04  0:00             ` Samuel Mize
1999-03-04  0:00               ` Samuel Mize
1999-03-05  0:00                 ` Robert A Duff
1999-03-05  0:00               ` Robert A Duff
1999-03-07  0:00               ` Florian Weimer
1999-03-07  0:00                 ` Michael Young
1999-03-07  0:00                   ` Matthew Heaney
1999-03-08  0:00                     ` Michael Young
1999-03-08  0:00                       ` Matthew Heaney
1999-03-07  0:00                   ` Larry Kilgallen
1999-03-07  0:00                     ` Michael Young
1999-03-08  0:00                       ` Larry Kilgallen
1999-03-08  0:00                         ` robert_dewar
1999-03-08  0:00                       ` robert_dewar
1999-03-08  0:00                         ` Richard D Riehle
1999-03-09  0:00                           ` Michael Young
1999-03-09  0:00                             ` Larry Kilgallen
1999-03-09  0:00                               ` billy
1999-03-10  0:00                                 ` Pascal Obry
1999-03-10  0:00                                 ` robert_dewar
1999-03-10  0:00                                   ` Dale Stanbrough
1999-03-10  0:00                                     ` Pascal Obry
1999-03-10  0:00                                     ` Richard D Riehle
1999-03-10  0:00                                     ` dennison
1999-03-10  0:00                                       ` bob
1999-03-10  0:00                                         ` Mike Silva
1999-03-10  0:00                                           ` dennison
1999-03-10  0:00                                           ` Nick Roberts
1999-03-09  0:00                               ` Michael Young
1999-03-10  0:00                                 ` Mike Silva
     [not found]                               ` <7 <7c58qa$b6b$1@cf01.edf.fr>
1999-03-10  0:00                                 ` fraser
     [not found]                               ` <7c4ru6$e45$1@remarq.com>
1999-03-10  0:00                                 ` fraser
     [not found]                             ` <1999Mar9.131659. <dale-1003991644340001@r1021c-07.ppp.cs.rmit.edu.au>
1999-03-10  0:00                               ` Larry Kilgallen
1999-03-08  0:00                       ` Florian Weimer
1999-03-04  0:00             ` robert_dewar
1999-03-04  0:00           ` Ehud Lamm
1999-03-05  0:00             ` Richard D Riehle
1999-03-05  0:00               ` Nick Roberts
1999-03-06  0:00                 ` Ehud Lamm
1999-03-06  0:00                   ` robert_dewar
1999-03-06  0:00                     ` Larry Kilgallen
1999-03-06  0:00                       ` Dave Taylor
1999-03-06  0:00                         ` Bruce or Tracy
1999-03-06  0:00                     ` Ehud Lamm
1999-03-03  0:00     ` Fraser Wilson
1999-03-03  0:00       ` David Starner
1999-03-04  0:00         ` robert_dewar
1999-03-04  0:00         ` Richard D Riehle
1999-03-04  0:00         ` Magnus Larsson
1999-03-03  0:00           ` Printing Enum Variable Re: Linux World (Correction) Hans Marqvardsen
1999-03-03  0:00           ` Printing Enum Variable Re: Linux World Hans Marqvardsen
1999-03-04  0:00             ` Nick Roberts
1999-03-04  0:00             ` robert_dewar
1999-03-04  0:00               ` Hans Marqvardsen
1999-03-05  0:00                 ` dewar
1999-03-07  0:00                   ` Hans Marqvardsen
1999-03-04  0:00               ` Hans Marqvardsen
1999-03-05  0:00                 ` dewar
1999-03-05  0:00                   ` David Botton
1999-03-05  0:00                     ` robert_dewar
1999-03-05  0:00                 ` Larry Kilgallen
1999-03-04  0:00         ` fraser
1999-03-05  0:00           ` Nick Roberts
1999-03-05  0:00             ` fraser
1999-03-04  0:00         ` Richard D Riehle
replies disabled

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