home *** CD-ROM | disk | FTP | other *** search
/ Amiga MA Magazine 1998 #6 / amigamamagazinepolishissue1998.iso / coders / proasm / routines / locale.r < prev    next >
Text File  |  1994-03-31  |  5KB  |  218 lines

  1.  
  2. ;---;  locale.r  ;-------------------------------------------------------------
  3. *
  4. *    ****    locale support routines    ****
  5. *
  6. *    Author        Daniel Weber
  7. *    Version        0.90
  8. *    Last Revision    30.03.94
  9. *    Identifier    loc_defined
  10. *       Prefix        loc_    (locale)
  11. *                 ¯¯¯
  12. *    Functions    OpenCatalog, FreeCatalog, GetLocString
  13. *
  14. *    Note        - LocaleBase(pc) must be available or set to zero
  15. *              if localization impossible (f.e.: for OS2.0 or lower)
  16. *            - LOCALE_START and LOCALE_END must be set, see
  17. *              GetLocString for detailed information.
  18. *            - Use MakeCat or CatComp to generate a catalog.
  19. *            - The comment mark (;) is used here to store the old
  20. *              local.r source.
  21. *
  22. *    Flags        loc_A5    - based storage (xxx(a5) used everytime)
  23. *
  24. ;------------------------------------------------------------------------------
  25.  
  26.     IFND    loc_defined
  27. loc_defined    SET    1
  28.  
  29. ;------------------
  30. loc_oldbase    EQU __BASE
  31.     base    loc_base
  32. loc_base:
  33.  
  34. ;------------------
  35.     opt    sto,o+,ow-,q+,qw-        ;all optimisations on
  36.  
  37.  
  38. ;------------------------------------------------------------------------------
  39. *
  40. * OpenCatalog    - open a locale katalog
  41. *
  42. * INPUT:    a0: CatalogName
  43. *        (a5: Base)
  44. *
  45. * RESULT:    d0: Catalog
  46. *        d1: Locale  (ZERO if failed)
  47. *
  48. * NOTE:
  49. *
  50. * A catalog name should be defined as string labled as 'CatalogName'
  51. * (f.e.: CatalogName: dc.b "asx.catalog",0), if no such string is defined
  52. * the assembler may report an error (symbol not found) or OpenCatalogA()
  53. * goes crazy...
  54. *
  55. * OpenCatalog searches for the catalogs in the following places:
  56. *        PROGDIR:Catalogs/languageName/name
  57. *        LOCALE:Catalogs/languageName/name
  58. *
  59. * See the autodocs for more detailed information.
  60. *
  61. ;------------------------------------------------------------------------------
  62.     IFD    xxx_OpenCatalog
  63. OpenCatalog:
  64.     movem.l    d7/a0/a1/a6,-(a7)
  65.     moveq    #0,d1
  66.     IFND    loc_A5
  67. ;    lea    loc_base(pc),a5
  68.     move.l    LocaleBase(pc),d0        ;exist base?
  69.     ELSE
  70.     move.l    LocaleBase(a5),d0
  71.     ENDC
  72.     beq.s    .out
  73.     move.l    a0,d7            ;store CatalogName
  74.     move.l    d0,a6
  75.     sub.l    a0,a0
  76.     jsr    -156(a6)        ;OpenLocale(name=0) => default locale
  77. ;    move.l    d0,Locale(a5)
  78.     move.l    d0,d1
  79.     beq.s    .out            ;should not occure (says locale.doc)
  80.  
  81.     move.l    d0,-(a7)
  82.     move.l    d0,a0
  83. ;    lea    CatalogName(pc),a1
  84.     move.l    d7,a1
  85.     sub.l    a2,a2
  86.     jsr    -150(a6)        ;OpenCatalogA(locale,name,tagList)
  87. ;    move.l    d0,Catalog(a5)        ;=>catalog
  88.     move.l    (a7)+,d1
  89.  
  90. .out:    movem.l    (a7)+,_movemlist
  91.     rts
  92.  
  93.  
  94. ;Loacle:    dc.l    0        ;store the results of OpenLocale
  95. ;Catalog:    dc.l    0        ;and OpenCatalogA here
  96.  
  97.     ENDC
  98.  
  99. ;------------------------------------------------------------------------------
  100. *
  101. * FreeCatalog    - Free an opened catalog
  102. *
  103. * INPUT:    d0: Catalog
  104. *        d1: Locale
  105. *        (a5: Base)
  106. *
  107. * NOTE:    No checks are perfomed to test whether the input values are zero or not!
  108. *
  109. ;------------------------------------------------------------------------------
  110.     IFD    xxx_FreeCatalog
  111. FreeCatalog:
  112.     movem.l    d7/a0/a1/a6,-(a7)
  113.     IFND    loc_A5
  114.     move.l    LocaleBase(pc),d7
  115.     ELSE
  116.     move.l    LocaleBase(a5),d7
  117.     ENDC
  118.     beq.s    .out
  119.     move.l    d7,a6
  120.     move.l    d1,d7            ;store locale
  121.     beq.s    .out
  122. ;    move.l    Catalog(pc),a0
  123.     move.l    d0,a0
  124.     jsr    -36(a6)            ;CloseCatalog()
  125.  
  126. ;    move.l    Locale(pc),a0
  127.     move.l    d7,a0
  128.     jsr    -42(a6)            ;CloseLocale()
  129.  
  130. .out:    movem.l    (a7)+,_movemlist
  131.     rts
  132.     ENDC
  133.  
  134. ;------------------------------------------------------------------------------
  135. *
  136. * GetString    - get a localized string
  137. *
  138. * INPUT:    d0: Catalog
  139. *        a0: pointer to original string
  140. *        a1: LOCAL_START
  141. *        a2: LOCAL_END
  142. *        (a5: Base)
  143. *
  144. * RESULT:    d0: pointer localized string or originally passed string
  145. *
  146. * NOTES
  147. *
  148. * The returned string is NULL-terminated, and it is READ-ONLY, do NOT modify!
  149. * This string pointer is valid only as long as the catalog remains open.
  150. *
  151. * LOCALE_START and LOCALE_END is an area containing all texts for localization
  152. * f.e.:        LOCALE_START:
  153. *        CancelTxt:    dc.b    "Cancel",0
  154. *        OkTxt:        dc.b    "Ok",0
  155. *        ProAsmPathTxt:    dc.b    "ProAsm path",0
  156. *        <...>
  157. *        LOCALE_END:
  158. *
  159. ;------------------------------------------------------------------------------
  160.     IFD    xxx_GetLocString
  161. GetLocString:
  162.     movem.l    d1/d6-a1/a6,-(a7)
  163.     move.l    a0,d6            ;store original string
  164.     tst.l    d0
  165.     beq.s    .eout
  166.     IFND    loc_A5
  167.     move.l    LocaleBase(pc),d7
  168.     ELSE
  169.     move.l    LocaleBase(a5),d7
  170.     ENDC
  171.     beq.s    .eout
  172.     move.l    d7,a6
  173.     move.l    d0,d7            ;store catalog
  174. ;    move.l    Catalog(pc),d0
  175. ;    beq.s    .eout
  176.  
  177.     moveq    #0,d0
  178.     move.l    a0,d1
  179.     exg    a0,a1            ;LOCAL_START in a0
  180. ;    move.l    a0,a1
  181. ;    lea    LOCALE_END(pc),a0
  182. ;    cmp.l    a0,d1
  183.     cmp.l    a2,d1
  184.     bgt.s    .eout
  185. ;    lea    LOCALE_START(pc),a0
  186.     cmp.l    a0,d1
  187.     blt.s    .eout
  188.     sub.l    a0,d1
  189.     beq.s    .getit
  190.  
  191.  
  192. .loop:    tst.b    (a0)+
  193.     bne.s    .ok
  194.     addq.l    #1,d0
  195. .ok:    subq.l    #1,d1
  196.     bne.s    .loop
  197. .getit:    move.l    d7,a0            ;Catalog in a0
  198. ;    move.l    Catalog(pc),a0
  199.     jsr    -72(a6)            ;GetCatalogStr(catalog,strNum,defaultStr)
  200. .out:    movem.l    (a7)+,_movemlist
  201.     rts
  202. .eout:    move.l    d6,d0
  203.     bra.s    .out
  204.  
  205.     ENDC
  206.  
  207.  
  208. ;--------------------------------------------------------------------
  209.  
  210.     base    loc_oldbase
  211.     opt    rcl
  212.  
  213. ;------------------
  214.     ENDIF
  215.  
  216.  end
  217.  
  218.