Mercurial > vim
comparison src/fileio.c @ 7819:f86adafb28d4 v7.4.1206
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Jan 30 15:52:46 2016 +0100
patch 7.4.1206
Problem: Using old style function declarations.
Solution: Change to new style function declarations. (script by Hirohito
Higashi)
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Sat, 30 Jan 2016 16:00:06 +0100 |
parents | a1e71a01dbd6 |
children | 226ed297307f |
comparison
equal
deleted
inserted
replaced
7818:19dfb097d82d | 7819:f86adafb28d4 |
---|---|
142 #ifdef FEAT_AUTOCMD | 142 #ifdef FEAT_AUTOCMD |
143 static char *e_auchangedbuf = N_("E812: Autocommands changed buffer or buffer name"); | 143 static char *e_auchangedbuf = N_("E812: Autocommands changed buffer or buffer name"); |
144 #endif | 144 #endif |
145 | 145 |
146 void | 146 void |
147 filemess(buf, name, s, attr) | 147 filemess( |
148 buf_T *buf; | 148 buf_T *buf, |
149 char_u *name; | 149 char_u *name, |
150 char_u *s; | 150 char_u *s, |
151 int attr; | 151 int attr) |
152 { | 152 { |
153 int msg_scroll_save; | 153 int msg_scroll_save; |
154 | 154 |
155 if (msg_silent != 0) | 155 if (msg_silent != 0) |
156 return; | 156 return; |
202 * READ_KEEP_UNDO don't clear undo info or read it from a file | 202 * READ_KEEP_UNDO don't clear undo info or read it from a file |
203 * | 203 * |
204 * return FAIL for failure, OK otherwise | 204 * return FAIL for failure, OK otherwise |
205 */ | 205 */ |
206 int | 206 int |
207 readfile(fname, sfname, from, lines_to_skip, lines_to_read, eap, flags) | 207 readfile( |
208 char_u *fname; | 208 char_u *fname, |
209 char_u *sfname; | 209 char_u *sfname, |
210 linenr_T from; | 210 linenr_T from, |
211 linenr_T lines_to_skip; | 211 linenr_T lines_to_skip, |
212 linenr_T lines_to_read; | 212 linenr_T lines_to_read, |
213 exarg_T *eap; /* can be NULL! */ | 213 exarg_T *eap, /* can be NULL! */ |
214 int flags; | 214 int flags) |
215 { | 215 { |
216 int fd = 0; | 216 int fd = 0; |
217 int newfile = (flags & READ_NEW); | 217 int newfile = (flags & READ_NEW); |
218 int check_readonly; | 218 int check_readonly; |
219 int filtering = (flags & READ_FILTER); | 219 int filtering = (flags & READ_FILTER); |
2694 * which is the name of files used for process substitution output by | 2694 * which is the name of files used for process substitution output by |
2695 * some shells on some operating systems, e.g., bash on SunOS. | 2695 * some shells on some operating systems, e.g., bash on SunOS. |
2696 * Do not accept "/dev/fd/[012]", opening these may hang Vim. | 2696 * Do not accept "/dev/fd/[012]", opening these may hang Vim. |
2697 */ | 2697 */ |
2698 static int | 2698 static int |
2699 is_dev_fd_file(fname) | 2699 is_dev_fd_file(char_u *fname) |
2700 char_u *fname; | |
2701 { | 2700 { |
2702 return (STRNCMP(fname, "/dev/fd/", 8) == 0 | 2701 return (STRNCMP(fname, "/dev/fd/", 8) == 0 |
2703 && VIM_ISDIGIT(fname[8]) | 2702 && VIM_ISDIGIT(fname[8]) |
2704 && *skipdigits(fname + 9) == NUL | 2703 && *skipdigits(fname + 9) == NUL |
2705 && (fname[9] != NUL | 2704 && (fname[9] != NUL |
2713 * From the current line count and characters read after that, estimate the | 2712 * From the current line count and characters read after that, estimate the |
2714 * line number where we are now. | 2713 * line number where we are now. |
2715 * Used for error messages that include a line number. | 2714 * Used for error messages that include a line number. |
2716 */ | 2715 */ |
2717 static linenr_T | 2716 static linenr_T |
2718 readfile_linenr(linecnt, p, endp) | 2717 readfile_linenr( |
2719 linenr_T linecnt; /* line count before reading more bytes */ | 2718 linenr_T linecnt, /* line count before reading more bytes */ |
2720 char_u *p; /* start of more bytes read */ | 2719 char_u *p, /* start of more bytes read */ |
2721 char_u *endp; /* end of more bytes read */ | 2720 char_u *endp) /* end of more bytes read */ |
2722 { | 2721 { |
2723 char_u *s; | 2722 char_u *s; |
2724 linenr_T lnum; | 2723 linenr_T lnum; |
2725 | 2724 |
2726 lnum = curbuf->b_ml.ml_line_count - linecnt + 1; | 2725 lnum = curbuf->b_ml.ml_line_count - linecnt + 1; |
2735 * Fill "*eap" to force the 'fileencoding', 'fileformat' and 'binary to be | 2734 * Fill "*eap" to force the 'fileencoding', 'fileformat' and 'binary to be |
2736 * equal to the buffer "buf". Used for calling readfile(). | 2735 * equal to the buffer "buf". Used for calling readfile(). |
2737 * Returns OK or FAIL. | 2736 * Returns OK or FAIL. |
2738 */ | 2737 */ |
2739 int | 2738 int |
2740 prep_exarg(eap, buf) | 2739 prep_exarg(exarg_T *eap, buf_T *buf) |
2741 exarg_T *eap; | |
2742 buf_T *buf; | |
2743 { | 2740 { |
2744 eap->cmd = alloc((unsigned)(STRLEN(buf->b_p_ff) | 2741 eap->cmd = alloc((unsigned)(STRLEN(buf->b_p_ff) |
2745 #ifdef FEAT_MBYTE | 2742 #ifdef FEAT_MBYTE |
2746 + STRLEN(buf->b_p_fenc) | 2743 + STRLEN(buf->b_p_fenc) |
2747 #endif | 2744 #endif |
2766 | 2763 |
2767 /* | 2764 /* |
2768 * Set default or forced 'fileformat' and 'binary'. | 2765 * Set default or forced 'fileformat' and 'binary'. |
2769 */ | 2766 */ |
2770 void | 2767 void |
2771 set_file_options(set_options, eap) | 2768 set_file_options(int set_options, exarg_T *eap) |
2772 int set_options; | |
2773 exarg_T *eap; | |
2774 { | 2769 { |
2775 /* set default 'fileformat' */ | 2770 /* set default 'fileformat' */ |
2776 if (set_options) | 2771 if (set_options) |
2777 { | 2772 { |
2778 if (eap != NULL && eap->force_ff != 0) | 2773 if (eap != NULL && eap->force_ff != 0) |
2794 #if defined(FEAT_MBYTE) || defined(PROTO) | 2789 #if defined(FEAT_MBYTE) || defined(PROTO) |
2795 /* | 2790 /* |
2796 * Set forced 'fileencoding'. | 2791 * Set forced 'fileencoding'. |
2797 */ | 2792 */ |
2798 void | 2793 void |
2799 set_forced_fenc(eap) | 2794 set_forced_fenc(exarg_T *eap) |
2800 exarg_T *eap; | |
2801 { | 2795 { |
2802 if (eap->force_enc != 0) | 2796 if (eap->force_enc != 0) |
2803 { | 2797 { |
2804 char_u *fenc = enc_canonize(eap->cmd + eap->force_enc); | 2798 char_u *fenc = enc_canonize(eap->cmd + eap->force_enc); |
2805 | 2799 |
2816 * When there are no more items, an empty string is returned and *pp is set to | 2810 * When there are no more items, an empty string is returned and *pp is set to |
2817 * NULL. | 2811 * NULL. |
2818 * When *pp is not set to NULL, the result is in allocated memory. | 2812 * When *pp is not set to NULL, the result is in allocated memory. |
2819 */ | 2813 */ |
2820 static char_u * | 2814 static char_u * |
2821 next_fenc(pp) | 2815 next_fenc(char_u **pp) |
2822 char_u **pp; | |
2823 { | 2816 { |
2824 char_u *p; | 2817 char_u *p; |
2825 char_u *r; | 2818 char_u *r; |
2826 | 2819 |
2827 if (**pp == NUL) | 2820 if (**pp == NUL) |
2862 * Returns name of the resulting converted file (the caller should delete it | 2855 * Returns name of the resulting converted file (the caller should delete it |
2863 * after reading it). | 2856 * after reading it). |
2864 * Returns NULL if the conversion failed ("*fdp" is not set) . | 2857 * Returns NULL if the conversion failed ("*fdp" is not set) . |
2865 */ | 2858 */ |
2866 static char_u * | 2859 static char_u * |
2867 readfile_charconvert(fname, fenc, fdp) | 2860 readfile_charconvert( |
2868 char_u *fname; /* name of input file */ | 2861 char_u *fname, /* name of input file */ |
2869 char_u *fenc; /* converted from */ | 2862 char_u *fenc, /* converted from */ |
2870 int *fdp; /* in/out: file descriptor of file */ | 2863 int *fdp) /* in/out: file descriptor of file */ |
2871 { | 2864 { |
2872 char_u *tmpname; | 2865 char_u *tmpname; |
2873 char_u *errmsg = NULL; | 2866 char_u *errmsg = NULL; |
2874 | 2867 |
2875 tmpname = vim_tempname('r', FALSE); | 2868 tmpname = vim_tempname('r', FALSE); |
2914 /* | 2907 /* |
2915 * Read marks for the current buffer from the viminfo file, when we support | 2908 * Read marks for the current buffer from the viminfo file, when we support |
2916 * buffer marks and the buffer has a name. | 2909 * buffer marks and the buffer has a name. |
2917 */ | 2910 */ |
2918 static void | 2911 static void |
2919 check_marks_read() | 2912 check_marks_read(void) |
2920 { | 2913 { |
2921 if (!curbuf->b_marks_read && get_viminfo_parameter('\'') > 0 | 2914 if (!curbuf->b_marks_read && get_viminfo_parameter('\'') > 0 |
2922 && curbuf->b_ffname != NULL) | 2915 && curbuf->b_ffname != NULL) |
2923 read_viminfo(NULL, VIF_WANT_MARKS); | 2916 read_viminfo(NULL, VIF_WANT_MARKS); |
2924 | 2917 |
2934 * If found, the magic number is removed from ptr[*sizep] and *sizep and | 2927 * If found, the magic number is removed from ptr[*sizep] and *sizep and |
2935 * *filesizep are updated. | 2928 * *filesizep are updated. |
2936 * Return the (new) encryption key, NULL for no encryption. | 2929 * Return the (new) encryption key, NULL for no encryption. |
2937 */ | 2930 */ |
2938 static char_u * | 2931 static char_u * |
2939 check_for_cryptkey(cryptkey, ptr, sizep, filesizep, newfile, fname, did_ask) | 2932 check_for_cryptkey( |
2940 char_u *cryptkey; /* previous encryption key or NULL */ | 2933 char_u *cryptkey, /* previous encryption key or NULL */ |
2941 char_u *ptr; /* pointer to read bytes */ | 2934 char_u *ptr, /* pointer to read bytes */ |
2942 long *sizep; /* length of read bytes */ | 2935 long *sizep, /* length of read bytes */ |
2943 off_t *filesizep; /* nr of bytes used from file */ | 2936 off_t *filesizep, /* nr of bytes used from file */ |
2944 int newfile; /* editing a new buffer */ | 2937 int newfile, /* editing a new buffer */ |
2945 char_u *fname; /* file name to display */ | 2938 char_u *fname, /* file name to display */ |
2946 int *did_ask; /* flag: whether already asked for key */ | 2939 int *did_ask) /* flag: whether already asked for key */ |
2947 { | 2940 { |
2948 int method = crypt_method_nr_from_magic((char *)ptr, *sizep); | 2941 int method = crypt_method_nr_from_magic((char *)ptr, *sizep); |
2949 int b_p_ro = curbuf->b_p_ro; | 2942 int b_p_ro = curbuf->b_p_ro; |
2950 | 2943 |
2951 if (method >= 0) | 2944 if (method >= 0) |
3009 } | 3002 } |
3010 #endif /* FEAT_CRYPT */ | 3003 #endif /* FEAT_CRYPT */ |
3011 | 3004 |
3012 #ifdef UNIX | 3005 #ifdef UNIX |
3013 static void | 3006 static void |
3014 set_file_time(fname, atime, mtime) | 3007 set_file_time( |
3015 char_u *fname; | 3008 char_u *fname, |
3016 time_t atime; /* access time */ | 3009 time_t atime, /* access time */ |
3017 time_t mtime; /* modification time */ | 3010 time_t mtime) /* modification time */ |
3018 { | 3011 { |
3019 # if defined(HAVE_UTIME) && defined(HAVE_UTIME_H) | 3012 # if defined(HAVE_UTIME) && defined(HAVE_UTIME_H) |
3020 struct utimbuf buf; | 3013 struct utimbuf buf; |
3021 | 3014 |
3022 buf.actime = atime; | 3015 buf.actime = atime; |
3047 | 3040 |
3048 /* | 3041 /* |
3049 * Return TRUE if a file appears to be read-only from the file permissions. | 3042 * Return TRUE if a file appears to be read-only from the file permissions. |
3050 */ | 3043 */ |
3051 int | 3044 int |
3052 check_file_readonly(fname, perm) | 3045 check_file_readonly( |
3053 char_u *fname; /* full path to file */ | 3046 char_u *fname, /* full path to file */ |
3054 int perm; /* known permissions on file */ | 3047 int perm) /* known permissions on file */ |
3055 { | 3048 { |
3056 #ifndef USE_MCH_ACCESS | 3049 #ifndef USE_MCH_ACCESS |
3057 int fd = 0; | 3050 int fd = 0; |
3058 #endif | 3051 #endif |
3059 | 3052 |
3086 * This function must NOT use NameBuff (because it's called by autowrite()). | 3079 * This function must NOT use NameBuff (because it's called by autowrite()). |
3087 * | 3080 * |
3088 * return FAIL for failure, OK otherwise | 3081 * return FAIL for failure, OK otherwise |
3089 */ | 3082 */ |
3090 int | 3083 int |
3091 buf_write(buf, fname, sfname, start, end, eap, append, forceit, | 3084 buf_write( |
3092 reset_changed, filtering) | 3085 buf_T *buf, |
3093 buf_T *buf; | 3086 char_u *fname, |
3094 char_u *fname; | 3087 char_u *sfname, |
3095 char_u *sfname; | 3088 linenr_T start, |
3096 linenr_T start, end; | 3089 linenr_T end, |
3097 exarg_T *eap; /* for forced 'ff' and 'fenc', can be | 3090 exarg_T *eap, /* for forced 'ff' and 'fenc', can be |
3098 NULL! */ | 3091 NULL! */ |
3099 int append; /* append to the file */ | 3092 int append, /* append to the file */ |
3100 int forceit; | 3093 int forceit, |
3101 int reset_changed; | 3094 int reset_changed, |
3102 int filtering; | 3095 int filtering) |
3103 { | 3096 { |
3104 int fd; | 3097 int fd; |
3105 char_u *backup = NULL; | 3098 char_u *backup = NULL; |
3106 int backup_copy = FALSE; /* copy the original file? */ | 3099 int backup_copy = FALSE; /* copy the original file? */ |
3107 int dobackup; | 3100 int dobackup; |
5121 /* | 5114 /* |
5122 * Set the name of the current buffer. Use when the buffer doesn't have a | 5115 * Set the name of the current buffer. Use when the buffer doesn't have a |
5123 * name and a ":r" or ":w" command with a file name is used. | 5116 * name and a ":r" or ":w" command with a file name is used. |
5124 */ | 5117 */ |
5125 static int | 5118 static int |
5126 set_rw_fname(fname, sfname) | 5119 set_rw_fname(char_u *fname, char_u *sfname) |
5127 char_u *fname; | |
5128 char_u *sfname; | |
5129 { | 5120 { |
5130 #ifdef FEAT_AUTOCMD | 5121 #ifdef FEAT_AUTOCMD |
5131 buf_T *buf = curbuf; | 5122 buf_T *buf = curbuf; |
5132 | 5123 |
5133 /* It's like the unnamed buffer is deleted.... */ | 5124 /* It's like the unnamed buffer is deleted.... */ |
5173 | 5164 |
5174 /* | 5165 /* |
5175 * Put file name into IObuff with quotes. | 5166 * Put file name into IObuff with quotes. |
5176 */ | 5167 */ |
5177 void | 5168 void |
5178 msg_add_fname(buf, fname) | 5169 msg_add_fname(buf_T *buf, char_u *fname) |
5179 buf_T *buf; | |
5180 char_u *fname; | |
5181 { | 5170 { |
5182 if (fname == NULL) | 5171 if (fname == NULL) |
5183 fname = (char_u *)"-stdin-"; | 5172 fname = (char_u *)"-stdin-"; |
5184 home_replace(buf, fname, IObuff + 1, IOSIZE - 4, TRUE); | 5173 home_replace(buf, fname, IObuff + 1, IOSIZE - 4, TRUE); |
5185 IObuff[0] = '"'; | 5174 IObuff[0] = '"'; |
5189 /* | 5178 /* |
5190 * Append message for text mode to IObuff. | 5179 * Append message for text mode to IObuff. |
5191 * Return TRUE if something appended. | 5180 * Return TRUE if something appended. |
5192 */ | 5181 */ |
5193 static int | 5182 static int |
5194 msg_add_fileformat(eol_type) | 5183 msg_add_fileformat(int eol_type) |
5195 int eol_type; | |
5196 { | 5184 { |
5197 #ifndef USE_CRNL | 5185 #ifndef USE_CRNL |
5198 if (eol_type == EOL_DOS) | 5186 if (eol_type == EOL_DOS) |
5199 { | 5187 { |
5200 STRCAT(IObuff, shortmess(SHM_TEXT) ? _("[dos]") : _("[dos format]")); | 5188 STRCAT(IObuff, shortmess(SHM_TEXT) ? _("[dos]") : _("[dos format]")); |
5220 | 5208 |
5221 /* | 5209 /* |
5222 * Append line and character count to IObuff. | 5210 * Append line and character count to IObuff. |
5223 */ | 5211 */ |
5224 void | 5212 void |
5225 msg_add_lines(insert_space, lnum, nchars) | 5213 msg_add_lines( |
5226 int insert_space; | 5214 int insert_space, |
5227 long lnum; | 5215 long lnum, |
5228 off_t nchars; | 5216 off_t nchars) |
5229 { | 5217 { |
5230 char_u *p; | 5218 char_u *p; |
5231 | 5219 |
5232 p = IObuff + STRLEN(IObuff); | 5220 p = IObuff + STRLEN(IObuff); |
5233 | 5221 |
5265 | 5253 |
5266 /* | 5254 /* |
5267 * Append message for missing line separator to IObuff. | 5255 * Append message for missing line separator to IObuff. |
5268 */ | 5256 */ |
5269 static void | 5257 static void |
5270 msg_add_eol() | 5258 msg_add_eol(void) |
5271 { | 5259 { |
5272 STRCAT(IObuff, shortmess(SHM_LAST) ? _("[noeol]") : _("[Incomplete last line]")); | 5260 STRCAT(IObuff, shortmess(SHM_LAST) ? _("[noeol]") : _("[Incomplete last line]")); |
5273 } | 5261 } |
5274 | 5262 |
5275 /* | 5263 /* |
5276 * Check modification time of file, before writing to it. | 5264 * Check modification time of file, before writing to it. |
5277 * The size isn't checked, because using a tool like "gzip" takes care of | 5265 * The size isn't checked, because using a tool like "gzip" takes care of |
5278 * using the same timestamp but can't set the size. | 5266 * using the same timestamp but can't set the size. |
5279 */ | 5267 */ |
5280 static int | 5268 static int |
5281 check_mtime(buf, st) | 5269 check_mtime(buf_T *buf, struct stat *st) |
5282 buf_T *buf; | |
5283 struct stat *st; | |
5284 { | 5270 { |
5285 if (buf->b_mtime_read != 0 | 5271 if (buf->b_mtime_read != 0 |
5286 && time_differs((long)st->st_mtime, buf->b_mtime_read)) | 5272 && time_differs((long)st->st_mtime, buf->b_mtime_read)) |
5287 { | 5273 { |
5288 msg_scroll = TRUE; /* don't overwrite messages here */ | 5274 msg_scroll = TRUE; /* don't overwrite messages here */ |
5297 } | 5283 } |
5298 return OK; | 5284 return OK; |
5299 } | 5285 } |
5300 | 5286 |
5301 static int | 5287 static int |
5302 time_differs(t1, t2) | 5288 time_differs(long t1, long t2) |
5303 long t1, t2; | |
5304 { | 5289 { |
5305 #if defined(__linux__) || defined(MSDOS) || defined(MSWIN) | 5290 #if defined(__linux__) || defined(MSDOS) || defined(MSWIN) |
5306 /* On a FAT filesystem, esp. under Linux, there are only 5 bits to store | 5291 /* On a FAT filesystem, esp. under Linux, there are only 5 bits to store |
5307 * the seconds. Since the roundoff is done when flushing the inode, the | 5292 * the seconds. Since the roundoff is done when flushing the inode, the |
5308 * time may change unexpectedly by one second!!! */ | 5293 * time may change unexpectedly by one second!!! */ |
5317 * Handles encryption and 'encoding' conversion. | 5302 * Handles encryption and 'encoding' conversion. |
5318 * | 5303 * |
5319 * Return FAIL for failure, OK otherwise. | 5304 * Return FAIL for failure, OK otherwise. |
5320 */ | 5305 */ |
5321 static int | 5306 static int |
5322 buf_write_bytes(ip) | 5307 buf_write_bytes(struct bw_info *ip) |
5323 struct bw_info *ip; | |
5324 { | 5308 { |
5325 int wlen; | 5309 int wlen; |
5326 char_u *buf = ip->bw_buf; /* data to write */ | 5310 char_u *buf = ip->bw_buf; /* data to write */ |
5327 int len = ip->bw_len; /* length of data */ | 5311 int len = ip->bw_len; /* length of data */ |
5328 #ifdef HAS_BW_FLAGS | 5312 #ifdef HAS_BW_FLAGS |
5712 /* | 5696 /* |
5713 * Convert a Unicode character to bytes. | 5697 * Convert a Unicode character to bytes. |
5714 * Return TRUE for an error, FALSE when it's OK. | 5698 * Return TRUE for an error, FALSE when it's OK. |
5715 */ | 5699 */ |
5716 static int | 5700 static int |
5717 ucs2bytes(c, pp, flags) | 5701 ucs2bytes( |
5718 unsigned c; /* in: character */ | 5702 unsigned c, /* in: character */ |
5719 char_u **pp; /* in/out: pointer to result */ | 5703 char_u **pp, /* in/out: pointer to result */ |
5720 int flags; /* FIO_ flags */ | 5704 int flags) /* FIO_ flags */ |
5721 { | 5705 { |
5722 char_u *p = *pp; | 5706 char_u *p = *pp; |
5723 int error = FALSE; | 5707 int error = FALSE; |
5724 int cc; | 5708 int cc; |
5725 | 5709 |
5797 /* | 5781 /* |
5798 * Return TRUE if file encoding "fenc" requires conversion from or to | 5782 * Return TRUE if file encoding "fenc" requires conversion from or to |
5799 * 'encoding'. | 5783 * 'encoding'. |
5800 */ | 5784 */ |
5801 static int | 5785 static int |
5802 need_conversion(fenc) | 5786 need_conversion(char_u *fenc) |
5803 char_u *fenc; | |
5804 { | 5787 { |
5805 int same_encoding; | 5788 int same_encoding; |
5806 int enc_flags; | 5789 int enc_flags; |
5807 int fenc_flags; | 5790 int fenc_flags; |
5808 | 5791 |
5835 * Check "ptr" for a unicode encoding and return the FIO_ flags needed for the | 5818 * Check "ptr" for a unicode encoding and return the FIO_ flags needed for the |
5836 * internal conversion. | 5819 * internal conversion. |
5837 * if "ptr" is an empty string, use 'encoding'. | 5820 * if "ptr" is an empty string, use 'encoding'. |
5838 */ | 5821 */ |
5839 static int | 5822 static int |
5840 get_fio_flags(ptr) | 5823 get_fio_flags(char_u *ptr) |
5841 char_u *ptr; | |
5842 { | 5824 { |
5843 int prop; | 5825 int prop; |
5844 | 5826 |
5845 if (*ptr == NUL) | 5827 if (*ptr == NUL) |
5846 ptr = p_enc; | 5828 ptr = p_enc; |
5879 * Check "ptr" for a MS-Windows codepage name and return the FIO_ flags needed | 5861 * Check "ptr" for a MS-Windows codepage name and return the FIO_ flags needed |
5880 * for the conversion MS-Windows can do for us. Also accept "utf-8". | 5862 * for the conversion MS-Windows can do for us. Also accept "utf-8". |
5881 * Used for conversion between 'encoding' and 'fileencoding'. | 5863 * Used for conversion between 'encoding' and 'fileencoding'. |
5882 */ | 5864 */ |
5883 static int | 5865 static int |
5884 get_win_fio_flags(ptr) | 5866 get_win_fio_flags(char_u *ptr) |
5885 char_u *ptr; | |
5886 { | 5867 { |
5887 int cp; | 5868 int cp; |
5888 | 5869 |
5889 /* Cannot do this when 'encoding' is not utf-8 and not a codepage. */ | 5870 /* Cannot do this when 'encoding' is not utf-8 and not a codepage. */ |
5890 if (!enc_utf8 && enc_codepage <= 0) | 5871 if (!enc_utf8 && enc_codepage <= 0) |
5908 /* | 5889 /* |
5909 * Check "ptr" for a Carbon supported encoding and return the FIO_ flags | 5890 * Check "ptr" for a Carbon supported encoding and return the FIO_ flags |
5910 * needed for the internal conversion to/from utf-8 or latin1. | 5891 * needed for the internal conversion to/from utf-8 or latin1. |
5911 */ | 5892 */ |
5912 static int | 5893 static int |
5913 get_mac_fio_flags(ptr) | 5894 get_mac_fio_flags(char_u *ptr) |
5914 char_u *ptr; | |
5915 { | 5895 { |
5916 if ((enc_utf8 || STRCMP(p_enc, "latin1") == 0) | 5896 if ((enc_utf8 || STRCMP(p_enc, "latin1") == 0) |
5917 && (enc_canon_props(ptr) & ENC_MACROMAN)) | 5897 && (enc_canon_props(ptr) & ENC_MACROMAN)) |
5918 return FIO_MACROMAN; | 5898 return FIO_MACROMAN; |
5919 return 0; | 5899 return 0; |
5925 * "size" must be at least 2. | 5905 * "size" must be at least 2. |
5926 * Return the name of the encoding and set "*lenp" to the length. | 5906 * Return the name of the encoding and set "*lenp" to the length. |
5927 * Returns NULL when no BOM found. | 5907 * Returns NULL when no BOM found. |
5928 */ | 5908 */ |
5929 static char_u * | 5909 static char_u * |
5930 check_for_bom(p, size, lenp, flags) | 5910 check_for_bom( |
5931 char_u *p; | 5911 char_u *p, |
5932 long size; | 5912 long size, |
5933 int *lenp; | 5913 int *lenp, |
5934 int flags; | 5914 int flags) |
5935 { | 5915 { |
5936 char *name = NULL; | 5916 char *name = NULL; |
5937 int len = 2; | 5917 int len = 2; |
5938 | 5918 |
5939 if (p[0] == 0xef && p[1] == 0xbb && size >= 3 && p[2] == 0xbf | 5919 if (p[0] == 0xef && p[1] == 0xbb && size >= 3 && p[2] == 0xbf |
5979 /* | 5959 /* |
5980 * Generate a BOM in "buf[4]" for encoding "name". | 5960 * Generate a BOM in "buf[4]" for encoding "name". |
5981 * Return the length of the BOM (zero when no BOM). | 5961 * Return the length of the BOM (zero when no BOM). |
5982 */ | 5962 */ |
5983 static int | 5963 static int |
5984 make_bom(buf, name) | 5964 make_bom(char_u *buf, char_u *name) |
5985 char_u *buf; | |
5986 char_u *name; | |
5987 { | 5965 { |
5988 int flags; | 5966 int flags; |
5989 char_u *p; | 5967 char_u *p; |
5990 | 5968 |
5991 flags = get_fio_flags(name); | 5969 flags = get_fio_flags(name); |
6013 * Try to find a shortname by comparing the fullname with the current | 5991 * Try to find a shortname by comparing the fullname with the current |
6014 * directory. | 5992 * directory. |
6015 * Returns "full_path" or pointer into "full_path" if shortened. | 5993 * Returns "full_path" or pointer into "full_path" if shortened. |
6016 */ | 5994 */ |
6017 char_u * | 5995 char_u * |
6018 shorten_fname1(full_path) | 5996 shorten_fname1(char_u *full_path) |
6019 char_u *full_path; | |
6020 { | 5997 { |
6021 char_u *dirname; | 5998 char_u *dirname; |
6022 char_u *p = full_path; | 5999 char_u *p = full_path; |
6023 | 6000 |
6024 dirname = alloc(MAXPATHL); | 6001 dirname = alloc(MAXPATHL); |
6040 * directory. | 6017 * directory. |
6041 * Returns NULL if not shorter name possible, pointer into "full_path" | 6018 * Returns NULL if not shorter name possible, pointer into "full_path" |
6042 * otherwise. | 6019 * otherwise. |
6043 */ | 6020 */ |
6044 char_u * | 6021 char_u * |
6045 shorten_fname(full_path, dir_name) | 6022 shorten_fname(char_u *full_path, char_u *dir_name) |
6046 char_u *full_path; | |
6047 char_u *dir_name; | |
6048 { | 6023 { |
6049 int len; | 6024 int len; |
6050 char_u *p; | 6025 char_u *p; |
6051 | 6026 |
6052 if (full_path == NULL) | 6027 if (full_path == NULL) |
6097 * When "force" is FALSE: Only try to shorten absolute file names. | 6072 * When "force" is FALSE: Only try to shorten absolute file names. |
6098 * For buffers that have buftype "nofile" or "scratch": never change the file | 6073 * For buffers that have buftype "nofile" or "scratch": never change the file |
6099 * name. | 6074 * name. |
6100 */ | 6075 */ |
6101 void | 6076 void |
6102 shorten_fnames(force) | 6077 shorten_fnames(int force) |
6103 int force; | |
6104 { | 6078 { |
6105 char_u dirname[MAXPATHL]; | 6079 char_u dirname[MAXPATHL]; |
6106 buf_T *buf; | 6080 buf_T *buf; |
6107 char_u *p; | 6081 char_u *p; |
6108 | 6082 |
6146 || defined(PROTO) | 6120 || defined(PROTO) |
6147 /* | 6121 /* |
6148 * Shorten all filenames in "fnames[count]" by current directory. | 6122 * Shorten all filenames in "fnames[count]" by current directory. |
6149 */ | 6123 */ |
6150 void | 6124 void |
6151 shorten_filenames(fnames, count) | 6125 shorten_filenames(char_u **fnames, int count) |
6152 char_u **fnames; | |
6153 int count; | |
6154 { | 6126 { |
6155 int i; | 6127 int i; |
6156 char_u dirname[MAXPATHL]; | 6128 char_u dirname[MAXPATHL]; |
6157 char_u *p; | 6129 char_u *p; |
6158 | 6130 |
6184 * characters otherwise. | 6156 * characters otherwise. |
6185 * Space for the returned name is allocated, must be freed later. | 6157 * Space for the returned name is allocated, must be freed later. |
6186 * Returns NULL when out of memory. | 6158 * Returns NULL when out of memory. |
6187 */ | 6159 */ |
6188 char_u * | 6160 char_u * |
6189 modname(fname, ext, prepend_dot) | 6161 modname( |
6190 char_u *fname, *ext; | 6162 char_u *fname, |
6191 int prepend_dot; /* may prepend a '.' to file name */ | 6163 char_u *ext, |
6164 int prepend_dot) /* may prepend a '.' to file name */ | |
6192 { | 6165 { |
6193 return buf_modname( | 6166 return buf_modname( |
6194 #ifdef SHORT_FNAME | 6167 #ifdef SHORT_FNAME |
6195 TRUE, | 6168 TRUE, |
6196 #else | 6169 #else |
6198 #endif | 6171 #endif |
6199 fname, ext, prepend_dot); | 6172 fname, ext, prepend_dot); |
6200 } | 6173 } |
6201 | 6174 |
6202 char_u * | 6175 char_u * |
6203 buf_modname(shortname, fname, ext, prepend_dot) | 6176 buf_modname( |
6204 int shortname; /* use 8.3 file name */ | 6177 int shortname, /* use 8.3 file name */ |
6205 char_u *fname, *ext; | 6178 char_u *fname, |
6206 int prepend_dot; /* may prepend a '.' to file name */ | 6179 char_u *ext, |
6180 int prepend_dot) /* may prepend a '.' to file name */ | |
6207 { | 6181 { |
6208 char_u *retval; | 6182 char_u *retval; |
6209 char_u *s; | 6183 char_u *s; |
6210 char_u *e; | 6184 char_u *e; |
6211 char_u *ptr; | 6185 char_u *ptr; |
6385 /* | 6359 /* |
6386 * Like fgets(), but if the file line is too long, it is truncated and the | 6360 * Like fgets(), but if the file line is too long, it is truncated and the |
6387 * rest of the line is thrown away. Returns TRUE for end-of-file. | 6361 * rest of the line is thrown away. Returns TRUE for end-of-file. |
6388 */ | 6362 */ |
6389 int | 6363 int |
6390 vim_fgets(buf, size, fp) | 6364 vim_fgets(char_u *buf, int size, FILE *fp) |
6391 char_u *buf; | |
6392 int size; | |
6393 FILE *fp; | |
6394 { | 6365 { |
6395 char *eof; | 6366 char *eof; |
6396 #define FGETS_SIZE 200 | 6367 #define FGETS_SIZE 200 |
6397 char tbuf[FGETS_SIZE]; | 6368 char tbuf[FGETS_SIZE]; |
6398 | 6369 |
6425 * Like vim_fgets(), but accept any line terminator: CR, CR-LF or LF. | 6396 * Like vim_fgets(), but accept any line terminator: CR, CR-LF or LF. |
6426 * Returns TRUE for end-of-file. | 6397 * Returns TRUE for end-of-file. |
6427 * Only used for the Mac, because it's much slower than vim_fgets(). | 6398 * Only used for the Mac, because it's much slower than vim_fgets(). |
6428 */ | 6399 */ |
6429 int | 6400 int |
6430 tag_fgets(buf, size, fp) | 6401 tag_fgets(char_u *buf, int size, FILE *fp) |
6431 char_u *buf; | |
6432 int size; | |
6433 FILE *fp; | |
6434 { | 6402 { |
6435 int i = 0; | 6403 int i = 0; |
6436 int c; | 6404 int c; |
6437 int eof = FALSE; | 6405 int eof = FALSE; |
6438 | 6406 |
6468 * rename() only works if both files are on the same file system, this | 6436 * rename() only works if both files are on the same file system, this |
6469 * function will (attempts to?) copy the file across if rename fails -- webb | 6437 * function will (attempts to?) copy the file across if rename fails -- webb |
6470 * Return -1 for failure, 0 for success. | 6438 * Return -1 for failure, 0 for success. |
6471 */ | 6439 */ |
6472 int | 6440 int |
6473 vim_rename(from, to) | 6441 vim_rename(char_u *from, char_u *to) |
6474 char_u *from; | |
6475 char_u *to; | |
6476 { | 6442 { |
6477 int fd_in; | 6443 int fd_in; |
6478 int fd_out; | 6444 int fd_out; |
6479 int n; | 6445 int n; |
6480 char *errmsg = NULL; | 6446 char *errmsg = NULL; |
6688 * busy. | 6654 * busy. |
6689 * Returns TRUE if some message was written (screen should be redrawn and | 6655 * Returns TRUE if some message was written (screen should be redrawn and |
6690 * cursor positioned). | 6656 * cursor positioned). |
6691 */ | 6657 */ |
6692 int | 6658 int |
6693 check_timestamps(focus) | 6659 check_timestamps( |
6694 int focus; /* called for GUI focus event */ | 6660 int focus) /* called for GUI focus event */ |
6695 { | 6661 { |
6696 buf_T *buf; | 6662 buf_T *buf; |
6697 int didit = 0; | 6663 int didit = 0; |
6698 int n; | 6664 int n; |
6699 | 6665 |
6756 * Move all the lines from buffer "frombuf" to buffer "tobuf". | 6722 * Move all the lines from buffer "frombuf" to buffer "tobuf". |
6757 * Return OK or FAIL. When FAIL "tobuf" is incomplete and/or "frombuf" is not | 6723 * Return OK or FAIL. When FAIL "tobuf" is incomplete and/or "frombuf" is not |
6758 * empty. | 6724 * empty. |
6759 */ | 6725 */ |
6760 static int | 6726 static int |
6761 move_lines(frombuf, tobuf) | 6727 move_lines(buf_T *frombuf, buf_T *tobuf) |
6762 buf_T *frombuf; | |
6763 buf_T *tobuf; | |
6764 { | 6728 { |
6765 buf_T *tbuf = curbuf; | 6729 buf_T *tbuf = curbuf; |
6766 int retval = OK; | 6730 int retval = OK; |
6767 linenr_T lnum; | 6731 linenr_T lnum; |
6768 char_u *p; | 6732 char_u *p; |
6805 * return 1 if a changed buffer was found. | 6769 * return 1 if a changed buffer was found. |
6806 * return 2 if a message has been displayed. | 6770 * return 2 if a message has been displayed. |
6807 * return 0 otherwise. | 6771 * return 0 otherwise. |
6808 */ | 6772 */ |
6809 int | 6773 int |
6810 buf_check_timestamp(buf, focus) | 6774 buf_check_timestamp( |
6811 buf_T *buf; | 6775 buf_T *buf, |
6812 int focus UNUSED; /* called for GUI focus event */ | 6776 int focus UNUSED) /* called for GUI focus event */ |
6813 { | 6777 { |
6814 struct stat st; | 6778 struct stat st; |
6815 int stat_res; | 6779 int stat_res; |
6816 int retval = 0; | 6780 int retval = 0; |
6817 char_u *path; | 6781 char_u *path; |
7098 * Used when the file was changed outside of Vim. | 7062 * Used when the file was changed outside of Vim. |
7099 * "orig_mode" is buf->b_orig_mode before the need for reloading was detected. | 7063 * "orig_mode" is buf->b_orig_mode before the need for reloading was detected. |
7100 * buf->b_orig_mode may have been reset already. | 7064 * buf->b_orig_mode may have been reset already. |
7101 */ | 7065 */ |
7102 void | 7066 void |
7103 buf_reload(buf, orig_mode) | 7067 buf_reload(buf_T *buf, int orig_mode) |
7104 buf_T *buf; | |
7105 int orig_mode; | |
7106 { | 7068 { |
7107 exarg_T ea; | 7069 exarg_T ea; |
7108 pos_T old_cursor; | 7070 pos_T old_cursor; |
7109 linenr_T old_topline; | 7071 linenr_T old_topline; |
7110 int old_ro = buf->b_p_ro; | 7072 int old_ro = buf->b_p_ro; |
7252 aucmd_restbuf(&aco); | 7214 aucmd_restbuf(&aco); |
7253 /* Careful: autocommands may have made "buf" invalid! */ | 7215 /* Careful: autocommands may have made "buf" invalid! */ |
7254 } | 7216 } |
7255 | 7217 |
7256 void | 7218 void |
7257 buf_store_time(buf, st, fname) | 7219 buf_store_time(buf_T *buf, struct stat *st, char_u *fname UNUSED) |
7258 buf_T *buf; | |
7259 struct stat *st; | |
7260 char_u *fname UNUSED; | |
7261 { | 7220 { |
7262 buf->b_mtime = (long)st->st_mtime; | 7221 buf->b_mtime = (long)st->st_mtime; |
7263 buf->b_orig_size = st->st_size; | 7222 buf->b_orig_size = st->st_size; |
7264 #ifdef HAVE_ST_MODE | 7223 #ifdef HAVE_ST_MODE |
7265 buf->b_orig_mode = (int)st->st_mode; | 7224 buf->b_orig_mode = (int)st->st_mode; |
7271 /* | 7230 /* |
7272 * Adjust the line with missing eol, used for the next write. | 7231 * Adjust the line with missing eol, used for the next write. |
7273 * Used for do_filter(), when the input lines for the filter are deleted. | 7232 * Used for do_filter(), when the input lines for the filter are deleted. |
7274 */ | 7233 */ |
7275 void | 7234 void |
7276 write_lnum_adjust(offset) | 7235 write_lnum_adjust(linenr_T offset) |
7277 linenr_T offset; | |
7278 { | 7236 { |
7279 if (curbuf->b_no_eol_lnum != 0) /* only if there is a missing eol */ | 7237 if (curbuf->b_no_eol_lnum != 0) /* only if there is a missing eol */ |
7280 curbuf->b_no_eol_lnum += offset; | 7238 curbuf->b_no_eol_lnum += offset; |
7281 } | 7239 } |
7282 | 7240 |
7333 | 7291 |
7334 /* | 7292 /* |
7335 * Delete the temp directory and all files it contains. | 7293 * Delete the temp directory and all files it contains. |
7336 */ | 7294 */ |
7337 void | 7295 void |
7338 vim_deltempdir() | 7296 vim_deltempdir(void) |
7339 { | 7297 { |
7340 if (vim_tempdir != NULL) | 7298 if (vim_tempdir != NULL) |
7341 { | 7299 { |
7342 /* remove the trailing path separator */ | 7300 /* remove the trailing path separator */ |
7343 gettail(vim_tempdir)[-1] = NUL; | 7301 gettail(vim_tempdir)[-1] = NUL; |
7351 * Directory "tempdir" was created. Expand this name to a full path and put | 7309 * Directory "tempdir" was created. Expand this name to a full path and put |
7352 * it in "vim_tempdir". This avoids that using ":cd" would confuse us. | 7310 * it in "vim_tempdir". This avoids that using ":cd" would confuse us. |
7353 * "tempdir" must be no longer than MAXPATHL. | 7311 * "tempdir" must be no longer than MAXPATHL. |
7354 */ | 7312 */ |
7355 static void | 7313 static void |
7356 vim_settempdir(tempdir) | 7314 vim_settempdir(char_u *tempdir) |
7357 char_u *tempdir; | |
7358 { | 7315 { |
7359 char_u *buf; | 7316 char_u *buf; |
7360 | 7317 |
7361 buf = alloc((unsigned)MAXPATHL + 2); | 7318 buf = alloc((unsigned)MAXPATHL + 2); |
7362 if (buf != NULL) | 7319 if (buf != NULL) |
7383 * | 7340 * |
7384 * The returned pointer is to allocated memory. | 7341 * The returned pointer is to allocated memory. |
7385 * The returned pointer is NULL if no valid name was found. | 7342 * The returned pointer is NULL if no valid name was found. |
7386 */ | 7343 */ |
7387 char_u * | 7344 char_u * |
7388 vim_tempname(extra_char, keep) | 7345 vim_tempname( |
7389 int extra_char UNUSED; /* char to use in the name instead of '?' */ | 7346 int extra_char UNUSED, /* char to use in the name instead of '?' */ |
7390 int keep UNUSED; | 7347 int keep UNUSED) |
7391 { | 7348 { |
7392 #ifdef USE_TMPNAM | 7349 #ifdef USE_TMPNAM |
7393 char_u itmp[L_tmpnam]; /* use tmpnam() */ | 7350 char_u itmp[L_tmpnam]; /* use tmpnam() */ |
7394 #else | 7351 #else |
7395 char_u itmp[TEMPNAMELEN]; | 7352 char_u itmp[TEMPNAMELEN]; |
7585 /* | 7542 /* |
7586 * Convert all backslashes in fname to forward slashes in-place, unless when | 7543 * Convert all backslashes in fname to forward slashes in-place, unless when |
7587 * it looks like a URL. | 7544 * it looks like a URL. |
7588 */ | 7545 */ |
7589 void | 7546 void |
7590 forward_slash(fname) | 7547 forward_slash(char_u *fname) |
7591 char_u *fname; | |
7592 { | 7548 { |
7593 char_u *p; | 7549 char_u *p; |
7594 | 7550 |
7595 if (path_with_url(fname)) | 7551 if (path_with_url(fname)) |
7596 return; | 7552 return; |
7836 | 7792 |
7837 /* | 7793 /* |
7838 * Show the autocommands for one AutoPat. | 7794 * Show the autocommands for one AutoPat. |
7839 */ | 7795 */ |
7840 static void | 7796 static void |
7841 show_autocmd(ap, event) | 7797 show_autocmd(AutoPat *ap, event_T event) |
7842 AutoPat *ap; | |
7843 event_T event; | |
7844 { | 7798 { |
7845 AutoCmd *ac; | 7799 AutoCmd *ac; |
7846 | 7800 |
7847 /* Check for "got_int" (here and at various places below), which is set | 7801 /* Check for "got_int" (here and at various places below), which is set |
7848 * when "q" has been hit for the "--more--" prompt */ | 7802 * when "q" has been hit for the "--more--" prompt */ |
7902 | 7856 |
7903 /* | 7857 /* |
7904 * Mark an autocommand pattern for deletion. | 7858 * Mark an autocommand pattern for deletion. |
7905 */ | 7859 */ |
7906 static void | 7860 static void |
7907 au_remove_pat(ap) | 7861 au_remove_pat(AutoPat *ap) |
7908 AutoPat *ap; | |
7909 { | 7862 { |
7910 vim_free(ap->pat); | 7863 vim_free(ap->pat); |
7911 ap->pat = NULL; | 7864 ap->pat = NULL; |
7912 ap->buflocal_nr = -1; | 7865 ap->buflocal_nr = -1; |
7913 au_need_clean = TRUE; | 7866 au_need_clean = TRUE; |
7915 | 7868 |
7916 /* | 7869 /* |
7917 * Mark all commands for a pattern for deletion. | 7870 * Mark all commands for a pattern for deletion. |
7918 */ | 7871 */ |
7919 static void | 7872 static void |
7920 au_remove_cmds(ap) | 7873 au_remove_cmds(AutoPat *ap) |
7921 AutoPat *ap; | |
7922 { | 7874 { |
7923 AutoCmd *ac; | 7875 AutoCmd *ac; |
7924 | 7876 |
7925 for (ac = ap->cmds; ac != NULL; ac = ac->next) | 7877 for (ac = ap->cmds; ac != NULL; ac = ac->next) |
7926 { | 7878 { |
7933 /* | 7885 /* |
7934 * Cleanup autocommands and patterns that have been deleted. | 7886 * Cleanup autocommands and patterns that have been deleted. |
7935 * This is only done when not executing autocommands. | 7887 * This is only done when not executing autocommands. |
7936 */ | 7888 */ |
7937 static void | 7889 static void |
7938 au_cleanup() | 7890 au_cleanup(void) |
7939 { | 7891 { |
7940 AutoPat *ap, **prev_ap; | 7892 AutoPat *ap, **prev_ap; |
7941 AutoCmd *ac, **prev_ac; | 7893 AutoCmd *ac, **prev_ac; |
7942 event_T event; | 7894 event_T event; |
7943 | 7895 |
7986 /* | 7938 /* |
7987 * Called when buffer is freed, to remove/invalidate related buffer-local | 7939 * Called when buffer is freed, to remove/invalidate related buffer-local |
7988 * autocmds. | 7940 * autocmds. |
7989 */ | 7941 */ |
7990 void | 7942 void |
7991 aubuflocal_remove(buf) | 7943 aubuflocal_remove(buf_T *buf) |
7992 buf_T *buf; | |
7993 { | 7944 { |
7994 AutoPat *ap; | 7945 AutoPat *ap; |
7995 event_T event; | 7946 event_T event; |
7996 AutoPatCmd *apc; | 7947 AutoPatCmd *apc; |
7997 | 7948 |
8023 /* | 7974 /* |
8024 * Add an autocmd group name. | 7975 * Add an autocmd group name. |
8025 * Return it's ID. Returns AUGROUP_ERROR (< 0) for error. | 7976 * Return it's ID. Returns AUGROUP_ERROR (< 0) for error. |
8026 */ | 7977 */ |
8027 static int | 7978 static int |
8028 au_new_group(name) | 7979 au_new_group(char_u *name) |
8029 char_u *name; | |
8030 { | 7980 { |
8031 int i; | 7981 int i; |
8032 | 7982 |
8033 i = au_find_group(name); | 7983 i = au_find_group(name); |
8034 if (i == AUGROUP_ERROR) /* the group doesn't exist yet, add it */ | 7984 if (i == AUGROUP_ERROR) /* the group doesn't exist yet, add it */ |
8049 | 7999 |
8050 return i; | 8000 return i; |
8051 } | 8001 } |
8052 | 8002 |
8053 static void | 8003 static void |
8054 au_del_group(name) | 8004 au_del_group(char_u *name) |
8055 char_u *name; | |
8056 { | 8005 { |
8057 int i; | 8006 int i; |
8058 | 8007 |
8059 i = au_find_group(name); | 8008 i = au_find_group(name); |
8060 if (i == AUGROUP_ERROR) /* the group doesn't exist */ | 8009 if (i == AUGROUP_ERROR) /* the group doesn't exist */ |
8069 /* | 8018 /* |
8070 * Find the ID of an autocmd group name. | 8019 * Find the ID of an autocmd group name. |
8071 * Return it's ID. Returns AUGROUP_ERROR (< 0) for error. | 8020 * Return it's ID. Returns AUGROUP_ERROR (< 0) for error. |
8072 */ | 8021 */ |
8073 static int | 8022 static int |
8074 au_find_group(name) | 8023 au_find_group(char_u *name) |
8075 char_u *name; | |
8076 { | 8024 { |
8077 int i; | 8025 int i; |
8078 | 8026 |
8079 for (i = 0; i < augroups.ga_len; ++i) | 8027 for (i = 0; i < augroups.ga_len; ++i) |
8080 if (AUGROUP_NAME(i) != NULL && STRCMP(AUGROUP_NAME(i), name) == 0) | 8028 if (AUGROUP_NAME(i) != NULL && STRCMP(AUGROUP_NAME(i), name) == 0) |
8084 | 8032 |
8085 /* | 8033 /* |
8086 * Return TRUE if augroup "name" exists. | 8034 * Return TRUE if augroup "name" exists. |
8087 */ | 8035 */ |
8088 int | 8036 int |
8089 au_has_group(name) | 8037 au_has_group(char_u *name) |
8090 char_u *name; | |
8091 { | 8038 { |
8092 return au_find_group(name) != AUGROUP_ERROR; | 8039 return au_find_group(name) != AUGROUP_ERROR; |
8093 } | 8040 } |
8094 | 8041 |
8095 /* | 8042 /* |
8096 * ":augroup {name}". | 8043 * ":augroup {name}". |
8097 */ | 8044 */ |
8098 void | 8045 void |
8099 do_augroup(arg, del_group) | 8046 do_augroup(char_u *arg, int del_group) |
8100 char_u *arg; | |
8101 int del_group; | |
8102 { | 8047 { |
8103 int i; | 8048 int i; |
8104 | 8049 |
8105 if (del_group) | 8050 if (del_group) |
8106 { | 8051 { |
8133 } | 8078 } |
8134 } | 8079 } |
8135 | 8080 |
8136 #if defined(EXITFREE) || defined(PROTO) | 8081 #if defined(EXITFREE) || defined(PROTO) |
8137 void | 8082 void |
8138 free_all_autocmds() | 8083 free_all_autocmds(void) |
8139 { | 8084 { |
8140 for (current_augroup = -1; current_augroup < augroups.ga_len; | 8085 for (current_augroup = -1; current_augroup < augroups.ga_len; |
8141 ++current_augroup) | 8086 ++current_augroup) |
8142 do_autocmd((char_u *)"", TRUE); | 8087 do_autocmd((char_u *)"", TRUE); |
8143 ga_clear_strings(&augroups); | 8088 ga_clear_strings(&augroups); |
8148 * Return the event number for event name "start". | 8093 * Return the event number for event name "start". |
8149 * Return NUM_EVENTS if the event name was not found. | 8094 * Return NUM_EVENTS if the event name was not found. |
8150 * Return a pointer to the next event name in "end". | 8095 * Return a pointer to the next event name in "end". |
8151 */ | 8096 */ |
8152 static event_T | 8097 static event_T |
8153 event_name2nr(start, end) | 8098 event_name2nr(char_u *start, char_u **end) |
8154 char_u *start; | |
8155 char_u **end; | |
8156 { | 8099 { |
8157 char_u *p; | 8100 char_u *p; |
8158 int i; | 8101 int i; |
8159 int len; | 8102 int len; |
8160 | 8103 |
8177 | 8120 |
8178 /* | 8121 /* |
8179 * Return the name for event "event". | 8122 * Return the name for event "event". |
8180 */ | 8123 */ |
8181 static char_u * | 8124 static char_u * |
8182 event_nr2name(event) | 8125 event_nr2name(event_T event) |
8183 event_T event; | |
8184 { | 8126 { |
8185 int i; | 8127 int i; |
8186 | 8128 |
8187 for (i = 0; event_names[i].name != NULL; ++i) | 8129 for (i = 0; event_names[i].name != NULL; ++i) |
8188 if (event_names[i].event == event) | 8130 if (event_names[i].event == event) |
8192 | 8134 |
8193 /* | 8135 /* |
8194 * Scan over the events. "*" stands for all events. | 8136 * Scan over the events. "*" stands for all events. |
8195 */ | 8137 */ |
8196 static char_u * | 8138 static char_u * |
8197 find_end_event(arg, have_group) | 8139 find_end_event( |
8198 char_u *arg; | 8140 char_u *arg, |
8199 int have_group; /* TRUE when group name was found */ | 8141 int have_group) /* TRUE when group name was found */ |
8200 { | 8142 { |
8201 char_u *pat; | 8143 char_u *pat; |
8202 char_u *p; | 8144 char_u *p; |
8203 | 8145 |
8204 if (*arg == '*') | 8146 if (*arg == '*') |
8229 | 8171 |
8230 /* | 8172 /* |
8231 * Return TRUE if "event" is included in 'eventignore'. | 8173 * Return TRUE if "event" is included in 'eventignore'. |
8232 */ | 8174 */ |
8233 static int | 8175 static int |
8234 event_ignored(event) | 8176 event_ignored(event_T event) |
8235 event_T event; | |
8236 { | 8177 { |
8237 char_u *p = p_ei; | 8178 char_u *p = p_ei; |
8238 | 8179 |
8239 while (*p != NUL) | 8180 while (*p != NUL) |
8240 { | 8181 { |
8249 | 8190 |
8250 /* | 8191 /* |
8251 * Return OK when the contents of p_ei is valid, FAIL otherwise. | 8192 * Return OK when the contents of p_ei is valid, FAIL otherwise. |
8252 */ | 8193 */ |
8253 int | 8194 int |
8254 check_ei() | 8195 check_ei(void) |
8255 { | 8196 { |
8256 char_u *p = p_ei; | 8197 char_u *p = p_ei; |
8257 | 8198 |
8258 while (*p) | 8199 while (*p) |
8259 { | 8200 { |
8276 * Add "what" to 'eventignore' to skip loading syntax highlighting for every | 8217 * Add "what" to 'eventignore' to skip loading syntax highlighting for every |
8277 * buffer loaded into the window. "what" must start with a comma. | 8218 * buffer loaded into the window. "what" must start with a comma. |
8278 * Returns the old value of 'eventignore' in allocated memory. | 8219 * Returns the old value of 'eventignore' in allocated memory. |
8279 */ | 8220 */ |
8280 char_u * | 8221 char_u * |
8281 au_event_disable(what) | 8222 au_event_disable(char *what) |
8282 char *what; | |
8283 { | 8223 { |
8284 char_u *new_ei; | 8224 char_u *new_ei; |
8285 char_u *save_ei; | 8225 char_u *save_ei; |
8286 | 8226 |
8287 save_ei = vim_strsave(p_ei); | 8227 save_ei = vim_strsave(p_ei); |
8301 } | 8241 } |
8302 return save_ei; | 8242 return save_ei; |
8303 } | 8243 } |
8304 | 8244 |
8305 void | 8245 void |
8306 au_event_restore(old_ei) | 8246 au_event_restore(char_u *old_ei) |
8307 char_u *old_ei; | |
8308 { | 8247 { |
8309 if (old_ei != NULL) | 8248 if (old_ei != NULL) |
8310 { | 8249 { |
8311 set_string_option_direct((char_u *)"ei", -1, old_ei, | 8250 set_string_option_direct((char_u *)"ei", -1, old_ei, |
8312 OPT_FREE, SID_NONE); | 8251 OPT_FREE, SID_NONE); |
8346 * :autocmd * *.c show all autocommands for *.c files. | 8285 * :autocmd * *.c show all autocommands for *.c files. |
8347 * | 8286 * |
8348 * Mostly a {group} argument can optionally appear before <event>. | 8287 * Mostly a {group} argument can optionally appear before <event>. |
8349 */ | 8288 */ |
8350 void | 8289 void |
8351 do_autocmd(arg, forceit) | 8290 do_autocmd(char_u *arg, int forceit) |
8352 char_u *arg; | |
8353 int forceit; | |
8354 { | 8291 { |
8355 char_u *pat; | 8292 char_u *pat; |
8356 char_u *envpat = NULL; | 8293 char_u *envpat = NULL; |
8357 char_u *cmd; | 8294 char_u *cmd; |
8358 event_T event; | 8295 event_T event; |
8464 * The "argp" argument is advanced to the following argument. | 8401 * The "argp" argument is advanced to the following argument. |
8465 * | 8402 * |
8466 * Returns the group ID, AUGROUP_ERROR for error (out of memory). | 8403 * Returns the group ID, AUGROUP_ERROR for error (out of memory). |
8467 */ | 8404 */ |
8468 static int | 8405 static int |
8469 au_get_grouparg(argp) | 8406 au_get_grouparg(char_u **argp) |
8470 char_u **argp; | |
8471 { | 8407 { |
8472 char_u *group_name; | 8408 char_u *group_name; |
8473 char_u *p; | 8409 char_u *p; |
8474 char_u *arg = *argp; | 8410 char_u *arg = *argp; |
8475 int group = AUGROUP_ALL; | 8411 int group = AUGROUP_ALL; |
8496 * If *cmd == NUL show entries. | 8432 * If *cmd == NUL show entries. |
8497 * If forceit == TRUE delete entries. | 8433 * If forceit == TRUE delete entries. |
8498 * If group is not AUGROUP_ALL, only use this group. | 8434 * If group is not AUGROUP_ALL, only use this group. |
8499 */ | 8435 */ |
8500 static int | 8436 static int |
8501 do_autocmd_event(event, pat, nested, cmd, forceit, group) | 8437 do_autocmd_event( |
8502 event_T event; | 8438 event_T event, |
8503 char_u *pat; | 8439 char_u *pat, |
8504 int nested; | 8440 int nested, |
8505 char_u *cmd; | 8441 char_u *cmd, |
8506 int forceit; | 8442 int forceit, |
8507 int group; | 8443 int group) |
8508 { | 8444 { |
8509 AutoPat *ap; | 8445 AutoPat *ap; |
8510 AutoPat **prev_ap; | 8446 AutoPat **prev_ap; |
8511 AutoCmd *ac; | 8447 AutoCmd *ac; |
8512 AutoCmd **prev_ac; | 8448 AutoCmd **prev_ac; |
8745 /* | 8681 /* |
8746 * Implementation of ":doautocmd [group] event [fname]". | 8682 * Implementation of ":doautocmd [group] event [fname]". |
8747 * Return OK for success, FAIL for failure; | 8683 * Return OK for success, FAIL for failure; |
8748 */ | 8684 */ |
8749 int | 8685 int |
8750 do_doautocmd(arg, do_msg) | 8686 do_doautocmd( |
8751 char_u *arg; | 8687 char_u *arg, |
8752 int do_msg; /* give message for no matching autocmds? */ | 8688 int do_msg) /* give message for no matching autocmds? */ |
8753 { | 8689 { |
8754 char_u *fname; | 8690 char_u *fname; |
8755 int nothing_done = TRUE; | 8691 int nothing_done = TRUE; |
8756 int group; | 8692 int group; |
8757 | 8693 |
8798 | 8734 |
8799 /* | 8735 /* |
8800 * ":doautoall": execute autocommands for each loaded buffer. | 8736 * ":doautoall": execute autocommands for each loaded buffer. |
8801 */ | 8737 */ |
8802 void | 8738 void |
8803 ex_doautoall(eap) | 8739 ex_doautoall(exarg_T *eap) |
8804 exarg_T *eap; | |
8805 { | 8740 { |
8806 int retval; | 8741 int retval; |
8807 aco_save_T aco; | 8742 aco_save_T aco; |
8808 buf_T *buf; | 8743 buf_T *buf; |
8809 char_u *arg = eap->arg; | 8744 char_u *arg = eap->arg; |
8850 * Check *argp for <nomodeline>. When it is present return FALSE, otherwise | 8785 * Check *argp for <nomodeline>. When it is present return FALSE, otherwise |
8851 * return TRUE and advance *argp to after it. | 8786 * return TRUE and advance *argp to after it. |
8852 * Thus return TRUE when do_modelines() should be called. | 8787 * Thus return TRUE when do_modelines() should be called. |
8853 */ | 8788 */ |
8854 int | 8789 int |
8855 check_nomodeline(argp) | 8790 check_nomodeline(char_u **argp) |
8856 char_u **argp; | |
8857 { | 8791 { |
8858 if (STRNCMP(*argp, "<nomodeline>", 12) == 0) | 8792 if (STRNCMP(*argp, "<nomodeline>", 12) == 0) |
8859 { | 8793 { |
8860 *argp = skipwhite(*argp + 12); | 8794 *argp = skipwhite(*argp + 12); |
8861 return FALSE; | 8795 return FALSE; |
8869 * one then use "aucmd_win". | 8803 * one then use "aucmd_win". |
8870 * Set "curbuf" and "curwin" to match "buf". | 8804 * Set "curbuf" and "curwin" to match "buf". |
8871 * When FEAT_AUTOCMD is not defined another version is used, see below. | 8805 * When FEAT_AUTOCMD is not defined another version is used, see below. |
8872 */ | 8806 */ |
8873 void | 8807 void |
8874 aucmd_prepbuf(aco, buf) | 8808 aucmd_prepbuf( |
8875 aco_save_T *aco; /* structure to save values in */ | 8809 aco_save_T *aco, /* structure to save values in */ |
8876 buf_T *buf; /* new curbuf */ | 8810 buf_T *buf) /* new curbuf */ |
8877 { | 8811 { |
8878 win_T *win; | 8812 win_T *win; |
8879 #ifdef FEAT_WINDOWS | 8813 #ifdef FEAT_WINDOWS |
8880 int save_ea; | 8814 int save_ea; |
8881 #endif | 8815 #endif |
8972 * Cleanup after executing autocommands for a (hidden) buffer. | 8906 * Cleanup after executing autocommands for a (hidden) buffer. |
8973 * Restore the window as it was (if possible). | 8907 * Restore the window as it was (if possible). |
8974 * When FEAT_AUTOCMD is not defined another version is used, see below. | 8908 * When FEAT_AUTOCMD is not defined another version is used, see below. |
8975 */ | 8909 */ |
8976 void | 8910 void |
8977 aucmd_restbuf(aco) | 8911 aucmd_restbuf( |
8978 aco_save_T *aco; /* structure holding saved values */ | 8912 aco_save_T *aco) /* structure holding saved values */ |
8979 { | 8913 { |
8980 #ifdef FEAT_WINDOWS | 8914 #ifdef FEAT_WINDOWS |
8981 int dummy; | 8915 int dummy; |
8982 #endif | 8916 #endif |
8983 | 8917 |
9087 /* | 9021 /* |
9088 * Execute autocommands for "event" and file name "fname". | 9022 * Execute autocommands for "event" and file name "fname". |
9089 * Return TRUE if some commands were executed. | 9023 * Return TRUE if some commands were executed. |
9090 */ | 9024 */ |
9091 int | 9025 int |
9092 apply_autocmds(event, fname, fname_io, force, buf) | 9026 apply_autocmds( |
9093 event_T event; | 9027 event_T event, |
9094 char_u *fname; /* NULL or empty means use actual file name */ | 9028 char_u *fname, /* NULL or empty means use actual file name */ |
9095 char_u *fname_io; /* fname to use for <afile> on cmdline */ | 9029 char_u *fname_io, /* fname to use for <afile> on cmdline */ |
9096 int force; /* when TRUE, ignore autocmd_busy */ | 9030 int force, /* when TRUE, ignore autocmd_busy */ |
9097 buf_T *buf; /* buffer for <abuf> */ | 9031 buf_T *buf) /* buffer for <abuf> */ |
9098 { | 9032 { |
9099 return apply_autocmds_group(event, fname, fname_io, force, | 9033 return apply_autocmds_group(event, fname, fname_io, force, |
9100 AUGROUP_ALL, buf, NULL); | 9034 AUGROUP_ALL, buf, NULL); |
9101 } | 9035 } |
9102 | 9036 |
9103 /* | 9037 /* |
9104 * Like apply_autocmds(), but with extra "eap" argument. This takes care of | 9038 * Like apply_autocmds(), but with extra "eap" argument. This takes care of |
9105 * setting v:filearg. | 9039 * setting v:filearg. |
9106 */ | 9040 */ |
9107 static int | 9041 static int |
9108 apply_autocmds_exarg(event, fname, fname_io, force, buf, eap) | 9042 apply_autocmds_exarg( |
9109 event_T event; | 9043 event_T event, |
9110 char_u *fname; | 9044 char_u *fname, |
9111 char_u *fname_io; | 9045 char_u *fname_io, |
9112 int force; | 9046 int force, |
9113 buf_T *buf; | 9047 buf_T *buf, |
9114 exarg_T *eap; | 9048 exarg_T *eap) |
9115 { | 9049 { |
9116 return apply_autocmds_group(event, fname, fname_io, force, | 9050 return apply_autocmds_group(event, fname, fname_io, force, |
9117 AUGROUP_ALL, buf, eap); | 9051 AUGROUP_ALL, buf, eap); |
9118 } | 9052 } |
9119 | 9053 |
9122 * processing is being aborted or if retval is FAIL when inside a try | 9056 * processing is being aborted or if retval is FAIL when inside a try |
9123 * conditional, no autocommands are executed. If otherwise the autocommands | 9057 * conditional, no autocommands are executed. If otherwise the autocommands |
9124 * cause the script to be aborted, retval is set to FAIL. | 9058 * cause the script to be aborted, retval is set to FAIL. |
9125 */ | 9059 */ |
9126 int | 9060 int |
9127 apply_autocmds_retval(event, fname, fname_io, force, buf, retval) | 9061 apply_autocmds_retval( |
9128 event_T event; | 9062 event_T event, |
9129 char_u *fname; /* NULL or empty means use actual file name */ | 9063 char_u *fname, /* NULL or empty means use actual file name */ |
9130 char_u *fname_io; /* fname to use for <afile> on cmdline */ | 9064 char_u *fname_io, /* fname to use for <afile> on cmdline */ |
9131 int force; /* when TRUE, ignore autocmd_busy */ | 9065 int force, /* when TRUE, ignore autocmd_busy */ |
9132 buf_T *buf; /* buffer for <abuf> */ | 9066 buf_T *buf, /* buffer for <abuf> */ |
9133 int *retval; /* pointer to caller's retval */ | 9067 int *retval) /* pointer to caller's retval */ |
9134 { | 9068 { |
9135 int did_cmd; | 9069 int did_cmd; |
9136 | 9070 |
9137 #ifdef FEAT_EVAL | 9071 #ifdef FEAT_EVAL |
9138 if (should_abort(*retval)) | 9072 if (should_abort(*retval)) |
9152 | 9086 |
9153 /* | 9087 /* |
9154 * Return TRUE when there is a CursorHold autocommand defined. | 9088 * Return TRUE when there is a CursorHold autocommand defined. |
9155 */ | 9089 */ |
9156 int | 9090 int |
9157 has_cursorhold() | 9091 has_cursorhold(void) |
9158 { | 9092 { |
9159 return (first_autopat[(int)(get_real_state() == NORMAL_BUSY | 9093 return (first_autopat[(int)(get_real_state() == NORMAL_BUSY |
9160 ? EVENT_CURSORHOLD : EVENT_CURSORHOLDI)] != NULL); | 9094 ? EVENT_CURSORHOLD : EVENT_CURSORHOLDI)] != NULL); |
9161 } | 9095 } |
9162 | 9096 |
9163 /* | 9097 /* |
9164 * Return TRUE if the CursorHold event can be triggered. | 9098 * Return TRUE if the CursorHold event can be triggered. |
9165 */ | 9099 */ |
9166 int | 9100 int |
9167 trigger_cursorhold() | 9101 trigger_cursorhold(void) |
9168 { | 9102 { |
9169 int state; | 9103 int state; |
9170 | 9104 |
9171 if (!did_cursorhold | 9105 if (!did_cursorhold |
9172 && has_cursorhold() | 9106 && has_cursorhold() |
9186 | 9120 |
9187 /* | 9121 /* |
9188 * Return TRUE when there is a CursorMoved autocommand defined. | 9122 * Return TRUE when there is a CursorMoved autocommand defined. |
9189 */ | 9123 */ |
9190 int | 9124 int |
9191 has_cursormoved() | 9125 has_cursormoved(void) |
9192 { | 9126 { |
9193 return (first_autopat[(int)EVENT_CURSORMOVED] != NULL); | 9127 return (first_autopat[(int)EVENT_CURSORMOVED] != NULL); |
9194 } | 9128 } |
9195 | 9129 |
9196 /* | 9130 /* |
9197 * Return TRUE when there is a CursorMovedI autocommand defined. | 9131 * Return TRUE when there is a CursorMovedI autocommand defined. |
9198 */ | 9132 */ |
9199 int | 9133 int |
9200 has_cursormovedI() | 9134 has_cursormovedI(void) |
9201 { | 9135 { |
9202 return (first_autopat[(int)EVENT_CURSORMOVEDI] != NULL); | 9136 return (first_autopat[(int)EVENT_CURSORMOVEDI] != NULL); |
9203 } | 9137 } |
9204 | 9138 |
9205 /* | 9139 /* |
9206 * Return TRUE when there is a TextChanged autocommand defined. | 9140 * Return TRUE when there is a TextChanged autocommand defined. |
9207 */ | 9141 */ |
9208 int | 9142 int |
9209 has_textchanged() | 9143 has_textchanged(void) |
9210 { | 9144 { |
9211 return (first_autopat[(int)EVENT_TEXTCHANGED] != NULL); | 9145 return (first_autopat[(int)EVENT_TEXTCHANGED] != NULL); |
9212 } | 9146 } |
9213 | 9147 |
9214 /* | 9148 /* |
9215 * Return TRUE when there is a TextChangedI autocommand defined. | 9149 * Return TRUE when there is a TextChangedI autocommand defined. |
9216 */ | 9150 */ |
9217 int | 9151 int |
9218 has_textchangedI() | 9152 has_textchangedI(void) |
9219 { | 9153 { |
9220 return (first_autopat[(int)EVENT_TEXTCHANGEDI] != NULL); | 9154 return (first_autopat[(int)EVENT_TEXTCHANGEDI] != NULL); |
9221 } | 9155 } |
9222 | 9156 |
9223 /* | 9157 /* |
9224 * Return TRUE when there is an InsertCharPre autocommand defined. | 9158 * Return TRUE when there is an InsertCharPre autocommand defined. |
9225 */ | 9159 */ |
9226 int | 9160 int |
9227 has_insertcharpre() | 9161 has_insertcharpre(void) |
9228 { | 9162 { |
9229 return (first_autopat[(int)EVENT_INSERTCHARPRE] != NULL); | 9163 return (first_autopat[(int)EVENT_INSERTCHARPRE] != NULL); |
9230 } | 9164 } |
9231 | 9165 |
9232 /* | 9166 /* |
9233 * Return TRUE when there is an CmdUndefined autocommand defined. | 9167 * Return TRUE when there is an CmdUndefined autocommand defined. |
9234 */ | 9168 */ |
9235 int | 9169 int |
9236 has_cmdundefined() | 9170 has_cmdundefined(void) |
9237 { | 9171 { |
9238 return (first_autopat[(int)EVENT_CMDUNDEFINED] != NULL); | 9172 return (first_autopat[(int)EVENT_CMDUNDEFINED] != NULL); |
9239 } | 9173 } |
9240 | 9174 |
9241 /* | 9175 /* |
9242 * Return TRUE when there is an FuncUndefined autocommand defined. | 9176 * Return TRUE when there is an FuncUndefined autocommand defined. |
9243 */ | 9177 */ |
9244 int | 9178 int |
9245 has_funcundefined() | 9179 has_funcundefined(void) |
9246 { | 9180 { |
9247 return (first_autopat[(int)EVENT_FUNCUNDEFINED] != NULL); | 9181 return (first_autopat[(int)EVENT_FUNCUNDEFINED] != NULL); |
9248 } | 9182 } |
9249 | 9183 |
9250 static int | 9184 static int |
9251 apply_autocmds_group(event, fname, fname_io, force, group, buf, eap) | 9185 apply_autocmds_group( |
9252 event_T event; | 9186 event_T event, |
9253 char_u *fname; /* NULL or empty means use actual file name */ | 9187 char_u *fname, /* NULL or empty means use actual file name */ |
9254 char_u *fname_io; /* fname to use for <afile> on cmdline, NULL means | 9188 char_u *fname_io, /* fname to use for <afile> on cmdline, NULL means |
9255 use fname */ | 9189 use fname */ |
9256 int force; /* when TRUE, ignore autocmd_busy */ | 9190 int force, /* when TRUE, ignore autocmd_busy */ |
9257 int group; /* group ID, or AUGROUP_ALL */ | 9191 int group, /* group ID, or AUGROUP_ALL */ |
9258 buf_T *buf; /* buffer for <abuf> */ | 9192 buf_T *buf, /* buffer for <abuf> */ |
9259 exarg_T *eap; /* command arguments */ | 9193 exarg_T *eap) /* command arguments */ |
9260 { | 9194 { |
9261 char_u *sfname = NULL; /* short file name */ | 9195 char_u *sfname = NULL; /* short file name */ |
9262 char_u *tail; | 9196 char_u *tail; |
9263 int save_changed; | 9197 int save_changed; |
9264 buf_T *old_curbuf; | 9198 buf_T *old_curbuf; |
9645 /* | 9579 /* |
9646 * Block triggering autocommands until unblock_autocmd() is called. | 9580 * Block triggering autocommands until unblock_autocmd() is called. |
9647 * Can be used recursively, so long as it's symmetric. | 9581 * Can be used recursively, so long as it's symmetric. |
9648 */ | 9582 */ |
9649 void | 9583 void |
9650 block_autocmds() | 9584 block_autocmds(void) |
9651 { | 9585 { |
9652 # ifdef FEAT_EVAL | 9586 # ifdef FEAT_EVAL |
9653 /* Remember the value of v:termresponse. */ | 9587 /* Remember the value of v:termresponse. */ |
9654 if (autocmd_blocked == 0) | 9588 if (autocmd_blocked == 0) |
9655 old_termresponse = get_vim_var_str(VV_TERMRESPONSE); | 9589 old_termresponse = get_vim_var_str(VV_TERMRESPONSE); |
9656 # endif | 9590 # endif |
9657 ++autocmd_blocked; | 9591 ++autocmd_blocked; |
9658 } | 9592 } |
9659 | 9593 |
9660 void | 9594 void |
9661 unblock_autocmds() | 9595 unblock_autocmds(void) |
9662 { | 9596 { |
9663 --autocmd_blocked; | 9597 --autocmd_blocked; |
9664 | 9598 |
9665 # ifdef FEAT_EVAL | 9599 # ifdef FEAT_EVAL |
9666 /* When v:termresponse was set while autocommands were blocked, trigger | 9600 /* When v:termresponse was set while autocommands were blocked, trigger |
9671 apply_autocmds(EVENT_TERMRESPONSE, NULL, NULL, FALSE, curbuf); | 9605 apply_autocmds(EVENT_TERMRESPONSE, NULL, NULL, FALSE, curbuf); |
9672 # endif | 9606 # endif |
9673 } | 9607 } |
9674 | 9608 |
9675 int | 9609 int |
9676 is_autocmd_blocked() | 9610 is_autocmd_blocked(void) |
9677 { | 9611 { |
9678 return autocmd_blocked != 0; | 9612 return autocmd_blocked != 0; |
9679 } | 9613 } |
9680 | 9614 |
9681 /* | 9615 /* |
9682 * Find next autocommand pattern that matches. | 9616 * Find next autocommand pattern that matches. |
9683 */ | 9617 */ |
9684 static void | 9618 static void |
9685 auto_next_pat(apc, stop_at_last) | 9619 auto_next_pat( |
9686 AutoPatCmd *apc; | 9620 AutoPatCmd *apc, |
9687 int stop_at_last; /* stop when 'last' flag is set */ | 9621 int stop_at_last) /* stop when 'last' flag is set */ |
9688 { | 9622 { |
9689 AutoPat *ap; | 9623 AutoPat *ap; |
9690 AutoCmd *cp; | 9624 AutoCmd *cp; |
9691 char_u *name; | 9625 char_u *name; |
9692 char *s; | 9626 char *s; |
9746 * Get next autocommand command. | 9680 * Get next autocommand command. |
9747 * Called by do_cmdline() to get the next line for ":if". | 9681 * Called by do_cmdline() to get the next line for ":if". |
9748 * Returns allocated string, or NULL for end of autocommands. | 9682 * Returns allocated string, or NULL for end of autocommands. |
9749 */ | 9683 */ |
9750 char_u * | 9684 char_u * |
9751 getnextac(c, cookie, indent) | 9685 getnextac(int c UNUSED, void *cookie, int indent UNUSED) |
9752 int c UNUSED; | |
9753 void *cookie; | |
9754 int indent UNUSED; | |
9755 { | 9686 { |
9756 AutoPatCmd *acp = (AutoPatCmd *)cookie; | 9687 AutoPatCmd *acp = (AutoPatCmd *)cookie; |
9757 char_u *retval; | 9688 char_u *retval; |
9758 AutoCmd *ac; | 9689 AutoCmd *ac; |
9759 | 9690 |
9810 * Return TRUE if there is a matching autocommand for "fname". | 9741 * Return TRUE if there is a matching autocommand for "fname". |
9811 * To account for buffer-local autocommands, function needs to know | 9742 * To account for buffer-local autocommands, function needs to know |
9812 * in which buffer the file will be opened. | 9743 * in which buffer the file will be opened. |
9813 */ | 9744 */ |
9814 int | 9745 int |
9815 has_autocmd(event, sfname, buf) | 9746 has_autocmd(event_T event, char_u *sfname, buf_T *buf) |
9816 event_T event; | |
9817 char_u *sfname; | |
9818 buf_T *buf; | |
9819 { | 9747 { |
9820 AutoPat *ap; | 9748 AutoPat *ap; |
9821 char_u *fname; | 9749 char_u *fname; |
9822 char_u *tail = gettail(sfname); | 9750 char_u *tail = gettail(sfname); |
9823 int retval = FALSE; | 9751 int retval = FALSE; |
9861 /* | 9789 /* |
9862 * Function given to ExpandGeneric() to obtain the list of autocommand group | 9790 * Function given to ExpandGeneric() to obtain the list of autocommand group |
9863 * names. | 9791 * names. |
9864 */ | 9792 */ |
9865 char_u * | 9793 char_u * |
9866 get_augroup_name(xp, idx) | 9794 get_augroup_name(expand_T *xp UNUSED, int idx) |
9867 expand_T *xp UNUSED; | |
9868 int idx; | |
9869 { | 9795 { |
9870 if (idx == augroups.ga_len) /* add "END" add the end */ | 9796 if (idx == augroups.ga_len) /* add "END" add the end */ |
9871 return (char_u *)"END"; | 9797 return (char_u *)"END"; |
9872 if (idx >= augroups.ga_len) /* end of list */ | 9798 if (idx >= augroups.ga_len) /* end of list */ |
9873 return NULL; | 9799 return NULL; |
9877 } | 9803 } |
9878 | 9804 |
9879 static int include_groups = FALSE; | 9805 static int include_groups = FALSE; |
9880 | 9806 |
9881 char_u * | 9807 char_u * |
9882 set_context_in_autocmd(xp, arg, doautocmd) | 9808 set_context_in_autocmd( |
9883 expand_T *xp; | 9809 expand_T *xp, |
9884 char_u *arg; | 9810 char_u *arg, |
9885 int doautocmd; /* TRUE for :doauto*, FALSE for :autocmd */ | 9811 int doautocmd) /* TRUE for :doauto*, FALSE for :autocmd */ |
9886 { | 9812 { |
9887 char_u *p; | 9813 char_u *p; |
9888 int group; | 9814 int group; |
9889 | 9815 |
9890 /* check for a group name, skip it if present */ | 9816 /* check for a group name, skip it if present */ |
9929 | 9855 |
9930 /* | 9856 /* |
9931 * Function given to ExpandGeneric() to obtain the list of event names. | 9857 * Function given to ExpandGeneric() to obtain the list of event names. |
9932 */ | 9858 */ |
9933 char_u * | 9859 char_u * |
9934 get_event_name(xp, idx) | 9860 get_event_name(expand_T *xp UNUSED, int idx) |
9935 expand_T *xp UNUSED; | |
9936 int idx; | |
9937 { | 9861 { |
9938 if (idx < augroups.ga_len) /* First list group names, if wanted */ | 9862 if (idx < augroups.ga_len) /* First list group names, if wanted */ |
9939 { | 9863 { |
9940 if (!include_groups || AUGROUP_NAME(idx) == NULL) | 9864 if (!include_groups || AUGROUP_NAME(idx) == NULL) |
9941 return (char_u *)""; /* skip deleted entries */ | 9865 return (char_u *)""; /* skip deleted entries */ |
9948 | 9872 |
9949 /* | 9873 /* |
9950 * Return TRUE if autocmd is supported. | 9874 * Return TRUE if autocmd is supported. |
9951 */ | 9875 */ |
9952 int | 9876 int |
9953 autocmd_supported(name) | 9877 autocmd_supported(char_u *name) |
9954 char_u *name; | |
9955 { | 9878 { |
9956 char_u *p; | 9879 char_u *p; |
9957 | 9880 |
9958 return (event_name2nr(name, &p) != NUM_EVENTS); | 9881 return (event_name2nr(name, &p) != NUM_EVENTS); |
9959 } | 9882 } |
9969 * exists("#Group#Event#pat") or | 9892 * exists("#Group#Event#pat") or |
9970 * exists("#Event") or | 9893 * exists("#Event") or |
9971 * exists("#Event#pat") | 9894 * exists("#Event#pat") |
9972 */ | 9895 */ |
9973 int | 9896 int |
9974 au_exists(arg) | 9897 au_exists(char_u *arg) |
9975 char_u *arg; | |
9976 { | 9898 { |
9977 char_u *arg_save; | 9899 char_u *arg_save; |
9978 char_u *pattern = NULL; | 9900 char_u *pattern = NULL; |
9979 char_u *event_name; | 9901 char_u *event_name; |
9980 char_u *p; | 9902 char_u *p; |
10100 * vim_regcomp() often. | 10022 * vim_regcomp() often. |
10101 * Used for autocommands and 'wildignore'. | 10023 * Used for autocommands and 'wildignore'. |
10102 * Returns TRUE if there is a match, FALSE otherwise. | 10024 * Returns TRUE if there is a match, FALSE otherwise. |
10103 */ | 10025 */ |
10104 static int | 10026 static int |
10105 match_file_pat(pattern, prog, fname, sfname, tail, allow_dirs) | 10027 match_file_pat( |
10106 char_u *pattern; /* pattern to match with */ | 10028 char_u *pattern, /* pattern to match with */ |
10107 regprog_T **prog; /* pre-compiled regprog or NULL */ | 10029 regprog_T **prog, /* pre-compiled regprog or NULL */ |
10108 char_u *fname; /* full path of file name */ | 10030 char_u *fname, /* full path of file name */ |
10109 char_u *sfname; /* short file name or NULL */ | 10031 char_u *sfname, /* short file name or NULL */ |
10110 char_u *tail; /* tail of path */ | 10032 char_u *tail, /* tail of path */ |
10111 int allow_dirs; /* allow matching with dir */ | 10033 int allow_dirs) /* allow matching with dir */ |
10112 { | 10034 { |
10113 regmatch_T regmatch; | 10035 regmatch_T regmatch; |
10114 int result = FALSE; | 10036 int result = FALSE; |
10115 | 10037 |
10116 regmatch.rm_ic = p_fic; /* ignore case if 'fileignorecase' is set */ | 10038 regmatch.rm_ic = p_fic; /* ignore case if 'fileignorecase' is set */ |
10146 * Return TRUE if a file matches with a pattern in "list". | 10068 * Return TRUE if a file matches with a pattern in "list". |
10147 * "list" is a comma-separated list of patterns, like 'wildignore'. | 10069 * "list" is a comma-separated list of patterns, like 'wildignore'. |
10148 * "sfname" is the short file name or NULL, "ffname" the long file name. | 10070 * "sfname" is the short file name or NULL, "ffname" the long file name. |
10149 */ | 10071 */ |
10150 int | 10072 int |
10151 match_file_list(list, sfname, ffname) | 10073 match_file_list(char_u *list, char_u *sfname, char_u *ffname) |
10152 char_u *list; | |
10153 char_u *sfname; | |
10154 char_u *ffname; | |
10155 { | 10074 { |
10156 char_u buf[100]; | 10075 char_u buf[100]; |
10157 char_u *tail; | 10076 char_u *tail; |
10158 char_u *regpat; | 10077 char_u *regpat; |
10159 char allow_dirs; | 10078 char allow_dirs; |
10188 * Handle backslashes before special characters, like "\*" and "\ ". | 10107 * Handle backslashes before special characters, like "\*" and "\ ". |
10189 * | 10108 * |
10190 * Returns NULL when out of memory. | 10109 * Returns NULL when out of memory. |
10191 */ | 10110 */ |
10192 char_u * | 10111 char_u * |
10193 file_pat_to_reg_pat(pat, pat_end, allow_dirs, no_bslash) | 10112 file_pat_to_reg_pat( |
10194 char_u *pat; | 10113 char_u *pat, |
10195 char_u *pat_end; /* first char after pattern or NULL */ | 10114 char_u *pat_end, /* first char after pattern or NULL */ |
10196 char *allow_dirs; /* Result passed back out in here */ | 10115 char *allow_dirs, /* Result passed back out in here */ |
10197 int no_bslash UNUSED; /* Don't use a backward slash as pathsep */ | 10116 int no_bslash UNUSED) /* Don't use a backward slash as pathsep */ |
10198 { | 10117 { |
10199 int size = 2; /* '^' at start, '$' at end */ | 10118 int size = 2; /* '^' at start, '$' at end */ |
10200 char_u *endp; | 10119 char_u *endp; |
10201 char_u *reg_pat; | 10120 char_u *reg_pat; |
10202 char_u *p; | 10121 char_u *p; |
10398 /* | 10317 /* |
10399 * Version of read() that retries when interrupted by EINTR (possibly | 10318 * Version of read() that retries when interrupted by EINTR (possibly |
10400 * by a SIGWINCH). | 10319 * by a SIGWINCH). |
10401 */ | 10320 */ |
10402 long | 10321 long |
10403 read_eintr(fd, buf, bufsize) | 10322 read_eintr(int fd, void *buf, size_t bufsize) |
10404 int fd; | |
10405 void *buf; | |
10406 size_t bufsize; | |
10407 { | 10323 { |
10408 long ret; | 10324 long ret; |
10409 | 10325 |
10410 for (;;) | 10326 for (;;) |
10411 { | 10327 { |
10419 /* | 10335 /* |
10420 * Version of write() that retries when interrupted by EINTR (possibly | 10336 * Version of write() that retries when interrupted by EINTR (possibly |
10421 * by a SIGWINCH). | 10337 * by a SIGWINCH). |
10422 */ | 10338 */ |
10423 long | 10339 long |
10424 write_eintr(fd, buf, bufsize) | 10340 write_eintr(int fd, void *buf, size_t bufsize) |
10425 int fd; | |
10426 void *buf; | |
10427 size_t bufsize; | |
10428 { | 10341 { |
10429 long ret = 0; | 10342 long ret = 0; |
10430 long wlen; | 10343 long wlen; |
10431 | 10344 |
10432 /* Repeat the write() so long it didn't fail, other than being interrupted | 10345 /* Repeat the write() so long it didn't fail, other than being interrupted |