comp.lang.ada
 help / color / mirror / Atom feed
* Copying a file using text_io
@ 1985-09-13 23:57 "David S. Bakin"
  0 siblings, 0 replies; only message in thread
From: "David S. Bakin" @ 1985-09-13 23:57 UTC (permalink / 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;

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~1985-09-13 23:57 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1985-09-13 23:57 Copying a file using text_io "David S. Bakin"

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