***************************************************************************
*                                                                         *
*  Project: RiscOS                                                        *
*                                                                         *
*  Module:  RISC_OSLib                                                    *
*                                                                         *
*  Created: Wed 24-Oct-90      By: Ran Mokady                             *
*                                                                         *
*  First version: 4.16                                                    *
*                                                                         *
*    Copyright:    (C) 1990, Acorn Computers Ltd., Cambridge, England.    *
*                                                                         *
***************************************************************************

Purpose:
========

C application support library for Risc OS.

***************************************************************************


Change Log:
===========


---------------------------------------------------------------------------

Version: 4.16 Wed 24-Oct-90        Ran Mokady                    


---------------------------------------------------------------------------

Version: 4.17 Wed 07-Nov-90        Jonathan Roach                

*  Add wimp_spritearea #define to wimp.h
*  Add dragasprite (dragasprit.h and dragasprit.c)
*  Use dragasprite for xfersend
*  Improve generation of save dbox icon to set ptr_hand over it

---------------------------------------------------------------------------

Version: 4.18 Wed 16-Jan-91        enevill                       

*  Stack extension / event interaction bug fixed
*  4.18 needed for DDE
*  C library sources now under source control (DDE 3.69)

---------------------------------------------------------------------------

Version: 4.19 Fri 01-Mar-91        philip colmer                 

*  longjmp in SVC mode fixed
*  IDJs edit bug fixes

---------------------------------------------------------------------------

Version: 4.20 Mon 11-Mar-91        Philip Colmer                 

*  support for BASIC tokenising/detokenising added to txtedit, txtfile
   and saveas

---------------------------------------------------------------------------

Version: 4.21 Sun 17-Mar-91        Ran Mokady                    

(Log entries by RM)

 Philip Colmer :- Fixed bug, old versions of !Edit confused by new BASIC code.
 Ran Mokady    :- Fixed stubs, and changed font.c to initialise zero data.

---------------------------------------------------------------------------

Version: 4.22 Mon 18-Mar-91        Ian Johnson                   

* bug fix in c.dbox, dbox_fillin_fixedcaret and dbox_fillin

---------------------------------------------------------------------------

Version: 4.23 Thu 11-Apr-91        Philip Colmer                 

* bug fix in c.txtfind, c.font

* removed BASIC support from c.saveas, changed BASIC support in c.txtedit,
  added support for new font menu in c.txtoptmenu

---------------------------------------------------------------------------

Version: 4.24 Fri 12-Apr-91        ENevill                       

* Text extraction & message lookup in C library

---------------------------------------------------------------------------

Version: 4.25 Sat 13-Apr-91        ENevill                       

* C locale stuff + lookup for RISC_OSLib messages file

---------------------------------------------------------------------------

Version: 4.26 Sat 13-Apr-91        Jonathan Coxhead

* New arguments to wimp_taskinit are expected if (and only if)
  *version >= 300, new header:

      os_error *wimp_taskinit (char *name, int *version /*inout*/,
            wimp_t *t /*out*/, ...);
      /* Name is the name of the program. Used instead of wimp_initialise,
         returns your task handle. *Version should be at least 200 on entry,
         and will return the current wimp version number. If *version >=
         300, a wimp_MCLOSEDOWN-terminated list of message numbers must be
         given.*/

* A new function wimpt_messages, as follows:

      /* ------------------------ wimpt_messages --------------------------
       * Description:   Tell wimpt which WIMP messages you understand.
       *
       * Parameters:    action, ... - a list of message numbers, terminated
       *                by wimp_MCLOSEDOWN (which every task must respond
       *                to)
       *
       * Returns:       void.
       *
       * Other Info:    Call this routine before calling wimpt_init, if you
       *                know about the message-masking feature of the WIMP
       *                present in version 3.00+. This list will be passed
       *                to SWI Wimp_Initialise. If you call this function
       *                without calling wimpt_version(), wimpt_init() will
       *                assume you know about WIMP 3.00.
       */
                      
      void wimpt_messages (wimp_msgaction, ...);

---------------------------------------------------------------------------

Version: 4.28 Wed 01-May-91        ENevill

* Improved error handling in C library kernel

---------------------------------------------------------------------------

Version: 4.29 Fri 21-Jun-91        ENevill                       

* _kernel_raise_error now unwinds stack and returns error to original caller
  if called from SVC mode.
* Now complains when trying to get a message from its message file and you
  have overloaded an old version (< 3.80).
* Calls TaskWindow_TaskInfo in _postmortem to see if this is a 'command'
  task.

---------------------------------------------------------------------------

Version: 4.30 Tue 02-Jul-91        Ian Johnson                   

