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