⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 structs.h

📁 VIM文本编辑器
💻 H
📖 第 1 页 / 共 2 页
字号:
/* vi:set ts=8 sts=4 sw=4:
 *
 * VIM - Vi IMproved	by Bram Moolenaar
 *
 * Do ":help uganda"  in Vim to read copying and usage conditions.
 * Do ":help credits" in Vim to see a list of people who contributed.
 */

/*
 * This file contains various definitions of structures that are used by Vim
 */

/*
 * There is something wrong in the SAS compiler that makes typedefs not
 * valid in include files.  Has been fixed in version 6.58.
 */
#if defined(SASC) && SASC < 658
typedef long		linenr_t;
typedef unsigned	colnr_t;
typedef unsigned short	short_u;
#endif

/*
 * file position
 */
typedef struct fpos	FPOS;

struct fpos
{
    linenr_t	    lnum;	    /* line number */
    colnr_t	    col;	    /* column number */
};

/*
 * Sorry to put this here, but gui.h needs the FPOS type, and WIN needs gui.h
 * for GuiScrollbar.  There is probably somewhere better it could go -- webb
 */
#ifdef USE_GUI
# include "gui.h"
#else
# define GuiColor int	    /* avoid error message for undefined struct */
#endif

/*
 * marks: positions in a file
 * (a normal mark is a lnum/col pair, the same as a file position)
 */

#define NMARKS		26	    /* max. # of named marks */
#define JUMPLISTSIZE	50	    /* max. # of marks in jump list */
#define TAGSTACKSIZE	20	    /* max. # of tags in tag stack */

struct filemark
{
    FPOS	    mark;	    /* cursor position */
    int		    fnum;	    /* file number */
};

/*
 * The taggy struct is used to store the information about a :tag command.
 */
struct taggy
{
    char_u	    *tagname;		/* tag name */
    struct filemark fmark;		/* cursor position BEFORE ":tag" */
    int		    cur_match;		/* match number */
};

/*
 * line number list
 */

/*
 * Each window can have a different line number associated with a buffer.
 * The window-pointer/line-number pairs are kept in the line number list.
 * The list of line numbers is kept in most-recently-used order.
 */

typedef struct window	    WIN;
typedef struct winfpos	    WINFPOS;

struct winfpos
{
    WINFPOS	*wl_next;	    /* next entry or NULL for last entry */
    WINFPOS	*wl_prev;	    /* previous entry or NULL for first entry */
    WIN		*wl_win;	    /* pointer to window that did set wl_lnum */
    FPOS	wl_fpos;	    /* last cursor position in the file */
};

/*
 * stuctures used for undo
 */

struct u_entry
{
    struct u_entry  *ue_next;	/* pointer to next entry in list */
    linenr_t	    ue_top;	/* number of line above undo block */
    linenr_t	    ue_bot;	/* number of line below undo block */
    linenr_t	    ue_lcount;	/* linecount when u_save called */
    char_u	    **ue_array;	/* array of lines in undo block */
    long	    ue_size;	/* number of lines in ue_array */
};

struct u_header
{
    struct u_header *uh_next;	/* pointer to next header in list */
    struct u_header *uh_prev;	/* pointer to previous header in list */
    struct u_entry  *uh_entry;	/* pointer to first entry */
    FPOS	     uh_cursor;	/* cursor position before saving */
    int		     uh_flags;	/* see below */
    FPOS	     uh_namedm[NMARKS];	/* marks before undo/after redo */
};

/* values for uh_flags */
#define UH_CHANGED  0x01	/* b_changed flag before undo/after redo */
#define UH_EMPTYBUF 0x02	/* buffer was empty */

/*
 * stuctures used in undo.c
 */
#if SIZEOF_INT > 2
# define ALIGN_LONG	/* longword alignment and use filler byte */
# define ALIGN_SIZE (sizeof(long))
#else
# define ALIGN_SIZE (sizeof(short))
#endif

#define ALIGN_MASK (ALIGN_SIZE - 1)

typedef struct m_info info_t;

/*
 * stucture used to link chunks in one of the free chunk lists.
 */
struct m_info
{
#ifdef ALIGN_LONG
    long_u   m_size;	/* size of the chunk (including m_info) */
#else
    short_u  m_size;	/* size of the chunk (including m_info) */
#endif
    info_t  *m_next;	/* pointer to next free chunk in the list */
};

/*
 * structure used to link blocks in the list of allocated blocks.
 */
struct m_block
{
    struct m_block  *mb_next;	/* pointer to next allocated block */
    info_t	    mb_info;	/* head of free chuck list for this block */
};

