comparison src/scriptfile.c @ 32834:61389a392fe8 v9.0.1730

patch 9.0.1730: passing multiple patterns to runtime not working Commit: https://github.com/vim/vim/commit/008c91537b55835aa91cd8fbe1a139256581da31 Author: zeertzjq <zeertzjq@outlook.com> Date: Thu Aug 17 23:08:53 2023 +0200 patch 9.0.1730: passing multiple patterns to runtime not working Problem: passing multiple patterns to runtime not working Solution: prepend prefix to each argument separately closes: #12617 Signed-off-by: Christian Brabandt <cb@256bit.org> Co-authored-by: zeertzjq <zeertzjq@outlook.com>
author Christian Brabandt <cb@256bit.org>
date Thu, 17 Aug 2023 23:15:04 +0200
parents 695b50472e85
children 5d3c0f914f26
comparison
equal deleted inserted replaced
32833:29bbdd9b425b 32834:61389a392fe8
402 *ret_sid = sid; 402 *ret_sid = sid;
403 } 403 }
404 #endif 404 #endif
405 405
406 /* 406 /*
407 * Find the file "name" in all directories in "path" and invoke 407 * Find the patterns in "name" in all directories in "path" and invoke
408 * "callback(fname, cookie)". 408 * "callback(fname, cookie)".
409 * "name" can contain wildcards. 409 * "prefix" is prepended to each pattern in "name".
410 * When "flags" has DIP_ALL: source all files, otherwise only the first one. 410 * When "flags" has DIP_ALL: source all files, otherwise only the first one.
411 * When "flags" has DIP_DIR: find directories instead of files. 411 * When "flags" has DIP_DIR: find directories instead of files.
412 * When "flags" has DIP_ERR: give an error message if there is no match. 412 * When "flags" has DIP_ERR: give an error message if there is no match.
413 * 413 *
414 * return FAIL when no file could be sourced, OK otherwise. 414 * Return FAIL when no file could be sourced, OK otherwise.
415 */ 415 */
416 int 416 int
417 do_in_path( 417 do_in_path(
418 char_u *path, 418 char_u *path,
419 char *prefix,
419 char_u *name, 420 char_u *name,
420 int flags, 421 int flags,
421 void (*callback)(char_u *fname, void *ck), 422 void (*callback)(char_u *fname, void *ck),
422 void *cookie) 423 void *cookie)
423 { 424 {
445 if (buf != NULL && rtp_copy != NULL) 446 if (buf != NULL && rtp_copy != NULL)
446 { 447 {
447 if (p_verbose > 10 && name != NULL) 448 if (p_verbose > 10 && name != NULL)
448 { 449 {
449 verbose_enter(); 450 verbose_enter();
450 smsg(_("Searching for \"%s\" in \"%s\""), 451 if (*prefix != NUL)
451 (char *)name, (char *)path); 452 smsg(_("Searching for \"%s\" under \"%s\" in \"%s\""),
453 (char *)name, prefix, (char *)path);
454 else
455 smsg(_("Searching for \"%s\" in \"%s\""),
456 (char *)name, (char *)path);
452 verbose_leave(); 457 verbose_leave();
453 } 458 }
454 459
455 // Loop over all entries in 'runtimepath'. 460 // Loop over all entries in 'runtimepath'.
456 rtp = rtp_copy; 461 rtp = rtp_copy;
477 { 482 {
478 (*callback)(buf, (void *) &cookie); 483 (*callback)(buf, (void *) &cookie);
479 if (!did_one) 484 if (!did_one)
480 did_one = (cookie == NULL); 485 did_one = (cookie == NULL);
481 } 486 }
482 else if (buflen + STRLEN(name) + 2 < MAXPATHL) 487 else if (buflen + 2 + STRLEN(prefix) + STRLEN(name) < MAXPATHL)
483 { 488 {
484 add_pathsep(buf); 489 add_pathsep(buf);
490 STRCAT(buf, prefix);
485 tail = buf + STRLEN(buf); 491 tail = buf + STRLEN(buf);
486 492
487 // Loop over all patterns in "name" 493 // Loop over all patterns in "name"
488 np = name; 494 np = name;
489 while (*np != NUL && ((flags & DIP_ALL) || !did_one)) 495 while (*np != NUL && ((flags & DIP_ALL) || !did_one))
557 int flags, 563 int flags,
558 void (*callback)(char_u *fname, void *ck), 564 void (*callback)(char_u *fname, void *ck),
559 void *cookie) 565 void *cookie)
560 { 566 {
561 int done = FAIL; 567 int done = FAIL;
562 char_u *s;
563 int len;
564 char *start_dir = "pack/*/start/*/%s";
565 char *opt_dir = "pack/*/opt/*/%s";
566 568
567 if ((flags & DIP_NORTP) == 0) 569 if ((flags & DIP_NORTP) == 0)
568 done = do_in_path(path, name, flags, callback, cookie); 570 done = do_in_path(path, "", name, flags, callback, cookie);
569 571
570 if ((done == FAIL || (flags & DIP_ALL)) && (flags & DIP_START)) 572 if ((done == FAIL || (flags & DIP_ALL)) && (flags & DIP_START))
571 { 573 done = do_in_path(p_pp, "pack/*/start/*/", name, flags, callback,
572 len = (int)(STRLEN(start_dir) + STRLEN(name)); 574 cookie);
573 s = alloc(len);
574 if (s == NULL)
575 return FAIL;
576 vim_snprintf((char *)s, len, start_dir, name);
577 done = do_in_path(p_pp, s, flags, callback, cookie);
578 vim_free(s);
579 }
580 575
581 if ((done == FAIL || (flags & DIP_ALL)) && (flags & DIP_OPT)) 576 if ((done == FAIL || (flags & DIP_ALL)) && (flags & DIP_OPT))
582 { 577 done = do_in_path(p_pp, "pack/*/opt/*/", name, flags, callback,
583 len = (int)(STRLEN(opt_dir) + STRLEN(name)); 578 cookie);
584 s = alloc(len);
585 if (s == NULL)
586 return FAIL;
587 vim_snprintf((char *)s, len, opt_dir, name);
588 done = do_in_path(p_pp, s, flags, callback, cookie);
589 vim_free(s);
590 }
591 579
592 return done; 580 return done;
593 } 581 }
594 582
595 /* 583 /*
897 * Add all packages in the "start" directory to 'runtimepath'. 885 * Add all packages in the "start" directory to 'runtimepath'.
898 */ 886 */
899 void 887 void
900 add_pack_start_dirs(void) 888 add_pack_start_dirs(void)
901 { 889 {
902 do_in_path(p_pp, (char_u *)"pack/*/start/*", DIP_ALL + DIP_DIR, 890 do_in_path(p_pp, "", (char_u *)"pack/*/start/*", DIP_ALL + DIP_DIR,
903 add_pack_plugin, &APP_ADD_DIR); 891 add_pack_plugin, &APP_ADD_DIR);
904 } 892 }
905 893
906 /* 894 /*
907 * Load plugins from all packages in the "start" directory. 895 * Load plugins from all packages in the "start" directory.
908 */ 896 */
909 void 897 void
910 load_start_packages(void) 898 load_start_packages(void)
911 { 899 {
912 did_source_packages = TRUE; 900 did_source_packages = TRUE;
913 do_in_path(p_pp, (char_u *)"pack/*/start/*", DIP_ALL + DIP_DIR, 901 do_in_path(p_pp, "", (char_u *)"pack/*/start/*", DIP_ALL + DIP_DIR,
914 add_pack_plugin, &APP_LOAD); 902 add_pack_plugin, &APP_LOAD);
915 } 903 }
916 904
917 /* 905 /*
918 * ":packloadall" 906 * ":packloadall"
955 if (pat == NULL) 943 if (pat == NULL)
956 return; 944 return;
957 vim_snprintf(pat, len, plugpat, round == 1 ? "start" : "opt", eap->arg); 945 vim_snprintf(pat, len, plugpat, round == 1 ? "start" : "opt", eap->arg);
958 // The first round don't give a "not found" error, in the second round 946 // The first round don't give a "not found" error, in the second round
959 // only when nothing was found in the first round. 947 // only when nothing was found in the first round.
960 res = do_in_path(p_pp, (char_u *)pat, 948 res = do_in_path(p_pp, "", (char_u *)pat,
961 DIP_ALL + DIP_DIR + (round == 2 && res == FAIL ? DIP_ERR : 0), 949 DIP_ALL + DIP_DIR + (round == 2 && res == FAIL ? DIP_ERR : 0),
962 add_pack_plugin, eap->forceit ? &APP_ADD_DIR : &APP_BOTH); 950 add_pack_plugin, eap->forceit ? &APP_ADD_DIR : &APP_BOTH);
963 vim_free(pat); 951 vim_free(pat);
964 } 952 }
965 } 953 }