| 1 |
/************************************************************************** |
| 2 |
* This program is Copyright (C) 1986-2002 by Jonathan Payne. JOVE is * |
| 3 |
* provided by Jonathan and Jovehacks without charge and without * |
| 4 |
* warranty. You may copy, modify, and/or distribute JOVE, provided that * |
| 5 |
* this notice is included in all the source files and documentation. * |
| 6 |
**************************************************************************/ |
| 7 |
|
| 8 |
#include "jove.h" |
| 9 |
#include "jctype.h" |
| 10 |
#include "chars.h" |
| 11 |
#include "fp.h" |
| 12 |
#include "disp.h" |
| 13 |
#include "ask.h" |
| 14 |
#include "extend.h" |
| 15 |
#include "fmt.h" |
| 16 |
#include "insert.h" |
| 17 |
#ifdef IPROCS |
| 18 |
# include "iproc.h" |
| 19 |
#endif |
| 20 |
#include "move.h" |
| 21 |
#include "macros.h" |
| 22 |
#include "screen.h" |
| 23 |
#include "term.h" |
| 24 |
#include "wind.h" |
| 25 |
|
| 26 |
#ifdef MAC |
| 27 |
# include "mac.h" |
| 28 |
#else |
| 29 |
# include <sys/stat.h> |
| 30 |
#endif |
| 31 |
|
| 32 |
/* define a couple of unique daddrs */ |
| 33 |
#define NOWHERE_DADDR (~NULL_DADDR | DDIRTY) /* not in tmp file */ |
| 34 |
#define UNSAVED_CURLINE_DADDR ((NOWHERE_DADDR - 1) | DDIRTY) /* not yet in tmp file */ |
| 35 |
|
| 36 |
struct screenline |
| 37 |
*Screen = NULL, /* the screen (a bunch of screenline) */ |
| 38 |
*Curline = NULL; /* current line */ |
| 39 |
|
| 40 |
private void |
| 41 |
DeTab(char *, int, char *, char *, jbool), |
| 42 |
DoIDline(int), |
| 43 |
do_cl_eol(int), |
| 44 |
ModeLine(Window *, char *, int), |
| 45 |
GotoDot(void), |
| 46 |
UpdLine(int), |
| 47 |
UpdWindow(Window *, int); |
| 48 |
|
| 49 |
#ifdef ID_CHAR |
| 50 |
private void |
| 51 |
DelChar(int, int, int), |
| 52 |
InsChar(int, int, int, char *); |
| 53 |
|
| 54 |
private jbool |
| 55 |
IDchar(char *, int), |
| 56 |
OkayDelete(int, int, jbool), |
| 57 |
OkayInsert(int, int); |
| 58 |
|
| 59 |
private int |
| 60 |
NumSimilar(char *, char *, int), |
| 61 |
IDcomp(char *, char *, int); |
| 62 |
#endif /* ID_CHAR */ |
| 63 |
|
| 64 |
private jbool |
| 65 |
AddLines(int, int), |
| 66 |
DelLines(int, int); |
| 67 |
|
| 68 |
jbool DisabledRedisplay = NO; |
| 69 |
|
| 70 |
/* Kludge windows gets called by the routines that delete lines from the |
| 71 |
* buffer. If the w->w_line or w->w_top are deleted and this procedure |
| 72 |
* is not called, the redisplay routine will barf. |
| 73 |
*/ |
| 74 |
void |
| 75 |
ChkWindows(LinePtr line1, LinePtr line2) |
| 76 |
{ |
| 77 |
Window *w = fwind; |
| 78 |
LinePtr lp, |
| 79 |
lend = line2->l_next; |
| 80 |
|
| 81 |
do { |
| 82 |
if (w->w_bufp == curbuf) { |
| 83 |
for (lp = line1->l_next; lp != lend; lp = lp->l_next) { |
| 84 |
if (lp == w->w_top) |
| 85 |
w->w_flags |= W_TOPGONE; |
| 86 |
if (lp == w->w_line) |
| 87 |
w->w_flags |= W_CURGONE; |
| 88 |
} |
| 89 |
} |
| 90 |
w = w->w_next; |
| 91 |
} while (w != fwind); |
| 92 |
} |
| 93 |
|
| 94 |
|
| 95 |
#ifdef WINRESIZE |
| 96 |
|
| 97 |
volatile jbool |
| 98 |
ResizePending = NO; /* asynch request for screen resize */ |
| 99 |
|
| 100 |
private void |
| 101 |
resize(void) |
| 102 |
{ |
| 103 |
jbool oldDisabledRedisplay = DisabledRedisplay; |
| 104 |
int |
| 105 |
oldILI = ILI, |
| 106 |
oldCO = CO; |
| 107 |
|
| 108 |
DisabledRedisplay = YES; /* prevent tragedy */ |
| 109 |
ResizePending = NO; /* early & safe */ |
| 110 |
ttsize(); /* update line (LI and ILI) and col (CO) info. */ |
| 111 |
|
| 112 |
if (oldILI != ILI || oldCO != CO) { |
| 113 |
int total; |
| 114 |
Window *wp; |
| 115 |
|
| 116 |
/* Go through the window list, changing each window size in |
| 117 |
* proportion to the resize. If the window would become too |
| 118 |
* small, we delete it. |
| 119 |
* |
| 120 |
* Actually, we must do the deletion in |
| 121 |
* a separate pass because del_wind donates the space to either |
| 122 |
* neighbouring window. We test the windows in a funny order: |
| 123 |
* top-most, then bottom-up. Although it isn't necessary |
| 124 |
* for correctness, it means that we consider any donated |
| 125 |
* space, cutting down the number of windows we decide to delete. |
| 126 |
* Loop termination is tricky: fwind may have changed due to a |
| 127 |
* del_wind. As a simple fix, we start over whenever we |
| 128 |
* delete a window. Although this is O(n**2), it can't |
| 129 |
* really be expensive. |
| 130 |
* |
| 131 |
* After scaling all the windows, we |
| 132 |
* give any space remaining to the current window (which would |
| 133 |
* have changed if the old current window had been deleted). |
| 134 |
* |
| 135 |
* This seems fairer than just resizing the current window. |
| 136 |
*/ |
| 137 |
wp = fwind; |
| 138 |
for (;;) { |
| 139 |
int newsize = ILI * wp->w_height / oldILI; |
| 140 |
|
| 141 |
if (newsize < 2) { |
| 142 |
del_wind(wp); |
| 143 |
wp = fwind; |
| 144 |
} else { |
| 145 |
wp = wp->w_prev; |
| 146 |
if (wp == fwind) |
| 147 |
break; |
| 148 |
} |
| 149 |
} |
| 150 |
|
| 151 |
total = 0; |
| 152 |
do { |
| 153 |
int newsize = ILI * wp->w_height / oldILI; |
| 154 |
|
| 155 |
wp->w_height = newsize; |
| 156 |
total += newsize; |
| 157 |
wp = wp->w_next; |
| 158 |
} while (wp != fwind); |
| 159 |
|
| 160 |
curwind->w_height += ILI - total; |
| 161 |
|
| 162 |
/* Make a new screen structure */ |
| 163 |
make_scr(); |
| 164 |
|
| 165 |
/* Do a 'hard' update on the screen - clear and redraw */ |
| 166 |
ClAndRedraw(); |
| 167 |
#ifdef WIN32 |
| 168 |
ResizeWindow(); |
| 169 |
#endif |
| 170 |
} |
| 171 |
DisabledRedisplay = oldDisabledRedisplay; |
| 172 |
} |
| 173 |
|
| 174 |
#endif /* WINRESIZE */ |
| 175 |
|
| 176 |
private jbool RingBell; /* So if we have a lot of errors ... |
| 177 |
ring the bell only ONCE */ |
| 178 |
|
| 179 |
void |
| 180 |
redisplay(void) |
| 181 |
{ |
| 182 |
if (DisabledRedisplay) |
| 183 |
return; |
| 184 |
|
| 185 |
#ifdef WINRESIZE |
| 186 |
do |
| 187 |
#endif |
| 188 |
{ |
| 189 |
Window |
| 190 |
*w; |
| 191 |
int |
| 192 |
lineno, |
| 193 |
i; |
| 194 |
jbool |
| 195 |
done_ID = NO, |
| 196 |
old_UpdModLine; |
| 197 |
struct scrimage |
| 198 |
*des_p, |
| 199 |
*phys_p; |
| 200 |
|
| 201 |
#ifdef WINRESIZE |
| 202 |
if (ResizePending) |
| 203 |
resize(); |
| 204 |
#endif |
| 205 |
curwind->w_line = curwind->w_bufp->b_dot; |
| 206 |
curwind->w_char = curwind->w_bufp->b_char; |
| 207 |
#ifdef MAC |
| 208 |
/* To avoid calling redisplay() recursively, |
| 209 |
* we must avoid calling CheckEvent(), |
| 210 |
* so we must avoid calling charp(). |
| 211 |
*/ |
| 212 |
InputPending = NO; |
| 213 |
#else |
| 214 |
if (PreEmptOutput()) |
| 215 |
return; |
| 216 |
#endif |
| 217 |
if (RingBell) { |
| 218 |
dobell(1); |
| 219 |
RingBell = NO; |
| 220 |
} |
| 221 |
AbortCnt = ScrBufSize; /* initialize this now */ |
| 222 |
if (UpdMesg) |
| 223 |
DrawMesg(YES); |
| 224 |
|
| 225 |
for (lineno = 0, w = fwind; lineno < ILI; w = w->w_next) { |
| 226 |
UpdWindow(w, lineno); |
| 227 |
lineno += w->w_height; |
| 228 |
} |
| 229 |
|
| 230 |
/* Now that we've called update window, we can |
| 231 |
* assume that the modeline will be updated. But |
| 232 |
* if while redrawing the modeline the user types |
| 233 |
* a character, ModeLine() is free to set this on |
| 234 |
* again so that the modeline will be fully drawn |
| 235 |
* at the next redisplay. Furthermore, if output |
| 236 |
* is preempted, we'll restore the old value because |
| 237 |
* we can't be sure that the updating has happened. |
| 238 |
*/ |
| 239 |
old_UpdModLine = UpdModLine; |
| 240 |
UpdModLine = NO; |
| 241 |
|
| 242 |
des_p = DesiredScreen; |
| 243 |
phys_p = PhysScreen; |
| 244 |
for (i = 0; i < ILI; i++, des_p++, phys_p++) { |
| 245 |
if (!done_ID && (des_p->s_id != phys_p->s_id)) { |
| 246 |
DoIDline(i); |
| 247 |
done_ID = YES; |
| 248 |
} |
| 249 |
if ((des_p->s_flags & (s_DIRTY | s_L_MOD)) |
| 250 |
|| des_p->s_id != phys_p->s_id |
| 251 |
|| des_p->s_vln != phys_p->s_vln |
| 252 |
|| des_p->s_offset != phys_p->s_offset) |
| 253 |
UpdLine(i); |
| 254 |
if (CheapPreEmptOutput()) { |
| 255 |
if (old_UpdModLine) |
| 256 |
UpdModLine = YES; |
| 257 |
goto suppress; |
| 258 |
} |
| 259 |
} |
| 260 |
|
| 261 |
if (Asking) { |
| 262 |
int p = calc_pos(mesgbuf, AskingWidth); |
| 263 |
jdbg("redisplay CO=%d aw=%d p=%d \"%s\"\n", CO, AskingWidth, p, mesgbuf); |
| 264 |
Placur(ILI, jmin(CO - 2, p)); |
| 265 |
/* Nice kludge */ |
| 266 |
flushscreen(); |
| 267 |
} else { |
| 268 |
GotoDot(); |
| 269 |
} |
| 270 |
suppress: ; |
| 271 |
} |
| 272 |
#ifdef WINRESIZE |
| 273 |
/**/ while (ResizePending); |
| 274 |
#endif |
| 275 |
#ifdef MAC |
| 276 |
if (Windchange) |
| 277 |
docontrols(); |
| 278 |
#endif |
| 279 |
} |
| 280 |
|
| 281 |
/* find_pos() returns the position on the line, that C_CHAR represents |
| 282 |
* in LINE |
| 283 |
*/ |
| 284 |
private int |
| 285 |
find_pos(LinePtr line, int c_char) |
| 286 |
{ |
| 287 |
return calc_pos(lcontents(line), c_char); |
| 288 |
} |
| 289 |
|
| 290 |
/* calc_pos calculates the screen column of character c_char. |
| 291 |
* |
| 292 |
* Note: the calc_pos, how_far, and DeTab must be in synch -- |
| 293 |
* each thinks it knows how characters are displayed. |
| 294 |
*/ |
| 295 |
|
| 296 |
int |
| 297 |
calc_pos(char *lp, int c_char) |
| 298 |
{ |
| 299 |
int pos = 0; |
| 300 |
ZXchar c; |
| 301 |
|
| 302 |
while ((--c_char >= 0) && (c = ZXC(*lp++)) != 0) { |
| 303 |
if (c == '\t' && tabstop != 0) { |
| 304 |
pos += TABDIST(pos); |
| 305 |
} else if (jisprint(c)) { |
| 306 |
pos += 1; |
| 307 |
} else { |
| 308 |
if (c <= DEL) |
| 309 |
pos += 2; |
| 310 |
else |
| 311 |
pos += 4; |
| 312 |
} |
| 313 |
} |
| 314 |
return pos; |
| 315 |
} |
| 316 |
|
| 317 |
volatile jbool |
| 318 |
UpdModLine = NO; |
| 319 |
jbool UpdMesg = NO; |
| 320 |
|
| 321 |
private void |
| 322 |
DoIDline(int start) |
| 323 |
{ |
| 324 |
struct scrimage *des_p = &DesiredScreen[start], |
| 325 |
*phys_p = &PhysScreen[start]; |
| 326 |
int i, |
| 327 |
j; |
| 328 |
|
| 329 |
/* Some changes have been made. Try for insert or delete lines. |
| 330 |
* If either case has happened, Addlines and/or DelLines will do |
| 331 |
* necessary scrolling, also CONVERTING PhysScreen to account for the |
| 332 |
* physical changes. The comparison continues from where the |
| 333 |
* insertion/deletion takes place; this doesn't happen very often, |
| 334 |
* usually it happens with more than one window with the same |
| 335 |
* buffer. |
| 336 |
*/ |
| 337 |
#ifdef TERMCAP |
| 338 |
if (!CanScroll) |
| 339 |
return; /* We should never have been called! */ |
| 340 |
#endif |
| 341 |
|
| 342 |
for (i = start; i < ILI; i++, des_p++, phys_p++) |
| 343 |
if (des_p->s_id != phys_p->s_id) |
| 344 |
break; |
| 345 |
|
| 346 |
for (; i < ILI; i++) { |
| 347 |
for (j = i + 1; j < ILI; j++) { |
| 348 |
des_p = &DesiredScreen[j]; |
| 349 |
phys_p = &PhysScreen[j]; |
| 350 |
if (des_p->s_id != NULL_DADDR && des_p->s_id == phys_p->s_id) |
| 351 |
break; |
| 352 |
|
| 353 |
if (des_p->s_id == PhysScreen[i].s_id) { |
| 354 |
if (des_p->s_id == NULL_DADDR) |
| 355 |
continue; |
| 356 |
|
| 357 |
if (AddLines(i, j - i)) { |
| 358 |
DoIDline(j); |
| 359 |
return; |
| 360 |
} |
| 361 |
break; |
| 362 |
} |
| 363 |
if ((des_p = &DesiredScreen[i])->s_id == phys_p->s_id) { |
| 364 |
if (des_p->s_id == NULL_DADDR) |
| 365 |
continue; |
| 366 |
|
| 367 |
if (DelLines(i, j - i)) { |
| 368 |
DoIDline(i); |
| 369 |
return; |
| 370 |
} |
| 371 |
break; |
| 372 |
} |
| 373 |
} |
| 374 |
} |
| 375 |
} |
| 376 |
|
| 377 |
/* Make DesiredScreen reflect what the screen should look like when we are done |
| 378 |
* with the redisplay. This deals with horizontal scrolling. Also makes |
| 379 |
* sure the current line of the Window is in the window. |
| 380 |
*/ |
| 381 |
jbool ScrollAll = NO; /* VAR: when current line scrolls, scroll whole window? */ |
| 382 |
int ScrollWidth = 10; /* VAR: unit of horizontal scrolling */ |
| 383 |
|
| 384 |
private void |
| 385 |
UpdWindow(Window *w, int start) |
| 386 |
{ |
| 387 |
LinePtr lp; |
| 388 |
long i, |
| 389 |
upper, /* top of window */ |
| 390 |
lower; /* bottom of window */ |
| 391 |
int strt_col, /* starting print column of current line */ |
| 392 |
ntries = 0; /* # of tries at updating window */ |
| 393 |
struct scrimage |
| 394 |
*des_p, |
| 395 |
*phys_p; |
| 396 |
Buffer *bp = w->w_bufp; |
| 397 |
|
| 398 |
do { |
| 399 |
if (w->w_flags & W_CURGONE) { |
| 400 |
w->w_line = bp->b_dot; |
| 401 |
w->w_char = bp->b_char; |
| 402 |
} |
| 403 |
if (w->w_flags & W_TOPGONE) |
| 404 |
CentWind(w); /* reset topline of screen */ |
| 405 |
w->w_flags &= ~(W_CURGONE | W_TOPGONE); |
| 406 |
|
| 407 |
/* make sure that the current line is in the window */ |
| 408 |
upper = start; |
| 409 |
lower = upper + WSIZE(w); |
| 410 |
for (i = upper, lp = w->w_top; ; lp = lp->l_next, i++) { |
| 411 |
if (i == lower || lp == NULL) { |
| 412 |
/* we've run out of window without finding dot */ |
| 413 |
ntries += 1; |
| 414 |
if (ntries == 1) { |
| 415 |
CalcWind(w); |
| 416 |
} else if (ntries == 2) { |
| 417 |
w->w_top = w->w_line = w->w_bufp->b_first; |
| 418 |
writef("\rERROR in redisplay: I got hopelessly lost!"); |
| 419 |
dobell(2); |
| 420 |
} else { |
| 421 |
writef("\n\rOops, still lost, quitting ...\r\n"); |
| 422 |
finish(-1); /* die! */ |
| 423 |
/*NOTREACHED*/ |
| 424 |
} |
| 425 |
break; |
| 426 |
} |
| 427 |
if (lp == w->w_line) { |
| 428 |
ntries = 0; /* happiness: dot is in window */ |
| 429 |
break; |
| 430 |
} |
| 431 |
} |
| 432 |
} while (ntries != 0); |
| 433 |
|
| 434 |
/* first do some calculations for the current line */ |
| 435 |
{ |
| 436 |
int |
| 437 |
nw = W_NUMWIDTH(w), |
| 438 |
dot_col, |
| 439 |
end_col; |
| 440 |
|
| 441 |
strt_col = ScrollAll? w->w_LRscroll : PhysScreen[i].s_offset; |
| 442 |
end_col = strt_col + (CO - 1) - (nw + SIWIDTH(strt_col)); |
| 443 |
/* Right now we are displaying from strt_col to |
| 444 |
* end_col of the buffer line. These are PRINT |
| 445 |
* columns, not actual characters. |
| 446 |
*/ |
| 447 |
dot_col = w->w_dotcol = find_pos(w->w_line, w->w_char); |
| 448 |
/* if the new dotcol is out of range, reselect |
| 449 |
* a horizontal window |
| 450 |
*/ |
| 451 |
if (PhysScreen[i].s_offset == -1 |
| 452 |
|| !(strt_col <= dot_col && dot_col < end_col)) |
| 453 |
{ |
| 454 |
/* If dot_col is within first step left of screen, step left. |
| 455 |
* Otherwise, if ditto for right. |
| 456 |
* Otherwise, if it is in first screenwidth, start from begining. |
| 457 |
* Otherwise, center dot_col. |
| 458 |
* Fudge: if a scroll left would work except for the necessary |
| 459 |
* appearance of an ! on the left, we scroll an extra column. |
| 460 |
*/ |
| 461 |
int |
| 462 |
step = jmin(ScrollWidth, end_col - strt_col); |
| 463 |
|
| 464 |
strt_col = |
| 465 |
strt_col > dot_col && strt_col - step <= dot_col |
| 466 |
? jmax(strt_col - step, 0) |
| 467 |
: dot_col >= end_col && dot_col < end_col + step |
| 468 |
? jmin(strt_col + step |
| 469 |
+ (strt_col == 0 && dot_col == end_col + step - 1? 1 : 0) |
| 470 |
, dot_col) |
| 471 |
: dot_col < ((CO - 1) - nw) |
| 472 |
? 0 |
| 473 |
: dot_col - ((CO - nw) / 2); |
| 474 |
|
| 475 |
if (ScrollAll) { |
| 476 |
if (w->w_LRscroll != strt_col) |
| 477 |
UpdModLine = YES; |
| 478 |
w->w_LRscroll = strt_col; |
| 479 |
} |
| 480 |
} |
| 481 |
w->w_dotline = i; |
| 482 |
w->w_dotcol = dot_col + nw + SIWIDTH(strt_col); |
| 483 |
} |
| 484 |
|
| 485 |
lp = w->w_top; |
| 486 |
des_p = &DesiredScreen[upper]; |
| 487 |
phys_p = &PhysScreen[upper]; |
| 488 |
for (i = upper; i < lower; i++, des_p++, phys_p++) { |
| 489 |
if (lp != NULL) { |
| 490 |
des_p->s_offset = (lp == w->w_line)? strt_col : w->w_LRscroll; |
| 491 |
des_p->s_flags = isdirty(lp) ? s_L_MOD : 0; |
| 492 |
des_p->s_vln = (w->w_flags & W_NUMLINES)? |
| 493 |
w->w_topnum + (i - upper) : 0; |
| 494 |
des_p->s_id = (lp == curline && DOLsave)? |
| 495 |
UNSAVED_CURLINE_DADDR : lp->l_dline & ~DDIRTY; |
| 496 |
des_p->s_lp = lp; |
| 497 |
lp = lp->l_next; |
| 498 |
} else { |
| 499 |
/* display line beyond end of buffer */ |
| 500 |
static const struct scrimage |
| 501 |
clean_plate = { 0, 0, 0, NULL_DADDR, NULL, NULL }; |
| 502 |
|
| 503 |
*des_p = clean_plate; |
| 504 |
if (phys_p->s_id != NULL_DADDR) |
| 505 |
des_p->s_flags = s_DIRTY; |
| 506 |
} |
| 507 |
des_p->s_window = w; |
| 508 |
} |
| 509 |
|
| 510 |
/* mode line: */ |
| 511 |
|
| 512 |
/* ??? The following assignment to des_p->s_id is tricky: |
| 513 |
* |
| 514 |
* We count on the cast pointer value being distinct from |
| 515 |
* any other daddr, but equal to itself. Turning |
| 516 |
* the "DDIRTY" bit on should ensure that it is distinct |
| 517 |
* from legitimate daddr values (except for NOWHERE_DADDR |
| 518 |
* and UNSAVED_CURLINE_DADDR). |
| 519 |
* If sizeof(Buffer *)>sizeof(daddr), nothing ensures that |
| 520 |
* these pointers are even distinct from each other. |
| 521 |
* |
| 522 |
* There also seems to be an assumption that every modeline |
| 523 |
* for a particular buffer will be the same. This is not |
| 524 |
* always the case: the last modeline on the screen is usually |
| 525 |
* different from any other modeline, even for the same buffer. |
| 526 |
* Currently, I think that only very contrived cases could cause |
| 527 |
* problems (probably involving window resizing). |
| 528 |
* Further problems will arise if JOVE is changed so that there are |
| 529 |
* other ways in which a modeline can reflect the window state |
| 530 |
* (instead of just the buffer state). |
| 531 |
* |
| 532 |
* -- DHR |
| 533 |
*/ |
| 534 |
des_p->s_window = w; |
| 535 |
des_p->s_id = (jwid_t) w->w_bufp | DDIRTY; |
| 536 |
des_p->s_flags = (des_p->s_id != phys_p->s_id || UpdModLine)? |
| 537 |
s_MODELINE | s_DIRTY : 0; |
| 538 |
des_p->s_offset = 0; |
| 539 |
des_p->s_vln = 0; |
| 540 |
des_p->s_lp = NULL; |
| 541 |
|
| 542 |
#ifdef MAC |
| 543 |
if (UpdModLine) |
| 544 |
Modechange = YES; |
| 545 |
if (w == curwind && w->w_control != NULL) |
| 546 |
SetScrollBar(w); |
| 547 |
#endif |
| 548 |
} |
| 549 |
|
| 550 |
/* Write whatever is in mesgbuf (maybe we are Asking, or just printed |
| 551 |
* a message). Turns off the UpdateMesg line flag. |
| 552 |
*/ |
| 553 |
void |
| 554 |
DrawMesg(jbool abortable) |
| 555 |
{ |
| 556 |
char outbuf[MAXCOLS + PPWIDTH]; /* assert(CO <= MAXCOLS); */ |
| 557 |
|
| 558 |
#ifndef MAC /* same reason as in redisplay() */ |
| 559 |
if (PreEmptOutput()) |
| 560 |
return; |
| 561 |
#endif |
| 562 |
i_set(ILI, 0); |
| 563 |
jdbg("DrawMesg aw=%d \"%s\"\n", AskingWidth, mesgbuf); |
| 564 |
DeTab(mesgbuf, 0, outbuf, outbuf + CO, NO); |
| 565 |
if (swrite(outbuf, NOEFFECT, abortable)) { |
| 566 |
cl_eol(); |
| 567 |
UpdMesg = NO; |
| 568 |
} |
| 569 |
flushscreen(); |
| 570 |
} |
| 571 |
|
| 572 |
/* Goto the current position in the current window. Presumably redisplay() |
| 573 |
* has already been called, and curwind->{w_dotline,w_dotcol} have been set |
| 574 |
* correctly. |
| 575 |
*/ |
| 576 |
private void |
| 577 |
GotoDot(void) |
| 578 |
{ |
| 579 |
if (!CheapPreEmptOutput()) { |
| 580 |
Placur(curwind->w_dotline, |
| 581 |
curwind->w_dotcol - PhysScreen[curwind->w_dotline].s_offset); |
| 582 |
flushscreen(); |
| 583 |
} |
| 584 |
} |
| 585 |
|
| 586 |
private int |
| 587 |
UntilEqual(int start) |
| 588 |
{ |
| 589 |
struct scrimage *des_p = &DesiredScreen[start], |
| 590 |
*phys_p = &PhysScreen[start]; |
| 591 |
|
| 592 |
while ((start < ILI) && (des_p->s_id != phys_p->s_id)) { |
| 593 |
des_p += 1; |
| 594 |
phys_p += 1; |
| 595 |
start += 1; |
| 596 |
} |
| 597 |
|
| 598 |
return start; |
| 599 |
} |
| 600 |
|
| 601 |
/* Calls the routine to do the physical changes, and changes PhysScreen to |
| 602 |
* reflect those changes. |
| 603 |
*/ |
| 604 |
private jbool |
| 605 |
AddLines(int at, int num) |
| 606 |
{ |
| 607 |
int i; |
| 608 |
int bottom = UntilEqual(at + num); |
| 609 |
|
| 610 |
if (num == 0 || num >= ((bottom - 1) - at)) |
| 611 |
return NO; /* we did nothing */ |
| 612 |
|
| 613 |
v_ins_line(num, at, bottom - 1); |
| 614 |
|
| 615 |
/* Now change PhysScreen to account for the physical change. */ |
| 616 |
|
| 617 |
for (i = bottom - 1; i - num >= at; i--) |
| 618 |
PhysScreen[i] = PhysScreen[i - num]; |
| 619 |
for (i = 0; i < num; i++) |
| 620 |
PhysScreen[at + i].s_id = NULL_DADDR; |
| 621 |
return YES; /* we did something */ |
| 622 |
} |
| 623 |
|
| 624 |
private jbool |
| 625 |
DelLines(int at, int num) |
| 626 |
{ |
| 627 |
int i; |
| 628 |
int bottom = UntilEqual(at + num); |
| 629 |
|
| 630 |
if (num == 0 || num >= ((bottom - 1) - at)) |
| 631 |
return NO; |
| 632 |
|
| 633 |
v_del_line(num, at, bottom - 1); |
| 634 |
|
| 635 |
for (i = at; num + i < bottom; i++) |
| 636 |
PhysScreen[i] = PhysScreen[num + i]; |
| 637 |
for (i = bottom - num; i < bottom; i++) |
| 638 |
PhysScreen[i].s_id = NULL_DADDR; |
| 639 |
return YES; |
| 640 |
} |
| 641 |
|
| 642 |
jbool MarkHighlighting = YES; /* VAR: highlight mark when visible */ |
| 643 |
|
| 644 |
/* Update line linenum in window w. Only set PhysScreen to DesiredScreen |
| 645 |
* if the swrite or cl_eol works, that is nothing is interrupted by |
| 646 |
* characters typed. |
| 647 |
*/ |
| 648 |
private void |
| 649 |
UpdLine(int linenum) |
| 650 |
{ |
| 651 |
struct scrimage *des_p = &DesiredScreen[linenum]; |
| 652 |
Window *w = des_p->s_window; |
| 653 |
char outbuf[MAXCOLS + PPWIDTH]; /* assert(CO <= MAXCOLS); */ |
| 654 |
|
| 655 |
i_set(linenum, 0); |
| 656 |
if (des_p->s_flags & s_MODELINE) { |
| 657 |
ModeLine(w, outbuf, linenum); |
| 658 |
} else if (des_p->s_id != NULL_DADDR) { |
| 659 |
char *lptr; |
| 660 |
int fromcol = W_NUMWIDTH(w); |
| 661 |
#ifdef HIGHLIGHTING |
| 662 |
static struct LErange lr = {0, 0, LENULLPROC, US_effect}; |
| 663 |
Mark *mark = b_curmark(w->w_bufp); |
| 664 |
jbool marked_line = (MarkHighlighting |
| 665 |
# ifdef TERMCAP |
| 666 |
&& US != NULL |
| 667 |
# endif |
| 668 |
&& mark != NULL |
| 669 |
&& mark->m_line == des_p->s_lp); |
| 670 |
#endif /* HIGHLIGHTING */ |
| 671 |
|
| 672 |
des_p->s_lp->l_dline &= ~DDIRTY; |
| 673 |
des_p->s_flags &= ~(s_DIRTY | s_L_MOD); |
| 674 |
|
| 675 |
if (w->w_flags & W_NUMLINES) { |
| 676 |
outbuf[fromcol-2] = ' '; |
| 677 |
swritef(outbuf, sizeof(outbuf), "%6D ", des_p->s_vln); |
| 678 |
if (outbuf[fromcol-2] != ' ') { |
| 679 |
outbuf[fromcol-2] = '*'; |
| 680 |
outbuf[fromcol-1] = ' '; |
| 681 |
} |
| 682 |
} |
| 683 |
if (des_p->s_offset != 0) { |
| 684 |
outbuf[fromcol++] = '!'; |
| 685 |
outbuf[fromcol] = '\0'; |
| 686 |
} |
| 687 |
lptr = lcontents(des_p->s_lp); |
| 688 |
DeTab(lptr, des_p->s_offset, outbuf + fromcol, |
| 689 |
outbuf + CO, (w->w_flags & W_VISSPACE) != 0); |
| 690 |
#ifdef HIGHLIGHTING |
| 691 |
if (marked_line) { |
| 692 |
lr.start = calc_pos(lptr, mark->m_char) |
| 693 |
- des_p->s_offset + fromcol; |
| 694 |
lr.width = 1; |
| 695 |
if (lr.start < sizeof(outbuf) - 1 && outbuf[lr.start] == '\0') { |
| 696 |
outbuf[lr.start] = ' '; |
| 697 |
outbuf[lr.start + 1] = '\0'; |
| 698 |
} |
| 699 |
} |
| 700 |
#endif /* HIGHLIGHTING */ |
| 701 |
#ifdef ID_CHAR |
| 702 |
/* REMIND: This code, along with the rest of the |
| 703 |
* ID_CHAR, belongs in the screen driver for |
| 704 |
* termcap based systems. mac and pc's and other |
| 705 |
* window-based drivers don't give a hoot about |
| 706 |
* ID_CHAR. |
| 707 |
*/ |
| 708 |
/* attempt to exploit insert or delete character capability |
| 709 |
* but only if not highlighting some part of the line |
| 710 |
*/ |
| 711 |
if (UseIC && Curline->s_effects == NOEFFECT |
| 712 |
# ifdef HIGHLIGHTING |
| 713 |
&& !marked_line |
| 714 |
# endif /* HIGHLIGHTING */ |
| 715 |
) { |
| 716 |
if (IDchar(outbuf, linenum)) { |
| 717 |
/* success: clean up and go home */ |
| 718 |
PhysScreen[linenum] = *des_p; |
| 719 |
return; |
| 720 |
} |
| 721 |
/* failure: re-initialize various cursors */ |
| 722 |
i_set(linenum, 0); |
| 723 |
} |
| 724 |
#endif /* ID_CHAR */ |
| 725 |
|
| 726 |
if (swrite(outbuf, |
| 727 |
#ifdef HIGHLIGHTING |
| 728 |
marked_line ? &lr : NOEFFECT, |
| 729 |
#else |
| 730 |
NOEFFECT, |
| 731 |
#endif |
| 732 |
YES)) |
| 733 |
{ |
| 734 |
do_cl_eol(linenum); |
| 735 |
} else { |
| 736 |
/* interrupted: mark indeterminate state */ |
| 737 |
PhysScreen[linenum].s_id = NOWHERE_DADDR; |
| 738 |
} |
| 739 |
} else if (PhysScreen[linenum].s_id != NULL_DADDR) { |
| 740 |
/* not the same ... make sure */ |
| 741 |
do_cl_eol(linenum); |
| 742 |
} |
| 743 |
} |
| 744 |
|
| 745 |
private void |
| 746 |
do_cl_eol(int linenum) |
| 747 |
{ |
| 748 |
cl_eol(); |
| 749 |
PhysScreen[linenum] = DesiredScreen[linenum]; |
| 750 |
} |
| 751 |
|
| 752 |
/* Expand tabs (and other funny characters) of a section of "buf" |
| 753 |
* into "outbuf". |
| 754 |
* |
| 755 |
* Note: outbuf must allow for at least PPWIDTH extra characters. |
| 756 |
* This is sufficient room for one extra character to be displayed, |
| 757 |
* streamlining the code. |
| 758 |
* |
| 759 |
* Note: the calc_pos, how_far, and DeTab must be in synch -- |
| 760 |
* each thinks it knows how characters are displayed. |
| 761 |
*/ |
| 762 |
|
| 763 |
private void |
| 764 |
DeTab(char *src, int start_offset, char *dst, char *dst_limit, jbool visspace) |
| 765 |
{ |
| 766 |
ZXchar c; |
| 767 |
int offset = start_offset; |
| 768 |
|
| 769 |
/* At any time, the number of characters we've output is |
| 770 |
* start_offset - offset. This is needed to correctly |
| 771 |
* calculate TABDIST() without having to add another |
| 772 |
* variable (pos) to be incremented for each call to addc. |
| 773 |
*/ |
| 774 |
#define addc(ch) { if (--offset < 0) *dst++ = (ch); } |
| 775 |
|
| 776 |
while ((c = ZXC(*src++)) != '\0') { |
| 777 |
if (c == '\t' && tabstop != 0) { |
| 778 |
int nchars = TABDIST(start_offset - offset); |
| 779 |
|
| 780 |
c = visspace? '>' : ' '; |
| 781 |
while (--nchars > 0 && dst < dst_limit) { |
| 782 |
addc(c); |
| 783 |
c = ' '; |
| 784 |
} |
| 785 |
} else if (jisprint(c)) { |
| 786 |
if (visspace && c == ' ') |
| 787 |
c = '_'; |
| 788 |
} else { |
| 789 |
char buf[PPWIDTH]; |
| 790 |
char *p; |
| 791 |
|
| 792 |
PPchar(c, buf); |
| 793 |
/* assert(buf[0] != '\0'); */ |
| 794 |
for (p = buf; (c = *p++), *p != '\0'; ) |
| 795 |
addc(c); |
| 796 |
} |
| 797 |
if (--offset < 0) { |
| 798 |
*dst++ = c; |
| 799 |
if (dst >= dst_limit) { |
| 800 |
/* we've run out of real estate: truncate and flag it */ |
| 801 |
dst = dst_limit-1; |
| 802 |
*dst++ = '!'; |
| 803 |
break; |
| 804 |
} |
| 805 |
} |
| 806 |
} |
| 807 |
#undef addc |
| 808 |
*dst = '\0'; |
| 809 |
} |
| 810 |
|
| 811 |
|
| 812 |
#ifdef ID_CHAR |
| 813 |
|
| 814 |
/* From here to the end of the file is code that tries to utilize the |
| 815 |
* insert/delete character feature on some terminals. It is very confusing |
| 816 |
* and not so well written code, AND there is a lot of it. You may want |
| 817 |
* to use the space for something else. |
| 818 |
*/ |
| 819 |
jbool IN_INSmode = NO; |
| 820 |
|
| 821 |
void |
| 822 |
INSmode(jbool on) |
| 823 |
{ |
| 824 |
if (on != IN_INSmode) { |
| 825 |
putpad(on? IM : EI, 1); |
| 826 |
IN_INSmode = on; |
| 827 |
} |
| 828 |
} |
| 829 |
|
| 830 |
/* ID character routines full of special cases and other fun stuff like that. |
| 831 |
* It actually works though ... |
| 832 |
* |
| 833 |
* Returns Non-Zero if you are finished (no differences left). |
| 834 |
*/ |
| 835 |
private jbool |
| 836 |
IDchar(char *new, int lineno) |
| 837 |
{ |
| 838 |
int col = 0; |
| 839 |
struct screenline |
| 840 |
*sline = &Screen[lineno]; |
| 841 |
char *old = sline->s_line; |
| 842 |
int newlen = strlen(new); |
| 843 |
|
| 844 |
for (;;) { |
| 845 |
int oldlen = sline->s_roof - old; |
| 846 |
int i; |
| 847 |
|
| 848 |
for (; ; col++) { |
| 849 |
if (col == oldlen || col == newlen) |
| 850 |
return oldlen == newlen; /* one ended; happy if both ended */ |
| 851 |
|
| 852 |
if (old[col] != new[col]) |
| 853 |
break; |
| 854 |
} |
| 855 |
|
| 856 |
/* col now is first difference, and not the end of either */ |
| 857 |
|
| 858 |
/* see if an insertion will help */ |
| 859 |
|
| 860 |
for (i = col + 1; i < newlen; i++) { |
| 861 |
if (new[i] == old[col]) { |
| 862 |
/* The number of saved characters is (roughly) |
| 863 |
* the number of characters we can retain after |
| 864 |
* the insertion, minus the number that we |
| 865 |
* could have salvaged without moving them. |
| 866 |
*/ |
| 867 |
int NumSaved = IDcomp(new + i, old + col, oldlen-col) |
| 868 |
- NumSimilar(new + col, old + col, jmin(i, oldlen)-col); |
| 869 |
|
| 870 |
if (OkayInsert(NumSaved, i - col)) { |
| 871 |
InsChar(lineno, col, i - col, new); |
| 872 |
col = i; |
| 873 |
break; |
| 874 |
} |
| 875 |
} |
| 876 |
} |
| 877 |
if (i != newlen) |
| 878 |
continue; |
| 879 |
|
| 880 |
/* see if a deletion will help */ |
| 881 |
|
| 882 |
for (i = col + 1; i < oldlen; i++) { |
| 883 |
if (new[col] == old[i]) { |
| 884 |
int NumSaved = IDcomp(new + col, old + i, oldlen - i); |
| 885 |
|
| 886 |
if (OkayDelete(NumSaved, i - col, newlen == oldlen)) { |
| 887 |
DelChar(lineno, col, i - col); |
| 888 |
break; |
| 889 |
} |
| 890 |
} |
| 891 |
} |
| 892 |
if (i != oldlen) |
| 893 |
continue; |
| 894 |
|
| 895 |
return NO; |
| 896 |
} |
| 897 |
} |
| 898 |
|
| 899 |
private int |
| 900 |
NumSimilar(char *s, char *t, int n) |
| 901 |
{ |
| 902 |
int num = 0; |
| 903 |
|
| 904 |
while (n--) |
| 905 |
if (*s++ == *t++) |
| 906 |
num += 1; |
| 907 |
return num; |
| 908 |
} |
| 909 |
|
| 910 |
private int |
| 911 |
IDcomp(char *s, char *t, int len) |
| 912 |
{ |
| 913 |
int i, |
| 914 |
num = 0, |
| 915 |
nonspace = 0; |
| 916 |
|
| 917 |
for (i = 0; i < len; i++) { |
| 918 |
char c = *s++; |
| 919 |
|
| 920 |
if (c == '\0' || c != *t++) |
| 921 |
break; |
| 922 |
|
| 923 |
if (c != ' ') |
| 924 |
nonspace = 1; |
| 925 |
num += nonspace; |
| 926 |
} |
| 927 |
|
| 928 |
return num; |
| 929 |
} |
| 930 |
|
| 931 |
private jbool |
| 932 |
OkayDelete(int Saved, int num, jbool samelength) |
| 933 |
{ |
| 934 |
/* If the old and the new have different lengths, then the competition |
| 935 |
* will have to clear to end of line. We take that into consideration. |
| 936 |
* Note: we must avoid multiplying by INFINITY. |
| 937 |
*/ |
| 938 |
return Saved + (samelength ? 0 : CElen) > |
| 939 |
jmin(MDClen, DC != NULL? DClen * num : INFINITY); |
| 940 |
} |
| 941 |
|
| 942 |
private jbool |
| 943 |
OkayInsert(int Saved, int num) |
| 944 |
{ |
| 945 |
# ifdef NCURSES_BUG |
| 946 |
/* Note: with the ncurses version of termcap/terminfo, we must use |
| 947 |
* any one of insert mode, insert character, or multiple insert character. |
| 948 |
*/ |
| 949 |
int n = INFINITY; |
| 950 |
|
| 951 |
if (IC != NULL) /* Per character prefixes */ |
| 952 |
n = num * IClen; |
| 953 |
n = jmin(n, MIClen); |
| 954 |
n = jmin(n, IMEIlen); |
| 955 |
# else /* !NCURSES_BUG */ |
| 956 |
/* Note: the way termcap/terminfo is defined, we must use *both* |
| 957 |
* IC and IM to insert, but normally only one will be defined. |
| 958 |
* See terminfo(5), under the heading "Insert/Delete Character". |
| 959 |
*/ |
| 960 |
int n = 0; |
| 961 |
|
| 962 |
if (IC != NULL) /* Per character prefixes */ |
| 963 |
n = jmin(num * IClen, MIClen); |
| 964 |
|
| 965 |
if (!IN_INSmode) |
| 966 |
n += IMEIlen; |
| 967 |
# endif /* !NCURSES_BUG */ |
| 968 |
n += num; /* The characters themselves */ |
| 969 |
|
| 970 |
return Saved > n; |
| 971 |
} |
| 972 |
|
| 973 |
private void |
| 974 |
DelChar(int lineno, int col, int num) |
| 975 |
{ |
| 976 |
struct screenline *sp = (&Screen[lineno]); |
| 977 |
|
| 978 |
Placur(lineno, col); |
| 979 |
putmulti(DC, M_DC, num, 1); |
| 980 |
|
| 981 |
/* Shift the remaining characters left in the buffer to close the gap. |
| 982 |
* byte_copy cannot be used since the destination overlaps the source. |
| 983 |
*/ |
| 984 |
{ |
| 985 |
char *to = sp->s_line + col, |
| 986 |
*from = to + num; |
| 987 |
size_t len = sp->s_roof - from; |
| 988 |
byte_move(from, to, len); |
| 989 |
} |
| 990 |
clrline(sp->s_roof - num, sp->s_roof); |
| 991 |
sp->s_roof -= num; |
| 992 |
} |
| 993 |
|
| 994 |
private void |
| 995 |
InsChar(int lineno, int col, int num, char *new) |
| 996 |
{ |
| 997 |
char *sp1, |
| 998 |
*sp2, /* To push over the array. */ |
| 999 |
*sp3; /* Last character to push over. */ |
| 1000 |
int i; |
| 1001 |
|
| 1002 |
i_set(lineno, 0); |
| 1003 |
sp2 = Curline->s_roof + num; |
| 1004 |
|
| 1005 |
if (sp2 > cursend) { |
| 1006 |
i_set(lineno, CO - num - 1); |
| 1007 |
cl_eol(); |
| 1008 |
sp2 = cursend; |
| 1009 |
} |
| 1010 |
Curline->s_roof = sp2; |
| 1011 |
sp1 = sp2 - num; |
| 1012 |
sp3 = Curline->s_line + col; |
| 1013 |
|
| 1014 |
while (sp1 > sp3) |
| 1015 |
*--sp2 = *--sp1; |
| 1016 |
|
| 1017 |
new += col; |
| 1018 |
byte_copy(new, sp3, (size_t) num); |
| 1019 |
|
| 1020 |
/* The internal screen is correct, and now we have to do |
| 1021 |
* the physical stuff. |
| 1022 |
*/ |
| 1023 |
Placur(lineno, col); |
| 1024 |
|
| 1025 |
# ifdef NCURSES_BUG |
| 1026 |
/* Note: with the ncurses version of termcap/terminfo, we must use |
| 1027 |
* any one of insert mode, insert character, or multiple insert character. |
| 1028 |
*/ |
| 1029 |
if (IN_INSmode |
| 1030 |
|| ((IC == NULL || IMEIlen < num * IClen) && IMEIlen < MIClen)) |
| 1031 |
INSmode(YES); |
| 1032 |
else |
| 1033 |
putmulti(IC, M_IC, num, 1); |
| 1034 |
# else /* !NCURSES_BUG */ |
| 1035 |
/* Note: the way termcap/terminfo is defined, we must use *both* |
| 1036 |
* IC and IM, but normally only one will be defined. |
| 1037 |
* See terminfo(5), under the heading "Insert/Delete Character". |
| 1038 |
*/ |
| 1039 |
if (IC != NULL) |
| 1040 |
putmulti(IC, M_IC, num, 1); |
| 1041 |
if (IM != NULL) |
| 1042 |
INSmode(YES); |
| 1043 |
# endif /* !NCURSES_BUG */ |
| 1044 |
|
| 1045 |
for (i = 0; i < num; i++) { |
| 1046 |
scr_putchar(new[i]); |
| 1047 |
if (IN_INSmode) |
| 1048 |
putpad(IP, 1); |
| 1049 |
} |
| 1050 |
CapCol += num; |
| 1051 |
} |
| 1052 |
|
| 1053 |
#endif /* ID_CHAR */ |
| 1054 |
|
| 1055 |
#ifdef UNIX /* obviously ... no mail today if not Unix*/ |
| 1056 |
|
| 1057 |
/* chkmail() returns YES if there is new mail since the |
| 1058 |
* last time we checked. |
| 1059 |
*/ |
| 1060 |
char Mailbox[FILESIZE]; /* VAR: mailbox name */ |
| 1061 |
int MailInt = 60; /* VAR: mail check interval (seconds) */ |
| 1062 |
|
| 1063 |
jbool |
| 1064 |
chkmail(jbool force) |
| 1065 |
{ |
| 1066 |
time_t now; |
| 1067 |
static jbool state = NO; /* assume unknown */ |
| 1068 |
static time_t last_chk = 0, |
| 1069 |
mbox_time = 0; |
| 1070 |
struct stat stbuf; |
| 1071 |
|
| 1072 |
if (MailInt == 0 || Mailbox[0] == '\0') |
| 1073 |
return NO; |
| 1074 |
|
| 1075 |
time(&now); |
| 1076 |
if ((force == NO) && (now < last_chk + MailInt)) |
| 1077 |
return state; |
| 1078 |
|
| 1079 |
last_chk = now; |
| 1080 |
if (stat(Mailbox, &stbuf) < 0) { |
| 1081 |
state = NO; /* no mail */ |
| 1082 |
return NO; |
| 1083 |
} |
| 1084 |
if ((stbuf.st_atime > stbuf.st_mtime && stbuf.st_atime > mbox_time) |
| 1085 |
|| stbuf.st_size == 0) |
| 1086 |
{ |
| 1087 |
mbox_time = stbuf.st_atime; |
| 1088 |
state = NO; |
| 1089 |
} else if (stbuf.st_mtime > mbox_time) { |
| 1090 |
if (mbox_time > 0) |
| 1091 |
dobell(2); /* announce the change */ |
| 1092 |
mbox_time = stbuf.st_mtime; |
| 1093 |
state = YES; |
| 1094 |
} |
| 1095 |
return state; |
| 1096 |
} |
| 1097 |
|
| 1098 |
#endif /* UNIX */ |
| 1099 |
|
| 1100 |
/* Print the mode line. */ |
| 1101 |
|
| 1102 |
private char *mode_p, |
| 1103 |
*mend_p; |
| 1104 |
jbool BriteMode = YES; /* VAR: make the mode line inverse? */ |
| 1105 |
|
| 1106 |
private void |
| 1107 |
mode_app(const char *str) |
| 1108 |
{ |
| 1109 |
ZXchar c; |
| 1110 |
|
| 1111 |
while (mode_p < mend_p && (c = ZXC(*str++)) != '\0') { |
| 1112 |
/* don't expand tabs: treat them as suspects */ |
| 1113 |
if (jisprint(c)) { |
| 1114 |
*mode_p++ = c; |
| 1115 |
} else { |
| 1116 |
char buf[PPWIDTH]; |
| 1117 |
|
| 1118 |
PPchar(c, buf); |
| 1119 |
mode_app(buf); |
| 1120 |
} |
| 1121 |
} |
| 1122 |
|
| 1123 |
} |
| 1124 |
|
| 1125 |
/* VAR: mode line format string */ |
| 1126 |
char ModeFmt[MAXCOLS] = "%[Jove%]%w%w%c(%M)%3c[%b:%n]%2c\"%f\"%c%i# %m*-%2c%p%2s%(%d%e(%t)%)"; |
| 1127 |
|
| 1128 |
private void |
| 1129 |
ModeLine(Window *w, char *line, int linenum) |
| 1130 |
{ |
| 1131 |
int n, |
| 1132 |
glue = 0; |
| 1133 |
jbool ign_some = NO, |
| 1134 |
td = NO; /* is time (kludge: or mail status) displayed? */ |
| 1135 |
char *fmt = ModeFmt, |
| 1136 |
fillc, |
| 1137 |
c; |
| 1138 |
Buffer *thisbuf = w->w_bufp, |
| 1139 |
*bp; |
| 1140 |
LineEffects |
| 1141 |
highlighting; |
| 1142 |
|
| 1143 |
mode_p = line; |
| 1144 |
mend_p = &line[CO - 1]; |
| 1145 |
|
| 1146 |
#ifdef TERMCAP |
| 1147 |
if (SO == NULL) |
| 1148 |
BriteMode = NO; /* we can't do it */ |
| 1149 |
#endif |
| 1150 |
/* ??? On Mac, perhaps '_' looks better than '-' */ |
| 1151 |
fillc = BriteMode? ' ' : '-'; |
| 1152 |
|
| 1153 |
while ((c = *fmt++)!='\0' && mode_p<mend_p) { |
| 1154 |
if (c != '%') { |
| 1155 |
if (c == '\\') |
| 1156 |
if ((c = *fmt++) == '\0') |
| 1157 |
break; |
| 1158 |
|
| 1159 |
if (!ign_some) { |
| 1160 |
static char x[] = "x"; |
| 1161 |
|
| 1162 |
x[0] = c; |
| 1163 |
mode_app(x); |
| 1164 |
} |
| 1165 |
continue; |
| 1166 |
} |
| 1167 |
if ((c = *fmt++) == '\0') /* char after the '%' */ |
| 1168 |
break; |
| 1169 |
|
| 1170 |
if (ign_some && c != ')') |
| 1171 |
continue; |
| 1172 |
|
| 1173 |
n = 1; |
| 1174 |
if (c >= '0' && c <= '9') { |
| 1175 |
n = 0; |
| 1176 |
while (c >= '0' && c <= '9') { |
| 1177 |
n = n * 10 + (c - '0'); |
| 1178 |
c = *fmt++; |
| 1179 |
} |
| 1180 |
if (c == '\0') |
| 1181 |
break; |
| 1182 |
} |
| 1183 |
switch (c) { |
| 1184 |
case '%': |
| 1185 |
mode_app("%"); |
| 1186 |
break; |
| 1187 |
|
| 1188 |
case '(': |
| 1189 |
if (w->w_next != fwind) /* Not bottom window. */ |
| 1190 |
ign_some = YES; |
| 1191 |
break; |
| 1192 |
|
| 1193 |
case ')': |
| 1194 |
ign_some = NO; |
| 1195 |
break; |
| 1196 |
|
| 1197 |
case '[': |
| 1198 |
case ']': |
| 1199 |
for (n=RecDepth; n>0 && mode_p<mend_p; n--) |
| 1200 |
*mode_p++ = c; |
| 1201 |
break; |
| 1202 |
|
| 1203 |
#ifdef UNIX |
| 1204 |
case 'C': /* check mail here */ |
| 1205 |
td = YES; /* kludge: reflect old behaviour where alarm could trigger mail check */ |
| 1206 |
if (chkmail(NO)) |
| 1207 |
mode_app("[New mail]"); |
| 1208 |
break; |
| 1209 |
#endif /* UNIX */ |
| 1210 |
|
| 1211 |
case 'M': |
| 1212 |
{ |
| 1213 |
static const char *const majname[NMAJORS] = { |
| 1214 |
"Fundamental", |
| 1215 |
"Text", |
| 1216 |
"C", |
| 1217 |
#ifdef LISP |
| 1218 |
"Lisp", |
| 1219 |
#endif |
| 1220 |
}; |
| 1221 |
|
| 1222 |
/* |
| 1223 |
* Minor mode names clue to the command needed * to turn |
| 1224 |
* them off |
| 1225 |
*/ |
| 1226 |
static const char *const minname[] = { |
| 1227 |
" AuFill", |
| 1228 |
" WoAbbr", |
| 1229 |
" OvWrt", |
| 1230 |
" AuInd", |
| 1231 |
" ReadO", |
| 1232 |
" ShoMat", |
| 1233 |
#ifdef IPROCS |
| 1234 |
" DBX", |
| 1235 |
#endif |
| 1236 |
}; |
| 1237 |
|
| 1238 |
int minors = thisbuf->b_minor; |
| 1239 |
const char *const *p; |
| 1240 |
|
| 1241 |
mode_app(majname[thisbuf->b_major]); |
| 1242 |
|
| 1243 |
for (p = minname; minors != 0; p++) { |
| 1244 |
if (minors & 01) |
| 1245 |
mode_app(*p); |
| 1246 |
minors >>= 1; |
| 1247 |
} |
| 1248 |
|
| 1249 |
if (InMacDefine) |
| 1250 |
mode_app(" Def"); |
| 1251 |
break; |
| 1252 |
} |
| 1253 |
|
| 1254 |
case 'c': |
| 1255 |
while (--n>=0 && mode_p<mend_p) |
| 1256 |
*mode_p++ = fillc; |
| 1257 |
break; |
| 1258 |
|
| 1259 |
case 'd': /* print working directory */ |
| 1260 |
mode_app(pr_name(pwd(), YES)); |
| 1261 |
break; |
| 1262 |
|
| 1263 |
case 'e': /* stretchable glue */ |
| 1264 |
*mode_p++ = '\0'; /* glue marker */ |
| 1265 |
glue++; |
| 1266 |
break; |
| 1267 |
|
| 1268 |
case 'b': |
| 1269 |
mode_app(thisbuf->b_name); |
| 1270 |
break; |
| 1271 |
|
| 1272 |
case 'f': |
| 1273 |
case 'F': |
| 1274 |
if (thisbuf->b_fname == NULL) |
| 1275 |
mode_app("[No file]"); |
| 1276 |
else { |
| 1277 |
if (c == 'f') |
| 1278 |
mode_app(pr_name(thisbuf->b_fname, YES)); |
| 1279 |
else |
| 1280 |
mode_app(jbasename(thisbuf->b_fname)); |
| 1281 |
} |
| 1282 |
break; |
| 1283 |
|
| 1284 |
case 'i': |
| 1285 |
{ |
| 1286 |
char yea = (*fmt == '\0') ? '#' : *fmt++; |
| 1287 |
char nay = (*fmt == '\0') ? ' ' : *fmt++; |
| 1288 |
|
| 1289 |
*mode_p++ = w->w_bufp->b_diverged ? yea : nay; |
| 1290 |
break; |
| 1291 |
} |
| 1292 |
|
| 1293 |
case 'm': |
| 1294 |
{ |
| 1295 |
char yea = (*fmt == '\0') ? '*' : *fmt++; |
| 1296 |
char nay = (*fmt == '\0') ? ' ' : *fmt++; |
| 1297 |
|
| 1298 |
*mode_p++ = IsModified(w->w_bufp) ? yea : nay; |
| 1299 |
break; |
| 1300 |
} |
| 1301 |
|
| 1302 |
case 'n': |
| 1303 |
{ |
| 1304 |
char tmp[16]; |
| 1305 |
|
| 1306 |
for (bp = world, n = 1; bp != NULL; bp = bp->b_next, n++) |
| 1307 |
if (bp == thisbuf) |
| 1308 |
break; |
| 1309 |
|
| 1310 |
swritef(tmp, sizeof(tmp), "%d", n); |
| 1311 |
mode_app(tmp); |
| 1312 |
break; |
| 1313 |
} |
| 1314 |
|
| 1315 |
case 'p': |
| 1316 |
#ifdef IPROCS |
| 1317 |
if (thisbuf->b_type == B_PROCESS) { |
| 1318 |
char tmp[40]; |
| 1319 |
|
| 1320 |
swritef(tmp, sizeof(tmp), "(%s)", pstate(thisbuf->b_process)); |
| 1321 |
mode_app(tmp); |
| 1322 |
} |
| 1323 |
#endif |
| 1324 |
break; |
| 1325 |
case 's': |
| 1326 |
if (mode_p[-1] != ' ') |
| 1327 |
*mode_p++ = ' '; |
| 1328 |
break; |
| 1329 |
|
| 1330 |
case 't': |
| 1331 |
{ |
| 1332 |
char timestr[12]; |
| 1333 |
|
| 1334 |
td = YES; |
| 1335 |
mode_app(get_time((time_t *)NULL, timestr, 11, 16)); |
| 1336 |
break; |
| 1337 |
} |
| 1338 |
|
| 1339 |
case 'w': |
| 1340 |
if (w->w_LRscroll > 0) |
| 1341 |
mode_app(">"); |
| 1342 |
break; |
| 1343 |
|
| 1344 |
default: |
| 1345 |
mode_app("?"); |
| 1346 |
break; |
| 1347 |
} |
| 1348 |
} |
| 1349 |
|
| 1350 |
/* Glue (Knuth's term) is a field that expands to fill |
| 1351 |
* any leftover space. Multiple glue fields compete |
| 1352 |
* on an equal basis. This is a generalization of a |
| 1353 |
* mechanism to allow centring and right-justification. |
| 1354 |
* The original meaning of %e (fill the rest of the |
| 1355 |
* line) has also been generalized. %e can now |
| 1356 |
* meaningfully be used 0 or more times. |
| 1357 |
*/ |
| 1358 |
|
| 1359 |
if (glue) { |
| 1360 |
/* 1 space unused, plus padding for magic cookies */ |
| 1361 |
char *to = &line[CO - 1 - (4 * SG)], |
| 1362 |
*from = mode_p; |
| 1363 |
|
| 1364 |
if (to < from) |
| 1365 |
to = from; |
| 1366 |
mode_p = to; |
| 1367 |
while (from != line) { |
| 1368 |
if ((*--to = *--from) == '\0') { |
| 1369 |
int portion = (to-from) / glue; |
| 1370 |
|
| 1371 |
glue--; |
| 1372 |
*to = fillc; |
| 1373 |
while (--portion >= 0) |
| 1374 |
*--to = fillc; |
| 1375 |
} |
| 1376 |
} |
| 1377 |
} else { |
| 1378 |
while (mode_p < &line[CO - 1 - (4 * SG)]) |
| 1379 |
*mode_p++ = fillc; |
| 1380 |
} |
| 1381 |
|
| 1382 |
*mode_p = '\0'; |
| 1383 |
|
| 1384 |
/* Highlight mode line. */ |
| 1385 |
highlighting = NOEFFECT; |
| 1386 |
if (BriteMode) { |
| 1387 |
highlighting = WindowRange(w); |
| 1388 |
#ifdef HIGHLIGHTING |
| 1389 |
{ |
| 1390 |
char |
| 1391 |
*p = &line[highlighting->start], |
| 1392 |
*e = p + highlighting->width; |
| 1393 |
|
| 1394 |
for (; p != e; p++) |
| 1395 |
if (*p == ' ') |
| 1396 |
*p = '-'; |
| 1397 |
} |
| 1398 |
#endif |
| 1399 |
} |
| 1400 |
if (w->w_next == fwind && TimeDisplayed != td) { |
| 1401 |
TimeDisplayed = td; |
| 1402 |
#ifdef UNIX |
| 1403 |
SetClockAlarm(YES); |
| 1404 |
#endif |
| 1405 |
} |
| 1406 |
#ifdef ID_CHAR |
| 1407 |
INSmode(NO); |
| 1408 |
#endif |
| 1409 |
if (swrite(line, highlighting, YES)) |
| 1410 |
do_cl_eol(linenum); |
| 1411 |
else |
| 1412 |
UpdModLine = YES; |
| 1413 |
} |
| 1414 |
|
| 1415 |
/* This tries to place the current line of the current window in the |
| 1416 |
* center of the window, OR to place it at the arg'th line of the window. |
| 1417 |
* This also causes the horizontal position of the line to be centered, |
| 1418 |
* if the line needs scrolling, or moved all the way back to the left, |
| 1419 |
* if that's possible. |
| 1420 |
*/ |
| 1421 |
void |
| 1422 |
RedrawDisplay(void) |
| 1423 |
{ |
| 1424 |
int line; |
| 1425 |
LinePtr newtop = prev_line((curwind->w_line = curline), |
| 1426 |
arg_or_default(WSIZE(curwind)/2)); |
| 1427 |
|
| 1428 |
if ((line = in_window(curwind, curwind->w_line)) != -1) |
| 1429 |
PhysScreen[line].s_offset = -1; |
| 1430 |
if (newtop == curwind->w_top) |
| 1431 |
ClAndRedraw(); |
| 1432 |
else |
| 1433 |
SetTop(curwind, newtop); |
| 1434 |
} |
| 1435 |
|
| 1436 |
void |
| 1437 |
ClAndRedraw(void) |
| 1438 |
{ |
| 1439 |
cl_scr(YES); |
| 1440 |
} |
| 1441 |
|
| 1442 |
void |
| 1443 |
NextPage(void) |
| 1444 |
{ |
| 1445 |
LinePtr newline; |
| 1446 |
|
| 1447 |
if (Asking) { |
| 1448 |
/* don't do it */ |
| 1449 |
} else if (arg_value() < 0) { |
| 1450 |
negate_arg(); |
| 1451 |
PrevPage(); |
| 1452 |
} else if (is_non_minus_arg()) { |
| 1453 |
UpScroll(); |
| 1454 |
} else { |
| 1455 |
if (in_window(curwind, curwind->w_bufp->b_last) != -1) { |
| 1456 |
rbell(); |
| 1457 |
return; |
| 1458 |
} |
| 1459 |
newline = next_line(curwind->w_top, jmax(1, WSIZE(curwind) - 1)); |
| 1460 |
SetTop(curwind, curwind->w_line = newline); |
| 1461 |
if (curwind->w_bufp == curbuf) |
| 1462 |
SetLine(newline); |
| 1463 |
} |
| 1464 |
} |
| 1465 |
|
| 1466 |
void |
| 1467 |
PrevPage(void) |
| 1468 |
{ |
| 1469 |
LinePtr newline; |
| 1470 |
|
| 1471 |
if (Asking) { |
| 1472 |
/* don't do it */ |
| 1473 |
} else if (arg_value() < 0) { |
| 1474 |
negate_arg(); |
| 1475 |
NextPage(); |
| 1476 |
} else if (is_non_minus_arg()) { |
| 1477 |
DownScroll(); |
| 1478 |
} else { |
| 1479 |
newline = prev_line(curwind->w_top, jmax(1, WSIZE(curwind) - 1)); |
| 1480 |
SetTop(curwind, curwind->w_line = newline); |
| 1481 |
if (curwind->w_bufp == curbuf) |
| 1482 |
SetLine(newline); |
| 1483 |
} |
| 1484 |
} |
| 1485 |
|
| 1486 |
void |
| 1487 |
UpScroll(void) |
| 1488 |
{ |
| 1489 |
SetTop(curwind, next_line(curwind->w_top, arg_value())); |
| 1490 |
if (curwind->w_bufp == curbuf |
| 1491 |
&& in_window(curwind, curline) == -1) |
| 1492 |
SetLine(curwind->w_top); |
| 1493 |
} |
| 1494 |
|
| 1495 |
void |
| 1496 |
DownScroll(void) |
| 1497 |
{ |
| 1498 |
SetTop(curwind, prev_line(curwind->w_top, arg_value())); |
| 1499 |
if (curwind->w_bufp == curbuf |
| 1500 |
&& in_window(curwind, curline) == -1) |
| 1501 |
SetLine(curwind->w_top); |
| 1502 |
} |
| 1503 |
|
| 1504 |
jbool VisBell = NO; /* VAR: use visible bell (if possible) */ |
| 1505 |
|
| 1506 |
void |
| 1507 |
rbell(void) |
| 1508 |
{ |
| 1509 |
RingBell = YES; |
| 1510 |
} |
| 1511 |
|
| 1512 |
/* Message prints the null terminated string onto the bottom line of the |
| 1513 |
* terminal. |
| 1514 |
*/ |
| 1515 |
void |
| 1516 |
message(const char *str) |
| 1517 |
{ |
| 1518 |
if (InJoverc) |
| 1519 |
return; |
| 1520 |
|
| 1521 |
UpdMesg = YES; |
| 1522 |
stickymsg = NO; |
| 1523 |
if (str != mesgbuf) |
| 1524 |
truncstr(mesgbuf, str); |
| 1525 |
} |
| 1526 |
|
| 1527 |
/* End of Window */ |
| 1528 |
|
| 1529 |
void |
| 1530 |
Eow(void) |
| 1531 |
{ |
| 1532 |
if (Asking) |
| 1533 |
return; |
| 1534 |
|
| 1535 |
SetLine(next_line(curwind->w_top, WSIZE(curwind) - 1 - |
| 1536 |
jmin(WSIZE(curwind) - 1, arg_value() - 1))); |
| 1537 |
if (!is_an_arg()) |
| 1538 |
Eol(); |
| 1539 |
} |
| 1540 |
|
| 1541 |
/* Beginning of Window */ |
| 1542 |
|
| 1543 |
void |
| 1544 |
Bow(void) |
| 1545 |
{ |
| 1546 |
if (Asking) |
| 1547 |
return; |
| 1548 |
|
| 1549 |
SetLine(next_line(curwind->w_top, jmin(WSIZE(curwind) - 1, arg_value() - 1))); |
| 1550 |
} |
| 1551 |
|
| 1552 |
/* Typeout Mechanism */ |
| 1553 |
|
| 1554 |
jbool UseBuffers = NO, /* VAR: use buffers with Typeout() */ |
| 1555 |
TOabort = NO; |
| 1556 |
|
| 1557 |
private int LineNo; /* screen line for Typeout (if not UseBuffers) */ |
| 1558 |
|
| 1559 |
private Window *old_wind; /* curwind before preempted by typeout to buffer */ |
| 1560 |
|
| 1561 |
/* This initializes the typeout. If send-typeout-to-buffers is set |
| 1562 |
* the buffer NAME is created (emptied if it already exists) and output |
| 1563 |
* goes to the buffer. Otherwise output is drawn on the screen and |
| 1564 |
* erased by TOstop() |
| 1565 |
*/ |
| 1566 |
void |
| 1567 |
TOstart(const char *name) |
| 1568 |
{ |
| 1569 |
if (UseBuffers) { |
| 1570 |
old_wind = curwind; |
| 1571 |
pop_wind(name, YES, B_SCRATCH); |
| 1572 |
} else |
| 1573 |
DisabledRedisplay = YES; |
| 1574 |
TOabort = NO; |
| 1575 |
LineNo = 0; |
| 1576 |
} |
| 1577 |
|
| 1578 |
private void |
| 1579 |
TOlineFits(char *s) |
| 1580 |
{ |
| 1581 |
i_set(LineNo, 0); |
| 1582 |
(void) swrite(s, NOEFFECT, NO); |
| 1583 |
PhysScreen[LineNo].s_id = NOWHERE_DADDR; |
| 1584 |
cl_eol(); |
| 1585 |
flushscreen(); |
| 1586 |
} |
| 1587 |
|
| 1588 |
private void |
| 1589 |
TOprompt(char *s) |
| 1590 |
{ |
| 1591 |
if (!TOabort) { |
| 1592 |
ZXchar c; |
| 1593 |
|
| 1594 |
TOlineFits(s); |
| 1595 |
c = kbd_getch(); |
| 1596 |
TOlineFits(""); |
| 1597 |
if (c != ' ') { |
| 1598 |
TOabort = YES; |
| 1599 |
if (c != AbortChar) |
| 1600 |
kbd_ungetch(c); |
| 1601 |
} |
| 1602 |
} |
| 1603 |
} |
| 1604 |
|
| 1605 |
void |
| 1606 |
Typeout(const char *fmt, ...) |
| 1607 |
{ |
| 1608 |
char string[MAX_TYPEOUT+1]; |
| 1609 |
va_list ap; |
| 1610 |
|
| 1611 |
va_start(ap, fmt); |
| 1612 |
format(string, sizeof string, fmt, ap); |
| 1613 |
va_end(ap); |
| 1614 |
if (UseBuffers) { |
| 1615 |
ins_str(string); |
| 1616 |
ins_str("\n"); |
| 1617 |
} else { |
| 1618 |
char outbuf[MAXCOLS + PPWIDTH]; /* assert(CO <= MAXCOLS); */ |
| 1619 |
|
| 1620 |
if (LineNo == ILI - 2) { |
| 1621 |
TOprompt("--more--"); |
| 1622 |
LineNo = 0; |
| 1623 |
} |
| 1624 |
if (!TOabort) { |
| 1625 |
DeTab(string, 0, outbuf, outbuf + CO, NO); |
| 1626 |
TOlineFits(outbuf); |
| 1627 |
LineNo += 1; |
| 1628 |
} |
| 1629 |
} |
| 1630 |
} |
| 1631 |
|
| 1632 |
void |
| 1633 |
TOstop(void) |
| 1634 |
{ |
| 1635 |
if (UseBuffers) { |
| 1636 |
ToFirst(); |
| 1637 |
SetWind(old_wind); |
| 1638 |
} else { |
| 1639 |
TOprompt("--end--"); |
| 1640 |
DisabledRedisplay = NO; |
| 1641 |
} |
| 1642 |
} |