
The !Compile Application
------------------------

C. J. Dollin, June, 1989
------------------------

The RISC-OS desktop provides a framework within which applications can
co-operate in loading and saving data. However, there are many activities
which are not catered for: in particular, those of us doing software 
development still have frequent recourse to the command line for doing
compilations and links.

The program presented in this article is a simple use of the Wimp to assist
in compilations. Installing the application "!Compile" adds another icon 
(a sewing machine - for stitching code together) to the icon bar. Dragging 
files from a directory into this icon will result in them being compiled.

Rather than building in a variety of compilation commands, !Compile uses a 
simple technique for deciding what compilation means for any given file:
the name of the directory within which the file resides is used to construct 
a command called

    comp_DIRECTORY

DIRECTORY is the "short" name of the directory, ie, not the full pathname. 
With suitable aliases set up, this is appropriate for Acorn's Pascal and C
compilations, as C files live in a directory called 'c', and Pascal files live 
in a directory called 'pas'.

    set alias$comp_c cc %*0
    set alias$comp_pas pascal %*0

Any output generated by the command will be put into a window automatically
by the Wimp. Of course, since the commands will usually not be Wimp tasks,
you will not be able to do any other operations while they execute.

Setting up:
-----------

If you are typing !Compile in, set up an application directory in the usual 
way (for details, see Risc User, Vol 2, Issue 4, pp20-21). Enter the !Boot and 
!Run files, and set their type to Obey:

    settype !Compile.!Boot Obey
    settype !Compile.!Run Obey

(assuming that the application is in the current directory). !Compile has
particularly simple !Boot and !Run files, as it does not create or use any
new kinds of files - all that need be done is set up the applications home
directory and establish the IconSprites file. Now enter the !Compile
program itself and save it as !RunImage.

The only remaining difficulty is setting up the sprite file. Rather than 
trying to type in a sprite file, I suggest you copy a !sprites file from an 
existing application, rename the sprites, and edit them to suit yourself.
For example, if you were to copy the !Mailman sprites, you would then
issue:

    sload !sprites
    srename !mailman !compile
    srename sm!mailman sm!compile
    ssave !sprites

!Compile would then use the postbox icon.

Program notes:
--------------

PROCsetup starts the Wimp and loads the sprite file into a byte array named
"sprites". FNcreate_sprite_icon is used to place the "!Compile" 
sprite on the right-hand side of the icon bar ("window" -1);
SYS "OS_SpriteOp" is used to find out the size of the sprite, and this is 
scaled from pixels to user co-ordinates with the scaling factors returned by
SUS "OS_ReadModVariable". The created icon is of just the right size to hold
the sprite.

Once setup is complete, the program sits in the usual Wimp_Poll loop,
waiting for messages - it ignores any clicks on its icon, as there is nothing
for it to do! When a message arrives, PROCreceive is used to decode it. It
ignores all but two types of message: type 0 (quit) messages, sent by the Wimp 
when a task should finish, and type 3 (load) messages, sent (usually) by the 
Filer when a file is dragged onto the !Compile icon.

Quit messages set Quit% to TRUE, which will end the polling loop and stop the
program. Load messages are handled by passing the name of the file to be loaded
to PROCload_file, which cuts it up into three pieces - the prefix, the 
directory, and the file. The file is the last part of the filename, and the 
directory is the name of the directory it appears in. All the rest (filing 
system name, other directories) is placed into the prefix.

!Compile checks to see if there is a suitable alias for this directory name,
using SYS "XOS_ReadVarVal". The (old) Programmers Reference Manual says that
to check for a variable existing, R2 (the 4th argument to SYS) should be
set negative. If it (the 3rd result from SYS) is still negative, the variable
exists; otherwise it does not.

If no such variable is found, PROCerror is used to report an error using SYS
Wimp_ReportError, which puts an error box onto the screen and waits for a 
mouse-click on its YES box. (This allows !Compile to give a more helpful 
message than "file not found", which is what we'd get if we just used WimpTask
without checking.) Otherwise the current directory is set to the
prefix (so that the compiler can find and place any associated files) and
OSCLI "WimpTask" used to run the compilation as another Wimp task. Using OSCLI 
directly would mean that !Compile would finish - not terribly useful if you 
want to do several compilations!

