From fc79c8e013f93dcaefa8953e5aa35b86aabf6d96 Mon Sep 17 00:00:00 2001 From: Renaud Fivet Date: Fri, 30 May 2014 18:08:58 +0800 Subject: [PATCH] Introduce bname_t type and reduce need of NBUFN buffer name length constant. --- buffer.c | 12 ++++++------ buffer.h | 7 ++++--- exec.c | 12 ++++++------ file.c | 4 ++-- main.c | 2 +- 5 files changed, 19 insertions(+), 18 deletions(-) diff --git a/buffer.c b/buffer.c index df4d39f..d0e2c57 100644 --- a/buffer.c +++ b/buffer.c @@ -59,9 +59,9 @@ int usebuffer(int f, int n) { struct buffer *bp; int s; - char bufn[NBUFN]; + bname_t bufn ; - if ((s = mlreply("Use buffer: ", bufn, NBUFN)) != TRUE) + if ((s = mlreply("Use buffer: ", bufn, sizeof bufn)) != TRUE) return s; if ((bp = bfind(bufn, TRUE, 0)) == NULL) return FALSE; @@ -168,9 +168,9 @@ int killbuffer(int f, int n) { struct buffer *bp; int s; - char bufn[NBUFN]; + bname_t bufn ; - if ((s = mlreply("Kill buffer: ", bufn, NBUFN)) != TRUE) + if ((s = mlreply("Kill buffer: ", bufn, sizeof bufn)) != TRUE) return s; if ((bp = bfind(bufn, FALSE, 0)) == NULL) /* Easy if unknown. */ return TRUE; @@ -218,10 +218,10 @@ int zotbuf(struct buffer *bp) int namebuffer(int f, int n) { struct buffer *bp; /* pointer to scan through all buffers */ - char bufn[NBUFN]; /* buffer to hold buffer name */ + bname_t bufn ; /* buffer to hold buffer name */ /* prompt for and get the new buffer name */ - ask:if (mlreply("Change buffer name to: ", bufn, NBUFN) != + ask:if (mlreply("Change buffer name to: ", bufn, sizeof bufn) != TRUE) return FALSE; diff --git a/buffer.h b/buffer.h index 3109de8..84de9d1 100644 --- a/buffer.h +++ b/buffer.h @@ -4,10 +4,11 @@ #include "crypt.h" #include "line.h" -#define NBUFN 16 /* # of bytes, buffer name */ #define NPAT 128 /* # of bytes, pattern */ -typedef char fname_t[ 80] ; +typedef char fname_t[ 80] ; /* file name */ +typedef char bname_t[ 16] ; /* buffer name */ +#define NBUFN sizeof( bname_t) /* * Text is kept in buffers. A buffer header, described below, exists for every @@ -32,7 +33,7 @@ struct buffer { char b_nwnd; /* Count of windows on buffer */ char b_flag; /* Flags */ fname_t b_fname ; /* File name */ - char b_bname[NBUFN]; /* Buffer name */ + bname_t b_bname ; /* Buffer name */ #if CRYPT char b_key[NPAT]; /* current encrypted key */ #endif diff --git a/exec.c b/exec.c index 8406617..a6130e2 100644 --- a/exec.c +++ b/exec.c @@ -319,7 +319,7 @@ int nextarg(const char *prompt, char *buffer, int size, int terminator) int storemac(int f, int n) { struct buffer *bp; /* pointer to macro buffer */ - char bname[NBUFN]; /* name of buffer to use */ + bname_t bname ; /* name of buffer to use */ /* must have a numeric argument to this function */ if (f == FALSE) { @@ -366,7 +366,7 @@ int storeproc(int f, int n) { struct buffer *bp; /* pointer to macro buffer */ int status; /* return status */ - char bname[NBUFN]; /* name of buffer to use */ + bname_t bname ; /* name of buffer to use */ /* a numeric argument means its a numbered macro */ if (f == TRUE) @@ -374,7 +374,7 @@ int storeproc(int f, int n) /* get the name of the procedure */ if ((status = - mlreply("Procedure name: ", &bname[1], NBUFN - 2)) != TRUE) + mlreply("Procedure name: ", &bname[1], sizeof bname - 2)) != TRUE) return status; /* construct the macro buffer name */ @@ -441,10 +441,10 @@ int execbuf(int f, int n) { struct buffer *bp; /* ptr to buffer to execute */ int status; /* status return */ - char bufn[NSTRING]; /* name of buffer to execute */ + bname_t bufn ; /* name of buffer to execute */ /* find out what buffer the user wants to execute */ - if ((status = mlreply("Execute buffer: ", bufn, NBUFN)) != TRUE) + if ((status = mlreply("Execute buffer: ", bufn, sizeof bufn)) != TRUE) return status; /* find the pointer to that buffer */ @@ -952,7 +952,7 @@ int dofile(char *fname) struct buffer *bp; /* buffer to place file to exeute */ struct buffer *cb; /* temp to hold current buf while we read */ int status; /* results of various calls */ - char bname[NBUFN]; /* name of buffer */ + bname_t bname ; /* name of buffer */ makename(bname, fname); /* derive the name of the buffer */ unqname(bname); /* make sure we don't stomp things */ diff --git a/file.c b/file.c index 1caa65c..21fc668 100644 --- a/file.c +++ b/file.c @@ -215,7 +215,7 @@ int getfile( const char *fname, boolean lockfl) struct line *lp; int i; int s; - char bname[NBUFN]; /* buffer name to put file */ + bname_t bname ; /* buffer name to put file */ #if MSDOS mklower(fname); /* msdos isn't case sensitive */ @@ -238,7 +238,7 @@ int getfile( const char *fname, boolean lockfl) makename(bname, fname); /* New buffer name. */ while ((bp = bfind(bname, FALSE, 0)) != NULL) { /* old buffer name conflict code */ - s = mlreply("Buffer name: ", bname, NBUFN); + s = mlreply("Buffer name: ", bname, sizeof bname); if (s == ABORT) /* ^G to just quit */ return s; if (s == FALSE) { /* CR to clobber it */ diff --git a/main.c b/main.c index 8c864c3..78b91b5 100644 --- a/main.c +++ b/main.c @@ -156,7 +156,7 @@ int main(int argc, char **argv) int searchflag; /* Do we need to search at start? */ int saveflag; /* temp store for lastflag */ int errflag; /* C error processing? */ - char bname[NBUFN]; /* buffer name of file to read */ + bname_t bname ; /* buffer name of file to read */ #if CRYPT int cryptflag; /* encrypting on the way in? */ char ekey[NPAT]; /* startup encryption key */