home *** CD-ROM | disk | FTP | other *** search
- // **************************************************************************
- // Copyright 1996 David Allison
- //
- // VV VV IIIIII SSSSS TTTTTT AA
- // VV VV II SS TT AA AA
- // VV VV II SSSS TT AA AA
- // VV VV II SS TT AAAAAAAA
- // VV IIIIII SSSS TT AA AA
- //
- // MULTI-THREADED C++ WIMP CLASS LIBRARY
- // for RISC OS
- // **************************************************************************
- //
- // P U B L I C D O M A I N L I C E N C E
- // -------------------------------------------
- //
- // This library is copyright. You may not sell the library for
- // profit, but you may sell products which use it providing
- // those products are presented as executable code and are not
- // libraries themselves. The library is supplied without any
- // warranty and the copyright owner cannot be held responsible for
- // damage resulting from failure of any part of this library.
- //
- // See the User Manual for details of the licence.
- //
- // *************************************************************************
-
-
- //
- // message translator
- //
-
- // this uses the RISC OS 3 MessageTrans module to do the translation
-
- #include "Vista:msgtrans.h"
- #include <kernel.h>
- #include <swis.h>
- #include <stdlib.h>
-
-
- MsgTrans::MsgTrans (char *filename)
- {
- _kernel_swi_regs r ;
- _kernel_oserror *e ;
- is_open = 0 ;
- r.r[1] = (int)filename ;
- if ((e = _kernel_swi (MessageTrans_FileInfo, &r, &r)) != NULL)
- throw (e) ;
- if (r.r[0] & 1)
- buffer = NULL ;
- else
- if ((buffer = (char*)malloc (r.r[2])) == NULL)
- throw ("Out of memory") ;
- //
- // now open the message file
- //
- r.r[0] = (int)&desc ;
- r.r[1] = (int)filename ;
- r.r[2] = (int)buffer ;
- if ((e = _kernel_swi (MessageTrans_OpenFile, &r, &r)) != NULL)
- throw (e) ;
- is_open = 1 ;
- }
-
- MsgTrans::~MsgTrans()
- {
- if (buffer != NULL)
- free (buffer) ;
- _kernel_swi_regs r ;
- _kernel_oserror *e ;
- is_open = 0 ;
- r.r[0] = (int)&desc ;
- if ((e = _kernel_swi (MessageTrans_CloseFile, &r, &r)) != NULL)
- throw (e) ;
- }
-
- char *MsgTrans::lookup (char *token)
- {
- if (!is_open)
- return token ;
- _kernel_swi_regs r ;
- _kernel_oserror *e ;
- r.r[0] = (int)&desc ;
- r.r[1] = (int)token ;
- r.r[2] = 0 ; // tell it not to copy the result
- if ((e = _kernel_swi (MessageTrans_Lookup, &r, &r)) == NULL)
- return (char*)r.r[2] ;
- return token ;
- }
-
-
-