The domain TextFile allows FriCAS to read and write character data and exchange text with other programs. This type behaves in FriCAS much like a File of strings, with additional operations to cause new lines. We give an example of how to produce an upper case copy of a file.
This is the file from which we read the text.
f1: TextFile := open("/etc/group", "input")
This is the file to which we write the text.
f2: TextFile := open("/tmp/MOTD", "output")
Entire lines are handled using the readLinereadLineTextFile and writeLinewriteLineTextFile operations.
l := readLine! f1
writeLine!(f2, upperCase l)
Use the endOfFile?endOfFile?TextFile operation to check if you have reached the end of the file.
while not endOfFile? f1 repeat s := readLine! f1 writeLine!(f2, upperCase s)
The file f1 is exhausted and should be closed.
It is sometimes useful to write lines a bit at a time. The writewriteTextFile operation allows this.
This ends the line. This is done in a machine-dependent manner.
Finally, clean up.
)system rm /tmp/MOTD