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
|
@ -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:
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue