Merge common code for setting prompt of search and incremental search.

This commit is contained in:
Renaud 2015-03-26 10:15:50 +08:00
parent ac267617ae
commit 247fcfdfb8
3 changed files with 13 additions and 11 deletions

View File

@ -209,7 +209,7 @@ static int isearch(int f, int n)
start_over:
/* ask the user for the text of a pattern */
col = promptpattern( "I-Search") ; /* Prompt, remember the col */
col = promptpattern( "ISearch") ; /* Prompt, remember the col */
cpos = 0; /* Start afresh */
status = TRUE; /* Assume everything's cool */
@ -432,11 +432,7 @@ static int promptpattern(char *prompt)
{
char tpat[NPAT + 20];
strncpy( tpat, prompt, 8) ; /* copy prompt to output string */
tpat[ 8] = '\0' ; /* only one pattern "I-Search" */
strcat(tpat, " ("); /* build new prompt string */
expandp(pat, &tpat[strlen(tpat)], NPAT / 2); /* add old pattern */
strcat(tpat, ")<Meta>: ");
setprompt( tpat, NPAT / 2, prompt, pat) ;
/* check to see if we are executing a command line */
if (!clexec) {

View File

@ -682,6 +682,14 @@ int eq(unsigned char bc, unsigned char pc)
return bc == pc;
}
void setprompt( char *tpat, unsigned tpat_size, char *prompt, char *apat) {
strncpy( tpat, prompt, 14) ; /* copy prompt to output string */
tpat[ 14] = '\0' ; /* longest prompt is "Reverse Search" */
strcat( tpat, " (") ; /* build new prompt string */
expandp( apat, &tpat[ strlen( tpat)], tpat_size) ; /* add old pattern */
strcat( tpat, ")<Meta>: ") ;
}
/*
* readpattern -- Read a pattern. Stash it in apat. If it is the
* search string, create the reverse pattern and the magic
@ -698,11 +706,7 @@ static int readpattern(char *prompt, char *apat, int srch)
int status;
char tpat[NPAT + 20];
strncpy( tpat, prompt, 14) ; /* copy prompt to output string */
tpat[ 14] = '\0' ; /* longest prompt is "Reverse Search" */
strcat(tpat, " ("); /* build new prompt string */
expandp(&apat[0], &tpat[strlen(tpat)], NPAT / 2); /* add old pattern */
strcat(tpat, ")<Meta>: ");
setprompt( tpat, NPAT / 2, prompt, apat) ;
/* Read a pattern. Either we get one,
* or we just get the META charater, and use the previous pattern.

View File

@ -39,6 +39,8 @@ int delins( int dlength, char *instr, int use_meta) ;
int expandp( char *srcstr, char *deststr, int maxlength) ;
int boundry( struct line *curline, int curoff, int dir) ;
void setprompt( char *tpat, unsigned tpat_size, char *prompt, char *apat) ;
#if MAGIC
void mcclear( void) ;
void rmcclear( void) ;