home *** CD-ROM | disk | FTP | other *** search
/ Media Share 9 / MEDIASHARE_09.ISO / utility / v11n06.zip / PCDICT.C < prev    next >
Text File  |  1992-01-02  |  7KB  |  232 lines

  1. //  PCDICT.C    The PCDICT.DLL sample Pen Windows dictionary
  2. //              module is used with DEMO5.EXE to demonstrate
  3. //              validation of user input and input completion
  4. //              by prefix matching.
  5. //  Copyright (C) 1991 Ray Duncan
  6.  
  7. #define WIN31
  8. #define NOCOMM
  9.  
  10. #include <windows.h>
  11. #include <penwin.h>
  12. #include <string.h>
  13. #include "pcdict.h"
  14.  
  15. #define cbMaxLen 256                        // max string size to process
  16.  
  17. #define dim(x) (sizeof(x) / sizeof(x[0]))   // returns no. of elements
  18.  
  19. char * szDesc = "PC Dictionary";
  20.  
  21. //
  22. // Hardwired wordlist of State names.  In a production dictionary,
  23. // the wordlist(s) would be loaded from a file specified by the 
  24. // client application program.
  25. //
  26. char * States[] = {
  27.     "Alabama",
  28.     "Alaska",
  29.     "Arizona",
  30.     "Arkansas",
  31.     "California",
  32.     "Colorado",
  33.     "Connecticut",
  34.     "Delaware",
  35.     "Florida",
  36.     "Georgia",
  37.     "Hawaii",
  38.     "Idaho",
  39.     "Illinois",
  40.     "Indiana",
  41.     "Iowa",
  42.     "Kansas",
  43.     "Kentucky",
  44.     "Louisiana",
  45.     "Maine",
  46.     "Maryland",
  47.     "Massachusetts",
  48.     "Michigan",
  49.     "Minnesota",
  50.     "Mississippi",
  51.     "Missouri",
  52.     "Montana",
  53.     "Nebraska",
  54.     "Nevada",
  55.     "New Hampshire",
  56.     "New Jersey",
  57.     "New Mexico",
  58.     "New York",
  59.     "North Carolina",
  60.     "North Dakota",
  61.     "Ohio",
  62.     "Oklahoma",
  63.     "Oregon",
  64.     "Pennsylvania",
  65.     "Rhode Island",
  66.     "South Carolina",
  67.     "South Dakota",
  68.     "Tennessee",
  69.     "Texas",
  70.     "Utah",
  71.     "Vermont",
  72.     "Virginia",
  73.     "Washington",
  74.     "West Virginia",
  75.     "Wisconsin",
  76.     "Wyoming" };
  77.  
  78. //
  79. // Table of dictionary commands supported by this DLL
  80. // and the functions which correspond to each command.
  81. //
  82. struct {                                    
  83.     int cmd_code;                       
  84.     int (*cmd_fxn)(int, LPVOID, LPVOID, int, LONG, LONG);
  85.     } commands[] = {
  86.     DIRQ_CLOSE, DictClose,
  87.     DIRQ_DESCRIPTION, DictDescription,
  88.     DIRQ_OPEN, DictOpen,
  89.     DIRQ_QUERY, DictQuery,
  90.     DIRQ_SETWORDLISTS, DictSetWordLists,
  91.     DIRQ_STRING, DictString,
  92.     DIRQ_SUGGEST, DictSuggest, } ;
  93.  
  94. //
  95. // LibMain -- Initialization routine for dynamic link library.
  96. // 
  97. int FAR PASCAL LibMain(HANDLE hInstance, WORD wDataSeg, 
  98.                        WORD wHeapSize, LPSTR lpszCmdLine)
  99. {
  100.     if (wHeapSize > 0)
  101.         UnlockData(0);
  102.  
  103.     return(TRUE);
  104. }
  105.  
  106. //
  107. // WEP -- called when use count for dynamic link library has
  108. //        reached zero and library is about to be unloaded.
  109. //
  110. int FAR PASCAL WEP(int nParam)
  111. {
  112.     return(TRUE);
  113. }
  114.  
  115. //
  116. // DictionaryProc -- Entry point to dictionary module for 
  117. //                   RC Manager and client programs.
  118. //
  119. int FAR PASCAL DictionaryProc(int dirq, LPVOID lpIn, LPVOID lpOut, 
  120.                               int cbMax, LONG lContext, LONG lData)
  121. {
  122.     int i;
  123.  
  124.     for(i = 0; i < dim(commands); i++)
  125.     {   
  126.         if(dirq == commands[i].cmd_code)
  127.             return((*commands[i].cmd_fxn)(dirq, lpIn, lpOut, cbMax, 
  128.                                           lContext, lData));
  129.     }
  130.     return(FALSE);
  131. }
  132.  
  133. //
  134. // DictClose -- function to process DIRQ_CLOSE messages.
  135. //
  136. int DictClose(int dirq, LPVOID lpIn, LPVOID lpOut, int cbMax, 
  137.               LONG lContext, LONG lData)
  138. {
  139.     return(TRUE);                           // stubbed out for now
  140. }
  141.  
  142. //
  143. // DictDescription -- function to process DIRQ_DESCRIPTION messages.
  144. //
  145. int DictDescription(int dirq, LPVOID lpIn, LPVOID lpOut, int cbMax, 
  146.                     LONG lContext, LONG lData)
  147. {                                           // return name of module
  148.     _fstrncpy((LPSTR) lpOut, (LPSTR) szDesc, min(cbMax-1, sizeof(szDesc)));
  149.     return(TRUE);
  150. }
  151.  
  152. //
  153. // DictOpen -- function to process DIRQ_OPEN messages.
  154. //
  155. int DictOpen(int dirq, LPVOID lpIn, LPVOID lpOut, int cbMax, 
  156.              LONG lContext, LONG lData)
  157. {
  158.     *(int far *) lpOut = TRUE;              // set dummy wordlist handle
  159.     return(TRUE);                           // return success
  160. }
  161.  
  162. //
  163. // DictQuery -- function to process DIRQ_QUERY messages.
  164. //
  165. int DictQuery(int dirq, LPVOID lpIn, LPVOID lpOut, int cbMax, 
  166.               LONG lContext, LONG lData)
  167. {
  168.     int i;
  169.  
  170.     for(i = 0; i < dim(commands); i++)      // check if command supported
  171.     {   
  172.         if(*(int far *) lpIn == commands[i].cmd_code)
  173.             return(TRUE);                   // yep, found it in table
  174.     }
  175.     return(FALSE);                          // nope, not supported
  176. }
  177.  
  178. //
  179. // DictSetWordLists -- function to process DIRQ_SETWORDLISTS messages.
  180. //
  181. int DictSetWordLists(int dirq, LPVOID lpIn, LPVOID lpOut, int cbMax, 
  182.                      LONG lContext, LONG lData)
  183. {
  184.     return(TRUE);                           // stubbed out for now
  185. }
  186.  
  187. //
  188. // DictString -- function to process DIRQ_STRING messages.
  189. //
  190. int DictString(int dirq, LPVOID lpIn, LPVOID lpOut, int cbMax, 
  191.                LONG lContext, LONG lData)
  192. {
  193.     int i;
  194.     char InStr[cbMaxLen+1];                 // receives input string
  195.  
  196.     if (lpIn)                               // any symbol string provided?
  197.     {                                       // translate it to char string
  198.         SymbolToCharacter((LPSYV)lpIn, cbMaxLen, InStr, NULL);
  199.  
  200.         for (i=0; i < dim(States); i++)     // perform case-insensitive
  201.         {                                   // match against States wordlist
  202.             if (! lstrcmpi((LPSTR) States[i], (LPSTR) InStr))
  203.                 return(CharacterToSymbol(States[i], lstrlen(States[i]), lpOut));
  204.         }   
  205.     }
  206.     return(FALSE);                          
  207. }
  208.  
  209. //
  210. // DictSuggest -- function to process DIRQ_SUGGEST messages.
  211. //
  212. int DictSuggest(int dirq, LPVOID lpIn, LPVOID lpOut, int cbMax, 
  213.                 LONG lContext, LONG lData)
  214. {
  215.     int i;
  216.     char InStr[cbMaxLen+1];                 // receives input string
  217.  
  218.     if (lpIn)                               // any symbol string provided?
  219.     {                                       // translate it to char string
  220.         SymbolToCharacter((LPSYV)lpIn, cbMaxLen, InStr, NULL);
  221.  
  222.         for (i=0; i < dim(States); i++)     // perform prefix matching
  223.         {                                   // against States wordlist
  224.             if(! _fstrnicmp(States[i], InStr, lstrlen(InStr)))
  225.                 return(CharacterToSymbol(States[i], lstrlen(States[i]), lpOut));
  226.         }
  227.     }
  228.     return(FALSE);
  229. }
  230.  
  231. 
  232.