1 /*- 2 * Copyright (c) 1980, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * %sccs.include.proprietary.c% 6 * 7 * @(#)ex_vis.h 8.1 (Berkeley) 06/09/93 8 */ 9 10 /* 11 * Ex version 3 12 * Mark Horton, UCB 13 * Bill Joy UCB 14 * 15 * Open and visual mode definitions. 16 * 17 * There are actually 4 major states in open/visual modes. These 18 * are visual, crt open (where the cursor can move about the screen and 19 * the screen can scroll and be erased), one line open (on dumb glass-crt's 20 * like the adm3), and hardcopy open (for everything else). 21 * 22 * The basic state is given by bastate, and the current state by state, 23 * since we can be in pseudo-hardcopy mode if we are on an adm3 and the 24 * line is longer than 80. 25 */ 26 27 var short bastate; 28 var short state; 29 30 #define VISUAL 0 31 #define CRTOPEN 1 32 #define ONEOPEN 2 33 #define HARDOPEN 3 34 35 /* 36 * The screen in visual and crtopen is of varying size; the basic 37 * window has top basWTOP and basWLINES lines are thereby implied. 38 * The current window (which may have grown from the basic size) 39 * has top WTOP and WLINES lines. The top line of the window is WTOP, 40 * and the bottom line WBOT. The line WECHO is used for messages, 41 * search strings and the like. If WBOT==WECHO then we are in ONEOPEN 42 * or HARDOPEN and there is no way back to the line we were on if we 43 * go to WECHO (i.e. we will have to scroll before we go there, and 44 * we can't get back). There are WCOLS columns per line. 45 * If WBOT!=WECHO then WECHO will be the last line on the screen 46 * and WBOT is the line before it. 47 */ 48 var short basWTOP; 49 var short basWLINES; 50 var short WTOP; 51 var short WBOT; 52 var short WLINES; 53 var short WCOLS; 54 var short WECHO; 55 56 /* 57 * When we are dealing with the echo area we consider the window 58 * to be "split" and set the variable splitw. Otherwise, moving 59 * off the bottom of the screen into WECHO causes a screen rollup. 60 */ 61 var bool splitw; 62 63 /* 64 * Information about each line currently on the screen includes 65 * the y coordinate associated with the line, the printing depth 66 * of the line (0 indicates unknown), and a mask which indicates 67 * whether the line is "unclean", i.e. whether we should check 68 * to make sure the line is displayed correctly at the next 69 * appropriate juncture. 70 */ 71 struct vlinfo { 72 short vliny; /* Y coordinate */ /* mjm: was char */ 73 short vdepth; /* Depth of displayed line */ /*mjm: was char */ 74 short vflags; /* Is line potentially dirty ? */ 75 }; 76 var struct vlinfo vlinfo[TUBELINES + 2]; 77 78 #define DEPTH(c) (vlinfo[c].vdepth) 79 #define LINE(c) (vlinfo[c].vliny) 80 #define FLAGS(c) (vlinfo[c].vflags) 81 82 #define VDIRT 1 83 84 /* 85 * Hacks to copy vlinfo structures around 86 */ 87 #ifdef V6 88 /* Kludge to make up for no structure assignment */ 89 struct { 90 long longi; 91 }; 92 # define vlcopy(i, j) i.longi = j.longi 93 #else 94 # define vlcopy(i, j) i = j; 95 #endif 96 97 /* 98 * The current line on the screen is represented by vcline. 99 * There are vcnt lines on the screen, the last being "vcnt - 1". 100 * Vcline is intimately tied to the current value of dot, 101 * and when command mode is used as a subroutine fancy footwork occurs. 102 */ 103 var short vcline; 104 var short vcnt; 105 106 /* 107 * To allow many optimizations on output, an exact image of the terminal 108 * screen is maintained in the space addressed by vtube0. The vtube 109 * array indexes this space as lines, and is shuffled on scrolls, insert+delete 110 * lines and the like rather than (more expensively) shuffling the screen 111 * data itself. It is also rearranged during insert mode across line 112 * boundaries to make incore work easier. 113 */ 114 var char *vtube[TUBELINES]; 115 var char *vtube0; 116 117 /* 118 * The current cursor position within the current line is kept in 119 * cursor. The current line is kept in linebuf. During insertions 120 * we use the auxiliary array genbuf as scratch area. 121 * The cursor wcursor and wdot are used in operations within/spanning 122 * lines to mark the other end of the affected area, or the target 123 * for a motion. 124 */ 125 var char *cursor; 126 var char *wcursor; 127 var line *wdot; 128 129 /* 130 * Undo information is saved in a LBSIZE buffer at "vutmp" for changes 131 * within the current line, or as for command mode for multi-line changes 132 * or changes on lines no longer the current line. 133 * The change kind "VCAPU" is used immediately after a U undo to prevent 134 * two successive U undo's from destroying the previous state. 135 */ 136 #define VNONE 0 137 #define VCHNG 1 138 #define VMANY 2 139 #define VCAPU 3 140 #define VMCHNG 4 141 #define VMANYINS 5 142 143 var short vundkind; /* Which kind of undo - from above */ 144 var char *vutmp; /* Prev line image when "VCHNG" */ 145 146 /* 147 * State information for undoing of macros. The basic idea is that 148 * if the macro does only 1 change or even none, we don't treat it 149 * specially. If it does 2 or more changes we want to be able to 150 * undo it as a unit. We remember how many changes have been made 151 * within the current macro. (Remember macros can be nested.) 152 */ 153 #define VC_NOTINMAC 0 /* Not in a macro */ 154 #define VC_NOCHANGE 1 /* In a macro, no changes so far */ 155 #define VC_ONECHANGE 2 /* In a macro, one change so far */ 156 #define VC_MANYCHANGE 3 /* In a macro, at least 2 changes so far */ 157 158 var short vch_mac; /* Change state - one of the above */ 159 160 /* 161 * For U undo's the line is grabbed by "vmove" after it first appears 162 * on that line. The "vUNDdot" which specifies which line has been 163 * saved is selectively cleared when changes involving other lines 164 * are made, i.e. after a 'J' join. This is because a 'JU' would 165 * lose completely the text of the line just joined on. 166 */ 167 var char *vUNDcurs; /* Cursor just before 'U' */ 168 var line *vUNDdot; /* The line address of line saved in vUNDsav */ 169 var line vUNDsav; /* Grabbed initial "*dot" */ 170 171 #define killU() vUNDdot = NOLINE 172 173 /* 174 * There are a number of cases where special behaviour is needed 175 * from deeply nested routines. This is accomplished by setting 176 * the bits of hold, which acts to change the state of the general 177 * visual editing behaviour in specific ways. 178 * 179 * HOLDAT prevents the clreol (clear to end of line) routines from 180 * putting out @'s or ~'s on empty lines. 181 * 182 * HOLDDOL prevents the reopen routine from putting a '$' at the 183 * end of a reopened line in list mode (for hardcopy mode, e.g.). 184 * 185 * HOLDROL prevents spurious blank lines when scrolling in hardcopy 186 * open mode. 187 * 188 * HOLDQIK prevents the fake insert mode during repeated commands. 189 * 190 * HOLDPUPD prevents updating of the physical screen image when 191 * mucking around while in insert mode. 192 * 193 * HOLDECH prevents clearing of the echo area while rolling the screen 194 * backwards (e.g.) in deference to the clearing of the area at the 195 * end of the scroll (1 time instead of n times). The fact that this 196 * is actually needed is recorded in heldech, which says that a clear 197 * of the echo area was actually held off. 198 */ 199 var short hold; 200 var short holdupd; /* Hold off update when echo line is too long */ 201 202 #define HOLDAT 1 203 #define HOLDDOL 2 204 #define HOLDROL 4 205 #define HOLDQIK 8 206 #define HOLDPUPD 16 207 #define HOLDECH 32 208 #define HOLDWIG 64 209 210 /* 211 * Miscellaneous variables 212 */ 213 var short CDCNT; /* Count of ^D's in insert on this line */ 214 var char DEL[VBSIZE]; /* Last deleted text */ 215 var bool HADUP; /* This insert line started with ^ then ^D */ 216 var bool HADZERO; /* This insert line started with 0 then ^D */ 217 var char INS[VBSIZE]; /* Last inserted text */ 218 var int Vlines; /* Number of file lines "before" vi command */ 219 var int Xcnt; /* External variable holding last cmd's count */ 220 var bool Xhadcnt; /* Last command had explicit count? */ 221 var short ex_ZERO; 222 var short dir; /* Direction for search (+1 or -1) */ 223 var short doomed; /* Disply chars right of cursor to be killed */ 224 var bool gobblebl; /* Wrapmargin space generated nl, eat a space */ 225 var bool hadcnt; /* (Almost) internal to vmain() */ 226 var bool heldech; /* We owe a clear of echo area */ 227 var bool insmode; /* Are in character insert mode */ 228 var char lastcmd[5]; /* Chars in last command */ 229 var int lastcnt; /* Count for last command */ 230 var char *lastcp; /* Save current command here to repeat */ 231 var bool lasthad; /* Last command had a count? */ 232 var short lastvgk; /* Previous input key, if not from keyboard */ 233 var short lastreg; /* Register with last command */ 234 var char *ncols['z'-'a'+2]; /* Cursor positions of marks */ 235 var char *notenam; /* Name to be noted with change count */ 236 var char *notesgn; /* Change count from last command */ 237 var char op; /* Operation of current command */ 238 var short Peek_key; /* Peek ahead key */ 239 var bool rubble; /* Line is filthy (in hardcopy open), redraw! */ 240 var int ex_vSCROLL; /* Number lines to scroll on ^D/^U */ 241 var char *vglobp; /* Untyped input (e.g. repeat insert text) */ 242 var char vmacbuf[VBSIZE]; /* Text of visual macro, hence nonnestable */ 243 var char *vmacp; /* Like vglobp but for visual macros */ 244 var char *vmcurs; /* Cursor for restore after undo d), e.g. */ 245 var short vmovcol; /* Column to try to keep on arrow keys */ 246 var bool vmoving; /* Are trying to keep vmovcol */ 247 var short vreg; /* Reg for this command */ /* mjm: was char */ 248 var short wdkind; /* Liberal/conservative words? */ 249 var char workcmd[5]; /* Temporary for lastcmd */ 250 251 252 /* 253 * Macros 254 */ 255 #define INF 30000 256 #define LASTLINE LINE(vcnt) 257 #define OVERBUF QUOTE 258 #define beep obeep 259 #define cindent() ((outline - vlinfo[vcline].vliny) * WCOLS + outcol) 260 #define vputp(cp, cnt) tputs(cp, cnt, vputch) 261 #define vputc(c) putch(c) 262 263 /* 264 * Function types 265 */ 266 int beep(); 267 int qcount(); 268 int vchange(); 269 int vdelete(); 270 int vgrabit(); 271 int vinschar(); 272 int vmove(); 273 int vputchar(); 274 int vshift(); 275 int vyankit(); 276