* fixed wimpt_messages to not ignore first message
* added three entries back in for Draw and paint
* added help handlers for dboxtcol and magnifier
* removed window limit
* most other fixes detiled in version 1.31 of Edit


---------------------------------------------------------------------------

Version: 4.31 Fri 19-Jul-91        Ian Johnson                   

* new messages file
* fileicon now supports directory and application icons
* txtfile.c fixed for large BASIC file saving
* new cl.messages
* stop looking up error token twice
* remove arguments to _armsys_libinit 
* replaced quick sort with shell sort

---------------------------------------------------------------------------

Version: 4.32 Mon 05-Aug-91        Ian Johnson                   

 * new functions dboxquery_close and dboxquery_quit to implement style
   guide behaviour for quit and close
 * new rl_spare and rl_entries for above changes
 * new s.bastxt, c.txtedit, c.txtfile, h.verintern.messages for changes 
   listed in Edit change list
 * new messages file

---------------------------------------------------------------------------

Version: 4.33 Tue 27-Aug-91        ENevill                       

 * RISC OS 2.18 release

---------------------------------------------------------------------------

Version: 4.34 Wed 04-Sep-91        ENevill                       

 * Fixed out by 1 buffer size problem in system()
 * Use &FF0 as workspace pointer so loading grungy old clib works.

---------------------------------------------------------------------------

Version: 4.35 Mon 16-Sep-91        ENevill                       

 * Generate zero init stubs$$data in ROMStubs and ROMCStubs

---------------------------------------------------------------------------

Version: 4.36 Mon 23-Sep-91        ENevill                       

 * Fix RMA memory leakage bug.

---------------------------------------------------------------------------

Version: 4.37 Thu 26-Sep-91        RISC OS Build                 

 * Return to 4.35 version for Amber RISC OS.

---------------------------------------------------------------------------

Version: 4.38 Tue 05-Nov-91        RISC OS Build                 

 * Change wimpt_messages so it takes a pointer to a block of messages
   rather than a variadic argument list. Much neater.

---------------------------------------------------------------------------

Version: 4.39 Tue 19-Nov-91        ENevill                       

 * RP-0367: Tidied up edit menus.
 * Added new SWI veneers

                                   Jonathan Coxhead

 * Threw away msgs_, now uses MessageTrans
 * Added msgtrans_ (new module, header file only!)

---------------------------------------------------------------------------

Version: 4.40 Mon 25-Nov-91        ENevill                       

 * New swis.h. Removed SWI defs from c files


---------------------------------------------------------------------------

Version: 4.41 Tue 03-Dec-91        ENevill                       

 * Fixed bug in os_read_var_val which caused bytes to be chopped off the
   end of system variables

---------------------------------------------------------------------------

Version: 4.42 Mon 20-Jan-92        ENevill                       

RP-0484:   3.92 - Resets __icnt in __filbuf in case ESC happens in read
                - Allow malloc(0)
G-RO-8405:      - Fixed sscanf("123", "%d %d %d", ...)
                - Changed ROMStubs so they call ROM SWI directly for
                  applications as well as modules so !Configure works with
                  an overloaded C library.
                - Separated stubs into module stubs and application stubs
                  so a module or application need only link with the
                  appropriate stubs thus saving space.
RP-0750:        - Changed txtedit so click on save opens save dbox with
                  untitled file.
                - Added Cancel icon to "not tokenised BASIC" error

---------------------------------------------------------------------------

Version: 4.43 Mon 17-Feb-92        ENevill                       

Bug fix:     fopen now closes the file if it gets an error trying to set the
             file extent when opening a locked file for writing.
Performance: template loading speeded up be using Wimp_LoadTemplate to find
             the buffer size required for indirected data instead of reading
             the file and determining this itself.
Performance: Sprite file loading. If the sprite file is held in ResourceFS
             the file is not loaded. A direct pointer to the file data is
             used instead.

---------------------------------------------------------------------------

Version: 4.44 Thu 20-Feb-92        ENevill                       

Bug fix:     _kernel_RMAextend previously freed the block it had just
             extended by falling through to _kernel_RMAfree.
Bug fix:     wording for error messages changed.

---------------------------------------------------------------------------

Version: 4.45 Thu 20-Feb-92        ENevill                       

Bug fix:     More error messages changed.

---------------------------------------------------------------------------

Version: 4.46 Thu 12-Mar-92        ENevill                       

* Added SIGOSERROR to signals intercepted by wimpt_init.
  Prevents Postmortems being generated from RISCOS_Lib Apps
* Return error from _kernel_moduleentry if error claiming workspace.
  Allows DOSFS initialisation to fail gracefully
