Tutorial: Handling Operating System Dependencies
Logo WebLord v2.2
The Document Assembly Tool

Tutorial: Handling Operating System Dependencies

From the beginning, WebLord addressed issues of operating system dependencies by providing to objects a variable to test: _OS. It is always available, although you could define your own to extend it if you like.

At the present time, WebLord can operate on three different operating systems. By testing the _OS variable, the script will find one of the following values:

Amiga
The script is being executed by an Amiga version of WebLord, running under AmigaOS.

Unix
The script is being executed on a Unix version of WebLord, running on a Unix (or Unix-like) operating system, such as FreeBSD, OpenBSD, Linux, Solaris, etc.

Win32
The script is running on a Microsoft Windows system, such as MS-Windows 95 or NT.

Selecting a value based on the current operating system

	text startup-file
	{
		select-case	= _OS;
		case:Amiga	= 's:startup-sequence';
		case:Unix	= '/bin/sh -c "cat ~/.bashrc"';
		case:Win32	= 'c:\autoexec.bat';
		case:		= NOFILE( msg =	'No startup-file known '
						'for O/S "' _OS '"' );
	}

	text NOFILE
	{
		echo	= ERROR++ msg;
		value	= '';	# needed to avoid complaint from evaluation engine
	}

We've thrown at you quite a load here, so if you have nodded wisely as you read the above, you are either fooling yourself, have done this before, or you are one smart person! :-)

Using SELECT-CASE

We have defined two objects. The first object defines no "value" property, but instead offers a "select-case" property, which has a value _OS. The result of the "select-case" property is then appended to the string "case:" and that property then serves to supply the value for the object.

If you think that you could put a quoted string on the left side of the "=" signs, think again! This is nothing but a dynamic selection of a property.

Generating Error Messages

Let's quickly examine what happens if _OS were to evaluate to nothing at all: The "case:" with this nothing appended would remain "case:" and the value of the "case:" property is a reference to the NOFILE object. This NOFILE object is being invoked with a list of properties (in key = value format, with multiple such properties separated, as always, with semicolons).

The NOFILE object echoes (to the output) the value of the "msg" property (which we defined in its argument list) and adds the value of a special object, the ERROR++ object. This object has no effect, other than to cause an error. This forces WebLord to stop processing.

Back to the STARTUP-FILE object

But back to what we set out to do: If the value of _OS evaluates to "Amiga" then "case:" and "Amiga" makes "case:Amiga"; the "case:Amiga" property is then examined and found to evaluate to "s:startup-sequence"; if we were running on a BeBox, then _OS would probably evaluate to "Be" and the "case:Be" property would supply the value for the "startup-file" object.

As no "case:Be" property is defined, the "case:" object is forced to supply a value. It invokes NOFILE with a "msg" property set to the value of 'No startup-file known for O/S "Be"' and WebLord will generate an error based on the presence of the (silent) ERROR++ symbol.


This material is Copyright © 1997,1998,1999,2000,2001 RingLord Technologies and Udo Schuermann. All rights reserved. The latest versions of the WebLord software and (this) documentation can be obtained from the WebLord Home Page (the link will only function if you are connected to the internet.)