home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / mmpm21tk.zip / TK / CASECONV / CONVCVSR.C < prev    next >
C/C++ Source or Header  |  1993-04-05  |  10KB  |  348 lines

  1. /*static char *SCCSID = "@(#)convcvsr.c    13.2 92/02/15";*/
  2. #pragma title ("CONVCVSR.C - Case Converter I/O Proc Conversion Routines")
  3.  
  4. /********************** START OF SPECIFICATIONS *****************************/
  5. /*                                                                          */
  6. /* SOURCE FILE NAME: CONVCVSR.C                                             */
  7. /*                                                                          */
  8. /* DESCRIPTIVE NAME: CONV Procedure Conversion Support Routines.            */
  9. /*                                                                          */
  10. /* COPYRIGHT:                                                               */
  11. /*                  Copyright (c) IBM Corporation  1992, 1993               */
  12. /*                         All Rights Reserved                              */
  13. /*                                                                          */
  14. /* STATUS: MMPM/2 Release 1.10                                              */
  15. /*                                                                          */
  16. /* FUNCTION: This module contains resource input routines for the           */
  17. /*           Case Converter I/O Procedure.                                  */
  18. /*                                                                          */
  19. /* NOTES:                                                                   */
  20. /*    DEPENDENCIES: NONE                                                    */
  21. /*    RESTRICTIONS: Runs in protect mode only                               */
  22. /*                                                                          */
  23. /* ENTRY POINTS:                                                            */
  24. /*                                                                          */
  25. /*   ROUTINES: convhlpGetFormatStringLength                                 */
  26. /*             convhlpGetFormatString                                       */
  27. /*             convhlpGetNLSData                                            */
  28. /*                                                                          */
  29. /* EXTERNAL REFERENCES:                                                     */
  30. /*                                                                          */
  31. /*********************** END OF SPECIFICATIONS ******************************/
  32.  
  33. /*
  34.  * Set up defines to include the necessary definitions from the OS/2
  35.  * include files.
  36.  */
  37.  
  38. #define INCL_NOPMAPI                   // no PM include files required
  39. #define INCL_DOSRESOURCES
  40. #define INCL_DOSMODULEMGR
  41. #define INCL_CONVPROC                  // defines and prototypes for CONV
  42.  
  43. #include <os2.h>
  44. #include <mmioos2.h>
  45. #include <stdio.h>
  46. #include <stdlib.h>
  47. #include <string.h>
  48. #include "convproc.h"
  49.  
  50. #pragma subtitle ("convhlpGetFormatStringLength - ")
  51. #pragma page ()
  52.  
  53. /**************************************************************************
  54. **   convhlpGetFormatStringLength                                        **
  55. ***************************************************************************
  56. *
  57. * ARGUMENTS:
  58. *
  59. *     fccIOProc         - Fourcc of the IOProc requested.
  60. *     plNameLength      - Address where to return string length.
  61. *
  62. * RETURN:
  63. *
  64. *     Error code or 0.
  65. *
  66. * DESCRIPTION:
  67. *
  68. *     This function will retrieve the length of the format string
  69. *     for the specified IOProc from the resource file that contains
  70. *     the strings.
  71. *
  72. * GLOBAL VARS REFERENCED:
  73. *
  74. * GLOBAL VARS MODIFIED:
  75. *
  76. * NOTES:
  77. *
  78. * SIDE EFFECTS:
  79. *
  80. ***************************************************************************/
  81.  
  82. ULONG APIENTRY convhlpGetFormatStringLength( FOURCC fccIOProc,
  83.                                              PLONG plNameLength )
  84. {
  85.    HMODULE hModHandle;
  86.    PVOID   pResourceData;
  87.    CHAR    *pTemp;
  88.    FOURCC  fccTemp;
  89.  
  90.    /*
  91.     * Retrieve the data out of the resource, which is contained in the DLL.
  92.     * Select the entry for the specified IOProc and return the string
  93.     * length. Use the API call to get the DLL module handle from MMIO.
  94.     */
  95.  
  96.    if (mmioQueryIOProcModuleHandle( (PMMIOPROC)&CONVProc,
  97.                                     &hModHandle ))
  98.       {
  99.       return (MMIO_ERROR);
  100.       }
  101.  
  102.    if (DosGetResource( hModHandle,
  103.                        RT_RCDATA,
  104.                        CONV_IOPROC_NAME_TABLE,
  105.                        &pResourceData ))
  106.       {
  107.       return (MMIO_ERROR);
  108.       }
  109.  
  110.    /*
  111.     * The resource table is of the form : FOURCC String\0
  112.     * Loop until a match is found, then return the length.
  113.     */
  114.  
  115.    (*plNameLength) = 0L;
  116.    pTemp = (CHAR *)pResourceData;
  117.  
  118.    while (pTemp)
  119.       {
  120.       memmove( &fccTemp, pTemp, sizeof(FOURCC) );
  121.  
  122.       if (fccTemp == 0L)
  123.          {
  124.          break;
  125.          }
  126.  
  127.       if (fccTemp == fccIOProc)
  128.          {
  129.          pTemp += sizeof(FOURCC);
  130.  
  131.          if (pTemp == NULL)
  132.             {
  133.             break;
  134.             }
  135.  
  136.          (*plNameLength) = strlen( pTemp );
  137.          break;
  138.          }
  139.  
  140.       pTemp += sizeof(FOURCC);
  141.  
  142.       if (pTemp == NULL)
  143.          {
  144.          break;
  145.          }
  146.  
  147.       pTemp += (strlen( pTemp ) + 1);
  148.       }
  149.  
  150.    DosFreeResource( pResourceData );
  151.  
  152.    return ((((*plNameLength) > 0L) ? MMIO_SUCCESS : MMIO_ERROR));
  153. }
  154.  
  155. #pragma subtitle ("convhlpGetFormatString - ")
  156. #pragma page ()
  157.  
  158. /**************************************************************************
  159. **   convhlpGetFormatString                                              **
  160. ***************************************************************************
  161. *
  162. * ARGUMENTS:
  163. *
  164. *     fccIOProc         - Fourcc of the IOProc requested.
  165. *     pszFormatString   - Address where to return string.
  166. *     lBytes            - Number of bytes to copy.
  167. *
  168. * RETURN:
  169. *
  170. *     Error code or 0.
  171. *
  172. * DESCRIPTION:
  173. *
  174. *     This function will retrieve the format string for the specified
  175. *     IOProc from the resource file that contains the strings.
  176. *
  177. * GLOBAL VARS REFERENCED:
  178. *
  179. * GLOBAL VARS MODIFIED:
  180. *
  181. * NOTES:
  182. *
  183. * SIDE EFFECTS:
  184. *
  185. ***************************************************************************/
  186.  
  187. LONG APIENTRY convhlpGetFormatString( FOURCC fccIOProc,
  188.                                       PSZ pszFormatString,
  189.                                       LONG lBytes )
  190. {
  191.    HMODULE hModHandle;
  192.    PVOID   pResourceData;
  193.    CHAR    *pTemp;
  194.    LONG    lSizeCopied;
  195.    FOURCC  fccTemp;
  196.  
  197.    /*
  198.     * Retrieve the data out of the resource, which is contained in the DLL.
  199.     * Select the entry for the specified IOProc and return the string.
  200.     */
  201.  
  202.    if (mmioQueryIOProcModuleHandle( (PMMIOPROC)&CONVProc,
  203.                                     &hModHandle ))
  204.       {
  205.       return (MMIO_ERROR);
  206.       }
  207.  
  208.    if (DosGetResource( hModHandle,
  209.                        RT_RCDATA,
  210.                        CONV_IOPROC_NAME_TABLE,
  211.                        &pResourceData ))
  212.       {
  213.       return (MMIO_ERROR);
  214.       }
  215.  
  216.    /*
  217.     * The resource table is of the form : FOURCC String\0
  218.     * Loop until a match is found, then return the string.
  219.     * Copy up to the number of bytes specified.
  220.     */
  221.  
  222.    lSizeCopied = 0L;
  223.    pTemp = (CHAR *)pResourceData;
  224.  
  225.    while (pTemp)
  226.       {
  227.       memmove( &fccTemp, pTemp, sizeof(FOURCC) );
  228.  
  229.       if (fccTemp == 0L)
  230.          {
  231.          break;
  232.          }
  233.  
  234.       if (fccTemp == fccIOProc)
  235.          {
  236.          pTemp += sizeof(FOURCC);
  237.  
  238.          if (pTemp == NULL)
  239.             {
  240.             break;
  241.             }
  242.  
  243.          lSizeCopied = (LONG)(min( (LONG)strlen( pTemp ), lBytes ));
  244.          strncpy( pszFormatString, pTemp, (ULONG)lSizeCopied );
  245.          break;
  246.          }
  247.  
  248.       pTemp += sizeof(FOURCC);
  249.  
  250.       if (pTemp == NULL)
  251.          {
  252.          break;
  253.          }
  254.  
  255.       pTemp += (strlen( pTemp ) + 1);
  256.       }
  257.  
  258.    DosFreeResource( pResourceData );
  259.  
  260.    return (lSizeCopied);
  261. }
  262.  
  263. #pragma subtitle ("convhlpGetNLSData - ")
  264. #pragma page ()
  265.  
  266. /**************************************************************************
  267. **   convhlpGetNLSData                                                   **
  268. ***************************************************************************
  269. *
  270. * ARGUMENTS:
  271. *
  272. *     pulCodePage       - Address where to return the code page/country.
  273. *     pulLanguage       - Address where to return the language/dialect.
  274. *
  275. * RETURN:
  276. *
  277. *     Error code or 0.
  278. *
  279. * DESCRIPTION:
  280. *
  281. *     This function will retrieve the NLS information for the IOProc
  282. *     strings contained in the resource file.
  283. *
  284. * GLOBAL VARS REFERENCED:
  285. *
  286. * GLOBAL VARS MODIFIED:
  287. *
  288. * NOTES:
  289. *
  290. * SIDE EFFECTS:
  291. *
  292. ***************************************************************************/
  293.  
  294. ULONG APIENTRY convhlpGetNLSData( PULONG pulCodePage,
  295.                                   PULONG pulLanguage )
  296. {
  297.    HMODULE hModHandle;
  298.    PVOID   pResourceData;
  299.    CHAR    *pTemp;
  300.  
  301.    /*
  302.     * Retrieve the data out of the resource, which is contained in the DLL.
  303.     */
  304.  
  305.    if (mmioQueryIOProcModuleHandle( (PMMIOPROC)&CONVProc,
  306.                                     &hModHandle ))
  307.       {
  308.       return (MMIO_ERROR);
  309.       }
  310.  
  311.    if (DosGetResource( hModHandle,
  312.                        RT_RCDATA,
  313.                        CONV_NLS_CHARSET_INFO,
  314.                        &pResourceData ))
  315.       {
  316.       return (MMIO_ERROR);
  317.       }
  318.  
  319.    /*
  320.     * The resource table is of the form :
  321.     *   usCodePage     Low
  322.     *   usCountryCode  High
  323.     *   usLanguage     Low
  324.     *   usDialect      High
  325.     */
  326.  
  327.    pTemp = (CHAR *)pResourceData;
  328.  
  329.    while (pTemp)
  330.       {
  331.       memmove( pulCodePage, pTemp, sizeof(ULONG) );
  332.       pTemp += sizeof(ULONG);
  333.  
  334.       if (pTemp == NULL)
  335.          {
  336.          break;
  337.          }
  338.  
  339.       memmove( pulLanguage, pTemp, sizeof(ULONG) );
  340.  
  341.       break;
  342.       }
  343.  
  344.    DosFreeResource( pResourceData );
  345.  
  346.    return (MMIO_SUCCESS);
  347. }
  348.