Introduce spat_t as search pattern type and reduce need for NPAT as pattern length constant.

This commit is contained in:
Renaud 2014-06-02 15:16:18 +08:00
parent fa6edaa282
commit 3197080cb1
8 changed files with 30 additions and 27 deletions

View File

@ -8,7 +8,6 @@
#define ENVFUNC 1
#define NSTRING 128 /* # of bytes, string buffers */
#define NPAT 128 /* # of bytes, pattern */
#define CONTROL 0x10000000 /* Control flag, or'ed in */
#define META 0x20000000 /* Meta flag, or'ed in */

4
exec.c
View File

@ -72,7 +72,7 @@ static const char *dname[] = {
"force"
};
static char golabel[ NPAT] = "" ; /* current line to go to */
static char golabel[ NSTRING] = "" ; /* current line to go to */
static int execlevel = 0 ; /* execution IF level */
static struct buffer *bstore = NULL ; /* buffer to store macro text to */
static int mstore = FALSE ; /* storing text to macro flag */
@ -798,7 +798,7 @@ static int dobuf(struct buffer *bp)
/* grab label to jump to */
eline =
token(eline, golabel, NPAT);
token( eline, golabel, sizeof golabel) ;
linlen = strlen(golabel);
glp = hlp->l_fp;
while (glp != hlp) {

View File

@ -61,7 +61,7 @@ static const int quotec = 0x11 ; /* quote char during mlreply() */
int mlyesno( const char *prompt)
{
char c; /* input character */
char buf[NPAT]; /* prompt to user */
char buf[ NSTRING] ; /* prompt to user */
for (;;) {
/* build and prompt the user */
@ -69,7 +69,7 @@ int mlyesno( const char *prompt)
strcat(buf, " (y/n)? ");
mlwrite(buf);
/* get the responce */
/* get the response */
c = tgetc();
if (c == ectoc(abortc)) /* Bail out! */

View File

@ -188,7 +188,7 @@ static int isearch(int f, int n)
int cpos; /* character number in search string */
int c; /* current input character */
int expc; /* function expanded input char */
char pat_save[NPAT]; /* Saved copy of the old pattern str */
spat_t pat_save ; /* Saved copy of the old pattern str */
struct line *curline; /* Current line on entry */
int curoff; /* Current offset on entry */
int init_direction; /* The initial search direction */
@ -198,7 +198,7 @@ static int isearch(int f, int n)
cmd_reexecute = -1; /* We're not re-executing (yet?) */
cmd_offset = 0; /* Start at the beginning of the buff */
cmd_buff[0] = '\0'; /* Init the command buffer */
strncpy(pat_save, pat, NPAT); /* Save the old pattern string */
strncpy( pat_save, pat, sizeof pat_save) ; /* Save the old pattern string */
curline = curwp->w_dotp; /* Save the current line pointer */
curoff = curwp->w_doto; /* Save the current offset */
init_direction = n; /* Save the initial search direction */
@ -276,7 +276,7 @@ static int isearch(int f, int n)
curwp->w_dotp = curline; /* Reset the line pointer */
curwp->w_doto = curoff; /* and the offset */
n = init_direction; /* Reset the search direction */
strncpy(pat, pat_save, NPAT); /* Restore the old search str */
strncpy( pat, pat_save, sizeof pat) ; /* Restore the old search str */
cmd_reexecute = 0; /* Start the whole mess over */
goto start_over; /* Let it take care of itself */
@ -292,7 +292,8 @@ static int isearch(int f, int n)
/* I guess we got something to search for, so search for it */
pat[cpos++] = c; /* put the char in the buffer */
if (cpos >= NPAT) { /* too many chars in string? *//* Yup. Complain about it */
if (cpos >= sizeof pat) { /* too many chars in string? */
/* Yup. Complain about it */
mlwrite("? Search string too long");
return TRUE; /* Return an error */
}

4
main.c
View File

@ -245,8 +245,8 @@ int main(int argc, char **argv)
case 's': /* -s for initial search string */
case 'S':
searchflag = TRUE;
strncpy( pat, &argv[ carg][ 2], NPAT - 1) ;
pat[ NPAT -1] = 0 ;
strncpy( pat, &argv[ carg][ 2], sizeof pat - 1) ;
pat[ sizeof pat -1] = 0 ;
break;
case 'v': /* -v for View File */
case 'V':

View File

@ -937,7 +937,7 @@ int adjustmode(int kind, int global)
int i; /* loop index */
int status; /* error return on input */
char prompt[50]; /* string to prompt user with */
char cbuf[NPAT]; /* buffer to recieve mode name into */
char cbuf[ NSTRING] ; /* buffer to recieve mode name into */
/* build the proper prompt string */
if (global)
@ -952,7 +952,7 @@ int adjustmode(int kind, int global)
/* prompt the user and get an answer */
status = mlreply(prompt, cbuf, NPAT - 1);
status = mlreply( prompt, cbuf, sizeof cbuf - 1) ;
if (status != TRUE)
return status;
@ -1033,11 +1033,11 @@ int writemsg(int f, int n)
char *sp; /* pointer into buf to expand %s */
char *np; /* ptr into nbuf */
int status;
char buf[NPAT]; /* buffer to recieve message into */
char nbuf[NPAT * 2]; /* buffer to expand string into */
char buf[ NSTRING] ; /* buffer to recieve message into */
char nbuf[ NSTRING * 2] ; /* buffer to expand string into */
if ((status =
mlreply("Message to write: ", buf, NPAT - 1)) != TRUE)
mlreply("Message to write: ", buf, sizeof buf - 1)) != TRUE)
return status;
/* expand all '%' to "%%" so mlwrite won't expect arguments */
@ -1231,11 +1231,11 @@ int fmatch(int ch)
int istring(int f, int n)
{
int status; /* status return code */
char tstring[NPAT + 1]; /* string to add */
char tstring[ NSTRING + 1] ; /* string to add */
/* ask for string to insert */
status =
mlreplyt("String to insert<META>: ", tstring, NPAT, metac);
mlreplyt("String to insert<META>: ", tstring, NSTRING, metac) ;
if (status != TRUE)
return status;
@ -1259,11 +1259,11 @@ int istring(int f, int n)
int ovstring(int f, int n)
{
int status; /* status return code */
char tstring[NPAT + 1]; /* string to add */
char tstring[ NSTRING + 1] ; /* string to add */
/* ask for string to insert */
status =
mlreplyt("String to overwrite<META>: ", tstring, NPAT, metac);
mlreplyt( "String to overwrite<META>: ", tstring, NSTRING, metac) ;
if (status != TRUE)
return status;

View File

@ -87,9 +87,9 @@ char *patmatch = NULL ;
static struct line *matchline = NULL;
static int matchoff = 0;
char pat[ NPAT] ; /* Search pattern */
char tap[ NPAT] ; /* Reversed pattern array. */
char rpat[ NPAT] ; /* replacement pattern */
spat_t pat ; /* Search pattern */
spat_t tap ; /* Reversed pattern array. */
spat_t rpat ; /* replacement pattern */
#if defined(MAGIC)
@ -815,7 +815,7 @@ static int replaces(int kind, int f, int n)
int nlflag; /* last char of search string a <NL>? */
int nlrepl; /* was a replace done on the last line? */
char c; /* input char for query */
char tpat[NPAT]; /* temporary to hold search pattern */
spat_t tpat ; /* temporary to hold search pattern */
struct line *origline; /* original "." position */
int origoff; /* and offset (for . query option) */
struct line *lastline; /* position of last replace and */

View File

@ -7,12 +7,15 @@
#define BELL 0x07 /* a bell character */
typedef char spat_t[ 128] ; /* search pattern type */
#define NPAT sizeof( spat_t) /* # of bytes, pattern */
extern unsigned int matchlen ;
extern char *patmatch ;
extern char pat[] ; /* Search pattern */
extern char tap[] ; /* Reversed pattern array. */
extern char rpat[] ; /* replacement pattern */
extern spat_t pat ; /* Search pattern */
extern spat_t tap ; /* Reversed pattern array. */
extern spat_t rpat ; /* replacement pattern */
/*
* PTBEG, PTEND, FORWARD, and REVERSE are all toggle-able values for