(* Collection of code snippets by Arne Vajhøj *)
(* (from articles on eksperten.dk / vajhoej.dk written sometime between 2004 and now) *)
[inherit('sys$library:pascal$lib_routines')]
program PlainReadLn(input, output);

type
    string = varying[32767] of char;

procedure test(fnm : string; expect : integer);

var
  f : text;
  line : string;
  t1, t2 : Cardinal;
  n : integer;

begin
  t1 := Clock;
  open(f, fnm, old);
  reset(f);
  n := 0;
  while not eof(f) do begin
    readln(f, line);
    n := n + 1;
  end;
  if n <> expect then begin
    writeln(n:1,' lines');
  end;
  close(f);
  t2 := Clock;
  writeln('Pascal readln : ', (t2 - t1):1, ' ms');
end;

var
  ix, expect, i : integer;
  cmdlin, fnm : string;

begin
  lib$get_foreign(resultant_string:=cmdlin.body,resultant_length:=cmdlin.length);
  ix := index(cmdlin, ' ');
  fnm := substr(cmdlin, 1, ix - 1);
  readv(substr(cmdlin, ix + 1), expect);
  for i := 1 to 10 do begin
    test(fnm, expect);
  end;
end.
