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