Oberon & writing files

Programming language questions
Post Reply
jackD
Posts: 10
Joined: Fri Oct 15, 2021 9:10 am

Oberon & writing files

Post 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;
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.
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.
cfbsoftware
Posts: 55
Joined: Wed Sep 18, 2013 10:06 pm
Contact:

Re: Oberon & writing files

Post 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:

https://miasap.se/obnc/getting-started.html

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:

https://lists.inf.ethz.ch/mailman/listinfo/oberon
jackD
Posts: 10
Joined: Fri Oct 15, 2021 9:10 am

Re: Oberon & writing files

Post 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.
Post Reply