I'm new to Oberon having used Turbo Pascal back in the 90s. Rather than go for Free Pascal I thought I'd try Oberon because it's simple, and it's been a long time since I did any programming. I'm using the OBNC compiler on Linux, which comes with a small set of modules (adhering to the Oakwood guidelines), including one for files. Here is my first attempt at writing some text to a file:
Code: Select all
MODULE helloworld;
IMPORT Files;
VAR
f : Files.File;
r : Files.Rider;
BEGIN
f := Files.New("HelloWorld.txt");
Files.Register(f);
Files.Set(r, f, 0);
Files.WriteString(r, "Hello World!");
Files.WriteString(r, 0AX);
Files.Close(f);
END helloworld.
Hello World!^@
^@
As I understand it, ^@ is the NULL terminator which is appended to the string in WriteString, and to start a new line I need Files.WriteString(r, 0AX) otherwise further lines will be written on the same line as "Hello World!", which I confirmed.
So my question is : is this normal for Oberon or is it an implementation issue? I'm guessing that it has to do with the way the Oberon OS was designed, and that so called "text" files are actually binary rather than ASCII. But if that's the case, why would the author of a compiler written for Linux/Windows where line endings are CR/LF do it this way? Maybe it's what's recommended in the Oakwood guidelines but it just seems odd. If this is a standard Oberon thing it does put me off using it because I'm planning on doing a lot of writing to files.
Thanks in advance for any explanation and advice.