main.c
------

History
-------
26th October 1992  J R C  Started

   The interface bettween the operating sustem and the rest of DrawGile is
held in this file. It defines functions |main_initialise| to initialise the
module, |main_swi| the SWI decoder, and |main_service| to handle service
calls (only one is relevant). It also contains the function |Terminate|
which is registered witht he C library as an exit handlr; this contains the
module termination code.

   There is a main programme |main| which  is only compiled if the
preprocessor flag TEST is set. This provides a main programme that calls the
same entry points as the SWI decoder, but as an application in user mode.
This is useful for debugging, since DDT is more helpful in user mode that it
is in supervisor mode. It renders the file RAM:$.TestFile.

   On initialisation, the module does the following:

         sets the C library to use the current territory;

         looks up DrawFile$Path, and loads the messages file found there
      into RAM (if it isn't already in ROM);

         creates three callback lists: one for verification of the draw file
      (see documentation on verify.c, in verify.doc), one for rendering (see
      render.doc) and one for declaring fonts (declare.doc).

Termination just reverses these changes. If there is an error on
initialisation, all incomplete pieces of intialisation are reversed.

   The SWI handler just calls |verify| to check the integrity of the draw
file, then either |render|, |bbox| or |declare| to do the work; this means
that the verification is done even for bad SWI numbers in the DrawFile SWI
chunk.

   The service call handler is needed only because the resource file
Messages might move. Therfore there is a Service_ResourceFSStarting handler,
which reneters ResourceFS by a direct call using the code

         (*(void (*) (resourcefs_file *, int, int, int)) regs->r [2])
               (resource_messages (), regs->r [1], regs->r [2],
               regs->r [3]);

   The file also contains three functions used in formatting error messages:
|main_format_int| formats an integer in decimal into a buffer;
|main_format_hex| does the same in hex; and |main_format_char| for a single
character. |Main_error_lookup| provides a convenient interface to
MessageTrans_ErrorLookup with a variable argument count.
