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