/*
 * Structure used for growing arrays.
 * This is used to store information that only grows, is deleted all at
 * once, and needs to be accessed by index.  See ga_clear() and ga_grow().
 */
struct growarray
{
    int	    ga_len;		    /* current number of items used */
    int	    ga_room;		    /* number of unused items at the end */
    int	    ga_itemsize;	    /* sizeof one item */
    int	    ga_growsize;	    /* number of items to grow each time */
    void    *ga_data;		    /* pointer to the first item */
};

/*
 * things used in memfile.c
 */

typedef struct block_hdr    BHDR;
typedef struct memfile	    MEMFILE;
typedef long		    blocknr_t;

/*
 * for each (previously) used block in the memfile there is one block header.
 *
 * The block may be linked in the used list OR in the free list.
 * The used blocks are also kept in hash lists.
 *
 * The used list is a doubly linked list, most recently used block first.
 *	The blocks in the used list have a block of memory allocated.
 *	mf_used_count is the number of pages in the used list.
 * The hash lists are used to quickly find a block in the used list.
 * The free list is a single linked list, not sorted.
 *	The blocks in the free list have no block of memory allocated and
 *	the contents of the block in the file (if any) is irrelevant.
 */

struct block_hdr
{
    BHDR	*bh_next;	    /* next block_hdr in free or used list */
    BHDR	*bh_prev;	    /* previous block_hdr in used list */
    BHDR	*bh_hash_next;	    /* next block_hdr in hash list */
    BHDR	*bh_hash_prev;	    /* previous block_hdr in hash list */
    blocknr_t	bh_bnum;		/* block number */
    char_u	*bh_data;	    /* pointer to memory (for used block) */
    int		bh_page_count;	    /* number of pages in this block */

#define BH_DIRTY    1
#define BH_LOCKED   2
    char	bh_flags;	    /* BH_DIRTY or BH_LOCKED */
};

/*
 * when a block with a negative number is flushed to the file, it gets
 * a positive number. Because the reference to the block is still the negative
 * number, we remember the translation to the new positive number in the
 * double linked trans lists. The structure is the same as the hash lists.
 */
typedef struct nr_trans NR_TRANS;

struct nr_trans
{
    NR_TRANS	*nt_next;	    /* next nr_trans in hash list */
    NR_TRANS	*nt_prev;	    /* previous nr_trans in hash list */
    blocknr_t	nt_old_bnum;		/* old, negative, number */
    blocknr_t	nt_new_bnum;		/* new, positive, number */
};

/*
 * Simplistic hashing scheme to quickly locate the blocks in the used list.
 * 64 blocks are found directly (64 * 4K = 256K, most files are smaller).
 */
#define MEMHASHSIZE	64
#define MEMHASH(nr)	((nr) & (MEMHASHSIZE - 1))

struct memfile
{
    char_u	*mf_fname;	    /* name of the file */
    char_u	*mf_ffname;	    /* idem, full path */
    int		mf_fd;		    /* file descriptor */
    BHDR	*mf_free_first;	    /* first block_hdr in free list */
    BHDR	*mf_used_first;	    /* mru block_hdr in used list */
    BHDR	*mf_used_last;	    /* lru block_hdr in used list */
    unsigned	mf_used_count;	    /* number of pages in used list */
    unsigned	mf_used_count_max;  /* maximum number of pages in memory */
    BHDR	*mf_hash[MEMHASHSIZE];	/* array of hash lists */
    NR_TRANS	*mf_trans[MEMHASHSIZE];	/* array of trans lists */
    blocknr_t	mf_blocknr_max;	    /* highest positive block number + 1*/
    blocknr_t	mf_blocknr_min;	    /* lowest negative block number - 1 */
    blocknr_t	mf_neg_count;	    /* number of negative blocks numbers */
    blocknr_t	mf_infile_count;    /* number of pages in the file */
    unsigned	mf_page_size;	    /* number of bytes in a page */
    int		mf_dirty;	    /* Set to TRUE if there are dirty blocks */
};

/*
 * things used in memline.c
 */
typedef struct info_pointer	IPTR;	    /* block/index pair */

/*
 * When searching for a specific line, we remember what blocks in the tree
 * are the branches leading to that block. This is stored in ml_stack.
 * Each entry is a pointer to info in a block (may be data block or pointer block)
 */
struct info_pointer
{
    blocknr_t	ip_bnum;	/* block number */
    linenr_t	ip_low;		/* lowest lnum in this block */
    linenr_t	ip_high;	/* highest lnum in this block */
    int		ip_index;	/* index for block with current lnum */
};

typedef struct memline MEMLINE;

/*
 * the memline structure holds all the information about a memline
 */
