Oberon & writing files

Programming language questions

Oberon & writing files

Postby jackD » Sun Oct 31, 2021 10:56 am

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.
jackD
 
Posts: 2
Joined: Fri Oct 15, 2021 9:10 am

Re: Oberon & writing files

Postby cfbsoftware » Sun Oct 31, 2021 12:32 pm

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
cfbsoftware
 
Posts: 48
Joined: Wed Sep 18, 2013 10:06 pm

Re: Oberon & writing files

Postby jackD » Sun Oct 31, 2021 3:22 pm

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.
jackD
 
Posts: 2
Joined: Fri Oct 15, 2021 9:10 am


Return to Component Pascal

Who is online

Users browsing this forum: No registered users and 1 guest

cron