home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c480 / 19.ddi / SAMPLES / EXPENSE / CUSTDICT.C_ / CUSTDICT.C
Encoding:
C/C++ Source or Header  |  1993-02-08  |  4.5 KB  |  209 lines

  1. /************************************************************
  2.  
  3.     PROGRAM:    CUSTDICT.C     (for CUSTDICT.DLL)
  4.  
  5.     PURPOSE:
  6.     
  7.         The CUSTDICT dynamic link library is used by the expense
  8.         report (sample dictionary application) to perform dictionary
  9.         requests such as DIRQ_QUERY and DIRQ_STRING.
  10.  
  11.     COMMENTS:
  12.  
  13.  
  14. ************************************************************/
  15.  
  16. #define WIN31
  17. #define NOCOMM
  18.  
  19. #include <windows.h>
  20. #include <penwin.h>
  21. #include <string.h>
  22. #include "custdict.h"
  23.  
  24.  
  25. int __export CALLBACK LibMain(HANDLE hInstance, WORD wDataSeg
  26.                        , WORD wHeapSize, LPSTR lpszCmdLine)
  27. /***************************************************************
  28.  
  29. FUNCTION:    LibMain(HANDLE hInstance, WORD wDataSeg, 
  30.                                     WORD wHeapSize, LPSTR lpszCmdLine)
  31.  
  32. PURPOSE:
  33.     
  34.     DLL entry point. 
  35.  
  36. ***************************************************************/
  37.     {
  38.     if (wHeapSize > 0)
  39.             UnlockData(0);
  40.  
  41.     return TRUE;
  42.     }
  43.  
  44.  
  45.  
  46. VOID __export CALLBACK _WEP(int nParameter)
  47. /***************************************************************
  48.  
  49. FUNCTION:    WEP(int nParameter)
  50.  
  51. PURPOSE:
  52.     
  53.     DLL termination point.
  54.  
  55. ***************************************************************/
  56.     {
  57.     }
  58.  
  59.  
  60. int __export CALLBACK DictionaryProc(    int irq, LPVOID lpIn, LPVOID lpOut, int cbMax
  61.                                     , LONG lContext, LONG lD)
  62. /***************************************************************
  63.  
  64. FUNCTION: int FAR PASCAL DictionaryProc(int irq, LPVOID lpIn, LPVOID lpOut, 
  65.                                         int cbMax, LONG lContext, LONG lD)
  66.  
  67. PURPOSE:
  68.     
  69.     Process all DIRQ MESSAGES
  70.  
  71. ***************************************************************/
  72.     {
  73.     WORD wRet;
  74.     char rgSrc[cbMaxLen+1];
  75.     int i;
  76.  
  77.     wRet = FALSE;
  78.  
  79.     switch(irq)
  80.         {
  81.         case DIRQ_QUERY: /* query function */
  82.             {
  83.             int qIrq = *(int FAR *)lpIn;
  84.  
  85.             wRet = (    (qIrq == DIRQ_SUGGEST)        ||
  86.                         (qIrq == DIRQ_DESCRIPTION)    ||
  87.                         (qIrq == DIRQ_QUERY)            ||
  88.                         (qIrq == DIRQ_STRING)        ||
  89.                         (qIrq == DIRQ_INIT)            ||
  90.                         (qIrq == DIRQ_CLEANUP)
  91.                     );
  92.             }
  93.             break;
  94.         case DIRQ_DESCRIPTION:
  95.             wRet = GetDllDescription(lpOut,cbMax);
  96.             break;
  97.         case DIRQ_INIT:
  98.         case DIRQ_CLEANUP:
  99.             wRet = 1;
  100.             break;
  101.         case DIRQ_STRING: /* search string */
  102.             if (lpIn)
  103.                 {
  104.                 SymbolToCharacter((LPSYV)lpIn, cbMaxLen, rgSrc, NULL);
  105.                 if (FLookup((LPSTR)rgSrc))
  106.                     {
  107.                     for(i=0; i<cbMax; ++i)
  108.                         if(!(*((LPSYV)lpOut)++ = *((LPSYV)lpIn)++))
  109.                             break;     /* also copies the NULL */ 
  110.                     wRet = i;
  111.                     }
  112.                 }
  113.             break;
  114.         case DIRQ_SUGGEST:
  115.             if (lpIn)
  116.                 {
  117.                 SymbolToCharacter((LPSYV)lpIn, cbMaxLen, rgSrc, NULL);
  118.                 wRet = FBestGuess((LPSTR)rgSrc, (LPSYV)lpOut);
  119.                 }
  120.             break;
  121.         default:
  122.             break;
  123.         }
  124.  
  125.     return(wRet);
  126.     }
  127.  
  128.  
  129. BOOL NEAR PASCAL FBestGuess(LPSTR lpstr, LPSYV lpsyv)
  130. /***************************************************************
  131.  
  132.      
  133. FUNCTION: FBestGuess (LPSTR lpstr, LPSYV lpsyv)
  134.  
  135. PURPOSE:
  136.     
  137.     Return TRUE if the string pointed to by lpstr is one of the
  138.     strings in the Custom Dictionary rgszCustWords. 
  139.     Returns FALSE if the word is not found.
  140.  
  141. ***************************************************************/
  142.     {
  143.     int i;
  144.     WORD wRet = FALSE;
  145.  
  146.     /* Perform case-insensitive prefix matching with lpstr and
  147.         those words in the rgszCustWords */
  148.  
  149.     for (i=0; i<CUST_DICT_SIZE && !wRet; i++)
  150.         {
  151.         if (!_fstrnicmp(rgszCustWords[i],lpstr, lstrlen(lpstr)))
  152.             wRet = CharacterToSymbol(rgszCustWords[i], lstrlen(rgszCustWords[i]), lpsyv);
  153.         }
  154.  
  155.     return (wRet);
  156.     }
  157.  
  158.  
  159.  
  160. BOOL NEAR PASCAL FLookup(LPSTR lpstr)
  161. /***************************************************************
  162.  
  163.      
  164. FUNCTION: FLookup(LPSTR lpstr)
  165.  
  166. PURPOSE:
  167.     
  168.     Return TRUE if the string pointed to by lpstr is one of the
  169.     strings in the Custom Dictionary rgszCustWords. 
  170.     Returns FALSE if the word is not found.
  171.  
  172. ***************************************************************/
  173.     {
  174.     int i;
  175.     WORD wRet = FALSE;
  176.  
  177.     for (i=0; i<CUST_DICT_SIZE && !wRet; i++)
  178.         if (!lstrcmp((LPSTR)rgszCustWords[i], lpstr))
  179.             wRet = TRUE;
  180.  
  181.     return (wRet);
  182.     }
  183.  
  184.  
  185. int NEAR PASCAL GetDllDescription(LPSTR lpOut, int cbMax)
  186. /***************************************************************
  187.  
  188.      
  189. FUNCTION: GetDllDescription(LPSTR lpOut, int cbMax)
  190.  
  191. PURPOSE:
  192.     
  193.     Return the description string for this DLL
  194.  
  195. ***************************************************************/
  196.     {
  197.     int sizeT;
  198.  
  199.     sizeT = _fstrlen(szDescription);
  200.     sizeT = min(sizeT, cbMax-1);
  201.     _fstrncpy((LPSTR)lpOut,(LPSTR)szDescription, sizeT);
  202.     *((LPSTR)lpOut+sizeT) = '\0';
  203.     return(TRUE);
  204.     }
  205.  
  206.  
  207.  
  208.  
  209.