1
0
mirror of https://github.com/rfivet/uemacs.git synced 2024-12-18 15:26:23 -05:00

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 ENVFUNC 1
#define NSTRING 128 /* # of bytes, string buffers */ #define NSTRING 128 /* # of bytes, string buffers */
#define NPAT 128 /* # of bytes, pattern */
#define CONTROL 0x10000000 /* Control flag, or'ed in */ #define CONTROL 0x10000000 /* Control flag, or'ed in */
#define META 0x20000000 /* Meta 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" "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 int execlevel = 0 ; /* execution IF level */
static struct buffer *bstore = NULL ; /* buffer to store macro text to */ static struct buffer *bstore = NULL ; /* buffer to store macro text to */
static int mstore = FALSE ; /* storing text to macro flag */ static int mstore = FALSE ; /* storing text to macro flag */
@ -798,7 +798,7 @@ static int dobuf(struct buffer *bp)
/* grab label to jump to */ /* grab label to jump to */
eline = eline =
token(eline, golabel, NPAT); token( eline, golabel, sizeof golabel) ;
linlen = strlen(golabel); linlen = strlen(golabel);
glp = hlp->l_fp; glp = hlp->l_fp;
while (glp != hlp) { while (glp != hlp) {

View File

@ -61,7 +61,7 @@ static const int quotec = 0x11 ; /* quote char during mlreply() */
int mlyesno( const char *prompt) int mlyesno( const char *prompt)
{ {
char c; /* input character */ char c; /* input character */
char buf[NPAT]; /* prompt to user */ char buf[ NSTRING] ; /* prompt to user */
for (;;) { for (;;) {
/* build and prompt the user */ /* build and prompt the user */
@ -69,7 +69,7 @@ int mlyesno( const char *prompt)
strcat(buf, " (y/n)? "); strcat(buf, " (y/n)? ");
mlwrite(buf); mlwrite(buf);
/* get the responce */ /* get the response */
c = tgetc(); c = tgetc();
if (c == ectoc(abortc)) /* Bail out! */ 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 cpos; /* character number in search string */
int c; /* current input character */ int c; /* current input character */
int expc; /* function expanded input char */ 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 */ struct line *curline; /* Current line on entry */
int curoff; /* Current offset on entry */ int curoff; /* Current offset on entry */
int init_direction; /* The initial search direction */ 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_reexecute = -1; /* We're not re-executing (yet?) */
cmd_offset = 0; /* Start at the beginning of the buff */ cmd_offset = 0; /* Start at the beginning of the buff */
cmd_buff[0] = '\0'; /* Init the command buffer */ 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 */ curline = curwp->w_dotp; /* Save the current line pointer */
curoff = curwp->w_doto; /* Save the current offset */ curoff = curwp->w_doto; /* Save the current offset */
init_direction = n; /* Save the initial search direction */ 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_dotp = curline; /* Reset the line pointer */
curwp->w_doto = curoff; /* and the offset */ curwp->w_doto = curoff; /* and the offset */
n = init_direction; /* Reset the search direction */ 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 */ cmd_reexecute = 0; /* Start the whole mess over */
goto start_over; /* Let it take care of itself */ 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 */ /* I guess we got something to search for, so search for it */
pat[cpos++] = c; /* put the char in the buffer */ 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"); mlwrite("? Search string too long");
return TRUE; /* Return an error */ 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': /* -s for initial search string */
case 'S': case 'S':
searchflag = TRUE; searchflag = TRUE;
strncpy( pat, &argv[ carg][ 2], NPAT - 1) ; strncpy( pat, &argv[ carg][ 2], sizeof pat - 1) ;
pat[ NPAT -1] = 0 ; pat[ sizeof pat -1] = 0 ;
break; break;
case 'v': /* -v for View File */ case 'v': /* -v for View File */
case 'V': case 'V':

View File

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

View File

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

View File

@ -7,12 +7,15 @@
#define BELL 0x07 /* a bell character */ #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 unsigned int matchlen ;
extern char *patmatch ; extern char *patmatch ;
extern char pat[] ; /* Search pattern */ extern spat_t pat ; /* Search pattern */
extern char tap[] ; /* Reversed pattern array. */ extern spat_t tap ; /* Reversed pattern array. */
extern char rpat[] ; /* replacement pattern */ extern spat_t rpat ; /* replacement pattern */
/* /*
* PTBEG, PTEND, FORWARD, and REVERSE are all toggle-able values for * PTBEG, PTEND, FORWARD, and REVERSE are all toggle-able values for