comparison src/fileio.c @ 633:7437be625546

updated for version 7.0183
author vimboss
date Fri, 20 Jan 2006 23:02:51 +0000
parents efb7557aea10
children 23a639c430c5
comparison
equal deleted inserted replaced
632:b6632d553df3 633:7437be625546
57 static char_u *check_for_cryptkey __ARGS((char_u *cryptkey, char_u *ptr, long *sizep, long *filesizep, int newfile)); 57 static char_u *check_for_cryptkey __ARGS((char_u *cryptkey, char_u *ptr, long *sizep, long *filesizep, int newfile));
58 #endif 58 #endif
59 #ifdef UNIX 59 #ifdef UNIX
60 static void set_file_time __ARGS((char_u *fname, time_t atime, time_t mtime)); 60 static void set_file_time __ARGS((char_u *fname, time_t atime, time_t mtime));
61 #endif 61 #endif
62 static int set_rw_fname __ARGS((char_u *fname, char_u *sfname));
62 static int msg_add_fileformat __ARGS((int eol_type)); 63 static int msg_add_fileformat __ARGS((int eol_type));
63 static void msg_add_eol __ARGS((void)); 64 static void msg_add_eol __ARGS((void));
64 static int check_mtime __ARGS((buf_T *buf, struct stat *s)); 65 static int check_mtime __ARGS((buf_T *buf, struct stat *s));
65 static int time_differs __ARGS((long t1, long t2)); 66 static int time_differs __ARGS((long t1, long t2));
66 #ifdef FEAT_AUTOCMD 67 #ifdef FEAT_AUTOCMD
299 && !filtering 300 && !filtering
300 && fname != NULL 301 && fname != NULL
301 && vim_strchr(p_cpo, CPO_FNAMER) != NULL 302 && vim_strchr(p_cpo, CPO_FNAMER) != NULL
302 && !(flags & READ_DUMMY)) 303 && !(flags & READ_DUMMY))
303 { 304 {
304 if (setfname(curbuf, fname, sfname, FALSE) == OK) 305 if (set_rw_fname(fname, sfname) == FAIL)
305 curbuf->b_flags |= BF_NOTEDITED; 306 return FAIL;
306 } 307 }
307 308
308 /* After reading a file the cursor line changes but we don't want to 309 /* After reading a file the cursor line changes but we don't want to
309 * display the line. */ 310 * display the line. */
310 ex_no_reprint = TRUE; 311 ex_no_reprint = TRUE;
2799 * BF_NOTEDITED is set to reflect this (in case the write fails). 2800 * BF_NOTEDITED is set to reflect this (in case the write fails).
2800 * Don't do this when the write is for a filter command. 2801 * Don't do this when the write is for a filter command.
2801 * Don't do this when appending. 2802 * Don't do this when appending.
2802 * Only do this when 'cpoptions' contains the 'F' flag. 2803 * Only do this when 'cpoptions' contains the 'F' flag.
2803 */ 2804 */
2804 if (reset_changed 2805 if (buf->b_ffname == NULL
2806 && reset_changed
2805 && whole 2807 && whole
2806 && buf == curbuf 2808 && buf == curbuf
2807 #ifdef FEAT_QUICKFIX 2809 #ifdef FEAT_QUICKFIX
2808 && !bt_nofile(buf) 2810 && !bt_nofile(buf)
2809 #endif 2811 #endif
2810 && buf->b_ffname == NULL
2811 && !filtering 2812 && !filtering
2812 && (!append || vim_strchr(p_cpo, CPO_FNAMEAPP) != NULL) 2813 && (!append || vim_strchr(p_cpo, CPO_FNAMEAPP) != NULL)
2813 && vim_strchr(p_cpo, CPO_FNAMEW) != NULL) 2814 && vim_strchr(p_cpo, CPO_FNAMEW) != NULL)
2814 { 2815 {
2815 #ifdef FEAT_AUTOCMD 2816 if (set_rw_fname(fname, sfname) == FAIL)
2816 /* It's like the unnamed buffer is deleted.... */
2817 if (curbuf->b_p_bl)
2818 apply_autocmds(EVENT_BUFDELETE, NULL, NULL, FALSE, curbuf);
2819 apply_autocmds(EVENT_BUFWIPEOUT, NULL, NULL, FALSE, curbuf);
2820 #ifdef FEAT_EVAL
2821 if (aborting()) /* autocmds may abort script processing */
2822 return FAIL; 2817 return FAIL;
2823 #endif 2818 buf = curbuf; /* just in case autocmds made "buf" invalid */
2824 #endif
2825 if (setfname(curbuf, fname, sfname, FALSE) == OK)
2826 curbuf->b_flags |= BF_NOTEDITED;
2827 #ifdef FEAT_AUTOCMD
2828 /* ....and a new named one is created */
2829 apply_autocmds(EVENT_BUFNEW, NULL, NULL, FALSE, curbuf);
2830 if (curbuf->b_p_bl)
2831 apply_autocmds(EVENT_BUFADD, NULL, NULL, FALSE, curbuf);
2832 #endif
2833 } 2819 }
2834 2820
2835 if (sfname == NULL) 2821 if (sfname == NULL)
2836 sfname = fname; 2822 sfname = fname;
2837 /* 2823 /*
4596 #ifdef MACOS_CLASSIC /* TODO: Is it need for MACOS_X? (Dany) */ 4582 #ifdef MACOS_CLASSIC /* TODO: Is it need for MACOS_X? (Dany) */
4597 /* Update machine specific information. */ 4583 /* Update machine specific information. */
4598 mch_post_buffer_write(buf); 4584 mch_post_buffer_write(buf);
4599 #endif 4585 #endif
4600 return retval; 4586 return retval;
4587 }
4588
4589 /*
4590 * Set the name of the current buffer. Use when the buffer doesn't have a
4591 * name and a ":r" or ":w" command with a file name is used.
4592 */
4593 static int
4594 set_rw_fname(fname, sfname)
4595 char_u *fname;
4596 char_u *sfname;
4597 {
4598 #ifdef FEAT_AUTOCMD
4599 /* It's like the unnamed buffer is deleted.... */
4600 if (curbuf->b_p_bl)
4601 apply_autocmds(EVENT_BUFDELETE, NULL, NULL, FALSE, curbuf);
4602 apply_autocmds(EVENT_BUFWIPEOUT, NULL, NULL, FALSE, curbuf);
4603 # ifdef FEAT_EVAL
4604 if (aborting()) /* autocmds may abort script processing */
4605 return FAIL;
4606 # endif
4607 #endif
4608
4609 if (setfname(curbuf, fname, sfname, FALSE) == OK)
4610 curbuf->b_flags |= BF_NOTEDITED;
4611
4612 #ifdef FEAT_AUTOCMD
4613 /* ....and a new named one is created */
4614 apply_autocmds(EVENT_BUFNEW, NULL, NULL, FALSE, curbuf);
4615 if (curbuf->b_p_bl)
4616 apply_autocmds(EVENT_BUFADD, NULL, NULL, FALSE, curbuf);
4617 # ifdef FEAT_EVAL
4618 if (aborting()) /* autocmds may abort script processing */
4619 return FAIL;
4620 # endif
4621
4622 /* Do filetype detection now if 'filetype' is empty. */
4623 if (*curbuf->b_p_ft == NUL)
4624 {
4625 (void)do_doautocmd((char_u *)"filetypedetect BufRead", TRUE);
4626 do_modelines(FALSE);
4627 }
4628 #endif
4629
4630 return OK;
4601 } 4631 }
4602 4632
4603 /* 4633 /*
4604 * Put file name into IObuff with quotes. 4634 * Put file name into IObuff with quotes.
4605 */ 4635 */