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