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=-2.9 required=5.0 tests=BAYES_00,MAILING_LIST_MULTI autolearn=unavailable autolearn_force=no version=3.4.4 X-Google-Thread: 103376,bed2755a22ee69a X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!t-online.de!130.59.10.21.MISMATCH!kanaga.switch.ch!switch.ch!news.in2p3.fr!in2p3.fr!proxad.net!cleanfeed3-a.proxad.net!nnrp12-1.free.fr!not-for-mail Return-Path: From: "Randy Brukardt" To: Subject: RE: Text Processing in Ada 95 Date: Thu, 22 Feb 2007 23:19:58 -0600 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook IMO, Build 9.0.6604 (9.0.2911.0) X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1807 In-Reply-To: Importance: Normal X-Trash-Finder: Limited filtering for message, local (outbound) source X-Virus-Scanned: amavisd-new at ada-france.org X-BeenThere: comp.lang.ada@ada-france.org X-Mailman-Version: 2.1.9rc1 Precedence: list List-Id: "Gateway to the comp.lang.ada Usenet newsgroup" List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.ada Message-ID: X-Leafnode-NNTP-Posting-Host: 88.191.17.134 Organization: Guest of ProXad - France NNTP-Posting-Date: 23 Feb 2007 06:20:37 MET NNTP-Posting-Host: 88.191.14.223 X-Trace: 1172208037 news-2.free.fr 28945 88.191.14.223:39699 X-Complaints-To: abuse@proxad.net Xref: g2news2.google.com comp.lang.ada:9443 Date: 2007-02-23T06:20:37+01:00 Steve writes: ... > Actually Direct_IO is an option, and probably the fastest way to > handle the > operation. > > Step 1. Determine the initial file size > Step 2. Allocate a buffer that is the size of the file plus the size of > the string you want to add (including a line terminator) > Step 3. Create an instance Direct_IO that is the file size > Step 5. Read the file into the start of the allocated buffer in one gulp > Step 6. Insert your string in the buffer (a little tricky, but doable) > Step 7. Create an instance of Direct_IO that is the size of the buffer > with the new string > Step 8. Write the buffer to a file as one operation. That's how you'd do it in Ada 83, but that's an awful lot of unnecessary complication in Ada 95 (not to mention Ada 2007). Just use Stream_IO for this, and you don't need instances to fill and write your buffer. (And you can easily start in the middle of the file and only read part of it if that works for your application.) I.e. > Step 1. Determine the initial file size Use Stream_IO.Size(File). > Step 2. Allocate a buffer that is the size of the file plus the size of > the string you want to add (including a line terminator) Buffer : Stream_Element_Array (1 .. Size); -- But you can make it bigger. > Step 3. Create an instance Direct_IO that is the file size null; > Step 5. Read the file into the start of the allocated buffer in one gulp Stream_IO.Read (File, Buffer, Last); > Step 6. Insert your string in the buffer (a little tricky, but doable) Exercise for the reader. ;-) > Step 7. Create an instance of Direct_IO that is the size of the buffer > with the new string null; > Step 8. Write the buffer to a file as one operation. Stream_IO.Set_Mode(File, Out_File); -- Or Reset. Stream_IO.Write(File, Buffer); Randy.