comparison src/fileio.c @ 612:b9370cfb091a

updated for version 7.0174
author vimboss
date Mon, 19 Dec 2005 22:08:24 +0000
parents ba54311bc43e
children 7fe13e0f5dce
comparison
equal deleted inserted replaced
611:8d920e93007b 612:b9370cfb091a
759 linecnt = curbuf->b_ml.ml_line_count; 759 linecnt = curbuf->b_ml.ml_line_count;
760 760
761 #ifdef FEAT_MBYTE 761 #ifdef FEAT_MBYTE
762 /* "++bad=" argument. */ 762 /* "++bad=" argument. */
763 if (eap != NULL && eap->bad_char != 0) 763 if (eap != NULL && eap->bad_char != 0)
764 {
764 bad_char_behavior = eap->bad_char; 765 bad_char_behavior = eap->bad_char;
766 if (newfile)
767 curbuf->b_bad_char = eap->bad_char;
768 }
769 else
770 curbuf->b_bad_char = 0;
765 771
766 /* 772 /*
767 * Decide which 'encoding' to use or use first. 773 * Decide which 'encoding' to use or use first.
768 */ 774 */
769 if (eap != NULL && eap->force_enc != 0) 775 if (eap != NULL && eap->force_enc != 0)
2427 return lnum; 2433 return lnum;
2428 } 2434 }
2429 #endif 2435 #endif
2430 2436
2431 /* 2437 /*
2432 * Fill "*eap" to force the 'fileencoding' and 'fileformat' to be equal to the 2438 * Fill "*eap" to force the 'fileencoding', 'fileformat' and 'binary to be
2433 * buffer "buf". Used for calling readfile(). 2439 * equal to the buffer "buf". Used for calling readfile().
2434 * Returns OK or FAIL. 2440 * Returns OK or FAIL.
2435 */ 2441 */
2436 int 2442 int
2437 prep_exarg(eap, buf) 2443 prep_exarg(eap, buf)
2438 exarg_T *eap; 2444 exarg_T *eap;
2447 return FAIL; 2453 return FAIL;
2448 2454
2449 #ifdef FEAT_MBYTE 2455 #ifdef FEAT_MBYTE
2450 sprintf((char *)eap->cmd, "e ++ff=%s ++enc=%s", buf->b_p_ff, buf->b_p_fenc); 2456 sprintf((char *)eap->cmd, "e ++ff=%s ++enc=%s", buf->b_p_ff, buf->b_p_fenc);
2451 eap->force_enc = 14 + (int)STRLEN(buf->b_p_ff); 2457 eap->force_enc = 14 + (int)STRLEN(buf->b_p_ff);
2458 eap->bad_char = buf->b_bad_char;
2452 #else 2459 #else
2453 sprintf((char *)eap->cmd, "e ++ff=%s", buf->b_p_ff); 2460 sprintf((char *)eap->cmd, "e ++ff=%s", buf->b_p_ff);
2454 #endif 2461 #endif
2455 eap->force_ff = 7; 2462 eap->force_ff = 7;
2463
2464 eap->force_bin = buf->b_p_bin ? FORCE_BIN : FORCE_NOBIN;
2465 eap->forceit = FALSE;
2456 return OK; 2466 return OK;
2457 } 2467 }
2458 2468
2459 #ifdef FEAT_MBYTE 2469 #ifdef FEAT_MBYTE
2460 /* 2470 /*
8815 } 8825 }
8816 8826
8817 #endif /* FEAT_CMDL_COMPL */ 8827 #endif /* FEAT_CMDL_COMPL */
8818 8828
8819 /* 8829 /*
8820 * Return TRUE if an autocommand is defined for "event" and "pattern". 8830 * Return TRUE if an autocommand is defined for a group, event and
8821 * "pattern" can be NULL to accept any pattern. Buffer-local patterns 8831 * pattern: The group can be omitted to accept any group. "event" and "pattern"
8822 * <buffer> or <buffer=N> are accepted. 8832 * can be NULL to accept any event and pattern. "pattern" can be NULL to accept
8823 * Used for exists("#Event#pat") 8833 * any pattern. Buffer-local patterns <buffer> or <buffer=N> are accepted.
8834 * Used for:
8835 * exists("#Group") or
8836 * exists("#Group#Event") or
8837 * exists("#Group#Event#pat") or
8838 * exists("#Event") or
8839 * exists("#Event#pat")
8824 */ 8840 */
8825 int 8841 int
8826 au_exists(name, name_end, pattern) 8842 au_exists(arg)
8827 char_u *name; 8843 char_u *arg;
8828 char_u *name_end;
8829 char_u *pattern;
8830 { 8844 {
8845 char_u *arg_save;
8846 char_u *pattern = NULL;
8831 char_u *event_name; 8847 char_u *event_name;
8832 char_u *p; 8848 char_u *p;
8833 EVENT_T event; 8849 EVENT_T event;
8834 AutoPat *ap; 8850 AutoPat *ap;
8835 buf_T *buflocal_buf = NULL; 8851 buf_T *buflocal_buf = NULL;
8852 int group;
8853 int retval = FALSE;
8854
8855 /* Make a copy so that we can change the '#' to a NUL. */
8856 arg_save = vim_strsave(arg);
8857 if (arg_save == NULL)
8858 return FALSE;
8859 p = vim_strchr(arg, '#');
8860 if (p != NULL)
8861 *p++ = NUL;
8862
8863 /* First, look for an autocmd group name */
8864 group = au_find_group(arg_save);
8865 if (group == AUGROUP_ERROR)
8866 {
8867 /* Didn't match a group name, assume the first argument is an event. */
8868 group = AUGROUP_ALL;
8869 event_name = arg_save;
8870 }
8871 else
8872 {
8873 if (p == NULL)
8874 {
8875 /* "Group": group name is present and it's recognized */
8876 retval = TRUE;
8877 goto theend;
8878 }
8879
8880 /* Must be "Group#Event" or "Group#Event#pat". */
8881 event_name = p;
8882 p = vim_strchr(event_name, '#');
8883 if (p != NULL)
8884 *p++ = NUL; /* "Group#Event#pat" */
8885 }
8886
8887 pattern = p; /* "pattern" is NULL when there is no pattern */
8836 8888
8837 /* find the index (enum) for the event name */ 8889 /* find the index (enum) for the event name */
8838 event_name = vim_strnsave(name, (int)(name_end - name));
8839 if (event_name == NULL)
8840 return FALSE;
8841 event = event_name2nr(event_name, &p); 8890 event = event_name2nr(event_name, &p);
8842 vim_free(event_name);
8843 8891
8844 /* return FALSE if the event name is not recognized */ 8892 /* return FALSE if the event name is not recognized */
8845 if (event == NUM_EVENTS) /* unknown event name */ 8893 if (event == NUM_EVENTS)
8846 return FALSE; 8894 goto theend;
8847 8895
8848 /* Find the first autocommand for this event. 8896 /* Find the first autocommand for this event.
8849 * If there isn't any, return FALSE; 8897 * If there isn't any, return FALSE;
8850 * If there is one and no pattern given, return TRUE; */ 8898 * If there is one and no pattern given, return TRUE; */
8851 ap = first_autopat[(int)event]; 8899 ap = first_autopat[(int)event];
8852 if (ap == NULL) 8900 if (ap == NULL)
8853 return FALSE; 8901 goto theend;
8854 if (pattern == NULL) 8902 if (pattern == NULL)
8855 return TRUE; 8903 {
8904 retval = TRUE;
8905 goto theend;
8906 }
8856 8907
8857 /* if pattern is "<buffer>", special handling is needed which uses curbuf */ 8908 /* if pattern is "<buffer>", special handling is needed which uses curbuf */
8858 /* for pattern "<buffer=N>, fnamecmp() will work fine */ 8909 /* for pattern "<buffer=N>, fnamecmp() will work fine */
8859 if (STRICMP(pattern, "<buffer>") == 0) 8910 if (STRICMP(pattern, "<buffer>") == 0)
8860 buflocal_buf = curbuf; 8911 buflocal_buf = curbuf;
8862 /* Check if there is an autocommand with the given pattern. */ 8913 /* Check if there is an autocommand with the given pattern. */
8863 for ( ; ap != NULL; ap = ap->next) 8914 for ( ; ap != NULL; ap = ap->next)
8864 /* only use a pattern when it has not been removed and has commands. */ 8915 /* only use a pattern when it has not been removed and has commands. */
8865 /* For buffer-local autocommands, fnamecmp() works fine. */ 8916 /* For buffer-local autocommands, fnamecmp() works fine. */
8866 if (ap->pat != NULL && ap->cmds != NULL 8917 if (ap->pat != NULL && ap->cmds != NULL
8918 && (group == AUGROUP_ALL || ap->group == group)
8867 && (buflocal_buf == NULL 8919 && (buflocal_buf == NULL
8868 ? fnamecmp(ap->pat, pattern) == 0 8920 ? fnamecmp(ap->pat, pattern) == 0
8869 : ap->buflocal_nr == buflocal_buf->b_fnum)) 8921 : ap->buflocal_nr == buflocal_buf->b_fnum))
8870 return TRUE; 8922 {
8871 8923 retval = TRUE;
8872 return FALSE; 8924 break;
8925 }
8926
8927 theend:
8928 vim_free(arg_save);
8929 return retval;
8873 } 8930 }
8874 8931
8875 #endif /* FEAT_AUTOCMD */ 8932 #endif /* FEAT_AUTOCMD */
8876 8933
8877 #if defined(FEAT_AUTOCMD) || defined(FEAT_WILDIGN) || defined(PROTO) 8934 #if defined(FEAT_AUTOCMD) || defined(FEAT_WILDIGN) || defined(PROTO)