comparison src/regexp.c @ 7805:0b6c37dd858d v7.4.1199

commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077 Author: Bram Moolenaar <Bram@vim.org> Date: Fri Jan 29 22:47:03 2016 +0100 patch 7.4.1199 Problem: Still using __ARGS. Solution: Remove __ARGS in several files. (script by Hirohito Higashi)
author Christian Brabandt <cb@256bit.org>
date Fri, 29 Jan 2016 23:00:05 +0100
parents 286fd54c7ae3
children 1a5d34492798
comparison
equal deleted inserted replaced
7804:874044d87168 7805:0b6c37dd858d
253 */ 253 */
254 #define Magic(x) ((int)(x) - 256) 254 #define Magic(x) ((int)(x) - 256)
255 #define un_Magic(x) ((x) + 256) 255 #define un_Magic(x) ((x) + 256)
256 #define is_Magic(x) ((x) < 0) 256 #define is_Magic(x) ((x) < 0)
257 257
258 static int no_Magic __ARGS((int x)); 258 static int no_Magic(int x);
259 static int toggle_Magic __ARGS((int x)); 259 static int toggle_Magic(int x);
260 260
261 static int 261 static int
262 no_Magic(x) 262 no_Magic(x)
263 int x; 263 int x;
264 { 264 {
345 #define EMSG2_RET_FAIL(m, c) return (EMSG2((m), (c) ? "" : "\\"), rc_did_emsg = TRUE, FAIL) 345 #define EMSG2_RET_FAIL(m, c) return (EMSG2((m), (c) ? "" : "\\"), rc_did_emsg = TRUE, FAIL)
346 #define EMSG_ONE_RET_NULL EMSG2_RET_NULL(_("E369: invalid item in %s%%[]"), reg_magic == MAGIC_ALL) 346 #define EMSG_ONE_RET_NULL EMSG2_RET_NULL(_("E369: invalid item in %s%%[]"), reg_magic == MAGIC_ALL)
347 347
348 #define MAX_LIMIT (32767L << 16L) 348 #define MAX_LIMIT (32767L << 16L)
349 349
350 static int re_multi_type __ARGS((int)); 350 static int re_multi_type(int);
351 static int cstrncmp __ARGS((char_u *s1, char_u *s2, int *n)); 351 static int cstrncmp(char_u *s1, char_u *s2, int *n);
352 static char_u *cstrchr __ARGS((char_u *, int)); 352 static char_u *cstrchr(char_u *, int);
353 353
354 #ifdef BT_REGEXP_DUMP 354 #ifdef BT_REGEXP_DUMP
355 static void regdump __ARGS((char_u *, bt_regprog_T *)); 355 static void regdump(char_u *, bt_regprog_T *);
356 #endif 356 #endif
357 #ifdef DEBUG 357 #ifdef DEBUG
358 static char_u *regprop __ARGS((char_u *)); 358 static char_u *regprop(char_u *);
359 #endif 359 #endif
360 360
361 static int re_mult_next __ARGS((char *what)); 361 static int re_mult_next(char *what);
362 362
363 static char_u e_missingbracket[] = N_("E769: Missing ] after %s["); 363 static char_u e_missingbracket[] = N_("E769: Missing ] after %s[");
364 static char_u e_unmatchedpp[] = N_("E53: Unmatched %s%%("); 364 static char_u e_unmatchedpp[] = N_("E53: Unmatched %s%%(");
365 static char_u e_unmatchedp[] = N_("E54: Unmatched %s("); 365 static char_u e_unmatchedp[] = N_("E54: Unmatched %s(");
366 static char_u e_unmatchedpar[] = N_("E55: Unmatched %s)"); 366 static char_u e_unmatchedpar[] = N_("E55: Unmatched %s)");
424 * \U - Long multibyte character code, eg \U12345678 424 * \U - Long multibyte character code, eg \U12345678
425 */ 425 */
426 static char_u REGEXP_INRANGE[] = "]^-n\\"; 426 static char_u REGEXP_INRANGE[] = "]^-n\\";
427 static char_u REGEXP_ABBR[] = "nrtebdoxuU"; 427 static char_u REGEXP_ABBR[] = "nrtebdoxuU";
428 428
429 static int backslash_trans __ARGS((int c)); 429 static int backslash_trans(int c);
430 static int get_char_class __ARGS((char_u **pp)); 430 static int get_char_class(char_u **pp);
431 static int get_equi_class __ARGS((char_u **pp)); 431 static int get_equi_class(char_u **pp);
432 static void reg_equi_class __ARGS((int c)); 432 static void reg_equi_class(int c);
433 static int get_coll_element __ARGS((char_u **pp)); 433 static int get_coll_element(char_u **pp);
434 static char_u *skip_anyof __ARGS((char_u *p)); 434 static char_u *skip_anyof(char_u *p);
435 static void init_class_tab __ARGS((void)); 435 static void init_class_tab(void);
436 436
437 /* 437 /*
438 * Translate '\x' to its control character, except "\n", which is Magic. 438 * Translate '\x' to its control character, except "\n", which is Magic.
439 */ 439 */
440 static int 440 static int
687 } parse_state_T; 687 } parse_state_T;
688 688
689 /* 689 /*
690 * Forward declarations for vim_regcomp()'s friends. 690 * Forward declarations for vim_regcomp()'s friends.
691 */ 691 */
692 static void initchr __ARGS((char_u *)); 692 static void initchr(char_u *);
693 static void save_parse_state __ARGS((parse_state_T *ps)); 693 static void save_parse_state(parse_state_T *ps);
694 static void restore_parse_state __ARGS((parse_state_T *ps)); 694 static void restore_parse_state(parse_state_T *ps);
695 static int getchr __ARGS((void)); 695 static int getchr(void);
696 static void skipchr_keepstart __ARGS((void)); 696 static void skipchr_keepstart(void);
697 static int peekchr __ARGS((void)); 697 static int peekchr(void);
698 static void skipchr __ARGS((void)); 698 static void skipchr(void);
699 static void ungetchr __ARGS((void)); 699 static void ungetchr(void);
700 static int gethexchrs __ARGS((int maxinputlen)); 700 static int gethexchrs(int maxinputlen);
701 static int getoctchrs __ARGS((void)); 701 static int getoctchrs(void);
702 static int getdecchrs __ARGS((void)); 702 static int getdecchrs(void);
703 static int coll_get_char __ARGS((void)); 703 static int coll_get_char(void);
704 static void regcomp_start __ARGS((char_u *expr, int flags)); 704 static void regcomp_start(char_u *expr, int flags);
705 static char_u *reg __ARGS((int, int *)); 705 static char_u *reg(int, int *);
706 static char_u *regbranch __ARGS((int *flagp)); 706 static char_u *regbranch(int *flagp);
707 static char_u *regconcat __ARGS((int *flagp)); 707 static char_u *regconcat(int *flagp);
708 static char_u *regpiece __ARGS((int *)); 708 static char_u *regpiece(int *);
709 static char_u *regatom __ARGS((int *)); 709 static char_u *regatom(int *);
710 static char_u *regnode __ARGS((int)); 710 static char_u *regnode(int);
711 #ifdef FEAT_MBYTE 711 #ifdef FEAT_MBYTE
712 static int use_multibytecode __ARGS((int c)); 712 static int use_multibytecode(int c);
713 #endif 713 #endif
714 static int prog_magic_wrong __ARGS((void)); 714 static int prog_magic_wrong(void);
715 static char_u *regnext __ARGS((char_u *)); 715 static char_u *regnext(char_u *);
716 static void regc __ARGS((int b)); 716 static void regc(int b);
717 #ifdef FEAT_MBYTE 717 #ifdef FEAT_MBYTE
718 static void regmbc __ARGS((int c)); 718 static void regmbc(int c);
719 # define REGMBC(x) regmbc(x); 719 # define REGMBC(x) regmbc(x);
720 # define CASEMBC(x) case x: 720 # define CASEMBC(x) case x:
721 #else 721 #else
722 # define regmbc(c) regc(c) 722 # define regmbc(c) regc(c)
723 # define REGMBC(x) 723 # define REGMBC(x)
724 # define CASEMBC(x) 724 # define CASEMBC(x)
725 #endif 725 #endif
726 static void reginsert __ARGS((int, char_u *)); 726 static void reginsert(int, char_u *);
727 static void reginsert_nr __ARGS((int op, long val, char_u *opnd)); 727 static void reginsert_nr(int op, long val, char_u *opnd);
728 static void reginsert_limits __ARGS((int, long, long, char_u *)); 728 static void reginsert_limits(int, long, long, char_u *);
729 static char_u *re_put_long __ARGS((char_u *pr, long_u val)); 729 static char_u *re_put_long(char_u *pr, long_u val);
730 static int read_limits __ARGS((long *, long *)); 730 static int read_limits(long *, long *);
731 static void regtail __ARGS((char_u *, char_u *)); 731 static void regtail(char_u *, char_u *);
732 static void regoptail __ARGS((char_u *, char_u *)); 732 static void regoptail(char_u *, char_u *);
733 733
734 static regengine_T bt_regengine; 734 static regengine_T bt_regengine;
735 static regengine_T nfa_regengine; 735 static regengine_T nfa_regengine;
736 736
737 /* 737 /*
1176 } 1176 }
1177 } 1177 }
1178 return 0; 1178 return 0;
1179 } 1179 }
1180 1180
1181 static void get_cpo_flags __ARGS((void)); 1181 static void get_cpo_flags(void);
1182 static int reg_cpo_lit; /* 'cpoptions' contains 'l' flag */ 1182 static int reg_cpo_lit; /* 'cpoptions' contains 'l' flag */
1183 static int reg_cpo_bsl; /* 'cpoptions' contains '\' flag */ 1183 static int reg_cpo_bsl; /* 'cpoptions' contains '\' flag */
1184 1184
1185 static void 1185 static void
1186 get_cpo_flags() 1186 get_cpo_flags()
1300 } 1300 }
1301 } 1301 }
1302 return p; 1302 return p;
1303 } 1303 }
1304 1304
1305 static regprog_T *bt_regcomp __ARGS((char_u *expr, int re_flags)); 1305 static regprog_T *bt_regcomp(char_u *expr, int re_flags);
1306 static void bt_regfree __ARGS((regprog_T *prog)); 1306 static void bt_regfree(regprog_T *prog);
1307 1307
1308 /* 1308 /*
1309 * bt_regcomp() - compile a regular expression into internal code for the 1309 * bt_regcomp() - compile a regular expression into internal code for the
1310 * traditional back track matcher. 1310 * traditional back track matcher.
1311 * Returns the program in allocated space. Returns NULL for an error. 1311 * Returns the program in allocated space. Returns NULL for an error.
3512 int save_need_clear_subexpr; 3512 int save_need_clear_subexpr;
3513 save_se_T save_start[NSUBEXP]; 3513 save_se_T save_start[NSUBEXP];
3514 save_se_T save_end[NSUBEXP]; 3514 save_se_T save_end[NSUBEXP];
3515 } regbehind_T; 3515 } regbehind_T;
3516 3516
3517 static char_u *reg_getline __ARGS((linenr_T lnum)); 3517 static char_u *reg_getline(linenr_T lnum);
3518 static long bt_regexec_both __ARGS((char_u *line, colnr_T col, proftime_T *tm)); 3518 static long bt_regexec_both(char_u *line, colnr_T col, proftime_T *tm);
3519 static long regtry __ARGS((bt_regprog_T *prog, colnr_T col)); 3519 static long regtry(bt_regprog_T *prog, colnr_T col);
3520 static void cleanup_subexpr __ARGS((void)); 3520 static void cleanup_subexpr(void);
3521 #ifdef FEAT_SYN_HL 3521 #ifdef FEAT_SYN_HL
3522 static void cleanup_zsubexpr __ARGS((void)); 3522 static void cleanup_zsubexpr(void);
3523 #endif 3523 #endif
3524 static void save_subexpr __ARGS((regbehind_T *bp)); 3524 static void save_subexpr(regbehind_T *bp);
3525 static void restore_subexpr __ARGS((regbehind_T *bp)); 3525 static void restore_subexpr(regbehind_T *bp);
3526 static void reg_nextline __ARGS((void)); 3526 static void reg_nextline(void);
3527 static void reg_save __ARGS((regsave_T *save, garray_T *gap)); 3527 static void reg_save(regsave_T *save, garray_T *gap);
3528 static void reg_restore __ARGS((regsave_T *save, garray_T *gap)); 3528 static void reg_restore(regsave_T *save, garray_T *gap);
3529 static int reg_save_equal __ARGS((regsave_T *save)); 3529 static int reg_save_equal(regsave_T *save);
3530 static void save_se_multi __ARGS((save_se_T *savep, lpos_T *posp)); 3530 static void save_se_multi(save_se_T *savep, lpos_T *posp);
3531 static void save_se_one __ARGS((save_se_T *savep, char_u **pp)); 3531 static void save_se_one(save_se_T *savep, char_u **pp);
3532 3532
3533 /* Save the sub-expressions before attempting a match. */ 3533 /* Save the sub-expressions before attempting a match. */
3534 #define save_se(savep, posp, pp) \ 3534 #define save_se(savep, posp, pp) \
3535 REG_MULTI ? save_se_multi((savep), (posp)) : save_se_one((savep), (pp)) 3535 REG_MULTI ? save_se_multi((savep), (posp)) : save_se_one((savep), (pp))
3536 3536
3539 if (REG_MULTI) \ 3539 if (REG_MULTI) \
3540 *(posp) = (savep)->se_u.pos; \ 3540 *(posp) = (savep)->se_u.pos; \
3541 else \ 3541 else \
3542 *(pp) = (savep)->se_u.ptr; } 3542 *(pp) = (savep)->se_u.ptr; }
3543 3543
3544 static int re_num_cmp __ARGS((long_u val, char_u *scan)); 3544 static int re_num_cmp(long_u val, char_u *scan);
3545 static int match_with_backref __ARGS((linenr_T start_lnum, colnr_T start_col, linenr_T end_lnum, colnr_T end_col, int *bytelen)); 3545 static int match_with_backref(linenr_T start_lnum, colnr_T start_col, linenr_T end_lnum, colnr_T end_col, int *bytelen);
3546 static int regmatch __ARGS((char_u *prog)); 3546 static int regmatch(char_u *prog);
3547 static int regrepeat __ARGS((char_u *p, long maxcount)); 3547 static int regrepeat(char_u *p, long maxcount);
3548 3548
3549 #ifdef DEBUG 3549 #ifdef DEBUG
3550 int regnarrate = 0; 3550 int regnarrate = 0;
3551 #endif 3551 #endif
3552 3552
3645 regsave_T regsave; 3645 regsave_T regsave;
3646 } rs_un; /* room for saving reginput */ 3646 } rs_un; /* room for saving reginput */
3647 short rs_no; /* submatch nr or BEHIND/NOBEHIND */ 3647 short rs_no; /* submatch nr or BEHIND/NOBEHIND */
3648 } regitem_T; 3648 } regitem_T;
3649 3649
3650 static regitem_T *regstack_push __ARGS((regstate_T state, char_u *scan)); 3650 static regitem_T *regstack_push(regstate_T state, char_u *scan);
3651 static void regstack_pop __ARGS((char_u **scan)); 3651 static void regstack_pop(char_u **scan);
3652 3652
3653 /* used for STAR, PLUS and BRACE_SIMPLE matching */ 3653 /* used for STAR, PLUS and BRACE_SIMPLE matching */
3654 typedef struct regstar_S 3654 typedef struct regstar_S
3655 { 3655 {
3656 int nextb; /* next byte */ 3656 int nextb; /* next byte */
3730 #endif 3730 #endif
3731 3731
3732 /* TRUE if using multi-line regexp. */ 3732 /* TRUE if using multi-line regexp. */
3733 #define REG_MULTI (reg_match == NULL) 3733 #define REG_MULTI (reg_match == NULL)
3734 3734
3735 static int bt_regexec_nl __ARGS((regmatch_T *rmp, char_u *line, colnr_T col, int line_lbr)); 3735 static int bt_regexec_nl(regmatch_T *rmp, char_u *line, colnr_T col, int line_lbr);
3736 3736
3737 3737
3738 /* 3738 /*
3739 * Match a regexp against a string. 3739 * Match a regexp against a string.
3740 * "rmp->regprog" is a compiled regexp as returned by vim_regcomp(). 3740 * "rmp->regprog" is a compiled regexp as returned by vim_regcomp().
3763 ireg_maxcol = 0; 3763 ireg_maxcol = 0;
3764 3764
3765 return bt_regexec_both(line, col, NULL); 3765 return bt_regexec_both(line, col, NULL);
3766 } 3766 }
3767 3767
3768 static long bt_regexec_multi __ARGS((regmmatch_T *rmp, win_T *win, buf_T *buf, linenr_T lnum, colnr_T col, proftime_T *tm)); 3768 static long bt_regexec_multi(regmmatch_T *rmp, win_T *win, buf_T *buf, linenr_T lnum, colnr_T col, proftime_T *tm);
3769 3769
3770 /* 3770 /*
3771 * Match a regexp against multiple lines. 3771 * Match a regexp against multiple lines.
3772 * "rmp->regprog" is a compiled regexp as returned by vim_regcomp(). 3772 * "rmp->regprog" is a compiled regexp as returned by vim_regcomp().
3773 * Uses curbuf for line count and 'iskeyword'. 3773 * Uses curbuf for line count and 'iskeyword'.
4031 4031
4032 return retval; 4032 return retval;
4033 } 4033 }
4034 4034
4035 #ifdef FEAT_SYN_HL 4035 #ifdef FEAT_SYN_HL
4036 static reg_extmatch_T *make_extmatch __ARGS((void)); 4036 static reg_extmatch_T *make_extmatch(void);
4037 4037
4038 /* 4038 /*
4039 * Create a new extmatch and mark it as referenced once. 4039 * Create a new extmatch and mark it as referenced once.
4040 */ 4040 */
4041 static reg_extmatch_T * 4041 static reg_extmatch_T *
4160 #endif 4160 #endif
4161 return 1 + reglnum; 4161 return 1 + reglnum;
4162 } 4162 }
4163 4163
4164 #ifdef FEAT_MBYTE 4164 #ifdef FEAT_MBYTE
4165 static int reg_prev_class __ARGS((void)); 4165 static int reg_prev_class(void);
4166 4166
4167 /* 4167 /*
4168 * Get class of previous character. 4168 * Get class of previous character.
4169 */ 4169 */
4170 static int 4170 static int
4175 - (*mb_head_off)(regline, reginput - 1), reg_buf); 4175 - (*mb_head_off)(regline, reginput - 1), reg_buf);
4176 return -1; 4176 return -1;
4177 } 4177 }
4178 #endif 4178 #endif
4179 4179
4180 static int reg_match_visual __ARGS((void)); 4180 static int reg_match_visual(void);
4181 4181
4182 /* 4182 /*
4183 * Return TRUE if the current reginput position matches the Visual area. 4183 * Return TRUE if the current reginput position matches the Visual area.
4184 */ 4184 */
4185 static int 4185 static int
7023 EMSG2_RET_FAIL(_("E888: (NFA regexp) cannot repeat %s"), what); 7023 EMSG2_RET_FAIL(_("E888: (NFA regexp) cannot repeat %s"), what);
7024 return OK; 7024 return OK;
7025 } 7025 }
7026 7026
7027 #ifdef FEAT_MBYTE 7027 #ifdef FEAT_MBYTE
7028 static void mb_decompose __ARGS((int c, int *c1, int *c2, int *c3)); 7028 static void mb_decompose(int c, int *c1, int *c2, int *c3);
7029 7029
7030 typedef struct 7030 typedef struct
7031 { 7031 {
7032 int a, b, c; 7032 int a, b, c;
7033 } decomp_T; 7033 } decomp_T;
7236 * We should define ftpr as a pointer to a function returning a pointer to 7236 * We should define ftpr as a pointer to a function returning a pointer to
7237 * a function returning a pointer to a function ... 7237 * a function returning a pointer to a function ...
7238 * This is impossible, so we declare a pointer to a function returning a 7238 * This is impossible, so we declare a pointer to a function returning a
7239 * pointer to a function returning void. This should work for all compilers. 7239 * pointer to a function returning void. This should work for all compilers.
7240 */ 7240 */
7241 typedef void (*(*fptr_T) __ARGS((int *, int)))(); 7241 typedef void (*(*fptr_T)(int *, int))();
7242 7242
7243 static fptr_T do_upper __ARGS((int *, int)); 7243 static fptr_T do_upper(int *, int);
7244 static fptr_T do_Upper __ARGS((int *, int)); 7244 static fptr_T do_Upper(int *, int);
7245 static fptr_T do_lower __ARGS((int *, int)); 7245 static fptr_T do_lower(int *, int);
7246 static fptr_T do_Lower __ARGS((int *, int)); 7246 static fptr_T do_Lower(int *, int);
7247 7247
7248 static int vim_regsub_both __ARGS((char_u *source, char_u *dest, int copy, int magic, int backslash)); 7248 static int vim_regsub_both(char_u *source, char_u *dest, int copy, int magic, int backslash);
7249 7249
7250 static fptr_T 7250 static fptr_T
7251 do_upper(d, c) 7251 do_upper(d, c)
7252 int *d; 7252 int *d;
7253 int c; 7253 int c;
7807 exit: 7807 exit:
7808 return (int)((dst - dest) + 1); 7808 return (int)((dst - dest) + 1);
7809 } 7809 }
7810 7810
7811 #ifdef FEAT_EVAL 7811 #ifdef FEAT_EVAL
7812 static char_u *reg_getline_submatch __ARGS((linenr_T lnum)); 7812 static char_u *reg_getline_submatch(linenr_T lnum);
7813 7813
7814 /* 7814 /*
7815 * Call reg_getline() with the line numbers from the submatch. If a 7815 * Call reg_getline() with the line numbers from the submatch. If a
7816 * substitute() was used the reg_maxline and other values have been 7816 * substitute() was used the reg_maxline and other values have been
7817 * overwritten. 7817 * overwritten.
8140 if (prog != NULL) 8140 if (prog != NULL)
8141 prog->engine->regfree(prog); 8141 prog->engine->regfree(prog);
8142 } 8142 }
8143 8143
8144 #ifdef FEAT_EVAL 8144 #ifdef FEAT_EVAL
8145 static void report_re_switch __ARGS((char_u *pat)); 8145 static void report_re_switch(char_u *pat);
8146 8146
8147 static void 8147 static void
8148 report_re_switch(pat) 8148 report_re_switch(pat)
8149 char_u *pat; 8149 char_u *pat;
8150 { 8150 {
8156 verbose_leave(); 8156 verbose_leave();
8157 } 8157 }
8158 } 8158 }
8159 #endif 8159 #endif
8160 8160
8161 static int vim_regexec_both __ARGS((regmatch_T *rmp, char_u *line, colnr_T col, int nl)); 8161 static int vim_regexec_both(regmatch_T *rmp, char_u *line, colnr_T col, int nl);
8162 8162
8163 /* 8163 /*
8164 * Match a regexp against a string. 8164 * Match a regexp against a string.
8165 * "rmp->regprog" is a compiled regexp as returned by vim_regcomp(). 8165 * "rmp->regprog" is a compiled regexp as returned by vim_regcomp().
8166 * Note: "rmp->regprog" may be freed and changed. 8166 * Note: "rmp->regprog" may be freed and changed.