Annotation of src/usr.bin/vim/structs.h, Revision 1.1.1.1
1.1 downsj 1: /* $OpenBSD$ */
2: /* vi:set ts=4 sw=4:
3: *
4: * VIM - Vi IMproved by Bram Moolenaar
5: *
6: * Do ":help uganda" in Vim to read copying and usage conditions.
7: * Do ":help credits" in Vim to see a list of people who contributed.
8: */
9:
10: /*
11: * This file contains various definitions of structures that are used by Vim
12: */
13:
14: /*
15: * file position
16: */
17:
18: typedef struct fpos FPOS;
19: /*
20: * there is something wrong in the SAS compiler that makes typedefs not
21: * valid in include files
22: */
23: #ifdef SASC
24: typedef long linenr_t;
25: typedef unsigned colnr_t;
26: typedef unsigned short short_u;
27: #endif
28:
29: struct fpos
30: {
31: linenr_t lnum; /* line number */
32: colnr_t col; /* column number */
33: };
34:
35: /*
36: * Sorry to put this here, but gui.h needs the FPOS type, and WIN needs gui.h
37: * for GuiScrollbar. There is probably somewhere better it could go -- webb
38: */
39: #ifdef USE_GUI
40: # include "gui.h"
41: #endif
42:
43: /*
44: * marks: positions in a file
45: * (a normal mark is a lnum/col pair, the same as a file position)
46: */
47:
48: #define NMARKS 26 /* max. # of named marks */
49: #define JUMPLISTSIZE 30 /* max. # of marks in jump list */
50: #define TAGSTACKSIZE 20 /* max. # of tags in tag stack */
51:
52: struct filemark
53: {
54: FPOS mark; /* cursor position */
55: int fnum; /* file number */
56: };
57:
58: /*
59: * the taggy struct is used to store the information about a :tag command:
60: * the tag name and the cursor position BEFORE the :tag command
61: */
62: struct taggy
63: {
64: char_u *tagname; /* tag name */
65: struct filemark fmark; /* cursor position */
66: };
67:
68: /*
69: * line number list
70: */
71:
72: /*
73: * Each window can have a different line number associated with a buffer.
74: * The window-pointer/line-number pairs are kept in the line number list.
75: * The list of line numbers is kept in most-recently-used order.
76: */
77:
78: typedef struct window WIN;
79: typedef struct winlnum WINLNUM;
80:
81: struct winlnum
82: {
83: WINLNUM *wl_next; /* next entry or NULL for last entry */
84: WINLNUM *wl_prev; /* previous entry or NULL for first entry */
85: WIN *wl_win; /* pointer to window that did set wl_lnum */
86: linenr_t wl_lnum; /* last cursor line in the file */
87: };
88:
89: /*
90: * stuctures used for undo
91: */
92:
93: struct u_entry
94: {
95: struct u_entry *ue_next; /* pointer to next entry in list */
96: linenr_t ue_top; /* number of line above undo block */
97: linenr_t ue_bot; /* number of line below undo block */
98: linenr_t ue_lcount; /* linecount when u_save called */
99: char_u **ue_array; /* array of lines in undo block */
100: long ue_size; /* number of lines in ue_array */
101: };
102:
103: struct u_header
104: {
105: struct u_header *uh_next; /* pointer to next header in list */
106: struct u_header *uh_prev; /* pointer to previous header in list */
107: struct u_entry *uh_entry; /* pointer to first entry */
108: FPOS uh_cursor; /* cursor position before saving */
109: int uh_flags; /* see below */
110: FPOS uh_namedm[NMARKS]; /* marks before undo/after redo */
111: };
112:
113: /* values for uh_flags */
114: #define UH_CHANGED 0x01 /* b_changed flag before undo/after redo */
115: #define UH_EMPTYBUF 0x02 /* buffer was empty */
116:
117: /*
118: * stuctures used in undo.c
119: */
120: #if defined(UNIX) || defined(WIN32) || defined(__EMX__)
121: # define ALIGN_LONG /* longword alignment and use filler byte */
122: # define ALIGN_SIZE (sizeof(long))
123: #else
124: # define ALIGN_SIZE (sizeof(short))
125: #endif
126:
127: #define ALIGN_MASK (ALIGN_SIZE - 1)
128:
129: typedef struct m_info info_t;
130:
131: /*
132: * stucture used to link chunks in one of the free chunk lists.
133: */
134: struct m_info
135: {
136: #ifdef ALIGN_LONG
137: long_u m_size; /* size of the chunk (including m_info) */
138: #else
139: short_u m_size; /* size of the chunk (including m_info) */
140: #endif
141: info_t *m_next; /* pointer to next free chunk in the list */
142: };
143:
144: /*
145: * structure used to link blocks in the list of allocated blocks.
146: */
147: struct m_block
148: {
149: struct m_block *mb_next; /* pointer to next allocated block */
150: info_t mb_info; /* head of free chuck list for this block */
151: };
152:
153: /*
154: * things used in memfile.c
155: */
156:
157: typedef struct block_hdr BHDR;
158: typedef struct memfile MEMFILE;
159: typedef long blocknr_t;
160:
161: /*
162: * for each (previously) used block in the memfile there is one block header.
163: *
164: * The block may be linked in the used list OR in the free list.
165: * The used blocks are also kept in hash lists.
166: *
167: * The used list is a doubly linked list, most recently used block first.
168: * The blocks in the used list have a block of memory allocated.
169: * mf_used_count is the number of pages in the used list.
170: * The hash lists are used to quickly find a block in the used list.
171: * The free list is a single linked list, not sorted.
172: * The blocks in the free list have no block of memory allocated and
173: * the contents of the block in the file (if any) is irrelevant.
174: */
175:
176: struct block_hdr
177: {
178: BHDR *bh_next; /* next block_hdr in free or used list */
179: BHDR *bh_prev; /* previous block_hdr in used list */
180: BHDR *bh_hash_next; /* next block_hdr in hash list */
181: BHDR *bh_hash_prev; /* previous block_hdr in hash list */
182: blocknr_t bh_bnum; /* block number */
183: char_u *bh_data; /* pointer to memory (for used block) */
184: int bh_page_count; /* number of pages in this block */
185:
186: #define BH_DIRTY 1
187: #define BH_LOCKED 2
188: char bh_flags; /* BH_DIRTY or BH_LOCKED */
189: };
190:
191: /*
192: * when a block with a negative number is flushed to the file, it gets
193: * a positive number. Because the reference to the block is still the negative
194: * number, we remember the translation to the new positive number in the
195: * double linked trans lists. The structure is the same as the hash lists.
196: */
197: typedef struct nr_trans NR_TRANS;
198:
199: struct nr_trans
200: {
201: NR_TRANS *nt_next; /* next nr_trans in hash list */
202: NR_TRANS *nt_prev; /* previous nr_trans in hash list */
203: blocknr_t nt_old_bnum; /* old, negative, number */
204: blocknr_t nt_new_bnum; /* new, positive, number */
205: };
206:
207: /*
208: * Simplistic hashing scheme to quickly locate the blocks in the used list.
209: * 64 blocks are found directly (64 * 4K = 256K, most files are smaller).
210: */
211: #define MEMHASHSIZE 64
212: #define MEMHASH(nr) ((nr) & (MEMHASHSIZE - 1))
213:
214: struct memfile
215: {
216: char_u *mf_fname; /* name of the file */
217: char_u *mf_xfname; /* idem, full path */
218: int mf_fd; /* file descriptor */
219: BHDR *mf_free_first; /* first block_hdr in free list */
220: BHDR *mf_used_first; /* mru block_hdr in used list */
221: BHDR *mf_used_last; /* lru block_hdr in used list */
222: unsigned mf_used_count; /* number of pages in used list */
223: unsigned mf_used_count_max; /* maximum number of pages in memory */
224: BHDR *mf_hash[MEMHASHSIZE]; /* array of hash lists */
225: NR_TRANS *mf_trans[MEMHASHSIZE]; /* array of trans lists */
226: blocknr_t mf_blocknr_max; /* highest positive block number + 1*/
227: blocknr_t mf_blocknr_min; /* lowest negative block number - 1 */
228: blocknr_t mf_neg_count; /* number of negative blocks numbers */
229: blocknr_t mf_infile_count; /* number of pages in the file */
230: unsigned mf_page_size; /* number of bytes in a page */
231: int mf_dirty; /* Set to TRUE if there are dirty blocks */
232: };
233:
234: /*
235: * things used in memline.c
236: */
237: typedef struct info_pointer IPTR; /* block/index pair */
238:
239: /*
240: * When searching for a specific line, we remember what blocks in the tree
241: * are the branches leading to that block. This is stored in ml_stack.
242: * Each entry is a pointer to info in a block (may be data block or pointer block)
243: */
244: struct info_pointer
245: {
246: blocknr_t ip_bnum; /* block number */
247: linenr_t ip_low; /* lowest lnum in this block */
248: linenr_t ip_high; /* highest lnum in this block */
249: int ip_index; /* index for block with current lnum */
250: };
251:
252: typedef struct memline MEMLINE;
253:
254: /*
255: * the memline structure holds all the information about a memline
256: */
257: struct memline
258: {
259: linenr_t ml_line_count; /* number of lines in the buffer */
260:
261: MEMFILE *ml_mfp; /* pointer to associated memfile */
262:
263: #define ML_EMPTY 1 /* empty buffer */
264: #define ML_LINE_DIRTY 2 /* cached line was changed and allocated */
265: #define ML_LOCKED_DIRTY 4 /* ml_locked was changed */
266: #define ML_LOCKED_POS 8 /* ml_locked needs positive block number */
267: int ml_flags;
268:
269: IPTR *ml_stack; /* stack of pointer blocks (array of IPTRs) */
270: int ml_stack_top; /* current top if ml_stack */
271: int ml_stack_size; /* total number of entries in ml_stack */
272:
273: linenr_t ml_line_lnum; /* line number of cached line, 0 if not valid */
274: char_u *ml_line_ptr; /* pointer to cached line */
275:
276: BHDR *ml_locked; /* block used by last ml_get */
277: linenr_t ml_locked_low; /* first line in ml_locked */
278: linenr_t ml_locked_high; /* last line in ml_locked */
279: int ml_locked_lineadd; /* number of lines inserted in ml_locked */
280: };
281:
282: /*
283: * buffer: structure that holds information about one file
284: *
285: * Several windows can share a single Buffer
286: * A buffer is unallocated if there is no memfile for it.
287: * A buffer is new if the associated file has never been loaded yet.
288: */
289:
290: typedef struct buffer BUF;
291:
292: struct buffer
293: {
294: MEMLINE b_ml; /* associated memline (also contains
295: * line count) */
296:
297: BUF *b_next; /* links in list of buffers */
298: BUF *b_prev;
299:
300: int b_changed; /* 'modified': Set to TRUE if
301: * something in the file has
302: * been changed and not written out.
303: */
304:
305: int b_notedited; /* Set to TRUE when file name is
306: * changed after starting to edit,
307: * reset when file is written out. */
308:
309: int b_nwindows; /* nr of windows open on this buffer */
310:
311: int b_neverloaded; /* file has never been loaded into
312: * buffer, many variables still need
313: * to be set */
314:
315: /*
316: * b_filename has the full path of the file.
317: * b_sfilename is the name as the user typed it.
318: * b_xfilename is the same as b_sfilename, unless did_cd is set, then it
319: * is the same as b_filename.
320: */
321: char_u *b_filename;
322: char_u *b_sfilename;
323: char_u *b_xfilename;
324:
325: int b_fnum; /* file number for this file. */
326: WINLNUM *b_winlnum; /* list of last used lnum for
327: * each window */
328:
329: long b_mtime; /* last change time of original file */
330: long b_mtime_read; /* last change time when reading */
331:
332: FPOS b_namedm[NMARKS]; /* current named marks (mark.c) */
333:
334: FPOS b_last_cursor; /* cursor position when last unloading
335: this buffer */
336:
337: /*
338: * Character table, only used in charset.c for 'iskeyword'
339: */
340: char b_chartab[256];
341:
342: /*
343: * start and end of an operator, also used for '[ and ']
344: */
345: FPOS b_op_start;
346: FPOS b_op_end;
347:
348: #ifdef VIMINFO
349: int b_marks_read; /* Have we read viminfo marks yet? */
350: #endif /* VIMINFO */
351:
352: /*
353: * The following only used in undo.c.
354: */
355: struct u_header *b_u_oldhead; /* pointer to oldest header */
356: struct u_header *b_u_newhead; /* pointer to newest header */
357: struct u_header *b_u_curhead; /* pointer to current header */
358: int b_u_numhead; /* current number of headers */
359: int b_u_synced; /* entry lists are synced */
360:
361: /*
362: * variables for "U" command in undo.c
363: */
364: char_u *b_u_line_ptr; /* saved line for "U" command */
365: linenr_t b_u_line_lnum; /* line number of line in u_line */
366: colnr_t b_u_line_colnr; /* optional column number */
367:
368: /*
369: * The following only used in undo.c
370: */
371: struct m_block b_block_head; /* head of allocated memory block list */
372: info_t *b_m_search; /* pointer to chunk before previously
373: * allocated/freed chunk */
374: struct m_block *b_mb_current; /* block where m_search points in */
375:
376: /*
377: * Options "local" to a buffer.
378: * They are here because their value depends on the type of file
379: * or contents of the file being edited.
380: * The "save" options are for when the paste option is set.
381: */
382: int b_p_initialized; /* set when options initialized */
383: int b_p_ai, b_p_ro, b_p_lisp;
384: int b_p_inf; /* infer case of ^N/^P completions */
385: int b_p_bin, b_p_eol, b_p_et, b_p_ml, b_p_tx;
386: #ifndef SHORT_FNAME
387: int b_p_sn;
388: #endif
389:
390: long b_p_sw, b_p_ts, b_p_tw, b_p_wm;
391: char_u *b_p_fo, *b_p_com, *b_p_isk;
392:
393: /* saved values for when 'bin' is set */
394: long b_p_wm_nobin, b_p_tw_nobin;
395: int b_p_tx_nobin, b_p_ta_nobin;
396: int b_p_ml_nobin, b_p_et_nobin;
397:
398: /* saved values for when 'paste' is set */
399: int b_p_ai_save, b_p_lisp_save;
400: long b_p_tw_save, b_p_wm_save;
401:
402: #ifdef SMARTINDENT
403: int b_p_si, b_p_si_save;
404: #endif
405: #ifdef CINDENT
406: int b_p_cin; /* use C progam indent mode */
407: int b_p_cin_save; /* b_p_cin saved for paste mode */
408: char_u *b_p_cino; /* C progam indent mode options */
409: char_u *b_p_cink; /* C progam indent mode keys */
410: #endif
411: #if defined(CINDENT) || defined(SMARTINDENT)
412: char_u *b_p_cinw; /* words extra indent for 'si' and 'cin' */
413: #endif
414:
415: char b_did_warn; /* Set to 1 if user has been warned on
416: * first change of a read-only file */
417: char b_help; /* buffer for help file */
418:
419: #ifndef SHORT_FNAME
420: int b_shortname; /* this file has an 8.3 filename */
421: #endif
422: };
423:
424: /*
425: * Structure which contains all information that belongs to a window
426: *
427: * All row numbers are relative to the start of the window, except w_winpos.
428: */
429:
430: struct window
431: {
432: BUF *w_buffer; /* buffer we are a window into */
433:
434: WIN *w_prev; /* link to previous window (above) */
435: WIN *w_next; /* link to next window (below) */
436:
437: FPOS w_cursor; /* cursor's position in buffer */
438:
439: /*
440: * These elements are related to the cursor's position in the window.
441: * This is related to character positions in the window, not in the file.
442: */
443: int w_row, w_col; /* cursor's position in window */
444:
445: /*
446: * w_cline_height is set in cursupdate() to the number of physical lines
447: * taken by the buffer line that the cursor is on. We use this to avoid
448: * extra calls to plines(). Note that w_cline_height and w_cline_row are
449: * only valid after calling cursupdate(), until the next vertical movement
450: * of the cursor or change of text.
451: */
452: int w_cline_height; /* current size of cursor line */
453:
454: int w_cline_row; /* starting row of the cursor line */
455:
456: colnr_t w_virtcol; /* column number of the file's actual */
457: /* line, as opposed to the column */
458: /* number we're at on the screen. */
459: /* This makes a difference on lines */
460: /* which span more than one screen */
461: /* line. */
462:
463: colnr_t w_curswant; /* The column we'd like to be at. */
464: /* This is used to try to stay in */
465: /* the same column through up/down */
466: /* cursor motions. */
467:
468: int w_set_curswant; /* If set, then update w_curswant */
469: /* the next time through cursupdate() */
470: /* to the current virtual column */
471:
472: /*
473: * the next three are used to update the visual part
474: */
475: linenr_t w_old_cursor_lnum; /* last known end of visual part */
476: colnr_t w_old_cursor_vcol; /* last known end of visual part */
477: linenr_t w_old_visual_lnum; /* last known start of visual part */
478: colnr_t w_old_curswant; /* last known value of Curswant */
479:
480: linenr_t w_topline; /* number of the line at the top of
481: * the screen */
482: linenr_t w_botline; /* number of the line below the bottom
483: * of the screen */
484: int w_empty_rows; /* number of ~ rows in window */
485:
486: int w_winpos; /* row of topline of window in screen */
487: int w_height; /* number of rows in window, excluding
488: status/command line */
489: int w_status_height; /* number of status lines (0 or 1) */
490:
491: int w_redr_status; /* if TRUE status line must be redrawn */
492: int w_redr_type; /* type of redraw to be performed on win */
493:
494: colnr_t w_leftcol; /* starting column of the screen */
495:
496: /*
497: * The height of the lines currently in the window is remembered
498: * to avoid recomputing it every time. The number of entries is w_nrows.
499: */
500: int w_lsize_valid; /* nr. of valid LineSizes */
501: linenr_t *w_lsize_lnum; /* array of line numbers for w_lsize */
502: char_u *w_lsize; /* array of line heights */
503:
504: int w_alt_fnum; /* alternate file (for # and CTRL-^) */
505:
506: int w_arg_idx; /* current index in argument list */
507: int w_arg_idx_invalid; /* editing another file then w_arg_idx */
508:
509: /*
510: * Variables "local" to a window.
511: * They are here because they influence the layout of the window or
512: * depend on the window layout.
513: */
514: int w_p_list,
515: w_p_nu,
516: #ifdef RIGHTLEFT
517: w_p_rl,
518: #endif
519: w_p_wrap,
520: w_p_lbr;
521: long w_p_scroll;
522:
523: /*
524: * The w_prev_pcmark field is used to check whether we really did jump to
525: * a new line after setting the w_pcmark. If not, then we revert to
526: * using the previous w_pcmark.
527: */
528: FPOS w_pcmark; /* previous context mark */
529: FPOS w_prev_pcmark; /* previous w_pcmark */
530:
531: /*
532: * the jumplist contains old cursor positions
533: */
534: struct filemark w_jumplist[JUMPLISTSIZE];
535: int w_jumplistlen; /* number of active entries */
536: int w_jumplistidx; /* current position */
537:
538: /*
539: * the tagstack grows from 0 upwards:
540: * entry 0: older
541: * entry 1: newer
542: * entry 2: newest
543: */
544: struct taggy w_tagstack[TAGSTACKSIZE]; /* the tag stack */
545: int w_tagstackidx; /* idx just below activ entry */
546: int w_tagstacklen; /* number of tags on stack */
547:
548: #ifdef USE_GUI
549: GuiScrollbar w_scrollbar; /* Scrollbar for this window */
550: #endif /* USE_GUI */
551: };