Introduce fname_t type and remove need of NFILEN filename length constant.

This commit is contained in:
Renaud 2014-05-30 15:27:56 +08:00
parent 5a0b64f952
commit 494210424c
5 changed files with 18 additions and 19 deletions

View File

@ -4,10 +4,11 @@
#include "crypt.h"
#include "line.h"
#define NFILEN 80 /* # of bytes, file name */
#define NBUFN 16 /* # of bytes, buffer name */
#define NPAT 128 /* # of bytes, pattern */
typedef char fname_t[ 80] ;
/*
* Text is kept in buffers. A buffer header, described below, exists for every
* buffer in the system. The buffers are kept in a big list, so that commands
@ -30,7 +31,7 @@ struct buffer {
char b_active; /* window activated flag */
char b_nwnd; /* Count of windows on buffer */
char b_flag; /* Flags */
char b_fname[NFILEN]; /* File name */
fname_t b_fname ; /* File name */
char b_bname[NBUFN]; /* Buffer name */
#if CRYPT
char b_key[NPAT]; /* current encrypted key */

24
file.c
View File

@ -60,11 +60,11 @@ boolean restflag = FALSE ; /* restricted use? */
int fileread(int f, int n)
{
int s;
char fname[NFILEN];
fname_t fname ;
if (restflag) /* don't allow this command if restricted */
return resterr();
if ((s = mlreply("Read file: ", fname, NFILEN)) != TRUE)
if ((s = mlreply("Read file: ", fname, sizeof fname)) != TRUE)
return s;
return readin(fname, TRUE);
}
@ -79,13 +79,13 @@ int fileread(int f, int n)
int insfile(int f, int n)
{
int s;
char fname[NFILEN];
fname_t fname ;
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 ((s = mlreply("Insert file: ", fname, NFILEN)) != TRUE)
if ((s = mlreply("Insert file: ", fname, sizeof fname)) != TRUE)
return s;
if ((s = ifile(fname)) != TRUE)
return s;
@ -103,25 +103,25 @@ int insfile(int f, int n)
*/
int filefind(int f, int n)
{
char fname[NFILEN]; /* file user wishes to find */
fname_t fname ; /* file user wishes to find */
int s; /* status return */
if (restflag) /* don't allow this command if restricted */
return resterr();
if ((s = mlreply("Find file: ", fname, NFILEN)) != TRUE)
if ((s = mlreply("Find file: ", fname, sizeof fname)) != TRUE)
return s;
return getfile(fname, TRUE);
}
int viewfile(int f, int n)
{ /* visit a file in VIEW mode */
char fname[NFILEN]; /* file user wishes to find */
fname_t fname ; /* file user wishes to find */
int s; /* status return */
struct window *wp; /* scan for windows that need updating */
if (restflag) /* don't allow this command if restricted */
return resterr();
if ((s = mlreply("View file: ", fname, NFILEN)) != TRUE)
if ((s = mlreply("View file: ", fname, sizeof fname)) != TRUE)
return s;
s = getfile(fname, FALSE);
if (s) { /* if we succeed, put it in view mode */
@ -481,11 +481,11 @@ int filewrite(int f, int n)
{
struct window *wp;
int s;
char fname[NFILEN];
fname_t fname ;
if (restflag) /* don't allow this command if restricted */
return resterr();
if ((s = mlreply("Write file: ", fname, NFILEN)) != TRUE)
if ((s = mlreply("Write file: ", fname, sizeof fname)) != TRUE)
return s;
if ((s = writeout(fname)) == TRUE) {
strcpy(curbp->b_fname, fname);
@ -608,11 +608,11 @@ int filename(int f, int n)
{
struct window *wp;
int s;
char fname[NFILEN];
fname_t fname ;
if (restflag) /* don't allow this command if restricted */
return resterr();
if ((s = mlreply("Name: ", fname, NFILEN)) == ABORT)
if ((s = mlreply("Name: ", fname, sizeof fname)) == ABORT)
return s;
if (s == FALSE)
strcpy(curbp->b_fname, "");

2
file.h
View File

@ -11,8 +11,6 @@ void cryptbufferkey( struct buffer *bp) ;
int set_encryption_key( int f, int n) ;
#endif
#define NFILEN 80 /* # of bytes, file name */
extern boolean restflag ; /* restricted use? */
int fileread( int f, int n) ;

4
main.c
View File

@ -274,8 +274,8 @@ int main(int argc, char **argv)
/* set this to inactive */
bp = bfind(bname, TRUE, 0);
strncpy( bp->b_fname, argv[ carg], NFILEN - 1) ; /* max filename length limited to NFILEN - 1 (79) */
bp->b_fname[ NFILEN - 1] = 0 ;
strncpy( bp->b_fname, argv[ carg], sizeof bp->b_fname - 1) ; /* max filename length limited to NFILEN - 1 (79) */
bp->b_fname[ sizeof bp->b_fname - 1] = 0 ;
bp->b_active = FALSE;
if (firstfile) {
firstbp = bp;

View File

@ -401,7 +401,7 @@ int filter_buffer(int f, int n)
int s; /* return status from CLI */
struct buffer *bp; /* pointer to buffer to zot */
char line[NLINE]; /* command line send to shell */
char tmpnam[NFILEN]; /* place to store real file name */
fname_t tmpnam ; /* place to store real file name */
static char bname1[] = "fltinp";
static char filnam1[] = "fltinp";