Data Structures | Macros | Typedefs | Enumerations | Functions | Variables
memline.c File Reference
#include <assert.h>
#include <errno.h>
#include <fcntl.h>
#include <inttypes.h>
#include <stdbool.h>
#include <string.h>
#include "nvim/ascii.h"
#include "nvim/buffer.h"
#include "nvim/change.h"
#include "nvim/cursor.h"
#include "nvim/eval.h"
#include "nvim/fileio.h"
#include "nvim/func_attr.h"
#include "nvim/getchar.h"
#include "nvim/main.h"
#include "nvim/mark.h"
#include "nvim/mbyte.h"
#include "nvim/memfile.h"
#include "nvim/memline.h"
#include "nvim/memory.h"
#include "nvim/message.h"
#include "nvim/misc1.h"
#include "nvim/option.h"
#include "nvim/os/input.h"
#include "nvim/os/os.h"
#include "nvim/os/process.h"
#include "nvim/os_unix.h"
#include "nvim/path.h"
#include "nvim/screen.h"
#include "nvim/sha256.h"
#include "nvim/spell.h"
#include "nvim/strings.h"
#include "nvim/ui.h"
#include "nvim/undo.h"
#include "nvim/version.h"
#include "nvim/vim.h"
#include "nvim/window.h"
#include <time.h>

Data Structures

struct  pointer_entry
 
struct  pointer_block
 
struct  data_block
 
struct  block0
 

Macros

#define CHECK(c, s)   do { } while (0)
 
#define DATA_ID   (('d' << 8) + 'a')
 
#define PTR_ID   (('p' << 8) + 't')
 
#define BLOCK0_ID0   'b'
 
#define BLOCK0_ID1   '0'
 
#define DB_MARKED   ((unsigned)1 << ((sizeof(unsigned) * 8) - 1))
 
#define DB_INDEX_MASK   (~DB_MARKED)
 
#define INDEX_SIZE   (sizeof(unsigned))
 
#define HEADER_SIZE   (sizeof(DATA_BL) - INDEX_SIZE)
 
#define B0_FNAME_SIZE_ORG   900
 
#define B0_FNAME_SIZE_NOCRYPT   898
 
#define B0_FNAME_SIZE_CRYPT   890
 
#define B0_UNAME_SIZE   40
 
#define B0_HNAME_SIZE   40
 
#define B0_MAGIC_LONG   0x30313233L
 
#define B0_MAGIC_INT   0x20212223L
 
#define B0_MAGIC_SHORT   0x10111213L
 
#define B0_MAGIC_CHAR   0x55
 
#define B0_DIRTY   0x55
 
#define b0_dirty   b0_fname[B0_FNAME_SIZE_ORG - 1]
 
#define b0_flags   b0_fname[B0_FNAME_SIZE_ORG - 2]
 
#define B0_FF_MASK   3
 
#define B0_SAME_DIR   4
 
#define B0_HAS_FENC   8
 
#define STACK_INCR   5
 
#define ML_DELETE   0x11
 
#define ML_INSERT   0x12
 
#define ML_FIND   0x13
 
#define ML_FLUSH   0x02
 
#define ML_SIMPLE(x)   (x & 0x10)
 
#define MLCS_MAXL   800
 
#define MLCS_MINL   400
 

Typedefs

typedef struct block0 ZERO_BL
 
typedef struct pointer_block PTR_BL
 
typedef struct data_block DATA_BL
 
typedef struct pointer_entry PTR_EN
 

Enumerations

enum  upd_block0_T { UB_FNAME = 0, UB_SAME_DIR }
 

Functions

int ml_open (buf_T *buf)
 
void ml_setname (buf_T *buf)
 
void ml_open_files (void)
 
void ml_open_file (buf_T *buf)
 
void check_need_swap (bool newfile)
 
void ml_close (buf_T *buf, int del_file)
 
void ml_close_all (int del_file)
 
void ml_close_notmod (void)
 
void ml_timestamp (buf_T *buf)
 
void ml_recover (bool checkext)
 
int recover_names (char_u *fname, int list, int nr, char_u **fname_out)
 
char * make_percent_swname (const char *dir, const char *name) FUNC_ATTR_NONNULL_ARG(1)
 
void get_b0_dict (const char *fname, dict_T *d)
 
void ml_sync_all (int check_file, int check_char, bool do_fsync)
 
void ml_preserve (buf_T *buf, int message, bool do_fsync)
 
char_uml_get (linenr_T lnum)
 
