diff options
Diffstat (limited to 'src/search.c')
-rw-r--r-- | src/search.c | 330 |
1 files changed, 149 insertions, 181 deletions
diff --git a/src/search.c b/src/search.c index 6007b53375..a46637efdb 100644 --- a/src/search.c +++ b/src/search.c @@ -113,12 +113,14 @@ typedef struct SearchedFile { * * returns FAIL if failed, OK otherwise. */ -int search_regcomp(pat, pat_save, pat_use, options, regmatch) -char_u *pat; -int pat_save; -int pat_use; -int options; -regmmatch_T *regmatch; /* return: pattern and ignore-case flag */ +int +search_regcomp ( + char_u *pat, + int pat_save, + int pat_use, + int options, + regmmatch_T *regmatch /* return: pattern and ignore-case flag */ +) { int magic; int i; @@ -190,7 +192,7 @@ regmmatch_T *regmatch; /* return: pattern and ignore-case flag */ /* * Get search pattern used by search_regcomp(). */ -char_u * get_search_pat() { +char_u *get_search_pat(void) { return mr_pattern; } @@ -198,8 +200,7 @@ char_u * get_search_pat() { * Reverse text into allocated memory. * Returns the allocated string, NULL when out of memory. */ -char_u * reverse_text(s) -char_u *s; +char_u *reverse_text(char_u *s) { unsigned len; unsigned s_i, rev_i; @@ -229,10 +230,7 @@ char_u *s; return rev; } -static void save_re_pat(idx, pat, magic) -int idx; -char_u *pat; -int magic; +static void save_re_pat(int idx, char_u *pat, int magic) { if (spats[idx].pat != pat) { vim_free(spats[idx].pat); @@ -253,7 +251,7 @@ int magic; */ static int save_level = 0; -void save_search_patterns() { +void save_search_patterns(void) { if (save_level++ == 0) { saved_spats[0] = spats[0]; if (spats[0].pat != NULL) @@ -266,7 +264,7 @@ void save_search_patterns() { } } -void restore_search_patterns() { +void restore_search_patterns(void) { if (--save_level == 0) { vim_free(spats[0].pat); spats[0] = saved_spats[0]; @@ -279,7 +277,7 @@ void restore_search_patterns() { } #if defined(EXITFREE) || defined(PROTO) -void free_search_patterns() { +void free_search_patterns(void) { vim_free(spats[0].pat); vim_free(spats[1].pat); @@ -296,8 +294,7 @@ void free_search_patterns() { * Return TRUE when case should be ignored for search pattern "pat". * Uses the 'ignorecase' and 'smartcase' options. */ -int ignorecase(pat) -char_u *pat; +int ignorecase(char_u *pat) { int ic = p_ic; @@ -313,8 +310,7 @@ char_u *pat; /* * Return TRUE if patter "pat" has an uppercase character. */ -int pat_has_uppercase(pat) -char_u *pat; +int pat_has_uppercase(char_u *pat) { char_u *p = pat; @@ -342,14 +338,14 @@ char_u *pat; return FALSE; } -char_u * last_search_pat() { +char_u *last_search_pat(void) { return spats[last_idx].pat; } /* * Reset search direction to forward. For "gd" and "gD" commands. */ -void reset_search_dir() { +void reset_search_dir(void) { spats[0].off.dir = '/'; set_vv_searchforward(); } @@ -358,11 +354,7 @@ void reset_search_dir() { * Set the last search pattern. For ":let @/ =" and viminfo. * Also set the saved search pattern, so that this works in an autocommand. */ -void set_last_search_pat(s, idx, magic, setlast) -char_u *s; -int idx; -int magic; -int setlast; +void set_last_search_pat(char_u *s, int idx, int magic, int setlast) { vim_free(spats[idx].pat); /* An empty string means that nothing should be matched. */ @@ -398,8 +390,7 @@ int setlast; * This is used for highlighting all matches in a window. * Values returned in regmatch->regprog and regmatch->rmm_ic. */ -void last_pat_prog(regmatch) -regmmatch_T *regmatch; +void last_pat_prog(regmmatch_T *regmatch) { if (spats[last_idx].pat == NULL) { regmatch->regprog = NULL; @@ -440,7 +431,7 @@ long count; int options; int pat_use; /* which pattern to use when "pat" is empty */ linenr_T stop_lnum; /* stop after this line number when != 0 */ -proftime_T *tm UNUSED; /* timeout limit or NULL */ +proftime_T *tm; /* timeout limit or NULL */ { int found; linenr_T lnum; /* no init to shut up Apollo cc */ @@ -827,21 +818,19 @@ proftime_T *tm UNUSED; /* timeout limit or NULL */ return submatch + 1; } -void set_search_direction(cdir) -int cdir; +void set_search_direction(int cdir) { spats[0].off.dir = cdir; } -static void set_vv_searchforward() { +static void set_vv_searchforward(void) { set_vim_var_nr(VV_SEARCHFORWARD, (long)(spats[0].off.dir == '/')); } /* * Return the number of the first subpat that matched. */ -static int first_submatch(rp) -regmmatch_T *rp; +static int first_submatch(regmmatch_T *rp) { int submatch; @@ -1208,11 +1197,7 @@ end_do_search: * ADDING is set. if p_ic is set then the pattern must be in lowercase. * Return OK for success, or FAIL if no line found. */ -int search_for_exact_line(buf, pos, dir, pat) -buf_T *buf; -pos_T *pos; -int dir; -char_u *pat; +int search_for_exact_line(buf_T *buf, pos_T *pos, int dir, char_u *pat) { linenr_T start = 0; char_u *ptr; @@ -1275,9 +1260,7 @@ char_u *pat; * Do this "cap->count1" times. * Return FAIL or OK. */ -int searchc(cap, t_cmd) -cmdarg_T *cap; -int t_cmd; +int searchc(cmdarg_T *cap, int t_cmd) { int c = cap->nchar; /* char to search for */ int dir = cap->arg; /* TRUE for searching forward */ @@ -1389,9 +1372,7 @@ int t_cmd; * * Improvement over vi: Braces inside quotes are ignored. */ -pos_T * findmatch(oap, initc) -oparg_T *oap; -int initc; +pos_T *findmatch(oparg_T *oap, int initc) { return findmatchlimit(oap, initc, 0, 0); } @@ -1403,11 +1384,7 @@ int initc; * is NULL. * Handles multibyte string correctly. */ -static int check_prevcol(linep, col, ch, prevcol) -char_u *linep; -int col; -int ch; -int *prevcol; +static int check_prevcol(char_u *linep, int col, int ch, int *prevcol) { --col; if (col > 0 && has_mbyte) @@ -1434,11 +1411,7 @@ int *prevcol; * NULL */ -pos_T * findmatchlimit(oap, initc, flags, maxtravel) -oparg_T *oap; -int initc; -int flags; -int maxtravel; +pos_T *findmatchlimit(oparg_T *oap, int initc, int flags, int maxtravel) { static pos_T pos; /* current search position */ int findc = 0; /* matching brace */ @@ -1945,8 +1918,7 @@ int maxtravel; * Return MAXCOL if not, otherwise return the column. * TODO: skip strings. */ -static int check_linecomment(line) -char_u *line; +static int check_linecomment(char_u *line) { char_u *p; @@ -1993,8 +1965,10 @@ char_u *line; * Show the match only if it is visible on the screen. * If there isn't a match, then beep. */ -void showmatch(c) -int c; /* char to show match for */ +void +showmatch ( + int c /* char to show match for */ +) { pos_T *lpos, save_cursor; pos_T mpos; @@ -2085,9 +2059,7 @@ int c; /* char to show match for */ * space or a line break. Also stop at an empty line. * Return OK if the next sentence was found. */ -int findsent(dir, count) -int dir; -long count; +int findsent(int dir, long count) { pos_T pos, tpos; int c; @@ -2201,12 +2173,14 @@ found: * If 'both' is TRUE also stop at '}'. * Return TRUE if the next paragraph or section was found. */ -int findpar(pincl, dir, count, what, both) -int *pincl; /* Return: TRUE if last char is to be included */ -int dir; -long count; -int what; -int both; +int +findpar ( + int *pincl, /* Return: TRUE if last char is to be included */ + int dir, + long count, + int what, + int both +) { linenr_T curr; int did_skip; /* TRUE after separating lines have been skipped */ @@ -2267,9 +2241,7 @@ int both; /* * check if the string 's' is a nroff macro that is in option 'opt' */ -static int inmacro(opt, s) -char_u *opt; -char_u *s; +static int inmacro(char_u *opt, char_u *s) { char_u *macro; @@ -2296,10 +2268,7 @@ char_u *s; * If 'para' is '{' or '}' only check for sections. * If 'both' is TRUE also stop at '}' */ -int startPS(lnum, para, both) -linenr_T lnum; -int para; -int both; +int startPS(linenr_T lnum, int para, int both) { char_u *s; @@ -2337,7 +2306,7 @@ static int cls_bigword; /* TRUE for "W", "B" or "E" */ * from class 2 and higher are reported as class 1 since only white space * boundaries are of interest. */ -static int cls() { +static int cls(void) { int c; c = gchar_cursor(); @@ -2375,10 +2344,12 @@ static int cls() { * Returns FAIL if the cursor was already at the end of the file. * If eol is TRUE, last word stops at end of line (for operators). */ -int fwd_word(count, bigword, eol) -long count; -int bigword; /* "W", "E" or "B" */ -int eol; +int +fwd_word ( + long count, + int bigword, /* "W", "E" or "B" */ + int eol +) { int sclass; /* starting class */ int i; @@ -2439,10 +2410,7 @@ int eol; * * Returns FAIL if top of the file was reached. */ -int bck_word(count, bigword, stop) -long count; -int bigword; -int stop; +int bck_word(long count, int bigword, int stop) { int sclass; /* starting class */ @@ -2499,11 +2467,7 @@ finished: * If stop is TRUE and we are already on the end of a word, move one less. * If empty is TRUE stop on an empty line. */ -int end_word(count, bigword, stop, empty) -long count; -int bigword; -int stop; -int empty; +int end_word(long count, int bigword, int stop, int empty) { int sclass; /* starting class */ @@ -2559,10 +2523,12 @@ finished: * * Returns FAIL if start of the file was reached. */ -int bckend_word(count, bigword, eol) -long count; -int bigword; /* TRUE for "B" */ -int eol; /* TRUE: stop at end of line. */ +int +bckend_word ( + long count, + int bigword, /* TRUE for "B" */ + int eol /* TRUE: stop at end of line. */ +) { int sclass; /* starting class */ int i; @@ -2602,9 +2568,7 @@ int eol; /* TRUE: stop at end of line. */ * Skip a row of characters of the same class. * Return TRUE when end-of-file reached, FALSE otherwise. */ -static int skip_chars(cclass, dir) -int cclass; -int dir; +static int skip_chars(int cclass, int dir) { while (cls() == cclass) if ((dir == FORWARD ? inc_cursor() : dec_cursor()) == -1) @@ -2615,7 +2579,7 @@ int dir; /* * Go back to the start of the word or the start of white space */ -static void back_in_line() { +static void back_in_line(void) { int sclass; /* starting class */ sclass = cls(); @@ -2630,8 +2594,7 @@ static void back_in_line() { } } -static void find_first_blank(posp) -pos_T *posp; +static void find_first_blank(pos_T *posp) { int c; @@ -2647,9 +2610,11 @@ pos_T *posp; /* * Skip count/2 sentences and count/2 separating white spaces. */ -static void findsent_forward(count, at_start_sent) -long count; -int at_start_sent; /* cursor is at start of sentence */ +static void +findsent_forward ( + long count, + int at_start_sent /* cursor is at start of sentence */ +) { while (count--) { findsent(FORWARD, 1L); @@ -2665,11 +2630,13 @@ int at_start_sent; /* cursor is at start of sentence */ * Find word under cursor, cursor at end. * Used while an operator is pending, and in Visual mode. */ -int current_word(oap, count, include, bigword) -oparg_T *oap; -long count; -int include; /* TRUE: include word and white space */ -int bigword; /* FALSE == word, TRUE == WORD */ +int +current_word ( + oparg_T *oap, + long count, + int include, /* TRUE: include word and white space */ + int bigword /* FALSE == word, TRUE == WORD */ +) { pos_T start_pos; pos_T pos; @@ -2815,10 +2782,7 @@ int bigword; /* FALSE == word, TRUE == WORD */ * Find sentence(s) under the cursor, cursor at end. * When Visual active, extend it by one or more sentences. */ -int current_sent(oap, count, include) -oparg_T *oap; -long count; -int include; +int current_sent(oparg_T *oap, long count, int include) { pos_T start_pos; pos_T pos; @@ -2973,12 +2937,14 @@ extend: * Find block under the cursor, cursor at end. * "what" and "other" are two matching parenthesis/brace/etc. */ -int current_block(oap, count, include, what, other) -oparg_T *oap; -long count; -int include; /* TRUE == include white space */ -int what; /* '(', '{', etc. */ -int other; /* ')', '}', etc. */ +int +current_block ( + oparg_T *oap, + long count, + int include, /* TRUE == include white space */ + int what, /* '(', '{', etc. */ + int other /* ')', '}', etc. */ +) { pos_T old_pos; pos_T *pos = NULL; @@ -3106,8 +3072,7 @@ static int in_html_tag __ARGS((int)); * Return TRUE if the cursor is on a "<aaa>" tag. Ignore "<aaa/>". * When "end_tag" is TRUE return TRUE if the cursor is on "</aaa>". */ -static int in_html_tag(end_tag) -int end_tag; +static int in_html_tag(int end_tag) { char_u *line = ml_get_curline(); char_u *p; @@ -3169,10 +3134,12 @@ int end_tag; /* * Find tag block under the cursor, cursor at end. */ -int current_tagblock(oap, count_arg, include) -oparg_T *oap; -long count_arg; -int include; /* TRUE == include white space */ +int +current_tagblock ( + oparg_T *oap, + long count_arg, + int include /* TRUE == include white space */ +) { long count = count_arg; long n; @@ -3344,11 +3311,13 @@ theend: return retval; } -int current_par(oap, count, include, type) -oparg_T *oap; -long count; -int include; /* TRUE == include white space */ -int type; /* 'p' for paragraph, 'S' for section */ +int +current_par ( + oparg_T *oap, + long count, + int include, /* TRUE == include white space */ + int type /* 'p' for paragraph, 'S' for section */ +) { linenr_T start_lnum; linenr_T end_lnum; @@ -3509,11 +3478,13 @@ static int find_prev_quote __ARGS((char_u *line, int col_start, int quotechar, * as a quote. * Returns column number of "quotechar" or -1 when not found. */ -static int find_next_quote(line, col, quotechar, escape) -char_u *line; -int col; -int quotechar; -char_u *escape; /* escape characters, can be NULL */ +static int +find_next_quote ( + char_u *line, + int col, + int quotechar, + char_u *escape /* escape characters, can be NULL */ +) { int c; @@ -3539,11 +3510,13 @@ char_u *escape; /* escape characters, can be NULL */ * as a quote. * Return the found column or zero. */ -static int find_prev_quote(line, col_start, quotechar, escape) -char_u *line; -int col_start; -int quotechar; -char_u *escape; /* escape characters, can be NULL */ +static int +find_prev_quote ( + char_u *line, + int col_start, + int quotechar, + char_u *escape /* escape characters, can be NULL */ +) { int n; @@ -3567,11 +3540,13 @@ char_u *escape; /* escape characters, can be NULL */ * Find quote under the cursor, cursor at end. * Returns TRUE if found, else FALSE. */ -int current_quote(oap, count, include, quotechar) -oparg_T *oap; -long count; -int include; /* TRUE == include quote char */ -int quotechar; /* Quote character */ +int +current_quote ( + oparg_T *oap, + long count, + int include, /* TRUE == include quote char */ + int quotechar /* Quote character */ +) { char_u *line = ml_get_curline(); int col_end; @@ -3779,9 +3754,11 @@ static int is_one_char __ARGS((char_u *pattern)); * Used while an operator is pending, and in Visual mode. * TODO: redo only works when used in operator pending mode */ -int current_search(count, forward) -long count; -int forward; /* move forward or backwards */ +int +current_search ( + long count, + int forward /* move forward or backwards */ +) { pos_T start_pos; /* position before the pattern */ pos_T orig_pos; /* position of the cursor at beginning */ @@ -3909,8 +3886,7 @@ int forward; /* move forward or backwards */ * Check if the pattern is one character or zero-width. * Returns TRUE, FALSE or -1 for failure. */ -static int is_one_char(pattern) -char_u *pattern; +static int is_one_char(char_u *pattern) { regmmatch_T regmatch; int nmatched = 0; @@ -3951,8 +3927,7 @@ char_u *pattern; /* * return TRUE if line 'lnum' is empty or has white chars only. */ -int linewhite(lnum) -linenr_T lnum; +int linewhite(linenr_T lnum) { char_u *p; @@ -3965,19 +3940,20 @@ linenr_T lnum; * Find identifiers or defines in included files. * If p_ic && (compl_cont_status & CONT_SOL) then ptr must be in lowercase. */ -void find_pattern_in_path(ptr, dir, len, whole, skip_comments, - type, count, action, start_lnum, end_lnum) -char_u *ptr; /* pointer to search pattern */ -int dir UNUSED; /* direction of expansion */ -int len; /* length of search pattern */ -int whole; /* match whole words only */ -int skip_comments; /* don't match inside comments */ -int type; /* Type of search; are we looking for a type? +void +find_pattern_in_path ( + char_u *ptr, /* pointer to search pattern */ + int dir, /* direction of expansion */ + int len, /* length of search pattern */ + int whole, /* match whole words only */ + int skip_comments, /* don't match inside comments */ + int type, /* Type of search; are we looking for a type? a macro? */ -long count; -int action; /* What to do when we find it */ -linenr_T start_lnum; /* first line to start searching */ -linenr_T end_lnum; /* last line for searching */ + long count, + int action, /* What to do when we find it */ + linenr_T start_lnum, /* first line to start searching */ + linenr_T end_lnum /* last line for searching */ +) { SearchedFile *files; /* Stack of included files */ SearchedFile *bigger; /* When we need more space */ @@ -4554,14 +4530,7 @@ fpip_end: vim_regfree(def_regmatch.regprog); } -static void show_pat_in_path(line, type, did_show, action, fp, lnum, count) -char_u *line; -int type; -int did_show; -int action; -FILE *fp; -linenr_T *lnum; -long count; +static void show_pat_in_path(char_u *line, int type, int did_show, int action, FILE *fp, linenr_T *lnum, long count) { char_u *p; @@ -4609,9 +4578,7 @@ long count; } } -int read_viminfo_search_pattern(virp, force) -vir_T *virp; -int force; +int read_viminfo_search_pattern(vir_T *virp, int force) { char_u *lp; int idx = -1; @@ -4684,8 +4651,7 @@ int force; return viminfo_readline(virp); } -void write_viminfo_search_pattern(fp) -FILE *fp; +void write_viminfo_search_pattern(FILE *fp) { if (get_viminfo_parameter('/') != 0) { fprintf(fp, "\n# hlsearch on (H) or off (h):\n~%c", @@ -4695,11 +4661,13 @@ FILE *fp; } } -static void wvsp_one(fp, idx, s, sc) -FILE *fp; /* file to write to */ -int idx; /* spats[] index */ -char *s; /* search pat */ -int sc; /* dir char */ +static void +wvsp_one ( + FILE *fp, /* file to write to */ + int idx, /* spats[] index */ + char *s, /* search pat */ + int sc /* dir char */ +) { if (spats[idx].pat != NULL) { fprintf(fp, _("\n# Last %sSearch Pattern:\n~"), s); |