A multi-file text-styles stripper - Directory.Convert

While developing in Oberon, occasionally the need may arise to process many files by a single command.

In this particular case we want to strip the styles and format information from e.g. all .Mod module text files.

The resulting plaintext files, even with CR line-endings, are often easier to handle during development when you use other software like a version control program or IDE on the Mac or PC, together with Oberon.

Also, conversion to plaintext is a necessary first step before translating to LF or CRLF line ends for export..

Processing many files within a single user command execution however puts a heavy load on Oberon, because each opened file remains open until the command terminates and the garbage collector has a chance to reclaim file resources.

Therefore Directory.Convert will execute small batches in the background, in this case not to create a "continuous" task, but rather to limit peak resource usage.

The following requirements for Directory.Convert are put forward:

The implementation in Oberon is straightforward, especially since the entire task can easily be split into small portions that can be executed by the Tasks mechanism.

We will borrow code from System.Directory, and System.List: they implement a good mechanism to interpret wildcard file spec arguments. However the code needs to be copied into our program, because we don't want to alter System.Mod. Note that System.Directory itself does not have to deal with overloading Oberon file resources, because it does not actually need to open files in order to list them.

Since the number of files is potentially large, we will keep a queue of to-be-processed files as a (unregistered, anonymous) task file.

Each activation of the Directory.Convert command results in depositing the names of the wanted files to the tail of the queue, tracked by taskW, i.e. they are appended to the task file. The activation also causes the Oberon Task to be switched on.

Each time the task is executed by Oberon, max 10 filenames (set by the constant taskLoad) are read from the head of the queue, which is tracked by the taskR rider. After each task execution, the garbage collector is prompted to do its magic asap.

When all files in the queue are processed, the head (taskR) and tail (taskW) riders are reset to the start of a fresh task file and the Oberon task is stopped. New user commands can safely be issued before Convert is ready (if you are in a hurry).

Note: This utility should be used with care, since e.g. "Directory.Convert *" will remove the styles/formats from all of your Oberon Text files! It does not create .Bak files but strips them too (if matching the pattern). Klingons don't take prisoners!

Typical usage would be more like "Directory.Convert *.Mod" to strip only source code texts.

The "Directory" module is available for download in case you don't want to program it yourself.

If used on another Project Oberon system (i.e. not Oberon Workstation) the import item "FileDir := FileDirOSX" should be replaced by just "FileDir", assuming a standard (Wirth) Oberon implementation.