home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format 115 / af115sub.adf / yahzee.lzx / yahzee / localize.c < prev    next >
C/C++ Source or Header  |  1998-06-03  |  2KB  |  108 lines

  1. /*
  2.  * localize.c
  3.  * ==========
  4.  * Handles localization of application.
  5.  *
  6.  * Copyright (C) 1994-1998 Håkan L. Younes (lorens@hem.passagen.se)
  7.  */
  8.  
  9. #include <exec/types.h>
  10. #include <exec/memory.h>
  11. #include <libraries/locale.h>
  12. #include "localize.h"
  13.  
  14. #include <clib/exec_protos.h>
  15. #include <clib/gadtools_protos.h>
  16. #include <clib/locale_protos.h>
  17.  
  18.  
  19. struct Library   *LocaleBase = NULL;
  20.  
  21. static struct LocaleInfo   li;
  22.  
  23.  
  24. STRPTR __asm
  25. GetString (
  26.    register __a0 struct LocaleInfo *li,
  27.    register __d0 LONG stringNum);
  28.  
  29.  
  30. void
  31. init_locale (
  32.    char  *catalog)
  33. {
  34.    li.li_LocaleBase = NULL;
  35.    if (LocaleBase = OpenLibrary ("locale.library", 38L))
  36.    {
  37.       li.li_LocaleBase = LocaleBase;
  38.       li.li_Catalog = OpenCatalogA (NULL, catalog, NULL);
  39.    }
  40. }
  41.  
  42. void
  43. finalize_locale (void)
  44. {
  45.    if (LocaleBase)
  46.    {
  47.       CloseCatalog (li.li_Catalog);
  48.       CloseLibrary (LocaleBase);
  49.    }
  50. }
  51.  
  52. char *
  53. localized_string (
  54.    LONG   string_num)
  55. {
  56.    return (char *)GetString (&li, string_num);
  57. }
  58.  
  59. struct Menu *
  60. CreateLocMenus (
  61.    struct NewMenu  *new_menus,
  62.    APTR             vis_info,
  63.    ULONG            tag,
  64.    ...)
  65. {
  66.    UWORD   i;
  67.    struct NewMenu  *nm;
  68.    struct Menu     *menus;
  69.    
  70.    i = 0;
  71.    while (new_menus[i++].nm_Type != NM_END)
  72.       ;
  73.    
  74.    if (!(nm = AllocVec (i * sizeof (struct NewMenu),
  75.                         MEMF_CLEAR | MEMF_PUBLIC)))
  76.    {
  77.       return NULL;
  78.    }
  79.    
  80.    while (i--)
  81.    {
  82.       nm[i] = new_menus[i];
  83.       
  84.       if (nm[i].nm_Label != NM_BARLABEL)
  85.       {
  86.          nm[i].nm_CommKey = GetString (&li, (LONG)nm[i].nm_Label);
  87.          nm[i].nm_Label = nm[i].nm_CommKey + 2;
  88.          if (nm[i].nm_CommKey[0] == ' ')
  89.             nm[i].nm_CommKey = NULL;
  90.       }
  91.    }
  92.    
  93.    if (menus = CreateMenusA (nm, (struct TagItem *)&tag))
  94.    {
  95.       if (!(LayoutMenus (menus, vis_info,
  96.                          GTMN_NewLookMenus, TRUE,
  97.                          TAG_DONE)))
  98.       {
  99.          FreeMenus (menus);
  100.          menus = NULL;
  101.       }
  102.    }
  103.    
  104.    FreeVec (nm);
  105.    
  106.    return menus;
  107. }
  108.