xref: /vim-8.2.3635/src/structs.h (revision 130cbfc3)
1 /* vi:set ts=8 sts=4 sw=4 noet:
2  *
3  * VIM - Vi IMproved	by Bram Moolenaar
4  *
5  * Do ":help uganda"  in Vim to read copying and usage conditions.
6  * Do ":help credits" in Vim to see a list of people who contributed.
7  */
8 
9 /*
10  * This file contains various definitions of structures that are used by Vim
11  */
12 
13 /*
14  * There is something wrong in the SAS compiler that makes typedefs not
15  * valid in include files.  Has been fixed in version 6.58.
16  */
17 #if defined(SASC) && SASC < 658
18 typedef long		linenr_T;
19 typedef int		colnr_T;
20 typedef unsigned short	short_u;
21 #endif
22 
23 /*
24  * Position in file or buffer.
25  */
26 typedef struct
27 {
28     linenr_T	lnum;	// line number
29     colnr_T	col;	// column number
30     colnr_T	coladd; // extra virtual column
31 } pos_T;
32 
33 
34 /*
35  * Same, but without coladd.
36  */
37 typedef struct
38 {
39     linenr_T	lnum;	// line number
40     colnr_T	col;	// column number
41 } lpos_T;
42 
43 /*
44  * Structure used for growing arrays.
45  * This is used to store information that only grows, is deleted all at
46  * once, and needs to be accessed by index.  See ga_clear() and ga_grow().
47  */
48 typedef struct growarray
49 {
50     int	    ga_len;		    // current number of items used
51     int	    ga_maxlen;		    // maximum number of items possible
52     int	    ga_itemsize;	    // sizeof(item)
53     int	    ga_growsize;	    // number of items to grow each time
54     void    *ga_data;		    // pointer to the first item
55 } garray_T;
56 
57 #define GA_EMPTY    {0, 0, 0, 0, NULL}
58 
59 typedef struct window_S		win_T;
60 typedef struct wininfo_S	wininfo_T;
61 typedef struct frame_S		frame_T;
62 typedef int			scid_T;		// script ID
63 typedef struct file_buffer	buf_T;		// forward declaration
64 typedef struct terminal_S	term_T;
65 
66 #ifdef FEAT_MENU
67 typedef struct VimMenu vimmenu_T;
68 #endif
69 
70 // maximum value for sc_version
71 #define SCRIPT_VERSION_MAX 4
72 // value for sc_version in a Vim9 script file
73 #define SCRIPT_VERSION_VIM9 999999
74 
75 /*
76  * SCript ConteXt (SCTX): identifies a script line.
77  * When sourcing a script "sc_lnum" is zero, "sourcing_lnum" is the current
78  * line number. When executing a user function "sc_lnum" is the line where the
79  * function was defined, "sourcing_lnum" is the line number inside the
80  * function.  When stored with a function, mapping, option, etc. "sc_lnum" is
81  * the line number in the script "sc_sid".
82  *
83  * sc_version is also here, for convenience.
84  */
85 typedef struct {
86 #ifdef FEAT_EVAL
87     scid_T	sc_sid;		// script ID
88     int		sc_seq;		// sourcing sequence number
89     linenr_T	sc_lnum;	// line number
90 #endif
91     int		sc_version;	// :scriptversion
92 } sctx_T;
93 
94 /*
95  * Reference to a buffer that stores the value of buf_free_count.
96  * bufref_valid() only needs to check "buf" when the count differs.
97  */
98 typedef struct {
99     buf_T   *br_buf;
100     int	    br_fnum;
101     int	    br_buf_free_count;
102 } bufref_T;
103 
104 /*
105  * This is here because regexp.h needs pos_T and below regprog_T is used.
106  */
107 #include "regexp.h"
108 
109 /*
110  * This is here because gui.h needs the pos_T and win_T, and win_T needs gui.h
111  * for scrollbar_T.
112  */
113 #ifdef FEAT_GUI
114 # include "gui.h"
115 #else
116 # ifdef FEAT_XCLIPBOARD
117 #  include <X11/Intrinsic.h>
118 # endif
119 # define guicolor_T long
120 # define INVALCOLOR ((guicolor_T)0x1ffffff)
121     // only used for cterm.bg_rgb and cterm.fg_rgb: use cterm color
122 # define CTERMCOLOR ((guicolor_T)0x1fffffe)
123 #endif
124 #define COLOR_INVALID(x) ((x) == INVALCOLOR || (x) == CTERMCOLOR)
125 
126 /*
127  * marks: positions in a file
128  * (a normal mark is a lnum/col pair, the same as a file position)
129  */
130 
131 // (Note: for EBCDIC there are more than 26, because there are gaps in the
132 // alphabet coding.  To minimize changes to the code, I decided to just
133 // increase the number of possible marks.
134 #define NMARKS		('z' - 'a' + 1)	// max. # of named marks
135 #define EXTRA_MARKS	10		// marks 0-9
136 #define JUMPLISTSIZE	100		// max. # of marks in jump list
137 #define TAGSTACKSIZE	20		// max. # of tags in tag stack
138 
139 typedef struct filemark
140 {
141     pos_T	mark;		// cursor position
142     int		fnum;		// file number
143 } fmark_T;
144 
145 // Xtended file mark: also has a file name
146 typedef struct xfilemark
147 {
148     fmark_T	fmark;
149     char_u	*fname;		// file name, used when fnum == 0
150 #ifdef FEAT_VIMINFO
151     time_T	time_set;
152 #endif
153 } xfmark_T;
154 
155 /*
156  * The taggy struct is used to store the information about a :tag command.
157  */
158 typedef struct taggy
159 {
160     char_u	*tagname;	// tag name
161     fmark_T	fmark;		// cursor position BEFORE ":tag"
162     int		cur_match;	// match number
163     int		cur_fnum;	// buffer number used for cur_match
164     char_u	*user_data;	// used with tagfunc
165 } taggy_T;
166 
167 /*
168  * Structure that contains all options that are local to a window.
169  * Used twice in a window: for the current buffer and for all buffers.
170  * Also used in wininfo_T.
171  */
172 typedef struct
173 {
174 #ifdef FEAT_ARABIC
175     int		wo_arab;
176 # define w_p_arab w_onebuf_opt.wo_arab	// 'arabic'
177 #endif
178 #ifdef FEAT_LINEBREAK
179     int		wo_bri;
180 # define w_p_bri w_onebuf_opt.wo_bri	// 'breakindent'
181     char_u	*wo_briopt;
182 # define w_p_briopt w_onebuf_opt.wo_briopt // 'breakindentopt'
183 #endif
184     char_u	*wo_wcr;
185 # define w_p_wcr w_onebuf_opt.wo_wcr	// 'wincolor'
186 #ifdef FEAT_DIFF
187     int		wo_diff;
188 # define w_p_diff w_onebuf_opt.wo_diff	// 'diff'
189 #endif
190 #ifdef FEAT_FOLDING
191     long	wo_fdc;
192 # define w_p_fdc w_onebuf_opt.wo_fdc	// 'foldcolumn'
193     int		wo_fdc_save;
194 # define w_p_fdc_save w_onebuf_opt.wo_fdc_save	// 'foldenable' saved for diff mode
195     int		wo_fen;
196 # define w_p_fen w_onebuf_opt.wo_fen	// 'foldenable'
197     int		wo_fen_save;
198 # define w_p_fen_save w_onebuf_opt.wo_fen_save	// 'foldenable' saved for diff mode
199     char_u	*wo_fdi;
200 # define w_p_fdi w_onebuf_opt.wo_fdi	// 'foldignore'
201     long	wo_fdl;
202 # define w_p_fdl w_onebuf_opt.wo_fdl	// 'foldlevel'
203     int		wo_fdl_save;
204 # define w_p_fdl_save w_onebuf_opt.wo_fdl_save	// 'foldlevel' state saved for diff mode
205     char_u	*wo_fdm;
206 # define w_p_fdm w_onebuf_opt.wo_fdm	// 'foldmethod'
207     char_u	*wo_fdm_save;
208 # define w_p_fdm_save w_onebuf_opt.wo_fdm_save	// 'fdm' saved for diff mode
209     long	wo_fml;
210 # define w_p_fml w_onebuf_opt.wo_fml	// 'foldminlines'
211     long	wo_fdn;
212 # define w_p_fdn w_onebuf_opt.wo_fdn	// 'foldnestmax'
213 # ifdef FEAT_EVAL
214     char_u	*wo_fde;
215 # define w_p_fde w_onebuf_opt.wo_fde	// 'foldexpr'
216     char_u	*wo_fdt;
217 #  define w_p_fdt w_onebuf_opt.wo_fdt	// 'foldtext'
218 # endif
219     char_u	*wo_fmr;
220 # define w_p_fmr w_onebuf_opt.wo_fmr	// 'foldmarker'
221 #endif
222 #ifdef FEAT_LINEBREAK
223     int		wo_lbr;
224 # define w_p_lbr w_onebuf_opt.wo_lbr	// 'linebreak'
225 #endif
226     int		wo_list;
227 #define w_p_list w_onebuf_opt.wo_list	// 'list'
228     char_u	*wo_lcs;
229 #define w_p_lcs w_onebuf_opt.wo_lcs	// 'listchars'
230     int		wo_nu;
231 #define w_p_nu w_onebuf_opt.wo_nu	// 'number'
232     int		wo_rnu;
233 #define w_p_rnu w_onebuf_opt.wo_rnu	// 'relativenumber'
234 #ifdef FEAT_LINEBREAK
235     long	wo_nuw;
236 # define w_p_nuw w_onebuf_opt.wo_nuw	// 'numberwidth'
237 #endif
238     int		wo_wfh;
239 # define w_p_wfh w_onebuf_opt.wo_wfh	// 'winfixheight'
240     int		wo_wfw;
241 # define w_p_wfw w_onebuf_opt.wo_wfw	// 'winfixwidth'
242 #if defined(FEAT_QUICKFIX)
243     int		wo_pvw;
244 # define w_p_pvw w_onebuf_opt.wo_pvw	// 'previewwindow'
245 #endif
246 #ifdef FEAT_RIGHTLEFT
247     int		wo_rl;
248 # define w_p_rl w_onebuf_opt.wo_rl	// 'rightleft'
249     char_u	*wo_rlc;
250 # define w_p_rlc w_onebuf_opt.wo_rlc	// 'rightleftcmd'
251 #endif
252     long	wo_scr;
253 #define w_p_scr w_onebuf_opt.wo_scr	// 'scroll'
254 #ifdef FEAT_SPELL
255     int		wo_spell;
256 # define w_p_spell w_onebuf_opt.wo_spell // 'spell'
257 #endif
258 #ifdef FEAT_SYN_HL
259     int		wo_cuc;
260 # define w_p_cuc w_onebuf_opt.wo_cuc	// 'cursorcolumn'
261     int		wo_cul;
262 # define w_p_cul w_onebuf_opt.wo_cul	// 'cursorline'
263     char_u	*wo_culopt;
264 # define w_p_culopt w_onebuf_opt.wo_culopt	// 'cursorlineopt'
265     char_u	*wo_cc;
266 # define w_p_cc w_onebuf_opt.wo_cc	// 'colorcolumn'
267 #endif
268 #ifdef FEAT_LINEBREAK
269     char_u	*wo_sbr;
270 #define w_p_sbr w_onebuf_opt.wo_sbr	// 'showbreak'
271 #endif
272 #ifdef FEAT_STL_OPT
273     char_u	*wo_stl;
274 #define w_p_stl w_onebuf_opt.wo_stl	// 'statusline'
275 #endif
276     int		wo_scb;
277 #define w_p_scb w_onebuf_opt.wo_scb	// 'scrollbind'
278     int		wo_diff_saved; // options were saved for starting diff mode
279 #define w_p_diff_saved w_onebuf_opt.wo_diff_saved
280     int		wo_scb_save;	// 'scrollbind' saved for diff mode
281 #define w_p_scb_save w_onebuf_opt.wo_scb_save
282     int		wo_wrap;
283 #define w_p_wrap w_onebuf_opt.wo_wrap	// 'wrap'
284 #ifdef FEAT_DIFF
285     int		wo_wrap_save;	// 'wrap' state saved for diff mode
286 # define w_p_wrap_save w_onebuf_opt.wo_wrap_save
287 #endif
288 #ifdef FEAT_CONCEAL
289     char_u	*wo_cocu;		// 'concealcursor'
290 # define w_p_cocu w_onebuf_opt.wo_cocu
291     long	wo_cole;		// 'conceallevel'
292 # define w_p_cole w_onebuf_opt.wo_cole
293 #endif
294     int		wo_crb;
295 #define w_p_crb w_onebuf_opt.wo_crb	// 'cursorbind'
296     int		wo_crb_save;	// 'cursorbind' state saved for diff mode
297 #define w_p_crb_save w_onebuf_opt.wo_crb_save
298 #ifdef FEAT_SIGNS
299     char_u	*wo_scl;
300 # define w_p_scl w_onebuf_opt.wo_scl	// 'signcolumn'
301 #endif
302 #ifdef FEAT_TERMINAL
303     char_u	*wo_twk;
304 # define w_p_twk w_onebuf_opt.wo_twk	// 'termwinkey'
305     char_u	*wo_tws;
306 # define w_p_tws w_onebuf_opt.wo_tws	// 'termwinsize'
307 #endif
308 
309 #ifdef FEAT_EVAL
310     sctx_T	wo_script_ctx[WV_COUNT];	// SCTXs for window-local options
311 # define w_p_script_ctx w_onebuf_opt.wo_script_ctx
312 #endif
313 } winopt_T;
314 
315 /*
316  * Window info stored with a buffer.
317  *
318  * Two types of info are kept for a buffer which are associated with a
319  * specific window:
320  * 1. Each window can have a different line number associated with a buffer.
321  * 2. The window-local options for a buffer work in a similar way.
322  * The window-info is kept in a list at b_wininfo.  It is kept in
323  * most-recently-used order.
324  */
325 struct wininfo_S
326 {
327     wininfo_T	*wi_next;	// next entry or NULL for last entry
328     wininfo_T	*wi_prev;	// previous entry or NULL for first entry
329     win_T	*wi_win;	// pointer to window that did set wi_fpos
330     pos_T	wi_fpos;	// last cursor position in the file
331     int		wi_optset;	// TRUE when wi_opt has useful values
332     winopt_T	wi_opt;		// local window options
333 #ifdef FEAT_FOLDING
334     int		wi_fold_manual;	// copy of w_fold_manual
335     garray_T	wi_folds;	// clone of w_folds
336 #endif
337 };
338 
339 /*
340  * Info used to pass info about a fold from the fold-detection code to the
341  * code that displays the foldcolumn.
342  */
343 typedef struct foldinfo
344 {
345     int		fi_level;	// level of the fold; when this is zero the
346 				// other fields are invalid
347     int		fi_lnum;	// line number where fold starts
348     int		fi_low_level;	// lowest fold level that starts in the same
349 				// line
350 } foldinfo_T;
351 
352 /*
353  * Structure to store info about the Visual area.
354  */
355 typedef struct
356 {
357     pos_T	vi_start;	// start pos of last VIsual
358     pos_T	vi_end;		// end position of last VIsual
359     int		vi_mode;	// VIsual_mode of last VIsual
360     colnr_T	vi_curswant;	// MAXCOL from w_curswant
361 } visualinfo_T;
362 
363 /*
364  * structures used for undo
365  */
366 
367 // One line saved for undo.  After the NUL terminated text there might be text
368 // properties, thus ul_len can be larger than STRLEN(ul_line) + 1.
369 typedef struct {
370     char_u	*ul_line;	// text of the line
371     long	ul_len;		// length of the line including NUL, plus text
372 				// properties
373 } undoline_T;
374 
375 typedef struct u_entry u_entry_T;
376 typedef struct u_header u_header_T;
377 struct u_entry
378 {
379     u_entry_T	*ue_next;	// pointer to next entry in list
380     linenr_T	ue_top;		// number of line above undo block
381     linenr_T	ue_bot;		// number of line below undo block
382     linenr_T	ue_lcount;	// linecount when u_save called
383     undoline_T	*ue_array;	// array of lines in undo block
384     long	ue_size;	// number of lines in ue_array
385 #ifdef U_DEBUG
386     int		ue_magic;	// magic number to check allocation
387 #endif
388 };
389 
390 struct u_header
391 {
392     // The following have a pointer and a number. The number is used when
393     // reading the undo file in u_read_undo()
394     union {
395 	u_header_T *ptr;	// pointer to next undo header in list
396 	long	   seq;
397     } uh_next;
398     union {
399 	u_header_T *ptr;	// pointer to previous header in list
400 	long	   seq;
401     } uh_prev;
402     union {
403 	u_header_T *ptr;	// pointer to next header for alt. redo
404 	long	   seq;
405     } uh_alt_next;
406     union {
407 	u_header_T *ptr;	// pointer to previous header for alt. redo
408 	long	   seq;
409     } uh_alt_prev;
410     long	uh_seq;		// sequence number, higher == newer undo
411     int		uh_walk;	// used by undo_time()
412     u_entry_T	*uh_entry;	// pointer to first entry
413     u_entry_T	*uh_getbot_entry; // pointer to where ue_bot must be set
414     pos_T	uh_cursor;	// cursor position before saving
415     long	uh_cursor_vcol;
416     int		uh_flags;	// see below
417     pos_T	uh_namedm[NMARKS];	// marks before undo/after redo
418     visualinfo_T uh_visual;	// Visual areas before undo/after redo
419     time_T	uh_time;	// timestamp when the change was made
420     long	uh_save_nr;	// set when the file was saved after the
421 				// changes in this block
422 #ifdef U_DEBUG
423     int		uh_magic;	// magic number to check allocation
424 #endif
425 };
426 
427 // values for uh_flags
428 #define UH_CHANGED  0x01	// b_changed flag before undo/after redo
429 #define UH_EMPTYBUF 0x02	// buffer was empty
430 
431 /*
432  * structures used in undo.c
433  */
434 #define ALIGN_LONG	// longword alignment and use filler byte
435 #define ALIGN_SIZE (sizeof(long))
436 
437 #define ALIGN_MASK (ALIGN_SIZE - 1)
438 
439 typedef struct m_info minfo_T;
440 
441 /*
442  * structure used to link chunks in one of the free chunk lists.
443  */
444 struct m_info
445 {
446 #ifdef ALIGN_LONG
447     long_u	m_size;		// size of the chunk (including m_info)
448 #else
449     short_u	m_size;		// size of the chunk (including m_info)
450 #endif
451     minfo_T	*m_next;	// pointer to next free chunk in the list
452 };
453 
454 /*
455  * things used in memfile.c
456  */
457 
458 typedef struct block_hdr    bhdr_T;
459 typedef struct memfile	    memfile_T;
460 typedef long		    blocknr_T;
461 
462 /*
463  * mf_hashtab_T is a chained hashtable with blocknr_T key and arbitrary
464  * structures as items.  This is an intrusive data structure: we require
465  * that items begin with mf_hashitem_T which contains the key and linked
466  * list pointers.  List of items in each bucket is doubly-linked.
467  */
468 
469 typedef struct mf_hashitem_S mf_hashitem_T;
470 
471 struct mf_hashitem_S
472 {
473     mf_hashitem_T   *mhi_next;
474     mf_hashitem_T   *mhi_prev;
475     blocknr_T	    mhi_key;
476 };
477 
478 #define MHT_INIT_SIZE   64
479 
480 typedef struct mf_hashtab_S
481 {
482     long_u	    mht_mask;	    // mask used for hash value (nr of items
483 				    // in array is "mht_mask" + 1)
484     long_u	    mht_count;	    // nr of items inserted into hashtable
485     mf_hashitem_T   **mht_buckets;  // points to mht_small_buckets or
486 				    //dynamically allocated array
487     mf_hashitem_T   *mht_small_buckets[MHT_INIT_SIZE];   // initial buckets
488     char	    mht_fixed;	    // non-zero value forbids growth
489 } mf_hashtab_T;
490 
491 /*
492  * for each (previously) used block in the memfile there is one block header.
493  *
494  * The block may be linked in the used list OR in the free list.
495  * The used blocks are also kept in hash lists.
496  *
497  * The used list is a doubly linked list, most recently used block first.
498  *	The blocks in the used list have a block of memory allocated.
499  *	mf_used_count is the number of pages in the used list.
500  * The hash lists are used to quickly find a block in the used list.
501  * The free list is a single linked list, not sorted.
502  *	The blocks in the free list have no block of memory allocated and
503  *	the contents of the block in the file (if any) is irrelevant.
504  */
505 
506 struct block_hdr
507 {
508     mf_hashitem_T bh_hashitem;      // header for hash table and key
509 #define bh_bnum bh_hashitem.mhi_key // block number, part of bh_hashitem
510 
511     bhdr_T	*bh_next;	    // next block_hdr in free or used list
512     bhdr_T	*bh_prev;	    // previous block_hdr in used list
513     char_u	*bh_data;	    // pointer to memory (for used block)
514     int		bh_page_count;	    // number of pages in this block
515 
516 #define BH_DIRTY    1
517 #define BH_LOCKED   2
518     char	bh_flags;	    // BH_DIRTY or BH_LOCKED
519 };
520 
521 /*
522  * when a block with a negative number is flushed to the file, it gets
523  * a positive number. Because the reference to the block is still the negative
524  * number, we remember the translation to the new positive number in the
525  * double linked trans lists. The structure is the same as the hash lists.
526  */
527 typedef struct nr_trans NR_TRANS;
528 
529 struct nr_trans
530 {
531     mf_hashitem_T nt_hashitem;		// header for hash table and key
532 #define nt_old_bnum nt_hashitem.mhi_key	// old, negative, number
533 
534     blocknr_T	nt_new_bnum;		// new, positive, number
535 };
536 
537 
538 typedef struct buffblock buffblock_T;
539 typedef struct buffheader buffheader_T;
540 
541 /*
542  * structure used to store one block of the stuff/redo/recording buffers
543  */
544 struct buffblock
545 {
546     buffblock_T	*b_next;	// pointer to next buffblock
547     char_u	b_str[1];	// contents (actually longer)
548 };
549 
550 /*
551  * header used for the stuff buffer and the redo buffer
552  */
553 struct buffheader
554 {
555     buffblock_T	bh_first;	// first (dummy) block of list
556     buffblock_T	*bh_curr;	// buffblock for appending
557     int		bh_index;	// index for reading
558     int		bh_space;	// space in bh_curr for appending
559 };
560 
561 typedef struct
562 {
563     buffheader_T sr_redobuff;
564     buffheader_T sr_old_redobuff;
565 } save_redo_T;
566 
567 /*
568  * used for completion on the command line
569  */
570 typedef struct expand
571 {
572     char_u	*xp_pattern;		// start of item to expand
573     int		xp_context;		// type of expansion
574     int		xp_pattern_len;		// bytes in xp_pattern before cursor
575 #if defined(FEAT_EVAL)
576     char_u	*xp_arg;		// completion function
577     sctx_T	xp_script_ctx;		// SCTX for completion function
578 #endif
579     int		xp_backslash;		// one of the XP_BS_ values
580 #ifndef BACKSLASH_IN_FILENAME
581     int		xp_shell;		// TRUE for a shell command, more
582 					// characters need to be escaped
583 #endif
584     int		xp_numfiles;		// number of files found by
585 					// file name completion
586     int		xp_col;			// cursor position in line
587     char_u	**xp_files;		// list of files
588     char_u	*xp_line;		// text being completed
589 } expand_T;
590 
591 /*
592  * values for xp_backslash
593  */
594 #define XP_BS_NONE	0	// nothing special for backslashes
595 #define XP_BS_ONE	1	// uses one backslash before a space
596 #define XP_BS_THREE	2	// uses three backslashes before a space
597 
598 /*
599  * Variables shared between getcmdline(), redrawcmdline() and others.
600  * These need to be saved when using CTRL-R |, that's why they are in a
601  * structure.
602  */
603 typedef struct
604 {
605     char_u	*cmdbuff;	// pointer to command line buffer
606     int		cmdbufflen;	// length of cmdbuff
607     int		cmdlen;		// number of chars in command line
608     int		cmdpos;		// current cursor position
609     int		cmdspos;	// cursor column on screen
610     int		cmdfirstc;	// ':', '/', '?', '=', '>' or NUL
611     int		cmdindent;	// number of spaces before cmdline
612     char_u	*cmdprompt;	// message in front of cmdline
613     int		cmdattr;	// attributes for prompt
614     int		overstrike;	// Typing mode on the command line.  Shared by
615 				// getcmdline() and put_on_cmdline().
616     expand_T	*xpc;		// struct being used for expansion, xp_pattern
617 				// may point into cmdbuff
618     int		xp_context;	// type of expansion
619 # ifdef FEAT_EVAL
620     char_u	*xp_arg;	// user-defined expansion arg
621     int		input_fn;	// when TRUE Invoked for input() function
622 # endif
623 } cmdline_info_T;
624 
625 /*
626  * Command modifiers ":vertical", ":browse", ":confirm" and ":hide" set a flag.
627  * This needs to be saved for recursive commands, put them in a structure for
628  * easy manipulation.
629  */
630 typedef struct
631 {
632     int		cmod_flags;		// CMOD_ flags
633 #define CMOD_SANDBOX	    0x0001	// ":sandbox"
634 #define CMOD_SILENT	    0x0002	// ":silent"
635 #define CMOD_ERRSILENT	    0x0004	// ":silent!"
636 #define CMOD_UNSILENT	    0x0008	// ":unsilent"
637 #define CMOD_NOAUTOCMD	    0x0010	// ":noautocmd"
638 #define CMOD_HIDE	    0x0020	// ":hide"
639 #define CMOD_BROWSE	    0x0040	// ":browse" - invoke file dialog
640 #define CMOD_CONFIRM	    0x0080	// ":confirm" - invoke yes/no dialog
641 #define CMOD_KEEPALT	    0x0100	// ":keepalt"
642 #define CMOD_KEEPMARKS	    0x0200	// ":keepmarks"
643 #define CMOD_KEEPJUMPS	    0x0400	// ":keepjumps"
644 #define CMOD_LOCKMARKS	    0x0800	// ":lockmarks"
645 #define CMOD_KEEPPATTERNS   0x1000	// ":keeppatterns"
646 #define CMOD_NOSWAPFILE	    0x2000	// ":noswapfile"
647 #define CMOD_VIM9CMD	    0x4000	// ":vim9cmd"
648 
649     int		cmod_split;		// flags for win_split()
650     int		cmod_tab;		// > 0 when ":tab" was used
651     regmatch_T	cmod_filter_regmatch;	// set by :filter /pat/
652     int		cmod_filter_force;	// set for :filter!
653 
654     int		cmod_verbose;		// non-zero to set 'verbose'
655 
656     // values for undo_cmdmod()
657     char_u	*cmod_save_ei;		// saved value of 'eventignore'
658 #ifdef HAVE_SANDBOX
659     int		cmod_did_sandbox;	// set when "sandbox" was incremented
660 #endif
661     long	cmod_verbose_save;	// if 'verbose' was set: value of
662 					// p_verbose plus one
663     int		cmod_save_msg_silent;	// if non-zero: saved value of
664 					// msg_silent + 1
665     int		cmod_save_msg_scroll;	// for restoring msg_scroll
666     int		cmod_did_esilent;	// incremented when emsg_silent is
667 } cmdmod_T;
668 
669 #define MF_SEED_LEN	8
670 
671 struct memfile
672 {
673     char_u	*mf_fname;		// name of the file
674     char_u	*mf_ffname;		// idem, full path
675     int		mf_fd;			// file descriptor
676     int		mf_flags;		// flags used when opening this memfile
677     int		mf_reopen;		// mf_fd was closed, retry opening
678     bhdr_T	*mf_free_first;		// first block_hdr in free list
679     bhdr_T	*mf_used_first;		// mru block_hdr in used list
680     bhdr_T	*mf_used_last;		// lru block_hdr in used list
681     unsigned	mf_used_count;		// number of pages in used list
682     unsigned	mf_used_count_max;	// maximum number of pages in memory
683     mf_hashtab_T mf_hash;		// hash lists
684     mf_hashtab_T mf_trans;		// trans lists
685     blocknr_T	mf_blocknr_max;		// highest positive block number + 1
686     blocknr_T	mf_blocknr_min;		// lowest negative block number - 1
687     blocknr_T	mf_neg_count;		// number of negative blocks numbers
688     blocknr_T	mf_infile_count;	// number of pages in the file
689     unsigned	mf_page_size;		// number of bytes in a page
690     int		mf_dirty;		// TRUE if there are dirty blocks
691 #ifdef FEAT_CRYPT
692     buf_T	*mf_buffer;		// buffer this memfile is for
693     char_u	mf_seed[MF_SEED_LEN];	// seed for encryption
694 
695     // Values for key, method and seed used for reading data blocks when
696     // updating for a newly set key or method. Only when mf_old_key != NULL.
697     char_u	*mf_old_key;
698     int		mf_old_cm;
699     char_u	mf_old_seed[MF_SEED_LEN];
700 #endif
701 };
702 
703 /*
704  * things used in memline.c
705  */
706 /*
707  * When searching for a specific line, we remember what blocks in the tree
708  * are the branches leading to that block. This is stored in ml_stack.  Each
709  * entry is a pointer to info in a block (may be data block or pointer block)
710  */
711 typedef struct info_pointer
712 {
713     blocknr_T	ip_bnum;	// block number
714     linenr_T	ip_low;		// lowest lnum in this block
715     linenr_T	ip_high;	// highest lnum in this block
716     int		ip_index;	// index for block with current lnum
717 } infoptr_T;	// block/index pair
718 
719 #ifdef FEAT_BYTEOFF
720 typedef struct ml_chunksize
721 {
722     int		mlcs_numlines;
723     long	mlcs_totalsize;
724 } chunksize_T;
725 
726 /*
727  * Flags when calling ml_updatechunk()
728  */
729 # define ML_CHNK_ADDLINE 1
730 # define ML_CHNK_DELLINE 2
731 # define ML_CHNK_UPDLINE 3
732 #endif
733 
734 /*
735  * the memline structure holds all the information about a memline
736  */
737 typedef struct memline
738 {
739     linenr_T	ml_line_count;	// number of lines in the buffer
740 
741     memfile_T	*ml_mfp;	// pointer to associated memfile
742 
743     infoptr_T	*ml_stack;	// stack of pointer blocks (array of IPTRs)
744     int		ml_stack_top;	// current top of ml_stack
745     int		ml_stack_size;	// total number of entries in ml_stack
746 
747 #define ML_EMPTY	1	// empty buffer
748 #define ML_LINE_DIRTY	2	// cached line was changed and allocated
749 #define ML_LOCKED_DIRTY	4	// ml_locked was changed
750 #define ML_LOCKED_POS	8	// ml_locked needs positive block number
751     int		ml_flags;
752 
753     colnr_T	ml_line_len;	// length of the cached line, including NUL
754     linenr_T	ml_line_lnum;	// line number of cached line, 0 if not valid
755     char_u	*ml_line_ptr;	// pointer to cached line
756 
757     bhdr_T	*ml_locked;	// block used by last ml_get
758     linenr_T	ml_locked_low;	// first line in ml_locked
759     linenr_T	ml_locked_high;	// last line in ml_locked
760     int		ml_locked_lineadd;  // number of lines inserted in ml_locked
761 #ifdef FEAT_BYTEOFF
762     chunksize_T *ml_chunksize;
763     int		ml_numchunks;
764     int		ml_usedchunks;
765 #endif
766 } memline_T;
767 
768 // Values for the flags argument of ml_delete_flags().
769 #define ML_DEL_MESSAGE	    1	// may give a "No lines in buffer" message
770 #define ML_DEL_UNDO	    2	// called from undo, do not update textprops
771 
772 // Values for the flags argument of ml_append_int().
773 #define ML_APPEND_NEW	    1	// starting to edit a new file
774 #define ML_APPEND_MARK	    2	// mark the new line
775 #define ML_APPEND_UNDO	    4	// called from undo
776 
777 
778 /*
779  * Structure defining text properties.  These stick with the text.
780  * When stored in memline they are after the text, ml_line_len is larger than
781  * STRLEN(ml_line_ptr) + 1.
782  */
783 typedef struct textprop_S
784 {
785     colnr_T	tp_col;		// start column (one based, in bytes)
786     colnr_T	tp_len;		// length in bytes
787     int		tp_id;		// identifier
788     int		tp_type;	// property type
789     int		tp_flags;	// TP_FLAG_ values
790 } textprop_T;
791 
792 #define TP_FLAG_CONT_NEXT	1	// property continues in next line
793 #define TP_FLAG_CONT_PREV	2	// property was continued from prev line
794 
795 /*
796  * Structure defining a property type.
797  */
798 typedef struct proptype_S
799 {
800     int		pt_id;		// value used for tp_id
801     int		pt_type;	// number used for tp_type
802     int		pt_hl_id;	// highlighting
803     int		pt_priority;	// priority
804     int		pt_flags;	// PT_FLAG_ values
805     char_u	pt_name[1];	// property type name, actually longer
806 } proptype_T;
807 
808 #define PT_FLAG_INS_START_INCL	1	// insert at start included in property
809 #define PT_FLAG_INS_END_INCL	2	// insert at end included in property
810 #define PT_FLAG_COMBINE		4	// combine with syntax highlight
811 
812 // Sign group
813 typedef struct signgroup_S
814 {
815     int		sg_next_sign_id;	// next sign id for this group
816     short_u	sg_refcount;		// number of signs in this group
817     char_u	sg_name[1];		// sign group name, actually longer
818 } signgroup_T;
819 
820 typedef struct sign_entry sign_entry_T;
821 struct sign_entry
822 {
823     int		 se_id;		// unique identifier for each placed sign
824     int		 se_typenr;	// typenr of sign
825     int		 se_priority;	// priority for highlighting
826     linenr_T	 se_lnum;	// line number which has this sign
827     signgroup_T	 *se_group;	// sign group
828     sign_entry_T *se_next;	// next entry in a list of signs
829     sign_entry_T *se_prev;	// previous entry -- for easy reordering
830 };
831 
832 /*
833  * Sign attributes. Used by the screen refresh routines.
834  */
835 typedef struct sign_attrs_S {
836     int		sat_typenr;
837     void	*sat_icon;
838     char_u	*sat_text;
839     int		sat_texthl;
840     int		sat_linehl;
841     int		sat_priority;
842 } sign_attrs_T;
843 
844 #if defined(FEAT_SIGNS) || defined(PROTO)
845 // Macros to get the sign group structure from the group name
846 #define SGN_KEY_OFF	offsetof(signgroup_T, sg_name)
847 #define HI2SG(hi)	((signgroup_T *)((hi)->hi_key - SGN_KEY_OFF))
848 
849 // Default sign priority for highlighting
850 #define SIGN_DEF_PRIO	10
851 
852 #endif
853 
854 /*
855  * Argument list: Array of file names.
856  * Used for the global argument list and the argument lists local to a window.
857  */
858 typedef struct arglist
859 {
860     garray_T	al_ga;		// growarray with the array of file names
861     int		al_refcount;	// number of windows using this arglist
862     int		id;		// id of this arglist
863 } alist_T;
864 
865 /*
866  * For each argument remember the file name as it was given, and the buffer
867  * number that contains the expanded file name (required for when ":cd" is
868  * used).
869  */
870 typedef struct argentry
871 {
872     char_u	*ae_fname;	// file name as specified
873     int		ae_fnum;	// buffer number with expanded file name
874 } aentry_T;
875 
876 #define ALIST(win)	(win)->w_alist
877 #define GARGLIST	((aentry_T *)global_alist.al_ga.ga_data)
878 #define ARGLIST		((aentry_T *)ALIST(curwin)->al_ga.ga_data)
879 #define WARGLIST(wp)	((aentry_T *)ALIST(wp)->al_ga.ga_data)
880 #define AARGLIST(al)	((aentry_T *)((al)->al_ga.ga_data))
881 #define GARGCOUNT	(global_alist.al_ga.ga_len)
882 #define ARGCOUNT	(ALIST(curwin)->al_ga.ga_len)
883 #define WARGCOUNT(wp)	(ALIST(wp)->al_ga.ga_len)
884 
885 /*
886  * A list used for saving values of "emsg_silent".  Used by ex_try() to save the
887  * value of "emsg_silent" if it was non-zero.  When this is done, the CSF_SILENT
888  * flag below is set.
889  */
890 
891 typedef struct eslist_elem eslist_T;
892 struct eslist_elem
893 {
894     int		saved_emsg_silent;	// saved value of "emsg_silent"
895     eslist_T	*next;			// next element on the list
896 };
897 
898 /*
899  * For conditional commands a stack is kept of nested conditionals.
900  * When cs_idx < 0, there is no conditional command.
901  */
902 #define CSTACK_LEN	50
903 
904 typedef struct {
905     short	cs_flags[CSTACK_LEN];	// CSF_ flags
906     char	cs_pending[CSTACK_LEN];	// CSTP_: what's pending in ":finally"
907     union {
908 	void	*csp_rv[CSTACK_LEN];	// return typeval for pending return
909 	void	*csp_ex[CSTACK_LEN];	// exception for pending throw
910     }		cs_pend;
911     void	*cs_forinfo[CSTACK_LEN]; // info used by ":for"
912     int		cs_line[CSTACK_LEN];	// line nr of ":while"/":for" line
913     int		cs_block_id[CSTACK_LEN];    // block ID stack
914     int		cs_script_var_len[CSTACK_LEN];	// value of sn_var_vals.ga_len
915 						// when entering the block
916     int		cs_idx;			// current entry, or -1 if none
917     int		cs_looplevel;		// nr of nested ":while"s and ":for"s
918     int		cs_trylevel;		// nr of nested ":try"s
919     eslist_T	*cs_emsg_silent_list;	// saved values of "emsg_silent"
920     char	cs_lflags;		// loop flags: CSL_ flags
921 } cstack_T;
922 # define cs_rettv	cs_pend.csp_rv
923 # define cs_exception	cs_pend.csp_ex
924 
925 // There is no CSF_IF, the lack of CSF_WHILE, CSF_FOR and CSF_TRY means ":if"
926 // was used.
927 # define CSF_TRUE	0x0001	// condition was TRUE
928 # define CSF_ACTIVE	0x0002	// current state is active
929 # define CSF_ELSE	0x0004	// ":else" has been passed
930 # define CSF_WHILE	0x0008	// is a ":while"
931 # define CSF_FOR	0x0010	// is a ":for"
932 # define CSF_BLOCK	0x0020	// is a "{" block
933 
934 # define CSF_TRY	0x0100	// is a ":try"
935 # define CSF_FINALLY	0x0200	// ":finally" has been passed
936 # define CSF_THROWN	0x0400	// exception thrown to this try conditional
937 # define CSF_CAUGHT	0x0800  // exception caught by this try conditional
938 # define CSF_SILENT	0x1000	// "emsg_silent" reset by ":try"
939 // Note that CSF_ELSE is only used when CSF_TRY and CSF_WHILE are unset
940 // (an ":if"), and CSF_SILENT is only used when CSF_TRY is set.
941 //
942 #define CSF_FUNC_DEF	0x2000	// a function was defined in this block
943 
944 /*
945  * What's pending for being reactivated at the ":endtry" of this try
946  * conditional:
947  */
948 # define CSTP_NONE	0	// nothing pending in ":finally" clause
949 # define CSTP_ERROR	1	// an error is pending
950 # define CSTP_INTERRUPT	2	// an interrupt is pending
951 # define CSTP_THROW	4	// a throw is pending
952 # define CSTP_BREAK	8	// ":break" is pending
953 # define CSTP_CONTINUE	16	// ":continue" is pending
954 # define CSTP_RETURN	24	// ":return" is pending
955 # define CSTP_FINISH	32	// ":finish" is pending
956 
957 /*
958  * Flags for the cs_lflags item in cstack_T.
959  */
960 # define CSL_HAD_LOOP	 1	// just found ":while" or ":for"
961 # define CSL_HAD_ENDLOOP 2	// just found ":endwhile" or ":endfor"
962 # define CSL_HAD_CONT	 4	// just found ":continue"
963 # define CSL_HAD_FINA	 8	// just found ":finally"
964 
965 /*
966  * A list of error messages that can be converted to an exception.  "throw_msg"
967  * is only set in the first element of the list.  Usually, it points to the
968  * original message stored in that element, but sometimes it points to a later
969  * message in the list.  See cause_errthrow().
970  */
971 typedef struct msglist msglist_T;
972 struct msglist
973 {
974     msglist_T	*next;		// next of several messages in a row
975     char	*msg;		// original message, allocated
976     char	*throw_msg;	// msg to throw: usually original one
977     char_u	*sfile;		// value from estack_sfile(), allocated
978     long	slnum;		// line number for "sfile"
979     int		msg_compiling;	// saved value of estack_compiling
980 };
981 
982 /*
983  * The exception types.
984  */
985 typedef enum
986 {
987     ET_USER,		// exception caused by ":throw" command
988     ET_ERROR,		// error exception
989     ET_INTERRUPT,	// interrupt exception triggered by Ctrl-C
990 } except_type_T;
991 
992 /*
993  * Structure describing an exception.
994  * (don't use "struct exception", it's used by the math library).
995  */
996 typedef struct vim_exception except_T;
997 struct vim_exception
998 {
999     except_type_T	type;		// exception type
1000     char		*value;		// exception value
1001     struct msglist	*messages;	// message(s) causing error exception
1002     char_u		*throw_name;	// name of the throw point
1003     linenr_T		throw_lnum;	// line number of the throw point
1004     except_T		*caught;	// next exception on the caught stack
1005 };
1006 
1007 /*
1008  * Structure to save the error/interrupt/exception state between calls to
1009  * enter_cleanup() and leave_cleanup().  Must be allocated as an automatic
1010  * variable by the (common) caller of these functions.
1011  */
1012 typedef struct cleanup_stuff cleanup_T;
1013 struct cleanup_stuff
1014 {
1015     int pending;		// error/interrupt/exception state
1016     except_T *exception;	// exception value
1017 };
1018 
1019 #ifdef FEAT_SYN_HL
1020 // struct passed to in_id_list()
1021 struct sp_syn
1022 {
1023     int		inc_tag;	// ":syn include" unique tag
1024     short	id;		// highlight group ID of item
1025     short	*cont_in_list;	// cont.in group IDs, if non-zero
1026 };
1027 
1028 /*
1029  * Each keyword has one keyentry, which is linked in a hash list.
1030  */
1031 typedef struct keyentry keyentry_T;
1032 
1033 struct keyentry
1034 {
1035     keyentry_T	*ke_next;	// next entry with identical "keyword[]"
1036     struct sp_syn k_syn;	// struct passed to in_id_list()
1037     short	*next_list;	// ID list for next match (if non-zero)
1038     int		flags;
1039     int		k_char;		// conceal substitute character
1040     char_u	keyword[1];	// actually longer
1041 };
1042 
1043 /*
1044  * Struct used to store one state of the state stack.
1045  */
1046 typedef struct buf_state
1047 {
1048     int		    bs_idx;	 // index of pattern
1049     int		    bs_flags;	 // flags for pattern
1050 #ifdef FEAT_CONCEAL
1051     int		    bs_seqnr;	 // stores si_seqnr
1052     int		    bs_cchar;	 // stores si_cchar
1053 #endif
1054     reg_extmatch_T *bs_extmatch; // external matches from start pattern
1055 } bufstate_T;
1056 
1057 /*
1058  * syn_state contains the syntax state stack for the start of one line.
1059  * Used by b_sst_array[].
1060  */
1061 typedef struct syn_state synstate_T;
1062 
1063 struct syn_state
1064 {
1065     synstate_T	*sst_next;	// next entry in used or free list
1066     linenr_T	sst_lnum;	// line number for this state
1067     union
1068     {
1069 	bufstate_T	sst_stack[SST_FIX_STATES]; // short state stack
1070 	garray_T	sst_ga;	// growarray for long state stack
1071     } sst_union;
1072     int		sst_next_flags;	// flags for sst_next_list
1073     int		sst_stacksize;	// number of states on the stack
1074     short	*sst_next_list;	// "nextgroup" list in this state
1075 				// (this is a copy, don't free it!
1076     disptick_T	sst_tick;	// tick when last displayed
1077     linenr_T	sst_change_lnum;// when non-zero, change in this line
1078 				// may have made the state invalid
1079 };
1080 #endif // FEAT_SYN_HL
1081 
1082 #define MAX_HL_ID       20000	// maximum value for a highlight ID.
1083 
1084 /*
1085  * Structure shared between syntax.c, screen.c and gui_x11.c.
1086  */
1087 typedef struct attr_entry
1088 {
1089     short	    ae_attr;		// HL_BOLD, etc.
1090     union
1091     {
1092 	struct
1093 	{
1094 	    char_u	    *start;	// start escape sequence
1095 	    char_u	    *stop;	// stop escape sequence
1096 	} term;
1097 	struct
1098 	{
1099 	    // These colors need to be > 8 bits to hold 256.
1100 	    short_u	    fg_color;	// foreground color number
1101 	    short_u	    bg_color;	// background color number
1102 	    short_u	    ul_color;	// underline color number
1103 # ifdef FEAT_TERMGUICOLORS
1104 	    guicolor_T	    fg_rgb;	// foreground color RGB
1105 	    guicolor_T	    bg_rgb;	// background color RGB
1106 	    guicolor_T	    ul_rgb;	// underline color RGB
1107 # endif
1108 	} cterm;
1109 # ifdef FEAT_GUI
1110 	struct
1111 	{
1112 	    guicolor_T	    fg_color;	// foreground color handle
1113 	    guicolor_T	    bg_color;	// background color handle
1114 	    guicolor_T	    sp_color;	// special color handle
1115 	    GuiFont	    font;	// font handle
1116 #  ifdef FEAT_XFONTSET
1117 	    GuiFontset	    fontset;	// fontset handle
1118 #  endif
1119 	} gui;
1120 # endif
1121     } ae_u;
1122 } attrentry_T;
1123 
1124 #ifdef USE_ICONV
1125 # ifdef HAVE_ICONV_H
1126 #  include <iconv.h>
1127 # else
1128 #  if defined(MACOS_X)
1129 #   include <sys/errno.h>
1130 #   ifndef EILSEQ
1131 #    define EILSEQ ENOENT // Early MacOS X does not have EILSEQ
1132 #   endif
1133 typedef struct _iconv_t *iconv_t;
1134 #  else
1135 #   include <errno.h>
1136 #  endif
1137 typedef void *iconv_t;
1138 # endif
1139 #endif
1140 
1141 /*
1142  * Used for the typeahead buffer: typebuf.
1143  */
1144 typedef struct
1145 {
1146     char_u	*tb_buf;	// buffer for typed characters
1147     char_u	*tb_noremap;	// mapping flags for characters in tb_buf[]
1148     int		tb_buflen;	// size of tb_buf[]
1149     int		tb_off;		// current position in tb_buf[]
1150     int		tb_len;		// number of valid bytes in tb_buf[]
1151     int		tb_maplen;	// nr of mapped bytes in tb_buf[]
1152     int		tb_silent;	// nr of silently mapped bytes in tb_buf[]
1153     int		tb_no_abbr_cnt; // nr of bytes without abbrev. in tb_buf[]
1154     int		tb_change_cnt;	// nr of time tb_buf was changed; never zero
1155 } typebuf_T;
1156 
1157 // Struct to hold the saved typeahead for save_typeahead().
1158 typedef struct
1159 {
1160     typebuf_T		save_typebuf;
1161     int			typebuf_valid;	    // TRUE when save_typebuf valid
1162     int			old_char;
1163     int			old_mod_mask;
1164     buffheader_T	save_readbuf1;
1165     buffheader_T	save_readbuf2;
1166 #ifdef USE_INPUT_BUF
1167     char_u		*save_inputbuf;
1168 #endif
1169 } tasave_T;
1170 
1171 /*
1172  * Used for conversion of terminal I/O and script files.
1173  */
1174 typedef struct
1175 {
1176     int		vc_type;	// zero or one of the CONV_ values
1177     int		vc_factor;	// max. expansion factor
1178 # ifdef MSWIN
1179     int		vc_cpfrom;	// codepage to convert from (CONV_CODEPAGE)
1180     int		vc_cpto;	// codepage to convert to (CONV_CODEPAGE)
1181 # endif
1182 # ifdef USE_ICONV
1183     iconv_t	vc_fd;		// for CONV_ICONV
1184 # endif
1185     int		vc_fail;	// fail for invalid char, don't use '?'
1186 } vimconv_T;
1187 
1188 /*
1189  * Structure used for the command line history.
1190  */
1191 typedef struct hist_entry
1192 {
1193     int		hisnum;		// identifying number
1194     int		viminfo;	// when TRUE hisstr comes from viminfo
1195     char_u	*hisstr;	// actual entry, separator char after the NUL
1196     time_t	time_set;	// when it was typed, zero if unknown
1197 } histentry_T;
1198 
1199 #define CONV_NONE		0
1200 #define CONV_TO_UTF8		1
1201 #define CONV_9_TO_UTF8		2
1202 #define CONV_TO_LATIN1		3
1203 #define CONV_TO_LATIN9		4
1204 #define CONV_ICONV		5
1205 #ifdef MSWIN
1206 # define CONV_CODEPAGE		10	// codepage -> codepage
1207 #endif
1208 #ifdef MACOS_X
1209 # define CONV_MAC_LATIN1	20
1210 # define CONV_LATIN1_MAC	21
1211 # define CONV_MAC_UTF8		22
1212 # define CONV_UTF8_MAC		23
1213 #endif
1214 
1215 /*
1216  * Structure used for mappings and abbreviations.
1217  */
1218 typedef struct mapblock mapblock_T;
1219 struct mapblock
1220 {
1221     mapblock_T	*m_next;	// next mapblock in list
1222     char_u	*m_keys;	// mapped from, lhs
1223     char_u	*m_str;		// mapped to, rhs
1224     char_u	*m_orig_str;	// rhs as entered by the user
1225     int		m_keylen;	// strlen(m_keys)
1226     int		m_mode;		// valid mode
1227     int		m_simplified;	// m_keys was simplified, do not use this map
1228 				// if seenModifyOtherKeys is TRUE
1229     int		m_noremap;	// if non-zero no re-mapping for m_str
1230     char	m_silent;	// <silent> used, don't echo commands
1231     char	m_nowait;	// <nowait> used
1232 #ifdef FEAT_EVAL
1233     sctx_T	m_script_ctx;	// SCTX where map was defined
1234     char	m_expr;		// <expr> used, m_str is an expression
1235 #endif
1236 };
1237 
1238 
1239 /*
1240  * Used for highlighting in the status line.
1241  */
1242 typedef struct
1243 {
1244     char_u	*start;
1245     int		userhl;		// 0: no HL, 1-9: User HL, < 0 for syn ID
1246 } stl_hlrec_T;
1247 
1248 
1249 /*
1250  * Syntax items - usually buffer-specific.
1251  */
1252 
1253 /*
1254  * Item for a hashtable.  "hi_key" can be one of three values:
1255  * NULL:	   Never been used
1256  * HI_KEY_REMOVED: Entry was removed
1257  * Otherwise:	   Used item, pointer to the actual key; this usually is
1258  *		   inside the item, subtract an offset to locate the item.
1259  *		   This reduces the size of hashitem by 1/3.
1260  */
1261 typedef struct hashitem_S
1262 {
1263     long_u	hi_hash;	// cached hash number of hi_key
1264     char_u	*hi_key;
1265 } hashitem_T;
1266 
1267 // The address of "hash_removed" is used as a magic number for hi_key to
1268 // indicate a removed item.
1269 #define HI_KEY_REMOVED &hash_removed
1270 #define HASHITEM_EMPTY(hi) ((hi)->hi_key == NULL || (hi)->hi_key == &hash_removed)
1271 
1272 // Initial size for a hashtable.  Our items are relatively small and growing
1273 // is expensive, thus use 16 as a start.  Must be a power of 2.
1274 // This allows for storing 10 items (2/3 of 16) before a resize is needed.
1275 #define HT_INIT_SIZE 16
1276 
1277 typedef struct hashtable_S
1278 {
1279     long_u	ht_mask;	// mask used for hash value (nr of items in
1280 				// array is "ht_mask" + 1)
1281     long_u	ht_used;	// number of items used
1282     long_u	ht_filled;	// number of items used + removed
1283     int		ht_changed;	// incremented when adding or removing an item
1284     int		ht_locked;	// counter for hash_lock()
1285     int		ht_error;	// when set growing failed, can't add more
1286 				// items before growing works
1287     hashitem_T	*ht_array;	// points to the array, allocated when it's
1288 				// not "ht_smallarray"
1289     hashitem_T	ht_smallarray[HT_INIT_SIZE];   // initial array
1290 } hashtab_T;
1291 
1292 typedef long_u hash_T;		// Type for hi_hash
1293 
1294 
1295 // Use 64-bit Number.
1296 #ifdef MSWIN
1297 # ifdef PROTO
1298    // workaround for cproto that doesn't recognize __int64
1299    typedef long			varnumber_T;
1300    typedef unsigned long	uvarnumber_T;
1301 #  define VARNUM_MIN		LONG_MIN
1302 #  define VARNUM_MAX		LONG_MAX
1303 #  define UVARNUM_MAX		ULONG_MAX
1304 # else
1305    typedef __int64		varnumber_T;
1306    typedef unsigned __int64	uvarnumber_T;
1307 #  define VARNUM_MIN		_I64_MIN
1308 #  define VARNUM_MAX		_I64_MAX
1309 #  define UVARNUM_MAX		_UI64_MAX
1310 # endif
1311 #elif defined(HAVE_NO_LONG_LONG)
1312 # if defined(HAVE_STDINT_H)
1313    typedef int64_t		varnumber_T;
1314    typedef uint64_t		uvarnumber_T;
1315 #  define VARNUM_MIN		INT64_MIN
1316 #  define VARNUM_MAX		INT64_MAX
1317 #  define UVARNUM_MAX		UINT64_MAX
1318 # else
1319    // this may cause trouble for code that depends on 64 bit ints
1320    typedef long			varnumber_T;
1321    typedef unsigned long	uvarnumber_T;
1322 #  define VARNUM_MIN		LONG_MIN
1323 #  define VARNUM_MAX		LONG_MAX
1324 #  define UVARNUM_MAX		ULONG_MAX
1325 # endif
1326 #else
1327   typedef long long		varnumber_T;
1328   typedef unsigned long long	uvarnumber_T;
1329 # ifdef LLONG_MIN
1330 #  define VARNUM_MIN		LLONG_MIN
1331 #  define VARNUM_MAX		LLONG_MAX
1332 #  define UVARNUM_MAX		ULLONG_MAX
1333 # else
1334 #  define VARNUM_MIN		LONG_LONG_MIN
1335 #  define VARNUM_MAX		LONG_LONG_MAX
1336 #  define UVARNUM_MAX		ULONG_LONG_MAX
1337 # endif
1338 #endif
1339 
1340 // On rare systems "char" is unsigned, sometimes we really want a signed 8-bit
1341 // value.
1342 typedef signed char int8_T;
1343 
1344 typedef double	float_T;
1345 
1346 typedef struct listvar_S list_T;
1347 typedef struct dictvar_S dict_T;
1348 typedef struct partial_S partial_T;
1349 typedef struct blobvar_S blob_T;
1350 
1351 // Struct that holds both a normal function name and a partial_T, as used for a
1352 // callback argument.
1353 // When used temporarily "cb_name" is not allocated.  The refcounts to either
1354 // the function or the partial are incremented and need to be decremented
1355 // later with free_callback().
1356 typedef struct {
1357     char_u	*cb_name;
1358     partial_T	*cb_partial;
1359     int		cb_free_name;	    // cb_name was allocated
1360 } callback_T;
1361 
1362 typedef struct isn_S isn_T;	    // instruction
1363 typedef struct dfunc_S dfunc_T;	    // :def function
1364 
1365 typedef struct jobvar_S job_T;
1366 typedef struct readq_S readq_T;
1367 typedef struct writeq_S writeq_T;
1368 typedef struct jsonq_S jsonq_T;
1369 typedef struct cbq_S cbq_T;
1370 typedef struct channel_S channel_T;
1371 typedef struct cctx_S cctx_T;
1372 typedef struct ectx_S ectx_T;
1373 
1374 typedef enum
1375 {
1376     VAR_UNKNOWN = 0,	// not set, any type or "void" allowed
1377     VAR_ANY,		// used for "any" type
1378     VAR_VOID,		// no value (function not returning anything)
1379     VAR_BOOL,		// "v_number" is used: VVAL_TRUE or VVAL_FALSE
1380     VAR_SPECIAL,	// "v_number" is used: VVAL_NULL or VVAL_NONE
1381     VAR_NUMBER,		// "v_number" is used
1382     VAR_FLOAT,		// "v_float" is used
1383     VAR_STRING,		// "v_string" is used
1384     VAR_BLOB,		// "v_blob" is used
1385     VAR_FUNC,		// "v_string" is function name
1386     VAR_PARTIAL,	// "v_partial" is used
1387     VAR_LIST,		// "v_list" is used
1388     VAR_DICT,		// "v_dict" is used
1389     VAR_JOB,		// "v_job" is used
1390     VAR_CHANNEL,	// "v_channel" is used
1391 } vartype_T;
1392 
1393 // A type specification.
1394 typedef struct type_S type_T;
1395 struct type_S {
1396     vartype_T	    tt_type;
1397     int8_T	    tt_argcount;    // for func, incl. vararg, -1 for unknown
1398     char	    tt_min_argcount; // number of non-optional arguments
1399     char	    tt_flags;	    // TTFLAG_ values
1400     type_T	    *tt_member;	    // for list, dict, func return type
1401     type_T	    **tt_args;	    // func argument types, allocated
1402 };
1403 
1404 #define TTFLAG_VARARGS	1	    // func args ends with "..."
1405 #define TTFLAG_OPTARG	2	    // func arg type with "?"
1406 #define TTFLAG_BOOL_OK	4	    // can be converted to bool
1407 #define TTFLAG_STATIC	8	    // one of the static types, e.g. t_any
1408 
1409 /*
1410  * Structure to hold an internal variable without a name.
1411  */
1412 typedef struct
1413 {
1414     vartype_T	v_type;
1415     char	v_lock;	    // see below: VAR_LOCKED, VAR_FIXED
1416     union
1417     {
1418 	varnumber_T	v_number;	// number value
1419 #ifdef FEAT_FLOAT
1420 	float_T		v_float;	// floating number value
1421 #endif
1422 	char_u		*v_string;	// string value (can be NULL!)
1423 	list_T		*v_list;	// list value (can be NULL!)
1424 	dict_T		*v_dict;	// dict value (can be NULL!)
1425 	partial_T	*v_partial;	// closure: function with args
1426 #ifdef FEAT_JOB_CHANNEL
1427 	job_T		*v_job;		// job value (can be NULL!)
1428 	channel_T	*v_channel;	// channel value (can be NULL!)
1429 #endif
1430 	blob_T		*v_blob;	// blob value (can be NULL!)
1431     }		vval;
1432 } typval_T;
1433 
1434 // Values for "dv_scope".
1435 #define VAR_SCOPE     1	// a:, v:, s:, etc. scope dictionaries
1436 #define VAR_DEF_SCOPE 2	// l:, g: scope dictionaries: here funcrefs are not
1437 			// allowed to mask existing functions
1438 
1439 // Values for "v_lock".
1440 #define VAR_LOCKED	1	// locked with lock(), can use unlock()
1441 #define VAR_FIXED	2	// locked forever
1442 
1443 /*
1444  * Structure to hold an item of a list: an internal variable without a name.
1445  */
1446 typedef struct listitem_S listitem_T;
1447 
1448 struct listitem_S
1449 {
1450     listitem_T	*li_next;	// next item in list
1451     listitem_T	*li_prev;	// previous item in list
1452     typval_T	li_tv;		// type and value of the variable
1453 };
1454 
1455 // Struct used by those that are using an item in a list.
1456 typedef struct listwatch_S listwatch_T;
1457 
1458 struct listwatch_S
1459 {
1460     listitem_T		*lw_item;	// item being watched
1461     listwatch_T		*lw_next;	// next watcher
1462 };
1463 
1464 /*
1465  * Structure to hold info about a list.
1466  * Order of members is optimized to reduce padding.
1467  * When created by range() it will at first have special value:
1468  *  lv_first == &range_list_item;
1469  * and use lv_start, lv_end, lv_stride.
1470  */
1471 struct listvar_S
1472 {
1473     listitem_T	*lv_first;	// first item, NULL if none
1474     listwatch_T	*lv_watch;	// first watcher, NULL if none
1475     union {
1476 	struct {	// used for non-materialized range list:
1477 			// "lv_first" is &range_list_item
1478 	    varnumber_T lv_start;
1479 	    varnumber_T lv_end;
1480 	    int		lv_stride;
1481 	} nonmat;
1482 	struct {	// used for materialized list
1483 	    listitem_T	*lv_last;	// last item, NULL if none
1484 	    listitem_T	*lv_idx_item;	// when not NULL item at index "lv_idx"
1485 	    int		lv_idx;		// cached index of an item
1486 	} mat;
1487     } lv_u;
1488     type_T	*lv_type;	// allocated by alloc_type()
1489     list_T	*lv_copylist;	// copied list used by deepcopy()
1490     list_T	*lv_used_next;	// next list in used lists list
1491     list_T	*lv_used_prev;	// previous list in used lists list
1492     int		lv_refcount;	// reference count
1493     int		lv_len;		// number of items
1494     int		lv_with_items;	// number of items following this struct that
1495 				// should not be freed
1496     int		lv_copyID;	// ID used by deepcopy()
1497     char	lv_lock;	// zero, VAR_LOCKED, VAR_FIXED
1498 };
1499 
1500 /*
1501  * Static list with 10 items.  Use init_static_list() to initialize.
1502  */
1503 typedef struct {
1504     list_T	sl_list;	// must be first
1505     listitem_T	sl_items[10];
1506 } staticList10_T;
1507 
1508 /*
1509  * Structure to hold an item of a Dictionary.
1510  * Also used for a variable.
1511  * The key is copied into "di_key" to avoid an extra alloc/free for it.
1512  */
1513 struct dictitem_S
1514 {
1515     typval_T	di_tv;		// type and value of the variable
1516     char_u	di_flags;	// DI_FLAGS_ flags (only used for variable)
1517     char_u	di_key[1];	// key (actually longer!)
1518 };
1519 typedef struct dictitem_S dictitem_T;
1520 
1521 /*
1522  * A dictitem with a 16 character key (plus NUL).  This is an efficient way to
1523  * have a fixed-size dictitem.
1524  */
1525 #define DICTITEM16_KEY_LEN 16
1526 struct dictitem16_S
1527 {
1528     typval_T	di_tv;		// type and value of the variable
1529     char_u	di_flags;	// DI_FLAGS_ flags (only used for variable)
1530     char_u	di_key[DICTITEM16_KEY_LEN + 1];	// key
1531 };
1532 typedef struct dictitem16_S dictitem16_T;
1533 
1534 // Flags for "di_flags"
1535 #define DI_FLAGS_RO	   0x01	    // read-only variable
1536 #define DI_FLAGS_RO_SBX	   0x02	    // read-only in the sandbox
1537 #define DI_FLAGS_FIX	   0x04	    // fixed: no :unlet or remove()
1538 #define DI_FLAGS_LOCK	   0x08	    // locked variable
1539 #define DI_FLAGS_ALLOC	   0x10	    // separately allocated
1540 #define DI_FLAGS_RELOAD	   0x20	    // set when script sourced again
1541 
1542 /*
1543  * Structure to hold info about a Dictionary.
1544  */
1545 struct dictvar_S
1546 {
1547     char	dv_lock;	// zero, VAR_LOCKED, VAR_FIXED
1548     char	dv_scope;	// zero, VAR_SCOPE, VAR_DEF_SCOPE
1549     int		dv_refcount;	// reference count
1550     int		dv_copyID;	// ID used by deepcopy()
1551     hashtab_T	dv_hashtab;	// hashtab that refers to the items
1552     type_T	*dv_type;	// allocated by alloc_type()
1553     dict_T	*dv_copydict;	// copied dict used by deepcopy()
1554     dict_T	*dv_used_next;	// next dict in used dicts list
1555     dict_T	*dv_used_prev;	// previous dict in used dicts list
1556 };
1557 
1558 /*
1559  * Structure to hold info about a blob.
1560  */
1561 struct blobvar_S
1562 {
1563     garray_T	bv_ga;		// growarray with the data
1564     int		bv_refcount;	// reference count
1565     char	bv_lock;	// zero, VAR_LOCKED, VAR_FIXED
1566 };
1567 
1568 typedef int (*cfunc_T)(int argcount, typval_T *argvars, typval_T *rettv, void *state);
1569 typedef void (*cfunc_free_T)(void *state);
1570 
1571 // type of getline() last argument
1572 typedef enum {
1573     GETLINE_NONE,	    // do not concatenate any lines
1574     GETLINE_CONCAT_CONT,    // concatenate continuation lines with backslash
1575     GETLINE_CONCAT_CONTBAR, // concatenate continuation lines with \ and |
1576     GETLINE_CONCAT_ALL	    // concatenate continuation and Vim9 # comment lines
1577 } getline_opt_T;
1578 
1579 typedef struct svar_S svar_T;
1580 
1581 #if defined(FEAT_EVAL) || defined(PROTO)
1582 typedef struct funccall_S funccall_T;
1583 
1584 // values used for "uf_def_status"
1585 typedef enum {
1586     UF_NOT_COMPILED,
1587     UF_TO_BE_COMPILED,
1588     UF_COMPILING,
1589     UF_COMPILED
1590 } def_status_T;
1591 
1592 /*
1593  * Structure to hold info for a user function.
1594  * When adding a field check copy_func().
1595  */
1596 typedef struct
1597 {
1598     int		uf_varargs;	// variable nr of arguments (old style)
1599     int		uf_flags;	// FC_ flags
1600     int		uf_calls;	// nr of active calls
1601     int		uf_cleared;	// func_clear() was already called
1602     def_status_T uf_def_status; // UF_NOT_COMPILED, UF_TO_BE_COMPILED, etc.
1603     int		uf_dfunc_idx;	// only valid if uf_def_status is UF_COMPILED
1604     garray_T	uf_args;	// arguments, including optional arguments
1605     garray_T	uf_def_args;	// default argument expressions
1606 
1607     // for :def (for :function uf_ret_type is NULL)
1608     type_T	**uf_arg_types;	// argument types (count == uf_args.ga_len)
1609     type_T	*uf_ret_type;	// return type
1610     garray_T	uf_type_list;	// types used in arg and return types
1611     partial_T	*uf_partial;	// for closure created inside :def function:
1612 				// information about the context
1613 
1614     char_u	*uf_va_name;	// name from "...name" or NULL
1615     type_T	*uf_va_type;	// type from "...name: type" or NULL
1616     type_T	*uf_func_type;	// type of the function, &t_func_any if unknown
1617     int		uf_block_depth;	// nr of entries in uf_block_ids
1618     int		*uf_block_ids;	// blocks a :def function is defined inside
1619 # if defined(FEAT_LUA)
1620     cfunc_T     uf_cb;		// callback function for cfunc
1621     cfunc_free_T uf_cb_free;    // callback function to free cfunc
1622     void        *uf_cb_state;   // state of uf_cb
1623 # endif
1624 
1625     garray_T	uf_lines;	// function lines
1626 # ifdef FEAT_PROFILE
1627     int		uf_profiling;	// TRUE when func is being profiled
1628     int		uf_prof_initialized;
1629     // profiling the function as a whole
1630     int		uf_tm_count;	// nr of calls
1631     proftime_T	uf_tm_total;	// time spent in function + children
1632     proftime_T	uf_tm_self;	// time spent in function itself
1633     proftime_T	uf_tm_children;	// time spent in children this call
1634     // profiling the function per line
1635     int		*uf_tml_count;	// nr of times line was executed
1636     proftime_T	*uf_tml_total;	// time spent in a line + children
1637     proftime_T	*uf_tml_self;	// time spent in a line itself
1638     proftime_T	uf_tml_start;	// start time for current line
1639     proftime_T	uf_tml_children; // time spent in children for this line
1640     proftime_T	uf_tml_wait;	// start wait time for current line
1641     int		uf_tml_idx;	// index of line being timed; -1 if none
1642     int		uf_tml_execed;	// line being timed was executed
1643 # endif
1644     sctx_T	uf_script_ctx;	// SCTX where function was defined,
1645 				// used for s: variables; sc_version changed
1646 				// for :function
1647     int		uf_script_ctx_version;  // original sc_version of SCTX
1648     int		uf_refcount;	// reference count, see func_name_refcount()
1649 
1650     funccall_T	*uf_scoped;	// l: local variables for closure
1651 
1652     char_u	*uf_name_exp;	// if "uf_name[]" starts with SNR the name with
1653 				// "<SNR>" as a string, otherwise NULL
1654     char_u	uf_name[4];	// name of function (actual size equals name);
1655 				// can start with <SNR>123_ (<SNR> is K_SPECIAL
1656 				// KS_EXTRA KE_SNR)
1657 } ufunc_T;
1658 
1659 // flags used in uf_flags
1660 #define FC_ABORT    0x01	// abort function on error
1661 #define FC_RANGE    0x02	// function accepts range
1662 #define FC_DICT	    0x04	// Dict function, uses "self"
1663 #define FC_CLOSURE  0x08	// closure, uses outer scope variables
1664 #define FC_DELETED  0x10	// :delfunction used while uf_refcount > 0
1665 #define FC_REMOVED  0x20	// function redefined while uf_refcount > 0
1666 #define FC_SANDBOX  0x40	// function defined in the sandbox
1667 #define FC_DEAD	    0x80	// function kept only for reference to dfunc
1668 #define FC_EXPORT   0x100	// "export def Func()"
1669 #define FC_NOARGS   0x200	// no a: variables in lambda
1670 #define FC_VIM9	    0x400	// defined in vim9 script file
1671 #define FC_CFUNC    0x800	// defined as Lua C func
1672 #define FC_COPY	    0x1000	// copy of another function by copy_func()
1673 
1674 #define MAX_FUNC_ARGS	20	// maximum number of function arguments
1675 #define VAR_SHORT_LEN	20	// short variable name length
1676 #define FIXVAR_CNT	12	// number of fixed variables
1677 
1678 /*
1679  * Structure to hold info for a function that is currently being executed.
1680  */
1681 struct funccall_S
1682 {
1683     ufunc_T	*func;		// function being called
1684     int		linenr;		// next line to be executed
1685     int		returned;	// ":return" used
1686     struct			// fixed variables for arguments
1687     {
1688 	dictitem_T	var;		// variable (without room for name)
1689 	char_u	room[VAR_SHORT_LEN];	// room for the name
1690     } fixvar[FIXVAR_CNT];
1691     dict_T	l_vars;		// l: local function variables
1692     dictitem_T	l_vars_var;	// variable for l: scope
1693     dict_T	l_avars;	// a: argument variables
1694     dictitem_T	l_avars_var;	// variable for a: scope
1695     list_T	l_varlist;	// list for a:000
1696     listitem_T	l_listitems[MAX_FUNC_ARGS];	// listitems for a:000
1697     typval_T	*rettv;		// return value
1698     linenr_T	breakpoint;	// next line with breakpoint or zero
1699     int		dbg_tick;	// debug_tick when breakpoint was set
1700     int		level;		// top nesting level of executed function
1701 #ifdef FEAT_PROFILE
1702     proftime_T	prof_child;	// time spent in a child
1703 #endif
1704     funccall_T	*caller;	// calling function or NULL; or next funccal in
1705 				// list pointed to by previous_funccal.
1706 
1707     // for closure
1708     int		fc_refcount;	// number of user functions that reference this
1709 				// funccal
1710     int		fc_copyID;	// for garbage collection
1711     garray_T	fc_funcs;	// list of ufunc_T* which keep a reference to
1712 				// "func"
1713 };
1714 
1715 /*
1716  * Struct used by trans_function_name()
1717  */
1718 typedef struct
1719 {
1720     dict_T	*fd_dict;	// Dictionary used
1721     char_u	*fd_newkey;	// new key in "dict" in allocated memory
1722     dictitem_T	*fd_di;		// Dictionary item used
1723 } funcdict_T;
1724 
1725 typedef struct funccal_entry funccal_entry_T;
1726 struct funccal_entry {
1727     void	    *top_funccal;
1728     funccal_entry_T *next;
1729 };
1730 
1731 // From user function to hashitem and back.
1732 #define UF2HIKEY(fp) ((fp)->uf_name)
1733 #define HIKEY2UF(p)  ((ufunc_T *)((p) - offsetof(ufunc_T, uf_name)))
1734 #define HI2UF(hi)     HIKEY2UF((hi)->hi_key)
1735 
1736 /*
1737  * Holds the hashtab with variables local to each sourced script.
1738  * Each item holds a variable (nameless) that points to the dict_T.
1739  */
1740 typedef struct {
1741     dictitem_T	sv_var;
1742     dict_T	sv_dict;
1743 } scriptvar_T;
1744 
1745 /*
1746  * Entry for "sn_all_vars".  Contains the s: variables from sn_vars plus the
1747  * block-local ones.
1748  */
1749 typedef struct sallvar_S sallvar_T;
1750 struct sallvar_S {
1751     sallvar_T	*sav_next;	  // var with same name but different block
1752     int		sav_block_id;	  // block ID where declared
1753     int		sav_var_vals_idx; // index in sn_var_vals
1754 
1755     // So long as the variable is valid (block it was defined in is still
1756     // active) "sav_di" is used.  It is set to NULL when leaving the block,
1757     // then sav_tv and sav_flags are used.
1758     dictitem_T *sav_di;		// dictitem with di_key and di_tv
1759     typval_T	sav_tv;		// type and value of the variable
1760     char_u	sav_flags;	// DI_FLAGS_ flags (only used for variable)
1761     char_u	sav_key[1];	// key (actually longer!)
1762 };
1763 
1764 /*
1765  * In the sn_all_vars hashtab item "hi_key" points to "sav_key" in a sallvar_T.
1766  * This makes it possible to store and find the sallvar_T.
1767  * SAV2HIKEY() converts a sallvar_T pointer to a hashitem key pointer.
1768  * HIKEY2SAV() converts a hashitem key pointer to a sallvar_T pointer.
1769  * HI2SAV() converts a hashitem pointer to a sallvar_T pointer.
1770  */
1771 #define SAV2HIKEY(sav) ((sav)->sav_key)
1772 #define HIKEY2SAV(p)  ((sallvar_T *)(p - offsetof(sallvar_T, sav_key)))
1773 #define HI2SAV(hi)     HIKEY2SAV((hi)->hi_key)
1774 
1775 /*
1776  * Entry for "sn_var_vals".  Used for script-local variables.
1777  */
1778 struct svar_S {
1779     char_u	*sv_name;	// points into "sn_all_vars" di_key
1780     typval_T	*sv_tv;		// points into "sn_vars" or "sn_all_vars" di_tv
1781     type_T	*sv_type;
1782     int		sv_const;	// 0, ASSIGN_CONST or ASSIGN_FINAL
1783     int		sv_export;	// "export let var = val"
1784 };
1785 
1786 typedef struct {
1787     char_u	*imp_name;	    // name imported as (allocated)
1788     int		imp_sid;	    // script ID of "from"
1789 
1790     int		imp_flags;	    // IMP_FLAGS_ values
1791 
1792     // for a variable
1793     type_T	*imp_type;
1794     int		imp_var_vals_idx;   // index in sn_var_vals of "from"
1795 
1796     // for a function
1797     char_u	*imp_funcname;	    // user func name (NOT allocated)
1798 } imported_T;
1799 
1800 #define IMP_FLAGS_STAR		1   // using "import * as Name"
1801 #define IMP_FLAGS_RELOAD	2   // script reloaded, OK to redefine
1802 
1803 /*
1804  * Info about an already sourced scripts.
1805  */
1806 typedef struct
1807 {
1808     char_u	*sn_name;
1809     int		sn_script_seq;	    // latest sctx_T sc_seq value
1810 
1811     // "sn_vars" stores the s: variables currently valid.  When leaving a block
1812     // variables local to that block are removed.
1813     scriptvar_T	*sn_vars;
1814 
1815     // Specific for a Vim9 script.
1816     // "sn_all_vars" stores all script variables ever declared.  So long as the
1817     // variable is still valid the value is in "sn_vars->sv_dict...di_tv".
1818     // When the block of a declaration is left the value is moved to
1819     // "sn_all_vars..sav_tv".
1820     // Variables with duplicate names are possible, the sav_block_id must be
1821     // used to check that which variable is valid.
1822     dict_T	sn_all_vars;	// all script variables, dict of sallvar_T
1823 
1824     // Stores the same variables as in "sn_all_vars" as a list of svar_T, so
1825     // that they can be quickly found by index instead of a hash table lookup.
1826     // Also stores the type.
1827     garray_T	sn_var_vals;
1828 
1829     garray_T	sn_imports;	// imported items, imported_T
1830     garray_T	sn_type_list;	// keeps types used by variables
1831     int		sn_current_block_id; // ID for current block, 0 for outer
1832     int		sn_last_block_id;  // Unique ID for each script block
1833 
1834     int		sn_version;	// :scriptversion
1835     int		sn_state;	// SN_STATE_ values
1836     char_u	*sn_save_cpo;	// 'cpo' value when :vim9script found
1837 
1838 # ifdef FEAT_PROFILE
1839     int		sn_prof_on;	// TRUE when script is/was profiled
1840     int		sn_pr_force;	// forceit: profile functions in this script
1841     proftime_T	sn_pr_child;	// time set when going into first child
1842     int		sn_pr_nest;	// nesting for sn_pr_child
1843     // profiling the script as a whole
1844     int		sn_pr_count;	// nr of times sourced
1845     proftime_T	sn_pr_total;	// time spent in script + children
1846     proftime_T	sn_pr_self;	// time spent in script itself
1847     proftime_T	sn_pr_start;	// time at script start
1848     proftime_T	sn_pr_children; // time in children after script start
1849     // profiling the script per line
1850     garray_T	sn_prl_ga;	// things stored for every line
1851     proftime_T	sn_prl_start;	// start time for current line
1852     proftime_T	sn_prl_children; // time spent in children for this line
1853     proftime_T	sn_prl_wait;	// wait start time for current line
1854     int		sn_prl_idx;	// index of line being timed; -1 if none
1855     int		sn_prl_execed;	// line being timed was executed
1856 # endif
1857 } scriptitem_T;
1858 
1859 #define SN_STATE_NEW		0   // newly loaded script, nothing done
1860 #define SN_STATE_RELOAD		1   // script loaded before, nothing done
1861 #define SN_STATE_HAD_COMMAND	9   // a command was executed
1862 
1863 // Struct passed through eval() functions.
1864 // See EVALARG_EVALUATE for a fixed value with eval_flags set to EVAL_EVALUATE.
1865 typedef struct {
1866     int		eval_flags;	    // EVAL_ flag values below
1867     int		eval_break_count;   // nr of line breaks consumed
1868 
1869     // copied from exarg_T when "getline" is "getsourceline". Can be NULL.
1870     char_u	*(*eval_getline)(int, void *, int, getline_opt_T);
1871     void	*eval_cookie;	    // argument for eval_getline()
1872 
1873     // used when compiling a :def function, NULL otherwise
1874     cctx_T	*eval_cctx;
1875 
1876     // Used to collect lines while parsing them, so that they can be
1877     // concatenated later.  Used when "eval_ga.ga_itemsize" is not zero.
1878     // "eval_ga.ga_data" is a list of pointers to lines.
1879     garray_T	eval_ga;
1880 
1881     // pointer to the last line obtained with getsourceline()
1882     char_u	*eval_tofree;
1883 
1884     // pointer to the last line of an inline function
1885     char_u	*eval_tofree_cmdline;
1886 
1887     // pointer to the lines concatenated for a lambda.
1888     char_u	*eval_tofree_lambda;
1889 } evalarg_T;
1890 
1891 // Flags for expression evaluation.
1892 #define EVAL_EVALUATE	    1	    // when missing don't actually evaluate
1893 #define EVAL_CONSTANT	    2	    // when not a constant return FAIL
1894 
1895 # ifdef FEAT_PROFILE
1896 /*
1897  * Struct used in sn_prl_ga for every line of a script.
1898  */
1899 typedef struct sn_prl_S
1900 {
1901     int		snp_count;	// nr of times line was executed
1902     proftime_T	sn_prl_total;	// time spent in a line + children
1903     proftime_T	sn_prl_self;	// time spent in a line itself
1904 } sn_prl_T;
1905 
1906 #  define PRL_ITEM(si, idx)	(((sn_prl_T *)(si)->sn_prl_ga.ga_data)[(idx)])
1907 
1908 typedef struct {
1909     int		pi_started_profiling;
1910     proftime_T	pi_wait_start;
1911     proftime_T	pi_call_start;
1912 } profinfo_T;
1913 
1914 # else
1915 typedef struct
1916 {
1917     int	    dummy;
1918 } profinfo_T;
1919 # endif
1920 #else
1921 // dummy typedefs for use in function prototypes
1922 typedef struct
1923 {
1924     int	    dummy;
1925 } ufunc_T;
1926 typedef struct
1927 {
1928     int	    dummy;
1929 } funccall_T;
1930 typedef struct
1931 {
1932     int	    dummy;
1933 } funcdict_T;
1934 typedef struct
1935 {
1936     int	    dummy;
1937 } funccal_entry_T;
1938 typedef struct
1939 {
1940     int	    dummy;
1941 } scriptitem_T;
1942 typedef struct
1943 {
1944     int	    dummy;
1945 } evalarg_T;
1946 #endif
1947 
1948 // Struct passed between functions dealing with function call execution.
1949 //
1950 // "argv_func", when not NULL, can be used to fill in arguments only when the
1951 // invoked function uses them.  It is called like this:
1952 //   new_argcount = argv_func(current_argcount, argv, partial_argcount,
1953 //							called_func_argcount)
1954 //
1955 typedef struct {
1956     int		(* argv_func)(int, typval_T *, int, int);
1957     linenr_T	firstline;	// first line of range
1958     linenr_T	lastline;	// last line of range
1959     int		*doesrange;	// if not NULL: return: function handled range
1960     int		evaluate;	// actually evaluate expressions
1961     partial_T	*partial;	// for extra arguments
1962     dict_T	*selfdict;	// Dictionary for "self"
1963     typval_T	*basetv;	// base for base->method()
1964     type_T	*check_type;	// type from funcref or NULL
1965 } funcexe_T;
1966 
1967 /*
1968  * Structure to hold the context of a compiled function, used by closures
1969  * defined in that function.
1970  */
1971 typedef struct funcstack_S
1972 {
1973     garray_T	fs_ga;		// contains the stack, with:
1974 				// - arguments
1975 				// - frame
1976 				// - local variables
1977     int		fs_var_offset;	// count of arguments + frame size == offset to
1978 				// local variables
1979 
1980     int		fs_refcount;	// nr of closures referencing this funcstack
1981     int		fs_min_refcount; // nr of closures on this funcstack
1982     int		fs_copyID;	// for garray_T collection
1983 } funcstack_T;
1984 
1985 typedef struct outer_S outer_T;
1986 struct outer_S {
1987     garray_T	*out_stack;	    // stack from outer scope
1988     int		out_frame_idx;	    // index of stack frame in out_stack
1989     outer_T	*out_up;	    // outer scope of outer scope or NULL
1990     int		out_up_is_copy;	    // don't free out_up
1991 };
1992 
1993 struct partial_S
1994 {
1995     int		pt_refcount;	// reference count
1996     char_u	*pt_name;	// function name; when NULL use
1997 				// pt_func->uf_name
1998     ufunc_T	*pt_func;	// function pointer; when NULL lookup function
1999 				// with pt_name
2000     int		pt_auto;	// when TRUE the partial was created for using
2001 				// dict.member in handle_subscript()
2002 
2003     // For a compiled closure: the arguments and local variables scope
2004     outer_T	pt_outer;
2005 
2006     funcstack_T	*pt_funcstack;	// copy of stack, used after context
2007 				// function returns
2008 
2009     int		pt_argc;	// number of arguments
2010     typval_T	*pt_argv;	// arguments in allocated array
2011 
2012     dict_T	*pt_dict;	// dict for "self"
2013     int		pt_copyID;	// funcstack may contain pointer to partial
2014 };
2015 
2016 typedef struct AutoPatCmd_S AutoPatCmd;
2017 
2018 /*
2019  * Entry in the execution stack "exestack".
2020  */
2021 typedef enum {
2022     ETYPE_TOP,		    // toplevel
2023     ETYPE_SCRIPT,           // sourcing script, use es_info.sctx
2024     ETYPE_UFUNC,            // user function, use es_info.ufunc
2025     ETYPE_AUCMD,            // autocomand, use es_info.aucmd
2026     ETYPE_MODELINE,         // modeline, use es_info.sctx
2027     ETYPE_EXCEPT,           // exception, use es_info.exception
2028     ETYPE_ARGS,             // command line argument
2029     ETYPE_ENV,              // environment variable
2030     ETYPE_INTERNAL,         // internal operation
2031     ETYPE_SPELL,            // loading spell file
2032 } etype_T;
2033 
2034 typedef struct {
2035     long      es_lnum;      // replaces "sourcing_lnum"
2036     char_u    *es_name;     // replaces "sourcing_name"
2037     etype_T   es_type;
2038     union {
2039 	sctx_T  *sctx;      // script and modeline info
2040 #if defined(FEAT_EVAL)
2041 	ufunc_T *ufunc;     // function info
2042 #endif
2043 	AutoPatCmd *aucmd;  // autocommand info
2044 	except_T   *except; // exception info
2045     } es_info;
2046 #if defined(FEAT_EVAL)
2047     scid_T	es_save_sid;	    // saved sc_sid when calling function
2048 #endif
2049 } estack_T;
2050 
2051 // Information returned by get_tty_info().
2052 typedef struct {
2053     int backspace;	// what the Backspace key produces
2054     int enter;		// what the Enter key produces
2055     int interrupt;	// interrupt character
2056     int nl_does_cr;	// TRUE when a NL is expanded to CR-NL on output
2057 } ttyinfo_T;
2058 
2059 // Status of a job.  Order matters!
2060 typedef enum
2061 {
2062     JOB_FAILED,
2063     JOB_STARTED,
2064     JOB_ENDED,	    // detected job done
2065     JOB_FINISHED,   // job done and cleanup done
2066 } jobstatus_T;
2067 
2068 /*
2069  * Structure to hold info about a Job.
2070  */
2071 struct jobvar_S
2072 {
2073     job_T	*jv_next;
2074     job_T	*jv_prev;
2075 #ifdef UNIX
2076     pid_t	jv_pid;
2077 #endif
2078 #ifdef MSWIN
2079     PROCESS_INFORMATION	jv_proc_info;
2080     HANDLE		jv_job_object;
2081 #endif
2082     char_u	*jv_tty_in;	// controlling tty input, allocated
2083     char_u	*jv_tty_out;	// controlling tty output, allocated
2084     jobstatus_T	jv_status;
2085     char_u	*jv_stoponexit;	// allocated
2086 #ifdef UNIX
2087     char_u	*jv_termsig;	// allocated
2088 #endif
2089 #ifdef MSWIN
2090     char_u	*jv_tty_type;	// allocated
2091 #endif
2092     int		jv_exitval;
2093     callback_T	jv_exit_cb;
2094 
2095     buf_T	*jv_in_buf;	// buffer from "in-name"
2096 
2097     int		jv_refcount;	// reference count
2098     int		jv_copyID;
2099 
2100     channel_T	*jv_channel;	// channel for I/O, reference counted
2101     char	**jv_argv;	// command line used to start the job
2102 };
2103 
2104 /*
2105  * Structures to hold info about a Channel.
2106  */
2107 struct readq_S
2108 {
2109     char_u	*rq_buffer;
2110     long_u	rq_buflen;
2111     readq_T	*rq_next;
2112     readq_T	*rq_prev;
2113 };
2114 
2115 struct writeq_S
2116 {
2117     garray_T	wq_ga;
2118     writeq_T	*wq_next;
2119     writeq_T	*wq_prev;
2120 };
2121 
2122 struct jsonq_S
2123 {
2124     typval_T	*jq_value;
2125     jsonq_T	*jq_next;
2126     jsonq_T	*jq_prev;
2127     int		jq_no_callback; // TRUE when no callback was found
2128 };
2129 
2130 struct cbq_S
2131 {
2132     callback_T	cq_callback;
2133     int		cq_seq_nr;
2134     cbq_T	*cq_next;
2135     cbq_T	*cq_prev;
2136 };
2137 
2138 // mode for a channel
2139 typedef enum
2140 {
2141     MODE_NL = 0,
2142     MODE_RAW,
2143     MODE_JSON,
2144     MODE_JS,
2145 } ch_mode_T;
2146 
2147 typedef enum {
2148     JIO_PIPE,	    // default
2149     JIO_NULL,
2150     JIO_FILE,
2151     JIO_BUFFER,
2152     JIO_OUT
2153 } job_io_T;
2154 
2155 #define CH_PART_FD(part)	ch_part[part].ch_fd
2156 
2157 // Ordering matters, it is used in for loops: IN is last, only SOCK/OUT/ERR
2158 // are polled.
2159 typedef enum {
2160     PART_SOCK = 0,
2161 #define CH_SOCK_FD	CH_PART_FD(PART_SOCK)
2162 #ifdef FEAT_JOB_CHANNEL
2163     PART_OUT,
2164 # define CH_OUT_FD	CH_PART_FD(PART_OUT)
2165     PART_ERR,
2166 # define CH_ERR_FD	CH_PART_FD(PART_ERR)
2167     PART_IN,
2168 # define CH_IN_FD	CH_PART_FD(PART_IN)
2169 #endif
2170     PART_COUNT,
2171 } ch_part_T;
2172 
2173 #define INVALID_FD	(-1)
2174 
2175 // The per-fd info for a channel.
2176 typedef struct {
2177     sock_T	ch_fd;	    // socket/stdin/stdout/stderr, -1 if not used
2178 
2179 # if defined(UNIX) && !defined(HAVE_SELECT)
2180     int		ch_poll_idx;	// used by channel_poll_setup()
2181 # endif
2182 
2183 #ifdef FEAT_GUI_X11
2184     XtInputId	ch_inputHandler; // Cookie for input
2185 #endif
2186 #ifdef FEAT_GUI_GTK
2187     gint	ch_inputHandler; // Cookie for input
2188 #endif
2189 
2190     ch_mode_T	ch_mode;
2191     job_io_T	ch_io;
2192     int		ch_timeout;	// request timeout in msec
2193 
2194     readq_T	ch_head;	// header for circular raw read queue
2195     jsonq_T	ch_json_head;	// header for circular json read queue
2196     garray_T	ch_block_ids;	// list of IDs that channel_read_json_block()
2197 				// is waiting for
2198     // When ch_wait_len is non-zero use ch_deadline to wait for incomplete
2199     // message to be complete. The value is the length of the incomplete
2200     // message when the deadline was set.  If it gets longer (something was
2201     // received) the deadline is reset.
2202     size_t	ch_wait_len;
2203 #ifdef MSWIN
2204     DWORD	ch_deadline;
2205 #else
2206     struct timeval ch_deadline;
2207 #endif
2208     int		ch_block_write;	// for testing: 0 when not used, -1 when write
2209 				// does not block, 1 simulate blocking
2210     int		ch_nonblocking;	// write() is non-blocking
2211     writeq_T	ch_writeque;	// header for write queue
2212 
2213     cbq_T	ch_cb_head;	// dummy node for per-request callbacks
2214     callback_T	ch_callback;	// call when a msg is not handled
2215 
2216     bufref_T	ch_bufref;	// buffer to read from or write to
2217     int		ch_nomodifiable; // TRUE when buffer can be 'nomodifiable'
2218     int		ch_nomod_error;	// TRUE when e_modifiable was given
2219     int		ch_buf_append;	// write appended lines instead top-bot
2220     linenr_T	ch_buf_top;	// next line to send
2221     linenr_T	ch_buf_bot;	// last line to send
2222 } chanpart_T;
2223 
2224 struct channel_S {
2225     channel_T	*ch_next;
2226     channel_T	*ch_prev;
2227 
2228     int		ch_id;		// ID of the channel
2229     int		ch_last_msg_id;	// ID of the last message
2230 
2231     chanpart_T	ch_part[PART_COUNT]; // info for socket, out, err and in
2232     int		ch_write_text_mode; // write buffer lines with CR, not NL
2233 
2234     char	*ch_hostname;	// only for socket, allocated
2235     int		ch_port;	// only for socket
2236 
2237     int		ch_to_be_closed; // bitset of readable fds to be closed.
2238 				 // When all readable fds have been closed,
2239 				 // set to (1 << PART_COUNT).
2240     int		ch_to_be_freed; // When TRUE channel must be freed when it's
2241 				// safe to invoke callbacks.
2242     int		ch_error;	// When TRUE an error was reported.  Avoids
2243 				// giving pages full of error messages when
2244 				// the other side has exited, only mention the
2245 				// first error until the connection works
2246 				// again.
2247 
2248     void	(*ch_nb_close_cb)(void);
2249 				// callback for Netbeans when channel is
2250 				// closed
2251 
2252 #ifdef MSWIN
2253     int		ch_named_pipe;	// using named pipe instead of pty
2254 #endif
2255     callback_T	ch_callback;	// call when any msg is not handled
2256     callback_T	ch_close_cb;	// call when channel is closed
2257     int		ch_drop_never;
2258     int		ch_keep_open;	// do not close on read error
2259     int		ch_nonblock;
2260 
2261     job_T	*ch_job;	// Job that uses this channel; this does not
2262 				// count as a reference to avoid a circular
2263 				// reference, the job refers to the channel.
2264     int		ch_job_killed;	// TRUE when there was a job and it was killed
2265 				// or we know it died.
2266     int		ch_anonymous_pipe;  // ConPTY
2267     int		ch_killing;	    // TerminateJobObject() was called
2268 
2269     int		ch_refcount;	// reference count
2270     int		ch_copyID;
2271 };
2272 
2273 #define JO_MODE		    0x0001	// channel mode
2274 #define JO_IN_MODE	    0x0002	// stdin mode
2275 #define JO_OUT_MODE	    0x0004	// stdout mode
2276 #define JO_ERR_MODE	    0x0008	// stderr mode
2277 #define JO_CALLBACK	    0x0010	// channel callback
2278 #define JO_OUT_CALLBACK	    0x0020	// stdout callback
2279 #define JO_ERR_CALLBACK	    0x0040	// stderr callback
2280 #define JO_CLOSE_CALLBACK   0x0080	// "close_cb"
2281 #define JO_WAITTIME	    0x0100	// only for ch_open()
2282 #define JO_TIMEOUT	    0x0200	// all timeouts
2283 #define JO_OUT_TIMEOUT	    0x0400	// stdout timeouts
2284 #define JO_ERR_TIMEOUT	    0x0800	// stderr timeouts
2285 #define JO_PART		    0x1000	// "part"
2286 #define JO_ID		    0x2000	// "id"
2287 #define JO_STOPONEXIT	    0x4000	// "stoponexit"
2288 #define JO_EXIT_CB	    0x8000	// "exit_cb"
2289 #define JO_OUT_IO	    0x10000	// "out_io"
2290 #define JO_ERR_IO	    0x20000	// "err_io" (JO_OUT_IO << 1)
2291 #define JO_IN_IO	    0x40000	// "in_io" (JO_OUT_IO << 2)
2292 #define JO_OUT_NAME	    0x80000	// "out_name"
2293 #define JO_ERR_NAME	    0x100000	// "err_name" (JO_OUT_NAME << 1)
2294 #define JO_IN_NAME	    0x200000	// "in_name" (JO_OUT_NAME << 2)
2295 #define JO_IN_TOP	    0x400000	// "in_top"
2296 #define JO_IN_BOT	    0x800000	// "in_bot"
2297 #define JO_OUT_BUF	    0x1000000	// "out_buf"
2298 #define JO_ERR_BUF	    0x2000000	// "err_buf" (JO_OUT_BUF << 1)
2299 #define JO_IN_BUF	    0x4000000	// "in_buf" (JO_OUT_BUF << 2)
2300 #define JO_CHANNEL	    0x8000000	// "channel"
2301 #define JO_BLOCK_WRITE	    0x10000000	// "block_write"
2302 #define JO_OUT_MODIFIABLE   0x20000000	// "out_modifiable"
2303 #define JO_ERR_MODIFIABLE   0x40000000	// "err_modifiable" (JO_OUT_ << 1)
2304 #define JO_ALL		    0x7fffffff
2305 
2306 #define JO2_OUT_MSG	    0x0001	// "out_msg"
2307 #define JO2_ERR_MSG	    0x0002	// "err_msg" (JO_OUT_ << 1)
2308 #define JO2_TERM_NAME	    0x0004	// "term_name"
2309 #define JO2_TERM_FINISH	    0x0008	// "term_finish"
2310 #define JO2_ENV		    0x0010	// "env"
2311 #define JO2_CWD		    0x0020	// "cwd"
2312 #define JO2_TERM_ROWS	    0x0040	// "term_rows"
2313 #define JO2_TERM_COLS	    0x0080	// "term_cols"
2314 #define JO2_VERTICAL	    0x0100	// "vertical"
2315 #define JO2_CURWIN	    0x0200	// "curwin"
2316 #define JO2_HIDDEN	    0x0400	// "hidden"
2317 #define JO2_TERM_OPENCMD    0x0800	// "term_opencmd"
2318 #define JO2_EOF_CHARS	    0x1000	// "eof_chars"
2319 #define JO2_NORESTORE	    0x2000	// "norestore"
2320 #define JO2_TERM_KILL	    0x4000	// "term_kill"
2321 #define JO2_ANSI_COLORS	    0x8000	// "ansi_colors"
2322 #define JO2_TTY_TYPE	    0x10000	// "tty_type"
2323 #define JO2_BUFNR	    0x20000	// "bufnr"
2324 #define JO2_TERM_API	    0x40000	// "term_api"
2325 #define JO2_TERM_HIGHLIGHT  0x80000	// "highlight"
2326 
2327 #define JO_MODE_ALL	(JO_MODE + JO_IN_MODE + JO_OUT_MODE + JO_ERR_MODE)
2328 #define JO_CB_ALL \
2329     (JO_CALLBACK + JO_OUT_CALLBACK + JO_ERR_CALLBACK + JO_CLOSE_CALLBACK)
2330 #define JO_TIMEOUT_ALL	(JO_TIMEOUT + JO_OUT_TIMEOUT + JO_ERR_TIMEOUT)
2331 
2332 /*
2333  * Options for job and channel commands.
2334  */
2335 typedef struct
2336 {
2337     int		jo_set;		// JO_ bits for values that were set
2338     int		jo_set2;	// JO2_ bits for values that were set
2339 
2340     ch_mode_T	jo_mode;
2341     ch_mode_T	jo_in_mode;
2342     ch_mode_T	jo_out_mode;
2343     ch_mode_T	jo_err_mode;
2344     int		jo_noblock;
2345 
2346     job_io_T	jo_io[4];	// PART_OUT, PART_ERR, PART_IN
2347     char_u	jo_io_name_buf[4][NUMBUFLEN];
2348     char_u	*jo_io_name[4];	// not allocated!
2349     int		jo_io_buf[4];
2350     int		jo_pty;
2351     int		jo_modifiable[4];
2352     int		jo_message[4];
2353     channel_T	*jo_channel;
2354 
2355     linenr_T	jo_in_top;
2356     linenr_T	jo_in_bot;
2357 
2358     callback_T	jo_callback;
2359     callback_T	jo_out_cb;
2360     callback_T	jo_err_cb;
2361     callback_T	jo_close_cb;
2362     callback_T	jo_exit_cb;
2363     int		jo_drop_never;
2364     int		jo_waittime;
2365     int		jo_timeout;
2366     int		jo_out_timeout;
2367     int		jo_err_timeout;
2368     int		jo_block_write;	// for testing only
2369     int		jo_part;
2370     int		jo_id;
2371     char_u	jo_stoponexit_buf[NUMBUFLEN];
2372     char_u	*jo_stoponexit;
2373     dict_T	*jo_env;	// environment variables
2374     char_u	jo_cwd_buf[NUMBUFLEN];
2375     char_u	*jo_cwd;
2376 
2377 #ifdef FEAT_TERMINAL
2378     // when non-zero run the job in a terminal window of this size
2379     int		jo_term_rows;
2380     int		jo_term_cols;
2381     int		jo_vertical;
2382     int		jo_curwin;
2383     buf_T	*jo_bufnr_buf;
2384     int		jo_hidden;
2385     int		jo_term_norestore;
2386     char_u	jo_term_name_buf[NUMBUFLEN];
2387     char_u	*jo_term_name;
2388     char_u	jo_term_opencmd_buf[NUMBUFLEN];
2389     char_u	*jo_term_opencmd;
2390     int		jo_term_finish;
2391     char_u	jo_eof_chars_buf[NUMBUFLEN];
2392     char_u	*jo_eof_chars;
2393     char_u	jo_term_kill_buf[NUMBUFLEN];
2394     char_u	*jo_term_kill;
2395 # if defined(FEAT_GUI) || defined(FEAT_TERMGUICOLORS)
2396     long_u	jo_ansi_colors[16];
2397 # endif
2398     char_u	jo_term_highlight_buf[NUMBUFLEN];
2399     char_u	*jo_term_highlight;
2400     int		jo_tty_type;	    // first character of "tty_type"
2401     char_u	jo_term_api_buf[NUMBUFLEN];
2402     char_u	*jo_term_api;
2403 #endif
2404 } jobopt_T;
2405 
2406 #ifdef FEAT_EVAL
2407 /*
2408  * Structure used for listeners added with listener_add().
2409  */
2410 typedef struct listener_S listener_T;
2411 struct listener_S
2412 {
2413     listener_T	*lr_next;
2414     int		lr_id;
2415     callback_T	lr_callback;
2416 };
2417 #endif
2418 
2419 /*
2420  * structure used for explicit stack while garbage collecting hash tables
2421  */
2422 typedef struct ht_stack_S
2423 {
2424     hashtab_T		*ht;
2425     struct ht_stack_S	*prev;
2426 } ht_stack_T;
2427 
2428 /*
2429  * structure used for explicit stack while garbage collecting lists
2430  */
2431 typedef struct list_stack_S
2432 {
2433     list_T		*list;
2434     struct list_stack_S	*prev;
2435 } list_stack_T;
2436 
2437 /*
2438  * Structure used for iterating over dictionary items.
2439  * Initialize with dict_iterate_start().
2440  */
2441 typedef struct
2442 {
2443     long_u	dit_todo;
2444     hashitem_T	*dit_hi;
2445 } dict_iterator_T;
2446 
2447 // values for b_syn_spell: what to do with toplevel text
2448 #define SYNSPL_DEFAULT	0	// spell check if @Spell not defined
2449 #define SYNSPL_TOP	1	// spell check toplevel text
2450 #define SYNSPL_NOTOP	2	// don't spell check toplevel text
2451 
2452 // values for b_syn_foldlevel: how to compute foldlevel on a line
2453 #define SYNFLD_START	0	// use level of item at start of line
2454 #define SYNFLD_MINIMUM	1	// use lowest local minimum level on line
2455 
2456 // avoid #ifdefs for when b_spell is not available
2457 #ifdef FEAT_SPELL
2458 # define B_SPELL(buf)  ((buf)->b_spell)
2459 #else
2460 # define B_SPELL(buf)  (0)
2461 #endif
2462 
2463 typedef struct qf_info_S qf_info_T;
2464 
2465 #ifdef FEAT_PROFILE
2466 /*
2467  * Used for :syntime: timing of executing a syntax pattern.
2468  */
2469 typedef struct {
2470     proftime_T	total;		// total time used
2471     proftime_T	slowest;	// time of slowest call
2472     long	count;		// nr of times used
2473     long	match;		// nr of times matched
2474 } syn_time_T;
2475 #endif
2476 
2477 typedef struct timer_S timer_T;
2478 struct timer_S
2479 {
2480     long	tr_id;
2481 #ifdef FEAT_TIMERS
2482     timer_T	*tr_next;
2483     timer_T	*tr_prev;
2484     proftime_T	tr_due;		    // when the callback is to be invoked
2485     char	tr_firing;	    // when TRUE callback is being called
2486     char	tr_paused;	    // when TRUE callback is not invoked
2487     int		tr_repeat;	    // number of times to repeat, -1 forever
2488     long	tr_interval;	    // msec
2489     callback_T	tr_callback;
2490     int		tr_emsg_count;
2491 #endif
2492 };
2493 
2494 #ifdef FEAT_CRYPT
2495 /*
2496  * Structure to hold the type of encryption and the state of encryption or
2497  * decryption.
2498  */
2499 typedef struct {
2500     int	    method_nr;
2501     void    *method_state;  // method-specific state information
2502 } cryptstate_T;
2503 
2504 // values for method_nr
2505 # define CRYPT_M_ZIP	0
2506 # define CRYPT_M_BF	1
2507 # define CRYPT_M_BF2	2
2508 # define CRYPT_M_COUNT	3 // number of crypt methods
2509 
2510 // Currently all crypt methods work inplace.  If one is added that isn't then
2511 // define this.
2512 //  # define CRYPT_NOT_INPLACE 1
2513 #endif
2514 
2515 #ifdef FEAT_PROP_POPUP
2516 typedef enum {
2517     POPPOS_BOTLEFT,
2518     POPPOS_TOPLEFT,
2519     POPPOS_BOTRIGHT,
2520     POPPOS_TOPRIGHT,
2521     POPPOS_CENTER,
2522     POPPOS_NONE
2523 } poppos_T;
2524 
2525 typedef enum {
2526     POPCLOSE_NONE,
2527     POPCLOSE_BUTTON,
2528     POPCLOSE_CLICK
2529 } popclose_T;
2530 
2531 # define POPUPWIN_DEFAULT_ZINDEX	 50
2532 # define POPUPMENU_ZINDEX		100
2533 # define POPUPWIN_DIALOG_ZINDEX		200
2534 # define POPUPWIN_NOTIFICATION_ZINDEX   300
2535 #endif
2536 
2537 /*
2538  * These are items normally related to a buffer.  But when using ":ownsyntax"
2539  * a window may have its own instance.
2540  */
2541 typedef struct {
2542 #ifdef FEAT_SYN_HL
2543     hashtab_T	b_keywtab;		// syntax keywords hash table
2544     hashtab_T	b_keywtab_ic;		// idem, ignore case
2545     int		b_syn_error;		// TRUE when error occurred in HL
2546 # ifdef FEAT_RELTIME
2547     int		b_syn_slow;		// TRUE when 'redrawtime' reached
2548 # endif
2549     int		b_syn_ic;		// ignore case for :syn cmds
2550     int		b_syn_foldlevel;	// how to compute foldlevel on a line
2551     int		b_syn_spell;		// SYNSPL_ values
2552     garray_T	b_syn_patterns;		// table for syntax patterns
2553     garray_T	b_syn_clusters;		// table for syntax clusters
2554     int		b_spell_cluster_id;	// @Spell cluster ID or 0
2555     int		b_nospell_cluster_id;	// @NoSpell cluster ID or 0
2556     int		b_syn_containedin;	// TRUE when there is an item with a
2557 					// "containedin" argument
2558     int		b_syn_sync_flags;	// flags about how to sync
2559     short	b_syn_sync_id;		// group to sync on
2560     long	b_syn_sync_minlines;	// minimal sync lines offset
2561     long	b_syn_sync_maxlines;	// maximal sync lines offset
2562     long	b_syn_sync_linebreaks;	// offset for multi-line pattern
2563     char_u	*b_syn_linecont_pat;	// line continuation pattern
2564     regprog_T	*b_syn_linecont_prog;	// line continuation program
2565 #ifdef FEAT_PROFILE
2566     syn_time_T  b_syn_linecont_time;
2567 #endif
2568     int		b_syn_linecont_ic;	// ignore-case flag for above
2569     int		b_syn_topgrp;		// for ":syntax include"
2570 # ifdef FEAT_CONCEAL
2571     int		b_syn_conceal;		// auto-conceal for :syn cmds
2572 # endif
2573 # ifdef FEAT_FOLDING
2574     int		b_syn_folditems;	// number of patterns with the HL_FOLD
2575 					// flag set
2576 # endif
2577     /*
2578      * b_sst_array[] contains the state stack for a number of lines, for the
2579      * start of that line (col == 0).  This avoids having to recompute the
2580      * syntax state too often.
2581      * b_sst_array[] is allocated to hold the state for all displayed lines,
2582      * and states for 1 out of about 20 other lines.
2583      * b_sst_array	pointer to an array of synstate_T
2584      * b_sst_len	number of entries in b_sst_array[]
2585      * b_sst_first	pointer to first used entry in b_sst_array[] or NULL
2586      * b_sst_firstfree	pointer to first free entry in b_sst_array[] or NULL
2587      * b_sst_freecount	number of free entries in b_sst_array[]
2588      * b_sst_check_lnum	entries after this lnum need to be checked for
2589      *			validity (MAXLNUM means no check needed)
2590      */
2591     synstate_T	*b_sst_array;
2592     int		b_sst_len;
2593     synstate_T	*b_sst_first;
2594     synstate_T	*b_sst_firstfree;
2595     int		b_sst_freecount;
2596     linenr_T	b_sst_check_lnum;
2597     short_u	b_sst_lasttick;	// last display tick
2598 #endif // FEAT_SYN_HL
2599 
2600 #ifdef FEAT_SPELL
2601     // for spell checking
2602     garray_T	b_langp;	    // list of pointers to slang_T, see spell.c
2603     char_u	b_spell_ismw[256];  // flags: is midword char
2604     char_u	*b_spell_ismw_mb;   // multi-byte midword chars
2605     char_u	*b_p_spc;	    // 'spellcapcheck'
2606     regprog_T	*b_cap_prog;	    // program for 'spellcapcheck'
2607     char_u	*b_p_spf;	    // 'spellfile'
2608     char_u	*b_p_spl;	    // 'spelllang'
2609     char_u	*b_p_spo;	    // 'spelloptions'
2610     int		b_cjk;		    // all CJK letters as OK
2611 #endif
2612 #if !defined(FEAT_SYN_HL) && !defined(FEAT_SPELL)
2613     int		dummy;
2614 #endif
2615     char_u	b_syn_chartab[32];  // syntax iskeyword option
2616     char_u	*b_syn_isk;	    // iskeyword option
2617 } synblock_T;
2618 
2619 
2620 /*
2621  * buffer: structure that holds information about one file
2622  *
2623  * Several windows can share a single Buffer
2624  * A buffer is unallocated if there is no memfile for it.
2625  * A buffer is new if the associated file has never been loaded yet.
2626  */
2627 
2628 struct file_buffer
2629 {
2630     memline_T	b_ml;		// associated memline (also contains line
2631 				// count)
2632 
2633     buf_T	*b_next;	// links in list of buffers
2634     buf_T	*b_prev;
2635 
2636     int		b_nwindows;	// nr of windows open on this buffer
2637 
2638     int		b_flags;	// various BF_ flags
2639     int		b_locked;	// Buffer is being closed or referenced, don't
2640 				// let autocommands wipe it out.
2641     int		b_locked_split;	// Buffer is being closed, don't allow opening
2642 				// a new window with it.
2643 
2644     /*
2645      * b_ffname has the full path of the file (NULL for no name).
2646      * b_sfname is the name as the user typed it (or NULL).
2647      * b_fname is the same as b_sfname, unless ":cd" has been done,
2648      *		then it is the same as b_ffname (NULL for no name).
2649      */
2650     char_u	*b_ffname;	// full path file name, allocated
2651     char_u	*b_sfname;	// short file name, allocated, may be equal to
2652 				// b_ffname
2653     char_u	*b_fname;	// current file name, points to b_ffname or
2654 				// b_sfname
2655 
2656 #ifdef UNIX
2657     int		b_dev_valid;	// TRUE when b_dev has a valid number
2658     dev_t	b_dev;		// device number
2659     ino_t	b_ino;		// inode number
2660 #endif
2661 #ifdef VMS
2662     char	 b_fab_rfm;	// Record format
2663     char	 b_fab_rat;	// Record attribute
2664     unsigned int b_fab_mrs;	// Max record size
2665 #endif
2666     int		b_fnum;		// buffer number for this file.
2667     char_u	b_key[VIM_SIZEOF_INT * 2 + 1];
2668 				// key used for buf_hashtab, holds b_fnum as
2669 				// hex string
2670 
2671     int		b_changed;	// 'modified': Set to TRUE if something in the
2672 				// file has been changed and not written out.
2673     dictitem16_T b_ct_di;	// holds the b:changedtick value in
2674 				// b_ct_di.di_tv.vval.v_number;
2675 				// incremented for each change, also for undo
2676 #define CHANGEDTICK(buf) ((buf)->b_ct_di.di_tv.vval.v_number)
2677 
2678     varnumber_T	b_last_changedtick; // b:changedtick when TextChanged or
2679 				    // TextChangedI was last triggered.
2680     varnumber_T	b_last_changedtick_pum; // b:changedtick when TextChangedP was
2681 					// last triggered.
2682 
2683     int		b_saving;	// Set to TRUE if we are in the middle of
2684 				// saving the buffer.
2685 
2686     /*
2687      * Changes to a buffer require updating of the display.  To minimize the
2688      * work, remember changes made and update everything at once.
2689      */
2690     int		b_mod_set;	// TRUE when there are changes since the last
2691 				// time the display was updated
2692     linenr_T	b_mod_top;	// topmost lnum that was changed
2693     linenr_T	b_mod_bot;	// lnum below last changed line, AFTER the
2694 				// change
2695     long	b_mod_xlines;	// number of extra buffer lines inserted;
2696 				// negative when lines were deleted
2697 
2698     wininfo_T	*b_wininfo;	// list of last used info for each window
2699 
2700     long	b_mtime;	// last change time of original file
2701     long	b_mtime_read;	// last change time when reading
2702     off_T	b_orig_size;	// size of original file in bytes
2703     int		b_orig_mode;	// mode of original file
2704 #ifdef FEAT_VIMINFO
2705     time_T	b_last_used;	// time when the buffer was last used; used
2706 				// for viminfo
2707 #endif
2708 
2709     pos_T	b_namedm[NMARKS]; // current named marks (mark.c)
2710 
2711     // These variables are set when VIsual_active becomes FALSE
2712     visualinfo_T b_visual;
2713 #ifdef FEAT_EVAL
2714     int		b_visual_mode_eval;  // b_visual.vi_mode for visualmode()
2715 #endif
2716 
2717     pos_T	b_last_cursor;	// cursor position when last unloading this
2718 				// buffer
2719     pos_T	b_last_insert;	// where Insert mode was left
2720     pos_T	b_last_change;	// position of last change: '. mark
2721 
2722 #ifdef FEAT_JUMPLIST
2723     /*
2724      * the changelist contains old change positions
2725      */
2726     pos_T	b_changelist[JUMPLISTSIZE];
2727     int		b_changelistlen;	// number of active entries
2728     int		b_new_change;		// set by u_savecommon()
2729 #endif
2730 
2731     /*
2732      * Character table, only used in charset.c for 'iskeyword'
2733      * 32 bytes of 8 bits: 1 bit per character 0-255.
2734      */
2735     char_u	b_chartab[32];
2736 
2737     // Table used for mappings local to a buffer.
2738     mapblock_T	*(b_maphash[256]);
2739 
2740     // First abbreviation local to a buffer.
2741     mapblock_T	*b_first_abbr;
2742 
2743     // User commands local to the buffer.
2744     garray_T	b_ucmds;
2745     // start and end of an operator, also used for '[ and ']
2746     pos_T	b_op_start;
2747     pos_T	b_op_start_orig;  // used for Insstart_orig
2748     pos_T	b_op_end;
2749 
2750 #ifdef FEAT_VIMINFO
2751     int		b_marks_read;	// Have we read viminfo marks yet?
2752 #endif
2753 
2754     /*
2755      * The following only used in undo.c.
2756      */
2757     u_header_T	*b_u_oldhead;	// pointer to oldest header
2758     u_header_T	*b_u_newhead;	// pointer to newest header; may not be valid
2759 				// if b_u_curhead is not NULL
2760     u_header_T	*b_u_curhead;	// pointer to current header
2761     int		b_u_numhead;	// current number of headers
2762     int		b_u_synced;	// entry lists are synced
2763     long	b_u_seq_last;	// last used undo sequence number
2764     long	b_u_save_nr_last; // counter for last file write
2765     long	b_u_seq_cur;	// hu_seq of header below which we are now
2766     time_T	b_u_time_cur;	// uh_time of header below which we are now
2767     long	b_u_save_nr_cur; // file write nr after which we are now
2768 
2769     /*
2770      * variables for "U" command in undo.c
2771      */
2772     undoline_T	b_u_line_ptr;	// saved line for "U" command
2773     linenr_T	b_u_line_lnum;	// line number of line in u_line
2774     colnr_T	b_u_line_colnr;	// optional column number
2775 
2776     int		b_scanned;	// ^N/^P have scanned this buffer
2777 
2778     // flags for use of ":lmap" and IM control
2779     long	b_p_iminsert;	// input mode for insert
2780     long	b_p_imsearch;	// input mode for search
2781 #define B_IMODE_USE_INSERT -1	//	Use b_p_iminsert value for search
2782 #define B_IMODE_NONE 0		//	Input via none
2783 #define B_IMODE_LMAP 1		//	Input via langmap
2784 #define B_IMODE_IM 2		//	Input via input method
2785 #define B_IMODE_LAST 2
2786 
2787 #ifdef FEAT_KEYMAP
2788     short	b_kmap_state;	// using "lmap" mappings
2789 # define KEYMAP_INIT	1	// 'keymap' was set, call keymap_init()
2790 # define KEYMAP_LOADED	2	// 'keymap' mappings have been loaded
2791     garray_T	b_kmap_ga;	// the keymap table
2792 #endif
2793 
2794     /*
2795      * Options local to a buffer.
2796      * They are here because their value depends on the type of file
2797      * or contents of the file being edited.
2798      */
2799     int		b_p_initialized;	// set when options initialized
2800 
2801 #ifdef FEAT_EVAL
2802     sctx_T	b_p_script_ctx[BV_COUNT]; // SCTXs for buffer-local options
2803 #endif
2804 
2805     int		b_p_ai;		// 'autoindent'
2806     int		b_p_ai_nopaste;	// b_p_ai saved for paste mode
2807     char_u	*b_p_bkc;	// 'backupcopy'
2808     unsigned	b_bkc_flags;    // flags for 'backupcopy'
2809     int		b_p_ci;		// 'copyindent'
2810     int		b_p_bin;	// 'binary'
2811     int		b_p_bomb;	// 'bomb'
2812     char_u	*b_p_bh;	// 'bufhidden'
2813     char_u	*b_p_bt;	// 'buftype'
2814 #ifdef FEAT_QUICKFIX
2815 #define BUF_HAS_QF_ENTRY 1
2816 #define BUF_HAS_LL_ENTRY 2
2817     int		b_has_qf_entry;
2818 #endif
2819     int		b_p_bl;		// 'buflisted'
2820 #ifdef FEAT_CINDENT
2821     int		b_p_cin;	// 'cindent'
2822     char_u	*b_p_cino;	// 'cinoptions'
2823     char_u	*b_p_cink;	// 'cinkeys'
2824 #endif
2825 #if defined(FEAT_CINDENT) || defined(FEAT_SMARTINDENT)
2826     char_u	*b_p_cinw;	// 'cinwords'
2827 #endif
2828     char_u	*b_p_com;	// 'comments'
2829 #ifdef FEAT_FOLDING
2830     char_u	*b_p_cms;	// 'commentstring'
2831 #endif
2832     char_u	*b_p_cpt;	// 'complete'
2833 #ifdef BACKSLASH_IN_FILENAME
2834     char_u	*b_p_csl;	// 'completeslash'
2835 #endif
2836 #ifdef FEAT_COMPL_FUNC
2837     char_u	*b_p_cfu;	// 'completefunc'
2838     char_u	*b_p_ofu;	// 'omnifunc'
2839 #endif
2840 #ifdef FEAT_EVAL
2841     char_u	*b_p_tfu;	// 'tagfunc'
2842 #endif
2843     int		b_p_eol;	// 'endofline'
2844     int		b_p_fixeol;	// 'fixendofline'
2845     int		b_p_et;		// 'expandtab'
2846     int		b_p_et_nobin;	// b_p_et saved for binary mode
2847     int		b_p_et_nopaste; // b_p_et saved for paste mode
2848     char_u	*b_p_fenc;	// 'fileencoding'
2849     char_u	*b_p_ff;	// 'fileformat'
2850     char_u	*b_p_ft;	// 'filetype'
2851     char_u	*b_p_fo;	// 'formatoptions'
2852     char_u	*b_p_flp;	// 'formatlistpat'
2853     int		b_p_inf;	// 'infercase'
2854     char_u	*b_p_isk;	// 'iskeyword'
2855 #ifdef FEAT_FIND_ID
2856     char_u	*b_p_def;	// 'define' local value
2857     char_u	*b_p_inc;	// 'include'
2858 # ifdef FEAT_EVAL
2859     char_u	*b_p_inex;	// 'includeexpr'
2860     long_u	b_p_inex_flags;	// flags for 'includeexpr'
2861 # endif
2862 #endif
2863 #if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
2864     char_u	*b_p_inde;	// 'indentexpr'
2865     long_u	b_p_inde_flags;	// flags for 'indentexpr'
2866     char_u	*b_p_indk;	// 'indentkeys'
2867 #endif
2868     char_u	*b_p_fp;	// 'formatprg'
2869 #if defined(FEAT_EVAL)
2870     char_u	*b_p_fex;	// 'formatexpr'
2871     long_u	b_p_fex_flags;	// flags for 'formatexpr'
2872 #endif
2873 #ifdef FEAT_CRYPT
2874     char_u	*b_p_key;	// 'key'
2875 #endif
2876     char_u	*b_p_kp;	// 'keywordprg'
2877 #ifdef FEAT_LISP
2878     int		b_p_lisp;	// 'lisp'
2879 #endif
2880     char_u	*b_p_menc;	// 'makeencoding'
2881     char_u	*b_p_mps;	// 'matchpairs'
2882     int		b_p_ml;		// 'modeline'
2883     int		b_p_ml_nobin;	// b_p_ml saved for binary mode
2884     int		b_p_ma;		// 'modifiable'
2885     char_u	*b_p_nf;	// 'nrformats'
2886     int		b_p_pi;		// 'preserveindent'
2887 #ifdef FEAT_TEXTOBJ
2888     char_u	*b_p_qe;	// 'quoteescape'
2889 #endif
2890     int		b_p_ro;		// 'readonly'
2891     long	b_p_sw;		// 'shiftwidth'
2892     int		b_p_sn;		// 'shortname'
2893 #ifdef FEAT_SMARTINDENT
2894     int		b_p_si;		// 'smartindent'
2895 #endif
2896     long	b_p_sts;	// 'softtabstop'
2897     long	b_p_sts_nopaste; // b_p_sts saved for paste mode
2898 #ifdef FEAT_SEARCHPATH
2899     char_u	*b_p_sua;	// 'suffixesadd'
2900 #endif
2901     int		b_p_swf;	// 'swapfile'
2902 #ifdef FEAT_SYN_HL
2903     long	b_p_smc;	// 'synmaxcol'
2904     char_u	*b_p_syn;	// 'syntax'
2905 #endif
2906     long	b_p_ts;		// 'tabstop'
2907     int		b_p_tx;		// 'textmode'
2908     long	b_p_tw;		// 'textwidth'
2909     long	b_p_tw_nobin;	// b_p_tw saved for binary mode
2910     long	b_p_tw_nopaste;	// b_p_tw saved for paste mode
2911     long	b_p_wm;		// 'wrapmargin'
2912     long	b_p_wm_nobin;	// b_p_wm saved for binary mode
2913     long	b_p_wm_nopaste;	// b_p_wm saved for paste mode
2914 #ifdef FEAT_VARTABS
2915     char_u	*b_p_vsts;	// 'varsofttabstop'
2916     int		*b_p_vsts_array;   // 'varsofttabstop' in internal format
2917     char_u	*b_p_vsts_nopaste; // b_p_vsts saved for paste mode
2918     char_u	*b_p_vts;	// 'vartabstop'
2919     int		*b_p_vts_array;	// 'vartabstop' in internal format
2920 #endif
2921 #ifdef FEAT_KEYMAP
2922     char_u	*b_p_keymap;	// 'keymap'
2923 #endif
2924 
2925     /*
2926      * local values for options which are normally global
2927      */
2928 #ifdef FEAT_QUICKFIX
2929     char_u	*b_p_gp;	// 'grepprg' local value
2930     char_u	*b_p_mp;	// 'makeprg' local value
2931     char_u	*b_p_efm;	// 'errorformat' local value
2932 #endif
2933     char_u	*b_p_ep;	// 'equalprg' local value
2934     char_u	*b_p_path;	// 'path' local value
2935     int		b_p_ar;		// 'autoread' local value
2936     char_u	*b_p_tags;	// 'tags' local value
2937     char_u	*b_p_tc;	// 'tagcase' local value
2938     unsigned	b_tc_flags;     // flags for 'tagcase'
2939     char_u	*b_p_dict;	// 'dictionary' local value
2940     char_u	*b_p_tsr;	// 'thesaurus' local value
2941     long	b_p_ul;		// 'undolevels' local value
2942 #ifdef FEAT_PERSISTENT_UNDO
2943     int		b_p_udf;	// 'undofile'
2944 #endif
2945 #ifdef FEAT_LISP
2946     char_u	*b_p_lw;	// 'lispwords' local value
2947 #endif
2948 #ifdef FEAT_TERMINAL
2949     long	b_p_twsl;	// 'termwinscroll'
2950 #endif
2951 
2952     /*
2953      * end of buffer options
2954      */
2955 
2956 #ifdef FEAT_CINDENT
2957     // values set from b_p_cino
2958     int		b_ind_level;
2959     int		b_ind_open_imag;
2960     int		b_ind_no_brace;
2961     int		b_ind_first_open;
2962     int		b_ind_open_extra;
2963     int		b_ind_close_extra;
2964     int		b_ind_open_left_imag;
2965     int		b_ind_jump_label;
2966     int		b_ind_case;
2967     int		b_ind_case_code;
2968     int		b_ind_case_break;
2969     int		b_ind_param;
2970     int		b_ind_func_type;
2971     int		b_ind_comment;
2972     int		b_ind_in_comment;
2973     int		b_ind_in_comment2;
2974     int		b_ind_cpp_baseclass;
2975     int		b_ind_continuation;
2976     int		b_ind_unclosed;
2977     int		b_ind_unclosed2;
2978     int		b_ind_unclosed_noignore;
2979     int		b_ind_unclosed_wrapped;
2980     int		b_ind_unclosed_whiteok;
2981     int		b_ind_matching_paren;
2982     int		b_ind_paren_prev;
2983     int		b_ind_maxparen;
2984     int		b_ind_maxcomment;
2985     int		b_ind_scopedecl;
2986     int		b_ind_scopedecl_code;
2987     int		b_ind_java;
2988     int		b_ind_js;
2989     int		b_ind_keep_case_label;
2990     int		b_ind_hash_comment;
2991     int		b_ind_cpp_namespace;
2992     int		b_ind_if_for_while;
2993     int		b_ind_cpp_extern_c;
2994     int		b_ind_pragma;
2995 #endif
2996 
2997     linenr_T	b_no_eol_lnum;	// non-zero lnum when last line of next binary
2998 				// write should not have an end-of-line
2999 
3000     int		b_start_eol;	// last line had eol when it was read
3001     int		b_start_ffc;	// first char of 'ff' when edit started
3002     char_u	*b_start_fenc;	// 'fileencoding' when edit started or NULL
3003     int		b_bad_char;	// "++bad=" argument when edit started or 0
3004     int		b_start_bomb;	// 'bomb' when it was read
3005 
3006 #ifdef FEAT_EVAL
3007     dictitem_T	b_bufvar;	// variable for "b:" Dictionary
3008     dict_T	*b_vars;	// internal variables, local to buffer
3009 
3010     listener_T	*b_listener;
3011     list_T	*b_recorded_changes;
3012 #endif
3013 #ifdef FEAT_PROP_POPUP
3014     int		b_has_textprop;	// TRUE when text props were added
3015     hashtab_T	*b_proptypes;	// text property types local to buffer
3016 #endif
3017 
3018 #if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
3019     char_u	*b_p_bexpr;	// 'balloonexpr' local value
3020     long_u	b_p_bexpr_flags;// flags for 'balloonexpr'
3021 #endif
3022 #ifdef FEAT_CRYPT
3023     char_u	*b_p_cm;	// 'cryptmethod'
3024 #endif
3025 
3026     // When a buffer is created, it starts without a swap file.  b_may_swap is
3027     // then set to indicate that a swap file may be opened later.  It is reset
3028     // if a swap file could not be opened.
3029     int		b_may_swap;
3030     int		b_did_warn;	// Set to 1 if user has been warned on first
3031 				// change of a read-only file
3032 
3033     // Two special kinds of buffers:
3034     // help buffer  - used for help files, won't use a swap file.
3035     // spell buffer - used for spell info, never displayed and doesn't have a
3036     //		      file name.
3037     int		b_help;		// TRUE for help file buffer (when set b_p_bt
3038 				// is "help")
3039 #ifdef FEAT_SPELL
3040     int		b_spell;	// TRUE for a spell file buffer, most fields
3041 				// are not used!  Use the B_SPELL macro to
3042 				// access b_spell without #ifdef.
3043 #endif
3044 
3045     int		b_shortname;	// this file has an 8.3 file name
3046 
3047 #ifdef FEAT_JOB_CHANNEL
3048     char_u	*b_prompt_text;		// set by prompt_setprompt()
3049     callback_T	b_prompt_callback;	// set by prompt_setcallback()
3050     callback_T	b_prompt_interrupt;	// set by prompt_setinterrupt()
3051     int		b_prompt_insert;	// value for restart_edit when entering
3052 					// a prompt buffer window.
3053 #endif
3054 #ifdef FEAT_MZSCHEME
3055     void	*b_mzscheme_ref; // The MzScheme reference to this buffer
3056 #endif
3057 
3058 #ifdef FEAT_PERL
3059     void	*b_perl_private;
3060 #endif
3061 
3062 #ifdef FEAT_PYTHON
3063     void	*b_python_ref;	// The Python reference to this buffer
3064 #endif
3065 
3066 #ifdef FEAT_PYTHON3
3067     void	*b_python3_ref;	// The Python3 reference to this buffer
3068 #endif
3069 
3070 #ifdef FEAT_TCL
3071     void	*b_tcl_ref;
3072 #endif
3073 
3074 #ifdef FEAT_RUBY
3075     void	*b_ruby_ref;
3076 #endif
3077 
3078 #if defined(FEAT_SYN_HL) || defined(FEAT_SPELL)
3079     synblock_T	b_s;		// Info related to syntax highlighting.  w_s
3080 				// normally points to this, but some windows
3081 				// may use a different synblock_T.
3082 #endif
3083 
3084 #ifdef FEAT_SIGNS
3085     sign_entry_T *b_signlist;	   // list of placed signs
3086 # ifdef FEAT_NETBEANS_INTG
3087     int		b_has_sign_column; // Flag that is set when a first sign is
3088 				   // added and remains set until the end of
3089 				   // the netbeans session.
3090 # endif
3091 #endif
3092 
3093 #ifdef FEAT_NETBEANS_INTG
3094     int		b_netbeans_file;    // TRUE when buffer is owned by NetBeans
3095     int		b_was_netbeans_file;// TRUE if b_netbeans_file was once set
3096 #endif
3097 #ifdef FEAT_JOB_CHANNEL
3098     int		b_write_to_channel; // TRUE when appended lines are written to
3099 				    // a channel.
3100 #endif
3101 
3102 #ifdef FEAT_CRYPT
3103     cryptstate_T *b_cryptstate;	// Encryption state while reading or writing
3104 				// the file. NULL when not using encryption.
3105 #endif
3106     int		b_mapped_ctrl_c; // modes where CTRL-C is mapped
3107 
3108 #ifdef FEAT_TERMINAL
3109     term_T	*b_term;	// When not NULL this buffer is for a terminal
3110 				// window.
3111 #endif
3112 #ifdef FEAT_DIFF
3113     int		b_diff_failed;	// internal diff failed for this buffer
3114 #endif
3115 }; // file_buffer
3116 
3117 
3118 #ifdef FEAT_DIFF
3119 /*
3120  * Stuff for diff mode.
3121  */
3122 # define DB_COUNT 8	// up to eight buffers can be diff'ed
3123 
3124 /*
3125  * Each diffblock defines where a block of lines starts in each of the buffers
3126  * and how many lines it occupies in that buffer.  When the lines are missing
3127  * in the buffer the df_count[] is zero.  This is all counted in
3128  * buffer lines.
3129  * There is always at least one unchanged line in between the diffs.
3130  * Otherwise it would have been included in the diff above or below it.
3131  * df_lnum[] + df_count[] is the lnum below the change.  When in one buffer
3132  * lines have been inserted, in the other buffer df_lnum[] is the line below
3133  * the insertion and df_count[] is zero.  When appending lines at the end of
3134  * the buffer, df_lnum[] is one beyond the end!
3135  * This is using a linked list, because the number of differences is expected
3136  * to be reasonable small.  The list is sorted on lnum.
3137  */
3138 typedef struct diffblock_S diff_T;
3139 struct diffblock_S
3140 {
3141     diff_T	*df_next;
3142     linenr_T	df_lnum[DB_COUNT];	// line number in buffer
3143     linenr_T	df_count[DB_COUNT];	// nr of inserted/changed lines
3144 };
3145 #endif
3146 
3147 #define SNAP_HELP_IDX	0
3148 #define SNAP_AUCMD_IDX 1
3149 #define SNAP_COUNT	2
3150 
3151 /*
3152  * Tab pages point to the top frame of each tab page.
3153  * Note: Most values are NOT valid for the current tab page!  Use "curwin",
3154  * "firstwin", etc. for that.  "tp_topframe" is always valid and can be
3155  * compared against "topframe" to find the current tab page.
3156  */
3157 typedef struct tabpage_S tabpage_T;
3158 struct tabpage_S
3159 {
3160     tabpage_T	    *tp_next;	    // next tabpage or NULL
3161     frame_T	    *tp_topframe;   // topframe for the windows
3162     win_T	    *tp_curwin;	    // current window in this Tab page
3163     win_T	    *tp_prevwin;    // previous window in this Tab page
3164     win_T	    *tp_firstwin;   // first window in this Tab page
3165     win_T	    *tp_lastwin;    // last window in this Tab page
3166 #ifdef FEAT_PROP_POPUP
3167     win_T	    *tp_first_popupwin; // first popup window in this Tab page
3168 #endif
3169     long	    tp_old_Rows;    // Rows when Tab page was left
3170     long	    tp_old_Columns; // Columns when Tab page was left
3171     long	    tp_ch_used;	    // value of 'cmdheight' when frame size
3172 				    // was set
3173 #ifdef FEAT_GUI
3174     int		    tp_prev_which_scrollbars[3];
3175 				    // previous value of which_scrollbars
3176 #endif
3177 
3178     char_u	    *tp_localdir;	// absolute path of local directory or
3179 					// NULL
3180     char_u	    *tp_prevdir;	// previous directory
3181 
3182 #ifdef FEAT_DIFF
3183     diff_T	    *tp_first_diff;
3184     buf_T	    *(tp_diffbuf[DB_COUNT]);
3185     int		    tp_diff_invalid;	// list of diffs is outdated
3186     int		    tp_diff_update;	// update diffs before redrawing
3187 #endif
3188     frame_T	    *(tp_snapshot[SNAP_COUNT]);  // window layout snapshots
3189 #ifdef FEAT_EVAL
3190     dictitem_T	    tp_winvar;	    // variable for "t:" Dictionary
3191     dict_T	    *tp_vars;	    // internal variables, local to tab page
3192 #endif
3193 
3194 #ifdef FEAT_PYTHON
3195     void	    *tp_python_ref;	// The Python value for this tab page
3196 #endif
3197 
3198 #ifdef FEAT_PYTHON3
3199     void	    *tp_python3_ref;	// The Python value for this tab page
3200 #endif
3201 };
3202 
3203 /*
3204  * Structure to cache info for displayed lines in w_lines[].
3205  * Each logical line has one entry.
3206  * The entry tells how the logical line is currently displayed in the window.
3207  * This is updated when displaying the window.
3208  * When the display is changed (e.g., when clearing the screen) w_lines_valid
3209  * is changed to exclude invalid entries.
3210  * When making changes to the buffer, wl_valid is reset to indicate wl_size
3211  * may not reflect what is actually in the buffer.  When wl_valid is FALSE,
3212  * the entries can only be used to count the number of displayed lines used.
3213  * wl_lnum and wl_lastlnum are invalid too.
3214  */
3215 typedef struct w_line
3216 {
3217     linenr_T	wl_lnum;	// buffer line number for logical line
3218     short_u	wl_size;	// height in screen lines
3219     char	wl_valid;	// TRUE values are valid for text in buffer
3220 #ifdef FEAT_FOLDING
3221     char	wl_folded;	// TRUE when this is a range of folded lines
3222     linenr_T	wl_lastlnum;	// last buffer line number for logical line
3223 #endif
3224 } wline_T;
3225 
3226 /*
3227  * Windows are kept in a tree of frames.  Each frame has a column (FR_COL)
3228  * or row (FR_ROW) layout or is a leaf, which has a window.
3229  */
3230 struct frame_S
3231 {
3232     char	fr_layout;	// FR_LEAF, FR_COL or FR_ROW
3233     int		fr_width;
3234     int		fr_newwidth;	// new width used in win_equal_rec()
3235     int		fr_height;
3236     int		fr_newheight;	// new height used in win_equal_rec()
3237     frame_T	*fr_parent;	// containing frame or NULL
3238     frame_T	*fr_next;	// frame right or below in same parent, NULL
3239 				// for last
3240     frame_T	*fr_prev;	// frame left or above in same parent, NULL
3241 				// for first
3242     // fr_child and fr_win are mutually exclusive
3243     frame_T	*fr_child;	// first contained frame
3244     win_T	*fr_win;	// window that fills this frame
3245 };
3246 
3247 #define FR_LEAF	0	// frame is a leaf
3248 #define FR_ROW	1	// frame with a row of windows
3249 #define FR_COL	2	// frame with a column of windows
3250 
3251 /*
3252  * Struct used for highlighting 'hlsearch' matches, matches defined by
3253  * ":match" and matches defined by match functions.
3254  * For 'hlsearch' there is one pattern for all windows.  For ":match" and the
3255  * match functions there is a different pattern for each window.
3256  */
3257 typedef struct
3258 {
3259     regmmatch_T	rm;	    // points to the regexp program; contains last
3260 			    // found match (may continue in next line)
3261     buf_T	*buf;	    // the buffer to search for a match
3262     linenr_T	lnum;	    // the line to search for a match
3263     int		attr;	    // attributes to be used for a match
3264     int		attr_cur;   // attributes currently active in win_line()
3265     linenr_T	first_lnum; // first lnum to search for multi-line pat
3266     colnr_T	startcol;   // in win_line() points to char where HL starts
3267     colnr_T	endcol;	    // in win_line() points to char where HL ends
3268     int		is_addpos;  // position specified directly by
3269 			    // matchaddpos(). TRUE/FALSE
3270 #ifdef FEAT_RELTIME
3271     proftime_T	tm;	    // for a time limit
3272 #endif
3273 } match_T;
3274 
3275 // number of positions supported by matchaddpos()
3276 #define MAXPOSMATCH 8
3277 
3278 /*
3279  * Same as lpos_T, but with additional field len.
3280  */
3281 typedef struct
3282 {
3283     linenr_T	lnum;	// line number
3284     colnr_T	col;	// column number
3285     int		len;	// length: 0 - to the end of line
3286 } llpos_T;
3287 
3288 /*
3289  * posmatch_T provides an array for storing match items for matchaddpos()
3290  * function.
3291  */
3292 typedef struct posmatch posmatch_T;
3293 struct posmatch
3294 {
3295     llpos_T	pos[MAXPOSMATCH];	// array of positions
3296     int		cur;			// internal position counter
3297     linenr_T	toplnum;		// top buffer line
3298     linenr_T	botlnum;		// bottom buffer line
3299 };
3300 
3301 /*
3302  * matchitem_T provides a linked list for storing match items for ":match" and
3303  * the match functions.
3304  */
3305 typedef struct matchitem matchitem_T;
3306 struct matchitem
3307 {
3308     matchitem_T	*next;
3309     int		id;	    // match ID
3310     int		priority;   // match priority
3311     char_u	*pattern;   // pattern to highlight
3312     regmmatch_T	match;	    // regexp program for pattern
3313     posmatch_T	pos;	    // position matches
3314     match_T	hl;	    // struct for doing the actual highlighting
3315     int		hlg_id;	    // highlight group ID
3316 #ifdef FEAT_CONCEAL
3317     int		conceal_char; // cchar for Conceal highlighting
3318 #endif
3319 };
3320 
3321 // Structure to store last cursor position and topline.  Used by check_lnums()
3322 // and reset_lnums().
3323 typedef struct
3324 {
3325     int		w_topline_save;	// original topline value
3326     int		w_topline_corr;	// corrected topline value
3327     pos_T	w_cursor_save;	// original cursor position
3328     pos_T	w_cursor_corr;	// corrected cursor position
3329 } pos_save_T;
3330 
3331 #ifdef FEAT_MENU
3332 typedef struct {
3333     int		wb_startcol;
3334     int		wb_endcol;
3335     vimmenu_T	*wb_menu;
3336 } winbar_item_T;
3337 #endif
3338 
3339 /*
3340  * Characters from the 'listchars' option
3341  */
3342 typedef struct
3343 {
3344     int		eol;
3345     int		ext;
3346     int		prec;
3347     int		nbsp;
3348     int		space;
3349     int		tab1;
3350     int		tab2;
3351     int		tab3;
3352     int		trail;
3353     int		lead;
3354 #ifdef FEAT_CONCEAL
3355     int		conceal;
3356 #endif
3357 } lcs_chars_T;
3358 
3359 /*
3360  * Structure which contains all information that belongs to a window
3361  *
3362  * All row numbers are relative to the start of the window, except w_winrow.
3363  */
3364 struct window_S
3365 {
3366     int		w_id;		    // unique window ID
3367 
3368     buf_T	*w_buffer;	    // buffer we are a window into
3369 
3370     win_T	*w_prev;	    // link to previous window
3371     win_T	*w_next;	    // link to next window
3372 
3373 #if defined(FEAT_SYN_HL) || defined(FEAT_SPELL)
3374     synblock_T	*w_s;		    // for :ownsyntax
3375 #endif
3376 
3377     int		w_closing;	    // window is being closed, don't let
3378 				    // autocommands close it too.
3379 
3380     frame_T	*w_frame;	    // frame containing this window
3381 
3382     pos_T	w_cursor;	    // cursor position in buffer
3383 
3384     colnr_T	w_curswant;	    // The column we'd like to be at.  This is
3385 				    // used to try to stay in the same column
3386 				    // for up/down cursor motions.
3387 
3388     int		w_set_curswant;	    // If set, then update w_curswant the next
3389 				    // time through cursupdate() to the
3390 				    // current virtual column
3391 
3392 #ifdef FEAT_SYN_HL
3393     linenr_T	w_last_cursorline;  // where last time 'cursorline' was drawn
3394 #endif
3395 
3396     /*
3397      * the next seven are used to update the Visual highlighting
3398      */
3399     char	w_old_visual_mode;  // last known VIsual_mode
3400     linenr_T	w_old_cursor_lnum;  // last known end of visual part
3401     colnr_T	w_old_cursor_fcol;  // first column for block visual part
3402     colnr_T	w_old_cursor_lcol;  // last column for block visual part
3403     linenr_T	w_old_visual_lnum;  // last known start of visual part
3404     colnr_T	w_old_visual_col;   // last known start of visual part
3405     colnr_T	w_old_curswant;	    // last known value of Curswant
3406 
3407     lcs_chars_T	w_lcs_chars;	    // 'listchars' characters
3408 
3409     /*
3410      * "w_topline", "w_leftcol" and "w_skipcol" specify the offsets for
3411      * displaying the buffer.
3412      */
3413     linenr_T	w_topline;	    // buffer line number of the line at the
3414 				    // top of the window
3415     char	w_topline_was_set;  // flag set to TRUE when topline is set,
3416 				    // e.g. by winrestview()
3417 
3418     linenr_T	w_botline;	    // number of the line below the bottom of
3419 				    // the window
3420 
3421 #ifdef FEAT_DIFF
3422     int		w_topfill;	    // number of filler lines above w_topline
3423     int		w_old_topfill;	    // w_topfill at last redraw
3424     int		w_botfill;	    // TRUE when filler lines are actually
3425 				    // below w_topline (at end of file)
3426     int		w_old_botfill;	    // w_botfill at last redraw
3427 #endif
3428     colnr_T	w_leftcol;	    // window column number of the left most
3429 				    // character in the window; used when
3430 				    // 'wrap' is off
3431     colnr_T	w_skipcol;	    // starting column when a single line
3432 				    // doesn't fit in the window
3433 
3434     int		w_empty_rows;	    // number of ~ rows in window
3435 #ifdef FEAT_DIFF
3436     int		w_filler_rows;	    // number of filler rows at the end of the
3437 				    // window
3438 #endif
3439 
3440     /*
3441      * Layout of the window in the screen.
3442      * May need to add "msg_scrolled" to "w_winrow" in rare situations.
3443      */
3444     int		w_winrow;	    // first row of window in screen
3445     int		w_height;	    // number of rows in window, excluding
3446 				    // status/command/winbar line(s)
3447 
3448     int		w_status_height;    // number of status lines (0 or 1)
3449     int		w_wincol;	    // Leftmost column of window in screen.
3450     int		w_width;	    // Width of window, excluding separation.
3451     int		w_vsep_width;	    // Number of separator columns (0 or 1).
3452 
3453     pos_save_T	w_save_cursor;	    // backup of cursor pos and topline
3454 
3455 #ifdef FEAT_PROP_POPUP
3456     int		w_popup_flags;	    // POPF_ values
3457     int		w_popup_handled;    // POPUP_HANDLE[0-9] flags
3458     char_u	*w_popup_title;
3459     poppos_T	w_popup_pos;
3460     int		w_popup_fixed;	    // do not shift popup to fit on screen
3461     int		w_popup_prop_type;  // when not zero: textprop type ID
3462     win_T	*w_popup_prop_win;  // window to search for textprop
3463     int		w_popup_prop_id;    // when not zero: textprop ID
3464     int		w_zindex;
3465     int		w_minheight;	    // "minheight" for popup window
3466     int		w_minwidth;	    // "minwidth" for popup window
3467     int		w_maxheight;	    // "maxheight" for popup window
3468     int		w_maxwidth;	    // "maxwidth" for popup window
3469     int		w_maxwidth_opt;	    // maxwidth from option
3470     int		w_wantline;	    // "line" for popup window
3471     int		w_wantcol;	    // "col" for popup window
3472     int		w_firstline;	    // "firstline" for popup window
3473     int		w_want_scrollbar;   // when zero don't use a scrollbar
3474     int		w_has_scrollbar;    // 1 if scrollbar displayed, 0 otherwise
3475     char_u	*w_scrollbar_highlight; // "scrollbarhighlight"
3476     char_u	*w_thumb_highlight; // "thumbhighlight"
3477     int		w_popup_padding[4]; // popup padding top/right/bot/left
3478     int		w_popup_border[4];  // popup border top/right/bot/left
3479     char_u	*w_border_highlight[4];  // popup border highlight
3480     int		w_border_char[8];   // popup border characters
3481 
3482     int		w_popup_leftoff;    // columns left of the screen
3483     int		w_popup_rightoff;   // columns right of the screen
3484     varnumber_T	w_popup_last_changedtick; // b:changedtick of popup buffer
3485 					  // when position was computed
3486     varnumber_T	w_popup_prop_changedtick; // b:changedtick of buffer with
3487 					  // w_popup_prop_type when position
3488 					  // was computed
3489     int		w_popup_prop_topline; // w_topline of window with
3490 				      // w_popup_prop_type when position was
3491 				      // computed
3492     linenr_T	w_popup_last_curline; // last known w_cursor.lnum of window
3493 				      // with "cursorline" set
3494     callback_T	w_close_cb;	    // popup close callback
3495     callback_T	w_filter_cb;	    // popup filter callback
3496     int		w_filter_errors;    // popup filter error count
3497     int		w_filter_mode;	    // mode when filter callback is used
3498 
3499     win_T	*w_popup_curwin;    // close popup if curwin differs
3500     linenr_T	w_popup_lnum;	    // close popup if cursor not on this line
3501     colnr_T	w_popup_mincol;	    // close popup if cursor before this col
3502     colnr_T	w_popup_maxcol;	    // close popup if cursor after this col
3503     int		w_popup_mouse_row;  // close popup if mouse moves away
3504     int		w_popup_mouse_mincol;  // close popup if mouse moves away
3505     int		w_popup_mouse_maxcol;  // close popup if mouse moves away
3506     popclose_T	w_popup_close;	    // allow closing the popup with the mouse
3507 
3508     list_T	*w_popup_mask;	     // list of lists for "mask"
3509     char_u	*w_popup_mask_cells; // cached mask cells
3510     int		w_popup_mask_height; // height of w_popup_mask_cells
3511     int		w_popup_mask_width;  // width of w_popup_mask_cells
3512 # if defined(FEAT_TIMERS)
3513     timer_T	*w_popup_timer;	    // timer for closing popup window
3514 # endif
3515 
3516     int		w_flags;	    // WFLAG_ flags
3517 
3518 # define WFLAG_WCOL_OFF_ADDED	1   // popup border and padding were added to
3519 				    // w_wcol
3520 # define WFLAG_WROW_OFF_ADDED	2   // popup border and padding were added to
3521 				    // w_wrow
3522 #endif
3523 
3524     /*
3525      * === start of cached values ====
3526      */
3527     /*
3528      * Recomputing is minimized by storing the result of computations.
3529      * Use functions in screen.c to check if they are valid and to update.
3530      * w_valid is a bitfield of flags, which indicate if specific values are
3531      * valid or need to be recomputed.	See screen.c for values.
3532      */
3533     int		w_valid;
3534     pos_T	w_valid_cursor;	    // last known position of w_cursor, used
3535 				    // to adjust w_valid
3536     colnr_T	w_valid_leftcol;    // last known w_leftcol
3537 
3538     /*
3539      * w_cline_height is the number of physical lines taken by the buffer line
3540      * that the cursor is on.  We use this to avoid extra calls to plines().
3541      */
3542     int		w_cline_height;	    // current size of cursor line
3543 #ifdef FEAT_FOLDING
3544     int		w_cline_folded;	    // cursor line is folded
3545 #endif
3546 
3547     int		w_cline_row;	    // starting row of the cursor line
3548 
3549     colnr_T	w_virtcol;	    // column number of the cursor in the
3550 				    // buffer line, as opposed to the column
3551 				    // number we're at on the screen.  This
3552 				    // makes a difference on lines which span
3553 				    // more than one screen line or when
3554 				    // w_leftcol is non-zero
3555 
3556     /*
3557      * w_wrow and w_wcol specify the cursor position in the window.
3558      * This is related to positions in the window, not in the display or
3559      * buffer, thus w_wrow is relative to w_winrow.
3560      */
3561     int		w_wrow, w_wcol;	    // cursor position in window
3562 
3563     /*
3564      * Info about the lines currently in the window is remembered to avoid
3565      * recomputing it every time.  The allocated size of w_lines[] is Rows.
3566      * Only the w_lines_valid entries are actually valid.
3567      * When the display is up-to-date w_lines[0].wl_lnum is equal to w_topline
3568      * and w_lines[w_lines_valid - 1].wl_lnum is equal to w_botline.
3569      * Between changing text and updating the display w_lines[] represents
3570      * what is currently displayed.  wl_valid is reset to indicated this.
3571      * This is used for efficient redrawing.
3572      */
3573     int		w_lines_valid;	    // number of valid entries
3574     wline_T	*w_lines;
3575 
3576 #ifdef FEAT_FOLDING
3577     garray_T	w_folds;	    // array of nested folds
3578     char	w_fold_manual;	    // when TRUE: some folds are opened/closed
3579 				    // manually
3580     char	w_foldinvalid;	    // when TRUE: folding needs to be
3581 				    // recomputed
3582 #endif
3583 #ifdef FEAT_LINEBREAK
3584     int		w_nrwidth;	    // width of 'number' and 'relativenumber'
3585 				    // column being used
3586 #endif
3587 
3588     /*
3589      * === end of cached values ===
3590      */
3591 
3592     int		w_redr_type;	    // type of redraw to be performed on win
3593     int		w_upd_rows;	    // number of window lines to update when
3594 				    // w_redr_type is REDRAW_TOP
3595     linenr_T	w_redraw_top;	    // when != 0: first line needing redraw
3596     linenr_T	w_redraw_bot;	    // when != 0: last line needing redraw
3597     int		w_redr_status;	    // if TRUE status line must be redrawn
3598 
3599 #ifdef FEAT_CMDL_INFO
3600     // remember what is shown in the ruler for this window (if 'ruler' set)
3601     pos_T	w_ru_cursor;	    // cursor position shown in ruler
3602     colnr_T	w_ru_virtcol;	    // virtcol shown in ruler
3603     linenr_T	w_ru_topline;	    // topline shown in ruler
3604     linenr_T	w_ru_line_count;    // line count used for ruler
3605 # ifdef FEAT_DIFF
3606     int		w_ru_topfill;	    // topfill shown in ruler
3607 # endif
3608     char	w_ru_empty;	    // TRUE if ruler shows 0-1 (empty line)
3609 #endif
3610 
3611     int		w_alt_fnum;	    // alternate file (for # and CTRL-^)
3612 
3613     alist_T	*w_alist;	    // pointer to arglist for this window
3614     int		w_arg_idx;	    // current index in argument list (can be
3615 				    // out of range!)
3616     int		w_arg_idx_invalid;  // editing another file than w_arg_idx
3617 
3618     char_u	*w_localdir;	    // absolute path of local directory or
3619 				    // NULL
3620     char_u	*w_prevdir;	    // previous directory
3621 #ifdef FEAT_MENU
3622     vimmenu_T	*w_winbar;	    // The root of the WinBar menu hierarchy.
3623     winbar_item_T *w_winbar_items;  // list of items in the WinBar
3624     int		w_winbar_height;    // 1 if there is a window toolbar
3625 #endif
3626 
3627     /*
3628      * Options local to a window.
3629      * They are local because they influence the layout of the window or
3630      * depend on the window layout.
3631      * There are two values: w_onebuf_opt is local to the buffer currently in
3632      * this window, w_allbuf_opt is for all buffers in this window.
3633      */
3634     winopt_T	w_onebuf_opt;
3635     winopt_T	w_allbuf_opt;
3636 
3637     // A few options have local flags for P_INSECURE.
3638 #ifdef FEAT_STL_OPT
3639     long_u	w_p_stl_flags;	    // flags for 'statusline'
3640 #endif
3641 #ifdef FEAT_EVAL
3642     long_u	w_p_fde_flags;	    // flags for 'foldexpr'
3643     long_u	w_p_fdt_flags;	    // flags for 'foldtext'
3644 #endif
3645 #ifdef FEAT_SYN_HL
3646     int		*w_p_cc_cols;	    // array of columns to highlight or NULL
3647     char_u	w_p_culopt_flags;   // flags for cursorline highlighting
3648 #endif
3649     long	w_p_siso;	    // 'sidescrolloff' local value
3650     long	w_p_so;		    // 'scrolloff' local value
3651 
3652 #ifdef FEAT_LINEBREAK
3653     int		w_briopt_min;	    // minimum width for breakindent
3654     int		w_briopt_shift;	    // additional shift for breakindent
3655     int		w_briopt_sbr;	    // sbr in 'briopt'
3656 #endif
3657 
3658     // transform a pointer to a "onebuf" option into a "allbuf" option
3659 #define GLOBAL_WO(p)	((char *)p + sizeof(winopt_T))
3660 
3661     long	w_scbind_pos;
3662 
3663 #ifdef FEAT_EVAL
3664     dictitem_T	w_winvar;	// variable for "w:" Dictionary
3665     dict_T	*w_vars;	// internal variables, local to window
3666 #endif
3667 
3668     /*
3669      * The w_prev_pcmark field is used to check whether we really did jump to
3670      * a new line after setting the w_pcmark.  If not, then we revert to
3671      * using the previous w_pcmark.
3672      */
3673     pos_T	w_pcmark;	// previous context mark
3674     pos_T	w_prev_pcmark;	// previous w_pcmark
3675 
3676 #ifdef FEAT_JUMPLIST
3677     /*
3678      * the jumplist contains old cursor positions
3679      */
3680     xfmark_T	w_jumplist[JUMPLISTSIZE];
3681     int		w_jumplistlen;		// number of active entries
3682     int		w_jumplistidx;		// current position
3683 
3684     int		w_changelistidx;	// current position in b_changelist
3685 #endif
3686 
3687 #ifdef FEAT_SEARCH_EXTRA
3688     matchitem_T	*w_match_head;		// head of match list
3689     int		w_next_match_id;	// next match ID
3690 #endif
3691 
3692     /*
3693      * the tagstack grows from 0 upwards:
3694      * entry 0: older
3695      * entry 1: newer
3696      * entry 2: newest
3697      */
3698     taggy_T	w_tagstack[TAGSTACKSIZE];   // the tag stack
3699     int		w_tagstackidx;		    // idx just below active entry
3700     int		w_tagstacklen;		    // number of tags on stack
3701 
3702     /*
3703      * w_fraction is the fractional row of the cursor within the window, from
3704      * 0 at the top row to FRACTION_MULT at the last row.
3705      * w_prev_fraction_row was the actual cursor row when w_fraction was last
3706      * calculated.
3707      */
3708     int		w_fraction;
3709     int		w_prev_fraction_row;
3710 
3711 #ifdef FEAT_GUI
3712     scrollbar_T	w_scrollbars[2];	// vert. Scrollbars for this window
3713 #endif
3714 #ifdef FEAT_LINEBREAK
3715     linenr_T	w_nrwidth_line_count;	// line count when ml_nrwidth_width
3716 					// was computed.
3717     long	w_nuw_cached;		// 'numberwidth' option cached
3718     int		w_nrwidth_width;	// nr of chars to print line count.
3719 #endif
3720 
3721 #ifdef FEAT_QUICKFIX
3722     qf_info_T	*w_llist;		// Location list for this window
3723     /*
3724      * Location list reference used in the location list window.
3725      * In a non-location list window, w_llist_ref is NULL.
3726      */
3727     qf_info_T	*w_llist_ref;
3728 #endif
3729 
3730 #ifdef FEAT_MZSCHEME
3731     void	*w_mzscheme_ref;	// The MzScheme value for this window
3732 #endif
3733 
3734 #ifdef FEAT_PERL
3735     void	*w_perl_private;
3736 #endif
3737 
3738 #ifdef FEAT_PYTHON
3739     void	*w_python_ref;		// The Python value for this window
3740 #endif
3741 
3742 #ifdef FEAT_PYTHON3
3743     void	*w_python3_ref;		// The Python value for this window
3744 #endif
3745 
3746 #ifdef FEAT_TCL
3747     void	*w_tcl_ref;
3748 #endif
3749 
3750 #ifdef FEAT_RUBY
3751     void	*w_ruby_ref;
3752 #endif
3753 };
3754 
3755 /*
3756  * Arguments for operators.
3757  */
3758 typedef struct oparg_S
3759 {
3760     int		op_type;	// current pending operator type
3761     int		regname;	// register to use for the operator
3762     int		motion_type;	// type of the current cursor motion
3763     int		motion_force;	// force motion type: 'v', 'V' or CTRL-V
3764     int		use_reg_one;	// TRUE if delete uses reg 1 even when not
3765 				// linewise
3766     int		inclusive;	// TRUE if char motion is inclusive (only
3767 				// valid when motion_type is MCHAR
3768     int		end_adjusted;	// backuped b_op_end one char (only used by
3769 				// do_format())
3770     pos_T	start;		// start of the operator
3771     pos_T	end;		// end of the operator
3772     pos_T	cursor_start;	// cursor position before motion for "gw"
3773 
3774     long	line_count;	// number of lines from op_start to op_end
3775 				// (inclusive)
3776     int		empty;		// op_start and op_end the same (only used by
3777 				// do_change())
3778     int		is_VIsual;	// operator on Visual area
3779     int		block_mode;	// current operator is Visual block mode
3780     colnr_T	start_vcol;	// start col for block mode operator
3781     colnr_T	end_vcol;	// end col for block mode operator
3782     long	prev_opcount;	// ca.opcount saved for K_CURSORHOLD
3783     long	prev_count0;	// ca.count0 saved for K_CURSORHOLD
3784 } oparg_T;
3785 
3786 /*
3787  * Arguments for Normal mode commands.
3788  */
3789 typedef struct cmdarg_S
3790 {
3791     oparg_T	*oap;		// Operator arguments
3792     int		prechar;	// prefix character (optional, always 'g')
3793     int		cmdchar;	// command character
3794     int		nchar;		// next command character (optional)
3795     int		ncharC1;	// first composing character (optional)
3796     int		ncharC2;	// second composing character (optional)
3797     int		extra_char;	// yet another character (optional)
3798     long	opcount;	// count before an operator
3799     long	count0;		// count before command, default 0
3800     long	count1;		// count before command, default 1
3801     int		arg;		// extra argument from nv_cmds[]
3802     int		retval;		// return: CA_* values
3803     char_u	*searchbuf;	// return: pointer to search pattern or NULL
3804 } cmdarg_T;
3805 
3806 // values for retval:
3807 #define CA_COMMAND_BUSY	    1	// skip restarting edit() once
3808 #define CA_NO_ADJ_OP_END    2	// don't adjust operator end
3809 
3810 #ifdef CURSOR_SHAPE
3811 /*
3812  * struct to store values from 'guicursor' and 'mouseshape'
3813  */
3814 // Indexes in shape_table[]
3815 #define SHAPE_IDX_N	0	// Normal mode
3816 #define SHAPE_IDX_V	1	// Visual mode
3817 #define SHAPE_IDX_I	2	// Insert mode
3818 #define SHAPE_IDX_R	3	// Replace mode
3819 #define SHAPE_IDX_C	4	// Command line Normal mode
3820 #define SHAPE_IDX_CI	5	// Command line Insert mode
3821 #define SHAPE_IDX_CR	6	// Command line Replace mode
3822 #define SHAPE_IDX_O	7	// Operator-pending mode
3823 #define SHAPE_IDX_VE	8	// Visual mode with 'selection' exclusive
3824 #define SHAPE_IDX_CLINE	9	// On command line
3825 #define SHAPE_IDX_STATUS 10	// A status line
3826 #define SHAPE_IDX_SDRAG 11	// dragging a status line
3827 #define SHAPE_IDX_VSEP	12	// A vertical separator line
3828 #define SHAPE_IDX_VDRAG 13	// dragging a vertical separator line
3829 #define SHAPE_IDX_MORE	14	// Hit-return or More
3830 #define SHAPE_IDX_MOREL	15	// Hit-return or More in last line
3831 #define SHAPE_IDX_SM	16	// showing matching paren
3832 #define SHAPE_IDX_COUNT	17
3833 
3834 #define SHAPE_BLOCK	0	// block cursor
3835 #define SHAPE_HOR	1	// horizontal bar cursor
3836 #define SHAPE_VER	2	// vertical bar cursor
3837 
3838 #define MSHAPE_NUMBERED	1000	// offset for shapes identified by number
3839 #define MSHAPE_HIDE	1	// hide mouse pointer
3840 
3841 #define SHAPE_MOUSE	1	// used for mouse pointer shape
3842 #define SHAPE_CURSOR	2	// used for text cursor shape
3843 
3844 typedef struct cursor_entry
3845 {
3846     int		shape;		// one of the SHAPE_ defines
3847     int		mshape;		// one of the MSHAPE defines
3848     int		percentage;	// percentage of cell for bar
3849     long	blinkwait;	// blinking, wait time before blinking starts
3850     long	blinkon;	// blinking, on time
3851     long	blinkoff;	// blinking, off time
3852     int		id;		// highlight group ID
3853     int		id_lm;		// highlight group ID for :lmap mode
3854     char	*name;		// mode name (fixed)
3855     char	used_for;	// SHAPE_MOUSE and/or SHAPE_CURSOR
3856 } cursorentry_T;
3857 #endif // CURSOR_SHAPE
3858 
3859 #ifdef FEAT_MENU
3860 
3861 // Indices into vimmenu_T->strings[] and vimmenu_T->noremap[] for each mode
3862 #define MENU_INDEX_INVALID	-1
3863 #define MENU_INDEX_NORMAL	0
3864 #define MENU_INDEX_VISUAL	1
3865 #define MENU_INDEX_SELECT	2
3866 #define MENU_INDEX_OP_PENDING	3
3867 #define MENU_INDEX_INSERT	4
3868 #define MENU_INDEX_CMDLINE	5
3869 #define MENU_INDEX_TERMINAL	6
3870 #define MENU_INDEX_TIP		7
3871 #define MENU_MODES		8
3872 
3873 // Menu modes
3874 #define MENU_NORMAL_MODE	(1 << MENU_INDEX_NORMAL)
3875 #define MENU_VISUAL_MODE	(1 << MENU_INDEX_VISUAL)
3876 #define MENU_SELECT_MODE	(1 << MENU_INDEX_SELECT)
3877 #define MENU_OP_PENDING_MODE	(1 << MENU_INDEX_OP_PENDING)
3878 #define MENU_INSERT_MODE	(1 << MENU_INDEX_INSERT)
3879 #define MENU_CMDLINE_MODE	(1 << MENU_INDEX_CMDLINE)
3880 #define MENU_TERMINAL_MODE	(1 << MENU_INDEX_TERMINAL)
3881 #define MENU_TIP_MODE		(1 << MENU_INDEX_TIP)
3882 #define MENU_ALL_MODES		((1 << MENU_INDEX_TIP) - 1)
3883 // note MENU_INDEX_TIP is not a 'real' mode
3884 
3885 // Start a menu name with this to not include it on the main menu bar
3886 #define MNU_HIDDEN_CHAR		']'
3887 
3888 struct VimMenu
3889 {
3890     int		modes;		    // Which modes is this menu visible for?
3891     int		enabled;	    // for which modes the menu is enabled
3892     char_u	*name;		    // Name of menu, possibly translated
3893     char_u	*dname;		    // Displayed Name ("name" without '&')
3894 #ifdef FEAT_MULTI_LANG
3895     char_u	*en_name;	    // "name" untranslated, NULL when "name"
3896 				    // was not translated
3897     char_u	*en_dname;	    // "dname" untranslated, NULL when "dname"
3898 				    // was not translated
3899 #endif
3900     int		mnemonic;	    // mnemonic key (after '&')
3901     char_u	*actext;	    // accelerator text (after TAB)
3902     int		priority;	    // Menu order priority
3903 #ifdef FEAT_GUI
3904     void	(*cb)(vimmenu_T *); // Call-back function
3905 #endif
3906 #ifdef FEAT_TOOLBAR
3907     char_u	*iconfile;	    // name of file for icon or NULL
3908     int		iconidx;	    // icon index (-1 if not set)
3909     int		icon_builtin;	    // icon names is BuiltIn{nr}
3910 #endif
3911     char_u	*strings[MENU_MODES]; // Mapped string for each mode
3912     int		noremap[MENU_MODES]; // A REMAP_ flag for each mode
3913     char	silent[MENU_MODES]; // A silent flag for each mode
3914     vimmenu_T	*children;	    // Children of sub-menu
3915     vimmenu_T	*parent;	    // Parent of menu
3916     vimmenu_T	*next;		    // Next item in menu
3917 #ifdef FEAT_GUI_X11
3918     Widget	id;		    // Manage this to enable item
3919     Widget	submenu_id;	    // If this is submenu, add children here
3920 #endif
3921 #ifdef FEAT_GUI_GTK
3922     GtkWidget	*id;		    // Manage this to enable item
3923     GtkWidget	*submenu_id;	    // If this is submenu, add children here
3924 # if defined(GTK_CHECK_VERSION) && !GTK_CHECK_VERSION(3,4,0)
3925     GtkWidget	*tearoff_handle;
3926 # endif
3927     GtkWidget   *label;		    // Used by "set wak=" code.
3928 #endif
3929 #ifdef FEAT_GUI_MOTIF
3930     int		sensitive;	    // turn button on/off
3931     char	**xpm;		    // pixmap data
3932     char	*xpm_fname;	    // file with pixmap data
3933 #endif
3934 #ifdef FEAT_GUI_ATHENA
3935     Pixmap	image;		    // Toolbar image
3936 #endif
3937 #ifdef FEAT_BEVAL_TIP
3938     BalloonEval *tip;		    // tooltip for this menu item
3939 #endif
3940 #ifdef FEAT_GUI_MSWIN
3941     UINT	id;		    // Id of menu item
3942     HMENU	submenu_id;	    // If this is submenu, add children here
3943     HWND	tearoff_handle;	    // hWnd of tearoff if created
3944 #endif
3945 #if FEAT_GUI_HAIKU
3946     BMenuItem  *id;		    // Id of menu item
3947     BMenu  *submenu_id;		    // If this is submenu, add children here
3948 # ifdef FEAT_TOOLBAR
3949     BPictureButton *button;
3950 # endif
3951 #endif
3952 #ifdef FEAT_GUI_PHOTON
3953     PtWidget_t	*id;
3954     PtWidget_t	*submenu_id;
3955 #endif
3956 };
3957 #else
3958 // For generating prototypes when FEAT_MENU isn't defined.
3959 typedef int vimmenu_T;
3960 
3961 #endif // FEAT_MENU
3962 
3963 /*
3964  * Struct to save values in before executing autocommands for a buffer that is
3965  * not the current buffer.
3966  */
3967 typedef struct
3968 {
3969     buf_T	*save_curbuf;	    // saved curbuf
3970     int		use_aucmd_win;	    // using aucmd_win
3971     int		save_curwin_id;	    // ID of saved curwin
3972     int		new_curwin_id;	    // ID of new curwin
3973     int		save_prevwin_id;    // ID of saved prevwin
3974     bufref_T	new_curbuf;	    // new curbuf
3975     char_u	*globaldir;	    // saved value of globaldir
3976 } aco_save_T;
3977 
3978 /*
3979  * Generic option table item, only used for printer at the moment.
3980  */
3981 typedef struct
3982 {
3983     const char	*name;
3984     int		hasnum;
3985     long	number;
3986     char_u	*string;	// points into option string
3987     int		strlen;
3988     int		present;
3989 } option_table_T;
3990 
3991 /*
3992  * Structure to hold printing color and font attributes.
3993  */
3994 typedef struct
3995 {
3996     long_u	fg_color;
3997     long_u	bg_color;
3998     int		bold;
3999     int		italic;
4000     int		underline;
4001     int		undercurl;
4002 } prt_text_attr_T;
4003 
4004 /*
4005  * Structure passed back to the generic printer code.
4006  */
4007 typedef struct
4008 {
4009     int		n_collated_copies;
4010     int		n_uncollated_copies;
4011     int		duplex;
4012     int		chars_per_line;
4013     int		lines_per_page;
4014     int		has_color;
4015     prt_text_attr_T number;
4016 #ifdef FEAT_SYN_HL
4017     int		modec;
4018     int		do_syntax;
4019 #endif
4020     int		user_abort;
4021     char_u	*jobname;
4022 #ifdef FEAT_POSTSCRIPT
4023     char_u	*outfile;
4024     char_u	*arguments;
4025 #endif
4026 } prt_settings_T;
4027 
4028 #define PRINT_NUMBER_WIDTH 8
4029 
4030 /*
4031  * Used for popup menu items.
4032  */
4033 typedef struct
4034 {
4035     char_u	*pum_text;	// main menu text
4036     char_u	*pum_kind;	// extra kind text (may be truncated)
4037     char_u	*pum_extra;	// extra menu text (may be truncated)
4038     char_u	*pum_info;	// extra info
4039 } pumitem_T;
4040 
4041 /*
4042  * Structure used for get_tagfname().
4043  */
4044 typedef struct
4045 {
4046     char_u	*tn_tags;	// value of 'tags' when starting
4047     char_u	*tn_np;		// current position in tn_tags
4048     int		tn_did_filefind_init;
4049     int		tn_hf_idx;
4050     void	*tn_search_ctx;
4051 } tagname_T;
4052 
4053 typedef struct {
4054   UINT32_T total[2];
4055   UINT32_T state[8];
4056   char_u   buffer[64];
4057 } context_sha256_T;
4058 
4059 /*
4060  * types for expressions.
4061  */
4062 typedef enum
4063 {
4064     EXPR_UNKNOWN = 0,
4065     EXPR_EQUAL,		// ==
4066     EXPR_NEQUAL,	// !=
4067     EXPR_GREATER,	// >
4068     EXPR_GEQUAL,	// >=
4069     EXPR_SMALLER,	// <
4070     EXPR_SEQUAL,	// <=
4071     EXPR_MATCH,		// =~
4072     EXPR_NOMATCH,	// !~
4073     EXPR_IS,		// is
4074     EXPR_ISNOT,		// isnot
4075     // used with ISN_OPNR
4076     EXPR_ADD,		// +
4077     EXPR_SUB,		// -
4078     EXPR_MULT,		// *
4079     EXPR_DIV,		// /
4080     EXPR_REM,		// %
4081 } exprtype_T;
4082 
4083 /*
4084  * Structure used for reading in json_decode().
4085  */
4086 struct js_reader
4087 {
4088     char_u	*js_buf;	// text to be decoded
4089     char_u	*js_end;	// NUL in js_buf
4090     int		js_used;	// bytes used from js_buf
4091     int		(*js_fill)(struct js_reader *);
4092 				// function to fill the buffer or NULL;
4093 				// return TRUE when the buffer was filled
4094     void	*js_cookie;	// can be used by js_fill
4095     int		js_cookie_arg;	// can be used by js_fill
4096 };
4097 typedef struct js_reader js_read_T;
4098 
4099 // Maximum number of commands from + or -c arguments.
4100 #define MAX_ARG_CMDS 10
4101 
4102 // values for "window_layout"
4103 #define WIN_HOR	    1	    // "-o" horizontally split windows
4104 #define	WIN_VER	    2	    // "-O" vertically split windows
4105 #define	WIN_TABS    3	    // "-p" windows on tab pages
4106 
4107 // Struct for various parameters passed between main() and other functions.
4108 typedef struct
4109 {
4110     int		argc;
4111     char	**argv;
4112 
4113     char_u	*fname;			// first file to edit
4114 
4115     int		evim_mode;		// started as "evim"
4116     char_u	*use_vimrc;		// vimrc from -u argument
4117     int		clean;			// --clean argument
4118 
4119     int		n_commands;		     // no. of commands from + or -c
4120     char_u	*commands[MAX_ARG_CMDS];     // commands from + or -c arg.
4121     char_u	cmds_tofree[MAX_ARG_CMDS];   // commands that need free()
4122     int		n_pre_commands;		     // no. of commands from --cmd
4123     char_u	*pre_commands[MAX_ARG_CMDS]; // commands from --cmd argument
4124 
4125     int		edit_type;		// type of editing to do
4126     char_u	*tagname;		// tag from -t argument
4127 #ifdef FEAT_QUICKFIX
4128     char_u	*use_ef;		// 'errorfile' from -q argument
4129 #endif
4130 
4131     int		want_full_screen;
4132     int		not_a_term;		// no warning for missing term?
4133     int		tty_fail;		// exit if not a tty
4134     char_u	*term;			// specified terminal name
4135 #ifdef FEAT_CRYPT
4136     int		ask_for_key;		// -x argument
4137 #endif
4138     int		no_swap_file;		// "-n" argument used
4139 #ifdef FEAT_EVAL
4140     int		use_debug_break_level;
4141 #endif
4142     int		window_count;		// number of windows to use
4143     int		window_layout;		// 0, WIN_HOR, WIN_VER or WIN_TABS
4144 
4145 #ifdef FEAT_CLIENTSERVER
4146     int		serverArg;		// TRUE when argument for a server
4147     char_u	*serverName_arg;	// cmdline arg for server name
4148     char_u	*serverStr;		// remote server command
4149     char_u	*serverStrEnc;		// encoding of serverStr
4150     char_u	*servername;		// allocated name for our server
4151 #endif
4152 #if !defined(UNIX)
4153 # define EXPAND_FILENAMES
4154     int		literal;		// don't expand file names
4155 #endif
4156 #ifdef MSWIN
4157     int		full_path;		// file name argument was full path
4158 #endif
4159 #ifdef FEAT_DIFF
4160     int		diff_mode;		// start with 'diff' set
4161 #endif
4162 } mparm_T;
4163 
4164 /*
4165  * Structure returned by get_lval() and used by set_var_lval().
4166  * For a plain name:
4167  *	"name"	    points to the variable name.
4168  *	"exp_name"  is NULL.
4169  *	"tv"	    is NULL
4170  * For a magic braces name:
4171  *	"name"	    points to the expanded variable name.
4172  *	"exp_name"  is non-NULL, to be freed later.
4173  *	"tv"	    is NULL
4174  * For an index in a list:
4175  *	"name"	    points to the (expanded) variable name.
4176  *	"exp_name"  NULL or non-NULL, to be freed later.
4177  *	"tv"	    points to the (first) list item value
4178  *	"li"	    points to the (first) list item
4179  *	"range", "n1", "n2" and "empty2" indicate what items are used.
4180  * For an existing Dict item:
4181  *	"name"	    points to the (expanded) variable name.
4182  *	"exp_name"  NULL or non-NULL, to be freed later.
4183  *	"tv"	    points to the dict item value
4184  *	"newkey"    is NULL
4185  * For a non-existing Dict item:
4186  *	"name"	    points to the (expanded) variable name.
4187  *	"exp_name"  NULL or non-NULL, to be freed later.
4188  *	"tv"	    points to the Dictionary typval_T
4189  *	"newkey"    is the key for the new item.
4190  */
4191 typedef struct lval_S
4192 {
4193     char_u	*ll_name;	// start of variable name (can be NULL)
4194     char_u	*ll_name_end;	// end of variable name (can be NULL)
4195     type_T	*ll_type;	// type of variable (can be NULL)
4196     char_u	*ll_exp_name;	// NULL or expanded name in allocated memory.
4197     typval_T	*ll_tv;		// Typeval of item being used.  If "newkey"
4198 				// isn't NULL it's the Dict to which to add
4199 				// the item.
4200     listitem_T	*ll_li;		// The list item or NULL.
4201     list_T	*ll_list;	// The list or NULL.
4202     int		ll_range;	// TRUE when a [i:j] range was used
4203     int		ll_empty2;	// Second index is empty: [i:]
4204     long	ll_n1;		// First index for list
4205     long	ll_n2;		// Second index for list range
4206     dict_T	*ll_dict;	// The Dictionary or NULL
4207     dictitem_T	*ll_di;		// The dictitem or NULL
4208     char_u	*ll_newkey;	// New key for Dict in alloc. mem or NULL.
4209     type_T	*ll_valtype;	// type expected for the value or NULL
4210     blob_T	*ll_blob;	// The Blob or NULL
4211 } lval_T;
4212 
4213 // Structure used to save the current state.  Used when executing Normal mode
4214 // commands while in any other mode.
4215 typedef struct {
4216     int		save_msg_scroll;
4217     int		save_restart_edit;
4218     int		save_msg_didout;
4219     int		save_State;
4220     int		save_insertmode;
4221     int		save_finish_op;
4222     int		save_opcount;
4223     int		save_reg_executing;
4224     int		save_script_version;
4225     tasave_T	tabuf;
4226 } save_state_T;
4227 
4228 typedef struct {
4229     varnumber_T vv_prevcount;
4230     varnumber_T vv_count;
4231     varnumber_T vv_count1;
4232 } vimvars_save_T;
4233 
4234 // Scope for changing directory
4235 typedef enum {
4236     CDSCOPE_GLOBAL,	// :cd
4237     CDSCOPE_TABPAGE,	// :tcd
4238     CDSCOPE_WINDOW	// :lcd
4239 } cdscope_T;
4240 
4241 // Variable flavor
4242 typedef enum
4243 {
4244     VAR_FLAVOUR_DEFAULT,	// doesn't start with uppercase
4245     VAR_FLAVOUR_SESSION,	// starts with uppercase, some lower
4246     VAR_FLAVOUR_VIMINFO		// all uppercase
4247 } var_flavour_T;
4248 
4249 // argument for mouse_find_win()
4250 typedef enum {
4251     IGNORE_POPUP,	// only check non-popup windows
4252     FIND_POPUP,		// also find popup windows
4253     FAIL_POPUP		// return NULL if mouse on popup window
4254 } mouse_find_T;
4255 
4256 // Symbolic names for some registers.
4257 #define DELETION_REGISTER	36
4258 #ifdef FEAT_CLIPBOARD
4259 # define STAR_REGISTER		37
4260 #  ifdef FEAT_X11
4261 #   define PLUS_REGISTER	38
4262 #  else
4263 #   define PLUS_REGISTER	STAR_REGISTER	    // there is only one
4264 #  endif
4265 #endif
4266 #ifdef FEAT_DND
4267 # define TILDE_REGISTER		(PLUS_REGISTER + 1)
4268 #endif
4269 
4270 #ifdef FEAT_CLIPBOARD
4271 # ifdef FEAT_DND
4272 #  define NUM_REGISTERS		(TILDE_REGISTER + 1)
4273 # else
4274 #  define NUM_REGISTERS		(PLUS_REGISTER + 1)
4275 # endif
4276 #else
4277 # define NUM_REGISTERS		37
4278 #endif
4279 
4280 // structure used by block_prep, op_delete and op_yank for blockwise operators
4281 // also op_change, op_shift, op_insert, op_replace - AKelly
4282 struct block_def
4283 {
4284     int		startspaces;	// 'extra' cols before first char
4285     int		endspaces;	// 'extra' cols after last char
4286     int		textlen;	// chars in block
4287     char_u	*textstart;	// pointer to 1st char (partially) in block
4288     colnr_T	textcol;	// index of chars (partially) in block
4289     colnr_T	start_vcol;	// start col of 1st char wholly inside block
4290     colnr_T	end_vcol;	// start col of 1st char wholly after block
4291     int		is_short;	// TRUE if line is too short to fit in block
4292     int		is_MAX;		// TRUE if curswant==MAXCOL when starting
4293     int		is_oneChar;	// TRUE if block within one character
4294     int		pre_whitesp;	// screen cols of ws before block
4295     int		pre_whitesp_c;	// chars of ws before block
4296     colnr_T	end_char_vcols;	// number of vcols of post-block char
4297     colnr_T	start_char_vcols; // number of vcols of pre-block char
4298 };
4299 
4300 // Each yank register has an array of pointers to lines.
4301 typedef struct
4302 {
4303     char_u	**y_array;	// pointer to array of line pointers
4304     linenr_T	y_size;		// number of lines in y_array
4305     char_u	y_type;		// MLINE, MCHAR or MBLOCK
4306     colnr_T	y_width;	// only set if y_type == MBLOCK
4307 #ifdef FEAT_VIMINFO
4308     time_t	y_time_set;
4309 #endif
4310 } yankreg_T;
4311 
4312 // The offset for a search command is store in a soff struct
4313 // Note: only spats[0].off is really used
4314 typedef struct soffset
4315 {
4316     int		dir;		// search direction, '/' or '?'
4317     int		line;		// search has line offset
4318     int		end;		// search set cursor at end
4319     long	off;		// line or char offset
4320 } soffset_T;
4321 
4322 // A search pattern and its attributes are stored in a spat struct
4323 typedef struct spat
4324 {
4325     char_u	    *pat;	// the pattern (in allocated memory) or NULL
4326     int		    magic;	// magicness of the pattern
4327     int		    no_scs;	// no smartcase for this pattern
4328     soffset_T	    off;
4329 } spat_T;
4330 
4331 /*
4332  * Optional extra arguments for searchit().
4333  */
4334 typedef struct
4335 {
4336     linenr_T	sa_stop_lnum;	// stop after this line number when != 0
4337 #ifdef FEAT_RELTIME
4338     proftime_T	*sa_tm;		// timeout limit or NULL
4339     int		sa_timed_out;	// set when timed out
4340 #endif
4341     int		sa_wrapped;	// search wrapped around
4342 } searchit_arg_T;
4343 
4344 /*
4345  * Cookie used by getsourceline().
4346  */
4347 /*
4348  * Cookie used to store info for each sourced file.
4349  * It is shared between do_source() and getsourceline().
4350  * This is passed to do_cmdline().
4351  */
4352 typedef struct {
4353     FILE	*fp;		// opened file for sourcing
4354     char_u	*nextline;	// if not NULL: line that was read ahead
4355     linenr_T	sourcing_lnum;	// line number of the source file
4356     int		finished;	// ":finish" used
4357 #ifdef USE_CRNL
4358     int		fileformat;	// EOL_UNKNOWN, EOL_UNIX or EOL_DOS
4359     int		error;		// TRUE if LF found after CR-LF
4360 #endif
4361 #ifdef FEAT_EVAL
4362     linenr_T	breakpoint;	// next line with breakpoint or zero
4363     char_u	*fname;		// name of sourced file
4364     int		dbg_tick;	// debug_tick when breakpoint was set
4365     int		level;		// top nesting level of sourced file
4366 #endif
4367     vimconv_T	conv;		// type of conversion
4368 } source_cookie_T;
4369 
4370 
4371 #define WRITEBUFSIZE	8192	// size of normal write buffer
4372 
4373 #define FIO_LATIN1	0x01	// convert Latin1
4374 #define FIO_UTF8	0x02	// convert UTF-8
4375 #define FIO_UCS2	0x04	// convert UCS-2
4376 #define FIO_UCS4	0x08	// convert UCS-4
4377 #define FIO_UTF16	0x10	// convert UTF-16
4378 #ifdef MSWIN
4379 # define FIO_CODEPAGE	0x20	// convert MS-Windows codepage
4380 # define FIO_PUT_CP(x) (((x) & 0xffff) << 16)	// put codepage in top word
4381 # define FIO_GET_CP(x)	(((x)>>16) & 0xffff)	// get codepage from top word
4382 #endif
4383 #ifdef MACOS_CONVERT
4384 # define FIO_MACROMAN	0x20	// convert MacRoman
4385 #endif
4386 #define FIO_ENDIAN_L	0x80	// little endian
4387 #define FIO_ENCRYPTED	0x1000	// encrypt written bytes
4388 #define FIO_NOCONVERT	0x2000	// skip encoding conversion
4389 #define FIO_UCSBOM	0x4000	// check for BOM at start of file
4390 #define FIO_ALL	-1	// allow all formats
4391 
4392 // When converting, a read() or write() may leave some bytes to be converted
4393 // for the next call.  The value is guessed...
4394 #define CONV_RESTLEN 30
4395 
4396 // We have to guess how much a sequence of bytes may expand when converting
4397 // with iconv() to be able to allocate a buffer.
4398 #define ICONV_MULT 8
4399 
4400 // Used for "magic_overruled".
4401 typedef enum {
4402     OPTION_MAGIC_NOT_SET,	// p_magic not overruled
4403     OPTION_MAGIC_ON,		// magic on inside regexp
4404     OPTION_MAGIC_OFF		// magic off inside regexp
4405 } optmagic_T;
4406 
4407 // Magicness of a pattern, used by regexp code.
4408 // The order and values matter:
4409 //  magic <= MAGIC_OFF includes MAGIC_NONE
4410 //  magic >= MAGIC_ON  includes MAGIC_ALL
4411 typedef enum {
4412     MAGIC_NONE = 1,		// "\V" very unmagic
4413     MAGIC_OFF = 2,		// "\M" or 'magic' off
4414     MAGIC_ON = 3,		// "\m" or 'magic'
4415     MAGIC_ALL = 4		// "\v" very magic
4416 } magic_T;
4417 
4418 // Struct used to pass to error messages about where the error happened.
4419 typedef struct {
4420     char    wt_index;	    // argument or variable index, 0 means unknown
4421     char    wt_variable;    // "variable" when TRUE, "argument" otherwise
4422 } where_T;
4423 
4424