home *** CD-ROM | disk | FTP | other *** search
/ Amiga Elysian Archive / AmigaElysianArchive.iso / anim / players / mpeg_src.lha / amiga / lib / iffpstrings.c next >
C/C++ Source or Header  |  1992-12-20  |  4KB  |  197 lines

  1. /* iffpstrings.c
  2.  *
  3.  *  centralized message routine for IFFP modules
  4.  *  If you plan to add international language support to
  5.  *  your iffparse application, all of the iffparse module
  6.  *  strings are here and are accessed via the SI() macro in
  7.  *  iffp/iff.h which calls GetString() 
  8.  *
  9.  *  There is some #ifdef'd out code here which will be useful if you
  10.  *  decide to localize your application when locale.library is released.
  11.  *
  12.  *  37.9 4/92   - fixed IFFerr() error equivalence tests and null string
  13.  *  37.10  7/92 - fixes to localization routine
  14.  */
  15.  
  16. #include <exec/types.h>
  17. #include <exec/memory.h>
  18. #include <exec/libraries.h>
  19. #include <intuition/intuition.h>
  20. #include <intuition/classes.h>
  21. #include <graphics/gfxbase.h>
  22. #include <graphics/gfxmacros.h>
  23. #include <graphics/modeid.h>
  24. #include <graphics/scale.h>
  25. #include <graphics/graphint.h>
  26. #include <dos/dos.h>
  27. #include <dos/exall.h>
  28.  
  29. /*
  30. #define LOCALIZED
  31. */
  32.  
  33. #define INCLUDENAME    "iffp/iffpstrings.h"
  34.  
  35. #ifdef LOCALIZED
  36. #define CATALOGNAME    "yourapp.catalog"
  37. #include <clib/locale_protos.h>
  38. #ifndef NO_SAS_PRAGMAS
  39. #include <pragmas/locale_pragmas.h>
  40. #endif
  41. #endif
  42.  
  43. /* Locale stuff */
  44. #define  IFFP_MODULES
  45. #define  STRINGARRAY
  46. #include INCLUDENAME
  47.  
  48. #ifdef LOCALIZED
  49. extern struct Library *LocaleBase;
  50. #endif
  51.  
  52. extern struct AppString AppStrings[];
  53. static APTR   catalog = NULL;
  54.  
  55. /* For reference
  56. struct AppString
  57. {
  58.     LONG   as_ID;
  59.     STRPTR as_Str;
  60. };
  61. */
  62.  
  63. #include "iffp/iff.h"
  64. #include <intuition/screens.h>
  65.  
  66. static UBYTE nullstring[] = {""};
  67.  
  68. /* OpenStrings - localizes strings
  69.  * Requires open locale.library to work, but safe to call without
  70.  * You may pass nulls as args if you have no localized application strings
  71.  */
  72.  
  73. #ifdef LOCALIZED
  74. void OpenStrings()
  75.    {
  76.    if((LocaleBase)&&(!catalog))
  77.     {
  78.     catalog = OpenCatalogA(NULL,CATALOGNAME,NULL);
  79.     }
  80.     }
  81. #endif
  82.  
  83. /* CloseStrings - release the localized strings 
  84.  * Make sure all error messages are printed BEFORE calling this function
  85.  */
  86. #ifdef LOCALIZED
  87. void CloseStrings()
  88.     {
  89.     if((LocaleBase)&&(catalog))
  90.     {
  91.         CloseCatalog(catalog);
  92.     }
  93.     }
  94. #endif
  95.  
  96. /*
  97.  * IFFerr
  98.  *
  99.  * Returns pointer to IFF Error string or NULL string (no error)
  100.  */
  101. UBYTE *IFFerr(LONG error)
  102. {
  103.     /*
  104.      * English error messages for possible IFFERR_#? returns from various
  105.      * IFF routines.  To get the index into this array, take your IFFERR
  106.      * code, negate it, and subtract one.
  107.      *  idx = -error - 1;
  108.      *
  109.      * To index localized string, then add MSG_IFFP_STDFIRST
  110.      */
  111.  
  112.     static UBYTE unknown[48];
  113.     UBYTE  *s = nullstring;
  114.  
  115.     if((error < 0)&&(error >= -12))
  116.         {
  117.         s=SI(((-error) - 1) + MSG_IFFP_STDFIRST);
  118.         }
  119.     else if(error == CLIENT_ERROR)
  120.         {
  121.         s=SI(MSG_IFFP_CLIENTERR);
  122.         }
  123.     else if(error == NOFILE)
  124.         {
  125.         s=SI(MSG_IFFP_NOFILE);
  126.         }
  127.     else if(error)
  128.         {
  129.         sprintf(unknown,SI(MSG_IFFP_UNKNOWNERR_D),error);
  130.         s=unknown;
  131.         }
  132.     return(s);
  133. }
  134.  
  135.  
  136. /* OpenScreen error messages
  137.  */
  138. UBYTE *openScreenErr(ULONG errorcode)
  139.    {
  140.    static UBYTE unknown[48];
  141.    UBYTE *s=NULL;
  142.  
  143.         switch ( errorcode )
  144.     {
  145.     case OSERR_NOMEM:
  146.         s=SI(MSG_IFFP_OSNOMEM);
  147.         break;
  148.     case OSERR_NOCHIPMEM:
  149.         s=SI(MSG_IFFP_OSNOCHIPMEM);
  150.         break;
  151.     case OSERR_NOMONITOR:
  152.         s=SI(MSG_IFFP_OSNOMONITOR);
  153.         break;
  154.     case OSERR_NOCHIPS:
  155.         s=SI(MSG_IFFP_OSNOCHIPS);
  156.         break;
  157.     case OSERR_PUBNOTUNIQUE:
  158.         s=SI(MSG_IFFP_OSPUBNOTUNIQUE);
  159.         break;
  160.     case OSERR_UNKNOWNMODE:
  161.         s=SI(MSG_IFFP_OSUNKNOWNMODE);
  162.         break;
  163.     default:
  164.         sprintf(unknown,SI(MSG_IFFP_OSUNKNOWNERR_D),errorcode);
  165.         s=unknown;
  166.     }
  167.     return(s);
  168.     }
  169.  
  170. static UBYTE *NULLSTRING = "";
  171.  
  172. UBYTE *GetString(ULONG id)
  173.     {
  174.     struct AppString *as;
  175.     UBYTE *s = NULLSTRING;
  176.     int k,l;
  177.  
  178.     l = sizeof(AppStrings) / sizeof(AppStrings[0]);
  179.     as = AppStrings;
  180.  
  181.     for(k=0; k<l; k++, as++)
  182.     {
  183.     if(as->as_ID == id)
  184.         {
  185.         s = as->as_Str;
  186.         break;
  187.         }
  188.     }
  189. #ifdef LOCALIZED
  190.     if((LocaleBase)&&(catalog)&&(*s))
  191.     {
  192.     s = GetCatalogStr(catalog,id,s);
  193.     }
  194. #endif
  195.     return(s);
  196.     }
  197.