Mercurial > vim
comparison src/ex_getln.c @ 714:0f9f4761ad9c v7.0216
updated for version 7.0216
author | vimboss |
---|---|
date | Mon, 06 Mar 2006 23:29:24 +0000 |
parents | a28f83d37113 |
children | 8ae24f338cab |
comparison
equal
deleted
inserted
replaced
713:0c381fb7846c | 714:0f9f4761ad9c |
---|---|
516 cmdline_del(i); | 516 cmdline_del(i); |
517 c = p_wc; | 517 c = p_wc; |
518 xpc.xp_context = EXPAND_NOTHING; | 518 xpc.xp_context = EXPAND_NOTHING; |
519 } | 519 } |
520 } | 520 } |
521 if (xpc.xp_context == EXPAND_FILES && p_wmnu) | 521 if ((xpc.xp_context == EXPAND_FILES |
522 || xpc.xp_context == EXPAND_SHELLCMD) && p_wmnu) | |
522 { | 523 { |
523 char_u upseg[5]; | 524 char_u upseg[5]; |
524 | 525 |
525 upseg[0] = PATHSEP; | 526 upseg[0] = PATHSEP; |
526 upseg[1] = '.'; | 527 upseg[1] = '.'; |
2464 int newlen = 0; | 2465 int newlen = 0; |
2465 int mb_l; | 2466 int mb_l; |
2466 int pc, pc1; | 2467 int pc, pc1; |
2467 int prev_c = 0; | 2468 int prev_c = 0; |
2468 int prev_c1 = 0; | 2469 int prev_c1 = 0; |
2469 int u8c, u8c_c1, u8c_c2; | 2470 int u8c; |
2471 int u8cc[MAX_MCO]; | |
2470 int nc = 0; | 2472 int nc = 0; |
2471 int dummy; | |
2472 | 2473 |
2473 /* | 2474 /* |
2474 * Do arabic shaping into a temporary buffer. This is very | 2475 * Do arabic shaping into a temporary buffer. This is very |
2475 * inefficient! | 2476 * inefficient! |
2476 */ | 2477 */ |
2493 } | 2494 } |
2494 | 2495 |
2495 for (j = start; j < start + len; j += mb_l) | 2496 for (j = start; j < start + len; j += mb_l) |
2496 { | 2497 { |
2497 p = ccline.cmdbuff + j; | 2498 p = ccline.cmdbuff + j; |
2498 u8c = utfc_ptr2char_len(p, &u8c_c1, &u8c_c2, start + len - j); | 2499 u8c = utfc_ptr2char_len(p, u8cc, start + len - j); |
2499 mb_l = utfc_ptr2len_len(p, start + len - j); | 2500 mb_l = utfc_ptr2len_len(p, start + len - j); |
2500 if (ARABIC_CHAR(u8c)) | 2501 if (ARABIC_CHAR(u8c)) |
2501 { | 2502 { |
2502 /* Do Arabic shaping. */ | 2503 /* Do Arabic shaping. */ |
2503 if (cmdmsg_rl) | 2504 if (cmdmsg_rl) |
2504 { | 2505 { |
2505 /* displaying from right to left */ | 2506 /* displaying from right to left */ |
2506 pc = prev_c; | 2507 pc = prev_c; |
2507 pc1 = prev_c1; | 2508 pc1 = prev_c1; |
2508 prev_c1 = u8c_c1; | 2509 prev_c1 = u8cc[0]; |
2509 if (j + mb_l >= start + len) | 2510 if (j + mb_l >= start + len) |
2510 nc = NUL; | 2511 nc = NUL; |
2511 else | 2512 else |
2512 nc = utf_ptr2char(p + mb_l); | 2513 nc = utf_ptr2char(p + mb_l); |
2513 } | 2514 } |
2515 { | 2516 { |
2516 /* displaying from left to right */ | 2517 /* displaying from left to right */ |
2517 if (j + mb_l >= start + len) | 2518 if (j + mb_l >= start + len) |
2518 pc = NUL; | 2519 pc = NUL; |
2519 else | 2520 else |
2520 pc = utfc_ptr2char_len(p + mb_l, &pc1, &dummy, | 2521 { |
2522 int pcc[MAX_MCO]; | |
2523 | |
2524 pc = utfc_ptr2char_len(p + mb_l, pcc, | |
2521 start + len - j - mb_l); | 2525 start + len - j - mb_l); |
2526 pc1 = pcc[0]; | |
2527 } | |
2522 nc = prev_c; | 2528 nc = prev_c; |
2523 } | 2529 } |
2524 prev_c = u8c; | 2530 prev_c = u8c; |
2525 | 2531 |
2526 u8c = arabic_shape(u8c, NULL, &u8c_c1, pc, pc1, nc); | 2532 u8c = arabic_shape(u8c, NULL, &u8cc[0], pc, pc1, nc); |
2527 | 2533 |
2528 newlen += (*mb_char2bytes)(u8c, arshape_buf + newlen); | 2534 newlen += (*mb_char2bytes)(u8c, arshape_buf + newlen); |
2529 if (u8c_c1 != 0) | 2535 if (u8cc[0] != 0) |
2530 { | 2536 { |
2531 newlen += (*mb_char2bytes)(u8c_c1, arshape_buf + newlen); | 2537 newlen += (*mb_char2bytes)(u8cc[0], arshape_buf + newlen); |
2532 if (u8c_c2 != 0) | 2538 if (u8cc[1] != 0) |
2533 newlen += (*mb_char2bytes)(u8c_c2, | 2539 newlen += (*mb_char2bytes)(u8cc[1], |
2534 arshape_buf + newlen); | 2540 arshape_buf + newlen); |
2535 } | 2541 } |
2536 } | 2542 } |
2537 else | 2543 else |
2538 { | 2544 { |
3351 for (i = 0; i < xp->xp_numfiles; ++i) | 3357 for (i = 0; i < xp->xp_numfiles; ++i) |
3352 { | 3358 { |
3353 #ifdef CASE_INSENSITIVE_FILENAME | 3359 #ifdef CASE_INSENSITIVE_FILENAME |
3354 if (xp->xp_context == EXPAND_DIRECTORIES | 3360 if (xp->xp_context == EXPAND_DIRECTORIES |
3355 || xp->xp_context == EXPAND_FILES | 3361 || xp->xp_context == EXPAND_FILES |
3362 || xp->xp_context == EXPAND_SHELLCMD | |
3356 || xp->xp_context == EXPAND_BUFFERS) | 3363 || xp->xp_context == EXPAND_BUFFERS) |
3357 { | 3364 { |
3358 if (TOLOWER_LOC(xp->xp_files[i][len]) != | 3365 if (TOLOWER_LOC(xp->xp_files[i][len]) != |
3359 TOLOWER_LOC(xp->xp_files[0][len])) | 3366 TOLOWER_LOC(xp->xp_files[0][len])) |
3360 break; | 3367 break; |
3452 tilde_replace(str, numfiles, files); | 3459 tilde_replace(str, numfiles, files); |
3453 | 3460 |
3454 if (options & WILD_ESCAPE) | 3461 if (options & WILD_ESCAPE) |
3455 { | 3462 { |
3456 if (xp->xp_context == EXPAND_FILES | 3463 if (xp->xp_context == EXPAND_FILES |
3464 || xp->xp_context == EXPAND_SHELLCMD | |
3457 || xp->xp_context == EXPAND_BUFFERS | 3465 || xp->xp_context == EXPAND_BUFFERS |
3458 || xp->xp_context == EXPAND_DIRECTORIES) | 3466 || xp->xp_context == EXPAND_DIRECTORIES) |
3459 { | 3467 { |
3460 /* | 3468 /* |
3461 * Insert a backslash into a file name before a space, \, %, # | 3469 * Insert a backslash into a file name before a space, \, %, # |
3646 /* find the length of the longest file name */ | 3654 /* find the length of the longest file name */ |
3647 maxlen = 0; | 3655 maxlen = 0; |
3648 for (i = 0; i < num_files; ++i) | 3656 for (i = 0; i < num_files; ++i) |
3649 { | 3657 { |
3650 if (!showtail && (xp->xp_context == EXPAND_FILES | 3658 if (!showtail && (xp->xp_context == EXPAND_FILES |
3659 || xp->xp_context == EXPAND_SHELLCMD | |
3651 || xp->xp_context == EXPAND_BUFFERS)) | 3660 || xp->xp_context == EXPAND_BUFFERS)) |
3652 { | 3661 { |
3653 home_replace(NULL, files_found[i], NameBuff, MAXPATHL, TRUE); | 3662 home_replace(NULL, files_found[i], NameBuff, MAXPATHL, TRUE); |
3654 j = vim_strsize(NameBuff); | 3663 j = vim_strsize(NameBuff); |
3655 } | 3664 } |
3698 break; | 3707 break; |
3699 } | 3708 } |
3700 for (j = maxlen - lastlen; --j >= 0; ) | 3709 for (j = maxlen - lastlen; --j >= 0; ) |
3701 msg_putchar(' '); | 3710 msg_putchar(' '); |
3702 if (xp->xp_context == EXPAND_FILES | 3711 if (xp->xp_context == EXPAND_FILES |
3712 || xp->xp_context == EXPAND_SHELLCMD | |
3703 || xp->xp_context == EXPAND_BUFFERS) | 3713 || xp->xp_context == EXPAND_BUFFERS) |
3704 { | 3714 { |
3705 /* highlight directories */ | 3715 /* highlight directories */ |
3706 j = (mch_isdir(files_found[k])); | 3716 j = (mch_isdir(files_found[k])); |
3707 if (showtail) | 3717 if (showtail) |
3787 { | 3797 { |
3788 char_u *s; | 3798 char_u *s; |
3789 char_u *end; | 3799 char_u *end; |
3790 | 3800 |
3791 /* When not completing file names a "/" may mean something different. */ | 3801 /* When not completing file names a "/" may mean something different. */ |
3792 if (xp->xp_context != EXPAND_FILES && xp->xp_context != EXPAND_DIRECTORIES) | 3802 if (xp->xp_context != EXPAND_FILES |
3803 && xp->xp_context != EXPAND_SHELLCMD | |
3804 && xp->xp_context != EXPAND_DIRECTORIES) | |
3793 return FALSE; | 3805 return FALSE; |
3794 | 3806 |
3795 end = gettail(xp->xp_pattern); | 3807 end = gettail(xp->xp_pattern); |
3796 if (end == xp->xp_pattern) /* there is no path separator */ | 3808 if (end == xp->xp_pattern) /* there is no path separator */ |
3797 return FALSE; | 3809 return FALSE; |
3824 char_u *retval; | 3836 char_u *retval; |
3825 int i, j; | 3837 int i, j; |
3826 int new_len; | 3838 int new_len; |
3827 char_u *tail; | 3839 char_u *tail; |
3828 | 3840 |
3829 if (context != EXPAND_FILES && context != EXPAND_DIRECTORIES) | 3841 if (context != EXPAND_FILES |
3842 && context != EXPAND_SHELLCMD | |
3843 && context != EXPAND_DIRECTORIES) | |
3830 { | 3844 { |
3831 /* | 3845 /* |
3832 * Matching will be done internally (on something other than files). | 3846 * Matching will be done internally (on something other than files). |
3833 * So we convert the file-matching-type wildcards into our kind for | 3847 * So we convert the file-matching-type wildcards into our kind for |
3834 * use with vim_regcomp(). First work out how long it will be: | 3848 * use with vim_regcomp(). First work out how long it will be: |
3941 * EXPAND_FILES After command with XFILE set, or after setting | 3955 * EXPAND_FILES After command with XFILE set, or after setting |
3942 * with P_EXPAND set. eg :e ^I, :w>>^I | 3956 * with P_EXPAND set. eg :e ^I, :w>>^I |
3943 * EXPAND_DIRECTORIES In some cases this is used instead of the latter | 3957 * EXPAND_DIRECTORIES In some cases this is used instead of the latter |
3944 * when we know only directories are of interest. eg | 3958 * when we know only directories are of interest. eg |
3945 * :set dir=^I | 3959 * :set dir=^I |
3960 * EXPAND_SHELLCMD After ":!cmd", ":r !cmd" or ":w !cmd". | |
3946 * EXPAND_SETTINGS Complete variable names. eg :set d^I | 3961 * EXPAND_SETTINGS Complete variable names. eg :set d^I |
3947 * EXPAND_BOOL_SETTINGS Complete boolean variables only, eg :set no^I | 3962 * EXPAND_BOOL_SETTINGS Complete boolean variables only, eg :set no^I |
3948 * EXPAND_TAGS Complete tags from the files in p_tags. eg :ta a^I | 3963 * EXPAND_TAGS Complete tags from the files in p_tags. eg :ta a^I |
3949 * EXPAND_TAGS_LISTFILES As above, but list filenames on ^D, after :tselect | 3964 * EXPAND_TAGS_LISTFILES As above, but list filenames on ^D, after :tselect |
3950 * EXPAND_HELP Complete tags from the file 'helpfile'/tags | 3965 * EXPAND_HELP Complete tags from the file 'helpfile'/tags |
4160 else | 4175 else |
4161 flags = (flags | EW_DIR) & ~EW_FILE; | 4176 flags = (flags | EW_DIR) & ~EW_FILE; |
4162 ret = expand_wildcards(1, &pat, num_file, file, flags); | 4177 ret = expand_wildcards(1, &pat, num_file, file, flags); |
4163 if (free_pat) | 4178 if (free_pat) |
4164 vim_free(pat); | 4179 vim_free(pat); |
4180 return ret; | |
4181 } | |
4182 | |
4183 if (xp->xp_context == EXPAND_SHELLCMD) | |
4184 { | |
4185 /* | |
4186 * Expand shell command. | |
4187 */ | |
4188 int i; | |
4189 char_u *path; | |
4190 int mustfree = FALSE; | |
4191 garray_T ga; | |
4192 char_u *buf = alloc(MAXPATHL); | |
4193 int l; | |
4194 char_u *s, *e; | |
4195 | |
4196 if (buf == NULL) | |
4197 return FAIL; | |
4198 | |
4199 /* for ":set path=" and ":set tags=" halve backslashes for escaped | |
4200 * space */ | |
4201 pat = vim_strsave(pat); | |
4202 for (i = 0; pat[i]; ++i) | |
4203 if (pat[i] == '\\' && pat[i + 1] == ' ') | |
4204 STRCPY(pat + i, pat + i + 1); | |
4205 | |
4206 flags |= EW_FILE | EW_EXEC; | |
4207 /* For an absolute name we don't use $PATH. */ | |
4208 if ((pat[0] == '.' && (vim_ispathsep(pat[1]) | |
4209 || (pat[1] == '.' && vim_ispathsep(pat[2]))))) | |
4210 path = (char_u *)"."; | |
4211 else | |
4212 path = vim_getenv((char_u *)"PATH", &mustfree); | |
4213 | |
4214 ga_init2(&ga, (int)sizeof(char *), 10); | |
4215 for (s = path; *s != NUL; s = e) | |
4216 { | |
4217 #if defined(MSDOS) || defined(MSWIN) || defined(OS2) | |
4218 e = vim_strchr(s, ';'); | |
4219 #else | |
4220 e = vim_strchr(s, ':'); | |
4221 #endif | |
4222 if (e == NULL) | |
4223 e = s + STRLEN(s); | |
4224 | |
4225 l = e - s; | |
4226 if (l > MAXPATHL - 5) | |
4227 break; | |
4228 vim_strncpy(buf, s, l); | |
4229 add_pathsep(buf); | |
4230 l = STRLEN(buf); | |
4231 vim_strncpy(buf + l, pat, MAXPATHL - 1 - l); | |
4232 | |
4233 /* Expand matches in one directory of $PATH. */ | |
4234 ret = expand_wildcards(1, &buf, num_file, file, flags); | |
4235 if (ret == OK) | |
4236 { | |
4237 if (ga_grow(&ga, *num_file) == FAIL) | |
4238 FreeWild(*num_file, *file); | |
4239 else | |
4240 { | |
4241 for (i = 0; i < *num_file; ++i) | |
4242 { | |
4243 s = (*file)[i]; | |
4244 if (STRLEN(s) > l) | |
4245 { | |
4246 /* Remove the path again. */ | |
4247 mch_memmove(s, s + l, STRLEN(s + l) + 1); | |
4248 ((char_u **)ga.ga_data)[ga.ga_len] = s; | |
4249 ++ga.ga_len; | |
4250 } | |
4251 else | |
4252 vim_free(s); | |
4253 } | |
4254 vim_free(*file); | |
4255 } | |
4256 } | |
4257 if (*e != NUL) | |
4258 ++e; | |
4259 } | |
4260 *file = ga.ga_data; | |
4261 *num_file = ga.ga_len; | |
4262 | |
4263 vim_free(buf); | |
4264 vim_free(pat); | |
4265 if (mustfree) | |
4266 vim_free(path); | |
4165 return ret; | 4267 return ret; |
4166 } | 4268 } |
4167 | 4269 |
4168 *file = (char_u **)""; | 4270 *file = (char_u **)""; |
4169 *num_file = 0; | 4271 *num_file = 0; |