summaryrefslogtreecommitdiffstats
path: root/vi/vim-7.2/7.2.049
blob: 0f6efa87fb41a6e5e949cea0d2efaa1906748e3a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
To: vim-dev@vim.org
Subject: Patch 7.2.049 (extra)
Fcc: outbox
From: Bram Moolenaar <Bram@moolenaar.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
------------

Patch 7.2.049 (extra)
Problem:    Win32: the clipboard doesn't support UTF-16.
Solution:   Change UCS-2 support to UTF-16 support. (Jia Yanwei)
Files:	    src/gui_w32.c, src/gui_w48.c, src/mbyte.c, src/misc1.c,
	    src/os_mswin.c, src/os_win32.c, src/proto/os_mswin.pro


*** ../vim-7.2.048/src/gui_w32.c	Tue Jun 24 23:46:14 2008
--- src/gui_w32.c	Thu Nov 20 16:47:10 2008
***************
*** 992,998 ****
  			    SendMessage(lpdi->hdr.hwndFrom, TTM_SETMAXTIPWIDTH,
  								      0, 500);
  
! 			    tt_text = enc_to_ucs2(str, NULL);
  			    lpdi->lpszText = tt_text;
  			    /* can't show tooltip if failed */
  			}
--- 992,998 ----
  			    SendMessage(lpdi->hdr.hwndFrom, TTM_SETMAXTIPWIDTH,
  								      0, 500);
  
! 			    tt_text = enc_to_utf16(str, NULL);
  			    lpdi->lpszText = tt_text;
  			    /* can't show tooltip if failed */
  			}
***************
*** 1935,1941 ****
      if (buf == NULL)
  	return NULL;
  
!     convbuf = ucs2_to_enc(buf, lenp);
      pImmReleaseContext(hwnd, hIMC);
      vim_free(buf);
      return convbuf;
--- 1935,1941 ----
      if (buf == NULL)
  	return NULL;
  
!     convbuf = utf16_to_enc(buf, lenp);
      pImmReleaseContext(hwnd, hIMC);
      vim_free(buf);
      return convbuf;
