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.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,8d3f28f2a74233d2 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2000-12-30 06:38:23 PST Path: supernews.google.com!sn-xit-02!sn-post-01!supernews.com!corp.supernews.com!not-for-mail From: "Jeff Creem" Newsgroups: comp.lang.ada Subject: Re: Newbie Questions about Get, Get_Line Date: Sat, 30 Dec 2000 09:31:12 -0500 Organization: Posted via Supernews, http://www.supernews.com Message-ID: References: X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.50.4522.1200 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4522.1200 X-Complaints-To: newsabuse@supernews.com Xref: supernews.google.com comp.lang.ada:3465 Date: 2000-12-30T09:31:12-05:00 List-Id: wrote in message news:k73r4toon9d6e0oi384t6240d32d7leohc@4ax.com... > I am getting back into Ada again after several months of doing other > things. This time I am working on a program that does interactive > terminal IO, and I am finding that the Ada.Text_IO routines I am > working with have some unexpected behavior. (Get, Get_Line, > Get_Immediate) (The compiler is gnat 3.13p on Linux) Well..I also was confused and found Get_Line had unexpected behaviour when I called it and it did not paint my house. Then I read the LRM description about what it is supposed to do and realized that my expectations were wrong. I think it reads < LRM Quote> Reads successive characters from the specified input file and assigns them to successive characters of the specified string. Reading stops if the end of the string is met. Reading also stops if the end of the line is met before meeting the end of the string; in this case Skip_Line is (in effect) called with a spacing of 1. The values of characters not assigned are not specified. If characters are read, returns in Last the index value such that Item(Last) is the last character assigned (the index of the first character assigned is Item'First). If no characters are read, returns in Last an index value that is one less than Item'First. The exception End_Error is propagated if an attempt is made to skip a file terminator. > > What I would really find useful is a routine that could take a string > variable and fill it with terminal input with the following > properties: > > If the user input is shorter that the string variable, it will be > padded with blanks. > > If the user input is longer than the string variable, the extra > characters should be thrown away, never to be seen again. > This is very easy to do but the part about padding with spaces is probably a bad idea. I have seen a lot of Ada code where local string variables are initialized to all spaces and then just parts filled in. This seems ok but it leads to a lot of wasteful code being generated messing with spaces especially when someone starts using very long strings. Having said that if you are really sure you want something like this try package Slow_Get is --If the user input is shorter that the string variable, it will be --padded with blanks. --If the user input is longer than the string variable, the extra --characters should be thrown away, never to be seen again. procedure Get_Line(Item : out String); end Slow_Get; with Text_Io; package body Slow_Get is procedure Get_Line ( Item : out String ) is Last : Integer; begin Text_Io.Get_Line( Item => Item, Last => Last); if Last = Item'Last then Text_Io.Skip_Line; end if; for Pad_Index in Last + 1 .. Item'Last loop Item(Pad_Index) := ' '; end loop; end Get_Line; end Slow_Get;