comparison src/fileio.c @ 153:19670b05ee32

updated for version 7.0047
author vimboss
date Wed, 02 Feb 2005 23:04:36 +0000
parents f67f8a8d81ba
children 6df0106fc595
comparison
equal deleted inserted replaced
152:c837baf03d43 153:19670b05ee32
6583 { 6583 {
6584 int group; /* group ID */ 6584 int group; /* group ID */
6585 char_u *pat; /* pattern as typed (NULL when pattern 6585 char_u *pat; /* pattern as typed (NULL when pattern
6586 has been removed) */ 6586 has been removed) */
6587 int patlen; /* strlen() of pat */ 6587 int patlen; /* strlen() of pat */
6588 char_u *reg_pat; /* pattern converted to regexp */ 6588 regprog_T *reg_prog; /* compiled regprog for pattern */
6589 char allow_dirs; /* Pattern may match whole path */ 6589 char allow_dirs; /* Pattern may match whole path */
6590 char last; /* last pattern for apply_autocmds() */ 6590 char last; /* last pattern for apply_autocmds() */
6591 AutoCmd *cmds; /* list of commands to do */ 6591 AutoCmd *cmds; /* list of commands to do */
6592 struct AutoPat *next; /* next AutoPat in AutoPat list */ 6592 struct AutoPat *next; /* next AutoPat in AutoPat list */
6593 int buflocal_nr; /* !=0 for buffer-local AutoPat */ 6593 int buflocal_nr; /* !=0 for buffer-local AutoPat */
6863 6863
6864 /* remove the pattern if it has been marked for deletion */ 6864 /* remove the pattern if it has been marked for deletion */
6865 if (ap->pat == NULL) 6865 if (ap->pat == NULL)
6866 { 6866 {
6867 *prev_ap = ap->next; 6867 *prev_ap = ap->next;
6868 vim_free(ap->reg_pat); 6868 vim_free(ap->reg_prog);
6869 vim_free(ap); 6869 vim_free(ap);
6870 } 6870 }
6871 else 6871 else
6872 prev_ap = &(ap->next); 6872 prev_ap = &(ap->next);
6873 } 6873 }
7165 char_u *old_ei; 7165 char_u *old_ei;
7166 { 7166 {
7167 if (old_ei != NULL) 7167 if (old_ei != NULL)
7168 { 7168 {
7169 set_string_option_direct((char_u *)"ei", -1, old_ei, OPT_FREE); 7169 set_string_option_direct((char_u *)"ei", -1, old_ei, OPT_FREE);
7170 apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn,
7171 curbuf->b_fname, TRUE, curbuf);
7172 vim_free(old_ei); 7170 vim_free(old_ei);
7173 } 7171 }
7174 } 7172 }
7175 # endif /* FEAT_SYN_HL */ 7173 # endif /* FEAT_SYN_HL */
7176 7174
7540 } 7538 }
7541 7539
7542 if (is_buflocal) 7540 if (is_buflocal)
7543 { 7541 {
7544 ap->buflocal_nr = buflocal_nr; 7542 ap->buflocal_nr = buflocal_nr;
7545 ap->reg_pat = NULL; 7543 ap->reg_prog = NULL;
7546 } 7544 }
7547 else 7545 else
7548 { 7546 {
7547 char_u *reg_pat;
7548
7549 ap->buflocal_nr = 0; 7549 ap->buflocal_nr = 0;
7550 ap->reg_pat = file_pat_to_reg_pat(pat, endpat, 7550 reg_pat = file_pat_to_reg_pat(pat, endpat,
7551 &ap->allow_dirs, TRUE); 7551 &ap->allow_dirs, TRUE);
7552 if (ap->reg_pat == NULL) 7552 if (reg_pat != NULL)
7553 ap->reg_prog = vim_regcomp(reg_pat, RE_MAGIC);
7554 if (reg_pat == NULL || ap->reg_prog == NULL)
7553 { 7555 {
7556 vim_free(reg_pat);
7554 vim_free(ap->pat); 7557 vim_free(ap->pat);
7555 vim_free(ap); 7558 vim_free(ap);
7556 return FAIL; 7559 return FAIL;
7557 } 7560 }
7558 } 7561 }
8248 if (ap->pat != NULL && ap->cmds != NULL 8251 if (ap->pat != NULL && ap->cmds != NULL
8249 && (apc->group == AUGROUP_ALL || apc->group == ap->group)) 8252 && (apc->group == AUGROUP_ALL || apc->group == ap->group))
8250 { 8253 {
8251 /* execution-condition */ 8254 /* execution-condition */
8252 if (ap->buflocal_nr == 0 8255 if (ap->buflocal_nr == 0
8253 ? (match_file_pat(ap->reg_pat, apc->fname, apc->sfname, 8256 ? (match_file_pat(NULL, ap->reg_prog, apc->fname,
8254 apc->tail, ap->allow_dirs)) 8257 apc->sfname, apc->tail, ap->allow_dirs))
8255 : ap->buflocal_nr == apc->arg_bufnr) 8258 : ap->buflocal_nr == apc->arg_bufnr)
8256 { 8259 {
8257 name = event_nr2name(apc->event); 8260 name = event_nr2name(apc->event);
8258 s = _("%s Auto commands for \"%s\""); 8261 s = _("%s Auto commands for \"%s\"");
8259 sourcing_name = alloc((unsigned)(STRLEN(s) 8262 sourcing_name = alloc((unsigned)(STRLEN(s)
8379 #endif 8382 #endif
8380 8383
8381 for (ap = first_autopat[(int)event]; ap != NULL; ap = ap->next) 8384 for (ap = first_autopat[(int)event]; ap != NULL; ap = ap->next)
8382 if (ap->pat != NULL && ap->cmds != NULL 8385 if (ap->pat != NULL && ap->cmds != NULL
8383 && (ap->buflocal_nr == 0 8386 && (ap->buflocal_nr == 0
8384 ? match_file_pat(ap->reg_pat, fname, sfname, tail, 8387 ? match_file_pat(NULL, ap->reg_prog,
8385 ap->allow_dirs) 8388 fname, sfname, tail, ap->allow_dirs)
8386 : buf != NULL && ap->buflocal_nr == buf->b_fnum 8389 : buf != NULL && ap->buflocal_nr == buf->b_fnum
8387 )) 8390 ))
8388 { 8391 {
8389 retval = TRUE; 8392 retval = TRUE;
8390 break; 8393 break;
8547 8550
8548 #endif /* FEAT_AUTOCMD */ 8551 #endif /* FEAT_AUTOCMD */
8549 8552
8550 #if defined(FEAT_AUTOCMD) || defined(FEAT_WILDIGN) || defined(PROTO) 8553 #if defined(FEAT_AUTOCMD) || defined(FEAT_WILDIGN) || defined(PROTO)
8551 /* 8554 /*
8552 * Try matching a filename with a pattern. 8555 * Try matching a filename with a "pattern" ("prog" is NULL), or use the
8556 * precompiled regprog "prog" ("pattern" is NULL). That avoids calling
8557 * vim_regcomp() often.
8553 * Used for autocommands and 'wildignore'. 8558 * Used for autocommands and 'wildignore'.
8554 * Returns TRUE if there is a match, FALSE otherwise. 8559 * Returns TRUE if there is a match, FALSE otherwise.
8555 */ 8560 */
8556 int 8561 int
8557 match_file_pat(pattern, fname, sfname, tail, allow_dirs) 8562 match_file_pat(pattern, prog, fname, sfname, tail, allow_dirs)
8558 char_u *pattern; /* pattern to match with */ 8563 char_u *pattern; /* pattern to match with */
8564 regprog_T *prog; /* pre-compiled regprog or NULL */
8559 char_u *fname; /* full path of file name */ 8565 char_u *fname; /* full path of file name */
8560 char_u *sfname; /* short file name or NULL */ 8566 char_u *sfname; /* short file name or NULL */
8561 char_u *tail; /* tail of path */ 8567 char_u *tail; /* tail of path */
8562 int allow_dirs; /* allow matching with dir */ 8568 int allow_dirs; /* allow matching with dir */
8563 { 8569 {
8608 else 8614 else
8609 regmatch.regprog = vim_regcomp(pattern + 1, RE_MAGIC); 8615 regmatch.regprog = vim_regcomp(pattern + 1, RE_MAGIC);
8610 } 8616 }
8611 else 8617 else
8612 #endif 8618 #endif
8613 regmatch.regprog = vim_regcomp(pattern, RE_MAGIC); 8619 {
8620 if (prog != NULL)
8621 regmatch.regprog = prog;
8622 else
8623 regmatch.regprog = vim_regcomp(pattern, RE_MAGIC);
8624 }
8614 8625
8615 /* 8626 /*
8616 * Try for a match with the pattern with: 8627 * Try for a match with the pattern with:
8617 * 1. the full file name, when the pattern has a '/'. 8628 * 1. the full file name, when the pattern has a '/'.
8618 * 2. the short file name, when the pattern has a '/'. 8629 * 2. the short file name, when the pattern has a '/'.
8631 || (sfname != NULL 8642 || (sfname != NULL
8632 && vim_regexec(&regmatch, sfname, (colnr_T)0)))) 8643 && vim_regexec(&regmatch, sfname, (colnr_T)0))))
8633 || (!allow_dirs && vim_regexec(&regmatch, tail, (colnr_T)0))))) 8644 || (!allow_dirs && vim_regexec(&regmatch, tail, (colnr_T)0)))))
8634 result = TRUE; 8645 result = TRUE;
8635 8646
8636 vim_free(regmatch.regprog); 8647 if (prog == NULL)
8648 vim_free(regmatch.regprog);
8637 return result; 8649 return result;
8638 } 8650 }
8639 #endif 8651 #endif
8640 8652
8641 #if defined(FEAT_WILDIGN) || defined(PROTO) 8653 #if defined(FEAT_WILDIGN) || defined(PROTO)
8665 { 8677 {
8666 copy_option_part(&p, buf, 100, ","); 8678 copy_option_part(&p, buf, 100, ",");
8667 regpat = file_pat_to_reg_pat(buf, NULL, &allow_dirs, FALSE); 8679 regpat = file_pat_to_reg_pat(buf, NULL, &allow_dirs, FALSE);
8668 if (regpat == NULL) 8680 if (regpat == NULL)
8669 break; 8681 break;
8670 match = match_file_pat(regpat, ffname, sfname, tail, (int)allow_dirs); 8682 match = match_file_pat(regpat, NULL, ffname, sfname,
8683 tail, (int)allow_dirs);
8671 vim_free(regpat); 8684 vim_free(regpat);
8672 if (match) 8685 if (match)
8673 return TRUE; 8686 return TRUE;
8674 } 8687 }
8675 return FALSE; 8688 return FALSE;