Skip to content

Commit

Permalink
Improve filter files
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasMertes committed Aug 12, 2023
1 parent 1f3b506 commit 3b5e71a
Show file tree
Hide file tree
Showing 3 changed files with 146 additions and 73 deletions.
103 changes: 72 additions & 31 deletions lib/lower.s7i
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
(********************************************************************)
(* *)
(* lower.s7i Filter file which turns characters to lower case *)
(* Copyright (C) 1992, 1993, 1994, 2005 Thomas Mertes *)
(* Copyright (C) 1992, 1993, 1994, 2005, 2023 Thomas Mertes *)
(* *)
(* This file is part of the Seed7 Runtime Library. *)
(* *)
Expand All @@ -26,75 +26,116 @@
(********************************************************************)


const type: lower_file is sub null_file struct
var file: destination_file is STD_NULL;
(**
* [[file|File]] implementation type which turns characters to lower case.
* All data that is written to a ''lowerFile'' is converted to lower
* case and forwarded to the ''destFile''. All functions that read from
* ''lowerFile'' read from ''destFile'' instead and deliver the data
* after converting it to lower case.
*)
const type: lowerFile is sub null_file struct
var file: destFile is STD_NULL;
end struct;


const func file: openLower (in file: aFile) is func
(**
* Open a filter file which turns characters to lower case.
* All data that is written to a ''lowerFile'' is converted to lower
* case and forwarded to the ''destFile''. E.g.:
* lowerOutput := openLower(OUT);
* repeat
* write("Enter sentence: ");
* flush(OUT);
* readln(sentence);
* writeln(lowerOutput, sentence);
* until sentence = "";
* All functions that read from ''lowerFile'' read from ''destFile''
* instead and deliver the data after converting it to lower case.
* This can be used to allow upper and lower case commands:
* KEYBOARD := openLower(KEYBOARD);
* repeat
* write("command: ");
* flush(OUT);
* command := getc(KEYBOARD);
* writeln;
* ...
* until command = 'q';
* @param destFile File to which data is written or from which data is read.
* @return the ''lowerFile'' opened.
*)
const func file: openLower (in file: destFile) is func
result
var file: newFile is STD_NULL;
local
var lower_file: new_lower_file is lower_file.value;
var lowerFile: new_lowerFile is lowerFile.value;
begin
new_lower_file.destination_file := aFile;
newFile := toInterface(new_lower_file);
new_lowerFile.destFile := destFile;
newFile := toInterface(new_lowerFile);
end func;


(*
const proc: page (ref lower_file: lower_fil) is func
(**
* Write the [[string]] ''stri'' to ''outFile''.
* The characters are converted to lower case, before they are written.
*)
const proc: write (inout lowerFile: outFile, in string: stri) is func
begin
page(lower_fil.destination_file);
write(outFile.destFile, lower(stri));
end func;
*)


const proc: write (inout lower_file: lower_fil, in string: stri) is func
(**
* Write end-of-line to ''outFile''.
*)
const proc: writeln (inout lowerFile: outFile) is func
begin
write(lower_fil.destination_file, lower(stri));
writeln(outFile.destFile);
end func;


const proc: writeln (inout lower_file: lower_fil) is func
(**
* Write a [[string]] followed by end-of-line to ''outFile''.
* The characters are converted to lower case, before they are written.
*)
const proc: writeln (inout lowerFile: outFile, in string: stri) is func
begin
writeln(lower_fil.destination_file);
writeln(outFile.destFile, lower(stri));
end func;


const proc: writeln (inout lower_file: lower_fil, in string: stri) is func
const proc: moveLeft (inout lowerFile: outFile, in string: stri) is func
begin
writeln(lower_fil.destination_file, lower(stri));
moveLeft(outFile.destFile, stri);
end func;


const proc: moveLeft (inout lower_file: lower_fil, in string: stri) is func
const proc: erase (inout lowerFile: outFile, in string: stri) is func
begin
moveLeft(lower_fil.destination_file, stri);
erase(outFile.destFile, stri);
end func;


const proc: erase (inout lower_file: lower_fil, in string: stri) is func
const proc: cursorOn (inout lowerFile: outFile, in char: cursorChar) is func
begin
erase(lower_fil.destination_file, stri);
cursorOn(outFile.destFile, cursorChar);
end func;


const proc: cursorOn (inout lower_file: lower_fil, in char: cursorChar) is func
const proc: cursorOff (inout lowerFile: outFile, in char: cursorChar) is func
begin
cursorOn(lower_fil.destination_file, cursorChar);
cursorOff(outFile.destFile, cursorChar);
end func;


const proc: cursorOff (inout lower_file: lower_fil, in char: cursorChar) is func
begin
cursorOff(lower_fil.destination_file, cursorChar);
end func;


const func string: gets (inout lower_file: lower_fil, in integer: maxLength) is func
(**
* Read a [[string]] with a maximum length from a file.
* The characters read are converted to lower case.
* @return the string read and converted to lower case.
* @exception RANGE_ERROR The parameter ''maxLength'' is negative.
*)
const func string: gets (inout lowerFile: inFile, in integer: maxLength) is func
result
var string: stri is "";
begin
stri := lower(gets(lower_fil.destination_file, maxLength));
stri := lower(gets(inFile.destFile, maxLength));
end func;
13 changes: 2 additions & 11 deletions lib/more.s7i
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ const type: moreFile is sub null_file struct
* Open a more filter file for viewing a file page by page or line by line.
* more := openMore(OUT, KEYBOARD, 20);
* writeln(more, multiPageDocument);
* After writing a page (command: space) or single line (command: return/enter)
* to a ''moreFile'' it prompts for the next command with:
* After writing the requested number of lines it prompts for the
* next command with:
* --More--
* The following commands are accepted:
* * space Display the next ''pageSize'' lines.
Expand Down Expand Up @@ -72,15 +72,6 @@ const func file: openMore (in file: destFile, in file: commandFile,
end func;


(*
const proc: page (inout moreFile: outFile) is func
begin
outFile.active := TRUE;
outFile.line := 0;
end func;
*)


(**
* Write end-of-line to ''outFile''.
* This function writes the end-of-line marker to the destination file.
Expand Down
103 changes: 72 additions & 31 deletions lib/upper.s7i
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
(********************************************************************)
(* *)
(* upper.s7i Filter file which turns characters to upper case *)
(* Copyright (C) 1992, 1993, 1994, 2005 Thomas Mertes *)
(* Copyright (C) 1992, 1993, 1994, 2005, 2023 Thomas Mertes *)
(* *)
(* This file is part of the Seed7 Runtime Library. *)
(* *)
Expand All @@ -26,75 +26,116 @@
(********************************************************************)


const type: upper_file is sub null_file struct
var file: destination_file is STD_NULL;
(**
* [[file|File]] implementation type which turns characters to upper case.
* All data that is written to a ''upperFile'' is converted to upper
* case and forwarded to the ''destFile''. All functions that read from
* ''upperFile'' read from ''destFile'' instead and deliver the data
* after converting it to upper case.
*)
const type: upperFile is sub null_file struct
var file: destFile is STD_NULL;
end struct;


const func file: openUpper (in file: aFile) is func
(**
* Open a filter file which turns characters to upper case.
* All data that is written to a ''upperFile'' is converted to upper
* case and forwarded to the ''destFile''. E.g.:
* upperOutput := openUpper(OUT);
* repeat
* write("Enter sentence: ");
* flush(OUT);
* readln(sentence);
* writeln(upperOutput, sentence);
* until sentence = "";
* All functions that read from ''upperFile'' read from ''destFile''
* instead and deliver the data after converting it to upper case.
* This can be used to allow upper and lower case commands:
* KEYBOARD := openUpper(KEYBOARD);
* repeat
* write("command: ");
* flush(OUT);
* command := getc(KEYBOARD);
* writeln;
* ...
* until command = 'Q';
* @param destFile File to which data is written or from which data is read.
* @return the ''upperFile'' opened.
*)
const func file: openUpper (in file: destFile) is func
result
var file: newFile is STD_NULL;
local
var upper_file: new_upper_file is upper_file.value;
var upperFile: new_upperFile is upperFile.value;
begin
new_upper_file.destination_file := aFile;
newFile := toInterface(new_upper_file);
new_upperFile.destFile := destFile;
newFile := toInterface(new_upperFile);
end func;


(*
const proc: page (ref upper_file: upper_fil) is func
(**
* Write the [[string]] ''stri'' to ''outFile''.
* The characters are converted to upper case, before they are written.
*)
const proc: write (inout upperFile: outFile, in string: stri) is func
begin
page(upper_fil.destination_file);
write(outFile.destFile, upper(stri));
end func;
*)


const proc: write (inout upper_file: upper_fil, in string: stri) is func
(**
* Write end-of-line to ''outFile''.
*)
const proc: writeln (inout upperFile: outFile) is func
begin
write(upper_fil.destination_file, upper(stri));
writeln(outFile.destFile);
end func;


const proc: writeln (inout upper_file: upper_fil) is func
(**
* Write a [[string]] followed by end-of-line to ''outFile''.
* The characters are converted to upper case, before they are written.
*)
const proc: writeln (inout upperFile: outFile, in string: stri) is func
begin
writeln(upper_fil.destination_file);
writeln(outFile.destFile, upper(stri));
end func;


const proc: writeln (inout upper_file: upper_fil, in string: stri) is func
const proc: moveLeft (inout upperFile: outFile, in string: stri) is func
begin
writeln(upper_fil.destination_file, upper(stri));
moveLeft(outFile.destFile, stri);
end func;


const proc: moveLeft (inout upper_file: upper_fil, in string: stri) is func
const proc: erase (inout upperFile: outFile, in string: stri) is func
begin
moveLeft(upper_fil.destination_file, stri);
erase(outFile.destFile, stri);
end func;


const proc: erase (inout upper_file: upper_fil, in string: stri) is func
const proc: cursorOn (inout upperFile: outFile, in char: cursorChar) is func
begin
erase(upper_fil.destination_file, stri);
cursorOn(outFile.destFile, cursorChar);
end func;


const proc: cursorOn (inout upper_file: upper_fil, in char: cursorChar) is func
const proc: cursorOff (inout upperFile: outFile, in char: cursorChar) is func
begin
cursorOn(upper_fil.destination_file, cursorChar);
cursorOff(outFile.destFile, cursorChar);
end func;


const proc: cursorOff (inout upper_file: upper_fil, in char: cursorChar) is func
begin
cursorOff(upper_fil.destination_file, cursorChar);
end func;


const func string: gets (inout upper_file: upper_fil, in integer: maxLength) is func
(**
* Read a [[string]] with a maximum length from a file.
* The characters read are converted to upper case.
* @return the string read and converted to upper case.
* @exception RANGE_ERROR The parameter ''maxLength'' is negative.
*)
const func string: gets (inout upperFile: inFile, in integer: maxLength) is func
result
var string: stri is "";
begin
stri := upper(gets(upper_fil.destination_file, maxLength));
stri := upper(gets(inFile.destFile, maxLength));
end func;

0 comments on commit 3b5e71a

Please sign in to comment.