Added !searchreplace preprocessor command for compiletime text search/replaces
git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@5852 212acab6-be3b-0410-9dea-997c60f758d6
This commit is contained in:
parent
86bcd61baa
commit
4ed3f49268
4 changed files with 55 additions and 1 deletions
|
@ -148,4 +148,13 @@ If \e{/file} is specified, the file is treated as a series of lines. The file is
|
|||
\c # search filename.cpp for a line '#define APP_VERSION "2.5"' and set ${VER_MAJOR} to 2, ${VER_MINOR} to 5.
|
||||
\c !searchparse /file filename.cpp `#define APP_VERSION "` VER_MAJOR `.` VER_MINOR `"`
|
||||
|
||||
\S1{searchreplace} !searchreplace
|
||||
|
||||
\c [/ignorecase] symbol_out source_string searchfor replacewith
|
||||
|
||||
Searches \e{source_string}, looking for \e{searchfor} and replacing all instances of it with \e{replacewith}. Unlike !define, !searchreplace allows you to redefine \e{symbol_out} without warning or error.
|
||||
|
||||
\c # defines ${blah} to "i like ponies"
|
||||
\c !searchreplace blah "i love ponies" "love" "like"
|
||||
|
||||
|
||||
|
|
|
@ -3076,7 +3076,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line)
|
|||
return PS_OK;
|
||||
case TOK_P_ECHO:
|
||||
SCRIPT_MSG("%s (%s:%d)\n", line.gettoken_str(1),curfilename,linecnt);
|
||||
return PS_OK;
|
||||
return PS_OK;
|
||||
case TOK_P_SEARCHPARSESTRING:
|
||||
{
|
||||
bool ignCase=false;
|
||||
|
@ -3194,6 +3194,49 @@ int CEXEBuild::doCommand(int which_token, LineParser &line)
|
|||
delete list;
|
||||
}
|
||||
return PS_OK;
|
||||
case TOK_P_SEARCHREPLACESTRING:
|
||||
{
|
||||
int ignoreCase=!stricmp(line.gettoken_str(1),"/ignorecase");
|
||||
if (line.getnumtokens()!=5+ignoreCase) PRINTHELP()
|
||||
|
||||
char *define=line.gettoken_str(1+ignoreCase);
|
||||
char *src = line.gettoken_str(2+ignoreCase);
|
||||
char *search = line.gettoken_str(3+ignoreCase);
|
||||
char *replace = line.gettoken_str(4+ignoreCase);
|
||||
int searchlen=strlen(search);
|
||||
int replacelen=strlen(replace);
|
||||
if (!searchlen)
|
||||
{
|
||||
ERROR_MSG("!searchreplace: search string must not be empty for search/replace!\n");
|
||||
return PS_ERROR;
|
||||
}
|
||||
|
||||
GrowBuf valout;
|
||||
|
||||
while (*src)
|
||||
{
|
||||
if (ignoreCase ? strnicmp(src,search,searchlen) : strncmp(src,search,searchlen))
|
||||
valout.add(src++,1);
|
||||
else
|
||||
{
|
||||
valout.add(replace,replacelen);
|
||||
src+=searchlen;
|
||||
}
|
||||
}
|
||||
|
||||
valout.add("",1);
|
||||
|
||||
definedlist.del(define); // allow changing variables since we'll often use this in series
|
||||
|
||||
if (definedlist.add(define,(char*)valout.get()))
|
||||
{
|
||||
ERROR_MSG("!searchreplace: error defining \"%s\"!\n",define);
|
||||
return PS_ERROR;
|
||||
}
|
||||
SCRIPT_MSG("!searchreplace: \"%s\"=\"%s\"\n",define,(char*)valout.get());
|
||||
|
||||
}
|
||||
return PS_OK;
|
||||
|
||||
case TOK_P_VERBOSE:
|
||||
{
|
||||
|
|
|
@ -258,6 +258,7 @@ static tokenType tokenlist[TOK__LAST] =
|
|||
{TOK_P_APPENDFILE,"!appendfile",2,0,"file appended_line",TP_ALL},
|
||||
|
||||
{TOK_P_SEARCHPARSESTRING,"!searchparse",3,-1,"[/ignorecase] [/noerrors] [/file] source_string substring OUTPUTSYM1 [substring [OUTPUTSYM2 [substring ...]]]",TP_ALL},
|
||||
{TOK_P_SEARCHREPLACESTRING,"!searchreplace",4,1,"[/ignorecase] output_name source_string substring replacestring", TP_ALL},
|
||||
|
||||
{TOK_MISCBUTTONTEXT,"MiscButtonText",0,4,"[back button text] [next button text] [cancel button text] [close button text]",TP_GLOBAL},
|
||||
{TOK_DETAILSBUTTONTEXT,"DetailsButtonText",0,1,"[details button text]",TP_PG},
|
||||
|
|
|
@ -118,6 +118,7 @@ enum
|
|||
TOK_P_APPENDFILE,
|
||||
|
||||
TOK_P_SEARCHPARSESTRING,
|
||||
TOK_P_SEARCHREPLACESTRING,
|
||||
|
||||
// section/function shit
|
||||
TOK_SECTION,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue