Annotation of src/usr.bin/mg/buffer.c, Revision 1.3
1.1 deraadt 1: /*
2: * Buffer handling.
3: */
4: #include "def.h"
1.3 ! millert 5: #include "kbd.h" /* needed for modes */
1.1 deraadt 6:
1.3 ! millert 7: static RSIZE itor __P((char *, int, RSIZE));
! 8: static BUFFER *makelist __P((void));
1.1 deraadt 9:
10: /*
11: * Attach a buffer to a window. The values of dot and mark come
12: * from the buffer if the use count is 0. Otherwise, they come
13: * from some other window. *scratch* is the default alternate
14: * buffer.
15: */
1.3 ! millert 16: /* ARGSUSED */
! 17: int
1.1 deraadt 18: usebuffer(f, n)
1.3 ! millert 19: int f, n;
1.1 deraadt 20: {
1.3 ! millert 21: BUFFER *bp;
! 22: int s;
! 23: char bufn[NBUFN];
1.1 deraadt 24:
25: /* Get buffer to use from user */
26: if ((curbp->b_altb == NULL)
27: && ((curbp->b_altb = bfind("*scratch*", TRUE)) == NULL))
1.3 ! millert 28: s = eread("Switch to buffer: ", bufn, NBUFN, EFNEW | EFBUF);
1.1 deraadt 29: else
1.3 ! millert 30: s = eread("Switch to buffer: (default %s) ", bufn, NBUFN,
! 31: EFNEW | EFBUF, curbp->b_altb->b_bname);
1.1 deraadt 32:
1.3 ! millert 33: if (s == ABORT)
! 34: return s;
! 35: if (s == FALSE && curbp->b_altb != NULL)
! 36: bp = curbp->b_altb;
! 37: else if ((bp = bfind(bufn, TRUE)) == NULL)
! 38: return FALSE;
1.1 deraadt 39:
40: /* and put it in current window */
41: curbp = bp;
1.3 ! millert 42: return showbuffer(bp, curwp, WFFORCE | WFHARD);
1.1 deraadt 43: }
44:
45: /*
46: * pop to buffer asked for by the user.
47: */
1.3 ! millert 48: /* ARGSUSED */
! 49: int
1.1 deraadt 50: poptobuffer(f, n)
1.3 ! millert 51: int f, n;
1.1 deraadt 52: {
1.3 ! millert 53: BUFFER *bp;
! 54: MGWIN *wp;
! 55: int s;
! 56: char bufn[NBUFN];
! 57: MGWIN *popbuf();
1.1 deraadt 58:
59: /* Get buffer to use from user */
60: if ((curbp->b_altb == NULL)
61: && ((curbp->b_altb = bfind("*scratch*", TRUE)) == NULL))
1.3 ! millert 62: s = eread("Switch to buffer in other window: ", bufn, NBUFN,
! 63: EFNEW | EFBUF);
1.1 deraadt 64: else
1.3 ! millert 65: s = eread("Switch to buffer in other window: (default %s) ",
! 66: bufn, NBUFN, EFNEW | EFBUF, curbp->b_altb->b_bname);
! 67: if (s == ABORT)
! 68: return s;
! 69: if (s == FALSE && curbp->b_altb != NULL)
! 70: bp = curbp->b_altb;
! 71: else if ((bp = bfind(bufn, TRUE)) == NULL)
! 72: return FALSE;
1.1 deraadt 73:
74: /* and put it in a new window */
1.3 ! millert 75: if ((wp = popbuf(bp)) == NULL)
! 76: return FALSE;
1.1 deraadt 77: curbp = bp;
78: curwp = wp;
79: return TRUE;
80: }
81:
82: /*
83: * Dispose of a buffer, by name.
84: * Ask for the name. Look it up (don't get too
85: * upset if it isn't there at all!). Clear the buffer (ask
86: * if the buffer has been changed). Then free the header
87: * line and the buffer header. Bound to "C-X K".
88: */
1.3 ! millert 89: /* ARGSUSED */
! 90: int
1.1 deraadt 91: killbuffer(f, n)
1.3 ! millert 92: int f, n;
1.1 deraadt 93: {
1.3 ! millert 94: BUFFER *bp;
! 95: BUFFER *bp1;
! 96: BUFFER *bp2;
! 97: MGWIN *wp;
! 98: int s;
! 99: char bufn[NBUFN];
! 100:
! 101: if ((s = eread("Kill buffer: (default %s) ", bufn, NBUFN, EFNEW | EFBUF,
! 102: curbp->b_bname)) == ABORT)
! 103: return (s);
! 104: else if (s == FALSE)
! 105: bp = curbp;
! 106: else if ((bp = bfind(bufn, FALSE)) == NULL)
! 107: return FALSE;
! 108:
! 109: /*
! 110: * Find some other buffer to display. try the alternate buffer,
! 111: * then the first different buffer in the buffer list. If there's
! 112: * only one buffer, create buffer *scratch* and make it the alternate
! 113: * buffer. Return if *scratch* is only buffer...
1.1 deraadt 114: */
115: if ((bp1 = bp->b_altb) == NULL) {
116: bp1 = (bp == bheadp) ? bp->b_bufp : bheadp;
117: if (bp1 == NULL) {
118: /* only one buffer. see if it's *scratch* */
1.3 ! millert 119: if (bp == bfind("*scratch*", FALSE))
1.1 deraadt 120: return FALSE;
121: /* create *scratch* for alternate buffer */
1.3 ! millert 122: if ((bp1 = bfind("*scratch*", TRUE)) == NULL)
1.1 deraadt 123: return FALSE;
124: }
125: }
1.3 ! millert 126: if (bclear(bp) != TRUE)
! 127: return TRUE;
1.1 deraadt 128: for (wp = wheadp; bp->b_nwnd > 0; wp = wp->w_wndp) {
1.3 ! millert 129: if (wp->w_bufp == bp) {
! 130: bp2 = bp1->b_altb; /* save alternate buffer */
! 131: if (showbuffer(bp1, wp, WFMODE | WFFORCE | WFHARD))
! 132: bp1->b_altb = bp2;
! 133: else
! 134: bp1 = bp2;
! 135: }
! 136: }
! 137: if (bp == curbp)
! 138: curbp = bp1;
! 139: free(bp->b_linep); /* Release header line. */
! 140: bp2 = NULL; /* Find the header. */
1.1 deraadt 141: bp1 = bheadp;
142: while (bp1 != bp) {
143: if (bp1->b_altb == bp)
144: bp1->b_altb = (bp->b_altb == bp1) ? NULL : bp->b_altb;
145: bp2 = bp1;
146: bp1 = bp1->b_bufp;
147: }
1.3 ! millert 148: bp1 = bp1->b_bufp; /* Next one in chain. */
! 149: if (bp2 == NULL) /* Unlink it. */
1.1 deraadt 150: bheadp = bp1;
151: else
152: bp2->b_bufp = bp1;
1.3 ! millert 153: while (bp1 != NULL) { /* Finish with altb's */
1.1 deraadt 154: if (bp1->b_altb == bp)
155: bp1->b_altb = (bp->b_altb == bp1) ? NULL : bp->b_altb;
156: bp1 = bp1->b_bufp;
157: }
1.3 ! millert 158: free(bp->b_bname); /* Release name block */
! 159: free(bp); /* Release buffer block */
1.1 deraadt 160: return TRUE;
161: }
162:
163: /*
164: * Save some buffers - just call anycb with the arg flag.
165: */
1.3 ! millert 166: /* ARGSUSED */
! 167: int
1.1 deraadt 168: savebuffers(f, n)
1.3 ! millert 169: int f, n;
1.1 deraadt 170: {
1.3 ! millert 171:
! 172: if (anycb(f) == ABORT)
! 173: return ABORT;
1.1 deraadt 174: return TRUE;
175: }
176:
177: /*
178: * Display the buffer list. This is done
179: * in two parts. The "makelist" routine figures out
180: * the text, and puts it in a buffer. "popbuf"
181: * then pops the data onto the screen. Bound to
182: * "C-X C-B".
183: */
1.3 ! millert 184: /* ARGSUSED */
! 185: int
1.1 deraadt 186: listbuffers(f, n)
1.3 ! millert 187: int f, n;
1.1 deraadt 188: {
1.3 ! millert 189: BUFFER *bp;
! 190: MGWIN *wp;
1.1 deraadt 191:
1.3 ! millert 192: if ((bp = makelist()) == NULL || (wp = popbuf(bp)) == NULL)
1.1 deraadt 193: return FALSE;
1.3 ! millert 194: wp->w_dotp = bp->b_dotp;/* fix up if window already on screen */
1.1 deraadt 195: wp->w_doto = bp->b_doto;
196: return TRUE;
197: }
198:
199: /*
200: * This routine rebuilds the text for the
201: * list buffers command. Return TRUE if
202: * everything works. Return FALSE if there
203: * is an error (if there is no memory).
204: */
1.3 ! millert 205: static BUFFER *
! 206: makelist()
! 207: {
! 208: char *cp1;
! 209: char *cp2;
! 210: int c;
! 211: BUFFER *bp;
! 212: LINE *lp;
! 213: RSIZE nbytes;
! 214: BUFFER *blp;
! 215: char b[6 + 1];
! 216: char line[128];
! 217:
! 218: if ((blp = bfind("*Buffer List*", TRUE)) == NULL)
! 219: return NULL;
! 220: if (bclear(blp) != TRUE)
! 221: return NULL;
! 222: blp->b_flag &= ~BFCHG; /* Blow away old. */
1.1 deraadt 223:
224: (VOID) strcpy(line, " MR Buffer");
225: cp1 = line + 10;
1.3 ! millert 226: while (cp1 < line + 4 + NBUFN + 1)
! 227: *cp1++ = ' ';
1.1 deraadt 228: (VOID) strcpy(cp1, "Size File");
1.3 ! millert 229: if (addline(blp, line) == FALSE)
! 230: return NULL;
1.1 deraadt 231: (VOID) strcpy(line, " -- ------");
232: cp1 = line + 10;
1.3 ! millert 233: while (cp1 < line + 4 + NBUFN + 1)
! 234: *cp1++ = ' ';
1.1 deraadt 235: (VOID) strcpy(cp1, "---- ----");
1.3 ! millert 236: if (addline(blp, line) == FALSE)
! 237: return NULL;
! 238: bp = bheadp; /* For all buffers */
1.1 deraadt 239: while (bp != NULL) {
1.3 ! millert 240: cp1 = &line[0]; /* Start at left edge */
1.1 deraadt 241: *cp1++ = (bp == curbp) ? '.' : ' ';
1.3 ! millert 242: *cp1++ = ((bp->b_flag & BFCHG) != 0) ? '*' : ' ';
! 243: *cp1++ = ' '; /* Gap. */
1.1 deraadt 244: *cp1++ = ' ';
1.3 ! millert 245: cp2 = &bp->b_bname[0]; /* Buffer name */
1.1 deraadt 246: while ((c = *cp2++) != 0)
247: *cp1++ = c;
1.3 ! millert 248: while (cp1 < &line[4 + NBUFN + 1])
1.1 deraadt 249: *cp1++ = ' ';
1.3 ! millert 250: nbytes = 0; /* Count bytes in buf. */
1.1 deraadt 251: if (bp != blp) {
252: lp = lforw(bp->b_linep);
253: while (lp != bp->b_linep) {
1.3 ! millert 254: nbytes += llength(lp) + 1;
1.1 deraadt 255: lp = lforw(lp);
256: }
1.3 ! millert 257: if (nbytes)
! 258: nbytes--; /* no bonus newline */
1.1 deraadt 259: }
260: (VOID) itor(b, 6, nbytes); /* 6 digit buffer size. */
261: cp2 = &b[0];
262: while ((c = *cp2++) != 0)
263: *cp1++ = c;
1.3 ! millert 264: *cp1++ = ' '; /* Gap.. */
! 265: cp2 = &bp->b_fname[0]; /* File name */
1.1 deraadt 266: if (*cp2 != 0) {
267: while ((c = *cp2++) != 0) {
1.3 ! millert 268: if (cp1 < &line[128 - 1])
1.1 deraadt 269: *cp1++ = c;
270: }
271: }
1.3 ! millert 272: *cp1 = 0; /* Add to the buffer. */
1.1 deraadt 273: if (addline(blp, line) == FALSE)
274: return NULL;
275: bp = bp->b_bufp;
276: }
1.3 ! millert 277: blp->b_dotp = lforw(blp->b_linep); /* put dot at beginning of
! 278: * buffer */
1.1 deraadt 279: blp->b_doto = 0;
1.3 ! millert 280: return blp; /* All done */
1.1 deraadt 281: }
282:
283: /*
284: * Used above.
285: */
1.3 ! millert 286: static RSIZE
! 287: itor(buf, width, num)
! 288: char *buf;
! 289: int width;
! 290: RSIZE num;
! 291: {
! 292: RSIZE r;
1.1 deraadt 293:
294: if (num / 10 == 0) {
295: buf[0] = (num % 10) + '0';
1.3 ! millert 296: for (r = 1; r < width; buf[r++] = ' ');
1.1 deraadt 297: buf[width] = '\0';
298: return 1;
299: } else {
1.3 ! millert 300: buf[r = itor(buf, width, num / (RSIZE) 10)] =
! 301: (num % (RSIZE) 10) + '0';
1.1 deraadt 302: return r + 1;
303: }
1.3 ! millert 304: /* NOTREACHED */
1.1 deraadt 305: }
306:
307: /*
1.3 ! millert 308: * The argument "text" points to a string. Append this line to the
! 309: * buffer. Handcraft the EOL on the end. Return TRUE if it worked and
1.1 deraadt 310: * FALSE if you ran out of room.
311: */
1.3 ! millert 312: int
! 313: addline(bp, text)
! 314: BUFFER *bp;
! 315: char *text;
! 316: {
! 317: LINE *lp;
! 318: int i;
! 319: int ntext;
1.1 deraadt 320:
321: ntext = strlen(text);
1.3 ! millert 322: if ((lp = lalloc(ntext)) == NULL)
1.1 deraadt 323: return FALSE;
1.3 ! millert 324: for (i = 0; i < ntext; ++i)
1.1 deraadt 325: lputc(lp, i, text[i]);
1.3 ! millert 326: bp->b_linep->l_bp->l_fp = lp; /* Hook onto the end */
1.1 deraadt 327: lp->l_bp = bp->b_linep->l_bp;
328: bp->b_linep->l_bp = lp;
329: lp->l_fp = bp->b_linep;
330: #ifdef CANTHAPPEN
1.3 ! millert 331: if (bp->b_dotp == bp->b_linep) /* If "." is at the end */
! 332: bp->b_dotp = lp; /* move it to new line */
! 333: if (bp->b_markp == bp->b_linep) /* ditto for mark */
1.1 deraadt 334: bp->b_markp = lp;
335: #endif
336: return TRUE;
337: }
338:
339: /*
1.3 ! millert 340: * Look through the list of buffers, giving the user a chance to save them.
! 341: * Return TRUE if there are any changed buffers afterwards. Buffers that
! 342: * don't have an associated file don't count. Return FALSE if there are
! 343: * no changed buffers.
! 344: */
! 345: int
! 346: anycb(f)
! 347: int f;
! 348: {
! 349: BUFFER *bp;
! 350: int s = FALSE, save = FALSE;
! 351: char prompt[NFILEN + 11];
1.1 deraadt 352:
353: for (bp = bheadp; bp != NULL; bp = bp->b_bufp) {
354: if (*(bp->b_fname) != '\0'
1.3 ! millert 355: && (bp->b_flag & BFCHG) != 0) {
1.1 deraadt 356: (VOID) strcpy(prompt, "Save file ");
357: (VOID) strcpy(prompt + 10, bp->b_fname);
358: if ((f == TRUE || (save = eyorn(prompt)) == TRUE)
1.3 ! millert 359: && buffsave(bp) == TRUE) {
1.1 deraadt 360: bp->b_flag &= ~BFCHG;
361: upmodes(bp);
1.3 ! millert 362: } else
! 363: s = TRUE;
! 364: if (save == ABORT)
! 365: return (save);
1.1 deraadt 366: save = TRUE;
367: }
368: }
369: if (save == FALSE /* && kbdmop == NULL */ ) /* experimental */
370: ewprintf("(No files need saving)");
371: return s;
372: }
373:
374: /*
375: * Search for a buffer, by name.
376: * If not found, and the "cflag" is TRUE,
377: * create a buffer and put it in the list of
378: * all buffers. Return pointer to the BUFFER
379: * block for the buffer.
380: */
1.3 ! millert 381: BUFFER *
! 382: bfind(bname, cflag)
! 383: char *bname;
! 384: int cflag;
! 385: {
! 386: BUFFER *bp;
! 387: LINE *lp;
! 388: int i;
! 389: extern int defb_nmodes;
! 390: extern MAPS *defb_modes[PBMODES];
! 391: extern int defb_flag;
1.1 deraadt 392:
393: bp = bheadp;
394: while (bp != NULL) {
395: if (fncmp(bname, bp->b_bname) == 0)
396: return bp;
397: bp = bp->b_bufp;
398: }
1.3 ! millert 399: if (cflag != TRUE)
! 400: return NULL;
! 401: /* NOSTRICT */
! 402: if ((bp = (BUFFER *) malloc(sizeof(BUFFER))) == NULL) {
1.1 deraadt 403: ewprintf("Can't get %d bytes", sizeof(BUFFER));
404: return NULL;
405: }
1.3 ! millert 406: if ((bp->b_bname = malloc((strlen(bname) + 1))) == NULL) {
! 407: ewprintf("Can't get %d bytes", strlen(bname) + 1);
1.1 deraadt 408: free((char *) bp);
409: return NULL;
410: }
411: if ((lp = lalloc(0)) == NULL) {
412: free(bp->b_bname);
413: free((char *) bp);
414: return NULL;
415: }
1.3 ! millert 416: bp->b_altb = bp->b_bufp = NULL;
! 417: bp->b_dotp = lp;
! 418: bp->b_doto = 0;
1.1 deraadt 419: bp->b_markp = NULL;
420: bp->b_marko = 0;
1.3 ! millert 421: bp->b_flag = defb_flag;
! 422: bp->b_nwnd = 0;
1.1 deraadt 423: bp->b_linep = lp;
424: bp->b_nmodes = defb_nmodes;
425: i = 0;
426: do {
1.3 ! millert 427: bp->b_modes[i] = defb_modes[i];
! 428: } while (i++ < defb_nmodes);
1.1 deraadt 429: bp->b_fname[0] = '\0';
430: bzero(&bp->b_fi, sizeof(bp->b_fi));
431: (VOID) strcpy(bp->b_bname, bname);
432: lp->l_fp = lp;
433: lp->l_bp = lp;
434: bp->b_bufp = bheadp;
435: bheadp = bp;
436: return bp;
437: }
438:
439: /*
440: * This routine blows away all of the text
441: * in a buffer. If the buffer is marked as changed
442: * then we ask if it is ok to blow it away; this is
443: * to save the user the grief of losing text. The
444: * window chain is nearly always wrong if this gets
445: * called; the caller must arrange for the updates
446: * that are required. Return TRUE if everything
447: * looks good.
448: */
1.3 ! millert 449: int
! 450: bclear(bp)
! 451: BUFFER *bp;
! 452: {
! 453: LINE *lp;
! 454: int s;
1.1 deraadt 455:
1.3 ! millert 456: if ((bp->b_flag & BFCHG) != 0 /* Changed. */
! 457: && (s = eyesno("Buffer modified; kill anyway")) != TRUE)
1.1 deraadt 458: return (s);
1.3 ! millert 459: bp->b_flag &= ~BFCHG; /* Not changed */
! 460: while ((lp = lforw(bp->b_linep)) != bp->b_linep)
1.1 deraadt 461: lfree(lp);
1.3 ! millert 462: bp->b_dotp = bp->b_linep; /* Fix "." */
! 463: bp->b_doto = 0;
! 464: bp->b_markp = NULL; /* Invalidate "mark" */
1.1 deraadt 465: bp->b_marko = 0;
466: return TRUE;
467: }
468:
469: /*
470: * Display the given buffer in the given window. Flags indicated
471: * action on redisplay.
472: */
1.3 ! millert 473: int
! 474: showbuffer(bp, wp, flags)
! 475: BUFFER *bp;
! 476: MGWIN *wp;
! 477: int flags;
! 478: {
! 479: BUFFER *obp;
! 480: MGWIN *owp;
1.1 deraadt 481:
1.3 ! millert 482: if (wp->w_bufp == bp) { /* Easy case! */
1.1 deraadt 483: wp->w_flag |= flags;
484: return TRUE;
485: }
486: /* First, dettach the old buffer from the window */
487: if ((bp->b_altb = obp = wp->w_bufp) != NULL) {
488: if (--obp->b_nwnd == 0) {
1.3 ! millert 489: obp->b_dotp = wp->w_dotp;
! 490: obp->b_doto = wp->w_doto;
1.1 deraadt 491: obp->b_markp = wp->w_markp;
492: obp->b_marko = wp->w_marko;
493: }
494: }
495: /* Now, attach the new buffer to the window */
496: wp->w_bufp = bp;
497:
1.3 ! millert 498: if (bp->b_nwnd++ == 0) { /* First use. */
! 499: wp->w_dotp = bp->b_dotp;
! 500: wp->w_doto = bp->b_doto;
1.1 deraadt 501: wp->w_markp = bp->b_markp;
502: wp->w_marko = bp->b_marko;
503: } else
1.3 ! millert 504: /* already on screen, steal values from other window */
1.1 deraadt 505: for (owp = wheadp; owp != NULL; owp = wp->w_wndp)
506: if (wp->w_bufp == bp && owp != wp) {
1.3 ! millert 507: wp->w_dotp = owp->w_dotp;
! 508: wp->w_doto = owp->w_doto;
1.1 deraadt 509: wp->w_markp = owp->w_markp;
510: wp->w_marko = owp->w_marko;
511: break;
512: }
1.3 ! millert 513: wp->w_flag |= WFMODE | flags;
1.1 deraadt 514: return TRUE;
515: }
516:
517: /*
518: * Pop the buffer we got passed onto the screen.
519: * Returns a status.
520: */
1.2 millert 521: MGWIN *
1.3 ! millert 522: popbuf(bp)
! 523: BUFFER *bp;
! 524: {
! 525: MGWIN *wp;
1.1 deraadt 526:
1.3 ! millert 527: if (bp->b_nwnd == 0) { /* Not on screen yet. */
! 528: if ((wp = wpopup()) == NULL)
! 529: return NULL;
1.1 deraadt 530: } else
531: for (wp = wheadp; wp != NULL; wp = wp->w_wndp)
532: if (wp->w_bufp == bp) {
1.3 ! millert 533: wp->w_flag |= WFHARD | WFFORCE;
! 534: return wp;
1.1 deraadt 535: }
1.3 ! millert 536: if (showbuffer(bp, wp, WFHARD) != TRUE)
! 537: return NULL;
1.1 deraadt 538: return wp;
539: }
540:
541: /*
542: * Insert another buffer at dot. Very useful.
543: */
1.3 ! millert 544: /* ARGSUSED */
! 545: int
1.1 deraadt 546: bufferinsert(f, n)
547: {
1.3 ! millert 548: BUFFER *bp;
! 549: LINE *clp;
! 550: int clo;
! 551: int nline;
! 552: int s;
! 553: char bufn[NBUFN];
1.1 deraadt 554:
555: /* Get buffer to use from user */
556: if (curbp->b_altb != NULL)
1.3 ! millert 557: s = eread("Insert buffer: (default %s) ", bufn, NBUFN,
! 558: EFNEW | EFBUF, &(curbp->b_altb->b_bname),
! 559: (char *) NULL);
1.1 deraadt 560: else
1.3 ! millert 561: s = eread("Insert buffer: ", bufn, NBUFN, EFNEW | EFBUF,
! 562: (char *) NULL);
! 563: if (s == ABORT)
! 564: return (s);
! 565: if (s == FALSE && curbp->b_altb != NULL)
! 566: bp = curbp->b_altb;
! 567: else if ((bp = bfind(bufn, FALSE)) == NULL)
! 568: return FALSE;
1.1 deraadt 569:
1.3 ! millert 570: if (bp == curbp) {
1.1 deraadt 571: ewprintf("Cannot insert buffer into self");
572: return FALSE;
573: }
574: /* insert the buffer */
575: nline = 0;
576: clp = lforw(bp->b_linep);
1.3 ! millert 577: for (;;) {
1.1 deraadt 578: for (clo = 0; clo < llength(clp); clo++)
579: if (linsert(1, lgetc(clp, clo)) == FALSE)
580: return FALSE;
1.3 ! millert 581: if ((clp = lforw(clp)) == bp->b_linep)
! 582: break;
! 583: if (newline(FFRAND, 1) == FALSE) /* fake newline */
1.1 deraadt 584: return FALSE;
585: nline++;
586: }
1.3 ! millert 587: if (nline == 1)
! 588: ewprintf("[Inserted 1 line]");
! 589: else
! 590: ewprintf("[Inserted %d lines]", nline);
1.1 deraadt 591:
1.3 ! millert 592: clp = curwp->w_linep; /* cosmetic adjustment */
! 593: if (curwp->w_dotp == clp) { /* for offscreen insert */
! 594: while (nline-- && lback(clp) != curbp->b_linep)
1.1 deraadt 595: clp = lback(clp);
1.3 ! millert 596: curwp->w_linep = clp; /* adjust framing. */
1.1 deraadt 597: curwp->w_flag |= WFHARD;
598: }
599: return (TRUE);
600: }
601:
602: /*
603: * Turn off the dirty bit on this buffer.
604: */
1.3 ! millert 605: /* ARGSUSED */
! 606: int
1.1 deraadt 607: notmodified(f, n)
608: {
1.3 ! millert 609: MGWIN *wp;
1.1 deraadt 610:
611: curbp->b_flag &= ~BFCHG;
1.3 ! millert 612: wp = wheadp; /* Update mode lines. */
1.1 deraadt 613: while (wp != NULL) {
614: if (wp->w_bufp == curbp)
615: wp->w_flag |= WFMODE;
616: wp = wp->w_wndp;
617: }
618: ewprintf("Modification-flag cleared");
619: return TRUE;
620: }
621:
622: #ifndef NO_HELP
623: /*
624: * Popbuf and set all windows to top of buffer. Currently only used by
625: * help functions.
626: */
1.3 ! millert 627: int
1.1 deraadt 628: popbuftop(bp)
1.3 ! millert 629: BUFFER *bp;
1.1 deraadt 630: {
1.3 ! millert 631: MGWIN *wp;
1.1 deraadt 632:
1.3 ! millert 633: bp->b_dotp = lforw(bp->b_linep);
! 634: bp->b_doto = 0;
! 635: if (bp->b_nwnd != 0) {
! 636: for (wp = wheadp; wp != NULL; wp = wp->w_wndp)
! 637: if (wp->w_bufp == bp) {
! 638: wp->w_dotp = bp->b_dotp;
! 639: wp->w_doto = 0;
! 640: wp->w_flag |= WFHARD;
! 641: }
! 642: }
! 643: return popbuf(bp) != NULL;
1.1 deraadt 644: }
645: #endif