home *** CD-ROM | disk | FTP | other *** search
/ Network Support Encyclopedia 96-1 / novell-nsepro-1996-1-cd2.iso / download / netware / dn511.exe / DSLOCALE.CPP < prev    next >
Text File  |  1995-01-09  |  4KB  |  154 lines

  1. /*
  2. **    Copyright ⌐ 1994 Novell, Inc.  All rights reserved.
  3. **
  4. **    Permission is granted to the recipient of this work ("you") to use,
  5. **    reproduce and distribute Novell's original publication of the work free
  6. **    of charge provided that you reproduce the work in its entirety and
  7. **    include all Novell copyright notices as they originally appear.
  8. **
  9. **    Novell grants you permission to modify and distribute copies of this
  10. **    work including any portion of this work (a "modified work") provided
  11. **    that you include prominent notification of such modification along with
  12. **    the date of modification on a modified work; distribute or publish a
  13. **    modified work to third parties under the same conditions and granting
  14. **    the same rights as are extended to you by Novell under this under
  15. **    permission notice; and provided that you include a copy of Novell's
  16. **    original publication of the work along with any copy of a modified
  17. **    work.
  18. **
  19. **    NOVELL MAKES NO WARRANTY, REPRESENTATION OR PROMISE THAT THIS WORK OR A
  20. **    MODIFIED WORK WILL SATISFY YOUR REQUIREMENTS OR THAT THIS WORK OR A
  21. **    MODIFIED WORK IS WITHOUT DEFECT OR ERROR.  NOVELL DISCLAIMS AND
  22. **    EXCLUDES ANY AND ALL IMPLIED WARRANTIES OF MERCHANTABILITY, TITLE OR
  23. **    FITNESS FOR A PARTICULAR PURPOSE.
  24. **
  25. **    IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW WILL NOVELL OR ANY OTHER
  26. **    PARTY BE LIABLE FOR DAMAGES INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL,
  27. **    CONSEQUENTIAL, INDIRECT OR PUNATIVE DAMAGES ARISING OUT OF THE USE OF
  28. **    OR INABLITITY TO USE THE WORK OR A MODIFIED WORK.
  29. **
  30. **    DSLOCALE.CPP - October 1994
  31. **
  32. **    Initialise and release unicode tables
  33. **
  34. **    Author: John Buckle, Asia Pacific Support Centre, Novell Australia
  35. **    ==================================================================
  36. **    9 Jan 1995           First release              John Buckle
  37. */
  38.  
  39. # include "dsdefs.h"
  40. # include "dslocale.h"
  41.  
  42. # define NWL_EXCLUDE_FILE
  43. # define NWL_EXCLUDE_TIME
  44.  
  45. # include <dir.h>
  46.  
  47. # include <nwmisc.h>
  48. # include <unicode.h>
  49. # include <nwlocale.h>
  50.  
  51. /*
  52. ** int DSLocale::Initialised        Indicates if the tables have already
  53. **                    been loaded.
  54. */
  55.  
  56. int DSLocale::Initialised = 0 ;
  57.  
  58. /*
  59. ** DSLocale::DSLocale()
  60. **
  61. **    Initialises the unicode tables by searching all drives for the
  62. **    NLS directory. The memeber field Status records whether the tables
  63. **    were loaded.
  64. */
  65.  
  66. DSLocale::DSLocale()
  67. {
  68. LCONV    lconvInfo ;
  69.  
  70.     Status = 0 ; if (Initialised++) return ;
  71.  
  72.     NWCallsInit(0,0) ;
  73.     NWLsetlocale(LC_ALL,"") ;
  74.     NWLlocaleconv(&lconvInfo) ;
  75.  
  76.     int currentDrive = getdisk() ;
  77.  
  78.     if ((Status = NWInitUnicodeTables(lconvInfo.country_id,lconvInfo.code_page)) == 0)
  79.         return ;
  80.  
  81.     for (int drive = 'Z'-'A' ; drive > 'B'-'A' ; drive--){
  82.         if (foundUnicodeTables(drive,lconvInfo.country_id,lconvInfo.code_page)) break ;
  83.         }
  84.     setdisk(currentDrive) ;
  85.  
  86.     if (Status) return ;
  87.  
  88.     NWGetLocalToUnicodeHandle    (&LocalToUnicodeHandle) ;
  89.     NWGetUnicodeToLocalHandle    (&UnicodeToLocalHandle) ;
  90.     NWGetCollationHandle(&UnicodeToCollationHandle) ;
  91.     NWGetMonocaseHandle (&UnicodeToMonocaseHandle) ;
  92. }
  93.  
  94. /*
  95. ** DSLocale::DSLocale(int country, int codePage)
  96. **
  97. **    Initialises the unicode tables by searching all drives for the
  98. **    NLS directory. The memeber field Status records whether the tables
  99. **    were loaded.
  100. */
  101.  
  102. DSLocale::DSLocale(int country, int codePage)
  103. {
  104.     Status = 0 ; if (Initialised++) return ;
  105.  
  106.     int currentDrive = getdisk() ;
  107.  
  108.     if ((Status = NWInitUnicodeTables(country,codePage)) == 0)
  109.         return ;
  110.  
  111.     for (int drive = 'Z'-'A' ; drive > 'B'-'A' ; drive--){
  112.         if (foundUnicodeTables(drive,country,codePage)) break ;
  113.         }
  114.     setdisk(currentDrive) ;
  115. }
  116.  
  117. /*
  118. ** DSLocale::~DSLocale()
  119. **
  120. **    Releases the unicode tables if this is the last object using them.
  121. */
  122.  
  123. DSLocale::~DSLocale()
  124. {
  125.     if (--Initialised == 0 && Status == 0) NWFreeUnicodeTables() ;
  126. }
  127.  
  128. /*
  129. ** NWDSCCODE DSLocale::foundUnicodeTables(int drive, int country, int codePage)
  130. **
  131. **    Test the specified drive for the unicode tables, first in the drive's
  132. **    current directory and then in any NLS subdirectory.
  133. */
  134.  
  135. NWDSCCODE DSLocale::foundUnicodeTables(int drive, int country, int codePage)
  136. {
  137.     if (setdisk(drive) == -1)
  138.         return 0 ;
  139.  
  140.     if ((Status = NWInitUnicodeTables(country,codePage)) == 0)
  141.         return 1 ;
  142.  
  143.     if (chdir("NLS") == -1)
  144.         return 0 ;
  145.  
  146.     Status = NWInitUnicodeTables(country,codePage) ;
  147.  
  148.     chdir("..") ;
  149.  
  150.     return Status == 0 ;
  151. }
  152.  
  153.  
  154.