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,5997b4b7b514f689 X-Google-Attributes: gid103376,public From: Rex Reges Subject: Re: Reading a line of arbitrary length Date: 1997/02/13 Message-ID: <33032AE2.666F@mds.lmco.com>#1/1 X-Deja-AN: 218516862 References: <5ds40o$rpo@fg70.rz.uni-karlsruhe.de> To: Thomas.Koenig@ciw.uni-karlsruhe.de Content-Type: text/plain; charset=us-ascii Organization: M&DS Mime-Version: 1.0 Reply-To: rex.r.reges@lmco.com Newsgroups: comp.lang.ada X-Mailer: Mozilla 3.0 (Win95; I) Date: 1997-02-13T00:00:00+00:00 List-Id: Thomas Koenig wrote: > > What's the best way of reading a line of arbitrary length in Ada? > > Get_Line only works on Strings, not Unbounded_Strings. Would I need > to read in chunks of fixed length, then paste them together? > -- > 74 a3 53 cc 0b 19 Inevitably, you will get various unexpected problems using the Get_Line function. Let's assume that you create a very large string buffer to handle most situations: Input_Buffer : String( 1..10_000_000 ) ; You may run into one of the following problems: 1) The IO buffer allocated by the operating system for file IO is too small to handle large strings and you will get an exception (happens on the Vax for strings on the order of a million characters). 2) You will get a storage_error exception because the variable Input_Buffer will exceed the operating system limits on your program size (or more commonly that you don't have stack space to instantiate it). 3) An exception will occur during the processing and all the data for that line will be lost. The most common exception is when an end-of-file is found before the end-of-line (a favorite of xedit users). Unfortunately, it turns out that getting one character at a time is the best solution to avoid losing data and to handle unlimited length strings. Actully, this is not as bad as it seems since the machines I have used buffer I/O in chunks anyway so that a get does not involve a disk access most of the time. -- Rex Reges or you can call me The Fixer Systems Analyst or you can call me The Lawyer Lockheed Martin, M&DS or you can call me The Doctor (610)354-5047 or you can call me Rexasaurus