* Generate UpCall NewApplication in modulewrap before changing exit handler.
  Allows Obey module to free its workspace correctly

---------------------------------------------------------------------------

Version: 4.47 Fri 13-Mar-92        Owen Smith                    

* Added resspr_readfile() function - same as resspr_init() but you pass
  in the pathname of the Sprites file eg. "Configure:Sprites". This allows
  the ROM apps to have their directories split in half, which fixes
  RP-0716.

* New module_wrap from Edward - it was missing an instruction or something.

---------------------------------------------------------------------------

Version: 4.48 Thu 02-Apr-92        ENevill                       

* Module wrap now kills all instantiations but one on soft reset
* Module wrap preserves error after *WimpSlot for FilerAct
* New call wimpt_install_signal_handlers prevents postmortems before wimpt_init
* Read "Width" string from messages file in !Edits menu
---------------------------------------------------------------------------

Version: 4.48 Fri 03-Apr-92        Jonathan Coxhead

* New argument added to xfersend_print(). Not implemented yet though.

---------------------------------------------------------------------------

Version: 4.49 Mon 06-Apr-92        Jonathan Coxhead              

* Implemented as follows, in two parts: (j) if the Message_PrintSave is not
  acknowledged by a Message_PrintFile, xfersend_print() calls the printing
  argument. (Then, if there is a printer driver module loaded, printing will
  happen; otherwise, a call to PDriver_Info at some point in the printing
  code will cause a 'Printer driver not loaded' error to be reported to the
  user.) (ij) If Printers replies with Message_PrintTypeOdd, the same
  happens and xfersend_print() replies with Message_PrintTypeKnown. If a
  printing argument of NULL is supplied, Printers will try again with a
  Message_DataSaveAck and then the saving argument or sending argument will
  be used.

* Also, xfersend() does the same. Neither of these functions now responds to
  Message_PrintFile under any circumstances.

---------------------------------------------------------------------------

Version: 4.49 Thu 23-Apr-92        ENevill                       

RP-2240    Don't print "Internal error (<error>) for SIGOSERROR, just print
           <error>
A-RO-7016c Fixed wimpt1 message lookup.
           Check return code from dbox_new in magnify
RP-2385    Fix gmtime - subtract timezone and DST from local time
RP-2483    Return errors from _kernel_oswrch so printf returns an error if
           OS_WriteC fails.

---------------------------------------------------------------------------

Version: 4.49 Fri 24-Apr-92        JRoach                      

RP-2621    Don't address exception, but return error instead in ModuleWrap
           if module was entered, but wasn't enough RMA to get workspace.

---------------------------------------------------------------------------

Version: 4.50 Fri 30-Jul-93        ENevill                       

* Fix timezone bug, where negative timezones went wrong.
* Support use of characters other than '.' as decimal point in scanf, printf etc

* Support indirected menu titles when title is longer than 12 chars
* Extend fixed size text buffers in txtedit from 20 to 40
* Look up word "Selection"
* Removed assumptions about alphabetic chars in dbox

---------------------------------------------------------------------------

Version: 4.51 Thu 26-Aug-93        Owen Love                     

* Improvement in the wording of the error messages stored in the message
file as part of the Libra project.

---------------------------------------------------------------------------

Version: 4.52 Thu 02-Sep-93        Steve Cormie                  

* No longer assumes the size of application space or the position/size
  of the RMA.

---------------------------------------------------------------------------

Version: 4.53 Tue 21-Sep-93        ENevill                       

* Changed fclose so it allows fclose(0), returning -1 to indicate an error

---------------------------------------------------------------------------

Version: 4.54 Mon 04-Oct-93        ENevill                       

* Fixed prehistoric register corruption bug in _kernel_unwind

---------------------------------------------------------------------------

Version: 4.55 Thu 11-Nov-93        Jonathan Roach                

* MED-00925: with just the right amount of free memory, !Edit will fail to
convert a BASIC proggy when it's shift-double-clicked, but open an empty
window with the file's name - not safe! Bug was in txtfile.

---------------------------------------------------------------------------

Version: 4.56 Thu 11-Nov-93        Jonathan Roach                

MED-01175: No error message when printer status Inactive. RISC_OSLib was
failing to respond to PrintError messages in xfer_send.

MED-01173: Corrupt error message from !Edit when printer status inactive.
The txt part of RISC_OSLib was respoinding to PrintError messages, but
indexing to the wrong position to print the error.

MED-02078: as MED-01173.

---------------------------------------------------------------------------

Version: 4.56 Wed 19-Jan-94        Jonathan Roach                

