home *** CD-ROM | disk | FTP | other *** search
/ Acorn User 2 / AUCD2.iso / program / vista.arc / c / msgtrans < prev    next >
Text File  |  1996-02-01  |  3KB  |  92 lines

  1. // **************************************************************************
  2. //                     Copyright 1996 David Allison
  3. //
  4. //             VV    VV    IIIIII     SSSSS     TTTTTT       AA
  5. //             VV    VV      II      SS           TT       AA  AA
  6. //             VV    VV      II        SSSS       TT      AA    AA
  7. //              VV  VV       II           SS      TT      AAAAAAAA
  8. //                VV       IIIIII     SSSS        TT      AA    AA
  9. //
  10. //                    MULTI-THREADED C++ WIMP CLASS LIBRARY
  11. //                                for RISC OS
  12. // **************************************************************************
  13. //
  14. //             P U B L I C    D O M A I N    L I C E N C E
  15. //             -------------------------------------------
  16. //
  17. //     This library is copyright. You may not sell the library for
  18. //     profit, but you may sell products which use it providing
  19. //     those products are presented as executable code and are not
  20. //     libraries themselves.  The library is supplied without any
  21. //     warranty and the copyright owner cannot be held responsible for
  22. //     damage resulting from failure of any part of this library.
  23. //
  24. //          See the User Manual for details of the licence.
  25. //
  26. // *************************************************************************
  27.  
  28.  
  29. //
  30. // message translator
  31. //
  32.  
  33. // this uses the RISC OS 3 MessageTrans module to do the translation
  34.  
  35. #include "Vista:msgtrans.h"
  36. #include <kernel.h>
  37. #include <swis.h>
  38. #include <stdlib.h>
  39.  
  40.  
  41. MsgTrans::MsgTrans (char *filename)
  42.    {
  43.    _kernel_swi_regs r ;
  44.    _kernel_oserror *e ;
  45.    is_open = 0 ;
  46.    r.r[1] = (int)filename ;
  47.    if ((e = _kernel_swi (MessageTrans_FileInfo, &r, &r)) != NULL)
  48.       throw (e) ;
  49.    if (r.r[0] & 1)
  50.       buffer = NULL ;
  51.    else
  52.       if ((buffer = (char*)malloc (r.r[2])) == NULL)
  53.          throw ("Out of memory") ;
  54. //
  55. //  now open the message file
  56. //
  57.    r.r[0] = (int)&desc ;
  58.    r.r[1] = (int)filename ;
  59.    r.r[2] = (int)buffer ;
  60.    if ((e = _kernel_swi (MessageTrans_OpenFile, &r, &r)) != NULL)
  61.       throw (e) ;
  62.    is_open = 1 ;
  63.    }
  64.  
  65. MsgTrans::~MsgTrans()
  66.    {
  67.    if (buffer != NULL)
  68.      free (buffer) ;
  69.    _kernel_swi_regs r ;
  70.    _kernel_oserror *e ;
  71.    is_open = 0 ;
  72.    r.r[0] = (int)&desc ;
  73.    if ((e = _kernel_swi (MessageTrans_CloseFile, &r, &r)) != NULL)
  74.       throw (e) ;
  75.    }
  76.  
  77. char *MsgTrans::lookup (char *token)
  78.    {
  79.    if (!is_open)
  80.       return token ;
  81.    _kernel_swi_regs r ;
  82.    _kernel_oserror *e ;
  83.    r.r[0] = (int)&desc ;
  84.    r.r[1] = (int)token ;
  85.    r.r[2] = 0 ;              // tell it not to copy the result
  86.    if ((e = _kernel_swi (MessageTrans_Lookup, &r, &r)) == NULL)
  87.       return (char*)r.r[2] ;
  88.    return token ;
  89.    }
  90.  
  91.  
  92.