test.c
上传用户:szljw888
上传日期:2010-04-11
资源大小:124k
文件大小:26k
源码类别:

输入法编程

开发平台:

C/C++

  1. /* 大熊猫输入法(Free Chinese Input)  由YJMSIR(yjmsir@163.com)编写
  2.  * 协议: GPL
  3.  * freeinput( A Chinese Input Method) by YJMSIR(yjmsir@163.com)
  4.  * Licence: GPL 
  5.  */
  6. #include "freepy.h"
  7. //#include <windows.h>
  8. #include <commdlg.h>
  9. //static TCHAR szFileName[MAX_PATH], szTitleName[MAX_PATH] ;
  10. #define GBK_QUFIRST  0x81
  11. #define GBK_QULAST   0xFE   //7e=128-2=126
  12. #define GBK_WEIFIRST 0x40
  13. #define GBK_WEILAST  0xFE   //Be=192-2=190  //126*190=23940,即24k //×4=96k
  14. BOOL YjmBatchMakeWord(TCHAR *FromFile,TCHAR *ToFile,BOOL bOUTPUTFILE,BOOL bINSERTWBLIB)
  15. {
  16.     FILE *fpDict,*fpDict1;
  17.     char    strText[MAXPERLINESTRLENGTH];
  18. int i,iCount;
  19. if((fpDict=_tfopen(FromFile,"r"))==NULL){
  20. MessageBoxPrintf("init","%s can not found",FromFile);
  21. return 1;
  22. }
  23. if(bOUTPUTFILE){
  24. if((fpDict1=_tfopen(ToFile,"wt"))==NULL){
  25. MessageBoxPrintf("init","%s can not found",ToFile);
  26. return 1;
  27. }
  28. }
  29.    for (;;) {
  30.    //首先读取一行
  31. if (!fgets (strText, MAXPERLINESTRLENGTH, fpDict))
  32. break;
  33. //删除末尾的空格和回车键
  34. iCount = strlen (strText) - 1;
  35. while ((strText[iCount] == 'n') || (strText[iCount] == ' ')) {
  36. strText[iCount] = '';
  37. if (!iCount)
  38. break;
  39. iCount--;
  40. }
  41. //删除行中的空格
  42. for(i=0;i<iCount;i++){
  43. if(*(strText+i)==0x20){
  44. _tcscpy(strText+i,strText+i+1);
  45. if (!iCount)
  46. break;
  47. i--;
  48. iCount--;
  49. }
  50. }
  51. if(wConversionSet1 & C_SET1_ERBIMAKEWORD) 
  52. AutoGetWordErbiCode(strText,bINSERTWBLIB);
  53. else AutoGetWordWubiCode(strText,bINSERTWBLIB);
  54. if(bOUTPUTFILE) fprintf(fpDict1,"%s %sn",AutoWuBiCode,strText);
  55.    }
  56.    fclose (fpDict);
  57.    fclose (fpDict1);
  58. return TRUE;
  59. }
  60. BOOL WINAPI BATCHMAKEWORDDialogProc(
  61. HWND hWnd ,
  62. UINT message ,
  63. WPARAM wParam ,
  64. LPARAM lParam )
  65. {
  66. static TCHAR szBATCHMAKEWORDFileName[2][MAX_PATH]={0};
  67. static BOOL  bOUTPUTFILE=0,bINSERTWBLIB=0; 
  68. switch(message) {
  69. case WM_INITDIALOG:
  70. if(!(wConversionSet & CONVERSION_SET_USEWB)){
  71. EndDialog(hWnd,TRUE);
  72. break;
  73. }
  74. if(!_tcslen(szBATCHMAKEWORDFileName[0]))
  75. Add(CurrentTableDir,"word.txt",szBATCHMAKEWORDFileName[0]);
  76. if(!_tcslen(szBATCHMAKEWORDFileName[1]))
  77. Add(CurrentTableDir,"wordout.txt",szBATCHMAKEWORDFileName[1]);
  78. SendMessage(GetDlgItem(hWnd,IDC_EDIT1),WM_SETTEXT,0,(LPARAM)szBATCHMAKEWORDFileName[0]);
  79. SendMessage(GetDlgItem(hWnd,IDC_EDIT2),WM_SETTEXT,0,(LPARAM)szBATCHMAKEWORDFileName[1]);
  80. break;
  81. case WM_COMMAND:
  82. switch(wParam) {
  83. case IDOK:
  84. GetDlgItemText(hWnd,IDC_EDIT1,szBATCHMAKEWORDFileName[0],MAX_PATH);
  85. GetDlgItemText(hWnd,IDC_EDIT2,szBATCHMAKEWORDFileName[1],MAX_PATH);
  86. if(!IsFileExist(szBATCHMAKEWORDFileName[0])){
  87. MessageBox(NULL,_T("没有找到文件"),_T("没有找到文件!"),MB_OK);
  88. EndDialog(hWnd,TRUE);
  89. break;
  90. }
  91. bOUTPUTFILE=(IsDlgButtonChecked(hWnd,IDC_OUTPUTFILE) == BST_CHECKED)?1:0;
  92. bINSERTWBLIB=(IsDlgButtonChecked(hWnd,IDC_INSERTWBLIB) == BST_CHECKED)?1:0;
  93. if(IsFileExist(szBATCHMAKEWORDFileName[1]) && bOUTPUTFILE){
  94. if (MessageBox(NULL, _T("是否覆盖?"),_T("已经存在文件!"), 
  95. MB_YESNO | MB_ICONQUESTION | MB_DEFBUTTON1) != IDYES) {
  96. EndDialog(hWnd,TRUE);
  97. break;
  98. }
  99. }
  100. //excute
  101. if(bOUTPUTFILE||bINSERTWBLIB)
  102. YjmBatchMakeWord(szBATCHMAKEWORDFileName[0],szBATCHMAKEWORDFileName[1],bOUTPUTFILE,bINSERTWBLIB);
  103. EndDialog(hWnd,TRUE);
  104. break;
  105. case IDCANCEL:
  106. EndDialog(hWnd,TRUE);
  107. break;
  108. case IDC_BUTTONDEF:
  109. Add(CurrentTableDir,"word.txt",szBATCHMAKEWORDFileName[0]);
  110. Add(CurrentTableDir,"wordout.txt",szBATCHMAKEWORDFileName[1]);
  111. SendMessage(GetDlgItem(hWnd,IDC_EDIT1),WM_SETTEXT,0,(LPARAM)szBATCHMAKEWORDFileName[0]);
  112. SendMessage(GetDlgItem(hWnd,IDC_EDIT2),WM_SETTEXT,0,(LPARAM)szBATCHMAKEWORDFileName[1]);
  113. //EndDialog(hWnd,TRUE);
  114. break;
  115. case IDC_BUTTONSYSSEL:
  116. if(YjmFileOpenTextDlg (NULL,szBATCHMAKEWORDFileName[0],YJMMessage,0)){
  117. SendMessage(GetDlgItem(hWnd,IDC_EDIT1),WM_SETTEXT,0,(LPARAM)szBATCHMAKEWORDFileName[0]);
  118. }
  119. break;
  120. case IDC_BUTTONUSRSEL:
  121. if(YjmFileOpenTextDlg (NULL,szBATCHMAKEWORDFileName[1],YJMMessage,0)){
  122. SendMessage(GetDlgItem(hWnd,IDC_EDIT2),WM_SETTEXT,0,(LPARAM)szBATCHMAKEWORDFileName[1]);
  123. }
  124. break;
  125. default:
  126. return FALSE;
  127. break;
  128. }
  129. break;
  130. default:
  131. return FALSE;
  132. break;
  133. }
  134. return TRUE;
  135. }
  136. BOOL YjmSortStr(TCHAR *str,BOOL FromSmallToBig)
  137. {
  138. UINT i,j,k;
  139. TCHAR temp;
  140. k=_tcslen(str);
  141. if(k){
  142. for(i=0;i<k;i++){
  143. if(*(str+i)==0x20){
  144. _tcscpy(str+i,str+i+1);
  145. i--;
  146. k--;
  147. }
  148. }
  149. }
  150. if(k){
  151. for(i=0;i<k;i++){
  152. for(j=i;j<k;j++){
  153. if(FromSmallToBig?(*(str+i)>*(str+j)):(*(str+i)<*(str+j))){
  154. temp=*(str+i);
  155. *(str+i)=*(str+j);
  156. *(str+j)=temp;
  157. }
  158. }
  159. }
  160. }
  161. return 1;
  162. }
  163. BOOL SetwubiFirstLeadChr(TCHAR cFirstChr)
  164. {
  165. WORD wHead=cFirstChr-_T('!');
  166. if(wubiFirstLeadChr[wHead]->prev==wubiDictHead->next) 
  167. return 0;
  168. while(wubiFirstLeadChr[wHead]->prev->strCode[0]>=cFirstChr && 
  169. wubiFirstLeadChr[wHead]->prev!=wubiDictHead->next){
  170. wubiFirstLeadChr[wHead]=wubiFirstLeadChr[wHead]->prev;
  171. }
  172. return 1;
  173. }
  174. BOOL ReInitDictionaryWubi()
  175. {
  176. ReLoadWubi:
  177. if ( (lpWubiMapFileBase = (LPVOID) MapViewOfFile( hWubiMapFile,
  178. FILE_MAP_ALL_ACCESS ,
  179. 0,
  180. 0,
  181. 0)) != NULL) {
  182. SwitchUserPath=1;
  183. DestroyDictionaryWubi(1);
  184. SwitchUserPath=0;
  185. if(!EnlargeWubiShareMemoryNumAndWriteUserIni()) 
  186. exit(1);//扩大五兆
  187. }
  188. if(InitDictionaryWubi()==2) {
  189. goto ReLoadWubi;
  190. }
  191. return 0;
  192. }
  193. BOOL ReInitDictionaryPinyin()
  194. {
  195. ReLoadPinyin:
  196. if ( (lpMapFileBase = (LPVOID) MapViewOfFile( hMapFile,
  197. FILE_MAP_ALL_ACCESS ,
  198. 0,
  199. 0,
  200. 0)) != NULL) {
  201. SwitchUserPath=1;
  202. DestroyDictionaryPinYin(1);
  203. SwitchUserPath=0;
  204. if(!EnlargePinyinShareMemoryNumAndWriteUserIni()) 
  205. exit(1);//扩大五兆
  206. }
  207. if(InitDictionaryPinYin()==2) {
  208. goto ReLoadPinyin;
  209. }
  210. return 0;
  211. }
  212. BOOL ReInitDictionaryAttachLib()
  213. {
  214. ReLoadAttachLib:
  215. if ( (lpAttachLibMapFileBase = (LPVOID) MapViewOfFile( hAttachLibMapFile,
  216. FILE_MAP_ALL_ACCESS ,
  217. 0,
  218. 0,
  219. 0)) != NULL) {
  220. SwitchUserPath=1;
  221. DestroyDictionaryAttachLib();
  222. SwitchUserPath=0;
  223. if(!EnlargeAttachShareMemoryNumAndWriteUserIni()) exit(1);//扩大五兆
  224. }
  225. if(InitDictionaryAttachLib()==2) {
  226. goto ReLoadAttachLib;
  227. }
  228. return 0;
  229. }
  230. BOOL EnlargePinyinShareMemoryNumAndWriteUserIni()
  231. {
  232. if(dwPinyinShareMemorySum<40000000){//40M
  233. dwPinyinShareMemorySum+=5000000;//5M
  234. WriteUserIni();
  235. return 1;
  236. }
  237. else 
  238. return 0;
  239. }
  240. BOOL EnlargeWubiShareMemoryNumAndWriteUserIni()
  241. {
  242. if(dwWubiShareMemorySum<40000000){
  243. dwWubiShareMemorySum+=5000000;
  244. WriteUserIni();
  245. return 1;
  246. }
  247. else 
  248. return 0;
  249. }
  250. BOOL EnlargeAttachShareMemoryNumAndWriteUserIni()
  251. {
  252. if(dwAttachShareMemorySum<40000000){
  253. dwAttachShareMemorySum+=5000000;
  254. WriteUserIni();
  255. return 1;
  256. }
  257. else 
  258. return 0;
  259. }
  260. BOOL WINAPI MainLibDialogProc(
  261. HWND hWnd ,
  262. UINT message ,
  263. WPARAM wParam ,
  264. LPARAM lParam )
  265. {
  266. TCHAR ButtonText[2][20]={"启用主词库","禁用主词库"};
  267. static TCHAR szMainLibFileNametmp[2][MAX_PATH]={0};
  268. switch(message) {
  269. case WM_INITDIALOG:
  270. _tcscpy(szMainLibFileNametmp[0],szMainLibFileName[0]);
  271. _tcscpy(szMainLibFileNametmp[1],szMainLibFileName[1]);
  272. SendMessage(GetDlgItem(hWnd,IDC_EDIT1),WM_SETTEXT,0,(LPARAM)szMainLibFileNametmp[0]);
  273. SendMessage(GetDlgItem(hWnd,IDC_EDIT2),WM_SETTEXT,0,(LPARAM)szMainLibFileNametmp[1]);
  274. if(wConversionSet & CONVERSION_SET_USEWB){
  275. SendMessage(GetDlgItem(hWnd,IDC_BUTTONNOMAIN),WM_SETTEXT,0,(LPARAM)ButtonText[1]);
  276. }
  277. else{
  278. SendMessage(GetDlgItem(hWnd,IDC_BUTTONNOMAIN),WM_SETTEXT,0,(LPARAM)ButtonText[0]);
  279. }
  280. break;
  281. case WM_COMMAND:
  282. switch(wParam) {
  283. case IDOK:
  284. MessageBox(NULL,_T("请慎用这个功能!"),_T("注意!"),MB_OK);
  285. GetDlgItemText(hWnd,IDC_EDIT1,szMainLibFileName[0],MAX_PATH);
  286. GetDlgItemText(hWnd,IDC_EDIT2,szMainLibFileName[1],MAX_PATH);
  287. EndDialog(hWnd,TRUE);
  288. break;
  289. case IDCANCEL:
  290. _tcscpy(szMainLibFileName[0],szMainLibFileNametmp[0]);
  291. _tcscpy(szMainLibFileName[1],szMainLibFileNametmp[1]);
  292. EndDialog(hWnd,TRUE);
  293. break;
  294. case IDC_BUTTONDEF:
  295. szMainLibFileName[0][0]='';
  296. szMainLibFileName[1][0]='';
  297. SendMessage(GetDlgItem(hWnd,IDC_EDIT1),WM_SETTEXT,0,(LPARAM)szMainLibFileName[0]);
  298. SendMessage(GetDlgItem(hWnd,IDC_EDIT2),WM_SETTEXT,0,(LPARAM)szMainLibFileName[1]);
  299. WriteUserIni();
  300. //EndDialog(hWnd,TRUE);
  301. break;
  302. case IDC_BUTTONSYSSEL:
  303. MessageBox(NULL,_T("请慎用这个功能!"),_T("注意!"),MB_OK);
  304. if(YjmFileOpenTextDlg (NULL,szMainLibFileName[0],YJMMessage,0)){
  305. SendMessage(GetDlgItem(hWnd,IDC_EDIT1),WM_SETTEXT,0,(LPARAM)szMainLibFileName[0]);
  306. WriteUserIni();
  307. }
  308. break;
  309. case IDC_BUTTONUSRSEL:
  310. MessageBox(NULL,_T("请慎用这个功能!"),_T("注意!"),MB_OK);
  311. if(YjmFileOpenTextDlg (NULL,szMainLibFileName[1],YJMMessage,0)){
  312. SendMessage(GetDlgItem(hWnd,IDC_EDIT2),WM_SETTEXT,0,(LPARAM)szMainLibFileName[1]);
  313. WriteUserIni();
  314. }
  315. break;
  316. case IDC_BUTTONNOMAIN:
  317. if(wConversionSet & CONVERSION_SET_USEWB){
  318. wConversionSet &= ~CONVERSION_SET_USEWB;
  319. WriteUserIni();
  320. SendMessage(GetDlgItem(hWnd,IDC_BUTTONNOMAIN),WM_SETTEXT,0,(LPARAM)ButtonText[0]);
  321. SwitchUserPath=1;
  322. DestroyDictionaryWubi(0);
  323. SwitchUserPath=0;
  324. }
  325. else{
  326. wConversionSet |= CONVERSION_SET_USEWB;
  327. WriteUserIni();
  328. SendMessage(GetDlgItem(hWnd,IDC_BUTTONNOMAIN),WM_SETTEXT,0,(LPARAM)ButtonText[1]);
  329. InitDictionaryWubi();
  330. }
  331. EndDialog(hWnd,TRUE);
  332. break;
  333. case IDC_BUTTONATONCE:
  334. //wWubiMapCount=1;/**/
  335. SwitchUserPath=1;
  336. DestroyDictionaryWubi(0);
  337. SwitchUserPath=0;
  338. InitDictionaryWubi();
  339. EndDialog(hWnd,TRUE);
  340. break;
  341. default:
  342. return FALSE;
  343. break;
  344. }
  345. break;
  346. default:
  347. return FALSE;
  348. break;
  349. }
  350. return TRUE;
  351. }
  352. BOOL WINAPI AttachLibDialogProc(
  353. HWND hWnd ,
  354. UINT message ,
  355. WPARAM wParam ,
  356. LPARAM lParam )
  357. {
  358. TCHAR ButtonText[2][20]={"启用附加词库","禁用附加词库"};
  359. switch(message) {
  360. case WM_INITDIALOG:
  361. SendMessage(GetDlgItem(hWnd,IDC_EDIT1),WM_SETTEXT,0,(LPARAM)szAttachLibFileName[0]);
  362. SendMessage(GetDlgItem(hWnd,IDC_EDIT2),WM_SETTEXT,0,(LPARAM)szAttachLibFileName[1]);
  363. SendMessage(GetDlgItem(hWnd,IDC_EDIT3),WM_SETTEXT,0,(LPARAM)szAttachLibFileName[2]);
  364. if(wConversionSet & CONVERSION_SET_USEATTACH){
  365. SendMessage(GetDlgItem(hWnd,IDC_BUTTONNOATT),WM_SETTEXT,0,(LPARAM)ButtonText[1]);
  366. }
  367. else{
  368. SendMessage(GetDlgItem(hWnd,IDC_BUTTONNOATT),WM_SETTEXT,0,(LPARAM)ButtonText[0]);
  369. }
  370. break;
  371. case WM_COMMAND:
  372. switch(wParam) {
  373. case IDOK:
  374. GetDlgItemText(hWnd,IDC_EDIT1,szAttachLibFileName[0],MAX_PATH);
  375. GetDlgItemText(hWnd,IDC_EDIT2,szAttachLibFileName[1],MAX_PATH);
  376. GetDlgItemText(hWnd,IDC_EDIT3,szAttachLibFileName[2],MAX_PATH);
  377. EndDialog(hWnd,TRUE);
  378. break;
  379. case IDCANCEL:
  380. EndDialog(hWnd,TRUE);
  381. break;
  382. case IDC_BUTTONDEF:
  383. szAttachLibFileName[0][0]='';
  384. szAttachLibFileName[1][0]='';
  385. szAttachLibFileName[2][0]='';
  386. WriteUserIni();
  387. SendMessage(GetDlgItem(hWnd,IDC_EDIT1),WM_SETTEXT,0,(LPARAM)szAttachLibFileName[0]);
  388. SendMessage(GetDlgItem(hWnd,IDC_EDIT2),WM_SETTEXT,0,(LPARAM)szAttachLibFileName[1]);
  389. SendMessage(GetDlgItem(hWnd,IDC_EDIT3),WM_SETTEXT,0,(LPARAM)szAttachLibFileName[2]);
  390. //EndDialog(hWnd,TRUE);
  391. break;
  392. case IDC_BUTTONATT1:
  393. if(YjmFileOpenTextDlg (NULL,szAttachLibFileName[0],YJMMessage,0)){
  394. WriteUserIni();
  395. SendMessage(GetDlgItem(hWnd,IDC_EDIT1),WM_SETTEXT,0,(LPARAM)szAttachLibFileName[0]);
  396. }
  397. break;
  398. case IDC_BUTTONATT2:
  399. if(YjmFileOpenTextDlg (NULL,szAttachLibFileName[1],YJMMessage,0)){
  400. WriteUserIni();
  401. SendMessage(GetDlgItem(hWnd,IDC_EDIT2),WM_SETTEXT,0,(LPARAM)szAttachLibFileName[1]);
  402. }
  403. break;
  404. case IDC_BUTTONATT3:
  405. if(YjmFileOpenTextDlg (NULL,szAttachLibFileName[2],YJMMessage,0)){
  406. WriteUserIni();
  407. SendMessage(GetDlgItem(hWnd,IDC_EDIT3),WM_SETTEXT,0,(LPARAM)szAttachLibFileName[2]);
  408. }
  409. break;
  410. case IDC_BUTTONNOATT:
  411. if(wConversionSet & CONVERSION_SET_USEATTACH){
  412. wConversionSet &= ~CONVERSION_SET_USEATTACH;
  413. WriteUserIni();
  414. SendMessage(GetDlgItem(hWnd,IDC_BUTTONNOATT),WM_SETTEXT,0,(LPARAM)ButtonText[0]);
  415. SwitchUserPath=1;
  416. DestroyDictionaryAttachLib();
  417. SwitchUserPath=0;
  418. }
  419. else{
  420. wConversionSet |= CONVERSION_SET_USEATTACH;
  421. WriteUserIni();
  422. SendMessage(GetDlgItem(hWnd,IDC_BUTTONNOATT),WM_SETTEXT,0,(LPARAM)ButtonText[1]);
  423. InitDictionaryAttachLib();
  424. }
  425. EndDialog(hWnd,TRUE);
  426. break;
  427. case IDC_BUTTONATONCE:
  428. //wAttachLibMapCount=1;
  429. SwitchUserPath=1;
  430. DestroyDictionaryAttachLib();
  431. SwitchUserPath=0;
  432. InitDictionaryAttachLib();
  433. EndDialog(hWnd,TRUE);
  434. break;
  435. default:
  436. return FALSE;
  437. break;
  438. }
  439. break;
  440. default:
  441. return FALSE;
  442. break;
  443. }
  444. return TRUE;
  445. }
  446. UINT QueryQuickSearchTablegbk(char *strHZ,char *resultcode)
  447. {
  448. unsigned char HZ[3]="aa",CODE[5]="aaaa",*lpcode;
  449. UINT k;
  450. if(_tcslen(strHZ)!=2) return 0;
  451. _tcscpy(HZ,strHZ);
  452. lpcode=WB4GBK+4*((GBK_WEILAST-GBK_WEIFIRST+1)*(HZ[0]-GBK_QUFIRST)+HZ[1]-GBK_WEIFIRST);
  453. for(k=0;k<4;k++){
  454. CODE[k]=*(lpcode+k);
  455. if(CODE[k]==0x20){
  456. CODE[k]='';
  457. break;
  458. }
  459. }
  460. CODE[4]='';
  461. if(!_tcslen(CODE)) return 0;
  462. _tcscpy(resultcode,CODE);
  463. return 1;
  464. }
  465. UINT GetQuickSearchTablegbk()
  466. {
  467.     WBRecord __based(lpWubiMapFileBase) *recTemp;
  468.     FILE    *fp,*fp1;
  469. TCHAR QuickSearchTable[GBK_QULAST-GBK_QUFIRST+2][GBK_WEILAST-GBK_WEIFIRST+1][4]={0};
  470. unsigned char HZ[3]="aa",CODE[7]="aaaa";
  471. UINT i,j,k,l;
  472. for(i=GBK_QUFIRST;i<=GBK_QULAST;i++){
  473. for(j=GBK_WEIFIRST;j<=GBK_WEILAST;j++){
  474. for(k=0;k<4;k++){
  475. QuickSearchTable[i-GBK_QUFIRST][j-GBK_WEIFIRST][k]=0x20;
  476. }
  477. }
  478. }
  479. if((fp=YJMOpenFileForWrite("wb4codegbk.dat"))== NULL) exit(1);
  480. if((fp1=YJMOpenFileForWrite("wb4codegbkRef.txt"))== NULL) exit(1);
  481. for(l=1;l<=6;l++){
  482. recTemp = wubiDictHead->next;
  483. if(wubiDictHead->prev!=NULL){
  484. while (recTemp!= wubiDictHead->prev) {
  485. if(_tcslen(recTemp->strHZ)==2 && _tcslen(recTemp->strCode)==l){
  486. _tcscpy(HZ,recTemp->strHZ);
  487. _tcscpy(CODE,recTemp->strCode);
  488. CODE[4]='';
  489. if(HZ[0]<=GBK_QULAST && HZ[0]>=GBK_QUFIRST &&
  490.    HZ[1]<=GBK_WEILAST && HZ[1]>=GBK_WEIFIRST){
  491. for(k=0;k<4;k++){
  492. if(CODE[k]=='') goto yjm_next_hz;
  493. QuickSearchTable[HZ[0]-GBK_QUFIRST][HZ[1]-GBK_WEIFIRST][k]=CODE[k];
  494. }
  495. yjm_next_hz:;
  496. }
  497. }
  498. recTemp = recTemp->next;
  499. }
  500. }
  501. }
  502. fprintf (fp, "%s", QuickSearchTable);
  503. fprintf (fp1, _T("生成此前4码表用于自动造词时参考,同时可以加快造词速度。方便大家检查码表是否标准。也希望大家共同努力制定出一个标准的反查表来。n"));
  504. fprintf (fp1, _T("汉字 编码 区码 位码n"));
  505. for(i=GBK_QUFIRST;i<=GBK_QULAST;i++){
  506. for(j=GBK_WEIFIRST;j<=GBK_WEILAST;j++){
  507. HZ[0]=i;
  508. HZ[1]=j;
  509. HZ[2]='';
  510. for(k=0;k<4;k++){
  511. CODE[k]=QuickSearchTable[i-GBK_QUFIRST][j-GBK_WEIFIRST][k];
  512. }
  513. CODE[4]='';
  514. fprintf (fp1, "%s  %s %x %xn",HZ,CODE,i,j);
  515. }
  516. }
  517. fclose (fp);
  518. fclose (fp1);
  519. return 0;
  520. }
  521. BOOL YjmFileOpenDlg (HWND hwnd, PTSTR pstrFileName, PTSTR pstrTitleName,int iSave)
  522. {
  523.   static OPENFILENAME ofn ;
  524.       static TCHAR szFilter[] =  TEXT ("Picture Files (*.bmp)*.bmp");
  525.       ofn.lStructSize        = sizeof (OPENFILENAME) ;
  526.       ofn.hwndOwner          = hwnd ;
  527.       ofn.hInstance          = NULL ;
  528.       ofn.lpstrFilter        = szFilter ;
  529.       ofn.lpstrCustomFilter  = NULL ;
  530.       ofn.nMaxCustFilter     = 0 ;
  531.       ofn.nFilterIndex       = 0 ;
  532.       //ofn.lpstrFile          = NULL ;           // Set in Open and Close functions
  533.       ofn.nMaxFile           = MAX_PATH ;
  534.       //ofn.lpstrFileTitle     = NULL ;           // Set in Open and Close functions
  535.       ofn.nMaxFileTitle      = MAX_PATH ;
  536.       ofn.lpstrInitialDir    = NULL ;
  537.       ofn.lpstrTitle         = NULL ;
  538.       ofn.Flags              = OFN_EXPLORER | OFN_FILEMUSTEXIST |OFN_PATHMUSTEXIST ;// Set in Open and Close functions
  539.       ofn.nFileOffset        = 0 ;
  540.       ofn.nFileExtension     = 0 ;
  541.       ofn.lpstrDefExt        = TEXT ("bmp") ;
  542.       ofn.lCustData          = 0L ;
  543.       ofn.lpfnHook           = NULL ;
  544.       ofn.lpTemplateName     = NULL ;
  545. //      ofn.hwndOwner          = hwnd ;
  546.       ofn.lpstrFile          = pstrFileName ;
  547.       ofn.lpstrFileTitle     = pstrTitleName ;
  548.       //ofn.Flags              = OFN_HIDEREADONLY | OFN_CREATEPROMPT ;
  549.      
  550. if(!iSave)
  551.       return GetOpenFileName (&ofn);
  552. else return GetSaveFileName (&ofn);
  553. }
  554. BOOL YjmFileOpenTextDlg (HWND hwnd, PTSTR pstrFileName, PTSTR pstrTitleName,int iSave)
  555. {
  556.   static OPENFILENAME ofn ;
  557.       static TCHAR szFilter[] =  TEXT ("Text Files (*.*)*.*");
  558.       ofn.lStructSize        = sizeof (OPENFILENAME) ;
  559.       ofn.hwndOwner          = hwnd ;
  560.       ofn.hInstance          = NULL ;
  561.       ofn.lpstrFilter        = szFilter ;
  562.       ofn.lpstrCustomFilter  = NULL ;
  563.       ofn.nMaxCustFilter     = 0 ;
  564.       ofn.nFilterIndex       = 0 ;
  565.       //ofn.lpstrFile          = NULL ;           // Set in Open and Close functions
  566.       ofn.nMaxFile           = MAX_PATH ;
  567.       //ofn.lpstrFileTitle     = NULL ;           // Set in Open and Close functions
  568.       ofn.nMaxFileTitle      = MAX_PATH ;
  569.       ofn.lpstrInitialDir    = NULL ;
  570.       ofn.lpstrTitle         = NULL ;
  571.       ofn.Flags              = OFN_EXPLORER | OFN_FILEMUSTEXIST |OFN_PATHMUSTEXIST ;              // Set in Open and Close functions
  572.       ofn.nFileOffset        = 0 ;
  573.       ofn.nFileExtension     = 0 ;
  574.       ofn.lpstrDefExt        = TEXT ("txt") ;
  575.       ofn.lCustData          = 0L ;
  576.       ofn.lpfnHook           = NULL ;
  577.       ofn.lpTemplateName     = NULL ;
  578. //      ofn.hwndOwner          = hwnd ;
  579.       ofn.lpstrFile          = pstrFileName ;
  580.       ofn.lpstrFileTitle     = pstrTitleName ;
  581.       //ofn.Flags              = OFN_HIDEREADONLY | OFN_CREATEPROMPT ;
  582. if(!iSave)
  583.       return GetOpenFileName (&ofn);
  584. else return GetSaveFileName (&ofn);
  585. }
  586. UINT YjmGetColor(COLORREF *ColorTarget)
  587. {
  588. CHOOSECOLOR cc ;
  589. COLORREF  crCustColors[16];
  590. cc.lStructSize     = sizeof (CHOOSECOLOR) ;
  591.     cc.hwndOwner       = NULL ;
  592.     cc.hInstance       = NULL ;
  593.     cc.rgbResult       = RGB (0x80, 0x80, 0x80) ;
  594.     cc.lpCustColors    = crCustColors ;
  595.     cc.Flags           = CC_RGBINIT | CC_FULLOPEN ;
  596.     cc.lCustData       = 0 ;
  597.     cc.lpfnHook        = NULL ;
  598. cc.lpTemplateName = NULL ;
  599.     if(ChooseColor (&cc))
  600. *ColorTarget=crCustColors[0];
  601. return 1;
  602. }
  603. //输出词条文件
  604. UINT GetSingWordPerLine(UINT num,UINT codenum)
  605. {
  606.     WBRecord __based(lpWubiMapFileBase) *recTemp;
  607.     FILE        *fp;
  608. TCHAR szTabFileName[MAX_PATH],szPreStr[100],szPrePreStr[100],szPrePrePreStr[100];
  609. UINT num2=num*2;
  610. Add(CurrentTableDir,"SingWordPerLine.txt",szTabFileName);
  611. if( (fp = _tfopen( szTabFileName, "wt" )) == NULL ){
  612. MessageBoxPrintf("init","%s can not found",szTabFileName);
  613. exit(1);
  614. }
  615.     recTemp = wubiDictHead->next;
  616. if(wubiDictHead->prev!=NULL){
  617. while (recTemp!= wubiDictHead->prev) {
  618. if(_tcslen(recTemp->strHZ)==num2){
  619. if(codenum!=0){
  620. if(_tcslen(recTemp->strCode)==codenum){
  621. fprintf (fp, "%s %sn", (char *)recTemp->strHZ,(char *)recTemp->strCode);
  622. }
  623. }
  624. else if(_tcscmp(szPreStr,(char *)recTemp->strHZ)&&
  625. _tcscmp(szPrePreStr,(char *)recTemp->strHZ)&&
  626. _tcscmp(szPrePrePreStr,(char *)recTemp->strHZ)){
  627. fprintf (fp, "%sn", (char *)recTemp->strHZ);
  628. _tcscpy(szPrePrePreStr,szPrePreStr);
  629. _tcscpy(szPrePreStr,szPreStr);
  630. _tcscpy(szPreStr,(char *)recTemp->strHZ);
  631. }
  632. }
  633. recTemp = recTemp->next;
  634. }
  635. }
  636. fclose (fp);
  637. return 0;
  638. }
  639. //输出词条文件
  640. UINT GetSingWordPerLinePinyin(UINT num,UINT codenum)
  641. {
  642. FILE *stream;
  643. TCHAR szTabFileName[MAX_PATH];
  644. int i,j,k;
  645. WORD awKey[MAX_PHRASE_LEN];
  646. WORD wLen;
  647. BYTE bLen;
  648. LPKEYPH lpKPh;
  649. LPHZPH lpHZPh;
  650. BOOL fFirst1,fFirst2;
  651. WORD wPhLen;
  652. TCHAR  YJMaPYTab[MAX_PY_NUM][MAX_PHRASE_LEN+1] = {0};
  653. Add(CurrentTableDir,"word_PY2.txt",szTabFileName);
  654. if( (stream = _tfopen( szTabFileName, "wt" )) == NULL ){
  655. MessageBoxPrintf("init","%s can not found",szTabFileName);
  656. exit(1);
  657. }
  658. for(i=0;i<26;i++){
  659. for(j=0;j<MAX_EACH_PY_NUM;j++){
  660. if(aPYTab[i][j].wKey){
  661. _tcscpy(YJMaPYTab[aPYTab[i][j].wKey],aPYTab[i][j].szPY);
  662. //fprintf (stream, "%d %sn",aPYTab[i][j].wKey,aPYTab[i][j].szPY);
  663. }
  664. }
  665. }
  666. //
  667. for(i=0;i<2;i++){
  668. for(j=0;j<MAX_PY_NUM;j++){
  669. if( !(lpKPh=(LPKEYPH)((LPBYTE)lpMapFileBase+i*MAX_PY_NUM*sizeof(KEYPH))+j)->wLen ) {
  670. continue;//如果是本码位没有词组,进入下一码位。
  671. }
  672. fFirst1 = TRUE;
  673. do {
  674. if( fFirst1 ) fFirst1 = FALSE;
  675. else lpKPh = lpKPh->lpNext;
  676. if( lpKPh->wLen !=(int) num ) continue;//yjm
  677. if( lpKPh->wLen < 0 ) continue;
  678. wLen = lpKPh->wLen;
  679. bLen = (BYTE)wLen;
  680. lpHZPh = lpKPh->lpHZPH;
  681. memcpy(awKey,lpKPh->awKey,wLen*2);
  682. fFirst2 = TRUE;
  683. wPhLen = 0;
  684. do {
  685. if( fFirst2 ) fFirst2 = FALSE;
  686. else lpHZPh = lpHZPh->lpNext;
  687. fprintf (stream, "%s", (char *)lpHZPh->szHZ);
  688. if(codenum>=1){
  689. for(k=0;k<bLen;k++){
  690. fprintf (stream, " %s",YJMaPYTab[awKey[k]]);
  691. }
  692. }
  693. if(codenum>=2){
  694. fprintf (stream, " %d",lpHZPh->dwAttrib);
  695. }
  696. fprintf (stream, "n");
  697. }while(lpHZPh->lpNext != NULL);
  698. } while(lpKPh->lpNext != NULL);
  699. }
  700. }
  701. fclose (stream);
  702. return 0;
  703. }
  704. UINT GetFreePYTable()
  705. {
  706.     WBRecord __based(lpWubiMapFileBase) *recTemp;
  707.     FILE        *fp;
  708. TCHAR szTabFileName[MAX_PATH],szHZStr[2000];
  709. char i,j,k[3];
  710. BOOL bFirst;
  711. LPTSTR lpDest;
  712. Add(CurrentTableDir,"freepyout.tab",szTabFileName);
  713. if( (fp = _tfopen( szTabFileName, "wt" )) == NULL ){
  714. MessageBoxPrintf("init","%s can not found",szTabFileName);
  715. exit(1);
  716. }
  717. fprintf (fp, "n[PUNCTUATION]nnn[DICTIONARY]");
  718. k[2]='';
  719. for(i='a';i<='z';i++){
  720. for(j='a';j<='z';j++){
  721. k[0]=i;
  722. k[1]=j;
  723. //fprintf (fp, "n%s ",k);
  724. bFirst=TRUE;
  725. recTemp = wubiDictHead->next;
  726. if(wubiDictHead->prev!=NULL){
  727. while (recTemp!= wubiDictHead->prev) {
  728. if((strlen(recTemp->strHZ)==2) &&
  729. (recTemp->strCode[0]==i) && 
  730. (recTemp->strCode[1]==j)){
  731. if(bFirst==TRUE) strcpy(szHZStr,recTemp->strHZ);
  732. else if((lpDest=strstr(szHZStr,recTemp->strHZ))==NULL||
  733. ((lpDest-szHZStr)%2))
  734. strcat(szHZStr,recTemp->strHZ);
  735. bFirst=FALSE;
  736. }
  737. recTemp = recTemp->next;
  738. }
  739. }
  740. if(bFirst!=TRUE)fprintf (fp, "n%s %s",k,szHZStr);
  741. }
  742. }
  743. fprintf (fp, "nn");
  744. fclose (fp);
  745. return 0;
  746. }
  747. BOOL WINAPI TestDialogProc(
  748. HWND hWnd ,
  749. UINT message ,
  750. WPARAM wParam ,
  751. LPARAM lParam )
  752. {
  753. TCHAR lpStr[4]="1";
  754. UINT num,codenum=0;
  755. //HWND hWndyjm;
  756. switch(message) {
  757. case WM_INITDIALOG:
  758. break;
  759. case WM_COMMAND:
  760. switch(wParam) {
  761. case IDOK:
  762. GetDlgItemText(hWnd,IDC_EDIT1,lpStr,3);
  763. sscanf(lpStr,"%u",&num);
  764. if(IsDlgButtonChecked(hWnd,IDC_CHECK1) == BST_CHECKED){
  765. GetDlgItemText(hWnd,IDC_EDIT2,lpStr,2);
  766. sscanf(lpStr,"%u",&codenum);
  767. }
  768. GetSingWordPerLine(num,codenum);
  769. EndDialog(hWnd,TRUE);
  770. break;
  771. case IDCANCEL:
  772. EndDialog(hWnd,TRUE);
  773. //MessageBox(NULL,_T("已经放弃."),_T("输出汉字词语"),MB_OK);
  774. break;
  775. case IDC_QUICKSEARCHGBK:
  776. GetQuickSearchTablegbk();
  777. EndDialog(hWnd,TRUE);
  778. break;
  779. case IDC_FREEPYTAB:
  780. GetFreePYTable();
  781. EndDialog(hWnd,TRUE);
  782. break;
  783. case IDC_FREEPYITEMTEXT:
  784. GetDlgItemText(hWnd,IDC_EDIT1,lpStr,3);
  785. if(!_tcslen(lpStr)){
  786. EndDialog(hWnd,TRUE);
  787. break;
  788. }
  789. sscanf(lpStr,"%u",&num);
  790. if(num<1 || num>MAX_PHRASE_LEN){
  791. EndDialog(hWnd,TRUE);
  792. break;
  793. }
  794. if(IsDlgButtonChecked(hWnd,IDC_CHECK1) == BST_CHECKED){
  795. GetDlgItemText(hWnd,IDC_EDIT2,lpStr,2);
  796. sscanf(lpStr,"%u",&codenum);
  797. }
  798. GetSingWordPerLinePinyin(num,codenum);
  799. EndDialog(hWnd,TRUE);
  800. break;
  801. /* case IDC_SOFTKB:
  802. if((hWndyjm=ImmCreateSoftKeyboard(SOFTKEYBOARD_TYPE_C1,hWnd,1,1))!=NULL)
  803. ImmShowSoftKeyboard(hWndyjm, SW_SHOWNOACTIVATE);
  804. else
  805. MessageBoxPrintf("调试中","锁定");
  806. EndDialog(hWnd,TRUE);
  807. break;*/
  808. //
  809. default:
  810. return FALSE;
  811. break;
  812. }
  813. break;
  814. default:
  815. return FALSE;
  816. break;
  817. }
  818. return TRUE;
  819. }
  820. //打开文件用于读入,如果没有文件,则生成一个空文件,并且报警退出。
  821. FILE *YJMOpenFileAndProcess(TCHAR filename[MAX_PATH])
  822. {
  823. TCHAR szFileName[MAX_PATH];
  824. FILE *fp;
  825. Add(CurrentTableDir,filename,szFileName);
  826. if( (fp = _tfopen( szFileName, "r" )) == NULL ){
  827. Add(InstallFromDir,filename,szFileName);
  828. if( (fp = _tfopen( szFileName, "r" )) == NULL ){
  829. MessageBoxPrintf("init","%s can not found",szFileName);
  830. fp = _tfopen( szFileName, "wt" );
  831. fclose(fp);
  832. return NULL;
  833. }
  834. }
  835. return fp;
  836. }
  837. //打开文件用于写入,如果出错则报警退出。
  838. FILE *YJMOpenFileForWrite(TCHAR filename[MAX_PATH])
  839. {
  840. TCHAR szFileName[MAX_PATH];
  841. FILE *fp;
  842. Add(CurrentTableDir,filename,szFileName);
  843. if( (fp = _tfopen( szFileName, "wt" )) == NULL ){
  844. MessageBoxPrintf("init","%s can not found",szFileName);
  845. return NULL;
  846. }
  847. return fp;
  848. }