char_uml_get_pos (const pos_T *pos) FUNC_ATTR_NONNULL_ALL
 
char_uml_get_buf (buf_T *buf, linenr_T lnum, bool will_change) FUNC_ATTR_NONNULL_ALL
 
int ml_line_alloced (void)
 
int ml_append (linenr_T lnum, char_u *line, colnr_T len, bool newfile)
 
int ml_append_buf (buf_T *buf, linenr_T lnum, char_u *line, colnr_T len, bool newfile) FUNC_ATTR_NONNULL_ARG(1)
 
void ml_add_deleted_len (char_u *ptr, ssize_t len)
 
void ml_add_deleted_len_buf (buf_T *buf, char_u *ptr, ssize_t len)
 
int ml_replace (linenr_T lnum, char_u *line, bool copy)
 
int ml_replace_buf (buf_T *buf, linenr_T lnum, char_u *line, bool copy)
 
int ml_delete (linenr_T lnum, bool message)
 
void ml_setmarked (linenr_T lnum)
 
linenr_T ml_firstmarked (void)
 
void ml_clearmarked (void)
 
size_t ml_flush_deleted_bytes (buf_T *buf, size_t *codepoints, size_t *codeunits)
 
char_umakeswapname (char_u *fname, char_u *ffname, buf_T *buf, char_u *dir_name)
 
char_uget_file_in_dir (char_u *fname, char_u *dname)
 
void copy_option_part ((char_u **) dirp,(char_u *) dir_name, dir_len, ",")
 
 for (;;)
 
 if (os_isdir((char_u *) dir_name))
 
else if (! *found_existing_dir &&**dirp==NUL)
 
 xfree (dir_name)
 
void ml_setflags (buf_T *buf)
 
long ml_find_line_or_offset (buf_T *buf, linenr_T lnum, long *offp, bool no_ff)
 
void goto_byte (long cnt)
 Goto byte in buffer with offset 'cnt'. More...
 
int inc (pos_T *lp)
 
int incl (pos_T *lp)
 Same as inc(), but skip NUL at the end of non-empty lines. More...
 
int dec (pos_T *lp)
 
int decl (pos_T *lp)
 Same as dec(), but skip NUL at the end of non-empty lines. More...
 

Variables

static char size_t n
 
char * dir_name = xmalloc(dir_len)
 
char * buf_fname = (char *)buf->b_fname
 
const size_t dir_len = strlen(*dirp) + 1
 
 fname
 

Macro Definition Documentation

◆ B0_DIRTY

#define B0_DIRTY   0x55

◆ b0_dirty

#define b0_dirty   b0_fname[B0_FNAME_SIZE_ORG - 1]

◆ B0_FF_MASK

#define B0_FF_MASK   3

◆ b0_flags

#define b0_flags   b0_fname[B0_FNAME_SIZE_ORG - 2]

◆ B0_FNAME_SIZE_CRYPT

#define B0_FNAME_SIZE_CRYPT   890

◆ B0_FNAME_SIZE_NOCRYPT

#define B0_FNAME_SIZE_NOCRYPT   898

◆ B0_FNAME_SIZE_ORG

#define B0_FNAME_SIZE_ORG   900

◆ B0_HAS_FENC

#define B0_HAS_FENC   8

◆ B0_HNAME_SIZE

#define B0_HNAME_SIZE   40

◆ B0_MAGIC_CHAR

#define B0_MAGIC_CHAR   0x55

◆ B0_MAGIC_INT

#define B0_MAGIC_INT   0x20212223L

◆ B0_MAGIC_LONG

#define B0_MAGIC_LONG   0x30313233L

◆ B0_MAGIC_SHORT

#define B0_MAGIC_SHORT   0x10111213L

◆ B0_SAME_DIR

#define B0_SAME_DIR   4

◆ B0_UNAME_SIZE

#define B0_UNAME_SIZE   40

◆ BLOCK0_ID0

#define BLOCK0_ID0   'b'

◆ BLOCK0_ID1

#define BLOCK0_ID1   '0'

◆ CHECK

#define CHECK (   c,
  s 
)    do { } while (0)

◆ DATA_ID

#define DATA_ID   (('d' << 8) + 'a')

◆ DB_INDEX_MASK

#define DB_INDEX_MASK   (~DB_MARKED)

◆ DB_MARKED

#define DB_MARKED   ((unsigned)1 << ((sizeof(unsigned) * 8) - 1))

◆ HEADER_SIZE

#define HEADER_SIZE   (sizeof(DATA_BL) - INDEX_SIZE)