***************
*** 2566,2572 ****
  	    {
  		/* 'encoding' differs from active codepage: convert menu name
  		 * and use wide function */
! 		wn = enc_to_ucs2(menu->name, NULL);
  		if (wn != NULL)
  		{
  		    MENUITEMINFOW	infow;
--- 2566,2572 ----
  	    {
  		/* 'encoding' differs from active codepage: convert menu name
  		 * and use wide function */
! 		wn = enc_to_utf16(menu->name, NULL);
  		if (wn != NULL)
  		{
  		    MENUITEMINFOW	infow;
***************
*** 2728,2734 ****
  	{
  	    /* 'encoding' differs from active codepage: convert menu item name
  	     * and use wide function */
! 	    wn = enc_to_ucs2(menu->name, NULL);
  	    if (wn != NULL)
  	    {
  		n = InsertMenuW(parent->submenu_id, (UINT)idx,
--- 2728,2734 ----
  	{
  	    /* 'encoding' differs from active codepage: convert menu item name
  	     * and use wide function */
! 	    wn = enc_to_utf16(menu->name, NULL);
  	    if (wn != NULL)
  	    {
  		n = InsertMenuW(parent->submenu_id, (UINT)idx,
***************
*** 3570,3576 ****
      if (enc_codepage == 0 && (int)GetACP() != enc_codepage)
      {
  	/* Not a codepage, use our own conversion function. */
! 	wn = enc_to_ucs2(lpAnsiIn, NULL);
  	if (wn != NULL)
  	{
  	    wcscpy(lpWCStr, wn);
--- 3570,3576 ----
      if (enc_codepage == 0 && (int)GetACP() != enc_codepage)
      {
  	/* Not a codepage, use our own conversion function. */
! 	wn = enc_to_utf16(lpAnsiIn, NULL);
  	if (wn != NULL)
  	{
  	    wcscpy(lpWCStr, wn);
*** ../vim-7.2.048/src/gui_w48.c	Wed Nov 12 13:35:31 2008
--- src/gui_w48.c	Thu Nov 20 16:42:32 2008
***************
*** 547,553 ****
  	else
  	{
  	    len = 1;
! 	    ws = ucs2_to_enc(wstring, &len);
  	    if (ws == NULL)
  		len = 0;
  	    else
--- 547,553 ----
  	else
  	{
  	    len = 1;
! 	    ws = utf16_to_enc(wstring, &len);
  	    if (ws == NULL)
  		len = 0;
  	    else
***************
*** 2128,2134 ****
      {
  	/* 'encoding' differs from active codepage: convert text and use wide
  	 * function */
! 	wstr = enc_to_ucs2(str, &wlen);
  	if (wstr != NULL)
  	{
  	    n = GetTextExtentPointW(hdc, wstr, wlen, &size);
--- 2128,2134 ----
      {
  	/* 'encoding' differs from active codepage: convert text and use wide
  	 * function */
! 	wstr = enc_to_utf16(str, &wlen);
  	if (wstr != NULL)
  	{
  	    n = GetTextExtentPointW(hdc, wstr, wlen, &size);
***************
*** 2252,2258 ****
      {
  	/* 'encoding' differs from active codepage: convert menu name
  	 * and use wide function */
! 	wn = enc_to_ucs2(item_text, NULL);
  	if (wn != NULL)
  	{
  	    MENUITEMINFOW	infow;
--- 2252,2258 ----
      {
  	/* 'encoding' differs from active codepage: convert menu name
  	 * and use wide function */
! 	wn = enc_to_utf16(item_text, NULL);
  	if (wn != NULL)
  	{
  	    MENUITEMINFOW	infow;
***************
*** 2422,2428 ****
  	if (use_unicode)
  	{
  	    /* Need to go through Unicode. */
! 	    wstr = enc_to_ucs2(NameBuff, NULL);
  	    if (wstr != NULL)
  	    {
  		TCITEMW		tiw;
--- 2422,2428 ----
  	if (use_unicode)
  	{
  	    /* Need to go through Unicode. */
! 	    wstr = enc_to_utf16(NameBuff, NULL);
  	    if (wstr != NULL)
  	    {
  		TCITEMW		tiw;
***************
*** 2521,2528 ****
  	WCHAR	*wbuf;
  	int	n;
  
! 	/* Convert the title from 'encoding' to ucs2. */
! 	wbuf = (WCHAR *)enc_to_ucs2((char_u *)title, NULL);
  	if (wbuf != NULL)
  	{
  	    n = SetWindowTextW(hwnd, wbuf);
--- 2521,2528 ----
  	WCHAR	*wbuf;
  	int	n;
  
! 	/* Convert the title from 'encoding' to UTF-16. */
! 	wbuf = (WCHAR *)enc_to_utf16((char_u *)title, NULL);
  	if (wbuf != NULL)
  	{
  	    n = SetWindowTextW(hwnd, wbuf);
***************
*** 3222,3228 ****
  	char_u *initdir,
  	char_u *filter)
  {
!     /* We always use the wide function.  This means enc_to_ucs2() must work,
       * otherwise it fails miserably! */
      OPENFILENAMEW	fileStruct;
      WCHAR		fileBuf[MAXPATHL];
--- 3222,3228 ----
  	char_u *initdir,
  	char_u *filter)
  {
!     /* We always use the wide function.  This means enc_to_utf16() must work,
       * otherwise it fails miserably! */
      OPENFILENAMEW	fileStruct;
      WCHAR		fileBuf[MAXPATHL];
***************
*** 3238,3244 ****
  	fileBuf[0] = NUL;
      else
      {
! 	wp = enc_to_ucs2(dflt, NULL);
  	if (wp == NULL)
  	    fileBuf[0] = NUL;
  	else
--- 3238,3244 ----
  	fileBuf[0] = NUL;
      else
      {
! 	wp = enc_to_utf16(dflt, NULL);
  	if (wp == NULL)
  	    fileBuf[0] = NUL;
  	else
***************
*** 3263,3273 ****
  #endif
  
      if (title != NULL)
! 	titlep = enc_to_ucs2(title, NULL);
      fileStruct.lpstrTitle = titlep;
  
      if (ext != NULL)
! 	extp = enc_to_ucs2(ext, NULL);
      fileStruct.lpstrDefExt = extp;
  
      fileStruct.lpstrFile = fileBuf;
--- 3263,3273 ----
  #endif
  
      if (title != NULL)
! 	titlep = enc_to_utf16(title, NULL);
      fileStruct.lpstrTitle = titlep;
  
      if (ext != NULL)
! 	extp = enc_to_utf16(ext, NULL);
      fileStruct.lpstrDefExt = extp;
  
      fileStruct.lpstrFile = fileBuf;
***************
*** 3278,3284 ****
      if (initdir != NULL && *initdir != NUL)
      {
  	/* Must have backslashes here, no matter what 'shellslash' says */
! 	initdirp = enc_to_ucs2(initdir, NULL);
  	if (initdirp != NULL)
  	{
  	    for (wp = initdirp; *wp != NUL; ++wp)
--- 3278,3284 ----
      if (initdir != NULL && *initdir != NUL)
      {
  	/* Must have backslashes here, no matter what 'shellslash' says */
! 	initdirp = enc_to_utf16(initdir, NULL);
  	if (initdirp != NULL)
  	{
  	    for (wp = initdirp; *wp != NUL; ++wp)
***************
*** 3318,3324 ****
      vim_free(extp);
  
      /* Convert from UCS2 to 'encoding'. */
!     p = ucs2_to_enc(fileBuf, NULL);
      if (p != NULL)
  	/* when out of memory we get garbage for non-ASCII chars */
  	STRCPY(fileBuf, p);
--- 3318,3324 ----
      vim_free(extp);
  
      /* Convert from UCS2 to 'encoding'. */
!     p = utf16_to_enc(fileBuf, NULL);
      if (p != NULL)
  	/* when out of memory we get garbage for non-ASCII chars */
  	STRCPY(fileBuf, p);
***************
*** 3518,3524 ****
  	{
  #ifdef FEAT_MBYTE
  	    if (DragQueryFileW(hDrop, i, wszFile, BUFPATHLEN) > 0)
! 		fnames[i] = ucs2_to_enc(wszFile, NULL);
  	    else
  #endif
  	    {
--- 3518,3524 ----
  	{
  #ifdef FEAT_MBYTE
  	    if (DragQueryFileW(hDrop, i, wszFile, BUFPATHLEN) > 0)
! 		fnames[i] = utf16_to_enc(wszFile, NULL);
  	    else
  #endif
  	    {
*** ../vim-7.2.048/src/mbyte.c	Thu Nov 20 11:55:53 2008
--- src/mbyte.c	Thu Nov 20 16:47:41 2008
***************
*** 6101,6107 ****
  
  	    /* 1. codepage/UTF-8  ->  ucs-2. */
  	    if (vcp->vc_cpfrom == 0)
! 		tmp_len = utf8_to_ucs2(ptr, len, NULL, NULL);
  	    else
  		tmp_len = MultiByteToWideChar(vcp->vc_cpfrom, 0,
  							      ptr, len, 0, 0);
--- 6101,6107 ----
  
  	    /* 1. codepage/UTF-8  ->  ucs-2. */
  	    if (vcp->vc_cpfrom == 0)
! 		tmp_len = utf8_to_utf16(ptr, len, NULL, NULL);
  	    else
  		tmp_len = MultiByteToWideChar(vcp->vc_cpfrom, 0,
  							      ptr, len, 0, 0);
***************
*** 6109,6121 ****
  	    if (tmp == NULL)
  		break;
  	    if (vcp->vc_cpfrom == 0)
! 		utf8_to_ucs2(ptr, len, tmp, unconvlenp);
  	    else
  		MultiByteToWideChar(vcp->vc_cpfrom, 0, ptr, len, tmp, tmp_len);
  
  	    /* 2. ucs-2  ->  codepage/UTF-8. */
  	    if (vcp->vc_cpto == 0)
! 		retlen = ucs2_to_utf8(tmp, tmp_len, NULL);
  	    else
  		retlen = WideCharToMultiByte(vcp->vc_cpto, 0,
  						    tmp, tmp_len, 0, 0, 0, 0);
--- 6109,6121 ----
  	    if (tmp == NULL)
  		break;
  	    if (vcp->vc_cpfrom == 0)
! 		utf8_to_utf16(ptr, len, tmp, unconvlenp);
  	    else
  		MultiByteToWideChar(vcp->vc_cpfrom, 0, ptr, len, tmp, tmp_len);
  
  	    /* 2. ucs-2  ->  codepage/UTF-8. */
  	    if (vcp->vc_cpto == 0)
! 		retlen = utf16_to_utf8(tmp, tmp_len, NULL);
  	    else
  		retlen = WideCharToMultiByte(vcp->vc_cpto, 0,
  						    tmp, tmp_len, 0, 0, 0, 0);
***************
*** 6123,6129 ****
  	    if (retval != NULL)
  	    {
  		if (vcp->vc_cpto == 0)
! 		    ucs2_to_utf8(tmp, tmp_len, retval);
  		else
  		    WideCharToMultiByte(vcp->vc_cpto, 0,
  					  tmp, tmp_len, retval, retlen, 0, 0);
--- 6123,6129 ----
  	    if (retval != NULL)
  	    {
  		if (vcp->vc_cpto == 0)
! 		    utf16_to_utf8(tmp, tmp_len, retval);
  		else
  		    WideCharToMultiByte(vcp->vc_cpto, 0,
  					  tmp, tmp_len, retval, retlen, 0, 0);
*** ../vim-7.2.048/src/misc1.c	Sun Nov  9 13:43:25 2008
--- src/misc1.c	Thu Nov 20 16:42:59 2008
***************
*** 8728,8734 ****
  	/* The active codepage differs from 'encoding'.  Attempt using the
  	 * wide function.  If it fails because it is not implemented fall back
  	 * to the non-wide version (for Windows 98) */
! 	wn = enc_to_ucs2(buf, NULL);
  	if (wn != NULL)
  	{
  	    hFind = FindFirstFileW(wn, &wfb);
--- 8728,8734 ----
  	/* The active codepage differs from 'encoding'.  Attempt using the
  	 * wide function.  If it fails because it is not implemented fall back
  	 * to the non-wide version (for Windows 98) */
! 	wn = enc_to_utf16(buf, NULL);
  	if (wn != NULL)
  	{
  	    hFind = FindFirstFileW(wn, &wfb);
***************
*** 8756,8762 ****
  #ifdef WIN3264
  # ifdef FEAT_MBYTE
  	if (wn != NULL)
! 	    p = ucs2_to_enc(wfb.cFileName, NULL);   /* p is allocated here */
  	else
  # endif
  	    p = (char_u *)fb.cFileName;
--- 8756,8762 ----
  #ifdef WIN3264
  # ifdef FEAT_MBYTE
  	if (wn != NULL)
! 	    p = utf16_to_enc(wfb.cFileName, NULL);   /* p is allocated here */
  	else
  # endif
  	    p = (char_u *)fb.cFileName;
***************
*** 8830,8836 ****
  	    if (wn != NULL)
  	    {
  		vim_free(wn);
! 		wn = enc_to_ucs2(buf, NULL);
  		if (wn != NULL)
  		    hFind = FindFirstFileW(wn, &wfb);
  	    }
--- 8830,8836 ----
  	    if (wn != NULL)
  	    {
  		vim_free(wn);
! 		wn = enc_to_utf16(buf, NULL);
  		if (wn != NULL)
  		    hFind = FindFirstFileW(wn, &wfb);
  	    }
*** ../vim-7.2.048/src/os_mswin.c	Sat Aug  9 19:37:30 2008
--- src/os_mswin.c	Thu Nov 20 17:05:10 2008
***************
*** 309,315 ****
  	if (enc_codepage >= 0 && (int)GetACP() != enc_codepage)
  	{
  	    /* Convert the title from 'encoding' to the active codepage. */
! 	    WCHAR	*wp = enc_to_ucs2(title, NULL);
  	    int	n;
  
  	    if (wp != NULL)
--- 309,315 ----
  	if (enc_codepage >= 0 && (int)GetACP() != enc_codepage)
  	{
  	    /* Convert the title from 'encoding' to the active codepage. */
! 	    WCHAR	*wp = enc_to_utf16(title, NULL);
  	    int	n;
  
  	    if (wp != NULL)
***************
*** 406,415 ****
  	     * - invoke _wfullpath()
  	     * - convert the result from UCS2 to 'encoding'.
  	     */
! 	    wname = enc_to_ucs2(fname, NULL);
  	    if (wname != NULL && _wfullpath(wbuf, wname, MAX_PATH - 1) != NULL)
  	    {
! 		cname = ucs2_to_enc((short_u *)wbuf, NULL);
  		if (cname != NULL)
  		{
  		    vim_strncpy(buf, cname, len - 1);
--- 406,415 ----
  	     * - invoke _wfullpath()
  	     * - convert the result from UCS2 to 'encoding'.
  	     */
! 	    wname = enc_to_utf16(fname, NULL);
  	    if (wname != NULL && _wfullpath(wbuf, wname, MAX_PATH - 1) != NULL)
  	    {
! 		cname = utf16_to_enc((short_u *)wbuf, NULL);
  		if (cname != NULL)
  		{
  		    vim_strncpy(buf, cname, len - 1);
***************
*** 507,513 ****
  # endif
         )
      {
! 	WCHAR	*wp = enc_to_ucs2(buf, NULL);
  	int	n;
  
  	if (wp != NULL)
--- 507,513 ----
  # endif
         )
      {
! 	WCHAR	*wp = enc_to_utf16(buf, NULL);
  	int	n;
  
  	if (wp != NULL)
***************
*** 668,674 ****
  #ifdef FEAT_MBYTE
      if (enc_codepage >= 0 && (int)GetACP() != enc_codepage)
      {
! 	WCHAR	*p = enc_to_ucs2(path, NULL);
  	int	n;
  
  	if (p != NULL)
--- 668,674 ----
  #ifdef FEAT_MBYTE
      if (enc_codepage >= 0 && (int)GetACP() != enc_codepage)
      {
! 	WCHAR	*p = enc_to_utf16(path, NULL);
  	int	n;
  
  	if (p != NULL)
***************
*** 891,909 ****
  
  #if defined(FEAT_MBYTE) || defined(PROTO)
  /*
!  * Convert an UTF-8 string to UCS-2.
   * "instr[inlen]" is the input.  "inlen" is in bytes.
!  * When "outstr" is NULL only return the number of UCS-2 words produced.
   * Otherwise "outstr" must be a buffer of sufficient size.
!  * Returns the number of UCS-2 words produced.
   */
      int
! utf8_to_ucs2(char_u *instr, int inlen, short_u *outstr, int *unconvlenp)
  {
      int		outlen = 0;
      char_u	*p = instr;
      int		todo = inlen;
      int		l;
  
      while (todo > 0)
      {
--- 891,910 ----
  
  #if defined(FEAT_MBYTE) || defined(PROTO)
  /*
!  * Convert an UTF-8 string to UTF-16.
   * "instr[inlen]" is the input.  "inlen" is in bytes.
!  * When "outstr" is NULL only return the number of UTF-16 words produced.
   * Otherwise "outstr" must be a buffer of sufficient size.
!  * Returns the number of UTF-16 words produced.
   */
      int
! utf8_to_utf16(char_u *instr, int inlen, short_u *outstr, int *unconvlenp)
  {
      int		outlen = 0;
      char_u	*p = instr;
      int		todo = inlen;
      int		l;
+     int		ch;
  
      while (todo > 0)
      {
***************
*** 917,924 ****
  	    break;
  	}
  
! 	if (outstr != NULL)
! 	    *outstr++ = utf_ptr2char(p);
  	++outlen;
  	p += l;
  	todo -= l;
--- 918,936 ----
  	    break;
  	}
  
! 	ch = utf_ptr2char(p);
! 	if (ch >= 0x10000)
! 	{
! 	    /* non-BMP character, encoding with surrogate pairs */
! 	    ++outlen;
! 	    if (outstr != NULL)
! 	    {
! 		*outstr++ = (0xD800 - (0x10000 >> 10)) + (ch >> 10);
! 		*outstr++ = 0xDC00 | (ch & 0x3FF);
! 	    }
! 	}
! 	else if (outstr != NULL)
! 	    *outstr++ = ch;
  	++outlen;
  	p += l;
  	todo -= l;
***************
*** 928,956 ****
  }
  
  /*
!  * Convert an UCS-2 string to UTF-8.
!  * The input is "instr[inlen]" with "inlen" in number of ucs-2 words.
   * When "outstr" is NULL only return the required number of bytes.
   * Otherwise "outstr" must be a buffer of sufficient size.
   * Return the number of bytes produced.
   */
      int
! ucs2_to_utf8(short_u *instr, int inlen, char_u *outstr)
  {
      int		outlen = 0;
      int		todo = inlen;
      short_u	*p = instr;
      int		l;
  
      while (todo > 0)
      {
  	if (outstr != NULL)
  	{
! 	    l = utf_char2bytes(*p, outstr);
  	    outstr += l;
  	}
  	else
! 	    l = utf_char2len(*p);
  	++p;
  	outlen += l;
  	--todo;
--- 940,981 ----
  }
  
  /*
!  * Convert an UTF-16 string to UTF-8.
!  * The input is "instr[inlen]" with "inlen" in number of UTF-16 words.
   * When "outstr" is NULL only return the required number of bytes.
   * Otherwise "outstr" must be a buffer of sufficient size.
   * Return the number of bytes produced.
   */
      int
! utf16_to_utf8(short_u *instr, int inlen, char_u *outstr)
  {
      int		outlen = 0;
      int		todo = inlen;
      short_u	*p = instr;
      int		l;
+     int		ch, ch2;
  
      while (todo > 0)
      {
+ 	ch = *p;
+ 	if (ch >= 0xD800 && ch <= 0xDBFF && todo > 1)
+ 	{
+ 	    /* surrogate pairs handling */
+ 	    ch2 = p[1];
+ 	    if (ch2 >= 0xDC00 && ch2 <= 0xDFFF)
+ 	    {
+ 		ch = ((ch - 0xD800) << 10) + (ch2 & 0x3FF) + 0x10000;
+ 		++p;
+ 		--todo;
+ 	    }
+ 	}
  	if (outstr != NULL)
  	{
! 	    l = utf_char2bytes(ch, outstr);
  	    outstr += l;
  	}
  	else
! 	    l = utf_char2len(ch);
  	++p;
  	outlen += l;
  	--todo;
***************
*** 1079,1092 ****
   */
  
  /*
!  * Convert "str" from 'encoding' to UCS-2.
   * Input in "str" with length "*lenp".  When "lenp" is NULL, use strlen().
   * Output is returned as an allocated string.  "*lenp" is set to the length of
   * the result.  A trailing NUL is always added.
   * Returns NULL when out of memory.
   */
      short_u *
! enc_to_ucs2(char_u *str, int *lenp)
  {
      vimconv_T	conv;
      WCHAR	*ret;
--- 1104,1117 ----
   */
  
  /*
!  * Convert "str" from 'encoding' to UTF-16.
   * Input in "str" with length "*lenp".  When "lenp" is NULL, use strlen().
   * Output is returned as an allocated string.  "*lenp" is set to the length of
   * the result.  A trailing NUL is always added.
   * Returns NULL when out of memory.
   */
      short_u *
! enc_to_utf16(char_u *str, int *lenp)
  {
      vimconv_T	conv;
      WCHAR	*ret;
***************
*** 1102,1108 ****
  
      if (enc_codepage > 0)
      {
! 	/* We can do any CP### -> UCS-2 in one pass, and we can do it
  	 * without iconv() (convert_* may need iconv). */
  	MultiByteToWideChar_alloc(enc_codepage, 0, str, *lenp, &ret, &length);
      }
--- 1127,1133 ----
  
      if (enc_codepage > 0)
      {
! 	/* We can do any CP### -> UTF-16 in one pass, and we can do it
  	 * without iconv() (convert_* may need iconv). */
  	MultiByteToWideChar_alloc(enc_codepage, 0, str, *lenp, &ret, &length);
      }
***************
*** 1123,1133 ****
  	}
  	convert_setup(&conv, NULL, NULL);
  
! 	length = utf8_to_ucs2(str, *lenp, NULL, NULL);
  	ret = (WCHAR *)alloc((unsigned)((length + 1) * sizeof(WCHAR)));
  	if (ret != NULL)
  	{
! 	    utf8_to_ucs2(str, *lenp, (short_u *)ret, NULL);
  	    ret[length] = 0;
  	}
  
--- 1148,1158 ----
  	}
  	convert_setup(&conv, NULL, NULL);
  
! 	length = utf8_to_utf16(str, *lenp, NULL, NULL);
  	ret = (WCHAR *)alloc((unsigned)((length + 1) * sizeof(WCHAR)));
  	if (ret != NULL)
  	{
! 	    utf8_to_utf16(str, *lenp, (short_u *)ret, NULL);
  	    ret[length] = 0;
  	}
  
***************
*** 1139,1145 ****
  }
  
  /*
!  * Convert an UCS-2 string to 'encoding'.
   * Input in "str" with length (counted in wide characters) "*lenp".  When
   * "lenp" is NULL, use wcslen().
   * Output is returned as an allocated string.  If "*lenp" is not NULL it is
--- 1164,1170 ----
  }
  
  /*
!  * Convert an UTF-16 string to 'encoding'.
   * Input in "str" with length (counted in wide characters) "*lenp".  When
   * "lenp" is NULL, use wcslen().
   * Output is returned as an allocated string.  If "*lenp" is not NULL it is
***************
*** 1147,1153 ****
   * Returns NULL when out of memory.
   */
      char_u *
! ucs2_to_enc(short_u *str, int *lenp)
  {
      vimconv_T	conv;
      char_u	*utf8_str = NULL, *enc_str = NULL;
--- 1172,1178 ----
   * Returns NULL when out of memory.
   */
      char_u *
! utf16_to_enc(short_u *str, int *lenp)
  {
      vimconv_T	conv;
      char_u	*utf8_str = NULL, *enc_str = NULL;
***************
*** 1161,1167 ****
  
      if (enc_codepage > 0)
      {
! 	/* We can do any UCS-2 -> CP### in one pass. */
  	int length;
  
  	WideCharToMultiByte_alloc(enc_codepage, 0, str, *lenp,
--- 1186,1192 ----
  
      if (enc_codepage > 0)
      {
! 	/* We can do any UTF-16 -> CP### in one pass. */
  	int length;
  
  	WideCharToMultiByte_alloc(enc_codepage, 0, str, *lenp,
***************
*** 1171,1180 ****
      }
  
      /* Avoid allocating zero bytes, it generates an error message. */
!     utf8_str = alloc(ucs2_to_utf8(str, *lenp == 0 ? 1 : *lenp, NULL));
      if (utf8_str != NULL)
      {
! 	*lenp = ucs2_to_utf8(str, *lenp, utf8_str);
  
  	/* We might be called before we have p_enc set up. */
  	conv.vc_type = CONV_NONE;
--- 1196,1205 ----
      }
  
      /* Avoid allocating zero bytes, it generates an error message. */
!     utf8_str = alloc(utf16_to_utf8(str, *lenp == 0 ? 1 : *lenp, NULL));
      if (utf8_str != NULL)
      {
! 	*lenp = utf16_to_utf8(str, *lenp, utf8_str);
  
  	/* We might be called before we have p_enc set up. */
  	conv.vc_type = CONV_NONE;
***************
*** 1308,1314 ****
  		    if (hMemWstr[str_size] == NUL)
  			break;
  	    }
! 	    to_free = str = ucs2_to_enc((short_u *)hMemWstr, &str_size);
  	    GlobalUnlock(hMemW);
  	}
      }
--- 1333,1339 ----
  		    if (hMemWstr[str_size] == NUL)
  			break;
  	    }
! 	    to_free = str = utf16_to_enc((short_u *)hMemWstr, &str_size);
  	    GlobalUnlock(hMemW);
  	}
      }
***************
*** 1340,1346 ****
  
  # if defined(FEAT_MBYTE) && defined(WIN3264)
  	    /* The text is in the active codepage.  Convert to 'encoding',
! 	     * going through UCS-2. */
  	    acp_to_enc(str, str_size, &to_free, &maxlen);
  	    if (to_free != NULL)
  	    {
--- 1365,1371 ----
  
  # if defined(FEAT_MBYTE) && defined(WIN3264)
  	    /* The text is in the active codepage.  Convert to 'encoding',
! 	     * going through UTF-16. */
  	    acp_to_enc(str, str_size, &to_free, &maxlen);
  	    if (to_free != NULL)
  	    {
***************
*** 1404,1410 ****
      if (widestr != NULL)
      {
  	++*outlen;	/* Include the 0 after the string */
! 	*out = ucs2_to_enc((short_u *)widestr, outlen);
  	vim_free(widestr);
      }
  }
--- 1429,1435 ----
      if (widestr != NULL)
      {
  	++*outlen;	/* Include the 0 after the string */
! 	*out = utf16_to_enc((short_u *)widestr, outlen);
  	vim_free(widestr);
      }
  }
***************
*** 1466,1474 ****
  	WCHAR		*out;
  	int		len = metadata.txtlen;
  
! 	/* Convert the text to UCS-2. This is put on the clipboard as
  	 * CF_UNICODETEXT. */
! 	out = (WCHAR *)enc_to_ucs2(str, &len);
  	if (out != NULL)
  	{
  	    WCHAR *lpszMemW;
--- 1491,1499 ----
  	WCHAR		*out;
  	int		len = metadata.txtlen;
  
! 	/* Convert the text to UTF-16. This is put on the clipboard as
  	 * CF_UNICODETEXT. */
! 	out = (WCHAR *)enc_to_utf16(str, &len);
  	if (out != NULL)
  	{
  	    WCHAR *lpszMemW;
***************
*** 1488,1494 ****
  	    WideCharToMultiByte(GetACP(), 0, out, len,
  						  str, metadata.txtlen, 0, 0);
  
! 	    /* Allocate memory for the UCS-2 text, add one NUL word to
  	     * terminate the string. */
  	    hMemW = (LPSTR)GlobalAlloc(GMEM_MOVEABLE | GMEM_DDESHARE,
  						   (len + 1) * sizeof(WCHAR));
--- 1513,1519 ----
  	    WideCharToMultiByte(GetACP(), 0, out, len,
  						  str, metadata.txtlen, 0, 0);
  
! 	    /* Allocate memory for the UTF-16 text, add one NUL word to
  	     * terminate the string. */
  	    hMemW = (LPSTR)GlobalAlloc(GMEM_MOVEABLE | GMEM_DDESHARE,
  						   (len + 1) * sizeof(WCHAR));
*** ../vim-7.2.048/src/os_win32.c	Thu Jul 24 20:50:30 2008
--- src/os_win32.c	Thu Nov 20 16:44:33 2008
***************
*** 1587,1593 ****
  #ifdef FEAT_MBYTE
      if (enc_codepage >= 0 && (int)GetACP() != enc_codepage)
      {
! 	WCHAR	*p = enc_to_ucs2(name, NULL);
  	WCHAR	fnamew[_MAX_PATH];
  	WCHAR	*dumw;
  	long	n;
--- 1587,1593 ----
  #ifdef FEAT_MBYTE
      if (enc_codepage >= 0 && (int)GetACP() != enc_codepage)
      {
! 	WCHAR	*p = enc_to_utf16(name, NULL);
  	WCHAR	fnamew[_MAX_PATH];
  	WCHAR	*dumw;
  	long	n;
***************
*** 2440,2446 ****
  
  	if (GetCurrentDirectoryW(_MAX_PATH, wbuf) != 0)
  	{
! 	    char_u  *p = ucs2_to_enc(wbuf, NULL);
  
  	    if (p != NULL)
  	    {
--- 2440,2446 ----
  
  	if (GetCurrentDirectoryW(_MAX_PATH, wbuf) != 0)
  	{
! 	    char_u  *p = utf16_to_enc(wbuf, NULL);
  
  	    if (p != NULL)
  	    {
***************
*** 2466,2472 ****
  #ifdef FEAT_MBYTE
      if (enc_codepage >= 0 && (int)GetACP() != enc_codepage)
      {
! 	WCHAR	*p = enc_to_ucs2(name, NULL);
  	long	n;
  
  	if (p != NULL)
--- 2466,2472 ----
  #ifdef FEAT_MBYTE
      if (enc_codepage >= 0 && (int)GetACP() != enc_codepage)
      {
! 	WCHAR	*p = enc_to_utf16(name, NULL);
  	long	n;
  
  	if (p != NULL)
***************
*** 2495,2501 ****
  #ifdef FEAT_MBYTE
      if (enc_codepage >= 0 && (int)GetACP() != enc_codepage)
      {
! 	WCHAR	*p = enc_to_ucs2(name, NULL);
  	long	n;
  
  	if (p != NULL)
--- 2495,2501 ----
  #ifdef FEAT_MBYTE
      if (enc_codepage >= 0 && (int)GetACP() != enc_codepage)
      {
! 	WCHAR	*p = enc_to_utf16(name, NULL);
  	long	n;
  
  	if (p != NULL)
***************
*** 2522,2528 ****
      WCHAR	*p = NULL;
  
      if (enc_codepage >= 0 && (int)GetACP() != enc_codepage)
! 	p = enc_to_ucs2(name, NULL);
  #endif
  
  #ifdef FEAT_MBYTE
--- 2522,2528 ----
      WCHAR	*p = NULL;
  
      if (enc_codepage >= 0 && (int)GetACP() != enc_codepage)
! 	p = enc_to_utf16(name, NULL);
  #endif
  
  #ifdef FEAT_MBYTE
***************
*** 2590,2596 ****
      WCHAR	*wn = NULL;
  
      if (enc_codepage >= 0 && (int)GetACP() != enc_codepage)
! 	wn = enc_to_ucs2(fname, NULL);
      if (wn != NULL)
      {
  	hFile = CreateFileW(wn,		/* file name */
--- 2590,2596 ----
      WCHAR	*wn = NULL;
  
      if (enc_codepage >= 0 && (int)GetACP() != enc_codepage)
! 	wn = enc_to_utf16(fname, NULL);
      if (wn != NULL)
      {
  	hFile = CreateFileW(wn,		/* file name */
***************
*** 4239,4245 ****
  
      if (enc_codepage >= 0 && (int)GetACP() != enc_codepage)
      {
! 	wn = enc_to_ucs2(name, NULL);
  	if (wn != NULL)
  	{
  	    SetFileAttributesW(wn, FILE_ATTRIBUTE_NORMAL);
--- 4239,4245 ----
  
      if (enc_codepage >= 0 && (int)GetACP() != enc_codepage)
      {
! 	wn = enc_to_utf16(name, NULL);
  	if (wn != NULL)
  	{
  	    SetFileAttributesW(wn, FILE_ATTRIBUTE_NORMAL);
***************
*** 4382,4389 ****
  
      if (enc_codepage >= 0 && (int)GetACP() != enc_codepage)
      {
! 	wold = enc_to_ucs2((char_u *)pszOldFile, NULL);
! 	wnew = enc_to_ucs2((char_u *)pszNewFile, NULL);
  	if (wold != NULL && wnew != NULL)
  	    retval = mch_wrename(wold, wnew);
  	vim_free(wold);
--- 4382,4389 ----
  
      if (enc_codepage >= 0 && (int)GetACP() != enc_codepage)
      {
! 	wold = enc_to_utf16((char_u *)pszOldFile, NULL);
! 	wnew = enc_to_utf16((char_u *)pszNewFile, NULL);
  	if (wold != NULL && wnew != NULL)
  	    retval = mch_wrename(wold, wnew);
  	vim_free(wold);
***************
*** 4492,4498 ****
      WCHAR	*wn = NULL;
  
      if (enc_codepage >= 0 && (int)GetACP() != enc_codepage)
! 	wn = enc_to_ucs2(n, NULL);
  #endif
  
      if (mch_isdir(n))
--- 4492,4498 ----
      WCHAR	*wn = NULL;
  
      if (enc_codepage >= 0 && (int)GetACP() != enc_codepage)
! 	wn = enc_to_utf16(n, NULL);
  #endif
  
      if (mch_isdir(n))
***************
*** 4618,4624 ****
  
  #if defined(FEAT_MBYTE) || defined(PROTO)
  /*
!  * Version of open() that may use ucs2 file name.
   */
      int
  mch_open(char *name, int flags, int mode)
--- 4618,4624 ----
  
  #if defined(FEAT_MBYTE) || defined(PROTO)
  /*
!  * Version of open() that may use UTF-16 file name.
   */
      int
  mch_open(char *name, int flags, int mode)
***************
*** 4630,4636 ****
  
      if (enc_codepage >= 0 && (int)GetACP() != enc_codepage)
      {
! 	wn = enc_to_ucs2(name, NULL);
  	if (wn != NULL)
  	{
  	    f = _wopen(wn, flags, mode);
--- 4630,4636 ----
  
      if (enc_codepage >= 0 && (int)GetACP() != enc_codepage)
      {
! 	wn = enc_to_utf16(name, NULL);
  	if (wn != NULL)
  	{
  	    f = _wopen(wn, flags, mode);
***************
*** 4648,4654 ****
  }
  
  /*
!  * Version of fopen() that may use ucs2 file name.
   */
      FILE *
  mch_fopen(char *name, char *mode)
--- 4648,4654 ----
  }
  
  /*
!  * Version of fopen() that may use UTF-16 file name.
   */
      FILE *
  mch_fopen(char *name, char *mode)
***************
*** 4675,4682 ****
  	else if (newMode == 'b')
  	    _set_fmode(_O_BINARY);
  # endif
! 	wn = enc_to_ucs2(name, NULL);
! 	wm = enc_to_ucs2(mode, NULL);
  	if (wn != NULL && wm != NULL)
  	    f = _wfopen(wn, wm);
  	vim_free(wn);
--- 4675,4682 ----
  	else if (newMode == 'b')
  	    _set_fmode(_O_BINARY);
  # endif
! 	wn = enc_to_utf16(name, NULL);
! 	wm = enc_to_utf16(mode, NULL);
  	if (wn != NULL && wm != NULL)
  	    f = _wfopen(wn, wm);
  	vim_free(wn);
***************
*** 4776,4783 ****
      int			len;
  
      /* Convert the file names to wide characters. */
!     fromw = enc_to_ucs2(from, NULL);
!     tow = enc_to_ucs2(to, NULL);
      if (fromw != NULL && tow != NULL)
      {
  	/* Open the file for reading. */
--- 4776,4783 ----
      int			len;
  
      /* Convert the file names to wide characters. */
!     fromw = enc_to_utf16(from, NULL);
!     tow = enc_to_utf16(to, NULL);
      if (fromw != NULL && tow != NULL)
      {
  	/* Open the file for reading. */
***************
*** 5122,5128 ****
      for (i = 0; i < used_file_count; ++i)
      {
  	idx = used_file_indexes[i];
! 	str = ucs2_to_enc(ArglistW[idx], NULL);
  	if (str != NULL)
  	{
  #ifdef FEAT_DIFF
--- 5122,5128 ----
      for (i = 0; i < used_file_count; ++i)
      {
  	idx = used_file_indexes[i];
! 	str = utf16_to_enc(ArglistW[idx], NULL);
  	if (str != NULL)
  	{
  #ifdef FEAT_DIFF
*** ../vim-7.2.048/src/proto/os_mswin.pro	Sat May  5 19:07:50 2007
--- src/proto/os_mswin.pro	Thu Nov 20 16:41:00 2008
***************
*** 22,35 ****
  int can_end_termcap_mode __ARGS((int give_msg));
  int mch_screenmode __ARGS((char_u *arg));
  int mch_libcall __ARGS((char_u *libname, char_u *funcname, char_u *argstring, int argint, char_u **string_result, int *number_result));
! int utf8_to_ucs2 __ARGS((char_u *instr, int inlen, short_u *outstr, int *unconvlenp));
! int ucs2_to_utf8 __ARGS((short_u *instr, int inlen, char_u *outstr));
  void MultiByteToWideChar_alloc __ARGS((UINT cp, DWORD flags, LPCSTR in, int inlen, LPWSTR *out, int *outlen));
  void WideCharToMultiByte_alloc __ARGS((UINT cp, DWORD flags, LPCWSTR in, int inlen, LPSTR *out, int *outlen, LPCSTR def, LPBOOL useddef));
  int clip_mch_own_selection __ARGS((VimClipboard *cbd));
  void clip_mch_lose_selection __ARGS((VimClipboard *cbd));
! short_u *enc_to_ucs2 __ARGS((char_u *str, int *lenp));
! char_u *ucs2_to_enc __ARGS((short_u *str, int *lenp));
  void clip_mch_request_selection __ARGS((VimClipboard *cbd));
  void acp_to_enc __ARGS((char_u *str, int str_size, char_u **out, int *outlen));
  void clip_mch_set_selection __ARGS((VimClipboard *cbd));
--- 22,35 ----
  int can_end_termcap_mode __ARGS((int give_msg));
  int mch_screenmode __ARGS((char_u *arg));
  int mch_libcall __ARGS((char_u *libname, char_u *funcname, char_u *argstring, int argint, char_u **string_result, int *number_result));
! int utf8_to_utf16 __ARGS((char_u *instr, int inlen, short_u *outstr, int *unconvlenp));
! int utf16_to_utf8 __ARGS((short_u *instr, int inlen, char_u *outstr));
  void MultiByteToWideChar_alloc __ARGS((UINT cp, DWORD flags, LPCSTR in, int inlen, LPWSTR *out, int *outlen));
  void WideCharToMultiByte_alloc __ARGS((UINT cp, DWORD flags, LPCWSTR in, int inlen, LPSTR *out, int *outlen, LPCSTR def, LPBOOL useddef));
  int clip_mch_own_selection __ARGS((VimClipboard *cbd));
  void clip_mch_lose_selection __ARGS((VimClipboard *cbd));
! short_u *enc_to_utf16 __ARGS((char_u *str, int *lenp));
! char_u *utf16_to_enc __ARGS((short_u *str, int *lenp));
  void clip_mch_request_selection __ARGS((VimClipboard *cbd));
  void acp_to_enc __ARGS((char_u *str, int str_size, char_u **out, int *outlen));
  void clip_mch_set_selection __ARGS((VimClipboard *cbd));
*** ../vim-7.2.048/src/version.c	Thu Nov 20 16:11:03 2008
--- src/version.c	Thu Nov 20 17:08:07 2008
***************
*** 678,679 ****
--- 678,681 ----
  {   /* Add new patch number below this line */
+ /**/
+     49,
  /**/

-- 
FIRST HEAD: All right! All right! We'll kill him first and then have tea and
            biscuits.
                 "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD

 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\        download, build and distribute -- http://www.A-A-P.org        ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///