aboutsummaryrefslogtreecommitdiff
path: root/src/memline.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/memline.c')
-rw-r--r--src/memline.c293
1 files changed, 114 insertions, 179 deletions
diff --git a/src/memline.c b/src/memline.c
index 15d5416829..2f8fd69669 100644
--- a/src/memline.c
+++ b/src/memline.c
@@ -255,8 +255,7 @@ static void ml_updatechunk __ARGS((buf_T *buf, long line, long len, int updtype)
*
* Return FAIL for failure, OK otherwise.
*/
-int ml_open(buf)
-buf_T *buf;
+int ml_open(buf_T *buf)
{
memfile_T *mfp;
bhdr_T *hp = NULL;
@@ -389,9 +388,7 @@ error:
/*
* Prepare encryption for "buf" with block 0 "b0p".
*/
-static void ml_set_b0_crypt(buf, b0p)
-buf_T *buf;
-ZERO_BL *b0p;
+static void ml_set_b0_crypt(buf_T *buf, ZERO_BL *b0p)
{
if (*buf->b_p_key == NUL)
b0p->b0_id[1] = BLOCK0_ID1;
@@ -415,10 +412,7 @@ ZERO_BL *b0p;
* "old_cm" is the previous 'cryptmethod'. It is equal to the current
* 'cryptmethod' when 'key' is changed.
*/
-void ml_set_crypt_key(buf, old_key, old_cm)
-buf_T *buf;
-char_u *old_key;
-int old_cm;
+void ml_set_crypt_key(buf_T *buf, char_u *old_key, int old_cm)
{
memfile_T *mfp = buf->b_ml.ml_mfp;
bhdr_T *hp;
@@ -533,8 +527,7 @@ int old_cm;
* ml_setname() is called when the file name of "buf" has been changed.
* It may rename the swap file.
*/
-void ml_setname(buf)
-buf_T *buf;
+void ml_setname(buf_T *buf)
{
int success = FALSE;
memfile_T *mfp;
@@ -615,7 +608,7 @@ buf_T *buf;
* been modified.
* Used when 'updatecount' changes from zero to non-zero.
*/
-void ml_open_files() {
+void ml_open_files(void) {
buf_T *buf;
for (buf = firstbuf; buf != NULL; buf = buf->b_next)
@@ -628,8 +621,7 @@ void ml_open_files() {
* If we are unable to find a file name, mf_fname will be NULL
* and the memfile will be in memory only (no recovery possible).
*/
-void ml_open_file(buf)
-buf_T *buf;
+void ml_open_file(buf_T *buf)
{
memfile_T *mfp;
char_u *fname;
@@ -696,8 +688,10 @@ buf_T *buf;
* If still need to create a swap file, and starting to edit a not-readonly
* file, or reading into an existing buffer, create a swap file now.
*/
-void check_need_swap(newfile)
-int newfile; /* reading file into new buffer */
+void
+check_need_swap (
+ int newfile /* reading file into new buffer */
+)
{
if (curbuf->b_may_swap && (!curbuf->b_p_ro || !newfile))
ml_open_file(curbuf);
@@ -707,9 +701,7 @@ int newfile; /* reading file into new buffer */
* Close memline for buffer 'buf'.
* If 'del_file' is TRUE, delete the swap file
*/
-void ml_close(buf, del_file)
-buf_T *buf;
-int del_file;
+void ml_close(buf_T *buf, int del_file)
{
if (buf->b_ml.ml_mfp == NULL) /* not open */
return;
@@ -732,8 +724,7 @@ int del_file;
* When 'del_file' is TRUE, delete the memfiles.
* But don't delete files that were ":preserve"d when we are POSIX compatible.
*/
-void ml_close_all(del_file)
-int del_file;
+void ml_close_all(int del_file)
{
buf_T *buf;
@@ -750,7 +741,7 @@ int del_file;
* Close all memfiles for not modified buffers.
* Only use just before exiting!
*/
-void ml_close_notmod() {
+void ml_close_notmod(void) {
buf_T *buf;
for (buf = firstbuf; buf != NULL; buf = buf->b_next)
@@ -762,8 +753,7 @@ void ml_close_notmod() {
* Update the timestamp in the .swp file.
* Used when the file has been written.
*/
-void ml_timestamp(buf)
-buf_T *buf;
+void ml_timestamp(buf_T *buf)
{
ml_upd_block0(buf, UB_FNAME);
}
@@ -771,8 +761,7 @@ buf_T *buf;
/*
* Return FAIL when the ID of "b0p" is wrong.
*/
-static int ml_check_b0_id(b0p)
-ZERO_BL *b0p;
+static int ml_check_b0_id(ZERO_BL *b0p)
{
if (b0p->b0_id[0] != BLOCK0_ID0
|| (b0p->b0_id[1] != BLOCK0_ID1
@@ -786,9 +775,7 @@ ZERO_BL *b0p;
/*
* Update the timestamp or the B0_SAME_DIR flag of the .swp file.
*/
-static void ml_upd_block0(buf, what)
-buf_T *buf;
-upd_block0_T what;
+static void ml_upd_block0(buf_T *buf, upd_block0_T what)
{
memfile_T *mfp;
bhdr_T *hp;
@@ -816,9 +803,7 @@ upd_block0_T what;
* Also set buf->b_mtime.
* Don't use NameBuff[]!!!
*/
-static void set_b0_fname(b0p, buf)
-ZERO_BL *b0p;
-buf_T *buf;
+static void set_b0_fname(ZERO_BL *b0p, buf_T *buf)
{
struct stat st;
@@ -878,9 +863,7 @@ buf_T *buf;
* This is fail safe: if we are not sure the directories are equal the flag is
* not set.
*/
-static void set_b0_dir_flag(b0p, buf)
-ZERO_BL *b0p;
-buf_T *buf;
+static void set_b0_dir_flag(ZERO_BL *b0p, buf_T *buf)
{
if (same_directory(buf->b_ml.ml_mfp->mf_fname, buf->b_ffname))
b0p->b0_flags |= B0_SAME_DIR;
@@ -891,9 +874,7 @@ buf_T *buf;
/*
* When there is room, add the 'fileencoding' to block zero.
*/
-static void add_b0_fenc(b0p, buf)
-ZERO_BL *b0p;
-buf_T *buf;
+static void add_b0_fenc(ZERO_BL *b0p, buf_T *buf)
{
int n;
int size = B0_FNAME_SIZE_NOCRYPT;
@@ -919,7 +900,7 @@ buf_T *buf;
/*
* Try to recover curbuf from the .swp file.
*/
-void ml_recover() {
+void ml_recover(void) {
buf_T *buf = NULL;
memfile_T *mfp = NULL;
char_u *fname;
@@ -1490,11 +1471,13 @@ theend:
* - list the swap files when recovering
* - find the name of the n'th swap file when recovering
*/
-int recover_names(fname, list, nr, fname_out)
-char_u *fname; /* base for swap file name */
-int list; /* when TRUE, list the swap file names */
-int nr; /* when non-zero, return nr'th swap file name */
-char_u **fname_out; /* result when "nr" > 0 */
+int
+recover_names (
+ char_u *fname, /* base for swap file name */
+ int list, /* when TRUE, list the swap file names */
+ int nr, /* when non-zero, return nr'th swap file name */
+ char_u **fname_out /* result when "nr" > 0 */
+)
{
int num_names;
char_u *(names[6]);
@@ -1694,9 +1677,7 @@ char_u **fname_out; /* result when "nr" > 0 */
* Append the full path to name with path separators made into percent
* signs, to dir. An unnamed buffer is handled as "" (<currentdir>/"")
*/
-static char_u * make_percent_swname(dir, name)
-char_u *dir;
-char_u *name;
+static char_u *make_percent_swname(char_u *dir, char_u *name)
{
char_u *d, *s, *f;
@@ -1727,8 +1708,7 @@ static int process_still_running;
* Give information about an existing swap file.
* Returns timestamp (0 when unknown).
*/
-static time_t swapfile_info(fname)
-char_u *fname;
+static time_t swapfile_info(char_u *fname)
{
struct stat st;
int fd;
@@ -1817,10 +1797,7 @@ char_u *fname;
return x;
}
-static int recov_file_names(names, path, prepend_dot)
-char_u **names;
-char_u *path;
-int prepend_dot;
+static int recov_file_names(char_u **names, char_u *path, int prepend_dot)
{
int num_names;
@@ -1909,9 +1886,7 @@ end:
* If 'check_char' is TRUE, stop syncing when character becomes available, but
* always sync at least one block.
*/
-void ml_sync_all(check_file, check_char)
-int check_file;
-int check_char;
+void ml_sync_all(int check_file, int check_char)
{
buf_T *buf;
struct stat st;
@@ -1956,9 +1931,7 @@ int check_char;
*
* when message is TRUE the success of preserving is reported
*/
-void ml_preserve(buf, message)
-buf_T *buf;
-int message;
+void ml_preserve(buf_T *buf, int message)
{
bhdr_T *hp;
linenr_T lnum;
@@ -2036,8 +2009,7 @@ theend:
* On failure an error message is given and IObuff is returned (to avoid
* having to check for error everywhere).
*/
-char_u * ml_get(lnum)
-linenr_T lnum;
+char_u *ml_get(linenr_T lnum)
{
return ml_get_buf(curbuf, lnum, FALSE);
}
@@ -2045,8 +2017,7 @@ linenr_T lnum;
/*
* Return pointer to position "pos".
*/
-char_u * ml_get_pos(pos)
-pos_T *pos;
+char_u *ml_get_pos(pos_T *pos)
{
return ml_get_buf(curbuf, pos->lnum, FALSE) + pos->col;
}
@@ -2054,14 +2025,14 @@ pos_T *pos;
/*
* Return pointer to cursor line.
*/
-char_u * ml_get_curline() {
+char_u *ml_get_curline(void) {
return ml_get_buf(curbuf, curwin->w_cursor.lnum, FALSE);
}
/*
* Return pointer to cursor position.
*/
-char_u * ml_get_cursor() {
+char_u *ml_get_cursor(void) {
return ml_get_buf(curbuf, curwin->w_cursor.lnum, FALSE) +
curwin->w_cursor.col;
}
@@ -2072,10 +2043,12 @@ char_u * ml_get_cursor() {
* "will_change": if TRUE mark the buffer dirty (chars in the line will be
* changed)
*/
-char_u * ml_get_buf(buf, lnum, will_change)
-buf_T *buf;
-linenr_T lnum;
-int will_change; /* line will be changed */
+char_u *
+ml_get_buf (
+ buf_T *buf,
+ linenr_T lnum,
+ int will_change /* line will be changed */
+)
{
bhdr_T *hp;
DATA_BL *dp;
@@ -2143,7 +2116,7 @@ errorret:
* Check if a line that was just obtained by a call to ml_get
* is in allocated memory.
*/
-int ml_line_alloced() {
+int ml_line_alloced(void) {
return curbuf->b_ml.ml_flags & ML_LINE_DIRTY;
}
@@ -2159,11 +2132,13 @@ int ml_line_alloced() {
*
* return FAIL for failure, OK otherwise
*/
-int ml_append(lnum, line, len, newfile)
-linenr_T lnum; /* append after this line (can be 0) */
-char_u *line; /* text of the new line */
-colnr_T len; /* length of new line, including NUL, or 0 */
-int newfile; /* flag, see above */
+int
+ml_append (
+ linenr_T lnum, /* append after this line (can be 0) */
+ char_u *line, /* text of the new line */
+ colnr_T len, /* length of new line, including NUL, or 0 */
+ int newfile /* flag, see above */
+)
{
/* When starting up, we might still need to create the memfile */
if (curbuf->b_ml.ml_mfp == NULL && open_buffer(FALSE, NULL, 0) == FAIL)
@@ -2178,12 +2153,14 @@ int newfile; /* flag, see above */
* Like ml_append() but for an arbitrary buffer. The buffer must already have
* a memline.
*/
-int ml_append_buf(buf, lnum, line, len, newfile)
-buf_T *buf;
-linenr_T lnum; /* append after this line (can be 0) */
-char_u *line; /* text of the new line */
-colnr_T len; /* length of new line, including NUL, or 0 */
-int newfile; /* flag, see above */
+int
+ml_append_buf (
+ buf_T *buf,
+ linenr_T lnum, /* append after this line (can be 0) */
+ char_u *line, /* text of the new line */
+ colnr_T len, /* length of new line, including NUL, or 0 */
+ int newfile /* flag, see above */
+)
{
if (buf->b_ml.ml_mfp == NULL)
return FAIL;
@@ -2193,13 +2170,15 @@ int newfile; /* flag, see above */
return ml_append_int(buf, lnum, line, len, newfile, FALSE);
}
-static int ml_append_int(buf, lnum, line, len, newfile, mark)
-buf_T *buf;
-linenr_T lnum; /* append after this line (can be 0) */
-char_u *line; /* text of the new line */
-colnr_T len; /* length of line, including NUL, or 0 */
-int newfile; /* flag, see above */
-int mark; /* mark the new line */
+static int
+ml_append_int (
+ buf_T *buf,
+ linenr_T lnum, /* append after this line (can be 0) */
+ char_u *line, /* text of the new line */
+ colnr_T len, /* length of line, including NUL, or 0 */
+ int newfile, /* flag, see above */
+ int mark /* mark the new line */
+)
{
int i;
int line_count; /* number of indexes in current block */
@@ -2656,10 +2635,7 @@ int mark; /* mark the new line */
*
* return FAIL for failure, OK otherwise
*/
-int ml_replace(lnum, line, copy)
-linenr_T lnum;
-char_u *line;
-int copy;
+int ml_replace(linenr_T lnum, char_u *line, int copy)
{
if (line == NULL) /* just checking... */
return FAIL;
@@ -2689,18 +2665,13 @@ int copy;
*
* return FAIL for failure, OK otherwise
*/
-int ml_delete(lnum, message)
-linenr_T lnum;
-int message;
+int ml_delete(linenr_T lnum, int message)
{
ml_flush_line(curbuf);
return ml_delete_int(curbuf, lnum, message);
}
-static int ml_delete_int(buf, lnum, message)
-buf_T *buf;
-linenr_T lnum;
-int message;
+static int ml_delete_int(buf_T *buf, linenr_T lnum, int message)
{
bhdr_T *hp;
memfile_T *mfp;
@@ -2842,8 +2813,7 @@ int message;
/*
* set the B_MARKED flag for line 'lnum'
*/
-void ml_setmarked(lnum)
-linenr_T lnum;
+void ml_setmarked(linenr_T lnum)
{
bhdr_T *hp;
DATA_BL *dp;
@@ -2871,7 +2841,7 @@ linenr_T lnum;
/*
* find the first line with its B_MARKED flag set
*/
-linenr_T ml_firstmarked() {
+linenr_T ml_firstmarked(void) {
bhdr_T *hp;
DATA_BL *dp;
linenr_T lnum;
@@ -2911,7 +2881,7 @@ linenr_T ml_firstmarked() {
/*
* clear all DB_MARKED flags
*/
-void ml_clearmarked() {
+void ml_clearmarked(void) {
bhdr_T *hp;
DATA_BL *dp;
linenr_T lnum;
@@ -2949,8 +2919,7 @@ void ml_clearmarked() {
/*
* flush ml_line if necessary
*/
-static void ml_flush_line(buf)
-buf_T *buf;
+static void ml_flush_line(buf_T *buf)
{
bhdr_T *hp;
DATA_BL *dp;
@@ -3046,10 +3015,7 @@ buf_T *buf;
/*
* create a new, empty, data block
*/
-static bhdr_T * ml_new_data(mfp, negative, page_count)
-memfile_T *mfp;
-int negative;
-int page_count;
+static bhdr_T *ml_new_data(memfile_T *mfp, int negative, int page_count)
{
bhdr_T *hp;
DATA_BL *dp;
@@ -3069,8 +3035,7 @@ int page_count;
/*
* create a new, empty, pointer block
*/
-static bhdr_T * ml_new_ptr(mfp)
-memfile_T *mfp;
+static bhdr_T *ml_new_ptr(memfile_T *mfp)
{
bhdr_T *hp;
PTR_BL *pp;
@@ -3102,10 +3067,7 @@ memfile_T *mfp;
*
* return: NULL for failure, pointer to block header otherwise
*/
-static bhdr_T * ml_find_line(buf, lnum, action)
-buf_T *buf;
-linenr_T lnum;
-int action;
+static bhdr_T *ml_find_line(buf_T *buf, linenr_T lnum, int action)
{
DATA_BL *dp;
PTR_BL *pp;
@@ -3286,8 +3248,7 @@ error_noblock:
*
* return -1 for failure, number of the new entry otherwise
*/
-static int ml_add_stack(buf)
-buf_T *buf;
+static int ml_add_stack(buf_T *buf)
{
int top;
infoptr_T *newstack;
@@ -3323,9 +3284,7 @@ buf_T *buf;
*
* Count is the number of lines added, negative if lines have been deleted.
*/
-static void ml_lineadd(buf, count)
-buf_T *buf;
-int count;
+static void ml_lineadd(buf_T *buf, int count)
{
int idx;
infoptr_T *ip;
@@ -3357,9 +3316,7 @@ int count;
* If it worked returns OK and the resolved link in "buf[MAXPATHL]".
* Otherwise returns FAIL.
*/
-int resolve_symlink(fname, buf)
-char_u *fname;
-char_u *buf;
+int resolve_symlink(char_u *fname, char_u *buf)
{
char_u tmp[MAXPATHL];
int ret;
@@ -3427,11 +3384,7 @@ char_u *buf;
* Make swap file name out of the file name and a directory name.
* Returns pointer to allocated memory or NULL.
*/
-char_u * makeswapname(fname, ffname, buf, dir_name)
-char_u *fname;
-char_u *ffname UNUSED;
-buf_T *buf;
-char_u *dir_name;
+char_u *makeswapname(char_u *fname, char_u *ffname, buf_T *buf, char_u *dir_name)
{
char_u *r, *s;
char_u *fname_res = fname;
@@ -3494,9 +3447,11 @@ char_u *dir_name;
*
* The return value is an allocated string and can be NULL.
*/
-char_u * get_file_in_dir(fname, dname)
-char_u *fname;
-char_u *dname; /* don't use "dirname", it is a global for Alpha */
+char_u *
+get_file_in_dir (
+ char_u *fname,
+ char_u *dname /* don't use "dirname", it is a global for Alpha */
+)
{
char_u *t;
char_u *tail;
@@ -3534,9 +3489,11 @@ static void attention_message __ARGS((buf_T *buf, char_u *fname));
/*
* Print the ATTENTION message: info about an existing swap file.
*/
-static void attention_message(buf, fname)
-buf_T *buf; /* buffer being edited */
-char_u *fname; /* swap file name */
+static void
+attention_message (
+ buf_T *buf, /* buffer being edited */
+ char_u *fname /* swap file name */
+)
{
struct stat st;
time_t x, sx;
@@ -3591,9 +3548,7 @@ static int do_swapexists __ARGS((buf_T *buf, char_u *fname));
* 5: quit
* 6: abort
*/
-static int do_swapexists(buf, fname)
-buf_T *buf;
-char_u *fname;
+static int do_swapexists(buf_T *buf, char_u *fname)
{
set_vim_var_string(VV_SWAPNAME, fname, -1);
set_vim_var_string(VV_SWAPCHOICE, NULL, -1);
@@ -3629,10 +3584,12 @@ char_u *fname;
* not being able to open the swap or undo file
* Note: May trigger SwapExists autocmd, pointers may change!
*/
-static char_u * findswapname(buf, dirp, old_fname)
-buf_T *buf;
-char_u **dirp; /* pointer to list of directories */
-char_u *old_fname; /* don't give warning for this file name */
+static char_u *
+findswapname (
+ buf_T *buf,
+ char_u **dirp, /* pointer to list of directories */
+ char_u *old_fname /* don't give warning for this file name */
+)
{
char_u *fname;
int n;
@@ -4030,8 +3987,7 @@ char_u *old_fname; /* don't give warning for this file name */
return fname;
}
-static int b0_magic_wrong(b0p)
-ZERO_BL *b0p;
+static int b0_magic_wrong(ZERO_BL *b0p)
{
return b0p->b0_magic_long != (long)B0_MAGIC_LONG
|| b0p->b0_magic_int != (int)B0_MAGIC_INT
@@ -4089,10 +4045,12 @@ ZERO_BL *b0p;
* versions.
*/
-static int fnamecmp_ino(fname_c, fname_s, ino_block0)
-char_u *fname_c; /* current file name */
-char_u *fname_s; /* file name from swap file */
-long ino_block0;
+static int
+fnamecmp_ino (
+ char_u *fname_c, /* current file name */
+ char_u *fname_s, /* file name from swap file */
+ long ino_block0
+)
{
struct stat st;
ino_t ino_c = 0; /* ino of current file */
@@ -4141,9 +4099,7 @@ long ino_block0;
* Move a long integer into a four byte character array.
* Used for machine independency in block zero.
*/
-static void long_to_char(n, s)
-long n;
-char_u *s;
+static void long_to_char(long n, char_u *s)
{
s[0] = (char_u)(n & 0xff);
n = (unsigned)n >> 8;
@@ -4154,8 +4110,7 @@ char_u *s;
s[3] = (char_u)(n & 0xff);
}
-static long char_to_long(s)
-char_u *s;
+static long char_to_long(char_u *s)
{
long retval;
@@ -4176,8 +4131,7 @@ char_u *s;
* - 'fileformat'
* - 'fileencoding'
*/
-void ml_setflags(buf)
-buf_T *buf;
+void ml_setflags(buf_T *buf)
{
bhdr_T *hp;
ZERO_BL *b0p;
@@ -4203,11 +4157,7 @@ buf_T *buf;
* in allocated memory. Return NULL when out of memory.
* Otherwise return "data".
*/
-char_u * ml_encrypt_data(mfp, data, offset, size)
-memfile_T *mfp;
-char_u *data;
-off_t offset;
-unsigned size;
+char_u *ml_encrypt_data(memfile_T *mfp, char_u *data, off_t offset, unsigned size)
{
DATA_BL *dp = (DATA_BL *)data;
char_u *head_end;
@@ -4244,11 +4194,7 @@ unsigned size;
/*
* Decrypt the text in "data" if it points to a data block.
*/
-void ml_decrypt_data(mfp, data, offset, size)
-memfile_T *mfp;
-char_u *data;
-off_t offset;
-unsigned size;
+void ml_decrypt_data(memfile_T *mfp, char_u *data, off_t offset, unsigned size)
{
DATA_BL *dp = (DATA_BL *)data;
char_u *head_end;
@@ -4275,10 +4221,7 @@ unsigned size;
/*
* Prepare for encryption/decryption, using the key, seed and offset.
*/
-static void ml_crypt_prepare(mfp, offset, reading)
-memfile_T *mfp;
-off_t offset;
-int reading;
+static void ml_crypt_prepare(memfile_T *mfp, off_t offset, int reading)
{
buf_T *buf = mfp->mf_buffer;
char_u salt[50];
@@ -4323,11 +4266,7 @@ int reading;
* ML_CHNK_DELLINE: Subtract len from parent chunk, possibly deleting it
* ML_CHNK_UPDLINE: Add len to parent chunk, as a signed entity.
*/
-static void ml_updatechunk(buf, line, len, updtype)
-buf_T *buf;
-linenr_T line;
-long len;
-int updtype;
+static void ml_updatechunk(buf_T *buf, linenr_T line, long len, int updtype)
{
static buf_T *ml_upd_lastbuf = NULL;
static linenr_T ml_upd_lastline;
@@ -4533,10 +4472,7 @@ int updtype;
* Find offset of line if "lnum" > 0
* return -1 if information is not available
*/
-long ml_find_line_or_offset(buf, lnum, offp)
-buf_T *buf;
-linenr_T lnum;
-long *offp;
+long ml_find_line_or_offset(buf_T *buf, linenr_T lnum, long *offp)
{
linenr_T curline;
int curix;
@@ -4652,8 +4588,7 @@ long *offp;
/*
* Goto byte in buffer with offset 'cnt'.
*/
-void goto_byte(cnt)
-long cnt;
+void goto_byte(long cnt)
{
long boff = cnt;
linenr_T lnum;