comparison src/filepath.c @ 22389:995f5e061e27 v8.2.1743

patch 8.2.1743: cannot build without the eval feature Commit: https://github.com/vim/vim/commit/273af497cac345897cf6369baa87a070876a5815 Author: Bram Moolenaar <Bram@vim.org> Date: Fri Sep 25 23:49:01 2020 +0200 patch 8.2.1743: cannot build without the eval feature Problem: Cannot build without the eval feature. Solution: Move shorten_dir outside of #ifdef.
author Bram Moolenaar <Bram@vim.org>
date Sat, 26 Sep 2020 00:00:04 +0200
parents 770fe121ca64
children aeeee593fe0f
comparison
equal deleted inserted replaced
22388:8d9d6be4de03 22389:995f5e061e27
708 } 708 }
709 709
710 return valid; 710 return valid;
711 } 711 }
712 712
713 /*
714 * Shorten the path of a file from "~/foo/../.bar/fname" to "~/f/../.b/fname"
715 * "trim_len" specifies how many characters to keep for each directory.
716 * Must be 1 or more.
717 * It's done in-place.
718 */
719 static void
720 shorten_dir_len(char_u *str, int trim_len)
721 {
722 char_u *tail, *s, *d;
723 int skip = FALSE;
724 int dirchunk_len = 0;
725
726 tail = gettail(str);
727 d = str;
728 for (s = str; ; ++s)
729 {
730 if (s >= tail) // copy the whole tail
731 {
732 *d++ = *s;
733 if (*s == NUL)
734 break;
735 }
736 else if (vim_ispathsep(*s)) // copy '/' and next char
737 {
738 *d++ = *s;
739 skip = FALSE;
740 dirchunk_len = 0;
741 }
742 else if (!skip)
743 {
744 *d++ = *s; // copy next char
745 if (*s != '~' && *s != '.') // and leading "~" and "."
746 {
747 ++dirchunk_len; // only count word chars for the size
748
749 // keep copying chars until we have our preferred length (or
750 // until the above if/else branches move us along)
751 if (dirchunk_len >= trim_len)
752 skip = TRUE;
753 }
754
755 if (has_mbyte)
756 {
757 int l = mb_ptr2len(s);
758
759 while (--l > 0)
760 *d++ = *++s;
761 }
762 }
763 }
764 }
765
766 /*
767 * Shorten the path of a file from "~/foo/../.bar/fname" to "~/f/../.b/fname"
768 * It's done in-place.
769 */
770 void
771 shorten_dir(char_u *str)
772 {
773 shorten_dir_len(str, 1);
774 }
775
713 #if defined(FEAT_EVAL) || defined(PROTO) 776 #if defined(FEAT_EVAL) || defined(PROTO)
714 777
715 /* 778 /*
716 * "chdir(dir)" function 779 * "chdir(dir)" function
717 */ 780 */
1347 } 1410 }
1348 mkdir_recurse(dir, prot); 1411 mkdir_recurse(dir, prot);
1349 } 1412 }
1350 } 1413 }
1351 rettv->vval.v_number = vim_mkdir_emsg(dir, prot); 1414 rettv->vval.v_number = vim_mkdir_emsg(dir, prot);
1352 }
1353
1354 /*
1355 * Shorten the path of a file from "~/foo/../.bar/fname" to "~/f/../.b/fname"
1356 * "trim_len" specifies how many characters to keep for each directory.
1357 * Must be 1 or more.
1358 * It's done in-place.
1359 */
1360 static void
1361 shorten_dir_len(char_u *str, int trim_len)
1362 {
1363 char_u *tail, *s, *d;
1364 int skip = FALSE;
1365 int dirchunk_len = 0;
1366
1367 tail = gettail(str);
1368 d = str;
1369 for (s = str; ; ++s)
1370 {
1371 if (s >= tail) // copy the whole tail
1372 {
1373 *d++ = *s;
1374 if (*s == NUL)
1375 break;
1376 }
1377 else if (vim_ispathsep(*s)) // copy '/' and next char
1378 {
1379 *d++ = *s;
1380 skip = FALSE;
1381 dirchunk_len = 0;
1382 }
1383 else if (!skip)
1384 {
1385 *d++ = *s; // copy next char
1386 if (*s != '~' && *s != '.') // and leading "~" and "."
1387 {
1388 ++dirchunk_len; // only count word chars for the size
1389
1390 // keep copying chars until we have our preferred length (or
1391 // until the above if/else branches move us along)
1392 if (dirchunk_len >= trim_len)
1393 skip = TRUE;
1394 }
1395
1396 if (has_mbyte)
1397 {
1398 int l = mb_ptr2len(s);
1399
1400 while (--l > 0)
1401 *d++ = *++s;
1402 }
1403 }
1404 }
1405 }
1406
1407 /*
1408 * Shorten the path of a file from "~/foo/../.bar/fname" to "~/f/../.b/fname"
1409 * It's done in-place.
1410 */
1411 void
1412 shorten_dir(char_u *str)
1413 {
1414 shorten_dir_len(str, 1);
1415 } 1415 }
1416 1416
1417 /* 1417 /*
1418 * "pathshorten()" function 1418 * "pathshorten()" function
1419 */ 1419 */