~ubuntu-branches/ubuntu/maverick/vim/maverick

« back to all changes in this revision

Viewing changes to src/os_mswin.c

  • Committer: Bazaar Package Importer
  • Author(s): Colin Watson
  • Date: 2009-01-13 18:39:18 UTC
  • mfrom: (1.1.7 upstream)
  • Revision ID: james.westby@ubuntu.com-20090113183918-kgq1jzdwsbbex4pq
Tags: 2:7.2.079-1ubuntu1
* Resynchronise with Debian (diversions fix closes LP: #296324). Remaining
  changes:
  - runtime/syntax/debcontrol.vim:
    + Add "metapackages" to the list of valid sections.
  - runtime/syntax/debchangelog.vim:
    + Add "jaunty" to the list of valid suites.
  - Drop vim-lesstif package and lesstif2-dev build-dependency.
  - Enable Python interpreter on basic builds.
  - Create a .pot file for translations.
  - Disable autoindent, line-wrapping, and backup files by default.
  - runtime/syntax/debsources.vim:
    + Add "jaunty" to debsourcesDistrKeyword
  - runtime/syntax/grub.vim:
    + Add Ubuntu-specific 'quiet' keyword.

Show diffs side-by-side

added added

removed removed

Lines of Context:
309
309
        if (enc_codepage >= 0 && (int)GetACP() != enc_codepage)
310
310
        {
311
311
            /* Convert the title from 'encoding' to the active codepage. */
312
 
            WCHAR       *wp = enc_to_ucs2(title, NULL);
 
312
            WCHAR       *wp = enc_to_utf16(title, NULL);
313
313
            int n;
314
314
 
315
315
            if (wp != NULL)
406
406
             * - invoke _wfullpath()
407
407
             * - convert the result from UCS2 to 'encoding'.
408
408
             */
409
 
            wname = enc_to_ucs2(fname, NULL);
 
409
            wname = enc_to_utf16(fname, NULL);
410
410
            if (wname != NULL && _wfullpath(wbuf, wname, MAX_PATH - 1) != NULL)
411
411
            {
412
 
                cname = ucs2_to_enc((short_u *)wbuf, NULL);
 
412
                cname = utf16_to_enc((short_u *)wbuf, NULL);
413
413
                if (cname != NULL)
414
414
                {
415
415
                    vim_strncpy(buf, cname, len - 1);
507
507
# endif
508
508
       )
509
509
    {
510
 
        WCHAR   *wp = enc_to_ucs2(buf, NULL);
 
510
        WCHAR   *wp = enc_to_utf16(buf, NULL);
511
511
        int     n;
512
512
 
513
513
        if (wp != NULL)
668
668
#ifdef FEAT_MBYTE
669
669
    if (enc_codepage >= 0 && (int)GetACP() != enc_codepage)
670
670
    {
671
 
        WCHAR   *p = enc_to_ucs2(path, NULL);
 
671
        WCHAR   *p = enc_to_utf16(path, NULL);
672
672
        int     n;
673
673
 
674
674
        if (p != NULL)
891
891
 
892
892
#if defined(FEAT_MBYTE) || defined(PROTO)
893
893
/*
894
 
 * Convert an UTF-8 string to UCS-2.
 
894
 * Convert an UTF-8 string to UTF-16.
895
895
 * "instr[inlen]" is the input.  "inlen" is in bytes.
896
 
 * When "outstr" is NULL only return the number of UCS-2 words produced.
 
896
 * When "outstr" is NULL only return the number of UTF-16 words produced.
897
897
 * Otherwise "outstr" must be a buffer of sufficient size.
898
 
 * Returns the number of UCS-2 words produced.
 
898
 * Returns the number of UTF-16 words produced.
899
899
 */
900
900
    int
901
 
utf8_to_ucs2(char_u *instr, int inlen, short_u *outstr, int *unconvlenp)
 
901
utf8_to_utf16(char_u *instr, int inlen, short_u *outstr, int *unconvlenp)
902
902
{
903
903
    int         outlen = 0;
904
904
    char_u      *p = instr;
905
905
    int         todo = inlen;
906
906
    int         l;
 
907
    int         ch;
907
908
 
908
909
    while (todo > 0)
909
910
    {
917
918
            break;
918
919
        }
919
920
 
920
 
        if (outstr != NULL)
921
 
            *outstr++ = utf_ptr2char(p);
 
921
        ch = utf_ptr2char(p);
 
922
        if (ch >= 0x10000)
 
923
        {
 
924
            /* non-BMP character, encoding with surrogate pairs */
 
925
            ++outlen;
 
926
            if (outstr != NULL)
 
927
            {
 
928
                *outstr++ = (0xD800 - (0x10000 >> 10)) + (ch >> 10);
 
929
                *outstr++ = 0xDC00 | (ch & 0x3FF);
 
930
            }
 
931
        }
 
932
        else if (outstr != NULL)
 
933
            *outstr++ = ch;
922
934
        ++outlen;
923
935
        p += l;
924
936
        todo -= l;
928
940
}
929
941
 
930
942
/*
931
 
 * Convert an UCS-2 string to UTF-8.
932
 
 * The input is "instr[inlen]" with "inlen" in number of ucs-2 words.
 
943
 * Convert an UTF-16 string to UTF-8.
 
944
 * The input is "instr[inlen]" with "inlen" in number of UTF-16 words.
933
945
 * When "outstr" is NULL only return the required number of bytes.
934
946
 * Otherwise "outstr" must be a buffer of sufficient size.
935
947
 * Return the number of bytes produced.
936
948
 */
937
949
    int
938
 
ucs2_to_utf8(short_u *instr, int inlen, char_u *outstr)
 
950
utf16_to_utf8(short_u *instr, int inlen, char_u *outstr)
939
951
{
940
952
    int         outlen = 0;
941
953
    int         todo = inlen;
942
954
    short_u     *p = instr;
943
955
    int         l;
 
956
    int         ch, ch2;
944
957
 
945
958
    while (todo > 0)
946
959
    {
 
960
        ch = *p;
 
961
        if (ch >= 0xD800 && ch <= 0xDBFF && todo > 1)
 
962
        {
 
963
            /* surrogate pairs handling */
 
964
            ch2 = p[1];
 
965
            if (ch2 >= 0xDC00 && ch2 <= 0xDFFF)
 
966
            {
 
967
                ch = ((ch - 0xD800) << 10) + (ch2 & 0x3FF) + 0x10000;
 
968
                ++p;
 
969
                --todo;
 
970
            }
 
971
        }
947
972
        if (outstr != NULL)
948
973
        {
949
 
            l = utf_char2bytes(*p, outstr);
 
974
            l = utf_char2bytes(ch, outstr);
950
975
            outstr += l;
951
976
        }
952
977
        else
953
 
            l = utf_char2len(*p);
 
978
            l = utf_char2len(ch);
954
979
        ++p;
955
980
        outlen += l;
956
981
        --todo;
1079
1104
 */
1080
1105
 
1081
1106
/*
1082
 
 * Convert "str" from 'encoding' to UCS-2.
 
1107
 * Convert "str" from 'encoding' to UTF-16.
1083
1108
 * Input in "str" with length "*lenp".  When "lenp" is NULL, use strlen().
1084
1109
 * Output is returned as an allocated string.  "*lenp" is set to the length of
1085
1110
 * the result.  A trailing NUL is always added.
1086
1111
 * Returns NULL when out of memory.
1087
1112
 */
1088
1113
    short_u *
1089
 
enc_to_ucs2(char_u *str, int *lenp)
 
1114
enc_to_utf16(char_u *str, int *lenp)
1090
1115
{
1091
1116
    vimconv_T   conv;
1092
1117
    WCHAR       *ret;
1102
1127
 
1103
1128
    if (enc_codepage > 0)
1104
1129
    {
1105
 
        /* We can do any CP### -> UCS-2 in one pass, and we can do it
 
1130
        /* We can do any CP### -> UTF-16 in one pass, and we can do it
1106
1131
         * without iconv() (convert_* may need iconv). */
1107
1132
        MultiByteToWideChar_alloc(enc_codepage, 0, str, *lenp, &ret, &length);
1108
1133
    }
1123
1148
        }
1124
1149
        convert_setup(&conv, NULL, NULL);
1125
1150
 
1126
 
        length = utf8_to_ucs2(str, *lenp, NULL, NULL);
 
1151
        length = utf8_to_utf16(str, *lenp, NULL, NULL);
1127
1152
        ret = (WCHAR *)alloc((unsigned)((length + 1) * sizeof(WCHAR)));
1128
1153
        if (ret != NULL)
1129
1154
        {
1130
 
            utf8_to_ucs2(str, *lenp, (short_u *)ret, NULL);
 
1155
            utf8_to_utf16(str, *lenp, (short_u *)ret, NULL);
1131
1156
            ret[length] = 0;
1132
1157
        }
1133
1158
 
1139
1164
}
1140
1165
 
1141
1166
/*
1142
 
 * Convert an UCS-2 string to 'encoding'.
 
1167
 * Convert an UTF-16 string to 'encoding'.
1143
1168
 * Input in "str" with length (counted in wide characters) "*lenp".  When
1144
1169
 * "lenp" is NULL, use wcslen().
1145
1170
 * Output is returned as an allocated string.  If "*lenp" is not NULL it is
1147
1172
 * Returns NULL when out of memory.
1148
1173
 */
1149
1174
    char_u *
1150
 
ucs2_to_enc(short_u *str, int *lenp)
 
1175
utf16_to_enc(short_u *str, int *lenp)
1151
1176
{
1152
1177
    vimconv_T   conv;
1153
1178
    char_u      *utf8_str = NULL, *enc_str = NULL;
1161
1186
 
1162
1187
    if (enc_codepage > 0)
1163
1188
    {
1164
 
        /* We can do any UCS-2 -> CP### in one pass. */
 
1189
        /* We can do any UTF-16 -> CP### in one pass. */
1165
1190
        int length;
1166
1191
 
1167
1192
        WideCharToMultiByte_alloc(enc_codepage, 0, str, *lenp,
1171
1196
    }
1172
1197
 
1173
1198
    /* Avoid allocating zero bytes, it generates an error message. */
1174
 
    utf8_str = alloc(ucs2_to_utf8(str, *lenp == 0 ? 1 : *lenp, NULL));
 
1199
    utf8_str = alloc(utf16_to_utf8(str, *lenp == 0 ? 1 : *lenp, NULL));
1175
1200
    if (utf8_str != NULL)
1176
1201
    {
1177
 
        *lenp = ucs2_to_utf8(str, *lenp, utf8_str);
 
1202
        *lenp = utf16_to_utf8(str, *lenp, utf8_str);
1178
1203
 
1179
1204
        /* We might be called before we have p_enc set up. */
1180
1205
        conv.vc_type = CONV_NONE;
1308
1333
                    if (hMemWstr[str_size] == NUL)
1309
1334
                        break;
1310
1335
            }
1311
 
            to_free = str = ucs2_to_enc((short_u *)hMemWstr, &str_size);
 
1336
            to_free = str = utf16_to_enc((short_u *)hMemWstr, &str_size);
1312
1337
            GlobalUnlock(hMemW);
1313
1338
        }
1314
1339
    }
1340
1365
 
1341
1366
# if defined(FEAT_MBYTE) && defined(WIN3264)
1342
1367
            /* The text is in the active codepage.  Convert to 'encoding',
1343
 
             * going through UCS-2. */
 
1368
             * going through UTF-16. */
1344
1369
            acp_to_enc(str, str_size, &to_free, &maxlen);
1345
1370
            if (to_free != NULL)
1346
1371
            {
1404
1429
    if (widestr != NULL)
1405
1430
    {
1406
1431
        ++*outlen;      /* Include the 0 after the string */
1407
 
        *out = ucs2_to_enc((short_u *)widestr, outlen);
 
1432
        *out = utf16_to_enc((short_u *)widestr, outlen);
1408
1433
        vim_free(widestr);
1409
1434
    }
1410
1435
}
1466
1491
        WCHAR           *out;
1467
1492
        int             len = metadata.txtlen;
1468
1493
 
1469
 
        /* Convert the text to UCS-2. This is put on the clipboard as
 
1494
        /* Convert the text to UTF-16. This is put on the clipboard as
1470
1495
         * CF_UNICODETEXT. */
1471
 
        out = (WCHAR *)enc_to_ucs2(str, &len);
 
1496
        out = (WCHAR *)enc_to_utf16(str, &len);
1472
1497
        if (out != NULL)
1473
1498
        {
1474
1499
            WCHAR *lpszMemW;
1488
1513
            WideCharToMultiByte(GetACP(), 0, out, len,
1489
1514
                                                  str, metadata.txtlen, 0, 0);
1490
1515
 
1491
 
            /* Allocate memory for the UCS-2 text, add one NUL word to
 
1516
            /* Allocate memory for the UTF-16 text, add one NUL word to
1492
1517
             * terminate the string. */
1493
1518
            hMemW = (LPSTR)GlobalAlloc(GMEM_MOVEABLE | GMEM_DDESHARE,
1494
1519
                                                   (len + 1) * sizeof(WCHAR));