Bring SharedCLibrary version up to SrcFiler version.

---------------------------------------------------------------------------

Version: 4.57 Fri 21-Jan-94        JCoxhead                      

dboxtcol.c - make colour model persistent
menu.c - various bugs fixed courtesy of Lionel Haines
wimp.c - pass TRUE to Wimp_ReadPalette, do not scale by 17/16
xfersend.c - only report a printer error if one is provided

---------------------------------------------------------------------------

Version: 4.58 Thu 10-Feb-94        William Stoye

txtar.c,wimpt.c - bug fix so that Edit notices EVERY mode change,
not just the ones that happen when it has windows open.

***************************************************************************
                      MEDUSA - RISC OS 3.50 build
***************************************************************************
*                                                                         *
*  Project: Black                                                         *
*                                                                         *
*  Module:  RISC_OSLib                                                    *
*                                                                         *
*  Created: Mon 01-Aug-94      By: Aideen McConville                      *
*                                                                         *
*  First version: 4.58                                                    *
*                                                                         *
*    Copyright:    (C) 1994, Acorn Computers Ltd., Cambridge, England.    *
*                                                                         *
***************************************************************************

Purpose:
========



***************************************************************************


Change Log:
===========


---------------------------------------------------------------------------

Version: 4.58 Mon 01-Aug-94        Aideen McConville             

Moved to new source tree.

---------------------------------------------------------------------------

Version: 4.59 Fri 19-Aug-94        Alan Glover                   

Fix bug MED-03572 (c.txtedit) Quitting edit from the task window whilst
there's a modified file causes the whole desktop to shut down when the
file is discarded

---------------------------------------------------------------------------

Version: 4.60 Tue 30-Aug-94        Alan Glover                   

Fix bug MED-03067 (c.txtedit, again). Was framing an error block and
not bothering to fill in an error number. Result was that spurious
fatal program errors sometimes occurred.

(AMcC) (30-Sep-94) also small change to c.txtfile (error reporting)
---------------------------------------------------------------------------

Version: 4.61 Tue 06-Sep-94        Aideen McConville             

* Makefile: added rom_link rule (needed for final stage of ROM Image build).

* s.version: updated to 4.61

---------------------------------------------------------------------------

Version: 4.62 Mon 26-Sep-94        Steve Cormie                  

* Fixed MED-03708:
  s.initmodule:                 Messages "Stub data size = " and
                                "Library data size = " now looked up in
                                Messages file.
  clib.Resources.UK.Messages:   Above messages added as C67, C68.
  kernel.s.k_body:              Sorted out _kernel_getmessage (could return
                                error pointer with no V set, also works for
                                :DEF:DEFAULT_TEXT now).
                                "registers at:" message only required for
                                :DEF:DEFAULT_TEXT.
  clib.s.cl_body:               "Postmortem" message only required for
                                :DEF:DEFAULT_TEXT.
  rlib.c.txtar:                 Debugging error removed.
  Makefile:                     Now builds lib.Clib (SharedCLibrary RAM module)
                                correctly.

---------------------------------------------------------------------------

Version: 4.63 Fri 28-Oct-94        Aideen McConville             

* Updated generation of swis.h (for Aquarius)
  hdr.SharedCLib: (new) contains SWI definitions (now included in swis.h)
  s.makeswis:     Generates SWI name defs for all SWIs listed in 3.50 PRM
                  Generates swis.h suitable for Aquarius

* s.modulewrap:   Looks for ResFiles in directory 's'.

* Makefile:       Exports hdr.SharedCLib (SWI defs)
                  Exports some files from rlib.h.EditIntern (needed by !Edit)
                  Generates o.c_abssym (c symbols only) as well as o.abssym -
                  some RISC_OSLib symbols clashed with symbols used by modules
                  that don't normally link with RISC_OSLib (e.g. RemPrnSpt).


---------------------------------------------------------------------------

Version: 4.64 Fri 28-Oct-94        Aideen McConville             

* Reinstated the following in the ROM library (needed by !Paint)

  - rlib.c.colourtran (colourtran_return_colourformode)
  - rlib.c.sprite     (sprite_get_given_rp)
  - rlib.c.wimp       (wimp_ploticon, wimp_which_icon)
  - rlib.c.win        (win_read_eventhandler)
  - rlib.s.rl_entries (reinstated above symbols)

---------------------------------------------------------------------------

Version: 4.65 Mon 31-Oct-94        Steve Cormie                  

* s.modulewrap: Make Filer_Action look up help/syntax in its own message file.
* Messages:     Added directed comments for message tokenisation.

---------------------------------------------------------------------------

