From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,b0d68c502c0ae6 X-Google-Attributes: gid103376,public From: Ehud Lamm Subject: Re: Printing Enum Variable Re: Linux World Date: 1999/03/04 Message-ID: #1/1 X-Deja-AN: 451216817 References: <7bfc2n$jl9@dfw-ixnews5.ix.netcom.com> <7bhh26$r7c$1@remarQ.com> <36DCAC1F.430E2C5E@aasaa.ofe.org> <7bk4v8$kl8$1@remarQ.com> <36DDA761.7B4E8099@aasaa.ofe.org> <7bmafu$hnq$1@nnrp1.dejanews.com> Content-Type: TEXT/PLAIN; charset=US-ASCII Organization: The hebrew University of Jerusalem Mime-Version: 1.0 Newsgroups: comp.lang.ada Date: 1999-03-04T00:00:00+00:00 List-Id: > > 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