version 1.31, 2005/03/10 18:27:47 |
version 1.32, 2005/04/03 02:09:28 |
|
|
|
|
bufp = eread("Insert file: ", fname, NFILEN, EFNEW | EFCR | EFFILE); |
bufp = eread("Insert file: ", fname, NFILEN, EFNEW | EFCR | EFFILE); |
if (bufp == NULL) |
if (bufp == NULL) |
return ABORT; |
return (ABORT); |
else if (bufp[0] == '\0') |
else if (bufp[0] == '\0') |
return FALSE; |
return (FALSE); |
adjf = adjustname(bufp); |
adjf = adjustname(bufp); |
if (adjf == NULL) |
if (adjf == NULL) |
return (FALSE); |
return (FALSE); |
return insertfile(adjf, NULL, FALSE); |
return (insertfile(adjf, NULL, FALSE)); |
} |
} |
|
|
/* |
/* |
|
|
|
|
bufp = eread("Find file: ", fname, NFILEN, EFNEW | EFCR | EFFILE); |
bufp = eread("Find file: ", fname, NFILEN, EFNEW | EFCR | EFFILE); |
if (bufp == NULL) |
if (bufp == NULL) |
return ABORT; |
return (ABORT); |
else if (bufp[0] == '\0') |
else if (bufp[0] == '\0') |
return FALSE; |
return (FALSE); |
adjf = adjustname(fname); |
adjf = adjustname(fname); |
if (adjf == NULL) |
if (adjf == NULL) |
return (FALSE); |
return (FALSE); |
if ((bp = findbuffer(adjf)) == NULL) |
if ((bp = findbuffer(adjf)) == NULL) |
return FALSE; |
return (FALSE); |
curbp = bp; |
curbp = bp; |
if (showbuffer(bp, curwp, WFHARD) != TRUE) |
if (showbuffer(bp, curwp, WFHARD) != TRUE) |
return FALSE; |
return (FALSE); |
if (bp->b_fname[0] == 0) { |
if (bp->b_fname[0] == 0) { |
int status; |
int status; |
|
|
if ((status = readin(adjf)) != TRUE) |
if ((status = readin(adjf)) != TRUE) |
killbuffer(bp); |
killbuffer(bp); |
return status; |
return (status); |
} |
} |
return TRUE; |
return (TRUE); |
} |
} |
|
|
int |
int |
|
|
curbp->b_flag |= BFREADONLY; |
curbp->b_flag |= BFREADONLY; |
return (TRUE); |
return (TRUE); |
} |
} |
|
|
/* |
/* |
* Pop to a file in the other window. Same as the last function, but uses |
* Pop to a file in the other window. Same as the last function, but uses |
* popbuf instead of showbuffer. |
* popbuf instead of showbuffer. |
|
|
|
|
if ((bufp = eread("Find file in other window: ", fname, NFILEN, |
if ((bufp = eread("Find file in other window: ", fname, NFILEN, |
EFNEW | EFCR | EFFILE)) == NULL) |
EFNEW | EFCR | EFFILE)) == NULL) |
return ABORT; |
return (ABORT); |
else if (bufp[0] == '\0') |
else if (bufp[0] == '\0') |
return FALSE; |
return (FALSE); |
adjf = adjustname(fname); |
adjf = adjustname(fname); |
if (adjf == NULL) |
if (adjf == NULL) |
return (FALSE); |
return (FALSE); |
if ((bp = findbuffer(adjf)) == NULL) |
if ((bp = findbuffer(adjf)) == NULL) |
return FALSE; |
return (FALSE); |
if ((wp = popbuf(bp)) == NULL) |
if ((wp = popbuf(bp)) == NULL) |
return FALSE; |
return (FALSE); |
curbp = bp; |
curbp = bp; |
curwp = wp; |
curwp = wp; |
if (bp->b_fname[0] == 0) { |
if (bp->b_fname[0] == 0) { |
|
|
|
|
if ((status = readin(adjf)) != TRUE) |
if ((status = readin(adjf)) != TRUE) |
killbuffer(bp); |
killbuffer(bp); |
return status; |
return (status); |
} |
} |
return TRUE; |
return (TRUE); |
} |
} |
|
|
/* |
/* |
* given a file name, either find the buffer it uses, or create a new |
* Given a file name, either find the buffer it uses, or create a new |
* empty buffer to put it in. |
* empty buffer to put it in. |
*/ |
*/ |
BUFFER * |
BUFFER * |
|
|
|
|
for (bp = bheadp; bp != NULL; bp = bp->b_bufp) { |
for (bp = bheadp; bp != NULL; bp = bp->b_bufp) { |
if (strcmp(bp->b_fname, fname) == 0) |
if (strcmp(bp->b_fname, fname) == 0) |
return bp; |
return (bp); |
} |
} |
i = strlcpy(bname, basename(fname), sizeof(bname)); |
i = strlcpy(bname, basename(fname), sizeof(bname)); |
remain = sizeof(bname) - i; |
remain = sizeof(bname) - i; |
for (count = 2; bfind(bname, FALSE) != NULL; count++) |
for (count = 2; bfind(bname, FALSE) != NULL; count++) |
snprintf(&bname[i], remain, "<%d>", count); |
snprintf(&bname[i], remain, "<%d>", count); |
|
|
return bfind(bname, TRUE); |
return (bfind(bname, TRUE)); |
} |
} |
|
|
/* |
/* |
|
|
|
|
/* might be old */ |
/* might be old */ |
if (bclear(curbp) != TRUE) |
if (bclear(curbp) != TRUE) |
return TRUE; |
return (TRUE); |
if ((status = insertfile(fname, fname, TRUE)) != TRUE) { |
if ((status = insertfile(fname, fname, TRUE)) != TRUE) { |
ewprintf("File is not readable: %s", fname); |
ewprintf("File is not readable: %s", fname); |
return FALSE; |
return (FALSE); |
} |
} |
|
|
/* |
/* |
|
|
} |
} |
} |
} |
|
|
/* We need to set the READONLY flag after we insert the file */ |
/* We need to set the READONLY flag after we insert the file. */ |
if (access(fname, W_OK) && errno != ENOENT) |
if (access(fname, W_OK) && errno != ENOENT) |
curbp->b_flag |= BFREADONLY; |
curbp->b_flag |= BFREADONLY; |
else |
else |
|
|
if (startrow) |
if (startrow) |
gotoline(FFARG, startrow); |
gotoline(FFARG, startrow); |
|
|
return status; |
return (status); |
} |
} |
|
|
/* |
/* |
|
|
* Insert a file in the current buffer, after dot. Set mark at the end of |
* Insert a file in the current buffer, after dot. Set mark at the end of |
* the text inserted; point at the beginning. Return a standard status. |
* the text inserted; point at the beginning. Return a standard status. |
* Print a summary (lines read, error message) out as well. Unless the |
* Print a summary (lines read, error message) out as well. Unless the |
* NO_BACKUP conditional is set, this routine also does the read end of |
* NO_BACKUP conditional is set, this routine also does the read end of |
* backup processing. The BFBAK flag, if set in a buffer, says that a |
* backup processing. The BFBAK flag, if set in a buffer, says that a |
* backup should be taken. It is set when a file is read in, but not on |
* backup should be taken. It is set when a file is read in, but not on |
* a new file. (You don't need to make a backup copy of nothing.) |
* a new file. (You don't need to make a backup copy of nothing.) |
|
|
bp->b_flag |= BFCHG; |
bp->b_flag |= BFCHG; |
#endif /* !NO_BACKUP */ |
#endif /* !NO_BACKUP */ |
/* |
/* |
* if the insert was at the end of buffer, set lp1 to the end of |
* If the insert was at the end of buffer, set lp1 to the end of |
* buffer line, and lp2 to the beginning of the newly inserted text. |
* buffer line, and lp2 to the beginning of the newly inserted text. |
* (Otherwise lp2 is set to NULL.) This is used below to set |
* (Otherwise lp2 is set to NULL.) This is used below to set |
* pointers in other windows correctly if they are also at the end of |
* pointers in other windows correctly if they are also at the end of |
|
|
undo_enable(x); |
undo_enable(x); |
|
|
/* return false if error */ |
/* return false if error */ |
return s != FIOERR; |
return (s != FIOERR); |
} |
} |
|
|
/* |
/* |
|
|
|
|
if ((bufp = eread("Write file: ", fname, NFILEN, |
if ((bufp = eread("Write file: ", fname, NFILEN, |
EFNEW | EFCR | EFFILE)) == NULL) |
EFNEW | EFCR | EFFILE)) == NULL) |
return ABORT; |
return (ABORT); |
else if (bufp[0] == '\0') |
else if (bufp[0] == '\0') |
return FALSE; |
return (FALSE); |
|
|
adjfname = adjustname(fname); |
adjfname = adjustname(fname); |
if (adjfname == NULL) |
if (adjfname == NULL) |
|
|
#endif /* !NO_BACKUP */ |
#endif /* !NO_BACKUP */ |
upmodes(curbp); |
upmodes(curbp); |
} |
} |
return s; |
return (s); |
} |
} |
|
|
/* |
/* |
|
|
int |
int |
filesave(int f, int n) |
filesave(int f, int n) |
{ |
{ |
return buffsave(curbp); |
return (buffsave(curbp)); |
} |
} |
|
|
/* |
/* |
|
|
/* return, no changes */ |
/* return, no changes */ |
if ((bp->b_flag & BFCHG) == 0) { |
if ((bp->b_flag & BFCHG) == 0) { |
ewprintf("(No changes need to be saved)"); |
ewprintf("(No changes need to be saved)"); |
return TRUE; |
return (TRUE); |
} |
} |
|
|
/* must have a name */ |
/* must have a name */ |
|
|
s = fbackupfile(bp->b_fname); |
s = fbackupfile(bp->b_fname); |
/* hard error */ |
/* hard error */ |
if (s == ABORT) |
if (s == ABORT) |
return FALSE; |
return (FALSE); |
/* softer error */ |
/* softer error */ |
if (s == FALSE && |
if (s == FALSE && |
(s = eyesno("Backup error, save anyway")) != TRUE) |
(s = eyesno("Backup error, save anyway")) != TRUE) |
return s; |
return (s); |
} |
} |
#endif /* !NO_BACKUP */ |
#endif /* !NO_BACKUP */ |
if ((s = writeout(bp, bp->b_fname)) == TRUE) { |
if ((s = writeout(bp, bp->b_fname)) == TRUE) { |
|
|
#endif /* !NO_BACKUP */ |
#endif /* !NO_BACKUP */ |
upmodes(bp); |
upmodes(bp); |
} |
} |
return s; |
return (s); |
} |
} |
|
|
#ifndef NO_BACKUP |
#ifndef NO_BACKUP |
|
|
else |
else |
makebackup = !makebackup; |
makebackup = !makebackup; |
ewprintf("Backup files %sabled", makebackup ? "en" : "dis"); |
ewprintf("Backup files %sabled", makebackup ? "en" : "dis"); |
return TRUE; |
return (TRUE); |
} |
} |
#endif /* !NO_BACKUP */ |
#endif /* !NO_BACKUP */ |
|
|
|
|
} else |
} else |
/* ignore close error if it is a write error */ |
/* ignore close error if it is a write error */ |
(void)ffclose(bp); |
(void)ffclose(bp); |
return s == FIOSUC; |
return (s == FIOSUC); |
} |
} |
|
|
/* |
/* |