Version: 4.66 Fri 25-Nov-94        Steve Cormie                  

* s.modulewrap: Other apps using modulewrap need to look up help and syntax
  for *Desktop_<AppName>.

---------------------------------------------------------------------------

Version: 4.67 Fri 25-Nov-94        Aideen McConville             

* Compatibility changes for 500 Series compiler:
    __rt_ symbols defined and exported as needed

  Changed files:
      clib.s.cl_body
      clib.s.cl_data
      clib.s.cl_entries
      kernel.s.k_body
      kernel.s.k_entries
      s.h_modmacro
      s.h_stubs

---------------------------------------------------------------------------

Version: 4.68 Fri 25-Nov-94        Aideen McConville             

* Create a 'special' Entries file (syms.A_Entries) that doesn't include
  swi and swix entries. This is necessary for ROM components that define
  their own versions of swi and swix (e.g. ShareFS)

  Changed files:
      syms.A_Entries (new)
      Makefile

---------------------------------------------------------------------------

Version: 4.69 Wed 30-Nov-94        Aideen McConville             

* Updated some CLib.h files in line with Aquarius versions:
      clib.h.ctype
      clib.h.kernel
      clib.h.math
      clib.h.stdio

* s.makeswis: Added Hdr:DragAnObj

* Makefile: Now exports ansilib
            Fixed typo: (o.rl.swi: --> o_rl.swi) to ensure that the correct
            definitions are copied to asmdefs before assembling swi

---------------------------------------------------------------------------

Version: 4.70 Mon 05-Dec-94        Steve Cormie                  

* Fixed MED-03597: s.modulewrap used ANDNV instructions as NOPs.

---------------------------------------------------------------------------

Version: 4.71 Fri 09-Dec-94        Steve Cormie                  

* Fixed MED-03777: s.initmodule and kernel.s.k_body used banked registers
  after a processor mode change.

---------------------------------------------------------------------------

Version: 4.72 Tue 03-Jan-95        Aideen McConville             

* s.makeswis: Added CDROM and SCSI SWIs (as requested by SPalmer)

---------------------------------------------------------------------------

Version: 4.73 Mon 09-Jan-95        Aideen McConville             

* s.makeswis: Added #defines for INR(..) and OUTR(..) and Usage comment
              (for Aquarius)

---------------------------------------------------------------------------

Version: 4.74 Wed 11-Jan-95        Steve Cormie                  

* s.initmodule, kernel.s.k_body: Fixed fixes made in version 4.71.
* clib.s.cl_body: Fixed MED-04254, pow(0,0) should have returned 1.
* c.stdio: Fixed MED-04294, setvbuf followed by getc failed to allocate a
  system buffer and hence crashed the machine.

---------------------------------------------------------------------------

Version: 4.75 Wed 18-Jan-95        Aideen McConville             

* MED-03784 - part of Fix (for !Edit) - look up Version/Date in Messages
  file and use to fill in ProgInfo template. Change in rlib.c.txtedit - part of
  RISC_OSLib but used only by !Edit (IJ).

* Moved rlib.h.EditIntern.editv to !Edit (not required by RISC_OSLib)

* Makefile: uptodate list of dynamic dependencies
            no longer exports rlib.h.EditIntern.editv

---------------------------------------------------------------------------

Version: 4.76 Wed 15-Feb-95        Steve Cormie                  

* h.hostsys, s.h_workspc, kernel.s.k_body, c.stdio - Fixed MED-04611:
  Function tmpnam() now uses byte in zero page as a counter and checks
  that the file name generated is not that of an existing file.

-----

Same version: Fri 17-Feb-95 AMcC - s.makeswis - changed Hdr:CDROMFS to Hdr:CDFS

---------------------------------------------------------------------------

Version: 4.77 Mon 27-Feb-95        Steve Cormie                  

* kernel.s.k_body - Fix made in version 4.76 prevented ansilib from being built.

---------------------------------------------------------------------------

Version: 4.78 Tue 28-Feb-95        JCoxhead                      

 * Fixed typo in dbox.c. (MED-04747)

AMcC: 29-Feb-95: Updated s.Version

---------------------------------------------------------------------------

Version: 4.79 Wed 01-Mar-95        Aideen McConville             

* Reinstated the following in the ROM library (needed by !Draw)

  - rlib.c.bbc        (bbc_gwindow)
  - rlib.s.rl_entries (reinstated above symbol)
  - s.Version

AMcConville (04-Apr-95): No new version

 * Makefile - export rule divided into two phases: export_hdrs, export_libs
              swis.h is created during the second phase (export_libs)
              This ensures that all components have exported their hdr files
              before any attempt is made to create swis.h