Mirror of the Vim source from https://github.com/vim/vim
Révision | 6edf4a4f6cac62dd123f7d1017a7624c9f48e71c (tree) |
---|---|
l'heure | 2005-07-20 07:22:13 |
Auteur | vimboss |
Commiter | vimboss |
updated for version 7.0110
@@ -12765,30 +12765,15 @@ | ||
12765 | 12765 | { |
12766 | 12766 | char_u *spat, *mpat, *epat; |
12767 | 12767 | char_u *skip; |
12768 | - char_u *pat, *pat2 = NULL, *pat3 = NULL; | |
12769 | - pos_T pos; | |
12770 | - pos_T firstpos; | |
12771 | - pos_T foundpos; | |
12772 | - pos_T save_cursor; | |
12773 | - pos_T save_pos; | |
12774 | 12768 | int save_p_ws = p_ws; |
12775 | - char_u *save_cpo; | |
12776 | 12769 | int dir; |
12777 | 12770 | int flags = 0; |
12778 | 12771 | char_u nbuf1[NUMBUFLEN]; |
12779 | 12772 | char_u nbuf2[NUMBUFLEN]; |
12780 | 12773 | char_u nbuf3[NUMBUFLEN]; |
12781 | - int n; | |
12782 | - int r; | |
12783 | - int nest = 1; | |
12784 | - int err; | |
12785 | 12774 | |
12786 | 12775 | rettv->vval.v_number = 0; /* default: FAIL */ |
12787 | 12776 | |
12788 | - /* Make 'cpoptions' empty, the 'l' flag should not be used here. */ | |
12789 | - save_cpo = p_cpo; | |
12790 | - p_cpo = (char_u *)""; | |
12791 | - | |
12792 | 12777 | /* Get the three pattern arguments: start, middle, end. */ |
12793 | 12778 | spat = get_tv_string_chk(&argvars[0]); |
12794 | 12779 | mpat = get_tv_string_buf_chk(&argvars[1], nbuf1); |
@@ -12796,19 +12781,6 @@ | ||
12796 | 12781 | if (spat == NULL || mpat == NULL || epat == NULL) |
12797 | 12782 | goto theend; /* type error */ |
12798 | 12783 | |
12799 | - /* Make two search patterns: start/end (pat2, for in nested pairs) and | |
12800 | - * start/middle/end (pat3, for the top pair). */ | |
12801 | - pat2 = alloc((unsigned)(STRLEN(spat) + STRLEN(epat) + 15)); | |
12802 | - pat3 = alloc((unsigned)(STRLEN(spat) + STRLEN(mpat) + STRLEN(epat) + 23)); | |
12803 | - if (pat2 == NULL || pat3 == NULL) | |
12804 | - goto theend; | |
12805 | - sprintf((char *)pat2, "\\(%s\\m\\)\\|\\(%s\\m\\)", spat, epat); | |
12806 | - if (*mpat == NUL) | |
12807 | - STRCPY(pat3, pat2); | |
12808 | - else | |
12809 | - sprintf((char *)pat3, "\\(%s\\m\\)\\|\\(%s\\m\\)\\|\\(%s\\m\\)", | |
12810 | - spat, epat, mpat); | |
12811 | - | |
12812 | 12784 | /* Handle the optional fourth argument: flags */ |
12813 | 12785 | dir = get_search_arg(&argvars[3], &flags); /* may set p_ws */ |
12814 | 12786 | if (dir == 0) |
@@ -12823,6 +12795,56 @@ | ||
12823 | 12795 | if (skip == NULL) |
12824 | 12796 | goto theend; /* type error */ |
12825 | 12797 | |
12798 | + rettv->vval.v_number = do_searchpair(spat, mpat, epat, dir, skip, flags); | |
12799 | + | |
12800 | +theend: | |
12801 | + p_ws = save_p_ws; | |
12802 | +} | |
12803 | + | |
12804 | +/* | |
12805 | + * Search for a start/middle/end thing. | |
12806 | + * Used by searchpair(), see its documentation for the details. | |
12807 | + * Returns 0 or -1 for no match, | |
12808 | + */ | |
12809 | + long | |
12810 | +do_searchpair(spat, mpat, epat, dir, skip, flags) | |
12811 | + char_u *spat; /* start pattern */ | |
12812 | + char_u *mpat; /* middle pattern */ | |
12813 | + char_u *epat; /* end pattern */ | |
12814 | + int dir; /* BACKWARD or FORWARD */ | |
12815 | + char_u *skip; /* skip expression */ | |
12816 | + int flags; /* SP_RETCOUNT, SP_REPEAT, SP_NOMOVE */ | |
12817 | +{ | |
12818 | + char_u *save_cpo; | |
12819 | + char_u *pat, *pat2 = NULL, *pat3 = NULL; | |
12820 | + long retval = 0; | |
12821 | + pos_T pos; | |
12822 | + pos_T firstpos; | |
12823 | + pos_T foundpos; | |
12824 | + pos_T save_cursor; | |
12825 | + pos_T save_pos; | |
12826 | + int n; | |
12827 | + int r; | |
12828 | + int nest = 1; | |
12829 | + int err; | |
12830 | + | |
12831 | + /* Make 'cpoptions' empty, the 'l' flag should not be used here. */ | |
12832 | + save_cpo = p_cpo; | |
12833 | + p_cpo = (char_u *)""; | |
12834 | + | |
12835 | + /* Make two search patterns: start/end (pat2, for in nested pairs) and | |
12836 | + * start/middle/end (pat3, for the top pair). */ | |
12837 | + pat2 = alloc((unsigned)(STRLEN(spat) + STRLEN(epat) + 15)); | |
12838 | + pat3 = alloc((unsigned)(STRLEN(spat) + STRLEN(mpat) + STRLEN(epat) + 23)); | |
12839 | + if (pat2 == NULL || pat3 == NULL) | |
12840 | + goto theend; | |
12841 | + sprintf((char *)pat2, "\\(%s\\m\\)\\|\\(%s\\m\\)", spat, epat); | |
12842 | + if (*mpat == NUL) | |
12843 | + STRCPY(pat3, pat2); | |
12844 | + else | |
12845 | + sprintf((char *)pat3, "\\(%s\\m\\)\\|\\(%s\\m\\)\\|\\(%s\\m\\)", | |
12846 | + spat, epat, mpat); | |
12847 | + | |
12826 | 12848 | save_cursor = curwin->w_cursor; |
12827 | 12849 | pos = curwin->w_cursor; |
12828 | 12850 | firstpos.lnum = 0; |
@@ -12861,7 +12883,7 @@ | ||
12861 | 12883 | { |
12862 | 12884 | /* Evaluating {skip} caused an error, break here. */ |
12863 | 12885 | curwin->w_cursor = save_cursor; |
12864 | - rettv->vval.v_number = -1; | |
12886 | + retval = -1; | |
12865 | 12887 | break; |
12866 | 12888 | } |
12867 | 12889 | if (r) |
@@ -12887,9 +12909,9 @@ | ||
12887 | 12909 | { |
12888 | 12910 | /* Found the match: return matchcount or line number. */ |
12889 | 12911 | if (flags & SP_RETCOUNT) |
12890 | - ++rettv->vval.v_number; | |
12891 | - else | |
12892 | - rettv->vval.v_number = pos.lnum; | |
12912 | + ++retval; | |
12913 | + else | |
12914 | + retval = pos.lnum; | |
12893 | 12915 | curwin->w_cursor = pos; |
12894 | 12916 | if (!(flags & SP_REPEAT)) |
12895 | 12917 | break; |
@@ -12898,14 +12920,15 @@ | ||
12898 | 12920 | } |
12899 | 12921 | |
12900 | 12922 | /* If 'n' flag is used or search failed: restore cursor position. */ |
12901 | - if ((flags & SP_NOMOVE) || rettv->vval.v_number == 0) | |
12923 | + if ((flags & SP_NOMOVE) || retval == 0) | |
12902 | 12924 | curwin->w_cursor = save_cursor; |
12903 | 12925 | |
12904 | 12926 | theend: |
12905 | 12927 | vim_free(pat2); |
12906 | 12928 | vim_free(pat3); |
12907 | - p_ws = save_p_ws; | |
12908 | 12929 | p_cpo = save_cpo; |
12930 | + | |
12931 | + return retval; | |
12909 | 12932 | } |
12910 | 12933 | |
12911 | 12934 | /*ARGSUSED*/ |