struct memline
{
    linenr_t	ml_line_count;	/* number of lines in the buffer */

    MEMFILE	*ml_mfp;	/* pointer to associated memfile */

#define ML_EMPTY	1	/* empty buffer */
#define ML_LINE_DIRTY	2	/* cached line was changed and allocated */
#define ML_LOCKED_DIRTY	4	/* ml_locked was changed */
#define ML_LOCKED_POS	8	/* ml_locked needs positive block number */
    int		ml_flags;

    IPTR	*ml_stack;	/* stack of pointer blocks (array of IPTRs) */
    int		ml_stack_top;	/* current top if ml_stack */
    int		ml_stack_size;	/* total number of entries in ml_stack */

    linenr_t	ml_line_lnum;	/* line number of cached line, 0 if not valid */
    char_u	*ml_line_ptr;	/* pointer to cached line */

    BHDR	*ml_locked;	/* block used by last ml_get */
    linenr_t	ml_locked_low;	/* first line in ml_locked */
    linenr_t	ml_locked_high;	/* last line in ml_locked */
    int		ml_locked_lineadd;  /* number of lines inserted in ml_locked */
};

#ifdef SYNTAX_HL
/*
 * Each keyword has one keyentry, which is linked in a hash list.
 */
struct keyentry
{
    struct keyentry *next;	/* next keyword in the hash list */
    int		    syn_inc_lvl;    /* ":syn include" level for this match */
    short	    syn_id;	/* syntax ID for this match (if non-zero) */
    short	    *next_list;	/* ID list for next match (if non-zero) */
    short	    flags;	/* see syntax.c */
    char_u	    keyword[1];	/* actually longer */
};

/*
 * syn_state contains syntax state at the start of a line.
 */
struct syn_state
{
    struct growarray	sst_ga;		/* growarray to store syntax state */
    short		*sst_next_list;	/* "nextgroup" list in this state
					   (this is a copy, don't free it! */
    int			sst_next_flags;	/* flags for sst_next_list */
};
#endif /* SYNTAX_HL */

/*
 * Structure shared between syntax.c, screen.c and gui_x11.c.
 */
struct attr_entry
{
    short	    ae_attr;		/* HL_BOLD, etc. */
    union
    {
	struct
	{
	    char_u	    *start;	/* start escape sequence */
	    char_u	    *stop;	/* stop escape sequence */
	} term;
	struct
	{
	    char_u	    fg_color;	/* foreground color number */
	    char_u	    bg_color;	/* background color number */
	} cterm;
# ifdef USE_GUI
	struct
	{
	    GuiColor	    fg_color;	/* foreground color handle */
	    GuiColor	    bg_color;	/* background color handle */
	    GuiFont	    font;	/* font handle */
	} gui;
# endif
    } ae_u;
};

/*
 * buffer: structure that holds information about one file
 *
 * Several windows can share a single Buffer
 * A buffer is unallocated if there is no memfile for it.
 * A buffer is new if the associated file has never been loaded yet.
 */

typedef struct buffer BUF;

struct buffer
{
    MEMLINE	     b_ml;		/* associated memline (also contains
					 * line count) */

    BUF		    *b_next;		/* links in list of buffers */
    BUF		    *b_prev;

    int		     b_changed;		/* 'modified': Set to TRUE if
					 * something in the file has
					 * been changed and not written out.
					 */

    int		     b_notedited;	/* Set to TRUE when file name is
					 * changed after starting to edit,
					 * reset when file is written out. */

    int		     b_nwindows;	/* nr of windows open on this buffer */

    int		     b_flags;		/* various BF_ flags */

    /*
     * b_ffname has the full path of the file.
     * b_sfname is the name as the user typed it.
     * b_fname is the same as b_sfname, unless ":cd" has been done,
     *		then it is the same as b_ffname.
     */
    char_u	    *b_ffname;		/* full path file name */
    char_u	    *b_sfname;		/* short file name */
    char_u	    *b_fname;		/* current file name */

#ifdef USE_SNIFF
    int		     b_sniff;		/* file was loaded through Sniff */
#endif

    int		     b_fnum;		/* file number for this file. */
    WINFPOS	    *b_winfpos;		/* list of last used lnum for
					 * each window */

    long	     b_mtime;		/* last change time of original file */
    long	     b_mtime_read;	/* last change time when reading */

    FPOS	     b_namedm[NMARKS];	/* current named marks (mark.c) */

    /* These variables are set when VIsual_active becomes FALSE */
    FPOS	     b_visual_start;	/* start pos of last VIsual */
    FPOS	     b_visual_end;	/* end position of last VIsual */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -