(********************************************************************) (* *) (* upper.s7i Filter file which turns characters to upper case *) (* Copyright (C) 1992, 1993, 1994, 2005, 2023 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. *) (* *) (********************************************************************) (** * [[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; (** * 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 upperFile: new_upperFile is upperFile.value; begin new_upperFile.destFile := destFile; newFile := toInterface(new_upperFile); end 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 write(outFile.destFile, upper(stri)); end func; (** * Write end-of-line to ''outFile''. *) const proc: writeln (inout upperFile: outFile) is func begin writeln(outFile.destFile); end 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(outFile.destFile, upper(stri)); end func; const proc: moveLeft (inout upperFile: outFile, in string: stri) is func begin moveLeft(outFile.destFile, stri); end func; const proc: erase (inout upperFile: outFile, in string: stri) is func begin erase(outFile.destFile, stri); end func; const proc: cursorOn (inout upperFile: outFile, in char: cursorChar) is func begin cursorOn(outFile.destFile, cursorChar); end func; const proc: cursorOff (inout upperFile: outFile, in char: cursorChar) is func begin cursorOff(outFile.destFile, cursorChar); end 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(inFile.destFile, maxLength)); end func;