◆ INDEX_SIZE

#define INDEX_SIZE   (sizeof(unsigned))

◆ ML_DELETE

#define ML_DELETE   0x11

◆ ML_FIND

#define ML_FIND   0x13

◆ ML_FLUSH

#define ML_FLUSH   0x02

◆ ML_INSERT

#define ML_INSERT   0x12

◆ ML_SIMPLE

#define ML_SIMPLE (   x)    (x & 0x10)

◆ MLCS_MAXL

#define MLCS_MAXL   800

◆ MLCS_MINL

#define MLCS_MINL   400

◆ PTR_ID

#define PTR_ID   (('p' << 8) + 't')

◆ STACK_INCR

#define STACK_INCR   5

Typedef Documentation

◆ DATA_BL

typedef struct data_block DATA_BL

◆ PTR_BL

typedef struct pointer_block PTR_BL

◆ PTR_EN

typedef struct pointer_entry PTR_EN

◆ ZERO_BL

typedef struct block0 ZERO_BL

Enumeration Type Documentation

◆ upd_block0_T

Enumerator
UB_FNAME 
UB_SAME_DIR 

Function Documentation

◆ check_need_swap()

void check_need_swap ( bool  newfile)

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.

Parameters
newfilereading file into new buffer

◆ copy_option_part()

void copy_option_part ( (char_u **)  dirp,
(char_u *)  dir_name,
dir_len  ,
,
 
)

◆ dec()

int dec ( pos_T lp)

◆ decl()

int decl ( pos_T lp)

Same as dec(), but skip NUL at the end of non-empty lines.

◆ for()

for ( ;;  )

◆ get_b0_dict()

void get_b0_dict ( const char *  fname,
dict_T d 
)

Return information found in swapfile "fname" in dictionary "d". This is used by the swapinfo() function.

◆ get_file_in_dir()

char_u* get_file_in_dir ( char_u fname,
char_u dname 
)

Get file name to use for swap file or backup file. Use the name of the edited file "fname" and an entry in the 'dir' or 'bdir' option "dname".

  • If "dname" is ".", return "fname" (swap file in dir of file).
  • If "dname" starts with "./", insert "dname" in "fname" (swap file relative to dir of file).
  • Otherwise, prepend "dname" to the tail of "fname" (swap file in specific dir).

The return value is an allocated string and can be NULL.

Parameters
dnamedon't use "dirname", it is a global for Alpha

◆ goto_byte()

void goto_byte ( long  cnt)

Goto byte in buffer with offset 'cnt'.

◆ if() [1/2]

else if ( ! *found_existing_dir &&**  dirp = NUL)

◆ if() [2/2]

if ( os_isdir((char_u *) dir_name )

◆ inc()

int inc ( pos_T lp)

Increment the line pointer "lp" crossing line boundaries as necessary. Return 1 when going to the next line. Return 2 when moving forward onto a NUL at the end of the line). Return -1 when at the end of file. Return 0 otherwise.

◆ incl()

int incl ( pos_T lp)

Same as inc(), but skip NUL at the end of non-empty lines.

◆ make_percent_swname()

char* make_percent_swname ( const char *  dir,
const char *  name 
)

◆ makeswapname()

char_u* makeswapname ( char_u fname,
char_u ffname,
buf_T buf,
char_u dir_name 
)

◆ ml_add_deleted_len()

void ml_add_deleted_len ( char_u ptr,
ssize_t  len 
)

◆ ml_add_deleted_len_buf()

void ml_add_deleted_len_buf ( buf_T buf,
char_u ptr,
ssize_t  len 
)

◆ ml_append()

int ml_append ( linenr_T  lnum,
char_u line,
colnr_T  len,
bool  newfile 
)

Append a line after lnum (may be 0 to insert a line in front of the file). "line" does not need to be allocated, but can't be another line in a buffer, unlocking may make it invalid.

newfile: TRUE when starting to edit a new file, meaning that pe_old_lnum will be set for recovery Check: The caller of this function should probably also call appended_lines().

Parameters
lnumappend after this line (can be 0)
linetext of the new line
lenlength of new line, including NUL, or 0
newfileflag, see above
Returns
FAIL for failure, OK otherwise

◆ ml_append_buf()

int ml_append_buf ( buf_T buf,
linenr_T  lnum,
char_u line,
colnr_T  len,
bool  newfile 
)

Like ml_append() but for an arbitrary buffer. The buffer must already have a memline.

