Annotation of src/usr.bin/mg/line.c, Revision 1.39
1.39 ! kjell 1: /* $OpenBSD: line.c,v 1.38 2006/05/27 21:20:11 kjell Exp $ */
1.23 kjell 2:
3: /* This file is in the public domain. */
1.5 niklas 4:
1.1 deraadt 5: /*
6: * Text line handling.
1.8 mickey 7: *
1.4 millert 8: * The functions in this file are a general set of line management
1.8 mickey 9: * utilities. They are the only routines that touch the text. They
10: * also touch the buffer and window structures to make sure that the
11: * necessary updating gets done. There are routines in this file that
1.4 millert 12: * handle the kill buffer too. It isn't here for any good reason.
1.1 deraadt 13: *
1.8 mickey 14: * Note that this code only updates the dot and mark values in the window
15: * list. Since all the code acts on the current window, the buffer that
16: * we are editing must be displayed, which means that "b_nwnd" is non-zero,
17: * which means that the dot and mark values in the buffer headers are
1.1 deraadt 18: * nonsense.
19: */
20:
1.4 millert 21: #include "def.h"
22:
1.32 kjell 23: #include <stdlib.h>
24: #include <string.h>
25:
1.4 millert 26: /*
1.9 vincent 27: * Allocate a new line of size `used'. lrealloc() can be called if the line
28: * ever needs to grow beyond that.
1.1 deraadt 29: */
1.28 deraadt 30: struct line *
1.9 vincent 31: lalloc(int used)
1.3 millert 32: {
1.28 deraadt 33: struct line *lp;
1.1 deraadt 34:
1.22 db 35: if ((lp = malloc(sizeof(*lp))) == NULL)
36: return (NULL);
1.9 vincent 37: lp->l_text = NULL;
38: lp->l_size = 0;
39: lp->l_used = used; /* XXX */
40: if (lrealloc(lp, used) == FALSE) {
41: free(lp);
1.22 db 42: return (NULL);
1.1 deraadt 43: }
1.22 db 44: return (lp);
1.1 deraadt 45: }
46:
1.9 vincent 47: int
1.28 deraadt 48: lrealloc(struct line *lp, int newsize)
1.1 deraadt 49: {
1.9 vincent 50: char *tmp;
1.1 deraadt 51:
1.18 millert 52: if (lp->l_size < newsize) {
53: if ((tmp = realloc(lp->l_text, newsize)) == NULL)
1.22 db 54: return (FALSE);
1.18 millert 55: lp->l_text = tmp;
56: lp->l_size = newsize;
57: }
1.22 db 58: return (TRUE);
1.1 deraadt 59: }
60:
61: /*
1.4 millert 62: * Delete line "lp". Fix all of the links that might point to it (they are
1.8 mickey 63: * moved to offset 0 of the next line. Unlink the line from whatever buffer
64: * it might be in, and release the memory. The buffers are updated too; the
1.4 millert 65: * magic conditions described in the above comments don't hold here.
1.1 deraadt 66: */
1.6 art 67: void
1.28 deraadt 68: lfree(struct line *lp)
1.3 millert 69: {
1.28 deraadt 70: struct buffer *bp;
71: struct mgwin *wp;
1.1 deraadt 72:
1.3 millert 73: for (wp = wheadp; wp != NULL; wp = wp->w_wndp) {
1.1 deraadt 74: if (wp->w_linep == lp)
75: wp->w_linep = lp->l_fp;
1.3 millert 76: if (wp->w_dotp == lp) {
77: wp->w_dotp = lp->l_fp;
78: wp->w_doto = 0;
1.1 deraadt 79: }
80: if (wp->w_markp == lp) {
81: wp->w_markp = lp->l_fp;
82: wp->w_marko = 0;
83: }
84: }
1.3 millert 85: for (bp = bheadp; bp != NULL; bp = bp->b_bufp) {
1.1 deraadt 86: if (bp->b_nwnd == 0) {
1.3 millert 87: if (bp->b_dotp == lp) {
1.1 deraadt 88: bp->b_dotp = lp->l_fp;
89: bp->b_doto = 0;
90: }
91: if (bp->b_markp == lp) {
92: bp->b_markp = lp->l_fp;
93: bp->b_marko = 0;
94: }
95: }
96: }
97: lp->l_bp->l_fp = lp->l_fp;
98: lp->l_fp->l_bp = lp->l_bp;
1.9 vincent 99: if (lp->l_text != NULL)
100: free(lp->l_text);
101: free(lp);
1.1 deraadt 102: }
103:
104: /*
1.8 mickey 105: * This routine is called when a character changes in place in the current
106: * buffer. It updates all of the required flags in the buffer and window
107: * system. The flag used is passed as an argument; if the buffer is being
108: * displayed in more than 1 window we change EDIT to HARD. Set MODE if the
1.4 millert 109: * mode line needs to be updated (the "*" has to be set).
1.1 deraadt 110: */
1.6 art 111: void
1.15 vincent 112: lchange(int flag)
1.3 millert 113: {
1.28 deraadt 114: struct mgwin *wp;
1.1 deraadt 115:
1.4 millert 116: /* update mode lines if this is the first change. */
117: if ((curbp->b_flag & BFCHG) == 0) {
118: flag |= WFMODE;
1.1 deraadt 119: curbp->b_flag |= BFCHG;
120: }
1.3 millert 121: for (wp = wheadp; wp != NULL; wp = wp->w_wndp) {
1.1 deraadt 122: if (wp->w_bufp == curbp) {
123: wp->w_flag |= flag;
1.3 millert 124: if (wp != curwp)
1.39 ! kjell 125: wp->w_flag |= WFFULL;
1.1 deraadt 126: }
127: }
128: }
129:
130: /*
1.20 vincent 131: * Insert "n" bytes from "s" at the current location of dot.
132: * In the easy case all that happens is the text is stored in the line.
133: * In the hard case, the line has to be reallocated. When the window list
134: * is updated, take special care; I screwed it up once. You always update
135: * dot in the current window. You update mark and a dot in another window
136: * if it is greater than the place where you did the insert. Return TRUE
137: * if all is well, and FALSE on errors.
138: */
139: int
140: linsert_str(const char *s, int n)
141: {
1.28 deraadt 142: struct line *lp1;
143: struct mgwin *wp;
1.20 vincent 144: RSIZE i;
145: int doto;
146:
147: if (curbp->b_flag & BFREADONLY) {
148: ewprintf("Buffer is read only");
1.22 db 149: return (FALSE);
1.20 vincent 150: }
151:
152: if (!n)
153: return (TRUE);
154:
1.39 ! kjell 155: lchange(WFFULL);
1.20 vincent 156:
157: /* current line */
158: lp1 = curwp->w_dotp;
159:
160: /* special case for the end */
161: if (lp1 == curbp->b_linep) {
1.28 deraadt 162: struct line *lp2, *lp3;
1.20 vincent 163:
164: /* now should only happen in empty buffer */
165: if (curwp->w_doto != 0)
166: panic("bug: linsert_str");
167: /* allocate a new line */
168: if ((lp2 = lalloc(n)) == NULL)
1.22 db 169: return (FALSE);
1.20 vincent 170: /* previous line */
171: lp3 = lp1->l_bp;
172: /* link in */
173: lp3->l_fp = lp2;
174: lp2->l_fp = lp1;
175: lp1->l_bp = lp2;
176: lp2->l_bp = lp3;
177: for (i = 0; i < n; ++i)
178: lp2->l_text[i] = s[i];
179: for (wp = wheadp; wp != NULL; wp = wp->w_wndp) {
180: if (wp->w_linep == lp1)
181: wp->w_linep = lp2;
182: if (wp->w_dotp == lp1)
183: wp->w_dotp = lp2;
184: if (wp->w_markp == lp1)
185: wp->w_markp = lp2;
186: }
187: undo_add_insert(lp2, 0, n);
188: curwp->w_doto = n;
1.22 db 189: return (TRUE);
1.20 vincent 190: }
191: /* save for later */
192: doto = curwp->w_doto;
193:
194: if ((lp1->l_used + n) > lp1->l_size) {
195: if (lrealloc(lp1, lp1->l_used + n) == FALSE)
1.22 db 196: return (FALSE);
1.20 vincent 197: }
198: lp1->l_used += n;
199: if (lp1->l_used != n)
200: memmove(&lp1->l_text[doto + n], &lp1->l_text[doto],
201: lp1->l_used - n - doto);
202:
203: /* Add the characters */
204: for (i = 0; i < n; ++i)
205: lp1->l_text[doto + i] = s[i];
206: for (wp = wheadp; wp != NULL; wp = wp->w_wndp) {
207: if (wp->w_dotp == lp1) {
208: if (wp == curwp || wp->w_doto > doto)
209: wp->w_doto += n;
210: }
211: if (wp->w_markp == lp1) {
212: if (wp->w_marko > doto)
213: wp->w_marko += n;
214: }
215: }
216: undo_add_insert(curwp->w_dotp, doto, n);
1.22 db 217: return (TRUE);
1.20 vincent 218: }
219:
220: /*
1.8 mickey 221: * Insert "n" copies of the character "c" at the current location of dot.
222: * In the easy case all that happens is the text is stored in the line.
223: * In the hard case, the line has to be reallocated. When the window list
224: * is updated, take special care; I screwed it up once. You always update
1.4 millert 225: * dot in the current window. You update mark and a dot in another window
226: * if it is greater than the place where you did the insert. Return TRUE
1.1 deraadt 227: * if all is well, and FALSE on errors.
228: */
1.4 millert 229: int
1.15 vincent 230: linsert(int n, int c)
1.1 deraadt 231: {
1.28 deraadt 232: struct line *lp1;
233: struct mgwin *wp;
1.4 millert 234: RSIZE i;
235: int doto;
1.1 deraadt 236:
1.20 vincent 237: if (!n)
238: return (TRUE);
239:
1.15 vincent 240: if (curbp->b_flag & BFREADONLY) {
241: ewprintf("Buffer is read only");
1.22 db 242: return (FALSE);
1.15 vincent 243: }
244:
1.1 deraadt 245: lchange(WFEDIT);
1.4 millert 246:
247: /* current line */
248: lp1 = curwp->w_dotp;
1.15 vincent 249:
1.4 millert 250: /* special case for the end */
251: if (lp1 == curbp->b_linep) {
1.28 deraadt 252: struct line *lp2, *lp3;
1.11 deraadt 253:
1.4 millert 254: /* now should only happen in empty buffer */
1.1 deraadt 255: if (curwp->w_doto != 0) {
256: ewprintf("bug: linsert");
1.22 db 257: return (FALSE);
1.1 deraadt 258: }
1.4 millert 259: /* allocate a new line */
1.9 vincent 260: if ((lp2 = lalloc(n)) == NULL)
1.22 db 261: return (FALSE);
1.4 millert 262: /* previous line */
263: lp3 = lp1->l_bp;
264: /* link in */
265: lp3->l_fp = lp2;
1.1 deraadt 266: lp2->l_fp = lp1;
267: lp1->l_bp = lp2;
268: lp2->l_bp = lp3;
1.3 millert 269: for (i = 0; i < n; ++i)
1.1 deraadt 270: lp2->l_text[i] = c;
1.3 millert 271: for (wp = wheadp; wp != NULL; wp = wp->w_wndp) {
1.1 deraadt 272: if (wp->w_linep == lp1)
273: wp->w_linep = lp2;
274: if (wp->w_dotp == lp1)
275: wp->w_dotp = lp2;
276: if (wp->w_markp == lp1)
277: wp->w_markp = lp2;
278: }
1.16 vincent 279: undo_add_insert(lp2, 0, n);
1.1 deraadt 280: curwp->w_doto = n;
1.22 db 281: return (TRUE);
1.1 deraadt 282: }
1.4 millert 283: /* save for later */
284: doto = curwp->w_doto;
1.9 vincent 285:
286: if ((lp1->l_used + n) > lp1->l_size) {
287: if (lrealloc(lp1, lp1->l_used + n) == FALSE)
1.22 db 288: return (FALSE);
1.11 deraadt 289: }
1.9 vincent 290: lp1->l_used += n;
1.11 deraadt 291: if (lp1->l_used != n)
1.9 vincent 292: memmove(&lp1->l_text[doto + n], &lp1->l_text[doto],
293: lp1->l_used - n - doto);
294:
1.4 millert 295: /* Add the characters */
296: for (i = 0; i < n; ++i)
1.9 vincent 297: lp1->l_text[doto + i] = c;
1.3 millert 298: for (wp = wheadp; wp != NULL; wp = wp->w_wndp) {
1.1 deraadt 299: if (wp->w_dotp == lp1) {
1.3 millert 300: if (wp == curwp || wp->w_doto > doto)
1.1 deraadt 301: wp->w_doto += n;
302: }
303: if (wp->w_markp == lp1) {
304: if (wp->w_marko > doto)
305: wp->w_marko += n;
306: }
307: }
1.16 vincent 308: undo_add_insert(curwp->w_dotp, doto, n);
1.22 db 309: return (TRUE);
1.1 deraadt 310: }
311:
1.4 millert 312: int
1.28 deraadt 313: lnewline_at(struct line *lp1, int doto)
1.1 deraadt 314: {
1.28 deraadt 315: struct line *lp2;
1.21 vincent 316: int nlen;
1.28 deraadt 317: struct mgwin *wp;
1.1 deraadt 318:
1.39 ! kjell 319: lchange(WFFULL);
1.14 vincent 320:
1.35 kjell 321: /* If start of line, allocate a new line instead of copying */
1.4 millert 322: if (doto == 0) {
323: /* new first part */
1.35 kjell 324: if ((lp2 = lalloc(0)) == NULL)
325: return (FALSE);
1.1 deraadt 326: lp2->l_bp = lp1->l_bp;
327: lp1->l_bp->l_fp = lp2;
328: lp2->l_fp = lp1;
329: lp1->l_bp = lp2;
1.3 millert 330: for (wp = wheadp; wp != NULL; wp = wp->w_wndp)
331: if (wp->w_linep == lp1)
332: wp->w_linep = lp2;
1.35 kjell 333: undo_add_boundary();
334: undo_add_insert(lp2, 0, 1);
335: undo_add_boundary();
336: return (TRUE);
1.1 deraadt 337: }
1.4 millert 338:
339: /* length of new part */
340: nlen = llength(lp1) - doto;
341:
342: /* new second half line */
1.35 kjell 343: if ((lp2 = lalloc(nlen)) == NULL)
344: return (FALSE);
1.3 millert 345: if (nlen != 0)
346: bcopy(&lp1->l_text[doto], &lp2->l_text[0], nlen);
1.1 deraadt 347: lp1->l_used = doto;
348: lp2->l_bp = lp1;
349: lp2->l_fp = lp1->l_fp;
350: lp1->l_fp = lp2;
351: lp2->l_fp->l_bp = lp2;
1.4 millert 352: /* Windows */
353: for (wp = wheadp; wp != NULL; wp = wp->w_wndp) {
1.1 deraadt 354: if (wp->w_dotp == lp1 && wp->w_doto >= doto) {
355: wp->w_dotp = lp2;
356: wp->w_doto -= doto;
357: }
358: if (wp->w_markp == lp1 && wp->w_marko >= doto) {
359: wp->w_markp = lp2;
360: wp->w_marko -= doto;
361: }
362: }
1.24 kjell 363: undo_add_boundary();
364: undo_add_insert(lp1, llength(lp1), 1);
365: undo_add_boundary();
1.35 kjell 366: return (TRUE);
1.1 deraadt 367: }
368:
369: /*
1.21 vincent 370: * Insert a newline into the buffer at the current location of dot in the
371: * current window.
372: */
373: int
374: lnewline(void)
375: {
376: if (curbp->b_flag & BFREADONLY) {
377: ewprintf("Buffer is read only");
1.22 db 378: return (FALSE);
1.21 vincent 379: }
1.22 db 380: return (lnewline_at(curwp->w_dotp, curwp->w_doto));
1.21 vincent 381: }
382:
383: /*
1.36 kjell 384: * This function deletes "n" bytes, starting at dot. (actually, n+1, as the
385: * newline is included) It understands how to deal with end of lines, etc.
386: * It returns TRUE if all of the characters were deleted, and FALSE if
387: * they were not (because dot ran into the end of the buffer).
388: * The "kflag" indicates either no insertion, or direction of insertion
389: * into the kill buffer.
1.1 deraadt 390: */
1.4 millert 391: int
1.15 vincent 392: ldelete(RSIZE n, int kflag)
1.3 millert 393: {
1.28 deraadt 394: struct line *dotp;
1.36 kjell 395: RSIZE chunk;
1.28 deraadt 396: struct mgwin *wp;
1.36 kjell 397: int doto;
398: char *cp1, *cp2;
399: size_t len;
400: char *sv;
401: int end;
1.1 deraadt 402:
1.15 vincent 403: if (curbp->b_flag & BFREADONLY) {
404: ewprintf("Buffer is read only");
1.22 db 405: return (FALSE);
1.15 vincent 406: }
1.32 kjell 407: len = n;
408: if ((sv = calloc(1, len + 1)) == NULL)
409: return (FALSE);
410: end = 0;
1.15 vincent 411:
1.16 vincent 412: undo_add_delete(curwp->w_dotp, curwp->w_doto, n);
1.15 vincent 413:
1.1 deraadt 414: while (n != 0) {
415: dotp = curwp->w_dotp;
416: doto = curwp->w_doto;
1.4 millert 417: /* Hit the end of the buffer */
418: if (dotp == curbp->b_linep)
1.22 db 419: return (FALSE);
1.4 millert 420: /* Size of the chunk */
421: chunk = dotp->l_used - doto;
1.20 vincent 422:
1.1 deraadt 423: if (chunk > n)
424: chunk = n;
1.4 millert 425: /* End of line, merge */
426: if (chunk == 0) {
1.3 millert 427: if (dotp == lback(curbp->b_linep))
1.4 millert 428: /* End of buffer */
1.22 db 429: return (FALSE);
1.39 ! kjell 430: lchange(WFFULL);
1.32 kjell 431: if (ldelnewline() == FALSE)
1.22 db 432: return (FALSE);
1.32 kjell 433: end = strlcat(sv, "\n", len + 1);
1.1 deraadt 434: --n;
435: continue;
436: }
437: lchange(WFEDIT);
1.4 millert 438: /* Scrunch text */
439: cp1 = &dotp->l_text[doto];
1.32 kjell 440: memcpy(&sv[end], cp1, chunk);
441: end += chunk;
442: sv[end] = '\0';
1.20 vincent 443: for (cp2 = cp1 + chunk; cp2 < &dotp->l_text[dotp->l_used];
444: cp2++)
445: *cp1++ = *cp2;
1.4 millert 446: dotp->l_used -= (int)chunk;
1.3 millert 447: for (wp = wheadp; wp != NULL; wp = wp->w_wndp) {
448: if (wp->w_dotp == dotp && wp->w_doto >= doto) {
449: /* NOSTRICT */
1.1 deraadt 450: wp->w_doto -= chunk;
451: if (wp->w_doto < doto)
452: wp->w_doto = doto;
453: }
1.3 millert 454: if (wp->w_markp == dotp && wp->w_marko >= doto) {
455: /* NOSTRICT */
1.1 deraadt 456: wp->w_marko -= chunk;
457: if (wp->w_marko < doto)
458: wp->w_marko = doto;
459: }
460: }
461: n -= chunk;
462: }
1.34 kjell 463: if (kchunk(sv, (RSIZE)len, kflag) != TRUE)
1.32 kjell 464: return (FALSE);
465: free(sv);
1.22 db 466: return (TRUE);
1.1 deraadt 467: }
468:
469: /*
1.8 mickey 470: * Delete a newline and join the current line with the next line. If the next
1.4 millert 471: * line is the magic header line always return TRUE; merging the last line
1.8 mickey 472: * with the header line can be thought of as always being a successful
473: * operation. Even if nothing is done, this makes the kill buffer work
474: * "right". Easy cases can be done by shuffling data around. Hard cases
475: * require that lines be moved about in memory. Return FALSE on error and
1.4 millert 476: * TRUE if all looks ok.
1.1 deraadt 477: */
1.4 millert 478: int
1.15 vincent 479: ldelnewline(void)
1.3 millert 480: {
1.28 deraadt 481: struct line *lp1, *lp2, *lp3;
482: struct mgwin *wp;
1.1 deraadt 483:
1.15 vincent 484: if (curbp->b_flag & BFREADONLY) {
485: ewprintf("Buffer is read only");
1.22 db 486: return (FALSE);
1.15 vincent 487: }
488:
1.1 deraadt 489: lp1 = curwp->w_dotp;
490: lp2 = lp1->l_fp;
1.4 millert 491: /* at the end of the buffer */
492: if (lp2 == curbp->b_linep)
1.22 db 493: return (TRUE);
1.1 deraadt 494: if (lp2->l_used <= lp1->l_size - lp1->l_used) {
495: bcopy(&lp2->l_text[0], &lp1->l_text[lp1->l_used], lp2->l_used);
1.3 millert 496: for (wp = wheadp; wp != NULL; wp = wp->w_wndp) {
1.1 deraadt 497: if (wp->w_linep == lp2)
498: wp->w_linep = lp1;
499: if (wp->w_dotp == lp2) {
1.3 millert 500: wp->w_dotp = lp1;
1.1 deraadt 501: wp->w_doto += lp1->l_used;
502: }
503: if (wp->w_markp == lp2) {
1.3 millert 504: wp->w_markp = lp1;
1.1 deraadt 505: wp->w_marko += lp1->l_used;
506: }
507: }
508: lp1->l_used += lp2->l_used;
509: lp1->l_fp = lp2->l_fp;
510: lp2->l_fp->l_bp = lp1;
1.37 kjell 511: free(lp2);
1.22 db 512: return (TRUE);
1.1 deraadt 513: }
1.3 millert 514: if ((lp3 = lalloc(lp1->l_used + lp2->l_used)) == NULL)
1.22 db 515: return (FALSE);
1.1 deraadt 516: bcopy(&lp1->l_text[0], &lp3->l_text[0], lp1->l_used);
517: bcopy(&lp2->l_text[0], &lp3->l_text[lp1->l_used], lp2->l_used);
518: lp1->l_bp->l_fp = lp3;
519: lp3->l_fp = lp2->l_fp;
520: lp2->l_fp->l_bp = lp3;
521: lp3->l_bp = lp1->l_bp;
1.3 millert 522: for (wp = wheadp; wp != NULL; wp = wp->w_wndp) {
523: if (wp->w_linep == lp1 || wp->w_linep == lp2)
1.1 deraadt 524: wp->w_linep = lp3;
525: if (wp->w_dotp == lp1)
1.3 millert 526: wp->w_dotp = lp3;
1.1 deraadt 527: else if (wp->w_dotp == lp2) {
1.3 millert 528: wp->w_dotp = lp3;
1.1 deraadt 529: wp->w_doto += lp1->l_used;
530: }
531: if (wp->w_markp == lp1)
1.3 millert 532: wp->w_markp = lp3;
1.1 deraadt 533: else if (wp->w_markp == lp2) {
1.3 millert 534: wp->w_markp = lp3;
1.1 deraadt 535: wp->w_marko += lp1->l_used;
536: }
537: }
1.37 kjell 538: free(lp1);
539: free(lp2);
1.22 db 540: return (TRUE);
1.1 deraadt 541: }
1.9 vincent 542:
1.1 deraadt 543: /*
1.8 mickey 544: * Replace plen characters before dot with argument string. Control-J
545: * characters in st are interpreted as newlines. There is a casehack
546: * disable flag (normally it likes to match case of replacement to what
1.4 millert 547: * was there).
1.1 deraadt 548: */
1.4 millert 549: int
1.27 kjell 550: lreplace(RSIZE plen, char *st)
1.4 millert 551: {
552: RSIZE rlen; /* replacement length */
1.15 vincent 553:
554: if (curbp->b_flag & BFREADONLY) {
555: ewprintf("Buffer is read only");
1.22 db 556: return (FALSE);
1.15 vincent 557: }
1.24 kjell 558: undo_add_boundary();
559: undo_no_boundary(TRUE);
1.25 deraadt 560:
1.6 art 561: (void)backchar(FFARG | FFRAND, (int)plen);
1.24 kjell 562: (void)ldelete(plen, KNONE);
1.15 vincent 563:
1.1 deraadt 564: rlen = strlen(st);
1.24 kjell 565: region_put_data(st, rlen);
1.39 ! kjell 566: lchange(WFFULL);
1.1 deraadt 567:
1.24 kjell 568: undo_no_boundary(FALSE);
569: undo_add_boundary();
1.29 kjell 570: return (TRUE);
1.38 kjell 571: }
572:
573: /*
574: * Allocate and return the supplied line as a C string
575: */
576: char *
577: linetostr(const struct line *ln)
578: {
579: size_t len;
580: char *line;
581:
582: len = llength(ln);
583: if (len == SIZE_MAX) /* (len + 1) overflow */
584: return (NULL);
585:
586: if ((line = malloc(len + 1)) == NULL)
587: return (NULL);
588:
589: (void)memcpy(line, ltext(ln), len);
590: line[len] = '\0';
591:
592: return (line);
1.1 deraadt 593: }