mirror of
https://github.com/rfivet/uemacs.git
synced 2024-12-18 15:26:23 -05:00
Review windows update when reading or writing buffers to file.
This commit is contained in:
parent
af23c6b3b5
commit
16e6f87ad5
615
file.c
615
file.c
@ -2,13 +2,13 @@
|
||||
|
||||
#include "file.h"
|
||||
|
||||
/* file.c
|
||||
/* file.c
|
||||
*
|
||||
* The routines in this file handle the reading, writing
|
||||
* and lookup of disk files. All of details about the
|
||||
* reading and writing of the disk are in "fileio.c".
|
||||
* The routines in this file handle the reading, writing
|
||||
* and lookup of disk files. All of details about the
|
||||
* reading and writing of the disk are in "fileio.c".
|
||||
*
|
||||
* modified by Petri Kutvonen
|
||||
* modified by Petri Kutvonen
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
@ -51,7 +51,7 @@ static const char *codename[] = {
|
||||
"MIXED"
|
||||
} ;
|
||||
|
||||
boolean restflag = FALSE ; /* restricted use? */
|
||||
boolean restflag = FALSE ; /* restricted use? */
|
||||
|
||||
|
||||
static int ifile( const char *fname) ;
|
||||
@ -64,54 +64,54 @@ boolean resterr( void) {
|
||||
|
||||
/*
|
||||
* Read a file into the current
|
||||
* buffer. This is really easy; all you do it
|
||||
* buffer. This is really easy; all you do is
|
||||
* find the name of the file, and call the standard
|
||||
* "read a file into the current buffer" code.
|
||||
* Bound to "C-X C-R".
|
||||
*/
|
||||
int fileread( int f, int n) {
|
||||
int status ;
|
||||
char *fname ;
|
||||
int status ;
|
||||
char *fname ;
|
||||
|
||||
if( restflag) /* don't allow this command if restricted */
|
||||
return resterr() ;
|
||||
if( restflag) /* don't allow this command if restricted */
|
||||
return resterr() ;
|
||||
|
||||
status = newmlarg( &fname, "Read file: ", sizeof( fname_t)) ;
|
||||
if( status == TRUE) {
|
||||
status = readin( fname, TRUE) ;
|
||||
free( fname) ;
|
||||
}
|
||||
status = newmlarg( &fname, "Read file: ", sizeof( fname_t)) ;
|
||||
if( status == TRUE) {
|
||||
status = readin( fname, TRUE) ;
|
||||
free( fname) ;
|
||||
}
|
||||
|
||||
return status ;
|
||||
}
|
||||
|
||||
/*
|
||||
* Insert a file into the current
|
||||
* buffer. This is really easy; all you do it
|
||||
* buffer. This is really easy; all you do is
|
||||
* find the name of the file, and call the standard
|
||||
* "insert a file into the current buffer" code.
|
||||
* Bound to "C-X C-I".
|
||||
*/
|
||||
int insfile( int f, int n) {
|
||||
int status ;
|
||||
char *fname ;
|
||||
int status ;
|
||||
char *fname ;
|
||||
|
||||
if( restflag) /* don't allow this command if restricted */
|
||||
return resterr() ;
|
||||
if( restflag) /* don't allow this command if restricted */
|
||||
return resterr() ;
|
||||
|
||||
if( curbp->b_mode & MDVIEW) /* don't allow this command if */
|
||||
return rdonly() ; /* we are in read only mode */
|
||||
if( curbp->b_mode & MDVIEW) /* don't allow this command if */
|
||||
return rdonly() ; /* we are in read only mode */
|
||||
|
||||
status = newmlarg( &fname, "Insert file: ", sizeof( fname_t)) ;
|
||||
if( status == TRUE) {
|
||||
status = ifile( fname) ;
|
||||
free( fname) ;
|
||||
status = newmlarg( &fname, "Insert file: ", sizeof( fname_t)) ;
|
||||
if( status == TRUE) {
|
||||
status = ifile( fname) ;
|
||||
free( fname) ;
|
||||
}
|
||||
|
||||
if( status != TRUE)
|
||||
return status ;
|
||||
return status ;
|
||||
|
||||
return reposition( TRUE, -1) ;
|
||||
return reposition( TRUE, -1) ; /* Redraw with dot at bottom of window */
|
||||
}
|
||||
|
||||
/*
|
||||
@ -124,14 +124,14 @@ int insfile( int f, int n) {
|
||||
* Bound to C-X C-F.
|
||||
*/
|
||||
int filefind( int f, int n) {
|
||||
char *fname ; /* file user wishes to find */
|
||||
int status ; /* status return */
|
||||
char *fname ; /* file user wishes to find */
|
||||
int status ; /* status return */
|
||||
|
||||
if( restflag) /* don't allow this command if restricted */
|
||||
return resterr() ;
|
||||
if( restflag) /* don't allow this command if restricted */
|
||||
return resterr() ;
|
||||
|
||||
status = newmlarg( &fname, "Find file: ", sizeof( fname_t)) ;
|
||||
if( status == TRUE) {
|
||||
status = newmlarg( &fname, "Find file: ", sizeof( fname_t)) ;
|
||||
if( status == TRUE) {
|
||||
status = getfile( fname, TRUE) ;
|
||||
free( fname) ;
|
||||
}
|
||||
@ -139,101 +139,112 @@ int filefind( int f, int n) {
|
||||
return status ;
|
||||
}
|
||||
|
||||
int viewfile( int f, int n) { /* visit a file in VIEW mode */
|
||||
char *fname ; /* file user wishes to find */
|
||||
int status ; /* status return */
|
||||
static void upd_mode( void) {
|
||||
struct window *wp ;
|
||||
|
||||
if( restflag) /* don't allow this command if restricted */
|
||||
return resterr() ;
|
||||
|
||||
status = newmlarg( &fname, "View file: ", sizeof( fname_t)) ;
|
||||
if( status == TRUE) {
|
||||
/* Update mode lines */
|
||||
for( wp = wheadp ; wp != NULL ; wp = wp->w_wndp)
|
||||
if( wp->w_bufp == curbp)
|
||||
wp->w_flag |= WFMODE ;
|
||||
}
|
||||
|
||||
int viewfile( int f, int n) { /* visit a file in VIEW mode */
|
||||
char *fname ; /* file user wishes to find */
|
||||
int status ; /* status return */
|
||||
|
||||
if( restflag) /* don't allow this command if restricted */
|
||||
return resterr() ;
|
||||
|
||||
status = newmlarg( &fname, "View file: ", sizeof( fname_t)) ;
|
||||
if( status == TRUE) {
|
||||
status = getfile(fname, FALSE) ;
|
||||
free( fname) ;
|
||||
|
||||
if( status == TRUE) { /* if we succeed, put it in view mode */
|
||||
curwp->w_bufp->b_mode |= MDVIEW ;
|
||||
upd_mode() ;
|
||||
}
|
||||
}
|
||||
|
||||
if( status == TRUE) { /* if we succeed, put it in view mode */
|
||||
struct window *wp ; /* scan for windows that need updating */
|
||||
|
||||
curwp->w_bufp->b_mode |= MDVIEW ;
|
||||
|
||||
/* scan through and update mode lines of all windows */
|
||||
wp = wheadp ;
|
||||
while( wp != NULL) {
|
||||
wp->w_flag |= WFMODE ;
|
||||
wp = wp->w_wndp ;
|
||||
}
|
||||
}
|
||||
|
||||
return status ;
|
||||
return status ;
|
||||
}
|
||||
|
||||
/*
|
||||
* getfile()
|
||||
*
|
||||
* char fname[]; file name to find
|
||||
* boolean lockfl; check the file for locks?
|
||||
* char fname[]; file name to find
|
||||
* boolean lockfl; check the file for locks?
|
||||
*/
|
||||
int getfile( const char *fname, boolean lockfl)
|
||||
{
|
||||
struct buffer *bp;
|
||||
struct line *lp;
|
||||
int i;
|
||||
int s;
|
||||
bname_t bname ; /* buffer name to put file */
|
||||
int getfile( const char *fname, boolean lockfl) {
|
||||
struct buffer *bp;
|
||||
int s;
|
||||
bname_t bname ; /* buffer name to put file */
|
||||
|
||||
#if MSDOS
|
||||
mklower(fname); /* msdos isn't case sensitive */
|
||||
#endif
|
||||
for (bp = bheadp; bp != NULL; bp = bp->b_bufp) {
|
||||
if ((bp->b_flag & BFINVS) == 0
|
||||
&& strcmp(bp->b_fname, fname) == 0) {
|
||||
swbuffer(bp);
|
||||
lp = curwp->w_dotp;
|
||||
i = curwp->w_ntrows / 2;
|
||||
while (i-- && lback(lp) != curbp->b_linep)
|
||||
lp = lback(lp);
|
||||
curwp->w_linep = lp;
|
||||
curwp->w_flag |= WFMODE | WFHARD;
|
||||
cknewwindow();
|
||||
mloutstr( "(Old buffer)") ;
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
makename(bname, fname); /* New buffer name. */
|
||||
while ((bp = bfind(bname, FALSE, 0)) != NULL) {
|
||||
char *new_bname ;
|
||||
/* Is the file in current buffer? */
|
||||
if( strcmp( curbp->b_fname, fname) == 0) {
|
||||
mloutstr( "(Current buffer)") ;
|
||||
return TRUE ;
|
||||
}
|
||||
|
||||
/* old buffer name conflict code */
|
||||
s = newmlarg( &new_bname, "Buffer name: ", sizeof( bname_t)) ;
|
||||
if( s == ABORT) /* ^G to just quit */
|
||||
return s ;
|
||||
else if (s == FALSE) { /* CR to clobber it */
|
||||
makename( bname, fname) ;
|
||||
break ;
|
||||
} else { /* TRUE */
|
||||
strncpy( bname, new_bname, sizeof bname - 1) ;
|
||||
bname[ sizeof bname - 1] = '\0' ;
|
||||
free( new_bname) ;
|
||||
}
|
||||
}
|
||||
/* Is the file in any buffer? */
|
||||
for( bp = bheadp; bp != NULL; bp = bp->b_bufp) {
|
||||
if( (bp->b_flag & BFINVS) == 0
|
||||
&& strcmp( bp->b_fname, fname) == 0) {
|
||||
line_p lp ;
|
||||
int i ;
|
||||
|
||||
if (bp == NULL && (bp = bfind(bname, TRUE, 0)) == NULL) {
|
||||
mloutstr( "Cannot create buffer") ;
|
||||
return FALSE;
|
||||
}
|
||||
if (--curbp->b_nwnd == 0) { /* Undisplay. */
|
||||
curbp->b_dotp = curwp->w_dotp;
|
||||
curbp->b_doto = curwp->w_doto;
|
||||
curbp->b_markp = curwp->w_markp;
|
||||
curbp->b_marko = curwp->w_marko;
|
||||
}
|
||||
curbp = bp; /* Switch to it. */
|
||||
curwp->w_bufp = bp;
|
||||
curbp->b_nwnd++;
|
||||
s = readin(fname, lockfl); /* Read it in. */
|
||||
cknewwindow();
|
||||
return s;
|
||||
swbuffer( bp) ;
|
||||
|
||||
/* Center dotted line in window */
|
||||
i = curwp->w_ntrows / 2 ;
|
||||
for( lp = curwp->w_dotp ; lback( lp) != curbp->b_linep ; lp = lback( lp))
|
||||
if( i-- == 0)
|
||||
break ;
|
||||
|
||||
curwp->w_linep = lp ;
|
||||
|
||||
/* Refresh window */
|
||||
curwp->w_flag |= WFMODE | WFHARD ;
|
||||
cknewwindow() ;
|
||||
mloutstr( "(Old buffer)") ;
|
||||
return TRUE ;
|
||||
}
|
||||
}
|
||||
|
||||
makename(bname, fname); /* New buffer name. */
|
||||
while ((bp = bfind(bname, FALSE, 0)) != NULL) {
|
||||
char *new_bname ;
|
||||
|
||||
/* old buffer name conflict code */
|
||||
s = newmlarg( &new_bname, "Buffer name: ", sizeof( bname_t)) ;
|
||||
if( s == ABORT) /* ^G to just quit */
|
||||
return s ;
|
||||
else if (s == FALSE) { /* CR to clobber it */
|
||||
makename( bname, fname) ;
|
||||
break ;
|
||||
} else { /* TRUE */
|
||||
strncpy( bname, new_bname, sizeof bname - 1) ;
|
||||
bname[ sizeof bname - 1] = '\0' ;
|
||||
free( new_bname) ;
|
||||
}
|
||||
}
|
||||
|
||||
if (bp == NULL && (bp = bfind(bname, TRUE, 0)) == NULL) {
|
||||
mloutstr( "Cannot create buffer") ;
|
||||
return FALSE;
|
||||
}
|
||||
if (--curbp->b_nwnd == 0) { /* Undisplay. */
|
||||
curbp->b_dotp = curwp->w_dotp;
|
||||
curbp->b_doto = curwp->w_doto;
|
||||
curbp->b_markp = curwp->w_markp;
|
||||
curbp->b_marko = curwp->w_marko;
|
||||
}
|
||||
curbp = bp; /* Switch to it. */
|
||||
curwp->w_bufp = bp;
|
||||
curbp->b_nwnd++;
|
||||
s = readin(fname, lockfl); /* Read it in. */
|
||||
cknewwindow();
|
||||
return s;
|
||||
}
|
||||
|
||||
/*
|
||||
@ -244,61 +255,61 @@ int getfile( const char *fname, boolean lockfl)
|
||||
* The command bound to M-FNR is called after the buffer is set up
|
||||
* and before it is read.
|
||||
*
|
||||
* char fname[]; name of file to read
|
||||
* boolean lockfl; check for file locks?
|
||||
* char fname[]; name of file to read
|
||||
* boolean lockfl; check for file locks?
|
||||
*/
|
||||
int readin(const char *fname, boolean lockfl)
|
||||
{
|
||||
struct window *wp;
|
||||
struct buffer *bp;
|
||||
struct window *wp;
|
||||
struct buffer *bp;
|
||||
int status ;
|
||||
fio_code s ;
|
||||
|
||||
bp = curbp; /* Cheap. */
|
||||
bp = curbp; /* Cheap. */
|
||||
#if (FILOCK && BSD) || SVR4
|
||||
if( lockfl && lockchk( fname) == ABORT)
|
||||
if( lockfl && lockchk( fname) == ABORT)
|
||||
#if PKCODE
|
||||
{
|
||||
s = FIOFNF;
|
||||
strcpy(bp->b_fname, "");
|
||||
{
|
||||
s = FIOFNF;
|
||||
strcpy(bp->b_fname, "");
|
||||
mloutstr( "(File in use)") ;
|
||||
goto out;
|
||||
}
|
||||
goto out;
|
||||
}
|
||||
#else
|
||||
return ABORT;
|
||||
return ABORT;
|
||||
#endif
|
||||
#endif
|
||||
if( (status = bclear( bp)) != TRUE) /* Might be old. */
|
||||
return status ;
|
||||
if( (status = bclear( bp)) != TRUE) /* Might be old. */
|
||||
return status ;
|
||||
|
||||
bp->b_flag &= ~(BFINVS | BFCHG);
|
||||
strncpy( bp->b_fname, fname, sizeof( fname_t) - 1) ;
|
||||
bp->b_fname[ sizeof( fname_t) - 1] = '\0' ;
|
||||
bp->b_flag &= ~(BFINVS | BFCHG);
|
||||
strncpy( bp->b_fname, fname, sizeof( fname_t) - 1) ;
|
||||
bp->b_fname[ sizeof( fname_t) - 1] = '\0' ;
|
||||
|
||||
/* let a user macro get hold of things...if he wants */
|
||||
execute(META | SPEC | 'R', FALSE, 1);
|
||||
/* let a user macro get hold of things...if he wants */
|
||||
execute(META | SPEC | 'R', FALSE, 1);
|
||||
|
||||
s = ffropen( bp->b_fname) ; /* Always use the name associated to buffer */
|
||||
if( s == FIOFNF) /* File not found. */
|
||||
if( s == FIOFNF) /* File not found. */
|
||||
mloutstr( "(New file)") ;
|
||||
else if( s == FIOSUC) {
|
||||
char *errmsg ;
|
||||
eoltype found_eol ;
|
||||
int nline = 0 ;
|
||||
eoltype found_eol ;
|
||||
int nline = 0 ;
|
||||
|
||||
/* read the file in */
|
||||
mloutstr( "(Reading file)") ;
|
||||
while ((s = ffgetline()) == FIOSUC) {
|
||||
line_p lp ;
|
||||
/* read the file in */
|
||||
mloutstr( "(Reading file)") ;
|
||||
while ((s = ffgetline()) == FIOSUC) {
|
||||
line_p lp ;
|
||||
|
||||
if( nline >= 10000000 /* MAXNLINE Maximum # of lines from one file */
|
||||
|| (lp = lalloc( fpayload)) == NULL) {
|
||||
s = FIOMEM ; /* Keep message on the */
|
||||
break ; /* display. */
|
||||
}
|
||||
s = FIOMEM ; /* Keep message on the */
|
||||
break ; /* display. */
|
||||
}
|
||||
|
||||
memcpy( lp->l_text, fline, fpayload) ;
|
||||
lp->l_fp = curbp->b_linep ; /* insert before end of buffer */
|
||||
lp->l_fp = curbp->b_linep ; /* insert before end of buffer */
|
||||
lp->l_bp = lp->l_fp->l_bp ;
|
||||
lp->l_fp->l_bp = lp ;
|
||||
lp->l_bp->l_fp = lp ;
|
||||
@ -309,21 +320,21 @@ int readin(const char *fname, boolean lockfl)
|
||||
mloutstr( "File read error") ;
|
||||
|
||||
switch( ftype) {
|
||||
case FTYPE_DOS:
|
||||
found_eol = EOL_DOS ;
|
||||
curbp->b_mode |= MDDOS ;
|
||||
break ;
|
||||
case FTYPE_UNIX:
|
||||
found_eol = EOL_UNIX ;
|
||||
break ;
|
||||
case FTYPE_MAC:
|
||||
found_eol = EOL_MAC ;
|
||||
break ;
|
||||
case FTYPE_NONE:
|
||||
found_eol = EOL_NONE ;
|
||||
break ;
|
||||
default:
|
||||
found_eol = EOL_MIXED ;
|
||||
case FTYPE_DOS:
|
||||
found_eol = EOL_DOS ;
|
||||
curbp->b_mode |= MDDOS ;
|
||||
break ;
|
||||
case FTYPE_UNIX:
|
||||
found_eol = EOL_UNIX ;
|
||||
break ;
|
||||
case FTYPE_MAC:
|
||||
found_eol = EOL_MAC ;
|
||||
break ;
|
||||
case FTYPE_NONE:
|
||||
found_eol = EOL_NONE ;
|
||||
break ;
|
||||
default:
|
||||
found_eol = EOL_MIXED ;
|
||||
curbp->b_mode |= MDVIEW ; /* force view mode as we have lost
|
||||
** EOL information */
|
||||
}
|
||||
@ -331,14 +342,14 @@ int readin(const char *fname, boolean lockfl)
|
||||
if( fcode == FCODE_UTF_8)
|
||||
curbp->b_mode |= MDUTF8 ;
|
||||
|
||||
if( s == FIOERR) {
|
||||
if( s == FIOERR) {
|
||||
errmsg = "I/O ERROR, " ;
|
||||
curbp->b_flag |= BFTRUNC ;
|
||||
} else if( s == FIOMEM) {
|
||||
errmsg = "OUT OF MEMORY, " ;
|
||||
curbp->b_flag |= BFTRUNC ;
|
||||
} else
|
||||
errmsg = "" ;
|
||||
curbp->b_flag |= BFTRUNC ;
|
||||
} else if( s == FIOMEM) {
|
||||
errmsg = "OUT OF MEMORY, " ;
|
||||
curbp->b_flag |= BFTRUNC ;
|
||||
} else
|
||||
errmsg = "" ;
|
||||
|
||||
mloutfmt( "(%sRead %d line%s, code/eol: %s/%s)",
|
||||
errmsg,
|
||||
@ -346,20 +357,20 @@ int readin(const char *fname, boolean lockfl)
|
||||
&"s"[ nline == 1],
|
||||
codename[ fcode & (FCODE_MASK - 1)],
|
||||
eolname[ found_eol]) ;
|
||||
ffclose() ; /* Ignore errors. */
|
||||
ffclose() ; /* Ignore errors. */
|
||||
}
|
||||
|
||||
out:
|
||||
for (wp = wheadp; wp != NULL; wp = wp->w_wndp) {
|
||||
if (wp->w_bufp == curbp) {
|
||||
wp->w_linep = lforw(curbp->b_linep);
|
||||
wp->w_dotp = lforw(curbp->b_linep);
|
||||
wp->w_doto = 0;
|
||||
wp->w_markp = NULL;
|
||||
wp->w_marko = 0;
|
||||
wp->w_flag |= WFMODE | WFHARD;
|
||||
}
|
||||
}
|
||||
for (wp = wheadp; wp != NULL; wp = wp->w_wndp) {
|
||||
if (wp->w_bufp == curbp) {
|
||||
wp->w_linep = lforw(curbp->b_linep);
|
||||
wp->w_dotp = lforw(curbp->b_linep);
|
||||
wp->w_doto = 0;
|
||||
wp->w_markp = NULL;
|
||||
wp->w_marko = 0;
|
||||
wp->w_flag |= WFMODE | WFHARD;
|
||||
}
|
||||
}
|
||||
|
||||
return (s == FIOERR || s == FIOFNF) ? FALSE : TRUE ;
|
||||
}
|
||||
@ -373,59 +384,59 @@ out:
|
||||
*/
|
||||
void makename( bname_t bname, const char *fname)
|
||||
{
|
||||
const char *cp1;
|
||||
char *cp2;
|
||||
const char *cp1;
|
||||
char *cp2;
|
||||
|
||||
cp1 = &fname[0];
|
||||
while (*cp1 != 0)
|
||||
++cp1;
|
||||
cp1 = &fname[0];
|
||||
while (*cp1 != 0)
|
||||
++cp1;
|
||||
|
||||
#if VMS
|
||||
#if VMS
|
||||
#if PKCODE
|
||||
while (cp1 != &fname[0] && cp1[-1] != ':' && cp1[-1] != ']'
|
||||
&& cp1[-1] != '>')
|
||||
while (cp1 != &fname[0] && cp1[-1] != ':' && cp1[-1] != ']'
|
||||
&& cp1[-1] != '>')
|
||||
#else
|
||||
while (cp1 != &fname[0] && cp1[-1] != ':' && cp1[-1] != ']')
|
||||
while (cp1 != &fname[0] && cp1[-1] != ':' && cp1[-1] != ']')
|
||||
#endif
|
||||
--cp1;
|
||||
--cp1;
|
||||
#endif
|
||||
#if MSDOS
|
||||
while (cp1 != &fname[0] && cp1[-1] != ':' && cp1[-1] != '\\'
|
||||
&& cp1[-1] != '/')
|
||||
--cp1;
|
||||
#if MSDOS
|
||||
while (cp1 != &fname[0] && cp1[-1] != ':' && cp1[-1] != '\\'
|
||||
&& cp1[-1] != '/')
|
||||
--cp1;
|
||||
#endif
|
||||
#if V7 | USG | BSD
|
||||
while (cp1 != &fname[0] && cp1[-1] != '/')
|
||||
--cp1;
|
||||
#if V7 | USG | BSD
|
||||
while (cp1 != &fname[0] && cp1[-1] != '/')
|
||||
--cp1;
|
||||
#endif
|
||||
cp2 = &bname[0];
|
||||
while( cp2 != &bname[ sizeof( bname_t) - 1] && *cp1 != 0 && *cp1 != ';')
|
||||
*cp2++ = *cp1++;
|
||||
*cp2 = 0;
|
||||
cp2 = &bname[0];
|
||||
while( cp2 != &bname[ sizeof( bname_t) - 1] && *cp1 != 0 && *cp1 != ';')
|
||||
*cp2++ = *cp1++;
|
||||
*cp2 = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* make sure a buffer name is unique
|
||||
*
|
||||
* char *name; name to check on
|
||||
* char *name; name to check on
|
||||
*/
|
||||
void unqname(char *name)
|
||||
{
|
||||
char *sp;
|
||||
char *sp;
|
||||
|
||||
/* check to see if it is in the buffer list */
|
||||
while (bfind(name, 0, FALSE) != NULL) {
|
||||
/* check to see if it is in the buffer list */
|
||||
while (bfind(name, 0, FALSE) != NULL) {
|
||||
|
||||
/* go to the end of the name */
|
||||
sp = name;
|
||||
while (*sp)
|
||||
++sp;
|
||||
if (sp == name || (*(sp - 1) < '0' || *(sp - 1) > '8')) {
|
||||
*sp++ = '0';
|
||||
*sp = 0;
|
||||
} else
|
||||
*(--sp) += 1;
|
||||
}
|
||||
/* go to the end of the name */
|
||||
sp = name;
|
||||
while (*sp)
|
||||
++sp;
|
||||
if (sp == name || (*(sp - 1) < '0' || *(sp - 1) > '8')) {
|
||||
*sp++ = '0';
|
||||
*sp = 0;
|
||||
} else
|
||||
*(--sp) += 1;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
@ -438,37 +449,26 @@ void unqname(char *name)
|
||||
* with ITS EMACS. Bound to "C-X C-W".
|
||||
*/
|
||||
int filewrite( int f, int n) {
|
||||
int status ;
|
||||
char *fname ;
|
||||
int status ;
|
||||
char *fname ;
|
||||
|
||||
if( restflag) /* don't allow this command if restricted */
|
||||
return resterr() ;
|
||||
if( restflag) /* don't allow this command if restricted */
|
||||
return resterr() ;
|
||||
|
||||
status = newmlarg( &fname, "Write file: ", sizeof( fname_t)) ;
|
||||
if( status == TRUE) {
|
||||
status = newmlarg( &fname, "Write file: ", sizeof( fname_t)) ;
|
||||
if( status == TRUE) {
|
||||
if( strlen( fname) > sizeof( fname_t) - 1)
|
||||
status = FALSE ;
|
||||
else {
|
||||
status = writeout( fname) ;
|
||||
if( status == TRUE) {
|
||||
struct window *wp ;
|
||||
|
||||
strcpy( curbp->b_fname, fname) ;
|
||||
curbp->b_flag &= ~BFCHG ;
|
||||
wp = wheadp ; /* Update mode lines. */
|
||||
while( wp != NULL) {
|
||||
if( wp->w_bufp == curbp)
|
||||
wp->w_flag |= WFMODE ;
|
||||
|
||||
wp = wp->w_wndp ;
|
||||
}
|
||||
}
|
||||
status = writeout( fname) ;
|
||||
if( status == TRUE)
|
||||
strcpy( curbp->b_fname, fname) ;
|
||||
}
|
||||
|
||||
|
||||
free( fname) ;
|
||||
}
|
||||
|
||||
return status ;
|
||||
return status ;
|
||||
}
|
||||
|
||||
/*
|
||||
@ -479,38 +479,25 @@ int filewrite( int f, int n) {
|
||||
* name for the buffer. Bound to "C-X C-S". May
|
||||
* get called by "C-Z".
|
||||
*/
|
||||
int filesave(int f, int n)
|
||||
{
|
||||
struct window *wp;
|
||||
int s;
|
||||
int filesave( int f, int n) {
|
||||
if (curbp->b_mode & MDVIEW) /* don't allow this command if */
|
||||
return rdonly(); /* we are in read only mode */
|
||||
if ((curbp->b_flag & BFCHG) == 0) /* Return, no changes. */
|
||||
return TRUE;
|
||||
if (curbp->b_fname[0] == 0) { /* Must have a name. */
|
||||
mloutstr( "No file name") ;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (curbp->b_mode & MDVIEW) /* don't allow this command if */
|
||||
return rdonly(); /* we are in read only mode */
|
||||
if ((curbp->b_flag & BFCHG) == 0) /* Return, no changes. */
|
||||
return TRUE;
|
||||
if (curbp->b_fname[0] == 0) { /* Must have a name. */
|
||||
mloutstr( "No file name") ;
|
||||
return FALSE;
|
||||
}
|
||||
/* complain about truncated files */
|
||||
if ((curbp->b_flag & BFTRUNC) != 0) {
|
||||
if (mlyesno("Truncated file ... write it out") == FALSE) {
|
||||
mloutstr( "(Aborted)") ;
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
/* complain about truncated files */
|
||||
if ((curbp->b_flag & BFTRUNC) != 0) {
|
||||
if (mlyesno("Truncated file ... write it out") == FALSE) {
|
||||
mloutstr( "(Aborted)") ;
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
if ((s = writeout(curbp->b_fname)) == TRUE) {
|
||||
curbp->b_flag &= ~BFCHG;
|
||||
wp = wheadp; /* Update mode lines. */
|
||||
while (wp != NULL) {
|
||||
if (wp->w_bufp == curbp)
|
||||
wp->w_flag |= WFMODE;
|
||||
wp = wp->w_wndp;
|
||||
}
|
||||
}
|
||||
return s;
|
||||
return writeout( curbp->b_fname) ;
|
||||
}
|
||||
|
||||
/*
|
||||
@ -524,7 +511,7 @@ int filesave(int f, int n)
|
||||
int writeout( const char *fn) {
|
||||
fio_code s ;
|
||||
|
||||
s = ffwopen( fn) ; /* Open writes message. */
|
||||
s = ffwopen( fn) ; /* Open writes message. */
|
||||
if( s != FIOSUC)
|
||||
mloutstr( "Cannot open file for writing") ;
|
||||
else {
|
||||
@ -532,12 +519,12 @@ int writeout( const char *fn) {
|
||||
fio_code s2 ;
|
||||
int nline = 0 ;
|
||||
|
||||
mloutstr( "(Writing...)") ; /* tell us we are writing */
|
||||
mloutstr( "(Writing...)") ; /* tell us we are writing */
|
||||
for( lp = lforw( curbp->b_linep) ; lp != curbp->b_linep ; lp = lforw( lp)) {
|
||||
s = ffputline( lp->l_text, llength( lp), curbp->b_mode & MDDOS) ;
|
||||
if( s != FIOSUC)
|
||||
break ;
|
||||
|
||||
|
||||
nline += 1 ;
|
||||
}
|
||||
|
||||
@ -548,11 +535,13 @@ int writeout( const char *fn) {
|
||||
mloutstr( "Error closing file") ;
|
||||
else { /* Successfull write and close. */
|
||||
mloutfmt( "(Wrote %d line%s)", nline, &"s"[ nline == 1]) ;
|
||||
curbp->b_flag &= ~BFCHG ;
|
||||
upd_mode() ;
|
||||
return TRUE ;
|
||||
}
|
||||
}
|
||||
|
||||
return FALSE ;
|
||||
return FALSE ;
|
||||
}
|
||||
|
||||
/*
|
||||
@ -565,34 +554,26 @@ int writeout( const char *fn) {
|
||||
* prompt if you wish.
|
||||
*/
|
||||
int filename( int f, int n) {
|
||||
struct window *wp ;
|
||||
int status ;
|
||||
char *fname ;
|
||||
int status ;
|
||||
char *fname ;
|
||||
|
||||
if( restflag) /* don't allow this command if restricted */
|
||||
return resterr() ;
|
||||
if( restflag) /* don't allow this command if restricted */
|
||||
return resterr() ;
|
||||
|
||||
status = newmlarg( &fname, "Name: ", sizeof( fname_t)) ;
|
||||
if( status == ABORT)
|
||||
return status ;
|
||||
else if( status == FALSE)
|
||||
curbp->b_fname[ 0] = '\0' ;
|
||||
else { /* TRUE */
|
||||
strncpy( curbp->b_fname, fname, sizeof( fname_t) - 1) ;
|
||||
curbp->b_fname[ sizeof( fname_t) - 1] = '\0' ;
|
||||
free( fname) ;
|
||||
}
|
||||
status = newmlarg( &fname, "Name: ", sizeof( fname_t)) ;
|
||||
if( status == ABORT)
|
||||
return status ;
|
||||
else if( status == FALSE)
|
||||
curbp->b_fname[ 0] = '\0' ;
|
||||
else { /* TRUE */
|
||||
strncpy( curbp->b_fname, fname, sizeof( fname_t) - 1) ;
|
||||
curbp->b_fname[ sizeof( fname_t) - 1] = '\0' ;
|
||||
free( fname) ;
|
||||
}
|
||||
|
||||
wp = wheadp ; /* Update mode lines. */
|
||||
while( wp != NULL) {
|
||||
if( wp->w_bufp == curbp)
|
||||
wp->w_flag |= WFMODE ;
|
||||
|
||||
wp = wp->w_wndp ;
|
||||
}
|
||||
|
||||
curbp->b_mode &= ~MDVIEW ; /* no longer read only mode */
|
||||
return TRUE ;
|
||||
curbp->b_mode &= ~MDVIEW ; /* no longer read only mode */
|
||||
upd_mode() ;
|
||||
return TRUE ;
|
||||
}
|
||||
|
||||
/*
|
||||
@ -603,21 +584,21 @@ int filename( int f, int n) {
|
||||
static int ifile( const char *fname) {
|
||||
fio_code s ;
|
||||
|
||||
curbp->b_flag |= BFCHG ; /* we have changed */
|
||||
curbp->b_flag |= BFCHG ; /* we have changed */
|
||||
curbp->b_flag &= ~BFINVS ; /* and are not temporary */
|
||||
s = ffropen( fname) ;
|
||||
if( s == FIOFNF) { /* File not found. */
|
||||
mloutstr( "(No such file)") ;
|
||||
return FALSE ;
|
||||
}
|
||||
if( s == FIOFNF) { /* File not found. */
|
||||
mloutstr( "(No such file)") ;
|
||||
return FALSE ;
|
||||
}
|
||||
|
||||
if( s == FIOSUC) { /* Hard file open. */
|
||||
int nline = 0 ; /* number of line read */
|
||||
if( s == FIOSUC) { /* Hard file open. */
|
||||
int nline = 0 ; /* number of line read */
|
||||
char *errmsg ;
|
||||
|
||||
mloutstr( "(Inserting file)") ;
|
||||
|
||||
/* back up a line and save the mark here */
|
||||
/* back up a line and save the mark here */
|
||||
curwp->w_dotp = lback(curwp->w_dotp);
|
||||
curwp->w_doto = 0;
|
||||
curwp->w_markp = curwp->w_dotp;
|
||||
@ -627,8 +608,8 @@ static int ifile( const char *fname) {
|
||||
line_p lpp, lp, lpn ;
|
||||
|
||||
if( (lp = lalloc( fpayload)) == NULL) {
|
||||
s = FIOMEM ; /* Keep message on the */
|
||||
break ; /* display. */
|
||||
s = FIOMEM ; /* Keep message on the */
|
||||
break ; /* display. */
|
||||
}
|
||||
|
||||
memcpy( lp->l_text, fline, fpayload) ;
|
||||
@ -642,16 +623,16 @@ static int ifile( const char *fname) {
|
||||
/* and advance and write out the current line */
|
||||
curwp->w_dotp = lp ;
|
||||
nline += 1 ;
|
||||
}
|
||||
}
|
||||
|
||||
ffclose() ; /* Ignore errors. */
|
||||
curwp->w_markp = lforw(curwp->w_markp);
|
||||
ffclose() ; /* Ignore errors. */
|
||||
curwp->w_markp = lforw(curwp->w_markp);
|
||||
if( s == FIOERR) {
|
||||
errmsg = "I/O ERROR, " ;
|
||||
curbp->b_flag |= BFTRUNC ;
|
||||
errmsg = "I/O ERROR, " ;
|
||||
curbp->b_flag |= BFTRUNC ;
|
||||
} else if( s == FIOMEM) {
|
||||
errmsg = "OUT OF MEMORY, " ;
|
||||
curbp->b_flag |= BFTRUNC;
|
||||
curbp->b_flag |= BFTRUNC;
|
||||
} else
|
||||
errmsg = "" ;
|
||||
|
||||
@ -662,14 +643,14 @@ static int ifile( const char *fname) {
|
||||
}
|
||||
|
||||
/* advance to the next line and mark the window for changes */
|
||||
curwp->w_dotp = lforw(curwp->w_dotp);
|
||||
curwp->w_flag |= WFHARD | WFMODE;
|
||||
curwp->w_dotp = lforw(curwp->w_dotp);
|
||||
curwp->w_flag |= WFHARD | WFMODE;
|
||||
|
||||
/* copy window parameters back to the buffer structure */
|
||||
curbp->b_dotp = curwp->w_dotp;
|
||||
curbp->b_doto = curwp->w_doto;
|
||||
curbp->b_markp = curwp->w_markp;
|
||||
curbp->b_marko = curwp->w_marko;
|
||||
curbp->b_dotp = curwp->w_dotp;
|
||||
curbp->b_doto = curwp->w_doto;
|
||||
curbp->b_markp = curwp->w_markp;
|
||||
curbp->b_marko = curwp->w_marko;
|
||||
|
||||
return (s == FIOERR) ? FALSE : TRUE ;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user