Parameters
lnumappend after this line (can be 0)
linetext of the new line
lenlength of new line, including NUL, or 0
newfileflag, see above

◆ ml_clearmarked()

void ml_clearmarked ( void  )

◆ ml_close()

void ml_close ( buf_T buf,
int  del_file 
)

◆ ml_close_all()

void ml_close_all ( int  del_file)

◆ ml_close_notmod()

void ml_close_notmod ( void  )

◆ ml_delete()

int ml_delete ( linenr_T  lnum,
bool  message 
)

Delete line lnum in the current buffer.

Note
The caller of this function should probably also call deleted_lines() after this.
Parameters
messageShow "--No lines in buffer--" message.
Returns
FAIL for failure, OK otherwise

◆ ml_find_line_or_offset()

long ml_find_line_or_offset ( buf_T buf,
linenr_T  lnum,
long *  offp,
bool  no_ff 
)

Find offset for line or line with offset.

Parameters
bufbuffer to use
lnumif > 0, find offset of lnum, return offset if == 0, return line with offset *offp
offpoffset to use to find line, store remaining column offset Should be NULL when getting offset of line
no_ffignore 'fileformat' option, always use one byte for NL.
Returns
-1 if information is not available

◆ ml_firstmarked()

linenr_T ml_firstmarked ( void  )

◆ ml_flush_deleted_bytes()

size_t ml_flush_deleted_bytes ( buf_T buf,
size_t *  codepoints,
size_t *  codeunits 
)

◆ ml_get()

char_u* ml_get ( linenr_T  lnum)

◆ ml_get_buf()

char_u* ml_get_buf ( buf_T buf,
linenr_T  lnum,
bool  will_change 
)

Return a pointer to a line in a specific buffer

Parameters
will_changetrue mark the buffer dirty (chars in the line will be changed)

◆ ml_get_pos()

char_u* ml_get_pos ( const pos_T pos)

◆ ml_line_alloced()

int ml_line_alloced ( void  )

◆ ml_open()

int ml_open ( buf_T buf)

◆ ml_open_file()

void ml_open_file ( buf_T buf)

◆ ml_open_files()

void ml_open_files ( void  )

◆ ml_preserve()

void ml_preserve ( buf_T buf,
int  message,
bool  do_fsync 
)

◆ ml_recover()

void ml_recover ( bool  checkext)

Try to recover curbuf from the .swp file.

Parameters
checkextIf true, check the extension and detect whether it is a swap file.

◆ ml_replace()

int ml_replace ( linenr_T  lnum,
char_u line,
bool  copy 
)

◆ ml_replace_buf()

int ml_replace_buf ( buf_T buf,
linenr_T  lnum,
char_u line,
bool  copy 
)

◆ ml_setflags()

void ml_setflags ( buf_T buf)

◆ ml_setmarked()

void ml_setmarked ( linenr_T  lnum)

◆ ml_setname()

void ml_setname ( buf_T buf)

◆ ml_sync_all()

void ml_sync_all ( int  check_file,
int  check_char,
bool  do_fsync 
)

◆ ml_timestamp()

void ml_timestamp ( buf_T buf)

◆ recover_names()

int recover_names ( char_u fname,
int  list,
int  nr,
char_u **  fname_out 
)

Find the names of swap files in current directory and the directory given with the 'directory' option.

Used to:

  • list the swap files for "vim -r"
  • count the number of swap files when recovering
  • list the swap files when recovering
  • find the name of the n'th swap file when recovering
Parameters
fnamebase for swap file name
listwhen TRUE, list the swap file names
nrwhen non-zero, return nr'th swap file name
fname_outresult when "nr" > 0

◆ xfree()

xfree ( dir_name  )

Variable Documentation

◆ buf_fname

char* buf_fname = (char *)buf->b_fname

◆ dir_len

const size_t dir_len = strlen(*dirp) + 1

◆ dir_name

dir_name = xmalloc(dir_len)

◆ fname

return fname
Initial value:
= (char *)makeswapname((char_u *)buf_fname, buf->b_ffname, buf,

◆ n

char size_t n
Initial value:
{
char *fname
makeswapname
char_u * makeswapname(char_u *fname, char_u *ffname, buf_T *buf, char_u *dir_name)
Definition: memline.c:3271
dir_name
char * dir_name
Definition: memline.c:3470
buf
char *const buf
Definition: encode.c:238
fname
fname
Definition: memline.c:3484
char_u
unsigned char char_u
Definition: types.h:12
buf_fname
char * buf_fname
Definition: memline.c:3471