| @@ -52,49 +52,54 @@ my_wcstombs(const wchar_t *wstr) | | | @@ -52,49 +52,54 @@ my_wcstombs(const wchar_t *wstr) |
52 | } | | 52 | } |
53 | | | 53 | |
54 | | | 54 | |
55 | static unsigned char | | 55 | static unsigned char |
56 | complete(EditLine *el, int ch) | | 56 | complete(EditLine *el, int ch) |
57 | { | | 57 | { |
58 | DIR *dd = opendir("."); | | 58 | DIR *dd = opendir("."); |
59 | struct dirent *dp; | | 59 | struct dirent *dp; |
60 | const wchar_t *ptr; | | 60 | const wchar_t *ptr; |
61 | char *buf, *bptr; | | 61 | char *buf, *bptr; |
62 | const LineInfoW *lf = el_wline(el); | | 62 | const LineInfoW *lf = el_wline(el); |
63 | int len, mblen, i; | | 63 | int len, mblen, i; |
64 | unsigned char res; | | 64 | unsigned char res; |
| | | 65 | wchar_t dir[1024]; |
65 | | | 66 | |
66 | /* Find the last word */ | | 67 | /* Find the last word */ |
67 | for (ptr = lf->cursor -1; !iswspace(*ptr) && ptr > lf->buffer; --ptr) | | 68 | for (ptr = lf->cursor -1; !iswspace(*ptr) && ptr > lf->buffer; --ptr) |
68 | continue; | | 69 | continue; |
69 | len = lf->cursor - ++ptr; | | 70 | len = lf->cursor - ++ptr; |
70 | | | 71 | |
71 | /* Convert last word to multibyte encoding, so we can compare to it */ | | 72 | /* Convert last word to multibyte encoding, so we can compare to it */ |
72 | wctomb(NULL, 0); /* Reset shift state */ | | 73 | wctomb(NULL, 0); /* Reset shift state */ |
73 | mblen = MB_LEN_MAX * len + 1; | | 74 | mblen = MB_LEN_MAX * len + 1; |
74 | buf = bptr =(char *)malloc(mblen); | | 75 | buf = bptr = malloc(mblen); |
| | | 76 | if (buf == NULL) |
| | | 77 | err(1, "malloc"); |
75 | for (i = 0; i < len; ++i) { | | 78 | for (i = 0; i < len; ++i) { |
76 | /* Note: really should test for -1 return from wctomb */ | | 79 | /* Note: really should test for -1 return from wctomb */ |
77 | bptr += wctomb(bptr, ptr[i]); | | 80 | bptr += wctomb(bptr, ptr[i]); |
78 | } | | 81 | } |
79 | *bptr = 0; /* Terminate multibyte string */ | | 82 | *bptr = 0; /* Terminate multibyte string */ |
80 | mblen = bptr - buf; | | 83 | mblen = bptr - buf; |
81 | | | 84 | |
82 | /* Scan directory for matching name */ | | 85 | /* Scan directory for matching name */ |
83 | for (dp = readdir(dd); dp != NULL; dp = readdir(dd)) { | | 86 | for (dp = readdir(dd); dp != NULL; dp = readdir(dd)) { |
84 | if (mblen > strlen(dp->d_name)) | | 87 | if (mblen > strlen(dp->d_name)) |
85 | continue; | | 88 | continue; |
86 | if (strncmp(dp->d_name, buf, mblen) == 0) { | | 89 | if (strncmp(dp->d_name, buf, mblen) == 0) { |
87 | if (el_insertstr(el, &dp->d_name[mblen]) == -1) | | 90 | mbstowcs(dir, &dp->d_name[mblen], |
| | | 91 | sizeof(dir) / sizeof(*dir)); |
| | | 92 | if (el_winsertstr(el, dir) == -1) |
88 | res = CC_ERROR; | | 93 | res = CC_ERROR; |
89 | else | | 94 | else |
90 | res = CC_REFRESH; | | 95 | res = CC_REFRESH; |
91 | break; | | 96 | break; |
92 | } | | 97 | } |
93 | } | | 98 | } |
94 | | | 99 | |
95 | closedir(dd); | | 100 | closedir(dd); |
96 | free(buf); | | 101 | free(buf); |
97 | return res; | | 102 | return res; |
98 | } | | 103 | } |
99 | | | 104 | |
100 | | | 105 | |