Mercurial > vim
comparison src/os_mswin.c @ 39:410fa1a31baf v7.0023
updated for version 7.0023
author | vimboss |
---|---|
date | Sun, 19 Dec 2004 22:46:22 +0000 |
parents | fdf55076c53f |
children | f529edb9bab3 |
comparison
equal
deleted
inserted
replaced
38:c524f99c7925 | 39:410fa1a31baf |
---|---|
362 } | 362 } |
363 #endif /* FEAT_TITLE */ | 363 #endif /* FEAT_TITLE */ |
364 | 364 |
365 | 365 |
366 /* | 366 /* |
367 * Get absolute file name into buffer 'buf' of length 'len' bytes, | 367 * Get absolute file name into buffer "buf" of length "len" bytes, |
368 * turning all '/'s into '\\'s and getting the correct case of each | 368 * turning all '/'s into '\\'s and getting the correct case of each component |
369 * component of the file name. Append a backslash to a directory name. | 369 * of the file name. Append a (back)slash to a directory name. |
370 * When 'shellslash' set do it the other way around. | 370 * When 'shellslash' set do it the other way around. |
371 * Return OK or FAIL. | 371 * Return OK or FAIL. |
372 */ | 372 */ |
373 int | 373 int |
374 mch_FullName( | 374 mch_FullName( |
382 #ifdef __BORLANDC__ | 382 #ifdef __BORLANDC__ |
383 if (*fname == NUL) /* Borland behaves badly here - make it consistent */ | 383 if (*fname == NUL) /* Borland behaves badly here - make it consistent */ |
384 nResult = mch_dirname(buf, len); | 384 nResult = mch_dirname(buf, len); |
385 else | 385 else |
386 #endif | 386 #endif |
387 if (_fullpath(buf, fname, len - 1) == NULL) | 387 { |
388 { | 388 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage |
389 STRNCPY(buf, fname, len); /* failed, use the relative path name */ | 389 # ifdef __BORLANDC__ |
390 buf[len - 1] = NUL; | 390 /* Wide functions of Borland C 5.5 do not work on Windows 98. */ |
391 #ifndef USE_FNAME_CASE | 391 && g_PlatformId == VER_PLATFORM_WIN32_NT |
392 slash_adjust(buf); | 392 # endif |
393 #endif | 393 ) |
394 } | 394 { |
395 else | 395 WCHAR *wname; |
396 nResult = OK; | 396 WCHAR wbuf[MAX_PATH]; |
397 char_u *cname = NULL; | |
398 | |
399 /* Use the wide function: | |
400 * - convert the fname from 'encoding' to UCS2. | |
401 * - invoke _wfullpath() | |
402 * - convert the result from UCS2 to 'encoding'. | |
403 */ | |
404 wname = enc_to_ucs2(fname, NULL); | |
405 if (wname != NULL && _wfullpath(wbuf, wname, MAX_PATH - 1) != NULL) | |
406 { | |
407 cname = ucs2_to_enc((short_u *)wbuf, NULL); | |
408 if (cname != NULL) | |
409 { | |
410 STRNCPY(buf, cname, len); | |
411 buf[len - 1] = NUL; | |
412 nResult = OK; | |
413 } | |
414 } | |
415 vim_free(wname); | |
416 vim_free(cname); | |
417 } | |
418 #ifdef FEAT_MBYTE | |
419 if (nResult == FAIL) /* fall back to non-wide function */ | |
420 #endif | |
421 { | |
422 if (_fullpath(buf, fname, len - 1) == NULL) | |
423 { | |
424 STRNCPY(buf, fname, len); /* failed, use relative path name */ | |
425 buf[len - 1] = NUL; | |
426 } | |
427 else | |
428 nResult = OK; | |
429 } | |
430 } | |
397 | 431 |
398 #ifdef USE_FNAME_CASE | 432 #ifdef USE_FNAME_CASE |
399 fname_case(buf, len); | 433 fname_case(buf, len); |
434 #else | |
435 slash_adjust(buf); | |
400 #endif | 436 #endif |
401 | 437 |
402 return nResult; | 438 return nResult; |
403 } | 439 } |
404 | 440 |
418 | 454 |
419 /* A name that can't be made absolute probably isn't absolute. */ | 455 /* A name that can't be made absolute probably isn't absolute. */ |
420 if (mch_FullName(fname, szName, _MAX_PATH, FALSE) == FAIL) | 456 if (mch_FullName(fname, szName, _MAX_PATH, FALSE) == FAIL) |
421 return FALSE; | 457 return FALSE; |
422 | 458 |
423 return pathcmp(fname, szName) == 0; | 459 return pathcmp(fname, szName, -1) == 0; |
424 } | 460 } |
425 | 461 |
426 /* | 462 /* |
427 * Replace all slashes by backslashes. | 463 * Replace all slashes by backslashes. |
428 * This used to be the other way around, but MS-DOS sometimes has problems | 464 * This used to be the other way around, but MS-DOS sometimes has problems |
439 if (p != NULL) | 475 if (p != NULL) |
440 while (*p) | 476 while (*p) |
441 { | 477 { |
442 if (*p == psepcN) | 478 if (*p == psepcN) |
443 *p = psepc; | 479 *p = psepc; |
444 #ifdef FEAT_MBYTE | 480 mb_ptr_adv(p); |
445 if (has_mbyte) | |
446 p += (*mb_ptr2len_check)(p); | |
447 else | |
448 #endif | |
449 ++p; | |
450 } | 481 } |
451 } | 482 } |
452 | 483 |
453 | 484 |
454 /* | 485 /* |
462 | 493 |
463 STRNCPY(buf, name, _MAX_PATH); | 494 STRNCPY(buf, name, _MAX_PATH); |
464 buf[_MAX_PATH] = NUL; | 495 buf[_MAX_PATH] = NUL; |
465 p = buf + strlen(buf); | 496 p = buf + strlen(buf); |
466 if (p > buf) | 497 if (p > buf) |
467 --p; | 498 mb_ptr_back(buf, p); |
468 #ifdef FEAT_MBYTE | |
469 if (p > buf && has_mbyte) | |
470 p -= (*mb_head_off)(buf, p); | |
471 #endif | |
472 if (p > buf && (*p == '\\' || *p == '/') && p[-1] != ':') | 499 if (p > buf && (*p == '\\' || *p == '/') && p[-1] != ':') |
473 *p = NUL; | 500 *p = NUL; |
474 #ifdef FEAT_MBYTE | 501 #ifdef FEAT_MBYTE |
475 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage | 502 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage |
476 # ifdef __BORLANDC__ | 503 # ifdef __BORLANDC__ |
586 * dos_expandpath(). | 613 * dos_expandpath(). |
587 */ | 614 */ |
588 int | 615 int |
589 mch_has_exp_wildcard(char_u *p) | 616 mch_has_exp_wildcard(char_u *p) |
590 { | 617 { |
591 for ( ; *p; ++p) | 618 for ( ; *p; mb_ptr_adv(p)) |
592 { | 619 { |
593 if (vim_strchr((char_u *)"?*[", *p) != NULL | 620 if (vim_strchr((char_u *)"?*[", *p) != NULL |
594 || (*p == '~' && p[1] != NUL)) | 621 || (*p == '~' && p[1] != NUL)) |
595 return TRUE; | 622 return TRUE; |
596 #ifdef FEAT_MBYTE | |
597 if (has_mbyte) | |
598 p += (*mb_ptr2len_check)(p) - 1; | |
599 #endif | |
600 } | 623 } |
601 return FALSE; | 624 return FALSE; |
602 } | 625 } |
603 | 626 |
604 /* | 627 /* |
606 * shortened file name). | 629 * shortened file name). |
607 */ | 630 */ |
608 int | 631 int |
609 mch_has_wildcard(char_u *p) | 632 mch_has_wildcard(char_u *p) |
610 { | 633 { |
611 for ( ; *p; ++p) | 634 for ( ; *p; mb_ptr_adv(p)) |
612 { | 635 { |
613 if (vim_strchr((char_u *) | 636 if (vim_strchr((char_u *) |
614 # ifdef VIM_BACKTICK | 637 # ifdef VIM_BACKTICK |
615 "?*$[`" | 638 "?*$[`" |
616 # else | 639 # else |
617 "?*$[" | 640 "?*$[" |
618 # endif | 641 # endif |
619 , *p) != NULL | 642 , *p) != NULL |
620 || (*p == '~' && p[1] != NUL)) | 643 || (*p == '~' && p[1] != NUL)) |
621 return TRUE; | 644 return TRUE; |
622 #ifdef FEAT_MBYTE | |
623 if (has_mbyte) | |
624 p += (*mb_ptr2len_check)(p) - 1; | |
625 #endif | |
626 } | 645 } |
627 return FALSE; | 646 return FALSE; |
628 } | 647 } |
629 | 648 |
630 | 649 |
2418 #define COPYDATA_KEYS 0 | 2437 #define COPYDATA_KEYS 0 |
2419 #define COPYDATA_REPLY 1 | 2438 #define COPYDATA_REPLY 1 |
2420 #define COPYDATA_EXPR 10 | 2439 #define COPYDATA_EXPR 10 |
2421 #define COPYDATA_RESULT 11 | 2440 #define COPYDATA_RESULT 11 |
2422 #define COPYDATA_ERROR_RESULT 12 | 2441 #define COPYDATA_ERROR_RESULT 12 |
2442 #define COPYDATA_ENCODING 20 | |
2423 | 2443 |
2424 /* This is a structure containing a server HWND and its name. */ | 2444 /* This is a structure containing a server HWND and its name. */ |
2425 struct server_id | 2445 struct server_id |
2426 { | 2446 { |
2427 HWND hwnd; | 2447 HWND hwnd; |
2428 char_u *name; | 2448 char_u *name; |
2429 }; | 2449 }; |
2450 | |
2451 /* Last received 'encoding' that the client uses. */ | |
2452 static char_u *client_enc = NULL; | |
2453 | |
2454 /* | |
2455 * Tell the other side what encoding we are using. | |
2456 * Errors are ignored. | |
2457 */ | |
2458 static void | |
2459 serverSendEnc(HWND target) | |
2460 { | |
2461 COPYDATASTRUCT data; | |
2462 | |
2463 data.dwData = COPYDATA_ENCODING; | |
2464 data.cbData = STRLEN(p_enc) + 1; | |
2465 data.lpData = p_enc; | |
2466 (void)SendMessage(target, WM_COPYDATA, (WPARAM)message_window, | |
2467 (LPARAM)(&data)); | |
2468 } | |
2430 | 2469 |
2431 /* | 2470 /* |
2432 * Clean up on exit. This destroys the hidden message window. | 2471 * Clean up on exit. This destroys the hidden message window. |
2433 */ | 2472 */ |
2434 static void | 2473 static void |
2461 { | 2500 { |
2462 if (msg == WM_COPYDATA) | 2501 if (msg == WM_COPYDATA) |
2463 { | 2502 { |
2464 /* This is a message from another Vim. The dwData member of the | 2503 /* This is a message from another Vim. The dwData member of the |
2465 * COPYDATASTRUCT determines the type of message: | 2504 * COPYDATASTRUCT determines the type of message: |
2505 * COPYDATA_ENCODING: | |
2506 * The encoding that the client uses. Following messages will | |
2507 * use this encoding, convert if needed. | |
2466 * COPYDATA_KEYS: | 2508 * COPYDATA_KEYS: |
2467 * A key sequence. We are a server, and a client wants these keys | 2509 * A key sequence. We are a server, and a client wants these keys |
2468 * adding to the input queue. | 2510 * adding to the input queue. |
2469 * COPYDATA_REPLY: | 2511 * COPYDATA_REPLY: |
2470 * A reply. We are a client, and a server has sent this message | 2512 * A reply. We are a client, and a server has sent this message |
2483 HWND sender = (HWND)wParam; | 2525 HWND sender = (HWND)wParam; |
2484 COPYDATASTRUCT reply; | 2526 COPYDATASTRUCT reply; |
2485 char_u *res; | 2527 char_u *res; |
2486 char_u winstr[30]; | 2528 char_u winstr[30]; |
2487 int retval; | 2529 int retval; |
2530 char_u *str; | |
2531 char_u *tofree; | |
2488 | 2532 |
2489 switch (data->dwData) | 2533 switch (data->dwData) |
2490 { | 2534 { |
2535 case COPYDATA_ENCODING: | |
2536 /* Remember the encoding that the client uses. */ | |
2537 vim_free(client_enc); | |
2538 client_enc = enc_canonize((char_u *)data->lpData); | |
2539 return 1; | |
2540 | |
2491 case COPYDATA_KEYS: | 2541 case COPYDATA_KEYS: |
2492 /* Remember who sent this, for <client> */ | 2542 /* Remember who sent this, for <client> */ |
2493 clientWindow = sender; | 2543 clientWindow = sender; |
2494 | 2544 |
2495 /* Add the received keys to the input buffer. The loop waiting | 2545 /* Add the received keys to the input buffer. The loop waiting |
2496 * for the user to do something should check the input buffer. */ | 2546 * for the user to do something should check the input buffer. */ |
2497 server_to_input_buf((char_u *)(data->lpData)); | 2547 str = serverConvert(client_enc, (char_u *)data->lpData, &tofree); |
2548 server_to_input_buf(str); | |
2549 vim_free(tofree); | |
2498 | 2550 |
2499 # ifdef FEAT_GUI | 2551 # ifdef FEAT_GUI |
2500 /* Wake up the main GUI loop. */ | 2552 /* Wake up the main GUI loop. */ |
2501 if (s_hwnd != 0) | 2553 if (s_hwnd != 0) |
2502 PostMessage(s_hwnd, WM_NULL, 0, 0); | 2554 PostMessage(s_hwnd, WM_NULL, 0, 0); |
2505 | 2557 |
2506 case COPYDATA_EXPR: | 2558 case COPYDATA_EXPR: |
2507 /* Remember who sent this, for <client> */ | 2559 /* Remember who sent this, for <client> */ |
2508 clientWindow = sender; | 2560 clientWindow = sender; |
2509 | 2561 |
2510 res = eval_client_expr_to_string(data->lpData); | 2562 str = serverConvert(client_enc, (char_u *)data->lpData, &tofree); |
2563 res = eval_client_expr_to_string(str); | |
2564 vim_free(tofree); | |
2565 | |
2511 if (res == NULL) | 2566 if (res == NULL) |
2512 { | 2567 { |
2513 res = vim_strsave(_(e_invexprmsg)); | 2568 res = vim_strsave(_(e_invexprmsg)); |
2514 reply.dwData = COPYDATA_ERROR_RESULT; | 2569 reply.dwData = COPYDATA_ERROR_RESULT; |
2515 } | 2570 } |
2516 else | 2571 else |
2517 reply.dwData = COPYDATA_RESULT; | 2572 reply.dwData = COPYDATA_RESULT; |
2518 reply.lpData = res; | 2573 reply.lpData = res; |
2519 reply.cbData = STRLEN(res) + 1; | 2574 reply.cbData = STRLEN(res) + 1; |
2520 | 2575 |
2576 serverSendEnc(sender); | |
2521 retval = SendMessage(sender, WM_COPYDATA, (WPARAM)message_window, | 2577 retval = SendMessage(sender, WM_COPYDATA, (WPARAM)message_window, |
2522 (LPARAM)(&reply)); | 2578 (LPARAM)(&reply)); |
2523 vim_free(res); | 2579 vim_free(res); |
2524 return retval; | 2580 return retval; |
2525 | 2581 |
2526 case COPYDATA_REPLY: | 2582 case COPYDATA_REPLY: |
2527 case COPYDATA_RESULT: | 2583 case COPYDATA_RESULT: |
2528 case COPYDATA_ERROR_RESULT: | 2584 case COPYDATA_ERROR_RESULT: |
2529 if (data->lpData != NULL) | 2585 if (data->lpData != NULL) |
2530 { | 2586 { |
2531 save_reply(sender, data->lpData, | 2587 str = serverConvert(client_enc, (char_u *)data->lpData, |
2588 &tofree); | |
2589 if (tofree == NULL) | |
2590 str = vim_strsave(str); | |
2591 if (save_reply(sender, str, | |
2532 (data->dwData == COPYDATA_REPLY ? 0 : | 2592 (data->dwData == COPYDATA_REPLY ? 0 : |
2533 (data->dwData == COPYDATA_RESULT ? 1 : | 2593 (data->dwData == COPYDATA_RESULT ? 1 : |
2534 2))); | 2594 2))) == FAIL) |
2595 vim_free(str); | |
2535 #ifdef FEAT_AUTOCMD | 2596 #ifdef FEAT_AUTOCMD |
2536 if (data->dwData == COPYDATA_REPLY) | 2597 else if (data->dwData == COPYDATA_REPLY) |
2537 { | 2598 { |
2538 sprintf((char *)winstr, "0x%x", (unsigned)sender); | 2599 sprintf((char *)winstr, "0x%x", (unsigned)sender); |
2539 apply_autocmds(EVENT_REMOTEREPLY, winstr, data->lpData, | 2600 apply_autocmds(EVENT_REMOTEREPLY, winstr, str, |
2540 TRUE, curbuf); | 2601 TRUE, curbuf); |
2541 } | 2602 } |
2542 #endif | 2603 #endif |
2543 } | 2604 } |
2544 return 1; | 2605 return 1; |
2760 | 2821 |
2761 data.dwData = COPYDATA_REPLY; | 2822 data.dwData = COPYDATA_REPLY; |
2762 data.cbData = STRLEN(reply) + 1; | 2823 data.cbData = STRLEN(reply) + 1; |
2763 data.lpData = reply; | 2824 data.lpData = reply; |
2764 | 2825 |
2826 serverSendEnc(target); | |
2765 if (SendMessage(target, WM_COPYDATA, (WPARAM)message_window, | 2827 if (SendMessage(target, WM_COPYDATA, (WPARAM)message_window, |
2766 (LPARAM)(&data))) | 2828 (LPARAM)(&data))) |
2767 return 0; | 2829 return 0; |
2768 | 2830 |
2769 return -1; | 2831 return -1; |
2795 | 2857 |
2796 data.dwData = asExpr ? COPYDATA_EXPR : COPYDATA_KEYS; | 2858 data.dwData = asExpr ? COPYDATA_EXPR : COPYDATA_KEYS; |
2797 data.cbData = STRLEN(cmd) + 1; | 2859 data.cbData = STRLEN(cmd) + 1; |
2798 data.lpData = cmd; | 2860 data.lpData = cmd; |
2799 | 2861 |
2862 serverSendEnc(target); | |
2800 if (SendMessage(target, WM_COPYDATA, (WPARAM)message_window, | 2863 if (SendMessage(target, WM_COPYDATA, (WPARAM)message_window, |
2801 (LPARAM)(&data)) == 0) | 2864 (LPARAM)(&data)) == 0) |
2802 return -1; | 2865 return -1; |
2803 | 2866 |
2804 if (asExpr) | 2867 if (asExpr) |
2848 #define REPLY_ROOM (reply_list.ga_room) | 2911 #define REPLY_ROOM (reply_list.ga_room) |
2849 | 2912 |
2850 /* Flag which is used to wait for a reply */ | 2913 /* Flag which is used to wait for a reply */ |
2851 static int reply_received = 0; | 2914 static int reply_received = 0; |
2852 | 2915 |
2916 /* | |
2917 * Store a reply. "reply" must be allocated memory (or NULL). | |
2918 */ | |
2853 static int | 2919 static int |
2854 save_reply(HWND server, char_u *reply, int expr) | 2920 save_reply(HWND server, char_u *reply, int expr) |
2855 { | 2921 { |
2856 reply_T *rep; | 2922 reply_T *rep; |
2857 | 2923 |
2858 if (ga_grow(&reply_list, 1) == FAIL) | 2924 if (ga_grow(&reply_list, 1) == FAIL) |
2859 return FAIL; | 2925 return FAIL; |
2860 | 2926 |
2861 rep = REPLY_ITEM(REPLY_COUNT); | 2927 rep = REPLY_ITEM(REPLY_COUNT); |
2862 rep->server = server; | 2928 rep->server = server; |
2863 rep->reply = vim_strsave(reply); | 2929 rep->reply = reply; |
2864 rep->expr_result = expr; | 2930 rep->expr_result = expr; |
2865 if (rep->reply == NULL) | 2931 if (rep->reply == NULL) |
2866 return FAIL; | 2932 return FAIL; |
2867 | 2933 |
2868 ++REPLY_COUNT; | 2934 ++REPLY_COUNT; |