Leaked source code of windows server 2003
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.

1211 lines
36 KiB

  1. /*************************************************
  2. * convcomm.c *
  3. * *
  4. * Copyright (C) 1995-1999 Microsoft Inc. *
  5. * *
  6. *************************************************/
  7. #include "conv.h"
  8. int CheckDescription(HANDLE hWnd, LPDESCRIPTION lpDescript)
  9. //*** check description illegal ****
  10. {
  11. TCHAR szStr[256];
  12. if(lstrlen(lpDescript->szName) == 0) {
  13. LoadString(NULL,IDS_IMENAMEENTRY,szStr, sizeof(szStr)/sizeof(TCHAR));
  14. InfoMessage(hWnd,szStr);
  15. lpDescript->szName[24] = 0;
  16. return FALSE;
  17. }
  18. if(lpDescript->wMaxCodes == 0) {
  19. LoadString(NULL,IDS_MAXCODESENTRY,szStr, sizeof(szStr)/sizeof(TCHAR));
  20. WarnMessage(hWnd,szStr);
  21. return FALSE;
  22. }
  23. if(lpDescript->byMaxElement == 0) {
  24. lpDescript->byMaxElement = 1;
  25. LoadString(NULL,IDS_ELEMENTENTRY,szStr, sizeof(szStr)/sizeof(TCHAR));
  26. WarnMessage(hWnd,szStr);
  27. return FALSE;
  28. }
  29. if( !CheckCodeCollection(hWnd,lpDescript->szUsedCode) )
  30. return FALSE;
  31. lpDescript->wNumCodes = (WORD) lstrlen(lpDescript->szUsedCode);
  32. if(lpDescript->cWildChar == 0)
  33. lpDescript->cWildChar = '?';
  34. if(_tcschr(lpDescript->szUsedCode,lpDescript->cWildChar) != NULL) {
  35. ProcessError(ERR_WILDCHAR,hWnd,ERR);
  36. return FALSE;
  37. }
  38. if(lpDescript->wNumRules >= 12) {
  39. lpDescript->wNumRules=0;
  40. LoadString(NULL,IDS_NUMRULESENTRY,szStr, sizeof(szStr)/sizeof(TCHAR));
  41. WarnMessage(szStr,hWnd);
  42. return FALSE;
  43. }
  44. return TRUE;
  45. }
  46. int GetDescriptEntry(LPTSTR szSrcStr, LPDESCRIPTION lpDescript)
  47. //*** get one description entry from source string ****
  48. {
  49. TCHAR szStr[256];
  50. int retValue;
  51. SetCursor (LoadCursor (NULL, IDC_WAIT));
  52. if( GetEntryString(szSrcStr,
  53. TEXT("Name"),
  54. lpDescript->szName,
  55. lpDescript->szName,
  56. NAMESIZE-1)
  57. )
  58. return TRUE;
  59. if( GetEntryInt(szSrcStr,
  60. TEXT("MaxCodes"),
  61. (int)lpDescript->wMaxCodes,
  62. &retValue)
  63. )
  64. {
  65. lpDescript->wMaxCodes = (WORD)retValue;
  66. return TRUE;
  67. }
  68. if( GetEntryInt(szSrcStr,
  69. TEXT("MaxElement"),
  70. (int)lpDescript->byMaxElement,
  71. & retValue)
  72. )
  73. {
  74. lpDescript->byMaxElement = (BYTE) retValue;
  75. return TRUE;
  76. }
  77. retValue = GetEntryString(szSrcStr,
  78. TEXT("UsedCodes"),
  79. lpDescript->szUsedCode,
  80. szStr,
  81. MAXUSEDCODES
  82. );
  83. if(retValue)
  84. {
  85. DelSpace(szStr);
  86. lstrncpy(lpDescript->szUsedCode,MAXUSEDCODES,szStr);
  87. return TRUE;
  88. }
  89. szStr[0] = lpDescript->cWildChar;
  90. szStr[1] = 0;
  91. retValue = GetEntryString(szSrcStr,
  92. TEXT("WildChar"),
  93. szStr,
  94. szStr,
  95. sizeof(szStr)/sizeof(TCHAR));
  96. if(retValue)
  97. {
  98. DelSpace(szStr);
  99. lpDescript->cWildChar = szStr[0];
  100. return TRUE;
  101. }
  102. if(GetEntryInt(szSrcStr,
  103. TEXT("NumRules"),
  104. (int)lpDescript->wNumRules,
  105. &retValue )
  106. )
  107. lpDescript->wNumRules = (WORD)retValue;
  108. return TRUE;
  109. }
  110. int ConvGetDescript(HANDLE hWnd,
  111. LPCTSTR FileName,
  112. LPDWORD fdwOffset,
  113. LPDWORD fdwLen,
  114. LPDESCRIPTION lpDescript,
  115. BOOL bOnlyGetLength)
  116. {
  117. TCHAR szStr[1024];
  118. TCHAR *Buffer;
  119. BOOL bDescript = FALSE,bText = FALSE,bRule = FALSE;
  120. BOOL bGetDes = FALSE;
  121. register int i,j;
  122. DWORD dwFstOffset=0 , dwOffset;
  123. DWORD dwReadBytes;
  124. HANDLE hFile;
  125. HLOCAL hBuffer;
  126. int errno;
  127. if(!bOnlyGetLength)
  128. {
  129. memset(lpDescript->szName,0,sizeof(lpDescript->szName));
  130. lpDescript->wMaxCodes=0;
  131. lpDescript->byMaxElement=1;
  132. memset(lpDescript->szUsedCode,0,sizeof(lpDescript->szUsedCode));
  133. lpDescript->wNumRules=0;
  134. lpDescript->wNumCodes=0;
  135. lpDescript->cWildChar=0;
  136. }
  137. hFile = Create_File(hWnd,FileName,GENERIC_READ,OPEN_EXISTING);
  138. if (hFile == (HANDLE)-1)
  139. return (-ERR_FILENOTOPEN);
  140. hBuffer = LocalAlloc(LMEM_ZEROINIT|LMEM_MOVEABLE, MAXREADBUFFER * sizeof(TCHAR));
  141. Buffer = (TCHAR *) LocalLock(hBuffer);
  142. SetCursor (LoadCursor (NULL, IDC_WAIT));
  143. *fdwOffset = 0;
  144. SetFilePointer(hFile,0,0,FILE_BEGIN);
  145. while(ReadFile(hFile,Buffer,MAXREADBUFFER,&dwReadBytes,NULL))
  146. {
  147. dwReadBytes = dwReadBytes/sizeof(TCHAR);
  148. lstrcpy(szStr,TEXT(""));
  149. j=0;
  150. for(i=0;i<(int)dwReadBytes;i++) {
  151. if(Buffer[i] == 0x0d || Buffer[i] == 0xfeff)
  152. continue;
  153. else if(Buffer[i] == TEXT('\n')) {
  154. szStr[j]=0;
  155. j=0;
  156. if(lstrlen(szStr) < 6) continue;
  157. if(lstrcmpi(szStr,TEXT(DescriptSeg))==0) {
  158. #ifdef UNICODE
  159. *fdwOffset= dwOffset - 2; //the size of 0xfeff flag
  160. #else
  161. *fdwOffset= dwOffset;
  162. #endif
  163. bDescript = TRUE;
  164. bGetDes = TRUE;
  165. lstrcpy(szStr,TEXT(""));
  166. continue;
  167. }
  168. if( lstrcmpi(szStr,TEXT(TextSeg))==0)
  169. {
  170. bText =TRUE;
  171. bGetDes = FALSE;
  172. }
  173. if( lstrcmpi(szStr,TEXT(RuleSeg))==0)
  174. {
  175. bRule = TRUE;
  176. bGetDes = FALSE;
  177. }
  178. if( (bText||bRule)&& bDescript && !bGetDes) {
  179. *fdwLen = dwOffset - (*fdwOffset);
  180. if(!bOnlyGetLength)
  181. errno = CheckDescription(hWnd, lpDescript);
  182. LocalUnlock(hBuffer);
  183. LocalFree(hBuffer);
  184. CloseHandle(hFile);
  185. SetCursor (LoadCursor (NULL, IDC_ARROW));
  186. return errno;
  187. }
  188. if(bGetDes && !bOnlyGetLength)
  189. {
  190. GetDescriptEntry(szStr,lpDescript);
  191. }
  192. lstrcpy(szStr,TEXT(""));
  193. continue;
  194. }
  195. else {
  196. if(j == 0)
  197. dwOffset = dwFstOffset + i*sizeof(TCHAR);
  198. if(j<1024){
  199. szStr[j]=Buffer[i];
  200. j++;
  201. }
  202. }
  203. }
  204. if(dwReadBytes*sizeof(TCHAR) < MAXREADBUFFER) break;
  205. dwFstOffset += MAXREADBUFFER;
  206. };
  207. *fdwLen = dwFstOffset+dwReadBytes-(*fdwOffset);
  208. if(!bDescript) *fdwLen = 0;
  209. LocalUnlock(hBuffer);
  210. LocalFree(hBuffer);
  211. CloseHandle(hFile);
  212. errno = 0;
  213. if(!bText) {
  214. ProcessError(ERR_TEXTSEG,hWnd,ERR);
  215. errno |= 4;
  216. }
  217. if(!bDescript) {
  218. if(bText)
  219. ProcessError(ERR_DESCRIPTSEG,hWnd,ERR);
  220. errno |= 1;
  221. }
  222. if(!bRule){
  223. if(bText && bDescript)
  224. ProcessError(ERR_RULESEG,hWnd,WARNING);
  225. errno |= 2;
  226. }
  227. SetCursor (LoadCursor (NULL, IDC_ARROW));
  228. if(bDescript && bRule && bText)
  229. return TRUE;
  230. else
  231. return (-errno);
  232. }
  233. BOOL ConvSaveDescript(LPCTSTR SrcFileName,
  234. LPDESCRIPTION lpDescript,
  235. DWORD dwOffset,
  236. DWORD dwLength)
  237. //*** save MB description to source text file ****
  238. {
  239. TCHAR szStr[256],szTemp[80],Buffer[4096];
  240. DWORD dwBytes,dwNewLen;
  241. HANDLE hSrcFile;
  242. BOOL bText=TRUE;
  243. WORD wFlag;
  244. hSrcFile = Create_File(GetFocus(),SrcFileName,GENERIC_READ|GENERIC_WRITE,OPEN_EXISTING);
  245. if (hSrcFile == (HANDLE)-1)
  246. return FALSE;
  247. #ifdef UNICODE
  248. Buffer[0] = 0xfeff;
  249. lstrcpy(&Buffer[1],TEXT("[Description]\r\n"));
  250. #else
  251. lstrcpy(Buffer,TEXT("[Description]\r\n"));
  252. #endif
  253. SetFilePointer(hSrcFile,dwOffset+dwLength,0,FILE_BEGIN);
  254. if (!ReadFile(hSrcFile,szTemp,sizeof(szTemp), &dwBytes,NULL))
  255. {
  256. CloseHandle(hSrcFile);
  257. return FALSE;
  258. }
  259. if(dwBytes == 0 || szTemp[0] != TEXT('['))
  260. bText = FALSE;
  261. if(SetFilePointer(hSrcFile,dwOffset,0,FILE_BEGIN) != dwOffset) {
  262. CloseHandle(hSrcFile);
  263. return FALSE;
  264. }
  265. if(!CheckCodeCollection(GetFocus(),lpDescript->szUsedCode))
  266. {
  267. CloseHandle(hSrcFile);
  268. return FALSE;
  269. }
  270. SetCursor (LoadCursor (NULL, IDC_WAIT));
  271. //write code list name to buffer ****
  272. StringCchPrintf(szStr, ARRAYSIZE(szStr), TEXT("Name=%s\r\n"),lpDescript->szName);
  273. StringCchCat(Buffer, ARRAYSIZE(Buffer), szStr);
  274. //write maximum length of codes to buffer***
  275. StringCchPrintf(szStr, ARRAYSIZE(szStr),TEXT("MaxCodes=%d\r\n"),(int)lpDescript->wMaxCodes);
  276. StringCchCat(Buffer, ARRAYSIZE(Buffer),szStr);
  277. //write maximum element to Buffer ***
  278. StringCchPrintf(szStr, ARRAYSIZE(szStr),TEXT("MaxElement=%d\r\n"),(int)lpDescript->byMaxElement);
  279. StringCchCat(Buffer, ARRAYSIZE(Buffer),szStr);
  280. //write used codes collection ***
  281. lstrncpy(szTemp,MAXUSEDCODES,lpDescript->szUsedCode);
  282. szTemp[MAXUSEDCODES]=0;
  283. StringCchPrintf(szStr, ARRAYSIZE(szStr),TEXT("UsedCodes=%s\r\n"),lpDescript->szUsedCode);
  284. StringCchCat(Buffer, ARRAYSIZE(Buffer),szStr);
  285. //write wild char ***
  286. if(lpDescript->cWildChar == 0)
  287. lpDescript->cWildChar = TEXT('?'); //**** add by yehfeh 95.10.11
  288. StringCchPrintf(szStr, ARRAYSIZE(szStr),TEXT("WildChar=%c\r\n"),lpDescript->cWildChar);
  289. StringCchCat(Buffer, ARRAYSIZE(Buffer),szStr);
  290. //write number of rules ***
  291. StringCchPrintf(szStr, ARRAYSIZE(szStr),TEXT("NumRules=%d\r\n"),(int)lpDescript->wNumRules);
  292. StringCchCat(Buffer, ARRAYSIZE(Buffer),szStr);
  293. if(!bText)
  294. StringCchCat(Buffer, ARRAYSIZE(Buffer),TEXT("[Text]\r\n"));
  295. dwNewLen = lstrlen(Buffer)*sizeof(TCHAR);
  296. if(dwNewLen > dwLength)
  297. MoveFileBlock(hSrcFile,dwOffset+dwLength,dwNewLen-dwLength,1);
  298. else
  299. MoveFileBlock(hSrcFile,dwOffset+dwLength,dwLength-dwNewLen,0);
  300. SetFilePointer(hSrcFile,dwOffset,0,FILE_BEGIN);
  301. WriteFile(hSrcFile,Buffer,dwNewLen,&dwBytes,NULL);
  302. CloseHandle(hSrcFile);
  303. SetCursor (LoadCursor (NULL, IDC_ARROW));
  304. return TRUE;
  305. }
  306. int ConvGetRule(HANDLE hWnd,LPCTSTR lpSrcFile,LPDWORD fdwOffset,
  307. LPDWORD fdwRuleLen,LPRULE lpRule, LPDESCRIPTION lpDescript)
  308. //*** read create word rule from source text file****
  309. {
  310. TCHAR szStr[256],*Buffer;
  311. BOOL bRule=FALSE;
  312. register int i,j;
  313. DWORD dwReadBytes;
  314. DWORD dwNumRules = 0;
  315. DWORD dwFstOffset = 0, dwOffset;
  316. HANDLE hSrcFile;
  317. Buffer = (TCHAR *)LocalAlloc(LMEM_FIXED, MAXREADBUFFER * sizeof(TCHAR));
  318. if (!Buffer)
  319. return (-ERR_OUTOFMEMORY);
  320. *fdwOffset = 0;
  321. hSrcFile = Create_File(hWnd,lpSrcFile,GENERIC_READ,OPEN_EXISTING);
  322. if (hSrcFile == (HANDLE)-1)
  323. {
  324. LocalFree(Buffer);
  325. return (-ERR_FILENOTOPEN);
  326. }
  327. SetCursor (LoadCursor (NULL, IDC_WAIT));
  328. SetFilePointer(hSrcFile,0,0,FILE_BEGIN);
  329. while(ReadFile(hSrcFile,Buffer,MAXREADBUFFER,&dwReadBytes,NULL))
  330. {
  331. dwReadBytes = dwReadBytes/sizeof(TCHAR);
  332. lstrcpy(szStr,TEXT(""));
  333. j=0;
  334. for(i=0;i<(int)dwReadBytes;i++) {
  335. if(Buffer[i] == 0x0d || Buffer[i] == 0xfeff)
  336. continue;
  337. else if(Buffer[i] == TEXT('\n')) {
  338. szStr[j]=0;
  339. j=0;
  340. if(lstrlen(szStr) < 4) continue;
  341. if(lstrcmpi(szStr,TEXT(RuleSeg))==0) {
  342. *fdwOffset= dwOffset;
  343. bRule = TRUE;
  344. lstrcpy(szStr,TEXT(""));
  345. continue;
  346. }
  347. if( (lstrcmpi(szStr,TEXT(TextSeg))==0
  348. ||lstrcmpi(szStr,TEXT(DescriptSeg))==0)
  349. && bRule) {
  350. *fdwRuleLen = dwOffset - (*fdwOffset);
  351. CloseHandle(hSrcFile);
  352. SetCursor (LoadCursor (NULL, IDC_ARROW));
  353. if(dwNumRules != lpDescript->wNumRules) {
  354. ProcessError(ERR_RULENUM,hWnd,ERR);
  355. lpDescript->wNumRules =(WORD) dwNumRules;
  356. LocalFree(Buffer);
  357. return (-ERR_RULENUM);
  358. }
  359. LocalFree(Buffer);
  360. return TRUE;
  361. }
  362. if(bRule) {
  363. if(RuleParse(hWnd,szStr,dwNumRules,lpRule,lpDescript->wMaxCodes))
  364. dwNumRules ++;
  365. else {
  366. CloseHandle(hSrcFile);
  367. SetCursor (LoadCursor (NULL, IDC_ARROW));
  368. LocalFree(Buffer);
  369. return (-ERR_RULENUM);
  370. }
  371. lstrcpy(szStr,TEXT(""));
  372. if(dwNumRules > lpDescript->wNumRules) {
  373. ProcessError(ERR_RULENUM,hWnd,ERR);
  374. CloseHandle(hSrcFile);
  375. SetCursor (LoadCursor (NULL, IDC_ARROW));
  376. LocalFree(Buffer);
  377. return(-ERR_RULENUM);
  378. }
  379. continue;
  380. }
  381. else {
  382. lstrcpy(szStr,TEXT(""));
  383. continue;
  384. }
  385. }
  386. else {
  387. if(j == 0)
  388. dwOffset = dwFstOffset + i*sizeof(TCHAR);
  389. szStr[j]=Buffer[i];
  390. j++;
  391. }
  392. } /*** for (i=0;...) ****/
  393. if(dwReadBytes*sizeof(TCHAR) < MAXREADBUFFER) break;
  394. dwFstOffset += MAXREADBUFFER;
  395. };
  396. *fdwRuleLen = dwFstOffset+dwReadBytes-(*fdwOffset);
  397. if(!bRule)
  398. *fdwRuleLen=0;
  399. CloseHandle(hSrcFile);
  400. SetCursor (LoadCursor (NULL, IDC_ARROW));
  401. if(bRule||lpDescript->wNumRules==0)
  402. {
  403. LocalFree(Buffer);
  404. return TRUE;
  405. }
  406. else {
  407. ProcessError(ERR_RULESEG,hWnd,ERR);
  408. lpDescript->wNumRules=0;
  409. LocalFree(Buffer);
  410. return (-ERR_RULESEG);
  411. }
  412. }
  413. BOOL ConvSaveRule(HANDLE hWnd,LPCTSTR SrcFileName,DWORD dwOffset, DWORD dwLength,
  414. LPRULE lpRule, DWORD dwNumRules)
  415. //*** save create word rule to source text file****
  416. {
  417. TCHAR szStr[256],Buffer[4096];
  418. DWORD dwBytes,dwNewLen;
  419. DWORD i;
  420. HANDLE hFile;
  421. hFile = Create_File(hWnd,SrcFileName,GENERIC_READ|GENERIC_WRITE,OPEN_EXISTING);
  422. if (hFile == (HANDLE)-1)
  423. return FALSE;
  424. SetCursor (LoadCursor (NULL, IDC_WAIT));
  425. lstrcpy(Buffer,TEXT("[Rule]\r\n"));
  426. for(i=0; i<dwNumRules; i++) {
  427. RuleToText(&lpRule[i], szStr);
  428. StringCchCat(Buffer,ARRAYSIZE(Buffer), szStr);
  429. }
  430. dwNewLen = lstrlen(Buffer)*sizeof(TCHAR);
  431. if(dwNewLen > dwLength)
  432. MoveFileBlock(hFile,dwOffset+dwLength,dwNewLen-dwLength,1);
  433. else
  434. MoveFileBlock(hFile,dwOffset+dwLength,dwLength-dwNewLen,0);
  435. SetFilePointer(hFile,dwOffset,0,FILE_BEGIN);
  436. WriteFile(hFile,Buffer,dwNewLen,&dwBytes,NULL);
  437. CloseHandle(hFile);
  438. SetCursor (LoadCursor (NULL, IDC_ARROW));
  439. return TRUE;
  440. }
  441. LPTSTR ConvCreateWord(HWND hWnd,LPCTSTR MBFileName,LPTSTR szWordStr)
  442. {
  443. int nWordLen = lstrlen(szWordStr)*sizeof(TCHAR)/2;
  444. DWORD i,j,k,dwCodeLen;
  445. TCHAR szDBCS[3],szCode[MAXCODELEN+1];
  446. static TCHAR lpCode[128];
  447. BOOL bReturn=FALSE;
  448. HANDLE hMBFile;
  449. DESCRIPTION Descript;
  450. HANDLE hRule0;
  451. LPRULE lpRule;
  452. MAININDEX MainIndex[NUMTABLES];
  453. for(i=0; i< 128; i++)
  454. lpCode[0] = 0;
  455. if(lstrlen(MBFileName)==0 || lstrlen(szWordStr) == 0)
  456. return (LPTSTR)lpCode;
  457. hMBFile = Create_File(hWnd,MBFileName,GENERIC_READ,OPEN_EXISTING);
  458. if(hMBFile == (HANDLE)-1)
  459. return (LPTSTR)lpCode;
  460. if(!ConvGetMainIndex(hWnd,hMBFile,MainIndex)) {
  461. CloseHandle(hMBFile);
  462. return (LPTSTR)lpCode;
  463. }
  464. ConvReadDescript(hMBFile,&Descript, MainIndex);
  465. if(Descript.wNumRules == 0) {
  466. MessageBeep((UINT)-1);
  467. MessageBeep((UINT)-1);
  468. CloseHandle(hMBFile);
  469. return (LPTSTR)lpCode;
  470. }
  471. hRule0 = GlobalAlloc(GMEM_MOVEABLE|GMEM_ZEROINIT,sizeof(RULE)*Descript.wNumRules);
  472. if(!hRule0) {
  473. ProcessError(ERR_OUTOFMEMORY,hWnd,ERR);
  474. CloseHandle(hMBFile);
  475. return (LPTSTR)lpCode;
  476. }
  477. if(!(lpRule = GlobalLock(hRule0)) ) {
  478. ProcessError(ERR_GLOBALLOCK,hWnd,ERR);
  479. CloseHandle(hMBFile);
  480. GlobalFree(hRule0);
  481. return (LPTSTR)lpCode;
  482. }
  483. ConvReadRule(hMBFile,Descript.wNumRules ,lpRule, MainIndex);
  484. for(i=0; i<Descript.wNumRules; i++)
  485. if( (lpRule[i].byLogicOpra == 0 && nWordLen == lpRule[i].byLength)
  486. ||(lpRule[i].byLogicOpra == 1 && nWordLen >= lpRule[i].byLength)
  487. ||(lpRule[i].byLogicOpra == 2 && nWordLen <= lpRule[i].byLength) ) {
  488. int retCodeLen = 0;
  489. for(j=0; j<lpRule[i].wNumCodeUnits; j++) {
  490. k = lpRule[i].CodeUnit[j].wDBCSPosition;
  491. if(k > (DWORD)nWordLen) k = (DWORD)nWordLen;
  492. if(lpRule[i].CodeUnit[j].dwDirectMode == 0)
  493. lstrncpy(szDBCS,2,&szWordStr[2*(k-1)]);
  494. else
  495. lstrncpy(szDBCS,2,&szWordStr[2*(nWordLen-k)]);
  496. szDBCS[2] = 0;
  497. k = EncodeToNo(szDBCS);
  498. if((long)k >= 0 && k < NUM_OF_ENCODE )
  499. {
  500. SetFilePointer(hMBFile,MainIndex[TAG_CRTWORDCODE-1].dwOffset+Descript.wMaxCodes*k*sizeof(TCHAR),
  501. 0,FILE_BEGIN);
  502. ReadFile(hMBFile,szCode,Descript.wMaxCodes,&k,NULL);
  503. szCode[Descript.wMaxCodes] = 0;
  504. dwCodeLen = lstrlen(szCode);
  505. k = lpRule[i].CodeUnit[j].wCodePosition;
  506. if(k == 0)
  507. {
  508. if(retCodeLen + dwCodeLen > Descript.wMaxCodes)
  509. szCode[Descript.wMaxCodes - retCodeLen] = 0;
  510. StringCchCat(lpCode,ARRAYSIZE(lpCode),szCode);
  511. }
  512. else
  513. {
  514. if(k > dwCodeLen) k = dwCodeLen;
  515. lpCode[j] = (szCode[k-1] == 0)?((k > 1)? szCode[k-2]:Descript.szUsedCode[0]):szCode[k-1];
  516. }
  517. }
  518. else
  519. lpCode[j] = (j > 0)?lpCode[j-1]:Descript.szUsedCode[0];
  520. retCodeLen = lstrlen(lpCode);
  521. }
  522. bReturn = TRUE;
  523. break;
  524. }
  525. if(!bReturn)
  526. ProcessError(ERR_NOTDEFRULE,GetFocus(),ERR);
  527. lpCode[Descript.wMaxCodes] = 0;
  528. CloseHandle(hMBFile);
  529. GlobalFree(hRule0);
  530. return (LPTSTR)lpCode;
  531. }
  532. INT ReadDescript(LPCTSTR MBFileName, LPDESCRIPTION lpDescript,DWORD ShareMode)
  533. //*** read description from .MB file ****
  534. {
  535. HANDLE hMBFile;
  536. DWORD dwBytes,i;
  537. DWORD dwOffset;
  538. MAININDEX lpMainIndex[NUMTABLES];
  539. hMBFile = Create_File(GetFocus(),MBFileName,GENERIC_READ,OPEN_EXISTING);
  540. if(hMBFile==INVALID_HANDLE_VALUE)
  541. return -1;
  542. SetFilePointer(hMBFile,ID_LENGTH,0,FILE_BEGIN);
  543. if (!ReadFile(hMBFile,lpMainIndex,sizeof(MAININDEX)*NUMTABLES,&dwBytes,NULL))
  544. {
  545. CloseHandle(hMBFile);
  546. return FALSE;
  547. }
  548. for(i=0; i<NUMTABLES; i++) {
  549. dwBytes = lpMainIndex[i].dwTag+
  550. lpMainIndex[i].dwOffset+
  551. lpMainIndex[i].dwLength;
  552. if(lpMainIndex[i].dwCheckSum != dwBytes) {
  553. CloseHandle(hMBFile);
  554. return FALSE;
  555. }
  556. }
  557. dwOffset = lpMainIndex[TAG_DESCRIPTION-1].dwOffset;
  558. SetFilePointer(hMBFile,dwOffset,0,FILE_BEGIN);
  559. if (!ReadFile(hMBFile,lpDescript,sizeof(DESCRIPTION),&dwBytes,NULL))
  560. {
  561. CloseHandle(hMBFile);
  562. return FALSE;
  563. }
  564. CloseHandle(hMBFile);
  565. if(dwBytes < sizeof(DESCRIPTION) )
  566. return FALSE;
  567. else
  568. return TRUE;
  569. }
  570. BOOL ReadRule(HWND hWnd,
  571. LPCTSTR MBFileName,
  572. int nRuleNum,
  573. LPRULE lpRule)
  574. //*** read create word rule from .MB file ****
  575. {
  576. HANDLE hMBFile;
  577. DWORD dwBytes,i;
  578. DWORD dwOffset;
  579. MAININDEX lpMainIndex[NUMTABLES];
  580. hMBFile = Create_File(hWnd,MBFileName,GENERIC_READ,OPEN_EXISTING);
  581. if(hMBFile==INVALID_HANDLE_VALUE)
  582. return(0);
  583. SetFilePointer(hMBFile,ID_LENGTH,0,FILE_BEGIN);
  584. if (!ReadFile(hMBFile,lpMainIndex,sizeof(MAININDEX)*NUMTABLES,&dwBytes,NULL))
  585. {
  586. CloseHandle(hMBFile);
  587. return FALSE;
  588. }
  589. for(i=0; i<NUMTABLES; i++) {
  590. dwBytes = lpMainIndex[i].dwTag+
  591. lpMainIndex[i].dwOffset+
  592. lpMainIndex[i].dwLength;
  593. if(lpMainIndex[i].dwCheckSum != dwBytes) {
  594. //ProcessError(ERR_READMAININDEX,hWnd);
  595. return FALSE;
  596. }
  597. }
  598. dwOffset = lpMainIndex[TAG_RULE-1].dwOffset;
  599. SetFilePointer(hMBFile,dwOffset,0,FILE_BEGIN);
  600. if (!ReadFile(hMBFile,lpRule,nRuleNum*sizeof(RULE),&dwBytes,NULL))
  601. {
  602. CloseHandle(hMBFile);
  603. return FALSE;
  604. }
  605. CloseHandle(hMBFile);
  606. if(dwBytes < nRuleNum*sizeof(RULE) )
  607. return FALSE;
  608. else
  609. return TRUE;
  610. }
  611. BOOL RuleParse(HANDLE hWnd, LPTSTR szStr,DWORD dwRuleNum, LPRULE lpRule, WORD wMaxCodes)
  612. {
  613. LPTSTR lpString;
  614. DWORD i,j;
  615. DWORD dwLen;
  616. BYTE byDBCSLen, byDBCSPos, byCodePos;
  617. static TCHAR subDBCS[] =TEXT("123456789abcdef");
  618. static TCHAR subCode[] =TEXT("0123456789abc");
  619. DelSpace(szStr);
  620. dwLen = lstrlen(szStr);
  621. if(dwLen == 0) return FALSE;
  622. if(_tcschr(szStr,TEXT('=')) == NULL) {
  623. ProcessError(ERR_RULEEQUAL,hWnd,ERR);
  624. return FALSE;
  625. }
  626. if(_tcschr(TEXT("Cc"),szStr[0]) == NULL) {
  627. ProcessError(ERR_RULEHEADER,hWnd,ERR);
  628. return FALSE;
  629. }
  630. if(_tcschr(TEXT("EeAaBb"),szStr[1]) == NULL) {
  631. ProcessError(ERR_RULELOGICOPRA,hWnd,ERR);
  632. return FALSE;
  633. }
  634. if(_tcschr(subDBCS,szStr[2]) == NULL
  635. || szStr[3] != TEXT('=')) {
  636. ProcessError(ERR_RULEWORDLEN,hWnd,ERR);
  637. return FALSE;
  638. }
  639. byDBCSLen = (szStr[2] > TEXT('9'))?szStr[2]-TEXT('a')+10:szStr[2]-TEXT('0');
  640. lpRule[dwRuleNum].wNumCodeUnits = 0;
  641. lpString = &szStr[4];
  642. for(i=0; i<dwLen-4; i+=4) {
  643. if(_tcschr(TEXT("PpNn"), lpString[i]) == NULL) {
  644. ProcessError(ERR_RULEDIRECTMODE,hWnd,ERR);
  645. return FALSE;
  646. }
  647. byDBCSPos = (lpString[i+1]>TEXT('9'))?10+lpString[i+1]-TEXT('a'):lpString[i+1]-TEXT('0');
  648. if(_tcschr(subDBCS, lpString[i+1]) == NULL
  649. ||byDBCSPos > byDBCSLen) {
  650. ProcessError(ERR_RULEDBCSPOS,hWnd,ERR) ;
  651. return FALSE;
  652. }
  653. byCodePos = (lpString[i+2]>TEXT('9'))?lpString[i+2]-TEXT('a')+10:lpString[i+2]-TEXT('0');
  654. if(_tcschr(subCode, lpString[i+2]) == NULL
  655. || (lpString[i+3] != TEXT('+') && lpString[i+3] != 0)
  656. || byCodePos > wMaxCodes) {
  657. ProcessError(ERR_RULECODEPOS,hWnd,ERR);
  658. return FALSE;
  659. }
  660. j = lpRule[dwRuleNum].wNumCodeUnits;
  661. lpRule[dwRuleNum].CodeUnit[j].dwDirectMode=(lpString[i]==TEXT('p'))?0:1;
  662. lpRule[dwRuleNum].CodeUnit[j].wDBCSPosition=(WORD)byDBCSPos;
  663. lpRule[dwRuleNum].CodeUnit[j].wCodePosition=(WORD)byCodePos;
  664. lpRule[dwRuleNum].wNumCodeUnits ++;
  665. }
  666. lpRule[dwRuleNum].byLogicOpra = (szStr[1]==TEXT('e'))?0:(szStr[1]==TEXT('a'))?1:2;
  667. lpRule[dwRuleNum].byLength = byDBCSLen;
  668. return TRUE;
  669. }
  670. BOOL ConvGetMainID(HANDLE hMBFile,LPMAINID lpMainID)
  671. {
  672. DWORD dwBytes;
  673. SetFilePointer(hMBFile,0,0,FILE_BEGIN);
  674. if (!ReadFile(hMBFile,lpMainID,sizeof(MAINID),&dwBytes,NULL))
  675. return FALSE;
  676. if(dwBytes < sizeof(MAINID) )
  677. return FALSE;
  678. else
  679. return TRUE;
  680. }
  681. BOOL ConvWriteMainID(HANDLE hMBFile,LPMAINID lpMainID)
  682. {
  683. DWORD dwBytes;
  684. if(SetFilePointer(hMBFile,0,0,FILE_BEGIN) != 0)
  685. return FALSE;
  686. WriteFile(hMBFile,lpMainID,sizeof(MAINID),&dwBytes,NULL);
  687. if(dwBytes < sizeof(MAINID) )
  688. return FALSE;
  689. else
  690. return TRUE;
  691. }
  692. BOOL ConvGetMainIndex(HANDLE hWnd, HANDLE hMBFile, LPMAININDEX lpMainIndex)
  693. {
  694. DWORD dwBytes;
  695. int i;
  696. if(SetFilePointer(hMBFile,ID_LENGTH,0,FILE_BEGIN) != ID_LENGTH)
  697. return FALSE;
  698. if (!ReadFile(hMBFile,lpMainIndex,sizeof(MAININDEX)*NUMTABLES,&dwBytes,NULL))
  699. return FALSE;
  700. if(dwBytes < sizeof(MAININDEX)*NUMTABLES ) {
  701. ProcessError(ERR_READMAININDEX,hWnd,ERR);
  702. return FALSE;
  703. }
  704. else
  705. return TRUE;
  706. for(i=0; i<NUMTABLES; i++) {
  707. dwBytes = lpMainIndex[i].dwTag+
  708. lpMainIndex[i].dwOffset+
  709. lpMainIndex[i].dwLength;
  710. if(lpMainIndex[i].dwCheckSum != dwBytes) {
  711. ProcessError(ERR_READMAININDEX,hWnd,ERR);
  712. return FALSE;
  713. }
  714. }
  715. }
  716. BOOL ConvWriteMainIndex(HANDLE hMBFile, LPMAININDEX lpMainIndex)
  717. {
  718. DWORD dwBytes;
  719. if(SetFilePointer(hMBFile,ID_LENGTH,0,FILE_BEGIN) != ID_LENGTH)
  720. return FALSE;
  721. WriteFile(hMBFile,lpMainIndex,sizeof(MAININDEX)*NUMTABLES,&dwBytes,NULL);
  722. if(dwBytes < sizeof(MAININDEX)*NUMTABLES )
  723. return FALSE;
  724. else
  725. return TRUE;
  726. }
  727. BOOL ConvReadDescript(HANDLE hMBFile,
  728. LPDESCRIPTION lpDescript,
  729. LPMAININDEX lpMainIndex)
  730. //*** read description from .MB file ****
  731. {
  732. DWORD dwBytes;
  733. DWORD dwOffset = lpMainIndex[TAG_DESCRIPTION-1].dwOffset;
  734. if(SetFilePointer(hMBFile,dwOffset,0,FILE_BEGIN) != dwOffset)
  735. return FALSE;
  736. if (!ReadFile(hMBFile,lpDescript,sizeof(DESCRIPTION),&dwBytes,NULL))
  737. return FALSE;
  738. if(dwBytes < sizeof(DESCRIPTION) )
  739. return FALSE;
  740. else
  741. return TRUE;
  742. }
  743. BOOL ConvWriteDescript(HANDLE hMBFile,
  744. LPDESCRIPTION lpDescript,
  745. LPMAININDEX lpMainIndex)
  746. //*** write description to .MB file ****
  747. {
  748. DWORD dwBytes;
  749. DWORD dwOffset = lpMainIndex[TAG_DESCRIPTION-1].dwOffset;
  750. if(SetFilePointer(hMBFile,dwOffset,0,FILE_BEGIN) != dwOffset)
  751. return FALSE;
  752. WriteFile(hMBFile,lpDescript,sizeof(DESCRIPTION),&dwBytes,NULL);
  753. if(dwBytes < sizeof(DESCRIPTION) )
  754. return FALSE;
  755. else
  756. return TRUE;
  757. }
  758. BOOL ConvReadRule(HANDLE hMBFile,
  759. int nRuleNum,
  760. LPRULE lpRule,
  761. LPMAININDEX lpMainIndex)
  762. //*** read create word rule from .MB file ****
  763. {
  764. DWORD dwBytes;
  765. DWORD dwOffset = lpMainIndex[TAG_RULE-1].dwOffset;
  766. if(SetFilePointer(hMBFile,dwOffset,0,FILE_BEGIN) != dwOffset)
  767. return FALSE;
  768. if (!ReadFile(hMBFile,lpRule,nRuleNum*sizeof(RULE),&dwBytes,NULL))
  769. return FALSE;
  770. if(dwBytes < nRuleNum*sizeof(RULE) )
  771. return FALSE;
  772. else
  773. return TRUE;
  774. }
  775. BOOL ConvWriteRule(HANDLE hMBFile,
  776. int nRuleNum,
  777. LPRULE lpRule,
  778. LPMAININDEX lpMainIndex)
  779. //*** write create word rule to .MB file ****
  780. {
  781. DWORD dwBytes;
  782. DWORD dwOffset = lpMainIndex[TAG_RULE-1].dwOffset;
  783. if(SetFilePointer(hMBFile,dwOffset,0,FILE_BEGIN) != dwOffset)
  784. return FALSE;
  785. WriteFile(hMBFile,lpRule,nRuleNum*sizeof(RULE),&dwBytes,NULL);
  786. if(dwBytes < nRuleNum*sizeof(RULE) )
  787. return FALSE;
  788. else
  789. return TRUE;
  790. }
  791. BOOL ConvGetEncode(HANDLE hMBFile,
  792. LPENCODEAREA lpEncode,
  793. LPDWORD fdwNumSWords,
  794. LPDWORD fdwNumEncodeArea,
  795. LPMAININDEX lpMainIndex)
  796. {
  797. DWORD dwBytes;
  798. DWORD dwOffset=lpMainIndex[TAG_ENCODE-1].dwOffset;
  799. if(SetFilePointer(hMBFile,dwOffset,0,FILE_BEGIN) != dwOffset)
  800. return FALSE;
  801. if (!ReadFile(hMBFile,fdwNumSWords,4,&dwBytes,NULL))
  802. return FALSE;
  803. if (!ReadFile(hMBFile,fdwNumEncodeArea,4,&dwBytes,NULL))
  804. return FALSE;
  805. if (!ReadFile(hMBFile,lpEncode,lpMainIndex[TAG_ENCODE-1].dwLength,&dwBytes,NULL))
  806. return FALSE;
  807. if(dwBytes < lpMainIndex[TAG_ENCODE-1].dwLength)
  808. return FALSE;
  809. else
  810. return TRUE;
  811. }
  812. //BOOL ConvInitEncode(LPENCODEAREA lpEncode)
  813. BOOL ConvInitEncode(HGLOBAL hEncode)
  814. {
  815. LPENCODEAREA lpEncode;
  816. DWORD i;
  817. lpEncode = (LPENCODEAREA) GlobalLock(hEncode);
  818. #ifdef UNICODE
  819. //CJK Symbols and Punctuation
  820. lpEncode[0].StartEncode = 0x3000;
  821. lpEncode[0].EndEncode = 0x303f;
  822. //CJK Miscellaneous
  823. lpEncode[1].StartEncode = 0x3190;
  824. lpEncode[1].EndEncode = 0x319f;
  825. //Enclosed CJK Letters
  826. lpEncode[2].StartEncode = 0x3200;
  827. lpEncode[2].EndEncode = 0x32ff;
  828. //CJK Compatibility
  829. lpEncode[3].StartEncode = 0x3300;
  830. lpEncode[3].EndEncode = 0x33ff;
  831. //CJK Unified Ideograph
  832. lpEncode[4].StartEncode = 0x4e00;
  833. lpEncode[4].EndEncode = 0x9fff;
  834. //Private Use Area
  835. lpEncode[5].StartEncode = 0xe000;
  836. lpEncode[5].EndEncode = 0xf8ff;
  837. //CJK Compatibility Ideograph
  838. lpEncode[6].StartEncode = 0xf900;
  839. lpEncode[6].EndEncode = 0xfaff;
  840. //CJK Compatibility Font
  841. lpEncode[7].StartEncode = 0xfe30;
  842. lpEncode[7].EndEncode = 0xfe4f;
  843. lpEncode[0].PreCount = 0;
  844. for(i=1; i< NUMENCODEAREA; i++) {
  845. lpEncode[i].PreCount = lpEncode[i-1].PreCount + lpEncode[i-1].EndEncode
  846. - lpEncode[i-1].StartEncode + 1;
  847. }
  848. #else
  849. for(i=0; i< NUMENCODEAREA/2; i++) {
  850. lpEncode[2*i].PreCount = i*190;
  851. lpEncode[2*i].StartEncode = (0x81+i)*256 + 0x40;
  852. lpEncode[2*i].EndEncode = lpEncode[2*i].StartEncode + 0x3e;
  853. lpEncode[2*i+1].PreCount = i*190 + 0x3f ;
  854. lpEncode[2*i+1].StartEncode = (0x81+i)*256 + 0x80;
  855. lpEncode[2*i+1].EndEncode = lpEncode[2*i+1].StartEncode + 0x7e;
  856. }
  857. #endif
  858. GlobalUnlock(hEncode);
  859. return TRUE;
  860. }
  861. BOOL ConvWriteEncode(HANDLE hMBFile, LPENCODEAREA lpEncode,
  862. LPMAININDEX lpMainIndex)
  863. {
  864. DWORD dwBytes,i;
  865. DWORD dwOffset=lpMainIndex[TAG_ENCODE-1].dwOffset;
  866. if(SetFilePointer(hMBFile,dwOffset,0,FILE_BEGIN) != dwOffset)
  867. return FALSE;
  868. i = NUM_OF_ENCODE;
  869. WriteFile(hMBFile,&i,4,&dwBytes,NULL);
  870. i = NUMENCODEAREA;
  871. WriteFile(hMBFile,&i,4,&dwBytes,NULL);
  872. WriteFile(hMBFile,lpEncode,
  873. lpMainIndex[TAG_ENCODE-1].dwLength,&dwBytes,NULL);
  874. if(dwBytes < lpMainIndex[TAG_ENCODE-1].dwLength)
  875. return FALSE;
  876. else
  877. return TRUE;
  878. }
  879. BOOL ConvGetCrtData(HANDLE hMBFile, LPCREATEWORD lpCreateWord,
  880. LPMAININDEX lpMainIndex)
  881. {
  882. DWORD dwBytes;
  883. DWORD dwOffset=lpMainIndex[TAG_CRTWORDCODE-1].dwOffset;
  884. if(SetFilePointer(hMBFile,dwOffset,0,FILE_BEGIN) != dwOffset)
  885. return FALSE;
  886. if (!ReadFile(hMBFile,lpCreateWord,lpMainIndex[TAG_CRTWORDCODE-1].dwLength,&dwBytes,NULL))
  887. return FALSE;
  888. if(dwBytes < lpMainIndex[TAG_CRTWORDCODE-1].dwLength)
  889. return FALSE;
  890. else
  891. return TRUE;
  892. }
  893. BOOL ConvWriteCrtData(HANDLE hMBFile, LPCREATEWORD lpCreateWord,
  894. LPMAININDEX lpMainIndex)
  895. {
  896. DWORD dwBytes;
  897. DWORD dwOffset=lpMainIndex[TAG_CRTWORDCODE-1].dwOffset;
  898. if(SetFilePointer(hMBFile,dwOffset,0,FILE_BEGIN) != dwOffset)
  899. return FALSE;
  900. WriteFile(hMBFile,lpCreateWord,
  901. lpMainIndex[TAG_CRTWORDCODE-1].dwLength,&dwBytes,NULL);
  902. if(dwBytes < lpMainIndex[TAG_CRTWORDCODE-1].dwLength)
  903. return FALSE;
  904. else
  905. return TRUE;
  906. }
  907. BOOL ConvGetReConvIndex(HANDLE hMBFile, LPRECONVINDEX lpReConvIndex,
  908. LPMAININDEX lpMainIndex)
  909. {
  910. DWORD dwBytes;
  911. DWORD dwOffset= lpMainIndex[TAG_RECONVINDEX-1].dwOffset;
  912. if(SetFilePointer(hMBFile,dwOffset,0,FILE_BEGIN) != dwOffset)
  913. return FALSE;
  914. if (!ReadFile(hMBFile,lpReConvIndex,lpMainIndex[TAG_RECONVINDEX-1].dwLength,&dwBytes,NULL))
  915. return FALSE;
  916. if(dwBytes < lpMainIndex[TAG_RECONVINDEX-1].dwLength)
  917. return FALSE;
  918. else
  919. return TRUE;
  920. }
  921. BOOL ConvWriteReConvIdx(HANDLE hMBFile, LPRECONVINDEX lpReConvIndex,
  922. LPMAININDEX lpMainIndex)
  923. {
  924. DWORD dwBytes;
  925. DWORD dwOffset= lpMainIndex[TAG_RECONVINDEX-1].dwOffset;
  926. if(SetFilePointer(hMBFile,dwOffset,0,FILE_BEGIN) != dwOffset)
  927. return FALSE;
  928. WriteFile(hMBFile,lpReConvIndex,
  929. lpMainIndex[TAG_RECONVINDEX-1].dwLength,&dwBytes,NULL);
  930. if(dwBytes < lpMainIndex[TAG_RECONVINDEX-1].dwLength)
  931. return FALSE;
  932. else
  933. return TRUE;
  934. }
  935. BOOL ConvGetCodeIndex(HANDLE hMBFile,LPDWORD fdwMaxXLen,
  936. LPSTR Code, LPMAININDEX lpMainIndex)
  937. {
  938. DWORD dwBytes;
  939. DWORD dwOffset= lpMainIndex[TAG_BASEDICINDEX-1].dwOffset;
  940. if(SetFilePointer(hMBFile,dwOffset,0,FILE_BEGIN) != dwOffset)
  941. return FALSE;
  942. if (!ReadFile(hMBFile,fdwMaxXLen,sizeof(DWORD),&dwBytes,NULL))
  943. return FALSE;
  944. if (!ReadFile(hMBFile,Code,MAXNUMCODES,&dwBytes,NULL))
  945. return FALSE;
  946. if(dwBytes < MAXNUMCODES)
  947. return FALSE;
  948. else
  949. return TRUE;
  950. }
  951. BOOL ConvWriteCodeIndex (HANDLE hMBFile, LPDWORD fdwMaxXLen,
  952. LPTSTR Code, LPMAININDEX lpMainIndex)
  953. {
  954. DWORD dwBytes,i;
  955. DWORD dwOffset= lpMainIndex[TAG_BASEDICINDEX-1].dwOffset;
  956. BYTE CodeIndex[MAXNUMCODES];
  957. if(SetFilePointer(hMBFile,dwOffset,0,FILE_BEGIN) != dwOffset)
  958. return FALSE;
  959. WriteFile(hMBFile,fdwMaxXLen,sizeof(DWORD),&dwBytes,NULL);
  960. for(i=0;i<MAXNUMCODES;i++)
  961. CodeIndex[i] = 0;
  962. for(i=0;i<(DWORD)lstrlen(Code);i++)
  963. CodeIndex[Code[i]] =(BYTE)(i+1);
  964. WriteFile(hMBFile,CodeIndex,MAXNUMCODES,&dwBytes,NULL);
  965. if(dwBytes < MAXNUMCODES)
  966. return FALSE;
  967. else
  968. return TRUE;
  969. }
  970. BOOL ConvGetDicIndex(HANDLE hMBFile, LPDICINDEX lpDicIndex ,
  971. DWORD dwNumCodes, LPMAININDEX lpMainIndex)
  972. {
  973. DWORD dwBytes,ReadBytes;
  974. DWORD dwOffset= lpMainIndex[TAG_BASEDICINDEX-1].dwOffset+
  975. MAXNUMCODES+CODEMAPOFFSET;
  976. if(SetFilePointer(hMBFile,dwOffset,0,FILE_BEGIN) != dwOffset)
  977. return FALSE;
  978. ReadBytes = sizeof(DWORD)*(dwNumCodes+1)*dwNumCodes;
  979. if (!ReadFile(hMBFile,lpDicIndex,ReadBytes,&dwBytes,NULL))
  980. return FALSE;
  981. if(dwBytes < ReadBytes)
  982. return FALSE;
  983. else
  984. return TRUE;
  985. }
  986. BOOL ConvWriteDicIndex(HANDLE hMBFile, LPDICINDEX lpDicIndex ,
  987. DWORD dwNumCodes, LPMAININDEX lpMainIndex)
  988. {
  989. DWORD dwBytes,WriteBytes;
  990. DWORD dwOffset= lpMainIndex[TAG_BASEDICINDEX-1].dwOffset+
  991. MAXNUMCODES+CODEMAPOFFSET;
  992. if(SetFilePointer(hMBFile,dwOffset,0,FILE_BEGIN) != dwOffset)
  993. return FALSE;
  994. WriteBytes = sizeof(DWORD)*(dwNumCodes+1)*dwNumCodes;
  995. WriteFile(hMBFile,lpDicIndex,WriteBytes,&dwBytes,NULL);
  996. if(dwBytes < WriteBytes)
  997. return FALSE;
  998. else
  999. return TRUE;
  1000. }
  1001. BOOL ConvGetNumXYWords(HANDLE hMBFile, LPDWORD lpNumXYWords,
  1002. DWORD dwNumCodes, LPMAININDEX lpMainIndex)
  1003. {
  1004. DWORD dwBytes,ReadBytes;
  1005. DWORD dwOffset;
  1006. ReadBytes = sizeof(DWORD)*(dwNumCodes+1)*dwNumCodes;
  1007. dwOffset=lpMainIndex[TAG_BASEDICINDEX-1].dwOffset+
  1008. MAXNUMCODES+CODEMAPOFFSET+ReadBytes;
  1009. if(SetFilePointer(hMBFile,dwOffset,0,FILE_BEGIN) != dwOffset)
  1010. return FALSE;
  1011. if (!ReadFile(hMBFile,lpNumXYWords,ReadBytes,&dwBytes,NULL))
  1012. return FALSE;
  1013. if(dwBytes < ReadBytes)
  1014. return FALSE;
  1015. else
  1016. return TRUE;
  1017. }
  1018. BOOL ConvWriteNumXYWords(HANDLE hMBFile, LPDWORD lpNumXYWords,
  1019. DWORD dwNumCodes, LPMAININDEX lpMainIndex)
  1020. {
  1021. DWORD dwBytes,WriteBytes;
  1022. DWORD dwOffset;
  1023. WriteBytes = sizeof(DWORD)*(dwNumCodes+1)*dwNumCodes;
  1024. dwOffset=lpMainIndex[TAG_BASEDICINDEX-1].dwOffset+
  1025. MAXNUMCODES+CODEMAPOFFSET+WriteBytes;
  1026. if(SetFilePointer(hMBFile,dwOffset,0,FILE_BEGIN) != dwOffset)
  1027. return FALSE;
  1028. SetFilePointer(hMBFile,lpMainIndex[TAG_BASEDICINDEX-1].dwOffset+
  1029. WriteBytes+MAXNUMCODES+CODEMAPOFFSET,0,FILE_BEGIN);
  1030. WriteFile(hMBFile,lpNumXYWords,WriteBytes,&dwBytes,NULL);
  1031. if(dwBytes < WriteBytes)
  1032. return FALSE;
  1033. else
  1034. return TRUE;
  1035. }
  1036. int ConvReconvIndex(HANDLE hWnd,
  1037. LPTSTR szDBCS,
  1038. LPCREATEWORD lpCreateWords,
  1039. WORDINDEX WordIndex,
  1040. LPDESCRIPTION lpDescript,
  1041. LPRECONVINDEX lpReConvIndex)
  1042. {
  1043. int no;
  1044. TCHAR tmpStr[256];
  1045. if(WordIndex.wDBCSLen != 1)
  1046. return FALSE;
  1047. no = EncodeToNo(szDBCS);
  1048. if(no < 0 || no >= NUM_OF_ENCODE)
  1049. return FALSE;
  1050. if(lpDescript->wNumRules != 0 && lpDescript->byMaxElement == 1)
  1051. {
  1052. lstrncpy(tmpStr,
  1053. lpDescript->wMaxCodes,
  1054. lpCreateWords + no*(DWORD)lpDescript->wMaxCodes);
  1055. if(lstrlen(tmpStr) == 0 ||
  1056. #ifdef UNICODE
  1057. (!(WriteCrtFlag[(no/8)] & (1 << (7 - (no%8))) ) && _wcsicmp(WordIndex.szCode,tmpStr) < 0) )
  1058. #else
  1059. (!(WriteCrtFlag[(no/8)] & (1 << (7 - (no%8))) ) && _strcmpi(WordIndex.szCode,tmpStr) < 0) )
  1060. #endif UNICODE
  1061. lstrncpy(lpCreateWords + no*(DWORD)lpDescript->wMaxCodes,
  1062. lpDescript->wMaxCodes,
  1063. WordIndex.szCode);
  1064. }
  1065. else
  1066. {
  1067. lstrncpy(tmpStr,
  1068. lpDescript->wMaxCodes,
  1069. lpReConvIndex + no*(DWORD)lpDescript->wMaxCodes);
  1070. tmpStr[lpDescript->wMaxCodes] = 0;
  1071. #ifdef UNICODE
  1072. if(lstrlen(tmpStr) == 0 || _wcsicmp(WordIndex.szCode,tmpStr) < 0)
  1073. #else
  1074. if(lstrlen(tmpStr) == 0 || _strcmpi(WordIndex.szCode,tmpStr) < 0)
  1075. #endif
  1076. lstrncpy(lpReConvIndex + no*(DWORD)lpDescript->wMaxCodes,
  1077. lpDescript->wMaxCodes,
  1078. WordIndex.szCode);
  1079. }
  1080. return TRUE;
  1081. }