
(********************************************************************)
(*                                                                  *)
(*  more.s7i      Filter file which shows another file screenwise   *)
(*  Copyright (C) 1992, 1993, 1994, 2005  Thomas Mertes             *)
(*                                                                  *)
(*  This file is part of the Seed7 Runtime Library.                 *)
(*                                                                  *)
(*  The Seed7 Runtime Library is free software; you can             *)
(*  redistribute it and/or modify it under the terms of the GNU     *)
(*  Lesser General Public License as published by the Free Software *)
(*  Foundation; either version 2.1 of the License, or (at your      *)
(*  option) any later version.                                      *)
(*                                                                  *)
(*  The Seed7 Runtime Library is distributed in the hope that it    *)
(*  will be useful, but WITHOUT ANY WARRANTY; without even the      *)
(*  implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR *)
(*  PURPOSE.  See the GNU Lesser General Public License for more    *)
(*  details.                                                        *)
(*                                                                  *)
(*  You should have received a copy of the GNU Lesser General       *)
(*  Public License along with this program; if not, write to the    *)
(*  Free Software Foundation, Inc., 51 Franklin Street,             *)
(*  Fifth Floor, Boston, MA  02110-1301, USA.                       *)
(*                                                                  *)
(********************************************************************)


const type: more_file is sub null_file struct
    var file: out_file is STD_NULL;
    var file: command_file is STD_NULL;
    var integer: pagesize is 0;
    var integer: line is 0;
    var boolean: active is TRUE;
  end struct;


const func file: openMore (in file: out_fil, in file: cmd_fil, in integer: pg_size) is func
  result
    var file: newFile is STD_NULL;
  local
    var more_file: new_more_file is more_file.value;
  begin
    new_more_file.out_file := out_fil;
    new_more_file.command_file := cmd_fil;
    new_more_file.pagesize := pg_size;
    new_more_file.line := 0;
    new_more_file.active := TRUE;
    newFile := toInterface(new_more_file);
  end func;


const proc: page (inout more_file: more_fil) is func
  begin
    more_fil.active := TRUE;
    more_fil.line := 0;
  end func;


const proc: writeln (inout more_file: more_fil) is func
  local
    var string: command is "";
  begin
    if more_fil.active then
      writeln(more_fil.out_file);
      incr(more_fil.line);
      if more_fil.line >= more_fil.pagesize then
        write(more_fil.out_file, " *** MORE *** ");
        readln(more_fil.command_file, command);
        writeln(more_fil.out_file);
        if lower(command) = "q" then
          more_fil.active := FALSE;
        end if;
        more_fil.line := 0;
      end if;
    end if;
  end func;


const proc: write (inout more_file: more_fil, in string: stri) is func
  begin
    if more_fil.active then
      write(more_fil.out_file, stri);
    end if;
  end func;
