Commit | Line | Data |
---|---|---|
dc3faadc BJ |
1 | #include "ex.h" |
2 | #ifdef VISUAL | |
3 | #include "ex_tty.h" | |
4 | #include "ex_vis.h" | |
5 | /* | |
6 | * Ex - a text editor | |
7 | * Bill Joy UCB September, 1977 | |
8 | */ | |
9 | ||
10 | /* | |
11 | * Fix the cursor to be positioned in the correct place | |
12 | */ | |
13 | vfixcurs() | |
14 | { | |
15 | ||
16 | vsetcurs(cursor); | |
17 | } | |
18 | ||
19 | /* | |
20 | * Set the cursor at nc | |
21 | */ | |
22 | vsetcurs(nc) | |
23 | register char *nc; | |
24 | { | |
25 | register int col; | |
26 | ||
27 | col = column(nc); | |
28 | if (linebuf[0]) | |
29 | col--; | |
30 | vgotoCL(col); | |
31 | cursor = nc; | |
32 | } | |
33 | ||
34 | /* | |
35 | * Invisible goto | |
36 | */ | |
37 | vigoto(y, x) | |
38 | int y, x; | |
39 | { | |
40 | ||
41 | if (y < 0) | |
42 | error("Internal error: vigoto@- please tell someone"); | |
43 | destline = y; | |
44 | destcol = x; | |
45 | } | |
46 | ||
47 | /* | |
48 | * Sync the cursor... i.e. make the current invisible position | |
49 | * the current actual physical position. | |
50 | */ | |
51 | vcsync() | |
52 | { | |
53 | ||
54 | vgoto(destline, destcol); | |
55 | } | |
56 | ||
57 | /* | |
58 | * Goto output position y on line x. | |
59 | * X may be greater than VCOLUMNS and is folded here | |
60 | * the screen is rolled up if need be. | |
61 | */ | |
62 | vgotoCL(x) | |
63 | { | |
64 | ||
65 | vgoto(vliny[vcline], x); | |
66 | } | |
67 | ||
68 | vgoto(y, x) | |
69 | int y, x; | |
70 | { | |
71 | register char *tp; | |
72 | ||
73 | if (y < 0) | |
74 | error("Internal error: vgoto@- please tell someone"); | |
75 | /* | |
76 | * Fold the possibly too large value of x. | |
77 | */ | |
78 | if (x >= COLUMNS) { | |
79 | y =+ x / COLUMNS; | |
80 | x =% COLUMNS; | |
81 | } | |
82 | if (outcol >= COLUMNS) { | |
83 | outline =+ outcol / COLUMNS; | |
84 | outcol =% COLUMNS; | |
85 | } | |
86 | if (!CA) { | |
87 | /* | |
88 | * We are doing a one line open on a terminal | |
89 | * without cursor addressing. | |
90 | */ | |
91 | if (y != outline) | |
92 | error("Line too long@for single line open"); | |
93 | if (x + 1 < outcol - x || (outcol > x && !BS)) | |
94 | vputc('\r'), outcol = 0; | |
95 | tp = vtube[LINES - 1] + outcol; | |
96 | while (outcol != x) | |
97 | if (outcol < x) { | |
98 | if (*tp == 0) | |
99 | *tp = ' '; | |
100 | vputc(*tp++), outcol++; | |
101 | } else | |
102 | vputc('\b'), outcol--; | |
103 | destcol = outcol = x; | |
104 | return; | |
105 | } | |
106 | if (y >= LINES - 1 && (y >= LINES || !splitw)) | |
107 | vrollup(&y); | |
108 | destline = y; | |
109 | destcol = x; | |
110 | fgoto(); | |
111 | } | |
112 | ||
113 | /* | |
114 | * Process the character c onto the screen at the current position. | |
115 | */ | |
116 | vputchar(c) | |
117 | int c; | |
118 | { | |
119 | register char *tp; | |
120 | int y; | |
121 | ||
122 | if (destcol >= VCOLUMNS && !visual && !CA) | |
123 | error("Line too long@for single line open"); | |
124 | if (destcol >= COLUMNS) { | |
125 | destline =+ destcol / COLUMNS; | |
126 | destcol =% VCOLUMNS; | |
127 | } | |
128 | if (destline > VLINES) { | |
129 | if (splitw) { | |
130 | if (destline > LINES || destcol >= VCOLUMNS) { | |
131 | beep(); | |
132 | return; | |
133 | } | |
134 | goto ok; | |
135 | } | |
136 | y = destline; | |
137 | vrollup(&y); | |
138 | } | |
139 | ok: | |
140 | tp = vtube[destline] + destcol; | |
141 | switch (c) { | |
142 | case '\t': | |
143 | do | |
144 | vputchar(' '); | |
145 | while (destcol & 07); | |
146 | return; | |
147 | case ' ': | |
148 | if (*tp == 0) { | |
149 | *tp = ' '; | |
150 | destcol++; | |
151 | return; | |
152 | } | |
153 | default: | |
154 | if (c < ' ' || c == 0177) | |
155 | c = '?'; | |
156 | if (*tp == c) { | |
157 | destcol++; | |
158 | return; | |
159 | } | |
160 | if (destline != outline || destcol != outcol) { | |
161 | vcsync(); | |
162 | tp = vtube[destline] + destcol; | |
163 | } | |
164 | *tp = c; | |
165 | vputc(c); | |
166 | destcol++, outcol++; | |
167 | return; | |
168 | } | |
169 | } | |
170 | #endif |