Page 1 of 1

Oberon & writing files

Posted: Sun Oct 31, 2021 10:56 am
by jackD
Not sure if it's ok to post here because my query is about Oberon (specifically Oberon-07) rather than C.P., but as they are so similar I thought it would be ok, and I haven't found any other forums or mailing lists for Oberon related questions (comp.lang.oberon seems to be defunct).

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;
  f : Files.File;
  r : Files.Rider;
  f := Files.New("HelloWorld.txt");
  Files.Set(r, f, 0);
  Files.WriteString(r, "Hello World!");
  Files.WriteString(r, 0AX);
END helloworld.
The code compiles and runs ok, but when I try to open HelloWorld.txt in an editor it complains that the file is binary. Using gvim, this is what I see :

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.

Re: Oberon & writing files

Posted: Sun Oct 31, 2021 12:32 pm
by cfbsoftware
You are correct. The Files module is used for reading / writing binary data from / to a file. Oberon systems often have a Texts module for writing text to a file. These usually have a WriteLn procedure for writing the newline character(s) relevant for the system it is running on. The Oakwood Out module can be used for writing text. The Hello World example is here:

I haven't used OBNC but presumably you can redirect the output to a file?

General Oberon-07 questions like these are usually answered in the ETH Oberon Mailing List:

Re: Oberon & writing files

Posted: Sun Oct 31, 2021 3:22 pm
by jackD
Thanks for the reply.
I haven't used OBNC but presumably you can redirect the output to a file?
Duh, I never thought of that! Yes, it works fine, so I needn't use the file module at all, unless I need to read/write binary files.

And thanks for the link to the ETH mailing list. If I have any more problems or queries I'll post them there.