1
0
mirror of https://github.com/rfivet/uemacs.git synced 2024-06-15 23:35:35 +00:00

File commands based on newmlarg (replacement of mlreply).

This commit is contained in:
Renaud 2015-10-05 11:34:33 +08:00
parent b86ceeaf5e
commit b59a47bb3a

163
file.c
View File

@ -12,6 +12,7 @@
*/ */
#include <stdio.h> #include <stdio.h>
#include <stdlib.h>
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
@ -73,16 +74,20 @@ boolean resterr( void) {
* "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 s; char *fname ;
fname_t fname ;
if( restflag) /* don't allow this command if restricted */ if( restflag) /* don't allow this command if restricted */
return resterr() ; return resterr() ;
if ((s = mlreply("Read file: ", fname, sizeof fname)) != TRUE)
return s; status = newmlarg( &fname, "Read file: ", sizeof( fname_t)) ;
return readin(fname, TRUE); if( status == TRUE) {
status = readin( fname, TRUE) ;
free( fname) ;
}
return status ;
} }
/* /*
@ -92,19 +97,25 @@ int fileread(int f, int n)
* "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 s; char *fname ;
fname_t 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 */
if ((s = mlreply("Insert file: ", fname, sizeof fname)) != TRUE)
return s; status = newmlarg( &fname, "Insert file: ", sizeof( fname_t)) ;
if ((s = ifile(fname)) != TRUE) if( status == TRUE) {
return s; status = ifile( fname) ;
free( fname) ;
}
if( status != TRUE)
return status ;
return reposition( TRUE, -1) ; return reposition( TRUE, -1) ;
} }
@ -117,30 +128,38 @@ int insfile(int f, int n)
* text, and switch to the new buffer. * text, and switch to the new buffer.
* 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 */
fname_t fname ; /* file user wishes to find */ int status ; /* status return */
int s; /* status return */
if( restflag) /* don't allow this command if restricted */ if( restflag) /* don't allow this command if restricted */
return resterr() ; return resterr() ;
if ((s = mlreply("Find file: ", fname, sizeof fname)) != TRUE)
return s; status = newmlarg( &fname, "Find file: ", sizeof( fname_t)) ;
return getfile(fname, TRUE); if( status == TRUE) {
status = getfile( fname, TRUE) ;
free( fname) ;
} }
int viewfile(int f, int n) return status ;
{ /* visit a file in VIEW mode */ }
fname_t fname ; /* file user wishes to find */
int s; /* status return */ int viewfile( int f, int n) { /* visit a file in VIEW mode */
struct window *wp; /* scan for windows that need updating */ char *fname ; /* file user wishes to find */
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() ;
if ((s = mlreply("View file: ", fname, sizeof fname)) != TRUE)
return s; status = newmlarg( &fname, "View file: ", sizeof( fname_t)) ;
s = getfile(fname, FALSE); if( status == TRUE) {
if (s) { /* if we succeed, put it in view mode */ status = getfile(fname, FALSE) ;
free( fname) ;
}
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 ; curwp->w_bufp->b_mode |= MDVIEW ;
/* scan through and update mode lines of all windows */ /* scan through and update mode lines of all windows */
@ -150,7 +169,8 @@ int viewfile(int f, int n)
wp = wp->w_wndp ; wp = wp->w_wndp ;
} }
} }
return s;
return status ;
} }
#if CRYPT #if CRYPT
@ -165,24 +185,25 @@ void cryptbufferkey( struct buffer *bp) {
* int f; default flag * int f; default flag
* int n; numeric argument * int n; numeric argument
*/ */
int set_encryption_key(int f, int n) int set_encryption_key( int f, int n) {
{
int status ; /* return status */ int status ; /* return status */
int odisinp; /* original vlaue of disinp */ int odisinp ; /* original value of disinp */
ekey_t key ; /* new encryption string */ char *key ; /* new encryption string */
/* turn command input echo off */ /* turn command input echo off */
odisinp = disinp ; odisinp = disinp ;
disinp = FALSE ; disinp = FALSE ;
/* get the string to use as an encrytion string */ /* get the string to use as an encrytion string */
status = mlreply("Encryption String: ", key, sizeof key - 1); status = newmlarg( &key, "Encryption String: ", sizeof( ekey_t)) ;
disinp = odisinp ; disinp = odisinp ;
if( status != TRUE) if( status != TRUE)
return status ; return status ;
/* save it off and encrypt it*/ /* save it off and encrypt it*/
strcpy(curbp->b_key, key); strncpy( curbp->b_key, key, sizeof( ekey_t) - 1) ;
curbp->b_key[ sizeof( ekey_t) - 1] = '\0' ;
free( key) ;
cryptbufferkey( curbp) ; cryptbufferkey( curbp) ;
mloutstr( "") ; /* clear the message line */ mloutstr( "") ; /* clear the message line */
@ -253,15 +274,22 @@ int getfile( const char *fname, boolean lockfl)
} }
makename(bname, fname); /* New buffer name. */ makename(bname, fname); /* New buffer name. */
while ((bp = bfind(bname, FALSE, 0)) != NULL) { while ((bp = bfind(bname, FALSE, 0)) != NULL) {
char *new_bname ;
/* old buffer name conflict code */ /* old buffer name conflict code */
s = mlreply("Buffer name: ", bname, sizeof bname); s = newmlarg( &new_bname, "Buffer name: ", sizeof( bname_t)) ;
if( s == ABORT) /* ^G to just quit */ if( s == ABORT) /* ^G to just quit */
return s ; return s ;
if (s == FALSE) { /* CR to clobber it */ else if (s == FALSE) { /* CR to clobber it */
makename( bname, fname) ; makename( bname, fname) ;
break ; 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) { if (bp == NULL && (bp = bfind(bname, TRUE, 0)) == NULL) {
mloutstr( "Cannot create buffer") ; mloutstr( "Cannot create buffer") ;
return FALSE; return FALSE;
@ -495,27 +523,35 @@ void unqname(char *name)
* is more compatable with Gosling EMACS than * is more compatable with Gosling EMACS than
* 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 ;
struct window *wp; char *fname ;
int s;
fname_t fname ;
if( restflag) /* don't allow this command if restricted */ if( restflag) /* don't allow this command if restricted */
return resterr() ; return resterr() ;
if ((s = mlreply("Write file: ", fname, sizeof fname)) != TRUE)
return s; status = newmlarg( &fname, "Write file: ", sizeof( fname_t)) ;
if ((s = writeout(fname)) == TRUE) { if( status == TRUE) {
strcpy(curbp->b_fname, fname); status = writeout( fname) ;
if( status == TRUE) {
struct window *wp ;
strncpy( curbp->b_fname, fname, sizeof( fname_t) - 1) ;
curbp->b_fname[ sizeof( fname_t) - 1] = '\0' ;
curbp->b_flag &= ~BFCHG ; curbp->b_flag &= ~BFCHG ;
wp = wheadp ; /* Update mode lines. */ wp = wheadp ; /* Update mode lines. */
while( wp != NULL) { while( wp != NULL) {
if( wp->w_bufp == curbp) if( wp->w_bufp == curbp)
wp->w_flag |= WFMODE ; wp->w_flag |= WFMODE ;
wp = wp->w_wndp ; wp = wp->w_wndp ;
} }
} }
return s;
free( fname) ;
}
return status ;
} }
/* /*
@ -622,26 +658,33 @@ int writeout( const char *fn)
* as needing an update. You can type a blank line at the * as needing an update. You can type a blank line at the
* prompt if you wish. * prompt if you wish.
*/ */
int filename(int f, int n) int filename( int f, int n) {
{
struct window *wp ; struct window *wp ;
int s; int status ;
fname_t 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 ((s = mlreply("Name: ", fname, sizeof fname)) == ABORT)
return s; status = newmlarg( &fname, "Name: ", sizeof( fname_t)) ;
if (s == FALSE) if( status == ABORT)
strcpy(curbp->b_fname, ""); return status ;
else else if( status == FALSE)
strcpy(curbp->b_fname, fname); 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. */ wp = wheadp ; /* Update mode lines. */
while( wp != NULL) { while( wp != NULL) {
if( wp->w_bufp == curbp) if( wp->w_bufp == curbp)
wp->w_flag |= WFMODE ; wp->w_flag |= WFMODE ;
wp = wp->w_wndp ; wp = wp->w_wndp ;
} }
curbp->b_mode &= ~MDVIEW ; /* no longer read only mode */ curbp->b_mode &= ~MDVIEW ; /* no longer read only mode */
return TRUE ; return TRUE ;
} }