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.

536 lines
16 KiB

  1. /*************************************************
  2. * addword.c *
  3. * *
  4. * Copyright (C) 1995-1999 Microsoft Inc. *
  5. * *
  6. *************************************************/
  7. #include "windows.h"
  8. #include "winuser.h"
  9. #include "immdev.h"
  10. #include "abc95def.h"
  11. #include "abcw2.h"
  12. #include "resource.h"
  13. BOOL WINAPI ErrExit(HWND hDlg, int err_number);
  14. WORD s_buf[0x1000];
  15. extern struct INPT_BF kbf;
  16. extern HWND hCrtDlg;
  17. OFSTRUCT s_open;
  18. BYTE str[45]={0};
  19. /*******************************************************
  20. write_data(): add the new word defined by the user into
  21. the user.rem
  22. ********************************************************/
  23. BOOL WINAPI write_data(count,temp_bf)
  24. int count;
  25. BYTE *temp_bf;
  26. {
  27. int hd;
  28. int op_count;
  29. hd=OpenFile(user_lib,&s_open,OF_WRITE);
  30. if (hd==-1)
  31. return(ErrExit(NULL,1));
  32. _llseek(hd,(data_start+count*data_record_length),0);
  33. op_count=_lwrite(hd,(LPSTR)temp_bf,data_record_length);
  34. if (op_count!=data_record_length)
  35. {_lclose(hd);
  36. return(ErrExit(NULL,1));
  37. }
  38. _lclose(hd);
  39. return(TRUE);
  40. }
  41. /****************************************************
  42. write_mulu(): write the changed index on the disk
  43. *****************************************************/
  44. BOOL WINAPI write_mulu()
  45. {
  46. int hd;
  47. int op_count;
  48. hd=OpenFile(user_lib,&s_open,OF_WRITE);
  49. if (hd==-1)
  50. return(ErrExit(NULL,1));
  51. op_count=_lwrite(hd,(LPSTR)&s_buf,mulu_true_length);
  52. if (op_count!=mulu_true_length)
  53. {_lclose(hd);
  54. return(ErrExit(NULL,1));
  55. }
  56. _lclose(hd);
  57. return(TRUE);
  58. }
  59. int WINAPI find_empty_item()
  60. {
  61. int i;
  62. BYTE *p;
  63. read_mulu();
  64. p = (BYTE *)&s_buf[8];
  65. i = 0;
  66. while ( i < mulu_true_length )
  67. {
  68. if ( p[i] & 0x80 )
  69. return( i );
  70. i += mulu_record_length;
  71. }
  72. return(-1);
  73. }
  74. //---------------------------------------------------------
  75. // ErrExit()
  76. // for file operating erorrs
  77. //---------------------------------------------------------
  78. BOOL WINAPI ErrExit(hDlg,err_number)
  79. HWND hDlg;
  80. int err_number;
  81. {
  82. MessageBox(hDlg, "�ļ�������",
  83. NULL, MB_OK | MB_ICONHAND);
  84. return(FALSE);
  85. }
  86. /***********************************************************
  87. read_mulu(): read the user definition index from the tmmr.rem
  88. *************************************************************/
  89. BOOL WINAPI read_mulu()
  90. {
  91. int hd;
  92. int op_count;
  93. hd=OpenFile(user_lib,&reopen,OF_READ);
  94. if (hd==-1)
  95. return(ErrExit(NULL,1)); //error
  96. op_count=_lread(hd,&s_buf,16);
  97. if (op_count!=16)
  98. {
  99. _lclose(hd);
  100. return(ErrExit(NULL,1)); //error
  101. }
  102. mulu_true_length=s_buf[3];
  103. op_count=_lread(hd,&s_buf[8],mulu_true_length-16);
  104. if (op_count!=mulu_true_length-16){
  105. _lclose(hd);
  106. return(ErrExit(NULL,1)); //error
  107. }
  108. _lclose(hd);
  109. return(TRUE);
  110. }
  111. /*****************************************************************
  112. listbox(hDlg): list the new word definated by the user.
  113. ******************************************************************/
  114. int WINAPI listbox(hDlg)
  115. HWND hDlg;
  116. {
  117. int i,c;
  118. BYTE *p;
  119. read_mulu();
  120. i=0x10;
  121. while (i<mulu_true_length){
  122. if (!read_data((i-0x10)/mulu_record_length)){
  123. MessageBox(hDlg, "�����ļ���",
  124. NULL, MB_OK | MB_ICONHAND);
  125. break;
  126. }
  127. p=(BYTE *)&s_buf[i/2];
  128. for (c=1; c<10; c++)
  129. out_svw[31+c]=p[c];
  130. out_svw[41]=0;
  131. {
  132. char temp_bf[42];
  133. {
  134. int i;
  135. for (i=0;i<41;i++)
  136. temp_bf[i]=0x20;
  137. //strnset(temp_bf,0x20,41);
  138. }
  139. temp_bf[41]=0;
  140. for (c=0; c<9; c++)
  141. temp_bf[c]=out_svw[32+c];
  142. temp_bf[9]=0x20;
  143. for(c=0; c<30;c++)
  144. temp_bf[c+10]=out_svw[2+c];
  145. if (out_svw[1]!=0x2a) { //1993.4.18 if the string has deleted, don't display it
  146. SendDlgItemMessage(hDlg,ID_LISTBOX,
  147. LB_ADDSTRING, // add these new word
  148. 0, // onto the listbox
  149. (LPARAM)((LPSTR *)temp_bf));
  150. }//if (out_svw)
  151. }
  152. i+=mulu_record_length;
  153. }
  154. return 0;
  155. }
  156. /***************************************************************
  157. if_code_equ(): search if the code in the index
  158. ****************************************************************/
  159. BOOL WINAPI if_code_equ(addr)
  160. int addr;
  161. {
  162. int i;
  163. BYTE *p;
  164. p=(BYTE *)s_buf;
  165. if (kbf.true_length!=(p[addr++]-0x30)) //minuse the 0x30 in order to get the record length
  166. return(STC); //if the length is not equal, exit
  167. for (i=0; i<kbf.true_length; i++){
  168. if ((kbf.buffer[i]!=p[addr])
  169. && ((kbf.buffer[i]&0xdf)!=p[addr]))
  170. return(STC);
  171. addr++;
  172. }
  173. return(CLC); //find the code in the index
  174. }
  175. /**************************************************************
  176. FUNCTION: OpenDlg(HWND,UNSIGNED,WORD,LONG)
  177. PURPOSE: let the user add a new term in the liberty
  178. ***************************************************************/
  179. INT_PTR WINAPI OpenDlg(hDlg, message, wParam, lParam)
  180. HWND hDlg;
  181. UINT message; //##!!unsigned message;
  182. WPARAM wParam; //##!!WORD wParam;
  183. LPARAM lParam;
  184. {
  185. WORD index;
  186. BYTE *p;
  187. //##!!PSTR pTptr;
  188. int i,count;
  189. //##!!HBRUSH OldBrush;
  190. HDC hDC;
  191. RECT Rect;
  192. //##!!RECT Rect1;
  193. int find_empty_flag; /*94.7.30*/
  194. switch (message) {
  195. case WM_COMMAND:
  196. switch (LOWORD(wParam)) {
  197. case ID_LISTBOX:
  198. {
  199. HIMC hIMC;
  200. hIMC = ImmGetContext(hDlg);
  201. ImmSetOpenStatus(hIMC,FALSE);
  202. ImmReleaseContext(hDlg,hIMC);
  203. }
  204. switch (HIWORD(lParam)) {
  205. case LBN_SELCHANGE:
  206. index=(WORD)SendDlgItemMessage(hDlg,ID_LISTBOX,
  207. LB_GETCURSEL,0,0l);
  208. SendDlgItemMessage(hDlg,ID_LISTBOX,
  209. LB_GETTEXT,index,
  210. (LPARAM)(LPSTR *)str);
  211. break;
  212. case LBN_DBLCLK:
  213. break;
  214. }
  215. return (TRUE);
  216. case ID_ADD:
  217. for (i=0; i<sizeof str; i++)
  218. str[i]=0; //1993.4.20 clear the buffer
  219. count = GetDlgItemText(hDlg, ID_NEWCHR, str, 31);
  220. i=0;
  221. while(str[i]==0x20) i++;
  222. if ((i==count)||(!str[0])){
  223. MessageBox(hDlg, "��δ�����´�",
  224. NULL, MB_OK | MB_ICONHAND);
  225. return (TRUE);
  226. }
  227. memmove(&str[2], &str[0], 30);
  228. str[0]=count+0x30; //save the string count
  229. str[1]=0x20;
  230. count+=2;
  231. while (count<user_word_max_length)
  232. str[count++]=0x20;
  233. GetDlgItemText(hDlg, ID_SHU, kbf.buffer, 10);
  234. if (!kbf.buffer[0]){
  235. MessageBox(hDlg, "���������",
  236. NULL, MB_OK | MB_ICONHAND);
  237. return (TRUE);
  238. }
  239. {
  240. int j=0;
  241. while (kbf.buffer[j]>0x20) j++;
  242. i=j;
  243. if(j>0)
  244. for(j=0;j<i; j++)
  245. if (kbf.buffer[j]>0xa0) i=0;
  246. if(!i) {
  247. MessageBox(hDlg, "�������зǷ��ַ�",
  248. NULL, MB_OK | MB_ICONHAND);
  249. return (TRUE);
  250. }
  251. for (j=0;j<i;j++)
  252. str[count+j]=kbf.buffer[j];
  253. }
  254. kbf.true_length=(WORD)i;
  255. read_mulu();
  256. for (i=0x10; i<(mulu_true_length+0x10); i=i+mulu_record_length){
  257. if (if_code_equ(i)){
  258. MessageBox(hDlg, "�����ظ�",
  259. NULL, MB_OK | MB_ICONHAND);
  260. SendDlgItemMessage(hDlg,ID_SHU,
  261. EM_SETSEL,
  262. 0,
  263. MAKELONG(0,0x7fff));
  264. return FALSE;
  265. }
  266. }
  267. mulu_true_length+=mulu_record_length;
  268. if (mulu_true_length>mulu_max_length)
  269. {
  270. find_empty_flag = find_empty_item();
  271. if ( find_empty_flag == -1 )
  272. {
  273. MessageBox(hDlg,"�û���������",
  274. NULL, MB_OK | MB_ICONHAND);
  275. mulu_true_length-=mulu_record_length;
  276. return FALSE;
  277. }
  278. p=(BYTE *)(&s_buf[8]) + find_empty_flag;
  279. count=find_empty_flag/mulu_record_length;
  280. }
  281. else
  282. {
  283. p=(BYTE *)&s_buf[s_buf[3]/2];
  284. count=(mulu_true_length-0x10)/mulu_record_length-1;
  285. }
  286. s_buf[3]=mulu_true_length;
  287. p[0]=kbf.true_length+0x30; /* fill string index length */
  288. for (i=0; i<kbf.true_length; i++)
  289. p[i+1]=kbf.buffer[i]; /* fill string index code */
  290. for (i=i; i<(mulu_record_length-1); i++) /* minuse the p[0] */
  291. p[i+1]=0x20; /* clear the rest part of index */
  292. for (i=0; i<user_word_max_length; i++) /* 32->user_word_max_length */
  293. kbf.buffer[i]=str[i]; /* move the string into writting buffer */
  294. if (write_mulu() == -1)
  295. return FALSE;
  296. if (write_data(count,kbf.buffer) == -1)
  297. return FALSE;
  298. {
  299. char temp_bf[41];
  300. WORD ndx;
  301. for(ndx=0; ndx<41;ndx++)
  302. temp_bf[ndx]=0x20;
  303. strncpy(&temp_bf[0],&p[1],kbf.true_length);
  304. strncpy(&temp_bf[10],&str[2],30);
  305. temp_bf[40]=0;
  306. ndx=(WORD)SendDlgItemMessage(hDlg,ID_LISTBOX, // add these new word
  307. LB_ADDSTRING, // onto the listbox
  308. 0, //1993.4.16 &str[2]->str[1]
  309. (LPARAM)((LPSTR *)&temp_bf[0])); //disp the space for deleting word
  310. SendDlgItemMessage(hDlg,
  311. ID_LISTBOX,
  312. LB_SETCURSEL,
  313. ndx,
  314. 0L);
  315. }
  316. break;
  317. case ID_DEL:
  318. index=(WORD)SendDlgItemMessage(hDlg,ID_LISTBOX,
  319. LB_GETCURSEL,0,0L);
  320. SendDlgItemMessage(hDlg,ID_LISTBOX,
  321. LB_GETTEXT,index,
  322. (LPARAM)(LPSTR *)str);
  323. i=0; //pointer the begining of string code
  324. while (str[i]&&(str[i]!=0x20)){
  325. kbf.buffer[i]=str[i]; //get the string index code
  326. i++;
  327. }
  328. kbf.true_length=(WORD)i; //get code length
  329. read_mulu();
  330. for (i=0x10; i<(mulu_true_length+0x10); i=i+mulu_record_length){
  331. if (if_code_equ(i)){
  332. p=(BYTE *)s_buf;
  333. p[i]|=0x80;
  334. write_mulu();
  335. count=(i-0x10)/mulu_record_length;
  336. if (!read_data(count))
  337. break; //break from the cycle
  338. out_svw[1]=0x2a;
  339. write_data(count,out_svw);
  340. SendDlgItemMessage(hDlg,ID_LISTBOX,
  341. LB_DELETESTRING, // add these new word
  342. index, // onto the listbox
  343. (LPARAM)((LPSTR *)str));
  344. return(TRUE);
  345. }
  346. }
  347. MessageBox(hDlg, "ɾ������ʧ��",
  348. NULL, MB_OK | MB_ICONHAND);
  349. break;
  350. case IDOK:
  351. {
  352. HIMC hIMC;
  353. hIMC = ImmGetContext(hDlg);
  354. ImmSetOpenStatus(hIMC,TRUE);
  355. ImmDestroyContext(hIMC);
  356. ImmReleaseContext(hDlg,hIMC);
  357. }
  358. Return=NULL;
  359. EndDialog(hDlg, TRUE);
  360. return (TRUE);
  361. break;
  362. case IDCANCEL:
  363. Return=NULL;
  364. {
  365. HIMC hIMC;
  366. hIMC = ImmGetContext(hDlg);
  367. ImmSetOpenStatus(hIMC,TRUE);
  368. ImmDestroyContext(hIMC);
  369. ImmReleaseContext(hDlg,hIMC);
  370. }
  371. EndDialog(hDlg, TRUE);
  372. return (TRUE);
  373. case ID_NEWCHR: //1993.4.19
  374. {
  375. HIMC hIMC;
  376. hIMC = ImmGetContext(hDlg);
  377. ImmSetOpenStatus(hIMC,TRUE);
  378. ImmReleaseContext(hDlg,hIMC);
  379. }
  380. break;
  381. case ID_SHU: //1993.4.19
  382. {
  383. HIMC hIMC;
  384. hIMC = ImmGetContext(hDlg);
  385. ImmSetOpenStatus(hIMC,FALSE);
  386. ImmReleaseContext(hDlg,hIMC);
  387. }
  388. break;
  389. }
  390. break;
  391. case WM_INITDIALOG: // message: initialize
  392. hCrtDlg = hDlg;
  393. SendDlgItemMessage(hDlg, // dialog handle
  394. ID_NEWCHR, // where to send message
  395. EM_SETSEL, // select characters
  396. 0, // additional information
  397. MAKELONG(0, 0x7fff)); // entire contents
  398. SetFocus(GetDlgItem(hDlg, ID_NEWCHR));
  399. listbox(hDlg);
  400. CenterWindow(hDlg);
  401. return (0); //##!!(NULL) Indicates the focus is set to a control
  402. case WM_PAINT:
  403. {
  404. PAINTSTRUCT ps;
  405. GetClientRect(hDlg, &Rect); //get the whole window area
  406. InvalidateRect(hDlg, &Rect, 1);
  407. hDC=BeginPaint(hDlg, &ps);
  408. Rect.left+=10;//5;
  409. Rect.top+=8;//5;
  410. Rect.right-=10;//5;
  411. Rect.bottom-=12;//5;
  412. DrawEdge(hDC, &Rect, EDGE_RAISED,/*EDGE_SUNKEN,*/ BF_RECT);
  413. EndPaint(hDlg, &ps);
  414. }
  415. break;
  416. case WM_DESTROY:
  417. {
  418. HIMC hIMC;
  419. hIMC = ImmGetContext(hDlg);
  420. ImmSetOpenStatus(hIMC,TRUE);
  421. ImmDestroyContext(hIMC);
  422. ImmReleaseContext(hDlg,hIMC);
  423. }
  424. return (TRUE);
  425. case WM_QUIT:
  426. case WM_CLOSE:
  427. Return=NULL;
  428. EndDialog(hDlg, TRUE);
  429. return (TRUE);
  430. }
  431. return FALSE;
  432. }