comp.lang.ada
 help / color / mirror / Atom feed
From: Bakin@MIT-MULTICS.ARPA ("David S. Bakin")
Subject: Copying a file using text_io
Date: Fri, 13-Sep-85 19:57:00 EDT	[thread overview]
Date: Fri Sep 13 19:57:00 1985
Message-ID: <850913235719.726375@MIT-MULTICS.ARPA> (raw)

By the way, here is the best way I've found to copy a file using text_io
(it copies standard-input to standard-output).  This program has already
been used as a quick basis for 3 useful filters.  Just plug into procedure
'process_a_line' something that does what you want to do.

-- Dave (Bakin -at mit-multics.arpa)

-------------------------- cut here --------------------------------------

with text_io;
procedure file_copy is

   -- If a file ends in a blank line, won't copy it.
   -- If a file ends in a line which only has a form feed, won't copy it.
   -- If a file ends in a blank line, followed by a line which only has
   --    a form feed, won't copy either of those two lines!

   use text_io;

   a_line:  string (1 .. 1024);
   a_len:   natural;

   page_skipped: boolean := false;

   procedure read_a_line is
      prev_page: positive_count := page(standard_input);
   begin
      get_line (a_line, a_len);
      if page(standard_input) /= prev_page and not end_of_file then
         page_skipped := true;
      end if;
   end;

   procedure process_a_line is
   begin
      null;
   end;

   procedure write_a_line is
   begin
      put_line (a_line (1 .. a_len));
      if page_skipped then
         new_page;
         page_skipped := false;
      end if;
   end;

begin

   while not end_of_file loop
      read_a_line;
      process_a_line;
      write_a_line;
   end loop;

end file_copy;

                 reply	other threads:[~1985-09-13 23:57 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed
replies disabled

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