Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1623 lines
47 KiB

  1. /*************************************************
  2. * basefunc.c *
  3. * *
  4. * Copyright (C) 1995-1999 Microsoft Inc. *
  5. * *
  6. *************************************************/
  7. #include <io.h>
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10. #include <stdarg.h>
  11. #include <windows.h>
  12. #include <string.h>
  13. #include <winbase.h>
  14. #include <commdlg.h>
  15. #include "conv.h"
  16. #include "propshet.h"
  17. #define MAX_VALUE_NAME 256
  18. #ifdef UNICODE
  19. TCHAR szCaption[] = {0x8F93, 0x5165, 0x6CD5, 0x751F, 0x6210, 0x5668, 0x0000};
  20. #else
  21. BYTE szCaption[] = "���뷨������"
  22. #endif
  23. /**** delete all spaces of string *****/
  24. void DelSpace(LPTSTR szStr)
  25. {
  26. TCHAR szStr1[512];
  27. int len,count=0;
  28. register int i=0;
  29. len = lstrlen(szStr);
  30. do {
  31. if(szStr[i] == 32||szStr[i] == TEXT('\t')) continue;
  32. szStr1[count] = szStr[i];
  33. if(szStr1[count] >= TEXT('A') && szStr1[count] <= TEXT('Z'))
  34. szStr1[count] |= 0x20;
  35. count ++;
  36. } while(i++<len);
  37. szStr1[count] = 0;
  38. lstrcpy(szStr,szStr1);
  39. }
  40. //***** start
  41. int GetEntryString(LPTSTR szSrcStr,
  42. LPTSTR szEntryName,
  43. LPTSTR szDefaultStr,
  44. LPTSTR szGetStr,
  45. DWORD dwLength
  46. )
  47. {
  48. LPTSTR lpStr;
  49. TCHAR szName[256];
  50. GetEntryName(szSrcStr, szName);
  51. lpStr = _tcschr(szSrcStr,TEXT('='));
  52. if(lpStr == NULL)
  53. {
  54. lstrcpy(szGetStr, szDefaultStr);
  55. return TRUE;
  56. }
  57. else if(lstrcmpi(szEntryName, szName) != 0)
  58. {
  59. lstrcpy(szGetStr, szDefaultStr);
  60. return FALSE;
  61. }
  62. else
  63. {
  64. lstrcpy(szGetStr, lpStr+1);
  65. return TRUE;
  66. }
  67. }
  68. int GetEntryInt(LPTSTR szSrcStr,
  69. LPTSTR szEntryName,
  70. int nDefault,
  71. LPINT fnPrivateInt
  72. )
  73. {
  74. LPTSTR lpStr;
  75. TCHAR szName[256];
  76. GetEntryName(szSrcStr, szName);
  77. lpStr = _tcschr(szSrcStr,TEXT('='));
  78. if(lpStr == NULL)
  79. {
  80. *fnPrivateInt = nDefault;
  81. return TRUE;
  82. }
  83. else if( lstrcmpi(szEntryName, szName) != 0)
  84. {
  85. *fnPrivateInt = nDefault;
  86. return FALSE;
  87. }
  88. else
  89. {
  90. lstrcpy(szName, lpStr+1);
  91. *fnPrivateInt = _ttoi(szName);
  92. return TRUE;
  93. }
  94. }
  95. void GetEntryName(LPTSTR szSrcStr, LPTSTR szEntryName)
  96. {
  97. LPTSTR lpStr;
  98. lstrcpy(szEntryName,szSrcStr);
  99. if((lpStr = _tcschr(szEntryName,TEXT('='))) == NULL)
  100. szEntryName[0] = 0;
  101. else
  102. *lpStr = 0;
  103. }
  104. //***** end 95.10.11
  105. BOOL ParseDBCSstr(HWND hWnd,
  106. TCHAR *szInputStr,
  107. LPTSTR szDBCS,
  108. LPTSTR szCodeStr,
  109. LPTSTR szCreateStr,
  110. WORD wMaxCodes)
  111. {
  112. int i, len, nDBCS = 0, nCodes = 0;
  113. TCHAR szStr[512], szTmpStr[256];
  114. #ifdef UNICODE
  115. len = lstrlen(szInputStr);
  116. for(i=0; i<len-1; i++) {
  117. if(szInputStr[i] > 0x100)
  118. nDBCS++;
  119. else
  120. break;
  121. }
  122. #else
  123. len = lstrlen(szInputStr);
  124. for(i=0; i<len-1; i+= 2) {
  125. if( ((UCHAR)szInputStr[i] < 0 || (UCHAR)szInputStr[i] > (UCHAR)0x80) &&
  126. ((UCHAR)szInputStr[i+1] >= 0x40 && (UCHAR)szInputStr[i+1] <= (UCHAR)0xfe &&
  127. (UCHAR)szInputStr[i+1] != (UCHAR)0x7f) )
  128. nDBCS += 2;
  129. else
  130. break;
  131. }
  132. #endif
  133. if(nDBCS == 0)
  134. {
  135. /* LoadString(NULL, IDS_NOTEXISTDBCS, szTmpStr, sizeof(szTmpStr));
  136. wsprintf(szStr,"\'%s%lu)",szTmpStr,dwLineNo);
  137. FatalMessage(hWnd,szStr);*/
  138. return -1;
  139. }
  140. lstrncpy(szDBCS,nDBCS,szInputStr);
  141. szDBCS[nDBCS] = 0;
  142. lstrcpy(szStr,&szInputStr[nDBCS]);
  143. trim(szStr);
  144. len = lstrlen(szStr);
  145. if(len > 0)
  146. {
  147. for(i = 0; i<len; i++)
  148. {
  149. if((int)szStr[i] == 32 || szStr[i] == TEXT('\t'))
  150. break;
  151. nCodes++;
  152. }
  153. }
  154. else
  155. nCodes = 0;
  156. if(nCodes > wMaxCodes) {
  157. LoadString(NULL, IDS_DBCSCODELEN, szTmpStr, sizeof(szTmpStr)/sizeof(TCHAR));
  158. #ifdef UNICODE
  159. {
  160. TCHAR UniTmp[] = {0x884C, 0x0000};
  161. wsprintf(szStr, TEXT("\'%ws\'%ws%d!(%ws:%lu)"),
  162. szDBCS,szTmpStr,wMaxCodes,UniTmp,dwLineNo);
  163. }
  164. #else
  165. wsprintf(szStr,"\'%s\'%s%d!(��:%lu)",
  166. szDBCS,szTmpStr,wMaxCodes,dwLineNo);
  167. #endif
  168. FatalMessage(hWnd,szStr);
  169. return FALSE;
  170. //szStr[wMaxCodes] = 0;
  171. }
  172. lstrncpy(szCodeStr,nCodes, szStr);
  173. szCodeStr[nCodes] = 0;
  174. DelSpace(szCodeStr);
  175. lstrcpy(szCreateStr,&szStr[nCodes]);
  176. szCreateStr[MAXCODELEN] = 0;
  177. DelSpace(szCreateStr);
  178. return TRUE;
  179. }
  180. /**** delete spaces of string's head and tail *****/
  181. void trim(LPTSTR szStr)
  182. {
  183. register int i=0;
  184. UINT len ;
  185. while(szStr[i] == 32 || szStr[i] == TEXT('\t'))
  186. i++;
  187. lstrcpy(szStr,&szStr[i]);
  188. len = lstrlen(szStr);
  189. if(len == 0) return;
  190. i = 1;
  191. while(szStr[len-i] == 32
  192. || szStr[len-i] == TEXT('\r')
  193. || szStr[len-i] == TEXT('\n')
  194. || szStr[len-i] == TEXT('\t')
  195. || szStr[len-i] == 0)
  196. i++;
  197. szStr[len-i+1] = 0;
  198. len = lstrlen(szStr);
  199. for(i=0; i<(int)len; i++)
  200. {
  201. if(szStr[i] > 0x100)
  202. continue;
  203. if(szStr[i] >= TEXT('A') && szStr[i] <= TEXT('Z'))
  204. szStr[i] |= 0x20;
  205. }
  206. }
  207. void fnsplit(LPCTSTR szFullPath, LPTSTR szFileName)
  208. {
  209. LPTSTR lpString;
  210. #ifdef UNICODE
  211. if((lpString=wcsrchr(szFullPath,TEXT('\\')))!=NULL)
  212. #else
  213. if((lpString=strrchr(szFullPath,TEXT('\\')))!=NULL)
  214. #endif
  215. lstrcpy(szFileName,lpString+1);
  216. else
  217. lstrcpy(szFileName,szFullPath);
  218. }
  219. BOOL ErrMessage(HANDLE hWnd,LPTSTR lpText)
  220. {
  221. int RetValue;
  222. RetValue = MessageBox(hWnd,
  223. lpText,
  224. szCaption,
  225. MB_ICONEXCLAMATION|MB_YESNO|MB_DEFBUTTON2);
  226. if(RetValue == IDYES)
  227. return TRUE;
  228. else
  229. return FALSE;
  230. }
  231. VOID WarnMessage(HANDLE hWnd,LPTSTR lpText)
  232. {
  233. MessageBox(hWnd,lpText,szCaption,MB_ICONEXCLAMATION|MB_OK);
  234. }
  235. VOID InfoMessage(HANDLE hWnd,LPTSTR lpText)
  236. {
  237. MessageBox(hWnd,lpText,szCaption,MB_ICONINFORMATION|MB_OK);
  238. }
  239. VOID FatalMessage(HANDLE hWnd,LPTSTR lpText)
  240. {
  241. MessageBox(hWnd,lpText,szCaption,MB_ICONSTOP|MB_OK);
  242. }
  243. void lstrncpy(LPTSTR lpDest,int nCount,LPTSTR lpSrc)
  244. {
  245. register int i;
  246. BOOL bEnd = FALSE;
  247. for(i=0; i<nCount; i++) {
  248. if(lpSrc[i] == 0)
  249. bEnd = TRUE;
  250. if(bEnd)
  251. lpDest[i] = 0;
  252. else
  253. lpDest[i] = lpSrc[i];
  254. }
  255. }
  256. void lstrncpy0(LPTSTR lpDest,int nCount,LPTSTR lpSrc)
  257. {
  258. register int i;
  259. BOOL bEnd = FALSE;
  260. for(i=0; i<nCount; i++)
  261. lpDest[i] = lpSrc[i];
  262. }
  263. /**************************************************************************
  264. * HANDLE CreateMapFile(HANDLE hWnd,char *MapFileName)
  265. *
  266. * Purpose: Create a Map file to map named share memory
  267. *
  268. * Inputs: hWnd - parent window's handle
  269. * *MapFileName - pointer to map file name
  270. *
  271. * Returns: MapFileHandle - a handle to the file
  272. * or NULL if failure
  273. *
  274. * Calls: CreateFile, ErrorOut
  275. *
  276. * History:
  277. *
  278. *
  279. \**************************************************************************/
  280. HANDLE CreateMapFile(HANDLE hWnd,TCHAR *MapFileName)
  281. {
  282. HANDLE MapFileHandle;
  283. MapFileHandle= CreateFile(MapFileName,
  284. GENERIC_READ | GENERIC_WRITE,
  285. FILE_SHARE_READ | FILE_SHARE_WRITE,
  286. NULL,
  287. CREATE_ALWAYS,
  288. FILE_ATTRIBUTE_NORMAL /* | STANDARD_RIGHTS_REQUIRED |
  289. FILE_MAP_WRITE | FILE_MAP_READ */,
  290. NULL);
  291. if (MapFileHandle == (HANDLE)-1)
  292. {
  293. ErrorOut(hWnd,TEXT("CreateFile"));
  294. return(NULL);
  295. }
  296. else
  297. return(MapFileHandle);
  298. }
  299. /**************************************************************************
  300. * HANDLE CreateMap(HANDLE hWnd,HANDLE *FileToBeMapped, char MapName[128] )
  301. *
  302. * Purpose: Create File Mapping object using the open file handle
  303. *
  304. * Inputs: hWnd - parent window's handle
  305. * *FileToBeMapped - pointer to the file handle
  306. *
  307. * Returns: MapHandle - handle to the file mapping object
  308. * or NULL if failure
  309. *
  310. * Calls: CreateFileMapping, ErrorOut
  311. *
  312. * History:
  313. *
  314. *
  315. \**************************************************************************/
  316. HANDLE CreateMap(HANDLE hWnd,HANDLE *FileToBeMapped, TCHAR MapName[128])
  317. {
  318. HANDLE MapHandle;
  319. MapHandle= CreateFileMapping(*FileToBeMapped,
  320. NULL,
  321. PAGE_READWRITE,
  322. 0,
  323. 4096,
  324. MapName);
  325. if (MapHandle == NULL)
  326. {
  327. ErrorOut(hWnd,TEXT("CreateFileMapping"));
  328. return(NULL);
  329. }
  330. else
  331. return(MapHandle);
  332. }
  333. /**************************************************************************
  334. * LPVOID MapView(HANDLE *hMap)
  335. *
  336. * Purpose: Map the file mapping object into address space
  337. *
  338. * Inputs: *hMap - pointer to the mapping object
  339. *
  340. * Returns: MappedPointer - pointer to the address space that the
  341. * object is mapped into
  342. * or NULL if failure
  343. *
  344. * Calls: MapViewOfFile, ErrorOut
  345. *
  346. * History:
  347. *
  348. *
  349. \**************************************************************************/
  350. LPVOID MapView(HANDLE hWnd,HANDLE *hMap)
  351. {
  352. LPVOID MappedPointer;
  353. MappedPointer= MapViewOfFile(*hMap,
  354. FILE_MAP_WRITE | FILE_MAP_READ,
  355. 0,
  356. 0,
  357. 4096);
  358. if (MappedPointer == NULL)
  359. {
  360. ErrorOut(hWnd,TEXT("MapViewOfFile"));
  361. return(NULL);
  362. }
  363. else
  364. return(MappedPointer);
  365. }
  366. /************************************************************************
  367. * void ErrorOut(HANDLE ghwndMain,char errstring[128])
  368. *
  369. * Purpose: Print out an meainful error code by means of
  370. * GetLastError and printf
  371. *
  372. * Inputs: ghwndMain - WinMain's HANDLE
  373. * errstring - the action that failed, passed by the
  374. * calling proc.
  375. *
  376. * Returns: none
  377. *
  378. * Calls: GetLastError
  379. *
  380. * History:
  381. *
  382. *
  383. \************************************************************************/
  384. void ErrorOut(HANDLE ghwndMain,TCHAR errstring[128])
  385. {
  386. DWORD Error;
  387. TCHAR str[80];
  388. Error= GetLastError();
  389. wsprintf((LPTSTR) str, TEXT("Error on %s = %d\n"), errstring, Error);
  390. MessageBox(ghwndMain, (LPTSTR)str, TEXT("Error"), MB_OK);
  391. }
  392. /*************************************************************************
  393. * HANDLE OpenMap(HANDLE hWnd,char MapName[128])
  394. *
  395. * Purpose: Open the mapping object pointed to by MapName
  396. *
  397. * Inputs: hWnd - parent window's handle
  398. * * MapName - pointer to map file name
  399. *
  400. * Returns: handle to mapped object or NULL if failure
  401. *
  402. * Calls: OpenFileMapping, ErrorOut
  403. *
  404. * History:
  405. *
  406. *
  407. \*************************************************************************/
  408. HANDLE OpenMap(HANDLE hWnd,TCHAR MapName[128])
  409. {
  410. HANDLE hAMap;
  411. hAMap= OpenFileMapping(FILE_MAP_READ | FILE_MAP_WRITE,
  412. TRUE,
  413. MapName);
  414. if (hAMap == NULL)
  415. {
  416. ErrorOut(hWnd,TEXT("OpenFileMapping"));
  417. return(NULL);
  418. }
  419. else
  420. return(hAMap);
  421. }
  422. /*************************************************************************
  423. * HANDLE Create_File(HANDLE hWnd,
  424. LPSTR lpFileName,
  425. DWORD fdwAccess,
  426. DWORD fdwCreate)
  427. *
  428. * Purpose: Open the object pointed to by lpFileName
  429. *
  430. * Inputs: hWnd - parent window's handle
  431. * lpFileName - pointer to file name
  432. * fdwAccess - access(read-write)mode
  433. * fdwCreate - how to create
  434. *
  435. * Returns: handle to object or NULL if failure
  436. *
  437. * History:
  438. *
  439. *
  440. \*************************************************************************/
  441. HANDLE Create_File(HANDLE hWnd,
  442. LPTSTR lpFileName,
  443. DWORD fdwAccess,
  444. DWORD fdwCreate)
  445. {
  446. HANDLE hFile;
  447. TCHAR szStr[256],szStr1[256];
  448. int RetValue;
  449. RetValue=CREATE_ALWAYS;
  450. if(fdwCreate == CREATE_ALWAYS) {
  451. if(_taccess(lpFileName,0)==0) {
  452. LoadString(NULL,IDS_OVERWRITE,szStr, sizeof(szStr)/sizeof(TCHAR));
  453. wsprintf(szStr1,TEXT("\'%s\' %s"),lpFileName,szStr);
  454. RetValue = MessageBox(hWnd,
  455. szStr1,
  456. szCaption,
  457. MB_ICONQUESTION|MB_YESNO|MB_DEFBUTTON2);
  458. if(RetValue != IDYES)
  459. //*if(!SaveFileAs(hWnd,lpFileName))
  460. return (HANDLE)-1;
  461. }
  462. }
  463. else if(fdwCreate == OPEN_EXISTING)
  464. {
  465. if(_taccess(lpFileName,0)) {
  466. /*LoadString(NULL,IDS_FILENOTEXIST,szStr, sizeof(szStr));
  467. wsprintf(szStr1,"\'%s\' %s",lpFileName,szStr);
  468. WarnMessage(hWnd,szStr1);*/
  469. return (HANDLE)-1;
  470. }
  471. }
  472. hFile = CreateFile(lpFileName,fdwAccess,FILE_SHARE_READ,NULL,
  473. fdwCreate,0,NULL);
  474. if (hFile == (HANDLE)-1) {
  475. LoadString(NULL,IDS_FILEOPEN,szStr, sizeof(szStr)/sizeof(TCHAR));
  476. wsprintf(szStr1,TEXT("\'%s\' %s\n"),lpFileName,szStr);
  477. FatalMessage(hWnd,szStr1);
  478. }
  479. return hFile;
  480. }
  481. BOOL SaveFileAs(HWND hwnd, LPTSTR szFilename) {
  482. OPENFILENAME ofn;
  483. TCHAR szFile[256], szFileTitle[256];
  484. static TCHAR *szFilter;
  485. // szFilter = "�����ļ�(*.*)\0\0";
  486. szFilter = TEXT("All files (*.*)\0\0");
  487. lstrcpy(szFile, TEXT("*.*\0"));
  488. ofn.lStructSize = sizeof(OPENFILENAME);
  489. ofn.hwndOwner = hwnd;
  490. ofn.lpstrFilter = szFilter;
  491. ofn.lpstrCustomFilter = (LPTSTR) NULL;
  492. ofn.nMaxCustFilter = 0L;
  493. ofn.nFilterIndex = 0L;
  494. ofn.lpstrFile = szFilename;
  495. ofn.nMaxFile = sizeof(szFile)/sizeof(TCHAR);
  496. ofn.lpstrFileTitle = szFileTitle;
  497. ofn.nMaxFileTitle = sizeof(szFileTitle)/sizeof(TCHAR);
  498. ofn.lpstrInitialDir = NULL;
  499. ofn.lpstrTitle = TEXT("Save file As");
  500. ofn.Flags = OFN_SHOWHELP | OFN_OVERWRITEPROMPT;
  501. ofn.nFileOffset = 0;
  502. ofn.nFileExtension = 0;
  503. ofn.lpstrDefExt = (LPTSTR)NULL;
  504. if (!GetSaveFileName(&ofn))
  505. return 0L;
  506. return 1L;
  507. }
  508. /****************************************************************************
  509. *
  510. * FUNCTION: ProcessCDError(DWORD)
  511. *
  512. * PURPOSE: Processes errors from the conversion functions.
  513. *
  514. * COMMENTS:
  515. *
  516. * This function is called whenever a conversion function
  517. * fails. The string is loaded and displayed for the user.
  518. *
  519. * RETURN VALUES:
  520. * void.
  521. *
  522. * HISTORY:
  523. * 03-04-95 Yehfew Tie Created.
  524. *
  525. ****************************************************************************/
  526. void ProcessError(DWORD dwErrorCode, HWND hWnd,DWORD ErrorLevel)
  527. {
  528. WORD wStringID;
  529. TCHAR buf[256];
  530. switch(dwErrorCode)
  531. {
  532. case ERR_MBNAME: wStringID=IDS_MBNAME; break;
  533. case ERR_FILENOTEXIST: wStringID=IDS_FILENOTEXIST; break;
  534. case ERR_FILENOTOPEN: wStringID=IDS_FILEOPEN; break;
  535. case ERR_OUTOFMEMORY: wStringID=IDS_MEMORY; break;
  536. case ERR_GLOBALLOCK: wStringID=IDS_GLOBALLOCK; break;
  537. case ERR_IMEUSE: wStringID=IDS_IMEUSE; break;
  538. case ERR_MAXCODES: wStringID=IDS_MAXCODES; break;
  539. case ERR_ELEMENT: wStringID=IDS_ELEMENT; break;
  540. case ERR_USEDCODE: wStringID=IDS_USEDCODE; break;
  541. case ERR_WILDCHAR: wStringID=IDS_WILDCHAR; break;
  542. case ERR_RULEHEADER: wStringID=IDS_RULEHEAD; break;
  543. case ERR_RULELOGICOPRA: wStringID=IDS_RULELOGIC; break;
  544. case ERR_RULEWORDLEN: wStringID=IDS_RULEWORDLEN; break;
  545. case ERR_RULEEQUAL: wStringID=IDS_RULEEQUAL; break;
  546. case ERR_RULEDIRECTMODE: wStringID=IDS_RULEDIRECT; break;
  547. case ERR_RULEDBCSPOS: wStringID=IDS_RULEDBCSPOS; break;
  548. case ERR_RULECODEPOS: wStringID=IDS_RULECODEPOS; break;
  549. case ERR_NORULE: wStringID=IDS_NORULE; break;
  550. case ERR_NOTDEFRULE: wStringID=IDS_NOTDEFRULE; break;
  551. case ERR_RULENUM: wStringID=IDS_RULENUM; break;
  552. case ERR_DBCSCODE: wStringID=IDS_DBCSCODE; break;
  553. case ERR_CODEUNITNOTEXIST: wStringID=IDS_CODEUNIT; break;
  554. case ERR_CREATECODE: wStringID=IDS_CREATECODE; break;
  555. case ERR_CREATENOTEXIST: wStringID=IDS_CRTCODEEMPTY; break;
  556. case ERR_CODEEMPTY: wStringID=IDS_CODEEMPTY; break;
  557. // case ERR_SINGLECODEWORDDOUBLE: wStringID=IDS_SCODEREP; break;
  558. case ERR_SBCS_IN_DBCS: wStringID=IDS_SBCSINDBCS; break;
  559. case ERR_GB2312NOTENTIRE: wStringID=IDS_GB2312; break;
  560. case ERR_USERWORDLEN: wStringID=IDS_USERWORDLEN; break;
  561. case ERR_WRITEID: wStringID=IDS_WRID; break;
  562. case ERR_WRITEMAININDEX: wStringID=IDS_WRMAININDEX; break;
  563. case ERR_WRITEDESCRIPT: wStringID=IDS_WRDESCRIPT; break;
  564. case ERR_WRITERULE: wStringID=IDS_WRRULE; break;
  565. case ERR_READID: wStringID=IDS_READID; break;
  566. case ERR_READMAININDEX: wStringID=IDS_RDMAININDEX; break;
  567. case ERR_READDESCRIPT: wStringID=IDS_RDDESCRIPT; break;
  568. case ERR_READRULE: wStringID=IDS_RDRULE; break;
  569. case ERR_DESCRIPTSEG: wStringID=IDS_DESCRIPTSEG; break;
  570. case ERR_RULESEG: wStringID=IDS_RULESEG; break;
  571. case ERR_TEXTSEG: wStringID=IDS_TEXTSEG; break;
  572. case ERR_TOOMANYUSERWORD: wStringID=IDS_TOOMANYUSERWORD; break;
  573. case ERR_OVERWRITE: wStringID=IDS_OVERWRITE; break;
  574. case ERR_IMENAMEENTRY: wStringID=IDS_IMENAMEENTRY; break;
  575. case ERR_MAXCODESENTRY: wStringID=IDS_MAXCODESENTRY; break;
  576. case ERR_ELEMENTENTRY: wStringID=IDS_ELEMENTENTRY; break;
  577. case ERR_USEDCODEENTRY: wStringID=IDS_USEDCODEENTRY; break;
  578. case ERR_NUMRULEENTRY: wStringID=IDS_NUMRULESENTRY; break;
  579. case ERR_CONVEND: wStringID=IDS_CONVEND; break;
  580. case ERR_RECONVEND: wStringID=IDS_RECONVEND; break;
  581. case ERR_SORTEND: wStringID=IDS_SORTEND; break;
  582. case ERR_VERSION: wStringID=IDS_VERSIONEMPTY; break;
  583. case ERR_GROUP: wStringID=IDS_GROUP; break;
  584. case 0: //User may have hit CANCEL or we got a *very* random error
  585. return;
  586. default:
  587. wStringID=IDS_UNKNOWNERROR;
  588. }
  589. LoadString(NULL, wStringID, buf, sizeof(buf)/sizeof(TCHAR));
  590. switch(ErrorLevel) {
  591. case INFO:
  592. MessageBox(hWnd, buf, szCaption, MB_OK|MB_ICONINFORMATION);
  593. break;
  594. case WARNING:
  595. MessageBox(hWnd, buf, szCaption, MB_OK|MB_ICONEXCLAMATION);
  596. break;
  597. case ERR:
  598. default:
  599. MessageBox(hWnd, buf, szCaption, MB_OK|MB_ICONSTOP);
  600. break;
  601. }
  602. return;
  603. }
  604. HANDLE IndexReAlloc(HANDLE hMem,LPINT nPages)
  605. {
  606. HANDLE hReMem;
  607. DWORD dwSize;
  608. *nPages++;
  609. dwSize = (DWORD)(*nPages)*GMEM_PAGESIZE*sizeof(WORDINDEX);
  610. GlobalUnlock(hMem);
  611. hReMem = GlobalReAlloc(hMem, dwSize, GMEM_MODIFY|GMEM_MOVEABLE);
  612. return hReMem;
  613. }
  614. BOOL ConvSort(HANDLE hWnd,LPWORDINDEX lpWordIndex,int nCount)
  615. {
  616. int i;
  617. TCHAR szStr[256];
  618. HANDLE hDlgItem;
  619. SetCursor (LoadCursor (NULL, IDC_WAIT));
  620. SetDlgItemText (hWnd,TM_TOTALINFO,TEXT(""));
  621. LoadString (NULL,IDS_TOTALINFO,szStr,sizeof(szStr)/sizeof(TCHAR));
  622. SetDlgItemText (hWnd,TM_TOTAL,szStr);
  623. LoadString(NULL,IDS_SORTWORDS,szStr,sizeof(szStr)/sizeof(TCHAR));
  624. SetDlgItemText (hWnd,TM_CONVINFO,szStr);
  625. SetDlgItemInt (hWnd,TM_TOTALNUM, nCount, FALSE);
  626. i = 0;
  627. SetDlgItemInt (hWnd,TM_CONVNUM,i,FALSE);
  628. InvalidateRect (hWnd,NULL,FALSE);
  629. hDlgItem = GetDlgItem(hWnd, TM_CONVNUM);
  630. for(i=1 ; i<= nCount; i++)
  631. {
  632. searchPos(lpWordIndex, i);
  633. if(i%100 == 0 || i == nCount)
  634. {
  635. SetDlgItemInt (hWnd,TM_CONVNUM,i,FALSE);
  636. InvalidateRect(hDlgItem,NULL,FALSE);
  637. }
  638. }
  639. SetCursor (LoadCursor (NULL, IDC_ARROW));
  640. return TRUE;
  641. }
  642. /******** Quick sort structure function ********/
  643. void qSort(LPWORDINDEX item, DWORD left,DWORD right)
  644. {
  645. int i,j,k,mid;
  646. WORDINDEX MidWord,SwapWord;
  647. if ( left > right ) return;
  648. i=(int)left;
  649. j=(int)right;
  650. mid = (i+j)/2;
  651. MidWord = item[mid];
  652. do {
  653. while( i < (int)right)
  654. {
  655. k = lstrcmpi(MidWord.szCode,item[i].szCode);
  656. if ( ( k > 0 ) || ( k==0 && i< mid ) )
  657. i++;
  658. else
  659. break;
  660. }
  661. while( j > (int)left )
  662. {
  663. k=lstrcmpi(MidWord.szCode,item[j].szCode);
  664. if ( ( k < 0 ) || (k == 0 && j > mid) )
  665. j--;
  666. else
  667. break;
  668. }
  669. if(i <= j) {
  670. SwapWord = item[i];
  671. item[i] = item[j];
  672. item[j] = SwapWord;
  673. i++;
  674. j--;
  675. }
  676. } while(i <= j);
  677. if((int)left < j) qSort(item,left,j);
  678. if(i < (int)right) qSort(item,i,right);
  679. }
  680. /******** Quick sort char function ********/
  681. void qSortChar(LPTSTR item, DWORD left,DWORD right)
  682. {
  683. int i,j,mid;
  684. TCHAR MidChar,SwapChar;
  685. if ( left > right ) return ;
  686. i=(int)left;
  687. j=(int)right;
  688. mid = (i+j)/2;
  689. MidChar = item[mid];
  690. do {
  691. while( ( MidChar > item[i] && i < (int)right)
  692. ||(MidChar == item[i] && i != mid) )
  693. i++;
  694. while( (MidChar <item[j] && j > (int)left)
  695. ||(MidChar == item[j] && j!=mid) )
  696. j--;
  697. if(i <= j) {
  698. SwapChar = item[i];
  699. item[i] = item[j];
  700. item[j] = SwapChar;
  701. i++;
  702. j--;
  703. }
  704. } while(i <= j);
  705. if((int)left < j) qSortChar(item,left,j);
  706. if(i < (int)right) qSortChar(item,i,right);
  707. }
  708. DWORD EncodeToNo(LPTSTR szDBCS)
  709. {
  710. WORD wCode;
  711. LPENCODEAREA lpEncode;
  712. DWORD dwNo = 0xffffffff, i;
  713. lpEncode = (LPENCODEAREA) GlobalLock(hEncode);
  714. #ifdef UNICODE
  715. wCode = szDBCS[0];
  716. #else
  717. wCode = (WORD)((UCHAR)szDBCS[0])*256 + (WORD)(UCHAR)szDBCS[1];
  718. #endif
  719. for( i = NUMENCODEAREA -1; (long)i>=0; i--) {
  720. if(wCode >= lpEncode[i].StartEncode) {
  721. dwNo = lpEncode[i].PreCount;
  722. dwNo += wCode - lpEncode[i].StartEncode;
  723. break;
  724. }
  725. }
  726. if(dwNo > NUM_OF_ENCODE)
  727. dwNo = 0xffffffff;
  728. GlobalUnlock(hEncode);
  729. return dwNo;
  730. }
  731. DWORD EncodeToGBNo(UCHAR szDBCS[3])
  732. {
  733. DWORD dwNo;
  734. if(szDBCS[0] < 0xa1 || szDBCS[1] < 0xa1 || szDBCS[1] > 0xfe)
  735. {
  736. dwNo = 0xffffffff;
  737. return dwNo;
  738. }
  739. dwNo = (DWORD)(szDBCS[0]-0xa0-16) ;
  740. dwNo = dwNo * 94 + (DWORD)(szDBCS[1]-0xa0-1) - ((dwNo > 39)?5:0);
  741. return dwNo;
  742. }
  743. void NoToEncode(DWORD dwNo,LPBYTE szDBCS, DWORD dwNumArea,
  744. LPENCODEAREA lpEncode)
  745. {
  746. DWORD Value,i;
  747. for( i =dwNumArea-1; (long)i>=0; i--) {
  748. if(dwNo >= lpEncode[i].PreCount) {
  749. Value = dwNo-lpEncode[i].PreCount;
  750. Value += lpEncode[i].StartEncode;
  751. #ifdef UNICODE
  752. szDBCS[0] = (UCHAR)(Value&0xff);
  753. szDBCS[1] = (UCHAR)((Value>>8)&0xff);
  754. #else
  755. szDBCS[0] = (UCHAR)((Value>>8)&0xff);
  756. szDBCS[1] = (UCHAR)(Value&0xff);
  757. #endif
  758. break;
  759. }
  760. }
  761. }
  762. void NoToGB2312Code(DWORD dwNo,LPBYTE szDBCS, DWORD dwNumArea)
  763. {
  764. DWORD Value;
  765. szDBCS[0] = 0;
  766. szDBCS[1] = 0;
  767. if(dwNo > GB2312WORDNUM)
  768. return;
  769. Value = dwNo + ((dwNo >= 3755)?5:0);
  770. szDBCS[0] = (BYTE)(Value/94 +16 +0xa0);
  771. szDBCS[1] = (BYTE)(Value%94 + 0xa1);
  772. }
  773. void RuleToText(LPRULE lpRule, LPTSTR szStr)
  774. {
  775. DWORD dwTemp;
  776. int nCount=0,i;
  777. szStr[0]=TEXT('c');
  778. dwTemp = lpRule->byLogicOpra;
  779. szStr[1]=(dwTemp==0)?TEXT('e'):(dwTemp==1)?TEXT('a'):TEXT('b');
  780. dwTemp = lpRule->byLength;
  781. szStr[2]=(dwTemp<10)?TEXT('0')+(TCHAR)dwTemp:TEXT('a')+(TCHAR)dwTemp-10;
  782. szStr[3]=TEXT('=');
  783. nCount = lpRule->wNumCodeUnits;
  784. for(i=0; i< nCount; i++) {
  785. dwTemp = lpRule->CodeUnit[i].dwDirectMode;
  786. szStr[4+i*4] = (dwTemp==0)?TEXT('p'):TEXT('n');
  787. dwTemp = lpRule->CodeUnit[i].wDBCSPosition;
  788. szStr[4+i*4+1] = (dwTemp<10)?TEXT('0')+(TCHAR)dwTemp:TEXT('a')+(TCHAR)dwTemp-10;
  789. dwTemp = lpRule->CodeUnit[i].wCodePosition;
  790. szStr[4+i*4+2] = (dwTemp<10)?TEXT('0')+(TCHAR)dwTemp:TEXT('a')+(TCHAR)dwTemp-10;
  791. szStr[4+i*4+3] = TEXT('+');
  792. }
  793. szStr[4+4*nCount-1] = 0;
  794. lstrcat(szStr,TEXT("\r\n"));
  795. }
  796. void MoveFileBlock(HANDLE hFile,DWORD dwOffset,DWORD dwSize, DWORD dwDirect)
  797. //** if (dwDirect==0) move block to file begin, else move to file end
  798. {
  799. BYTE Buffer[MAXREADBUFFER];
  800. static BYTE space[MAXREADBUFFER];
  801. DWORD i,dwReadBytes,dwFilePtr;
  802. SetFilePointer(hFile,dwOffset,0,FILE_BEGIN);
  803. if(dwDirect == 0) {
  804. do {
  805. ReadFile(hFile,Buffer,sizeof(Buffer),&dwReadBytes,NULL);
  806. SetFilePointer(hFile, (0-dwReadBytes-dwSize),0,FILE_CURRENT);
  807. WriteFile(hFile,Buffer,dwReadBytes,&dwReadBytes,NULL);
  808. SetFilePointer(hFile, dwSize,0,FILE_CURRENT);
  809. }while(dwReadBytes == MAXREADBUFFER);
  810. SetFilePointer(hFile, 0-dwSize,0,FILE_CURRENT);
  811. for(i=0;i<dwSize;i++)
  812. //#60639 10/18/96
  813. space[i] = (BYTE)0;
  814. WriteFile(hFile,space,dwSize,&dwReadBytes,NULL);
  815. }
  816. else {
  817. dwFilePtr = SetFilePointer(hFile,0,0,FILE_END);
  818. while(dwFilePtr > dwOffset) {
  819. if(dwFilePtr > dwOffset+MAXREADBUFFER)
  820. dwReadBytes = MAXREADBUFFER;
  821. else
  822. dwReadBytes = dwFilePtr - dwOffset;
  823. dwFilePtr = SetFilePointer(hFile,(0-dwReadBytes),0,FILE_CURRENT);
  824. ReadFile(hFile,Buffer,dwReadBytes,&dwReadBytes,NULL);
  825. SetFilePointer(hFile, (dwSize-dwReadBytes),0,FILE_CURRENT);
  826. WriteFile(hFile,Buffer,dwReadBytes,&dwReadBytes,NULL);
  827. SetFilePointer(hFile, (0-dwSize-dwReadBytes),0,FILE_CURRENT);
  828. }
  829. }
  830. }
  831. BOOL Copy_File(LPCTSTR SrcFile,LPCTSTR DestFile)
  832. {
  833. BYTE Buffer[MAXREADBUFFER];
  834. HANDLE hSrcFile, hDestFile;
  835. DWORD dwReadBytes;
  836. hSrcFile = Create_File(GetFocus(),(LPTSTR)SrcFile,GENERIC_READ,OPEN_EXISTING);
  837. hDestFile = CreateFile((LPTSTR)DestFile,GENERIC_WRITE|GENERIC_READ,FILE_SHARE_READ,NULL,OPEN_ALWAYS,0,NULL);
  838. if(hSrcFile == (HANDLE)-1)
  839. return FALSE;
  840. if(hDestFile == (HANDLE)-1)
  841. {
  842. CloseHandle(hSrcFile);
  843. return FALSE;
  844. }
  845. SetFilePointer(hSrcFile,0,0,FILE_BEGIN);
  846. do {
  847. ReadFile(hSrcFile,Buffer,sizeof(Buffer),&dwReadBytes,NULL);
  848. WriteFile(hDestFile,Buffer,dwReadBytes,&dwReadBytes,NULL);
  849. }while(dwReadBytes == MAXREADBUFFER);
  850. CloseHandle(hSrcFile);
  851. CloseHandle(hDestFile);
  852. return TRUE;
  853. }
  854. /****************************************************************************
  855. *
  856. * FUNCTION: CheckCrtData(HANDLE hWnd,
  857. * LPCREATEWORD lpCreateWords,
  858. * LPENCODEAREA lpEncode,
  859. * DWORD dwMaxCodes)
  860. *
  861. * PURPOSE: check whether create word data is entired or not.
  862. *
  863. * RETURN VALUES:
  864. * TRUE or FALSE.
  865. *
  866. * HISTORY:
  867. *
  868. *
  869. ****************************************************************************/
  870. BOOL CheckCrtData(HANDLE hWnd,
  871. LPCREATEWORD lpCreateWords,
  872. LPENCODEAREA lpEncode,
  873. DWORD dwMaxCodes)
  874. {
  875. DWORD i;
  876. TCHAR szDBCS[3],szCreate[13];
  877. TCHAR szTemp[128],szTmpStr[128];
  878. BOOL bErr = FALSE;
  879. #ifdef UNICODE
  880. //check CJK Unified Ideograph subset only
  881. for (i=0x250; i< 0x250+NUM_OF_CJK_CHINESE; i++) {
  882. #else
  883. for (i=0; i< NUM_OF_ENCODE ; i++) {
  884. #endif
  885. lstrncpy(szCreate,dwMaxCodes,&lpCreateWords[i*dwMaxCodes]);
  886. szCreate[dwMaxCodes] = 0;
  887. if(lstrlen(szCreate) == 0) {
  888. NoToEncode(i, (LPBYTE)szDBCS, NUMENCODEAREA, lpEncode);
  889. //NoToGB2312Code(i,szDBCS,NUMENCODEAREA);
  890. szDBCS[1] =0; //#62550
  891. LoadString(NULL, IDS_WORDNOTEXIST, szTmpStr, sizeof(szTmpStr)/sizeof(TCHAR));
  892. wsprintf(szTemp,TEXT("\'%s\' %s"),szDBCS,szTmpStr);
  893. if(ErrMessage(hWnd,szTemp))
  894. return FALSE;
  895. bErr = TRUE;
  896. }
  897. }
  898. return (!bErr) ;
  899. }
  900. void DispInfo(HANDLE hWnd,WORD wStrID)
  901. {
  902. TCHAR text[80];
  903. LoadString(NULL,wStrID,text,sizeof(text)/sizeof(TCHAR));
  904. SetDlgItemText(hWnd,TM_TOTALINFO,text);
  905. SetDlgItemText(hWnd,TM_TOTAL,TEXT(""));
  906. SetDlgItemText(hWnd,TM_TOTALNUM,TEXT(""));
  907. SetDlgItemText(hWnd,TM_CONVINFO,TEXT(""));
  908. SetDlgItemText(hWnd,TM_CONVNUM,TEXT(""));
  909. InvalidateRect(hWnd,NULL,FALSE);
  910. }
  911. BOOL WriteEMBToFile(LPCTSTR path_name,LPEMB_Head EMB_Table) {
  912. HANDLE hFile;
  913. DWORD byte_t_write;
  914. TCHAR szStr[256],szStr1[256];
  915. hFile = CreateFile(path_name,GENERIC_WRITE,0,NULL,CREATE_ALWAYS,0,NULL);
  916. if(hFile==INVALID_HANDLE_VALUE) {
  917. LoadString(NULL,IDS_FILEOPEN,szStr, sizeof(szStr)/sizeof(TCHAR));
  918. wsprintf(szStr1,TEXT("\'%s\' %s\n"),path_name,szStr);
  919. FatalMessage(GetFocus(),szStr1);
  920. return(0);
  921. }
  922. WriteFile(hFile,&EMB_Count,sizeof(EMB_Count),&byte_t_write,NULL);
  923. WriteFile(hFile,EMB_Table,EMB_Count*sizeof(EMB_Head), &byte_t_write, NULL);
  924. GlobalUnlock(HmemEMB_Table);
  925. SetEndOfFile(hFile);
  926. CloseHandle(hFile);
  927. return (1);
  928. }
  929. BOOL ReadEMBFromFile(LPCTSTR path_name, LPEMB_Head EMB_Table) {
  930. HANDLE hFile;
  931. DWORD byte_t_write;
  932. hFile = CreateFile(path_name,GENERIC_READ,
  933. FILE_SHARE_READ,NULL,OPEN_ALWAYS,0,NULL);
  934. if(hFile==INVALID_HANDLE_VALUE) {
  935. ProcessError(ERR_IMEUSE, GetFocus(), ERR);
  936. return FALSE;
  937. }
  938. /* if(hFile == INVALID_HANDLE_VALUE) {
  939. ProcessError(ERR_FILENOTOPEN,GetFocus(),ERR);
  940. return(0);
  941. }*/
  942. SetFilePointer(hFile,0,0,FILE_BEGIN);
  943. EMB_Count = 0;
  944. ReadFile(hFile,&EMB_Count,sizeof(EMB_Count),&byte_t_write,NULL);
  945. if(EMB_Count > 1000) {
  946. CloseHandle(hFile);
  947. return (0);
  948. }
  949. HmemEMB_Table = GlobalAlloc(GMEM_DISCARDABLE,(EMB_Count+1)*sizeof(EMB_Head));
  950. EMB_Table = GlobalLock(HmemEMB_Table);
  951. ReadFile(hFile,EMB_Table,EMB_Count*sizeof(EMB_Head), &byte_t_write, NULL);
  952. GlobalUnlock(HmemEMB_Table);
  953. SetEndOfFile(hFile);
  954. CloseHandle(hFile);
  955. return (1);
  956. }
  957. int AddZCItem(LPCTSTR path_name,LPEMB_Head EMB_Table,LPTSTR wai_code,LPTSTR cCharStr) { //string must end by '\0'
  958. int i;
  959. if(EMB_Count >= 1000)
  960. return FALSE;
  961. for(i=0; i<EMB_Count;i++) {
  962. #ifdef UNICODE
  963. if(wcsncmp(wai_code,EMB_Table[i].W_Code,MAXCODELEN) == 0 &&
  964. wcsncmp(cCharStr,EMB_Table[i].C_Char,USER_WORD_SIZE) == 0)
  965. {
  966. return FALSE;
  967. }
  968. if(wcsncmp(wai_code,EMB_Table[i].W_Code,MAXCODELEN) < 0 )
  969. break;
  970. #else
  971. if(strncmp(wai_code,EMB_Table[i].W_Code,MAXCODELEN) == 0 &&
  972. strncmp(cCharStr,EMB_Table[i].C_Char,USER_WORD_SIZE) == 0)
  973. {
  974. return FALSE;
  975. }
  976. if(strncmp(wai_code,EMB_Table[i].W_Code,MAXCODELEN) < 0 )
  977. break;
  978. #endif
  979. }
  980. EMB_Count ++;
  981. memmove(&EMB_Table[i+1],&EMB_Table[i], (EMB_Count-i-1)*sizeof(EMB_Head));
  982. lstrncpy(EMB_Table[i].W_Code,MAXCODELEN,wai_code);
  983. lstrncpy(EMB_Table[i].C_Char,USER_WORD_SIZE,cCharStr);
  984. // GlobalUnlock(HmemEMB_Table);
  985. WriteEMBToFile(path_name,EMB_Table);
  986. return TRUE;
  987. }
  988. void DelSelCU(LPCTSTR path_name,LPEMB_Head EMB_Table, int item) {
  989. memcpy(EMB_Table+item,EMB_Table+item+1,(EMB_Count-item-1)*sizeof(EMB_Head));
  990. EMB_Count --;
  991. WriteEMBToFile(path_name,EMB_Table);
  992. }
  993. /****************************************************************************
  994. *
  995. * FUNCTION: ReadUserWord(HWND hWnd,LPSTR lpFileName,LPDWORD fdwUserWords)
  996. *
  997. * PURPOSE: read user words from file pointed by lpFileName.
  998. *
  999. * INPUTS: hWnd - parent window's handle
  1000. * lpFileName - pointer to file name
  1001. fdwUserWord - pointer to number of user words
  1002. *
  1003. * RETURN VALUES:
  1004. * TRUE or FALSE.
  1005. *
  1006. * HISTORY:
  1007. *
  1008. *
  1009. ****************************************************************************/
  1010. BOOL ReadUserWord(HWND hWnd,LPTSTR lpFileName,LPDWORD fdwUserWords,WORD wMaxCodes)
  1011. {
  1012. HANDLE hFile;
  1013. TCHAR Buffer[MAXREADBUFFER];
  1014. DWORD dwReadBytes;
  1015. TCHAR szStr[256];
  1016. int nRet;
  1017. register int i,j;
  1018. *fdwUserWords = 0;
  1019. hFile = Create_File(hWnd,lpFileName,GENERIC_READ,OPEN_EXISTING);
  1020. if (hFile == (HANDLE)-1)
  1021. return FALSE;
  1022. SendDlgItemMessage(hWnd,IDC_LIST,LB_RESETCONTENT,0,0L);
  1023. SetFilePointer(hFile,0,0,FILE_BEGIN);
  1024. SetCursor (LoadCursor (NULL, IDC_WAIT));
  1025. dwLineNo = 0;
  1026. while(ReadFile(hFile,Buffer,MAXREADBUFFER,&dwReadBytes,NULL))
  1027. {
  1028. lstrcpy(szStr,TEXT(""));
  1029. j=0;
  1030. dwReadBytes = dwReadBytes/sizeof(TCHAR);
  1031. for(i=0;i<(int)dwReadBytes;i++) {
  1032. if(Buffer[i] == 0x0d || Buffer[i] == 0xfeff)
  1033. continue;
  1034. else if(Buffer[i] == TEXT('\n')) {
  1035. dwLineNo ++;
  1036. szStr[j]=0;
  1037. j=0;
  1038. if(lstrlen(szStr) == 0) continue;
  1039. nRet = CheckUserWord(hWnd,szStr,wMaxCodes);
  1040. if(nRet == FALSE) {
  1041. CloseHandle(hFile);
  1042. SetCursor (LoadCursor (NULL, IDC_ARROW));
  1043. return FALSE;
  1044. }
  1045. else if(nRet == -1)
  1046. {
  1047. szStr[0]=0;
  1048. continue;
  1049. }
  1050. SendDlgItemMessage(hWnd,IDC_LIST,LB_ADDSTRING,0,(LPARAM)szStr);
  1051. (*fdwUserWords)++;
  1052. if((*fdwUserWords) >= 1000) {
  1053. ProcessError(ERR_TOOMANYUSERWORD,hWnd,WARNING);
  1054. CloseHandle(hFile);
  1055. SetCursor (LoadCursor (NULL, IDC_ARROW));
  1056. return FALSE;
  1057. }
  1058. szStr[0]=0;
  1059. }
  1060. else {
  1061. szStr[j]=Buffer[i];
  1062. j++;
  1063. }
  1064. } /*** for (i=0;...) ****/
  1065. if(j)
  1066. SetFilePointer(hFile,0-j,0,FILE_CURRENT);
  1067. if(dwReadBytes*sizeof(TCHAR) < MAXREADBUFFER) break;
  1068. };
  1069. CloseHandle(hFile);
  1070. SetCursor (LoadCursor (NULL, IDC_ARROW));
  1071. return TRUE;
  1072. }
  1073. int CheckUserWord(HWND hWnd,LPTSTR szUserWord,WORD wMaxCodes)
  1074. {
  1075. int retValue;
  1076. TCHAR szTemp[256];
  1077. TCHAR szDBCS[256],szCode[30];
  1078. retValue = ParseDBCSstr(hWnd,szUserWord, szDBCS,szCode,szTemp,wMaxCodes);
  1079. if(retValue != TRUE)
  1080. return retValue;
  1081. if(lstrlen(szDBCS) == 0 || lstrlen(szCode) == 0)
  1082. return -1;
  1083. else
  1084. return retValue;
  1085. }
  1086. BOOL CheckUserDBCS(HWND hWnd,LPTSTR szDBCS)
  1087. {
  1088. int nDBCS=0,i;
  1089. static TCHAR szTmpStr[256],szTemp[256];
  1090. nDBCS=lstrlen(szDBCS);
  1091. if(nDBCS == 0)
  1092. return FALSE;
  1093. #ifndef UNICODE
  1094. if(nDBCS%2 == 1) {
  1095. MessageBeep((UINT)-1);
  1096. for(i=0; i <nDBCS; i += 2) {
  1097. if((BYTE)szDBCS[i] < 0x81)
  1098. memcpy(&szDBCS[i],&szDBCS[i+1], nDBCS-i);
  1099. }
  1100. return FALSE;
  1101. }
  1102. #endif
  1103. return TRUE;
  1104. }
  1105. BOOL CheckCodeLegal(HWND hWnd,LPTSTR szDBCS,LPTSTR szCode,LPTSTR szCreate, LPDESCRIPTION lpDescript)
  1106. {
  1107. int len = lstrlen(szCode);
  1108. int i;
  1109. TCHAR szTemp[256],szTmpStr[256];
  1110. if(len==0) return TRUE;
  1111. if(len > lpDescript->wMaxCodes) {
  1112. LoadString(NULL, IDS_DBCSCODELEN, szTmpStr, sizeof(szTmpStr)/sizeof(TCHAR));
  1113. #ifdef UNICODE
  1114. {
  1115. TCHAR UniTmp[] = {0x884C, 0x0000};
  1116. wsprintf(szTemp,TEXT("\'%ws\'%ws %d(%ws:%ld)!"), szDBCS,szTmpStr,(int)lpDescript->wMaxCodes, UniTmp, dwLineNo);
  1117. }
  1118. #else
  1119. wsprintf(szTemp,"\'%s\'%s %d(��:%ld)!", szDBCS,szTmpStr,(int)lpDescript->wMaxCodes, dwLineNo);
  1120. #endif
  1121. FatalMessage(hWnd,szTemp);
  1122. return FALSE;
  1123. }
  1124. for(i=0; i<len; i++) {
  1125. if(_tcschr(lpDescript->szUsedCode,szCode[i]) == NULL) {
  1126. LoadString(NULL, IDS_DBCSCODE, szTmpStr, sizeof(szTmpStr)/sizeof(TCHAR));
  1127. #ifdef UNICODE
  1128. {
  1129. TCHAR UniTmp[] = {0x884C, 0x0000};
  1130. wsprintf(szTemp,TEXT("\'%ws%ws\' %ws(%ws:%ld) "), szDBCS,szCode,szTmpStr, UniTmp, dwLineNo);
  1131. }
  1132. #else
  1133. wsprintf(szTemp,"\'%s%s\' %s(��:%ld) ", szDBCS,szCode,szTmpStr, dwLineNo);
  1134. #endif
  1135. FatalMessage(hWnd,szTemp);
  1136. return FALSE;
  1137. }
  1138. }
  1139. len = lstrlen(szCreate);
  1140. if(lpDescript->byMaxElement == 1 || len == 0)
  1141. return TRUE;
  1142. for(i=0; i<len; i++) {
  1143. if(_tcschr(lpDescript->szUsedCode,szCreate[i]) == NULL) {
  1144. LoadString(NULL, IDS_DBCSCODE, szTmpStr, sizeof(szTmpStr)/sizeof(TCHAR));
  1145. #ifdef UNICODE
  1146. {
  1147. TCHAR UniTmp[] = {0x884C, 0x0000};
  1148. wsprintf(szTemp, TEXT("\'%ws%ws %ws\' %ws(%ws:%ld) "), szDBCS,szCode,szCreate,szTmpStr, UniTmp, dwLineNo);
  1149. }
  1150. #else
  1151. wsprintf(szTemp,"\'%s%s %s\' %s(��:%ld) ", szDBCS,szCode,szCreate,szTmpStr, dwLineNo);
  1152. #endif
  1153. FatalMessage(hWnd,szTemp);
  1154. return FALSE;
  1155. }
  1156. }
  1157. return TRUE;
  1158. }
  1159. void DelIllegalCode(TCHAR *szCode)
  1160. {
  1161. static TCHAR collection[48]=
  1162. TEXT("`1234567890-=\\[];',./abcdefghijklmnopqrstuvwxyz");
  1163. int i,len = lstrlen(szCode), j;
  1164. TCHAR szStr[512];
  1165. if(len==0)
  1166. return ;
  1167. j = 0;
  1168. for(i=0; i<len;i++)
  1169. if(_tcschr(collection,szCode[i]) != NULL)
  1170. {
  1171. szStr[j] = szCode[i];
  1172. j ++;
  1173. }
  1174. szStr[j] = 0;
  1175. lstrcpy(szCode,szStr);
  1176. return ;
  1177. }
  1178. BOOL CheckCodeCollection(HWND hWnd,LPTSTR szUsedCode)
  1179. {
  1180. static TCHAR collection[48]=
  1181. TEXT("`1234567890-=\\[];',./abcdefghijklmnopqrstuvwxyz");
  1182. int i,len = lstrlen(szUsedCode);
  1183. if(len==0) {
  1184. ProcessError(ERR_USEDCODE,hWnd,ERR);
  1185. return FALSE;
  1186. }
  1187. qSortChar(szUsedCode,0,len-1);
  1188. for(i=0; i<len-1 ;i++)
  1189. {
  1190. if(szUsedCode[i] == szUsedCode[i+1]
  1191. || _tcschr(collection,szUsedCode[len-1])== NULL
  1192. || _tcschr(collection,szUsedCode[i])== NULL) {
  1193. ProcessError(ERR_USEDCODE,hWnd,ERR);
  1194. return FALSE;
  1195. }
  1196. }
  1197. return TRUE;
  1198. }
  1199. // QueryKey - enumerates the subkeys of a given key and the associated
  1200. // values and then copies the information about the keys and values
  1201. // into a pair of edit controls and list boxes.
  1202. // hDlg - dialog box that contains the edit controls and list boxes
  1203. // hKey - key whose subkeys and values are to be enumerated
  1204. //
  1205. BOOL QueryKey(HWND hDlg, HANDLE hKey)
  1206. {
  1207. TCHAR achKey[MAX_PATH];
  1208. TCHAR achClass[MAX_PATH] = TEXT(""); /* buffer for class name */
  1209. DWORD cchClassName = MAX_PATH; /* length of class string */
  1210. DWORD cSubKeys; /* number of subkeys */
  1211. DWORD cbMaxSubKey; /* longest subkey size */
  1212. DWORD cchMaxClass; /* longest class string */
  1213. DWORD cValues; /* number of values for key */
  1214. DWORD cchMaxValue; /* longest value name */
  1215. DWORD cbMaxValueData; /* longest value data */
  1216. DWORD cbSecurityDescriptor; /* size of security descriptor */
  1217. FILETIME ftLastWriteTime; /* last write time */
  1218. DWORD i, j;
  1219. DWORD retCode;
  1220. DWORD dwcValueName = MAX_VALUE_NAME;
  1221. // Get the class name and the value count.
  1222. RegQueryInfoKey(hKey, /* key handle */
  1223. achClass, /* buffer for class name */
  1224. &cchClassName, /* length of class string */
  1225. NULL, /* reserved */
  1226. &cSubKeys, /* number of subkeys */
  1227. &cbMaxSubKey, /* longest subkey size */
  1228. &cchMaxClass, /* longest class string */
  1229. &cValues, /* number of values for this key */
  1230. &cchMaxValue, /* longest value name */
  1231. &cbMaxValueData, /* longest value data */
  1232. &cbSecurityDescriptor, /* security descriptor */
  1233. &ftLastWriteTime); /* last write time */
  1234. // Enumerate the child keys, looping until RegEnumKey fails. Then
  1235. // get the name of each child key and copy it into the list box.
  1236. SetCursor(LoadCursor(NULL, IDC_WAIT));
  1237. j = 0;
  1238. for (i = 0, retCode = ERROR_SUCCESS;
  1239. retCode == ERROR_SUCCESS; i++) {
  1240. retCode = RegEnumKey(hKey, i, achKey, MAX_PATH);
  1241. if (retCode == (DWORD)ERROR_SUCCESS) {
  1242. SendMessage(GetDlgItem(hDlg, IDC_LIST),
  1243. LB_ADDSTRING, 0,
  1244. (LPARAM)achKey);
  1245. }
  1246. }
  1247. SetCursor(LoadCursor (NULL, IDC_ARROW));
  1248. return TRUE;
  1249. }
  1250. BOOL CreateMbKey(PHKEY phKey,LPCTSTR FileName,LPCTSTR KeyName)
  1251. {
  1252. HKEY hkResult;
  1253. DWORD i;
  1254. DWORD Value=1;
  1255. #ifdef UNICODE
  1256. static TCHAR ValueName[][12]= {
  1257. 0x7801, 0x8868, 0x6587, 0x4EF6, 0x540D,0x0000,
  1258. 0x8BCD, 0x8BED, 0x8054, 0x60F3, 0x0000,
  1259. 0x8BCD, 0x8BED, 0x8F93, 0x5165, 0x0000,
  1260. 0x9010, 0x6E10, 0x63D0, 0x793A, 0x0000,
  1261. 0x5916, 0x7801, 0x63D0, 0x793A, 0x0000,
  1262. '<','S','P','A','C','E','>', 0x0000,
  1263. '<','E','N','T','E','R','>', 0x0000,
  1264. 0x5149, 0x6807, 0x8DDF, 0x968F, 0x0000
  1265. };
  1266. #else
  1267. static TCHAR ValueName[][12]= {
  1268. "�����ļ���",
  1269. "��������",
  1270. "��������",
  1271. "������ʾ",
  1272. "������ʾ",
  1273. "<SPACE>",
  1274. "<ENTER>",
  1275. "��������"
  1276. };
  1277. #endif \\UNICODE
  1278. if(!RegOpenKey(*phKey,KeyName,&hkResult))
  1279. return FALSE;
  1280. if(RegCreateKey(*phKey,KeyName,&hkResult))
  1281. return FALSE;
  1282. RegSetValueEx(hkResult,ValueName[0],0,REG_SZ,(BYTE*)FileName,(lstrlen(FileName)+1) * sizeof(TCHAR) );
  1283. for(i=1;i<6;i++)
  1284. RegSetValueEx(hkResult,ValueName[i],0,REG_DWORD,(LPSTR)&Value,sizeof(DWORD));
  1285. RegSetValueEx(hkResult,ValueName[7],0,REG_DWORD,(LPSTR)&Value,sizeof(DWORD));
  1286. Value = 0;
  1287. RegSetValueEx(hkResult,ValueName[5],0,REG_DWORD,(LPSTR)&Value,sizeof(DWORD));
  1288. RegSetValueEx(hkResult,ValueName[6],0,REG_DWORD,(LPSTR)&Value,sizeof(DWORD));
  1289. RegCloseKey(hkResult);
  1290. return TRUE;
  1291. }
  1292. BOOL SetRegValue(HKEY hKey,LPDWORD Value)
  1293. {
  1294. DWORD i;
  1295. #ifdef UNICODE
  1296. static TCHAR ValueName[][12]= {
  1297. 0x8BCD, 0x8BED, 0x8054, 0x60F3, 0x0000,
  1298. 0x8BCD, 0x8BED, 0x8F93, 0x5165, 0x0000,
  1299. 0x9010, 0x6E10, 0x63D0, 0x793A, 0x0000,
  1300. 0x5916, 0x7801, 0x63D0, 0x793A, 0x0000,
  1301. '<','S','P','A','C','E','>', 0x0000,
  1302. '<','E','N','T','E','R','>', 0x0000,
  1303. 0x5149, 0x6807, 0x8DDF, 0x968F, 0x0000
  1304. };
  1305. #else
  1306. static TCHAR ValueName[][12]= {
  1307. "��������",
  1308. "��������",
  1309. "������ʾ",
  1310. "������ʾ",
  1311. "<SPACE>",
  1312. "<ENTER>",
  1313. "��������"
  1314. };
  1315. #endif \\UNICODE
  1316. for(i=0;i<7;i++)
  1317. RegSetValueEx(hKey,ValueName[i],0,REG_DWORD,(LPSTR)&Value[i],sizeof(DWORD));
  1318. return TRUE;
  1319. }
  1320. BOOL GetRegValue(HWND hDlg,HKEY hKey,LPDWORD Value)
  1321. {
  1322. #ifdef UNICODE
  1323. static TCHAR ValueName[][12]= {
  1324. 0x8BCD, 0x8BED, 0x8054, 0x60F3, 0x0000,
  1325. 0x8BCD, 0x8BED, 0x8F93, 0x5165, 0x0000,
  1326. 0x9010, 0x6E10, 0x63D0, 0x793A, 0x0000,
  1327. 0x5916, 0x7801, 0x63D0, 0x793A, 0x0000,
  1328. '<','S','P','A','C','E','>', 0x0000,
  1329. '<','E','N','T','E','R','>', 0x0000,
  1330. 0x5149, 0x6807, 0x8DDF, 0x968F, 0x0000
  1331. };
  1332. #else
  1333. static TCHAR ValueName[][12]= {
  1334. "��������",
  1335. "��������",
  1336. "������ʾ",
  1337. "������ʾ",
  1338. "<SPACE>",
  1339. "<ENTER>",
  1340. "��������"
  1341. };
  1342. #endif \\UNICODE
  1343. DWORD i,j,retValue,dwcValueName;
  1344. TCHAR Buf[80];
  1345. SetCursor (LoadCursor (NULL, IDC_WAIT));
  1346. for (j = 0, retValue = ERROR_SUCCESS; j < 7; j++)
  1347. {
  1348. dwcValueName = MAX_VALUE_NAME;
  1349. i=sizeof(DWORD);
  1350. retValue = RegQueryValueEx (hKey, ValueName[j],
  1351. NULL,
  1352. NULL, //&dwType,
  1353. (LPSTR)&Value[j], //&bData,
  1354. &i); //&bcData);
  1355. if (retValue != (DWORD)ERROR_SUCCESS &&
  1356. retValue != ERROR_INSUFFICIENT_BUFFER)
  1357. {
  1358. wsprintf (Buf, TEXT("Line:%d 0 based index = %d, retValue = %d, ValueLen = %d"),
  1359. __LINE__, j, retValue, dwcValueName);
  1360. MessageBox (hDlg, Buf, TEXT("Debug"), MB_OK);
  1361. }
  1362. }// end for(;;)
  1363. SetCursor (LoadCursor (NULL, IDC_ARROW));
  1364. return TRUE;
  1365. }
  1366. LPTSTR _tcschr(LPTSTR string, TCHAR c)
  1367. {
  1368. #ifdef UNICODE
  1369. return (wcschr(string, c));
  1370. #else
  1371. return (strchr(string, c));
  1372. #endif
  1373. }
  1374. LPTSTR _tcsrchr(LPTSTR string, TCHAR c)
  1375. {
  1376. #ifdef UNICODE
  1377. return (wcsrchr(string, c));
  1378. #else
  1379. return (strrchr(string, c));
  1380. #endif
  1381. }
  1382. LPTSTR _tcsstr(LPTSTR string1, LPTSTR string2)
  1383. {
  1384. #ifdef UNICODE
  1385. return (wcsstr(string1, string2));
  1386. #else
  1387. return (strstr(string1, string2));
  1388. #endif
  1389. }
  1390. LPTSTR _tcsupr(LPTSTR string)
  1391. {
  1392. #ifdef UNICODE
  1393. return (_wcsupr(string));
  1394. #else
  1395. return (_strupr(string));
  1396. #endif
  1397. }
  1398. int _ttoi(LPTSTR string)
  1399. {
  1400. #ifdef UNICODE
  1401. return (_wtoi(string));
  1402. #else
  1403. return (atoi(string));
  1404. #endif
  1405. }
  1406. int _taccess(LPTSTR szFileName, int mode)
  1407. {
  1408. char szDbcsName[256];
  1409. #ifdef UNICODE
  1410. WideCharToMultiByte(CP_ACP, WC_COMPOSITECHECK, szFileName, -1, szDbcsName,
  1411. sizeof(szDbcsName), NULL, NULL);
  1412. #else
  1413. lstrcpy(szDbcsName, szFileName);
  1414. #endif
  1415. return (_access(szDbcsName, mode));
  1416. }