comparison src/misc2.c @ 39:410fa1a31baf v7.0023

updated for version 7.0023
author vimboss
date Sun, 19 Dec 2004 22:46:22 +0000
parents ac33b7c03fac
children f529edb9bab3
comparison
equal deleted inserted replaced
38:c524f99c7925 39:410fa1a31baf
198 while (col <= wcol && *ptr != NUL) 198 while (col <= wcol && *ptr != NUL)
199 { 199 {
200 /* Count a tab for what it's worth (if list mode not on) */ 200 /* Count a tab for what it's worth (if list mode not on) */
201 #ifdef FEAT_LINEBREAK 201 #ifdef FEAT_LINEBREAK
202 csize = win_lbr_chartabsize(curwin, ptr, col, &head); 202 csize = win_lbr_chartabsize(curwin, ptr, col, &head);
203 # ifdef FEAT_MBYTE 203 mb_ptr_adv(ptr);
204 if (has_mbyte)
205 ptr += (*mb_ptr2len_check)(ptr);
206 else
207 # endif
208 ++ptr;
209 #else 204 #else
210 csize = lbr_chartabsize_adv(&ptr, col); 205 csize = lbr_chartabsize_adv(&ptr, col);
211 #endif 206 #endif
212 col += csize; 207 col += csize;
213 } 208 }
1449 1444
1450 while (*string) 1445 while (*string)
1451 { 1446 {
1452 if (*string == c) 1447 if (*string == c)
1453 retval = string; 1448 retval = string;
1454 #ifdef FEAT_MBYTE 1449 mb_ptr_adv(string);
1455 if (has_mbyte)
1456 string += (*mb_ptr2len_check)(string);
1457 else
1458 #endif
1459 ++string;
1460 } 1450 }
1461 return retval; 1451 return retval;
1462 } 1452 }
1463 1453
1464 /* 1454 /*
1477 { 1467 {
1478 while (*s) 1468 while (*s)
1479 { 1469 {
1480 if (vim_strchr(charset, *s) != NULL) 1470 if (vim_strchr(charset, *s) != NULL)
1481 return s; 1471 return s;
1482 #ifdef FEAT_MBYTE 1472 mb_ptr_adv(s);
1483 if (has_mbyte)
1484 s += (*mb_ptr2len_check)(s);
1485 else
1486 #endif
1487 ++s;
1488 } 1473 }
1489 return NULL; 1474 return NULL;
1490 } 1475 }
1491 # endif 1476 # endif
1492 #endif 1477 #endif
2643 return OP_PENDING; 2628 return OP_PENDING;
2644 } 2629 }
2645 return State; 2630 return State;
2646 } 2631 }
2647 2632
2633 #if defined(FEAT_MBYTE) || defined(PROTO)
2634 /*
2635 * Return TRUE if "p" points to just after a path separator.
2636 * Take care of multi-byte characters.
2637 * "b" must point to the start of the file name
2638 */
2639 int
2640 after_pathsep(b, p)
2641 char_u *b;
2642 char_u *p;
2643 {
2644 return vim_ispathsep(p[-1])
2645 && (!has_mbyte || (*mb_head_off)(b, p - 1) == 0);
2646 }
2647 #endif
2648
2649 /*
2650 * Return TRUE if file names "f1" and "f2" are in the same directory.
2651 * "f1" may be a short name, "f2" must be a full path.
2652 */
2653 int
2654 same_directory(f1, f2)
2655 char_u *f1;
2656 char_u *f2;
2657 {
2658 char_u ffname[MAXPATHL];
2659 char_u *t1;
2660 char_u *t2;
2661
2662 /* safety check */
2663 if (f1 == NULL || f2 == NULL)
2664 return FALSE;
2665
2666 (void)vim_FullName(f1, ffname, MAXPATHL, FALSE);
2667 t1 = gettail_sep(ffname);
2668 t2 = gettail_sep(f2);
2669 return (t1 - ffname == t2 - f2
2670 && pathcmp((char *)ffname, (char *)f2, (int)(t1 - ffname)) == 0);
2671 }
2672
2648 #if defined(FEAT_SESSION) || defined(MSWIN) || defined(FEAT_GUI_MAC) \ 2673 #if defined(FEAT_SESSION) || defined(MSWIN) || defined(FEAT_GUI_MAC) \
2649 || ((defined(FEAT_GUI_GTK) || defined(FEAT_GUI_KDE)) \ 2674 || ((defined(FEAT_GUI_GTK) || defined(FEAT_GUI_KDE)) \
2650 && ( defined(FEAT_WINDOWS) || defined(FEAT_DND)) ) \ 2675 && ( defined(FEAT_WINDOWS) || defined(FEAT_DND)) ) \
2651 || defined(FEAT_SUN_WORKSHOP) || defined(FEAT_NETBEANS_INTG) \ 2676 || defined(FEAT_SUN_WORKSHOP) || defined(FEAT_NETBEANS_INTG) \
2652 || defined(PROTO) 2677 || defined(PROTO)
2657 */ 2682 */
2658 int 2683 int
2659 vim_chdirfile(fname) 2684 vim_chdirfile(fname)
2660 char_u *fname; 2685 char_u *fname;
2661 { 2686 {
2662 char_u temp_string[MAXPATHL]; 2687 char_u dir[MAXPATHL];
2663 char_u *p; 2688
2664 char_u *t; 2689 STRNCPY(dir, fname, MAXPATHL);
2665 2690 dir[MAXPATHL - 1] = NUL;
2666 STRCPY(temp_string, fname); 2691 *gettail_sep(dir) = NUL;
2667 p = get_past_head(temp_string); 2692 return mch_chdir((char *)dir) == 0 ? OK : FAIL;
2668 t = gettail(temp_string);
2669 while (t > p && vim_ispathsep(t[-1]))
2670 --t;
2671 *t = NUL; /* chop off end of string */
2672
2673 return mch_chdir((char *)temp_string) == 0 ? OK : FAIL;
2674 } 2693 }
2675 #endif 2694 #endif
2676 2695
2677 #if defined(STAT_IGNORES_SLASH) || defined(PROTO) 2696 #if defined(STAT_IGNORES_SLASH) || defined(PROTO)
2678 /* 2697 /*
5194 #endif 5213 #endif
5195 5214
5196 #if !defined(NO_EXPANDPATH) || defined(PROTO) 5215 #if !defined(NO_EXPANDPATH) || defined(PROTO)
5197 /* 5216 /*
5198 * Compare path "p[]" to "q[]". 5217 * Compare path "p[]" to "q[]".
5218 * If "maxlen" >= 0 compare "p[maxlen]" to "q[maxlen]"
5199 * Return value like strcmp(p, q), but consider path separators. 5219 * Return value like strcmp(p, q), but consider path separators.
5200 */ 5220 */
5201 int 5221 int
5202 pathcmp(p, q) 5222 pathcmp(p, q, maxlen)
5203 const char *p, *q; 5223 const char *p, *q;
5224 int maxlen;
5204 { 5225 {
5205 int i; 5226 int i;
5206 const char *s; 5227 const char *s;
5207 5228
5208 for (i = 0; ; ++i) 5229 for (i = 0; maxlen < 0 || i < maxlen; ++i)
5209 { 5230 {
5210 /* End of "p": check if "q" also ends or just has a slash. */ 5231 /* End of "p": check if "q" also ends or just has a slash. */
5211 if (p[i] == NUL) 5232 if (p[i] == NUL)
5212 { 5233 {
5213 if (q[i] == NUL) /* full match */ 5234 if (q[i] == NUL) /* full match */
5243 return ((char_u *)p)[i] - ((char_u *)q)[i]; /* no match */ 5264 return ((char_u *)p)[i] - ((char_u *)q)[i]; /* no match */
5244 } 5265 }
5245 } 5266 }
5246 5267
5247 /* ignore a trailing slash, but not "//" or ":/" */ 5268 /* ignore a trailing slash, but not "//" or ":/" */
5248 if (s[i + 1] == NUL && i > 0 && !vim_ispathsep(s[i - 1]) 5269 if (i >= maxlen
5270 || (s[i + 1] == NUL
5271 && i > 0
5272 && !after_pathsep((char_u *)s, (char_u *)s + i)
5249 #ifdef BACKSLASH_IN_FILENAME 5273 #ifdef BACKSLASH_IN_FILENAME
5250 && (s[i] == '/' || s[i] == '\\') 5274 && (s[i] == '/' || s[i] == '\\')
5251 #else 5275 #else
5252 && s[i] == '/' 5276 && s[i] == '/'
5253 #endif 5277 #endif
5254 ) 5278 ))
5255 return 0; /* match with trailing slash */ 5279 return 0; /* match with trailing slash */
5256 if (s == q) 5280 if (s == q)
5257 return -1; /* no match */ 5281 return -1; /* no match */
5258 return 1; 5282 return 1;
5259 } 5283 }