version 1.63, 2006/11/17 08:45:31 |
version 1.64, 2006/12/24 01:20:53 |
|
|
(void)strlcat(bp->b_cwd, "/", sizeof(bp->b_cwd)); |
(void)strlcat(bp->b_cwd, "/", sizeof(bp->b_cwd)); |
} |
} |
opos = curwp->w_doto; |
opos = curwp->w_doto; |
|
|
/* Open a new line, at point, and start inserting after it. */ |
|
x2 = undo_enable(FALSE); |
|
oline = curwp->w_dotline; |
oline = curwp->w_dotline; |
|
/* |
|
* Open a new line at dot and start inserting after it. |
|
* We will delete this newline after insertion. |
|
* Disable undo, as we create the undo record manually. |
|
*/ |
|
x2 = undo_enable(FALSE); |
(void)lnewline(); |
(void)lnewline(); |
olp = lback(curwp->w_dotp); |
olp = lback(curwp->w_dotp); |
if (olp == curbp->b_headp) { |
|
/* if at end of buffer, create a line to insert before */ |
|
(void)lnewline(); |
|
curwp->w_dotp = lback(curwp->w_dotp); |
|
} |
|
undo_enable(x2); |
undo_enable(x2); |
|
|
/* don't count fake lines at the end */ |
|
nline = 0; |
nline = 0; |
siz = 0; |
siz = 0; |
while ((s = ffgetline(line, linesize, &nbytes)) != FIOERR) { |
while ((s = ffgetline(line, linesize, &nbytes)) != FIOERR) { |
doneread: |
retry: |
siz += nbytes + 1; |
siz += nbytes + 1; |
switch (s) { |
switch (s) { |
case FIOSUC: |
case FIOSUC: |
/* FALLTHRU */ |
/* FALLTHRU */ |
case FIOEOF: |
case FIOEOF: |
/* the last line of the file */ |
|
++nline; |
++nline; |
if ((lp1 = lalloc(nbytes)) == NULL) { |
if ((lp1 = lalloc(nbytes)) == NULL) { |
/* keep message on the display */ |
/* keep message on the display */ |
s = FIOERR; |
s = FIOERR; |
|
undo_add_insert(olp, opos, |
|
siz - nbytes - 1 - 1); |
goto endoffile; |
goto endoffile; |
} |
} |
bcopy(line, <ext(lp1)[0], nbytes); |
bcopy(line, <ext(lp1)[0], nbytes); |
|
|
lp1->l_fp = curwp->w_dotp; |
lp1->l_fp = curwp->w_dotp; |
lp1->l_bp = lp2; |
lp1->l_bp = lp2; |
curwp->w_dotp->l_bp = lp1; |
curwp->w_dotp->l_bp = lp1; |
if (s == FIOEOF) |
if (s == FIOEOF) { |
|
undo_add_insert(olp, opos, siz - 1); |
goto endoffile; |
goto endoffile; |
|
} |
break; |
break; |
case FIOLONG: { |
case FIOLONG: { |
/* a line too long to fit in our buffer */ |
/* a line too long to fit in our buffer */ |
|
|
linesize = newsize; |
linesize = newsize; |
if (s == FIOERR) |
if (s == FIOERR) |
goto endoffile; |
goto endoffile; |
goto doneread; |
goto retry; |
} |
} |
default: |
default: |
ewprintf("Unknown code %d reading file", s); |
ewprintf("Unknown code %d reading file", s); |
|
|
} |
} |
} |
} |
endoffile: |
endoffile: |
undo_add_insert(olp, opos, siz - 1); |
|
|
|
/* ignore errors */ |
/* ignore errors */ |
ffclose(NULL); |
ffclose(NULL); |
/* don't zap an error */ |
/* don't zap an error */ |
|
|
/* set mark at the end of the text */ |
/* set mark at the end of the text */ |
curwp->w_dotp = curwp->w_markp = lback(curwp->w_dotp); |
curwp->w_dotp = curwp->w_markp = lback(curwp->w_dotp); |
curwp->w_marko = llength(curwp->w_markp); |
curwp->w_marko = llength(curwp->w_markp); |
(void)ldelnewline(); |
curwp->w_markline = oline + nline + 1; |
|
/* |
|
* if we are at the end of the file, ldelnewline is a no-op, |
|
* but we still need to decrement the line and markline counts |
|
* as we've accounted for this fencepost in our arithmetic |
|
*/ |
|
if (lforw(curwp->w_dotp) == curwp->w_bufp->b_headp) { |
|
curwp->w_bufp->b_lines--; |
|
curwp->w_markline--; |
|
} else |
|
(void)ldelnewline(); |
curwp->w_dotp = olp; |
curwp->w_dotp = olp; |
curwp->w_doto = opos; |
curwp->w_doto = opos; |
curwp->w_dotline = oline; |
curwp->w_dotline = oline; |