diff options
Diffstat (limited to 'src/nvim/fileio.c')
-rw-r--r-- | src/nvim/fileio.c | 228 |
1 files changed, 91 insertions, 137 deletions
diff --git a/src/nvim/fileio.c b/src/nvim/fileio.c index 6c42a2bef3..d4faafeed6 100644 --- a/src/nvim/fileio.c +++ b/src/nvim/fileio.c @@ -58,37 +58,89 @@ #define BUFSIZE 8192 /* size of normal write buffer */ #define SMBUFSIZE 256 /* size of emergency write buffer */ -static char_u *next_fenc(char_u **pp); -static char_u *readfile_charconvert(char_u *fname, char_u *fenc, - int *fdp); -static void check_marks_read(void); -#ifdef UNIX -static void set_file_time(char_u *fname, time_t atime, time_t mtime); -#endif -static int set_rw_fname(char_u *fname, char_u *sfname); -static int msg_add_fileformat(int eol_type); -static void msg_add_eol(void); -static int check_mtime(buf_T *buf, FileInfo *file_info); -static int time_differs(long t1, long t2); -static int apply_autocmds_exarg(event_T event, char_u *fname, char_u *fname_io, - int force, buf_T *buf, - exarg_T *eap); -static int au_find_group(char_u *name); - -# define AUGROUP_DEFAULT -1 /* default autocmd group */ -# define AUGROUP_ERROR -2 /* erroneous autocmd group */ -# define AUGROUP_ALL -3 /* all autocmd groups */ - -# define HAS_BW_FLAGS -# define FIO_LATIN1 0x01 /* convert Latin1 */ -# define FIO_UTF8 0x02 /* convert UTF-8 */ -# define FIO_UCS2 0x04 /* convert UCS-2 */ -# define FIO_UCS4 0x08 /* convert UCS-4 */ -# define FIO_UTF16 0x10 /* convert UTF-16 */ -# define FIO_ENDIAN_L 0x80 /* little endian */ -# define FIO_NOCONVERT 0x2000 /* skip encoding conversion */ -# define FIO_UCSBOM 0x4000 /* check for BOM at start of file */ -# define FIO_ALL -1 /* allow all formats */ +/* + * The autocommands are stored in a list for each event. + * Autocommands for the same pattern, that are consecutive, are joined + * together, to avoid having to match the pattern too often. + * The result is an array of Autopat lists, which point to AutoCmd lists: + * + * first_autopat[0] --> Autopat.next --> Autopat.next --> NULL + * Autopat.cmds Autopat.cmds + * | | + * V V + * AutoCmd.next AutoCmd.next + * | | + * V V + * AutoCmd.next NULL + * | + * V + * NULL + * + * first_autopat[1] --> Autopat.next --> NULL + * Autopat.cmds + * | + * V + * AutoCmd.next + * | + * V + * NULL + * etc. + * + * The order of AutoCmds is important, this is the order in which they were + * defined and will have to be executed. + */ +typedef struct AutoCmd { + char_u *cmd; /* The command to be executed (NULL + when command has been removed) */ + char nested; /* If autocommands nest here */ + char last; /* last command in list */ + scid_T scriptID; /* script ID where defined */ + struct AutoCmd *next; /* Next AutoCmd in list */ +} AutoCmd; + +typedef struct AutoPat { + char_u *pat; /* pattern as typed (NULL when pattern + has been removed) */ + regprog_T *reg_prog; /* compiled regprog for pattern */ + AutoCmd *cmds; /* list of commands to do */ + struct AutoPat *next; /* next AutoPat in AutoPat list */ + int group; /* group ID */ + int patlen; /* strlen() of pat */ + int buflocal_nr; /* !=0 for buffer-local AutoPat */ + char allow_dirs; /* Pattern may match whole path */ + char last; /* last pattern for apply_autocmds() */ +} AutoPat; + +/* + * struct used to keep status while executing autocommands for an event. + */ +typedef struct AutoPatCmd { + AutoPat *curpat; /* next AutoPat to examine */ + AutoCmd *nextcmd; /* next AutoCmd to execute */ + int group; /* group being used */ + char_u *fname; /* fname to match with */ + char_u *sfname; /* sfname to match with */ + char_u *tail; /* tail of fname */ + event_T event; /* current event */ + int arg_bufnr; /* initially equal to <abuf>, set to zero when + buf is deleted */ + struct AutoPatCmd *next; /* chain of active apc-s for auto-invalidation*/ +} AutoPatCmd; + +#define AUGROUP_DEFAULT -1 /* default autocmd group */ +#define AUGROUP_ERROR -2 /* erroneous autocmd group */ +#define AUGROUP_ALL -3 /* all autocmd groups */ + +#define HAS_BW_FLAGS +#define FIO_LATIN1 0x01 /* convert Latin1 */ +#define FIO_UTF8 0x02 /* convert UTF-8 */ +#define FIO_UCS2 0x04 /* convert UCS-2 */ +#define FIO_UCS4 0x08 /* convert UCS-4 */ +#define FIO_UTF16 0x10 /* convert UTF-16 */ +#define FIO_ENDIAN_L 0x80 /* little endian */ +#define FIO_NOCONVERT 0x2000 /* skip encoding conversion */ +#define FIO_UCSBOM 0x4000 /* check for BOM at start of file */ +#define FIO_ALL -1 /* allow all formats */ /* When converting, a read() or write() may leave some bytes to be converted * for the next call. The value is guessed... */ @@ -121,19 +173,14 @@ struct bw_info { # endif }; -static int buf_write_bytes(struct bw_info *ip); +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "fileio.c.generated.h" +#endif -static linenr_T readfile_linenr(linenr_T linecnt, char_u *p, - char_u *endp); -static int ucs2bytes(unsigned c, char_u **pp, int flags); -static int need_conversion(char_u *fenc); -static int get_fio_flags(char_u *ptr); -static char_u *check_for_bom(char_u *p, long size, int *lenp, int flags); -static int make_bom(char_u *buf, char_u *name); -static int move_lines(buf_T *frombuf, buf_T *tobuf); -#ifdef TEMPDIRNAMES -static void vim_settempdir(char_u *tempdir); +#ifdef UNIX #endif + + static char *e_auchangedbuf = N_( "E812: Autocommands changed buffer or buffer name"); @@ -5364,59 +5411,6 @@ void forward_slash(char_u *fname) */ -/* - * The autocommands are stored in a list for each event. - * Autocommands for the same pattern, that are consecutive, are joined - * together, to avoid having to match the pattern too often. - * The result is an array of Autopat lists, which point to AutoCmd lists: - * - * first_autopat[0] --> Autopat.next --> Autopat.next --> NULL - * Autopat.cmds Autopat.cmds - * | | - * V V - * AutoCmd.next AutoCmd.next - * | | - * V V - * AutoCmd.next NULL - * | - * V - * NULL - * - * first_autopat[1] --> Autopat.next --> NULL - * Autopat.cmds - * | - * V - * AutoCmd.next - * | - * V - * NULL - * etc. - * - * The order of AutoCmds is important, this is the order in which they were - * defined and will have to be executed. - */ -typedef struct AutoCmd { - char_u *cmd; /* The command to be executed (NULL - when command has been removed) */ - char nested; /* If autocommands nest here */ - char last; /* last command in list */ - scid_T scriptID; /* script ID where defined */ - struct AutoCmd *next; /* Next AutoCmd in list */ -} AutoCmd; - -typedef struct AutoPat { - char_u *pat; /* pattern as typed (NULL when pattern - has been removed) */ - regprog_T *reg_prog; /* compiled regprog for pattern */ - AutoCmd *cmds; /* list of commands to do */ - struct AutoPat *next; /* next AutoPat in AutoPat list */ - int group; /* group ID */ - int patlen; /* strlen() of pat */ - int buflocal_nr; /* !=0 for buffer-local AutoPat */ - char allow_dirs; /* Pattern may match whole path */ - char last; /* last pattern for apply_autocmds() */ -} AutoPat; - static struct event_name { char *name; /* event name */ event_T event; /* event number */ @@ -5522,22 +5516,6 @@ static AutoPat *first_autopat[NUM_EVENTS] = NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL }; -/* - * struct used to keep status while executing autocommands for an event. - */ -typedef struct AutoPatCmd { - AutoPat *curpat; /* next AutoPat to examine */ - AutoCmd *nextcmd; /* next AutoCmd to execute */ - int group; /* group being used */ - char_u *fname; /* fname to match with */ - char_u *sfname; /* sfname to match with */ - char_u *tail; /* tail of fname */ - event_T event; /* current event */ - int arg_bufnr; /* initially equal to <abuf>, set to zero when - buf is deleted */ - struct AutoPatCmd *next; /* chain of active apc-s for auto-invalidation*/ -} AutoPatCmd; - static AutoPatCmd *active_apc_list = NULL; /* stack of active autocommands */ /* @@ -5553,24 +5531,6 @@ static int current_augroup = AUGROUP_DEFAULT; static int au_need_clean = FALSE; /* need to delete marked patterns */ -static void show_autocmd(AutoPat *ap, event_T event); -static void au_remove_pat(AutoPat *ap); -static void au_remove_cmds(AutoPat *ap); -static void au_cleanup(void); -static int au_new_group(char_u *name); -static void au_del_group(char_u *name); -static event_T event_name2nr(char_u *start, char_u **end); -static char_u *event_nr2name(event_T event); -static char_u *find_end_event(char_u *arg, int have_group); -static int event_ignored(event_T event); -static int au_get_grouparg(char_u **argp); -static int do_autocmd_event(event_T event, char_u *pat, int nested, - char_u *cmd, int forceit, - int group); -static int apply_autocmds_group(event_T event, char_u *fname, char_u *fname_io, - int force, int group, buf_T *buf, - exarg_T *eap); -static void auto_next_pat(AutoPatCmd *apc, int stop_at_last); static event_T last_event; @@ -7803,10 +7763,7 @@ file_pat_to_reg_pat ( * Version of read() that retries when interrupted by EINTR (possibly * by a SIGWINCH). */ -long read_eintr(fd, buf, bufsize) -int fd; -void *buf; -size_t bufsize; +long read_eintr(int fd, void *buf, size_t bufsize) { long ret; @@ -7822,10 +7779,7 @@ size_t bufsize; * Version of write() that retries when interrupted by EINTR (possibly * by a SIGWINCH). */ -long write_eintr(fd, buf, bufsize) -int fd; -void *buf; -size_t bufsize; +long write_eintr(int fd, void *buf, size_t bufsize) { long ret = 0; long wlen; |